Passed
Push — master ( e0d6a2...2ec881 )
by Anton
05:25 queued 02:20
created

View::display()   F

Complexity

Conditions 9
Paths 256

Size

Total Lines 40
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 40
rs 3
c 0
b 0
f 0
cc 9
eloc 13
nc 256
nop 1
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)->block();
30
31
			# Set auth
32
33
			if (Auth::check()) {
34
35
				$layout->getBlock('user')->enable(); $layout->getBlock('auth')->disable();
36
37
				$layout->getBlock('user')->gravatar = Auth::user()->gravatar;
38
39
				$layout->getBlock('user')->name = Auth::user()->name;
40
41
				if (Auth::user()->rank === RANK_ADMINISTRATOR) $layout->getBlock('admin')->enable();
42
			}
43
44
			# Set title
45
46
			$layout->title = (SEO::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::data('iso');
68
69
			# Set SEO data
70
71
			$page->description = (SEO::description() ?: Settings::get('site_description'));
72
73
			$page->keywords = (SEO::keywords() ?: Settings::get('site_keywords'));
74
75
			$page->robots = SEO::robots();
76
77
			# Set title
78
79
			$title = (SEO::title() ?: Language::get($this->title) ?: '');
80
81
			$page->title = ((('' !== $title) ? ($title . ' | ') : '') . Settings::get('site_title'));
82
83
			# Set canonical
84
85
			if (false !== SEO::canonical()) $page->getBlock('canonical')->enable()->link = SEO::canonical();
86
87
			# Set layout
88
89
			$page->layout = $this->getLayout($contents->setBlock('messages', Messages::block()));
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