Completed
Push — master ( d13b22...a2d243 )
by Justin
05:45
created
system/packages/com.jukusoft.cms.admin/classes/pageeditpage.php 1 patch
Indentation   +308 added lines, -308 removed lines patch added patch discarded remove patch
@@ -27,343 +27,343 @@  discard block
 block discarded – undo
27 27
 
28 28
 class PageEditPage extends PageType {
29 29
 
30
-	protected $sitemap_change_frequencies = array(
31
-		"AlWAYS", "HOURLY", "DAILY", "WEEKLY", "MONTHLY", "YEARLY", "NEVER"
32
-	);
33
-
34
-	public function getContent(): string {
35
-		$template = new DwooTemplate("pages/editpage");
36
-
37
-		//check, if pageID is set
38
-		if (!isset($_REQUEST['edit']) || empty($_REQUEST['edit'])) {
39
-			//show error
40
-			return $this->showError("No pageID was set!");
41
-		}
42
-
43
-		$pageID = (int) $_REQUEST['edit'];
44
-
45
-		$page = new Page();
46
-		$page->loadByID($pageID);
47
-
48
-		//first check permissions
49
-		if (!PermissionChecker::current()->hasRight("can_edit_all_pages") && !(PermissionChecker::current()->hasRight("can_edit_own_pages") && $page->getAuthorID() == User::current()->getID())) {
50
-			//user doesn't have permissions to edit this page
51
-			return $this->showError("You don't have permissions to edit this page!");
52
-		}
53
-
54
-		//first, lock page
55
-		Page::lockPage($page->getPageID(), User::current()->getID());
56
-
57
-		$success_messages = array();
58
-		$error_messages = array();
59
-
60
-		//save page
61
-		if (isset($_REQUEST['submit'])) {
62
-			if ($_REQUEST['submit'] === "Save") {
63
-				//save page
64
-				$res = $this->save($page);
65
-
66
-				if ($res === true) {
67
-					$success_messages[] = "Saved page successfully!";
68
-				} else {
69
-					$error_messages[] = $res;
70
-				}
71
-			} else if ($_REQUEST['submit'] === "SaveUnlock") {
72
-				//save page
73
-				$res = $this->save($page);
74
-
75
-				if ($res === true) {
76
-					//unlock page
77
-					Page::unlockPage($page->getPageID());
78
-
79
-					//redirect to admin/pages
80
-					header("Location: " . DomainUtils::generateURL("admin/pages"));
81
-
82
-					ob_flush();
83
-					ob_end_flush();
84
-
85
-					exit;
86
-				} else {
87
-					$error_messages[] = $res;
88
-				}
89
-			} else if ($_REQUEST['submit'] === "Publish") {
90
-				//save page
91
-				$res = $this->save($page);
92
-
93
-				if ($res === true) {
94
-					$success_messages[] = "Saved page successfully!";
95
-				} else {
96
-					$error_messages[] = $res;
97
-				}
98
-
99
-				//publish page
100
-				$res = $this->publish($page);
101
-
102
-				if ($res === true) {
103
-					$success_messages[] = "Page published successfully!";
104
-				} else {
105
-					$error_messages[] = $res;
106
-				}
107
-			}
108
-		}
109
-
110
-		$template->assign("action_url", DomainUtils::generateURL($this->getPage()->getAlias(), array("edit" => $pageID)));
111
-
112
-		$template->assign("page", array(
113
-			'id' => $page->getPageID(),
114
-			'alias' => "/" . $page->getAlias(),
115
-			'title' => $page->getTitle(),
116
-			'content' => $page->getContent(),
117
-			'is_published' => $page->isPublished(),
118
-			'can_publish' => (!$page->isPublished() && (PermissionChecker::current()->hasRight("can_publish_all_pages") || (PermissionChecker::current()->hasRight("can_publish_own_pages") && $page->getAuthorID() == User::current()->getID()))),
119
-			'can_change_owner' => (PermissionChecker::current()->hasRight("can_change_page_owner") || $page->getAuthorID() == User::current()->getID()),
120
-			'folder' => $page->getFolder(),
121
-			'preview_url' => DomainUtils::generateURL($page->getAlias(), array("preview" => "true")),
122
-			'current_style' => $page->getStyle(),
123
-			'template' => $page->getCustomTemplate(),
124
-			'has_custom_template' => $page->hasCustomTemplate(),
125
-			'parent' => $page->getParentID(),
126
-			'meta_description' => $page->getMetaDescription(),
127
-			'meta_keywords' => $page->getMetaKeywords(),
128
-			'meta_robots' => $page->getMetaRobotsOptions(),
129
-			'meta_canonicals' => $page->getMetaCanonicals(),
130
-			'has_canoncials' => !empty($page->getMetaCanonicals()),
131
-			'sitemap' => $page->isSitemapEnabled(),
132
-			'sitemap_changefreq' => $page->getSitemapChangeFreq(),
133
-			'sitemap_priority' => $page->getSitemapPriority(),
134
-			'og_type' => $page->getOgType()
135
-		));
136
-
137
-		//set available styles
138
-		$template->assign("styles", StyleController::listAllStyles());
139
-
140
-		//get all pages from database
141
-		$pages = array();
142
-		$rows = Database::getInstance()->listRows("SELECT `id`, `alias` FROM `{praefix}pages` WHERE `editable` = '1' AND `activated` = '1'; ");
143
-
144
-		foreach ($rows as $row) {
145
-			$pages[] = array(
146
-				'id' => $row['id'],
147
-				'alias' => $row['alias']
148
-			);
149
-		}
150
-
151
-		$template->assign("parent_pages", $pages);
152
-
153
-		//https://developers.google.com/search/reference/robots_meta_tag?hl=de
154
-		$robots_options = array(
155
-			"all",
156
-			"noindex",
157
-			"nofollow",
158
-			"none",
159
-			"noarchive",
160
-			"nosnippet",
161
-			"noodp",
162
-			"notranslate",
163
-			"noimageindex",
164
-			"unavailable_after: "
165
-		);
166
-
167
-		$template->assign("robots_options", $robots_options);
168
-
169
-		$sitemap_change_frequencies = $this->sitemap_change_frequencies;
170
-
171
-		$template->assign("sitemap_change_frequencies", $sitemap_change_frequencies);
172
-
173
-		//OpenGraph types,https://developers.facebook.com/docs/reference/opengraph/
174
-		$og_types = array("website", "article", "book", "profile");
175
-
176
-		$template->assign("og_types", $og_types);
177
-
178
-		//add support to show additional code from plugins
179
-		$additional_code_header = "";
180
-		$additional_code_footer = "";
181
-
182
-		Events::throwEvent("page_edit_additional_code_header", array(
183
-			'page' => &$page,
184
-			'code' => &$additional_code_header
185
-		));
186
-
187
-		$template->assign("additional_code_header", $additional_code_footer);
188
-
189
-		Events::throwEvent("page_edit_additional_code_footer", array(
190
-			'page' => &$page,
191
-			'code' => &$additional_code_footer
192
-		));
193
-
194
-		$template->assign("additional_code_footer", $additional_code_footer);
195
-
196
-		$template->assign("errors", $error_messages);
197
-		$template->assign("success_messages", $success_messages);
30
+    protected $sitemap_change_frequencies = array(
31
+        "AlWAYS", "HOURLY", "DAILY", "WEEKLY", "MONTHLY", "YEARLY", "NEVER"
32
+    );
33
+
34
+    public function getContent(): string {
35
+        $template = new DwooTemplate("pages/editpage");
36
+
37
+        //check, if pageID is set
38
+        if (!isset($_REQUEST['edit']) || empty($_REQUEST['edit'])) {
39
+            //show error
40
+            return $this->showError("No pageID was set!");
41
+        }
42
+
43
+        $pageID = (int) $_REQUEST['edit'];
44
+
45
+        $page = new Page();
46
+        $page->loadByID($pageID);
47
+
48
+        //first check permissions
49
+        if (!PermissionChecker::current()->hasRight("can_edit_all_pages") && !(PermissionChecker::current()->hasRight("can_edit_own_pages") && $page->getAuthorID() == User::current()->getID())) {
50
+            //user doesn't have permissions to edit this page
51
+            return $this->showError("You don't have permissions to edit this page!");
52
+        }
53
+
54
+        //first, lock page
55
+        Page::lockPage($page->getPageID(), User::current()->getID());
56
+
57
+        $success_messages = array();
58
+        $error_messages = array();
59
+
60
+        //save page
61
+        if (isset($_REQUEST['submit'])) {
62
+            if ($_REQUEST['submit'] === "Save") {
63
+                //save page
64
+                $res = $this->save($page);
65
+
66
+                if ($res === true) {
67
+                    $success_messages[] = "Saved page successfully!";
68
+                } else {
69
+                    $error_messages[] = $res;
70
+                }
71
+            } else if ($_REQUEST['submit'] === "SaveUnlock") {
72
+                //save page
73
+                $res = $this->save($page);
74
+
75
+                if ($res === true) {
76
+                    //unlock page
77
+                    Page::unlockPage($page->getPageID());
78
+
79
+                    //redirect to admin/pages
80
+                    header("Location: " . DomainUtils::generateURL("admin/pages"));
81
+
82
+                    ob_flush();
83
+                    ob_end_flush();
84
+
85
+                    exit;
86
+                } else {
87
+                    $error_messages[] = $res;
88
+                }
89
+            } else if ($_REQUEST['submit'] === "Publish") {
90
+                //save page
91
+                $res = $this->save($page);
92
+
93
+                if ($res === true) {
94
+                    $success_messages[] = "Saved page successfully!";
95
+                } else {
96
+                    $error_messages[] = $res;
97
+                }
98
+
99
+                //publish page
100
+                $res = $this->publish($page);
101
+
102
+                if ($res === true) {
103
+                    $success_messages[] = "Page published successfully!";
104
+                } else {
105
+                    $error_messages[] = $res;
106
+                }
107
+            }
108
+        }
109
+
110
+        $template->assign("action_url", DomainUtils::generateURL($this->getPage()->getAlias(), array("edit" => $pageID)));
111
+
112
+        $template->assign("page", array(
113
+            'id' => $page->getPageID(),
114
+            'alias' => "/" . $page->getAlias(),
115
+            'title' => $page->getTitle(),
116
+            'content' => $page->getContent(),
117
+            'is_published' => $page->isPublished(),
118
+            'can_publish' => (!$page->isPublished() && (PermissionChecker::current()->hasRight("can_publish_all_pages") || (PermissionChecker::current()->hasRight("can_publish_own_pages") && $page->getAuthorID() == User::current()->getID()))),
119
+            'can_change_owner' => (PermissionChecker::current()->hasRight("can_change_page_owner") || $page->getAuthorID() == User::current()->getID()),
120
+            'folder' => $page->getFolder(),
121
+            'preview_url' => DomainUtils::generateURL($page->getAlias(), array("preview" => "true")),
122
+            'current_style' => $page->getStyle(),
123
+            'template' => $page->getCustomTemplate(),
124
+            'has_custom_template' => $page->hasCustomTemplate(),
125
+            'parent' => $page->getParentID(),
126
+            'meta_description' => $page->getMetaDescription(),
127
+            'meta_keywords' => $page->getMetaKeywords(),
128
+            'meta_robots' => $page->getMetaRobotsOptions(),
129
+            'meta_canonicals' => $page->getMetaCanonicals(),
130
+            'has_canoncials' => !empty($page->getMetaCanonicals()),
131
+            'sitemap' => $page->isSitemapEnabled(),
132
+            'sitemap_changefreq' => $page->getSitemapChangeFreq(),
133
+            'sitemap_priority' => $page->getSitemapPriority(),
134
+            'og_type' => $page->getOgType()
135
+        ));
136
+
137
+        //set available styles
138
+        $template->assign("styles", StyleController::listAllStyles());
139
+
140
+        //get all pages from database
141
+        $pages = array();
142
+        $rows = Database::getInstance()->listRows("SELECT `id`, `alias` FROM `{praefix}pages` WHERE `editable` = '1' AND `activated` = '1'; ");
143
+
144
+        foreach ($rows as $row) {
145
+            $pages[] = array(
146
+                'id' => $row['id'],
147
+                'alias' => $row['alias']
148
+            );
149
+        }
150
+
151
+        $template->assign("parent_pages", $pages);
152
+
153
+        //https://developers.google.com/search/reference/robots_meta_tag?hl=de
154
+        $robots_options = array(
155
+            "all",
156
+            "noindex",
157
+            "nofollow",
158
+            "none",
159
+            "noarchive",
160
+            "nosnippet",
161
+            "noodp",
162
+            "notranslate",
163
+            "noimageindex",
164
+            "unavailable_after: "
165
+        );
166
+
167
+        $template->assign("robots_options", $robots_options);
168
+
169
+        $sitemap_change_frequencies = $this->sitemap_change_frequencies;
170
+
171
+        $template->assign("sitemap_change_frequencies", $sitemap_change_frequencies);
172
+
173
+        //OpenGraph types,https://developers.facebook.com/docs/reference/opengraph/
174
+        $og_types = array("website", "article", "book", "profile");
175
+
176
+        $template->assign("og_types", $og_types);
177
+
178
+        //add support to show additional code from plugins
179
+        $additional_code_header = "";
180
+        $additional_code_footer = "";
181
+
182
+        Events::throwEvent("page_edit_additional_code_header", array(
183
+            'page' => &$page,
184
+            'code' => &$additional_code_header
185
+        ));
186
+
187
+        $template->assign("additional_code_header", $additional_code_footer);
188
+
189
+        Events::throwEvent("page_edit_additional_code_footer", array(
190
+            'page' => &$page,
191
+            'code' => &$additional_code_footer
192
+        ));
193
+
194
+        $template->assign("additional_code_footer", $additional_code_footer);
195
+
196
+        $template->assign("errors", $error_messages);
197
+        $template->assign("success_messages", $success_messages);
198 198
 
199
-		return $template->getCode();
200
-	}
199
+        return $template->getCode();
200
+    }
201 201
 
202
-	protected function save (Page &$page) {
203
-		//first check permissions
204
-		if (!PermissionChecker::current()->hasRight("can_edit_all_pages") && !(PermissionChecker::current()->hasRight("can_edit_own_pages") && $page->getAuthorID() == User::current()->getID())) {
205
-			//user doesn't have permissions to edit this page
206
-			return "You don't have permissions to edit this page!";
207
-		}
208
-
209
-		if (!isset($_POST['title']) || empty($_POST['title'])) {
210
-			return "No title was set";
211
-		}
212
-
213
-		//validate title
214
-		$title = htmlentities($_POST['title']);
215
-
216
-		if (!isset($_POST['html_code']) || empty($_POST['html_code'])) {
217
-			return "No content was set or content is empty!";
218
-		}
219
-
220
-		$content = $_POST['html_code'];
221
-
222
-		//TODO: save page attributes
223
-		if (!isset($_REQUEST['parent']) || empty($_REQUEST['parent'])) {
224
-			return "Parent page wasn't set!";
225
-		}
202
+    protected function save (Page &$page) {
203
+        //first check permissions
204
+        if (!PermissionChecker::current()->hasRight("can_edit_all_pages") && !(PermissionChecker::current()->hasRight("can_edit_own_pages") && $page->getAuthorID() == User::current()->getID())) {
205
+            //user doesn't have permissions to edit this page
206
+            return "You don't have permissions to edit this page!";
207
+        }
208
+
209
+        if (!isset($_POST['title']) || empty($_POST['title'])) {
210
+            return "No title was set";
211
+        }
212
+
213
+        //validate title
214
+        $title = htmlentities($_POST['title']);
215
+
216
+        if (!isset($_POST['html_code']) || empty($_POST['html_code'])) {
217
+            return "No content was set or content is empty!";
218
+        }
219
+
220
+        $content = $_POST['html_code'];
221
+
222
+        //TODO: save page attributes
223
+        if (!isset($_REQUEST['parent']) || empty($_REQUEST['parent'])) {
224
+            return "Parent page wasn't set!";
225
+        }
226 226
 
227
-		$parent = (int) $_REQUEST['parent'];
227
+        $parent = (int) $_REQUEST['parent'];
228 228
 
229
-		if (!isset($_REQUEST['design']) || empty($_REQUEST['design'])) {
230
-			return "Design wasn't set!";
231
-		}
229
+        if (!isset($_REQUEST['design']) || empty($_REQUEST['design'])) {
230
+            return "Design wasn't set!";
231
+        }
232 232
 
233
-		$design = $_REQUEST['design'];
233
+        $design = $_REQUEST['design'];
234 234
 
235
-		//TODO: check, if style (design) exists
235
+        //TODO: check, if style (design) exists
236 236
 
237
-		$template = "none";
237
+        $template = "none";
238 238
 
239
-		if (isset($_REQUEST['has_custom_template']) && isset($_REQUEST['template']) && !empty($_REQUEST['template'])) {
240
-			$template = $_REQUEST['template'];
241
-		}
239
+        if (isset($_REQUEST['has_custom_template']) && isset($_REQUEST['template']) && !empty($_REQUEST['template'])) {
240
+            $template = $_REQUEST['template'];
241
+        }
242 242
 
243
-		if (!isset($_REQUEST['meta_keywords']) || empty($_REQUEST['meta_keywords'])) {
244
-			return "Meta keywords wasn't set!";
245
-		}
243
+        if (!isset($_REQUEST['meta_keywords']) || empty($_REQUEST['meta_keywords'])) {
244
+            return "Meta keywords wasn't set!";
245
+        }
246 246
 
247
-		$keywords = htmlentities($_REQUEST['meta_keywords']);
247
+        $keywords = htmlentities($_REQUEST['meta_keywords']);
248 248
 
249
-		$robots = "";
249
+        $robots = "";
250 250
 
251
-		if (!isset($_REQUEST['meta_robots']) || empty($_REQUEST['meta_robots'])) {
252
-			//return "Meta robots wasn't set!";
253
-		} else {
254
-			$robots = htmlentities($_REQUEST['meta_robots']);
255
-		}
251
+        if (!isset($_REQUEST['meta_robots']) || empty($_REQUEST['meta_robots'])) {
252
+            //return "Meta robots wasn't set!";
253
+        } else {
254
+            $robots = htmlentities($_REQUEST['meta_robots']);
255
+        }
256 256
 
257
-		$canoncials = "";
257
+        $canoncials = "";
258 258
 
259
-		if (isset($_REQUEST['has_canoncials']) && isset($_REQUEST['meta_canoncials']) && !empty($_REQUEST['meta_canoncials'])) {
260
-			$canoncials = $_REQUEST['meta_canoncials'];
261
-		}
259
+        if (isset($_REQUEST['has_canoncials']) && isset($_REQUEST['meta_canoncials']) && !empty($_REQUEST['meta_canoncials'])) {
260
+            $canoncials = $_REQUEST['meta_canoncials'];
261
+        }
262 262
 
263
-		$sitemap = 0;
264
-		$sitemap_changefreq = "WEEKLY";
265
-		$sitemap_priority = 0.5;
263
+        $sitemap = 0;
264
+        $sitemap_changefreq = "WEEKLY";
265
+        $sitemap_priority = 0.5;
266 266
 
267
-		if (isset($_REQUEST['sitemap'])) {
268
-			$sitemap = 1;
267
+        if (isset($_REQUEST['sitemap'])) {
268
+            $sitemap = 1;
269 269
 
270
-			if (!isset($_REQUEST['sitemap_changefreq']) || empty($_REQUEST['sitemap_changefreq'])) {
271
-				return "Sitemap change frequency wasn't set!";
272
-			}
270
+            if (!isset($_REQUEST['sitemap_changefreq']) || empty($_REQUEST['sitemap_changefreq'])) {
271
+                return "Sitemap change frequency wasn't set!";
272
+            }
273 273
 
274
-			$sitemap_changefreq = $_REQUEST['sitemap_changefreq'];
274
+            $sitemap_changefreq = $_REQUEST['sitemap_changefreq'];
275 275
 
276
-			if (!in_array($sitemap_changefreq, $this->sitemap_change_frequencies)) {
277
-				return "Invalide value for sitemap change frequency: " . $sitemap_changefreq;
278
-			}
276
+            if (!in_array($sitemap_changefreq, $this->sitemap_change_frequencies)) {
277
+                return "Invalide value for sitemap change frequency: " . $sitemap_changefreq;
278
+            }
279 279
 
280
-			if (!isset($_REQUEST['sitemap_priority']) || empty($_REQUEST['sitemap_priority'])) {
281
-				return "Sitemap priority wasn't set!";
282
-			}
280
+            if (!isset($_REQUEST['sitemap_priority']) || empty($_REQUEST['sitemap_priority'])) {
281
+                return "Sitemap priority wasn't set!";
282
+            }
283 283
 
284
-			$sitemap_priority = (float) $_REQUEST['sitemap_priority'];
284
+            $sitemap_priority = (float) $_REQUEST['sitemap_priority'];
285 285
 
286
-			if ($sitemap_priority < 0) {
287
-				return "Minimum value of sitemap priority is 0.";
288
-			}
286
+            if ($sitemap_priority < 0) {
287
+                return "Minimum value of sitemap priority is 0.";
288
+            }
289 289
 
290
-			if ($sitemap_priority > 1) {
291
-				return "Maximum value of sitemap priority is 1.";
292
-			}
293
-		}
290
+            if ($sitemap_priority > 1) {
291
+                return "Maximum value of sitemap priority is 1.";
292
+            }
293
+        }
294 294
 
295
-		if (!isset($_REQUEST['og_type']) || empty($_REQUEST['og_type'])) {
296
-			return "OpenGraph type wasn't set!";
297
-		}
295
+        if (!isset($_REQUEST['og_type']) || empty($_REQUEST['og_type'])) {
296
+            return "OpenGraph type wasn't set!";
297
+        }
298 298
 
299
-		$og_type = $_REQUEST['og_type'];
299
+        $og_type = $_REQUEST['og_type'];
300 300
 
301
-		//update page in database
302
-		Database::getInstance()->execute("UPDATE `{praefix}pages` SET `title` = :title, `content` = :content, `parent` = :parent, `design` = :design, `template` = :template, `sitemap` = :sitemap, `sitemap_changefreq` = :sitemap_changefreq, `sitemap_priority` = :sitemap_priority, `meta_keywords` = :keywords, `meta_robots` = :robots, `meta_canonicals` = :canoncials, `og_type` = :og_type WHERE `id` = :pageID; ", array(
303
-			'title' => $title,
304
-			'content' => $content,
305
-			'pageID' => $page->getPageID(),
306
-			'parent' => $parent,
307
-			'design' => $design,
308
-			'template' => $template,
309
-			'sitemap' => $sitemap,
310
-			'sitemap_changefreq' => $sitemap_changefreq,
311
-			'sitemap_priority' => $sitemap_priority,
312
-			'keywords' => $keywords,
313
-			'robots' => $robots,
314
-			'canoncials' => $canoncials,
315
-			'og_type' => $og_type
316
-		));
301
+        //update page in database
302
+        Database::getInstance()->execute("UPDATE `{praefix}pages` SET `title` = :title, `content` = :content, `parent` = :parent, `design` = :design, `template` = :template, `sitemap` = :sitemap, `sitemap_changefreq` = :sitemap_changefreq, `sitemap_priority` = :sitemap_priority, `meta_keywords` = :keywords, `meta_robots` = :robots, `meta_canonicals` = :canoncials, `og_type` = :og_type WHERE `id` = :pageID; ", array(
303
+            'title' => $title,
304
+            'content' => $content,
305
+            'pageID' => $page->getPageID(),
306
+            'parent' => $parent,
307
+            'design' => $design,
308
+            'template' => $template,
309
+            'sitemap' => $sitemap,
310
+            'sitemap_changefreq' => $sitemap_changefreq,
311
+            'sitemap_priority' => $sitemap_priority,
312
+            'keywords' => $keywords,
313
+            'robots' => $robots,
314
+            'canoncials' => $canoncials,
315
+            'og_type' => $og_type
316
+        ));
317 317
 
318
-		//clear cache
319
-		$page->clearCache();
318
+        //clear cache
319
+        $page->clearCache();
320 320
 
321
-		//reload page from database
322
-		$page->loadByID($page->getPageID(), false);
321
+        //reload page from database
322
+        $page->loadByID($page->getPageID(), false);
323 323
 
324
-		//TODO: remove this line later
325
-		Cache::clear("pages");
324
+        //TODO: remove this line later
325
+        Cache::clear("pages");
326 326
 
327
-		return true;
328
-	}
327
+        return true;
328
+    }
329 329
 
330
-	protected function publish (Page &$page) {
331
-		//check permissions for publishing
332
-		if (PermissionChecker::current()->hasRight("can_publish_all_pages") || (PermissionChecker::current()->hasRight("can_publish_own_pages") && $page->getAuthorID() == User::current()->getID())) {
333
-			//update page in database
334
-			Database::getInstance()->execute("UPDATE `{praefix}pages` SET `published` = '1' WHERE `id` = :pageID; ", array(
335
-				'pageID' => $page->getPageID()
336
-			));
330
+    protected function publish (Page &$page) {
331
+        //check permissions for publishing
332
+        if (PermissionChecker::current()->hasRight("can_publish_all_pages") || (PermissionChecker::current()->hasRight("can_publish_own_pages") && $page->getAuthorID() == User::current()->getID())) {
333
+            //update page in database
334
+            Database::getInstance()->execute("UPDATE `{praefix}pages` SET `published` = '1' WHERE `id` = :pageID; ", array(
335
+                'pageID' => $page->getPageID()
336
+            ));
337 337
 
338
-			//clear cache
339
-			$page->clearCache();
338
+            //clear cache
339
+            $page->clearCache();
340 340
 
341
-			//reload page from database
342
-			$page->loadByID($page->getPageID(), false);
343
-
344
-			//TODO: remove this line later
345
-			Cache::clear("pages");
341
+            //reload page from database
342
+            $page->loadByID($page->getPageID(), false);
343
+
344
+            //TODO: remove this line later
345
+            Cache::clear("pages");
346 346
 
347
-			return true;
348
-		} else {
349
-			return "You don't have the permissions to publish this page!";
350
-		}
351
-	}
352
-
353
-	protected function showError (string $message) : string {
354
-		//show error
355
-		$template = new DwooTemplate("pages/error");
356
-		$template->assign("message", "No pageID was set!");
357
-		return $template->getCode();
358
-	}
359
-
360
-	public function getFooterScripts(): string {
361
-		$style_name = Registry::singleton()->getSetting("current_style_name");
362
-		$style_path = DomainUtils::getBaseURL() . "/styles/" . $style_name . "/";
363
-
364
-		$thirdparty_url = Registry::singleton()->getSetting("thirdparty_url");
365
-
366
-		/*return "<!-- CK Editor -->
347
+            return true;
348
+        } else {
349
+            return "You don't have the permissions to publish this page!";
350
+        }
351
+    }
352
+
353
+    protected function showError (string $message) : string {
354
+        //show error
355
+        $template = new DwooTemplate("pages/error");
356
+        $template->assign("message", "No pageID was set!");
357
+        return $template->getCode();
358
+    }
359
+
360
+    public function getFooterScripts(): string {
361
+        $style_name = Registry::singleton()->getSetting("current_style_name");
362
+        $style_path = DomainUtils::getBaseURL() . "/styles/" . $style_name . "/";
363
+
364
+        $thirdparty_url = Registry::singleton()->getSetting("thirdparty_url");
365
+
366
+        /*return "<!-- CK Editor -->
367 367
 			<script src=\"" . $style_path . "bower_components/ckeditor/ckeditor.js\"></script>
368 368
 			
369 369
 			<script>
@@ -377,7 +377,7 @@  discard block
 block discarded – undo
377 377
 				});
378 378
 			</script>";*/
379 379
 
380
-		return "<script src=\"" . $thirdparty_url . "tinymce_4.8.2/js/tinymce/tinymce.min.js\"></script>
380
+        return "<script src=\"" . $thirdparty_url . "tinymce_4.8.2/js/tinymce/tinymce.min.js\"></script>
381 381
   				<script>tinymce.init({
382 382
 					  selector: 'textarea',
383 383
 					  height: 500,
@@ -409,11 +409,11 @@  discard block
 block discarded – undo
409 409
 					document.getElementById('inputSitemapPriority').disabled = !this.checked;
410 410
 				};
411 411
 				</script>";
412
-	}
412
+    }
413 413
 
414
-	public function listRequiredPermissions(): array {
415
-		return array("can_edit_all_pages", "can_edit_own_pages");
416
-	}
414
+    public function listRequiredPermissions(): array {
415
+        return array("can_edit_all_pages", "can_edit_own_pages");
416
+    }
417 417
 
418 418
 }
419 419
 
Please login to merge, or discard this patch.