Completed
Push — master ( 2c1eb1...6e4c54 )
by Justin
03:16
created
system/packages/com.jukusoft.cms.admin/classes/pageeditpage.php 1 patch
Indentation   +248 added lines, -248 removed lines patch added patch discarded remove patch
@@ -27,262 +27,262 @@  discard block
 block discarded – undo
27 27
 
28 28
 class PageEditPage extends PageType {
29 29
 
30
-	public function getContent(): string {
31
-		$template = new DwooTemplate("pages/editpage");
32
-
33
-		//check, if pageID is set
34
-		if (!isset($_REQUEST['edit']) || empty($_REQUEST['edit'])) {
35
-			//show error
36
-			return $this->showError("No pageID was set!");
37
-		}
38
-
39
-		$pageID = (int) $_REQUEST['edit'];
40
-
41
-		$page = new Page();
42
-		$page->loadByID($pageID);
43
-
44
-		//first check permissions
45
-		if (!PermissionChecker::current()->hasRight("can_edit_all_pages") && !(PermissionChecker::current()->hasRight("can_edit_own_pages") && $page->getAuthorID() == User::current()->getID())) {
46
-			//user doesn't have permissions to edit this page
47
-			return $this->showError("You don't have permissions to edit this page!");
48
-		}
49
-
50
-		//first, lock page
51
-		Page::lockPage($page->getPageID(), User::current()->getID());
52
-
53
-		$success_messages = array();
54
-		$error_messages = array();
55
-
56
-		//save page
57
-		if (isset($_REQUEST['submit'])) {
58
-			if ($_REQUEST['submit'] === "Save") {
59
-				//save page
60
-				$res = $this->save($page);
61
-
62
-				if ($res === true) {
63
-					$success_messages[] = "Saved page successfully!";
64
-				} else {
65
-					$error_messages[] = $res;
66
-				}
67
-			} else if ($_REQUEST['submit'] === "SaveUnlock") {
68
-				//save page
69
-				$res = $this->save($page);
70
-
71
-				if ($res === true) {
72
-					//unlock page
73
-					Page::unlockPage($page->getPageID());
74
-
75
-					//redirect to admin/pages
76
-					header("Location: " . DomainUtils::generateURL("admin/pages"));
77
-
78
-					ob_flush();
79
-					ob_end_flush();
80
-
81
-					exit;
82
-				} else {
83
-					$error_messages[] = $res;
84
-				}
85
-			} else if ($_REQUEST['submit'] === "Publish") {
86
-				//save page
87
-				$res = $this->save($page);
88
-
89
-				if ($res === true) {
90
-					$success_messages[] = "Saved page successfully!";
91
-				} else {
92
-					$error_messages[] = $res;
93
-				}
94
-
95
-				//publish page
96
-				$res = $this->publish($page);
97
-
98
-				if ($res === true) {
99
-					$success_messages[] = "Page published successfully!";
100
-				} else {
101
-					$error_messages[] = $res;
102
-				}
103
-			}
104
-		}
105
-
106
-		$template->assign("action_url", DomainUtils::generateURL($this->getPage()->getAlias(), array("edit" => $pageID)));
107
-
108
-		$template->assign("page", array(
109
-			'id' => $page->getPageID(),
110
-			'alias' => "/" . $page->getAlias(),
111
-			'title' => $page->getTitle(),
112
-			'content' => $page->getContent(),
113
-			'is_published' => $page->isPublished(),
114
-			'can_publish' => (!$page->isPublished() && (PermissionChecker::current()->hasRight("can_publish_all_pages") || (PermissionChecker::current()->hasRight("can_publish_own_pages") && $page->getAuthorID() == User::current()->getID()))),
115
-			'can_change_owner' => (PermissionChecker::current()->hasRight("can_change_page_owner") || $page->getAuthorID() == User::current()->getID()),
116
-			'folder' => $page->getFolder(),
117
-			'preview_url' => DomainUtils::generateURL($page->getAlias(), array("preview" => "true")),
118
-			'current_style' => $page->getStyle(),
119
-			'template' => $page->getCustomTemplate(),
120
-			'has_custom_template' => $page->hasCustomTemplate(),
121
-			'parent' => $page->getParentID(),
122
-			'meta_description' => $page->getMetaDescription(),
123
-			'meta_keywords' => $page->getMetaKeywords(),
124
-			'meta_robots' => $page->getMetaRobotsOptions(),
125
-			'meta_canonicals' => $page->getMetaCanonicals(),
126
-			'has_canoncials' => !empty($page->getMetaCanonicals()),
127
-			'sitemap' => $page->isSitemapEnabled()
128
-		));
129
-
130
-		//set available styles
131
-		$template->assign("styles", StyleController::listAllStyles());
132
-
133
-		//get all pages from database
134
-		$pages = array();
135
-		$rows = Database::getInstance()->listRows("SELECT `id`, `alias` FROM `{praefix}pages` WHERE `editable` = '1' AND `activated` = '1'; ");
136
-
137
-		foreach ($rows as $row) {
138
-			$pages[] = array(
139
-				'id' => $row['id'],
140
-				'alias' => $row['alias']
141
-			);
142
-		}
143
-
144
-		$template->assign("parent_pages", $pages);
145
-
146
-		//https://developers.google.com/search/reference/robots_meta_tag?hl=de
147
-		$robots_options = array(
148
-			"all",
149
-			"noindex",
150
-			"nofollow",
151
-			"none",
152
-			"noarchive",
153
-			"nosnippet",
154
-			"noodp",
155
-			"notranslate",
156
-			"noimageindex",
157
-			"unavailable_after: "
158
-		);
159
-
160
-		$template->assign("robots_options", $robots_options);
161
-
162
-		//add support to show additional code from plugins
163
-		$additional_code_header = "";
164
-		$additional_code_footer = "";
165
-
166
-		Events::throwEvent("page_edit_additional_code_header", array(
167
-			'page' => &$page,
168
-			'code' => &$additional_code_header
169
-		));
170
-
171
-		$template->assign("additional_code_header", $additional_code_footer);
172
-
173
-		Events::throwEvent("page_edit_additional_code_footer", array(
174
-			'page' => &$page,
175
-			'code' => &$additional_code_footer
176
-		));
177
-
178
-		$template->assign("additional_code_footer", $additional_code_footer);
179
-
180
-		$template->assign("errors", $error_messages);
181
-		$template->assign("success_messages", $success_messages);
182
-
183
-		return $template->getCode();
184
-	}
185
-
186
-	protected function save (Page &$page) {
187
-		//first check permissions
188
-		if (!PermissionChecker::current()->hasRight("can_edit_all_pages") && !(PermissionChecker::current()->hasRight("can_edit_own_pages") && $page->getAuthorID() == User::current()->getID())) {
189
-			//user doesn't have permissions to edit this page
190
-			return "You don't have permissions to edit this page!";
191
-		}
192
-
193
-		if (!isset($_POST['title']) || empty($_POST['title'])) {
194
-			return "No title was set";
195
-		}
196
-
197
-		//validate title
198
-		$title = htmlentities($_POST['title']);
199
-
200
-		if (!isset($_POST['html_code']) || empty($_POST['html_code'])) {
201
-			return "No content was set or content is empty!";
202
-		}
203
-
204
-		$content = $_POST['html_code'];
205
-
206
-		//TODO: save page attributes
207
-		if (!isset($_REQUEST['parent']) || empty($_REQUEST['parent'])) {
208
-			return "Parent page wasn't set!";
209
-		}
210
-
211
-		$parent = (int) $_REQUEST['parent'];
212
-
213
-		if (!isset($_REQUEST['design']) || empty($_REQUEST['design'])) {
214
-			return "Design wasn't set!";
215
-		}
216
-
217
-		$design = $_REQUEST['design'];
218
-
219
-		//TODO: check, if style (design) exists
220
-
221
-		$template = "none";
222
-
223
-		if (isset($_REQUEST['has_custom_template']) && isset($_REQUEST['template']) && !empty($_REQUEST['template'])) {
224
-			$template = $_REQUEST['template'];
225
-		}
226
-
227
-		//update page in database
228
-		Database::getInstance()->execute("UPDATE `{praefix}pages` SET `title` = :title, `content` = :content, `parent` = :parent, `design` = :design, `template` = :template WHERE `id` = :pageID; ", array(
229
-			'title' => $title,
230
-			'content' => $content,
231
-			'pageID' => $page->getPageID(),
232
-			'parent' => $parent,
233
-			'design' => $design,
234
-			'template' => $template
235
-		));
30
+    public function getContent(): string {
31
+        $template = new DwooTemplate("pages/editpage");
32
+
33
+        //check, if pageID is set
34
+        if (!isset($_REQUEST['edit']) || empty($_REQUEST['edit'])) {
35
+            //show error
36
+            return $this->showError("No pageID was set!");
37
+        }
38
+
39
+        $pageID = (int) $_REQUEST['edit'];
40
+
41
+        $page = new Page();
42
+        $page->loadByID($pageID);
43
+
44
+        //first check permissions
45
+        if (!PermissionChecker::current()->hasRight("can_edit_all_pages") && !(PermissionChecker::current()->hasRight("can_edit_own_pages") && $page->getAuthorID() == User::current()->getID())) {
46
+            //user doesn't have permissions to edit this page
47
+            return $this->showError("You don't have permissions to edit this page!");
48
+        }
49
+
50
+        //first, lock page
51
+        Page::lockPage($page->getPageID(), User::current()->getID());
52
+
53
+        $success_messages = array();
54
+        $error_messages = array();
55
+
56
+        //save page
57
+        if (isset($_REQUEST['submit'])) {
58
+            if ($_REQUEST['submit'] === "Save") {
59
+                //save page
60
+                $res = $this->save($page);
61
+
62
+                if ($res === true) {
63
+                    $success_messages[] = "Saved page successfully!";
64
+                } else {
65
+                    $error_messages[] = $res;
66
+                }
67
+            } else if ($_REQUEST['submit'] === "SaveUnlock") {
68
+                //save page
69
+                $res = $this->save($page);
70
+
71
+                if ($res === true) {
72
+                    //unlock page
73
+                    Page::unlockPage($page->getPageID());
74
+
75
+                    //redirect to admin/pages
76
+                    header("Location: " . DomainUtils::generateURL("admin/pages"));
77
+
78
+                    ob_flush();
79
+                    ob_end_flush();
80
+
81
+                    exit;
82
+                } else {
83
+                    $error_messages[] = $res;
84
+                }
85
+            } else if ($_REQUEST['submit'] === "Publish") {
86
+                //save page
87
+                $res = $this->save($page);
88
+
89
+                if ($res === true) {
90
+                    $success_messages[] = "Saved page successfully!";
91
+                } else {
92
+                    $error_messages[] = $res;
93
+                }
94
+
95
+                //publish page
96
+                $res = $this->publish($page);
97
+
98
+                if ($res === true) {
99
+                    $success_messages[] = "Page published successfully!";
100
+                } else {
101
+                    $error_messages[] = $res;
102
+                }
103
+            }
104
+        }
105
+
106
+        $template->assign("action_url", DomainUtils::generateURL($this->getPage()->getAlias(), array("edit" => $pageID)));
107
+
108
+        $template->assign("page", array(
109
+            'id' => $page->getPageID(),
110
+            'alias' => "/" . $page->getAlias(),
111
+            'title' => $page->getTitle(),
112
+            'content' => $page->getContent(),
113
+            'is_published' => $page->isPublished(),
114
+            'can_publish' => (!$page->isPublished() && (PermissionChecker::current()->hasRight("can_publish_all_pages") || (PermissionChecker::current()->hasRight("can_publish_own_pages") && $page->getAuthorID() == User::current()->getID()))),
115
+            'can_change_owner' => (PermissionChecker::current()->hasRight("can_change_page_owner") || $page->getAuthorID() == User::current()->getID()),
116
+            'folder' => $page->getFolder(),
117
+            'preview_url' => DomainUtils::generateURL($page->getAlias(), array("preview" => "true")),
118
+            'current_style' => $page->getStyle(),
119
+            'template' => $page->getCustomTemplate(),
120
+            'has_custom_template' => $page->hasCustomTemplate(),
121
+            'parent' => $page->getParentID(),
122
+            'meta_description' => $page->getMetaDescription(),
123
+            'meta_keywords' => $page->getMetaKeywords(),
124
+            'meta_robots' => $page->getMetaRobotsOptions(),
125
+            'meta_canonicals' => $page->getMetaCanonicals(),
126
+            'has_canoncials' => !empty($page->getMetaCanonicals()),
127
+            'sitemap' => $page->isSitemapEnabled()
128
+        ));
129
+
130
+        //set available styles
131
+        $template->assign("styles", StyleController::listAllStyles());
132
+
133
+        //get all pages from database
134
+        $pages = array();
135
+        $rows = Database::getInstance()->listRows("SELECT `id`, `alias` FROM `{praefix}pages` WHERE `editable` = '1' AND `activated` = '1'; ");
136
+
137
+        foreach ($rows as $row) {
138
+            $pages[] = array(
139
+                'id' => $row['id'],
140
+                'alias' => $row['alias']
141
+            );
142
+        }
143
+
144
+        $template->assign("parent_pages", $pages);
145
+
146
+        //https://developers.google.com/search/reference/robots_meta_tag?hl=de
147
+        $robots_options = array(
148
+            "all",
149
+            "noindex",
150
+            "nofollow",
151
+            "none",
152
+            "noarchive",
153
+            "nosnippet",
154
+            "noodp",
155
+            "notranslate",
156
+            "noimageindex",
157
+            "unavailable_after: "
158
+        );
159
+
160
+        $template->assign("robots_options", $robots_options);
161
+
162
+        //add support to show additional code from plugins
163
+        $additional_code_header = "";
164
+        $additional_code_footer = "";
165
+
166
+        Events::throwEvent("page_edit_additional_code_header", array(
167
+            'page' => &$page,
168
+            'code' => &$additional_code_header
169
+        ));
170
+
171
+        $template->assign("additional_code_header", $additional_code_footer);
172
+
173
+        Events::throwEvent("page_edit_additional_code_footer", array(
174
+            'page' => &$page,
175
+            'code' => &$additional_code_footer
176
+        ));
177
+
178
+        $template->assign("additional_code_footer", $additional_code_footer);
179
+
180
+        $template->assign("errors", $error_messages);
181
+        $template->assign("success_messages", $success_messages);
182
+
183
+        return $template->getCode();
184
+    }
185
+
186
+    protected function save (Page &$page) {
187
+        //first check permissions
188
+        if (!PermissionChecker::current()->hasRight("can_edit_all_pages") && !(PermissionChecker::current()->hasRight("can_edit_own_pages") && $page->getAuthorID() == User::current()->getID())) {
189
+            //user doesn't have permissions to edit this page
190
+            return "You don't have permissions to edit this page!";
191
+        }
192
+
193
+        if (!isset($_POST['title']) || empty($_POST['title'])) {
194
+            return "No title was set";
195
+        }
196
+
197
+        //validate title
198
+        $title = htmlentities($_POST['title']);
199
+
200
+        if (!isset($_POST['html_code']) || empty($_POST['html_code'])) {
201
+            return "No content was set or content is empty!";
202
+        }
203
+
204
+        $content = $_POST['html_code'];
205
+
206
+        //TODO: save page attributes
207
+        if (!isset($_REQUEST['parent']) || empty($_REQUEST['parent'])) {
208
+            return "Parent page wasn't set!";
209
+        }
210
+
211
+        $parent = (int) $_REQUEST['parent'];
212
+
213
+        if (!isset($_REQUEST['design']) || empty($_REQUEST['design'])) {
214
+            return "Design wasn't set!";
215
+        }
216
+
217
+        $design = $_REQUEST['design'];
218
+
219
+        //TODO: check, if style (design) exists
220
+
221
+        $template = "none";
222
+
223
+        if (isset($_REQUEST['has_custom_template']) && isset($_REQUEST['template']) && !empty($_REQUEST['template'])) {
224
+            $template = $_REQUEST['template'];
225
+        }
226
+
227
+        //update page in database
228
+        Database::getInstance()->execute("UPDATE `{praefix}pages` SET `title` = :title, `content` = :content, `parent` = :parent, `design` = :design, `template` = :template WHERE `id` = :pageID; ", array(
229
+            'title' => $title,
230
+            'content' => $content,
231
+            'pageID' => $page->getPageID(),
232
+            'parent' => $parent,
233
+            'design' => $design,
234
+            'template' => $template
235
+        ));
236 236
 
237
-		//clear cache
238
-		$page->clearCache();
237
+        //clear cache
238
+        $page->clearCache();
239 239
 
240
-		//reload page from database
241
-		$page->loadByID($page->getPageID(), false);
240
+        //reload page from database
241
+        $page->loadByID($page->getPageID(), false);
242 242
 
243
-		//TODO: remove this line later
244
-		Cache::clear("pages");
243
+        //TODO: remove this line later
244
+        Cache::clear("pages");
245 245
 
246
-		return true;
247
-	}
246
+        return true;
247
+    }
248 248
 
249
-	protected function publish (Page &$page) {
250
-		//check permissions for publishing
251
-		if (PermissionChecker::current()->hasRight("can_publish_all_pages") || (PermissionChecker::current()->hasRight("can_publish_own_pages") && $page->getAuthorID() == User::current()->getID())) {
252
-			//update page in database
253
-			Database::getInstance()->execute("UPDATE `{praefix}pages` SET `published` = '1' WHERE `id` = :pageID; ", array(
254
-				'pageID' => $page->getPageID()
255
-			));
249
+    protected function publish (Page &$page) {
250
+        //check permissions for publishing
251
+        if (PermissionChecker::current()->hasRight("can_publish_all_pages") || (PermissionChecker::current()->hasRight("can_publish_own_pages") && $page->getAuthorID() == User::current()->getID())) {
252
+            //update page in database
253
+            Database::getInstance()->execute("UPDATE `{praefix}pages` SET `published` = '1' WHERE `id` = :pageID; ", array(
254
+                'pageID' => $page->getPageID()
255
+            ));
256 256
 
257
-			//clear cache
258
-			$page->clearCache();
257
+            //clear cache
258
+            $page->clearCache();
259 259
 
260
-			//reload page from database
261
-			$page->loadByID($page->getPageID(), false);
260
+            //reload page from database
261
+            $page->loadByID($page->getPageID(), false);
262 262
 
263
-			//TODO: remove this line later
264
-			Cache::clear("pages");
263
+            //TODO: remove this line later
264
+            Cache::clear("pages");
265 265
 
266
-			return true;
267
-		} else {
268
-			return "You don't have the permissions to publish this page!";
269
-		}
270
-	}
266
+            return true;
267
+        } else {
268
+            return "You don't have the permissions to publish this page!";
269
+        }
270
+    }
271 271
 
272
-	protected function showError (string $message) : string {
273
-		//show error
274
-		$template = new DwooTemplate("pages/error");
275
-		$template->assign("message", "No pageID was set!");
276
-		return $template->getCode();
277
-	}
272
+    protected function showError (string $message) : string {
273
+        //show error
274
+        $template = new DwooTemplate("pages/error");
275
+        $template->assign("message", "No pageID was set!");
276
+        return $template->getCode();
277
+    }
278 278
 
279
-	public function getFooterScripts(): string {
280
-		$style_name = Registry::singleton()->getSetting("current_style_name");
281
-		$style_path = DomainUtils::getBaseURL() . "/styles/" . $style_name . "/";
279
+    public function getFooterScripts(): string {
280
+        $style_name = Registry::singleton()->getSetting("current_style_name");
281
+        $style_path = DomainUtils::getBaseURL() . "/styles/" . $style_name . "/";
282 282
 
283
-		$thirdparty_url = Registry::singleton()->getSetting("thirdparty_url");
283
+        $thirdparty_url = Registry::singleton()->getSetting("thirdparty_url");
284 284
 
285
-		/*return "<!-- CK Editor -->
285
+        /*return "<!-- CK Editor -->
286 286
 			<script src=\"" . $style_path . "bower_components/ckeditor/ckeditor.js\"></script>
287 287
 			
288 288
 			<script>
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
 				});
297 297
 			</script>";*/
298 298
 
299
-		return "<script src=\"" . $thirdparty_url . "tinymce_4.8.2/js/tinymce/tinymce.min.js\"></script>
299
+        return "<script src=\"" . $thirdparty_url . "tinymce_4.8.2/js/tinymce/tinymce.min.js\"></script>
300 300
   				<script>tinymce.init({
301 301
 					  selector: 'textarea',
302 302
 					  height: 500,
@@ -323,11 +323,11 @@  discard block
 block discarded – undo
323 323
 					}
324 324
 				};
325 325
 				</script>";
326
-	}
326
+    }
327 327
 
328
-	public function listRequiredPermissions(): array {
329
-		return array("can_edit_all_pages", "can_edit_own_pages");
330
-	}
328
+    public function listRequiredPermissions(): array {
329
+        return array("can_edit_all_pages", "can_edit_own_pages");
330
+    }
331 331
 
332 332
 }
