@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | use Core\Controller; |
9 | 9 | use Core\Container; |
10 | 10 | |
11 | -class Post extends Controller{ |
|
11 | +class Post extends Controller { |
|
12 | 12 | |
13 | 13 | protected $siteConfig; |
14 | 14 | |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * @throws \Twig_Error_Runtime |
27 | 27 | * @throws \Twig_Error_Syntax |
28 | 28 | */ |
29 | - public function viewPost(string $slug){ |
|
29 | + public function viewPost(string $slug) { |
|
30 | 30 | |
31 | 31 | $tagModel = new TagModel($this->container); |
32 | 32 | $postModel = new PostModel($this->container); |
@@ -4,7 +4,7 @@ |
||
4 | 4 | |
5 | 5 | use Core\Model; |
6 | 6 | |
7 | -class UserModel extends Model{ |
|
7 | +class UserModel extends Model { |
|
8 | 8 | |
9 | 9 | public function getAuthorDetails(int $authorId) |
10 | 10 | { |
@@ -67,7 +67,7 @@ |
||
67 | 67 | $this->query($sql); |
68 | 68 | $this->bind(":tag", $tag); |
69 | 69 | $this->execute(); |
70 | - return (int)$this->dbh->lastInsertId(); |
|
70 | + return (int) $this->dbh->lastInsertId(); |
|
71 | 71 | |
72 | 72 | } |
73 | 73 |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | * fetches the result from an executed query |
102 | 102 | * @return array |
103 | 103 | */ |
104 | - protected function fetchAll(){ |
|
104 | + protected function fetchAll() { |
|
105 | 105 | return $this->stmt->fetchAll(); |
106 | 106 | } |
107 | 107 | |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | * returns a single line from the executed query |
110 | 110 | * @return mixed |
111 | 111 | */ |
112 | - protected function fetch(){ |
|
112 | + protected function fetch() { |
|
113 | 113 | return $this->stmt->fetch(); |
114 | 114 | } |
115 | 115 | |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | $table = $reflect->getShortName(); //this is to only get the model name, otherwise we get the full namespace |
137 | 137 | //since our models all end with Model, we should remove it. |
138 | 138 | $table = $this->removeFromEnd($table, 'Model'); |
139 | - $table = $table . 's'; //adding the s since the table should be plural. Might be some special case where the plural isn't just with an s |
|
139 | + $table = $table.'s'; //adding the s since the table should be plural. Might be some special case where the plural isn't just with an s |
|
140 | 140 | $table = strtolower($table); //the database names are in lowercase |
141 | 141 | } |
142 | 142 | |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | } |
156 | 156 | |
157 | 157 | //if we are here, then table doesn't exist, check for view |
158 | - $view = 'v_' . $table; |
|
158 | + $view = 'v_'.$table; |
|
159 | 159 | $stmt->bindValue(':table', $view, PDO::PARAM_STR); |
160 | 160 | $stmt->execute(); |
161 | 161 | $exists = $stmt->rowCount() > 0; //will return 1 if table exists or 0 if non existant |
@@ -176,8 +176,8 @@ discard block |
||
176 | 176 | * @param $table string the table name |
177 | 177 | * @return string |
178 | 178 | */ |
179 | - protected function getTablePrefix($table){ |
|
180 | - if(Config::TABLE_PREFIX != '') |
|
179 | + protected function getTablePrefix($table) { |
|
180 | + if (Config::TABLE_PREFIX != '') |
|
181 | 181 | { |
182 | 182 | $table = Config::TABLE_PREFIX.'_'.$table; |
183 | 183 | } |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | protected function getRowById($rowId, $table = null) |
249 | 249 | { |
250 | 250 | $tableName = $this->getTable($table); |
251 | - $idName = 'id' . $tableName; |
|
251 | + $idName = 'id'.$tableName; |
|
252 | 252 | $sql = "SELECT * FROM $tableName WHERE $idName = :rowId"; |
253 | 253 | $this->query($sql); |
254 | 254 | $this->bind(':rowId', $rowId); |
@@ -26,7 +26,7 @@ |
||
26 | 26 | throw new \Exception("Pagination Error", "404"); |
27 | 27 | } |
28 | 28 | $pageNo = $this->removeFromBeginning($page, "page-"); |
29 | - if(!filter_var($pageNo, FILTER_VALIDATE_INT)){ |
|
29 | + if (!filter_var($pageNo, FILTER_VALIDATE_INT)) { |
|
30 | 30 | throw new \Exception("Invalid page number"); |
31 | 31 | } |
32 | 32 | $offset = ($pageNo - 1) * $rowsPerPage; |
@@ -196,10 +196,12 @@ |
||
196 | 196 | $this->alertBox->setAlert("empty slug not allowed", "error"); |
197 | 197 | } |
198 | 198 | |
199 | - if ($postSlug != $originalPostSlug) //if the slug has been updated |
|
199 | + if ($postSlug != $originalPostSlug) { |
|
200 | + //if the slug has been updated |
|
200 | 201 | { |
201 | 202 | if (!$this->slugModel->isUnique($postSlug, "posts", "posts_slug")) { |
202 | 203 | $error = true; |
204 | + } |
|
203 | 205 | $originalPostSlug = $this->slugModel->getSlugFromId($postId, "posts", "idposts", "posts_slug"); |
204 | 206 | $this->alertBox->setAlert("Slug not unique", "error"); |
205 | 207 | } |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | $totalPosts = $this->postModel->totalNumberFullPosts(); |
81 | 81 | $pagination = $this->pagination->getPagination($page, $totalPosts, $postsPerPage); |
82 | 82 | |
83 | - if($postsPerPage !== Constant::LIST_PER_PAGE){ |
|
83 | + if ($postsPerPage !== Constant::LIST_PER_PAGE) { |
|
84 | 84 | $this->data['paginationPostsPerPage'] = $postsPerPage; |
85 | 85 | } |
86 | 86 | |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | $onFrontpage = $posts["isOnFrontPage"]; |
136 | 136 | $idUser = $userSessionId; |
137 | 137 | |
138 | - if(!is_int($idUser) || $idUser === null) |
|
138 | + if (!is_int($idUser) || $idUser === null) |
|
139 | 139 | { |
140 | 140 | throw new \Error("Invalid userID"); |
141 | 141 | } |
@@ -169,10 +169,10 @@ discard block |
||
169 | 169 | |
170 | 170 | //checking result and redirecting |
171 | 171 | if ($postId != null) { |
172 | - $this->alertBox->setAlert("Post " . $title . " Created"); |
|
173 | - $this->container->getResponse()->redirect("admin/post/modify/" . $postSlug); |
|
172 | + $this->alertBox->setAlert("Post ".$title." Created"); |
|
173 | + $this->container->getResponse()->redirect("admin/post/modify/".$postSlug); |
|
174 | 174 | } |
175 | - $this->alertBox->setAlert("Error creating " . $title, "error"); |
|
175 | + $this->alertBox->setAlert("Error creating ".$title, "error"); |
|
176 | 176 | $this->container->getResponse()->redirect("admin/post/new"); |
177 | 177 | |
178 | 178 | } |
@@ -241,11 +241,11 @@ discard block |
||
241 | 241 | |
242 | 242 | //checking result and redirecting |
243 | 243 | if ($postUpdate) { |
244 | - $this->alertBox->setAlert("Post " . $title . " Updated"); |
|
245 | - $this->container->getResponse()->redirect("admin/post/modify/" . $postSlug); |
|
244 | + $this->alertBox->setAlert("Post ".$title." Updated"); |
|
245 | + $this->container->getResponse()->redirect("admin/post/modify/".$postSlug); |
|
246 | 246 | } |
247 | - $this->alertBox->setAlert("Error updating " . $title, "error"); |
|
248 | - $this->container->getResponse()->redirect("admin/post/modify/" . $originalPostSlug); |
|
247 | + $this->alertBox->setAlert("Error updating ".$title, "error"); |
|
248 | + $this->container->getResponse()->redirect("admin/post/modify/".$originalPostSlug); |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | $this->tagModel->removeTagsOnPost($postId); |
262 | 262 | $removedPost = $this->postModel->deletePost($postId); |
263 | 263 | |
264 | - if($removedPost) |
|
264 | + if ($removedPost) |
|
265 | 265 | { |
266 | 266 | $this->alertBox->setAlert("Post ".$postTitle." deleted"); |
267 | 267 | } |
@@ -8,7 +8,7 @@ |
||
8 | 8 | { |
9 | 9 | public function index() |
10 | 10 | { |
11 | - if(!$this->auth->isUser()){ |
|
11 | + if (!$this->auth->isUser()) { |
|
12 | 12 | $this->alertBox->setAlert("You must be connected to access the admin interface", 'warning'); |
13 | 13 | $this->container->getResponse()->redirect(); |
14 | 14 | } |
@@ -225,13 +225,13 @@ |
||
225 | 225 | } |
226 | 226 | |
227 | 227 | /** |
228 | - * get the list of all the posts. |
|
229 | - * @param int $offset |
|
230 | - * @param array $select array of limiters [$key => $val] will convert to "where $key = $val" |
|
231 | - * @param int $limit |
|
232 | - * @return array |
|
233 | - * @throws \ErrorException |
|
234 | - */ |
|
228 | + * get the list of all the posts. |
|
229 | + * @param int $offset |
|
230 | + * @param array $select array of limiters [$key => $val] will convert to "where $key = $val" |
|
231 | + * @param int $limit |
|
232 | + * @return array |
|
233 | + * @throws \ErrorException |
|
234 | + */ |
|
235 | 235 | public function getPosts(int $offset = 0, array $select = [], int $limit = Constant::POSTS_PER_PAGE): array |
236 | 236 | { |
237 | 237 | return $this->getAllPublishedPosts($offset, $limit, false, $select); |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | $this->query($sql); |
114 | 114 | if ($select != null) { |
115 | 115 | foreach ($select as $col => $val) { |
116 | - $this->bind(":" . $col, $val); |
|
116 | + $this->bind(":".$col, $val); |
|
117 | 117 | } |
118 | 118 | } |
119 | 119 | $this->bind(":limit", $limit); |
@@ -130,13 +130,13 @@ discard block |
||
130 | 130 | * @return int number of posts |
131 | 131 | * @throws Exception |
132 | 132 | */ |
133 | - private function countNumberPosts(array $select = [], $published=true): int |
|
133 | + private function countNumberPosts(array $select = [], $published = true): int |
|
134 | 134 | { |
135 | 135 | $sql = "SELECT COUNT(*) FROM $this->postsTbl"; |
136 | 136 | if ($this->queryWithTags) { |
137 | 137 | $sql .= " LEFT JOIN $this->postTagTbl ON $this->postsTbl.idposts = $this->postTagTbl.post_idposts"; |
138 | 138 | } |
139 | - if($published) |
|
139 | + if ($published) |
|
140 | 140 | { |
141 | 141 | $sql .= " WHERE published = 1"; |
142 | 142 | } |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | $this->query($sql); |
152 | 152 | if ($select != null) { |
153 | 153 | foreach ($select as $col => $val) { |
154 | - $this->bind(":" . $col, $val); |
|
154 | + $this->bind(":".$col, $val); |
|
155 | 155 | } |
156 | 156 | } |
157 | 157 | $this->execute(); |
@@ -334,7 +334,7 @@ discard block |
||
334 | 334 | |
335 | 335 | $this->execute(); |
336 | 336 | |
337 | - return (int)$this->dbh->lastInsertId(); |
|
337 | + return (int) $this->dbh->lastInsertId(); |
|
338 | 338 | } |
339 | 339 | |
340 | 340 | /** |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | use Core\AjaxController; |
7 | 7 | use Core\Container; |
8 | 8 | |
9 | -class postModification extends AjaxController{ |
|
9 | +class postModification extends AjaxController { |
|
10 | 10 | |
11 | 11 | |
12 | 12 | private $postModule; |
@@ -23,8 +23,8 @@ discard block |
||
23 | 23 | if (!$this->container->getRequest()->isPost()) { |
24 | 24 | throw new \Core\JsonException('Call is not post'); |
25 | 25 | } |
26 | - $state = (bool)($this->request->getData("state") === 'true'); |
|
27 | - $postId = (int)$this->request->getData("postId"); |
|
26 | + $state = (bool) ($this->request->getData("state") === 'true'); |
|
27 | + $postId = (int) $this->request->getData("postId"); |
|
28 | 28 | |
29 | 29 | $result["success"] = $this->postModule->setPublished(!$state, $postId); |
30 | 30 | $result["state"] = !$state; |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | throw new \Core\JsonException('Call is not post'); |
40 | 40 | } |
41 | 41 | $state = ($this->request->getData("state") === 'true'); |
42 | - $postId = (int)$this->request->getData("postId"); |
|
42 | + $postId = (int) $this->request->getData("postId"); |
|
43 | 43 | |
44 | 44 | $result["success"] = $this->postModule->setOnFrontPage(!$state, $postId); |
45 | 45 | $result["state"] = !$state; |