Skip to content

armgit / Vvveb

Public Imported from GitHub
0

Powerful and easy to use cms to build websites, blogs or ecommerce stores.

Install defaults from env or get parameters, changed docker configuration to pass database settings to env for easier installation, page cache support for docker nginx, option for database port.

givanzc49af3ea38cd
diff --git a/.dockerignore b/.dockerignore
index 6f01688..2fa34ba 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -1,2 +1,3 @@
*
!php.ini
+!docker-entrypoint.sh
diff --git a/Dockerfile b/Dockerfile
index fa07ad7..9f90910 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,4 +1,4 @@
-FROM php:8.2-fpm
+FROM php:8.3-fpm
RUN apt-get clean && apt-get update
@@ -12,9 +12,14 @@ RUN apt-get install -y \
libonig-dev \
libcurl4-openssl-dev \
&& docker-php-ext-configure gd --with-webp --with-jpeg\
- && docker-php-ext-install -j$(nproc) gd \
+ && docker-php-ext-install -j$(nproc) gd\
&& docker-php-ext-install xml dom curl mbstring intl gettext\
&& docker-php-ext-install zip\
+ && pecl bundle -d /usr/src/php/ext apcu\
+ && docker-php-ext-install /usr/src/php/ext/apcu\
+# && docker-php-ext-install sqlite3\
&& docker-php-ext-install mysqli
COPY php.ini ${PHP_INI_DIR}
+COPY docker-entrypoint.sh /entrypoint.sh
+ENTRYPOINT ["/entrypoint.sh"]
diff --git a/Dockerfile-apache b/Dockerfile-apache
index 738cd61..2149a8c 100644
--- a/Dockerfile-apache
+++ b/Dockerfile-apache
@@ -1,4 +1,4 @@
-FROM php:8.2.11-apache
+FROM php:8.3-apache
ARG DOWNLOAD_URL
@@ -30,6 +30,8 @@ RUN apt-get install -y \
&& docker-php-ext-install -j$(nproc) gd \
&& docker-php-ext-install xml dom curl mbstring intl gettext\
&& docker-php-ext-install zip\
+ && pecl bundle -d /usr/src/php/ext apcu\
+ && docker-php-ext-install /usr/src/php/ext/apcu\
&& docker-php-ext-install mysqli
@@ -69,6 +71,10 @@ RUN chmod -R 666 ${DIR_CACHE}
RUN chmod -R 666 ${DIR_DIGITAL_ASSETS}
RUN chmod -R 666 ${DIR_IMAGE_CACHE}
+COPY php.ini ${PHP_INI_DIR}
+COPY docker-entrypoint.sh /entrypoint.sh
+ENTRYPOINT ["/entrypoint.sh"]
+
EXPOSE 80
#CMD ["apachectl", "-D", "FOREGROUND"]
CMD ["apache2-foreground"]
diff --git a/docker-compose.yaml b/docker-compose.yaml
index d23e9f8..7da7fbb 100755
--- a/docker-compose.yaml
+++ b/docker-compose.yaml
@@ -19,8 +19,18 @@ services:
build:
context: .
dockerfile: Dockerfile
+ environment:
+ VVVEB_HOST: db
+ VVVEB_PASSWORD: vvveb
+ DB_HOST: db
+ DB_DATABASE: vvveb
+ DB_USER: vvveb
+ DB_PASSWORD: vvveb
+ DB_ENGINE: mysqli
volumes:
- ./:/var/www/html/
+ links:
+ - db:mysql
depends_on:
- db
networks:
diff --git a/install/controller/index.php b/install/controller/index.php
index e1e7959..8b48cf0 100755
--- a/install/controller/index.php
+++ b/install/controller/index.php
@@ -43,6 +43,8 @@ define('DEFAULT_LANG', 'en_US');
#[\AllowDynamicProperties]
class Index extends Base {
+ private $config = ['engine' => 'mysqli', 'host' => '127.0.0.1', 'database' => 'vvveb', 'user' => 'root', 'password' => '', 'port' => null, 'prefix' => ''];
+
function __construct() {
if (! ($lang = session('language'))) {
$lang = userPreferedLanguage();
@@ -116,8 +118,8 @@ class Index extends Base {
clearstatcache(true, $configFile);
}
- function import($noimport = false) {
- $config = ['engine' => '', 'host' => '', 'database' => '', 'user' => '', 'password' => '', 'prefix' => ''];
+ private function import($noimport = false) {
+ $config = $this->config;
array_walk($this->request->post, function ($value, $key) use (&$config) {
if (isset($config[$key])) {
@@ -140,16 +142,16 @@ class Index extends Base {
try {
if (! defined('DB_ENGINE')) {
define('DB_ENGINE', $engine);
- define('DB_HOST', $host);
- define('DB_USER', $user);
- define('DB_PASS', $password);
- define('DB_NAME', $database);
+ define('DB_HOST', $host);
+ define('DB_USER', $user);
+ define('DB_PASS', $password);
+ define('DB_NAME', $database);
define('DB_PREFIX', $prefix);
- define('DB_CHARSET', 'utf8mb4');
- define('DIR_SQL', DIR_APP . 'sql/' . DB_ENGINE . '/');
+ define('DB_PORT', $port);
+ define('DIR_SQL', DIR_APP . 'sql/' . DB_ENGINE . '/');
}
- $import = new \Vvveb\System\Import\Sql($engine, $host, $database, $user, $password, $prefix);
+ $import = new \Vvveb\System\Import\Sql($engine, $host, $database, $user, $password, $port, $prefix);
//$import->createDb($database);
if ($engine == 'mysqli') {
$import->createDb($database);
@@ -184,6 +186,19 @@ class Index extends Base {
\Vvveb\System\CacheManager::clearFrontend();
+ //get defaults from get parameters if passed or from env if available
+ foreach ($this->config as $key => &$value) {
+ $env = 'DB_' . strtoupper($key);
+
+ if (isset($_ENV[$env])) {
+ $value = $_ENV[$env];
+ }
+
+ if (isset($this->request->get[$key])) {
+ $value = $this->request->get[$key];
+ }
+ }
+
if ($this->request->post) {
if (isset($this->request->post['language'])) {
$lang = $this->request->post['language'];
@@ -198,9 +213,10 @@ class Index extends Base {
}
}
- $installedLanguages = [DEFAULT_LANG => '0'] + array_flip(installedLanguages());
- $languagesList = include DIR_SYSTEM . 'data/languages-list.php';
- $languages = array_intersect_key($languagesList, $installedLanguages);
+ $installedLanguages = [DEFAULT_LANG => '0'] + array_flip(installedLanguages());
+ $languagesList = include DIR_SYSTEM . 'data/languages-list.php';
+ $languages = array_intersect_key($languagesList, $installedLanguages);
+ $this->view->config = $this->config;
if (! defined('CLI')) {
$this->view->languagesList = $languages;
@@ -259,7 +275,7 @@ class Index extends Base {
$site = [
'host' => $hostname ?? '*.*.*', //$_SERVER['HTTP_HOST']
- 'id' => 1,
+ 'id' => 1,
'name' => 'Default',
'theme' => $theme,
'settings' => json_encode($settings),
@@ -318,6 +334,11 @@ class Index extends Base {
@\Vvveb\set_config('app.cronkey', Str::random(32));
@\Vvveb\set_config('app.key', Str::random(32));
+ //set APCu memory cache if available instead of default file cache
+ if (function_exists('apcu_cache_info') && ini_get('apc.enabled')) {
+ @\Vvveb\set_config('app.cache.driver', 'APCu');
+ }
+
$success = __('Installation succesful!');
$this->view->success[] = $success;
$admin_path = \Vvveb\adminPath();
diff --git a/install/template/common.tpl b/install/template/common.tpl
index 8f63383..03fcc6b 100755
--- a/install/template/common.tpl
+++ b/install/template/common.tpl
@@ -1,18 +1,3 @@
-//example class="copy_from_index.html"
-.copy_from*|outerHTML = from(@@__class:copy_from:([^\,]+)__@@|@@__class:copy_from:[^\,]+\,([^\,]+)__@@)
-
-
-/* modifiers */
-.capitalize|register_filter = <?php ucfirst($content, $arg1, $arg2);?>
-
-
-.if_*|after = <?php } ?>
-
-.if_*|before =
-<?php if (@@macro if('@@__class__@@')@@) {?>
-
-[class*=":if_"]|addClass = <?php @@macro class_if('@@__class__@@')@@?>
-
/*body|prepend = <?php var_dump($this);?>*/
head base|href = <?php echo Vvveb\themeUrlPath()?>;
@@ -20,23 +5,29 @@ head base|href = <?php echo Vvveb\themeUrlPath()?>;
input[type="text"]|value =
<?php
- if (isset($_POST['@@__name__@@']))
+ if (isset($_POST['@@__name__@@']))
echo $_POST['@@__name__@@'];
+ else if (isset($this->config['@@__name__@@']))
+ echo $this->config['@@__name__@@'];
else echo '@@__value__@@';
?>
input[type="password"]|value =
<?php
- if (isset($_POST['@@__name__@@']))
- echo $_POST['@@__name__@@'];
- else echo '@@__value__@@';
+ if (isset($_POST['@@__name__@@']))
+ echo $_POST['@@__name__@@'];
+ else if (isset($this->config['@@__name__@@']))
+ echo $this->config['@@__name__@@'];
+ else echo '@@__value__@@';
?>
input[type="email"]|value =
<?php
- if (isset($_POST['@@__name__@@']))
+ if (isset($_POST['@@__name__@@']))
echo $_POST['@@__name__@@'];
+ else if (isset($this->config['@@__name__@@']))
+ echo $this->config['@@__name__@@'];
else echo '@@__value__@@';
?>
@@ -45,7 +36,9 @@ input[type="checkbox"]|value =
<?php
if (isset($_POST['@@__name__@@']))
echo $_POST['@@__name__@@'];
- else echo '@@__value__@@';
+ else if (isset($this->config['@@__name__@@']))
+ echo $this->config['@@__name__@@'];
+ else echo '@@__value__@@';
?>
/*
@@ -101,4 +94,4 @@ if (isset($this->message)) foreach($this->message as $message) {?>
@message|after = <?php
}
-?>
\ No newline at end of file
+?>
diff --git a/nginx-docker.conf b/nginx-docker.conf
index b5b9ac3..e7db193 100644
--- a/nginx-docker.conf
+++ b/nginx-docker.conf
@@ -4,18 +4,63 @@ server {
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
- root /var/www/html;
+ root /var/www/html/public;
index index.php index.html;
error_page 404 /index.php;
+
+ set $skip_cache 0;
+ set $cache_uri $request_uri;
+
+
+ if ($query_string != "") {
+ set $skip_cache 1;
+ set $cache_uri null;
+ }
+
+ # Don't cache uris containing the following segments
+ if ($request_uri ~* "/admin/|/user/|/cart/|/feed/|index.php|sitemap(_index)?.xml") {
+ set $skip_cache 1;
+ set $cache_uri null;
+ }
+
+ # Don't use the cache for logged in users or if products in cart
+ if ($http_cookie ~* "nocache|cart|user") {
+ set $skip_cache 1;
+ set $cache_uri null;
+ }
+ # POST requests and urls with a query string should always go to PHP
+ if ($request_method = POST) {
+ set $skip_cache 1;
+ set $cache_uri null;
+ }
+
+ #static files
+ location ~* "\.(?!php)([\w]{3,4})$" {
+ expires max;
+ log_not_found off;
+ sendfile on;
+ sendfile_max_chunk 1m;
+ fastcgi_hide_header "Set-Cookie";
+
+ try_files $uri =404;
+ }
+
location / {
- try_files $uri $uri/ /index.php?$query_string;
+ default_type text/html;
+ index index.php index.html index.htm;
+ try_files /page-cache/$http_host$cache_uri /page-cache/$http_host$cache_uri/index.html $uri $uri/ /index.php$is_args$args;
+ #try_files $uri $uri/ /index.php$is_args$args;
+
+ #cache debug
+ #add_header "uri" $cache_uri;
}
location ~ \.php$ {
# try_files $uri =404;
+ #fastcgi_pass unix:/var/run/php-fpm83/php-fpm.pid;
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
diff --git a/nginx-live.conf b/nginx-live.conf
index 19452a2..f4d2cc7 100755
--- a/nginx-live.conf
+++ b/nginx-live.conf
@@ -1,9 +1,11 @@
#replace /var/www/vvveb/public with your vvveb website public folder and set server_name for your domain
-#copy this file to /etc/nginx/sites-available/vvveb
+#copy this file to /etc/nginx/sites-available/vvveb
#sudo ln -s /etc/nginx/sites-available/vvveb /etc/nginx/sites-enabled/vvveb
+# or for apline linux /etc/nginx/httpd.d/default.conf
upstream php {
- server unix:/run/php/php-fpm.sock;
+ server unix:/var/run/php/php-fpm.sock;
+ #server unix:/var/run/php-fpm82/php-fpm.pid;#alpine
#server 127.0.0.1:9000;
}
@@ -14,6 +16,7 @@ upstream php81 {
upstream php82 {
server unix:/var/run/php/php8.2-fpm.sock;
+ server unix:/var/run/php-fpm82.pid;#alpine
#server 127.0.0.1:9000;
}
@@ -33,7 +36,7 @@ server {
#always use public folder as root for security
root /var/www/vvveb/public;
#replace vvveb.net with your domain
- server_name *.vvveb.net vvveb.net;
+ #server_name *.vvveb.net vvveb.net;
#listen 80 server;
#listen [::]:80 server;
@@ -77,7 +80,7 @@ server {
}
# Don't use the cache for logged in users or recent commenters
- if ($http_cookie ~* "nocache") {
+ if ($http_cookie ~* "nocache|user|cart") {
set $skip_cache 1;
set $cache_uri null;
}
@@ -98,12 +101,15 @@ server {
log_not_found off;
sendfile on;
sendfile_max_chunk 1m;
+ fastcgi_hide_header "Set-Cookie";
try_files $uri =404;
}
location / {
default_type text/html;
+ index index.php;
+
try_files /page-cache/$http_host$cache_uri /page-cache/$http_host$cache_uri/index.html $uri $uri/ /index.php?$args;
#try_files $uri $uri/ /index.php?$args;
@@ -115,16 +121,11 @@ server {
location ~ /media/.+?\.php$ {
deny all;
}
-
- location ~* ^.+\.(ogg|ogv|svg|svgz|swf|eot|otf|woff|woff2|mov|mp3|mp4|webm|flv|ttf|rss|atom|jpg|jpeg|gif|png|webp|ico|bmp|mid|midi|wav|rtf|css|js|jar)$ {
- expires 30d;
- fastcgi_hide_header "Set-Cookie";
- }
-
+
location ~ \.php$ {
- #fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
+ #fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
#fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
- fastcgi_pass php82;
+ fastcgi_pass php;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
diff --git a/system/core/startup.php b/system/core/startup.php
index bf84277..4ca9b87 100755
--- a/system/core/startup.php
+++ b/system/core/startup.php
@@ -309,12 +309,12 @@ $connection = \Vvveb\config('db.connections.' . $dbDefault, []);
if ($connection) {
// Define default database configuration
define('DB_ENGINE', $connection['engine']);
- define('DB_HOST', $connection['host'] ?? '');
- define('DB_USER', $connection['user'] ?? '');
- define('DB_PASS', $connection['password'] ?? '');
- define('DB_NAME', $connection['database'] ?? '');
+ define('DB_HOST', $connection['host'] ?? '');
+ define('DB_USER', $connection['user'] ?? '');
+ define('DB_PASS', $connection['password'] ?? '');
+ define('DB_NAME', $connection['database'] ?? '');
define('DB_PREFIX', $connection['prefix'] ?? '');
- define('DB_CHARSET', 'utf8mb4');
+ define('DB_PORT', $connection['port'] ?? null);
} else {/*
define('DB_ENGINE', 'mysqli');
define('DB_HOST', 'localhost');
@@ -322,7 +322,6 @@ if ($connection) {
define('DB_PASS', '');
define('DB_NAME', 'vvveb');
define('DB_PREFIX', '');
- define('DB_CHARSET', 'utf8mb4');
*/
}
diff --git a/system/db/mysqli.php b/system/db/mysqli.php
index d601982..f541aff 100755
--- a/system/db/mysqli.php
+++ b/system/db/mysqli.php
@@ -24,10 +24,6 @@ namespace Vvveb\System\Db;
use Vvveb\System\Event;
-//ini_set('mysql.trace_mode', '0');
-//ini_set('mysqli.trace_mode', '0');
-
-//define('SQL_ALLOW_FUNCTIONS','NOW,DATE,CURTIME');
/*
Define and use mysqli_result if native is missing
*/
@@ -127,7 +123,7 @@ class Mysqli extends DBDriver {
return $result;
}
- public function __construct($host = DB_HOST, $dbname = DB_NAME, $user = DB_USER, $pass = DB_PASS, $prefix = DB_PREFIX) {
+ public function __construct($host = DB_HOST, $dbname = DB_NAME, $user = DB_USER, $pass = DB_PASS, $port = DB_PORT, $prefix = DB_PREFIX) {
//mysqli_report(MYSQLI_REPORT_OFF);
//connect to database
if (self :: $link) {
@@ -135,10 +131,10 @@ class Mysqli extends DBDriver {
}
$this->prefix = $prefix;
- mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
+ \mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
try {
- self :: $link = new \Mysqli(/*'p:' . */$host, $user, $pass, $dbname);
+ self :: $link = new \Mysqli(/*'p:' . */$host, $user, $pass, $dbname, $port);
//self :: $link = $this;
} catch (\mysqli_sql_exception $e) {
$errorMessage = str_replace($pass,'*****', $e->getMessage());
diff --git a/system/db/pgsql.php b/system/db/pgsql.php
index 5e5e41d..3c2d288 100755
--- a/system/db/pgsql.php
+++ b/system/db/pgsql.php
@@ -73,10 +73,10 @@ class Pgsql extends DBDriver {
return $stmt;
}
- public function __construct($host = DB_HOST, $dbname = DB_NAME, $user = DB_USER, $pass = DB_PASS, $prefix = DB_PREFIX) {
+ public function __construct($host = DB_HOST, $dbname = DB_NAME, $user = DB_USER, $pass = DB_PASS, $port = DB_PORT, $prefix = DB_PREFIX) {
if (! self :: $link) {
//port 5432 for direct pgsql connection 6432 for pgbouncer
- $port = 5432;
+ $port = $port ?: 5432;
$connect_string = "host=$host port=$port dbname=$dbname user=$user password=$pass";
if (self :: $persistent) {
diff --git a/system/db/sqlite.php b/system/db/sqlite.php
index 4e947a7..78b67af 100755
--- a/system/db/sqlite.php
+++ b/system/db/sqlite.php
@@ -72,7 +72,7 @@ class Sqlite extends DBDriver {
return $result;
}
- public function __construct($filename = DB_HOST, $dbname = DB_NAME, $user = DB_USER, $pass = DB_PASS, $prefix = DB_PREFIX) {
+ public function __construct($filename = DB_HOST, $dbname = DB_NAME, $user = DB_USER, $pass = DB_PASS, $port = null, $prefix = DB_PREFIX) {
if (self :: $link) {
return self :: $link;
}
@@ -161,8 +161,8 @@ class Sqlite extends DBDriver {
}
return $return;
- }
-
+ }
+
public function fetchArray($result) {
$return = false;
@@ -171,8 +171,8 @@ class Sqlite extends DBDriver {
}
return $return;
- }
-
+ }
+
public function fetchAll($result) {
$return = [];
@@ -195,7 +195,7 @@ class Sqlite extends DBDriver {
$this->affected_rows = self :: $link->changes();
$this->insert_id = self :: $link->lastInsertRowID();
$this->num_rows = $result->numColumns() && $result->columnType(0) != SQLITE3_NULL;
- //$result->finalize();
+ //$result->finalize();
} else {
throw new \Exception($this->error(), $this->errorCode());
}
diff --git a/system/import/sql.php b/system/import/sql.php
index 33111bf..b60893b 100755
--- a/system/import/sql.php
+++ b/system/import/sql.php
@@ -22,22 +22,24 @@
namespace Vvveb\System\Import;
+use function Vvveb\globBrace;
+
#[\AllowDynamicProperties]
class Sql {
public $db;
- function __construct($driver = DB_ENGINE, $host = DB_HOST, $dbname = DB_NAME, $user = DB_USER, $pass = DB_PASS, $prefix = DB_PREFIX) {
+ function __construct($driver = DB_ENGINE, $host = DB_HOST, $dbname = DB_NAME, $user = DB_USER, $pass = DB_PASS, $port = DB_PASS, $prefix = DB_PREFIX) {
$this->sqlPath = DIR_ROOT . "install/sql/$driver/";
$engine = '\Vvveb\System\Db\\' . ucfirst($driver);
$this->prefix = $prefix;
try {
- $this->db = new $engine($host, $dbname, $user, $pass, $prefix);
+ $this->db = new $engine($host, $dbname, $user, $pass, $port, $prefix);
} catch (\Exception $e) {
//unknown database, try to create
if ($e->getCode() == 1049) {
- $this->db = new $engine($host, '', $user, $pass, $prefix);
+ $this->db = new $engine($host, '', $user, $pass, $port, $prefix);
if ($driver !== 'sqlite') {
$this->createDb($dbname);
@@ -173,7 +175,12 @@ class Sql {
$this->db->query($query , 'fts5 test module');
}
- foreach (glob($this->sqlPath . '{,**/}*.sql', GLOB_BRACE) as $filename) {
+ $glob = ['', '*/*/', '*/'];
+
+ //$files = glob($name, GLOB_BRACE);
+ $files = globBrace($this->sqlPath, ['', '**/'], '*.sql');
+
+ foreach ($files as $filename) {
$sql = file_get_contents($filename);
$filename = str_replace($this->sqlPath, '', $filename);
@@ -229,7 +236,12 @@ class Sql {
}
function insertData($filter = []) {
- foreach (glob($this->sqlPath . '{,**/}*.sql', GLOB_BRACE) as $filename) {
+ $glob = ['', '*/*/', '*/'];
+
+ //$files = glob($name, GLOB_BRACE);
+ $files = globBrace($this->sqlPath, ['', '**/'], '*.sql');
+
+ foreach ($files as $filename) {
$name = basename($filename);
if ($filter && ! in_array($name, $filter)) {
diff --git a/system/import/xml.php b/system/import/xml.php
index 7b6237b..b22a7bb 100755
--- a/system/import/xml.php
+++ b/system/import/xml.php
@@ -43,18 +43,18 @@ class Xml {
private $cDataColumns = ['content', 'excerpt', 'name', 'title', 'description', 'meta_title', 'meta_description', 'slug'];
- function __construct($driver = DB_ENGINE, $host = DB_HOST, $dbname = DB_NAME, $user = DB_USER, $pass = DB_PASS, $prefix = DB_PREFIX) {
+ function __construct($driver = DB_ENGINE, $host = DB_HOST, $dbname = DB_NAME, $user = DB_USER, $pass = DB_PASS, $port = DB_PORT, $prefix = DB_PREFIX) {
$this->sqlPath = DIR_ROOT . "install/sql/$driver/";
$engine = '\Vvveb\System\Db\\' . ucfirst($driver);
$this->prefix = $prefix;
try {
- $this->db = new $engine($host, $dbname, $user, $pass, $prefix);
+ $this->db = new $engine($host, $dbname, $user, $pass, $port, $prefix);
} catch (\Exception $e) {
//unknown database, try to create
if ($e->getCode() == 1049) {
- $this->db = new $engine($host, '', $user, $pass, $prefix);
+ $this->db = new $engine($host, '', $user, $pass, $port, $prefix);
$this->createDb($dbname);
} else {
throw($e);