Passed
Push — master ( 355b9e...54a74b )
by Francis
01:27
created
models/BlogManager.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
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
   /**
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
    *                         database. Returns 0 if the post couldn't be
45 45
    *                         created.
46 46
    */
47
-  function createPost(string $title, string $content, int $adminId=null): int {
47
+  function createPost(string $title, string $content, int $adminId = null): int {
48 48
     $this->ci->load->helper("url");
49 49
     $data = array(
50 50
       "title"   => $title,
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
    * @param  [type] $adminId [description]
64 64
    * @return [type]          [description]
65 65
    */
66
-  function createAndPublishPost($title, $content, $adminId=null) {
66
+  function createAndPublishPost($title, $content, $adminId = null) {
67 67
     $data = array(
68 68
       "title"          => $title,
69 69
       "content"        => $content,
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
    *
92 92
    * @return array           Array of posts for a given page.
93 93
    */
94
-  function getPosts(int $page=1, int $limit=5, bool $filter=false, bool $hits=false): array {
94
+  function getPosts(int $page = 1, int $limit = 5, bool $filter = false, bool $hits = false): array {
95 95
     if ($limit != 0) $this->db->limit($limit, ($page * $limit) - $limit);
96 96
     if ($filter) $this->db->where("published", 1);
97 97
     if ($hits) {
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
    * @param  boolean $filter [description]
108 108
    * @return [type]          [description]
109 109
    */
110
-  function getRecentPosts($limit=5, $filter=false) {
110
+  function getRecentPosts($limit = 5, $filter = false) {
111 111
     if ($limit != null && $limit != null) $this->db->limit($limit);
112 112
     if ($filter) $this->db->where("published", 1);
113 113
     $this->db->order_by("id", "DESC");
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
    * @return bool            True on success, False if not.
123 123
    */
124 124
   function savePost($postId, $title, $content): bool {
125
-    $data = array (
125
+    $data = array(
126 126
       "title"   => $title,
127 127
       "content" => $content,
128 128
       "slug"    => url_title($title)
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
    * @param  int   $postId ID of the post to retrieve.
137 137
    * @return array An associative array for the Posts's data.
138 138
    */
139
-  function getPost($postId, $hit=true) {
139
+  function getPost($postId, $hit = true) {
140 140
     if (is_numeric($postId)) {
141 141
       $this->db->where("id", $postId);
142 142
     } else {
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
           $this->db->update($this->table_name);
154 154
         }
155 155
       }
156
-      $post =  $query->result_array()[0];
156
+      $post = $query->result_array()[0];
157 157
       $images = array();
158 158
       // Fetch all images in post.
159 159
       preg_match("/<img\s[^>]*?src\s*=\s*['\"]([^'\"]*?)['\"][^>]*?>/", $post["content"], $images);
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
    * [getPostsCount get the total number of posts in the database.]
196 196
    * @return [type] [description]
197 197
    */
198
-  function getPostsCount(bool $filter=true): int {
198
+  function getPostsCount(bool $filter = true): int {
199 199
     if ($filter) $this->db->where("published", 1);
200 200
     $this->db->select("COUNT(title) as posts");
201 201
     return (int) $this->db->get($this->table_name)->result()[0]->posts;
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
    * @param  boolean $filter [description]
218 218
    * @return [type]          [description]
219 219
    */
220
-  function searchPosts($words, $page, $limit=0, $filter=false) {
220
+  function searchPosts($words, $page, $limit = 0, $filter = false) {
221 221
     if ($limit != 0) $this->db->limit($limit, ($page * $limit) - $limit);
222 222
     if ($filter) $this->db->where("published", 1);
223 223
     $this->db->like("title", $words);
Please login to merge, or discard this patch.
Braces   +48 added lines, -16 removed lines patch added patch discarded remove patch
@@ -51,9 +51,15 @@  discard block
 block discarded – undo
51 51
       "content" => $content,
52 52
       "slug"    => url_title($title)
53 53
     );
54
-    if (is_numeric($title)) $data["slug"] = "_" . $data["slug"];
55
-    if ($adminId !== null) $data["poster_id"] = $adminId;
56
-    if ($this->db->insert($this->table_name, $data)) return $this->db->insert_id();
54
+    if (is_numeric($title)) {
55
+      $data["slug"] = "_" . $data["slug"];
56
+    }
57
+    if ($adminId !== null) {
58
+      $data["poster_id"] = $adminId;
59
+    }
60
+    if ($this->db->insert($this->table_name, $data)) {
61
+      return $this->db->insert_id();
62
+    }
57 63
     return 0;
58 64
   }
59 65
   /**
@@ -71,9 +77,15 @@  discard block
 block discarded – undo
71 77
       "published"      => 1,
72 78
       "date_published" => date("Y-m-d H:i:s")
73 79
     );
74
-    if (is_numeric($title)) $data["slug"] = "_" . $data["slug"];
75
-    if ($adminId != null) $data["poster_id"] = $adminId;
76
-    if ($this->db->insert($this->table_name, $data)) return $this->db->insert_id();
80
+    if (is_numeric($title)) {
81
+      $data["slug"] = "_" . $data["slug"];
82
+    }
83
+    if ($adminId != null) {
84
+      $data["poster_id"] = $adminId;
85
+    }
86
+    if ($this->db->insert($this->table_name, $data)) {
87
+      return $this->db->insert_id();
88
+    }
77 89
     return false;
78 90
   }
79 91
   /**
@@ -92,8 +104,12 @@  discard block
 block discarded – undo
92 104
    * @return array           Array of posts for a given page.
93 105
    */
94 106
   function getPosts(int $page=1, int $limit=5, bool $filter=false, bool $hits=false): array {
95
-    if ($limit != 0) $this->db->limit($limit, ($page * $limit) - $limit);
96
-    if ($filter) $this->db->where("published", 1);
107
+    if ($limit != 0) {
108
+      $this->db->limit($limit, ($page * $limit) - $limit);
109
+    }
110
+    if ($filter) {
111
+      $this->db->where("published", 1);
112
+    }
97 113
     if ($hits) {
98 114
       $this->db->order_by("hits", "DESC");
99 115
     } else {
@@ -108,8 +124,12 @@  discard block
 block discarded – undo
108 124
    * @return [type]          [description]
109 125
    */
110 126
   function getRecentPosts($limit=5, $filter=false) {
111
-    if ($limit != null && $limit != null) $this->db->limit($limit);
112
-    if ($filter) $this->db->where("published", 1);
127
+    if ($limit != null && $limit != null) {
128
+      $this->db->limit($limit);
129
+    }
130
+    if ($filter) {
131
+      $this->db->where("published", 1);
132
+    }
113 133
     $this->db->order_by("id", "DESC");
114 134
     return $this->db->get($this->table_name)->result_array();
115 135
   }
@@ -147,7 +167,9 @@  discard block
 block discarded – undo
147 167
       if ($hit) {
148 168
         if ($this->ci->config->item("blogger_hits") === null ||
149 169
         $this->ci->config->item("blogger_hits") === true) {
150
-          if (!is_numeric($postId)) $postId = $query->result()[0]->id;
170
+          if (!is_numeric($postId)) {
171
+            $postId = $query->result()[0]->id;
172
+          }
151 173
           $this->db->where("id", $postId);
152 174
           $this->db->set("hits", "hits+1", FALSE);
153 175
           $this->db->update($this->table_name);
@@ -162,7 +184,9 @@  discard block
 block discarded – undo
162 184
       $src = array();
163 185
       // Get the contents of the src tag.
164 186
       preg_match("/(http|https):\/\/[a-zA-Z0-9-._\/]+/", $share_image, $src);
165
-      if (count($src) == 0) return $post;
187
+      if (count($src) == 0) {
188
+        return $post;
189
+      }
166 190
       $post["share_image"] = $src[0];
167 191
       return $post;
168 192
     }
@@ -176,7 +200,9 @@  discard block
 block discarded – undo
176 200
   function getHits(int $postId): int {
177 201
     $this->db->where("id", $postId);
178 202
     $query = $this->db->get($this->table_name);
179
-    if ($query->num_rows() > 0) return $query->result()[0]->hits;
203
+    if ($query->num_rows() > 0) {
204
+      return $query->result()[0]->hits;
205
+    }
180 206
     return 0;
181 207
   }
182 208
   /**
@@ -196,7 +222,9 @@  discard block
 block discarded – undo
196 222
    * @return [type] [description]
197 223
    */
198 224
   function getPostsCount(bool $filter=true): int {
199
-    if ($filter) $this->db->where("published", 1);
225
+    if ($filter) {
226
+      $this->db->where("published", 1);
227
+    }
200 228
     $this->db->select("COUNT(title) as posts");
201 229
     return (int) $this->db->get($this->table_name)->result()[0]->posts;
202 230
   }
@@ -218,8 +246,12 @@  discard block
 block discarded – undo
218 246
    * @return [type]          [description]
219 247
    */
220 248
   function searchPosts($words, $page, $limit=0, $filter=false) {
221
-    if ($limit != 0) $this->db->limit($limit, ($page * $limit) - $limit);
222
-    if ($filter) $this->db->where("published", 1);
249
+    if ($limit != 0) {
250
+      $this->db->limit($limit, ($page * $limit) - $limit);
251
+    }
252
+    if ($filter) {
253
+      $this->db->where("published", 1);
254
+    }
223 255
     $this->db->like("title", $words);
224 256
     $this->db->or_like("content", $words);
225 257
     return $this->db->get($this->table_name)->result_array();
Please login to merge, or discard this patch.
libraries/Blogger.php 2 patches
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -74,8 +74,8 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
   /**
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
    *
336 336
    * @return bool                True if successful, false if not.
337 337
    */
338
-  public function renderPostItems(string $view=null, string $callback=null, string $empty_view=null, int $page=1, int $limit=5, bool $filter=false, bool $hits=false, bool $slug=true): bool {
338
+  public function renderPostItems(string $view = null, string $callback = null, string $empty_view = null, int $page = 1, int $limit = 5, bool $filter = false, bool $hits = false, bool $slug = true): bool {
339 339
     if ($view === null || $empty_view === null) $this->ci->load->bind("francis94c/blog", $blogger);
340 340
     $posts = $this->getPosts($page, $limit, $filter, $hits);
341 341
     if (count($posts) == 0) {
@@ -364,7 +364,7 @@  discard block
 block discarded – undo
364 364
    *
365 365
    * @return array        Array of posts ordered by ID (Most recent first).
366 366
    */
367
-  public function getRecentPosts(int $limit=5, bool $filter=false): array {
367
+  public function getRecentPosts(int $limit = 5, bool $filter = false): array {
368 368
     return $this->ci->bmanager->getRecentPosts($limit, $filter);
369 369
   }
370 370
   /**
@@ -378,7 +378,7 @@  discard block
 block discarded – undo
378 378
    *
379 379
    * @return bool             True if successful, false if not.
380 380
    */
381
-  public function renderPost($post, string $view=null): bool {
381
+  public function renderPost($post, string $view = null): bool {
382 382
     if (!is_array($post)) $post = $this->ci->bmanager->getPost($post);
383 383
     if (!$post) return false;
384 384
     $post["content"] = $this->ci->parsedown->text($post["content"]);
@@ -417,7 +417,7 @@  discard block
 block discarded – undo
417 417
    *
418 418
    * @return int          Posts count.
419 419
    */
420
-  public function getPostsCount(bool $filter=true): int {
420
+  public function getPostsCount(bool $filter = true): int {
421 421
     return $this->ci->bmanager->getPostsCount($filter);
422 422
   }
423 423
   /**
@@ -429,7 +429,7 @@  discard block
 block discarded – undo
429 429
    *
430 430
    * @return array          An associative array of a single post.
431 431
    */
432
-  public function getPost($postId, $hit=true) {
432
+  public function getPost($postId, $hit = true) {
433 433
     return $this->ci->bmanager->getPost($postId, $hit);
434 434
   }
435 435
   /**
@@ -467,7 +467,7 @@  discard block
 block discarded – undo
467 467
    * @param  boolean $filter [description]
468 468
    * @return [type]          [description]
469 469
    */
470
-  public function searchPosts($words, $page, $limit=0, $filter=false) {
470
+  public function searchPosts($words, $page, $limit = 0, $filter = false) {
471 471
     return $this->ci->bmanager->searchPosts($words, $page, $limit, $filter);
472 472
   }
473 473
 }
Please login to merge, or discard this patch.
Braces   +36 added lines, -12 removed lines patch added patch discarded remove patch
@@ -139,7 +139,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
   /**
@@ -336,7 +352,9 @@  discard block
 block discarded – undo
336 352
    * @return bool                True if successful, false if not.
337 353
    */
338 354
   public function renderPostItems(string $view=null, string $callback=null, string $empty_view=null, int $page=1, int $limit=5, bool $filter=false, bool $hits=false, bool $slug=true): bool {
339
-    if ($view === null || $empty_view === null) $this->ci->load->bind("francis94c/blog", $blogger);
355
+    if ($view === null || $empty_view === null) {
356
+      $this->ci->load->bind("francis94c/blog", $blogger);
357
+    }
340 358
     $posts = $this->getPosts($page, $limit, $filter, $hits);
341 359
     if (count($posts) == 0) {
342 360
       if ($empty_view === null) { $blogger->load->view("empty"); } else {
@@ -379,8 +397,12 @@  discard block
 block discarded – undo
379 397
    * @return bool             True if successful, false if not.
380 398
    */
381 399
   public function renderPost($post, string $view=null): bool {
382
-    if (!is_array($post)) $post = $this->ci->bmanager->getPost($post);
383
-    if (!$post) return false;
400
+    if (!is_array($post)) {
401
+      $post = $this->ci->bmanager->getPost($post);
402
+    }
403
+    if (!$post) {
404
+      return false;
405
+    }
384 406
     $post["content"] = $this->ci->parsedown->text($post["content"]);
385 407
     if ($view === null) {
386 408
       $this->ci->load->splint("francis94c/blog", "-post_item", $post);
@@ -403,7 +425,9 @@  discard block
 block discarded – undo
403 425
     $data = array();
404 426
     $data["title"] = $post["title"];
405 427
     $data["description"] = substr($post["content"], 0, 154);
406
-    if (isset($post["share_image"])) $data["image_link"] = $post["share_image"];
428
+    if (isset($post["share_image"])) {
429
+      $data["image_link"] = $post["share_image"];
430
+    }
407 431
     $data["url"] = current_url();
408 432
     // Return Meta OG View String.
409 433
     return $this->ci->load->splint(self::PACKAGE, "-meta_og", $data, true);
Please login to merge, or discard this patch.