@@ -18,334 +18,334 @@ |
||
| 18 | 18 | |
| 19 | 19 | class Page { |
| 20 | 20 | |
| 21 | - protected $alias = null; |
|
| 22 | - protected $row = null; |
|
| 23 | - protected $pagetype = ""; |
|
| 24 | - |
|
| 25 | - protected $author = null; |
|
| 26 | - |
|
| 27 | - public function __construct() { |
|
| 28 | - // |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - public function load ($alias = null) { |
|
| 32 | - if ($alias == null) { |
|
| 33 | - if (isset($_REQUEST['page']) && !empty($_REQUEST['page'])) { |
|
| 34 | - $alias = Validator_String::get($_REQUEST['page']); |
|
| 35 | - } else { |
|
| 36 | - $alias = $this->getDomain()->getHomePage(); |
|
| 37 | - } |
|
| 38 | - } else { |
|
| 39 | - //$alias = Database::getInstance()->escape($alias); |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - Events::throwEvent("get_alias", array( |
|
| 43 | - 'alias' => &$alias, |
|
| 44 | - 'page' => &$this, |
|
| 45 | - 'domain' => $this->getDomain() |
|
| 46 | - )); |
|
| 47 | - |
|
| 48 | - $this->alias = $alias; |
|
| 49 | - |
|
| 50 | - if (Cache::contains("pages", "page_" . $alias)) { |
|
| 51 | - $this->row = Cache::get("pages", "page_" . $alias); |
|
| 52 | - } else { |
|
| 53 | - $row = Database::getInstance()->getRow("SELECT * FROM `{praefix}pages` WHERE `alias` = :alias AND `activated` = '1'; ", array('alias' => $alias)); |
|
| 54 | - |
|
| 55 | - if (!$row) { |
|
| 56 | - if (PHPUtils::strEqs("error404", $alias)) { |
|
| 57 | - throw new IllegalStateException("No page with alias 'error404' exists (requested alias: " . $alias . ")."); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - //page not found |
|
| 61 | - $new_alias = "error404"; |
|
| 62 | - |
|
| 63 | - Events::throwEvent("load_page_error404", array( |
|
| 64 | - 'alias' => &$new_alias, |
|
| 65 | - 'original_alias' => $alias, |
|
| 66 | - 'page' => &$this, |
|
| 67 | - 'domain' => $this->getDomain() |
|
| 68 | - )); |
|
| 69 | - |
|
| 70 | - $this->load($new_alias); |
|
| 71 | - return null; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - $this->row = $row; |
|
| 75 | - |
|
| 76 | - //cache result |
|
| 77 | - Cache::put("pages", "page_" . $alias, $row); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - //get name of page type (class name) |
|
| 81 | - $this->pagetype = $this->row['page_type']; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - protected function getDomain () : Domain { |
|
| 85 | - return Registry::singleton()->getObject("domain"); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - public function reloadCache () { |
|
| 89 | - Cache::clear("pages"); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - public function getPageID () : int { |
|
| 93 | - return $this->row['id']; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - public function getAlias () : string { |
|
| 97 | - return $this->alias; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - public function getPageType () : string { |
|
| 101 | - return $this->pagetype; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - public function getTitle () : string { |
|
| 105 | - return $this->row['title']; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - public function getContent () : string { |
|
| 109 | - return $this->row['content']; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - public function getGlobalMenuID () : int { |
|
| 113 | - return $this->row['global_menu']; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - public function getLocalMenuID () : int { |
|
| 117 | - return $this->row['local_menu']; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - public function getStyle () : string { |
|
| 121 | - return $this->row['design']; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - public function getFolder () : string { |
|
| 125 | - return $this->row['folder']; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - public function getLastEdit () { |
|
| 129 | - return $this->row['lastUpdate']; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - public function hasCustomTemplate () : bool { |
|
| 133 | - return $this->row['template'] !== "none"; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - public function getCustomTemplate () : string { |
|
| 137 | - return $this->row['template']; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - public function hasCustomPermissions () : bool { |
|
| 141 | - return $this->row['can_see_permissions'] !== "none"; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - public function listCustomPermissions () : array { |
|
| 145 | - return explode("|", $this->row['can_see_permissions']); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - public function isPublished () : bool { |
|
| 149 | - return $this->row['published'] == 1; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - public function getContentType () : string { |
|
| 153 | - return $this->row['content_type']; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - public function getLeftSidebarID () : int { |
|
| 157 | - return $this->row['sidebar_left']; |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - public function getRightSidebarID () : int { |
|
| 161 | - return $this->row['sidebar_right']; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - public function getMetaDescription () : string { |
|
| 165 | - return $this->row['meta_description']; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - public function getMetaKeywords () : string { |
|
| 169 | - return $this->row['meta_keywords']; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - public function getMetaRobotsOptions () : string { |
|
| 173 | - return $this->row['meta_robots']; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - public function getMetaCanonicals () : string { |
|
| 177 | - return $this->row['meta_canonicals']; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - public function getAuthorID () : int { |
|
| 181 | - return $this->row['author']; |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - public function getAuthor () : User { |
|
| 185 | - if ($this->author == null) { |
|
| 186 | - //load author |
|
| 187 | - $this->author = new User(); |
|
| 188 | - |
|
| 189 | - if ($this->getAuthorID() <= 0) { |
|
| 190 | - throw new IllegalArgumentException("authorID has to be > 0."); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - $this->author->load($this->getAuthorID()); |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - return $this->author; |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - public function activate (bool $bool = true) { |
|
| 200 | - $this->row['activated'] = $bool; |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * save changes into database |
|
| 205 | - */ |
|
| 206 | - public function save () { |
|
| 207 | - //TODO: add code here |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - public static function createIfAbsent (string $alias, string $title, string $page_type, string $content = "", string $folder = "/", int $globalMenu = -1, int $localMenu = -1, int $parentID = -1, bool $sitemap = true, bool $published = true, bool $editable = true, string $author = "system") : int { |
|
| 211 | - //throw event |
|
| 212 | - Events::throwEvent("create_page", array( |
|
| 213 | - 'alias' => &$alias, |
|
| 214 | - 'title' => &$title, |
|
| 215 | - 'page_type' => &$page_type, |
|
| 216 | - 'content' => &$content, |
|
| 217 | - 'folder' => &$folder, |
|
| 218 | - 'global_menu' => &$globalMenu, |
|
| 219 | - 'local_menu' => &$localMenu, |
|
| 220 | - 'parentID' => &$parentID, |
|
| 221 | - 'sitemap' => &$sitemap, |
|
| 222 | - 'published' => &$published, |
|
| 223 | - 'editable' => &$editable, |
|
| 224 | - 'author' => &$author |
|
| 225 | - )); |
|
| 226 | - |
|
| 227 | - if (!is_int($author)) { |
|
| 228 | - //get userID of author |
|
| 229 | - $author = User::getIDByUsernameFromDB($author); |
|
| 230 | - } else { |
|
| 231 | - $author = (int) $author; |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - Database::getInstance()->execute("INSERT INTO `{praefix}pages` ( |
|
| 21 | + protected $alias = null; |
|
| 22 | + protected $row = null; |
|
| 23 | + protected $pagetype = ""; |
|
| 24 | + |
|
| 25 | + protected $author = null; |
|
| 26 | + |
|
| 27 | + public function __construct() { |
|
| 28 | + // |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + public function load ($alias = null) { |
|
| 32 | + if ($alias == null) { |
|
| 33 | + if (isset($_REQUEST['page']) && !empty($_REQUEST['page'])) { |
|
| 34 | + $alias = Validator_String::get($_REQUEST['page']); |
|
| 35 | + } else { |
|
| 36 | + $alias = $this->getDomain()->getHomePage(); |
|
| 37 | + } |
|
| 38 | + } else { |
|
| 39 | + //$alias = Database::getInstance()->escape($alias); |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + Events::throwEvent("get_alias", array( |
|
| 43 | + 'alias' => &$alias, |
|
| 44 | + 'page' => &$this, |
|
| 45 | + 'domain' => $this->getDomain() |
|
| 46 | + )); |
|
| 47 | + |
|
| 48 | + $this->alias = $alias; |
|
| 49 | + |
|
| 50 | + if (Cache::contains("pages", "page_" . $alias)) { |
|
| 51 | + $this->row = Cache::get("pages", "page_" . $alias); |
|
| 52 | + } else { |
|
| 53 | + $row = Database::getInstance()->getRow("SELECT * FROM `{praefix}pages` WHERE `alias` = :alias AND `activated` = '1'; ", array('alias' => $alias)); |
|
| 54 | + |
|
| 55 | + if (!$row) { |
|
| 56 | + if (PHPUtils::strEqs("error404", $alias)) { |
|
| 57 | + throw new IllegalStateException("No page with alias 'error404' exists (requested alias: " . $alias . ")."); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + //page not found |
|
| 61 | + $new_alias = "error404"; |
|
| 62 | + |
|
| 63 | + Events::throwEvent("load_page_error404", array( |
|
| 64 | + 'alias' => &$new_alias, |
|
| 65 | + 'original_alias' => $alias, |
|
| 66 | + 'page' => &$this, |
|
| 67 | + 'domain' => $this->getDomain() |
|
| 68 | + )); |
|
| 69 | + |
|
| 70 | + $this->load($new_alias); |
|
| 71 | + return null; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + $this->row = $row; |
|
| 75 | + |
|
| 76 | + //cache result |
|
| 77 | + Cache::put("pages", "page_" . $alias, $row); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + //get name of page type (class name) |
|
| 81 | + $this->pagetype = $this->row['page_type']; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + protected function getDomain () : Domain { |
|
| 85 | + return Registry::singleton()->getObject("domain"); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + public function reloadCache () { |
|
| 89 | + Cache::clear("pages"); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + public function getPageID () : int { |
|
| 93 | + return $this->row['id']; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + public function getAlias () : string { |
|
| 97 | + return $this->alias; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + public function getPageType () : string { |
|
| 101 | + return $this->pagetype; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + public function getTitle () : string { |
|
| 105 | + return $this->row['title']; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + public function getContent () : string { |
|
| 109 | + return $this->row['content']; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + public function getGlobalMenuID () : int { |
|
| 113 | + return $this->row['global_menu']; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + public function getLocalMenuID () : int { |
|
| 117 | + return $this->row['local_menu']; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + public function getStyle () : string { |
|
| 121 | + return $this->row['design']; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + public function getFolder () : string { |
|
| 125 | + return $this->row['folder']; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + public function getLastEdit () { |
|
| 129 | + return $this->row['lastUpdate']; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + public function hasCustomTemplate () : bool { |
|
| 133 | + return $this->row['template'] !== "none"; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + public function getCustomTemplate () : string { |
|
| 137 | + return $this->row['template']; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + public function hasCustomPermissions () : bool { |
|
| 141 | + return $this->row['can_see_permissions'] !== "none"; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + public function listCustomPermissions () : array { |
|
| 145 | + return explode("|", $this->row['can_see_permissions']); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + public function isPublished () : bool { |
|
| 149 | + return $this->row['published'] == 1; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + public function getContentType () : string { |
|
| 153 | + return $this->row['content_type']; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + public function getLeftSidebarID () : int { |
|
| 157 | + return $this->row['sidebar_left']; |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + public function getRightSidebarID () : int { |
|
| 161 | + return $this->row['sidebar_right']; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + public function getMetaDescription () : string { |
|
| 165 | + return $this->row['meta_description']; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + public function getMetaKeywords () : string { |
|
| 169 | + return $this->row['meta_keywords']; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + public function getMetaRobotsOptions () : string { |
|
| 173 | + return $this->row['meta_robots']; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + public function getMetaCanonicals () : string { |
|
| 177 | + return $this->row['meta_canonicals']; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + public function getAuthorID () : int { |
|
| 181 | + return $this->row['author']; |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + public function getAuthor () : User { |
|
| 185 | + if ($this->author == null) { |
|
| 186 | + //load author |
|
| 187 | + $this->author = new User(); |
|
| 188 | + |
|
| 189 | + if ($this->getAuthorID() <= 0) { |
|
| 190 | + throw new IllegalArgumentException("authorID has to be > 0."); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + $this->author->load($this->getAuthorID()); |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + return $this->author; |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + public function activate (bool $bool = true) { |
|
| 200 | + $this->row['activated'] = $bool; |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * save changes into database |
|
| 205 | + */ |
|
| 206 | + public function save () { |
|
| 207 | + //TODO: add code here |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + public static function createIfAbsent (string $alias, string $title, string $page_type, string $content = "", string $folder = "/", int $globalMenu = -1, int $localMenu = -1, int $parentID = -1, bool $sitemap = true, bool $published = true, bool $editable = true, string $author = "system") : int { |
|
| 211 | + //throw event |
|
| 212 | + Events::throwEvent("create_page", array( |
|
| 213 | + 'alias' => &$alias, |
|
| 214 | + 'title' => &$title, |
|
| 215 | + 'page_type' => &$page_type, |
|
| 216 | + 'content' => &$content, |
|
| 217 | + 'folder' => &$folder, |
|
| 218 | + 'global_menu' => &$globalMenu, |
|
| 219 | + 'local_menu' => &$localMenu, |
|
| 220 | + 'parentID' => &$parentID, |
|
| 221 | + 'sitemap' => &$sitemap, |
|
| 222 | + 'published' => &$published, |
|
| 223 | + 'editable' => &$editable, |
|
| 224 | + 'author' => &$author |
|
| 225 | + )); |
|
| 226 | + |
|
| 227 | + if (!is_int($author)) { |
|
| 228 | + //get userID of author |
|
| 229 | + $author = User::getIDByUsernameFromDB($author); |
|
| 230 | + } else { |
|
| 231 | + $author = (int) $author; |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + Database::getInstance()->execute("INSERT INTO `{praefix}pages` ( |
|
| 235 | 235 | `id`, `alias`, `title`, `content`, `parent`, `folder`, `global_menu`, `local_menu`, `page_type`, `design`, `sitemap`, `published`, `version`, `last_update`, `created`, `editable`, `author`, `activated` |
| 236 | 236 | ) VALUES ( |
| 237 | 237 | NULL, :alias, :title, :content, :parent, :folder, :globalMenu, :localMenu, :pageType, 'none', :sitemap, :published, '1', '0000-00-00 00:00:00', CURRENT_TIMESTAMP, :editable, :author, '1' |
| 238 | 238 | ) ON DUPLICATE KEY UPDATE `alias` = :alias; ", array( |
| 239 | - 'alias' => $alias, |
|
| 240 | - 'title' => $title, |
|
| 241 | - 'content' => $content, |
|
| 242 | - 'parent' => $parentID, |
|
| 243 | - 'folder' => $folder, |
|
| 244 | - 'globalMenu' => $globalMenu, |
|
| 245 | - 'localMenu' => $localMenu, |
|
| 246 | - 'pageType' => $page_type, |
|
| 247 | - 'sitemap' => ($sitemap ? 1 : 0), |
|
| 248 | - 'published' => ($published ? 1 : 0), |
|
| 249 | - 'editable' => ($editable ? 1 : 0), |
|
| 250 | - 'author' => $author |
|
| 251 | - )); |
|
| 252 | - |
|
| 253 | - Cache::clear("pages"); |
|
| 254 | - |
|
| 255 | - //return page id |
|
| 256 | - $insertID = Database::getInstance()->lastInsertId(); |
|
| 257 | - |
|
| 258 | - //throw event |
|
| 259 | - Events::throwEvent("created_page", array( |
|
| 260 | - 'alias' => $alias, |
|
| 261 | - 'title' => $title, |
|
| 262 | - 'insertID' => $insertID |
|
| 263 | - )); |
|
| 264 | - |
|
| 265 | - //get pageID by alias |
|
| 266 | - $pageID = Page::getPageIDByAlias($alias); |
|
| 267 | - |
|
| 268 | - //set default rights, allow page for administrators, registered users, guests and bots |
|
| 269 | - PageRights::setDefaultAllowedGroups($pageID, array(1, 2, 3, 4)); |
|
| 270 | - |
|
| 271 | - return $pageID; |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - public static function delete (string $alias) { |
|
| 275 | - $delete = true; |
|
| 276 | - |
|
| 277 | - //plugins can avoid deletion or change alias |
|
| 278 | - Events::throwEvent("delete_page_alias", array( |
|
| 279 | - 'alias' => &$alias, |
|
| 280 | - 'delete' => &$delete |
|
| 281 | - )); |
|
| 282 | - |
|
| 283 | - if ($delete) { |
|
| 284 | - //remove page from database |
|
| 285 | - Database::getInstance()->execute("DELETE FROM `{praefix}pages` WHERE `alias` = :alias; ", array('alias' => $alias)); |
|
| 286 | - |
|
| 287 | - Cache::clear("pages"); |
|
| 288 | - } |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - public static function deleteByID (int $id) { |
|
| 292 | - $delete = true; |
|
| 293 | - |
|
| 294 | - //plugins can avoid deletion or change alias |
|
| 295 | - Events::throwEvent("delete_page_id", array( |
|
| 296 | - 'alias' => &$id, |
|
| 297 | - 'delete' => &$delete |
|
| 298 | - )); |
|
| 299 | - |
|
| 300 | - if ($delete) { |
|
| 301 | - //remove page from database |
|
| 302 | - Database::getInstance()->execute("DELETE FROM `{praefix}pages` WHERE `id` = :id; ", array('id' => $id)); |
|
| 303 | - |
|
| 304 | - Cache::clear("pages"); |
|
| 305 | - } |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - public static function get (string $alias) : Page { |
|
| 309 | - $page = new Page(); |
|
| 310 | - $page->load($alias); |
|
| 311 | - |
|
| 312 | - return $page; |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - public static function setPageType (string $alias, string $page_type) { |
|
| 316 | - Events::throwEvent("set_pagetype", array( |
|
| 317 | - 'alias' => &$alias, |
|
| 318 | - 'page_type' => &$page_type |
|
| 319 | - )); |
|
| 320 | - |
|
| 321 | - Database::getInstance()->execute("UPDATE `{praefix}pages` SET `page_type` = :page_type WHERE `alias` = :alias; ", array( |
|
| 322 | - 'alias' => $alias, |
|
| 323 | - 'page_type' => $page_type |
|
| 324 | - )); |
|
| 325 | - |
|
| 326 | - Cache::clear("pages"); |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - /** |
|
| 330 | - * get id of page by alias |
|
| 331 | - * |
|
| 332 | - * only use this method for database upgrade, because their is no caching for this method! |
|
| 333 | - * |
|
| 334 | - * @param string $alias alias of page |
|
| 335 | - * |
|
| 336 | - * @throws IllegalStateException if alias doesnt exists |
|
| 337 | - * |
|
| 338 | - * @return int pageID |
|
| 339 | - */ |
|
| 340 | - public static function getPageIDByAlias (string $alias) : int { |
|
| 341 | - $row = Database::getInstance()->getRow("SELECT * FROM `{praefix}pages` WHERE `alias` = :alias; ", array('alias' => $alias)); |
|
| 342 | - |
|
| 343 | - if (!$row) { |
|
| 344 | - throw new IllegalStateException("page with alias '" . $alias . "' doesnt exists."); |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - return $row['id']; |
|
| 348 | - } |
|
| 239 | + 'alias' => $alias, |
|
| 240 | + 'title' => $title, |
|
| 241 | + 'content' => $content, |
|
| 242 | + 'parent' => $parentID, |
|
| 243 | + 'folder' => $folder, |
|
| 244 | + 'globalMenu' => $globalMenu, |
|
| 245 | + 'localMenu' => $localMenu, |
|
| 246 | + 'pageType' => $page_type, |
|
| 247 | + 'sitemap' => ($sitemap ? 1 : 0), |
|
| 248 | + 'published' => ($published ? 1 : 0), |
|
| 249 | + 'editable' => ($editable ? 1 : 0), |
|
| 250 | + 'author' => $author |
|
| 251 | + )); |
|
| 252 | + |
|
| 253 | + Cache::clear("pages"); |
|
| 254 | + |
|
| 255 | + //return page id |
|
| 256 | + $insertID = Database::getInstance()->lastInsertId(); |
|
| 257 | + |
|
| 258 | + //throw event |
|
| 259 | + Events::throwEvent("created_page", array( |
|
| 260 | + 'alias' => $alias, |
|
| 261 | + 'title' => $title, |
|
| 262 | + 'insertID' => $insertID |
|
| 263 | + )); |
|
| 264 | + |
|
| 265 | + //get pageID by alias |
|
| 266 | + $pageID = Page::getPageIDByAlias($alias); |
|
| 267 | + |
|
| 268 | + //set default rights, allow page for administrators, registered users, guests and bots |
|
| 269 | + PageRights::setDefaultAllowedGroups($pageID, array(1, 2, 3, 4)); |
|
| 270 | + |
|
| 271 | + return $pageID; |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + public static function delete (string $alias) { |
|
| 275 | + $delete = true; |
|
| 276 | + |
|
| 277 | + //plugins can avoid deletion or change alias |
|
| 278 | + Events::throwEvent("delete_page_alias", array( |
|
| 279 | + 'alias' => &$alias, |
|
| 280 | + 'delete' => &$delete |
|
| 281 | + )); |
|
| 282 | + |
|
| 283 | + if ($delete) { |
|
| 284 | + //remove page from database |
|
| 285 | + Database::getInstance()->execute("DELETE FROM `{praefix}pages` WHERE `alias` = :alias; ", array('alias' => $alias)); |
|
| 286 | + |
|
| 287 | + Cache::clear("pages"); |
|
| 288 | + } |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + public static function deleteByID (int $id) { |
|
| 292 | + $delete = true; |
|
| 293 | + |
|
| 294 | + //plugins can avoid deletion or change alias |
|
| 295 | + Events::throwEvent("delete_page_id", array( |
|
| 296 | + 'alias' => &$id, |
|
| 297 | + 'delete' => &$delete |
|
| 298 | + )); |
|
| 299 | + |
|
| 300 | + if ($delete) { |
|
| 301 | + //remove page from database |
|
| 302 | + Database::getInstance()->execute("DELETE FROM `{praefix}pages` WHERE `id` = :id; ", array('id' => $id)); |
|
| 303 | + |
|
| 304 | + Cache::clear("pages"); |
|
| 305 | + } |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + public static function get (string $alias) : Page { |
|
| 309 | + $page = new Page(); |
|
| 310 | + $page->load($alias); |
|
| 311 | + |
|
| 312 | + return $page; |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + public static function setPageType (string $alias, string $page_type) { |
|
| 316 | + Events::throwEvent("set_pagetype", array( |
|
| 317 | + 'alias' => &$alias, |
|
| 318 | + 'page_type' => &$page_type |
|
| 319 | + )); |
|
| 320 | + |
|
| 321 | + Database::getInstance()->execute("UPDATE `{praefix}pages` SET `page_type` = :page_type WHERE `alias` = :alias; ", array( |
|
| 322 | + 'alias' => $alias, |
|
| 323 | + 'page_type' => $page_type |
|
| 324 | + )); |
|
| 325 | + |
|
| 326 | + Cache::clear("pages"); |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + /** |
|
| 330 | + * get id of page by alias |
|
| 331 | + * |
|
| 332 | + * only use this method for database upgrade, because their is no caching for this method! |
|
| 333 | + * |
|
| 334 | + * @param string $alias alias of page |
|
| 335 | + * |
|
| 336 | + * @throws IllegalStateException if alias doesnt exists |
|
| 337 | + * |
|
| 338 | + * @return int pageID |
|
| 339 | + */ |
|
| 340 | + public static function getPageIDByAlias (string $alias) : int { |
|
| 341 | + $row = Database::getInstance()->getRow("SELECT * FROM `{praefix}pages` WHERE `alias` = :alias; ", array('alias' => $alias)); |
|
| 342 | + |
|
| 343 | + if (!$row) { |
|
| 344 | + throw new IllegalStateException("page with alias '" . $alias . "' doesnt exists."); |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + return $row['id']; |
|
| 348 | + } |
|
| 349 | 349 | |
| 350 | 350 | } |
| 351 | 351 | |