Completed
Push — master ( 716d4c...0b2ff0 )
by Justin
24:28 queued 21:15
created
system/packages/com.jukusoft.cms.admin/classes/pageeditpage.php 1 patch
Indentation   +251 added lines, -251 removed lines patch added patch discarded remove patch
@@ -27,264 +27,264 @@  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
-		));
126
-
127
-		//set available styles
128
-		$template->assign("styles", StyleController::listAllStyles());
129
-
130
-		//get all pages from database
131
-		$pages = array();
132
-		$rows = Database::getInstance()->listRows("SELECT `id`, `alias` FROM `{praefix}pages` WHERE `editable` = '1' AND `activated` = '1'; ");
133
-
134
-		foreach ($rows as $row) {
135
-			$pages[] = array(
136
-				'id' => $row['id'],
137
-				'alias' => $row['alias']
138
-			);
139
-		}
140
-
141
-		$template->assign("parent_pages", $pages);
142
-
143
-		//https://developers.google.com/search/reference/robots_meta_tag?hl=de
144
-		$robots_options = array(
145
-			"all",
146
-			"noindex",
147
-			"nofollow",
148
-			"none",
149
-			"noarchive",
150
-			"nosnippet",
151
-			"noodp",
152
-			"notranslate",
153
-			"noimageindex",
154
-			"unavailable_after: "
155
-		);
156
-
157
-		Events::throwEvent("edit_page_robots_options", array(
158
-			'page' => &$this->getPage(),
159
-			'options' => &$robots_options
160
-		));
161
-
162
-		$template->assign("robots_options", $robots_options);
163
-
164
-		//add support to show additional code from plugins
165
-		$additional_code_header = "";
166
-		$additional_code_footer = "";
167
-
168
-		Events::throwEvent("page_edit_additional_code_header", array(
169
-			'page' => &$page,
170
-			'code' => &$additional_code_header
171
-		));
172
-
173
-		$template->assign("additional_code_header", $additional_code_footer);
174
-
175
-		Events::throwEvent("page_edit_additional_code_footer", array(
176
-			'page' => &$page,
177
-			'code' => &$additional_code_footer
178
-		));
179
-
180
-		$template->assign("additional_code_footer", $additional_code_footer);
181
-
182
-		$template->assign("errors", $error_messages);
183
-		$template->assign("success_messages", $success_messages);
184
-
185
-		return $template->getCode();
186
-	}
187
-
188
-	protected function save (Page &$page) {
189
-		//first check permissions
190
-		if (!PermissionChecker::current()->hasRight("can_edit_all_pages") && !(PermissionChecker::current()->hasRight("can_edit_own_pages") && $page->getAuthorID() == User::current()->getID())) {
191
-			//user doesn't have permissions to edit this page
192
-			return "You don't have permissions to edit this page!";
193
-		}
194
-
195
-		if (!isset($_POST['title']) || empty($_POST['title'])) {
196
-			return "No title was set";
197
-		}
198
-
199
-		//validate title
200
-		$title = htmlentities($_POST['title']);
201
-
202
-		if (!isset($_POST['html_code']) || empty($_POST['html_code'])) {
203
-			return "No content was set or content is empty!";
204
-		}
205
-
206
-		$content = $_POST['html_code'];
207
-
208
-		//TODO: save page attributes
209
-		if (!isset($_REQUEST['parent']) || empty($_REQUEST['parent'])) {
210
-			return "Parent page wasn't set!";
211
-		}
212
-
213
-		$parent = (int) $_REQUEST['parent'];
214
-
215
-		if (!isset($_REQUEST['design']) || empty($_REQUEST['design'])) {
216
-			return "Design wasn't set!";
217
-		}
218
-
219
-		$design = $_REQUEST['design'];
220
-
221
-		//TODO: check, if style (design) exists
222
-
223
-		$template = "none";
224
-
225
-		if (isset($_REQUEST['has_custom_template']) && isset($_REQUEST['template']) && !empty($_REQUEST['template'])) {
226
-			$template = $_REQUEST['template'];
227
-		}
228
-
229
-		//update page in database
230
-		Database::getInstance()->execute("UPDATE `{praefix}pages` SET `title` = :title, `content` = :content, `parent` = :parent, `design` = :design, `template` = :template WHERE `id` = :pageID; ", array(
231
-			'title' => $title,
232
-			'content' => $content,
233
-			'pageID' => $page->getPageID(),
234
-			'parent' => $parent,
235
-			'design' => $design,
236
-			'template' => $template
237
-		));
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
+        ));
126
+
127
+        //set available styles
128
+        $template->assign("styles", StyleController::listAllStyles());
129
+
130
+        //get all pages from database
131
+        $pages = array();
132
+        $rows = Database::getInstance()->listRows("SELECT `id`, `alias` FROM `{praefix}pages` WHERE `editable` = '1' AND `activated` = '1'; ");
133
+
134
+        foreach ($rows as $row) {
135
+            $pages[] = array(
136
+                'id' => $row['id'],
137
+                'alias' => $row['alias']
138
+            );
139
+        }
140
+
141
+        $template->assign("parent_pages", $pages);
142
+
143
+        //https://developers.google.com/search/reference/robots_meta_tag?hl=de
144
+        $robots_options = array(
145
+            "all",
146
+            "noindex",
147
+            "nofollow",
148
+            "none",
149
+            "noarchive",
150
+            "nosnippet",
151
+            "noodp",
152
+            "notranslate",
153
+            "noimageindex",
154
+            "unavailable_after: "
155
+        );
156
+
157
+        Events::throwEvent("edit_page_robots_options", array(
158
+            'page' => &$this->getPage(),
159
+            'options' => &$robots_options
160
+        ));
161
+
162
+        $template->assign("robots_options", $robots_options);
163
+
164
+        //add support to show additional code from plugins
165
+        $additional_code_header = "";
166
+        $additional_code_footer = "";
167
+
168
+        Events::throwEvent("page_edit_additional_code_header", array(
169
+            'page' => &$page,
170
+            'code' => &$additional_code_header
171
+        ));
172
+
173
+        $template->assign("additional_code_header", $additional_code_footer);
174
+
175
+        Events::throwEvent("page_edit_additional_code_footer", array(
176
+            'page' => &$page,
177
+            'code' => &$additional_code_footer
178
+        ));
179
+
180
+        $template->assign("additional_code_footer", $additional_code_footer);
181
+
182
+        $template->assign("errors", $error_messages);
183
+        $template->assign("success_messages", $success_messages);
184
+
185
+        return $template->getCode();
186
+    }
187
+
188
+    protected function save (Page &$page) {
189
+        //first check permissions
190
+        if (!PermissionChecker::current()->hasRight("can_edit_all_pages") && !(PermissionChecker::current()->hasRight("can_edit_own_pages") && $page->getAuthorID() == User::current()->getID())) {
191
+            //user doesn't have permissions to edit this page
192
+            return "You don't have permissions to edit this page!";
193
+        }
194
+
195
+        if (!isset($_POST['title']) || empty($_POST['title'])) {
196
+            return "No title was set";
197
+        }
198
+
199
+        //validate title
200
+        $title = htmlentities($_POST['title']);
201
+
202
+        if (!isset($_POST['html_code']) || empty($_POST['html_code'])) {
203
+            return "No content was set or content is empty!";
204
+        }
205
+
206
+        $content = $_POST['html_code'];
207
+
208
+        //TODO: save page attributes
209
+        if (!isset($_REQUEST['parent']) || empty($_REQUEST['parent'])) {
210
+            return "Parent page wasn't set!";
211
+        }
212
+
213
+        $parent = (int) $_REQUEST['parent'];
214
+
215
+        if (!isset($_REQUEST['design']) || empty($_REQUEST['design'])) {
216
+            return "Design wasn't set!";
217
+        }
218
+
219
+        $design = $_REQUEST['design'];
220
+
221
+        //TODO: check, if style (design) exists
222
+
223
+        $template = "none";
224
+
225
+        if (isset($_REQUEST['has_custom_template']) && isset($_REQUEST['template']) && !empty($_REQUEST['template'])) {
226
+            $template = $_REQUEST['template'];
227
+        }
228
+
229
+        //update page in database
230
+        Database::getInstance()->execute("UPDATE `{praefix}pages` SET `title` = :title, `content` = :content, `parent` = :parent, `design` = :design, `template` = :template WHERE `id` = :pageID; ", array(
231
+            'title' => $title,
232
+            'content' => $content,
233
+            'pageID' => $page->getPageID(),
234
+            'parent' => $parent,
235
+            'design' => $design,
236
+            'template' => $template
237
+        ));
238 238
 
239
-		//clear cache
240
-		$page->clearCache();
239
+        //clear cache
240
+        $page->clearCache();
241 241
 
242
-		//reload page from database
243
-		$page->loadByID($page->getPageID(), false);
244
-
245
-		//TODO: remove this line later
246
-		Cache::clear("pages");
242
+        //reload page from database
243
+        $page->loadByID($page->getPageID(), false);
244
+
245
+        //TODO: remove this line later
246
+        Cache::clear("pages");
247 247
 
248
-		return true;
249
-	}
248
+        return true;
249
+    }
250 250
 
