@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | </textarea> |
| 48 | 48 | </div> |
| 49 | 49 | <?php |
| 50 | -$ci =& get_instance(); |
|
| 50 | +$ci = & get_instance(); |
|
| 51 | 51 | $ci->load->splint("francis94c/ci-parsedown", "+Parsedown", null, "parsedown"); |
| 52 | 52 | ?> |
| 53 | 53 | <div class="w3-padding w3-margin w3-border w3-round" id="preview"> |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | * @return [type] [description] |
| 77 | 77 | */ |
| 78 | 78 | function saveAndPublish() { |
| 79 | - document.getElementById("action").value = <?=$type == "edit" ? "\"publish\"" : "\"createAndPublish\"";?>; |
|
| 79 | + document.getElementById("action").value = <?=$type == "edit" ? "\"publish\"" : "\"createAndPublish\""; ?>; |
|
| 80 | 80 | document.getElementById("postForm").submit(); |
| 81 | 81 | } |
| 82 | 82 | /** |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | </script> |
| 105 | 105 | <input type="hidden" name="id" value="<?=$type == "edit" ? $id : ""?>"/> |
| 106 | 106 | <input id="action" type="hidden" name="action" value="publish"/> |
| 107 | -<?=form_close();?> |
|
| 107 | +<?=form_close(); ?> |
|
| 108 | 108 | <button onclick="save();" class="w3-margin w3-button w3-teal w3-round w3-hover-theme"><?=$type == "edit" ? "Save" : "Create"?></button> |
| 109 | 109 | <button onclick="promptPublish();" class="w3-margin w3-button w3-teal w3-hover-theme w3-round"><?=$type == "edit" ? "Save and Publish" : "Create and Publish"?></button> |
| 110 | 110 | <?php if ($type == "edit") {?> |
@@ -1,7 +1,13 @@ |
||
| 1 | 1 | <?php |
| 2 | -if (!isset($title)) $title = ""; |
|
| 3 | -if (!isset($content)) $content = ""; |
|
| 4 | -if (!isset($prompt_color)) $prompt_color = "w3-green"; |
|
| 2 | +if (!isset($title)) { |
|
| 3 | + $title = ""; |
|
| 4 | +} |
|
| 5 | +if (!isset($content)) { |
|
| 6 | + $content = ""; |
|
| 7 | +} |
|
| 8 | +if (!isset($prompt_color)) { |
|
| 9 | + $prompt_color = "w3-green"; |
|
| 10 | +} |
|
| 5 | 11 | ?> |
| 6 | 12 | <div id="publishModal" class="w3-modal w3-animate-opacity"> |
| 7 | 13 | <div class="w3-modal-content"> |
@@ -46,9 +46,15 @@ discard block |
||
| 46 | 46 | "content" => $content, |
| 47 | 47 | "slug" => url_title($title) |
| 48 | 48 | ); |
| 49 | - if (is_numeric($title)) $data["slug"] = "_" . $data["slug"]; |
|
| 50 | - if ($adminId != null) $data["poster_id"] = $adminId; |
|
| 51 | - if ($this->db->insert($this->table_name, $data)) return $this->db->insert_id(); |
|
| 49 | + if (is_numeric($title)) { |
|
| 50 | + $data["slug"] = "_" . $data["slug"]; |
|
| 51 | + } |
|
| 52 | + if ($adminId != null) { |
|
| 53 | + $data["poster_id"] = $adminId; |
|
| 54 | + } |
|
| 55 | + if ($this->db->insert($this->table_name, $data)) { |
|
| 56 | + return $this->db->insert_id(); |
|
| 57 | + } |
|
| 52 | 58 | return false; |
| 53 | 59 | } |
| 54 | 60 | /** |
@@ -66,9 +72,15 @@ discard block |
||
| 66 | 72 | "published" => 1, |
| 67 | 73 | "date_published" => date("Y-m-d H:i:s") |
| 68 | 74 | ); |
| 69 | - if (is_numeric($title)) $data["slug"] = "_" . $data["slug"]; |
|
| 70 | - if ($adminId != null) $data["poster_id"] = $adminId; |
|
| 71 | - if ($this->db->insert($this->table_name, $data)) return $this->db->insert_id(); |
|
| 75 | + if (is_numeric($title)) { |
|
| 76 | + $data["slug"] = "_" . $data["slug"]; |
|
| 77 | + } |
|
| 78 | + if ($adminId != null) { |
|
| 79 | + $data["poster_id"] = $adminId; |
|
| 80 | + } |
|
| 81 | + if ($this->db->insert($this->table_name, $data)) { |
|
| 82 | + return $this->db->insert_id(); |
|
| 83 | + } |
|
| 72 | 84 | return false; |
| 73 | 85 | } |
| 74 | 86 | /** |
@@ -82,8 +94,12 @@ discard block |
||
| 82 | 94 | * @return array Array of posts for a given page. |
| 83 | 95 | */ |
| 84 | 96 | function getPosts($page=1, $limit=5, $filter=false, $hits=false) { |
| 85 | - if ($limit != 0) $this->db->limit($limit, ($page * $limit) - $limit); |
|
| 86 | - if ($filter) $this->db->where("published", 1); |
|
| 97 | + if ($limit != 0) { |
|
| 98 | + $this->db->limit($limit, ($page * $limit) - $limit); |
|
| 99 | + } |
|
| 100 | + if ($filter) { |
|
| 101 | + $this->db->where("published", 1); |
|
| 102 | + } |
|
| 87 | 103 | if ($hits) { |
| 88 | 104 | $this->db->order_by("hits", "DESC"); |
| 89 | 105 | } else { |
@@ -98,8 +114,12 @@ discard block |
||
| 98 | 114 | * @return [type] [description] |
| 99 | 115 | */ |
| 100 | 116 | function getRecentPosts($limit=5, $filter=false) { |
| 101 | - if ($limit != null && $limit != null) $this->db->limit($limit); |
|
| 102 | - if ($filter) $this->db->where("published", 1); |
|
| 117 | + if ($limit != null && $limit != null) { |
|
| 118 | + $this->db->limit($limit); |
|
| 119 | + } |
|
| 120 | + if ($filter) { |
|
| 121 | + $this->db->where("published", 1); |
|
| 122 | + } |
|
| 103 | 123 | $this->db->order_by("id", "DESC"); |
| 104 | 124 | return $this->db->get($this->table_name)->result_array(); |
| 105 | 125 | } |
@@ -151,7 +171,9 @@ discard block |
||
| 151 | 171 | $src = array(); |
| 152 | 172 | // Get the contents of the src tag. |
| 153 | 173 | preg_match("/(http|https):\/\/[a-zA-Z0-9-._\/]+/", $share_image, $src); |
| 154 | - if (count($src) == 0) return $post; |
|
| 174 | + if (count($src) == 0) { |
|
| 175 | + return $post; |
|
| 176 | + } |
|
| 155 | 177 | $post["share_image"] = $src[0]; |
| 156 | 178 | return $post; |
| 157 | 179 | } |
@@ -165,7 +187,9 @@ discard block |
||
| 165 | 187 | function getHits($postId) { |
| 166 | 188 | $this->db->where("id", $postId); |
| 167 | 189 | $query = $this->db->get($this->table_name); |
| 168 | - if ($query->num_rows() > 0) return $query->result()[0]->hits; |
|
| 190 | + if ($query->num_rows() > 0) { |
|
| 191 | + return $query->result()[0]->hits; |
|
| 192 | + } |
|
| 169 | 193 | return 0; |
| 170 | 194 | } |
| 171 | 195 | /** |
@@ -206,8 +230,12 @@ discard block |
||
| 206 | 230 | * @return [type] [description] |
| 207 | 231 | */ |
| 208 | 232 | function searchPosts($words, $page, $limit=0, $filter=false) { |
| 209 | - if ($limit != 0) $this->db->limit($limit, ($page * $limit) - $limit); |
|
| 210 | - if ($filter) $this->db->where("published", 1); |
|
| 233 | + if ($limit != 0) { |
|
| 234 | + $this->db->limit($limit, ($page * $limit) - $limit); |
|
| 235 | + } |
|
| 236 | + if ($filter) { |
|
| 237 | + $this->db->where("published", 1); |
|
| 238 | + } |
|
| 211 | 239 | $this->db->like("title", $words); |
| 212 | 240 | $this->db->or_like("content", $words); |
| 213 | 241 | return $this->db->get($this->table_name)->result_array(); |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | |
| 12 | 12 | function __construct() { |
| 13 | 13 | parent::__construct(); |
| 14 | - $this->ci =& get_instance(); |
|
| 14 | + $this->ci = & get_instance(); |
|
| 15 | 15 | $this->ci->load->database(); |
| 16 | 16 | } |
| 17 | 17 | /** |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | * database. Returns false if the post couldn't be |
| 41 | 41 | * created. |
| 42 | 42 | */ |
| 43 | - function createPost($title, $content, $adminId=null) { |
|
| 43 | + function createPost($title, $content, $adminId = null) { |
|
| 44 | 44 | $this->ci->load->helper("url"); |
| 45 | 45 | $data = array( |
| 46 | 46 | "title" => $title, |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | * @param [type] $adminId [description] |
| 60 | 60 | * @return [type] [description] |
| 61 | 61 | */ |
| 62 | - function createAndPublishPost($title, $content, $adminId=null) { |
|
| 62 | + function createAndPublishPost($title, $content, $adminId = null) { |
|
| 63 | 63 | $data = array( |
| 64 | 64 | "title" => $title, |
| 65 | 65 | "content" => $content, |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | * @param boolean $hits order by hits. |
| 83 | 83 | * @return array Array of posts for a given page. |
| 84 | 84 | */ |
| 85 | - function getPosts($page=1, $limit=5, $filter=false, $hits=false) { |
|
| 85 | + function getPosts($page = 1, $limit = 5, $filter = false, $hits = false) { |
|
| 86 | 86 | if ($limit != 0) $this->db->limit($limit, ($page * $limit) - $limit); |
| 87 | 87 | if ($filter) $this->db->where("published", 1); |
| 88 | 88 | if ($hits) { |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | * @param boolean $filter [description] |
| 99 | 99 | * @return [type] [description] |
| 100 | 100 | */ |
| 101 | - function getRecentPosts($limit=5, $filter=false) { |
|
| 101 | + function getRecentPosts($limit = 5, $filter = false) { |
|
| 102 | 102 | if ($limit != null && $limit != null) $this->db->limit($limit); |
| 103 | 103 | if ($filter) $this->db->where("published", 1); |
| 104 | 104 | $this->db->order_by("id", "DESC"); |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | * @return bool True on success, False if not. |
| 114 | 114 | */ |
| 115 | 115 | function savePost($postId, $title, $content) { |
| 116 | - $data = array ( |
|
| 116 | + $data = array( |
|
| 117 | 117 | "title" => $title, |
| 118 | 118 | "content" => $content, |
| 119 | 119 | "slug" => url_title($title) |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | * @param int $postId ID of the post to retrieve. |
| 128 | 128 | * @return array An associative array for the Posts's data. |
| 129 | 129 | */ |
| 130 | - function getPost($postId, $hit=true) { |
|
| 130 | + function getPost($postId, $hit = true) { |
|
| 131 | 131 | if (is_numeric($postId)) { |
| 132 | 132 | $this->db->where("id", $postId); |
| 133 | 133 | } else { |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | $this->db->update($this->table_name); |
| 144 | 144 | } |
| 145 | 145 | } |
| 146 | - $post = $query->result_array()[0]; |
|
| 146 | + $post = $query->result_array()[0]; |
|
| 147 | 147 | $images = array(); |
| 148 | 148 | // Fetch all images in post. |
| 149 | 149 | preg_match("/<img\s[^>]*?src\s*=\s*['\"]([^'\"]*?)['\"][^>]*?>/", $post["content"], $images); |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | * @param boolean $filter [description] |
| 207 | 207 | * @return [type] [description] |
| 208 | 208 | */ |
| 209 | - function searchPosts($words, $page, $limit=0, $filter=false) { |
|
| 209 | + function searchPosts($words, $page, $limit = 0, $filter = false) { |
|
| 210 | 210 | if ($limit != 0) $this->db->limit($limit, ($page * $limit) - $limit); |
| 211 | 211 | if ($filter) $this->db->where("published", 1); |
| 212 | 212 | $this->db->like("title", $words); |
@@ -14,7 +14,7 @@ |
||
| 14 | 14 | * Prerquisites for the Unit Tests. |
| 15 | 15 | */ |
| 16 | 16 | public static function setUpBeforeClass(): void { |
| 17 | - self::$ci =& get_instance(); |
|
| 17 | + self::$ci = & get_instance(); |
|
| 18 | 18 | self::$ci->load->database('mysqli://root@localhost/test_db'); |
| 19 | 19 | $queries = [ |
| 20 | 20 | "CREATE TABLE IF NOT EXISTS admins (id INT(7) AUTO_INCREMENT PRIMARY KEY, name VARCHAR(20) NOT NULL, password TEXT NOT NULL) Engine=InnoDB;", |
@@ -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"); |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | * |
| 220 | 220 | * @return bool True if sucessfull without errors, false if not. |
| 221 | 221 | */ |
| 222 | - public function loadEditor(string $callback, int $postId=null, bool $w3css=true): bool { |
|
| 222 | + public function loadEditor(string $callback, int $postId = null, bool $w3css = true): bool { |
|
| 223 | 223 | $this->loadScripts($w3css); |
| 224 | 224 | $this->ci->load->helper("form"); |
| 225 | 225 | $data = array( |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | * inputs. These are public string constants declared in |
| 250 | 250 | * this file. |
| 251 | 251 | */ |
| 252 | - public function savePost(int $posterId=null): string { |
|
| 252 | + public function savePost(int $posterId = null): string { |
|
| 253 | 253 | $action = $this->ci->security->xss_clean($this->ci->input->post("action")); |
| 254 | 254 | if ($action == "save") { |
| 255 | 255 | $id = $this->ci->security->xss_clean($this->ci->input->post("id")); |
@@ -293,7 +293,7 @@ discard block |
||
| 293 | 293 | * |
| 294 | 294 | * @return array Array of posts for a given page. |
| 295 | 295 | */ |
| 296 | - public function getPosts(int $page, int $limit, bool $filter=false, bool $hits=false): array { |
|
| 296 | + public function getPosts(int $page, int $limit, bool $filter = false, bool $hits = false): array { |
|
| 297 | 297 | return $this->ci->bmanager->getPosts($page, $limit, $filter, $hits); |
| 298 | 298 | } |
| 299 | 299 | /** |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | * @param boolean $hits [description] |
| 307 | 307 | * @return [type] [description] |
| 308 | 308 | */ |
| 309 | - public function renderPostItems($view=null, $callback=null, $empty_view=null, $page=1, $limit=5, $filter=false, $hits=false, $slug=true) { |
|
| 309 | + public function renderPostItems($view = null, $callback = null, $empty_view = null, $page = 1, $limit = 5, $filter = false, $hits = false, $slug = true) { |
|
| 310 | 310 | if ($view == null || $empty_view == null) $this->ci->load->bind("francis94c/blog", $blogger); |
| 311 | 311 | $posts = $this->getPosts($page, $limit, $filter, $hits); |
| 312 | 312 | if (count($posts) == 0) { |
@@ -332,7 +332,7 @@ discard block |
||
| 332 | 332 | * @param boolean $filter [description] |
| 333 | 333 | * @return [type] [description] |
| 334 | 334 | */ |
| 335 | - public function getRecentPosts($limit=5, $filter=false) { |
|
| 335 | + public function getRecentPosts($limit = 5, $filter = false) { |
|
| 336 | 336 | return $this->ci->bmanager->getRecentPosts($limit, $filter); |
| 337 | 337 | } |
| 338 | 338 | /** |
@@ -341,7 +341,7 @@ discard block |
||
| 341 | 341 | * @param [type] $view [description] |
| 342 | 342 | * @return [type] [description] |
| 343 | 343 | */ |
| 344 | - public function renderPost($post, $view=null) { |
|
| 344 | + public function renderPost($post, $view = null) { |
|
| 345 | 345 | if (!is_array($post)) $post = $this->ci->bmanager->getPost($post); |
| 346 | 346 | if (!$post) return false; |
| 347 | 347 | $post["content"] = $this->ci->parsedown->text($post["content"]); |
@@ -377,7 +377,7 @@ discard block |
||
| 377 | 377 | * @param [type] $postId [description] |
| 378 | 378 | * @return [type] [description] |
| 379 | 379 | */ |
| 380 | - public function getPost($postId, $hit=true) { |
|
| 380 | + public function getPost($postId, $hit = true) { |
|
| 381 | 381 | return $this->ci->bmanager->getPost($postId, $hit); |
| 382 | 382 | } |
| 383 | 383 | /** |
@@ -413,7 +413,7 @@ discard block |
||
| 413 | 413 | * @param boolean $filter [description] |
| 414 | 414 | * @return [type] [description] |
| 415 | 415 | */ |
| 416 | - public function searchPosts($words, $page, $limit=0, $filter=false) { |
|
| 416 | + public function searchPosts($words, $page, $limit = 0, $filter = false) { |
|
| 417 | 417 | return $this->ci->bmanager->searchPosts($words, $page, $limit, $filter); |
| 418 | 418 | } |
| 419 | 419 | } |
@@ -143,7 +143,9 @@ discard block |
||
| 143 | 143 | $this->ci->dbforge->add_field($fields); |
| 144 | 144 | $this->ci->dbforge->add_field("date_created TIMESTAMP DEFAULT CURRENT_TIMESTAMP"); |
| 145 | 145 | $attributes = array('ENGINE' => 'InnoDB'); |
| 146 | - if (!$this->ci->dbforge->create_table($blogName, true, $attributes)) return false; |
|
| 146 | + if (!$this->ci->dbforge->create_table($blogName, true, $attributes)) { |
|
| 147 | + return false; |
|
| 148 | + } |
|
| 147 | 149 | return true; |
| 148 | 150 | } |
| 149 | 151 | /** |
@@ -263,7 +265,9 @@ discard block |
||
| 263 | 265 | } elseif ($action == "publish" || $action == "createAndPublish") { |
| 264 | 266 | if ($action == "publish") { |
| 265 | 267 | $id = $this->ci->security->xss_clean($this->ci->input->post("id")); |
| 266 | - if ($id == "") return self::ABORT; |
|
| 268 | + if ($id == "") { |
|
| 269 | + return self::ABORT; |
|
| 270 | + } |
|
| 267 | 271 | $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); |
| 268 | 272 | $this->ci->bmanager->publishPost($id, true); |
| 269 | 273 | return self::PUBLISH; |
@@ -274,7 +278,9 @@ discard block |
||
| 274 | 278 | return self::ABORT; |
| 275 | 279 | } |
| 276 | 280 | } elseif ($action == "delete") { |
| 277 | - if ($this->ci->bmanager->deletePost($this->ci->security->xss_clean($this->ci->input->post("id")))) return self::DELETE; |
|
| 281 | + if ($this->ci->bmanager->deletePost($this->ci->security->xss_clean($this->ci->input->post("id")))) { |
|
| 282 | + return self::DELETE; |
|
| 283 | + } |
|
| 278 | 284 | } |
| 279 | 285 | return self::NO_ACTION; |
| 280 | 286 | } |
@@ -307,7 +313,9 @@ discard block |
||
| 307 | 313 | * @return [type] [description] |
| 308 | 314 | */ |
| 309 | 315 | public function renderPostItems($view=null, $callback=null, $empty_view=null, $page=1, $limit=5, $filter=false, $hits=false, $slug=true) { |
| 310 | - if ($view == null || $empty_view == null) $this->ci->load->bind("francis94c/blog", $blogger); |
|
| 316 | + if ($view == null || $empty_view == null) { |
|
| 317 | + $this->ci->load->bind("francis94c/blog", $blogger); |
|
| 318 | + } |
|
| 311 | 319 | $posts = $this->getPosts($page, $limit, $filter, $hits); |
| 312 | 320 | if (count($posts) == 0) { |
| 313 | 321 | if ($empty_view == null) { $blogger->load->view("empty"); } else { |
@@ -342,8 +350,12 @@ discard block |
||
| 342 | 350 | * @return [type] [description] |
| 343 | 351 | */ |
| 344 | 352 | public function renderPost($post, $view=null) { |
| 345 | - if (!is_array($post)) $post = $this->ci->bmanager->getPost($post); |
|
| 346 | - if (!$post) return false; |
|
| 353 | + if (!is_array($post)) { |
|
| 354 | + $post = $this->ci->bmanager->getPost($post); |
|
| 355 | + } |
|
| 356 | + if (!$post) { |
|
| 357 | + return false; |
|
| 358 | + } |
|
| 347 | 359 | $post["content"] = $this->ci->parsedown->text($post["content"]); |
| 348 | 360 | if ($view == null) { |
| 349 | 361 | $this->ci->load->splint("francis94c/blog", "-post_item", $post); |
@@ -361,7 +373,9 @@ discard block |
||
| 361 | 373 | $data = array(); |
| 362 | 374 | $data["title"] = $post["title"]; |
| 363 | 375 | $data["description"] = substr($post["content"], 0, 154); |
| 364 | - if (isset($post["share_image"])) $data["image_link"] = $post["share_image"]; |
|
| 376 | + if (isset($post["share_image"])) { |
|
| 377 | + $data["image_link"] = $post["share_image"]; |
|
| 378 | + } |
|
| 365 | 379 | $data["url"] = current_url(); |
| 366 | 380 | return $this->ci->load->splint(self::PACKAGE, "-meta_og", $data, true); |
| 367 | 381 | } |