@@ -106,12 +106,12 @@ discard block |
||
106 | 106 | $loadModuleObj = $this->getModuleNamespace($loadModule); |
107 | 107 | //Modules must be children of the Module template |
108 | 108 | if (!is_subclass_of($loadModuleObj, 'Core\Modules\Module')) { |
109 | - throw new \ErrorException('Module ' . $loadModuleName . ' must be a sub class of module'); |
|
109 | + throw new \ErrorException('Module '.$loadModuleName.' must be a sub class of module'); |
|
110 | 110 | } |
111 | 111 | $loadedModule = new $loadModuleObj($this->container); |
112 | 112 | //we are not allowed to create public modules, they must be a placeholder ready |
113 | 113 | if (!property_exists($this, $loadModuleName)) { |
114 | - throw new \ErrorException('the protected or private variable of ' . $loadModuleName . ' is not present'); |
|
114 | + throw new \ErrorException('the protected or private variable of '.$loadModuleName.' is not present'); |
|
115 | 115 | } |
116 | 116 | $this->$loadModuleName = $loadedModule; |
117 | 117 | } |
@@ -128,23 +128,23 @@ discard block |
||
128 | 128 | $childClass = new \ReflectionClass(get_class($this)); |
129 | 129 | $childClassNamespace = $childClass->getNamespaceName(); |
130 | 130 | //check in classNameSpace |
131 | - if (class_exists($childClassNamespace . '\\Modules\\' . $loadModule)) { |
|
132 | - $this->addToDevHelper('module ' . $loadModule . ' loaded', $childClassNamespace . '\\' . $loadModule); |
|
133 | - return $childClassNamespace . '\\' . $loadModule; |
|
131 | + if (class_exists($childClassNamespace.'\\Modules\\'.$loadModule)) { |
|
132 | + $this->addToDevHelper('module '.$loadModule.' loaded', $childClassNamespace.'\\'.$loadModule); |
|
133 | + return $childClassNamespace.'\\'.$loadModule; |
|
134 | 134 | } |
135 | 135 | //check in app |
136 | - if (class_exists('App\\Modules\\' . $loadModule)) { |
|
137 | - $this->addToDevHelper('module ' . $loadModule . ' loaded', 'App\\Modules\\' . $loadModule); |
|
138 | - return 'App\\Modules\\' . $loadModule; |
|
136 | + if (class_exists('App\\Modules\\'.$loadModule)) { |
|
137 | + $this->addToDevHelper('module '.$loadModule.' loaded', 'App\\Modules\\'.$loadModule); |
|
138 | + return 'App\\Modules\\'.$loadModule; |
|
139 | 139 | } |
140 | 140 | //check in core, send error popup if overcharged |
141 | - if (class_exists('Core\\Modules\\' . $loadModule)) { |
|
142 | - $this->addToDevHelper('module ' . $loadModule . ' loaded', 'Core\\Modules\\' . $loadModule); |
|
143 | - return 'Core\\Modules\\' . $loadModule; |
|
141 | + if (class_exists('Core\\Modules\\'.$loadModule)) { |
|
142 | + $this->addToDevHelper('module '.$loadModule.' loaded', 'Core\\Modules\\'.$loadModule); |
|
143 | + return 'Core\\Modules\\'.$loadModule; |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | //if we are here then no module found |
147 | - throw new \ErrorException('module ' . $loadModule . ' does not exist or not loaded'); |
|
147 | + throw new \ErrorException('module '.$loadModule.' does not exist or not loaded'); |
|
148 | 148 | |
149 | 149 | } |
150 | 150 | |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | public function getView($template) |
170 | 170 | { |
171 | 171 | $twig = $this->container->getTemplate(); |
172 | - return $twig->render($template . '.twig', $this->data); |
|
172 | + return $twig->render($template.'.twig', $this->data); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | /** |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | } |
196 | 196 | |
197 | 197 | $twig = $this->container->getTemplate(); |
198 | - $twig->display($template . '.twig', $this->data); |
|
198 | + $twig->display($template.'.twig', $this->data); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | /** |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | protected function addToDevHelper($name, $var) |
228 | 228 | { |
229 | 229 | //only populate if in dev environment |
230 | - if (Config::DEV_ENVIRONMENT){ |
|
230 | + if (Config::DEV_ENVIRONMENT) { |
|
231 | 231 | $classMethods = []; |
232 | 232 | $classMethods[$name] = $var; |
233 | 233 | if (!isset($this->data['dev_info'])) { |
@@ -28,8 +28,8 @@ discard block |
||
28 | 28 | if (!$this->container->getRequest()->isPost()) { |
29 | 29 | throw new \Core\JsonException('Call is not post'); |
30 | 30 | } |
31 | - $state = (bool)($this->request->getData("state") === 'true'); |
|
32 | - $postId = (int)$this->request->getData("postId"); |
|
31 | + $state = (bool) ($this->request->getData("state") === 'true'); |
|
32 | + $postId = (int) $this->request->getData("postId"); |
|
33 | 33 | |
34 | 34 | $result = array(); |
35 | 35 | $result["success"] = $this->postModule->setPublished(!$state, $postId); |
@@ -48,8 +48,8 @@ discard block |
||
48 | 48 | if (!$this->container->getRequest()->isPost()) { |
49 | 49 | throw new \Core\JsonException('Call is not post'); |
50 | 50 | } |
51 | - $state = (bool)($this->request->getData("state") === 'true'); //TODO test this element |
|
52 | - $postId = (int)$this->request->getData("postId"); |
|
51 | + $state = (bool) ($this->request->getData("state") === 'true'); //TODO test this element |
|
52 | + $postId = (int) $this->request->getData("postId"); |
|
53 | 53 | |
54 | 54 | $result = array(); |
55 | 55 | $result["success"] = $this->postModule->setOnFrontPage(!$state, $postId); |
@@ -92,7 +92,7 @@ |
||
92 | 92 | * return the entire session superglobal. |
93 | 93 | * @return mixed |
94 | 94 | */ |
95 | - public function getAllSessionVars(){ |
|
95 | + public function getAllSessionVars() { |
|
96 | 96 | return $_SESSION; |
97 | 97 | } |
98 | 98 |
@@ -23,7 +23,7 @@ |
||
23 | 23 | const POSTS_PER_PAGE = 4; |
24 | 24 | const LIST_PER_PAGE = 10; |
25 | 25 | |
26 | - const EXCERPT_WORD_COUNT =50; |
|
26 | + const EXCERPT_WORD_COUNT = 50; |
|
27 | 27 | |
28 | 28 | //login security |
29 | 29 | const NUMBER_OF_BAD_PASSWORD_TRIES = 3; |
@@ -44,24 +44,24 @@ discard block |
||
44 | 44 | private function getFilename(string $folder, string $file): string |
45 | 45 | { |
46 | 46 | //slugify the file name to avoid security errors or bugs with special characters. |
47 | - $fileName = pathinfo($file, PATHINFO_FILENAME ); |
|
48 | - $fileExtension = pathinfo($file, PATHINFO_EXTENSION ); |
|
47 | + $fileName = pathinfo($file, PATHINFO_FILENAME); |
|
48 | + $fileExtension = pathinfo($file, PATHINFO_EXTENSION); |
|
49 | 49 | $slugify = new Slugify(); |
50 | 50 | $fileName = $slugify->slugify($fileName); |
51 | 51 | //if the filename has only special chars, the slugify will be empty, create a unique ID |
52 | - if($fileName ==="") |
|
52 | + if ($fileName === "") |
|
53 | 53 | { |
54 | 54 | $fileName = uniqid(); |
55 | 55 | } |
56 | 56 | $file = $fileName.".".$fileExtension; |
57 | - $fileUrl = $folder . $file; |
|
57 | + $fileUrl = $folder.$file; |
|
58 | 58 | $docRoot = $this->request->getDocumentRoot(); |
59 | - $filePath = $docRoot . "/public/" . $fileUrl; |
|
59 | + $filePath = $docRoot."/public/".$fileUrl; |
|
60 | 60 | if (file_exists($filePath) !== 1) { |
61 | 61 | $fileNum = 0; |
62 | 62 | while (file_exists($filePath)) { |
63 | - $fileUrl = $folder . $fileNum . "_" . $file; |
|
64 | - $filePath = $docRoot . "/public/" . $fileUrl; |
|
63 | + $fileUrl = $folder.$fileNum."_".$file; |
|
64 | + $filePath = $docRoot."/public/".$fileUrl; |
|
65 | 65 | $fileNum += 1; |
66 | 66 | } |
67 | 67 | } |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | |
86 | 86 | // Respond to the successful upload with JSON. |
87 | 87 | echo json_encode(array('location' => $filetowrite)); |
88 | - } else { |
|
88 | + }else { |
|
89 | 89 | // Notify editor that the upload failed |
90 | 90 | echo json_encode(array('error' => 'Upload failed, file might be too big')); |
91 | 91 | |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | |
120 | 120 | // Respond to the successful upload with JSON. |
121 | 121 | echo json_encode(array('location' => $filetowrite)); |
122 | - } else { |
|
122 | + }else { |
|
123 | 123 | // Notify editor that the upload failed |
124 | 124 | header("HTTP/1.1 500 Server Error"); |
125 | 125 | } |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | //check if email is valid for sanity |
139 | 139 | if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { |
140 | 140 | $email = htmlspecialchars($email); |
141 | - throw new BlogocException("invalid email " . $email); |
|
141 | + throw new BlogocException("invalid email ".$email); |
|
142 | 142 | } |
143 | 143 | $sql = $this->baseSqlSelect(); |
144 | 144 | $sql .= " |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | $this->bind(':roles_idroles', 1); |
187 | 187 | $this->execute(); |
188 | 188 | |
189 | - return (int)$this->dbh->lastInsertId(); |
|
189 | + return (int) $this->dbh->lastInsertId(); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | /** |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | } |
218 | 218 | |
219 | 219 | if ($this->isAccountPasswordBlocked($user)) { |
220 | - $response->message = "too many bad passwords, account is blocked for " . Constant::LOCKOUT_MINUTES . " minutes"; |
|
220 | + $response->message = "too many bad passwords, account is blocked for ".Constant::LOCKOUT_MINUTES." minutes"; |
|
221 | 221 | return $response; |
222 | 222 | } |
223 | 223 | |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | { |
241 | 241 | if ($token_value) { |
242 | 242 | $this->token = $token_value; |
243 | - } else { |
|
243 | + }else { |
|
244 | 244 | $this->token = bin2hex(random_bytes(16)); |
245 | 245 | } |
246 | 246 | } |
@@ -301,9 +301,9 @@ discard block |
||
301 | 301 | $this->execute(); |
302 | 302 | $result = $this->fetch(); |
303 | 303 | |
304 | - if($result) |
|
304 | + if ($result) |
|
305 | 305 | { |
306 | - if(strtotime($result->expires_at) < time()) |
|
306 | + if (strtotime($result->expires_at) < time()) |
|
307 | 307 | { |
308 | 308 | //token has expired |
309 | 309 | $this->deleteToken($hashedToken); |
@@ -204,9 +204,11 @@ |
||
204 | 204 | |
205 | 205 | $user = $this->getUserDetailsByEmail($email); |
206 | 206 | |
207 | - if ($user === false) //no user exists |
|
207 | + if ($user === false) { |
|
208 | + //no user exists |
|
208 | 209 | { |
209 | 210 | $response->message = "email doesn't exist, register a new account?"; |
211 | + } |
|
210 | 212 | return $response; |
211 | 213 | } |
212 | 214 |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | |
40 | 40 | // Create the Transport for mail sending |
41 | 41 | $config = $this->siteConfig->getSiteConfig(); |
42 | - $this->transport = (new Swift_SmtpTransport($config["SMTP_server"], (int)$config["SMTP_port"])) |
|
42 | + $this->transport = (new Swift_SmtpTransport($config["SMTP_server"], (int) $config["SMTP_port"])) |
|
43 | 43 | ->setUsername($config["SMTP_user"]) |
44 | 44 | ->setPassword($config["SMTP_pass"]) |
45 | 45 | ; |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | private function populateUserFromId(int $userId) |
80 | 80 | { |
81 | 81 | $result = $this->userModel->getUserDetailsById($userId); |
82 | - $this->populateUser((array)$result); |
|
82 | + $this->populateUser((array) $result); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | */ |
101 | 101 | public function index() |
102 | 102 | { |
103 | - if($this->session->isParamSet("user")) |
|
103 | + if ($this->session->isParamSet("user")) |
|
104 | 104 | { |
105 | 105 | //we are already connected, redirect |
106 | 106 | $this->response->redirect(); |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | */ |
130 | 130 | public function register() |
131 | 131 | { |
132 | - if($this->session->isParamSet("user")) |
|
132 | + if ($this->session->isParamSet("user")) |
|
133 | 133 | { |
134 | 134 | //we are already connected, redirect |
135 | 135 | $this->response->redirect(); |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | } |
190 | 190 | |
191 | 191 | $authUser = $this->userModel->authenticateUser($email, $password); |
192 | - if(!$authUser->success) |
|
192 | + if (!$authUser->success) |
|
193 | 193 | { |
194 | 194 | $error = true; |
195 | 195 | $loginErrors->global = $authUser->message; |
@@ -208,14 +208,14 @@ discard block |
||
208 | 208 | //we are authenticated here |
209 | 209 | |
210 | 210 | //populate the user object with returned data |
211 | - $this->populateUser((array)$authUser->user); |
|
211 | + $this->populateUser((array) $authUser->user); |
|
212 | 212 | |
213 | 213 | //if the user wanted to be remembered |
214 | - if($rememberMe) |
|
214 | + if ($rememberMe) |
|
215 | 215 | { |
216 | 216 | $this->userModel->setToken(); //generate a new token |
217 | 217 | $rememberMeToken = $this->userModel->rememberMe($this->user->idusers); |
218 | - if($rememberMeToken->success) |
|
218 | + if ($rememberMeToken->success) |
|
219 | 219 | { |
220 | 220 | //set cookie |
221 | 221 | $this->cookie->setCookie("rememberMe", $rememberMeToken->token, $rememberMeToken->expiry_timestamp); |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | $categories = $categoryModel->getCategories(); |
48 | 48 | foreach ($categories as $category) { |
49 | 49 | $data += [ |
50 | - $category->category_name => '/category/posts/' . $category->categories_slug |
|
50 | + $category->category_name => '/category/posts/'.$category->categories_slug |
|
51 | 51 | ]; |
52 | 52 | } |
53 | 53 | return $data; |
@@ -60,11 +60,11 @@ discard block |
||
60 | 60 | $session = $this->container->getSession(); |
61 | 61 | |
62 | 62 | $userToken = $cookie->getCookie("rememberMe"); |
63 | - if($userToken) |
|
63 | + if ($userToken) |
|
64 | 64 | { |
65 | 65 | //we have a rememberMe Hash, login |
66 | 66 | $rememberedLogin = $userModel->findByToken($userToken); |
67 | - if($rememberedLogin){ |
|
67 | + if ($rememberedLogin) { |
|
68 | 68 | //we have a hash, login |
69 | 69 | $user = $userModel->getUserDetailsById($rememberedLogin->users_idusers); |
70 | 70 | $session->regenerateSessionId(); //regenerate the ID to avoid session ghosting |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | namespace Core\Dependency; |
4 | 4 | |
5 | -class Cookie{ |
|
5 | +class Cookie { |
|
6 | 6 | |
7 | 7 | /** |
8 | 8 | * set a cookie |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | */ |
22 | 22 | public function deleteCookie(string $name) |
23 | 23 | { |
24 | - setcookie($name, "", time()-3600); //expire the cookie |
|
24 | + setcookie($name, "", time() - 3600); //expire the cookie |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | /** |