251
-	protected function publish (Page &$page) {
252
-		//check permissions for publishing
253
-		if (PermissionChecker::current()->hasRight("can_publish_all_pages") || (PermissionChecker::current()->hasRight("can_publish_own_pages") && $page->getAuthorID() == User::current()->getID())) {
254
-			//update page in database
255
-			Database::getInstance()->execute("UPDATE `{praefix}pages` SET `published` = '1' WHERE `id` = :pageID; ", array(
256
-				'pageID' => $page->getPageID()
257
-			));
251
+    protected function publish (Page &$page) {
252
+        //check permissions for publishing
253
+        if (PermissionChecker::current()->hasRight("can_publish_all_pages") || (PermissionChecker::current()->hasRight("can_publish_own_pages") && $page->getAuthorID() == User::current()->getID())) {
254
+            //update page in database
255
+            Database::getInstance()->execute("UPDATE `{praefix}pages` SET `published` = '1' WHERE `id` = :pageID; ", array(
256
+                'pageID' => $page->getPageID()
257
+            ));
258 258
 
259
-			//clear cache
260
-			$page->clearCache();
259
+            //clear cache
260
+            $page->clearCache();
261 261
 
262
-			//reload page from database
263
-			$page->loadByID($page->getPageID(), false);
262
+            //reload page from database
263
+            $page->loadByID($page->getPageID(), false);
264 264
 
265
-			//TODO: remove this line later
266
-			Cache::clear("pages");
265
+            //TODO: remove this line later
266
+            Cache::clear("pages");
267 267
 
268
-			return true;
269
-		} else {
270
-			return "You don't have the permissions to publish this page!";
271
-		}
272
-	}
268
+            return true;
269
+        } else {
270
+            return "You don't have the permissions to publish this page!";
271
+        }
272
+    }
273 273
 
