1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @package Cadmium\System\Frames\Site |
5
|
|
|
* @author Anton Romanov |
6
|
|
|
* @copyright Copyright (c) 2015-2017, Anton Romanov |
7
|
|
|
* @link http://cadmium-cms.com |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Frames\Site { |
11
|
|
|
|
12
|
|
|
use Modules\Auth, Modules\Extend, Modules\Settings, Utils\Menu, Utils\Messages; |
13
|
|
|
use Utils\SEO, Utils\Template\Variables, Utils\Template\Widgets, Language, Template; |
14
|
|
|
|
15
|
|
|
class View extends \Utils\View { |
16
|
|
|
|
17
|
|
|
private $title = '', $layout = ''; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Get a layout block |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
private function getLayout(Template\Block $contents) : Template\Block { |
24
|
|
|
|
25
|
|
|
$layout = View::get('Layouts/' . $this->layout); |
26
|
|
|
|
27
|
|
|
# Set menu |
28
|
|
|
|
29
|
|
|
$layout->menu = (new Menu)->getBlock(); |
|
|
|
|
30
|
|
|
|
31
|
|
|
# Set auth |
32
|
|
|
|
33
|
|
|
if (Auth::isLogged()) { |
34
|
|
|
|
35
|
|
|
$layout->getBlock('user')->enable(); $layout->getBlock('auth')->disable(); |
36
|
|
|
|
37
|
|
|
$layout->getBlock('user')->gravatar = Auth::get('gravatar'); |
|
|
|
|
38
|
|
|
|
39
|
|
|
$layout->getBlock('user')->name = Auth::get('name'); |
|
|
|
|
40
|
|
|
|
41
|
|
|
if (Auth::get('rank') === RANK_ADMINISTRATOR) $layout->getBlock('admin')->enable(); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
# Set title |
45
|
|
|
|
46
|
|
|
$layout->title = (SEO::get('title') ?: Language::get($this->title) ?: Settings::get('site_title')); |
|
|
|
|
47
|
|
|
|
48
|
|
|
# Set contents |
49
|
|
|
|
50
|
|
|
$layout->contents = $contents; |
|
|
|
|
51
|
|
|
|
52
|
|
|
# ------------------------ |
53
|
|
|
|
54
|
|
|
return $layout; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Output the page contents |
59
|
|
|
*/ |
60
|
|
|
|
61
|
|
|
public function display(Template\Block $contents) { |
62
|
|
|
|
63
|
|
|
$page = View::get('Main/Page'); |
64
|
|
|
|
65
|
|
|
# Set language |
66
|
|
|
|
67
|
|
|
$page->language = Extend\Languages::get('iso'); |
|
|
|
|
68
|
|
|
|
69
|
|
|
# Set SEO data |
70
|
|
|
|
71
|
|
|
$page->description = (SEO::get('description') ?: Settings::get('site_description')); |
|
|
|
|
72
|
|
|
|
73
|
|
|
$page->keywords = (SEO::get('keywords') ?: Settings::get('site_keywords')); |
|
|
|
|
74
|
|
|
|
75
|
|
|
$page->robots = SEO::getRobots(); |
|
|
|
|
76
|
|
|
|
77
|
|
|
# Set title |
78
|
|
|
|
79
|
|
|
$title = (SEO::get('title') ?: Language::get($this->title) ?: ''); |
80
|
|
|
|
81
|
|
|
$page->title = ((('' !== $title) ? ($title . ' | ') : '') . Settings::get('site_title')); |
|
|
|
|
82
|
|
|
|
83
|
|
|
# Set canonical |
84
|
|
|
|
85
|
|
|
if (false !== SEO::get('canonical')) $page->getBlock('canonical')->enable()->link = SEO::get('canonical'); |
|
|
|
|
86
|
|
|
|
87
|
|
|
# Set layout |
88
|
|
|
|
89
|
|
|
$page->layout = $this->getLayout($contents->setBlock('messages', Messages::getBlock())); |
|
|
|
|
90
|
|
|
|
91
|
|
|
# Set global components |
92
|
|
|
|
93
|
|
|
foreach (Variables::generate() as $name => $value) Template::setGlobal($name, $value); |
94
|
|
|
|
95
|
|
|
foreach (Widgets::generate() as $name => $block) Template::setWidget($name, $block); |
96
|
|
|
|
97
|
|
|
# ------------------------ |
98
|
|
|
|
99
|
|
|
Template::output($page); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Constructor |
104
|
|
|
*/ |
105
|
|
|
|
106
|
|
|
public function __construct(string $title, string $layout) { |
107
|
|
|
|
108
|
|
|
$this->title = $title; $this->layout = $layout; |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
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.