summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2024-12-11 19:57:12 -0500
committerFreya Murphy <freya@freyacat.org>2024-12-11 19:57:12 -0500
commitd5f1976e62cb0a32b8bafdb71d7d082d16413256 (patch)
tree487832bc4deae45429bd78875ebb221739d73a8b /src
parentfix spacing, remote __init function (diff)
downloadwebsite-d5f1976e62cb0a32b8bafdb71d7d082d16413256.tar.gz
website-d5f1976e62cb0a32b8bafdb71d7d082d16413256.tar.bz2
website-d5f1976e62cb0a32b8bafdb71d7d082d16413256.zip
make ip nullable, refactor get_ip and get_req_route in router
Diffstat (limited to 'src')
-rw-r--r--src/db/migrations/0002.sql12
-rw-r--r--src/web/core/controller.php1
-rw-r--r--src/web/core/router.php65
3 files changed, 29 insertions, 49 deletions
diff --git a/src/db/migrations/0002.sql b/src/db/migrations/0002.sql
new file mode 100644
index 0000000..99f1494
--- /dev/null
+++ b/src/db/migrations/0002.sql
@@ -0,0 +1,12 @@
+BEGIN TRANSACTION;
+SET search_path = public;
+
+-- Migration Start
+ALTER TABLE admin.comment
+ ALTER COLUMN ip DROP NOT NULL;
+-- Migration End;
+
+-- Set Current Revision
+UPDATE sys.database_info SET curr_revision = 3 WHERE name = current_database();
+
+COMMIT TRANSACTION;
diff --git a/src/web/core/controller.php b/src/web/core/controller.php
index 340bbb1..ac1e458 100644
--- a/src/web/core/controller.php
+++ b/src/web/core/controller.php
@@ -25,7 +25,6 @@ abstract class Controller extends Component {
if (is_file($__path)) {
extract($data);
require($__path);
- return;
}
}
diff --git a/src/web/core/router.php b/src/web/core/router.php
index a1307cf..6a543aa 100644
--- a/src/web/core/router.php
+++ b/src/web/core/router.php
@@ -52,47 +52,11 @@ class Router extends Component {
$parts = explode('/', $path);
// get the length
$len = count($parts);
-
// get route info
$route = array();
- // e.g. /
- if ($path === '')
- $route = array(
- 'app' => 'index',
- 'slug' => 'index',
- 'args' => array(),
- );
- // e.g. /home /login
- else if ($len === 1)
- $route = array(
- 'app' => $parts[0],
- 'slug' => 'index',
- 'args' => array(),
- );
- // e.g. /home/posts
- else if ($len === 2)
- $route = array (
- 'app' => $parts[0],
- 'slug' => $parts[1],
- 'args' => array(),
- );
- // e.g. /home/posts/joe
- else
- $route = array (
- 'app' => $parts[0],
- 'slug' => $parts[1],
- 'args' => array_slice($parts, 2),
- );
-
- if (isset($routes[$path])) {
- $parts = explode('/', $routes[$path]);
- if (count($parts) == 1) {
- $route['app'] = $parts[0];
- } else {
- $route['app'] = $parts[0];
- $route['slug'] = $parts[1];
- }
- }
+ $route['app'] = $len > 0 ? $parts[0] : 'index';
+ $route['slug'] = $len > 1 ? $parts[1] : 'index';
+ $route['args'] = array_slice($parts, 2);
return $route;
}
@@ -100,17 +64,22 @@ class Router extends Component {
/**
* Gets the users ip
*/
- private function get_ip(): string
+ private function get_ip(): ?string
{
- $ip = '';
- if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
- $ip = $_SERVER['HTTP_CLIENT_IP'];
- } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
- $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
- } else {
- $ip = $_SERVER['REMOTE_ADDR'];
+ $headers = array (
+ 'HTTP_CLIENT_IP',
+ 'HTTP_X_FORWARDED_FOR',
+ 'HTTP_X_FORWARDED',
+ 'HTTP_FORWARDED_FOR',
+ 'HTTP_FORWARDED',
+ 'HTTP_X_REAL_IP',
+ 'REMOTE_ADDR'
+ );
+ foreach ($headers as $header) {
+ if (isset($_SERVER[$header]))
+ return $_SERVER[$header];
}
- return $ip;
+ return NULL;
}
/**