Completed
Push — master ( d13b22...a2d243 )
by Justin
05:45
created
system/packages/com.jukusoft.cms.page/classes/pagetype.php 2 patches
Indentation   +327 added lines, -327 removed lines patch added patch discarded remove patch
@@ -18,337 +18,337 @@
 block discarded – undo
18 18
 
19 19
 class PageType {
20 20
 
21
-	protected $page = null;
22
-
23
-	public function __construct() {
24
-		//
25
-	}
26
-
27
-	public function setPage (Page &$page) {
28
-		$this->page = $page;
29
-	}
30
-
31
-	protected function getPage () : Page {
32
-		return $this->page;
33
-	}
34
-
35
-	public function showDesign () {
36
-		return true;
37
-	}
38
-
39
-	public function getContentType () : string {
40
-		return "" . $this->page->getContentType() . "; charset=" . $this->getCharset();
41
-	}
42
-
43
-	public function getCharset () : string {
44
-		return "utf-8";
45
-	}
46
-
47
-	public function setCustomHeader () {
48
-		//
49
-	}
50
-
51
-	public function getAdditionalHeaderCode () : string {
52
-		return "";
53
-	}
54
-
55
-	public function showFooter () : bool {
56
-		return true;
57
-	}
58
-
59
-	public function getFooterScripts () : string {
60
-		return "";
61
-	}
62
-
63
-	public function showHTMLComments () : bool {
64
-		return true;
65
-	}
66
-
67
-	public function getOgTitle () : string {
68
-		return $this->page->getOgTitle();
69
-	}
70
-
71
-	public function getOgDescription () : string {
72
-		return $this->page->getOgDescription();
73
-	}
74
-
75
-	public function getOgType () : string {
76
-		return $this->page->getOgType();
77
-	}
78
-
79
-	public function getOgImages () : array {
80
-		return $this->page->getOgImages();
81
-	}
82
-
83
-	public function getOgUrl () : string {
84
-		return DomainUtils::generateURL($this->page->getAlias());
85
-	}
86
-
87
-	public function getOgTags () : string {
88
-		$tags = array();
89
-		$tags['og:type'] = $this->getOgType();
90
-		$tags['og:url'] = $this->getOgUrl();
91
-		$tags['og:title'] = $this->getOgTitle();
92
-		$tags['og:description'] = $this->getOgDescription();
93
-
94
-		if (!empty($this->getOgImages())) {
95
-			$tags['og:image'] = $this->getOgImages();
96
-		}
97
-
98
-		$this->getAdditionalTags($tags);
99
-
100
-		Events::throwEvent("og_tags", array(
101
-			'page' => &$this->page,
102
-			'page_type' => &$this,
103
-			'tags' => &$tags
104
-		));
105
-
106
-		$tags_lines = "<!-- OpenGraph tags -->\r\n";
107
-
108
-		foreach ($tags as $property=>$content) {
109
-			if (is_array($content)) {
110
-				foreach ($content as $value) {
111
-					$tags_lines .= "\t<meta property=\"" . $property . "\" content=\"" . $value . "\" />\r\n";
112
-				}
113
-			} else {
114
-				$tags_lines .= "\t<meta property=\"" . $property . "\" content=\"" . $content . "\" />\r\n";
115
-			}
116
-		}
117
-
118
-		return $tags_lines;
119
-	}
120
-
121
-	/**
122
-	 * add additional tags
123
-	 *
124
-	 * This method was added so that page types doesn't have to override getOgTags() completely
125
-	 */
126
-	protected function getAdditionalTags (array &$tags) {
127
-		//add additional tags
128
-	}
129
-
130
-	public function getContent () : string {
131
-		$content = $this->getPage()->getContent();
132
-
133
-		//check, if page has custom template
134
-		if ($this->getPage()->hasCustomTemplate()) {
135
-			//get custom template
136
-			$template = Validator_String::get($this->getPage()->getCustomTemplate());
137
-
138
-			$current_style = Registry::singleton()->getSetting("current_style_name");
139
-
140
-			//check, if custom template exists
141
-			if (file_exists(STYLE_PATH . $current_style . "/" . $template)) {
142
-				$template = new Template($template);
143
-
144
-				$template->assign("TITLE", $this->getPage()->getTitle());
145
-				$template->assign("CONTENT", $content);
146
-
147
-				$template->parse("main");
148
-				$content = $template->getCode();
149
-			} else {
150
-				throw new IllegalStateException("Custom template '" . $template . "' doesnt exists.");
151
-			}
152
-		}
153
-
154
-		Events::throwEvent("get_content", array(
155
-			'content' => &$content,
156
-			'page' => &$this->page,
157
-			'page_type' => &$this
158
-		));
159
-
160
-		return $content;
161
-	}
162
-
163
-	public function generateNormalPage (string $content, $vars = array()) : string {
164
-		$current_style = Registry::singleton()->getSetting("current_style_name");
165
-
166
-		if (file_exists(STYLE_PATH . $current_style . "/pages/normal.tpl")) {
167
-			$template = new DwooTemplate(STYLE_PATH . $current_style . "/pages/normal.tpl");
168
-
169
-			$title_preafix = Settings::get("title_praefix", "");
170
-			$title_suffix = Settings::get("title_suffix", "");
171
-
172
-			//translate title
173
-			$title = Translator::translateTitle($this->getPage()->getTitle());
174
-
175
-			$template->assign("RAW_TITLE", $title);
176
-			$template->assign("TITLE", $title_preafix . $title . $title_suffix);
177
-			$template->assign("CONTENT", $content);
178
-			$template->assign("FOOTER", Registry::singleton()->getSetting("footer", ""));
179
-
180
-			Events::throwEvent("generate_normal_page", array(
181
-				'template' => &$template,
182
-				'current_style' => $current_style,
183
-				'content' => &$content,
184
-				'page_type' => &$this,
185
-				'page' => $this->getPage()
186
-			));
187
-
188
-			foreach ($vars as $key=>$value) {
189
-				$template->assign($key, $value);
190
-			}
191
-
192
-			return $template->getCode();
193
-		} else {
194
-			throw new IllegalStateException("no normal template (pages/normal.tpl) found!");
195
-			//return $content;
196
-		}
197
-	}
198
-
199
-	public function checkPermissions (PermissionChecker $permission_checker) {
200
-		//first, check required permissions
201
-		if (count($this->listRequiredPermissions()) > 0) {
202
-			$bool = false;
203
-
204
-			foreach ($this->listRequiredPermissions() as $permission) {
205
-				if ($permission_checker->hasRight($permission)) {
206
-					$bool = true;
207
-					break;
208
-				}
209
-			}
210
-
211
-			if (!$bool) {
212
-				return false;
213
-			}
214
-		}
215
-
216
-		if (!$this->getPage()->hasCustomPermissions()) {
217
-			return true;
218
-		} else {
219
-			$permissions = $this->getPage()->listCustomPermissions();
220
-
221
-			foreach ($permissions as $permission) {
222
-				if ($permission_checker->hasRight($permission)) {
223
-					return true;
224
-				}
225
-			}
226
-
227
-			return false;
228
-		}
229
-	}
230
-
231
-	protected function listRequiredPermissions () : array {
232
-		return array();
233
-	}
234
-
235
-	public function exitAfterOutput () {
236
-		return false;
237
-	}
238
-
239
-	public static function reloadCache () {
240
-		Cache::clear("pagetypes");
241
-	}
242
-
243
-	public static function listPageTypes (bool $advanced = false) : array {
244
-		$rows = array();
245
-
246
-		$advanced_str = $advanced ? "advanced" : "normal";
247
-
248
-		if (Cache::contains("pagetypes", "list-" . $advanced_str)) {
249
-			$rows = Cache::get("pagetypes", "list-" . $advanced_str);
250
-		} else {
251
-			if ($advanced) {
252
-				//show all page types
253
-				$rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}page_types` WHERE `activated` = '1' ORDER BY `order`; ");
254
-			} else {
255
-				//show only not-expert page types
256
-				$rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}page_types` WHERE `advanced` = '0' AND `activated` = '1' ORDER BY `order`; ");
257
-			}
258
-
259
-			//put into cache
260
-			Cache::put("pagetypes", "list-" . $advanced_str, $rows);
261
-		}
262
-
263
-		return $rows;
264
-	}
265
-
266
-	public static function createPageType (string $class_name, string $title, bool $advanced = false, int $order = 10, array $permissions = array("none"), string $owner = "system") {
267
-		//validate values
268
-		$class_name = Validator_String::get($class_name);
269
-		$title = Validator_String::get($title);
270
-		$order = Validator_Int::get($order);
271
-
272
-		Events::throwEvent("before_add_pagetype", array(
273
-			'class_name' => &$class_name,
274
-			'title' => &$title,
275
-			'create_permissions' => &$permissions,
276
-			'advanced' => &$advanced,
277
-			'owner' => &$owner,
278
-			'order' => &$order
279
-		));
280
-
281
-		//validate and convert array to string
282
-		$permissions = implode("|", $permissions);
283
-		$permissions = Validator_String::get($permissions);
284
-
285
-		Database::getInstance()->execute("INSERT INTO `{praefix}page_types` (
21
+    protected $page = null;
22
+
23
+    public function __construct() {
24
+        //
25
+    }
26
+
27
+    public function setPage (Page &$page) {
28
+        $this->page = $page;
29
+    }
30
+
31
+    protected function getPage () : Page {
32
+        return $this->page;
33
+    }
34
+
35
+    public function showDesign () {
36
+        return true;
37
+    }
38
+
39
+    public function getContentType () : string {
40
+        return "" . $this->page->getContentType() . "; charset=" . $this->getCharset();
41
+    }
42
+
43
+    public function getCharset () : string {
44
+        return "utf-8";
45
+    }
46
+
47
+    public function setCustomHeader () {
48
+        //
49
+    }
50
+
51
+    public function getAdditionalHeaderCode () : string {
52
+        return "";
53
+    }
54
+
55
+    public function showFooter () : bool {
56
+        return true;
57
+    }
58
+
59
+    public function getFooterScripts () : string {
60
+        return "";
61
+    }
62
+
63
+    public function showHTMLComments () : bool {
64
+        return true;
65
+    }
66
+
67
+    public function getOgTitle () : string {
68
+        return $this->page->getOgTitle();
69
+    }
70
+
71
+    public function getOgDescription () : string {
72
+        return $this->page->getOgDescription();
73
+    }
74
+
75
+    public function getOgType () : string {
76
+        return $this->page->getOgType();
77
+    }
78
+
79
+    public function getOgImages () : array {
80
+        return $this->page->getOgImages();
81
+    }
82
+
83
+    public function getOgUrl () : string {
84
+        return DomainUtils::generateURL($this->page->getAlias());
85
+    }
86
+
87
+    public function getOgTags () : string {
88
+        $tags = array();
89
+        $tags['og:type'] = $this->getOgType();
90
+        $tags['og:url'] = $this->getOgUrl();
91
+        $tags['og:title'] = $this->getOgTitle();
92
+        $tags['og:description'] = $this->getOgDescription();
93
+
94
+        if (!empty($this->getOgImages())) {
95
+            $tags['og:image'] = $this->getOgImages();
96
+        }
97
+
98
+        $this->getAdditionalTags($tags);
99
+
100
+        Events::throwEvent("og_tags", array(
101
+            'page' => &$this->page,
102
+            'page_type' => &$this,
103
+            'tags' => &$tags
104
+        ));
105
+
106
+        $tags_lines = "<!-- OpenGraph tags -->\r\n";
107
+
108
+        foreach ($tags as $property=>$content) {
109
+            if (is_array($content)) {
110
+                foreach ($content as $value) {
111
+                    $tags_lines .= "\t<meta property=\"" . $property . "\" content=\"" . $value . "\" />\r\n";
112
+                }
113
+            } else {
114
+                $tags_lines .= "\t<meta property=\"" . $property . "\" content=\"" . $content . "\" />\r\n";
115
+            }
116
+        }
117
+
118
+        return $tags_lines;
119
+    }
120
+
121
+    /**
122
+     * add additional tags
123
+     *
124
+     * This method was added so that page types doesn't have to override getOgTags() completely
125
+     */
126
+    protected function getAdditionalTags (array &$tags) {
127
+        //add additional tags
128
+    }
129
+
130
+    public function getContent () : string {
131
+        $content = $this->getPage()->getContent();
132
+
133
+        //check, if page has custom template
134
+        if ($this->getPage()->hasCustomTemplate()) {
135
+            //get custom template
136
+            $template = Validator_String::get($this->getPage()->getCustomTemplate());
137
+
138
+            $current_style = Registry::singleton()->getSetting("current_style_name");
139
+
140
+            //check, if custom template exists
141
+            if (file_exists(STYLE_PATH . $current_style . "/" . $template)) {
142
+                $template = new Template($template);
143
+
144
+                $template->assign("TITLE", $this->getPage()->getTitle());
145
+                $template->assign("CONTENT", $content);
146
+
147
+                $template->parse("main");
148
+                $content = $template->getCode();
149
+            } else {
150
+                throw new IllegalStateException("Custom template '" . $template . "' doesnt exists.");
151
+            }
152
+        }
153
+
154
+        Events::throwEvent("get_content", array(
155
+            'content' => &$content,
156
+            'page' => &$this->page,
157
+            'page_type' => &$this
158
+        ));
159
+
160
+        return $content;
161
+    }
162
+
163
+    public function generateNormalPage (string $content, $vars = array()) : string {
164
+        $current_style = Registry::singleton()->getSetting("current_style_name");
165
+
166
+        if (file_exists(STYLE_PATH . $current_style . "/pages/normal.tpl")) {
167
+            $template = new DwooTemplate(STYLE_PATH . $current_style . "/pages/normal.tpl");
168
+
169
+            $title_preafix = Settings::get("title_praefix", "");
170
+            $title_suffix = Settings::get("title_suffix", "");
171
+
172
+            //translate title
173
+            $title = Translator::translateTitle($this->getPage()->getTitle());
174
+
175
+            $template->assign("RAW_TITLE", $title);
176
+            $template->assign("TITLE", $title_preafix . $title . $title_suffix);
177
+            $template->assign("CONTENT", $content);
178
+            $template->assign("FOOTER", Registry::singleton()->getSetting("footer", ""));
179
+
180
+            Events::throwEvent("generate_normal_page", array(
181
+                'template' => &$template,
182
+                'current_style' => $current_style,
183
+                'content' => &$content,
184
+                'page_type' => &$this,
185
+                'page' => $this->getPage()
186
+            ));
187
+
188
+            foreach ($vars as $key=>$value) {
189
+                $template->assign($key, $value);
190
+            }
191
+
192
+            return $template->getCode();
193
+        } else {
194
+            throw new IllegalStateException("no normal template (pages/normal.tpl) found!");
195
+            //return $content;
196
+        }
197
+    }
198
+
199
+    public function checkPermissions (PermissionChecker $permission_checker) {
200
+        //first, check required permissions
201
+        if (count($this->listRequiredPermissions()) > 0) {
202
+            $bool = false;
203
+
204
+            foreach ($this->listRequiredPermissions() as $permission) {
205
+                if ($permission_checker->hasRight($permission)) {
206
+                    $bool = true;
207
+                    break;
208
+                }
209
+            }
210
+
211
+            if (!$bool) {
212
+                return false;
213
+            }
214
+        }
215
+
216
+        if (!$this->getPage()->hasCustomPermissions()) {
217
+            return true;
218
+        } else {
219
+            $permissions = $this->getPage()->listCustomPermissions();
220
+
221
+            foreach ($permissions as $permission) {
222
+                if ($permission_checker->hasRight($permission)) {
223
+                    return true;
224
+                }
225
+            }
226
+
227
+            return false;
228
+        }
229
+    }
230
+
231
+    protected function listRequiredPermissions () : array {
232
+        return array();
233
+    }
234
+
235
+    public function exitAfterOutput () {
236
+        return false;
237
+    }
238
+
239
+    public static function reloadCache () {
240
+        Cache::clear("pagetypes");
241
+    }
242
+
243
+    public static function listPageTypes (bool $advanced = false) : array {
244
+        $rows = array();
245
+
246
+        $advanced_str = $advanced ? "advanced" : "normal";
247
+
248
+        if (Cache::contains("pagetypes", "list-" . $advanced_str)) {
249
+            $rows = Cache::get("pagetypes", "list-" . $advanced_str);
250
+        } else {
251
+            if ($advanced) {
252
+                //show all page types
253
+                $rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}page_types` WHERE `activated` = '1' ORDER BY `order`; ");
254
+            } else {
255
+                //show only not-expert page types
256
+                $rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}page_types` WHERE `advanced` = '0' AND `activated` = '1' ORDER BY `order`; ");
257
+            }
258
+
259
+            //put into cache
260
+            Cache::put("pagetypes", "list-" . $advanced_str, $rows);
261
+        }
262
+
263
+        return $rows;
264
+    }
265
+
266
+    public static function createPageType (string $class_name, string $title, bool $advanced = false, int $order = 10, array $permissions = array("none"), string $owner = "system") {
267
+        //validate values
268
+        $class_name = Validator_String::get($class_name);
269
+        $title = Validator_String::get($title);
270
+        $order = Validator_Int::get($order);
271
+
272
+        Events::throwEvent("before_add_pagetype", array(
273
+            'class_name' => &$class_name,
274
+            'title' => &$title,
275
+            'create_permissions' => &$permissions,
276
+            'advanced' => &$advanced,
277
+            'owner' => &$owner,
278
+            'order' => &$order
279
+        ));
280
+
281
+        //validate and convert array to string
282
+        $permissions = implode("|", $permissions);
283
+        $permissions = Validator_String::get($permissions);
284
+
285
+        Database::getInstance()->execute("INSERT INTO `{praefix}page_types` (
286 286
 			`page_type`, `title`, `create_permissions`, `advanced`, `owner`, `order`, `activated`
287 287
 		) VALUES (
288 288
 			:pagetype, :title, :permissions, :advanced, :owner, :order, '1'
289 289
 		) ON DUPLICATE KEY UPDATE `title` = :title, `create_permissions` = :permissions, `advanced` = :advanced, `owner` = :owner, `order` = :order, `activated` = '1'; ", array(
290
-			'pagetype' => $class_name,
291
-			'title' => $title,
292
-			'permissions' => $permissions,
293
-			'advanced' => ($advanced ? 1 : 0),
294
-			'owner' => $owner,
295
-			'order' => $order
296
-		));
297
-
298
-		Events::throwEvent("after_add_pagetype", array(
299
-			'class_name' => $class_name,
300
-			'title' => $title,
301
-			'create_permissions' => $permissions,
302
-			'advanced' => $advanced,
303
-			'owner' => $owner,
304
-			'order' => $order
305
-		));
306
-
307
-		//clear cache
308
-		Cache::clear("pagetypes");
309
-	}
310
-
311
-	public static function removePageType (string $class_name) {
312
-		//validate value
313
-		$class_name = Validator_String::get($class_name);
314
-
315
-		$delete = true;
316
-
317
-		//throw event, so plugins can interact
318
-		Events::throwEvent("before_remove_pagetype", array(
319
-			'class_name' => &$class_name,
320
-			'delete' => &$delete
321
-		));
322
-
323
-		if ($delete) {
324
-			Database::getInstance()->execute("DELETE FROM `{praefix}page_types` WHERE `page_type` = :pagetype; ", array('pagetype' => $class_name));
325
-
326
-			//throw event, so plugins can interact
327
-			Events::throwEvent("after_remove_pagetype", array(
328
-				'class_name' => $class_name
329
-			));
330
-
331
-			//clear cache
332
-			Cache::clear("pagetypes");
333
-		}
334
-	}
335
-
336
-	public static function removePageTypesByOwner (string $owner) {
337
-		Database::getInstance()->execute("DELETE FROM `{praefix}page_types` WHERE `owner` = :owner; ", array('owner' => $owner));
338
-
339
-		//TODO: change all pages which have this page type
340
-
341
-		//clear cache
342
-		Cache::clear("pagetypes");
343
-	}
344
-
345
-	public static function exists (string $class_name) : bool {
346
-		$row = Database::getInstance()->getRow("SELECT * FROM `{praefix}page_types` WHERE `page_type` = :pagetype; ", array(
347
-			'pagetype' => $class_name
348
-		));
349
-
350
-		return $row !== false;
351
-	}
290
+            'pagetype' => $class_name,
291
+            'title' => $title,
292
+            'permissions' => $permissions,
293
+            'advanced' => ($advanced ? 1 : 0),
294
+            'owner' => $owner,
295
+            'order' => $order
296
+        ));
297
+
298
+        Events::throwEvent("after_add_pagetype", array(
299
+            'class_name' => $class_name,
300
+            'title' => $title,
301
+            'create_permissions' => $permissions,
302
+            'advanced' => $advanced,
303
+            'owner' => $owner,
304
+            'order' => $order
305
+        ));
306
+
307
+        //clear cache
308
+        Cache::clear("pagetypes");
309
+    }
310
+
311
+    public static function removePageType (string $class_name) {
312
+        //validate value
313
+        $class_name = Validator_String::get($class_name);
314
+
315
+        $delete = true;
316
+
317
+        //throw event, so plugins can interact
318
+        Events::throwEvent("before_remove_pagetype", array(
319
+            'class_name' => &$class_name,
320
+            'delete' => &$delete
321
+        ));
322
+
323
+        if ($delete) {
324
+            Database::getInstance()->execute("DELETE FROM `{praefix}page_types` WHERE `page_type` = :pagetype; ", array('pagetype' => $class_name));
325
+
326
+            //throw event, so plugins can interact
327
+            Events::throwEvent("after_remove_pagetype", array(
328
+                'class_name' => $class_name
329
+            ));
330
+
331
+            //clear cache
332
+            Cache::clear("pagetypes");
333
+        }
334
+    }
335
+
336
+    public static function removePageTypesByOwner (string $owner) {
337
+        Database::getInstance()->execute("DELETE FROM `{praefix}page_types` WHERE `owner` = :owner; ", array('owner' => $owner));
338
+
339
+        //TODO: change all pages which have this page type
340
+
341
+        //clear cache
342
+        Cache::clear("pagetypes");
343
+    }
344
+
345
+    public static function exists (string $class_name) : bool {
346
+        $row = Database::getInstance()->getRow("SELECT * FROM `{praefix}page_types` WHERE `page_type` = :pagetype; ", array(
347
+            'pagetype' => $class_name
348
+        ));
349
+
350
+        return $row !== false;
351
+    }
352 352
 
