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
Limit list and duplicate to own posts and products if other capability is missing https://github.com/givanz/Vvveb/security/advisories/GHSA-g7j8-g4xq-f232
Givan82679f5d2183
diff --git a/admin/controller/content/posts.php b/admin/controller/content/posts.phpold mode 100755new mode 100644index 8514d2d..0d3ab8f--- a/admin/controller/content/posts.php+++ b/admin/controller/content/posts.php@@ -28,17 +28,24 @@ use function Vvveb\humanReadable;use Vvveb\Sql\PostSQL;use Vvveb\System\Cache;use Vvveb\System\Images;-use Vvveb\System\locale;+use Vvveb\System\Locale;use Vvveb\System\User\Admin;use function Vvveb\url;class Posts extends Listing {- protected $type = 'post';-- //check for other modules permission like post and editor to enable links like save/delete etc- protected $additionalPermissionCheck = ['content/post/save'];-- function init() {+ protected string $type = 'post';++ /**+ * @var array<int, string> Additional modules to check permissions for (e.g. content/post/save).+ */+ protected ?array $additionalPermissionCheck = ['content/post/save'];++ /**+ * Initializes the controller, setting the post type from the request.+ *+ * @return string|null+ */+ public function init(): ?string {if (isset($this->request->get['type'])) {$this->type = $this->request->get['type'];}@@ -46,16 +53,37 @@ class Posts extends Listing {return parent::init();}- function duplicate() {+ /**+ * Duplicates an existing post with all its content, taxonomy items, and sites.+ *+ * @return void+ */+ public function duplicate(): void {$post_id = $this->request->post['post_id'] ?? false;if ($post_id) {$this->posts = new PostSQL();- $data = $this->posts->get(['post_id' => $post_id, 'type' => $this->type]);+ $options = ['post_id' => $post_id, 'type' => $this->type] + $this->global;++ $editCapability = 'edit_other_posts';++ if (Admin::hasCapability($editCapability)) {+ unset($options['admin_id']);+ }++ $data = $this->posts->get($options);++ if (!$data) {+ $this->view->errors[] = sprintf(__('%s not found!'), ucfirst($this->type));+ $this->index();++ return;+ }+$old_id = $data['post_id'];unset($data['post_id']);- $id = rand(1, 1000);+ $id = random_int(1, 1000000);foreach ($data['post_content'] as &$content) {unset($content['post_id']);@@ -64,11 +92,15 @@ class Posts extends Listing {}if (isset($data['post_to_taxonomy_item'])) {+ $taxonomy_item_id = [];+foreach ($data['post_to_taxonomy_item'] as &$item) {$taxonomy_item_id[] = $item['taxonomy_item_id'];}}+ $site_id = [];+if (isset($data['post_to_site'])) {foreach ($data['post_to_site'] as &$item) {$site_id[] = $item['site_id'];@@ -93,15 +125,20 @@ class Posts extends Listing {//$this->session->set('success', $success);//$this->redirect(['module' => 'content/posts', 'type' => $this->type], [], false);} else {- $this->view->errors[] = sprintf(__('Error duplicating %s!'), $this->type);+ $this->view->errors[] = sprintf(__('Error duplicating %s!'), $this->type);}}}- return $this->index();+ $this->index();}- function delete() {+ /**+ * Deletes one or more posts by ID.+ *+ * @return void+ */+ public function delete(): void {$post_id = $this->request->post['post_id'] ?? false;if ($post_id) {@@ -109,7 +146,7 @@ class Posts extends Listing {$post_id = [$post_id];}- $this->posts = new postSQL();+ $this->posts = new PostSQL();$options = ['post_id' => $post_id, 'type' => $this->type,] + $this->global;@@ -118,7 +155,6 @@ class Posts extends Listing {if (Admin::hasCapability($editCapability)) {unset($options['admin_id']);- } else {}$result = $this->posts->delete($options);@@ -126,25 +162,32 @@ class Posts extends Listing {if ($result && isset($result['post'])) {$this->view->success[] = ucfirst($this->type) . __(' deleted!');} else {- $this->view->errors[] = sprintf(__('Error deleting %s!'), $this->type);+ $this->view->errors[] = sprintf(__('Error deleting %s!'), $this->type);}}- return $this->index();+ $this->index();}- function archives($options) {+ /**+ * Returns archived posts grouped by year/month.+ *+ * @param array<string, mixed> $options Query options.+ *+ * @return array<string, string> Archive entries keyed by year/month.+ */+ public function archives(array $options): array {$options['interval'] = 'month';$archives = $this->posts->getArchives($options);$return = [];- $df = false;+ $df = false;if (class_exists('\IntlDateFormatter')) {$dt = new \DateTime();- $df = new \IntlDateFormatter(Locale::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) {@@ -156,10 +199,10 @@ class Posts extends Listing {$archive['month_text'] = $monthNum;if ($df) {- $archive['month_text'] = ucfirst(datefmt_format($df, $dt));$dt->setDate(0, $archive['month'], 0);+ $archive['month_text'] = ucfirst(datefmt_format($df, $dt));} else {- $archive['month_text'] = date('F',mktime(0,0,0,$monthNum,1,$archive['year']));+ $archive['month_text'] = date('F', mktime(0, 0, 0, $monthNum, 1, $archive['year']));}}@@ -172,6 +215,7 @@ class Posts extends Listing {$return[$archive['year'] . '/' . $archive['month']] = $name;}+/*$return = [];@@ -200,9 +244,14 @@ class Posts extends Listing {return $return;}- function index() {+ /**+ * Lists all posts with filtering, archive links, and capability-based access control.+ *+ * @return void+ */+ public function index(): void {$view = $this->view;- $this->posts = new postSQL();+ $this->posts = new PostSQL();$this->type = $this->request->get['type'] ?? 'post';$this->filter = array_filter($this->request->get['filter'] ?? []);@@ -220,8 +269,8 @@ class Posts extends Listing {$options += $this->filter;- //override admin if admin_id filter set- if (isset($this->filter['admin_id'])) {+ //override admin only for users that can view other authors posts+ if (Admin::hasCapability('view_other_posts') && isset($this->filter['admin_id'])) {$options['admin_id'] = $this->filter['admin_id'];}@@ -249,13 +298,13 @@ class Posts extends Listing {$post['image'] = Images::image($post['image'], 'post');}- if (! $post['name'] && ($post['language_id'] != $this->global['default_language_id'])) {+ if (!$post['name'] && ($post['language_id'] != $this->global['default_language_id'])) {$post['name'] = '[' . __('No translation') . ']';}$url = ['module' => 'content/post', 'post_id' => $post['post_id'], 'type' => $post['type']];$adminPath = \Vvveb\adminPath();- $template = $post['template'] ? $post['template'] : $defaultTemplate;+ $template = $post['template'] ?: $defaultTemplate;$post['url'] = url($url);$post['edit-url'] = $post['url'];$post['admin-url'] = url(['module' => 'content/posts']) . '&type=' . $this->type . '&filter[admin_id_text]=' . $post['username'] . ' &filter[admin_id]=' . $post['admin_id'];@@ -263,16 +312,20 @@ class Posts extends Listing {$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'], '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);+ $post['design-url'] = url(['module' => 'editor/page-builder', 'name' => urlencode($post['name'] ?? ''), 'url' => $relativeUrl, 'template' => $template], false);}}//archives for filter$cache = Cache::getInstance();- $archives = $cache->cache('posts',"archives.{$this->type}.{$this->global['site_id']}" ,- function () use (&$options) {- return $this->archives($options) ?? [];- }, 259200);+ $archives = $cache->cache(+ 'posts',+ "archives.{$this->type}.{$this->global['site_id']}",+ function() use (&$options) {+ return $this->archives($options);+ },+ 259200+ );$view->set($results);$view->status = ['publish' => __('Publish'), 'pending' => __('Pending'), 'draft' => __('Draft'), 'private' => __('Private'), 'password' => __('Password'), 'scheduled' => __('Scheduled')];diff --git a/admin/controller/product/products.php b/admin/controller/product/products.phpold mode 100755new mode 100644index 52f090d..8d921a9--- a/admin/controller/product/products.php+++ b/admin/controller/product/products.php@@ -25,6 +25,9 @@ namespace Vvveb\Controller\Product;use function Vvveb\__;use Vvveb\Controller\Listing;use function Vvveb\humanReadable;+use Vvveb\Sql\Product_option_valueSQL;+use Vvveb\Sql\Product_optionSQL;+use Vvveb\Sql\Product_variantSQL;use Vvveb\Sql\ProductSQL;use Vvveb\System\Core\View;use Vvveb\System\Images;@@ -32,12 +35,17 @@ use Vvveb\System\User\Admin;use function Vvveb\url;class Products extends Listing {- protected $type = 'product';+ protected string $type = 'product';- //check for other modules permission like post and editor to enable links like save/delete etc- protected $additionalPermissionCheck = ['product/product/save'];+ /** @var list<string> Check for other modules permission like post and editor to enable links like save/delete etc */+ protected ?array $additionalPermissionCheck = ['product/product/save'];- function init() {+ /**+ * Initialize the controller, setting the type from request if present.+ *+ * @return string|null+ */+ public function init(): ?string {if (isset($this->request->get['type'])) {$this->type = $this->request->get['type'];}@@ -45,15 +53,35 @@ class Products extends Listing {return parent::init();}- function duplicate() {+ /**+ * Duplicate a product by its ID.+ *+ * @return void+ */+ public function duplicate(): void {$product_id = $this->request->post['product_id'] ?? false;if ($product_id) {$this->products = new ProductSQL();- $data = $this->products->get(['product_id' => $product_id, 'type' => $this->type]);+ $options = ['product_id' => $product_id, 'type' => $this->type] + $this->global;++ $editCapability = 'edit_other_products';++ if (Admin::hasCapability($editCapability)) {+ unset($options['admin_id']);+ }++ $data = $this->products->get($options);++ if (!$data) {+ $this->view->errors[] = sprintf(__('%s not found!'), ucfirst($this->type));+ $this->index();++ return;+ }unset($data['product_id']);- $id = rand(1, 1000);+ $id = mt_rand(1, 1000);foreach ($data['product_content'] as &$content) {unset($content['product_id']);@@ -61,12 +89,16 @@ class Products extends Listing {$content['slug'] .= '-' . __('duplicate') . "-$id";}+ $taxonomy_item_id = [];+if (isset($data['product_to_taxonomy_item'])) {foreach ($data['product_to_taxonomy_item'] as &$item) {$taxonomy_item_id[] = $item['taxonomy_item_id'];}}+ $site_id = [];+if (isset($data['product_to_site'])) {foreach ($data['product_to_site'] as &$item) {$site_id[] = $item['site_id'];@@ -77,7 +109,7 @@ class Products extends Listing {$result = $this->products->add(['product' => $data,'product_content' => $data['product_content'],- 'taxonomy_item_id' => $taxonomy_item_id ?? [],+ 'taxonomy_item_id' => $taxonomy_item_id,'site_id' => $site_id,]);@@ -90,7 +122,75 @@ class Products extends Listing {foreach ($data['product_image'] as $image) {$product_image[] = $image['image'];}- $images = $this->products->productImage(['product_image' => $product_image, 'product_id' => $product_id]);+ $this->products->productImage(['product_image' => $product_image, 'product_id' => $product_id]);+ }++ $optionSQL = new Product_optionSQL();+ $productoptionvalueSQL = new Product_option_valueSQL();++ $product_option_map = [];+ $product_option_value_map = [];+ if (isset($data['product_option'])) {+ foreach ($data['product_option'] as $i => $opt) {+ $opt['product_id'] = $product_id;+ $product_option_id = $opt['product_option_id'];+ // new option+ unset($opt['product_option_id']);+ $result = $optionSQL->add(['product_option' => $opt] + $this->global);++ if ($result && $result['product_option']) {+ //set new id to use for option values+ $opt['product_option_id'] = $result['product_option'];+ $product_option_map[$product_option_id] = $result['product_option'];+ }++ if (isset($data['product_option_value'])) {+ foreach ($data['product_option_value'] as $j => $value) {+ //values only for this option+ if ($product_option_id != $value['product_option_id']) {+ continue;+ }+ $product_option_value_id = $value['product_option_value_id'];+ //set parent option id+ $value['product_option_id'] = $opt['product_option_id'];+ $value['option_id'] = $opt['option_id'];+ $value['product_id'] = $product_id;++ unset($value['product_option_value_id']);+ $result = $productoptionvalueSQL->add(['product_option_value' => $value] + $this->global);++ if ($result && $result['product_option_value']) {+ $product_option_value_map[$product_option_value_id] = $result['product_option_value'];+ }+ }+ }+ }+ }++ $variantSQL = new Product_variantSQL();++ if (isset($data['product_variant'])) {+ foreach ($data['product_variant'] as $i => $opt) {+ $opt['product_id'] = $product_id;+ unset($opt['product_variant_id']);++ $options = explode(',', $opt['options']);+ foreach ($options as &$el) {+ $vals = explode(':', $el);+ $vals[0] = $product_option_map[$vals[0]];+ $vals[1] = $product_option_value_map[$vals[1]];+ $el = implode(':', $vals);+ }++ $opt['options'] = implode(',', $options);++ $result = $variantSQL->add(['product_variant' => $opt] + $this->global);++ if ($result && $result['product_variant']) {+ //set new id to use for variant values+ $opt['product_variant_id'] = $result['product_variant'];+ }+ }}$url = url(['module' => 'product/product', 'product_id' => $product_id, 'type' => $this->type]);@@ -101,16 +201,21 @@ class Products extends Listing {$this->session->set('success', $success);$this->redirect(['module' => 'product/products'], [], false);} else {- $this->view->errors[] = sprintf(__('Error duplicating %s!'), $this->type);+ $this->view->errors[] = sprintf(__('Error duplicating %s!'), $this->type);}}}- return $this->index();+ $this->index();}- function delete() {- $product_id = $this->request->post['product_id'];+ /**+ * Delete one or more products.+ *+ * @return void+ */+ public function delete(): void {+ $product_id = $this->request->post['product_id'] ?? [];if ($product_id) {if (is_numeric($product_id)) {@@ -124,7 +229,6 @@ class Products extends Listing {if (Admin::hasCapability($editCapability)) {unset($options['admin_id']);- } else {}$result = $products->delete($options);@@ -136,11 +240,16 @@ class Products extends Listing {}}- return $this->index();+ $this->index();}- function index() {- $view = View :: getInstance();+ /**+ * Display the products listing page.+ *+ * @return void+ */+ public function index(): void {+ $view = View::getInstance();$products = new ProductSQL();$this->filter = array_filter($this->request->get['filter'] ?? []);@@ -154,7 +263,7 @@ class Products extends Listing {}$options = [- 'type' => $this->type,+ 'type' => $this->type,] + $this->global;if (Admin::hasCapability('view_other_products')) {@@ -179,7 +288,7 @@ class Products extends Listing {if ($results && isset($results['product'])) {foreach ($results['product'] as $id => &$product) {if (isset($product['images'])) {- $product['images'] = json_decode($product['images'], 1);+ $product['images'] = json_decode($product['images'], true);foreach ($product['images'] as &$image) {$image = Images::image($image, 'product');@@ -190,11 +299,10 @@ class Products extends Listing {}}- if (! $product['name'] && ($product['language_id'] != $this->global['default_language_id'])) {+ if (!$product['name'] && ($product['language_id'] != $this->global['default_language_id'])) {$product['name'] = '[' . __('No translation') . ']';}- $adminPath = \Vvveb\adminPath();$url = ['module' => 'product/product', 'product_id' => $product['product_id'], 'type' => $product['type']];$template = (isset($product['template']) && $product['template']) ? $product['template'] : $defaultTemplate;$product['url'] = url($url);@@ -203,7 +311,7 @@ class Products extends Listing {$product['duplicate-url'] = url(['module' => 'product/products', 'action' => 'duplicate'] + $url); // + ['product_id' => $product['product_id']]);$product['view-url'] = url('product/product/index', $product + $url + ['host' => $this->global['host'], 'path' => $this->global['path'] ? '/' . $this->global['path'] : null]);$relativeUrl = url('product/product/index', $product + $url);- $product['design-url'] = url(['module' => 'editor/editor', 'name' => urlencode($product['name'] ?? ''), 'url' => $relativeUrl, 'template' => $template], false);+ $product['design-url'] = url(['module' => 'editor/page-builder', 'name' => urlencode($product['name'] ?? ''), 'url' => $relativeUrl, 'template' => $template], false);}}