333 333
 
Please login to merge, or discard this patch.
system/packages/com.jukusoft.cms.page/classes/page.php 1 patch
Indentation   +481 added lines, -481 removed lines patch added patch discarded remove patch
@@ -18,502 +18,502 @@
 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
-	}
213
-
214
-	public function getMetaDescription () : string {
215
-		return $this->row['meta_description'];
216
-	}
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 activate (bool $bool = true) {
274
-		$this->row['activated'] = ($bool ? 1 : 0);
275
-	}
276
-
277
-	public function isTrash () : bool {
278
-		return $this->row['activated'] == 2;
279
-	}
280
-
281
-	public function isEditable () : bool {
282
-		return $this->row['editable'] == 1;
283
-	}
284
-
285
-	public function isDeletable () : bool {
286
-		return $this->row['deletable'] == 1;
287
-	}
288
-
289
-	public function isActivated () : bool {
290
-		return $this->row['activated'] == 1;
291
-	}
292
-
293
-	public function moveToTrash () {
294
-		self::movePageToTrash($this->pageID);
295
-
296
-		//clear cache
297
-		$this->clearCache();
298
-	}
299
-
300
-	/**
301
-	 * restore page from trash
302
-	 */
303
-	public function restore () {
304
-		self::restorePage($this->pageID);
305
-
306
-		//clear cache
307
-		$this->clearCache();
308
-	}
309
-
310
-	/**
311
-	 * save changes into database
312
-	 */
313
-	public function save () {
314
-		//TODO: add code here
315
-	}
316
-
317
-	public function clearCache () {
318
-		if (!is_int($this->getPageID())) {
319
-			throw new IllegalStateException("pageID isn't set.");
320
-		}
321
-
322
-		//clear cache
323
-		Cache::clear("pages", "pageID_" . $this->getPageID());
324
-		Cache::clear("pages", "page_" . $this->getAlias());
325
-	}
326
-
327
-	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 {
328
-		//throw event
329
-		Events::throwEvent("create_page", array(
330
-			'alias' => &$alias,
331
-			'title' => &$title,
332
-			'page_type' => &$page_type,
333
-			'content' => &$content,
334
-			'folder' => &$folder,
335
-			'global_menu' => &$globalMenu,
336
-			'local_menu' => &$localMenu,
337
-			'parentID' => &$parentID,
338
-			'sitemap' => &$sitemap,
339
-			'published' => &$published,
340
-			'editable' => &$editable,
341
-			'author' => &$author
342
-		));
343
-
344
-		if (!is_int($author)) {
345
-			//get userID of author
346
-			$author = User::getIDByUsernameFromDB($author);
347
-
348
-			if ($author == -1) {
349
-				//username doesnt exists, so choose first user
350
-				$author = 1;
351
-			}
352
-		} else {
353
-			$author = (int) $author;
354
-		}
355
-
356
-		Database::getInstance()->execute("INSERT INTO `{praefix}pages` (
210
+    public function getRightSidebarID () : int {
211
+        return $this->row['sidebar_right'];
212
+    }
213
+
214
+    public function getMetaDescription () : string {
215
+        return $this->row['meta_description'];
216
+    }
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 activate (bool $bool = true) {
274
+        $this->row['activated'] = ($bool ? 1 : 0);
275
+    }
276
+
277
+    public function isTrash () : bool {
278
+        return $this->row['activated'] == 2;
279
+    }
280
+
281
+    public function isEditable () : bool {
282
+        return $this->row['editable'] == 1;
283
+    }
284
+
285
+    public function isDeletable () : bool {
286
+        return $this->row['deletable'] == 1;
287
+    }
288
+
289
+    public function isActivated () : bool {
290
+        return $this->row['activated'] == 1;
291
+    }
292
+
293
+    public function moveToTrash () {
294
+        self::movePageToTrash($this->pageID);
295
+
296
+        //clear cache
297
+        $this->clearCache();
298
+    }
299
+
300
+    /**
301
+     * restore page from trash
302
+     */
303
+    public function restore () {
304
+        self::restorePage($this->pageID);
305
+
306
+        //clear cache
307
+        $this->clearCache();
308
+    }
309
+
310
+    /**
311
+     * save changes into database
312
+     */
313
+    public function save () {
314
+        //TODO: add code here
315
+    }
316
+
317
+    public function clearCache () {
318
+        if (!is_int($this->getPageID())) {
319
+            throw new IllegalStateException("pageID isn't set.");
320
+        }
321
+
322
+        //clear cache
323
+        Cache::clear("pages", "pageID_" . $this->getPageID());
324
+        Cache::clear("pages", "page_" . $this->getAlias());
325
+    }
326
+
327
+    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 {
328
+        //throw event
329
+        Events::throwEvent("create_page", array(
330
+            'alias' => &$alias,
331
+            'title' => &$title,
332
+            'page_type' => &$page_type,
333
+            'content' => &$content,
334
+            'folder' => &$folder,
335
+            'global_menu' => &$globalMenu,
336
+            'local_menu' => &$localMenu,
337
+            'parentID' => &$parentID,
338
+            'sitemap' => &$sitemap,
339
+            'published' => &$published,
340
+            'editable' => &$editable,
341
+            'author' => &$author
342
+        ));
343
+
344
+        if (!is_int($author)) {
345
+            //get userID of author
346
+            $author = User::getIDByUsernameFromDB($author);
347
+
348
+            if ($author == -1) {
349
+                //username doesnt exists, so choose first user
350
+                $author = 1;
351
+            }
352
+        } else {
353
+            $author = (int) $author;
354
+        }
355
+
356
+        Database::getInstance()->execute("INSERT INTO `{praefix}pages` (
357 357
 			`id`, `alias`, `title`, `content`, `parent`, `folder`, `global_menu`, `local_menu`, `page_type`, `design`, `sitemap`, `published`, `version`, `last_update`, `created`, `editable`, `deletable`, `author`, `activated`
358 358
 		) VALUES (
359 359
 			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'
360 360
 		) ON DUPLICATE KEY UPDATE `alias` = :alias, `editable` = :editable, `deletable` = :deletable; ", array(
361
-			'alias' => $alias,
362
-			'title' => $title,
363
-			'content' => $content,
364
-			'parent' => $parentID,
365
-			'folder' => $folder,
366
-			'globalMenu' => $globalMenu,
367
-			'localMenu' => $localMenu,
368
-			'pageType' => $page_type,
369
-			'sitemap' => ($sitemap ? 1 : 0),
370
-			'published' => ($published ? 1 : 0),
371
-			'editable' => ($editable ? 1 : 0),
372
-			'deletable' => ($deletable ? 1 : 0),
373
-			'author' => $author
374
-		));
375
-
376
-		Cache::clear("pages");
377
-
378
-		//return page id
379
-		$insertID = Database::getInstance()->lastInsertId();
380
-
381
-		//throw event
382
-		Events::throwEvent("created_page", array(
383
-			'alias' => $alias,
384
-			'title' => $title,
385
-			'insertID' => $insertID
386
-		));
387
-
388
-		//get pageID by alias
389
-		$pageID = Page::getPageIDByAlias($alias);
390
-
391
-		//set default rights, allow page for administrators, registered users, guests and bots
392
-		PageRights::setDefaultAllowedGroups($pageID, array(1, 2, 3, 4));
393
-
394
-		return $pageID;
395
-	}
396
-
397
-	public static function delete (string $alias) {
398
-		$delete = true;
399
-
400
-		//plugins can avoid deletion or change alias
401
-		Events::throwEvent("delete_page_alias", array(
402
-			'alias' => &$alias,
403
-			'delete' => &$delete
404
-		));
405
-
406
-		if ($delete) {
407
-			//remove page from database
408
-			Database::getInstance()->execute("DELETE FROM `{praefix}pages` WHERE `alias` = :alias; ", array('alias' => $alias));
409
-
410
-			Cache::clear("pages");
411
-		}
412
-	}
413
-
414
-	public static function deleteByID (int $id) {
415
-		$delete = true;
416
-
417
-		//plugins can avoid deletion or change alias
418
-		Events::throwEvent("delete_page_id", array(
419
-			'alias' => &$id,
420
-			'delete' => &$delete
421
-		));
422
-
423
-		if ($delete) {
424
-			//remove page from database
425
-			Database::getInstance()->execute("DELETE FROM `{praefix}pages` WHERE `id` = :id; ", array('id' => $id));
426
-
427
-			Cache::clear("pages");
428
-		}
429
-	}
430
-
431
-	public static function get (string $alias) : Page {
432
-		$page = new Page();
433
-		$page->load($alias);
434
-
435
-		return $page;
436
-	}
437
-
438
-	public static function setPageType (string $alias, string $page_type) {
439
-		Events::throwEvent("set_pagetype", array(
440
-			'alias' => &$alias,
441
-			'page_type' => &$page_type
442
-		));
443
-
444
-		Database::getInstance()->execute("UPDATE `{praefix}pages` SET `page_type` = :page_type WHERE `alias` = :alias; ", array(
445
-			'alias' => $alias,
446
-			'page_type' => $page_type
447
-		));
448
-
449
-		Cache::clear("pages");
450
-	}
451
-
452
-	/**
453
-	 * get id of page by alias
454
-	 *
455
-	 * only use this method for database upgrade, because their is no caching for this method!
456
-	 *
457
-	 * @param string $alias alias of page
458
-	 *
459
-	 * @throws IllegalStateException if alias doesnt exists
460
-	 *
461
-	 * @return int pageID
462
-	 */
463
-	public static function getPageIDByAlias (string $alias) : int {
464
-		$row = Database::getInstance()->getRow("SELECT * FROM `{praefix}pages` WHERE `alias` = :alias; ", array('alias' => $alias));
465
-
466
-		if (!$row) {
467
-			throw new IllegalStateException("page with alias '" . $alias . "' doesnt exists.");
468
-		}
469
-
470
-		return $row['id'];
471
-	}
472
-
473
-	public static function lockPage (int $pageID, int $userID) {
474
-		Database::getInstance()->execute("UPDATE `{praefix}pages` SET `locked_by` = :userID, `locked_timestamp` = CURRENT_TIMESTAMP WHERE `id` = :pageID; ", array(
475
-			'userID' => $userID,
476
-			'pageID' => $pageID
477
-		));
478
-
479
-		//clear cache
480
-		Cache::clear("pages", "pageID_" . $pageID);
481
-	}
482
-
483
-	public static function unlockPage (int $pageID) {
484
-		Database::getInstance()->execute("UPDATE `{praefix}pages` SET `locked_by` = '-1' WHERE `id` = :pageID; ", array(
485
-			'pageID' => $pageID
486
-		));
487
-
488
-		//clear cache
489
-		Cache::clear("pages", "pageID_" . $pageID);
490
-	}
491
-
492
-	protected static function movePageToTrash (int $pageID) {
493
-		Database::getInstance()->execute("UPDATE `{praefix}pages` SET `activated` = 2 WHERE `id` = :pageID; ", array(
494
-			'pageID' => $pageID
495
-		));
496
-
497
-		//clear cache
498
-		Cache::clear("pages", "pageID_" . $pageID);
499
-	}
500
-
501
-	protected static function restorePage (int $pageID) {
502
-		Database::getInstance()->execute("UPDATE `{praefix}pages` SET `activated` = 1 WHERE `id` = :pageID; ", array(
503
-			'pageID' => $pageID
504
-		));
505
-
506
-		//clear cache
507
-		Cache::clear("pages", "pageID_" . $pageID);
508
-	}
509
-
510
-	public static function exists (string $alias) : bool {
511
-		$row = Database::getInstance()->getRow("SELECT * FROM `{praefix}pages` WHERE `alias` = :alias; ", array(
512
-			'alias' => $alias
513
-		));
514
-
515
-		return $row !== false;
516
-	}
361
+            'alias' => $alias,
362
+            'title' => $title,
363
+            'content' => $content,
364
+            'parent' => $parentID,
365
+            'folder' => $folder,
366
+            'globalMenu' => $globalMenu,
367
+            'localMenu' => $localMenu,
368
+            'pageType' => $page_type,
369
+            'sitemap' => ($sitemap ? 1 : 0),
370
+            'published' => ($published ? 1 : 0),
371
+            'editable' => ($editable ? 1 : 0),
372
+            'deletable' => ($deletable ? 1 : 0),
373
+            'author' => $author
374
+        ));
375
+
376
+        Cache::clear("pages");
377
+
378
+        //return page id
379
+        $insertID = Database::getInstance()->lastInsertId();
380
+
381
+        //throw event
382
+        Events::throwEvent("created_page", array(
383
+            'alias' => $alias,
384
+            'title' => $title,
385
+            'insertID' => $insertID
386
+        ));
387
+
388
+        //get pageID by alias
389
+        $pageID = Page::getPageIDByAlias($alias);
390
+
391
+        //set default rights, allow page for administrators, registered users, guests and bots
392
+        PageRights::setDefaultAllowedGroups($pageID, array(1, 2, 3, 4));
393
+
394
+        return $pageID;
395
+    }
396
+
397
+    public static function delete (string $alias) {
398
+        $delete = true;
399
+
400
+        //plugins can avoid deletion or change alias
401
+        Events::throwEvent("delete_page_alias", array(
402
+            'alias' => &$alias,
403
+            'delete' => &$delete
404
+        ));
405
+
406
+        if ($delete) {
407
+            //remove page from database
408
+            Database::getInstance()->execute("DELETE FROM `{praefix}pages` WHERE `alias` = :alias; ", array('alias' => $alias));
409
+
410
+            Cache::clear("pages");
411
+        }
412
+    }
413
+
414
+    public static function deleteByID (int $id) {
415
+        $delete = true;
416
+
417
+        //plugins can avoid deletion or change alias
418
+        Events::throwEvent("delete_page_id", array(
419
+            'alias' => &$id,
420
+            'delete' => &$delete
421
+        ));
422
+
423
+        if ($delete) {
424
+            //remove page from database
425
+            Database::getInstance()->execute("DELETE FROM `{praefix}pages` WHERE `id` = :id; ", array('id' => $id));
426
+
427
+            Cache::clear("pages");
428
+        }
429
+    }
430
+
431
+    public static function get (string $alias) : Page {
432
+        $page = new Page();
433
+        $page->load($alias);
434
+
435
+        return $page;
436
+    }
437
+
438
+    public static function setPageType (string $alias, string $page_type) {
439
+        Events::throwEvent("set_pagetype", array(
440
+            'alias' => &$alias,
441
+            'page_type' => &$page_type
442
+        ));
443
+
444
+        Database::getInstance()->execute("UPDATE `{praefix}pages` SET `page_type` = :page_type WHERE `alias` = :alias; ", array(
445
+            'alias' => $alias,
446
+            'page_type' => $page_type
447
+        ));
448
+
449
+        Cache::clear("pages");
450
+    }
451
+
452
+    /**
453
+     * get id of page by alias
454
+     *
455
+     * only use this method for database upgrade, because their is no caching for this method!
456
+     *
457
+     * @param string $alias alias of page
458
+     *
459
+     * @throws IllegalStateException if alias doesnt exists
460
+     *
461
+     * @return int pageID
462
+     */
463
+    public static function getPageIDByAlias (string $alias) : int {
464
+        $row = Database::getInstance()->getRow("SELECT * FROM `{praefix}pages` WHERE `alias` = :alias; ", array('alias' => $alias));
465
+
466
+        if (!$row) {
467
+            throw new IllegalStateException("page with alias '" . $alias . "' doesnt exists.");
468
+        }
469
+
470
+        return $row['id'];
471
+    }
472
+
473
+    public static function lockPage (int $pageID, int $userID) {
474
+        Database::getInstance()->execute("UPDATE `{praefix}pages` SET `locked_by` = :userID, `locked_timestamp` = CURRENT_TIMESTAMP WHERE `id` = :pageID; ", array(
475
+            'userID' => $userID,
476
+            'pageID' => $pageID
477
+        ));
478
+
479
+        //clear cache
480
+        Cache::clear("pages", "pageID_" . $pageID);
481
+    }
482
+
483
+    public static function unlockPage (int $pageID) {
484
+        Database::getInstance()->execute("UPDATE `{praefix}pages` SET `locked_by` = '-1' WHERE `id` = :pageID; ", array(
485
+            'pageID' => $pageID
486
+        ));
487
+
488
+        //clear cache
489
+        Cache::clear("pages", "pageID_" . $pageID);
490
+    }
491
+
492
+    protected static function movePageToTrash (int $pageID) {
493
+        Database::getInstance()->execute("UPDATE `{praefix}pages` SET `activated` = 2 WHERE `id` = :pageID; ", array(
494
+            'pageID' => $pageID
495
+        ));
496
+
497
+        //clear cache
498
+        Cache::clear("pages", "pageID_" . $pageID);
499
+    }
500
+
501
+    protected static function restorePage (int $pageID) {
502
+        Database::getInstance()->execute("UPDATE `{praefix}pages` SET `activated` = 1 WHERE `id` = :pageID; ", array(
503
+            'pageID' => $pageID
504
+        ));
505
+
506
+        //clear cache
507
+        Cache::clear("pages", "pageID_" . $pageID);
508
+    }
509
+
510
+    public static function exists (string $alias) : bool {
511
+        $row = Database::getInstance()->getRow("SELECT * FROM `{praefix}pages` WHERE `alias` = :alias; ", array(
512
+            'alias' => $alias
513
+        ));
514
+
515
+        return $row !== false;
516
+    }
517 517
 
518 518
 }
519 519
 
Please login to merge, or discard this patch.