@@ -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"> |
@@ -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 | $data = array( |
| 45 | 45 | "title" => $title, |
| 46 | 46 | "content" => $content, |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | * @param [type] $adminId [description] |
| 59 | 59 | * @return [type] [description] |
| 60 | 60 | */ |
| 61 | - function createAndPublishPost($title, $content, $adminId=null) { |
|
| 61 | + function createAndPublishPost($title, $content, $adminId = null) { |
|
| 62 | 62 | $data = array( |
| 63 | 63 | "title" => $title, |
| 64 | 64 | "content" => $content, |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | * @param boolean $hits order by hits. |
| 82 | 82 | * @return array Array of posts for a given page. |
| 83 | 83 | */ |
| 84 | - function getPosts($page=1, $limit=5, $filter=false, $hits=false) { |
|
| 84 | + function getPosts($page = 1, $limit = 5, $filter = false, $hits = false) { |
|
| 85 | 85 | if ($limit != 0) $this->db->limit($limit, ($page * $limit) - $limit); |
| 86 | 86 | if ($filter) $this->db->where("published", 1); |
| 87 | 87 | if ($hits) { |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | * @param boolean $filter [description] |
| 98 | 98 | * @return [type] [description] |
| 99 | 99 | */ |
| 100 | - function getRecentPosts($limit=5, $filter=false) { |
|
| 100 | + function getRecentPosts($limit = 5, $filter = false) { |
|
| 101 | 101 | if ($limit != null && $limit != null) $this->db->limit($limit); |
| 102 | 102 | if ($filter) $this->db->where("published", 1); |
| 103 | 103 | $this->db->order_by("id", "DESC"); |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | * @return bool True on success, False if not. |
| 113 | 113 | */ |
| 114 | 114 | function savePost($postId, $title, $content) { |
| 115 | - $data = array ( |
|
| 115 | + $data = array( |
|
| 116 | 116 | "title" => $title, |
| 117 | 117 | "content" => $content, |
| 118 | 118 | "slug" => url_title($title) |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | * @param int $postId ID of the post to retrieve. |
| 127 | 127 | * @return array An associative array for the Posts's data. |
| 128 | 128 | */ |
| 129 | - function getPost($postId, $hit=true) { |
|
| 129 | + function getPost($postId, $hit = true) { |
|
| 130 | 130 | if (is_numeric($postId)) { |
| 131 | 131 | $this->db->where("id", $postId); |
| 132 | 132 | } else { |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | $this->db->update($this->table_name); |
| 143 | 143 | } |
| 144 | 144 | } |
| 145 | - $post = $query->result_array()[0]; |
|
| 145 | + $post = $query->result_array()[0]; |
|
| 146 | 146 | $images = array(); |
| 147 | 147 | // Fetch all images in post. |
| 148 | 148 | preg_match("/<img\s[^>]*?src\s*=\s*['\"]([^'\"]*?)['\"][^>]*?>/", $post["content"], $images); |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | * @param boolean $filter [description] |
| 206 | 206 | * @return [type] [description] |
| 207 | 207 | */ |
| 208 | - function searchPosts($words, $page, $limit=0, $filter=false) { |
|
| 208 | + function searchPosts($words, $page, $limit = 0, $filter = false) { |
|
| 209 | 209 | if ($limit != 0) $this->db->limit($limit, ($page * $limit) - $limit); |
| 210 | 210 | if ($filter) $this->db->where("published", 1); |
| 211 | 211 | $this->db->like("title", $words); |
@@ -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(); |
@@ -27,8 +27,8 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | const ABORT = "abortAction"; |
| 29 | 29 | |
| 30 | - function __construct($params=null) { |
|
| 31 | - $this->ci =& get_instance(); |
|
| 30 | + function __construct($params = null) { |
|
| 31 | + $this->ci = & get_instance(); |
|
| 32 | 32 | $this->ci->load->database(); |
| 33 | 33 | $this->table_name = self::TABLE_PREFIX . (isset($params["name"]) ? "_" . $params["name"] : ""); |
| 34 | 34 | $this->ci->load->database(); |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | * @param [type] $adminIdColumnConstraint [description] |
| 46 | 46 | * @return [type] [description] |
| 47 | 47 | */ |
| 48 | - function install($blogName=null, $adminTableName = null, $adminIdColumnName = null, $adminIdColumnConstraint = null) { |
|
| 48 | + function install($blogName = null, $adminTableName = null, $adminIdColumnName = null, $adminIdColumnConstraint = null) { |
|
| 49 | 49 | $blogName = $blogName == null ? $this->table_name : self::TABLE_PREFIX . "_" . $blogName; |
| 50 | 50 | $this->ci->load->dbforge(); |
| 51 | 51 | $this->ci->dbforge->add_field("id"); |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | * @param boolean $w3css [description] |
| 138 | 138 | * @return [type] [description] |
| 139 | 139 | */ |
| 140 | - function loadEditor($callback, $postId=null, $w3css=true) { |
|
| 140 | + function loadEditor($callback, $postId = null, $w3css = true) { |
|
| 141 | 141 | $this->loadScripts($w3css); |
| 142 | 142 | $this->ci->load->helper("form"); |
| 143 | 143 | $data = array( |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | * @param [type] $posterId [description] |
| 159 | 159 | * @return [type] [description] |
| 160 | 160 | */ |
| 161 | - function savePost($posterId=null) { |
|
| 161 | + function savePost($posterId = null) { |
|
| 162 | 162 | $action = $this->ci->security->xss_clean($this->ci->input->post("action")); |
| 163 | 163 | if ($action == "save") { |
| 164 | 164 | $id = $this->ci->security->xss_clean($this->ci->input->post("id")); |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | * return all posts. false by default. |
| 195 | 195 | * @return array Array of posts for a given page. |
| 196 | 196 | */ |
| 197 | - function getPosts($page, $limit, $filter=false, $hits=false) { |
|
| 197 | + function getPosts($page, $limit, $filter = false, $hits = false) { |
|
| 198 | 198 | return $this->ci->bmanager->getPosts($page, $limit, $filter, $hits); |
| 199 | 199 | } |
| 200 | 200 | /** |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | * @param boolean $hits [description] |
| 208 | 208 | * @return [type] [description] |
| 209 | 209 | */ |
| 210 | - function renderPostItems($view=null, $callback=null, $empty_view=null, $page=1, $limit=5, $filter=false, $hits=false, $slug=true) { |
|
| 210 | + function renderPostItems($view = null, $callback = null, $empty_view = null, $page = 1, $limit = 5, $filter = false, $hits = false, $slug = true) { |
|
| 211 | 211 | if ($view == null || $empty_view == null) $this->ci->load->bind("francis94c/blog", $blogger); |
| 212 | 212 | $posts = $this->getPosts($page, $limit, $filter, $hits); |
| 213 | 213 | if (count($posts) == 0) { |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | * @param boolean $filter [description] |
| 233 | 233 | * @return [type] [description] |
| 234 | 234 | */ |
| 235 | - function getRecentPosts($limit=5, $filter=false) { |
|
| 235 | + function getRecentPosts($limit = 5, $filter = false) { |
|
| 236 | 236 | return $this->ci->bmanager->getRecentPosts($limit, $filter); |
| 237 | 237 | } |
| 238 | 238 | /** |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | * @param [type] $view [description] |
| 242 | 242 | * @return [type] [description] |
| 243 | 243 | */ |
| 244 | - function renderPost($post, $view=null) { |
|
| 244 | + function renderPost($post, $view = null) { |
|
| 245 | 245 | if (!is_array($post)) $post = $this->ci->bmanager->getPost($post); |
| 246 | 246 | $post["content"] = $this->ci->parsedown->text($post["content"]); |
| 247 | 247 | if ($view == null) { |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | * @param [type] $postId [description] |
| 276 | 276 | * @return [type] [description] |
| 277 | 277 | */ |
| 278 | - function getPost($postId, $hit=true) { |
|
| 278 | + function getPost($postId, $hit = true) { |
|
| 279 | 279 | return $this->ci->bmanager->getPost($postId, $hit); |
| 280 | 280 | } |
| 281 | 281 | /** |
@@ -311,7 +311,7 @@ discard block |
||
| 311 | 311 | * @param boolean $filter [description] |
| 312 | 312 | * @return [type] [description] |
| 313 | 313 | */ |
| 314 | - function searchPosts($words, $page, $limit=0, $filter=false) { |
|
| 314 | + function searchPosts($words, $page, $limit = 0, $filter = false) { |
|
| 315 | 315 | return $this->ci->bmanager->searchPosts($words, $page, $limit, $filter); |
| 316 | 316 | } |
| 317 | 317 | } |
@@ -88,7 +88,9 @@ discard block |
||
| 88 | 88 | "FOREIGN KEY (poster_id) REFERENCES $adminTableName($adminIdColumnName)"); |
| 89 | 89 | } |
| 90 | 90 | $attributes = array('ENGINE' => 'InnoDB'); |
| 91 | - if (!$this->ci->dbforge->create_table($blogName, true, $attributes)) return false; |
|
| 91 | + if (!$this->ci->dbforge->create_table($blogName, true, $attributes)) { |
|
| 92 | + return false; |
|
| 93 | + } |
|
| 92 | 94 | return true; |
| 93 | 95 | } |
| 94 | 96 | /** |
@@ -172,7 +174,9 @@ discard block |
||
| 172 | 174 | } elseif ($action == "publish" || $action == "createAndPublish") { |
| 173 | 175 | if ($action == "publish") { |
| 174 | 176 | $id = $this->ci->security->xss_clean($this->ci->input->post("id")); |
| 175 | - if ($id == "") return self::ABORT; |
|
| 177 | + if ($id == "") { |
|
| 178 | + return self::ABORT; |
|
| 179 | + } |
|
| 176 | 180 | $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); |
| 177 | 181 | $this->ci->bmanager->publishPost($id, true); |
| 178 | 182 | return self::PUBLISH; |
@@ -181,7 +185,9 @@ discard block |
||
| 181 | 185 | return self::CREATE_AND_PUBLISH; |
| 182 | 186 | } |
| 183 | 187 | } elseif ($action == "delete") { |
| 184 | - if ($this->ci->bmanager->deletePost($this->ci->security->xss_clean($this->ci->input->post("id")))) return self::DELETE; |
|
| 188 | + if ($this->ci->bmanager->deletePost($this->ci->security->xss_clean($this->ci->input->post("id")))) { |
|
| 189 | + return self::DELETE; |
|
| 190 | + } |
|
| 185 | 191 | } |
| 186 | 192 | return false; |
| 187 | 193 | } |
@@ -208,7 +214,9 @@ discard block |
||
| 208 | 214 | * @return [type] [description] |
| 209 | 215 | */ |
| 210 | 216 | function renderPostItems($view=null, $callback=null, $empty_view=null, $page=1, $limit=5, $filter=false, $hits=false, $slug=true) { |
| 211 | - if ($view == null || $empty_view == null) $this->ci->load->bind("francis94c/blog", $blogger); |
|
| 217 | + if ($view == null || $empty_view == null) { |
|
| 218 | + $this->ci->load->bind("francis94c/blog", $blogger); |
|
| 219 | + } |
|
| 212 | 220 | $posts = $this->getPosts($page, $limit, $filter, $hits); |
| 213 | 221 | if (count($posts) == 0) { |
| 214 | 222 | if ($empty_view == null) { $blogger->load->view("empty"); } else { |
@@ -242,7 +250,9 @@ discard block |
||
| 242 | 250 | * @return [type] [description] |
| 243 | 251 | */ |
| 244 | 252 | function renderPost($post, $view=null) { |
| 245 | - if (!is_array($post)) $post = $this->ci->bmanager->getPost($post); |
|
| 253 | + if (!is_array($post)) { |
|
| 254 | + $post = $this->ci->bmanager->getPost($post); |
|
| 255 | + } |
|
| 246 | 256 | $post["content"] = $this->ci->parsedown->text($post["content"]); |
| 247 | 257 | if ($view == null) { |
| 248 | 258 | $this->ci->load->splint("francis94c/blog", "-post_item", $post); |
@@ -259,7 +269,9 @@ discard block |
||
| 259 | 269 | $data = array(); |
| 260 | 270 | $data["title"] = $post["title"]; |
| 261 | 271 | $data["description"] = substr($post["content"], 0, 154); |
| 262 | - if (isset($post["share_image"])) $data["image_link"] = $post["share_image"]; |
|
| 272 | + if (isset($post["share_image"])) { |
|
| 273 | + $data["image_link"] = $post["share_image"]; |
|
| 274 | + } |
|
| 263 | 275 | $data["url"] = current_url(); |
| 264 | 276 | return $this->ci->load->splint(self::PACKAGE, "-meta_og", $data, true); |
| 265 | 277 | } |
@@ -4,7 +4,7 @@ |
||
| 4 | 4 | final class BlogTest extends TestCase { |
| 5 | 5 | |
| 6 | 6 | public function testLoadBlog() { |
| 7 | - $ci =& get_instance(); |
|
| 7 | + $ci = & get_instance(); |
|
| 8 | 8 | $ci->load->splint("francis94c/blog", "+Blogger", null, "blogger"); |
| 9 | 9 | $ci->load->database(); |
| 10 | 10 | $this->assertTrue($ci->blogger->install("test_blog")); |