@@ -7,7 +7,7 @@ |
||
| 7 | 7 | "services" => [ |
| 8 | 8 | "request" => [ |
| 9 | 9 | "shared" => true, |
| 10 | - "callback" => function () { |
|
| 10 | + "callback" => function() { |
|
| 11 | 11 | $obj = new \Anax\Request\Request(); |
| 12 | 12 | $obj->init(); |
| 13 | 13 | return $obj; |
@@ -8,22 +8,22 @@ |
||
| 8 | 8 | "services" => [ |
| 9 | 9 | "cache" => [ |
| 10 | 10 | "shared" => true, |
| 11 | - "callback" => function () { |
|
| 11 | + "callback" => function() { |
|
| 12 | 12 | $cache = new \Anax\Cache\FileCache(); |
| 13 | 13 | |
| 14 | 14 | // Load the configuration files |
| 15 | 15 | $cfg = $this->get("configuration"); |
| 16 | 16 | $config = $cfg->load("cache.php"); |
| 17 | - $file = $config["file"] ?? null; |
|
| 18 | - $config = $config["config"] ?? null; |
|
| 17 | + $file = $config[ "file" ] ?? null; |
|
| 18 | + $config = $config[ "config" ] ?? null; |
|
| 19 | 19 | |
| 20 | - $path = $config["basePath"] ?? null; |
|
| 20 | + $path = $config[ "basePath" ] ?? null; |
|
| 21 | 21 | if (!$path || !is_dir($path) || !is_writable($path)) { |
| 22 | 22 | throw new Exception("Configuration file '$file': Cachedir '$path' is not a writable directory."); |
| 23 | 23 | } |
| 24 | 24 | $cache->setPath($path); |
| 25 | 25 | |
| 26 | - $timeToLive = $config["timeToLive"] ?? null; |
|
| 26 | + $timeToLive = $config[ "timeToLive" ] ?? null; |
|
| 27 | 27 | if ($timeToLive) { |
| 28 | 28 | $cache->setTimeToLive($timeToLive); |
| 29 | 29 | } |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | "session" => [ |
| 9 | 9 | "active" => defined("ANAX_WITH_SESSION") && ANAX_WITH_SESSION, // true|false |
| 10 | 10 | "shared" => true, |
| 11 | - "callback" => function () { |
|
| 11 | + "callback" => function() { |
|
| 12 | 12 | $session = new \Anax\Session\Session(); |
| 13 | 13 | |
| 14 | 14 | // Load the configuration files |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | $config = $cfg->load("session"); |
| 17 | 17 | |
| 18 | 18 | // Set session name |
| 19 | - $name = $config["config"]["name"] ?? null; |
|
| 19 | + $name = $config[ "config" ][ "name" ] ?? null; |
|
| 20 | 20 | if (is_string($name)) { |
| 21 | 21 | $session->name($name); |
| 22 | 22 | } |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | "services" => [ |
| 7 | 7 | "router" => [ |
| 8 | 8 | "shared" => true, |
| 9 | - "callback" => function () { |
|
| 9 | + "callback" => function() { |
|
| 10 | 10 | $router = new \Anax\Route\Router(); |
| 11 | 11 | $router->setDI($this); |
| 12 | 12 | |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | $config = $cfg->load("router"); |
| 16 | 16 | |
| 17 | 17 | // Set DEVELOPMENT/PRODUCTION mode, if defined |
| 18 | - $mode = $config["config"]["mode"] ?? null; |
|
| 18 | + $mode = $config[ "config" ][ "mode" ] ?? null; |
|
| 19 | 19 | if (isset($mode)) { |
| 20 | 20 | $router->setMode($mode); |
| 21 | 21 | } else if (defined("ANAX_PRODUCTION")) { |
@@ -25,15 +25,15 @@ discard block |
||
| 25 | 25 | // Add routes from configuration file/dir |
| 26 | 26 | $file = null; |
| 27 | 27 | try { |
| 28 | - $file = $config["file"] ?? null; |
|
| 29 | - $items = $config["config"] ?? []; |
|
| 28 | + $file = $config[ "file" ] ?? null; |
|
| 29 | + $items = $config[ "config" ] ?? [ ]; |
|
| 30 | 30 | if (!empty($items)) { |
| 31 | 31 | $router->addRoutes($items); |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - foreach ($config["items"] ?? [] as $routes) { |
|
| 35 | - $file = $routes["file"]; |
|
| 36 | - $items = $routes["config"] ?? []; |
|
| 34 | + foreach ($config[ "items" ] ?? [ ] as $routes) { |
|
| 35 | + $file = $routes[ "file" ]; |
|
| 36 | + $items = $routes[ "config" ] ?? [ ]; |
|
| 37 | 37 | $router->addRoutes($items); |
| 38 | 38 | } |
| 39 | 39 | } catch (Exception $e) { |
@@ -8,15 +8,15 @@ |
||
| 8 | 8 | "services" => [ |
| 9 | 9 | "content" => [ |
| 10 | 10 | "shared" => true, |
| 11 | - "callback" => function () { |
|
| 11 | + "callback" => function() { |
|
| 12 | 12 | $content = new \Anax\Content\FileBasedContent(); |
| 13 | 13 | $content->setDI($this); |
| 14 | 14 | |
| 15 | 15 | // Load the configuration files |
| 16 | 16 | $cfg = $this->get("configuration"); |
| 17 | 17 | $config = $cfg->load("content.php"); |
| 18 | - $config = $config["config"] ?? null; |
|
| 19 | - $file = $config["file"] ?? null; |
|
| 18 | + $config = $config[ "config" ] ?? null; |
|
| 19 | + $file = $config[ "file" ] ?? null; |
|
| 20 | 20 | |
| 21 | 21 | $content->configure($config); |
| 22 | 22 | |
@@ -7,22 +7,22 @@ |
||
| 7 | 7 | "view" => [ |
| 8 | 8 | "active" => false, |
| 9 | 9 | "shared" => true, |
| 10 | - "callback" => function () { |
|
| 10 | + "callback" => function() { |
|
| 11 | 11 | $view = new \Anax\View\ViewCollection(); |
| 12 | 12 | $view->setDI($this); |
| 13 | 13 | |
| 14 | 14 | // Load the configuration files |
| 15 | 15 | $cfg = $this->get("configuration"); |
| 16 | 16 | $config = $cfg->load("view.php"); |
| 17 | - $file = $config["file"] ?? null; |
|
| 17 | + $file = $config[ "file" ] ?? null; |
|
| 18 | 18 | |
| 19 | - $paths = $config["config"]["paths"] ?? null; |
|
| 19 | + $paths = $config[ "config" ][ "paths" ] ?? null; |
|
| 20 | 20 | if (!$paths) { |
| 21 | 21 | throw new Exception("Configuration file '$file' has no key 'paths', its needed."); |
| 22 | 22 | } |
| 23 | 23 | $view->setPaths($paths); |
| 24 | 24 | |
| 25 | - $suffix = $config["config"]["suffix"] ?? null; |
|
| 25 | + $suffix = $config[ "config" ][ "suffix" ] ?? null; |
|
| 26 | 26 | if ($suffix) { |
| 27 | 27 | $view->setSuffix($suffix); |
| 28 | 28 | } |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | "services" => [ |
| 8 | 8 | "db" => [ |
| 9 | 9 | "shared" => true, |
| 10 | - "callback" => function () { |
|
| 10 | + "callback" => function() { |
|
| 11 | 11 | $db = new \Anax\Database\Database(); |
| 12 | 12 | |
| 13 | 13 | // Load the configuration files |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | $config = $cfg->load("database"); |
| 16 | 16 | |
| 17 | 17 | // Set the database configuration |
| 18 | - $connection = $config["config"] ?? []; |
|
| 18 | + $connection = $config[ "config" ] ?? [ ]; |
|
| 19 | 19 | $db->setOptions($connection); |
| 20 | 20 | |
| 21 | 21 | return $db; |
@@ -25,10 +25,10 @@ discard block |
||
| 25 | 25 | error_reporting(-1); // Report all type of errors |
| 26 | 26 | //error_reporting(E_ALL ^ E_DEPRECATED); // Report no deprecated errors |
| 27 | 27 | if (constant("ANAX_DEVELOPMENT")) { |
| 28 | - ini_set("display_errors", 1); // Display all errors |
|
| 28 | + ini_set("display_errors", 1); // Display all errors |
|
| 29 | 29 | } elseif (constant("ANAX_PRODUCTION")) { |
| 30 | - ini_set("display_errors", 0); // Display no errors |
|
| 31 | - ini_set("log_errors", 1); // Log errors to file error_log |
|
| 30 | + ini_set("display_errors", 0); // Display no errors |
|
| 31 | + ini_set("log_errors", 1); // Log errors to file error_log |
|
| 32 | 32 | ini_set("error_log", ANAX_INSTALL_PATH . "/log/error_log"); |
| 33 | 33 | } |
| 34 | 34 | |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | /** |
| 38 | 38 | * Default exception handler. |
| 39 | 39 | */ |
| 40 | -set_exception_handler(function ($e) { |
|
| 40 | +set_exception_handler(function($e) { |
|
| 41 | 41 | echo "<p>Anax: Uncaught exception:</p><p>Line " |
| 42 | 42 | . $e->getLine() |
| 43 | 43 | . " in file " |
@@ -44,10 +44,10 @@ discard block |
||
| 44 | 44 | // Connect the database |
| 45 | 45 | $this->db = $this->di->get("db"); |
| 46 | 46 | $this->db->connect(); |
| 47 | - if ($this->currentUser !=null) { |
|
| 47 | + if ($this->currentUser!=null) { |
|
| 48 | 48 | $sql = "SELECT id from users where username = ?;"; |
| 49 | - $res = $this->db->executeFetchAll($sql, [$this->currentUser]); |
|
| 50 | - $this->userId = $res[0]->id; |
|
| 49 | + $res = $this->db->executeFetchAll($sql, [ $this->currentUser ]); |
|
| 50 | + $this->userId = $res[ 0 ]->id; |
|
| 51 | 51 | } |
| 52 | 52 | } |
| 53 | 53 | |
@@ -114,13 +114,13 @@ discard block |
||
| 114 | 114 | $tags = $request->getPost("Tags") ?: null; |
| 115 | 115 | |
| 116 | 116 | $sql = "INSERT INTO posts (title, content, user_id) VALUES (?, ?, ?);"; |
| 117 | - $this->db->execute($sql, [$title, $content, $this->userId]); |
|
| 117 | + $this->db->execute($sql, [ $title, $content, $this->userId ]); |
|
| 118 | 118 | $lastInsertId = $this->db->lastInsertId(); |
| 119 | 119 | var_dump($lastInsertId); |
| 120 | 120 | $tagsArray = explode(",", $tags); |
| 121 | 121 | foreach ($tagsArray as $value) { |
| 122 | 122 | $sql = "INSERT INTO post2tag (post_id, tag_name) VALUES (?, ?);"; |
| 123 | - $this->db->execute($sql, [$lastInsertId, trim($value)]); |
|
| 123 | + $this->db->execute($sql, [ $lastInsertId, trim($value) ]); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | return $response->redirect("post"); |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | $comment = $request->getPost("answer") ?: null; |
| 147 | 147 | |
| 148 | 148 | $sql = "INSERT INTO comments (comment, user_id, post_id, answer) VALUES (?, ?, ?, ?);"; |
| 149 | - $this->db->execute($sql, [$comment, $this->userId, $post_id, 1]); |
|
| 149 | + $this->db->execute($sql, [ $comment, $this->userId, $post_id, 1 ]); |
|
| 150 | 150 | $response = $this->di->get("response"); |
| 151 | 151 | return $response->redirect("post/show/$post_id"); |
| 152 | 152 | } |
@@ -171,32 +171,32 @@ discard block |
||
| 171 | 171 | $orderBy = $request->getGet("orderby") ?: "created"; |
| 172 | 172 | $order = $request->getGet("order") ?: "asc"; |
| 173 | 173 | $sql = "SELECT * from posts WHERE id=?;"; |
| 174 | - $posts = $this->db->executeFetchAll($sql, [$postid]); |
|
| 174 | + $posts = $this->db->executeFetchAll($sql, [ $postid ]); |
|
| 175 | 175 | $sql = "select * from post2tag where post_id=?;"; |
| 176 | - $posttags = $db->executeFetchAll($sql, [$item->id]); |
|
| 176 | + $posttags = $db->executeFetchAll($sql, [ $item->id ]); |
|
| 177 | 177 | $sql = "SELECT sum(score) as postscore from post_votes where post_id=?;"; |
| 178 | - $score = $this->db->executeFetchAll($sql, [$item->id]); |
|
| 178 | + $score = $this->db->executeFetchAll($sql, [ $item->id ]); |
|
| 179 | 179 | $sql = "SELECT sum(answer) as totalanswer from comments where post_id=?;"; |
| 180 | - $answer = $this->db->executeFetchAll($sql, [$item->id]); |
|
| 180 | + $answer = $this->db->executeFetchAll($sql, [ $item->id ]); |
|
| 181 | 181 | |
| 182 | 182 | $sql = "SELECT * from v_comments_user WHERE post_id=? and answer=1 order by accepted desc, $orderBy $order;"; |
| 183 | 183 | //Get the answers for the post |
| 184 | - $answers = $this->db->executeFetchAll($sql, [$postid]); |
|
| 184 | + $answers = $this->db->executeFetchAll($sql, [ $postid ]); |
|
| 185 | 185 | $sql = "SELECT * from v_comments_user WHERE post_id=? and answer=0 and ISNULL(comment_reply_id);"; |
| 186 | 186 | // Get the comments for the post |
| 187 | - $comments0 = $this->db->executeFetchAll($sql, [$postid]); |
|
| 187 | + $comments0 = $this->db->executeFetchAll($sql, [ $postid ]); |
|
| 188 | 188 | |
| 189 | 189 | |
| 190 | 190 | // check if the current user is the owner of the question, if yes, show the accepted answer button otherwise not |
| 191 | 191 | // var_dump($this->currentUser,$posts[0]->username ); |
| 192 | - $isOwner=true; |
|
| 193 | - if ($this->currentUser != $posts[0]->username ) { |
|
| 192 | + $isOwner = true; |
|
| 193 | + if ($this->currentUser!=$posts[ 0 ]->username) { |
|
| 194 | 194 | $isOwner = false; |
| 195 | 195 | } |
| 196 | 196 | $page->add("post/show", |
| 197 | - ["post" => $posts[0], |
|
| 198 | - "postscore" => $postscore[0]->postscore?:0, |
|
| 199 | - "totalanswer" => $answer[0]->totalanswer?:0, |
|
| 197 | + [ "post" => $posts[ 0 ], |
|
| 198 | + "postscore" => $postscore[ 0 ]->postscore ?: 0, |
|
| 199 | + "totalanswer" => $answer[ 0 ]->totalanswer ?: 0, |
|
| 200 | 200 | "answers" => $answers, |
| 201 | 201 | "comments0" => $comments0, |
| 202 | 202 | "isOwner" => $isOwner, |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | $page = $this->di->get("page"); |
| 213 | 213 | |
| 214 | 214 | $sql = "INSERT INTO post_votes (score, post_id, user_id) VALUES (?, ?, ?);"; |
| 215 | - $this->db->execute($sql, [1, $id, $this->userId]); |
|
| 215 | + $this->db->execute($sql, [ 1, $id, $this->userId ]); |
|
| 216 | 216 | |
| 217 | 217 | |
| 218 | 218 | $response = $this->di->get("response"); |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | $page = $this->di->get("page"); |
| 225 | 225 | |
| 226 | 226 | $sql = "INSERT INTO post_votes (score, post_id, user_id) VALUES (?, ?, ?);"; |
| 227 | - $this->db->execute($sql, [-1, $id, $this->userId]); |
|
| 227 | + $this->db->execute($sql, [-1, $id, $this->userId ]); |
|
| 228 | 228 | |
| 229 | 229 | |
| 230 | 230 | $response = $this->di->get("response"); |