Skip to content

Commit e4bf5e6

Browse files
committed
commit
1 parent 82e8ffd commit e4bf5e6

File tree

9 files changed

+294
-102
lines changed

9 files changed

+294
-102
lines changed

app/base/tools/Assets/Manager.php

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use \App\Site\Routing\RouteInfo;
2323
use \App\Base\Abstracts\Controllers\BasePage;
2424
use \App\Base\Abstracts\Models\BaseModel;
25+
use \Degami\Basics\Html\TagElement;
2526
use \LessQL\Row;
2627
use \Swift_Message;
2728
use \Exception;
@@ -218,13 +219,21 @@ protected function minifyJs($js)
218219
*/
219220
public function renderPageInlineJS()
220221
{
221-
$output = '';
222222
$js = $this->generatePageJs();
223223
if (!empty($js)) {
224-
$output .= "\n<script type=\"text/javascript\">\n".$js."\n</script>\n";
224+
$options = [
225+
'tag' => 'script',
226+
'type' => 'text/javascript',
227+
'attributes' => [
228+
'class' => '',
229+
],
230+
'text' => $js,
231+
];
232+
233+
return $this->getContainer()->make(TagElement::class, ['options' => $options]);
225234
}
226235

227-
return $output;
236+
return '';
228237
}
229238

230239
/**
@@ -234,13 +243,21 @@ public function renderPageInlineJS()
234243
*/
235244
public function renderHeadInlineJS()
236245
{
237-
$output = '';
238246
$js = $this->generateHeadJs();
239247
if (!empty($js)) {
240-
$output .= "\n<script type=\"text/javascript\">\n".$js."\n</script>\n";
248+
$options = [
249+
'tag' => 'script',
250+
'type' => 'text/javascript',
251+
'attributes' => [
252+
'class' => '',
253+
],
254+
'text' => $js,
255+
];
256+
257+
return $this->getContainer()->make(TagElement::class, ['options' => $options]);
241258
}
242259

243-
return $output;
260+
return '';
244261
}
245262

246263
/**
@@ -288,12 +305,16 @@ public function getCss()
288305
*/
289306
public function renderPageInlineCSS()
290307
{
291-
$output = '';
292308
if (count($this->getCss()) > 0) {
293-
$output .= '<style>'.implode("\n", $this->getCss())."</style>";
309+
$options = [
310+
'tag' => 'style',
311+
'text' => implode("\n", $this->getCss()),
312+
];
313+
314+
return $this->getContainer()->make(TagElement::class, ['options' => $options]);
294315
}
295316

296-
return $output;
317+
return '';
297318
}
298319

299320
/**

app/base/tools/Utils/Globals.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,8 @@ public function getSiteMenu($menu_name, $website_id, $locale, $menu_element = nu
291291
$out = array_map(
292292
function ($el) use ($menu_name, $website_id, $locale) {
293293
/**
294-
* @var Menu $menu_model
295-
*/
294+
* @var Menu $menu_model
295+
*/
296296
$menu_model = $this->getContainer()->make(Menu::class, ['dbrow' => $el]);
297297
return $this->getSiteMenu($menu_name, $website_id, $locale, $menu_model);
298298
},

app/base/tools/Utils/HtmlPartsRenderer.php

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -198,20 +198,32 @@ public function renderSiteMenu($locale)
198198

