@@ -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 | /** |
@@ -92,8 +104,12 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 218 | 246 | * @return [type] [description] |
| 219 | 247 | */ |
| 220 | 248 | function searchPosts($words, $page=1, $limit=5, $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(); |