aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apache/sites/nowayforward_human.conf.tpl10
-rw-r--r--constants.php13
-rw-r--r--controllers/archive.php3
-rw-r--r--controllers/meta.php2
-rw-r--r--models/database.php23
-rw-r--r--views/global/router.php2
-rw-r--r--views/list/export/index.php3
7 files changed, 37 insertions, 19 deletions
diff --git a/apache/sites/nowayforward_human.conf.tpl b/apache/sites/nowayforward_human.conf.tpl
index 059a678..7c462e2 100644
--- a/apache/sites/nowayforward_human.conf.tpl
+++ b/apache/sites/nowayforward_human.conf.tpl
@@ -9,19 +9,9 @@
</If>
</FilesMatch>
- # Database
- SetEnv SERVER ${SERVER}
- SetEnv PORT ${PORT}
- SetEnv USER ${USER}
- SetEnv PASSWORD ${PASSWORD}
- SetEnv MYSQL_UNIX_SOCKET ${MYSQL_UNIX_SOCKET}
-
# 5 minutes
TimeOut 300
- # Project
- SetEnv ARCHIVES_DIR ${ARCHIVES_DIR}
-
RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.*)
diff --git a/constants.php b/constants.php
new file mode 100644
index 0000000..267d6f7
--- /dev/null
+++ b/constants.php
@@ -0,0 +1,13 @@
+<?php
+
+$SERVER = 'localhost';
+$PORT = 3306;
+$USER = 'root';
+$PASSWORD = '';
+$DB_NAME = 'nwfh';
+
+$REPOSITORY = __DIR__;
+$ARCHIVES_DIR = $REPOSITORY . '/.archives';
+
+// ONLY FOR LINUX
+$MYSQL_UNIX_SOCKET = $REPOSITORY . '/.config/mysql/mysql.sock';
diff --git a/controllers/archive.php b/controllers/archive.php
index a3afb9f..8ef8dbf 100644
--- a/controllers/archive.php
+++ b/controllers/archive.php
@@ -10,6 +10,7 @@ use ValueError;
set_time_limit(300);
function on_post() {
+ global $ARCHIVES_DIR;
if (!array_key_exists('async', $_POST) || $_POST['async'] !== 'true') {
return;
}
@@ -19,7 +20,7 @@ function on_post() {
global $TOKEN;
$WEBSITE_CATEGORY = 'url';
- $DOWNLOADS_FOLDER = getenv('ARCHIVES_DIR');
+ $DOWNLOADS_FOLDER = $ARCHIVES_DIR;
$website_url = htmlspecialchars($_POST[$WEBSITE_CATEGORY]);
$uid = 1;
$authorized = false;
diff --git a/controllers/meta.php b/controllers/meta.php
index 46550d3..aa7a09b 100644
--- a/controllers/meta.php
+++ b/controllers/meta.php
@@ -1,5 +1,7 @@
<?php
+include_once __DIR__ . '/../constants.php';
+
function call_handler(string $name) {
if (function_exists($name)) {
call_user_func($name);
diff --git a/models/database.php b/models/database.php
index 8efd20c..1295044 100644
--- a/models/database.php
+++ b/models/database.php
@@ -3,6 +3,8 @@ namespace Database;
use PDO;
use Exception;
+include __DIR__ . '/../constants.php';
+
abstract class Table {
// Cannot be created, because FETCH_CLASS will assign to all attributes
// and then call the constructor
@@ -62,20 +64,27 @@ abstract class Table {
}
static protected function connect() : PDO {
- $unix_socket = getenv('MYSQL_UNIX_SOCKET');
+ global $SERVER;
+ global $PORT;
+ global $USER;
+ global $PASSWORD;
+ global $DB_NAME;
+ global $MYSQL_UNIX_SOCKET;
+
+ $unix_socket = $MYSQL_UNIX_SOCKET;
$conn = null;
// Windows support
if ($unix_socket == '') {
$conn = new PDO(
- "mysql:host=" . getenv('SERVER') . ";port=" . getenv('PORT') . ";dbname=nwfh",
- getenv('USER'),
- getenv('PASSWORD'));
+ "mysql:host=" . $SERVER . ";port=" . $PORT . ";dbname=" . $DB_NAME,
+ $USER,
+ $PASSWORD);
}
else {
$conn = new PDO(
- "mysql:unix_socket=$unix_socket;dbname=nwfh",
- getenv('USER'),
- getenv('PASSWORD'));
+ "mysql:unix_socket=$unix_socket;dbname=" . $DB_NAME,
+ $USER,
+ $PASSWORD);
}
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
diff --git a/views/global/router.php b/views/global/router.php
index ab3a0be..894af6b 100644
--- a/views/global/router.php
+++ b/views/global/router.php
@@ -1,5 +1,7 @@
<?php
+include __DIR__ . '/../../constants.php';
+
$VIEWS_DIR = __DIR__ . '/..';
$CONTROLLERS_DIR = __DIR__ . '/../../controllers';
$MODELS_DIR = __DIR__ . '/../../models';
diff --git a/views/list/export/index.php b/views/list/export/index.php
index fc8630b..e38be24 100644
--- a/views/list/export/index.php
+++ b/views/list/export/index.php
@@ -11,10 +11,11 @@
catch (Exception $e) {}
function createWithDOMPDF() {
+ global $ARCHIVES_DIR;
$url = $_GET['url'];
$title = $_GET['title'];
$wid = $_GET['wid'];
- $archive_dir = getenv('ARCHIVES_DIR') . '/' . $wid;
+ $archive_dir = $ARCHIVES_DIR . '/' . $wid;
$html = file_get_contents($archive_dir . '/index.php');
$dompdf = new Dompdf();