@@ -18,326 +18,326 @@ |
||
| 18 | 18 | |
| 19 | 19 | class PageType { |
| 20 | 20 | |
| 21 | - protected $page = null; |
|
| 21 | + protected $page = null; |
|
| 22 | 22 | |
| 23 | - public function __construct() { |
|
| 24 | - // |
|
| 25 | - } |
|
| 23 | + public function __construct() { |
|
| 24 | + // |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - public function setPage (Page &$page) { |
|
| 28 | - $this->page = $page; |
|
| 29 | - } |
|
| 27 | + public function setPage (Page &$page) { |
|
| 28 | + $this->page = $page; |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - protected function getPage () : Page { |
|
| 32 | - return $this->page; |
|
| 33 | - } |
|
| 31 | + protected function getPage () : Page { |
|
| 32 | + return $this->page; |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - public function showDesign () { |
|
| 36 | - return true; |
|
| 37 | - } |
|
| 35 | + public function showDesign () { |
|
| 36 | + return true; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - public function getContentType () : string { |
|
| 40 | - return "" . $this->page->getContentType() . "; charset=" . $this->getCharset(); |
|
| 41 | - } |
|
| 39 | + public function getContentType () : string { |
|
| 40 | + return "" . $this->page->getContentType() . "; charset=" . $this->getCharset(); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - public function getCharset () : string { |
|
| 44 | - return "utf-8"; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - public function setCustomHeader () { |
|
| 48 | - // |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - public function getAdditionalHeaderCode () : string { |
|
| 52 | - return ""; |
|
| 53 | - } |
|
| 43 | + public function getCharset () : string { |
|
| 44 | + return "utf-8"; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + public function setCustomHeader () { |
|
| 48 | + // |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + public function getAdditionalHeaderCode () : string { |
|
| 52 | + return ""; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - public function showFooter () : bool { |
|
| 56 | - return true; |
|
| 57 | - } |
|
| 55 | + public function showFooter () : bool { |
|
| 56 | + return true; |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - public function getFooterScripts () : string { |
|
| 60 | - return ""; |
|
| 61 | - } |
|
| 59 | + public function getFooterScripts () : string { |
|
| 60 | + return ""; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - public function showHTMLComments () : bool { |
|
| 64 | - return true; |
|
| 65 | - } |
|
| 63 | + public function showHTMLComments () : bool { |
|
| 64 | + return true; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - public function getOgTitle () : string { |
|
| 68 | - return $this->page->getOgTitle(); |
|
| 69 | - } |
|
| 67 | + public function getOgTitle () : string { |
|
| 68 | + return $this->page->getOgTitle(); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - public function getOgType () : string { |
|
| 72 | - return $this->page->getOgType(); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - public function getOgImage () : string { |
|
| 76 | - return $this->page->getOgImage(); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - public function getOgUrl () : string { |
|
| 80 | - return DomainUtils::generateURL($this->page->getAlias()); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - public function getOgTags () : string { |
|
| 84 | - $tags = array(); |
|
| 85 | - $tags['og:type'] = $this->getOgType(); |
|
| 86 | - $tags['og:url'] = $this->getOgUrl(); |
|
| 87 | - $tags['og:title'] = $this->getOgTitle(); |
|
| 88 | - |
|
| 89 | - if (!empty($this->getOgImage())) { |
|
| 90 | - $tags['og:image'] = $this->getOgImage(); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - $this->getAdditionalTags($tags); |
|
| 94 | - |
|
| 95 | - Events::throwEvent("og_tags", array( |
|
| 96 | - 'page' => &$this->page, |
|
| 97 | - 'page_type' => &$this, |
|
| 98 | - 'tags' => &$tags |
|
| 99 | - )); |
|
| 100 | - |
|
| 101 | - $tags_lines = "<!-- OpenGraph tags -->\r\n"; |
|
| 102 | - |
|
| 103 | - foreach ($tags as $property=>$content) { |
|
| 104 | - $tags_lines .= "\t<meta property=\"" . $property . "\" content=\"" . $content . "\" />\r\n"; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - return $tags_lines; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * add additional tags |
|
| 112 | - * |
|
| 113 | - * This method was added so that page types doesn't have to override getOgTags() completely |
|
| 114 | - */ |
|
| 115 | - protected function getAdditionalTags (array &$tags) { |
|
| 116 | - //add additional tags |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - public function getContent () : string { |
|
| 120 | - $content = $this->getPage()->getContent(); |
|
| 121 | - |
|
| 122 | - //check, if page has custom template |
|
| 123 | - if ($this->getPage()->hasCustomTemplate()) { |
|
| 124 | - //get custom template |
|
| 125 | - $template = Validator_String::get($this->getPage()->getCustomTemplate()); |
|
| 126 | - |
|
| 127 | - $current_style = Registry::singleton()->getSetting("current_style_name"); |
|
| 128 | - |
|
| 129 | - //check, if custom template exists |
|
| 130 | - if (file_exists(STYLE_PATH . $current_style . "/" . $template)) { |
|
| 131 | - $template = new Template($template); |
|
| 132 | - |
|
| 133 | - $template->assign("TITLE", $this->getPage()->getTitle()); |
|
| 134 | - $template->assign("CONTENT", $content); |
|
| 135 | - |
|
| 136 | - $template->parse("main"); |
|
| 137 | - $content = $template->getCode(); |
|
| 138 | - } else { |
|
| 139 | - throw new IllegalStateException("Custom template '" . $template . "' doesnt exists."); |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - Events::throwEvent("get_content", array( |
|
| 144 | - 'content' => &$content, |
|
| 145 | - 'page' => &$this->page, |
|
| 146 | - 'page_type' => &$this |
|
| 147 | - )); |
|
| 148 | - |
|
| 149 | - return $content; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - public function generateNormalPage (string $content, $vars = array()) : string { |
|
| 153 | - $current_style = Registry::singleton()->getSetting("current_style_name"); |
|
| 154 | - |
|
| 155 | - if (file_exists(STYLE_PATH . $current_style . "/pages/normal.tpl")) { |
|
| 156 | - $template = new DwooTemplate(STYLE_PATH . $current_style . "/pages/normal.tpl"); |
|
| 157 | - |
|
| 158 | - $title_preafix = Settings::get("title_praefix", ""); |
|
| 159 | - $title_suffix = Settings::get("title_suffix", ""); |
|
| 160 | - |
|
| 161 | - //translate title |
|
| 162 | - $title = Translator::translateTitle($this->getPage()->getTitle()); |
|
| 163 | - |
|
| 164 | - $template->assign("RAW_TITLE", $title); |
|
| 165 | - $template->assign("TITLE", $title_preafix . $title . $title_suffix); |
|
| 166 | - $template->assign("CONTENT", $content); |
|
| 167 | - $template->assign("FOOTER", Registry::singleton()->getSetting("footer", "")); |
|
| 168 | - |
|
| 169 | - Events::throwEvent("generate_normal_page", array( |
|
| 170 | - 'template' => &$template, |
|
| 171 | - 'current_style' => $current_style, |
|
| 172 | - 'content' => &$content, |
|
| 173 | - 'page_type' => &$this, |
|
| 174 | - 'page' => $this->getPage() |
|
| 175 | - )); |
|
| 176 | - |
|
| 177 | - foreach ($vars as $key=>$value) { |
|
| 178 | - $template->assign($key, $value); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - return $template->getCode(); |
|
| 182 | - } else { |
|
| 183 | - throw new IllegalStateException("no normal template (pages/normal.tpl) found!"); |
|
| 184 | - //return $content; |
|
| 185 | - } |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - public function checkPermissions (PermissionChecker $permission_checker) { |
|
| 189 | - //first, check required permissions |
|
| 190 | - if (count($this->listRequiredPermissions()) > 0) { |
|
| 191 | - $bool = false; |
|
| 192 | - |
|
| 193 | - foreach ($this->listRequiredPermissions() as $permission) { |
|
| 194 | - if ($permission_checker->hasRight($permission)) { |
|
| 195 | - $bool = true; |
|
| 196 | - break; |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - if (!$bool) { |
|
| 201 | - return false; |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - if (!$this->getPage()->hasCustomPermissions()) { |
|
| 206 | - return true; |
|
| 207 | - } else { |
|
| 208 | - $permissions = $this->getPage()->listCustomPermissions(); |
|
| 209 | - |
|
| 210 | - foreach ($permissions as $permission) { |
|
| 211 | - if ($permission_checker->hasRight($permission)) { |
|
| 212 | - return true; |
|
| 213 | - } |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - return false; |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - protected function listRequiredPermissions () : array { |
|
| 221 | - return array(); |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - public function exitAfterOutput () { |
|
| 225 | - return false; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - public static function reloadCache () { |
|
| 229 | - Cache::clear("pagetypes"); |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - public static function listPageTypes (bool $advanced = false) : array { |
|
| 233 | - $rows = array(); |
|
| 234 | - |
|
| 235 | - $advanced_str = $advanced ? "advanced" : "normal"; |
|
| 236 | - |
|
| 237 | - if (Cache::contains("pagetypes", "list-" . $advanced_str)) { |
|
| 238 | - $rows = Cache::get("pagetypes", "list-" . $advanced_str); |
|
| 239 | - } else { |
|
| 240 | - if ($advanced) { |
|
| 241 | - //show all page types |
|
| 242 | - $rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}page_types` WHERE `activated` = '1' ORDER BY `order`; "); |
|
| 243 | - } else { |
|
| 244 | - //show only not-expert page types |
|
| 245 | - $rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}page_types` WHERE `advanced` = '0' AND `activated` = '1' ORDER BY `order`; "); |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - //put into cache |
|
| 249 | - Cache::put("pagetypes", "list-" . $advanced_str, $rows); |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - return $rows; |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - public static function createPageType (string $class_name, string $title, bool $advanced = false, int $order = 10, array $permissions = array("none"), string $owner = "system") { |
|
| 256 | - //validate values |
|
| 257 | - $class_name = Validator_String::get($class_name); |
|
| 258 | - $title = Validator_String::get($title); |
|
| 259 | - $order = Validator_Int::get($order); |
|
| 260 | - |
|
| 261 | - Events::throwEvent("before_add_pagetype", array( |
|
| 262 | - 'class_name' => &$class_name, |
|
| 263 | - 'title' => &$title, |
|
| 264 | - 'create_permissions' => &$permissions, |
|
| 265 | - 'advanced' => &$advanced, |
|
| 266 | - 'owner' => &$owner, |
|
| 267 | - 'order' => &$order |
|
| 268 | - )); |
|
| 269 | - |
|
| 270 | - //validate and convert array to string |
|
| 271 | - $permissions = implode("|", $permissions); |
|
| 272 | - $permissions = Validator_String::get($permissions); |
|
| 273 | - |
|
| 274 | - Database::getInstance()->execute("INSERT INTO `{praefix}page_types` ( |
|
| 71 | + public function getOgType () : string { |
|
| 72 | + return $this->page->getOgType(); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + public function getOgImage () : string { |
|
| 76 | + return $this->page->getOgImage(); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + public function getOgUrl () : string { |
|
| 80 | + return DomainUtils::generateURL($this->page->getAlias()); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + public function getOgTags () : string { |
|
| 84 | + $tags = array(); |
|
| 85 | + $tags['og:type'] = $this->getOgType(); |
|
| 86 | + $tags['og:url'] = $this->getOgUrl(); |
|
| 87 | + $tags['og:title'] = $this->getOgTitle(); |
|
| 88 | + |
|
| 89 | + if (!empty($this->getOgImage())) { |
|
| 90 | + $tags['og:image'] = $this->getOgImage(); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + $this->getAdditionalTags($tags); |
|
| 94 | + |
|
| 95 | + Events::throwEvent("og_tags", array( |
|
| 96 | + 'page' => &$this->page, |
|
| 97 | + 'page_type' => &$this, |
|
| 98 | + 'tags' => &$tags |
|
| 99 | + )); |
|
| 100 | + |
|
| 101 | + $tags_lines = "<!-- OpenGraph tags -->\r\n"; |
|
| 102 | + |
|
| 103 | + foreach ($tags as $property=>$content) { |
|
| 104 | + $tags_lines .= "\t<meta property=\"" . $property . "\" content=\"" . $content . "\" />\r\n"; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + return $tags_lines; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * add additional tags |
|
| 112 | + * |
|
| 113 | + * This method was added so that page types doesn't have to override getOgTags() completely |
|
| 114 | + */ |
|
| 115 | + protected function getAdditionalTags (array &$tags) { |
|
| 116 | + //add additional tags |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + public function getContent () : string { |
|
| 120 | + $content = $this->getPage()->getContent(); |
|
| 121 | + |
|
| 122 | + //check, if page has custom template |
|
| 123 | + if ($this->getPage()->hasCustomTemplate()) { |
|
| 124 | + //get custom template |
|
| 125 | + $template = Validator_String::get($this->getPage()->getCustomTemplate()); |
|
| 126 | + |
|
| 127 | + $current_style = Registry::singleton()->getSetting("current_style_name"); |
|
| 128 | + |
|
| 129 | + //check, if custom template exists |
|
| 130 | + if (file_exists(STYLE_PATH . $current_style . "/" . $template)) { |
|
| 131 | + $template = new Template($template); |
|
| 132 | + |
|
| 133 | + $template->assign("TITLE", $this->getPage()->getTitle()); |
|
| 134 | + $template->assign("CONTENT", $content); |
|
| 135 | + |
|
| 136 | + $template->parse("main"); |
|
| 137 | + $content = $template->getCode(); |
|
| 138 | + } else { |
|
| 139 | + throw new IllegalStateException("Custom template '" . $template . "' doesnt exists."); |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + Events::throwEvent("get_content", array( |
|
| 144 | + 'content' => &$content, |
|
| 145 | + 'page' => &$this->page, |
|
| 146 | + 'page_type' => &$this |
|
| 147 | + )); |
|
| 148 | + |
|
| 149 | + return $content; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + public function generateNormalPage (string $content, $vars = array()) : string { |
|
| 153 | + $current_style = Registry::singleton()->getSetting("current_style_name"); |
|
| 154 | + |
|
| 155 | + if (file_exists(STYLE_PATH . $current_style . "/pages/normal.tpl")) { |
|
| 156 | + $template = new DwooTemplate(STYLE_PATH . $current_style . "/pages/normal.tpl"); |
|
| 157 | + |
|
| 158 | + $title_preafix = Settings::get("title_praefix", ""); |
|
| 159 | + $title_suffix = Settings::get("title_suffix", ""); |
|
| 160 | + |
|
| 161 | + //translate title |
|
| 162 | + $title = Translator::translateTitle($this->getPage()->getTitle()); |
|
| 163 | + |
|
| 164 | + $template->assign("RAW_TITLE", $title); |
|
| 165 | + $template->assign("TITLE", $title_preafix . $title . $title_suffix); |
|
| 166 | + $template->assign("CONTENT", $content); |
|
| 167 | + $template->assign("FOOTER", Registry::singleton()->getSetting("footer", "")); |
|
| 168 | + |
|
| 169 | + Events::throwEvent("generate_normal_page", array( |
|
| 170 | + 'template' => &$template, |
|
| 171 | + 'current_style' => $current_style, |
|
| 172 | + 'content' => &$content, |
|
| 173 | + 'page_type' => &$this, |
|
| 174 | + 'page' => $this->getPage() |
|
| 175 | + )); |
|
| 176 | + |
|
| 177 | + foreach ($vars as $key=>$value) { |
|
| 178 | + $template->assign($key, $value); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + return $template->getCode(); |
|
| 182 | + } else { |
|
| 183 | + throw new IllegalStateException("no normal template (pages/normal.tpl) found!"); |
|
| 184 | + //return $content; |
|
| 185 | + } |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + public function checkPermissions (PermissionChecker $permission_checker) { |
|
| 189 | + //first, check required permissions |
|
| 190 | + if (count($this->listRequiredPermissions()) > 0) { |
|
| 191 | + $bool = false; |
|
| 192 | + |
|
| 193 | + foreach ($this->listRequiredPermissions() as $permission) { |
|
| 194 | + if ($permission_checker->hasRight($permission)) { |
|
| 195 | + $bool = true; |
|
| 196 | + break; |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + if (!$bool) { |
|
| 201 | + return false; |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + if (!$this->getPage()->hasCustomPermissions()) { |
|
| 206 | + return true; |
|
| 207 | + } else { |
|
| 208 | + $permissions = $this->getPage()->listCustomPermissions(); |
|
| 209 | + |
|
| 210 | + foreach ($permissions as $permission) { |
|
| 211 | + if ($permission_checker->hasRight($permission)) { |
|
| 212 | + return true; |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + return false; |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + protected function listRequiredPermissions () : array { |
|
| 221 | + return array(); |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + public function exitAfterOutput () { |
|
| 225 | + return false; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + public static function reloadCache () { |
|
| 229 | + Cache::clear("pagetypes"); |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + public static function listPageTypes (bool $advanced = false) : array { |
|
| 233 | + $rows = array(); |
|
| 234 | + |
|
| 235 | + $advanced_str = $advanced ? "advanced" : "normal"; |
|
| 236 | + |
|
| 237 | + if (Cache::contains("pagetypes", "list-" . $advanced_str)) { |
|
| 238 | + $rows = Cache::get("pagetypes", "list-" . $advanced_str); |
|
| 239 | + } else { |
|
| 240 | + if ($advanced) { |
|
| 241 | + //show all page types |
|
| 242 | + $rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}page_types` WHERE `activated` = '1' ORDER BY `order`; "); |
|
| 243 | + } else { |
|
| 244 | + //show only not-expert page types |
|
| 245 | + $rows = Database::getInstance()->listRows("SELECT * FROM `{praefix}page_types` WHERE `advanced` = '0' AND `activated` = '1' ORDER BY `order`; "); |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + //put into cache |
|
| 249 | + Cache::put("pagetypes", "list-" . $advanced_str, $rows); |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + return $rows; |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + public static function createPageType (string $class_name, string $title, bool $advanced = false, int $order = 10, array $permissions = array("none"), string $owner = "system") { |
|
| 256 | + //validate values |
|
| 257 | + $class_name = Validator_String::get($class_name); |
|
| 258 | + $title = Validator_String::get($title); |
|
| 259 | + $order = Validator_Int::get($order); |
|
| 260 | + |
|
| 261 | + Events::throwEvent("before_add_pagetype", array( |
|
| 262 | + 'class_name' => &$class_name, |
|
| 263 | + 'title' => &$title, |
|
| 264 | + 'create_permissions' => &$permissions, |
|
| 265 | + 'advanced' => &$advanced, |
|
| 266 | + 'owner' => &$owner, |
|
| 267 | + 'order' => &$order |
|
| 268 | + )); |
|
| 269 | + |
|
| 270 | + //validate and convert array to string |
|
| 271 | + $permissions = implode("|", $permissions); |
|
| 272 | + $permissions = Validator_String::get($permissions); |
|
| 273 | + |
|
| 274 | + Database::getInstance()->execute("INSERT INTO `{praefix}page_types` ( |
|
| 275 | 275 | `page_type`, `title`, `create_permissions`, `advanced`, `owner`, `order`, `activated` |
| 276 | 276 | ) VALUES ( |
| 277 | 277 | :pagetype, :title, :permissions, :advanced, :owner, :order, '1' |
| 278 | 278 | ) ON DUPLICATE KEY UPDATE `title` = :title, `create_permissions` = :permissions, `advanced` = :advanced, `owner` = :owner, `order` = :order, `activated` = '1'; ", array( |
| 279 | - 'pagetype' => $class_name, |
|
| 280 | - 'title' => $title, |
|
| 281 | - 'permissions' => $permissions, |
|
| 282 | - 'advanced' => ($advanced ? 1 : 0), |
|
| 283 | - 'owner' => $owner, |
|
| 284 | - 'order' => $order |
|
| 285 | - )); |
|
| 286 | - |
|
| 287 | - Events::throwEvent("after_add_pagetype", array( |
|
| 288 | - 'class_name' => $class_name, |
|
| 289 | - 'title' => $title, |
|
| 290 | - 'create_permissions' => $permissions, |
|
| 291 | - 'advanced' => $advanced, |
|
| 292 | - 'owner' => $owner, |
|
| 293 | - 'order' => $order |
|
| 294 | - )); |
|
| 295 | - |
|
| 296 | - //clear cache |
|
| 297 | - Cache::clear("pagetypes"); |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - public static function removePageType (string $class_name) { |
|
| 301 | - //validate value |
|
| 302 | - $class_name = Validator_String::get($class_name); |
|
| 303 | - |
|
| 304 | - $delete = true; |
|
| 305 | - |
|
| 306 | - //throw event, so plugins can interact |
|
| 307 | - Events::throwEvent("before_remove_pagetype", array( |
|
| 308 | - 'class_name' => &$class_name, |
|
| 309 | - 'delete' => &$delete |
|
| 310 | - )); |
|
| 311 | - |
|
| 312 | - if ($delete) { |
|
| 313 | - Database::getInstance()->execute("DELETE FROM `{praefix}page_types` WHERE `page_type` = :pagetype; ", array('pagetype' => $class_name)); |
|
| 314 | - |
|
| 315 | - //throw event, so plugins can interact |
|
| 316 | - Events::throwEvent("after_remove_pagetype", array( |
|
| 317 | - 'class_name' => $class_name |
|
| 318 | - )); |
|
| 319 | - |
|
| 320 | - //clear cache |
|
| 321 | - Cache::clear("pagetypes"); |
|
| 322 | - } |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - public static function removePageTypesByOwner (string $owner) { |
|
| 326 | - Database::getInstance()->execute("DELETE FROM `{praefix}page_types` WHERE `owner` = :owner; ", array('owner' => $owner)); |
|
| 327 | - |
|
| 328 | - //TODO: change all pages which have this page type |
|
| 329 | - |
|
| 330 | - //clear cache |
|
| 331 | - Cache::clear("pagetypes"); |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - public static function exists (string $class_name) : bool { |
|
| 335 | - $row = Database::getInstance()->getRow("SELECT * FROM `{praefix}page_types` WHERE `page_type` = :pagetype; ", array( |
|
| 336 | - 'pagetype' => $class_name |
|
| 337 | - )); |
|
| 338 | - |
|
| 339 | - return $row !== false; |
|
| 340 | - } |
|
| 279 | + 'pagetype' => $class_name, |
|
| 280 | + 'title' => $title, |
|
| 281 | + 'permissions' => $permissions, |
|
| 282 | + 'advanced' => ($advanced ? 1 : 0), |
|
| 283 | + 'owner' => $owner, |
|
| 284 | + 'order' => $order |
|
| 285 | + )); |
|
| 286 | + |
|
| 287 | + Events::throwEvent("after_add_pagetype", array( |
|
| 288 | + 'class_name' => $class_name, |
|
| 289 | + 'title' => $title, |
|
| 290 | + 'create_permissions' => $permissions, |
|
| 291 | + 'advanced' => $advanced, |
|
| 292 | + 'owner' => $owner, |
|
| 293 | + 'order' => $order |
|
| 294 | + )); |
|
| 295 | + |
|
| 296 | + //clear cache |
|
| 297 | + Cache::clear("pagetypes"); |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + public static function removePageType (string $class_name) { |
|
| 301 | + //validate value |
|
| 302 | + $class_name = Validator_String::get($class_name); |
|
| 303 | + |
|
| 304 | + $delete = true; |
|
| 305 | + |
|
| 306 | + //throw event, so plugins can interact |
|
| 307 | + Events::throwEvent("before_remove_pagetype", array( |
|
| 308 | + 'class_name' => &$class_name, |
|
| 309 | + 'delete' => &$delete |
|
| 310 | + )); |
|
| 311 | + |
|
| 312 | + if ($delete) { |
|
| 313 | + Database::getInstance()->execute("DELETE FROM `{praefix}page_types` WHERE `page_type` = :pagetype; ", array('pagetype' => $class_name)); |
|
| 314 | + |
|
| 315 | + //throw event, so plugins can interact |
|
| 316 | + Events::throwEvent("after_remove_pagetype", array( |
|
| 317 | + 'class_name' => $class_name |
|
| 318 | + )); |
|
| 319 | + |
|
| 320 | + //clear cache |
|
| 321 | + Cache::clear("pagetypes"); |
|
| 322 | + } |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + public static function removePageTypesByOwner (string $owner) { |
|
| 326 | + Database::getInstance()->execute("DELETE FROM `{praefix}page_types` WHERE `owner` = :owner; ", array('owner' => $owner)); |
|
| 327 | + |
|
| 328 | + //TODO: change all pages which have this page type |
|
| 329 | + |
|
| 330 | + //clear cache |
|
| 331 | + Cache::clear("pagetypes"); |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + public static function exists (string $class_name) : bool { |
|
| 335 | + $row = Database::getInstance()->getRow("SELECT * FROM `{praefix}page_types` WHERE `page_type` = :pagetype; ", array( |
|
| 336 | + 'pagetype' => $class_name |
|
| 337 | + )); |
|
| 338 | + |
|
| 339 | + return $row !== false; |
|
| 340 | + } |
|
| 341 | 341 | |
| 342 | 342 | } |
| 343 | 343 | |