353 353
 }
354 354
 
Please login to merge, or discard this patch.
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -24,67 +24,67 @@  discard block
 block discarded – undo
24 24
 		//
25 25
 	}
26 26
 
27
-	public function setPage (Page &$page) {
27
+	public function setPage(Page &$page) {
28 28
 		$this->page = $page;
29 29
 	}
30 30
 
31
-	protected function getPage () : Page {
31
+	protected function getPage() : Page {
32 32
 		return $this->page;
33 33
 	}
34 34
 
35
-	public function showDesign () {
35
+	public function showDesign() {
36 36
 		return true;
37 37
 	}
38 38
 
39
-	public function getContentType () : string {
39
+	public function getContentType() : string {
40 40
 		return "" . $this->page->getContentType() . "; charset=" . $this->getCharset();
41 41
 	}
42 42
 
43
-	public function getCharset () : string {
43
+	public function getCharset() : string {
44 44
 		return "utf-8";
45 45
 	}
46 46
 
47
-	public function setCustomHeader () {
47
+	public function setCustomHeader() {
48 48
 		//
49 49
 	}
50 50
 
51
-	public function getAdditionalHeaderCode () : string {
51
+	public function getAdditionalHeaderCode() : string {
52 52
 		return "";
53 53
 	}
54 54
 
55
-	public function showFooter () : bool {
55
+	public function showFooter() : bool {
56 56
 		return true;
57 57
 	}
58 58
 
59
-	public function getFooterScripts () : string {
59
+	public function getFooterScripts() : string {
60 60
 		return "";
61 61
 	}
62 62
 
63
-	public function showHTMLComments () : bool {
63
+	public function showHTMLComments() : bool {
64 64
 		return true;
65 65
 	}
66 66
 
67
-	public function getOgTitle () : string {
67
+	public function getOgTitle() : string {
68 68
 		return $this->page->getOgTitle();
69 69
 	}
70 70
 
71
-	public function getOgDescription () : string {
71
+	public function getOgDescription() : string {
72 72
 		return $this->page->getOgDescription();
73 73
 	}
74 74
 
75
-	public function getOgType () : string {
75
+	public function getOgType() : string {
76 76
 		return $this->page->getOgType();
77 77
 	}
78 78
 
79
-	public function getOgImages () : array {
79
+	public function getOgImages() : array {
80 80
 		return $this->page->getOgImages();
81 81
 	}
82 82
 
83
-	public function getOgUrl () : string {
83
+	public function getOgUrl() : string {
84 84
 		return DomainUtils::generateURL($this->page->getAlias());
85 85
 	}
86 86
 
87
-	public function getOgTags () : string {
87
+	public function getOgTags() : string {
88 88
 		$tags = array();
89 89
 		$tags['og:type'] = $this->getOgType();
90 90
 		$tags['og:url'] = $this->getOgUrl();
@@ -123,11 +123,11 @@  discard block
 block discarded – undo
123 123
 	 *
124 124
 	 * This method was added so that page types doesn't have to override getOgTags() completely
125 125
 	 */
126
-	protected function getAdditionalTags (array &$tags) {
126
+	protected function getAdditionalTags(array &$tags) {
127 127
 		//add additional tags
128 128
 	}
129 129
 
130
-	public function getContent () : string {
130
+	public function getContent() : string {
131 131
 		$content = $this->getPage()->getContent();
132 132
 
133 133
 		//check, if page has custom template
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 		return $content;
161 161
 	}
162 162
 
163
-	public function generateNormalPage (string $content, $vars = array()) : string {
163
+	public function generateNormalPage(string $content, $vars = array()) : string {
164 164
 		$current_style = Registry::singleton()->getSetting("current_style_name");
165 165
 
166 166
 		if (file_exists(STYLE_PATH . $current_style . "/pages/normal.tpl")) {
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
 		}
197 197
 	}
198 198
 
199
-	public function checkPermissions (PermissionChecker $permission_checker) {
199
+	public function checkPermissions(PermissionChecker $permission_checker) {
200 200
 		//first, check required permissions
201 201
 		if (count($this->listRequiredPermissions()) > 0) {
202 202
 			$bool = false;
@@ -228,19 +228,19 @@  discard block
 block discarded – undo
228 228
 		}
229 229
 	}
230 230
 
231
-	protected function listRequiredPermissions () : array {
231
+	protected function listRequiredPermissions() : array {
232 232
 		return array();
233 233
 	}
234 234
 
235
-	public function exitAfterOutput () {
235
+	public function exitAfterOutput() {
236 236
 		return false;
237 237
 	}
238 238
 
239
-	public static function reloadCache () {
239
+	public static function reloadCache() {
240 240
 		Cache::clear("pagetypes");
241 241
 	}
242 242
 
243
-	public static function listPageTypes (bool $advanced = false) : array {
243
+	public static function listPageTypes(bool $advanced = false) : array {
244 244
 		$rows = array();
245 245
 
246 246
 		$advanced_str = $advanced ? "advanced" : "normal";
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
 		return $rows;
264 264
 	}
265 265
 
266
-	public static function createPageType (string $class_name, string $title, bool $advanced = false, int $order = 10, array $permissions = array("none"), string $owner = "system") {
266
+	public static function createPageType(string $class_name, string $title, bool $advanced = false, int $order = 10, array $permissions = array("none"), string $owner = "system") {
267 267
 		//validate values
268 268
 		$class_name = Validator_String::get($class_name);
269 269
 		$title = Validator_String::get($title);
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
 		Cache::clear("pagetypes");
309 309
 	}
310 310
 
311
-	public static function removePageType (string $class_name) {
311
+	public static function removePageType(string $class_name) {
312 312
 		//validate value
313 313
 		$class_name = Validator_String::get($class_name);
314 314
 
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
 		}
334 334
 	}
335 335
 
336
-	public static function removePageTypesByOwner (string $owner) {
336
+	public static function removePageTypesByOwner(string $owner) {
337 337
 		Database::getInstance()->execute("DELETE FROM `{praefix}page_types` WHERE `owner` = :owner; ", array('owner' => $owner));
338 338
 
339 339
 		//TODO: change all pages which have this page type
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
 		Cache::clear("pagetypes");
343 343
 	}
344 344
 
345
-	public static function exists (string $class_name) : bool {
345
+	public static function exists(string $class_name) : bool {
346 346
 		$row = Database::getInstance()->getRow("SELECT * FROM `{praefix}page_types` WHERE `page_type` = :pagetype; ", array(
347 347
 			'pagetype' => $class_name
348 348
 		));
Please login to merge, or discard this patch.
system/packages/com.jukusoft.cms.admin/classes/pagelistpage.php 1 patch
Indentation   +166 added lines, -166 removed lines patch added patch discarded remove patch
@@ -27,168 +27,168 @@  discard block
 block discarded – undo
27 27
 
28 28
 class PageListPage extends PageType {
29 29
 
30
-	public function getContent(): string {
31
-		$template = new DwooTemplate("pages/pagelist");
32
-
33
-		$template->assign("no_edit_permissions", (boolean) (!PermissionChecker::current()->hasRight("an_edit_all_pages") && !PermissionChecker::current()->hasRight("can_edit_own_pages")));
34
-
35
-		//set table columns
36
-		$template->assign("columns", array(
37
-			Translator::translate("ID"),
38
-			Translator::translate("Alias"),
39
-			Translator::translate("Title"),
40
-			Translator::translate("Author"),
41
-			Translator::translate("State"),
42
-			Translator::translate("Actions")
43
-		));
44
-
45
-		//get permissions
46
-		$current_userID = User::current()->getID();
47
-		$permission_can_edit_all_pages = PermissionChecker::current()->hasRight("can_edit_all_pages");
48
-		$permission_can_edit_own_pages = PermissionChecker::current()->hasRight("can_edit_own_pages");
49
-		$permission_can_unlock_all_pages = PermissionChecker::current()->hasRight("can_unlock_all_pages");
50
-		$permission_can_delete_own_pages = PermissionChecker::current()->hasRight("can_delete_own_pages");
51
-		$permission_can_delete_all_pages = PermissionChecker::current()->hasRight("can_delete_all_pages");
52
-		$permission_can_see_trash_pages = PermissionChecker::current()->hasRight("can_see_trash_pages");
53
-		$permission_can_restore_trash_pages = PermissionChecker::current()->hasRight("can_restore_trash_pages");
54
-		$permission_can_delete_all_pages_permanently = PermissionChecker::current()->hasRight("can_delete_all_pages_permanently");
55
-
56
-		$success_messages = array();
57
-
58
-		//unlock pages
59
-		if (isset($_REQUEST['unlock']) && $permission_can_unlock_all_pages) {
60
-			$pageID = (int) $_REQUEST['unlock'];
61
-			Page::unlockPage($pageID);
62
-
63
-			$success_messages[] = "Unlocked page successfully!";
64
-		}
65
-
66
-		//move pages to trash
67
-		if (isset($_REQUEST['trash']) && is_numeric($_REQUEST['trash']) && ($permission_can_delete_own_pages || $permission_can_delete_all_pages)) {
68
-			//move page to trash
69
-			$pageID = (int) $_REQUEST['trash'];
70
-
71
-			//load page
72
-			$page = new Page();
73
-			$page->loadByID($pageID);
74
-
75
-			//check permisssion
76
-			if ($permission_can_delete_all_pages || ($permission_can_delete_own_pages && $page->getAuthorID() == User::current()->getID())) {
77
-				//check, if page is deletable
78
-				if ($page->isDeletable()) {
79
-					//move page to trash
80
-					$page->moveToTrash();
81
-
82
-					$success_messages[] = "Moved page '" . $page->getAlias() . "' to trash.";
83
-				}
84
-			}
85
-		}
86
-
87
-		//restore pages from trash
88
-		if (isset($_REQUEST['restore']) && is_numeric($_REQUEST['restore']) && $permission_can_restore_trash_pages) {
89
-			//restore page
90
-			$pageID = (int) $_REQUEST['restore'];
91
-
92
-			//load page
93
-			$page = new Page();
94
-			$page->loadByID($pageID);
95
-
96
-			if ($page->isTrash()) {
97
-				$page->restore();
98
-
99
-				$success_messages[] = "Restored page '" . $page->getAlias() . "' successfully!";
100
-			}
101
-		}
102
-
103
-		//delete pages from trash
104
-		if (isset($_REQUEST['delete_permanently']) && is_numeric($_REQUEST['delete_permanently']) && $permission_can_delete_all_pages_permanently) {
105
-			$pageID = (int) $_REQUEST['delete_permanently'];
106
-
107
-			//load page
108
-			$page = new Page();
109
-			$page->loadByID($pageID);
110
-
111
-			//check, if page is in trash
112
-			if ($page->isTrash()) {
113
-				Page::deleteByID($page->getPageID());
114
-
115
-				$success_messages[] = "Deleted page '" . $page->getAlias() . "' permanently successful!";
116
-			}
117
-		}
118
-
119
-		$show_trash = false;
120
-
121
-		//show pages in trash
122
-		if (isset($_REQUEST['show_trash']) && $permission_can_see_trash_pages) {
123
-			$show_trash = true;
124
-		}
125
-
126
-		$template->assign("show_trash", $show_trash);
127
-		$template->assign("page_url", DomainUtils::generateURL($this->getPage()->getAlias()));
128
-
129
-		$pages = array();
130
-
131
-		if (!$show_trash) {
132
-			//count pages in trash
133
-			$row = Database::getInstance()->getRow("SELECT COUNT(*) FROM `{praefix}pages` WHERE `activated` = 2; ");
134
-
135
-			$number_of_pages_in_trash = (int) $row['COUNT(*)'];
136
-			$template->assign("pages_in_trash", $number_of_pages_in_trash);
137
-			$template->assign("trash_url", DomainUtils::generateURL($this->getPage()->getAlias(), array("show_trash" => 1)));
138
-		}
139
-
140
-		//get all pages from database
141
-		$rows = Database::getInstance()->listRows("SELECT *, `{praefix}pages`.`activated` as `activated` FROM `{praefix}pages` LEFT JOIN `{praefix}user` ON (`{praefix}pages`.`author` = `{praefix}user`.`userID`) WHERE `{praefix}pages`.`editable` = '1' AND `{praefix}pages`.`activated` = :activated; ", array(
142
-			'activated' => (!$show_trash ? 1 : 2)
143
-		));
144
-
145
-		foreach ($rows as $row) {
146
-			$is_author_online = $row['online'] == 1;
147
-			$is_own_page = $row['author'] == $current_userID;
148
-			$editable = $permission_can_edit_all_pages || ($permission_can_edit_own_pages && $is_own_page);
149
-			$is_trash = $row['activated'] == 2;
150
-
151
-			$pages[] = array(
152
-				'id' => $row['id'],
153
-				'alias' => $row['alias'],
154
-				'title' => Translator::translateTitle($row['title']),
155
-				'author' => $row['username'],
156
-				'state' => ($row['published'] == 1 ? "Published" : "Draft"),
157
-				'actions' => "&nbsp;",
158
-				'user_online' => (boolean) $is_author_online,
159
-				'url' => DomainUtils::generateURL($row['alias']),
160
-				'own_page' => (boolean) $is_own_page,
161
-				'editable' => (boolean) $editable,
162
-				'published' => $row['published'] == 1,
163
-				'locked' => $row['locked_by'] != -1,
164
-				'locked_user' => $row['locked_by'],
165
-				'locked_by_me' => $row['locked_by'] == User::current()->getID(),
166
-				'locked_timestamp' => $row['locked_timestamp'],
167
-				'unlock_url' => DomainUtils::generateURL($this->getPage()->getAlias(), array("unlock" => $row['id'])),
168
-				'can_edit' => ($permission_can_edit_all_pages || ($permission_can_edit_own_pages && $is_own_page)) && $row['editable'] == 1,
169
-				'edit_url' => DomainUtils::generateURL("admin/edit_page", array("edit" => $row['id'])),
170
-				'can_delete' => ($permission_can_delete_all_pages || ($permission_can_delete_own_pages && $is_own_page)) && $row['deletable'] == 1,
171
-				'delete_url' => DomainUtils::generateURL($this->getPage()->getAlias(), array("trash" => $row['id'])),
172
-				'is_in_trash' => (boolean) $is_trash,
173
-				'restore_url' => DomainUtils::generateURL($this->getPage()->getAlias(), array("restore" => $row['id'])),
174
-				'delete_permanently_url' => DomainUtils::generateURL($this->getPage()->getAlias(), array("delete_permanently" => $row['id'], "show_trash" => 1)),
175
-				'preview_url' => DomainUtils::generateURL($row['alias'], array("preview" => "true"))
176
-			);
177
-		}
178
-
179
-		$template->assign("permission_can_unlock_all_pages", $permission_can_unlock_all_pages);
180
-		$template->assign("permission_can_restore_trash_pages", $permission_can_restore_trash_pages);
181
-		$template->assign("permission_can_delete_all_pages_permanently", $permission_can_delete_all_pages_permanently);
182
-
183
-		$template->assign("success_messages", $success_messages);
184
-
185
-		$template->assign("pagelist", $pages);
186
-
187
-		return $template->getCode();
188
-	}
189
-
190
-	public function getFooterScripts(): string {
191
-		return "<script>
30
+    public function getContent(): string {
31
+        $template = new DwooTemplate("pages/pagelist");
32
+
33
+        $template->assign("no_edit_permissions", (boolean) (!PermissionChecker::current()->hasRight("an_edit_all_pages") && !PermissionChecker::current()->hasRight("can_edit_own_pages")));
34
+
35
+        //set table columns
36
+        $template->assign("columns", array(
37
+            Translator::translate("ID"),
38
+            Translator::translate("Alias"),
39
+            Translator::translate("Title"),
40
+            Translator::translate("Author"),
41
+            Translator::translate("State"),
42
+            Translator::translate("Actions")
43
+        ));
44
+
45
+        //get permissions
46
+        $current_userID = User::current()->getID();
47
+        $permission_can_edit_all_pages = PermissionChecker::current()->hasRight("can_edit_all_pages");
48
+        $permission_can_edit_own_pages = PermissionChecker::current()->hasRight("can_edit_own_pages");
49
+        $permission_can_unlock_all_pages = PermissionChecker::current()->hasRight("can_unlock_all_pages");
50
+        $permission_can_delete_own_pages = PermissionChecker::current()->hasRight("can_delete_own_pages");
51
+        $permission_can_delete_all_pages = PermissionChecker::current()->hasRight("can_delete_all_pages");
52
+        $permission_can_see_trash_pages = PermissionChecker::current()->hasRight("can_see_trash_pages");
53
+        $permission_can_restore_trash_pages = PermissionChecker::current()->hasRight("can_restore_trash_pages");
54
+        $permission_can_delete_all_pages_permanently = PermissionChecker::current()->hasRight("can_delete_all_pages_permanently");
55
+
56
+        $success_messages = array();
57
+
58
+        //unlock pages
59
+        if (isset($_REQUEST['unlock']) && $permission_can_unlock_all_pages) {
60
+            $pageID = (int) $_REQUEST['unlock'];
61
+            Page::unlockPage($pageID);
62
+
63
+            $success_messages[] = "Unlocked page successfully!";
64
+        }
65
+
66
+        //move pages to trash
67
+        if (isset($_REQUEST['trash']) && is_numeric($_REQUEST['trash']) && ($permission_can_delete_own_pages || $permission_can_delete_all_pages)) {
68
+            //move page to trash
69
+            $pageID = (int) $_REQUEST['trash'];
70
+
71
+            //load page
72
+            $page = new Page();
73
+            $page->loadByID($pageID);
74
+
75
+            //check permisssion
76
+            if ($permission_can_delete_all_pages || ($permission_can_delete_own_pages && $page->getAuthorID() == User::current()->getID())) {
77
+                //check, if page is deletable
78
+                if ($page->isDeletable()) {
79
+                    //move page to trash
80
+                    $page->moveToTrash();
81
+
82
+                    $success_messages[] = "Moved page '" . $page->getAlias() . "' to trash.";
83
+                }
84
+            }
85
+        }
86
+
87
+        //restore pages from trash
88
+        if (isset($_REQUEST['restore']) && is_numeric($_REQUEST['restore']) && $permission_can_restore_trash_pages) {
89
+            //restore page
90
+            $pageID = (int) $_REQUEST['restore'];
91
+
92
+            //load page
93
+            $page = new Page();
94
+            $page->loadByID($pageID);
95
+
96
+            if ($page->isTrash()) {
97
+                $page->restore();
98
+
99
+                $success_messages[] = "Restored page '" . $page->getAlias() . "' successfully!";
100
+            }
101
+        }
102
+
103
+        //delete pages from trash
104
+        if (isset($_REQUEST['delete_permanently']) && is_numeric($_REQUEST['delete_permanently']) && $permission_can_delete_all_pages_permanently) {
105
+            $pageID = (int) $_REQUEST['delete_permanently'];
106
+
107
+            //load page
108
+            $page = new Page();
109
+            $page->loadByID($pageID);
110
+
111
+            //check, if page is in trash
112
+            if ($page->isTrash()) {
113
+                Page::deleteByID($page->getPageID());
114
+
115
+                $success_messages[] = "Deleted page '" . $page->getAlias() . "' permanently successful!";
116
+            }
117
+        }
118
+
119
+        $show_trash = false;
120
+
121
+        //show pages in trash
122
+        if (isset($_REQUEST['show_trash']) && $permission_can_see_trash_pages) {
123
+            $show_trash = true;
124
+        }
125
+
126
+        $template->assign("show_trash", $show_trash);
127
+        $template->assign("page_url", DomainUtils::generateURL($this->getPage()->getAlias()));
128
+
129
+        $pages = array();
130
+
131
+        if (!$show_trash) {
132
+            //count pages in trash
133
+            $row = Database::getInstance()->getRow("SELECT COUNT(*) FROM `{praefix}pages` WHERE `activated` = 2; ");
134
+
135
+            $number_of_pages_in_trash = (int) $row['COUNT(*)'];
136
+            $template->assign("pages_in_trash", $number_of_pages_in_trash);
137
+            $template->assign("trash_url", DomainUtils::generateURL($this->getPage()->getAlias(), array("show_trash" => 1)));
138
+        }
139
+
140
+        //get all pages from database
141
+        $rows = Database::getInstance()->listRows("SELECT *, `{praefix}pages`.`activated` as `activated` FROM `{praefix}pages` LEFT JOIN `{praefix}user` ON (`{praefix}pages`.`author` = `{praefix}user`.`userID`) WHERE `{praefix}pages`.`editable` = '1' AND `{praefix}pages`.`activated` = :activated; ", array(
142
+            'activated' => (!$show_trash ? 1 : 2)
143
+        ));
144
+
145
+        foreach ($rows as $row) {
146
+            $is_author_online = $row['online'] == 1;
147
+            $is_own_page = $row['author'] == $current_userID;
148
+            $editable = $permission_can_edit_all_pages || ($permission_can_edit_own_pages && $is_own_page);
149
+            $is_trash = $row['activated'] == 2;
150
+
151
+            $pages[] = array(
152
+                'id' => $row['id'],
153
+                'alias' => $row['alias'],
154
+                'title' => Translator::translateTitle($row['title']),
155
+                'author' => $row['username'],
156
+                'state' => ($row['published'] == 1 ? "Published" : "Draft"),
157
+                'actions' => "&nbsp;",
158
+                'user_online' => (boolean) $is_author_online,
159
+                'url' => DomainUtils::generateURL($row['alias']),
160
+                'own_page' => (boolean) $is_own_page,
161
+                'editable' => (boolean) $editable,
162
+                'published' => $row['published'] == 1,
163
+                'locked' => $row['locked_by'] != -1,
164
+                'locked_user' => $row['locked_by'],
165
+                'locked_by_me' => $row['locked_by'] == User::current()->getID(),
166
+                'locked_timestamp' => $row['locked_timestamp'],
167
+                'unlock_url' => DomainUtils::generateURL($this->getPage()->getAlias(), array("unlock" => $row['id'])),
168
+                'can_edit' => ($permission_can_edit_all_pages || ($permission_can_edit_own_pages && $is_own_page)) && $row['editable'] == 1,
169
+                'edit_url' => DomainUtils::generateURL("admin/edit_page", array("edit" => $row['id'])),
170
+                'can_delete' => ($permission_can_delete_all_pages || ($permission_can_delete_own_pages && $is_own_page)) && $row['deletable'] == 1,
171
+                'delete_url' => DomainUtils::generateURL($this->getPage()->getAlias(), array("trash" => $row['id'])),
172
+                'is_in_trash' => (boolean) $is_trash,
173
+                'restore_url' => DomainUtils::generateURL($this->getPage()->getAlias(), array("restore" => $row['id'])),
174
+                'delete_permanently_url' => DomainUtils::generateURL($this->getPage()->getAlias(), array("delete_permanently" => $row['id'], "show_trash" => 1)),
175
+                'preview_url' => DomainUtils::generateURL($row['alias'], array("preview" => "true"))
176
+            );
177
+        }
178
+
179
+        $template->assign("permission_can_unlock_all_pages", $permission_can_unlock_all_pages);
180
+        $template->assign("permission_can_restore_trash_pages", $permission_can_restore_trash_pages);
181
+        $template->assign("permission_can_delete_all_pages_permanently", $permission_can_delete_all_pages_permanently);
182
+
183
+        $template->assign("success_messages", $success_messages);
184
+
185
+        $template->assign("pagelist", $pages);
186
+
187
+        return $template->getCode();
188
+    }
189
+
190
+    public function getFooterScripts(): string {
191
+        return "<script>
192 192
 		  $(function () {
193 193
 			$('#pagetable').DataTable({
194 194
 			  'paging'      : true,
@@ -200,11 +200,11 @@  discard block
 block discarded – undo
200 200
 			});
201 201
 		  });
202 202
 		</script>";
203
-	}
203
+    }
204 204
 
205
-	public function listRequiredPermissions(): array {
206
-		return array("can_see_all_pages", "can_edit_all_pages");
207
-	}
205
+    public function listRequiredPermissions(): array {
206
+        return array("can_see_all_pages", "can_edit_all_pages");
207
+    }
208 208
 
209 209
 }
210 210
 
Please login to merge, or discard this patch.
system/packages/com.jukusoft.cms.htmlpage/classes/htmlpage.php 1 patch
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -18,21 +18,21 @@
 block discarded – undo
18 18
 
19 19
 class HTMLPage extends PageType {
20 20
 
21
-	public function getContent(): string {
22
-		//first check, if specific template exists
23
-		$current_style = Registry::singleton()->getSetting("current_style_name");
24
-		if (file_exists(STYLE_PATH . $current_style . "/pages/htmlpage.tpl")) {
25
-			$template = new Template($this->getPage()->hasCustomTemplate() ? $this->getPage()->getCustomTemplate() : "pages/htmlpage");
21
+    public function getContent(): string {
22
+        //first check, if specific template exists
23
+        $current_style = Registry::singleton()->getSetting("current_style_name");
24
+        if (file_exists(STYLE_PATH . $current_style . "/pages/htmlpage.tpl")) {
25
+            $template = new Template($this->getPage()->hasCustomTemplate() ? $this->getPage()->getCustomTemplate() : "pages/htmlpage");
26 26
 
27
-			$template->assign("TITLE", $this->getPage()->getTitle());
28
-			$template->assign("CONTENT", parent::getContent());
27
+            $template->assign("TITLE", $this->getPage()->getTitle());
28
+            $template->assign("CONTENT", parent::getContent());
29 29
 
30
-			$template->parse("main");
31
-			return $template->getCode();
32
-		} else {
33
-			return parent::getContent();
34
-		}
35
-	}
30
+            $template->parse("main");
31
+            return $template->getCode();
32
+        } else {
33
+            return parent::getContent();
34
+        }
35
+    }
36 36
 
37 37
 }
38 38
 
Please login to merge, or discard this patch.
system/packages/com.jukusoft.cms.page/classes/page.php 2 patches
Indentation   +487 added lines, -487 removed lines patch added patch discarded remove patch
@@ -18,510 +18,510 @@
 block discarded – undo
18 18
 
19 19
 class Page {
20 20
 
21
-	protected $pageID = -1;
22
-	protected $alias = null;
23
-	protected $row = null;
24
-	protected $pagetype = "";
25
-
26
-	protected $author = null;
27
-
28
-	//changed columns to save with save()
29
-	protected $changes = array();
30
-
31
-	public function __construct() {
32
-		//
33
-	}
34
-
35
-	public function load ($alias = null) {
36
-		if ($alias == null) {
37
-			if (isset($_REQUEST['page']) && !empty($_REQUEST['page'])) {
38
-				$alias = Validator_String::get($_REQUEST['page']);
39
-			} else {
40
-				$alias = $this->getDomain()->getHomePage();
41
-			}
42
-		} else {
43
-			//$alias = Database::getInstance()->escape($alias);
44
-		}
45
-
46
-		Events::throwEvent("get_alias", array(
47
-			'alias' => &$alias,
48
-			'page' => &$this,
49
-			'domain' => $this->getDomain()
50
-		));
51
-
52
-		$this->alias = $alias;
53
-
54
-		if (Cache::contains("pages", "page_" . $alias)) {
55
-			$this->row = Cache::get("pages", "page_" . $alias);
56
-		} else {
57
-			$row = Database::getInstance()->getRow("SELECT * FROM `{praefix}pages` WHERE `alias` = :alias AND `activated` = '1'; ", array('alias' => $alias));
58
-
59
-			if (!$row) {
60
-				if (PHPUtils::strEqs("error404", $alias)) {
61
-					throw new IllegalStateException("No page with alias 'error404' exists (requested alias: " . $alias . ").");
62
-				}
63
-
64
-				//page not found
65
-				$new_alias = "error404";
66
-
67
-				Events::throwEvent("load_page_error404", array(
68
-					'alias' => &$new_alias,
69
-					'original_alias' => $alias,
70
-					'page' => &$this,
71
-					'domain' => $this->getDomain()
72
-				));
73
-
74
-				$this->load($new_alias);
75
-				return null;
76
-			}
77
-
78
-			$this->row = $row;
79
-
80
-			//cache result
81
-			Cache::put("pages", "page_" . $alias, $row);
82
-		}
83
-
84
-		//get pageID
85
-		$this->pageID = $this->row['id'];
86
-
87
-		//get name of page type (class name)
88
-		$this->pagetype = $this->row['page_type'];
89
-	}
90
-
91
-	public function loadByID (int $pageID, bool $use_cache = true) {
92
-		if ($use_cache && Cache::contains("pages", "pageID_" . $pageID)) {
93
-			$this->row = Cache::get("pages", "pageID_" . $pageID);
94
-		} else {
95
-			$row = Database::getInstance()->getRow("SELECT * FROM `{praefix}pages` WHERE `id` = :pageID; ", array('pageID' => $pageID));
96
-
97
-			if (!$row) {
98
-				throw new IllegalStateException("Page with pageID " . $pageID . " doesnt exists!");
99
-			}
100
-
101
-			$this->row = $row;
102
-
103
-			//cache result
104
-			Cache::put("pages", "pageID_" . $pageID, $row);
105
-		}
106
-
107
-		$this->pageID = $this->row['id'];
108
-		$this->alias = $this->row['alias'];
109
-
110
-		//get name of page type (class name)
111
-		$this->pagetype = $this->row['page_type'];
112
-	}
113
-
114
-	protected function getDomain () : Domain {
115
-		return Registry::singleton()->getObject("domain");
116
-	}
117
-
118
-	public function reloadCache () {
119
-		Cache::clear("pages");
120
-	}
121
-
122
-	public function getPageID () : int {
123
-		return $this->row['id'];
124
-	}
125
-
126
-	public function getAlias () : string {
127
-		return $this->alias;
128
-	}
129
-
130
-	public function getPageType () : string {
131
-		return $this->pagetype;
132
-	}
133
-
134
-	public function getTitle () : string {
135
-		return $this->row['title'];
136
-	}
137
-
138
-	public function setTitle (string $title) {
139
-		$this->row['title'] = $title;
140
-		$this->changes[] = "title";
141
-	}
142
-
143
-	public function getContent () : string {
144
-		return $this->row['content'];
145
-	}
146
-
147
-	public function setContent (string $content) {
148
-		$this->row['content'] = $content;
149
-		$this->changes[] = "content";
150
-		$this->changes[] = "content";
151
-	}
152
-
153
-	public function getGlobalMenuID () : int {
154
-		return $this->row['global_menu'];
155
-	}
156
-
157
-	public function getLocalMenuID () : int {
158
-		return $this->row['local_menu'];
159
-	}
160
-
161
-	public function getStyle () : string {
162
-		return $this->row['design'];
163
-	}
164
-
165
-	public function getFolder () : string {
166
-		return $this->row['folder'];
167
-	}
21
+    protected $pageID = -1;
22
+    protected $alias = null;
23
+    protected $row = null;
24
+    protected $pagetype = "";
25
+
26
+    protected $author = null;
27
+
28
+    //changed columns to save with save()
29
+    protected $changes = array();
30
+
31
+    public function __construct() {
32
+        //
33
+    }
34
+
35
+    public function load ($alias = null) {
36
+        if ($alias == null) {
37
+            if (isset($_REQUEST['page']) && !empty($_REQUEST['page'])) {
38
+                $alias = Validator_String::get($_REQUEST['page']);
39
+            } else {
40
+                $alias = $this->getDomain()->getHomePage();
41
+            }
42
+        } else {
43
+            //$alias = Database::getInstance()->escape($alias);
44
+        }
45
+
46
+        Events::throwEvent("get_alias", array(
47
+            'alias' => &$alias,
48
+            'page' => &$this,
49
+            'domain' => $this->getDomain()
50
+        ));
51
+
52
+        $this->alias = $alias;
53
+
54
+        if (Cache::contains("pages", "page_" . $alias)) {
55
+            $this->row = Cache::get("pages", "page_" . $alias);
56
+        } else {
57
+            $row = Database::getInstance()->getRow("SELECT * FROM `{praefix}pages` WHERE `alias` = :alias AND `activated` = '1'; ", array('alias' => $alias));
58
+
59
+            if (!$row) {
60
+                if (PHPUtils::strEqs("error404", $alias)) {
61
+                    throw new IllegalStateException("No page with alias 'error404' exists (requested alias: " . $alias . ").");
62
+                }
63
+
64
+                //page not found
65
+                $new_alias = "error404";
66
+
67
+                Events::throwEvent("load_page_error404", array(
68
+                    'alias' => &$new_alias,
69
+                    'original_alias' => $alias,
70
+                    'page' => &$this,
71
+                    'domain' => $this->getDomain()
72
+                ));
73
+
74
+                $this->load($new_alias);
75
+                return null;
76
+            }
77
+
78
+            $this->row = $row;
79
+
80
+            //cache result
81
+            Cache::put("pages", "page_" . $alias, $row);
82
+        }
83
+
84
+        //get pageID
85
+        $this->pageID = $this->row['id'];
86
+
87
+        //get name of page type (class name)
88
+        $this->pagetype = $this->row['page_type'];
89
+    }
90
+
91
+    public function loadByID (int $pageID, bool $use_cache = true) {
92
+        if ($use_cache && Cache::contains("pages", "pageID_" . $pageID)) {
93
+            $this->row = Cache::get("pages", "pageID_" . $pageID);
94
+        } else {
95
+            $row = Database::getInstance()->getRow("SELECT * FROM `{praefix}pages` WHERE `id` = :pageID; ", array('pageID' => $pageID));
96
+
97
+            if (!$row) {
98
+                throw new IllegalStateException("Page with pageID " . $pageID . " doesnt exists!");
99
+            }
100
+
101
+            $this->row = $row;
102
+
103
+            //cache result
104
+            Cache::put("pages", "pageID_" . $pageID, $row);
105
+        }
106
+
107
+        $this->pageID = $this->row['id'];
108
+        $this->alias = $this->row['alias'];
109
+
110
+        //get name of page type (class name)
111
+        $this->pagetype = $this->row['page_type'];
112
+    }
113
+
114
+    protected function getDomain () : Domain {
115
+        return Registry::singleton()->getObject("domain");
116
+    }
117
+
118
+    public function reloadCache () {
119
+        Cache::clear("pages");
120
+    }
121
+
122
+    public function getPageID () : int {
123
+        return $this->row['id'];
124
+    }
125
+
126
+    public function getAlias () : string {
127
+        return $this->alias;
128
+    }
129
+
130
+    public function getPageType () : string {
131
+        return $this->pagetype;
132
+    }
133
+
134
+    public function getTitle () : string {
135
+        return $this->row['title'];
136
+    }
137
+
138
+    public function setTitle (string $title) {
139
+        $this->row['title'] = $title;
140
+        $this->changes[] = "title";
141
+    }
142
+
143
+    public function getContent () : string {
144
+        return $this->row['content'];
145
+    }
146
+
147
+    public function setContent (string $content) {
148
+        $this->row['content'] = $content;
149
+        $this->changes[] = "content";
150
+        $this->changes[] = "content";
151
+    }
152
+
153
+    public function getGlobalMenuID () : int {
154
+        return $this->row['global_menu'];
155
+    }
156
+
157
+    public function getLocalMenuID () : int {
158
+        return $this->row['local_menu'];
159
+    }
160
+
161
+    public function getStyle () : string {
162
+        return $this->row['design'];
163
+    }
164
+
165
+    public function getFolder () : string {
166
+        return $this->row['folder'];
167
+    }
168 168
 
169
-	public function getLastEdit () {
170
-		return $this->row['lastUpdate'];
171
-	}
169
+    public function getLastEdit () {
170
+        return $this->row['lastUpdate'];
171
+    }
172 172
 
173
-	public function hasCustomTemplate () : bool {
174
-		return $this->row['template'] !== "none";
175
-	}
173
+    public function hasCustomTemplate () : bool {
174
+        return $this->row['template'] !== "none";
175
+    }
176 176
 
177
-	public function getCustomTemplate () : string {
178
-		return $this->row['template'];
179
-	}
177
+    public function getCustomTemplate () : string {
178
+        return $this->row['template'];
179
+    }
180 180
 
181
-	public function hasCustomPermissions () : bool {
182
-		return $this->row['can_see_permissions'] !== "none";
183
-	}
181
+    public function hasCustomPermissions () : bool {
182
+        return $this->row['can_see_permissions'] !== "none";
183
+    }
184 184
 
185
-	public function listCustomPermissions () : array {
186
-		return explode("|", $this->row['can_see_permissions']);
187
-	}
185
+    public function listCustomPermissions () : array {
186
+        return explode("|", $this->row['can_see_permissions']);
187
+    }
188 188
 
189
-	public function isPublished () : bool {
190
-		return $this->row['published'] == 1;
191
-	}
189
+    public function isPublished () : bool {
190
+        return $this->row['published'] == 1;
191
+    }
192 192
 
193
-	public function publish () {
194
-		$this->row['published'] = 1;
195
-		$this->changes[] = "published";
196
-	}
193
+    public function publish () {
194
+        $this->row['published'] = 1;
195
+        $this->changes[] = "published";
196
+    }
197 197
 
198
-	public function getContentType () : string {
199
-		return $this->row['content_type'];
200
-	}
198
+    public function getContentType () : string {
199
+        return $this->row['content_type'];
200
+    }
201 201
 
202
-	public function getParentID () : int {
203
-		return $this->row['parent'];
204
-	}
202
+    public function getParentID () : int {
203
+        return $this->row['parent'];
204
+    }
205 205
 
206
-	public function getLeftSidebarID () : int {
207
-		return $this->row['sidebar_left'];
208
-	}
206
+    public function getLeftSidebarID () : int {
207
+        return $this->row['sidebar_left'];
208
+    }
209 209
 
210
-	public function getRightSidebarID () : int {
211
-		return $this->row['sidebar_right'];
212
-	}
210
+    public function getRightSidebarID () : int {
211
+        return $this->row['sidebar_right'];
212
+    }
213 213
 
214
-	public function getMetaDescription () : string {
215
-		return $this->row['meta_description'];
216
-	}
214
+    public function getMetaDescription () : string {
215
+        return $this->row['meta_description'];
216
+    }
217 217
 
218
-	public function getMetaKeywords () : string {
219
-		return $this->row['meta_keywords'];
220
-	}
221
-
222
-	public function getMetaRobotsOptions () : string {
223
-		return $this->row['meta_robots'];
224
-	}
225
-
226
-	public function getMetaCanonicals () : string {
227
-		return $this->row['meta_canonicals'];
228
-	}
229
-
230
-	public function getOgType () : string {
231
-		return $this->row['og_type'];
232
-	}
233
-
234
-	public function getOgTitle () : string {
235
-		return !empty($this->row['og_title']) ? $this->row['og_title'] : $this->getTitle();
236
-	}
237
-
238
-	public function getOgDescription () : string {
239
-		return !empty($this->row['og_description']) ? $this->row['og_description'] : $this->getMetaDescription();
240
-	}
241
-
242
-	public function getOgImages () : array {
243
-		if (empty($this->row['og_image'])) {
244
-			return array();
245
-		}
246
-
247
-		return explode(",", $this->row['og_image']);
248
-	}
249
-
250
-	public function getAuthorID () : int {
251
-		return $this->row['author'];
252
-	}
253
-
254
-	public function getAuthor () : User {
255
-		if ($this->author == null) {
256
-			//load author
257
-			$this->author = new User();
258
-
259
-			if ($this->getAuthorID() <= 0) {
260
-				throw new IllegalArgumentException("authorID has to be > 0.");
261
-			}
262
-
263
-			$this->author->load($this->getAuthorID());
264
-		}
265
-
266
-		return $this->author;
267
-	}
268
-
269
-	public function isSitemapEnabled () : bool {
270
-		return $this->row['sitemap'] == 1;
271
-	}
272
-
273
-	public function getSitemapChangeFreq () : string {
274
-		return $this->row['sitemap_changefreq'];
275
-	}
276
-
277
-	public function getSitemapPriority () : string {
278
-		return $this->row['sitemap_priority'];
279
-	}
280
-
281
-	public function activate (bool $bool = true) {
282
-		$this->row['activated'] = ($bool ? 1 : 0);
283
-	}
284
-
285
-	public function isTrash () : bool {
286
-		return $this->row['activated'] == 2;
287
-	}
288
-
289
-	public function isEditable () : bool {
290
-		return $this->row['editable'] == 1;
291
-	}
292
-
293
-	public function isDeletable () : bool {
294
-		return $this->row['deletable'] == 1;
295
-	}
296
-
297
-	public function isActivated () : bool {
298
-		return $this->row['activated'] == 1;
299
-	}
300
-
301
-	public function moveToTrash () {
302
-		self::movePageToTrash($this->pageID);
303
-
304
-		//clear cache
305
-		$this->clearCache();
306
-	}
307
-
308
-	/**
309
-	 * restore page from trash
310
-	 */
311
-	public function restore () {
312
-		self::restorePage($this->pageID);
313
-
314
-		//clear cache
315
-		$this->clearCache();
316
-	}
317
-
318
-	/**
319
-	 * save changes into database
320
-	 */
321
-	public function save () {
322
-		//TODO: add code here
323
-	}
324
-
325
-	public function clearCache () {
326
-		if (!is_int($this->getPageID())) {
327
-			throw new IllegalStateException("pageID isn't set.");
328
-		}
329
-
330
-		//clear cache
331
-		Cache::clear("pages", "pageID_" . $this->getPageID());
332
-		Cache::clear("pages", "page_" . $this->getAlias());
333
-	}
334
-
335
-	public static function createIfAbsent (string $alias, string $title, string $page_type, string $content = "", string $folder = "/", int $globalMenu = -1, int $localMenu = -1, int $parentID = -1, bool $sitemap = true, bool $published = true, bool $editable = true, bool $deletable = true, string $author = "system") : int {
336
-		//throw event
337
-		Events::throwEvent("create_page", array(
338
-			'alias' => &$alias,
339
-			'title' => &$title,
340
-			'page_type' => &$page_type,
341
-			'content' => &$content,
342
-			'folder' => &$folder,
343
-			'global_menu' => &$globalMenu,
344
-			'local_menu' => &$localMenu,
345
-			'parentID' => &$parentID,
346
-			'sitemap' => &$sitemap,
347
-			'published' => &$published,
348
-			'editable' => &$editable,
349
-			'author' => &$author
350
-		));
351
-
352
-		if (!is_int($author)) {
353
-			//get userID of author
354
-			$author = User::getIDByUsernameFromDB($author);
355
-
356
-			if ($author == -1) {
357
-				//username doesnt exists, so choose first user
358
-				$author = 1;
359
-			}
360
-		} else {
361
-			$author = (int) $author;
362
-		}
363
-
364
-		Database::getInstance()->execute("INSERT INTO `{praefix}pages` (
218
+    public function getMetaKeywords () : string {
219
+        return $this->row['meta_keywords'];
220
+    }
221
+
222
+    public function getMetaRobotsOptions () : string {
223
+        return $this->row['meta_robots'];
224
+    }
225
+
226
+    public function getMetaCanonicals () : string {
227
+        return $this->row['meta_canonicals'];
228
+    }
229
+
230
+    public function getOgType () : string {
231
+        return $this->row['og_type'];
232
+    }
233
+
234
+    public function getOgTitle () : string {
235
+        return !empty($this->row['og_title']) ? $this->row['og_title'] : $this->getTitle();
236
+    }
237
+
238
+    public function getOgDescription () : string {
239
+        return !empty($this->row['og_description']) ? $this->row['og_description'] : $this->getMetaDescription();
240
+    }
241
+
242
+    public function getOgImages () : array {
243
+        if (empty($this->row['og_image'])) {
244
+            return array();
245
+        }
246
+
247
+        return explode(",", $this->row['og_image']);
248
+    }
249
+
250
+    public function getAuthorID () : int {
251
+        return $this->row['author'];
252
+    }
253
+
254
+    public function getAuthor () : User {
255
+        if ($this->author == null) {
256
+            //load author
257
+            $this->author = new User();
258
+
259
+            if ($this->getAuthorID() <= 0) {
260
+                throw new IllegalArgumentException("authorID has to be > 0.");
261
+            }
262
+
263
+            $this->author->load($this->getAuthorID());
264
+        }
265
+
266
+        return $this->author;
267
+    }
268
+
269
+    public function isSitemapEnabled () : bool {
270
+        return $this->row['sitemap'] == 1;
271
+    }
272
+
273
+    public function getSitemapChangeFreq () : string {
274
+        return $this->row['sitemap_changefreq'];
275
+    }
276
+
277
+    public function getSitemapPriority () : string {
278
+        return $this->row['sitemap_priority'];
279
+    }
280
+
281
+    public function activate (bool $bool = true) {
282
+        $this->row['activated'] = ($bool ? 1 : 0);
283
+    }
284
+
285
+    public function isTrash () : bool {
286
+        return $this->row['activated'] == 2;
287
+    }
288
+
289
+    public function isEditable () : bool {
290
+        return $this->row['editable'] == 1;
291
+    }
292
+
293
+    public function isDeletable () : bool {
294
+        return $this->row['deletable'] == 1;
295
+    }
296
+
297
+    public function isActivated () : bool {
298
+        return $this->row['activated'] == 1;
299
+    }
300
+
301
+    public function moveToTrash () {
302
+        self::movePageToTrash($this->pageID);
303
+
304
+        //clear cache
305
+        $this->clearCache();
306
+    }
307
+
308
+    /**
309
+     * restore page from trash
310
+     */
311
+    public function restore () {
312
+        self::restorePage($this->pageID);
313
+
314
+        //clear cache
315
+        $this->clearCache();
316
+    }
317
+
318
+    /**
319
+     * save changes into database
320
+     */
321
+    public function save () {
322
+        //TODO: add code here
323
+    }
324
+
325
+    public function clearCache () {
326
+        if (!is_int($this->getPageID())) {
327
+            throw new IllegalStateException("pageID isn't set.");
328
+        }
329
+
330
+        //clear cache
331
+        Cache::clear("pages", "pageID_" . $this->getPageID());
332
+        Cache::clear("pages", "page_" . $this->getAlias());
333
+    }
334
+
335
+    public static function createIfAbsent (string $alias, string $title, string $page_type, string $content = "", string $folder = "/", int $globalMenu = -1, int $localMenu = -1, int $parentID = -1, bool $sitemap = true, bool $published = true, bool $editable = true, bool $deletable = true, string $author = "system") : int {
336
+        //throw event
337
+        Events::throwEvent("create_page", array(
338
+            'alias' => &$alias,
339
+            'title' => &$title,
340
+            'page_type' => &$page_type,
341
+            'content' => &$content,
342
+            'folder' => &$folder,
343
+            'global_menu' => &$globalMenu,
344
+            'local_menu' => &$localMenu,
345
+            'parentID' => &$parentID,
346
+            'sitemap' => &$sitemap,
347
+            'published' => &$published,
348
+            'editable' => &$editable,
349
+            'author' => &$author
350
+        ));
351
+
352
+        if (!is_int($author)) {
353
+            //get userID of author
354
+            $author = User::getIDByUsernameFromDB($author);
355
+
356
+            if ($author == -1) {
357
+                //username doesnt exists, so choose first user
358
+                $author = 1;
359
+            }
360
+        } else {
361
+            $author = (int) $author;
362
+        }
363
+
364
+        Database::getInstance()->execute("INSERT INTO `{praefix}pages` (
365 365
 			`id`, `alias`, `title`, `content`, `parent`, `folder`, `global_menu`, `local_menu`, `page_type`, `design`, `sitemap`, `published`, `version`, `last_update`, `created`, `editable`, `deletable`, `author`, `activated`
366 366
 		) VALUES (
367 367
 			NULL, :alias, :title, :content, :parent, :folder, :globalMenu, :localMenu, :pageType, 'none', :sitemap, :published, '1', '0000-00-00 00:00:00', CURRENT_TIMESTAMP, :editable, :deletable, :author, '1'
368 368
 		) ON DUPLICATE KEY UPDATE `alias` = :alias, `editable` = :editable, `deletable` = :deletable; ", array(
369
-			'alias' => $alias,
370
-			'title' => $title,
371
-			'content' => $content,
372
-			'parent' => $parentID,
373
-			'folder' => $folder,
374
-			'globalMenu' => $globalMenu,
375
-			'localMenu' => $localMenu,
376
-			'pageType' => $page_type,
377
-			'sitemap' => ($sitemap ? 1 : 0),
378
-			'published' => ($published ? 1 : 0),
379
-			'editable' => ($editable ? 1 : 0),
380
-			'deletable' => ($deletable ? 1 : 0),
381
-			'author' => $author
382
-		));
383
-
384
-		Cache::clear("pages");
385
-
386
-		//return page id
387
-		$insertID = Database::getInstance()->lastInsertId();
388
-
389
-		//throw event
390
-		Events::throwEvent("created_page", array(
391
-			'alias' => $alias,
392
-			'title' => $title,
393
-			'insertID' => $insertID
394
-		));
395
-
396
-		//get pageID by alias
397
-		$pageID = Page::getPageIDByAlias($alias);
398
-
399
-		//set default rights, allow page for administrators, registered users, guests and bots
400
-		PageRights::setDefaultAllowedGroups($pageID, array(1, 2, 3, 4));
401
-
402
-		return $pageID;
403
-	}
404
-
405
-	public static function delete (string $alias) {
406
-		$delete = true;
407
-
408
-		//plugins can avoid deletion or change alias
409
-		Events::throwEvent("delete_page_alias", array(
410
-			'alias' => &$alias,
411
-			'delete' => &$delete
412
-		));
413
-
414
-		if ($delete) {
415
-			//remove page from database
416
-			Database::getInstance()->execute("DELETE FROM `{praefix}pages` WHERE `alias` = :alias; ", array('alias' => $alias));
417
-
418
-			Cache::clear("pages");
419
-		}
420
-	}
421
-
422
-	public static function deleteByID (int $id) {
423
-		$delete = true;
424
-
425
-		//plugins can avoid deletion or change alias
426
-		Events::throwEvent("delete_page_id", array(
427
-			'alias' => &$id,
428
-			'delete' => &$delete
429
-		));
430
-
431
-		if ($delete) {
432
-			//remove page from database
433
-			Database::getInstance()->execute("DELETE FROM `{praefix}pages` WHERE `id` = :id; ", array('id' => $id));
434
-
435
-			Cache::clear("pages");
436
-		}
437
-	}
438
-
439
-	public static function get (string $alias) : Page {
440
-		$page = new Page();
441
-		$page->load($alias);
442
-
443
-		return $page;
444
-	}
445
-
446
-	public static function setPageType (string $alias, string $page_type) {
447
-		Events::throwEvent("set_pagetype", array(
448
-			'alias' => &$alias,
449
-			'page_type' => &$page_type
450
-		));
451
-
452
-		Database::getInstance()->execute("UPDATE `{praefix}pages` SET `page_type` = :page_type WHERE `alias` = :alias; ", array(
453
-			'alias' => $alias,
454
-			'page_type' => $page_type
455
-		));
456
-
457
-		Cache::clear("pages");
458
-	}
459
-
460
-	/**
461
-	 * get id of page by alias
462
-	 *
463
-	 * only use this method for database upgrade, because their is no caching for this method!
464
-	 *
465
-	 * @param string $alias alias of page
466
-	 *
467
-	 * @throws IllegalStateException if alias doesnt exists
468
-	 *
469
-	 * @return int pageID
470
-	 */
471
-	public static function getPageIDByAlias (string $alias) : int {
472
-		$row = Database::getInstance()->getRow("SELECT * FROM `{praefix}pages` WHERE `alias` = :alias; ", array('alias' => $alias));
473
-
474
-		if (!$row) {
475
-			throw new IllegalStateException("page with alias '" . $alias . "' doesnt exists.");
476
-		}
477
-
478
-		return $row['id'];
479
-	}
480
-
481
-	public static function lockPage (int $pageID, int $userID) {
482
-		Database::getInstance()->execute("UPDATE `{praefix}pages` SET `locked_by` = :userID, `locked_timestamp` = CURRENT_TIMESTAMP WHERE `id` = :pageID; ", array(
483
-			'userID' => $userID,
484
-			'pageID' => $pageID
485
-		));
486
-
487
-		//clear cache
488
-		Cache::clear("pages", "pageID_" . $pageID);
489
-	}
490
-
491
-	public static function unlockPage (int $pageID) {
492
-		Database::getInstance()->execute("UPDATE `{praefix}pages` SET `locked_by` = '-1' WHERE `id` = :pageID; ", array(
493
-			'pageID' => $pageID
494
-		));
495
-
496
-		//clear cache
497
-		Cache::clear("pages", "pageID_" . $pageID);
498
-	}
499
-
500
-	protected static function movePageToTrash (int $pageID) {
501
-		Database::getInstance()->execute("UPDATE `{praefix}pages` SET `activated` = 2 WHERE `id` = :pageID; ", array(
502
-			'pageID' => $pageID
503
-		));
504
-
505
-		//clear cache
506
-		Cache::clear("pages", "pageID_" . $pageID);
507
-	}
508
-
509
-	protected static function restorePage (int $pageID) {
510
-		Database::getInstance()->execute("UPDATE `{praefix}pages` SET `activated` = 1 WHERE `id` = :pageID; ", array(
511
-			'pageID' => $pageID
512
-		));
513
-
514
-		//clear cache
515
-		Cache::clear("pages", "pageID_" . $pageID);
516
-	}
517
-
518
-	public static function exists (string $alias) : bool {
519
-		$row = Database::getInstance()->getRow("SELECT * FROM `{praefix}pages` WHERE `alias` = :alias; ", array(
520
-			'alias' => $alias
521
-		));
522
-
523
-		return $row !== false;
524
-	}
369
+            'alias' => $alias,
370
+            'title' => $title,
371
+            'content' => $content,
372
+            'parent' => $parentID,
373
+            'folder' => $folder,
374
+            'globalMenu' => $globalMenu,
375
+            'localMenu' => $localMenu,
376
+            'pageType' => $page_type,
377
+            'sitemap' => ($sitemap ? 1 : 0),
378
+            'published' => ($published ? 1 : 0),
379
+            'editable' => ($editable ? 1 : 0),
380
+            'deletable' => ($deletable ? 1 : 0),
381
+            'author' => $author
382
+        ));
383
+
384
+        Cache::clear("pages");
385
+
386
+        //return page id
387
+        $insertID = Database::getInstance()->lastInsertId();
388
+
389
+        //throw event
390
+        Events::throwEvent("created_page", array(
391
+            'alias' => $alias,
392
+            'title' => $title,
393
+            'insertID' => $insertID
394
+        ));
395
+
396
+        //get pageID by alias
397
+        $pageID = Page::getPageIDByAlias($alias);
398
+
399
+        //set default rights, allow page for administrators, registered users, guests and bots
400
+        PageRights::setDefaultAllowedGroups($pageID, array(1, 2, 3, 4));
401
+
402
+        return $pageID;
403
+    }
404
+
405
+    public static function delete (string $alias) {
406
+        $delete = true;
407
+
408
+        //plugins can avoid deletion or change alias
409
+        Events::throwEvent("delete_page_alias", array(
410
+            'alias' => &$alias,
411
+            'delete' => &$delete
412
+        ));
413
+
414
+        if ($delete) {
415
+            //remove page from database
416
+            Database::getInstance()->execute("DELETE FROM `{praefix}pages` WHERE `alias` = :alias; ", array('alias' => $alias));
417
+
418
+            Cache::clear("pages");
419
+        }
420
+    }
421
+
422
+    public static function deleteByID (int $id) {
423
+        $delete = true;
424
+
425
+        //plugins can avoid deletion or change alias
426
+        Events::throwEvent("delete_page_id", array(
427
+            'alias' => &$id,
428
+            'delete' => &$delete
429
+        ));
430
+
431
+        if ($delete) {
432
+            //remove page from database
433
+            Database::getInstance()->execute("DELETE FROM `{praefix}pages` WHERE `id` = :id; ", array('id' => $id));
434
+
435
+            Cache::clear("pages");
436
+        }
437
+    }
438
+
439
+    public static function get (string $alias) : Page {
440
+        $page = new Page();
441
+        $page->load($alias);
442
+
443
+        return $page;
444
+    }
445
+
446
+    public static function setPageType (string $alias, string $page_type) {
447
+        Events::throwEvent("set_pagetype", array(
448
+            'alias' => &$alias,
449
+            'page_type' => &$page_type
450
+        ));
451
+
452
+        Database::getInstance()->execute("UPDATE `{praefix}pages` SET `page_type` = :page_type WHERE `alias` = :alias; ", array(
453
+            'alias' => $alias,
454
+            'page_type' => $page_type
455
+        ));
456
+
457
+        Cache::clear("pages");
458
+    }
459
+
460
+    /**
461
+     * get id of page by alias
462
+     *
463
+     * only use this method for database upgrade, because their is no caching for this method!
464
+     *
465
+     * @param string $alias alias of page
466
+     *
467
+     * @throws IllegalStateException if alias doesnt exists
468
+     *
469
+     * @return int pageID
470
+     */
471
+    public static function getPageIDByAlias (string $alias) : int {
472
+        $row = Database::getInstance()->getRow("SELECT * FROM `{praefix}pages` WHERE `alias` = :alias; ", array('alias' => $alias));
473
+
474
+        if (!$row) {
475
+            throw new IllegalStateException("page with alias '" . $alias . "' doesnt exists.");
476
+        }
477
+
478
+        return $row['id'];
479
+    }
480
+
481
+    public static function lockPage (int $pageID, int $userID) {
482
+        Database::getInstance()->execute("UPDATE `{praefix}pages` SET `locked_by` = :userID, `locked_timestamp` = CURRENT_TIMESTAMP WHERE `id` = :pageID; ", array(
483
+            'userID' => $userID,
484
+            'pageID' => $pageID
485
+        ));
486
+
487
+        //clear cache
488
+        Cache::clear("pages", "pageID_" . $pageID);
489
+    }
490
+
491
+    public static function unlockPage (int $pageID) {
492
+        Database::getInstance()->execute("UPDATE `{praefix}pages` SET `locked_by` = '-1' WHERE `id` = :pageID; ", array(
493
+            'pageID' => $pageID
494
+        ));
495
+
496
+        //clear cache
497
+        Cache::clear("pages", "pageID_" . $pageID);
498
+    }
499
+
500
+    protected static function movePageToTrash (int $pageID) {
501
+        Database::getInstance()->execute("UPDATE `{praefix}pages` SET `activated` = 2 WHERE `id` = :pageID; ", array(
502
+            'pageID' => $pageID
503
+        ));
504
+
505
+        //clear cache
506
+        Cache::clear("pages", "pageID_" . $pageID);
507
+    }
508
+
509
+    protected static function restorePage (int $pageID) {
510
+        Database::getInstance()->execute("UPDATE `{praefix}pages` SET `activated` = 1 WHERE `id` = :pageID; ", array(
511
+            'pageID' => $pageID
512
+        ));
513
+
514
+        //clear cache
515
+        Cache::clear("pages", "pageID_" . $pageID);
516
+    }
517
+
518
+    public static function exists (string $alias) : bool {
519
+        $row = Database::getInstance()->getRow("SELECT * FROM `{praefix}pages` WHERE `alias` = :alias; ", array(
520
+            'alias' => $alias
521
+        ));
522
+
523
+        return $row !== false;
524
+    }
525 525
 
526 526
 }
527 527
 
Please login to merge, or discard this patch.
Spacing   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
 		//
33 33
 	}
34 34
 
35
-	public function load ($alias = null) {
35
+	public function load($alias = null) {
36 36
 		if ($alias == null) {
37 37
 			if (isset($_REQUEST['page']) && !empty($_REQUEST['page'])) {
38 38
 				$alias = Validator_String::get($_REQUEST['page']);
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 		$this->pagetype = $this->row['page_type'];
89 89
 	}
90 90
 
91
-	public function loadByID (int $pageID, bool $use_cache = true) {
91
+	public function loadByID(int $pageID, bool $use_cache = true) {
92 92
 		if ($use_cache && Cache::contains("pages", "pageID_" . $pageID)) {
93 93
 			$this->row = Cache::get("pages", "pageID_" . $pageID);
94 94
 		} else {
@@ -111,135 +111,135 @@  discard block
 block discarded – undo
111 111
 		$this->pagetype = $this->row['page_type'];
112 112
 	}
113 113
 
114
-	protected function getDomain () : Domain {
114
+	protected function getDomain() : Domain {
115 115
 		return Registry::singleton()->getObject("domain");
116 116
 	}
117 117
 
118
-	public function reloadCache () {
118
+	public function reloadCache() {
119 119
 		Cache::clear("pages");
120 120
 	}
121 121
 
122
-	public function getPageID () : int {
122
+	public function getPageID() : int {
123 123
 		return $this->row['id'];
124 124
 	}
125 125
 
126
-	public function getAlias () : string {
126
+	public function getAlias() : string {
127 127
 		return $this->alias;
128 128
 	}
129 129
 
130
-	public function getPageType () : string {
130
+	public function getPageType() : string {
131 131
 		return $this->pagetype;
132 132
 	}
133 133
 
134
-	public function getTitle () : string {
134
+	public function getTitle() : string {
135 135
 		return $this->row['title'];
136 136
 	}
137 137
 
138
-	public function setTitle (string $title) {
138
+	public function setTitle(string $title) {
139 139
 		$this->row['title'] = $title;
140 140
 		$this->changes[] = "title";
141 141
 	}
142 142
 
143
-	public function getContent () : string {
143
+	public function getContent() : string {
144 144
 		return $this->row['content'];
145 145
 	}
146 146
 
147
-	public function setContent (string $content) {
147
+	public function setContent(string $content) {
148 148
 		$this->row['content'] = $content;
149 149
 		$this->changes[] = "content";
150 150
 		$this->changes[] = "content";
151 151
 	}
152 152
 
153
-	public function getGlobalMenuID () : int {
153
+	public function getGlobalMenuID() : int {
154 154
 		return $this->row['global_menu'];
155 155
 	}
156 156
 
157
-	public function getLocalMenuID () : int {
157
+	public function getLocalMenuID() : int {
158 158
 		return $this->row['local_menu'];
159 159
 	}
160 160
 
161
-	public function getStyle () : string {
161
+	public function getStyle() : string {
162 162
 		return $this->row['design'];
163 163
 	}
164 164
 
165
-	public function getFolder () : string {
165
+	public function getFolder() : string {
166 166
 		return $this->row['folder'];
167 167
 	}
168 168
 
169
-	public function getLastEdit () {
169
+	public function getLastEdit() {
170 170
 		return $this->row['lastUpdate'];
171 171
 	}
172 172
 
173
-	public function hasCustomTemplate () : bool {
173
+	public function hasCustomTemplate() : bool {
174 174
 		return $this->row['template'] !== "none";
175 175
 	}
176 176
 
177
-	public function getCustomTemplate () : string {
177
+	public function getCustomTemplate() : string {
178 178
 		return $this->row['template'];
179 179
 	}
180 180
 
181
-	public function hasCustomPermissions () : bool {
181
+	public function hasCustomPermissions() : bool {
182 182
 		return $this->row['can_see_permissions'] !== "none";
183 183
 	}
184 184
 
185
-	public function listCustomPermissions () : array {
185
+	public function listCustomPermissions() : array {
186 186
 		return explode("|", $this->row['can_see_permissions']);
187 187
 	}
188 188
 
189
-	public function isPublished () : bool {
189
+	public function isPublished() : bool {
190 190
 		return $this->row['published'] == 1;
191 191
 	}
192 192
 
193
-	public function publish () {
193
+	public function publish() {
194 194
 		$this->row['published'] = 1;
195 195
 		$this->changes[] = "published";
196 196
 	}
197 197
 
198
-	public function getContentType () : string {
198
+	public function getContentType() : string {
199 199
 		return $this->row['content_type'];
200 200
 	}
201 201
 
202
-	public function getParentID () : int {
202
+	public function getParentID() : int {
203 203
 		return $this->row['parent'];
204 204
 	}
205 205
 
206
-	public function getLeftSidebarID () : int {
206
+	public function getLeftSidebarID() : int {
207 207
 		return $this->row['sidebar_left'];
208 208
 	}
209 209
 
210
-	public function getRightSidebarID () : int {
210
+	public function getRightSidebarID() : int {
211 211
 		return $this->row['sidebar_right'];
212 212
 	}
213 213
 
214
-	public function getMetaDescription () : string {
214
+	public function getMetaDescription() : string {
215 215
 		return $this->row['meta_description'];
216 216
 	}
217 217
 
218
-	public function getMetaKeywords () : string {
218
+	public function getMetaKeywords() : string {
219 219
 		return $this->row['meta_keywords'];
220 220
 	}
221 221
 
222
-	public function getMetaRobotsOptions () : string {
222
+	public function getMetaRobotsOptions() : string {
223 223
 		return $this->row['meta_robots'];
224 224
 	}
225 225
 
226
-	public function getMetaCanonicals () : string {
226
+	public function getMetaCanonicals() : string {
227 227
 		return $this->row['meta_canonicals'];
228 228
 	}
229 229
 
230
-	public function getOgType () : string {
230
+	public function getOgType() : string {
231 231
 		return $this->row['og_type'];
232 232
 	}
233 233
 
234
-	public function getOgTitle () : string {
234
+	public function getOgTitle() : string {
235 235
 		return !empty($this->row['og_title']) ? $this->row['og_title'] : $this->getTitle();
236 236
 	}
237 237
 
238
-	public function getOgDescription () : string {
238
+	public function getOgDescription() : string {
239 239
 		return !empty($this->row['og_description']) ? $this->row['og_description'] : $this->getMetaDescription();
240 240
 	}
241 241
 
242
-	public function getOgImages () : array {
242
+	public function getOgImages() : array {
243 243
 		if (empty($this->row['og_image'])) {
244 244
 			return array();
245 245
 		}
@@ -247,11 +247,11 @@  discard block
 block discarded – undo
247 247
 		return explode(",", $this->row['og_image']);
248 248
 	}
249 249
 
250
-	public function getAuthorID () : int {
250
+	public function getAuthorID() : int {
251 251
 		return $this->row['author'];
252 252
 	}
253 253
 
254
-	public function getAuthor () : User {
254
+	public function getAuthor() : User {
255 255
 		if ($this->author == null) {
256 256
 			//load author
257 257
 			$this->author = new User();
@@ -266,39 +266,39 @@  discard block
 block discarded – undo
266 266
 		return $this->author;
267 267
 	}
268 268
 
269
-	public function isSitemapEnabled () : bool {
269
+	public function isSitemapEnabled() : bool {
270 270
 		return $this->row['sitemap'] == 1;
271 271
 	}
272 272
 
273
-	public function getSitemapChangeFreq () : string {
273
+	public function getSitemapChangeFreq() : string {
274 274
 		return $this->row['sitemap_changefreq'];
275 275
 	}
276 276
 
277
-	public function getSitemapPriority () : string {
277
+	public function getSitemapPriority() : string {
278 278
 		return $this->row['sitemap_priority'];
279 279
 	}
280 280
 
281
-	public function activate (bool $bool = true) {
281
+	public function activate(bool $bool = true) {
282 282
 		$this->row['activated'] = ($bool ? 1 : 0);
283 283
 	}
284 284
 
285
-	public function isTrash () : bool {
285
+	public function isTrash() : bool {
286 286
 		return $this->row['activated'] == 2;
287 287
 	}
288 288
 
289
-	public function isEditable () : bool {
289
+	public function isEditable() : bool {
290 290
 		return $this->row['editable'] == 1;
291 291
 	}
292 292
 
293
-	public function isDeletable () : bool {
293
+	public function isDeletable() : bool {
294 294
 		return $this->row['deletable'] == 1;
295 295
 	}
296 296
 
297
-	public function isActivated () : bool {
297
+	public function isActivated() : bool {
298 298
 		return $this->row['activated'] == 1;
299 299
 	}
300 300
 
301
-	public function moveToTrash () {
301
+	public function moveToTrash() {
302 302
 		self::movePageToTrash($this->pageID);
303 303
 
304 304
 		//clear cache
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
 	/**
309 309
 	 * restore page from trash
310 310
 	 */
311
-	public function restore () {
311
+	public function restore() {
312 312
 		self::restorePage($this->pageID);
313 313
 
314 314
 		//clear cache
@@ -318,11 +318,11 @@  discard block
 block discarded – undo
318 318
 	/**
319 319
 	 * save changes into database
320 320
 	 */
321
-	public function save () {
321
+	public function save() {
322 322
 		//TODO: add code here
323 323
 	}
324 324
 
325
-	public function clearCache () {
325
+	public function clearCache() {
326 326
 		if (!is_int($this->getPageID())) {
327 327
 			throw new IllegalStateException("pageID isn't set.");
328 328
 		}
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
 		Cache::clear("pages", "page_" . $this->getAlias());
333 333
 	}
334 334
 
335
-	public static function createIfAbsent (string $alias, string $title, string $page_type, string $content = "", string $folder = "/", int $globalMenu = -1, int $localMenu = -1, int $parentID = -1, bool $sitemap = true, bool $published = true, bool $editable = true, bool $deletable = true, string $author = "system") : int {
335
+	public static function createIfAbsent(string $alias, string $title, string $page_type, string $content = "", string $folder = "/", int $globalMenu = -1, int $localMenu = -1, int $parentID = -1, bool $sitemap = true, bool $published = true, bool $editable = true, bool $deletable = true, string $author = "system") : int {
336 336
 		//throw event
337 337
 		Events::throwEvent("create_page", array(
338 338
 			'alias' => &$alias,
@@ -402,7 +402,7 @@  discard block
 block discarded – undo
402 402
 		return $pageID;
403 403
 	}
404 404
 
405
-	public static function delete (string $alias) {
405
+	public static function delete(string $alias) {
406 406
 		$delete = true;
407 407
 
408 408
 		//plugins can avoid deletion or change alias
@@ -419,7 +419,7 @@  discard block
 block discarded – undo
419 419
 		}
420 420
 	}
421 421
 
422
-	public static function deleteByID (int $id) {
422
+	public static function deleteByID(int $id) {
423 423
 		$delete = true;
424 424
 
425 425
 		//plugins can avoid deletion or change alias
@@ -436,14 +436,14 @@  discard block
 block discarded – undo
436 436
 		}
437 437
 	}
438 438
 
439
-	public static function get (string $alias) : Page {
439
+	public static function get(string $alias) : Page {
440 440
 		$page = new Page();
441 441
 		$page->load($alias);
442 442
 
443 443
 		return $page;
444 444
 	}
445 445
 
446
-	public static function setPageType (string $alias, string $page_type) {
446
+	public static function setPageType(string $alias, string $page_type) {
447 447
 		Events::throwEvent("set_pagetype", array(
448 448
 			'alias' => &$alias,
449 449
 			'page_type' => &$page_type
@@ -468,7 +468,7 @@  discard block
 block discarded – undo
468 468
 	 *
469 469
 	 * @return int pageID
470 470
 	 */
471
-	public static function getPageIDByAlias (string $alias) : int {
471
+	public static function getPageIDByAlias(string $alias) : int {
472 472
 		$row = Database::getInstance()->getRow("SELECT * FROM `{praefix}pages` WHERE `alias` = :alias; ", array('alias' => $alias));
473 473
 
474 474
 		if (!$row) {
@@ -478,7 +478,7 @@  discard block
 block discarded – undo
478 478
 		return $row['id'];
479 479
 	}
480 480
 
481
-	public static function lockPage (int $pageID, int $userID) {
481
+	public static function lockPage(int $pageID, int $userID) {
482 482
 		Database::getInstance()->execute("UPDATE `{praefix}pages` SET `locked_by` = :userID, `locked_timestamp` = CURRENT_TIMESTAMP WHERE `id` = :pageID; ", array(
483 483
 			'userID' => $userID,
484 484
 			'pageID' => $pageID
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
 		Cache::clear("pages", "pageID_" . $pageID);
489 489
 	}
490 490
 
491
-	public static function unlockPage (int $pageID) {
491
+	public static function unlockPage(int $pageID) {
492 492
 		Database::getInstance()->execute("UPDATE `{praefix}pages` SET `locked_by` = '-1' WHERE `id` = :pageID; ", array(
493 493
 			'pageID' => $pageID
494 494
 		));
@@ -497,7 +497,7 @@  discard block
 block discarded – undo
497 497
 		Cache::clear("pages", "pageID_" . $pageID);
498 498
 	}
499 499
 
500
-	protected static function movePageToTrash (int $pageID) {
500
+	protected static function movePageToTrash(int $pageID) {
501 501
 		Database::getInstance()->execute("UPDATE `{praefix}pages` SET `activated` = 2 WHERE `id` = :pageID; ", array(
502 502
 			'pageID' => $pageID
503 503
 		));
@@ -506,7 +506,7 @@  discard block
 block discarded – undo
506 506
 		Cache::clear("pages", "pageID_" . $pageID);
507 507
 	}
508 508
 
509
-	protected static function restorePage (int $pageID) {
509
+	protected static function restorePage(int $pageID) {
510 510
 		Database::getInstance()->execute("UPDATE `{praefix}pages` SET `activated` = 1 WHERE `id` = :pageID; ", array(
511 511
 			'pageID' => $pageID
512 512
 		));
@@ -515,7 +515,7 @@  discard block
 block discarded – undo
515 515
 		Cache::clear("pages", "pageID_" . $pageID);
516 516
 	}
517 517
 
518
-	public static function exists (string $alias) : bool {
518
+	public static function exists(string $alias) : bool {
519 519
 		$row = Database::getInstance()->getRow("SELECT * FROM `{praefix}pages` WHERE `alias` = :alias; ", array(
520 520
 			'alias' => $alias
521 521
 		));
Please login to merge, or discard this patch.