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