Powerful and easy to use cms to build websites, blogs or ecommerce stores.
HTML backendblogblog-engineblog-platformbloggingcmscontent-managementcontent-management-systemecommerceecommerce-platformno-codepage-builderphpphp-cmsphp7php8self-hostedshopping-cartweb-applicationwebsite-builder
Meta classes and functions and settings refactoring
givanz47f47d583ba1
diff --git a/admin/controller/settings/checkout.php b/admin/controller/settings/checkout.phpindex aadd714..da8533b 100755--- a/admin/controller/settings/checkout.php+++ b/admin/controller/settings/checkout.php@@ -39,7 +39,7 @@ class Checkout extends Base {if ($settings &&($errors = $validator->validate($settings)) === true) {$settings = $validator->filter($settings);- $results = \Vvveb\set_settings('checkout',$settings);+ $results = \Vvveb\setMultiSetting('checkout',$settings);$this->view->success[] = __('Settings saved!');} else {$this->view->errors = $errors;diff --git a/admin/controller/settings/discount.php b/admin/controller/settings/discount.phpindex 2f83be2..ca243f4 100755--- a/admin/controller/settings/discount.php+++ b/admin/controller/settings/discount.php@@ -39,7 +39,7 @@ class Discount extends Base {if ($settings &&($errors = $validator->validate($settings)) === true) {$settings = $validator->filter($settings);- $results = \Vvveb\set_settings('discount',$settings);+ $results = \Vvveb\setMultiSetting('discount',$settings);$this->view->success[] = __('Settings saved!');} else {$this->view->errors = $errors;diff --git a/admin/controller/settings/email.php b/admin/controller/settings/email.phpindex cd3d87a..2be2dd8 100755--- a/admin/controller/settings/email.php+++ b/admin/controller/settings/email.php@@ -26,7 +26,7 @@ use function Vvveb\__;use function Vvveb\config;use Vvveb\Controller\Base;use function Vvveb\email;-use function Vvveb\set_config;+use function Vvveb\setConfig;use Vvveb\System\Config;use Vvveb\System\Validator;@@ -64,8 +64,8 @@ class Email extends Base {if ($settings /*&&($errors = $validator->validate($settings)) === true*/) {//$settings = $validator->filter($settings);- //$results = \Vvveb\set_settings('mail',$settings);- $results = set_config('mail',$settings);+ //$results = \Vvveb\setMultiSetting('mail',$settings);+ $results = setConfig('mail',$settings);if ($results) {$this->view->success[] = __('Settings saved!');diff --git a/admin/controller/settings/notifications.php b/admin/controller/settings/notifications.phpindex 7ec3a30..9d3c092 100755--- a/admin/controller/settings/notifications.php+++ b/admin/controller/settings/notifications.php@@ -39,7 +39,7 @@ class Notifications extends Base {if ($settings &&($errors = $validator->validate($settings)) === true) {$settings = $validator->filter($settings);- $results = \Vvveb\set_settings($settings);+ $results = \Vvveb\setMultiSetting($settings);$this->view->success[] = __('Settings saved!');} else {$this->view->errors = $errors;diff --git a/admin/controller/settings/post-type.php b/admin/controller/settings/post-type.phpindex b0e1e6a..f8087f6 100644--- a/admin/controller/settings/post-type.php+++ b/admin/controller/settings/post-type.php@@ -35,7 +35,7 @@ class PostType extends Base {$userType = $this->request->get['type'] ?? false;if ($postType) {- $userPostTypes = \Vvveb\get_setting($this->type, 'types', []);+ $userPostTypes = \Vvveb\getSetting($this->type, 'types', []);if ($userType) {//edit@@ -54,7 +54,7 @@ class PostType extends Base {$userPostTypes[$postType['type']] = $postType;}- $userPostTypes = \Vvveb\set_setting($this->type, 'types', $userPostTypes);+ $userPostTypes = \Vvveb\setSetting($this->type, 'types', $userPostTypes);$successMessage = humanReadable(__($this->type)) . ' ' . __('type saved!');$this->view->success[] = $successMessage;@@ -70,7 +70,7 @@ class PostType extends Base {function index() {$type = ucfirst($this->type);- $userPostTypes = \Vvveb\get_setting($this->type, 'types', []);+ $userPostTypes = \Vvveb\getSetting($this->type, 'types', []);$userType = $this->request->get['type'] ?? false;$customType = [];diff --git a/admin/controller/settings/post-types.php b/admin/controller/settings/post-types.phpindex c38b565..a8f65d1 100644--- a/admin/controller/settings/post-types.php+++ b/admin/controller/settings/post-types.php@@ -32,7 +32,7 @@ class PostTypes extends Listing {$userType = $this->request->get['type'] ?? false;if ($userType) {- $userPostTypes = \Vvveb\get_setting($this->type, 'types', []);+ $userPostTypes = \Vvveb\getSetting($this->type, 'types', []);if ($userPostTypes) {if (! is_array($userType)) {@@ -44,7 +44,7 @@ class PostTypes extends Listing {unset($userPostTypes[$type]);}}- $userPostTypes = \Vvveb\set_setting($this->type, 'types', $userPostTypes);+ $userPostTypes = \Vvveb\setSetting($this->type, 'types', $userPostTypes);}}@@ -77,7 +77,7 @@ class PostTypes extends Listing {list($pluginTypes) = Event::trigger('Vvveb\Controller\Base', "custom$type", []);array_walk($pluginTypes, function (&$type,$key) {$type['source'] = 'plugin'; $type['name'] = ucfirst($key); });- $userTypes = \Vvveb\get_setting($this->type, 'types', []);+ $userTypes = \Vvveb\getSetting($this->type, 'types', []);$params = ['module' => "settings/{$this->type}-type"];$paramsList = ['module' => "settings/{$this->type}-types"];diff --git a/admin/controller/settings/settings.php b/admin/controller/settings/settings.phpindex 5b5d11f..cdad11d 100755--- a/admin/controller/settings/settings.php+++ b/admin/controller/settings/settings.php@@ -35,7 +35,7 @@ class Settings extends Base {if ($settings /*&&($errors = $validator->validate($settings)) === true*/) {//$settings = $validator->filter($settings);- $results = \Vvveb\set_settings('settings',$settings);+ $results = \Vvveb\setMultiSetting('settings',$settings);if ($results) {$this->view->success[] = __('Settings saved!');diff --git a/admin/controller/settings/shipping.php b/admin/controller/settings/shipping.phpindex e08179c..ace6f06 100755--- a/admin/controller/settings/shipping.php+++ b/admin/controller/settings/shipping.php@@ -39,7 +39,7 @@ class Shipping extends Base {if ($settings &&($errors = $validator->validate($settings)) === true) {$settings = $validator->filter($settings);- $results = \Vvveb\set_settings('shipping',$settings);+ $results = \Vvveb\setMultiSetting('shipping',$settings);$this->view->success[] = __('Settings saved!');} else {$this->view->errors = $errors;diff --git a/admin/controller/settings/site.php b/admin/controller/settings/site.phpindex 1cd699c..6f90241 100755--- a/admin/controller/settings/site.php+++ b/admin/controller/settings/site.php@@ -28,6 +28,7 @@ use Vvveb\Sql\CountrySQL;use Vvveb\Sql\regionSQL;use Vvveb\Sql\SiteSQL;use Vvveb\System\CacheManager;+use Vvveb\System\Event;use Vvveb\System\Extensions\Themes;use Vvveb\System\Images;use Vvveb\System\Sites;@@ -116,8 +117,8 @@ class Site extends Base {$site['key'] = strtolower(Sites::siteKey($site['host']));- if (isset($this->request->get['site_id'])) {- $data['site_id'] = (int)$this->request->get['site_id'];+ if (isset($this->request->get['site_id']) && ($site_id = $this->request->get['site_id'])) {+ $data['site_id'] = (int)$site_id;$site['settings'] = json_encode($settings);$data['site'] = $site;$site['id'] = $data['site_id'];@@ -128,6 +129,8 @@ class Site extends Base {Sites::setSiteDataById($data['site_id'], null, $site);+ list($data, $settings, $site_id) = Event :: trigger(__CLASS__,__FUNCTION__, $data, $settings, $site_id);+if ($result >= 0) {//CacheManager::delete('site');CacheManager::delete();@@ -141,19 +144,21 @@ class Site extends Base {$data['site'] = $site;$data['site']['settings'] = json_encode($settings);$return = $sites->add($data);- $id = $return['site'];+ $site_id = $return['site'];$site['state'] = 'live';$site['id'] = $id;Sites::saveSite($site);- if (! $id) {+ list($site, $setting, $site_id, $data) = Event :: trigger(__CLASS__,__FUNCTION__, $site, $setting, $site_id, $data);++ if (! $site_id) {$view->errors = [$sites->error];} else {//CacheManager::delete('site');CacheManager::delete();$message = __('Site saved!');$view->success = [$message];- $this->redirect(['module'=>'settings/site', 'success'=> $message, 'site_id' => $id]);+ $this->redirect(['module'=>'settings/site', 'success'=> $message, 'site_id' => $site_id]);}}} else {@@ -189,7 +194,7 @@ class Site extends Base {}$data = $siteSql->getData(($setting ?? []) + $this->global);- $data['complete_status_id'] = $data['processing_status_id'] = $data['order_status_id'];+ $data['complete_status_id'] = $data['processing_status_id'] = ($data['order_status_id'] ?? 1);$data['timezone'] = [];@@ -220,6 +225,8 @@ class Site extends Base {$data['time_format'][$format] = date($format);}+ list($site, $setting, $site_id, $data) = Event :: trigger(__CLASS__,__FUNCTION__, $site, $setting, $site_id, $data);+if (! defined('CLI')) {$view->domain = '';diff --git a/admin/controller/settings/taxonomy.php b/admin/controller/settings/taxonomy.phpindex ff910a9..d215833 100644--- a/admin/controller/settings/taxonomy.php+++ b/admin/controller/settings/taxonomy.php@@ -39,13 +39,13 @@ class Taxonomy extends Crud {$this->view->type = ['categories' => __('Categories'), 'tags' => __('Tags')];$postType = ['post' => __('Post'), 'page' => __('Page'), 'product' => __('product')];- $userPostTypes = \Vvveb\get_setting('post', 'types', []);+ $userPostTypes = \Vvveb\getSetting('post', 'types', []);list($pluginPostTypes) = Event::trigger('Vvveb\Controller\Base', 'customPost', []);$customPost = $userPostTypes + $pluginPostTypes;array_walk($customPost, fn (&$type, $key) => $type = ucfirst($key));$postType += $customPost;- $userProductTypes = \Vvveb\get_setting('product', 'types', []);+ $userProductTypes = \Vvveb\getSetting('product', 'types', []);list($pluginProductTypes) = Event::trigger('Vvveb\Controller\Base', 'customProduct', []);$customProduct = $userProductTypes + $pluginProductTypes;array_walk($customProduct, fn (&$type, $key) => $type = ucfirst($key));diff --git a/system/extensions/plugins.php b/system/extensions/plugins.phpindex 4d68da1..4ecfb89 100755--- a/system/extensions/plugins.php+++ b/system/extensions/plugins.php@@ -81,14 +81,14 @@ class Plugins extends Extensions {if (file_exists($file)) {$key = "plugins.$site_id.$pluginName.status";- $status = \Vvveb\get_config($key);+ $status = \Vvveb\getConfig($key);if (! $status) {//if no plugin info then this is first activation, run plugin setupEvent :: trigger(__CLASS__, 'setup', $pluginName, $site_id);}- $return = \Vvveb\set_config($key, 'active');+ $return = \Vvveb\setConfig($key, 'active');Event :: trigger(__CLASS__, __FUNCTION__, $pluginName, $site_id);self :: clearPluginsCache($site_id);@@ -105,10 +105,10 @@ class Plugins extends Extensions {return;}$key = "plugins.$site_id.$pluginName.status";- $return = \Vvveb\set_config($key, 'inactive');+ $return = \Vvveb\setConfig($key, 'inactive');/*$key = "plugins.$site_id.$pluginName";- $return = \Vvveb\unset_config($key, []);+ $return = \Vvveb\unsetConfig($key, []);*/Event :: trigger(__CLASS__, __FUNCTION__, $pluginName, $site_id);@@ -150,7 +150,7 @@ class Plugins extends Extensions {$success = rrmdir($pluginDir);$key = "plugins.$site_id.$pluginName";- \Vvveb\unset_config($key, []);+ \Vvveb\unsetConfig($key, []);self :: clearPluginsCache($site_id);Event :: trigger(__CLASS__, __FUNCTION__, $pluginName, $success);diff --git a/system/functions.php b/system/functions.phpindex 39eabf3..3d23308 100755--- a/system/functions.php+++ b/system/functions.php@@ -87,32 +87,80 @@ function config($key = null, $default = null) {return System\Config::getInstance()->get($key, $default);}-function get_config($key = null, $default = null) {+function getConfig($key = null, $default = null) {return System\Config::getInstance()->get($key, $default);}-function set_config($key, $value = null) {+function setConfig($key, $value = null) {return System\Config::getInstance()->set($key, $value);}-function unset_config($key) {+function unsetConfig($key) {return System\Config::getInstance()->unset($key);}-function get_setting($namespace, $key = null, $default = null, $site_id = SITE_ID) {+//setting+function getSetting($namespace, $key = null, $default = null, $site_id = SITE_ID) {return System\Setting::getInstance()->get($namespace, $key, $default, $site_id);}-function set_setting($namespace, $key = null, $value = null, $site_id = SITE_ID) {+function setSetting($namespace, $key = null, $value = null, $site_id = SITE_ID) {return System\Setting::getInstance()->set($namespace, $key, $value, $site_id);}-function delete_setting($namespace, $key = null, $site_id = SITE_ID) {+function deleteSetting($namespace, $key = null, $site_id = SITE_ID) {return System\Setting::getInstance()->delete($namespace, $key, $value, $site_id);}-function set_settings($namespace, $settings, $site_id = SITE_ID) {- return System\Setting::getInstance()->multiSet($namespace, $settings, $site_id);+function setMultiSetting($namespace, $settings, $site_id = SITE_ID) {+ return System\Setting::getInstance()->setMulti($namespace, $settings, $site_id);+}++//setting content+function getMultiSettingContent($site_id, $namespace, $key = null, $default = null, $language_id = false) {+ return System\Meta\SettingContent::getInstance()->getMulti($site_id, $namespace, $key, $default, $language_id);+}++function setMultiSettingContent($site_id, $meta) {+ return System\Meta\SettingContent::getInstance()->setMulti($site_id, $meta);+}++// post meta+function getPostMeta($post_id, $namespace, $key = null, $default = null) {+ return System\Meta\PostMeta::getInstance()->get($post_id, $namespace, $key, $default);+}++function setPostMeta($post_id, $namespace, $key = null, $value = null) {+ return System\Meta\PostMeta::getInstance()->set($post_id, $namespace, $key, $value);+}++function deletePostMeta($post_id, $namespace, $key = null) {+ return System\Meta\PostMeta::getInstance()->delete($post_id, $namespace, $key, $value);+}++function setMultiPostMeta($post_id, $namespace, $meta) {+ return System\Meta\PostMeta::getInstance()->setMulti($post_id, $namespace, $meta);+}++// post meta content+function getPostContentMeta($post_id, $namespace, $key = null, $default = null, $language_id = false) {+ return System\Meta\PostContentMeta::getInstance()->get($post_id, $namespace, $key, $default, $language_id);+}++function getMultiPostContentMeta($post_id, $namespace, $key = null, $default = null, $language_id = false) {+ return System\Meta\PostContentMeta::getInstance()->getMulti($post_id, $namespace, $key, $default, $language_id);+}++function setPostContentMeta($post_id, $namespace, $key = null, $value = null, $language_id = false) {+ return System\Meta\PostContentMeta::getInstance()->set($post_id, $namespace, $key, $value, $language_id);+}++function deletePostContentMeta($post_id, $namespace, $key = null, $language_id = false) {+ return System\Meta\PostContentMeta::getInstance()->delete($post_id, $namespace, $key, $value, $language_id);+}++function setMultiPostContentMeta($post_id, $meta) {+ return System\Meta\PostContentMeta::getInstance()->setMulti($post_id, $meta);}function getCurrentTemplate() {@@ -431,11 +479,15 @@ if (function_exists('_')) {function __($text, $plural = false, $count = false) {global $vvvebTranslationDomains;+ $text = substr($text, 0, 1024);+if ($plural) {+ $plural = substr($plural, 0, 1024);+foreach ($vvvebTranslationDomains as $domain) {$translation = dngettext($domain, $text, $plural, $count);- if ($translation != $text) {+ if ($translation && ($translation != $text)) {break;}}@@ -443,7 +495,7 @@ if (function_exists('_')) {foreach ($vvvebTranslationDomains as $domain) {$translation = dgettext($domain, $text);- if ($translation != $text) {+ if ($translation && ($translation != $text)) {break;}}@@ -670,9 +722,9 @@ function getActionName() {* @return* The new array if the key exists, otherwise the unchanged array.*- * @see array_insert_after()+ * @see arrayInsertAfter()*/-function array_insert_before($key, array &$array, $new_key, $new_value) {+function arrayInsertBefore($key, array &$array, $new_key, $new_value) {if (array_key_exists($key, $array)) {$new = [];@@ -704,9 +756,9 @@ function array_insert_before($key, array &$array, $new_key, $new_value) {* @return* The new array if the key exists, otherwise the unchanged array.*- * @see array_insert_after()+ * @see arrayInsertAfter()*/-function array_insert_array_before($key, array &$array, $new_array) {+function arrayInsertArrayBefore($key, array &$array, $new_array) {if (array_key_exists($key, $array)) {$new = [];@@ -738,9 +790,9 @@ function array_insert_array_before($key, array &$array, $new_array) {* @return* The new array if the key exists, otherwise the unchanged array.*- * @see array_insert_before()+ * @see arrayInsertBefore()*/-function array_insert_after($key, array &$array, $new_key, $new_value) {+function arrayInsertAfter($key, array &$array, $new_key, $new_value) {if (array_key_exists($key, $array)) {$new = [];@@ -773,9 +825,9 @@ function array_insert_after($key, array &$array, $new_key, $new_value) {* @return* The new array if the key exists, otherwise the unchanged array.*- * @see array_insert_before()+ * @see arrayInsertBefore()*/-function array_insert_array_after($key, array &$array, $new_array) {+function arrayInsertArrayAfter($key, array &$array, $new_array) {if (array_key_exists($key, $array)) {$new = [];@@ -807,7 +859,7 @@ function isEditor() {return isset($_GET['r']);}-function log_error($message) {+function logError($message) {error_log($message);}@@ -818,7 +870,7 @@ function getThemeFolderList($theme = false) {$theme = \Vvveb\System\Sites::getTheme() ?? 'default';}- $themeFolder = DIR_THEMES . DS . $theme;+ $themeFolder = DIR_THEMES . $theme;$files = glob("$themeFolder/*", GLOB_ONLYDIR);$pages['/'] = ['name' => '/', 'title' => '/', 'filename' => '/', 'file' => '/', 'path' => '/', 'folder' => $theme];@@ -862,8 +914,10 @@ function getTemplateList($theme = null, $skip = []) {$theme = \Vvveb\System\Sites::getTheme() ?? 'default';}$pages = [];- $themeFolder = DIR_THEMES . DS . $theme;- $files = glob("$themeFolder/{,*/*/,*/}*.html", GLOB_BRACE);+ $themeFolder = DIR_THEMES . $theme;+ //$files = glob("$themeFolder/{,*/*/,*/}*.html", GLOB_BRACE);+ $glob = ['', '*/*/', '*/'];+ $files = globBrace($themeFolder, $glob, '*.html');foreach ($files as $file) {$file = preg_replace('@^.*/themes/[^/]+/@', '', $file);@@ -903,6 +957,10 @@ function getTemplateList($theme = null, $skip = []) {}function sanitizeFileName($file) {+ if (! $file) {+ return $file;+ }+//sanitize, remove double dot .. and remove get parameters if any$file = preg_replace('@\?.*$|\.{2,}|[^\/\\a-zA-Z0-9\-\._]@' , '', $file);$file = preg_replace('@[^\/\w\s\d\.\-_~,;:\[\]\(\)\\]|[\.]{2,}@', '', $file);@@ -1180,7 +1238,7 @@ function getLanguage() {return session('language', 'en_US');}-function siteSettings($site_id = SITE_ID) {+function siteSettings($site_id = SITE_ID, $language_id = false) {$cache = System\Cache::getInstance();$site = $cache->cache(APP,'site.' . $site_id, function () use ($site_id) {$siteSql = new Sql\SiteSQL();@@ -1202,6 +1260,10 @@ function siteSettings($site_id = SITE_ID) {return [];}, 259200);+ if ($language_id && $site) {+ $site['description'] = $site['description'][$language_id] ?? $site['description'][1] ?? '';+ }+return $site;}@@ -1262,8 +1324,8 @@ function email($to, $subject, $template, $data = [], $config = []) {}//get site contact email for sender and reply to- $site = siteSettings();- $sender = $config['sender'] ?? $site['title'];+ $site = siteSettings(SITE_ID, session('language_id') ?? 1);+ $sender = $config['sender'] ?? $site['description']['title'];$from = $config['from'] ?? $site['contact-email'];$reply = $config['reply'] ?? $site['contact-email'];@@ -1508,7 +1570,7 @@ function globBrace($path, $glob, $filename = '') {//$glob = ['*','*/*','*/*/*'];$files = [];- if (false && defined('GLOB_BRACE')) {+ if (defined('GLOB_BRACE')) {$path .= '{' . implode(',', $glob) . '}' . $filename;$files = glob($path, GLOB_BRACE);} else {diff --git a/system/meta/meta.php b/system/meta/meta.phpnew file mode 100644index 0000000..ee82992--- /dev/null+++ b/system/meta/meta.php@@ -0,0 +1,156 @@+<?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/>.+ *+ */++namespace Vvveb\System\Meta;++use function Vvveb\model;++class Meta {+ private $setting = [];++ protected $settingSql;++ private static $instance;++ protected $model;++ protected $item_id;++ public static function getInstance() {+ if (static::$instance) {+ return static::$instance;+ } else {+ return static::$instance = new static();+ }+ }++ function __construct() {+ $this->settingSql = model($this->model);+ }++ public function getMulti($item_id, $namespace, $key = null, $default = null, $language_id = false) {+ if ($key && ! is_array($key)) {+ $key = [$key];+ }++ $result = $this->settingSql->getMulti([$this->item_id => $item_id, 'namespace' => $namespace, 'key' => $key, 'language_id' => $language_id]);++ $return = [];++ if ($result) {+ foreach ($result as &$value) {+ $val = &$value['value'];++ if ($val && is_string($val) && $val[0] == '{') {+ $json = json_decode($val, true);+ $val = $json ?: $val;+ }+ }++ $return = $result;+ } else {+ $return = [];++ if (is_array($key)) {+ foreach ($key as $value) {+ $return[$value] = $default;+ }+ } else {+ return $default;+ }+ }++ return $return;+ }++ public function get($item_id, $namespace, $key = null, $default = null, $language_id = false) {+ if (! $namespace && ! $key) {+ return $default;+ }++ if (is_array($key) || empty($key)) {+ $this->getMulti($item_id, $namespace, $key, $default, $language_id);+ } else {+ if (isset($this->setting[$namespace][$key])) {+ return $this->setting[$namespace][$key];+ }++ $result = $this->settingSql->get([$this->item_id => $item_id, 'namespace' => $namespace, 'key' => $key, 'language_id' => $language_id]) ?? $default;++ if ($result && is_string($result) && $result[0] == '{') {+ $json = json_decode($result, true);+ $result = $json ?: $result;+ }++ return $result;+ }+ }++ public function set($item_id, $namespace, $key, $value, $language_id = false) {+ if (! $namespace || ! $key) {+ return $default;+ }++ $this->setting[$namespace][$key] = $value;++ if (is_array($value)) {+ $value = json_encode($value);+ }++ return $this->settingSql->set([$this->item_id => $item_id, 'namespace' => $namespace, 'key' => $key, 'value' => $value, 'language_id' => $language_id]);+ }++ public function delete($item_id, $namespace, $key, $value, $language_id = false) {+ if (! $namespace || ! $key) {+ return $default;+ }++ unset($this->setting[$namespace][$key]);++ return $this->settingSql->delete([$this->item_id => $item_id, 'namespace' => $namespace, 'key' => $key, 'language_id' => $language_id]);+ }++ public function setMulti($item_id, $meta) {+ $result = false;++ foreach ($meta as &$item) {+ if (is_array($item['value'])) {+ $item['value'] = json_encode($item['value']);+ }+ }++ $result = $this->settingSql->setMulti([$this->item_id => $item_id, 'meta' => $meta]);++ if ($meta) {+ /*+ foreach ($meta as $key => $value) {+ if (is_array($value)) {+ $value = json_encode($value);+ }+ $this->setting[$namespace][$key] = $value;+ $result = $this->settingSql->set([$this->item_id => $item_id, 'namespace' => $namespace, 'key' => $key, 'value' => $value, 'site_id' => $site_id, 'language_id' => $language_id]);+ }*/+ }++ return $result;+ }+}diff --git a/system/meta/post-content-meta.php b/system/meta/post-content-meta.phpnew file mode 100644index 0000000..bcfbf9e--- /dev/null+++ b/system/meta/post-content-meta.php@@ -0,0 +1,29 @@+<?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/>.+ *+ */++namespace Vvveb\System\Meta;++class PostContentMeta extends Meta {+ protected $model = 'post_content_meta';++ protected $item_id = 'post_id';+}diff --git a/system/meta/post-meta.php b/system/meta/post-meta.phpnew file mode 100644index 0000000..b85030c--- /dev/null+++ b/system/meta/post-meta.php@@ -0,0 +1,29 @@+<?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/>.+ *+ */++namespace Vvveb\System\Meta;++class PostMeta extends Meta {+ protected $model = 'post_meta';++ protected $item_id = 'post_id';+}diff --git a/system/meta/setting-content.php b/system/meta/setting-content.phpnew file mode 100644index 0000000..7a76fd1--- /dev/null+++ b/system/meta/setting-content.php@@ -0,0 +1,29 @@+<?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/>.+ *+ */++namespace Vvveb\System\Meta;++class SettingContent extends Meta {+ protected $model = 'setting_content';++ protected $item_id = 'site_id';+}diff --git a/system/setting.php b/system/setting.phpindex 3d21662..6eab9dd 100755--- a/system/setting.php+++ b/system/setting.php@@ -49,7 +49,7 @@ class Setting {}if (is_array($key) || empty($key)) {- $result = $this->settingSql->getSettings(['namespace' => $namespace, 'key' => $key, 'site_id' => $site_id]);+ $result = $this->settingSql->getMulti(['namespace' => $namespace, 'key' => $key, 'site_id' => $site_id]);if ($result) {$return = [];@@ -83,7 +83,7 @@ class Setting {return $this->setting[$namespace][$key];}- $result = $this->settingSql->getSetting(['namespace' => $namespace, 'key' => $key, 'site_id' => $site_id]) ?? $default;+ $result = $this->settingSql->get(['namespace' => $namespace, 'key' => $key, 'site_id' => $site_id]) ?? $default;if ($result && is_string($result) && $result[0] == '{') {$json = json_decode($result, true);@@ -105,7 +105,7 @@ class Setting {$value = json_encode($value);}- return $this->settingSql->setSetting(['namespace' => $namespace, 'key' => $key, 'value' => $value, 'site_id' => $site_id]);+ return $this->settingSql->set(['namespace' => $namespace, 'key' => $key, 'value' => $value, 'site_id' => $site_id]);}public function delete($namespace, $key, $value, $site_id = SITE_ID) {@@ -118,21 +118,31 @@ class Setting {return $this->settingSql->delete(['namespace' => $namespace, 'key' => $key, 'site_id' => $site_id]);}- public function multiSet($namespace, $settings, $site_id = SITE_ID) {+ public function setMulti($namespace, $settings, $site_id = SITE_ID) {if (! $site_id) {$site_id = 0;}$result = false;+ foreach ($settings as &$item) {+ if (is_array($item)) {+ $item = json_encode($item);+ }+ }++ $result = $this->settingSql->setMulti(['site_id' => $site_id, 'namespace' => $namespace, 'settings' => $settings]);+if ($settings) {+ /*foreach ($settings as $key => $value) {if (is_array($value)) {$value = json_encode($value);}$this->setting[$namespace][$key] = $value;- $result = $this->settingSql->setSetting(['namespace' => $namespace, 'key' => $key, 'value' => $value, 'site_id' => $site_id]);+ $result = $this->settingSql->set(['namespace' => $namespace, 'key' => $key, 'value' => $value, 'site_id' => $site_id]);}+ */}return $result;diff --git a/system/sites.php b/system/sites.phpindex 6b4d692..253d490 100755--- a/system/sites.php+++ b/system/sites.php@@ -199,11 +199,11 @@ class Sites {//key has changed replace siteif (isset($value['key']) && ($value['key'] != $site['key'])) {- $config = \Vvveb\get_config($key);+ $config = \Vvveb\getConfig($key);if ($config) {$value += $config;- $config = \Vvveb\unset_config($key);+ $config = \Vvveb\unsetConfig($key);$key = "sites.{$value['key']}";}}@@ -212,7 +212,7 @@ class Sites {$key .= ".$name";}- return \Vvveb\set_config($key, $value);+ return \Vvveb\setConfig($key, $value);}return false;@@ -230,7 +230,7 @@ class Sites {$key .= ".$name";}- return \Vvveb\set_config($key, $value);+ return \Vvveb\setConfig($key, $value);}return false;@@ -294,11 +294,11 @@ class Sites {public static function saveSite($site) {$key = self :: siteKey(trim($site['key'] ?? $site['host']));unset($site['key']);- $return = \Vvveb\set_config("sites.$key", $site);+ $return = \Vvveb\setConfig("sites.$key", $site);}public static function deleteSite($site) {$key = self :: siteKey(trim($site['key'] ?? $site['host']));- $return = \Vvveb\unset_config("sites.$key", $site);+ $return = \Vvveb\unsetConfig("sites.$key", $site);}}