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
User defined custom posts and products
givanz4933dd1aa2aa
diff --git a/admin/controller/base.php b/admin/controller/base.phpindex b0ecf1d..ad1a5b5 100755--- a/admin/controller/base.php+++ b/admin/controller/base.php@@ -36,6 +36,7 @@ use Vvveb\System\Core\View;use Vvveb\System\Event;use Vvveb\System\Extensions\Plugins;use Vvveb\System\Functions\Str;+use Vvveb\System\Images;use Vvveb\System\PageCache;use Vvveb\System\Session;use Vvveb\System\Sites;@@ -64,7 +65,7 @@ class Base {$this->session->set('site_id', $site_id);$this->session->set('site_url', $site['host']);$this->session->set('site', $site['id']);- $this->session->set('state', $site['state']);+ $this->session->set('state', $site['state'] ?? 'live');return $site_id;}@@ -76,7 +77,7 @@ class Base {return $taxonomies['taxonomy'] ?? [];}- protected function customPosts() {+ protected function customPost() {//custom posts -- add to menu$default_custom_posts =[@@ -94,8 +95,9 @@ class Base {],];- $custom_posts_types = \Vvveb\get_setting('custom_posts', 'types', $default_custom_posts);- list($custom_posts_types) = Event::trigger(__CLASS__, __FUNCTION__, $custom_posts_types);+ $custom_posts_types = \Vvveb\get_setting('post', 'types', []);+ $custom_posts_types += $default_custom_posts;+ list($custom_posts_types) = Event::trigger(__CLASS__, __FUNCTION__, $custom_posts_types);$custom_post_menu = \Vvveb\config('custom-post-menu', []);$posts_menu = [];@@ -111,7 +113,7 @@ class Base {__(ucfirst($settings['plural']));$posts_menu[$type]['icon'] = $settings['icon'] ?? '';- $posts_menu[$type]['icon-img'] = $settings['icon-img'] ?? '';+ $posts_menu[$type]['icon-img'] = (isset($settings['icon-img']) && $settings['icon-img']) ? Images::image($settings['icon-img'], $type) : '';$posts_menu[$type]['url'] .= "&type=$type";if (isset($settings['comments']) && ! $settings['comments']) {@@ -136,7 +138,7 @@ class Base {$tax = [$key => ['name' => __($taxonomy['name']),//'subtitle' => __('(Flat)'),- 'url' => "$admin_path?module=$module&type={$taxonomy['post_type']}&taxonomy_id={$taxonomy['taxonomy_id']}",+ 'url' => "{$admin_path}index.php?module=$module&type={$taxonomy['post_type']}&taxonomy_id={$taxonomy['taxonomy_id']}",'module' => $module,'action' => 'index','icon' => $icon,@@ -149,7 +151,7 @@ class Base {return $posts_menu;}- protected function customProducts() {+ protected function customProduct() {//custom products -- add to menu$default_custom_products =[@@ -160,8 +162,9 @@ class Base {],];- $custom_products_types = \Vvveb\get_setting('custom_products', 'types', $default_custom_products);- list($custom_products_types) = Event::trigger(__CLASS__, __FUNCTION__, $custom_products_types);+ $custom_products_types = \Vvveb\get_setting('product', 'types', []);+ $custom_products_types += $default_custom_products;+ list($custom_products_types) = Event::trigger(__CLASS__, __FUNCTION__, $custom_products_types);$custom_product_menu = \Vvveb\config('custom-product-menu', []);$products_menu = [];@@ -177,7 +180,7 @@ class Base {__(ucfirst($settings['plural']));$products_menu[$type]['icon'] = $settings['icon'] ?? '';- $products_menu[$type]['icon-img'] = $settings['icon-img'] ?? '';+ $products_menu[$type]['icon-img'] = (isset($settings['icon-img']) && $settings['icon-img']) ? Images::image($settings['icon-img'], $type) : '';$products_menu[$type]['url'] .= "&type=$type";foreach ($products_menu[$type]['items'] as $item => &$values) {@@ -199,7 +202,7 @@ class Base {$tax = [$key => ['name' => __($taxonomy['name']),//'subtitle' => __('(Flat)'),- 'url' => "$admin_path?module=$module&type={$taxonomy['post_type']}&taxonomy_id={$taxonomy['taxonomy_id']}",+ 'url' => "{$admin_path}index.php?module=$module&type={$taxonomy['post_type']}&taxonomy_id={$taxonomy['taxonomy_id']}",'module' => $module,'action' => 'index','icon' => $icon,@@ -377,6 +380,21 @@ class Base {//$this->session->delete('csrf');//$this->session = Session::getInstance();//$this->request = Request::getInstance();+ $view = View :: getInstance();+ $view->removeVattrs(false);++ if (isset($this->request->get['errors']) && $this->request->get['errors']) {+ $view->errors['get'] = htmlentities($this->request->get['errors']);+ }++ if (isset($this->request->get['success']) && $this->request->get['success']) {+ $view->success['get'] = htmlentities($this->request->get['success']);+ }++ //prevent admin loading in iframe+ $this->response->addHeader('X-Frame-Options', 'SAMEORIGIN');+ $this->response->addHeader('X-Content-Type-Options', 'nosniff');+$admin = Admin::current();if (! $admin) {@@ -397,9 +415,6 @@ class Base {$site_id = $this->setSite();}- $view = View :: getInstance();- $view->removeVattrs(false);-$this->language('en_US', 1);$this->currency('USD', 1);@@ -437,19 +452,11 @@ class Base {Plugins :: loadPlugins($site_id);}- if (isset($this->request->get['errors'])) {- $view->errors['get'] = htmlentities($this->request->get['errors']);- }-if ($errors = $this->session->get('errors')) {$view->errors['session'] = $errors;$this->session->delete('errors');}- if (isset($this->request->get['success'])) {- $view->success['get'] = htmlentities($this->request->get['success']);- }-if ($success = $this->session->get('success')) {$view->success['session'] = $success;$this->session->delete('success');@@ -468,11 +475,11 @@ class Base {//custom posts -- add to menu$this->taxonomies = $this->getTaxonomies();- $posts_menu = $this->customPosts();+ $posts_menu = $this->customPost();$menu = array_insert_array_after('edit', $menu, $posts_menu);//products - add to menu- $products_menu = $this->customProducts();+ $products_menu = $this->customProduct();$menu = array_insert_array_after('sales', $menu, $products_menu);list($menu) = Event::trigger(__CLASS__, __FUNCTION__ . '-menu', $menu);@@ -486,6 +493,8 @@ class Base {$view->menu = $menu;+ $adminPath = \Vvveb\adminPath();+ $view->adminPath = $adminPath;$view->mediaPath = PUBLIC_PATH . 'media';$view->publicPath = PUBLIC_PATH . 'media';}@@ -516,7 +525,7 @@ class Base {//return \Vvveb\System\Core\FrontController::redirect('user/login');//$view = view :: getInstance();$admin_path = \Vvveb\adminPath();- $this->view->action = "$admin_path/?module=user/login";+ $this->view->action = "{$admin_path}index.php?module=user/login";$this->view->template('user/login.html');die($this->view->render());diff --git a/admin/controller/settings/post-type.php b/admin/controller/settings/post-type.phpnew file mode 100644index 0000000..b0e1e6a--- /dev/null+++ b/admin/controller/settings/post-type.php@@ -0,0 +1,99 @@+<?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\Controller\Settings;++use function Vvveb\__;+use Vvveb\Controller\Base;+use function Vvveb\humanReadable;+use Vvveb\System\Images;++class PostType extends Base {+ protected $type = 'post';++ function save() {+ $postType = $this->request->post['post_type'] ?? false;+ $userType = $this->request->get['type'] ?? false;++ if ($postType) {+ $userPostTypes = \Vvveb\get_setting($this->type, 'types', []);++ if ($userType) {+ //edit+ if (isset($userPostTypes[$userType])) {+ $userPostTypes[$userType] = $postType + $userPostTypes[$userType];++ if ($userType != $postType['type']) {+ $userPostTypes[$postType['type']] = $userPostTypes[$userType];+ unset($userPostTypes[$userType]);+ }+ } else {+ return $this->notFound();+ }+ } else {+ //new+ $userPostTypes[$postType['type']] = $postType;+ }++ $userPostTypes = \Vvveb\set_setting($this->type, 'types', $userPostTypes);++ $successMessage = humanReadable(__($this->type)) . ' ' . __('type saved!');+ $this->view->success[] = $successMessage;++ if ($userType != $postType['type']) {+ $this->session->set('success', $successMessage);+ $this->redirect(['module' => "settings/{$this->type}-type", 'type' => $postType['type']]);+ }+ }++ return $this->index();+ }++ function index() {+ $type = ucfirst($this->type);+ $userPostTypes = \Vvveb\get_setting($this->type, 'types', []);++ $userType = $this->request->get['type'] ?? false;+ $customType = [];++ if ($userType && isset($userPostTypes[$userType])) {+ $customType = $userPostTypes[$userType];+ }++ if ($userType && ! $customType) {+ $this->notFound();+ }++ if (isset($customType['icon-img'])) {+ $customType['image_url'] = Images::image($customType['icon-img'], $type);+ }++ $view = &$this->view;+ $admin_path = \Vvveb\adminPath();+ $view->post_type = $customType;+ $controllerPath = $admin_path . 'index.php?module=media/media';+ $view->scanUrl = "$controllerPath&action=scan";+ $view->uploadUrl = "$controllerPath&action=upload";++ //$this->view->taxonomy_id = $taxonomy_item_id;+ }+}diff --git a/admin/controller/settings/post-types.php b/admin/controller/settings/post-types.phpnew file mode 100644index 0000000..c38b565--- /dev/null+++ b/admin/controller/settings/post-types.php@@ -0,0 +1,97 @@+<?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\Controller\Settings;++use Vvveb\Controller\Listing;+use Vvveb\System\Event;++class PostTypes extends Listing {+ protected $type = 'post';++ function delete() {+ $userType = $this->request->get['type'] ?? false;++ if ($userType) {+ $userPostTypes = \Vvveb\get_setting($this->type, 'types', []);++ if ($userPostTypes) {+ if (! is_array($userType)) {+ $userType = [$userType];+ }++ foreach ($userType as $type) {+ if (isset($userPostTypes[$type])) {+ unset($userPostTypes[$type]);+ }+ }+ $userPostTypes = \Vvveb\set_setting($this->type, 'types', $userPostTypes);+ }+ }++ return $this->index();+ }++ protected $defaultTypes = [+ 'post' => [+ 'name' => 'Post',+ 'source' => 'default',+ 'site_id' => '0',+ 'type' => 'post',+ 'plural' => 'posts',+ 'icon' => 'icon-document-text-outline',+ 'comments'=> true,+ ],+ 'page' => [+ 'name' => 'Page',+ 'source' => 'default',+ 'site_id' => '0',+ 'type' => 'page',+ 'plural' => 'pages',+ 'icon' => 'icon-document-outline',+ 'comments'=> false,+ ],+ ];++ function index() {+ $type = ucfirst($this->type);+ 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', []);++ $params = ['module' => "settings/{$this->type}-type"];+ $paramsList = ['module' => "settings/{$this->type}-types"];++ array_walk($userTypes, function (&$type,$key) use ($params, $paramsList) {+ $type['source'] = 'user';+ $type['name'] = ucfirst($key);+ $type['url'] = \Vvveb\url($params + ['type' => $type['type']]);+ $type['delete-url'] = \Vvveb\url($paramsList + ['action' => 'delete', 'type[]' => $type['type']]);+ });++ $types = $this->defaultTypes + $pluginTypes + $userTypes;++ $this->view->types = $types;+ $this->view->count = count($types);+ }+}diff --git a/admin/controller/settings/product-type.php b/admin/controller/settings/product-type.phpnew file mode 100644index 0000000..0338956--- /dev/null+++ b/admin/controller/settings/product-type.php@@ -0,0 +1,27 @@+<?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\Controller\Settings;++class ProductType extends PostType {+ protected $type = 'product';+}diff --git a/admin/controller/settings/product-types.php b/admin/controller/settings/product-types.phpnew file mode 100644index 0000000..86bd2d7--- /dev/null+++ b/admin/controller/settings/product-types.php@@ -0,0 +1,38 @@+<?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\Controller\Settings;++class ProductTypes extends PostTypes {+ protected $type = 'product';++ protected $defaultTypes = [+ 'product' => [+ 'name' => 'Product',+ 'type' => 'product',+ 'site_id' => '0',+ 'source' => 'default',+ 'plural' => 'products',+ 'icon' => 'icon-cube-outline',+ ],+ ];+}diff --git a/admin/controller/settings/taxonomy.php b/admin/controller/settings/taxonomy.phpold mode 100755new mode 100644index 02e826d..ff910a9--- a/admin/controller/settings/taxonomy.php+++ b/admin/controller/settings/taxonomy.php@@ -24,6 +24,7 @@ namespace Vvveb\Controller\Settings;use function Vvveb\__;use Vvveb\Controller\Crud;+use Vvveb\System\Event;class Taxonomy extends Crud {protected $type = 'taxonomy';@@ -36,7 +37,22 @@ class Taxonomy extends Crud {parent::index();$this->view->type = ['categories' => __('Categories'), 'tags' => __('Tags')];- $this->view->post_type = ['post' => __('Post'), 'page' => __('Page'), 'product' => __('product')];+ $postType = ['post' => __('Post'), 'page' => __('Page'), 'product' => __('product')];++ $userPostTypes = \Vvveb\get_setting('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', []);+ list($pluginProductTypes) = Event::trigger('Vvveb\Controller\Base', 'customProduct', []);+ $customProduct = $userProductTypes + $pluginProductTypes;+ array_walk($customProduct, fn (&$type, $key) => $type = ucfirst($key));+ $postType += $customProduct;++ $this->view->post_type = $postType;+//$this->view->taxonomy_id = $taxonomy_item_id;}}diff --git a/admin/template/settings/post-type.tpl b/admin/template/settings/post-type.tplnew file mode 100755index 0000000..b50ccea--- /dev/null+++ b/admin/template/settings/post-type.tpl@@ -0,0 +1,7 @@+import(common.tpl)++[data-v-post_type-*] = $this->post_type['@@__data-v-post_type-(*)__@@']++[data-v-image]|data-v-image = $this->post_type['image_url']+input[data-v-image]|value = $this->post_type['icon-img']+img[data-v-image]|src = <?php echo (isset($this->post_type['image_url']) && $this->post_type['image_url']) ? $this->post_type['image_url'] : 'img/placeholder.svg';?>diff --git a/admin/template/settings/post-types.tpl b/admin/template/settings/post-types.tplnew file mode 100755index 0000000..e31c433--- /dev/null+++ b/admin/template/settings/post-types.tpl@@ -0,0 +1 @@+import(listing.tpl, {"type":"type", "list": "types"})diff --git a/admin/template/settings/product-type.tpl b/admin/template/settings/product-type.tplnew file mode 100644index 0000000..dc2e614--- /dev/null+++ b/admin/template/settings/product-type.tpl@@ -0,0 +1 @@+import(settings/post-type.tpl)\ No newline at end of filediff --git a/admin/template/settings/product-types.tpl b/admin/template/settings/product-types.tplnew file mode 100755index 0000000..e31c433--- /dev/null+++ b/admin/template/settings/product-types.tpl@@ -0,0 +1 @@+import(listing.tpl, {"type":"type", "list": "types"})