Completed
Push — master ( 0b2ff0...3826b7 )
by Justin
27:01 queued 23:53
created
system/packages/com.jukusoft.cms.admin/classes/pageeditpage.php 1 patch
Indentation   +245 added lines, -245 removed lines patch added patch discarded remove patch
@@ -27,259 +27,259 @@  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
-		$template->assign("robots_options", $robots_options);
158
-
159
-		//add support to show additional code from plugins
160
-		$additional_code_header = "";
161
-		$additional_code_footer = "";
162
-
163
-		Events::throwEvent("page_edit_additional_code_header", array(
164
-			'page' => &$page,
165
-			'code' => &$additional_code_header
166
-		));
167
-
168
-		$template->assign("additional_code_header", $additional_code_footer);
169
-
170
-		Events::throwEvent("page_edit_additional_code_footer", array(
171
-			'page' => &$page,
172
-			'code' => &$additional_code_footer
173
-		));
174
-
175
-		$template->assign("additional_code_footer", $additional_code_footer);
176
-
177
-		$template->assign("errors", $error_messages);
178
-		$template->assign("success_messages", $success_messages);
179
-
180
-		return $template->getCode();
181
-	}
182
-
183
-	protected function save (Page &$page) {
184
-		//first check permissions
185
-		if (!PermissionChecker::current()->hasRight("can_edit_all_pages") && !(PermissionChecker::current()->hasRight("can_edit_own_pages") && $page->getAuthorID() == User::current()->getID())) {
186
-			//user doesn't have permissions to edit this page
187
-			return "You don't have permissions to edit this page!";
188
-		}
189
-
190
-		if (!isset($_POST['title']) || empty($_POST['title'])) {
191
-			return "No title was set";
192
-		}
193
-
194
-		//validate title
195
-		$title = htmlentities($_POST['title']);
196
-
197
-		if (!isset($_POST['html_code']) || empty($_POST['html_code'])) {
198
-			return "No content was set or content is empty!";
199
-		}
200
-
201
-		$content = $_POST['html_code'];
202
-
203
-		//TODO: save page attributes
204
-		if (!isset($_REQUEST['parent']) || empty($_REQUEST['parent'])) {
205
-			return "Parent page wasn't set!";
206
-		}
207
-
208
-		$parent = (int) $_REQUEST['parent'];
209
-
210
-		if (!isset($_REQUEST['design']) || empty($_REQUEST['design'])) {
211
-			return "Design wasn't set!";
212
-		}
213
-
214
-		$design = $_REQUEST['design'];
215
-
216
-		//TODO: check, if style (design) exists
217
-
218
-		$template = "none";
219
-
220
-		if (isset($_REQUEST['has_custom_template']) && isset($_REQUEST['template']) && !empty($_REQUEST['template'])) {
221
-			$template = $_REQUEST['template'];
222
-		}
223
-
224
-		//update page in database
225
-		Database::getInstance()->execute("UPDATE `{praefix}pages` SET `title` = :title, `content` = :content, `parent` = :parent, `design` = :design, `template` = :template WHERE `id` = :pageID; ", array(
226
-			'title' => $title,
227
-			'content' => $content,
228
-			'pageID' => $page->getPageID(),
229
-			'parent' => $parent,
230
-			'design' => $design,
231
-			'template' => $template
232
-		));
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
+        $template->assign("robots_options", $robots_options);
158
+
159
+        //add support to show additional code from plugins
160
+        $additional_code_header = "";
161
+        $additional_code_footer = "";
162
+
163
+        Events::throwEvent("page_edit_additional_code_header", array(
164
+            'page' => &$page,
165
+            'code' => &$additional_code_header
166
+        ));
167
+
168
+        $template->assign("additional_code_header", $additional_code_footer);
169
+
170
+        Events::throwEvent("page_edit_additional_code_footer", array(
171
+            'page' => &$page,
172
+            'code' => &$additional_code_footer
173
+        ));
174
+
175
+        $template->assign("additional_code_footer", $additional_code_footer);
176
+
177
+        $template->assign("errors", $error_messages);
178
+        $template->assign("success_messages", $success_messages);
179
+
180
+        return $template->getCode();
181
+    }
182
+
183
+    protected function save (Page &$page) {
184
+        //first check permissions
185
+        if (!PermissionChecker::current()->hasRight("can_edit_all_pages") && !(PermissionChecker::current()->hasRight("can_edit_own_pages") && $page->getAuthorID() == User::current()->getID())) {
186
+            //user doesn't have permissions to edit this page
187
+            return "You don't have permissions to edit this page!";
188
+        }
189
+
190
+        if (!isset($_POST['title']) || empty($_POST['title'])) {
191
+            return "No title was set";
192
+        }
193
+
194
+        //validate title
195
+        $title = htmlentities($_POST['title']);
196
+
197
+        if (!isset($_POST['html_code']) || empty($_POST['html_code'])) {
198
+            return "No content was set or content is empty!";
199
+        }
200
+
201
+        $content = $_POST['html_code'];
202
+
203
+        //TODO: save page attributes
204
+        if (!isset($_REQUEST['parent']) || empty($_REQUEST['parent'])) {
205
+            return "Parent page wasn't set!";
206
+        }
207
+
208
+        $parent = (int) $_REQUEST['parent'];
209
+
210
+        if (!isset($_REQUEST['design']) || empty($_REQUEST['design'])) {
211
+            return "Design wasn't set!";
212
+        }
213
+
214
+        $design = $_REQUEST['design'];
215
+
216
+        //TODO: check, if style (design) exists
217
+
218
+        $template = "none";
219
+
220
+        if (isset($_REQUEST['has_custom_template']) && isset($_REQUEST['template']) && !empty($_REQUEST['template'])) {
221
+            $template = $_REQUEST['template'];
222
+        }
223
+
224
+        //update page in database
225
+        Database::getInstance()->execute("UPDATE `{praefix}pages` SET `title` = :title, `content` = :content, `parent` = :parent, `design` = :design, `template` = :template WHERE `id` = :pageID; ", array(
226
+            'title' => $title,
227
+            'content' => $content,
228
+            'pageID' => $page->getPageID(),
229
+            'parent' => $parent,
230
+            'design' => $design,
231
+            'template' => $template
232
+        ));
233 233
 
234
-		//clear cache
235
-		$page->clearCache();
234
+        //clear cache
235
+        $page->clearCache();
236 236
 
237
-		//reload page from database
238
-		$page->loadByID($page->getPageID(), false);
237
+        //reload page from database
238
+        $page->loadByID($page->getPageID(), false);
239 239
 
240
-		//TODO: remove this line later
241
-		Cache::clear("pages");
240
+        //TODO: remove this line later
241
+        Cache::clear("pages");
242 242
 
243
-		return true;
244
-	}
243
+        return true;
244
+    }
245 245
 
