@@ -74,8 +74,8 @@ discard block |
||
| 74 | 74 | * Constructor |
| 75 | 75 | * @param mixed $params associative array of parameters. See README.md |
| 76 | 76 | */ |
| 77 | - function __construct($params=null) { |
|
| 78 | - $this->ci =& /** @scrutinizer ignore-call */ get_instance(); |
|
| 77 | + function __construct($params = null) { |
|
| 78 | + $this->ci = & /** @scrutinizer ignore-call */ get_instance(); |
|
| 79 | 79 | $this->ci->load->database(); |
| 80 | 80 | $this->table_name = self::TABLE_PREFIX . (isset($params["name"]) ? "_" . $params["name"] : ""); |
| 81 | 81 | $this->ci->load->database(); |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | * |
| 100 | 100 | * @return bool True on Success, False if Not. |
| 101 | 101 | */ |
| 102 | - public function install(string $blogName=null, string $adminTableName=null, string $adminIdColumnName=null, int $adminIdColumnConstraint=null): bool { |
|
| 102 | + public function install(string $blogName = null, string $adminTableName = null, string $adminIdColumnName = null, int $adminIdColumnConstraint = null): bool { |
|
| 103 | 103 | $blogName = $blogName === null ? $this->table_name : self::TABLE_PREFIX . "_" . $blogName; |
| 104 | 104 | $this->ci->load->dbforge(); |
| 105 | 105 | $this->ci->dbforge->add_field("id"); |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | * |
| 216 | 216 | * @return bool True if sucessfull without errors, false if not. |
| 217 | 217 | */ |
| 218 | - public function loadEditor(string $callback, int $postId=null, bool $w3css=true): bool { |
|
| 218 | + public function loadEditor(string $callback, int $postId = null, bool $w3css = true): bool { |
|
| 219 | 219 | $this->loadScripts($w3css); |
| 220 | 220 | $this->ci->load->helper("form"); |
| 221 | 221 | $data = array( |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | * inputs. These are public string constants declared in |
| 246 | 246 | * this file. |
| 247 | 247 | */ |
| 248 | - public function savePost(int $posterId=null): string { |
|
| 248 | + public function savePost(int $posterId = null): string { |
|
| 249 | 249 | $action = $this->ci->security->xss_clean($this->ci->input->post("action")); |
| 250 | 250 | switch ($action) { |
| 251 | 251 | case "save": |
@@ -269,7 +269,7 @@ discard block |
||
| 269 | 269 | * |
| 270 | 270 | * @return string Action taken during the pocess; Blogger::CREATE Or Blogger::EDIT |
| 271 | 271 | */ |
| 272 | - private function handleSavePost(int $posterId=null): string { |
|
| 272 | + private function handleSavePost(int $posterId = null): string { |
|
| 273 | 273 | $id = $this->ci->security->xss_clean($this->ci->input->post("id")); |
| 274 | 274 | if ($id != "") { |
| 275 | 275 | if (!$this->ci->bmanager->savePost($this->ci->input->post("id"), $this->ci->security->xss_clean($this->ci->input->post("title")), $this->ci->security->xss_clean($this->ci->input->post("editor")), $posterId)) return self::ABORT; |
@@ -287,7 +287,7 @@ discard block |
||
| 287 | 287 | |
| 288 | 288 | * @return string Action reached while processing form inputs. |
| 289 | 289 | */ |
| 290 | - private function handlePublishPost(int $posterId=null): string { |
|
| 290 | + private function handlePublishPost(int $posterId = null): string { |
|
| 291 | 291 | $id = $this->ci->security->xss_clean($this->ci->input->post("id")); |
| 292 | 292 | if ($id == "") return self::ABORT; |
| 293 | 293 | if (!$this->ci->bmanager->savePost($id, $this->ci->security->xss_clean($this->ci->input->post("title")), $this->ci->security->xss_clean($this->ci->input->post("editor")), $posterId)) return self::ABORT; |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | * |
| 310 | 310 | * @return array Array of posts for a given page. |
| 311 | 311 | */ |
| 312 | - public function getPosts(int $page, int $limit, bool $filter=false, bool $hits=false): array { |
|
| 312 | + public function getPosts(int $page, int $limit, bool $filter = false, bool $hits = false): array { |
|
| 313 | 313 | return $this->ci->bmanager->getPosts($page, $limit, $filter, $hits); |
| 314 | 314 | } |
| 315 | 315 | /** |
@@ -323,7 +323,7 @@ discard block |
||
| 323 | 323 | * @param boolean $hits [description] |
| 324 | 324 | * @return bool [description] |
| 325 | 325 | */ |
| 326 | - public function renderPostItems($view=null, $callback=null, $empty_view=null, $page=1, $limit=5, $filter=false, $hits=false, $slug=true) { |
|
| 326 | + public function renderPostItems($view = null, $callback = null, $empty_view = null, $page = 1, $limit = 5, $filter = false, $hits = false, $slug = true) { |
|
| 327 | 327 | if ($view == null || $empty_view == null) $this->ci->load->bind("francis94c/blog", $blogger); |
| 328 | 328 | $posts = $this->getPosts($page, $limit, $filter, $hits); |
| 329 | 329 | if (count($posts) == 0) { |
@@ -349,7 +349,7 @@ discard block |
||
| 349 | 349 | * @param boolean $filter [description] |
| 350 | 350 | * @return [type] [description] |
| 351 | 351 | */ |
| 352 | - public function getRecentPosts($limit=5, $filter=false) { |
|
| 352 | + public function getRecentPosts($limit = 5, $filter = false) { |
|
| 353 | 353 | return $this->ci->bmanager->getRecentPosts($limit, $filter); |
| 354 | 354 | } |
| 355 | 355 | /** |
@@ -358,7 +358,7 @@ discard block |
||
| 358 | 358 | * @param [type] $view [description] |
| 359 | 359 | * @return [type] [description] |
| 360 | 360 | */ |
| 361 | - public function renderPost($post, $view=null) { |
|
| 361 | + public function renderPost($post, $view = null) { |
|
| 362 | 362 | if (!is_array($post)) $post = $this->ci->bmanager->getPost($post); |
| 363 | 363 | if (!$post) return false; |
| 364 | 364 | $post["content"] = $this->ci->parsedown->text($post["content"]); |
@@ -394,7 +394,7 @@ discard block |
||
| 394 | 394 | * @param [type] $postId [description] |
| 395 | 395 | * @return [type] [description] |
| 396 | 396 | */ |
| 397 | - public function getPost($postId, $hit=true) { |
|
| 397 | + public function getPost($postId, $hit = true) { |
|
| 398 | 398 | return $this->ci->bmanager->getPost($postId, $hit); |
| 399 | 399 | } |
| 400 | 400 | /** |
@@ -430,7 +430,7 @@ discard block |
||
| 430 | 430 | * @param boolean $filter [description] |
| 431 | 431 | * @return [type] [description] |
| 432 | 432 | */ |
| 433 | - public function searchPosts($words, $page, $limit=0, $filter=false) { |
|
| 433 | + public function searchPosts($words, $page, $limit = 0, $filter = false) { |
|
| 434 | 434 | return $this->ci->bmanager->searchPosts($words, $page, $limit, $filter); |
| 435 | 435 | } |
| 436 | 436 | } |
@@ -139,7 +139,9 @@ discard block |
||
| 139 | 139 | } |
| 140 | 140 | $this->ci->dbforge->add_field("date_created TIMESTAMP DEFAULT CURRENT_TIMESTAMP"); |
| 141 | 141 | $attributes = array('ENGINE' => 'InnoDB'); |
| 142 | - if (!$this->ci->dbforge->create_table($blogName, true, $attributes)) return false; |
|
| 142 | + if (!$this->ci->dbforge->create_table($blogName, true, $attributes)) { |
|
| 143 | + return false; |
|
| 144 | + } |
|
| 143 | 145 | return true; |
| 144 | 146 | } |
| 145 | 147 | /** |
@@ -253,10 +255,14 @@ discard block |
||
| 253 | 255 | case "publish": |
| 254 | 256 | return $this->handlePublishPost($posterId); |
| 255 | 257 | case "createAndPublish": |
| 256 | - if ($this->ci->bmanager->createAndPublishPost($this->ci->security->xss_clean($this->ci->input->post("title")), $this->ci->security->xss_clean($this->ci->input->post("editor")), $posterId) !== false) return self::CREATE_AND_PUBLISH; |
|
| 258 | + if ($this->ci->bmanager->createAndPublishPost($this->ci->security->xss_clean($this->ci->input->post("title")), $this->ci->security->xss_clean($this->ci->input->post("editor")), $posterId) !== false) { |
|
| 259 | + return self::CREATE_AND_PUBLISH; |
|
| 260 | + } |
|
| 257 | 261 | return self::ABORT; |
| 258 | 262 | case "delete": |
| 259 | - if ($this->ci->bmanager->deletePost($this->ci->security->xss_clean($this->ci->input->post("id")))) return self::DELETE; |
|
| 263 | + if ($this->ci->bmanager->deletePost($this->ci->security->xss_clean($this->ci->input->post("id")))) { |
|
| 264 | + return self::DELETE; |
|
| 265 | + } |
|
| 260 | 266 | return self::ABORT; |
| 261 | 267 | default: |
| 262 | 268 | return self::NO_ACTION; |
@@ -272,10 +278,14 @@ discard block |
||
| 272 | 278 | private function handleSavePost(int $posterId=null): string { |
| 273 | 279 | $id = $this->ci->security->xss_clean($this->ci->input->post("id")); |
| 274 | 280 | if ($id != "") { |
| 275 | - if (!$this->ci->bmanager->savePost($this->ci->input->post("id"), $this->ci->security->xss_clean($this->ci->input->post("title")), $this->ci->security->xss_clean($this->ci->input->post("editor")), $posterId)) return self::ABORT; |
|
| 281 | + if (!$this->ci->bmanager->savePost($this->ci->input->post("id"), $this->ci->security->xss_clean($this->ci->input->post("title")), $this->ci->security->xss_clean($this->ci->input->post("editor")), $posterId)) { |
|
| 282 | + return self::ABORT; |
|
| 283 | + } |
|
| 276 | 284 | return self::EDIT; |
| 277 | 285 | } else { |
| 278 | - if ($this->ci->bmanager->createPost($this->ci->security->xss_clean($this->ci->input->post("title")), $this->ci->security->xss_clean($this->ci->input->post("editor")), $posterId) == 0) return self::ABORT; |
|
| 286 | + if ($this->ci->bmanager->createPost($this->ci->security->xss_clean($this->ci->input->post("title")), $this->ci->security->xss_clean($this->ci->input->post("editor")), $posterId) == 0) { |
|
| 287 | + return self::ABORT; |
|
| 288 | + } |
|
| 279 | 289 | return self::CREATE; |
| 280 | 290 | } |
| 281 | 291 | } |
@@ -289,9 +299,15 @@ discard block |
||
| 289 | 299 | */ |
| 290 | 300 | private function handlePublishPost(int $posterId=null): string { |
| 291 | 301 | $id = $this->ci->security->xss_clean($this->ci->input->post("id")); |
| 292 | - if ($id == "") return self::ABORT; |
|
| 293 | - if (!$this->ci->bmanager->savePost($id, $this->ci->security->xss_clean($this->ci->input->post("title")), $this->ci->security->xss_clean($this->ci->input->post("editor")), $posterId)) return self::ABORT; |
|
| 294 | - if (!$this->ci->bmanager->publishPost($id, true)) return self::ABORT; |
|
| 302 | + if ($id == "") { |
|
| 303 | + return self::ABORT; |
|
| 304 | + } |
|
| 305 | + if (!$this->ci->bmanager->savePost($id, $this->ci->security->xss_clean($this->ci->input->post("title")), $this->ci->security->xss_clean($this->ci->input->post("editor")), $posterId)) { |
|
| 306 | + return self::ABORT; |
|
| 307 | + } |
|
| 308 | + if (!$this->ci->bmanager->publishPost($id, true)) { |
|
| 309 | + return self::ABORT; |
|
| 310 | + } |
|
| 295 | 311 | return self::PUBLISH; |
| 296 | 312 | } |
| 297 | 313 | /** |
@@ -324,7 +340,9 @@ discard block |
||
| 324 | 340 | * @return bool [description] |
| 325 | 341 | */ |
| 326 | 342 | public function renderPostItems($view=null, $callback=null, $empty_view=null, $page=1, $limit=5, $filter=false, $hits=false, $slug=true) { |
| 327 | - if ($view == null || $empty_view == null) $this->ci->load->bind("francis94c/blog", $blogger); |
|
| 343 | + if ($view == null || $empty_view == null) { |
|
| 344 | + $this->ci->load->bind("francis94c/blog", $blogger); |
|
| 345 | + } |
|
| 328 | 346 | $posts = $this->getPosts($page, $limit, $filter, $hits); |
| 329 | 347 | if (count($posts) == 0) { |
| 330 | 348 | if ($empty_view == null) { $blogger->load->view("empty"); } else { |
@@ -359,8 +377,12 @@ discard block |
||
| 359 | 377 | * @return [type] [description] |
| 360 | 378 | */ |
| 361 | 379 | public function renderPost($post, $view=null) { |
| 362 | - if (!is_array($post)) $post = $this->ci->bmanager->getPost($post); |
|
| 363 | - if (!$post) return false; |
|
| 380 | + if (!is_array($post)) { |
|
| 381 | + $post = $this->ci->bmanager->getPost($post); |
|
| 382 | + } |
|
| 383 | + if (!$post) { |
|
| 384 | + return false; |
|
| 385 | + } |
|
| 364 | 386 | $post["content"] = $this->ci->parsedown->text($post["content"]); |
| 365 | 387 | if ($view == null) { |
| 366 | 388 | $this->ci->load->splint("francis94c/blog", "-post_item", $post); |
@@ -378,7 +400,9 @@ discard block |
||
| 378 | 400 | $data = array(); |
| 379 | 401 | $data["title"] = $post["title"]; |
| 380 | 402 | $data["description"] = substr($post["content"], 0, 154); |
| 381 | - if (isset($post["share_image"])) $data["image_link"] = $post["share_image"]; |
|
| 403 | + if (isset($post["share_image"])) { |
|
| 404 | + $data["image_link"] = $post["share_image"]; |
|
| 405 | + } |
|
| 382 | 406 | $data["url"] = current_url(); |
| 383 | 407 | return $this->ci->load->splint(self::PACKAGE, "-meta_og", $data, true); |
| 384 | 408 | } |