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