199199
if ($this->getSiteData()->getShowLogoOnMenu($website_id)) {
200200
// add logo
201-
$menu->addChild(
202-
$this->getContainer()->make(
203-
TagElement::class,
204-
['options' => [
201+
$logo = $this->getContainer()->make(
202+
TagElement::class,
203+
['options' => [
204+
'tag' => 'img',
205+
'attributes' => [
206+
'class' => '',
207+
'title' => $this->getEnv('APPNAME'),
208+
'src' => $this->getAssets()->assetUrl('/sitebase_logo.png'),
209+
],
210+
]]
211+
);
212+
213+
$atag = $this->getContainer()->make(
214+
TagElement::class,
215+
['options' => [
205216
'tag' => 'a',
206217
'attributes' => [
207-
'class' => 'navbar-brand',
208-
'href' => $this->getRouting()->getUrl('frontend.root'),
209-
'title' => $this->getEnv('APPNAME'),
218+
'class' => 'navbar-brand',
219+
'href' => $this->getRouting()->getUrl('frontend.root'),
220+
'title' => $this->getEnv('APPNAME'),
210221
],
211-
'text' => '<img src="'.$this->getAssets()->assetUrl('/sitebase_logo.png').'" />',
212-
]]
213-
)
222+
]]
214223
);
224+
225+
$atag->addChild($logo);
226+
$menu->addChild($atag);
215227
}
216228

217229
// add mobile toggle button

app/site/blocks/BreadCrumbs.php

Lines changed: 88 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use \App\Base\Traits\AdminTrait;
1919
use \App\Site\Controllers\Frontend\Page;
2020
use \App\Site\Models\Rewrite;
21+
use \Degami\Basics\Html\TagElement;
2122

2223
/**
2324
* Breadcrumbs Block
@@ -44,54 +45,96 @@ public function renderHTML(BasePage $current_page = null)
4445
$menu_item = reset($menuitems);
4546
$home_url = $this->getRouting()->getUrl('frontend.root');
4647

47-
$breadcrumbs_links = [];
48+
$breadcrumbs_links = $this->getContainer()->make(TagElement::class, ['options' => [
49+
'tag' => 'ol',
50+
'attributes' => [
51+
'class' => 'breadcrumb',
52+
],
53+
]]);
54+
4855

4956
$homepageid = $this->getSiteData()->getHomePageId(
5057
$this->getSiteData()->getCurrentWebsiteId(),
5158
$current_page->getCurrentLocale()
5259
);
5360

5461
if (!$current_page->isHomePage()) {
55-
$breadcrumbs_links[] = '<a href="'.$home_url.'">'.$this->getUtils()->translate('Home', $locale).'</a>';
62+
$li = $this->getContainer()->make(
63+
TagElement::class,
64+
['options' => [
65+
'tag' => 'li',
66+
'attributes' => ['class' => 'breadcrumb-item'],
67+
]]
68+
);
69+
70+
$atag = $this->getContainer()->make(
71+
TagElement::class,
72+
['options' => [
73+
'tag' => 'a',
74+
'attributes' => [
75+
'class' => 'breadcrumb-link',
76+
'href' => $home_url,
77+
'title' => (trim($title) != '') ? $this->getUtils()->translate($title, $this->getCurrentLocale()) : '',
78+
],
79+
'text' => $this->getUtils()->translate('Home', $locale),
80+
]]
81+
);
82+
83+
$li->addChild($atag);
84+
$breadcrumbs_links->addChild($li);
5685
}
5786

58-
$breadcrumbs_html = '<nav aria-label="breadcrumb"><ol class="breadcrumb"><li class="breadcrumb-item">';
5987
if ($menu_item instanceof Menu) {
6088
$breadcrumbs = explode('/', $menu_item->getBreadcrumb());
6189
if (count($breadcrumbs) == 0 || $breadcrumbs[count($breadcrumbs)-1] != $menu_item->getId()) {
6290
$breadcrumbs[] = $menu_item->getId();
6391
}
6492

65-
array_push(
66-
$breadcrumbs_links,
67-
...array_map(
68-
function ($id) use ($homepageid, $locale) {
69-
$menuItem = $this->getContainer()->call([Menu::class, 'load'], ['id' => $id]);
70-
71-
if ($menuItem->getRewriteId()) {
72-
/**
73-
* @var Rewrite $rewrite
74-
*/
75-
$rewrite = $this->getContainer()->make(Rewrite::class)->fill($menuItem->getRewriteId());
76-
if ($rewrite->getRoute() == '/page/'.$homepageid) {
77-
$menuItem->setTitle($this->getUtils()->translate('Home', $locale));
78-
}
93+
foreach (array_map(
94+
function ($id) use ($homepageid, $locale) {
95+
$menuItem = $this->getContainer()->call([Menu::class, 'load'], ['id' => $id]);
96+
97+
if ($menuItem->getRewriteId()) {
98+
/**
99+
* @var Rewrite $rewrite
100+
*/
101+
$rewrite = $this->getContainer()->make(Rewrite::class)->fill($menuItem->getRewriteId());
102+
if ($rewrite->getRoute() == '/page/'.$homepageid) {
103+
$menuItem->setTitle($this->getUtils()->translate('Home', $locale));
79104
}
105+
}
80106

81-
$leaf = [
82-
'title' => $menuItem->getTitle(),
83-
'href' => $menuItem->getLinkUrl(),
84-
'target' => $menuItem->getTarget(),
85-
];
86-
return $this->_renderLink($leaf);
87-
},
88-
array_filter($breadcrumbs)
89-
)
90-
);
107+
$leaf = [
108+
'title' => $menuItem->getTitle(),
109+
'href' => $menuItem->getLinkUrl(),
110+
'target' => $menuItem->getTarget(),
111+
];
112+
return $this->_renderLink($leaf);
113+
},
114+
array_filter($breadcrumbs)
115+
) as $atag) {
116+
$li = $this->getContainer()->make(
117+
TagElement::class,
118+
['options' => [
119+
'tag' => 'li',
120+
'attributes' => ['class' => 'breadcrumb-item'],
121+
]]
122+
);
123+
124+
$li->addChild($atag);
125+
$breadcrumbs_links->addChild($li);
126+
}
91127
}
92-
$breadcrumbs_html .= implode('</li><li class="breadcrumb-item">', $breadcrumbs_links);
93-
$breadcrumbs_html .= '</li></ol></nav>';
94-
return $breadcrumbs_html;
128+
129+
$breadcrumbs_container = $this->getContainer()->make(TagElement::class, ['options' => [
130+
'tag' => 'nav',
131+
'attributes' => [
132+
'aria-label' => 'breadcrumb',
133+
],
134+
]]);
135+
136+
$breadcrumbs_container->addChild($breadcrumbs_links);
137+
return $breadcrumbs_container;
95138
}
96139