274
-	protected function showError (string $message) : string {
275
-		//show error
276
-		$template = new DwooTemplate("pages/error");
277
-		$template->assign("message", "No pageID was set!");
278
-		return $template->getCode();
279
-	}
274
+    protected function showError (string $message) : string {
275
+        //show error
276
+        $template = new DwooTemplate("pages/error");
277
+        $template->assign("message", "No pageID was set!");
278
+        return $template->getCode();
279
+    }
280 280
 
281
-	public function getFooterScripts(): string {
282
-		$style_name = Registry::singleton()->getSetting("current_style_name");
283
-		$style_path = DomainUtils::getBaseURL() . "/styles/" . $style_name . "/";
281
+    public function getFooterScripts(): string {
282
+        $style_name = Registry::singleton()->getSetting("current_style_name");
283
+        $style_path = DomainUtils::getBaseURL() . "/styles/" . $style_name . "/";
284 284
 
285
-		$thirdparty_url = Registry::singleton()->getSetting("thirdparty_url");
285
+        $thirdparty_url = Registry::singleton()->getSetting("thirdparty_url");
286 286
 
287
-		/*return "<!-- CK Editor -->
287
+        /*return "<!-- CK Editor -->
288 288
 			<script src=\"" . $style_path . "bower_components/ckeditor/ckeditor.js\"></script>
289 289
 			
290 290
 			<script>
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
 				});
299 299
 			</script>";*/
300 300
 
301
-		return "<script src=\"" . $thirdparty_url . "tinymce_4.8.2/js/tinymce/tinymce.min.js\"></script>
301
+        return "<script src=\"" . $thirdparty_url . "tinymce_4.8.2/js/tinymce/tinymce.min.js\"></script>
302 302
   				<script>tinymce.init({
303 303
 					  selector: 'textarea',
304 304
 					  height: 500,
@@ -317,11 +317,11 @@  discard block
 block discarded – undo
317 317
 					}
318 318
 				};
319 319
 				</script>";
320
-	}
320
+    }
321 321
 
322
-	public function listRequiredPermissions(): array {
323
-		return array("can_edit_all_pages", "can_edit_own_pages");
324
-	}
322
+    public function listRequiredPermissions(): array {
323
+        return array("can_edit_all_pages", "can_edit_own_pages");
324
+    }
325 325
 
326 326
 }
327 327
 
Please login to merge, or discard this patch.