@@ -42,11 +42,11 @@ discard block |
||
| 42 | 42 | public function viewPost(string $slug, string $page = "page-1", int $linesPerPage = Constant::COMMENTS_PER_PAGE) |
| 43 | 43 | { |
| 44 | 44 | |
| 45 | - $postId = (int)$this->postModel->getPostIdFromSlug($slug); |
|
| 45 | + $postId = (int) $this->postModel->getPostIdFromSlug($slug); |
|
| 46 | 46 | |
| 47 | 47 | $posts = $this->postModel->getSinglePost($postId); |
| 48 | 48 | |
| 49 | - if($posts === false) |
|
| 49 | + if ($posts === false) |
|
| 50 | 50 | { |
| 51 | 51 | throw new \Exception("Page no longer exists", "404"); |
| 52 | 52 | } |
@@ -89,9 +89,9 @@ discard block |
||
| 89 | 89 | $this->onlyUser(); |
| 90 | 90 | |
| 91 | 91 | //get the session userId |
| 92 | - $userId = (int)$this->session->get("userId"); |
|
| 93 | - $comment = (string)$this->request->getData("newComment"); |
|
| 94 | - $postId = (int)$this->request->getData("postId"); |
|
| 92 | + $userId = (int) $this->session->get("userId"); |
|
| 93 | + $comment = (string) $this->request->getData("newComment"); |
|
| 94 | + $postId = (int) $this->request->getData("postId"); |
|
| 95 | 95 | |
| 96 | 96 | //check if we are admin, Admins do not need moderation |
| 97 | 97 | $admin = $this->session->get('user_role_level') >= Constant::ADMIN_LEVEL; |
@@ -103,8 +103,8 @@ discard block |
||
| 103 | 103 | $post = $this->postModel->getSinglePost($postId); |
| 104 | 104 | $baseUrl = $this->request->getBaseUrl(); |
| 105 | 105 | |
| 106 | - $emailMessage = "<h1>New comment on post " . $post->title . "</a></h1>"; |
|
| 107 | - $emailMessage .= "<p>Check it out <a href='" . $baseUrl . "admin/comments/moderate-comment/" . $commentId . "'>here</a> </p>"; |
|
| 106 | + $emailMessage = "<h1>New comment on post ".$post->title."</a></h1>"; |
|
| 107 | + $emailMessage .= "<p>Check it out <a href='".$baseUrl."admin/comments/moderate-comment/".$commentId."'>here</a> </p>"; |
|
| 108 | 108 | |
| 109 | 109 | $this->sendMail->send($siteConfig["admin_email_address"], "New comment added", $emailMessage); |
| 110 | 110 | |
@@ -113,6 +113,6 @@ discard block |
||
| 113 | 113 | |
| 114 | 114 | $postSlug = $this->postModel->getPostSlugFromId($postId); |
| 115 | 115 | |
| 116 | - $this->response->redirect("/post/view-post/" . $postSlug); |
|
| 116 | + $this->response->redirect("/post/view-post/".$postSlug); |
|
| 117 | 117 | } |
| 118 | 118 | } |
| 119 | 119 | \ No newline at end of file |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | $this->onlyPost(); |
| 118 | 118 | |
| 119 | 119 | $posts = $this->request->getDataFull(); |
| 120 | - $userSessionId = (int)$this->session->get("userId"); |
|
| 120 | + $userSessionId = (int) $this->session->get("userId"); |
|
| 121 | 121 | |
| 122 | 122 | |
| 123 | 123 | $title = trim($posts["postTitle"]); |
@@ -163,10 +163,10 @@ discard block |
||
| 163 | 163 | |
| 164 | 164 | //checking result and redirecting |
| 165 | 165 | if ($postId != null) { |
| 166 | - $this->alertBox->setAlert("Post " . $title . " Created"); |
|
| 167 | - $this->container->getResponse()->redirect("admin/post/modify/" . $postSlug); |
|
| 166 | + $this->alertBox->setAlert("Post ".$title." Created"); |
|
| 167 | + $this->container->getResponse()->redirect("admin/post/modify/".$postSlug); |
|
| 168 | 168 | } |
| 169 | - $this->alertBox->setAlert("Error creating " . $title, "error"); |
|
| 169 | + $this->alertBox->setAlert("Error creating ".$title, "error"); |
|
| 170 | 170 | $this->container->getResponse()->redirect("admin/post/new"); |
| 171 | 171 | |
| 172 | 172 | } |
@@ -231,11 +231,11 @@ discard block |
||
| 231 | 231 | |
| 232 | 232 | //checking result and redirecting |
| 233 | 233 | if ($postUpdate) { |
| 234 | - $this->alertBox->setAlert("Post " . $title . " Updated"); |
|
| 235 | - $this->container->getResponse()->redirect("admin/post/modify/" . $postSlug); |
|
| 234 | + $this->alertBox->setAlert("Post ".$title." Updated"); |
|
| 235 | + $this->container->getResponse()->redirect("admin/post/modify/".$postSlug); |
|
| 236 | 236 | } |
| 237 | - $this->alertBox->setAlert("Error updating " . $title, "error"); |
|
| 238 | - $this->container->getResponse()->redirect("admin/post/modify/" . $originalPostSlug); |
|
| 237 | + $this->alertBox->setAlert("Error updating ".$title, "error"); |
|
| 238 | + $this->container->getResponse()->redirect("admin/post/modify/".$originalPostSlug); |
|
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | $removedPost = $this->postModel->deletePost($postId); |
| 253 | 253 | |
| 254 | 254 | if ($removedPost) { |
| 255 | - $this->alertBox->setAlert("Post " . $postTitle . " deleted"); |
|
| 255 | + $this->alertBox->setAlert("Post ".$postTitle." deleted"); |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | $this->response->redirect("admin/post/list/"); |
@@ -50,10 +50,10 @@ discard block |
||
| 50 | 50 | $twigOptions = []; |
| 51 | 51 | if (!Config::DEV_ENVIRONMENT) { |
| 52 | 52 | $twigOptions = [ |
| 53 | - 'cache' => dirname(__DIR__) . '/Cache' |
|
| 53 | + 'cache' => dirname(__DIR__).'/Cache' |
|
| 54 | 54 | ]; |
| 55 | 55 | } |
| 56 | - $loader = new \Twig_Loader_Filesystem(dirname(__DIR__) . '/App/Views'); |
|
| 56 | + $loader = new \Twig_Loader_Filesystem(dirname(__DIR__).'/App/Views'); |
|
| 57 | 57 | $twig = new \Twig_Environment($loader, $twigOptions); |
| 58 | 58 | |
| 59 | 59 | return $twig; |
@@ -68,14 +68,14 @@ discard block |
||
| 68 | 68 | if ($this->dbh) { |
| 69 | 69 | return $this->dbh; |
| 70 | 70 | } |
| 71 | - $dsn = "mysql:host=" . Config::DB_HOST . ";dbname=" . Config::DB_NAME . ";charset=utf8"; //Creating the Data Source name |
|
| 71 | + $dsn = "mysql:host=".Config::DB_HOST.";dbname=".Config::DB_NAME.";charset=utf8"; //Creating the Data Source name |
|
| 72 | 72 | $opt = [ |
| 73 | 73 | PDO::ATTR_PERSISTENT => true, |
| 74 | 74 | PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, |
| 75 | 75 | PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ, |
| 76 | 76 | PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true |
| 77 | 77 | ]; |
| 78 | - $this->dbh = new PDO($dsn, Config::DB_USER, Config::DB_PASSWORD, $opt);; |
|
| 78 | + $this->dbh = new PDO($dsn, Config::DB_USER, Config::DB_PASSWORD, $opt); ; |
|
| 79 | 79 | return $this->dbh; |
| 80 | 80 | } |
| 81 | 81 | |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | */ |
| 122 | 122 | public function getCookie(): Dependency\Cookie |
| 123 | 123 | { |
| 124 | - if(!$this->cookie){ |
|
| 124 | + if (!$this->cookie) { |
|
| 125 | 125 | $this->cookie = new Cookie(); |
| 126 | 126 | } |
| 127 | 127 | return $this->cookie; |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | private function checkOriginalAdmin(): bool |
| 45 | 45 | { |
| 46 | - $userId = (int)$this->user->userId; |
|
| 46 | + $userId = (int) $this->user->userId; |
|
| 47 | 47 | //The admin selector should be disables and not sent so forcing default role |
| 48 | 48 | $userLockedOut = $this->user->userLockedOut ?? 0; |
| 49 | 49 | $userRoleSelector = $this->user->userRoleSelector ?? 2; |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | //forcing the default values |
| 63 | - if($userId === 1){ |
|
| 63 | + if ($userId === 1) { |
|
| 64 | 64 | $this->user->userRoleSelector = 2; |
| 65 | 65 | $this->user->userLockedOut = 0; |
| 66 | 66 | } |
@@ -173,14 +173,14 @@ discard block |
||
| 173 | 173 | $this->onlyUser(); |
| 174 | 174 | $this->onlyPost(); |
| 175 | 175 | |
| 176 | - $this->user = (object)$this->request->getDataFull(); |
|
| 176 | + $this->user = (object) $this->request->getDataFull(); |
|
| 177 | 177 | $redirectUrl = "/admin"; |
| 178 | 178 | |
| 179 | 179 | if ($this->user->userId !== $this->session->get("userId") || isset($this->user->userRoleSelector) || isset($this->user->locked_out)) { |
| 180 | 180 | //an admin is trying to update a user or form tampered with |
| 181 | 181 | $this->onlyAdmin(); |
| 182 | - $redirectUrl = "/admin/home/view-user/" . $this->user->userId; |
|
| 183 | - } else { |
|
| 182 | + $redirectUrl = "/admin/home/view-user/".$this->user->userId; |
|
| 183 | + }else { |
|
| 184 | 184 | //set the role to the original state for update |
| 185 | 185 | $beforeUser = $this->userModel->getUserDetailsById($this->user->userId); |
| 186 | 186 | $this->user->userRoleSelector = $beforeUser->roles_idroles; |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | $categories = $this->categoryModel->getCategories(); |
| 61 | 61 | foreach ($categories as $category) { |
| 62 | 62 | $data += [ |
| 63 | - $category->category_name => '/category/posts/' . $category->categories_slug |
|
| 63 | + $category->category_name => '/category/posts/'.$category->categories_slug |
|
| 64 | 64 | ]; |
| 65 | 65 | } |
| 66 | 66 | return $data; |
@@ -76,11 +76,11 @@ discard block |
||
| 76 | 76 | $session = $this->container->getSession(); |
| 77 | 77 | $userToken = $cookie->getCookie("rememberMe"); |
| 78 | 78 | |
| 79 | - if($userToken && $this->isHexa($userToken)) |
|
| 79 | + if ($userToken && $this->isHexa($userToken)) |
|
| 80 | 80 | { |
| 81 | 81 | //we have a rememberMe Hash, login |
| 82 | 82 | $rememberedLogin = $this->rememberedLoginModel->findByToken($userToken); |
| 83 | - if($rememberedLogin){ |
|
| 83 | + if ($rememberedLogin) { |
|
| 84 | 84 | //we have a hash, login |
| 85 | 85 | $user = $this->userModel->getUserDetailsById($rememberedLogin->users_idusers); |
| 86 | 86 | $session->regenerateSessionId(); //regenerate the ID to avoid session ghosting |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | $table = $reflect->getShortName(); //this is to only get the model name, otherwise we get the full namespace |
| 160 | 160 | //since our models all end with Model, we should remove it. |
| 161 | 161 | $table = $this->removeFromEnd($table, 'Model'); |
| 162 | - $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 |
|
| 162 | + $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 |
|
| 163 | 163 | $table = strtolower($table); //the database names are in lowercase |
| 164 | 164 | } |
| 165 | 165 | |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | //if we are here, then table doesn't exist, check for view |
| 185 | - $view = 'v_' . $table; |
|
| 185 | + $view = 'v_'.$table; |
|
| 186 | 186 | $stmt->bindValue(':table', $view, PDO::PARAM_STR); |
| 187 | 187 | $stmt->execute(); |
| 188 | 188 | $exists = $stmt->rowCount() > 0; //will return 1 if table exists or 0 if non existant |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | protected function getTablePrefix($table) |
| 207 | 207 | { |
| 208 | 208 | if (Config::TABLE_PREFIX != '') { |
| 209 | - $table = Config::TABLE_PREFIX . '_' . $table; |
|
| 209 | + $table = Config::TABLE_PREFIX.'_'.$table; |
|
| 210 | 210 | } |
| 211 | 211 | return $table; |
| 212 | 212 | } |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | protected function getRowById($rowId, $table = null) |
| 276 | 276 | { |
| 277 | 277 | $tableName = $this->getTable($table); |
| 278 | - $idName = 'id' . str_replace(Config::TABLE_PREFIX."_","",$tableName); |
|
| 278 | + $idName = 'id'.str_replace(Config::TABLE_PREFIX."_", "", $tableName); |
|
| 279 | 279 | $sql = "SELECT * FROM $tableName WHERE $idName = :rowId"; |
| 280 | 280 | $this->query($sql); |
| 281 | 281 | $this->bind(':rowId', $rowId); |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | if (!$this->configModel->updateConfig($update->name, $update->value)) { |
| 48 | 48 | $result['success'] = false; |
| 49 | 49 | $result['errorId'][] = $update->name; |
| 50 | - } else { |
|
| 50 | + }else { |
|
| 51 | 51 | $result['successId'][] = $update->name; |
| 52 | 52 | } |
| 53 | 53 | } |
@@ -59,15 +59,15 @@ discard block |
||
| 59 | 59 | * Send a test mail |
| 60 | 60 | * @throws JsonException |
| 61 | 61 | */ |
| 62 | - public function testMail(){ |
|
| 62 | + public function testMail() { |
|
| 63 | 63 | $this->onlyAdmin(); |
| 64 | 64 | $this->onlyPost(); |
| 65 | 65 | $result = array(); |
| 66 | 66 | $result['success'] = false; |
| 67 | - try{ |
|
| 67 | + try { |
|
| 68 | 68 | $this->sendMail->sendTestMail(); |
| 69 | 69 | $result['success'] = true; |
| 70 | - }catch (Swift_TransportException $e) { |
|
| 70 | + } catch (Swift_TransportException $e) { |
|
| 71 | 71 | $result['success'] = false; |
| 72 | 72 | } |
| 73 | 73 | |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | // Create the Transport for mail sending |
| 27 | 27 | //$config = $this->siteConfig->getSiteConfig(); |
| 28 | 28 | $this->transport = (new Swift_SmtpTransport($this->siteConfig["SMTP_server"], |
| 29 | - (int)$this->siteConfig["SMTP_port"])) |
|
| 29 | + (int) $this->siteConfig["SMTP_port"])) |
|
| 30 | 30 | ->setUsername($this->siteConfig["SMTP_user"]) |
| 31 | 31 | ->setPassword($this->siteConfig["SMTP_pass"]); |
| 32 | 32 | |
@@ -68,11 +68,11 @@ discard block |
||
| 68 | 68 | public function sendResetPasswordMail(string $to, string $token, int $userId) |
| 69 | 69 | { |
| 70 | 70 | $url = $this->container->getRequest()->getBaseUrl(); |
| 71 | - $url .= "password/reset/get&token=" . $token; |
|
| 72 | - $url .= "&userId=" . $userId; |
|
| 71 | + $url .= "password/reset/get&token=".$token; |
|
| 72 | + $url .= "&userId=".$userId; |
|
| 73 | 73 | |
| 74 | - $message = "<h1>Message from <a href='" . $this->container->getRequest()->getBaseUrl() . "'>" . $this->siteConfig["site_name"] . "</a></h1>"; |
|
| 75 | - $message .= "<p>You have asked to reset your password, please click <a href=\"" . $url . "\">Here</a> to define a new password</p>"; |
|
| 74 | + $message = "<h1>Message from <a href='".$this->container->getRequest()->getBaseUrl()."'>".$this->siteConfig["site_name"]."</a></h1>"; |
|
| 75 | + $message .= "<p>You have asked to reset your password, please click <a href=\"".$url."\">Here</a> to define a new password</p>"; |
|
| 76 | 76 | |
| 77 | 77 | $this->send($to, "Define New Password", $message); |
| 78 | 78 | } |
@@ -86,14 +86,14 @@ discard block |
||
| 86 | 86 | public function sendNewPasswordMail(string $to, string $token, int $userId) |
| 87 | 87 | { |
| 88 | 88 | $url = $this->container->getRequest()->getBaseUrl(); |
| 89 | - $url .= "password/reset/get&token=" . $token; |
|
| 90 | - $url .= "&userId=" . $userId; |
|
| 91 | - $message = "<h1>Message from <a href='" . $this->container->getRequest()->getBaseUrl() . "'>" . $this->siteConfig["site_name"] . "</a></h1>"; |
|
| 89 | + $url .= "password/reset/get&token=".$token; |
|
| 90 | + $url .= "&userId=".$userId; |
|
| 91 | + $message = "<h1>Message from <a href='".$this->container->getRequest()->getBaseUrl()."'>".$this->siteConfig["site_name"]."</a></h1>"; |
|
| 92 | 92 | $message .= "<h2>Welcome to the site</h2>"; |
| 93 | - $message .= "<p>You have sucsessfuly created an account, now all you need to do is <a href=\"" . $url . "\">Create your new password</a></p>"; |
|
| 93 | + $message .= "<p>You have sucsessfuly created an account, now all you need to do is <a href=\"".$url."\">Create your new password</a></p>"; |
|
| 94 | 94 | $message .= "<p>Have fun</p>"; |
| 95 | 95 | |
| 96 | - $this->send($to, "Define Password at " . $this->siteConfig["site_name"], $message); |
|
| 96 | + $this->send($to, "Define Password at ".$this->siteConfig["site_name"], $message); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | /** |
@@ -51,7 +51,7 @@ |
||
| 51 | 51 | die(); |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - if(!$this->categoryModel->isCategorySlugUnique($send["categories_slug"])) |
|
| 54 | + if (!$this->categoryModel->isCategorySlugUnique($send["categories_slug"])) |
|
| 55 | 55 | { |
| 56 | 56 | $result["success"] = false; |
| 57 | 57 | $result["errorMessage"] = "Slug is not unique"; |