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