|
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
|
|
|
$this->redirectUrl($this->presenter->getHttpRequest()->url->baseUrl.$this->actualPage->getRedirect()); |
|
243
|
|
|
} |
|
244
|
|
|
} |
|
245
|
|
|
|
|
246
|
|
|
if (!file_exists('sitemap.xml')) { |
|
247
|
|
|
$this->generateSitemap(); |
|
248
|
|
|
} |
|
249
|
|
|
|
|
250
|
|
|
if (is_object($this->actualPage)) { |
|
251
|
|
|
$this->setDefaultSeo(); |
|
252
|
|
|
} |
|
253
|
|
|
|
|
254
|
|
|
// generate sitemap if doesn't exist yet |
|
255
|
|
|
if (!file_exists('sitemap.xml')) { |
|
256
|
|
|
$this->generateSitemap(); |
|
257
|
|
|
} |
|
258
|
|
|
|
|
259
|
|
|
if ($this->isAjax()) { |
|
260
|
|
|
$this->invalidateControl(); |
|
261
|
|
|
|
|
262
|
|
|
$this->payload->title = $this->template->seoTitle; |
|
|
|
|
|
|
263
|
|
|
$this->payload->url = $this->link('this', array( |
|
|
|
|
|
|
264
|
|
|
'path' => $this->actualPage->getPath(), |
|
265
|
|
|
'abbr' => $this->abbr, |
|
266
|
|
|
)); |
|
267
|
|
|
$this->payload->nameSeo = $this->actualPage->getSlug(); |
|
|
|
|
|
|
268
|
|
|
$this->payload->name = $this->actualPage->getTitle(); |
|
|
|
|
|
|
269
|
|
|
$this->payload->class = $this->actualPage->getClass(); |
|
|
|
|
|
|
270
|
|
|
} |
|
271
|
|
|
} |
|
272
|
|
|
|
|
273
|
|
View Code Duplication |
public function generateSitemap() |
|
|
|
|
|
|
274
|
|
|
{ |
|
275
|
|
|
$sitemapXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n"; |
|
276
|
|
|
|
|
277
|
|
|
$repository = $this->em->getRepository('WebCMS\Entity\Page'); |
|
278
|
|
|
$pages = $repository->findAll(); |
|
279
|
|
|
|
|
280
|
|
|
foreach ($pages as $page) { |
|
281
|
|
|
if ($page->getParent() !== null) { |
|
282
|
|
|
$sitemapXml .= "<url>\n\t<loc>".$this->getSitemapLink($page)."</loc>\n</url>\n"; |
|
283
|
|
|
} |
|
284
|
|
|
} |
|
285
|
|
|
|
|
286
|
|
|
$sitemapXml .= '</urlset>'; |
|
287
|
|
|
|
|
288
|
|
|
file_put_contents('./sitemap.xml', $sitemapXml); |
|
289
|
|
|
} |
|
290
|
|
|
|
|
291
|
|
View Code Duplication |
private function getSitemapLink($page) |
|
|
|
|
|
|
292
|
|
|
{ |
|
293
|
|
|
$url = $this->context->httpRequest->url->baseUrl; |
|
|
|
|
|
|
294
|
|
|
$url .= !$page->getLanguage()->getDefaultFrontend() ? $page->getLanguage()->getAbbr().'/' : ''; |
|
295
|
|
|
$url .= $page->getPath(); |
|
296
|
|
|
|
|
297
|
|
|
return $url; |
|
298
|
|
|
} |
|
299
|
|
|
|
|
300
|
|
|
public function createTemplate($class = null) |
|
301
|
|
|
{ |
|
302
|
|
|
$template = parent::createTemplate($class); |
|
303
|
|
|
|
|
304
|
|
|
$template->setTranslator($this->translator); |
|
305
|
|
|
$template->registerHelperLoader('\WebCMS\Helpers\SystemHelper::loader'); |
|
306
|
|
|
|
|
307
|
|
|
return $template; |
|
308
|
|
|
} |
|
309
|
|
|
|
|
310
|
|
|
protected function getLanguageId() |
|
311
|
|
|
{ |
|
312
|
|
|
return $this->language->getId(); |
|
313
|
|
|
} |
|
314
|
|
|
|
|
315
|
|
|
public function createForm($do = '', $action = 'default', $context = null, $parameters = array()) |
|
316
|
|
|
{ |
|
317
|
|
|
$form = new UI\Form(); |
|
318
|
|
|
|
|
319
|
|
|
if ($context != null) { |
|
320
|
|
|
$page = $context->actualPage; |
|
321
|
|
|
$abbr = $context->abbr; |
|
322
|
|
|
$translator = $context->translator; |
|
323
|
|
|
$c = $context; |
|
324
|
|
|
} else { |
|
325
|
|
|
$page = $this->actualPage; |
|
326
|
|
|
$abbr = $this->abbr; |
|
327
|
|
|
$translator = $this->translator; |
|
328
|
|
|
$c = $this; |
|
329
|
|
|
} |
|
330
|
|
|
|
|
331
|
|
|
$form->getElementPrototype()->action = $c->link($action, array( |
|
332
|
|
|
'path' => $page->getPath(), |
|
333
|
|
|
'abbr' => $abbr, |
|
334
|
|
|
'do' => $do, |
|
335
|
|
|
'parameters' => $parameters, |
|
336
|
|
|
)); |
|
337
|
|
|
|
|
338
|
|
|
$form->setTranslator($translator); |
|
339
|
|
|
$form->setRenderer(new BootstrapRenderer()); |
|
340
|
|
|
|
|
341
|
|
|
return $form; |
|
342
|
|
|
} |
|
343
|
|
|
|
|
344
|
|
|
public function createComponentLanguagesForm() |
|
345
|
|
|
{ |
|
346
|
|
|
$form = $this->createForm(); |
|
347
|
|
|
|
|
348
|
|
|
$form->getElementPrototype()->action = $this->link('this', array( |
|
349
|
|
|
'id' => $this->actualPage->getId(), |
|
350
|
|
|
'path' => $this->actualPage->getPath(), |
|
351
|
|
|
'abbr' => $this->abbr, |
|
352
|
|
|
'do' => 'languagesForm-submit', |
|
353
|
|
|
)); |
|
354
|
|
|
|
|
355
|
|
|
$items = array(); |
|
356
|
|
|
foreach ($this->languages as $lang) { |
|
357
|
|
|
$items[$lang->getId()] = $lang->getName(); |
|
358
|
|
|
} |
|
359
|
|
|
|
|
360
|
|
|
$form->addSelect('language', 'Change language')->setItems($items)->setDefaultValue($this->language->getId()); |
|
361
|
|
|
$form->addSubmit('submit', 'Change'); |
|
362
|
|
|
$form->onSuccess[] = callback($this, 'languagesFormSubmitted', array('abbr' => '', 'path' => $this->actualPage->getPath())); |
|
|
|
|
|
|
363
|
|
|
|
|
364
|
|
|
return $form; |
|
365
|
|
|
} |
|
366
|
|
|
|
|
367
|
|
|
public function languagesFormSubmitted($form) |
|
368
|
|
|
{ |
|
369
|
|
|
$values = $form->getValues(); |
|
370
|
|
|
|
|
371
|
|
|
$this->changeLanguage($values->language); |
|
372
|
|
|
} |
|
373
|
|
|
|
|
374
|
|
|
private function changeLanguage($idLanguage) |
|
375
|
|
|
{ |
|
376
|
|
|
$home = $this->em->getRepository('WebCMS\Entity\Page')->findOneBy(array( |
|
377
|
|
|
'language' => $idLanguage, |
|
378
|
|
|
'default' => TRUE, |
|
379
|
|
|
)); |
|
380
|
|
|
|
|
381
|
|
|
if (is_object($home)) { |
|
382
|
|
|
$abbr = $home->getLanguage()->getDefaultFrontend() ? '' : $home->getLanguage()->getAbbr().'/'; |
|
383
|
|
|
|
|
384
|
|
|
$this->redirectUrl( |
|
385
|
|
|
$this->getHttpRequest()->url->baseUrl.$abbr.$home->getPath() |
|
386
|
|
|
); |
|
387
|
|
|
} else { |
|
388
|
|
|
$this->flashMessage('No default page for selected language.', 'error'); |
|
389
|
|
|
} |
|
390
|
|
|
} |
|
391
|
|
|
|
|
392
|
|
|
/** |
|
393
|
|
|
* Set up boxes (call box function and save it into array) and give them to the template. |
|
394
|
|
|
*/ |
|
395
|
|
|
private function setUpBoxes() |
|
396
|
|
|
{ |
|
397
|
|
|
$parameters = $this->context->getParameters(); |
|
|
|
|
|
|
398
|
|
|
$boxes = $parameters['boxes']; |
|
399
|
|
|
|
|
400
|
|
|
$finalBoxes = array(); |
|
401
|
|
|
if (is_array($boxes)) { |
|
402
|
|
|
foreach ($boxes as $key => $box) { |
|
403
|
|
|
$finalBoxes[$key] = null; |
|
404
|
|
|
} |
|
405
|
|
|
} |
|
406
|
|
|
|
|
407
|
|
|
$assocBoxes = $this->em->getRepository('WebCMS\Entity\Box')->findBy(array( |
|
408
|
|
|
'pageTo' => $this->actualPage |
|
409
|
|
|
)); |
|
410
|
|
|
|
|
411
|
|
|
foreach ($assocBoxes as $box) { |
|
412
|
|
|
$presenter = 'FrontendModule\\'.$box->getModuleName().'Module\\'.$box->getPresenter().'Presenter'; |
|
413
|
|
|
$object = new $presenter(); |
|
414
|
|
|
|
|
415
|
|
|
if (method_exists($object, $box->getFunction())) { |
|
416
|
|
|
$function = $box->getFunction(); |
|
417
|
|
|
$pageFrom = $box->getPageFrom(); |
|
418
|
|
|
if ($pageFrom) { |
|
419
|
|
|
$finalBoxes[$box->getBox()] = call_user_func(array($object, $function), $this, $pageFrom); |
|
420
|
|
|
} |
|
421
|
|
|
} |
|
422
|
|
|
} |
|
423
|
|
|
|
|
424
|
|
|
$this->template->boxes = $finalBoxes; |
|
|
|
|
|
|
425
|
|
|
} |
|
426
|
|
|
|
|
427
|
|
|
/** |
|
428
|
|
|
* Load all system structures. |
|
429
|
|
|
* @return type |
|
430
|
|
|
*/ |
|
431
|
|
|
private function getStructures($direct = true, $rootClass = 'nav navbar-nav', $dropDown = false, $rootId = '') |
|
432
|
|
|
{ |
|
433
|
|
|
$repo = $this->em->getRepository('WebCMS\Entity\Page'); |
|
434
|
|
|
|
|
435
|
|
|
$structs = $repo->findBy(array( |
|
436
|
|
|
'language' => $this->language, |
|
437
|
|
|
'parent' => NULL, |
|
438
|
|
|
)); |
|
439
|
|
|
|
|
440
|
|
|
$structures = array(); |
|
441
|
|
|
foreach ($structs as $s) { |
|
442
|
|
|
$structures[$s->getTitle()] = $this->getStructure($this, $s, $repo, $direct, $rootClass, $dropDown, true, null, '', null, $rootId); |
|
|
|
|
|
|
443
|
|
|
} |
|
444
|
|
|
|
|
445
|
|
|
return $structures; |
|
446
|
|
|
} |
|
447
|
|
|
|
|
448
|
|
|
/** |
|
449
|
|
|
* TODO refactor, maybe it will be better in template |
|
450
|
|
|
* Get structure by node. In node is set to null whole tree is returned. |
|
451
|
|
|
* @param type $node |
|
452
|
|
|
* @param Repository $repo |
|
453
|
|
|
* @param type $direct |
|
454
|
|
|
* @param type $rootClass |
|
455
|
|
|
* @param type $dropDown |
|
456
|
|
|
* @param BasePresenter $context |
|
457
|
|
|
* @return type |
|
458
|
|
|
*/ |
|
459
|
|
|
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 = '') |
|
460
|
|
|
{ |
|
461
|
|
|
return $repo->childrenHierarchy($node, $direct, array( |
|
462
|
|
|
'decorate' => true, |
|
463
|
|
|
'html' => true, |
|
464
|
|
|
'rootOpen' => function ($nodes) use ($rootClass, $dropDown, $sideClass, $rootId) { |
|
465
|
|
|
|
|
466
|
|
|
$drop = $nodes[0]['level'] == 2 ? true : false; |
|
467
|
|
|
$class = $nodes[0]['level'] < 2 ? $rootClass : $sideClass; |
|
468
|
|
|
|
|
469
|
|
|
if ($drop && $dropDown) { |
|
470
|
|
|
$class .= ' dropdown-menu submenu'; |
|
471
|
|
|
} |
|
472
|
|
|
|
|
473
|
|
|
$htmlId = ''; |
|
474
|
|
|
if (!empty($rootId)) { |
|
475
|
|
|
$htmlId = ' id = "'.$rootId.'"'; |
|
476
|
|
|
} |
|
477
|
|
|
|
|
478
|
|
|
return '<ul class="'.$class.'"'.$htmlId.'>'; |
|
479
|
|
|
}, |
|
480
|
|
|
'rootClose' => '</ul>', |
|
481
|
|
|
'childOpen' => function ($node) use ($dropDown, $context) { |
|
482
|
|
|
$hasChildrens = count($node['__children']) > 0 ? true : false; |
|
483
|
|
|
$param = $context->getRequest()->getParameters(); |
|
484
|
|
|
$active = $context->getParam('id') == $node['id'] ? true : false; |
|
|
|
|
|
|
485
|
|
|
$class = ''; |
|
486
|
|
|
|
|
487
|
|
|
if (!array_key_exists('fullPath', $param)) { |
|
488
|
|
|
$param['fullPath'] = '/defPath'; |
|
489
|
|
|
} |
|
490
|
|
|
|
|
491
|
|
|
if (array_key_exists('redirect', $node)) { |
|
492
|
|
|
if ($param['fullPath'] == $node['redirect']) { |
|
493
|
|
|
$active = true; |
|
494
|
|
|
} |
|
495
|
|
|
} |
|
496
|
|
|
|
|
497
|
|
|
if ($context->getParam('lft') > $node['lft'] && $context->getParam('lft') < $node['rgt'] && $context->getParam('root') == $node['root']) { |
|
|
|
|
|
|
498
|
|
|
$class .= ' active'; |
|
499
|
|
|
} |
|
500
|
|
|
|
|
501
|
|
|
if ($hasChildrens && $dropDown) { |
|
502
|
|
|
$class .= ' dropdown'; |
|
503
|
|
|
} |
|
504
|
|
|
|
|
505
|
|
|
if ($active) { |
|
506
|
|
|
$class .= ' active'; |
|
507
|
|
|
} |
|
508
|
|
|
|
|
509
|
|
|
if (!$node['visible']) { |
|
510
|
|
|
$class .= ' hidden'; |
|
511
|
|
|
} |
|
512
|
|
|
|
|
513
|
|
|
if ($node['secured']) { |
|
514
|
|
|
$class .= ' secured'; |
|
515
|
|
|
} |
|
516
|
|
|
|
|
517
|
|
|
return '<li class="'.$class.'">'; |
|
518
|
|
|
}, |
|
519
|
|
|
'childClose' => '</li>', |
|
520
|
|
|
'nodeDecorator' => function ($node) use ($dropDown, $system, $context, $fromPage, $moduleNameAbstract) { |
|
521
|
|
|
$hasChildrens = count($node['__children']) > 0 ? true : false; |
|
522
|
|
|
$params = ''; |
|
523
|
|
|
$class = ''; |
|
524
|
|
|
|
|
525
|
|
|
$moduleName = array_key_exists('moduleName', $node) ? $node['moduleName'] : $moduleNameAbstract; |
|
526
|
|
|
$presenter = array_key_exists('presenter', $node) ? $node['presenter'] : 'Categories'; |
|
527
|
|
|
$path = $moduleName === $moduleNameAbstract && !$system ? (is_object($fromPage) ? $fromPage->getPath().'/' : '').$node['path'] : $node['path']; |
|
528
|
|
|
|
|
529
|
|
|
$link = $context->link(':Frontend:'.$moduleName.':'.$presenter.':default', array('id' => $node['id'], 'path' => $path, 'abbr' => $context->abbr)); |
|
530
|
|
|
|
|
531
|
|
|
$span = ''; |
|
532
|
|
|
if ($hasChildrens && $node['level'] == 1 && $dropDown) { |
|
533
|
|
|
$params = ' data-toggle="dropdown"'; |
|
534
|
|
|
$class .= ' dropdown-toggle'; |
|
535
|
|
|
//$link = '#'; |
|
536
|
|
|
$span = '<span class="caret"></span>'; |
|
537
|
|
|
} |
|
538
|
|
|
|
|
539
|
|
|
if (!empty($node['class'])) { |
|
540
|
|
|
$class .= ' '.$node['class']; |
|
541
|
|
|
} |
|
542
|
|
|
|
|
543
|
|
|
return '<a '.$params.' data-seo="'.$path.'" class="'.$class.'" href="'.$link.'"><span>'.$node['title'].$span.'</span></a>'; |
|
544
|
|
|
}, |
|
545
|
|
|
)); |
|
546
|
|
|
} |
|
547
|
|
|
|
|
548
|
|
|
public function getBreadcrumbs() |
|
549
|
|
|
{ |
|
550
|
|
|
// bredcrumb |
|
551
|
|
|
$default = $this->em->getRepository('WebCMS\Entity\Page')->findOneBy(array( |
|
552
|
|
|
'default' => TRUE, |
|
553
|
|
|
'language' => $this->language, |
|
554
|
|
|
)); |
|
555
|
|
|
|
|
556
|
|
|
if ($this->actualPage->getDefault()) { |
|
557
|
|
|
$default = array(); |
|
558
|
|
|
} else { |
|
559
|
|
|
$default = array($default); |
|
560
|
|
|
} |
|
561
|
|
|
|
|
562
|
|
|
// system breadcrumbs |
|
563
|
|
|
$system = $default + $this->em->getRepository('WebCMS\Entity\Page')->getPath($this->actualPage); |
|
564
|
|
|
$finalSystem = array(); |
|
565
|
|
|
foreach ($system as $item) { |
|
566
|
|
|
if ($item->getParent()) { |
|
567
|
|
|
$finalSystem[] = new \WebCMS\Entity\BreadcrumbsItem($item->getId(), $item->getModuleName(), $item->getPresenter(), $item->getTitle(), $item->getPath() |
|
568
|
|
|
); |
|
569
|
|
|
} |
|
570
|
|
|
} |
|
571
|
|
|
|
|
572
|
|
|
foreach ($this->breadcrumbs as $b) { |
|
573
|
|
|
array_push($finalSystem, $b); |
|
574
|
|
|
} |
|
575
|
|
|
|
|
576
|
|
|
return $finalSystem; |
|
577
|
|
|
} |
|
578
|
|
|
|
|
579
|
|
|
/** |
|
580
|
|
|
* |
|
581
|
|
|
*/ |
|
582
|
|
|
public function addToBreadcrumbs($id, $moduleName, $presenter, $title, $path) |
|
583
|
|
|
{ |
|
584
|
|
|
$this->breadcrumbs[] = new \WebCMS\Entity\BreadcrumbsItem($id, $moduleName, $presenter, $title, $path); |
|
585
|
|
|
} |
|
586
|
|
|
|
|
587
|
|
|
public function selfRedirect($path = '') |
|
588
|
|
|
{ |
|
589
|
|
|
$this->redirect('this', array( |
|
590
|
|
|
'id' => $this->actualPage->getId(), |
|
591
|
|
|
'path' => $this->actualPage->getPath().$path, |
|
592
|
|
|
'abbr' => $this->abbr, |
|
593
|
|
|
)); |
|
594
|
|
|
} |
|
595
|
|
|
|
|
596
|
|
|
/* @deprecated */ |
|
597
|
|
|
|
|
598
|
|
|
public function flashMessageTranslated($message, $type = 'info') |
|
599
|
|
|
{ |
|
600
|
|
|
$this->flashMessage($this->translation[$message], $type); |
|
601
|
|
|
} |
|
602
|
|
|
|
|
603
|
|
|
public function flashMessage($text, $type = 'info') |
|
604
|
|
|
{ |
|
605
|
|
|
parent::flashMessage($this->translation[$text], $type); |
|
606
|
|
|
} |
|
607
|
|
|
|
|
608
|
|
|
/** |
|
609
|
|
|
* Formats layout template file names. |
|
610
|
|
|
* @return array |
|
611
|
|
|
*/ |
|
612
|
|
|
public function formatLayoutTemplateFiles() |
|
613
|
|
|
{ |
|
614
|
|
|
$name = $this->getName(); |
|
615
|
|
|
$presenter = substr($name, strrpos(':'.$name, ':')); |
|
616
|
|
|
$layout = $this->layout ? $this->layout : 'layout'; |
|
|
|
|
|
|
617
|
|
|
$dir = dirname($this->getReflection()->getFileName()); |
|
618
|
|
|
$dir = is_dir("$dir/templates") ? $dir : dirname($dir); |
|
619
|
|
|
$list = array( |
|
620
|
|
|
APP_DIR."/templates/@$layout.latte", |
|
621
|
|
|
"$dir/templates/$presenter/@$layout.latte", |
|
622
|
|
|
"$dir/templates/$presenter.@$layout.latte", |
|
623
|
|
|
"$dir/templates/$presenter/@$layout.phtml", |
|
624
|
|
|
"$dir/templates/$presenter.@$layout.phtml", |
|
625
|
|
|
); |
|
626
|
|
View Code Duplication |
do { |
|
|
|
|
|
|
627
|
|
|
$list[] = "$dir/templates/@$layout.latte"; |
|
628
|
|
|
$list[] = "$dir/templates/@$layout.phtml"; |
|
629
|
|
|
$dir = dirname($dir); |
|
630
|
|
|
} while ($dir && ($name = substr($name, 0, strrpos($name, ':')))); |
|
631
|
|
|
|
|
632
|
|
|
return $list; |
|
633
|
|
|
} |
|
634
|
|
|
|
|
635
|
|
|
/** |
|
636
|
|
|
* Formats view template file names. |
|
637
|
|
|
* @return array |
|
638
|
|
|
*/ |
|
639
|
|
|
public function formatTemplateFiles() |
|
640
|
|
|
{ |
|
641
|
|
|
$name = $this->getName(); |
|
642
|
|
|
|
|
643
|
|
|
$path = explode(':', $name); |
|
644
|
|
|
|
|
645
|
|
|
if (isset($path[2])) { |
|
646
|
|
|
$module = $path[1]; |
|
647
|
|
|
$presenter = $path[2]; |
|
648
|
|
|
} else { |
|
649
|
|
|
$module = $path[0]; |
|
650
|
|
|
$presenter = $path[1]; |
|
651
|
|
|
} |
|
652
|
|
|
|
|
653
|
|
|
$dir = dirname($this->getReflection()->getFileName()); |
|
654
|
|
|
$dir = is_dir("$dir/templates") ? $dir : dirname($dir); |
|
655
|
|
|
|
|
656
|
|
|
$appPath = APP_DIR."/templates/".lcfirst($module)."-module/$presenter/$this->view.latte"; |
|
|
|
|
|
|
657
|
|
|
|
|
658
|
|
|
return array( |
|
659
|
|
|
$appPath, |
|
660
|
|
|
"$dir/templates/$presenter/$this->view.latte", |
|
|
|
|
|
|
661
|
|
|
"$dir/templates/$presenter.$this->view.latte", |
|
|
|
|
|
|
662
|
|
|
"$dir/templates/$presenter/$this->view.phtml", |
|
|
|
|
|
|
663
|
|
|
"$dir/templates/$presenter.$this->view.phtml", |
|
|
|
|
|
|
664
|
|
|
); |
|
665
|
|
|
} |
|
666
|
|
|
} |
|
667
|
|
|
|
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@propertyannotation 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.