97140
/**
@@ -103,6 +146,20 @@ function ($id) use ($homepageid, $locale) {
103146
*/
104147
protected function _renderLink($leaf, $link_class = 'breadcrumb-link')
105148
{
106-
return '<a class="'.$link_class.'" href="'.$leaf['href'].'"'. (($leaf['target']) ? ' target="'.$leaf['target'].'"':'') .'>'.$leaf['title'].'</a>';
149+
$link_options = [
150+
'tag' => 'a',
151+
'attributes' => [
152+
'class' => $link_class,
153+
'href' => $leaf['href'],
154+
'title' => $leaf['title'],
155+
],
156+
'text' => $leaf['title'],
157+
];
158+
159+
if ($leaf['target']) {
160+
$link_options['attributes']['target'] = $leaf['target'];
161+
}
162+
163+
return $this->getContainer()->make(TagElement::class, ['options' => $link_options]);
107164
}
108165
}

app/site/blocks/ChangeLanguage.php

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use \Degami\PHPFormsApi as FAPI;
1818
use \App\Site\Models\Language;
1919
use \Exception;
20+
use \Degami\Basics\Html\TagElement;
2021

2122
/**
2223
* Change Language Block
@@ -43,29 +44,56 @@ public function renderHTML(BasePage $current_page = null, $data = [])
4344

4445
if (is_callable([$current_page, 'getTranslations'])) {
4546
if (($translations = $current_page->getTranslations()) && !empty($translations)) {
46-
return '<ul class="choose-lang"><li>'.implode(
47-
'</li><li>',
48-
array_map(
49-
function ($el, $key) use ($config) {
50-
$text = '';
51-
$language = $this->getContainer()->call([Language::class, 'loadBy'], ['field' => 'locale', 'value' => $key]);
47+
$changelanguage_links = $this->getContainer()->make(TagElement::class, ['options' => [
48+
'tag' => 'ul',
49+
'attributes' => [
50+
'class' => 'choose-lang',
51+
],
52+
]]);
5253

53-
if (isset($config['show-language']) && $config['show-language'] == 'code') {
54-
$text = $key;
55-
}
56-
if (isset($config['show-language']) && $config['show-language'] == 'full') {
57-
$text = $language->native;
58-
}
59-
if (isset($config['show-flags']) && boolval($config['show-flags'])) {
60-
$text .= ' '.$this->getHtmlRenderer()->renderFlag($key);
61-
}
54+
foreach (array_map(
55+
function ($el, $key) use ($config) {
56+
$text = '';
57+
$language = $this->getContainer()->call([Language::class, 'loadBy'], ['field' => 'locale', 'value' => $key]);
6258

63-
return '<a href="'.$el.'">'.$text.'</a>';
64-
},
65-
$translations,
66-
array_keys($translations)
67-
)
68-
).'</li></ul>';
59+
if (isset($config['show-language']) && $config['show-language'] == 'code') {
60+
$text = $key;
61+
}
62+
if (isset($config['show-language']) && $config['show-language'] == 'full') {
63+
$text = $language->native;
64+
}
65+
if (isset($config['show-flags']) && boolval($config['show-flags'])) {
66+
$text .= ' '.$this->getHtmlRenderer()->renderFlag($key);
67+
}
68+
69+
$link_options = [
70+
'tag' => 'a',
71+
'attributes' => [
72+
'class' => '',
73+
'href' => $el,
74+
'title' => strip_tags($text),
75+
],
76+
'text' => $text,
77+
];
78+
79+
return $this->getContainer()->make(TagElement::class, ['options' => $link_options]);
80+
},
81+
$translations,
82+
array_keys($translations)
83+
) as $atag) {
84+
$li = $this->getContainer()->make(
85+
TagElement::class,
86+
['options' => [
87+
'tag' => 'li',
88+
'attributes' => ['class' => ''],
89+
]]
90+
);
91+
92+
$li->addChild($atag);
93+
$changelanguage_links->addChild($li);
94+
}
95+
96+
return $changelanguage_links;
6997
}
7098
}
7199
} catch (Exception $e) {

0 commit comments

Comments
 (0)