summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbin/compose2
-rw-r--r--build/db-init/Dockerfile3
-rw-r--r--build/init/Dockerfile3
-rw-r--r--build/nginx/Dockerfile3
-rw-r--r--build/php/Dockerfile3
-rw-r--r--build/postgres/Dockerfile3
-rw-r--r--build/postgrest/Dockerfile3
-rw-r--r--src/_base.php61
-rw-r--r--src/_model.php2
-rw-r--r--src/lib/lang.php2
10 files changed, 50 insertions, 35 deletions
diff --git a/bin/compose b/bin/compose
index f8c1796..cd63aa1 100755
--- a/bin/compose
+++ b/bin/compose
@@ -41,7 +41,7 @@ elif [[ $uid -eq 0 ]] && [[ $gid -eq 0 ]]; then
true # all set
else
# root required (1000:1000 may not exist)
- exec sudo -E $command
+ exec sudo $command
fi
# ========================================================= LOAD ENVIRONMENT ==
diff --git a/build/db-init/Dockerfile b/build/db-init/Dockerfile
index c5a4b59..7bc16ce 100644
--- a/build/db-init/Dockerfile
+++ b/build/db-init/Dockerfile
@@ -15,7 +15,8 @@
###
### You should have received a copy of the GNU General Public License
### along with CRIMSON. If not, see <http://www.gnu.org/licenses/>.
-FROM alpine:latest
+ARG ALPINE_VERSION="3.23"
+FROM alpine:${ALPINE_VERSION}
# install packages
RUN apk add --no-cache postgresql16-client tini shadow sed
diff --git a/build/init/Dockerfile b/build/init/Dockerfile
index cd2af92..176b07f 100644
--- a/build/init/Dockerfile
+++ b/build/init/Dockerfile
@@ -1,4 +1,5 @@
-FROM alpine:latest
+ARG ALPINE_VERSION="3.23"
+FROM alpine:${ALPINE_VERSION}
# install packages
RUN apk add --no-cache tini shadow coreutils findutils
diff --git a/build/nginx/Dockerfile b/build/nginx/Dockerfile
index f74d555..2094d4d 100644
--- a/build/nginx/Dockerfile
+++ b/build/nginx/Dockerfile
@@ -1,4 +1,5 @@
-FROM alpine:latest
+ARG ALPINE_VERSION="3.23"
+FROM alpine:${ALPINE_VERSION}
# install packages
RUN apk add --no-cache nginx shadow curl tini
diff --git a/build/php/Dockerfile b/build/php/Dockerfile
index 5f4bdd5..a1bc31a 100644
--- a/build/php/Dockerfile
+++ b/build/php/Dockerfile
@@ -1,4 +1,5 @@
-FROM php:fpm-alpine
+ARG ALPINE_VERSION="3.23"
+FROM php:fpm-alpine${ALPINE_VERSION}
# install packages
RUN apk add --no-cache postgresql-dev runuser shadow
diff --git a/build/postgres/Dockerfile b/build/postgres/Dockerfile
index 8223800..32d0c7e 100644
--- a/build/postgres/Dockerfile
+++ b/build/postgres/Dockerfile
@@ -1,4 +1,5 @@
-FROM postgres:16-alpine
+ARG ALPINE_VERSION="3.23"
+FROM postgres:16-alpine${ALPINE_VERSION}
# install packages
RUN apk add --no-cache make git shadow
diff --git a/build/postgrest/Dockerfile b/build/postgrest/Dockerfile
index 747052f..eb281d1 100644
--- a/build/postgrest/Dockerfile
+++ b/build/postgrest/Dockerfile
@@ -1,4 +1,5 @@
-FROM alpine:latest
+ARG ALPINE_VERSION="3.23"
+FROM alpine:${ALPINE_VERSION}
# install packages
RUN apk add --no-cache tini wget curl shadow
diff --git a/src/_base.php b/src/_base.php
index d53905d..e029130 100644
--- a/src/_base.php
+++ b/src/_base.php
@@ -35,7 +35,7 @@ abstract class Base {
* @param string $dir - the directory theese objects are stored in
* @param string $type - the type of the object
*/
- private function load_type($name, $dir, $type): object|NULL
+ private static function load_type($name, $dir, $type): object|NULL
{
$path = $dir . '/' . $name . '.php';
@@ -71,20 +71,20 @@ abstract class Base {
* Loads a model
* @param string $name - the name of the model to load
*/
- public function load_model($name): Model|NULL
+ public static function load_model($name): Model|NULL
{
$dir = WEB_ROOT . '/_model';
- return $this->load_type($name, $dir, 'model');
+ return self::load_type($name, $dir, 'model');
}
/**
* Loads a controller
* @param string $name - the name of the controller to load
*/
- public function load_controller($name): Controller|NULL
+ public static function load_controller($name): Controller|NULL
{
$dir = WEB_ROOT . '/_controller';
- return $this->load_type($name, $dir, 'controller');
+ return self::load_type($name, $dir, 'controller');
}
// ==================================================================== LANG ==
@@ -96,7 +96,7 @@ abstract class Base {
/**
* Loads a php lang file into the lang array
*/
- private function load_lang_file(string $file): void
+ private static function load_lang_file(string $file): void
{
if (isset(self::$loaded[$file]))
return;
@@ -110,13 +110,13 @@ abstract class Base {
/**
* Loads each php file lang strings in a directory
*/
- private function load_lang_dir(string $dir): void
+ private static function load_lang_dir(string $dir): void
{
if ($handle = opendir($dir)) {
while (false !== ($entry = readdir($handle))) {
if ($entry === '.' || $entry === '..')
continue;
- $this->load_lang_file($entry);
+ self::load_lang_file($entry);
}
}
}
@@ -124,7 +124,7 @@ abstract class Base {
/**
* Loads the given common lang
*/
- public function load_lang(string ...$langs): array
+ public static function load_lang(string ...$langs): array
{
$root = WEB_ROOT . '/lang';
@@ -133,9 +133,9 @@ abstract class Base {
$dir = "{$root}/{$lang}";
if (file_exists($file))
- $this->load_lang_file($file);
+ self::load_lang_file($file);
else if (is_dir($dir))
- $this->load_lang_dir($dir);
+ self::load_lang_dir($dir);
}
@@ -145,7 +145,7 @@ abstract class Base {
/**
* Returns the currently loaded lang
*/
- public function get_lang(): array
+ public static function get_lang(): array
{
return self::$loaded_lang;
}
@@ -158,7 +158,7 @@ abstract class Base {
/**
* Loads the database
*/
- public function db(): DatabaseHelper
+ public static function db(): DatabaseHelper
{
if (!self::$db)
self::$db = new DatabaseHelper();
@@ -171,7 +171,7 @@ abstract class Base {
* Gets the stamp for a asset path
* @param string $path
*/
- public function asset_stamp(string $path): int
+ public static function asset_stamp(string $path): int
{
if (ENVIRONMENT == 'development')
return time();
@@ -185,7 +185,7 @@ abstract class Base {
* @param string $path
* @param bool $timestamp
*/
- public function get_url(string $path, bool $timestamp = FALSE): string
+ public static function get_url(string $path, bool $timestamp = FALSE): string
{
$scheme = 'http';
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']))
@@ -205,7 +205,7 @@ abstract class Base {
$base = CONFIG['base_path'];
$url = "{$scheme}://{$host}{$base}{$path}";
if ($timestamp) {
- $time = $this->asset_stamp($path);
+ $time = self::asset_stamp($path);
$url .= "?timestamp={$time}";
}
return $url;
@@ -215,10 +215,10 @@ abstract class Base {
* Loads a js html link
* @param string $path - the path to the js file
*/
- public function link_js(string $path): string
+ public static function link_js(string $path): string
{
- $stamp = $this->asset_stamp("public/$path");
- $href = $this->get_url("public/{$path}?timestamp={$stamp}");
+ $stamp = self::asset_stamp("public/$path");
+ $href = self::get_url("public/{$path}?timestamp={$stamp}");
return '<script src="'. $href .'"></script>';
}
@@ -226,10 +226,10 @@ abstract class Base {
* Loads a css html link
* @param string $path - the path to the css file
*/
- public function link_css(string $path): string
+ public static function link_css(string $path): string
{
- $stamp = $this->asset_stamp("public/$path");
- $href = $this->get_url("public/{$path}?timestamp={$stamp}");
+ $stamp = self::asset_stamp("public/$path");
+ $href = self::get_url("public/{$path}?timestamp={$stamp}");
return '<link rel="stylesheet" href="'. $href .'">';
}
@@ -237,7 +237,7 @@ abstract class Base {
* Loads a css html link
* @param string $path - the path to the css file
*/
- public function embed_css(string $path): string
+ public static function embed_css(string $path): string
{
$file = PUBLIC_ROOT . '/' . $path;
if (file_exists($file)) {
@@ -248,6 +248,15 @@ abstract class Base {
}
}
+ /**
+ * Formats a ISO date
+ * @param $iso_date the ISO date
+ */
+ public function format_date(string $iso_date): string
+ {
+ return date("Y-m-d D H:i", strtotime($iso_date));
+ }
+
// =============================================================== HTTP POST ==
/**
@@ -255,7 +264,7 @@ abstract class Base {
* php://input if AJAX. Returns FALSE if input is not a post request,
* or NULL if unable to parse request body.
*/
- private function get_post_data()
+ private static function get_post_data()
{
static $data = NULL;
@@ -290,9 +299,9 @@ abstract class Base {
* @returns FALSE if request is POST but has invalid body.
* @returns NULL if request is not POST.
*/
- public function post_data(?string $key = NULL)
+ public static function post_data(?string $key = NULL)
{
- $data = $this->get_post_data();
+ $data = self::get_post_data();
if (!$data)
return $data;
diff --git a/src/_model.php b/src/_model.php
index ce8dd82..ecd63df 100644
--- a/src/_model.php
+++ b/src/_model.php
@@ -44,7 +44,7 @@ abstract class Model extends Base {
// sanity check
assert(is_string($app));
} catch (Exception $_e) {
- $app = CONTEXT['app'];
+ $app = ROUTER->req['app'];
}
$data['css'] = $this->flatten_array([
diff --git a/src/lib/lang.php b/src/lib/lang.php
index 6be65e1..be04dce 100644
--- a/src/lib/lang.php
+++ b/src/lib/lang.php
@@ -28,7 +28,7 @@ function lang(
string $key,
?string $default = NULL,
?array $sub = NULL
-): string {
+): string|array {
$lang = ROUTER->get_lang();
$result = NULL;