1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace FrontendModule; |
4
|
|
|
|
5
|
|
|
use Nette; |
6
|
|
|
use Kdyby\BootstrapFormRenderer\BootstrapRenderer; |
7
|
|
|
use Nette\Application\UI; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Base class for all application presenters. |
11
|
|
|
* |
12
|
|
|
* @author Tomáš Voslař <tomas.voslar at webcook.cz> |
13
|
|
|
* @package WebCMS2 |
14
|
|
|
*/ |
15
|
|
|
class BasePresenter extends \WebCMS2\Common\BasePresenter |
16
|
|
|
{ |
17
|
|
|
/** @var Doctrine\ORM\EntityManager */ |
18
|
|
|
protected $em; |
19
|
|
|
|
20
|
|
|
/* @var \WebCMS\Translation\Translation */ |
21
|
|
|
public $translation; |
22
|
|
|
|
23
|
|
|
/* @var \WebCMS\Translation\Translator */ |
24
|
|
|
public $translator; |
25
|
|
|
|
26
|
|
|
/* @var Nette\Http\SessionSection */ |
27
|
|
|
public $language; |
28
|
|
|
|
29
|
|
|
/* @var User */ |
30
|
|
|
public $systemUser; |
31
|
|
|
|
32
|
|
|
/* @var \WebCMS\Settings */ |
33
|
|
|
public $settings; |
34
|
|
|
|
35
|
|
|
/* $var \WebCMS\MobileDetect */ |
36
|
|
|
public $mobileDetect; |
37
|
|
|
|
38
|
|
|
/* @var Page */ |
39
|
|
|
public $actualPage; |
40
|
|
|
|
41
|
|
|
/* @var string */ |
42
|
|
|
public $abbr; |
43
|
|
|
|
44
|
|
|
/* @var Array */ |
45
|
|
|
public $languages; |
46
|
|
|
|
47
|
|
|
/* @var Array */ |
48
|
|
|
private $breadcrumbs = array(); |
49
|
|
|
|
50
|
|
|
/* Method is executed before render. */ |
51
|
|
|
protected function beforeRender() |
52
|
|
|
{ |
53
|
|
|
|
54
|
|
|
// secured page |
55
|
|
|
if (is_object($this->actualPage)) { |
56
|
|
|
if (!$this->getUser()->isLoggedIn() && $this->actualPage->getSecured()) { |
57
|
|
|
$this->redirect(':Frontend:Login:'); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
if (is_object($this->actualPage)) { |
62
|
|
|
if ($this->actualPage->getLayout()) { |
63
|
|
|
$this->setLayout($this->actualPage->getLayout()); |
64
|
|
|
} elseif ($this->actualPage->getDefault()) { |
65
|
|
|
$this->setLayout("layoutDefault"); |
66
|
|
|
} else { |
67
|
|
|
$this->setLayout("layout"); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
if ($this->isAjax()) { |
72
|
|
|
$this->invalidateControl('flashMessages'); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
$this->template->registerHelperLoader('\WebCMS\Helpers\SystemHelper::loader'); |
|
|
|
|
76
|
|
|
|
77
|
|
|
// get top page for sidebar menu |
78
|
|
|
if (is_object($this->actualPage)) { |
79
|
|
|
$top = $this->actualPage; |
80
|
|
|
while ($top->getParent() != NULL && $top->getLevel() > 1) { |
81
|
|
|
$top = $top->getParent(); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
// set up boxes |
86
|
|
|
$this->setUpBoxes(); |
87
|
|
|
|
88
|
|
|
// load user defined scripts & styles |
89
|
|
|
$this->setPageScripts(); |
90
|
|
|
$this->setPageStyles(); |
91
|
|
|
|
92
|
|
|
// set default seo settings |
93
|
|
|
if (is_object($this->actualPage)) { |
94
|
|
|
$this->template->breadcrumb = $this->getBreadcrumbs(); |
|
|
|
|
95
|
|
|
$this->template->sidebar = $this->getStructure($this, $top, $this->em->getRepository('WebCMS\Entity\Page'), false, $this->settings->get('Sidebar class', \WebCMS\Settings::SECTION_BASIC, 'text')->getValue(), false, false, null, $this->settings->get('Sidebar class', \WebCMS\Settings::SECTION_BASIC, 'text')->getValue()); |
|
|
|
|
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
$this->template->abbr = $this->abbr; |
|
|
|
|
99
|
|
|
$this->template->settings = $this->settings; |
|
|
|
|
100
|
|
|
// !params load from settings |
101
|
|
|
$this->template->structuresRaw = $this->em->getRepository('WebCMS\Entity\Page')->findBy(array( |
|
|
|
|
102
|
|
|
'language' => $this->language |
103
|
|
|
)); |
104
|
|
|
$this->template->structures = $this->getStructures(!$this->settings->get('Navbar dropdown', \WebCMS\Settings::SECTION_BASIC, 'text')->getValue(), $this->settings->get('Navbar class', \WebCMS\Settings::SECTION_BASIC, 'text')->getValue(), $this->settings->get('Navbar dropdown', \WebCMS\Settings::SECTION_BASIC, 'text')->getValue(), $this->settings->get('Navbar id', \WebCMS\Settings::SECTION_BASIC, 'text')->getValue()); |
|
|
|
|
105
|
|
|
$this->template->setTranslator($this->translator); |
|
|
|
|
106
|
|
|
$this->template->actualPage = $this->actualPage; |
|
|
|
|
107
|
|
|
$this->template->user = $this->getUser(); |
|
|
|
|
108
|
|
|
$this->template->activePresenter = $this->getPresenter()->getName(); |
|
|
|
|
109
|
|
|
$this->template->language = $this->language; |
|
|
|
|
110
|
|
|
$this->template->languages = $this->em->getRepository('WebCMS\Entity\Language')->findAll(); |
|
|
|
|
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
private function setDefaultSeo() |
114
|
|
|
{ |
115
|
|
|
$temp = $this->actualPage->getMetaKeywords(); |
116
|
|
View Code Duplication |
if (!empty($temp)) { |
|
|
|
|
117
|
|
|
$this->template->seoKeywords = $this->actualPage->getMetaKeywords(); |
|
|
|
|
118
|
|
|
} else { |
119
|
|
|
$this->template->seoKeywords = $this->settings->get('Seo keywords', \WebCMS\Settings::SECTION_BASIC, 'text')->getValue(); |
|
|
|
|
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
$temp = $this->actualPage->getMetaDescription(); |
123
|
|
View Code Duplication |
if (!empty($temp)) { |
|
|
|
|
124
|
|
|
$this->template->seoDescription = $this->actualPage->getMetaDescription(); |
|
|
|
|
125
|
|
|
} else { |
126
|
|
|
$this->template->seoDescription = $this->settings->get('Seo description', \WebCMS\Settings::SECTION_BASIC, 'text')->getValue(); |
|
|
|
|
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
$temp = $this->actualPage->getMetaTitle(); |
130
|
|
|
if (!empty($temp)) { |
131
|
|
|
$this->template->seoTitle = $this->actualPage->getMetaTitle(); |
|
|
|
|
132
|
|
|
} else { |
133
|
|
|
$this->template->seoTitle = $this->actualPage->getTitle(); |
|
|
|
|
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
if ($this->settings->get('Seo title before', \WebCMS\Settings::SECTION_BASIC, 'checkbox')->getValue()) { |
137
|
|
|
$this->template->seoTitle = $this->settings->get('Seo title', \WebCMS\Settings::SECTION_BASIC, 'text')->getValue().$this->template->seoTitle; |
|
|
|
|
138
|
|
|
} else { |
139
|
|
|
$this->template->seoTitle = $this->template->seoTitle.$this->settings->get('Seo title', \WebCMS\Settings::SECTION_BASIC, 'text')->getValue(); |
|
|
|
|
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
private function setPageScripts() |
144
|
|
|
{ |
145
|
|
|
$globalHead = $this->settings->get('Enable scripts head', \WebCMS\Settings::SECTION_BASIC, 'checkbox-toggle')->getValue(); |
146
|
|
|
$globalBodyStart = $this->settings->get('Enable scripts body start', \WebCMS\Settings::SECTION_BASIC, 'checkbox-toggle')->getValue(); |
147
|
|
|
$globalBodyEnd = $this->settings->get('Enable scripts body end', \WebCMS\Settings::SECTION_BASIC, 'checkbox-toggle')->getValue(); |
148
|
|
|
|
149
|
|
|
if ($globalHead) { |
150
|
|
|
$rawScript = $this->settings->get('Scripts head', \WebCMS\Settings::SECTION_BASIC, 'textarea-plain')->getValue(); |
151
|
|
|
|
152
|
|
|
$vars = array(); |
153
|
|
|
$vars['%device%'] = $this->mobileDetect->getDeviceType(); |
154
|
|
|
$vars['%response%'] = $this->getHttpResponse()->getCode(); |
155
|
|
|
|
156
|
|
|
$pageScriptsHead = \WebCMS\Helpers\SystemHelper::strFindAndReplaceAll($vars, $rawScript); |
157
|
|
|
} else { |
158
|
|
|
$pageScriptsHead = ''; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
if ($globalBodyStart) { |
162
|
|
|
$pageScriptsBodyStart = $this->settings->get('Scripts body start', \WebCMS\Settings::SECTION_BASIC, 'textarea-plain')->getValue(); |
163
|
|
|
} else { |
164
|
|
|
$pageScriptsBodyStart = ''; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
if ($globalBodyEnd) { |
168
|
|
|
$pageScriptsBodyEnd = $this->settings->get('Scripts body end', \WebCMS\Settings::SECTION_BASIC, 'textarea-plain')->getValue(); |
169
|
|
|
} else { |
170
|
|
|
$pageScriptsBodyEnd = ''; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
$this->template->pageScriptsHead = $this->createTemplate('Nette\Templating\Template')->setSource($pageScriptsHead); |
|
|
|
|
174
|
|
|
$this->template->pageScriptsBodyStart = $this->createTemplate('Nette\Templating\Template')->setSource($pageScriptsBodyStart); |
|
|
|
|
175
|
|
|
$this->template->pageScriptsBodyEnd = $this->createTemplate('Nette\Templating\Template')->setSource($pageScriptsBodyEnd); |
|
|
|
|
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
private function setPageStyles() |
179
|
|
|
{ |
180
|
|
|
$globalStylesHead = $this->settings->get('Enable styles head', \WebCMS\Settings::SECTION_BASIC, 'checkbox-toggle')->getValue(); |
181
|
|
|
|
182
|
|
|
if ($globalStylesHead) { |
183
|
|
|
$pageStylesHead = $this->settings->get('Styles head', \WebCMS\Settings::SECTION_BASIC, 'textarea-plain')->getValue(); |
184
|
|
|
} else { |
185
|
|
|
$pageStylesHead = ''; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
$this->template->pageStylesHead = $this->createTemplate('Nette\Templating\Template')->setSource($pageStylesHead); |
|
|
|
|
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/* Startup method. */ |
192
|
|
|
|
193
|
|
|
protected function startup() |
194
|
|
|
{ |
195
|
|
|
parent::startup(); |
196
|
|
|
|
197
|
|
|
// change language |
198
|
|
|
if (is_numeric($this->getParam('l'))) { |
|
|
|
|
199
|
|
|
$this->changeLanguage($this->getParam('l')); |
|
|
|
|
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
// set language |
203
|
|
|
if (is_numeric($this->getParam('language'))) { |
|
|
|
|
204
|
|
|
$this->language = $this->em->find('WebCMS\Entity\Language', $this->getParam('language')); |
|
|
|
|
205
|
|
|
} else { |
206
|
|
|
$this->language = $this->em->getRepository('WebCMS\Entity\Language')->findOneBy(array( |
207
|
|
|
'defaultFrontend' => TRUE, |
208
|
|
|
)); |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
$this->abbr = $this->language->getDefaultFrontend() ? '' : $this->language->getAbbr().'/'; |
212
|
|
|
|
213
|
|
|
// load languages |
214
|
|
|
$this->languages = $this->em->getRepository('WebCMS\Entity\Language')->findAll(); |
215
|
|
|
|
216
|
|
|
setlocale(LC_ALL, $this->language->getLocale()); |
217
|
|
|
\WebCMS\Helpers\PriceFormatter::setLocale($this->language->getLocale()); |
218
|
|
|
|
219
|
|
|
// translations |
220
|
|
|
$translation = new \WebCMS\Translation\Translation($this->em, $this->language, 0, $this->getContext()->getService('cacheStorage')); |
221
|
|
|
$this->translation = $translation->getTranslations(); |
222
|
|
|
$this->translator = new \WebCMS\Translation\Translator($this->translation); |
223
|
|
|
|
224
|
|
|
// system settings |
225
|
|
|
$this->settings = new \WebCMS\Settings($this->em, $this->language); |
226
|
|
|
$this->settings->setSettings($this->getSettings()); |
227
|
|
|
|
228
|
|
|
// mobile device detection |
229
|
|
|
$this->mobileDetect = new \WebCMS\MobileDetect; |
230
|
|
|
|
231
|
|
|
// system helper sets variables |
232
|
|
|
\WebCMS\Helpers\SystemHelper::setVariables(array( |
233
|
|
|
'baseUrl' => $this->presenter->getHttpRequest()->url->baseUrl, |
234
|
|
|
'infoEmail' => $this->settings->get('Info email', 'basic')->getValue(), |
235
|
|
|
)); |
236
|
|
|
|
237
|
|
|
$id = $this->getParam('id'); |
|
|
|
|
238
|
|
|
if ($id) { |
239
|
|
|
$this->actualPage = $this->em->find('WebCMS\Entity\Page', $id); |
240
|
|
|
|
241
|
|
|
if ($this->actualPage->getRedirect() != NULL) { |
242
|
|
|
if (strpos($this->actualPage->getRedirect(), 'http') === false) { |
243
|
|
|
$this->redirectUrl($this->presenter->getHttpRequest()->url->baseUrl . $this->actualPage->getRedirect()); |
244
|
|
|
} else { |
245
|
|
|
$this->redirectUrl($this->actualPage->getRedirect()); |
246
|
|
|
} |
247
|
|
|
} |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
if (!file_exists('sitemap.xml')) { |
251
|
|
|
$this->generateSitemap(); |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
if (is_object($this->actualPage)) { |
255
|
|
|
$this->setDefaultSeo(); |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
// generate sitemap if doesn't exist yet |
259
|
|
|
if (!file_exists('sitemap.xml')) { |
260
|
|
|
$this->generateSitemap(); |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
if ($this->isAjax()) { |
264
|
|
|
$this->invalidateControl(); |
265
|
|
|
|
266
|
|
|
$this->payload->title = $this->template->seoTitle; |
|
|
|
|
267
|
|
|
$this->payload->url = $this->link('this', array( |
|
|
|
|
268
|
|
|
'path' => $this->actualPage->getPath(), |
269
|
|
|
'abbr' => $this->abbr, |
270
|
|
|
)); |
271
|
|
|
$this->payload->nameSeo = $this->actualPage->getSlug(); |
|
|
|
|
272
|
|
|
$this->payload->name = $this->actualPage->getTitle(); |
|
|
|
|
273
|
|
|
$this->payload->class = $this->actualPage->getClass(); |
|
|
|
|
274
|
|
|
} |
275
|
|
|
} |
276
|
|
|
|
277
|
|
View Code Duplication |
public function generateSitemap() |
|
|
|
|
278
|
|
|
{ |
279
|
|
|
$sitemapXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n"; |
280
|
|
|
|
281
|
|
|
$repository = $this->em->getRepository('WebCMS\Entity\Page'); |
282
|
|
|
$pages = $repository->findAll(); |
283
|
|
|
|
284
|
|
|
foreach ($pages as $page) { |
285
|
|
|
if ($page->getParent() !== null) { |
286
|
|
|
$sitemapXml .= "<url>\n\t<loc>".$this->getSitemapLink($page)."</loc>\n</url>\n"; |
287
|
|
|
} |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
$sitemapXml .= '</urlset>'; |
291
|
|
|
|
292
|
|
|
file_put_contents('./sitemap.xml', $sitemapXml); |
293
|
|
|
} |
294
|
|
|
|
295
|
|
View Code Duplication |
private function getSitemapLink($page) |
|
|
|
|
296
|
|
|
{ |
297
|
|
|
$url = $this->context->httpRequest->url->baseUrl; |
|
|
|
|
298
|
|
|
$url .= !$page->getLanguage()->getDefaultFrontend() ? $page->getLanguage()->getAbbr().'/' : ''; |
299
|
|
|
$url .= $page->getPath(); |
300
|
|
|
|
301
|
|
|
return $url; |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
public function createTemplate($class = null) |
305
|
|
|
{ |
306
|
|
|
$template = parent::createTemplate($class); |
307
|
|
|
|
308
|
|
|
$template->setTranslator($this->translator); |
309
|
|
|
$template->registerHelperLoader('\WebCMS\Helpers\SystemHelper::loader'); |
310
|
|
|
|
311
|
|
|
return $template; |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
protected function getLanguageId() |
315
|
|
|
{ |
316
|
|
|
return $this->language->getId(); |
317
|
|
|
} |
318
|
|
|
|
319
|
|
|
public function createForm($do = '', $action = 'default', $context = null, $parameters = array()) |
320
|
|
|
{ |
321
|
|
|
$form = new UI\Form(); |
322
|
|
|
|
323
|
|
|
if ($context != null) { |
324
|
|
|
$page = $context->actualPage; |
325
|
|
|
$abbr = $context->abbr; |
326
|
|
|
$translator = $context->translator; |
327
|
|
|
$c = $context; |
328
|
|
|
} else { |
329
|
|
|
$page = $this->actualPage; |
330
|
|
|
$abbr = $this->abbr; |
331
|
|
|
$translator = $this->translator; |
332
|
|
|
$c = $this; |
333
|
|
|
} |
334
|
|
|
|
335
|
|
|
$form->getElementPrototype()->action = $c->link($action, array( |
336
|
|
|
'path' => $page->getPath(), |
337
|
|
|
'abbr' => $abbr, |
338
|
|
|
'do' => $do, |
339
|
|
|
'parameters' => $parameters, |
340
|
|
|
)); |
341
|
|
|
|
342
|
|
|
$form->setTranslator($translator); |
343
|
|
|
$form->setRenderer(new BootstrapRenderer()); |
344
|
|
|
|
345
|
|
|
return $form; |
346
|
|
|
} |
347
|
|
|
|
348
|
|
|
public function createComponentLanguagesForm() |
349
|
|
|
{ |
350
|
|
|
$form = $this->createForm(); |
351
|
|
|
|
352
|
|
|
$form->getElementPrototype()->action = $this->link('this', array( |
353
|
|
|
'id' => $this->actualPage->getId(), |
354
|
|
|
'path' => $this->actualPage->getPath(), |
355
|
|
|
'abbr' => $this->abbr, |
356
|
|
|
'do' => 'languagesForm-submit', |
357
|
|
|
)); |
358
|
|
|
|
359
|
|
|
$items = array(); |
360
|
|
|
foreach ($this->languages as $lang) { |
361
|
|
|
$items[$lang->getId()] = $lang->getName(); |
362
|
|
|
} |
363
|
|
|
|
364
|
|
|
$form->addSelect('language', 'Change language')->setItems($items)->setDefaultValue($this->language->getId()); |
365
|
|
|
$form->addSubmit('submit', 'Change'); |
366
|
|
|
$form->onSuccess[] = callback($this, 'languagesFormSubmitted', array('abbr' => '', 'path' => $this->actualPage->getPath())); |
|
|
|
|
367
|
|
|
|
368
|
|
|
return $form; |
369
|
|
|
} |
370
|
|
|
|
371
|
|
|
public function languagesFormSubmitted($form) |
372
|
|
|
{ |
373
|
|
|
$values = $form->getValues(); |
374
|
|
|
|
375
|
|
|
$this->changeLanguage($values->language); |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
private function changeLanguage($idLanguage) |
379
|
|
|
{ |
380
|
|
|
$home = $this->em->getRepository('WebCMS\Entity\Page')->findOneBy(array( |
381
|
|
|
'language' => $idLanguage, |
382
|
|
|
'default' => TRUE, |
383
|
|
|
)); |
384
|
|
|
|
385
|
|
|
if (is_object($home)) { |
386
|
|
|
$abbr = $home->getLanguage()->getDefaultFrontend() ? '' : $home->getLanguage()->getAbbr().'/'; |
387
|
|
|
|
388
|
|
|
$this->redirectUrl( |
389
|
|
|
$this->getHttpRequest()->url->baseUrl.$abbr.$home->getPath() |
390
|
|
|
); |
391
|
|
|
} else { |
392
|
|
|
$this->flashMessage('No default page for selected language.', 'error'); |
393
|
|
|
} |
394
|
|
|
} |
395
|
|
|
|
396
|
|
|
/** |
397
|
|
|
* Set up boxes (call box function and save it into array) and give them to the template. |
398
|
|
|
*/ |
399
|
|
|
private function setUpBoxes() |
400
|
|
|
{ |
401
|
|
|
$parameters = $this->context->getParameters(); |
|
|
|
|
402
|
|
|
$boxes = $parameters['boxes']; |
403
|
|
|
|
404
|
|
|
$finalBoxes = array(); |
405
|
|
|
if (is_array($boxes)) { |
406
|
|
|
foreach ($boxes as $key => $box) { |
407
|
|
|
$finalBoxes[$key] = null; |
408
|
|
|
} |
409
|
|
|
} |
410
|
|
|
|
411
|
|
|
$assocBoxes = $this->em->getRepository('WebCMS\Entity\Box')->findBy(array( |
412
|
|
|
'pageTo' => $this->actualPage |
413
|
|
|
)); |
414
|
|
|
|
415
|
|
|
foreach ($assocBoxes as $box) { |
416
|
|
|
$presenter = 'FrontendModule\\'.$box->getModuleName().'Module\\'.$box->getPresenter().'Presenter'; |
417
|
|
|
$object = new $presenter(); |
418
|
|
|
|
419
|
|
|
if (method_exists($object, $box->getFunction())) { |
420
|
|
|
$function = $box->getFunction(); |
421
|
|
|
$pageFrom = $box->getPageFrom(); |
422
|
|
|
if ($pageFrom) { |
423
|
|
|
$finalBoxes[$box->getBox()] = call_user_func(array($object, $function), $this, $pageFrom); |
424
|
|
|
} |
425
|
|
|
} |
426
|
|
|
} |
427
|
|
|
|
428
|
|
|
$this->template->boxes = $finalBoxes; |
|
|
|
|
429
|
|
|
} |
430
|
|
|
|
431
|
|
|
/** |
432
|
|
|
* Load all system structures. |
433
|
|
|
* @return type |
434
|
|
|
*/ |
435
|
|
|
private function getStructures($direct = true, $rootClass = 'nav navbar-nav', $dropDown = false, $rootId = '') |
436
|
|
|
{ |
437
|
|
|
$repo = $this->em->getRepository('WebCMS\Entity\Page'); |
438
|
|
|
|
439
|
|
|
$structs = $repo->findBy(array( |
440
|
|
|
'language' => $this->language, |
441
|
|
|
'parent' => NULL, |
442
|
|
|
)); |
443
|
|
|
|
444
|
|
|
$structures = array(); |
445
|
|
|
foreach ($structs as $s) { |
446
|
|
|
$structures[$s->getTitle()] = $this->getStructure($this, $s, $repo, $direct, $rootClass, $dropDown, true, null, '', null, $rootId); |
|
|
|
|
447
|
|
|
} |
448
|
|
|
|
449
|
|
|
return $structures; |
450
|
|
|
} |
451
|
|
|
|
452
|
|
|
/** |
453
|
|
|
* TODO refactor, maybe it will be better in template |
454
|
|
|
* Get structure by node. In node is set to null whole tree is returned. |
455
|
|
|
* @param type $node |
456
|
|
|
* @param Repository $repo |
457
|
|
|
* @param type $direct |
458
|
|
|
* @param type $rootClass |
459
|
|
|
* @param type $dropDown |
460
|
|
|
* @param BasePresenter $context |
461
|
|
|
* @return type |
462
|
|
|
*/ |
463
|
|
|
protected function getStructure($context, $node = null, $repo, $direct = true, $rootClass = 'nav navbar-nav', $dropDown = false, $system = true, $fromPage = null, $sideClass = 'nav navbar', $moduleNameAbstract = null, $rootId = '') |
464
|
|
|
{ |
465
|
|
|
return $repo->childrenHierarchy($node, $direct, array( |
466
|
|
|
'decorate' => true, |
467
|
|
|
'html' => true, |
468
|
|
|
'rootOpen' => function ($nodes) use ($rootClass, $dropDown, $sideClass, $rootId) { |
469
|
|
|
|
470
|
|
|
$drop = $nodes[0]['level'] == 2 ? true : false; |
471
|
|
|
$class = $nodes[0]['level'] < 2 ? $rootClass : $sideClass; |
472
|
|
|
|
473
|
|
|
if ($drop && $dropDown) { |
474
|
|
|
$class .= ' dropdown-menu submenu'; |
475
|
|
|
} |
476
|
|
|
|
477
|
|
|
$htmlId = ''; |
478
|
|
|
if (!empty($rootId)) { |
479
|
|
|
$htmlId = ' id = "'.$rootId.'"'; |
480
|
|
|
} |
481
|
|
|
|
482
|
|
|
return '<ul class="'.$class.'"'.$htmlId.'>'; |
483
|
|
|
}, |
484
|
|
|
'rootClose' => '</ul>', |
485
|
|
|
'childOpen' => function ($node) use ($dropDown, $context) { |
486
|
|
|
$hasChildrens = count($node['__children']) > 0 ? true : false; |
487
|
|
|
$param = $context->getRequest()->getParameters(); |
488
|
|
|
$active = $context->getParam('id') == $node['id'] ? true : false; |
|
|
|
|
489
|
|
|
$class = ''; |
490
|
|
|
|
491
|
|
|
if (!array_key_exists('fullPath', $param)) { |
492
|
|
|
$param['fullPath'] = '/defPath'; |
493
|
|
|
} |
494
|
|
|
|
495
|
|
|
if (array_key_exists('redirect', $node)) { |
496
|
|
|
if ($param['fullPath'] == $node['redirect']) { |
497
|
|
|
$active = true; |
498
|
|
|
} |
499
|
|
|
} |
500
|
|
|
|
501
|
|
|
if ($context->getParam('lft') > $node['lft'] && $context->getParam('lft') < $node['rgt'] && $context->getParam('root') == $node['root']) { |
|
|
|
|
502
|
|
|
$class .= ' active'; |
503
|
|
|
} |
504
|
|
|
|
505
|
|
|
if ($hasChildrens && $dropDown) { |
506
|
|
|
$class .= ' dropdown'; |
507
|
|
|
} |
508
|
|
|
|
509
|
|
|
if ($active) { |
510
|
|
|
$class .= ' active'; |
511
|
|
|
} |
512
|
|
|
|
513
|
|
|
if (!$node['visible']) { |
514
|
|
|
$class .= ' hidden'; |
515
|
|
|
} |
516
|
|
|
|
517
|
|
|
if ($node['secured']) { |
518
|
|
|
$class .= ' secured'; |
519
|
|
|
} |
520
|
|
|
|
521
|
|
|
return '<li class="'.$class.'">'; |
522
|
|
|
}, |
523
|
|
|
'childClose' => '</li>', |
524
|
|
|
'nodeDecorator' => function ($node) use ($dropDown, $system, $context, $fromPage, $moduleNameAbstract) { |
525
|
|
|
$hasChildrens = count($node['__children']) > 0 ? true : false; |
526
|
|
|
$params = ''; |
527
|
|
|
$class = ''; |
528
|
|
|
|
529
|
|
|
$moduleName = array_key_exists('moduleName', $node) ? $node['moduleName'] : $moduleNameAbstract; |
530
|
|
|
$presenter = array_key_exists('presenter', $node) ? $node['presenter'] : 'Categories'; |
531
|
|
|
$path = $moduleName === $moduleNameAbstract && !$system ? (is_object($fromPage) ? $fromPage->getPath().'/' : '').$node['path'] : $node['path']; |
532
|
|
|
|
533
|
|
|
$link = $context->link(':Frontend:'.$moduleName.':'.$presenter.':default', array('id' => $node['id'], 'path' => $path, 'abbr' => $context->abbr)); |
534
|
|
|
|
535
|
|
|
$span = ''; |
536
|
|
|
if ($hasChildrens && $node['level'] == 1 && $dropDown) { |
537
|
|
|
$params = ' data-toggle="dropdown"'; |
538
|
|
|
$class .= ' dropdown-toggle'; |
539
|
|
|
//$link = '#'; |
540
|
|
|
$span = '<span class="caret"></span>'; |
541
|
|
|
} |
542
|
|
|
|
543
|
|
|
if (!empty($node['class'])) { |
544
|
|
|
$class .= ' '.$node['class']; |
545
|
|
|
} |
546
|
|
|
|
547
|
|
|
return '<a '.$params.' data-seo="'.$path.'" class="'.$class.'" href="'.$link.'"><span>'.$node['title'].$span.'</span></a>'; |
548
|
|
|
}, |
549
|
|
|
)); |
550
|
|
|
} |
551
|
|
|
|
552
|
|
|
public function getBreadcrumbs() |
553
|
|
|
{ |
554
|
|
|
// bredcrumb |
555
|
|
|
$default = $this->em->getRepository('WebCMS\Entity\Page')->findOneBy(array( |
556
|
|
|
'default' => TRUE, |
557
|
|
|
'language' => $this->language, |
558
|
|
|
)); |
559
|
|
|
|
560
|
|
|
if ($this->actualPage->getDefault()) { |
561
|
|
|
$default = array(); |
562
|
|
|
} else { |
563
|
|
|
$default = array($default); |
564
|
|
|
} |
565
|
|
|
|
566
|
|
|
// system breadcrumbs |
567
|
|
|
$system = $default + $this->em->getRepository('WebCMS\Entity\Page')->getPath($this->actualPage); |
568
|
|
|
$finalSystem = array(); |
569
|
|
|
foreach ($system as $item) { |
570
|
|
|
if ($item->getParent()) { |
571
|
|
|
$finalSystem[] = new \WebCMS\Entity\BreadcrumbsItem($item->getId(), $item->getModuleName(), $item->getPresenter(), $item->getTitle(), $item->getPath() |
572
|
|
|
); |
573
|
|
|
} |
574
|
|
|
} |
575
|
|
|
|
576
|
|
|
foreach ($this->breadcrumbs as $b) { |
577
|
|
|
array_push($finalSystem, $b); |
578
|
|
|
} |
579
|
|
|
|
580
|
|
|
return $finalSystem; |
581
|
|
|
} |
582
|
|
|
|
583
|
|
|
/** |
584
|
|
|
* |
585
|
|
|
*/ |
586
|
|
|
public function addToBreadcrumbs($id, $moduleName, $presenter, $title, $path) |
587
|
|
|
{ |
588
|
|
|
$this->breadcrumbs[] = new \WebCMS\Entity\BreadcrumbsItem($id, $moduleName, $presenter, $title, $path); |
589
|
|
|
} |
590
|
|
|
|
591
|
|
|
public function selfRedirect($path = '') |
592
|
|
|
{ |
593
|
|
|
$this->redirect('this', array( |
594
|
|
|
'id' => $this->actualPage->getId(), |
595
|
|
|
'path' => $this->actualPage->getPath().$path, |
596
|
|
|
'abbr' => $this->abbr, |
597
|
|
|
)); |
598
|
|
|
} |
599
|
|
|
|
600
|
|
|
/* @deprecated */ |
601
|
|
|
|
602
|
|
|
public function flashMessageTranslated($message, $type = 'info') |
603
|
|
|
{ |
604
|
|
|
$this->flashMessage($this->translation[$message], $type); |
605
|
|
|
} |
606
|
|
|
|
607
|
|
|
public function flashMessage($text, $type = 'info') |
608
|
|
|
{ |
609
|
|
|
parent::flashMessage($this->translation[$text], $type); |
610
|
|
|
} |
611
|
|
|
|
612
|
|
|
/** |
613
|
|
|
* Formats layout template file names. |
614
|
|
|
* @return array |
615
|
|
|
*/ |
616
|
|
|
public function formatLayoutTemplateFiles() |
617
|
|
|
{ |
618
|
|
|
$name = $this->getName(); |
619
|
|
|
$presenter = substr($name, strrpos(':'.$name, ':')); |
620
|
|
|
$layout = $this->layout ? $this->layout : 'layout'; |
|
|
|
|
621
|
|
|
$dir = dirname($this->getReflection()->getFileName()); |
622
|
|
|
$dir = is_dir("$dir/templates") ? $dir : dirname($dir); |
623
|
|
|
$list = array( |
624
|
|
|
APP_DIR."/templates/@$layout.latte", |
625
|
|
|
"$dir/templates/$presenter/@$layout.latte", |
626
|
|
|
"$dir/templates/$presenter.@$layout.latte", |
627
|
|
|
"$dir/templates/$presenter/@$layout.phtml", |
628
|
|
|
"$dir/templates/$presenter.@$layout.phtml", |
629
|
|
|
); |
630
|
|
View Code Duplication |
do { |
|
|
|
|
631
|
|
|
$list[] = "$dir/templates/@$layout.latte"; |
632
|
|
|
$list[] = "$dir/templates/@$layout.phtml"; |
633
|
|
|
$dir = dirname($dir); |
634
|
|
|
} while ($dir && ($name = substr($name, 0, strrpos($name, ':')))); |
635
|
|
|
|
636
|
|
|
return $list; |
637
|
|
|
} |
638
|
|
|
|
639
|
|
|
/** |
640
|
|
|
* Formats view template file names. |
641
|
|
|
* @return array |
642
|
|
|
*/ |
643
|
|
|
public function formatTemplateFiles() |
644
|
|
|
{ |
645
|
|
|
$name = $this->getName(); |
646
|
|
|
|
647
|
|
|
$path = explode(':', $name); |
648
|
|
|
|
649
|
|
|
if (isset($path[2])) { |
650
|
|
|
$module = $path[1]; |
651
|
|
|
$presenter = $path[2]; |
652
|
|
|
} else { |
653
|
|
|
$module = $path[0]; |
654
|
|
|
$presenter = $path[1]; |
655
|
|
|
} |
656
|
|
|
|
657
|
|
|
$dir = dirname($this->getReflection()->getFileName()); |
658
|
|
|
$dir = is_dir("$dir/templates") ? $dir : dirname($dir); |
659
|
|
|
|
660
|
|
|
$appPath = APP_DIR."/templates/".lcfirst($module)."-module/$presenter/$this->view.latte"; |
|
|
|
|
661
|
|
|
|
662
|
|
|
return array( |
663
|
|
|
$appPath, |
664
|
|
|
"$dir/templates/$presenter/$this->view.latte", |
|
|
|
|
665
|
|
|
"$dir/templates/$presenter.$this->view.latte", |
|
|
|
|
666
|
|
|
"$dir/templates/$presenter/$this->view.phtml", |
|
|
|
|
667
|
|
|
"$dir/templates/$presenter.$this->view.phtml", |
|
|
|
|
668
|
|
|
); |
669
|
|
|
} |
670
|
|
|
} |
671
|
|
|
|
Since your code implements the magic setter
_set
, this function will be called for any write access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.