@@ -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 | /** |
@@ -190,7 +214,9 @@ discard block |
||
190 | 214 | * @return [type] [description] |
191 | 215 | */ |
192 | 216 | function getPostsCount(bool $filter=true): int { |
193 | - if ($filter) $this->db->where("published", 1); |
|
217 | + if ($filter) { |
|
218 | + $this->db->where("published", 1); |
|
219 | + } |
|
194 | 220 | $this->db->select("COUNT(title) as posts"); |
195 | 221 | return (int) $this->db->get($this->table_name)->result()[0]->posts; |
196 | 222 | } |
@@ -212,8 +238,12 @@ discard block |
||
212 | 238 | * @return [type] [description] |
213 | 239 | */ |
214 | 240 | function searchPosts($words, $page, $limit=0, $filter=false) { |
215 | - if ($limit != 0) $this->db->limit($limit, ($page * $limit) - $limit); |
|
216 | - if ($filter) $this->db->where("published", 1); |
|
241 | + if ($limit != 0) { |
|
242 | + $this->db->limit($limit, ($page * $limit) - $limit); |
|
243 | + } |
|
244 | + if ($filter) { |
|
245 | + $this->db->where("published", 1); |
|
246 | + } |
|
217 | 247 | $this->db->like("title", $words); |
218 | 248 | $this->db->or_like("content", $words); |
219 | 249 | return $this->db->get($this->table_name)->result_array(); |