@@ -51,9 +51,15 @@ discard block |
||
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 |
||
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 | /** |
@@ -87,8 +99,12 @@ discard block |
||
87 | 99 | * @return array Array of posts for a given page. |
88 | 100 | */ |
89 | 101 | function getPosts($page=1, $limit=5, $filter=false, $hits=false) { |
90 | - if ($limit != 0) $this->db->limit($limit, ($page * $limit) - $limit); |
|
91 | - if ($filter) $this->db->where("published", 1); |
|
102 | + if ($limit != 0) { |
|
103 | + $this->db->limit($limit, ($page * $limit) - $limit); |
|
104 | + } |
|
105 | + if ($filter) { |
|
106 | + $this->db->where("published", 1); |
|
107 | + } |
|
92 | 108 | if ($hits) { |
93 | 109 | $this->db->order_by("hits", "DESC"); |
94 | 110 | } else { |
@@ -103,8 +119,12 @@ discard block |
||
103 | 119 | * @return [type] [description] |
104 | 120 | */ |
105 | 121 | function getRecentPosts($limit=5, $filter=false) { |
106 | - if ($limit != null && $limit != null) $this->db->limit($limit); |
|
107 | - if ($filter) $this->db->where("published", 1); |
|
122 | + if ($limit != null && $limit != null) { |
|
123 | + $this->db->limit($limit); |
|
124 | + } |
|
125 | + if ($filter) { |
|
126 | + $this->db->where("published", 1); |
|
127 | + } |
|
108 | 128 | $this->db->order_by("id", "DESC"); |
109 | 129 | return $this->db->get($this->table_name)->result_array(); |
110 | 130 | } |
@@ -156,7 +176,9 @@ discard block |
||
156 | 176 | $src = array(); |
157 | 177 | // Get the contents of the src tag. |
158 | 178 | preg_match("/(http|https):\/\/[a-zA-Z0-9-._\/]+/", $share_image, $src); |
159 | - if (count($src) == 0) return $post; |
|
179 | + if (count($src) == 0) { |
|
180 | + return $post; |
|
181 | + } |
|
160 | 182 | $post["share_image"] = $src[0]; |
161 | 183 | return $post; |
162 | 184 | } |
@@ -170,7 +192,9 @@ discard block |
||
170 | 192 | function getHits($postId) { |
171 | 193 | $this->db->where("id", $postId); |
172 | 194 | $query = $this->db->get($this->table_name); |
173 | - if ($query->num_rows() > 0) return $query->result()[0]->hits; |
|
195 | + if ($query->num_rows() > 0) { |
|
196 | + return $query->result()[0]->hits; |
|
197 | + } |
|
174 | 198 | return 0; |
175 | 199 | } |
176 | 200 | /** |
@@ -211,8 +235,12 @@ discard block |
||
211 | 235 | * @return [type] [description] |
212 | 236 | */ |
213 | 237 | function searchPosts($words, $page, $limit=0, $filter=false) { |
214 | - if ($limit != 0) $this->db->limit($limit, ($page * $limit) - $limit); |
|
215 | - if ($filter) $this->db->where("published", 1); |
|
238 | + if ($limit != 0) { |
|
239 | + $this->db->limit($limit, ($page * $limit) - $limit); |
|
240 | + } |
|
241 | + if ($filter) { |
|
242 | + $this->db->where("published", 1); |
|
243 | + } |
|
216 | 244 | $this->db->like("title", $words); |
217 | 245 | $this->db->or_like("content", $words); |
218 | 246 | return $this->db->get($this->table_name)->result_array(); |
@@ -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 | /** |
@@ -252,7 +254,9 @@ discard block |
||
252 | 254 | } elseif ($action == "publish" || $action == "createAndPublish") { |
253 | 255 | if ($action == "publish") { |
254 | 256 | $id = $this->ci->security->xss_clean($this->ci->input->post("id")); |
255 | - if ($id == "") return self::ABORT; |
|
257 | + if ($id == "") { |
|
258 | + return self::ABORT; |
|
259 | + } |
|
256 | 260 | $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); |
257 | 261 | $this->ci->bmanager->publishPost($id, true); |
258 | 262 | return self::PUBLISH; |
@@ -263,7 +267,9 @@ discard block |
||
263 | 267 | return self::ABORT; |
264 | 268 | } |
265 | 269 | } elseif ($action == "delete") { |
266 | - if ($this->ci->bmanager->deletePost($this->ci->security->xss_clean($this->ci->input->post("id")))) return self::DELETE; |
|
270 | + if ($this->ci->bmanager->deletePost($this->ci->security->xss_clean($this->ci->input->post("id")))) { |
|
271 | + return self::DELETE; |
|
272 | + } |
|
267 | 273 | } |
268 | 274 | return self::NO_ACTION; |
269 | 275 | } |
@@ -274,10 +280,14 @@ discard block |
||
274 | 280 | private function handleSavePost(): string { |
275 | 281 | $id = $this->ci->security->xss_clean($this->ci->input->post("id")); |
276 | 282 | if ($id != "") { |
277 | - 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; |
|
283 | + 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)) { |
|
284 | + return self::ABORT; |
|
285 | + } |
|
278 | 286 | return self::EDIT; |
279 | 287 | } else { |
280 | - 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; |
|
288 | + 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) { |
|
289 | + return self::ABORT; |
|
290 | + } |
|
281 | 291 | return self::CREATE; |
282 | 292 | } |
283 | 293 | } |
@@ -310,7 +320,9 @@ discard block |
||
310 | 320 | * @return [type] [description] |
311 | 321 | */ |
312 | 322 | public function renderPostItems($view=null, $callback=null, $empty_view=null, $page=1, $limit=5, $filter=false, $hits=false, $slug=true) { |
313 | - if ($view == null || $empty_view == null) $this->ci->load->bind("francis94c/blog", $blogger); |
|
323 | + if ($view == null || $empty_view == null) { |
|
324 | + $this->ci->load->bind("francis94c/blog", $blogger); |
|
325 | + } |
|
314 | 326 | $posts = $this->getPosts($page, $limit, $filter, $hits); |
315 | 327 | if (count($posts) == 0) { |
316 | 328 | if ($empty_view == null) { $blogger->load->view("empty"); } else { |
@@ -345,8 +357,12 @@ discard block |
||
345 | 357 | * @return [type] [description] |
346 | 358 | */ |
347 | 359 | public function renderPost($post, $view=null) { |
348 | - if (!is_array($post)) $post = $this->ci->bmanager->getPost($post); |
|
349 | - if (!$post) return false; |
|
360 | + if (!is_array($post)) { |
|
361 | + $post = $this->ci->bmanager->getPost($post); |
|
362 | + } |
|
363 | + if (!$post) { |
|
364 | + return false; |
|
365 | + } |
|
350 | 366 | $post["content"] = $this->ci->parsedown->text($post["content"]); |
351 | 367 | if ($view == null) { |
352 | 368 | $this->ci->load->splint("francis94c/blog", "-post_item", $post); |
@@ -364,7 +380,9 @@ discard block |
||
364 | 380 | $data = array(); |
365 | 381 | $data["title"] = $post["title"]; |
366 | 382 | $data["description"] = substr($post["content"], 0, 154); |
367 | - if (isset($post["share_image"])) $data["image_link"] = $post["share_image"]; |
|
383 | + if (isset($post["share_image"])) { |
|
384 | + $data["image_link"] = $post["share_image"]; |
|
385 | + } |
|
368 | 386 | $data["url"] = current_url(); |
369 | 387 | return $this->ci->load->splint(self::PACKAGE, "-meta_og", $data, true); |
370 | 388 | } |