246
-	protected function publish (Page &$page) {
247
-		//check permissions for publishing
248
-		if (PermissionChecker::current()->hasRight("can_publish_all_pages") || (PermissionChecker::current()->hasRight("can_publish_own_pages") && $page->getAuthorID() == User::current()->getID())) {
249
-			//update page in database
250
-			Database::getInstance()->execute("UPDATE `{praefix}pages` SET `published` = '1' WHERE `id` = :pageID; ", array(
251
-				'pageID' => $page->getPageID()
252
-			));
246
+    protected function publish (Page &$page) {
247
+        //check permissions for publishing
248
+        if (PermissionChecker::current()->hasRight("can_publish_all_pages") || (PermissionChecker::current()->hasRight("can_publish_own_pages") && $page->getAuthorID() == User::current()->getID())) {
249
+            //update page in database
250
+            Database::getInstance()->execute("UPDATE `{praefix}pages` SET `published` = '1' WHERE `id` = :pageID; ", array(
251
+                'pageID' => $page->getPageID()
252
+            ));
253 253
 
254
-			//clear cache
255
-			$page->clearCache();
254
+            //clear cache
255
+            $page->clearCache();
256 256
 
257
-			//reload page from database
258
-			$page->loadByID($page->getPageID(), false);
257
+            //reload page from database
258
+            $page->loadByID($page->getPageID(), false);
259 259
 
260
-			//TODO: remove this line later
261
-			Cache::clear("pages");
260
+            //TODO: remove this line later
261
+            Cache::clear("pages");
262 262
 
263
-			return true;
264
-		} else {
265
-			return "You don't have the permissions to publish this page!";
266
-		}
267
-	}
263
+            return true;
264
+        } else {
265
+            return "You don't have the permissions to publish this page!";
266
+        }
267
+    }
268 268
 
269
-	protected function showError (string $message) : string {
270
-		//show error
271
-		$template = new DwooTemplate("pages/error");
272
-		$template->assign("message", "No pageID was set!");
273
-		return $template->getCode();
274
-	}
269
+    protected function showError (string $message) : string {
270
+        //show error
271
+        $template = new DwooTemplate("pages/error");
272
+        $template->assign("message", "No pageID was set!");
273
+        return $template->getCode();
274
+    }
275 275
 
276
-	public function getFooterScripts(): string {
277
-		$style_name = Registry::singleton()->getSetting("current_style_name");
278
-		$style_path = DomainUtils::getBaseURL() . "/styles/" . $style_name . "/";
276
+    public function getFooterScripts(): string {
277
+        $style_name = Registry::singleton()->getSetting("current_style_name");
278
+        $style_path = DomainUtils::getBaseURL() . "/styles/" . $style_name . "/";
279 279
 
280
-		$thirdparty_url = Registry::singleton()->getSetting("thirdparty_url");
280
+        $thirdparty_url = Registry::singleton()->getSetting("thirdparty_url");
281 281
 
282
-		/*return "<!-- CK Editor -->
282
+        /*return "<!-- CK Editor -->
283 283
 			<script src=\"" . $style_path . "bower_components/ckeditor/ckeditor.js\"></script>
284 284
 			
285 285
 			<script>
@@ -293,7 +293,7 @@  discard block
 block discarded – undo
293 293
 				});
294 294
 			</script>";*/
295 295
 
296
-		return "<script src=\"" . $thirdparty_url . "tinymce_4.8.2/js/tinymce/tinymce.min.js\"></script>
296
+        return "<script src=\"" . $thirdparty_url . "tinymce_4.8.2/js/tinymce/tinymce.min.js\"></script>
297 297
   				<script>tinymce.init({
298 298
 					  selector: 'textarea',
299 299
 					  height: 500,
@@ -312,11 +312,11 @@  discard block
 block discarded – undo
312 312
 					}
313 313
 				};
314 314
 				</script>";
315
-	}
315
+    }
316 316
 
317
-	public function listRequiredPermissions(): array {
318
-		return array("can_edit_all_pages", "can_edit_own_pages");
319
-	}
317
+    public function listRequiredPermissions(): array {
318
+        return array("can_edit_all_pages", "can_edit_own_pages");
319
+    }
320 320
 
321 321
 }
322 322
 
Please login to merge, or discard this patch.