Skip to content

armgit / Vvveb

Public Imported from GitHub
0

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

Languages code refactor

givanza7955a6e6a8c
diff --git a/admin/component/languages.php b/admin/component/languages.php
index 2459e3e..d7ceb91 100644
--- a/admin/component/languages.php
+++ b/admin/component/languages.php
@@ -22,9 +22,9 @@
namespace Vvveb\Component;
-use function Vvveb\availableLanguages;
use Vvveb\System\Component\ComponentBase;
use Vvveb\System\Event;
+use Vvveb\System\Locale;
class Languages extends ComponentBase {
public static $defaultOptions = [
@@ -44,7 +44,7 @@ class Languages extends ComponentBase {
function results() {
$results = [];
- $results['language'] = availableLanguages();
+ $results['language'] = Locale::availableLanguages();
if ($results['language']) {
$results['current'] = $code = self :: $global['language'];
diff --git a/admin/controller/base.php b/admin/controller/base.php
index 7bc2760..9a0a801 100755
--- a/admin/controller/base.php
+++ b/admin/controller/base.php
@@ -24,11 +24,7 @@ namespace Vvveb\Controller;
use function Vvveb\__;
use function Vvveb\arrayInsertArrayAfter;
-use function Vvveb\availableCurrencies;
-use function Vvveb\availableLanguages;
-use function Vvveb\clearLanguageCache;
use function Vvveb\filter;
-use function Vvveb\setLanguage;
use Vvveb\Sql\taxonomySQL;
use Vvveb\System\Cache;
use Vvveb\System\CacheManager;
@@ -39,6 +35,7 @@ use Vvveb\System\Event;
use Vvveb\System\Extensions\Plugins;
use Vvveb\System\Functions\Str;
use Vvveb\System\Images;
+use Vvveb\System\Locale;
use Vvveb\System\PageCache;
use Vvveb\System\Session;
use Vvveb\System\Sites;
@@ -72,6 +69,7 @@ class Base {
$this->session->set('site_url', $site['url']);
$this->session->set('site', $site['site_id']);
$this->session->set('host', $site['host']);
+ $this->session->set('path', $site['path'] ?? '');
$this->session->set('state', $site['state'] ?? 'live');
return $site['site_id'];
@@ -223,7 +221,7 @@ class Base {
}
protected function language($defaultLanguage = false, $defaultLanguageId = false, $defaultLocale = false, $defaultCode = false, $languages = null) {
- $languages = $languages ?? availableLanguages();
+ $languages = $languages ?? Locale::availableLanguages();
$default_language = $this->session->get('default_language');
$default_language_id = $this->session->get('default_language_id');
@@ -242,7 +240,7 @@ class Base {
$this->session->set('code', $languages[$language]['code']);
$this->session->set('rtl', $languages[$language]['rtl'] ?? false);
$default_language = false; //recheck default language
- clearLanguageCache($language);
+ Locale::clearLanguageCache($language);
}
}
@@ -343,7 +341,7 @@ class Base {
$this->session->set('rtl', $rtl);
}
- setLanguage($code);
+ Locale::setLanguage($code);
if (! defined('CLI')) {
$view = $this->view;
@@ -354,7 +352,7 @@ class Base {
protected function currency($defaultCurrency = false, $defaultCurrencyId = false) {
if (($currency = ($this->request->post['currency'] ?? false)) && ! is_array($currency)) {
$currency = filter('/[A-Za-z_-]+/', $currency, 50);
- $currencies = availableCurrencies();
+ $currencies = Locale::availableCurrencies();
if (isset($currencies[$currency])) {
$this->session->set('currency_id', $currencies[$currency]['currency_id']);
@@ -368,7 +366,7 @@ class Base {
$currency_id = $this->session->get('currency_id');
if (! $currency || ! $currency_id) {
- $currencies = availableCurrencies();
+ $currencies = Locale::availableCurrencies();
if ($currencies) {
foreach ($currencies as $code => $c) {
@@ -429,7 +427,10 @@ class Base {
return $this->requireLogin();
}
- if (!$this->checkCsrf()) {
+ //$className = get_class($this);
+ //$errorController = (strncmp($className, 'Vvveb\Controller\Error', 22) === 0);
+
+ if (/*!$errorController && */! $this->checkCsrf()) {
return;
}
@@ -460,11 +461,12 @@ class Base {
}
}
- $page = $this->request->get['page'] ?? 1;
- $limit = $this->request->get['limit'] ?? 10;
+ $page = $this->request->get['page'] ?? 1 ?: 1;
+ $limit = $this->request->get['limit'] ?? 10 ?: 10;
$this->global['site_id'] = $site_id;
$this->global['host'] = $this->session->get('host');
+ $this->global['path'] = $this->session->get('path');
$this->global['site_url'] = $this->session->get('site_url');
$this->global['admin_id'] = $admin['admin_id'];
$this->global['state'] = $state;
@@ -473,12 +475,10 @@ class Base {
$this->global['limit'] = $limit;
//Check permissions
- $className = get_class($this);
-
- if ($className != 'Vvveb\Controller\Error403') {
- $this->permission();
- $this->setPermissions();
- }
+ //if (!$errorController) {
+ $this->permission();
+ $this->setPermissions();
+ //}
//load plugins for active site if safe mode is not selected
if (! isset($admin['safemode']) || ! $admin['safemode']) {
@@ -597,7 +597,7 @@ class Base {
$this->notFound('Invalid csrf!', 403);
return false;
}
-
+
return true;
}
@@ -609,7 +609,7 @@ class Base {
* @param mixed $service
* @param mixed $message
*/
- protected function notFound($message = false, $statusCode = 404, $service = true) {
+ protected function notFound($message = false, $statusCode = 404, $service = false) {
return FrontController::notFound($service, $message, $statusCode);
}
diff --git a/admin/controller/content/posts.php b/admin/controller/content/posts.php
index 98b3221..2056d98 100755
--- a/admin/controller/content/posts.php
+++ b/admin/controller/content/posts.php
@@ -28,6 +28,7 @@ use function Vvveb\humanReadable;
use Vvveb\Sql\PostSQL;
use Vvveb\System\Cache;
use Vvveb\System\Images;
+use Vvveb\System\locale;
use Vvveb\System\User\Admin;
use function Vvveb\url;
@@ -136,7 +137,7 @@ class Posts extends Listing {
if (class_exists('\IntlDateFormatter')) {
$dt = new \DateTime();
- $df = new \IntlDateFormatter(\Vvveb\getLanguage(), \IntlDateFormatter::NONE, \IntlDateFormatter::NONE, NULL, NULL, 'MMMM');
+ $df = new \IntlDateFormatter(Locale::getLanguage(), \IntlDateFormatter::NONE, \IntlDateFormatter::NONE, NULL, NULL, 'MMMM');
}
foreach ($archives['archives'] as $index => &$archive) {
@@ -217,6 +218,14 @@ class Posts extends Listing {
$options['admin_id'] = $this->filter['admin_id'];
}
+ if (isset($this->request->get['filter']['site_id'])) {
+ if ($this->request->get['filter']['site_id']) {
+ //$options['site_id'] = $this->filter['site_id'];
+ } else {
+ unset($options['site_id']);
+ }
+ }
+
if (isset($this->filter['archives']) && $this->filter['archives']) {
$archives = explode('/', $this->filter['archives']);
$options['year'] = $archives[0];
@@ -245,7 +254,7 @@ class Posts extends Listing {
$post['admin-url'] = url(['module' => 'content/posts']) . '&filter[admin_id_text]=' . $post['username'] . ' &filter[admin_id]=' . $post['admin_id'];
$post['delete-url'] = url(['module' => 'content/posts', 'action' => 'delete'] + $url); // + ['post_id[]' => $post['post_id']]);
$post['duplicate-url'] = url(['module' => 'content/posts', 'action' => 'duplicate'] + $url); // + ['post_id' => $post['post_id']]);
- $post['view-url'] = url("content/{$this->type}/index", $post + $url + ['host' => $this->global['host']]);
+ $post['view-url'] = url("content/{$this->type}/index", $post + $url + ['host' => $this->global['host'], 'path' => $this->global['path'] ? '/' . $this->global['path'] : null]);
$relativeUrl = url("content/{$this->type}/index", $post + $url);
$post['design-url'] = url(['module' => 'editor/editor', 'name' => urlencode($post['name'] ?? ''), 'url' => $relativeUrl, 'template' => $template], false);
}
@@ -259,7 +268,7 @@ class Posts extends Listing {
}, 259200);
$view->set($results);
- $view->status = ['publish' => 'Publish', 'pending' => 'Pending', 'draft' => 'Draft', 'private' => 'Private', 'password' => 'Password'];
+ $view->status = ['publish' => __('Publish'), 'pending' => __('Pending'), 'draft' => __('Draft'), 'private' => __('Private'), 'password' => __('Password'), 'scheduled' => __('Scheduled')];
$view->archives = $archives;
$view->filter = $this->filter;
$view->limit = $options['limit'];
diff --git a/admin/controller/editor/translate.php b/admin/controller/editor/translate.php
index bb24b20..4572dca 100644
--- a/admin/controller/editor/translate.php
+++ b/admin/controller/editor/translate.php
@@ -24,24 +24,25 @@ namespace Vvveb\Controller\Editor;
use function Vvveb\__;
use Vvveb\Controller\Base;
+use Vvveb\System\Locale;
class Translate extends Base {
function get() {
$text = $this->request->post['text'];
- $languages = \Vvveb\availableLanguages();
+ $languages = Locale::availableLanguages();
$translations = [];
- $defaultLang = \Vvveb\getLanguage();
+ $defaultLang = Locale::getLanguage();
foreach ($languages as $lang) {
$code = $lang['code'];
- \Vvveb\setLanguage($code);
- \Vvveb\setLanguageCode($code);
+ Locale :: setLanguage($code);
+ Locale :: setLanguageCode($code);
$translations[$code] = __($text, false, false, true);
}
//restore language
- \Vvveb\setLanguage($defaultLang);
- \Vvveb\setLanguageCode($defaultLang);
+ Locale :: setLanguage($defaultLang);
+ Locale :: setLanguageCode($defaultLang);
$this->response->setType('json');
$this->response->output($translations);
diff --git a/admin/controller/localization/language.php b/admin/controller/localization/language.php
old mode 100755
new mode 100644
index 031e1b2..64e35e8
--- a/admin/controller/localization/language.php
+++ b/admin/controller/localization/language.php
@@ -26,9 +26,9 @@ use function Vvveb\__;
use Vvveb\Controller\Crud;
use function Vvveb\download;
use function Vvveb\filter;
-use function Vvveb\installedLanguages;
use function Vvveb\model;
use Vvveb\System\CacheManager;
+use Vvveb\System\Locale;
class Language extends Crud {
protected $type = 'language';
@@ -107,7 +107,7 @@ class Language extends Crud {
function index() {
parent::index();
$languageList = include DIR_SYSTEM . 'data' . DS . 'languages-list.php';
- $installed = installedLanguages();
+ $installed = Locale :: installedLanguages();
foreach ($installed as $l) {
$languageList[$l]['installed'] = true;
diff --git a/admin/controller/user/login.php b/admin/controller/user/login.php
index 066d34f..e7e8d5d 100755
--- a/admin/controller/user/login.php
+++ b/admin/controller/user/login.php
@@ -24,12 +24,11 @@ namespace Vvveb\Controller\User;
use \Vvveb\System\Functions\Str;
use function Vvveb\__;
-use function Vvveb\availableLanguages;
use function Vvveb\pregMatch;
-use function Vvveb\setLanguage;
use Vvveb\Sql\Admin_Failed_LoginSQL;
use Vvveb\System\Event;
use Vvveb\System\Extensions\Plugins;
+use Vvveb\System\Locale;
use Vvveb\System\User\Admin;
use Vvveb\System\Validator;
@@ -43,7 +42,7 @@ class Login {
protected function language() {
$default_rtl = false;
if (! ($default_code = $this->session->get('code'))) {
- $languages = availableLanguages();
+ $languages = Locale::availableLanguages();
foreach ($languages as $code => $lang) {
//set global default language
@@ -60,7 +59,7 @@ class Login {
} else {
}
- setLanguage($default_code);
+ Locale :: setLanguage($default_code);
$this->global['code'] = $default_code;
$this->global['rtl'] = $default_rtl;
}
diff --git a/admin/controller/user/reset.php b/admin/controller/user/reset.php
index 34f1823..27a0f75 100755
--- a/admin/controller/user/reset.php
+++ b/admin/controller/user/reset.php
@@ -24,7 +24,6 @@ namespace Vvveb\Controller\User;
use function Vvveb\__;
use function Vvveb\email;
-use function Vvveb\setLanguage;
use Vvveb\System\Functions\Str;
use Vvveb\System\Sites;
use Vvveb\System\User\Admin;
@@ -73,7 +72,7 @@ class Reset {
$loginData = [];
$language = $this->session->get('language') ?? 'en_US';
- setLanguage($language);
+ Locale :: setLanguage($language);
if ($email) {
$loginData['email'] = $email;
diff --git a/app/component/content/archives.php b/app/component/content/archives.php
index d9f39ce..cc5891d 100755
--- a/app/component/content/archives.php
+++ b/app/component/content/archives.php
@@ -22,9 +22,9 @@
namespace Vvveb\Component\Content;
-use function Vvveb\getLanguage;
use Vvveb\System\Component\ComponentBase;
use Vvveb\System\Event;
+use Vvveb\System\Locale;
class Archives extends ComponentBase {
public static $defaultOptions = [
@@ -49,7 +49,7 @@ class Archives extends ComponentBase {
if (class_exists('\IntlDateFormatter')) {
$dt = new \DateTime();
- $df = new \IntlDateFormatter(getLanguage(), \IntlDateFormatter::NONE, \IntlDateFormatter::NONE, NULL, NULL, 'MMMM');
+ $df = new \IntlDateFormatter(Locale::getLanguage(), \IntlDateFormatter::NONE, \IntlDateFormatter::NONE, NULL, NULL, 'MMMM');
}
foreach ($results['archives'] as $index => &$archive) {
diff --git a/app/component/currency.php b/app/component/currency.php
index bef1dfc..e7f0529 100755
--- a/app/component/currency.php
+++ b/app/component/currency.php
@@ -22,10 +22,11 @@
namespace Vvveb\Component;
-use function Vvveb\availableCurrencies;
use function Vvveb\session;
use Vvveb\System\Component\ComponentBase;
use Vvveb\System\Event;
+use Vvveb\System\Locale;
+
class Currency extends ComponentBase {
public static $defaultOptions = [
@@ -45,7 +46,7 @@ class Currency extends ComponentBase {
$results = [];
$results['active'] = false;
$results['current'] = self :: $global['currency'];
- $results['currency'] = availableCurrencies();
+ $results['currency'] = Locale::availableCurrencies();
if (isset($results['currency']) && $results['currency']) {
if (isset($this->options['site_only']) && $this->options['site_only'] && self :: $global['currencies']) {
diff --git a/app/component/language.php b/app/component/language.php
index cce68b1..b206fe8 100755
--- a/app/component/language.php
+++ b/app/component/language.php
@@ -22,14 +22,13 @@
namespace Vvveb\Component;
-use function Vvveb\availableLanguages;
-use function Vvveb\getCurrentUrl;
use function Vvveb\isSecure;
use Vvveb\System\Cache;
use Vvveb\System\Component\ComponentBase;
use Vvveb\System\Core\Request;
use Vvveb\System\Core\View;
use Vvveb\System\Event;
+use Vvveb\System\Locale;
use function Vvveb\url;
class Language extends ComponentBase {
@@ -51,7 +50,7 @@ class Language extends ComponentBase {
$results = [];
$options = $this->options;
- $results['language'] = availableLanguages();
+ $results['language'] = Locale::availableLanguages();
$publicPath = \Vvveb\publicUrlPath();
$request = Request::getInstance();
@@ -89,26 +88,26 @@ class Language extends ComponentBase {
$lang = [];
$language['img'] = "{$publicPath}img/flags/$shortcode.png";
- if (! $language['default']) {
- $lang = ['language' => $language['slug']];
- }
-
//if post or product page check if content available
if (isset($view->content)) {
$content = $view->content[$language['slug']] ?? [];
+ //if translation is missing there is no slug
+ if (! isset($content['slug']) || ! $content['slug']) {
+ unset($content['slug']);
+ }
}
- $get = $request->get;
- unset($get['language']);
+ $params = ['language' => $language['slug'], 'host' => $_SERVER['HTTP_HOST'] ?? '', 'scheme' => $scheme] + $content + $request->get;
- //$url = getCurrentUrl();
- if (true/* && $options['default'] != $code*/) {
- $params = $lang + $content + $get + ['host' => $_SERVER['HTTP_HOST'] ?? '', 'scheme' => $scheme];
- $url = url($request->get['module'] ?? '', $params, false); //"/$shortcode" . getCurrentUrl();
- $hreflang[$shortcode] = $url;
+
+ if ($language['language_id'] == $options['default_language_id']) {
+ unset($params['language']);
}
- $language['url'] = $url;
+ $url = url($request->get['module'] ?? '', $params, false);
+
+ $language['url'] = $url;
+ $hreflang[$shortcode] = $url;
}
$view->hreflang = $hreflang;
diff --git a/app/controller/base.php b/app/controller/base.php
index 6417783..67e1c65 100755
--- a/app/controller/base.php
+++ b/app/controller/base.php
@@ -24,15 +24,12 @@ namespace Vvveb\Controller;
use \Vvveb\System\Core\FrontController;
use \Vvveb\System\Functions\Str;
-use function Vvveb\availableCurrencies;
-use function Vvveb\availableLanguages;
-use function Vvveb\clearLanguageCache;
use function Vvveb\filter;
-use function Vvveb\setLanguage;
use function Vvveb\siteSettings;
use Vvveb\System\Core\View;
use Vvveb\System\Event;
use Vvveb\System\Images;
+use Vvveb\System\Locale;
use Vvveb\System\PageCache;
use Vvveb\System\Sites;
use Vvveb\System\User\Admin;
@@ -42,77 +39,54 @@ use Vvveb\System\User\User;
class Base {
protected $global;
- protected function language($defaultLanguage = false, $defaultLanguageId = false, $defaultLocale = false, $defaultCode = false, $languages = null) {
- $languages = $languages ?? availableLanguages();
+ protected function language($default_language = false, $default_language_id = false, $default_locale = false, $default_code = false, $languages = null) {
+ $languages = $languages ?? Locale::availableLanguages();
- $default_language = $this->session->get('default_language');
- $default_language_id = $this->session->get('default_language_id');
- $default_locale = $this->session->get('default_locale');
- $default_code = $this->session->get('default_code');
- $default_rtl = false;
- $site_language = false;
+ $default_rtl = false;
+ $site_language = false;
+ $language = false;
- if (($lang = ($this->request->post['language'] ?? $this->request->get['language'] ?? false)) && ! is_array($lang)) {
+ if (($lang = ($this->request->post['language'] ?? false)) && ! is_array($lang)) {
$language = filter('/[A-Za-z_-]+/', $lang, 10);
if (isset($languages[$language])) {
$this->session->set('language', $language);
- $this->session->set('language_id', $languages[$language]['language_id']);
- $this->session->set('locale', $languages[$language]['locale']);
- $this->session->set('code', $languages[$language]['code']);
- $this->session->set('rtl', $languages[$language]['rtl'] ?? false);
- $default_language = false; //recheck default language
- //clearLanguageCache($language);
+ $this->session->set('language_id', $language_id = $languages[$language]['language_id']);
+ $this->session->set('locale', $locale = $languages[$language]['locale']);
+ $this->session->set('code', $code = $languages[$language]['code']);
+ $this->session->set('rtl', $rtl = ($languages[$language]['rtl'] ?? false));
}
}
- if (! $default_language) {
- foreach ($languages as $code => $lang) {
- //set site language
- if ($defaultLanguageId && ($defaultLanguageId == $lang['language_id'])) {
- $site_language = $code;
- $site_language_id = $lang['language_id'];
- $site_locale = $lang['locale'];
- $site_code = $lang['code'];
- }
-
- //set global default language
- if ($lang['default']) {
- $default_language = $code;
- $default_language_id = $lang['language_id'];
- $default_locale = $lang['locale'];
- $default_code = $lang['code'];
- $default_rtl = $lang['rtl'] ?? false;
- }
- }
+ if (($lang = ($this->request->get['language'] ?? false)) && ! is_array($lang)) {
+ $language = filter('/[A-Za-z_-]+/', $lang, 10);
- if ($site_language) {
- $default_language = $site_language;
- $default_language_id = $site_language_id;
- $default_locale = $site_locale;
- $default_code = $site_code;
+ if (isset($languages[$language])) {
+ $lg = $languages[$language];
+ $language_id = $lg['language_id'];
+ $locale = $lg['locale'];
+ $code = $lg['code'];
+ $rtl = $lg['rtl'] ?? false;
}
-
- //no valid default site or global language? set english as default
- if (! $default_language) {
- $default_language = 'en';
- $default_language_id = 1;
- $default_locale = 'en-us';
- $default_code = 'en_US';
- $default_rtl = false;
+ } else {
+ //don't set user session language for default language homepage
+ if (! isset($this->request->get['module']) || $this->request->get['module'] != 'index/index') {
+ $language = $this->session->get('language') ?? $default_language;
+ $language_id = $this->session->get('language_id') ?? $default_language_id;
+ $locale = $this->session->get('locale') ?? $default_locale;
+ $code = $this->session->get('code') ?? $default_code;
+ $rtl = $this->session->get('rtl') ?? false;
}
-
- $this->session->set('default_language', $default_language);
- $this->session->set('default_language_id', $default_language_id);
- $this->session->set('default_locale', $default_locale);
- $this->session->set('default_code', $default_code);
}
- $language = $this->session->get('language') ?? $default_language;
- $language_id = $this->session->get('language_id') ?? $default_language_id;
- $locale = $this->session->get('locale') ?? $default_locale;
- $code = $this->session->get('code') ?? $default_code;
- $rtl = $this->session->get('rtl') ?? false;
+ //if no language configured then set default language as current language
+ if (! $language) {
+ $language = $default_language;
+ $language_id = $default_language_id;
+ $locale = $default_locale;
+ $code = $default_code;
+ $rtl = $default_rtl;
+ }
//if no default language configured then set first language as current language
if (! isset($languages[$language])) {
@@ -121,28 +95,13 @@ class Base {
$lang = $languages[$default_language] ?? [];
if ($lang) {
- $default_language_id = $lang['language_id'] ?? $defaultLanguageId;
- $default_locale = $lang['locale'] ?? $defaultLocale;
- $default_code = $lang['code'] ?? $defaultCode;
- $default_rtl = $lang['rtl'] ?? false;
+ $language_id = $default_language_id = $lang['language_id'];
+ $locale = $default_locale = $lang['locale'];
+ $code = $default_code = $lang['code'];
+ $rtl = $default_rtl = $lang['rtl'] ?? false;
}
}
- //if no language configured then set default language as current language
- if (! $language) {
- $language = $default_language;
- $language_id = $default_language_id;
- $locale = $default_locale;
- $code = $default_code;
- $rtl = $default_rtl;
-
- $this->session->set('language', $language);
- $this->session->set('language_id', $language_id);
- $this->session->set('locale', $locale);
- $this->session->set('code', $code);
- $this->session->set('rtl', $rtl);
- }
-
$this->global['language'] = $language;
$this->global['locale'] = $locale;
$this->global['code'] = $code;
@@ -152,13 +111,13 @@ class Base {
$this->global['default_locale'] = $default_locale;
$this->global['default_language_id'] = $default_language_id;
- setLanguage($code);
+ Locale :: setLanguage($code);
}
protected function currency($defaultCurrency = false, $defaultCurrencyId = false) {
if (($currency = ($this->request->post['currency'] ?? false)) && ! is_array($currency)) {
$currency = filter('/[A-Za-z_-]+/', $currency, 50);
- $currencies = availableCurrencies();
+ $currencies = Locale::availableCurrencies();
if (isset($currencies[$currency])) {
$this->session->set('currency_id', $currencies[$currency]['currency_id']);
@@ -172,7 +131,7 @@ class Base {
$currency_id = $this->session->get('currency_id');
if (! $currency || ! $currency_id) {
- $currencies = availableCurrencies();
+ $currencies = Locale::availableCurrencies();
if ($currencies) {
foreach ($currencies as $code => $c) {
@@ -265,11 +224,12 @@ class Base {
$this->global['user_id'] = $user['user_id'] ?? false;
$this->global['user_group_id'] = $user['user_group_id'] ?? 1;
$this->global['site'] = &$site;
+ $this->global['path'] = SITE_PATH;
$this->global['user'] = $user ?? [];
$this->global['admin'] = $admin ?? [];
$this->global['current_year'] = date('Y');
- $languages = availableLanguages();
+ $languages = Locale::availableLanguages();
$language = $languages[$site['language'] ?? 'en'] ?? ['slug' => 'en', 'language_id' => 1, 'locale' => 'en', 'code' => 'en_US', $languages];
$this->language($language['slug'], $language['language_id'], $language['locale'], $language['code']);
@@ -310,7 +270,9 @@ class Base {
$this->view->errors[] = 'This is a dummy error message!';
$this->view->success[] = 'This is a dummy success message!';
$this->view->info[] = 'This is a dummy info message!';
- $this->view->message[] = 'This is a dummy message!';
+ if (! isset($this->view->message)) {
+ $this->view->message[] = 'This is a dummy message!';
+ }
}
list($this->global) = Event::trigger(__CLASS__, __FUNCTION__ . ':after', $this->global);
diff --git a/app/controller/content/archive.php b/app/controller/content/archive.php
index b324333..918c02a 100755
--- a/app/controller/content/archive.php
+++ b/app/controller/content/archive.php
@@ -23,7 +23,7 @@
namespace Vvveb\Controller\Content;
use Vvveb\Controller\Base;
-use function Vvveb\getLanguage;
+use Vvveb\System\Locale;
class Archive extends Base {
function index() {
@@ -36,7 +36,7 @@ class Archive extends Base {
if (class_exists('\IntlDateFormatter')) {
$dt = new \DateTime();
$dt->setDate(0, $month, 0);
- $df = new \IntlDateFormatter(getLanguage(), \IntlDateFormatter::NONE, \IntlDateFormatter::NONE, NULL, NULL, 'MMMM');
+ $df = new \IntlDateFormatter(Locale::getLanguage(), \IntlDateFormatter::NONE, \IntlDateFormatter::NONE, NULL, NULL, 'MMMM');
$month_name = ucfirst(datefmt_format($df, $dt));
}
diff --git a/app/controller/content/post.php b/app/controller/content/post.php
index 382ed78..dcfe9c9 100755
--- a/app/controller/content/post.php
+++ b/app/controller/content/post.php
@@ -28,9 +28,9 @@ use Vvveb\Controller\Base;
//use Vvveb\System\Component\Component;
use function Vvveb\model;
use function Vvveb\postTypes;
-use function Vvveb\setLanguage;
use Vvveb\System\Core\FrontController;
use Vvveb\System\Event;
+use Vvveb\System\Locale;
use Vvveb\System\User\Admin;
class Post extends Base {
@@ -50,15 +50,38 @@ class Post extends Base {
$language = $this->request->get['language'] ?? $this->global['language'] ?? $this->global['default_language'];
$post_id = $this->request->get['post_id'] ?? '';
$slug = $this->request->get['slug'] ?? '';
+ $type = $this->request->get['type'] ?? null;
$created_at = $this->request->get['created_at'] ?? ''; //revision preview
+ //check for custom post or product
+ if ($type) {
+ $class = '';
+ $postTypes = postTypes('post');
+
+ if (isset($postTypes[$type])) {
+ } else {
+ $postTypes = postTypes('product');
+
+ if (isset($postTypes[$type])) {
+ $class = 'Product';
+ FrontController::redirect($class, 'index');
+
+ die();
+ } else {
+ $error = sprintf(__('%s not found!'), ucfirst(__($this->type)));
+ return $this->notFound(true, ['message' => $error, 'title' => $error]);
+ }
+ }
+ }
+
if ($post_id || $slug) {
$contentSql = new PostSQL();
- $options = $this->global + ['post_id' => $post_id, 'slug' => $slug/*, 'type' => $this->type*/];
+ $options = $this->global + ['post_id' => $post_id, 'slug' => $slug, 'type' => $type ?? $this->type];
$content = $contentSql->getContent($options) ?? [];
$class = __NAMESPACE__ . '\\' . ucfirst($this->type); //__CLASS__ is always Post
list($content, $language, $slug) = Event :: trigger($class,__FUNCTION__, $content, $language, $slug);
+ $languageContent = [];
if ($content) {
if (isset($content[$language])) {
@@ -73,7 +96,7 @@ class Post extends Base {
if ($languageContent) {
if ($this->global['language'] != $languageContent['code']) {
- setLanguage($languageContent['code']);
+ Locale :: setLanguage($languageContent['code']);
}
$this->global['language'] = $languageContent['code'];
diff --git a/app/controller/product/product.php b/app/controller/product/product.php
index 60dbb46..d89cad7 100755
--- a/app/controller/product/product.php
+++ b/app/controller/product/product.php
@@ -26,8 +26,12 @@ use \Vvveb\Sql\ProductSQL;
use function Vvveb\__;
use Vvveb\Controller\Base;
use Vvveb\Controller\Content\CommentTrait;
-use function Vvveb\setLanguage;
+use function Vvveb\model;
+use function Vvveb\postTypes;
+use Vvveb\System\Core\FrontController;
use Vvveb\System\Event;
+use Vvveb\System\Locale;
+use Vvveb\System\User\Admin;
class Product extends Base {
public $type = 'product';
@@ -54,15 +58,37 @@ class Product extends Base {
$language = $this->request->get['language'] ?? $this->global['language'] ?? $this->global['default_language'];
$product_id = $this->request->get['product_id'] ?? '';
$slug = $this->request->get['slug'] ?? '';
+ $type = $this->request->get['type'] ?? '';
+ $created_at = $this->request->get['created_at'] ?? ''; //revision preview
- if ($slug) {
+ //check for custom post or product
+ if ($type) {
+ $class = '';
+ $postTypes = postTypes('product');
+
+ if (isset($postTypes[$type])) {
+ } else {
+ $postTypes = postTypes('post');
+
+ if (isset($postTypes[$type])) {
+ $class = 'Content';
+ FrontController::redirect($class, 'index');
+
+ die();
+ } else {
+ $error = sprintf(__('%s not found!'), ucfirst(__($this->type)));
+ return $this->notFound(true, ['message' => $error, 'title' => $error]);
+ }
+ }
+ }
+
+ if ($product_id || $slug) {
$contentSql = new ProductSQL();
- $options = $this->global + ['product_id' => $product_id, 'slug' => $slug, /*'type' => $this->type, */'status' => 1];
+ $options = $this->global + ['product_id' => $product_id, 'slug' => $slug, 'type' => $type ?? $this->type, 'status' => 1];
$content = $contentSql->getContent($options);
- list($content, $language, $slug) = Event :: trigger(__CLASS__,__FUNCTION__, $content, $language, $slug);
-
- $error = __('Product not found!');
+ $class = __NAMESPACE__ . '\\' . ucfirst($this->type); //__CLASS__ is always Product
+ list($content, $language, $slug) = Event :: trigger($class,__FUNCTION__, $content, $language, $slug);
$languageContent = [];
if ($content) {
@@ -78,7 +104,7 @@ class Product extends Base {
if ($languageContent) {
if ($this->global['language'] != $languageContent['code']) {
- setLanguage($languageContent['code']);
+ Locale :: setLanguage($languageContent['code']);
}
$this->global['language'] = $languageContent['code'];
@@ -88,6 +114,7 @@ class Product extends Base {
//$this->session->set('language_id', $languageContent['language_id']);
$this->request->get['product_id'] = $languageContent['product_id'];
+ $this->request->get['admin_id'] = $languageContent['admin_id'];
$this->request->request['product_id'] = $languageContent['product_id'];
$this->request->get['type'] = $languageContent['type'];
$this->request->get['name'] = $languageContent['name'];
@@ -95,13 +122,28 @@ class Product extends Base {
$this->request->request['code'] = $languageContent['code'];
$this->request->request['language_id'] = $languageContent['language_id'];
+ if ($created_at) {
+ //check if admin user to allow revision preview
+ $admin = Admin::current();
+
+ if ($admin) {
+ $revisions = model('product_content_revision');
+ $revision = $revisions->get(['created_at' => $created_at, 'post_id' => $languageContent['post_id']] + $this->global);
+
+ if ($revision && isset($revision['content'])) {
+ $languageContent['content'] = $revision['content'];
+ }
+ }
+ }
+
if (isset($languageContent['template']) && $languageContent['template']) {
$this->view->template($languageContent['template']);
//force product template if a different html template is selected
$this->view->tplFile("product/{$this->type}.tpl");
}
} else {
- $this->notFound(true, ['message' => $error, 'title' => $error]);
+ $error = sprintf(__('%s not found!'), ucfirst(__($this->type)));
+ return $this->notFound(true, ['message' => $error, 'title' => $error]);
}
$languageContent['title'] = $languageContent['name'];
@@ -109,9 +151,31 @@ class Product extends Base {
$languageContent['title'] = $languageContent['title'] . ' - ' . $this->global['site']['description']['title'];
}
- list($content, $languageContent, $language, $slug) = Event :: trigger(__CLASS__,__FUNCTION__ . ':after', $content, $languageContent, $language, $slug);
+ list($content, $languageContent, $language, $slug) = Event :: trigger($class, __FUNCTION__ . ':after', $content, $languageContent, $language, $slug);
} else {
- $this->notFound(true, ['message' => $error, 'title' => $error]);
+ //check for custom post or product
+ $class = '';
+ $postTypes = postTypes('post');
+
+ if (isset($postTypes[$slug])) {
+ $class = 'Content';
+ } else {
+ $postTypes = postTypes('product');
+
+ if (isset($postTypes[$slug])) {
+ $class = 'Product';
+ }
+ }
+
+ if ($class) {
+ $this->request->get['type'] = $slug;
+ FrontController::redirect($class, 'index');
+
+ die();
+ } else {
+ $error = sprintf(__('%s not found!'), ucfirst(__($this->type)));
+ return $this->notFound(true, ['message' => $error, 'title' => $error]);
+ }
}
$this->view->product = $languageContent;
diff --git a/config/sites.php b/config/sites.php
index 420cf7d..c00e1b9 100755
--- a/config/sites.php
+++ b/config/sites.php
@@ -24,9 +24,10 @@
'* * *' => [
'name' => 'Default site',
'host' => '*.*.*',
+ 'path' => '',
'theme' => 'landing',
- 'state' => 'live',
'template' => '',
+ 'state' => 'live',
'site_id' => 1,
- ],
- ];
+ ]
+];
diff --git a/install/sql/insert/site/site.sql b/install/sql/insert/site/site.sql
index f49eabb..3371fb3 100644
--- a/install/sql/insert/site/site.sql
+++ b/install/sql/insert/site/site.sql
@@ -1,2 +1,2 @@
-INSERT INTO `site` (`site_id`, `key`, `name`, `host`, `theme`, `template`, `settings`) VALUES
-(1, 'default','Default','*.*.*', 'landing', '', '{"description":{"1":{"title": "Vvveb","description": "The next generation website builder","meta-keywords": "cms, page builder, drag and drop, ecommerce, ecommerce platform, designer, developer, php, bootstrap 5","meta-description": "Powerful and easy to use drag and drop website builder for blogs, presentation or ecommerce stores","phone-number": "+55 (111) 123 777"}},"address":"West 21st Street Brooklyn NY","admin-email":"[email protected]","contact-email":"[email protected]","logo":"logo.png","logo-sticky":"logo.png","logo-dark":"logo-white.png","logo-dark-sticky":"logo-white.png","favicon":"favicon.ico","webbanner":"biglogo.png","post_xlarge_width":"1200","post_xlarge_height":"675","post_large_width":"800","post_large_height":"450","post_medium_width":"400","post_medium_height":"225","post_thumb_width":"150","post_thumb_height":"84","product_xlarge_width":"1200","product_xlarge_height":"1536","product_large_width":"800","product_large_height":"1021","product_medium_width":"400","product_medium_height":"510","product_thumb_width":"150","product_thumb_height":"190","date_format":"j F Y","time_format":"g:i A", "country_id":"223","region_id":"3655","language_id":"1","currency_id":"1","language":"en","languages":"","currency":"USD","currencies":"","invoice_format":"I-{year2}-{month}-{order_id}-{user_id}-{customer_order_id}","order_id_format":"{rand-str-12}-{year2}","language_id":"1","currency_id":"1","length_type_id":"1","weight_type_id":"1","order_status_id":"1", "default_comment_status":"1","anonymous_comments":"1"}');
+INSERT INTO `site` (`site_id`, `name`, `settings`) VALUES
+(1, 'Default', '{"description":{"1":{"title": "Vvveb","description": "The next generation website builder","meta-keywords": "cms, page builder, drag and drop, ecommerce, ecommerce platform, designer, developer, php, bootstrap 5","meta-description": "Powerful and easy to use drag and drop website builder for blogs, presentation or ecommerce stores","phone-number": "+55 (111) 123 777"}},"address":"West 21st Street Brooklyn NY","admin-email":"[email protected]","contact-email":"[email protected]","logo":"logo.png","logo-sticky":"logo.png","logo-dark":"logo-white.png","logo-dark-sticky":"logo-white.png","favicon":"favicon.ico","webbanner":"biglogo.png","post_xlarge_width":"1200","post_xlarge_height":"675","post_large_width":"800","post_large_height":"450","post_medium_width":"400","post_medium_height":"225","post_thumb_width":"150","post_thumb_height":"84","product_xlarge_width":"1200","product_xlarge_height":"1536","product_large_width":"800","product_large_height":"1021","product_medium_width":"400","product_medium_height":"510","product_thumb_width":"150","product_thumb_height":"190","date_format":"j F Y","time_format":"g:i A", "country_id":"223","region_id":"3655","language_id":"1","currency_id":"1","language":"en","languages":"","currency":"USD","currencies":"","invoice_format":"I-{year2}-{month}-{order_id}-{user_id}-{customer_order_id}","order_id_format":"{rand-str-12}-{year2}","language_id":"1","currency_id":"1","length_type_id":"1","weight_type_id":"1","order_status_id":"1", "default_comment_status":"1","anonymous_comments":"1"}');
diff --git a/install/sql/mysqli/schema/site/site.sql b/install/sql/mysqli/schema/site/site.sql
old mode 100755
new mode 100644
index ab88217..fdabc33
--- a/install/sql/mysqli/schema/site/site.sql
+++ b/install/sql/mysqli/schema/site/site.sql
@@ -2,11 +2,7 @@ DROP TABLE IF EXISTS `site`;
CREATE TABLE `site` (
`site_id` tinyint(6) NOT NULL AUTO_INCREMENT,
- `key` varchar(191) NOT NULL,
`name` varchar(191) NOT NULL,
- `host` varchar(191) NOT NULL,
- `theme` varchar(191) NOT NULL,
- `template` varchar(191) NOT NULL DEFAULT '',
`settings` text,
PRIMARY KEY (`site_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;
diff --git a/system/cart/cart.php b/system/cart/cart.php
index 91a089d..a36013f 100755
--- a/system/cart/cart.php
+++ b/system/cart/cart.php
@@ -22,7 +22,6 @@
namespace Vvveb\System\Cart;
-use function \Vvveb\getCurrency;
use function \Vvveb\model;
use function \Vvveb\url;
use Vvveb\Sql\Product_Option_ValueSQL;
@@ -30,6 +29,7 @@ use Vvveb\Sql\Product_VariantSQL;
use Vvveb\Sql\ProductSQL;
use Vvveb\Sql\Subscription_PlanSQL;
use Vvveb\System\Images;
+use Vvveb\System\Locale;
use Vvveb\System\Session;
class Cart {
@@ -171,7 +171,7 @@ class Cart {
$this->total_items = 0;
$results = ['products' => [], 'count' => 0];
- $currency = getCurrency();
+ $currency = Locale::getCurrency();
if (! empty($this->products)) {
$productIds = [];
@@ -360,7 +360,7 @@ class Cart {
}
}
- $this->addTotal('sub_total', 'Sub-total', $this->total);
+ $this->addTotal('total', 'sub_total', 'Sub-total', $this->total);
//set cart cookie to disable cache if products in cart
if ($this->total_items) {
@@ -479,7 +479,7 @@ class Cart {
$product_data = [];
foreach ($this->products as $value) {
- if ($value['subscription']) {
+ if (isset($value['subscription'])) {
$product_data[] = $value;
}
}
diff --git a/system/cart/currency.php b/system/cart/currency.php
old mode 100755
new mode 100644
index 6ef47dc..6eeaaf5
--- a/system/cart/currency.php
+++ b/system/cart/currency.php
@@ -22,8 +22,8 @@
namespace Vvveb\System\Cart;
-use function Vvveb\availableCurrencies;
use function Vvveb\session as sess;
+use Vvveb\System\Locale;
class Currency {
private $currencies;
@@ -42,7 +42,7 @@ class Currency {
public function __construct($options = []) {
$this->options = $options;
- $this->currencies = availableCurrencies();
+ $this->currencies = Locale::availableCurrencies();
}
public function format($number, $currency = false, $format = true, $value = 0) {
@@ -50,7 +50,7 @@ class Currency {
$currency = $this->options['currency'] ?? sess('currency');
}
- if (! isset($this->currencies[$currency])) {
+ if (! $currency || ! isset($this->currencies[$currency])) {
return '';
}
diff --git a/system/component/component-base.php b/system/component/component-base.php
index 12ac5bb..f4cb18c 100644
--- a/system/component/component-base.php
+++ b/system/component/component-base.php
@@ -27,6 +27,7 @@ use function Vvveb\siteSettings;
use Vvveb\System\Core\Request;
use Vvveb\System\Core\View;
use Vvveb\System\Event;
+use Vvveb\System\Locale;
use Vvveb\System\Session;
use Vvveb\System\User\User;
@@ -57,27 +58,30 @@ class ComponentBase {
self :: $global['user_group_id'] = $user['user_group_id'] ?? 1;
self :: $global['languages'] = $site['languages'] ?? [];
self :: $global['default_language'] = sess('default_language') ?? $site['language'] ?? 'en';
- self :: $global['default_language_id'] = sess('default_language_id') ?? $site['language_id'] ?? 1;
- self :: $global['currency_id'] = sess('currency_id') ?? $site['currency_id'] ?? 1;
+ self :: $global['default_language_id'] = (int)(sess('default_language_id') ?? $site['language_id'] ?? 1);
+ self :: $global['language'] = ($site['language'] ?? '') ?: 'en';
+ self :: $global['language_id'] = (int)($site['language_id'] ?? '') ?: 1;
+ self :: $global['currency_id'] = (int)(sess('currency_id') ?? $site['currency_id'] ?? 1);
self :: $global['currency'] = sess('currency') ?? $site['currency'] ?? 'usd';
self :: $global['currencies'] = $site['currencies'] ?? [];
- self :: $global['language'] = ($site['language'] ?? '') ?: 'en';
- self :: $global['language_id'] = ($site['language_id'] ?? '') ?: 1;
- if ($language = sess('language')) {
- self :: $global['language'] = $language;
+ //don't set user session language for default language homepage
+ if (! isset($request->get['module']) || $request->get['module'] != 'index/index') {
+ self :: $global['language'] = (sess('language') ?? self :: $global['language']);
+ self :: $global['language_id'] = (sess('language_id') ?? self :: $global['language_id']);
}
- if ($language_id = sess('language_id')) {
- self :: $global['language_id'] = $language_id;
- }
-
- if (isset($request->request['language']) && is_string($request->request['language'])) {
- self :: $global['language'] = $request->request['language'];
+ if ((isset($request->post['language']) && is_string($request->post['language']) && ($lang = $request->post['language'])) ||
+ (isset($request->get['language']) && is_string($request->get['language']) && ($lang = $request->get['language']))) {
+ $languages = Locale::availableLanguages();
+ if (isset($languages[$lang])) {
+ self :: $global['language'] = $lang;
+ self :: $global['language_id'] = $languages[$lang]['language_id'];
+ }
}
- if (isset($request->request['language_id']) && is_string($request->request['language_id'])) {
- self :: $global['language_id'] = $request->request['language_id'];
+ if (isset($request->post['language_id']) && is_string($request->post['language_id'])) {
+ self :: $global['language_id'] = $request->post['language_id'];
}
}
diff --git a/system/component/component.php b/system/component/component.php
index b5ad7cb..f0703c7 100644
--- a/system/component/component.php
+++ b/system/component/component.php
@@ -59,6 +59,8 @@ class Component {
private $documentType = 'html';
private $cache = true;
+
+ private $copyFromElements = [];
static function getInstance($view = false, $regenerate = false, $content = false, $app = null) {
if (self :: $instance === NULL) {
@@ -398,16 +400,21 @@ class Component {
if (preg_match('/([^\,]+)\,([^$,]+)/', $attribute , $from)) {
$file = html_entity_decode(trim($from[1]));
$selector = html_entity_decode(trim($from[2]));
-
- if ($this->documentType == 'html') {
- $fromDocument->loadHTMLFile($view->getTemplatePath() . $file);
+
+ if (isset($this->copyFromElements[$file][$selector])) {
+ $fromElements = $this->copyFromElements[$file][$selector];
} else {
- $fromDocument->loadXML($view->getTemplatePath() . $file);
- }
+ if ($this->documentType == 'html') {
+ $fromDocument->loadHTMLFile($view->getTemplatePath() . $file);
+ } else {
+ $fromDocument->loadXML($view->getTemplatePath() . $file);
+ }
- $fromXpath = new \DOMXpath($fromDocument);
+ $fromXpath = new \DOMXpath($fromDocument);
- $fromElements = $fromXpath->query(\Vvveb\cssToXpath($selector));
+ $fromElements = $fromXpath->query(\Vvveb\cssToXpath($selector));
+ $this->copyFromElements[$file][$selector] = $fromElements;
+ }
$count = 0;
$parent = $element->parentNode;
diff --git a/system/functions.php b/system/functions.php
index e3f33e4..d3955f0 100755
--- a/system/functions.php
+++ b/system/functions.php
@@ -41,14 +41,16 @@ function url($parameters, $mergeParameters = false, $useCurrentUrl = true) {
}
}
+ $path = $mergeParameters['path'] ?? SITE_PATH;
+
$url = System\Routes::url($parameters, $mergeParameters);
- $result .= (V_SUBDIR_INSTALL ? V_SUBDIR_INSTALL : '') . ($url ?? '');
+ $result .= (V_SUBDIR_INSTALL ? V_SUBDIR_INSTALL : '') . $path . ($url ?? '');
} else {
static $url = '';
static $urlParams = [];
if ($useCurrentUrl) {
- $url = parse_url($_SERVER['REQUEST_URI'] ?? '');
+ $url = parse_url(SITE_URI ?? $_SERVER['REQUEST_URI'] ?? '');
if (isset($url['query'])) {
parse_str($url['query'], $urlParams);
@@ -72,6 +74,7 @@ function url($parameters, $mergeParameters = false, $useCurrentUrl = true) {
}
$result = '';
+ $path = $parameters['path'] ?? SITE_PATH;
if (isset($parameters['host'])) {
$result .= '//' . \Vvveb\System\Sites::url($parameters['host']);
@@ -83,7 +86,7 @@ function url($parameters, $mergeParameters = false, $useCurrentUrl = true) {
}
} else {
if (! $useCurrentUrl) {
- $result .= (V_SUBDIR_INSTALL ? V_SUBDIR_INSTALL : '');
+ $result .= (V_SUBDIR_INSTALL ? V_SUBDIR_INSTALL : '') . $path;
}
}
@@ -514,9 +517,9 @@ if ((!defined('GETTEXT') || GETTEXT == true) && function_exists('_')) {
function __($text, $plural = false, $count = false, $nocache = false) {
static $translations;
- if ($translations === null || $nocache) {
+ if (($translations === null || $nocache) && !isEditor()) {
$translations = [];
- $lang = getLanguage();
+ $lang = System\Locale::getLanguage();
$cacheFile = DIR_CACHE . $lang . '-translations.php';
@@ -1184,6 +1187,7 @@ function getTemplateList($theme = null, $skip = []) {
}
$url = PUBLIC_PATH . "themes/$theme/$file";
+ $title = str_replace('index', 'home', $title);
$pages[$name] = ['name' => $name, 'filename' => $filename, 'file' => $file, 'url' => $url, 'title' => humanReadable($title), 'folder' => $path, 'description' => $description, 'global' => $friendlyNames[$name]['global'] ?? false];
@@ -1464,178 +1468,6 @@ function sanitizeHTML($string) {
return $string;
}
-function availableLanguages() {
- static $languages = [];
- if ($languages != []) {
- return $languages;
- }
-
- $cache = System\Cache::getInstance();
- $languages = $cache->cache(APP,'languages',function () {
- $languages = new Sql\LanguageSQL();
- $result = $languages->getAll(['status' => 1]);
-
- if ($result && isset($result['language'])) {
- return $result['language'];
- }
-
- return [];
- }, 259200);
-
- return $languages;
-}
-
-function availableCurrencies() {
- static $currencies = [];
- if ($currencies != []) {
- return $currencies;
- }
-
- $cache = System\Cache::getInstance();
- $currencies = $cache->cache(APP,'currency',function () {
- $currency = new Sql\CurrencySQL();
- $result = $currency->getAll(['status' => 1]);
-
- if ($result && isset($result['currency'])) {
- return $result['currency'];
- }
-
- return [];
- }, 259200);
-
- return $currencies;
-}
-
-function installedLanguages() {
- $languages = glob(DIR_ROOT . 'locale/*', GLOB_ONLYDIR);
-
- foreach ($languages as &$language) {
- $language = basename($language);
- }
-
- return $languages;
-}
-
-function userPreferedLanguages() {
- if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
- $languages = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
-
- foreach ($languages as &$language) {
- $language = \Vvveb\filter('/[-\w]+/', $language);
- $language = str_replace('-', '_', $language);
- }
- }
-
- return $languages ?? [];
-}
-
-function userPreferedLanguage() {
- $languages = userPreferedLanguages();
- $installed = installedLanguages();
-
- foreach ($languages as $language) {
- if (isset($installed[$language])) {
- return $language;
- }
-
- foreach ($installed as $lang) {
- if (strpos($lang, $language) === 0) {
- //return $language;
- return $lang;
- }
- }
- }
-
- return false;
-}
-
-/**
- * Change locale language for gettext.
- *
- * @param string $langCode ['en_US']
- * @param string $domain ['vvveb']
- *
- * @return mixed
- */
-function setLanguage($langCode = 'en_US', $domain = 'vvveb') {
- //global $vvvebTranslationDomains;
- //setlocale(LC_TIME, "");
- //\putenv('LOCPATH=' . DIR_ROOT. "locale");
-
- //translating theme text will change theme texts and break translation
- if (isEditor()) {
- return;
- }
-
- if (function_exists('bindtextdomain')) {
- /*
- foreach ($vvvebTranslationDomains as $tdomain) {
- bindtextdomain($tdomain, DIR_ROOT . 'locale');
- }
- */
- bindtextdomain($domain, DIR_ROOT . 'locale');
- textdomain($domain);
- bind_textdomain_codeset($domain, 'UTF-8');
-
- setlocale(LC_ALL,'C.UTF-8');
-
- if (function_exists('putenv')) {
- @\putenv("LC_ALL=$langCode");
- @\putenv("LC_MESSAGES=$langCode");
- @\putenv("LANG=$langCode");
- @\putenv('LANGUAGE=' . $langCode);
- }
-
- if (defined('LC_MESSAGES')) {
- setlocale(LC_MESSAGES, "$langCode.UTF-8");
- setlocale(LC_CTYPE,"$langCode.UTF-8");
- } else {
- setlocale(5, "$langCode.UTF-8");
- setlocale(6,"$langCode.UTF-8");
- setlocale(LC_ALL, "$langCode.UTF-8");
- }
- }
-}
-
-function clearLanguageCache($langCode = 'en_US', $domain = 'vvveb') {
- if (function_exists('bindtextdomain')) {
- $locale = DIR_ROOT . 'locale';
- $nocache = DIR_CACHE . 'nocache';
- $mo = $locale . DS . $langCode . DS . 'LC_MESSAGES' . DS . "$domain.mo";
- clearstatcache(false, $mo);
-
- if (function_exists('opcache_reset')) {
- opcache_invalidate($mo, true);
- opcache_reset();
- }
-
- if (function_exists('symlink') && @symlink($locale, $nocache)) {
- bindtextdomain($domain, $nocache);
- textdomain($domain);
- bind_textdomain_codeset($domain, 'different_codeset');
- bindtextdomain($domain, $locale);
- }
-
- @unlink($nocache);
- @rrmdir($nocache); //for windows if it copies folder instead of link
- }
-}
-
-function getLanguage() {
- return session('code') ?? 'en_US';
-}
-
-function setLanguageCode($code) {
- return session(['code' => $code]);
-}
-
-function getLanguageId() {
- return session('language_id') ?? 1;
-}
-
-function getCurrency() {
- return session('currency') ?? 'USD';
-}
function siteSettings($site_id = SITE_ID, $language_id = false) {
$cache = System\Cache::getInstance();
@@ -1699,6 +1531,7 @@ function truncateWords($text, $limit) {
* @param array $data
* @param mixed $config
* @param null|mixed $app
+ * @param mixed $site_id
* @return bool
*/
function email($to, $subject, $template, $data = [], $config = [], $app = null, $site_id = SITE_ID) {
@@ -1883,11 +1716,14 @@ function download($url) {
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT'] ?? 'Vvveb ' . V_VERSION);
- $result = curl_exec($ch);
+ $result = curl_exec($ch);
+ $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (PHP_MAJOR_VERSION < 8) {
curl_close($ch);
}
+
+ if ($httpcode != 200) return;
}
} else {
if (ini_get('allow_url_fopen') == '1') {
@@ -1921,8 +1757,7 @@ function validateUrl($url) {
}
//don't allow ip
- if (preg_match('/^(\d+\.)+\d+$/', $url, $matches) ||
- (false !== filter_var($url, FILTER_VALIDATE_IP))) {
+ if (false !== filter_var($url, FILTER_VALIDATE_IP)) {
return '';
}
@@ -1963,9 +1798,13 @@ function getUrl($url, $cache = true, $expire = 604800, $timeout = 5, $exception
$streamVerboseHandle = fopen('php://temp', 'w+');
curl_setopt($ch, CURLOPT_STDERR, $streamVerboseHandle);
}
+
$result = curl_exec($ch);
if ($result) {
+ $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
+ if ($httpcode != 200) return;
+
if ($cache) {
$cacheDriver->set('url', $cacheKey, $result);
}
@@ -2183,7 +2022,11 @@ function invoiceFormat($format, $data) {
remove <?xml declaration to avoid issues with php short start tag
*/
function xmlStripVersionDeclr($xmlString) {
- return preg_replace('/<\?xml\s+version[^\?]+\?>\s*/', '', $xmlString ?? '');
+ $xmlString = preg_replace('/<\?xml\s+version[^\?]+\?>\s*/', '', $xmlString ?? '');
+ //xml stylesheet
+ $xmlString = str_replace('<?xml-', '<?php echo \'<?xml-\';?>', $xmlString);
+
+ return $xmlString;
}
function array2xml($array, $xml = false) {
@@ -2360,7 +2203,7 @@ function reconstructJson(&$array, $removeAttrs = false) {
$key = substr($key, 0, -7);
$value = (array)$value;
} else {
- if (! $value) {
+ if ($value === null) {
$value = '';
}
}
diff --git a/system/locale.php b/system/locale.php
new file mode 100644
index 0000000..cfe57ea
--- /dev/null
+++ b/system/locale.php
@@ -0,0 +1,214 @@
+<?php
+
+/**
+ * Vvveb
+ *
+ * Copyright (C) 2022 Ziadin Givan
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+/**
+ * Manages image retrival and saving.
+ *
+ * @package Vvveb
+ * @subpackage System
+ * @since 0.0.1
+ */
+
+namespace Vvveb\System;
+
+use function Vvveb\rrmdir;
+use function Vvveb\session;
+
+class Locale {
+ static private $code;
+
+ static function availableLanguages() {
+ static $languages = [];
+ if ($languages != []) {
+ return $languages;
+ }
+
+ $cache = Cache::getInstance();
+ $languages = $cache->cache(APP,'languages',static function () {
+ $languages = new \Vvveb\Sql\LanguageSQL();
+ $result = $languages->getAll(['status' => 1]);
+
+ if ($result && isset($result['language'])) {
+ return $result['language'];
+ }
+
+ return [];
+ }, 259200);
+
+ return $languages;
+ }
+
+ static function availableCurrencies() {
+ static $currencies = [];
+ if ($currencies != []) {
+ return $currencies;
+ }
+
+ $cache = Cache::getInstance();
+ $currencies = $cache->cache(APP,'currency',static function () {
+ $currency = new \Vvveb\Sql\CurrencySQL();
+ $result = $currency->getAll(['status' => 1]);
+
+ if ($result && isset($result['currency'])) {
+ return $result['currency'];
+ }
+
+ return [];
+ }, 259200);
+
+ return $currencies;
+ }
+
+ static function installedLanguages() {
+ $languages = glob(DIR_ROOT . 'locale/*', GLOB_ONLYDIR);
+
+ foreach ($languages as &$language) {
+ $language = basename($language);
+ }
+
+ return $languages;
+ }
+
+ static function userPreferedLanguages() {
+ if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
+ $languages = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
+
+ foreach ($languages as &$language) {
+ $language = \Vvveb\filter('/[-\w]+/', $language);
+ $language = str_replace('-', '_', $language);
+ }
+ }
+
+ return $languages ?? [];
+ }
+
+ static function userPreferedLanguage() {
+ $languages = self :: userPreferedLanguages();
+ $installed = self :: installedLanguages();
+
+ foreach ($languages as $language) {
+ if (isset($installed[$language])) {
+ return $language;
+ }
+
+ foreach ($installed as $lang) {
+ if (strpos($lang, $language) === 0) {
+ //return $language;
+ return $lang;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Change locale language for gettext.
+ *
+ * @param string $langCode ['en_US']
+ * @param string $domain ['vvveb']
+ *
+ * @return mixed
+ */
+ static function setLanguage($langCode = 'en_US', $domain = 'vvveb') {
+ //global $vvvebTranslationDomains;
+ //setlocale(LC_TIME, "");
+ //\putenv('LOCPATH=' . DIR_ROOT. "locale");
+
+ //translating theme text will change theme texts and break translation
+ if (\Vvveb\isEditor()) {
+ return;
+ }
+
+ self :: $code = $langCode;
+
+ if (function_exists('bindtextdomain')) {
+ /*
+ foreach ($vvvebTranslationDomains as $tdomain) {
+ bindtextdomain($tdomain, DIR_ROOT . 'locale');
+ }
+ */
+ bindtextdomain($domain, DIR_ROOT . 'locale');
+ textdomain($domain);
+ bind_textdomain_codeset($domain, 'UTF-8');
+
+ setlocale(LC_ALL,'C.UTF-8');
+
+ if (function_exists('putenv')) {
+ @\putenv("LC_ALL=$langCode");
+ @\putenv("LC_MESSAGES=$langCode");
+ @\putenv("LANG=$langCode");
+ @\putenv('LANGUAGE=' . $langCode);
+ }
+
+ if (defined('LC_MESSAGES')) {
+ setlocale(LC_MESSAGES, "$langCode.UTF-8");
+ setlocale(LC_CTYPE,"$langCode.UTF-8");
+ } else {
+ setlocale(5, "$langCode.UTF-8");
+ setlocale(6,"$langCode.UTF-8");
+ setlocale(LC_ALL, "$langCode.UTF-8");
+ }
+ }
+ }
+
+ static function clearLanguageCache($langCode = 'en_US', $domain = 'vvveb') {
+ if (function_exists('bindtextdomain')) {
+ $locale = DIR_ROOT . 'locale';
+ $nocache = DIR_CACHE . 'nocache';
+ $mo = $locale . DS . $langCode . DS . 'LC_MESSAGES' . DS . "$domain.mo";
+ clearstatcache(false, $mo);
+
+ if (function_exists('opcache_reset')) {
+ opcache_invalidate($mo, true);
+ opcache_reset();
+ }
+
+ if (function_exists('symlink') && @symlink($locale, $nocache)) {
+ bindtextdomain($domain, $nocache);
+ textdomain($domain);
+ bind_textdomain_codeset($domain, 'different_codeset');
+ bindtextdomain($domain, $locale);
+ }
+
+ @unlink($nocache);
+ @rrmdir($nocache); //for windows if it copies folder instead of link
+ }
+ }
+
+ static function getLanguage() {
+ return self :: $code ?? session('code') ?? 'en_US';
+ }
+
+ static function setLanguageCode($code) {
+ self :: $code = $code;
+ return session(['code' => $code]);
+ }
+
+ static function getLanguageId() {
+ return session('language_id') ?? 1;
+ }
+
+ static function getCurrency() {
+ return session('currency') ?? 'USD';
+ }
+}