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
Theme and plugin marketplace categories filter and search
givanz0887e76d991d
diff --git a/admin/controller/plugin/market.php b/admin/controller/plugin/market.phpindex abea4c8..e0310d6 100755--- a/admin/controller/plugin/market.php+++ b/admin/controller/plugin/market.php@@ -24,13 +24,14 @@ namespace Vvveb\Controller\Plugin;use function Vvveb\__;use Vvveb\Controller\Base;+use Vvveb\System\CacheManager;use Vvveb\System\Core\View;use Vvveb\System\Extensions\Plugins;use Vvveb\System\Validator;class Market extends Base {function install() {- $slug = $this->request->get['slug'];+ $slug = $this->request->post['slug'] ?? false;try {if ($slug) {@@ -49,6 +50,7 @@ class Market extends Base {$this->view->log[] = sprintf(__('Unpacking "%s"'), $tempFile);if (Plugins :: install($tempFile, $slug)) {+ CacheManager::clearObjectCache('vvveb', 'plugins_list_' . $this->global['site_id']);$pluginName = \Vvveb\humanReadable($slug);$pluginName = "<b>$pluginName</b>";$pluginActivateUrl = \Vvveb\url(['module' => 'plugin/plugins', 'action'=> 'activate', 'plugin' => $slug]);@@ -56,7 +58,7 @@ class Market extends Base {$successMessage = sprintf(__('Plugin %s was successfully installed!'), $pluginName, $pluginActivateUrl);$this->view->log[] = $successMessage;- $successMessage .= "<a class='btn btn-primary btn-sm m-2' href='$pluginActivateUrl'>" . __('Activate plugin') . '</a>';+ $successMessage .= "<button class='btn btn-primary btn-sm m-2' formaction='$pluginActivateUrl' name='plugin' value='$slug'>" . __('Activate plugin') . '</button>';$this->view->success[] = $successMessage;} else {$error = sprintf(__('Error installing "%s"!'), $slug);@@ -95,14 +97,15 @@ class Market extends Base {$validator = new Validator(['plugins']);//allow only fields that are in the validator list and remove the rest- $request = $validator->filter($this->request->get);+ $request = array_filter($validator->filter($this->request->get));$plugins = [];$request['limit'] = $this->view->limit = 8;try {- $plugins = Plugins :: getMarketList($request);- $installed = Plugins :: getList($this->global['site_id']);+ $plugins = Plugins :: getMarketList($request);+ $categories = Plugins :: getMarketCategories(['limit' => 100] + $request, 'categories');+ $installed = Plugins :: getList($this->global['site_id']);foreach ($plugins['plugins'] as &$plugin) {$plugin['installed'] = isset($installed[$plugin['slug']]);@@ -117,6 +120,8 @@ class Market extends Base {$admin_path = \Vvveb\adminPath();$view->installUrl = $admin_path . 'index.php?module=plugin/market&action=install&json';+ $view->categories = $categories['categories'];+ $view->set($request);$view->set($plugins);}}diff --git a/admin/controller/plugin/plugins.php b/admin/controller/plugin/plugins.phpindex 049e829..23084cb 100755--- a/admin/controller/plugin/plugins.php+++ b/admin/controller/plugin/plugins.php@@ -37,24 +37,32 @@ class Plugins extends Base {function init() {parent::init();- $this->plugin = $this->request->get['plugin'] ?? null;+ $this->plugin = $this->request->post['plugin'] ?? null;}function deactivate() {- $global = $this->request->get['plugin'] ?? false;-if (PluginsList::deactivate($this->plugin, $this->global['site_id'])) {- $this->view->success[] = sprintf(__('Plugin `%s` deactivated!'), \Vvveb\humanReadable($this->plugin));+ $this->view->success[] = sprintf(__('Plugin `%s` deactivated!'), '<b>' . \Vvveb\humanReadable($this->plugin) . '</b>');+ CacheManager::clearObjectCache('admin-menu');CacheManager::clearCompiledFiles();+ CacheManager::clearPageCache();+ } else {+ $this->view->errors[] = sprintf(__('Error deactivating plugin `%s`!'), '<b>' . \Vvveb\humanReadable($this->plugin) . '</b>');}return $this->index();}function checkPluginAndActivate() {- $global = $this->request->get['plugin'] ?? false;+ //allow plugin activation through get parameter if csrf is provided+ if (($csrf = $this->request->get['csrf'] ?? false) &&+ ($plugin = $this->request->get['plugin'] ?? null) &&+ ($csrf == $this->session->get('csrf'))) {+ $this->plugin = $plugin;+ }+$this->category = $this->request->get['category'] ?? false;- $this->pluginCheckUrl = \Vvveb\url(['module' => 'plugin/plugins', 'action'=> 'activate', 'plugin' => $this->plugin, 'category' => $this->category]);+ $this->pluginCheckUrl = \Vvveb\url(['module' => 'plugin/plugins', 'action'=> 'activate', 'plugin' => $this->plugin, 'category' => $this->category, 'csrf' => $this->session->get('csrf')]);$this->view->checkPluginUrl = $this->pluginCheckUrl;$this->view->info[] = sprintf(__('Activating %s plugin ...'), '<b>' . \Vvveb\humanReadable($this->plugin) . '</b> <span class="spinner-border spinner-border-sm align-middle" role="status" aria-hidden="true"></span>');@@ -71,25 +79,27 @@ class Plugins extends Base {}function delete() {- try {- if (PluginsList::uninstall($this->plugin, $this->global['site_id'])) {- $this->view->success[] = sprintf(__('Plugin "%s" removed!'), \Vvveb\humanReadable($this->plugin));- } else {- $this->view->errors[] = sprintf(__('Error removing "%s" plugin!'), \Vvveb\humanReadable($this->plugin));- }+ if ($this->plugin) {+ try {+ if (PluginsList::uninstall($this->plugin, $this->global['site_id'])) {+ $this->view->success[] = sprintf(__('Plugin "%s" removed!'), \Vvveb\humanReadable($this->plugin));+ } else {+ $this->view->errors[] = sprintf(__('Error removing "%s" plugin!'), \Vvveb\humanReadable($this->plugin));+ }- /*- //remove plugin public files if any- rrmdir(DIR_PUBLIC . DS . 'plugins' . DS . $this->plugin);+ /*+ //remove plugin public files if any+ rrmdir(DIR_PUBLIC . DS . 'plugins' . DS . $this->plugin);- if (rrmdir(DIR_PLUGINS . $this->plugin)) {- $this->view->success[] = sprintf(__('Plugin "%s" removed!'), \Vvveb\humanReadable($this->plugin));- } else {- $this->view->errors[] = sprintf(__('Error removing "%s" plugin!'), \Vvveb\humanReadable($this->plugin));+ if (rrmdir(DIR_PLUGINS . $this->plugin)) {+ $this->view->success[] = sprintf(__('Plugin "%s" removed!'), \Vvveb\humanReadable($this->plugin));+ } else {+ $this->view->errors[] = sprintf(__('Error removing "%s" plugin!'), \Vvveb\humanReadable($this->plugin));+ }+ */+ } catch (\Exception $e) {+ $this->view->errors[] = sprintf(__('Error removing "%s" plugin!'), \Vvveb\humanReadable($this->plugin)) . ' - ' . $e->getMessage();}- */- } catch (\Exception $e) {- $this->view->errors[] = sprintf(__('Error removing "%s" plugin!'), \Vvveb\humanReadable($this->plugin)) . ' - ' . $e->getMessage();}return $this->index();@@ -118,9 +128,9 @@ class Plugins extends Base {if ($this->pluginSlug) {$this->pluginName = \Vvveb\humanReadable($this->pluginSlug);$this->pluginName = "<b>$this->pluginName</b>";- $this->pluginActivateUrl = \Vvveb\url(['module' => 'plugin/plugins', 'action'=> 'checkPluginAndActivate', 'plugin' => $this->pluginSlug]);+ $this->pluginActivateUrl = \Vvveb\url(['module' => 'plugin/plugins', 'action'=> 'checkPluginAndActivate', 'plugin' => $this->pluginSlug, 'csrf' => $this->session->get('csrf')]);$successMessage = sprintf(__('Plugin %s was successfully installed!'), $this->pluginName, $this->pluginActivateUrl);- $successMessage .= "<p><a class='btn btn-primary btn-sm m-2' href='{$this->pluginActivateUrl}'>" . __('Activate plugin') . '</a></p>';+ $successMessage .= "<a class='btn btn-primary btn-sm m-2' href='{$this->pluginActivateUrl}'>" . __('Activate plugin') . '</a>';$this->view->success[] = $successMessage;} else {$errorMessage = sprintf(__('Failed to install %s plugin!'), $this->pluginName);@@ -136,7 +146,13 @@ class Plugins extends Base {header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');header('Cache-Control: post-check=0, pre-check=0', false);header('Pragma: no-cache');- $this->category = $this->request->get['category'] ?? false;+ $this->category = $this->request->get['category'] ?? false;+ $this->plugin = $this->request->post['plugin'] ?? $this->request->get['plugin'] ?? null;+ $csrf = $this->request->post['csrf'] ?? $this->request->get['csrf'] ?? false;++ if ($csrf != $this->session->get('csrf')) {+ die('Invalid csrf!');+ }$active = false;$error = false;@@ -163,12 +179,20 @@ class Plugins extends Base {if ($active) {$refreshUrl = \Vvveb\url(['module' => 'plugin/plugins', 'cache' => false, 'category' => $this->category], false) . '&t=' . time();- $success = sprintf(__('Plugin `%s` activated!'), \Vvveb\humanReadable($this->plugin));+ $success = sprintf(__('Plugin `%s` activated!'), '<b>' . \Vvveb\humanReadable($this->plugin) . '</b>');+ $plugin = PluginsList :: getList($this->global['site_id'])[$this->plugin] ?? [];++ if (isset($plugin['settings']) && $plugin['settings']) {+ $success .= "<a class='btn btn-primary btn-sm m-2' href='{$plugin['settings']}'>" . __('Settings') . '</a>';+ }+ $this->session->set('success', $success);ignore_user_abort(1);clearstatcache(true);+ CacheManager::clearObjectCache('admin-menu');CacheManager::clearCompiledFiles();+ CacheManager::clearPageCache();if (defined('CLI')) {$this->view->success = [$success];@@ -178,7 +202,8 @@ class Plugins extends Base {<head><script>function reloadPage() {- setTimeout(() => parent.location='$refreshUrl&success=$success', 100);+ //setTimeout(() => parent.location='$refreshUrl&success=$success', 100);+ setTimeout(() => parent.location='$refreshUrl', 100);}</script></head>@@ -189,7 +214,7 @@ class Plugins extends Base {die($response);}} else {- die(__('Error activating plugin!') . '<br/>' . __('Check config file permissions!'));+ die(sprintf(__('Error activating plugin `%s`!'), $this->plugin) . '<br/>' . __('Check config file permissions!'));}return false;diff --git a/admin/controller/theme/market.php b/admin/controller/theme/market.phpindex a63dddc..1ac03e1 100755--- a/admin/controller/theme/market.php+++ b/admin/controller/theme/market.php@@ -24,13 +24,14 @@ namespace Vvveb\Controller\Theme;use function Vvveb\__;use Vvveb\Controller\Base;+use Vvveb\System\CacheManager;use Vvveb\System\Core\View;use Vvveb\System\Extensions\Themes;use Vvveb\System\Validator;class Market extends Base {function install() {- $slug = $this->request->get['slug'];+ $slug = $this->request->post['slug'] ?? false;try {if ($slug) {@@ -49,6 +50,8 @@ class Market extends Base {$this->view->log[] = sprintf(__('Unpacking "%s"'), $tempFile);if (Themes :: install($tempFile, $slug, false)) {+ CacheManager::clearObjectCache('vvveb', 'themes_list_' . $this->global['site_id']);+$themeName = \Vvveb\humanReadable($slug);$themeName = "<b>$themeName</b>";$themeActivateUrl = \Vvveb\url(['module' => 'theme/themes', 'action'=> 'activate', 'theme' => $slug]);@@ -56,7 +59,7 @@ class Market extends Base {$successMessage = sprintf(__('Theme %s was successfully installed!'), $themeName, $themeActivateUrl);$this->view->log[] = $successMessage;- $successMessage .= "<a class='btn btn-primary btn-sm m-2' href='$themeActivateUrl'>" . __('Activate theme') . '</a>';+ $successMessage .= "<button class='btn btn-primary btn-sm m-2' formaction='$themeActivateUrl' name='theme' value='$slug'>" . __('Activate theme') . '</button>';$this->view->success[] = $successMessage;} else {$error = sprintf(__('Error installing "%s"!'), $slug);@@ -88,14 +91,15 @@ class Market extends Base {$validator = new Validator(['themes']);//allow only fields that are in the validator- $request = $validator->filter($this->request->get);+ $request = array_filter($validator->filter($this->request->get));$themes = [];$request['limit'] = $this->view->limit = 8;try {- $themes = Themes :: getMarketList($request);- $installed = Themes :: getList($this->global['site_id']);+ $themes = Themes :: getMarketList($request);+ $categories = Themes :: getMarketCategories(['limit' => 100] + $request, 'categories');+ $installed = Themes :: getList($this->global['site_id']);foreach ($themes['themes'] as &$theme) {$theme['installed'] = isset($installed[$theme['slug']]);@@ -109,5 +113,7 @@ class Market extends Base {}$view->set($themes);+ $view->categories = $categories['categories'];+ $view->set($request);}}diff --git a/system/extensions/extensions.php b/system/extensions/extensions.phpindex 50aa0b1..9a79d85 100755--- a/system/extensions/extensions.php+++ b/system/extensions/extensions.php@@ -242,14 +242,15 @@ abstract class Extensions {return static :: $url;}- static function getMarketList($params = []) {+ static function getMarketUrl($url, $params = [], $key = null) {$query = http_build_query($params);- $content = getUrl(static :: $feedUrl . '?' . $query);+ $content = getUrl($url . '?' . $query);if ($content) {$rss = new Rss($content);- $result[static :: $extension . 's'] = $rss->get($params['start'] ?? 1, $params['limit'] ?? 10);+ $key = $key ?? static :: $extension . 's';+ $result[$key] = $rss->get($params['start'] ?? 1, $params['limit'] ?? 10);$result['count'] = $rss->value('count');return $result;@@ -257,4 +258,12 @@ abstract class Extensions {return [];}++ static function getMarketCategories($params = [], $key = null) {+ return static :: getMarketUrl(static :: $categoriesFeedUrl, $params, $key);+ }++ static function getMarketList($params = [], $key = null) {+ return static :: getMarketUrl(static :: $feedUrl, $params, $key);+ }}diff --git a/system/extensions/plugins.php b/system/extensions/plugins.phpindex a07521c..2afda33 100755--- a/system/extensions/plugins.php+++ b/system/extensions/plugins.php@@ -32,6 +32,8 @@ class Plugins extends Extensions {static protected $feedUrl = 'https://plugins.vvveb.com/feed/plugins';+ static protected $categoriesFeedUrl = 'https://plugins.vvveb.com/feed/categories';+static protected $extension = 'plugin';static protected $loaded = false;@@ -124,7 +126,12 @@ class Plugins extends Extensions {$publicDest = DIR_PUBLIC . "plugins/$pluginName";if (! file_exists($publicDest)) {- return rcopy($publicSrc, $publicDest);+ //try symlink first+ if(symlink($publicSrc, $publicDest)){+ return true;+ } else {+ return rcopy($publicSrc, $publicDest);+ }} else {return false;}@@ -132,12 +139,14 @@ class Plugins extends Extensions {}static function install($zipFile, $slug = false, $validate = true) {- $pluginName = parent :: install($zipFile, $validate);+ if ($pluginName = parent :: install($zipFile, $validate)) {- self :: copyPublicDir($pluginName);- self :: clearPluginsCache();+ if (self :: copyPublicDir($pluginName)) {+ self :: clearPluginsCache();- return $pluginName;+ return $pluginName;+ }+ }}static function uninstall($pluginName, $site_id = SITE_ID) {diff --git a/system/extensions/themes.php b/system/extensions/themes.phpindex c2a4610..37ce01e 100755--- a/system/extensions/themes.php+++ b/system/extensions/themes.php@@ -22,6 +22,7 @@namespace Vvveb\System\Extensions;+use \Vvveb\System\Cache;use \Vvveb\System\Event;use \Vvveb\System\Sites;use function Vvveb\__;@@ -37,6 +38,8 @@ class Themes extends Extensions {static protected $feedUrl = 'https://themes.vvveb.com/feed/themes';+ static protected $categoriesFeedUrl = 'https://themes.vvveb.com/feed/categories';+static protected $themes = [];static protected $categories = [];@@ -48,44 +51,72 @@ class Themes extends Extensions {return $params;}- static function getList($site_id = false) {- $activeTheme = Sites::getTheme($site_id) ?? 'default';- $list = glob(DIR_ROOT . '/public/themes/*/index.html');-- $themes = [];+ static function clearThemesCache($site_id = SITE_ID) {+ $cacheDriver = Cache :: getInstance();+ $cacheKey = "themes_list_$site_id";+ $cacheDriver->delete('vvveb', $cacheKey);+ }- foreach ($list as $file) {- $folder = Str::match('@/([^/]+)/[a-z]+.\w+$@', $file);- $dir = Str::match('@(.+)/[a-z]+.\w+$@', $file);- $themeConfig = $dir . DS . 'theme.php';+ static function getList($site_id = false, $cache = true) {+ $cacheDriver = Cache :: getInstance();+ $cacheKey = "themes_list_$site_id";+ $activeTheme = Sites::getTheme($site_id) ?? 'default';- if ($folder == 'default') {- continue;+ if ($cache && $themes = $cacheDriver->get('vvveb', $cacheKey)) {+ foreach ($themes as &$theme) {+ $theme['active'] = ($activeTheme == $theme['folder']);}- $theme = [];- $theme['file'] = $file;- $theme['folder'] = $folder;- $theme['import'] = false;- $theme['author'] = 'n/a';-- if (file_exists($themeConfig)) {- $content = file_get_contents($themeConfig);- $theme = static::getInfo($content, $folder) + $theme;- $theme['import'] = file_exists($dir . DS . 'import');++ if (isset($themes[$activeTheme])) {+ $theme = $themes[$activeTheme];+ unset($themes[$activeTheme]);+ $themes = [$activeTheme => $theme] + $themes;}- $theme['name'] = $theme['name'] ?? ucfirst($theme['folder']);- $theme['screenshot'] = $theme['screenshot'] ?? (file_exists($dir . DS . 'screenshot.png') ? PUBLIC_PATH . 'themes/' . $folder . '/screenshot.png' : '/../media/extension.svg');+ return $themes;+ } else {+ $list = glob(DIR_ROOT . '/public/themes/*/index.html');- $themes[$folder] = $theme;+ $themes = [];- if ($theme['active'] = ($activeTheme == $theme['folder'])) {- unset($themes[$activeTheme]);- $themes = [$activeTheme => $theme] + $themes;+ foreach ($list as $file) {+ $folder = Str::match('@/([^/]+)/[a-z]+.\w+$@', $file);+ $dir = Str::match('@(.+)/[a-z]+.\w+$@', $file);+ $themeConfig = $dir . DS . 'theme.php';++ if ($folder == 'default') {+ continue;+ }+ $theme = [];+ $theme['file'] = $file;+ $theme['folder'] = $folder;+ $theme['slug'] = $folder;+ $theme['import'] = false;+ $theme['author'] = 'n/a';++ if (file_exists($themeConfig)) {+ $content = file_get_contents($themeConfig);+ $theme = static::getInfo($content, $folder) + $theme;+ $theme['import'] = file_exists($dir . DS . 'import');+ }++ $theme['name'] = $theme['name'] ?? ucfirst($theme['folder']);+ $theme['screenshot'] = $theme['screenshot'] ?? (file_exists($dir . DS . 'screenshot.png') ? PUBLIC_PATH . 'themes/' . $folder . '/screenshot.png' : '/../media/extension.svg');++ $themes[$folder] = $theme;++ if ($theme['active'] = ($activeTheme == $theme['folder'])) {+ unset($themes[$activeTheme]);+ $themes = [$activeTheme => $theme] + $themes;+ }}- }- static :: $extensions[static :: $extension] = $themes;+ static :: $extensions[static :: $extension] = $themes;++ if ($cache) {+ $cacheDriver->set('vvveb', $cacheKey, $themes);+ }+ }return $themes;}