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
Add user subscriptions pages, cart trait extraction, llms.txt feed, email templates, cart and checkout components
Givandff2171d9fe2
diff --git a/app/component/admin.php b/app/component/admin.phpindex a2a1cec..2a57252 100755--- a/app/component/admin.php+++ b/app/component/admin.php@@ -29,23 +29,21 @@ use Vvveb\System\User\Admin as AdminClass;use function Vvveb\url;class Admin extends ComponentBase {- public static $defaultOptions = [+ public static array $defaultOptions = ['admin_id' => null,'username' => null,];- protected $options = [];+ protected array $options = [];- public $cacheExpire = 0;+ public int $cacheExpire = 0;- //seconds- /*- function cacheKey() {- //disable caching- return false;- }- */- function results() {+ /**+ * Get admin user data with avatar/cover images and profile URL.+ *+ * @return array<string, mixed> Admin data with image URLs and profile info.+ */+ public function results(): array {if (isset($this->options['admin_id']) || isset($this->options['username'])) {$admins = new \Vvveb\Sql\AdminSQL();@@ -59,17 +57,17 @@ class Admin extends ComponentBase {foreach (['avatar', 'cover'] as $image) {if (isset($results[$image])) {- $results[$image . '_url']= Images::image($results[$image], 'admin');+ $results[$image . '_url'] = Images::image($results[$image], 'admin');}}- $results['website'] = $results['website'] ?? $results['url'];+ $results['website'] ??= $results['url'];$results['url'] = url('content/user/index', ['username' => $results['username']]);} else {$results = [];}- list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);+ [$results] = Event :: trigger(__CLASS__, __FUNCTION__, $results);return $results;}diff --git a/app/component/admins.php b/app/component/admins.phpindex 225a4a8..bcf2917 100644--- a/app/component/admins.php+++ b/app/component/admins.php@@ -28,15 +28,22 @@ use Vvveb\System\Images;use function Vvveb\url;class Admins extends ComponentBase {- public static $defaultOptions = [- 'start' => 0,- 'limit' => ['url', 4],- 'status' => 1,+ public static array $defaultOptions = [+ 'start' => 0,+ 'limit' => ['url', 4],+ 'status' => 1,+ 'search' => 1,+ 'admin_id' => 1,];- public $options = [];+ public array $options = [];- function results() {+ /**+ * Get admins list with avatar images and profile URLs.+ *+ * @return array<string, mixed> Admins data with admin list and image URLs.+ */+ public function results(): array {$admins = new \Vvveb\Sql\AdminSQL();$results = $admins->getAll($this->options);@@ -51,7 +58,7 @@ class Admins extends ComponentBase {}}- list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);+ [$results] = Event :: trigger(__CLASS__, __FUNCTION__, $results);return $results;}diff --git a/app/component/breadcrumb.php b/app/component/breadcrumb.phpindex 84c1a2a..eecefd2 100644--- a/app/component/breadcrumb.php+++ b/app/component/breadcrumb.php@@ -30,22 +30,31 @@ use Vvveb\System\Event;use function Vvveb\url;class Breadcrumb extends ComponentBase {- public static $defaultOptions = [+ public static array $defaultOptions = ['absoluteURL' => null,- 'blog' => true,- 'shop' => true,+ 'blog' => true,+ 'shop' => true,];- public $options = [];+ public array $options = [];- public $cacheExpire = 0; //no cache+ public int $cacheExpire = 0;- function cacheKey() {- //disable caching- return false;+ /**+ * Disable caching for breadcrumb component.+ *+ * @return null Always returns null to disable caching.+ */+ public function cacheKey(): ?string {+ return null;}- function results() {+ /**+ * Build breadcrumb navigation based on current request module.+ *+ * @return array<string, mixed> Breadcrumb data with breadcrumb array of text/url pairs.+ */+ public function results(): array {$request = Request::getInstance();$module = $request->get['module'] ?? '';$slug = $request->get['slug'] ?? '';@@ -61,13 +70,13 @@ class Breadcrumb extends ComponentBase {}if (($this->options['default_language'] != $this->options['language']) || self :: $global['default_lang_slug']) {- $urlOptions += ['language'=> $this->options['language']];+ $urlOptions += ['language' => $this->options['language']];}if ($type && $type != 'post' && $type != 'product') {$shopText = __(ucfirst($type));$blogText = __(ucfirst($type));- $urlOptions += ['type'=> $type];+ $urlOptions += ['type' => $type];}$breadcrumb = [@@ -87,10 +96,11 @@ class Breadcrumb extends ComponentBase {$category = new CategorySQL();$result = $category->getCategory(['product_id' => $product_id, 'limit' => 1, 'type' => 'categories', 'post_type' => 'product']- + self :: $global);+ + self :: $global+ );if ($result && isset($result['taxonomy_item_id'])) {- $cat = ['slug' => $result['slug']];+ $cat = ['slug' => $result['slug']];$breadcrumb[] = ['text' => $result['name'], 'url' => url('product/category/index', $cat + $urlOptions)];}}@@ -139,10 +149,11 @@ class Breadcrumb extends ComponentBase {$category = new CategorySQL();$result = $category->getCategory(['post_id' => $post_id, 'limit' => 1, 'type' => 'categories', 'post_type' => 'post']- + self :: $global);+ + self :: $global+ );if ($result && isset($result['taxonomy_item_id'])) {- $cat = ['slug' => $result['slug']];+ $cat = ['slug' => $result['slug']];$breadcrumb[] = ['text' => $result['name'], 'url' => url('content/category/index', $cat + $urlOptions)];}}@@ -158,10 +169,11 @@ class Breadcrumb extends ComponentBase {$category = new CategorySQL();$result = $category->getCategory(['post_id' => $post_id, 'limit' => 1, 'type' => 'categories', 'post_type' => 'page']- + self :: $global);+ + self :: $global+ );if ($result && isset($result['taxonomy_item_id'])) {- $cat = ['slug' => $result['slug'], 'type' => 'page'];+ $cat = ['slug' => $result['slug'], 'type' => 'page'];$breadcrumb[] = ['text' => $result['name'], 'url' => url('content/category/index', $cat + $urlOptions)];}}@@ -192,7 +204,7 @@ class Breadcrumb extends ComponentBase {'breadcrumb' => $breadcrumb,];- list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);+ [$results] = Event :: trigger(__CLASS__, __FUNCTION__, $results);return $results;}diff --git a/app/component/cart.php b/app/component/cart.phpindex 43fd089..66caa8c 100755--- a/app/component/cart.php+++ b/app/component/cart.php@@ -28,25 +28,36 @@ use Vvveb\System\Component\ComponentBase;use Vvveb\System\Event;class Cart extends ComponentBase {- public static $defaultOptions = [- 'cart_id' => null, //cart_id/encrypted_cart_id cart id or encrypted cart id generated by Cart::getEncryptedId+ public static array $defaultOptions = [+ 'cart_id' => null,'language_id' => null,'site_id' => null,];- public $cacheExpire = 0; //seconds+ public int $cacheExpire = 0;- function cacheKey() {- //disable caching- return false;- }+ protected array $options = [];- protected $options = [];+ /**+ * Disable caching for cart component.+ *+ * @return null Always returns null to disable caching.+ */+ public function cacheKey(): ?string {+ return null;+ }- function results() {+ /**+ * Get cart contents with products, coupons, totals, and formatted grand total.+ *+ * @return array<string, mixed> Cart data with products, coupons, totals, and total.+ */+ public function results(): array {$site = siteSettings($this->options['site_id'], $this->options['language_id']);- $this->options += array_intersect_key($site,- array_flip(['weight_type_id', 'length_type_id', 'currency_id', 'country_id']));+ $this->options += array_intersect_key(+ $site,+ array_flip(['weight_type_id', 'length_type_id', 'currency_id', 'country_id'])+ );$cart = ShoppingCart::getInstance($this->options);$results['products'] = $cart->getAll();@@ -56,7 +67,7 @@ class Cart extends ComponentBase {$results['total'] = $cart->getGrandTotal();$results['total_formatted'] = $cart->getGrandTotalFormatted();- list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);+ [$results] = Event :: trigger(__CLASS__, __FUNCTION__, $results);return $results;}diff --git a/app/component/categories.php b/app/component/categories.phpindex 6bb96ed..d965b00 100755--- a/app/component/categories.php+++ b/app/component/categories.php@@ -29,39 +29,49 @@ use Vvveb\System\Images;use function Vvveb\url;class Categories extends ComponentBase {- public static $defaultOptions = [+ public static array $defaultOptions = ['start' => 0,'limit' => 7,- 'site_id' => NULL,- 'language_id' => NULL,+ 'site_id' => null,+ 'language_id' => null,'order' => ['url', 'price asc'],- 'taxonomy_id' => NULL,- 'post_id' => NULL,- 'parent_id' => NULL,- 'search' => NULL,+ 'taxonomy_id' => null,+ 'post_id' => null,+ 'parent_id' => null,+ 'search' => null,'type' => 'categories',- 'post_type' => NULL,- 'count' => false, //include number of posts+ 'post_type' => null,+ 'count' => false,'parents_only' => false,'parents_children_only' => false,'parents_without_children' => false,];- function cacheKey() {+ /**+ * Disable caching when search is active.+ *+ * @return string|null Parent cache key or null to disable caching.+ */+ public function cacheKey(): ?string {if (isset($this->options['search'])) {- return false;+ return null;}return parent::cacheKey();}- function results() {+ /**+ * Get categories with child counts, images, URLs, and pagination.+ *+ * @return array<string, mixed> Categories data with nested children counts and pagination info.+ */+ public function results(): array {$category = new CategorySQL();- $results = $category->getCategories($this->options);+ $results = $category->getCategories($this->options);$taxonomy_type = 'category';- if (isset($this->options['type']) && $this->options['type'] == 'tags') {+ if (isset($this->options['type']) && $this->options['type'] === 'tags') {$taxonomy_type = 'tag';}@@ -71,7 +81,7 @@ class Categories extends ComponentBase {$parent_id = $category['parent_id'] ?? false;$category['active'] = false;- if (! isset($category['children'])) {+ if (!isset($category['children'])) {$category['children'] = 0;}@@ -106,13 +116,20 @@ class Categories extends ComponentBase {$results['start'] = $this->options['start'];$results['search'] = $this->options['search'] ?? '';- list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);+ [$results] = Event :: trigger(__CLASS__, __FUNCTION__, $results);return $results;}- //called on each request- function request(&$results, $index = 0) {+ /**+ * Set active category based on current request module and category_id.+ *+ * @param array<string, mixed> &$results Component results to modify.+ * @param int $index Request index.+ *+ * @return array<string, mixed> Modified results with active flags.+ */+ public function request(array &$results, int $index = 0): array {$module = \Vvveb\getModuleName();$categoryId = false;@@ -132,10 +149,9 @@ class Categories extends ComponentBase {if ($categoryId == $category['taxonomy_item_id']) {$key = key($categories);$categories[$key]['active'] = true;- //$category['active'] = true;- $categoryId = $category['parent_id'];+ $categoryId = $category['parent_id'];- if (! $categoryId) {+ if (!$categoryId) {break;}}diff --git a/app/component/categories/pages.php b/app/component/categories/pages.phpold mode 100755new mode 100644index 5b05dd2..96e72ec--- a/app/component/categories/pages.php+++ b/app/component/categories/pages.php@@ -28,21 +28,27 @@ use Vvveb\System\Images;use function Vvveb\url;class Pages extends ComponentBase {- public static $defaultOptions = [+ public static array $defaultOptions = ['start' => 0,'limit' => 7,'posts_start' => 0,- 'posts_limit' => NULL,+ 'posts_limit' => null,'type' => 'categories','post_type' => 'post',- 'site_id' => NULL,+ 'site_id' => null,'order' => ['url', 'price asc'],- 'taxonomy_item_id' => NULL,+ 'taxonomy_item_id' => null,'page' => 1,- 'parent_id' => NULL,+ 'parent_id' => null,+ 'levels' => null,];- function results() {+ /**+ * Get category pages with embedded post counts and images.+ *+ * @return array<string, mixed> Pages data with categories containing post counts and images.+ */+ public function results(): array {$category = new \Vvveb\Sql\CategorySQL();$results = $category->getCategoriesPages($this->options);@@ -52,16 +58,17 @@ class Pages extends ComponentBase {$parent_id = $category['parent_id'] ?? false;$category['active'] = false;- if (! isset($category['children'])) {- $category['children'] = 0;+ if (!isset($category['children'])) {+ $category['children'] = 0;+ $category['posts_count'] = 0;}- if (isset($category['post']) && $category['post'] && $category['post'][0] = '[') {+ if ((isset($category['post']) && $category['post']) && $category['post'][0] === '[') {$category['post'] = json_decode($category['post'], true);if (is_array($category['post'])) {if (isset($this->options['posts_limit'])) {- $category['post'] = array_slice($category['post'], 0 , $this->options['posts_limit']);+ $category['post'] = array_slice($category['post'], 0, $this->options['posts_limit']);if (isset($category['image'])) {$category['image'] = Images::image($category['image'], 'post', $this->options['image_size'] ?? 'medium');@@ -90,7 +97,7 @@ class Pages extends ComponentBase {}}- list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);+ [$results] = Event :: trigger(__CLASS__, __FUNCTION__, $results);return $results;}diff --git a/app/component/category.php b/app/component/category.phpindex b353d6b..fe70b87 100755--- a/app/component/category.php+++ b/app/component/category.php@@ -24,37 +24,61 @@ namespace Vvveb\Component;use Vvveb\System\Component\ComponentBase;use Vvveb\System\Event;+use Vvveb\System\Images;+use function Vvveb\url;class Category extends ComponentBase {- public static $defaultOptions = [- 'start' => 0,- 'language_id' => 1,- 'site_id' => 1,- 'count' => ['url', 7],- 'id_manufacturer' => NULL,- 'order' => ['url', 'price asc'],- 'id_category' => 'url',- 'slug' => 'url',+ public static array $defaultOptions = [+ 'taxonomy_item_id' => 'url',+ 'slug' => 'url',+ 'type' => null,+ 'post_type' => null,+ 'language_id' => null,+ 'site_id' => null,];- public $cacheExpire = 0; //seconds+ public int $cacheExpire = 0;- function __construct($class = __CLASS__) {- return parent::__construct($class);+ /**+ * Disable caching for category component.+ *+ * @return null Always returns null to disable caching.+ */+ public function cacheKey(): ?string {+ return null;}- function cacheKey() {- //disable caching- return false;- }-- function results() {+ /**+ * Get single category details with URL and image.+ *+ * @return array<string, mixed> Category data with URL, full-url, and image_url.+ */+ public function results(): array {$product = new \Vvveb\Sql\CategorySQL();$results = $product->getCategory($this->options);- //$_REQUEST['taxonomy_item_id'] = $results['taxonomy_item_id'];+ if ($results) {+ $taxonomy_type = 'category';++ if (isset($this->options['type']) && $this->options['type'] === 'tags') {+ $taxonomy_type = 'tag';+ }++ if (isset($this->options['post_type']) && $this->options['post_type']) {+ $results['post_type'] = $this->options['post_type'];+ }++ $url = ['slug' => $results['slug']];++ $results['url'] = url('content/' . $taxonomy_type . '/index', $url);+ $results['full-url'] = url('content/' . $taxonomy_type . '/index', $url + ['host' => SITE_URL, 'scheme' => $_SERVER['REQUEST_SCHEME'] ?? 'http']);++ if (isset($results['image'])) {+ $results['image_url'] = Images::image($results['image'], 'taxonomy_item');+ }+ }- list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);+ [$results] = Event :: trigger(__CLASS__, __FUNCTION__, $results);return $results;}diff --git a/app/component/checkout.php b/app/component/checkout.phpindex 190c75b..2ec8d9c 100755--- a/app/component/checkout.php+++ b/app/component/checkout.php@@ -22,30 +22,41 @@namespace Vvveb\Component;+use Vvveb\System\Cart\Cart as ShoppingCart;use Vvveb\System\Component\ComponentBase;+use Vvveb\System\Event;class Checkout extends ComponentBase {- public static $defaultOptions = [+ public static array $defaultOptions = ['language_id' => null,'site_id' => null,];- public $cacheExpire = 0; //seconds+ public int $cacheExpire = 0;- function cacheKey() {- //disable caching- return false;- }+ protected array $options = [];- protected $options = [];+ /**+ * Disable caching for checkout component.+ *+ * @return null Always returns null to disable caching.+ */+ public function cacheKey(): ?string {+ return null;+ }- function results() {+ /**+ * Get checkout results including cart contents and totals.+ *+ * @return array<string, mixed> Checkout data with product, total_items, and total.+ */+ public function results(): array {$cart = ShoppingCart::getInstance($this->options);$results['product'] = $cart->getAll();$results['total_items'] = $cart->getNoProducts();$results['total'] = '500$';- list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);+ [$results] = Event :: trigger(__CLASS__, __FUNCTION__, $results);return $results;}diff --git a/app/component/checkout/payment.php b/app/component/checkout/payment.phpold mode 100755new mode 100644index 9aee77f..d1140e9--- a/app/component/checkout/payment.php+++ b/app/component/checkout/payment.php@@ -28,21 +28,30 @@ use Vvveb\System\Event;use Vvveb\System\Payment as PaymentApi;class Payment extends ComponentBase {- public static $defaultOptions = [+ public static array $defaultOptions = ['checkout' => null,];- public $cacheExpire = 0; //no cache+ public int $cacheExpire = 0;- function cacheKey() {- //disable caching- return false;+ /**+ * Disable caching for payment component.+ *+ * @return null Always returns null to disable caching.+ */+ public function cacheKey(): ?string {+ return null;}- function results() {+ /**+ * Get available payment methods with count.+ *+ * @return array<string, mixed> Payment data with payment methods and count.+ */+ public function results(): array {$checkoutInfo = [];- if ($this->options['checkout']) {+ if (isset($this->options['checkout']) && $this->options['checkout']) {$checkoutInfo = sess('checkout', []) ?? [];}@@ -50,8 +59,10 @@ class Payment extends ComponentBase {$payment = PaymentApi::getInstance();$results['payment'] = $payment->getMethods($checkoutInfo);$results['count'] = $results['payment'] ? count($results['payment']) : 0;+ //$siteSettings = siteSettings();+ //$results['default'] = $siteSettings['payment_method'] ?? '';- list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);+ [$results] = Event :: trigger(__CLASS__, __FUNCTION__, $results);return $results;}diff --git a/app/component/checkout/shipping.php b/app/component/checkout/shipping.phpold mode 100755new mode 100644index cabc807..2e7bc0d--- a/app/component/checkout/shipping.php+++ b/app/component/checkout/shipping.php@@ -28,21 +28,30 @@ use Vvveb\System\Event;use Vvveb\System\Shipping as ShippingApi;class Shipping extends ComponentBase {- public static $defaultOptions = [+ public static array $defaultOptions = ['checkout' => null,];- public $cacheExpire = 0; //no cache+ public int $cacheExpire = 0;- function cacheKey() {- //disable caching- return false;+ /**+ * Disable caching for shipping component.+ *+ * @return null Always returns null to disable caching.+ */+ public function cacheKey(): ?string {+ return null;}- function results() {+ /**+ * Get available shipping methods with count.+ *+ * @return array<string, mixed> Shipping data with shipping methods and count.+ */+ public function results(): array {$checkoutInfo = [];- if ($this->options['checkout']) {+ if (isset($this->options['checkout']) && $this->options['checkout']) {$checkoutInfo = sess('checkout', []) ?? [];}@@ -50,8 +59,10 @@ class Shipping extends ComponentBase {$shipping = ShippingApi::getInstance();$results['shipping'] = $shipping->getMethods($checkoutInfo);$results['count'] = $results['shipping'] ? count($results['shipping']) : 0;+ //$siteSettings = siteSettings();+ //$results['default'] = $siteSettings['payment_method'] ?? '';- list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);+ [$results] = Event :: trigger(__CLASS__, __FUNCTION__, $results);return $results;}diff --git a/app/component/comments.php b/app/component/comments.phpindex e626c71..d0edca2 100755--- a/app/component/comments.php+++ b/app/component/comments.php@@ -24,49 +24,51 @@ namespace Vvveb\Component;use function Vvveb\model;use function Vvveb\session as sess;-use Vvveb\Sql\CommentSQL;use Vvveb\System\Component\ComponentBase;use Vvveb\System\Event;use Vvveb\System\Images;use function Vvveb\url;class Comments extends ComponentBase {- protected $type = 'comment';+ protected string $type = 'comment';- protected $route = 'content/post/index';+ protected string $route = 'content/post/index';- protected $modelName = 'comment';+ protected string $modelName = 'comment';- public static $defaultOptions = [+ public static array $defaultOptions = ['post_id' => 'url','user_id' => null,'slug' => 'url',- 'post_title' => NULL, //include post title (for recent comments etc)+ 'post_title' => null, //include post title (for recent comments etc)'status' => 1, //approved comments- 'language_id' => NULL,+ 'language_id' => null,'start' => 0,'limit' => 10,- 'order' => 'asc', //desc+ 'order' => 'asc',];- public $cacheExpire = 0; //no cache+ public int $cacheExpire = 0;- //called when fetching data, when cache expires- function results() {- $this->modelInstance = model($this->modelName); //new CommentSQL();+ /**+ * Get comments sorted by parent hierarchy with avatars, URLs, and levels.+ *+ * @return array<string, mixed> Comments data with sorted comments, levels, and URLs.+ */+ public function results(): array {+ $this->modelInstance = model($this->modelName);$results = $this->modelInstance->getAll($this->options);- $results[$this->type] = $results[$this->type] ?? [];+ $results[$this->type] ??= [];$order = $this->options['order'];if ($results && isset($results[$this->type])) {//sort comments by parent id and add child comments below parent- //usort($results[$this->type], function ($a, $b) use ($order) {- uasort($results[$this->type], function ($a, $b) use ($order) {+ uasort($results[$this->type], function($a, $b) use ($order) {//both root parents or both have same parentif (($a['parent_id'] == 0 && $b['parent_id'] == 0) ||- ($a['parent_id'] == $b['parent_id'])) {- if ($order == 'desc') {+ ($a['parent_id'] === $b['parent_id'])) {+ if ($order === 'desc') {return $b[$this->type . '_id'] <=> $a[$this->type . '_id'];} else {return $a[$this->type . '_id'] <=> $b[$this->type . '_id'];@@ -83,27 +85,19 @@ class Comments extends ComponentBase {return $a['parent_id'] <=> $b[$this->type . '_id'];}- //b has parent bigger then a id- if ($b['parent_id'] != 0) {- return $a[$this->type . '_id'] <=> $b['parent_id'];- }-- return 0;+ //a is root, b has parent+ return $a[$this->type . '_id'] <=> $b['parent_id'];});$level = 0;$parent_id = 0;+ $language = ['language' => $this->options['language']];- $language = ['language'=> $this->options['language']];-- if (self :: $global['default_language'] != self :: $global['language']) {- } else {- if (!self :: $global['default_lang_slug']) {- $language = [];- }+ if (self :: $global['default_language'] === self :: $global['language'] && !self :: $global['default_lang_slug']) {+ $language = [];}-+foreach ($results[$this->type] as $id => &$comment) {if ($comment['parent_id'] == 0) {$level = 0;@@ -128,22 +122,22 @@ class Comments extends ComponentBase {$comment['pubDate'] = date('r', strtotime($comment['created_at']));$anchor = '#comment-' . $comment[$this->type . '_id'];-+//url$url = $language;- if ($comment['type'] != 'post' && $comment['type'] != 'page') {+ if ($comment['type'] !== 'post' && $comment['type'] !== 'page') {$url['type'] = $comment['type'];$type = 'post';}-+//if translation is missing slug is not availableif (isset($comment['slug']) && $comment['slug']) {$url['slug'] = $comment['slug'];} else {$url['post_id'] = $comment['post_id'];}-+$comment['url'] = url($this->route, $url) . $anchor;$comment['full-url'] = url($this->route, $url + ['host' => SITE_URL, 'scheme' => $_SERVER['REQUEST_SCHEME'] ?? 'http']) . $anchor;}@@ -152,25 +146,30 @@ class Comments extends ComponentBase {}}- //list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);-return $results;}- //called on each request- function request(&$results, $index = 0) {+ /**+ * Merge pending user comments from session into results.+ *+ * @param array<string, mixed> &$results Component results to modify.+ * @param int $index Request index.+ *+ * @return array<string, mixed> Modified results with pending comments merged.+ */+ public function request(array &$results, int $index = 0): array {//check for user pending comments$slug = $this->options['slug'] ?? false;$pendingComments = sess($this->type, []);if ($slug && $pendingComments && isset($pendingComments[$slug])) {$comments = $pendingComments[$slug];- $results[$this->type] = $results[$this->type] + $comments;+ $results[$this->type] += $comments;$results['count'] += count($comments);}//for component event convention use `results` as function- list($results) = Event :: trigger(__CLASS__, 'results', $results);+ [$results] = Event :: trigger(__CLASS__, 'results', $results);return $results;}diff --git a/app/component/compare.php b/app/component/compare.phpindex 1f1281a..008c920 100644--- a/app/component/compare.php+++ b/app/component/compare.php@@ -26,13 +26,20 @@ use Vvveb\System\Component\ComponentBase;use Vvveb\System\Event;class Compare extends ComponentBase {- public static $defaultOptions = [+ public static array $defaultOptions = [];- public $options = [];+ public array $options = [];- function results() {- list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);+ /**+ * Get product comparison results.+ *+ * @return array<string, mixed> Comparison data triggered by event.+ */+ public function results(): array {+ $results = [];++ [$results] = Event :: trigger(__CLASS__, __FUNCTION__, $results);return $results;}diff --git a/app/component/content/archives.php b/app/component/content/archives.phpindex cc5891d..ebe1d4a 100755--- a/app/component/content/archives.php+++ b/app/component/content/archives.php@@ -27,36 +27,38 @@ use Vvveb\System\Event;use Vvveb\System\Locale;class Archives extends ComponentBase {- public static $defaultOptions = [+ public static array $defaultOptions = ['start' => 0,'language_id' => 1,'site_id' => 1,'count' => ['url', 4],- 'id_manufacturer' => NULL,+ 'id_manufacturer' => null,'order' => ['url', 'price asc'],- 'id_category' => NULL,+ 'id_category' => null,'limit' => 0,- 'start' => 1,'type' => 'post',- 'interval' => 'month', //year, month, day+ 'interval' => 'month',];- function results() {+ /**+ * Get content archives with localized month names and URLs.+ *+ * @return array<string, mixed> Archives data with formatted month names and archive URLs.+ */+ public function results(): array {$post = new \Vvveb\Sql\PostSQL();$results = $post->getArchives($this->options) ?? [];- $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 ($results['archives'] as $index => &$archive) {if (isset($archive['month'])) {$monthNum = $archive['month'];- //$dateObj = \DateTime::createFromFormat('!m', $monthNum);- //$monthName = $dateObj->format('F');$archive['month_text'] = $monthNum;@@ -64,7 +66,7 @@ class Archives extends ComponentBase {$archive['month_text'] = ucfirst(datefmt_format($df, $dt));$dt->setDate(0, $archive['month'], 0);} 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']));}}@@ -78,7 +80,7 @@ class Archives extends ComponentBase {$archive['url'] = htmlspecialchars(\Vvveb\url('content/archive/index', $archive));}- list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);+ [$results] = Event :: trigger(__CLASS__, __FUNCTION__, $results);return $results;}diff --git a/app/component/content/categories.php b/app/component/content/categories.phpindex 492696d..a532116 100755--- a/app/component/content/categories.php+++ b/app/component/content/categories.php@@ -29,32 +29,37 @@ use Vvveb\System\Images;use function Vvveb\url;class Categories extends ComponentBase {- public static $defaultOptions = [+ public static array $defaultOptions = ['start' => 0,'limit' => 7,- 'site_id' => NULL,- 'language_id' => NULL,+ 'site_id' => null,+ 'language_id' => null,'order' => ['url', 'price asc'],- 'taxonomy_id' => NULL,- 'post_id' => NULL,- 'parent_id' => NULL,- 'search' => NULL,- 'type' => 'categories', //tags+ 'taxonomy_id' => null,+ 'post_id' => null,+ 'parent_id' => null,+ 'search' => null,+ 'type' => 'categories','post_type' => 'post',- 'count' => false, //include number of posts+ 'count' => false,'parents_only' => false,'parents_children_only' => false,'parents_without_children' => false,];- function results() {+ /**+ * Get content categories with child counts, images, and URLs.+ *+ * @return array<string, mixed> Categories data with nested children counts.+ */+ public function results(): array {$category = new CategorySQL();$this->options['post_categories'] = true;- $results = $category->getCategories($this->options);- $taxonomy_type = 'category';+ $results = $category->getCategories($this->options);+ $taxonomy_type = 'category';- if (isset($this->options['type']) && $this->options['type'] == 'tags') {+ if (isset($this->options['type']) && $this->options['type'] === 'tags') {$taxonomy_type = 'tag';}@@ -64,7 +69,7 @@ class Categories extends ComponentBase {$parent_id = $category['parent_id'] ?? false;$category['active'] = false;- if (! isset($category['children'])) {+ if (!isset($category['children'])) {$category['children'] = 0;}@@ -95,13 +100,20 @@ class Categories extends ComponentBase {}}- list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);+ [$results] = Event :: trigger(__CLASS__, __FUNCTION__, $results);return $results;}- //called on each request- function request(&$results, $index = 0) {+ /**+ * Set active category based on current request module and category_id.+ *+ * @param array<string, mixed> $results Component results to modify.+ * @param int $index Request index.+ *+ * @return array<string, mixed> Modified results with active flags.+ */+ public function request(array &$results, int $index = 0): array {$module = \Vvveb\getModuleName();$categoryId = false;@@ -121,10 +133,9 @@ class Categories extends ComponentBase {if ($categoryId == $category['taxonomy_item_id']) {$key = key($categories);$categories[$key]['active'] = true;- //$category['active'] = true;- $categoryId = $category['parent_id'];+ $categoryId = $category['parent_id'];- if (! $categoryId) {+ if (!$categoryId) {break;}}diff --git a/app/component/content/tags.php b/app/component/content/tags.phpold mode 100644new mode 100755index ec75ac4..60f23b6--- a/app/component/content/tags.php+++ b/app/component/content/tags.php@@ -26,12 +26,12 @@ use Vvveb\System\Component\ComponentBase;use Vvveb\System\Event;class Tags extends ComponentBase {- public static $defaultOptions = [- 'language_id' => NULL,- 'count' => NULL,- 'id_manufacturer' => NULL,+ public static array $defaultOptions = [+ 'language_id' => null,+ 'count' => null,+ 'id_manufacturer' => null,'order' => ['url', 'price asc'],- 'id_category' => NULL,+ 'id_category' => null,'start' => 0,'limit' => 7,'page' => 1,@@ -42,11 +42,16 @@ class Tags extends ComponentBase {'parents_without_children' => false,];- function results() {+ /**+ * Get content tags from category taxonomy.+ *+ * @return array<string, mixed> Tags data from category query.+ */+ public function results(): array {$category = new \Vvveb\Sql\CategorySQL();$results = $category->getCategories($this->options);- list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);+ [$results] = Event :: trigger(__CLASS__, __FUNCTION__, $results);return $results;}diff --git a/app/component/currency.php b/app/component/currency.phpindex e7f0529..afe8fd4 100755--- a/app/component/currency.php+++ b/app/component/currency.php@@ -27,28 +27,36 @@ use Vvveb\System\Component\ComponentBase;use Vvveb\System\Event;use Vvveb\System\Locale;-class Currency extends ComponentBase {- public static $defaultOptions = [- 'start' => 1,- 'limit' => 1000,- 'status' => 1,- 'site_only' => true, //show only site available currencies otherwise show all active- 'default' => null,+ public static array $defaultOptions = [+ 'start' => 1,+ 'limit' => 1000,+ 'status' => 1,+ 'site_only' => true,+ 'default' => null,];- function cacheKey() {- //disable caching- return false;+ /**+ * Disable caching for currency component.+ *+ * @return null Always returns null to disable caching.+ */+ public function cacheKey(): ?string {+ return null;}- function results() {+ /**+ * Get available currencies and current active currency.+ *+ * @return array<string, mixed> Currency data with active, current, and currency list.+ */+ public function results(): array {$results = [];$results['active'] = false;$results['current'] = self :: $global['currency'];$results['currency'] = Locale::availableCurrencies();- if (isset($results['currency']) && $results['currency']) {+ if ($results['currency']) {if (isset($this->options['site_only']) && $this->options['site_only'] && self :: $global['currencies']) {$results['currency'] = array_intersect_key($results['currency'], self :: $global['currencies']);}@@ -56,13 +64,13 @@ class Currency extends ComponentBase {$code = session('currency') ?? self :: $global['currency'];if ($code && isset($results['currency'][$code])) {- $currency = $results['currency'][$code] ?? [];+ $currency = $results['currency'][$code];$results['current'] = $code;$results['active'] = $currency;}}- list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);+ [$results] = Event :: trigger(__CLASS__, __FUNCTION__, $results);return $results;}diff --git a/app/component/digital_assets.php b/app/component/digital_assets.phpold mode 100644new mode 100755index d0825f4..fc720cc--- a/app/component/digital_assets.php+++ b/app/component/digital_assets.php@@ -29,7 +29,7 @@ use Vvveb\System\Event;use function Vvveb\url;class Digital_assets extends ComponentBase {- public static $defaultOptions = [+ public static array $defaultOptions = ['start' => 0,'user_id' => null,'product_id' => null,@@ -38,11 +38,16 @@ class Digital_assets extends ComponentBase {'digital_asset' => ['url', 'price asc'],];- public $options = [];+ public array $options = [];- public $cacheExpire = 0; //no cache+ public int $cacheExpire = 0;- function results() {+ /**+ * Get digital assets with secure download URLs.+ *+ * @return array<string, mixed> Digital assets data with download URLs.+ */+ public function results(): array {$digital_asset = new Digital_assetSQL();$results = $digital_asset->getAll($this->options);@@ -50,7 +55,7 @@ class Digital_assets extends ComponentBase {if (isset($results['digital_asset'])) {foreach ($results['digital_asset'] as $id => &$digital_asset) {- $digital_asset['url'] = url('user/downloads/download',[+ $digital_asset['url'] = url('user/downloads/download', ['digital_asset_id' => $digital_asset['digital_asset_id'],'public' => str_replace(['/', '-'], '_', $digital_asset['public']),'customer_order_id' => $digital_asset['customer_order_id'],@@ -59,7 +64,7 @@ class Digital_assets extends ComponentBase {}}- list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);+ [$results] = Event :: trigger(__CLASS__, __FUNCTION__, $results);return $results;}diff --git a/app/component/fields.php b/app/component/fields.phpindex 2c90b83..9baf3f9 100644--- a/app/component/fields.php+++ b/app/component/fields.php@@ -27,26 +27,31 @@ use Vvveb\System\Component\ComponentBase;use Vvveb\System\Event;class Fields extends ComponentBase {- public static $defaultOptions = [- 'start' => 0,- 'limit' => 100,- 'site_id' => NULL,- 'language_id' => NULL,- 'field_group_id' => NULL,- 'type' => NULL,- 'subtype' => NULL,- 'post_type' => NULL,- 'product_id' => 'url',- 'post_id' => 'url',- 'user_id' => 'url',- 'order_id' => 'url',- 'taxonomy_item_id' => 'url',- 'field_id' => NULL, //array with filed_id's to filter+ public static array $defaultOptions = [+ 'start' => 0,+ 'limit' => 100,+ 'site_id' => null,+ 'language_id' => null,+ 'field_group_id' => null,+ 'type' => null,+ 'subtype' => null,+ 'post_type' => null,+ 'product_id' => 'url',+ 'post_id' => 'url',+ 'user_id' => 'url',+ 'order_id' => 'url',+ 'taxonomy_item_id' => 'url',+ 'field_id' => null,];- public $cacheExpire = 0; //no cache+ public int $cacheExpire = 0;- function results() {+ /**+ * Get custom field values for the specified entity type with decoded settings.+ *+ * @return array<string, mixed> Fields data with field list containing decoded settings and values.+ */+ public function results(): array {$model = false;$field_type = trim($this->options['type'] ?? '');@@ -55,11 +60,11 @@ class Fields extends ComponentBase {$model = model($field_type . '_field_value');}- if (! $model) {+ if (!$model) {return [];}- if (! $this->options['subtype']) {+ if (!$this->options['subtype']) {unset($this->options['subtype']);}@@ -71,7 +76,7 @@ class Fields extends ComponentBase {$field['name'] = $field['settings']['name'];$field['type'] = $field['settings']['type'];- if ($field['value'] && $field['value'][0] == '{') {+ if ($field['value'] && $field['value'][0] === '{') {$field['value'] = json_decode($field['value'], true);}}@@ -80,13 +85,20 @@ class Fields extends ComponentBase {$results['field'] = $results[$modelName] ?? [];unset($results[$modelName]);- list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);+ [$results] = Event :: trigger(__CLASS__, __FUNCTION__, $results);return $results;}- //called on each request- function request(&$results, $index = 0) {+ /**+ * Filter results by field_id array if specified.+ *+ * @param array<string, mixed> &$results Component results to filter.+ * @param int $index Request index.+ *+ * @return array<string, mixed> Filtered results.+ */+ public function request(array &$results, int $index = 0): array {if (isset($this->options['field_id']) && is_array($this->options['field_id'])) {$results = array_intersect_key($results, $this->options['field_id']);}diff --git a/app/component/language.php b/app/component/language.phpindex 8a0e64c..db2ae7a 100755--- a/app/component/language.php+++ b/app/component/language.php@@ -23,7 +23,6 @@namespace Vvveb\Component;use function Vvveb\isSecure;-use Vvveb\System\Cache;use Vvveb\System\Component\ComponentBase;use Vvveb\System\Core\Request;use Vvveb\System\Core\View;@@ -32,24 +31,32 @@ use Vvveb\System\Locale;use function Vvveb\url;class Language extends ComponentBase {- public static $defaultOptions = [- 'start' => 1,- 'limit' => 1000,- 'status' => 1,- 'site_only' => true, //show only site available languages otherwise show all active- 'default' => null, //'en',+ public static array $defaultOptions = [+ 'start' => 1,+ 'limit' => 1000,+ 'status' => 1,+ 'site_only' => true,+ 'default' => null,];- function cacheKey() {- //disable caching- return false;+ /**+ * Disable caching for language component.+ *+ * @return null Always returns null to disable caching.+ */+ public function cacheKey(): ?string {+ return null;}- //called when fetching data, when cache expires- function results() {+ /**+ * Get available languages with URLs, hreflang tags, and active language info.+ *+ * @return array<string, mixed> Language data with language list, active language, and hreflang.+ */+ public function results(): array {$results = [];- $options = $this->options;+ $options = $this->options;$results['language'] = Locale::availableLanguages();$publicPath = \Vvveb\publicUrlPath();@@ -64,13 +71,13 @@ class Language extends ComponentBase {$results['current'] = $code = self :: $global['language'];$language = $results['language'][$code] ?? [];- if (! $language && isset($options['default'])) {+ if (!$language && isset($options['default'])) {$language = $results['language'][$options['default']] ?? [];}$code = $language['code'] ?? '';$slug = $language['slug'] ?? '';- $shortcode = \Vvveb\filter('/[a-z]+/',$code);+ $shortcode = \Vvveb\filter('/[a-z]+/', $code);$img = "{$publicPath}img/flags/$shortcode.png";$results['active'] = [];@@ -83,7 +90,7 @@ class Language extends ComponentBase {$scheme = isSecure() ? 'https' : 'http';foreach ($results['language'] as $code => &$language) {- $shortcode = \Vvveb\filter('/[a-z]+/',$code);+ $shortcode = \Vvveb\filter('/[a-z]+/', $code);$content = [];$lang = [];$language['img'] = "{$publicPath}img/flags/$shortcode.png";@@ -92,13 +99,12 @@ class Language extends ComponentBase {if (isset($view->content)) {$content = $view->content[$language['slug']] ?? [];//if translation is missing there is no slug- if (! isset($content['slug']) || ! $content['slug']) {+ if (!isset($content['slug']) || !$content['slug']) {unset($content['slug']);}}- $params = ['language' => $language['slug'], 'host' => $_SERVER['HTTP_HOST'] ?? '', 'scheme' => $scheme] + $content + $request->get;-+ $params = ['language' => $language['slug'], 'host' => $_SERVER['HTTP_HOST'] ?? '', 'scheme' => $scheme] + $content + $request->get;if (($language['language_id'] == $options['default_language_id']) && !self :: $global['default_lang_slug']) {unset($params['language']);@@ -113,7 +119,7 @@ class Language extends ComponentBase {$view->hreflang = $hreflang;}- list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);+ [$results] = Event :: trigger(__CLASS__, __FUNCTION__, $results);return $results;}diff --git a/app/component/menu.php b/app/component/menu.phpindex 700b6fd..069752d 100644--- a/app/component/menu.php+++ b/app/component/menu.php@@ -25,9 +25,9 @@ namespace Vvveb\Component;use function Vvveb\__;use function Vvveb\getCurrentUrl;use function Vvveb\sanitizeHTML;-use Vvveb\Sql\menuSQL;-use Vvveb\Sql\postSQL;-use Vvveb\Sql\productSQL;+use Vvveb\Sql\MenuSQL;+use Vvveb\Sql\PostSQL;+use Vvveb\Sql\ProductSQL;use Vvveb\System\Component\ComponentBase;use Vvveb\System\Event;use Vvveb\System\Images;@@ -35,16 +35,21 @@ use Vvveb\System\Sites;use function Vvveb\url;class Menu extends ComponentBase {- public static $defaultOptions = [- 'start' => 0, //defaut, override from html+ public static array $defaultOptions = [+ 'start' => 0,'limit' => 10000,- 'menu_id' => null, //unset, set from html- 'slug' => null, //unset, set from html- 'site_id' => null, //unset, set from html- 'language_id' => null, //unset, set from html+ 'menu_id' => null,+ 'slug' => null,+ 'site_id' => null,+ 'language_id' => null,];- function results() {+ /**+ * Get menu items with product/post URLs, images, and hierarchy.+ *+ * @return array<string, mixed> Menu data with menu_item list and count.+ */+ public function results(): array {$options = $this->options;//if menu id is set then ignore slug@@ -52,12 +57,12 @@ class Menu extends ComponentBase {unset($options['slug']);}- $menuSql = new menuSQL();- $results = $menuSql->getMenuItems($options);+ $menuSQL = new MenuSQL();+ $results = $menuSQL->getMenuItems($options);$noTranslationText = '[' . __('No translation') . ']';$defaultLanguage = true;- $language = ['language'=> $options['language']];+ $language = ['language' => $options['language']];if (self :: $global['default_language'] != self :: $global['language']) {$defaultLanguage = false;@@ -69,14 +74,16 @@ class Menu extends ComponentBase {//count the number of child menus (subcategories) for each categoryif (isset($results['menu_item'])) {- $productIds = [];- $postIds = [];+ $productIds = [];+ $postIds = [];+ $taxonomyProducts = [];+ $taxonomyPosts = [];foreach ($results['menu_item'] as $taxonomy_item_id => &$category) {$parent_id = $category['parent_id'] ?? false;$type = $category['type'] ?? 'link';- if (! isset($category['children'])) {+ if (!isset($category['children'])) {$category['children'] = 0;}@@ -100,79 +107,82 @@ class Menu extends ComponentBase {$parent['children'] = 1;}- if ($type == 'text') {+ if ($type === 'text') {$parent['has-text'] = true;- $category['content'] = $category['content'] ?? (! $defaultLanguage ? $noTranslationText : null);+ $category['content'] = $category['content'] ?? (!$defaultLanguage ? $noTranslationText : null);}}- if ($type == 'product') {+ if ($type === 'product') {$productIds[$taxonomy_item_id] = $category['item_id'];$taxonomyProducts[$category['item_id']][] = $taxonomy_item_id;}- if (($type == 'post' || $type == 'page') && $category['item_id']) {+ if (($type === 'post' || $type === 'page') && $category['item_id']) {$postIds[$category['item_id']] = $category['item_id'];$taxonomyPosts[$category['item_id']][] = $taxonomy_item_id;}- if ($type == 'home') {+ if ($type === 'home') {$category['url'] = url('index/index', $language);$category['name'] = $category['name'] ?: __('Home');}- if ($type == 'blog') {+ if ($type === 'blog') {$category['url'] = url('content', $language);$category['name'] = $category['name'] ?: __('Blog');}- if ($type == 'shop') {+ if ($type === 'shop') {$category['url'] = url('product/index', $language);$category['name'] = $category['name'] ?: __('Shop');}- if ($type == 'link' && isset($category['url']) && (strncmp($category['url'], 'http', 4) !== 0)) {- $category['url'] = (V_SUBDIR_INSTALL ? V_SUBDIR_INSTALL : '') . Sites::url($category['url'] ?? '');+ if (($type === 'link' && isset($category['url'])) && (strncmp($category['url'], 'http', 4) !== 0)) {+ $category['url'] = V_SUBDIR_INSTALL . Sites::url($category['url'] ?? '');}- $category['name'] = $category['name'] ?? (! $defaultLanguage ? $noTranslationText : null);- $category['language_id'] = $category['language_id'] ?? $options['language_id'];+ $category['name'] = $category['name'] ?? (!$defaultLanguage ? $noTranslationText : null);+ $category['language_id'] ??= $options['language_id'];}//get product itemsif ($productIds) {$productOptions = [- 'product_id' => $productIds,+ 'product_id' => array_values($productIds),'language_id' => $options['language_id'],- //'site_id' => $options['site_id'],];- $productSql = new productSql();- $products = $productSql->getAll($productOptions);+ $productSQL = new ProductSQL();+ $products = $productSQL->getAll($productOptions);- if (isset($products['products']) && $products['products']) {- foreach ($products['products'] as $product) {- foreach ($taxonomyPosts[$product['product_id']] as $taxonomy_item_id) {- $taxonomy_item_id = $productTaxonomy[$product['product_id']];- $category = &$results['menu_item'][$taxonomy_item_id];- $route = "product/{$category['type']}/index";-- $url = $language;+ if (!empty($products['product'])) {+ foreach ($products['product'] as $product) {+ //map back from product id to the menu items referencing it+ foreach ($taxonomyProducts[$product['product_id']] ?? [] as $taxonomy_item_id) {+ if (!isset($results['menu_item'][$taxonomy_item_id])) {+ continue;+ }++ $category = &$results['menu_item'][$taxonomy_item_id];+ $route = "product/{$category['type']}/index";++ $url = $language;- if ($product['type'] != 'product') {+ if (($product['type'] ?? 'product') != 'product') {$url['type'] = $product['type'];}//if translation is missing slug is not available- if (isset($product['slug'])) {+ if (isset($product['slug']) && $product['slug']) {$url['slug'] = $product['slug'];} else {$url['product_id'] = $product['product_id'];- }-+ }+$category['url'] = url($route, $url);- $category['name'] = $product['name'] ?? (! $defaultLanguage ? $noTranslationText : null);- $category['language_id'] = $product['language_id'] ?: $options['language_id'];+ $category['name'] = $product['name'] ?? (!$defaultLanguage ? $noTranslationText : null);+ $category['language_id'] = $product['language_id'] ?: ($options['language_id'] ?? null);}}}@@ -183,18 +193,17 @@ class Menu extends ComponentBase {$postOptions = ['post_id' => $postIds,'language_id' => $options['language_id'],- //'site_id' => $options['site_id'],];- $postSql = new postSql();- $posts = $postSql->getAll($postOptions);+ $postSQL = new PostSQL();+ $posts = $postSQL->getAll($postOptions);if (isset($posts['post']) && $posts['post']) {foreach ($posts['post'] as $post) {foreach ($taxonomyPosts[$post['post_id']] as $taxonomy_item_id) {- $category = &$results['menu_item'][$taxonomy_item_id];- $route = "content/{$category['type']}/index";- $url = $post['slug'] ? url($route, ['slug'=> $post['slug'], 'post_id'=> $post['post_id']] + $language) : '/';+ $category = &$results['menu_item'][$taxonomy_item_id];+ $route = "content/{$category['type']}/index";+ $url = $post['slug'] ? url($route, ['slug' => $post['slug'], 'post_id' => $post['post_id']] + $language) : '/';//url$url = $language;@@ -203,16 +212,16 @@ class Menu extends ComponentBase {$url['type'] = $post['type'];$type = 'post';}-+//if translation is missing slug is not availableif (isset($post['slug']) && $post['slug']) {$url['slug'] = $post['slug'];} else {$url['post_id'] = $post['post_id'];- }-+ }+$category['url'] = url($route, $url);- $category['name'] = $post['name'] ?? (! $defaultLanguage ? $noTranslationText : null);+ $category['name'] = $post['name'] ?? (!$defaultLanguage ? $noTranslationText : null);$category['language_id'] = $post['language_id'] ?? $options['language_id'];}}@@ -222,13 +231,20 @@ class Menu extends ComponentBase {$results = ['menu_item' => [], 'count' => 0];}- list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);+ [$results] = Event :: trigger(__CLASS__, __FUNCTION__, $results);return $results;}- //called on each request- function request(&$results, $index = 0) {+ /**+ * Set active menu item based on current URL match.+ *+ * @param array<string, mixed> $results Component results to modify.+ * @param int $index Request index.+ *+ * @return array<string, mixed> Modified results with active flags.+ */+ public function request(array &$results, int $index = 0): array {if (isset($results['menu_item'])) {$currentUrl = getCurrentUrl();@@ -240,10 +256,17 @@ class Menu extends ComponentBase {return $results;}- //called by editor on page save for each component on page- //this method is called from admin app- static function editorSave($id, $fields, $type = 'menu') {- $menu = new menuSQL();+ /**+ * Save menu item content from editor on page save.+ *+ * @param int $id Menu item ID.+ * @param array<int, array<string, mixed>> $fields Field data from editor.+ * @param string $type Menu type identifier.+ *+ * @return void+ */+ public static function editorSave(int $id, array $fields, string $type = 'menu'): void {+ $menu = new MenuSQL();$menu_item_content = [];$menu_item = [];@@ -253,16 +276,16 @@ class Menu extends ComponentBase {$name = trim(str_replace('item', '', $name), '- ');- if (! $name) {+ if (!$name) {continue;}- if ($name == 'name') {+ if ($name === 'name') {$menu_item_content[$name] = strip_tags($value);} else {- if ($name == 'content') {+ if ($name === 'content') {$menu_item_content[$name] = sanitizeHTML($value);- } else if ($name == 'img') {+ } elseif ($name === 'img') {} else {$menu_item[$name] = $value;}@@ -272,13 +295,11 @@ class Menu extends ComponentBase {$menu_item_content['language_id'] = self :: $global['language_id'];$menu_item['menu_item_id'] = $id;- if ($menu_item_content) {- $menu_item_content['content'] = $menu_item_content['content'] ?? '';- $menu_item['menu_item_content'][] = $menu_item_content;- }+ $menu_item_content['content'] ??= '';+ $menu_item['menu_item_content'][] = $menu_item_content;if ((isset($menu_item_content['name']) && $menu_item_content['name']) ||- (isset($menu_item_content['content']) && $menu_item_content['content'])) {+ !empty($menu_item_content['content'])) {$result = $menu->editMenuItem(['menu_item' => $menu_item, 'menu_item_id' => $id]);}}diff --git a/app/component/order.php b/app/component/order.phpold mode 100644new mode 100755index 2f65382..2775231--- a/app/component/order.php+++ b/app/component/order.php@@ -22,7 +22,7 @@namespace Vvveb\Component;-use function Vvveb\prefixArrayKeys;+use function Vvveb\humanReadable;use Vvveb\System\Cart\Currency;use Vvveb\System\Component\ComponentBase;use Vvveb\System\Core\Request;@@ -31,19 +31,25 @@ use Vvveb\System\Images;use Vvveb\System\Sites;class Order extends ComponentBase {- public static $defaultOptions = [+ public static array $defaultOptions = ['order_id' => null,'customer_order_id' => null,'user_id' => null,+ 'language_id' => null,'email' => null,'image_size' => 'thumb',];- public $options = [];+ public array $options = [];- public $cacheExpire = 0; //no cache+ public int $cacheExpire = 0;- function results() {+ /**+ * Get single order details with products, images, totals, and shipping/payment data.+ *+ * @return array<string, mixed> Order data with products, totals, and formatted prices.+ */+ public function results(): array {$results = [];$request = Request::getInstance();@@ -68,13 +74,20 @@ class Order extends ComponentBase {$product['images'] = json_decode($product['images'], true);foreach ($product['images'] as &$image) {- $image['image'] = $host . Images::image($image['image'], 'product', $this->options['image_size']);+ $image['image'] = Images::image($image['image'], 'product', $this->options['image_size']);+ //don't add host for remote images+ if (!str_contains($image['image'], ':')) {+ $image['image'] = $host . $image['image'];+ }}}if (isset($product['image']) && $product['image']) {- $product['image'] = $host . Images::image($product['image'], 'product', $this->options['image_size']);- //$product['images'][] = ['image' => Images::image($product['image'], 'product')];+ $product['image'] = Images::image($product['image'], 'product', $this->options['image_size']);+ //don't add host for remote images+ if (!str_contains($product['image'], ':')) {+ $product['image'] = $host . $product['image'];+ }}if (isset($product['option_value'])) {@@ -97,14 +110,33 @@ class Order extends ComponentBase {$order = &$results['order'];$order['total_formatted'] = $currency->format($order['total']);- $order['shipping_data'] = isset($order['shipping_data']) ? json_decode($order['shipping_data'], true) : [];- $order['payment_data'] = isset($order['payment_data']) ? json_decode($order['payment_data'], true) : [];+ $shippingData = isset($order['shipping_data']) ? json_decode($order['shipping_data'], true) : [];+ $paymentData = isset($order['payment_data']) ? json_decode($order['payment_data'], true) : [];++ if (!is_array($shippingData)) {+ $shippingData = [];+ }++ if (!is_array($paymentData)) {+ $paymentData = [];+ }- $order += prefixArrayKeys('shipping_', $order['shipping_data']) ?? [];- $order += prefixArrayKeys('payment_', $order['payment_data']) ?? [];+ $order['shipping_data'] = $shippingData;+ $order['payment_data'] = $paymentData;++ //human readable method titles, falling back to the stored method+ //key (minus the -index suffix) when the gateway did not record one+ $shippingMethod = preg_replace('/-\d+$/', '', (string)($order['shipping_method'] ?? ''));+ $paymentMethod = preg_replace('/-\d+$/', '', (string)($order['payment_method'] ?? ''));+ $order['shipping_title'] = $shippingData['title'] ?? $shippingData['gateway'] ?? ($shippingMethod ? humanReadable($shippingMethod) : '');+ $order['payment_title'] = $paymentData['title'] ?? $paymentData['gateway'] ?? ($paymentMethod ? humanReadable($paymentMethod) : '');+ $order['shipping_description'] = $shippingData['description'] ?? $shippingData['text'] ?? '';+ $order['payment_description'] = $paymentData['description'] ?? $paymentData['text'] ?? '';+ //legacy alias, the customer note column is `notes`+ $order['comment'] = $order['notes'] ?? '';}- list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);+ [$results] = Event :: trigger(__CLASS__, __FUNCTION__, $results);}return $results;diff --git a/app/component/orders.php b/app/component/orders.phpindex 7eeac97..c87485c 100755--- a/app/component/orders.php+++ b/app/component/orders.php@@ -28,7 +28,7 @@ use Vvveb\System\Images;use function Vvveb\url;class Orders extends ComponentBase {- public static $defaultOptions = [+ public static array $defaultOptions = ['start' => 0,'limit' => ['url', 4],'user_id' => null,@@ -47,18 +47,23 @@ class Orders extends ComponentBase {'site_id' => null,];- public $options = [];+ public array $options = [];- function results() {+ /**+ * Get orders list with images and order URLs.+ *+ * @return array<string, mixed> Orders data with order list and images.+ */+ public function results(): array {$orders = new \Vvveb\Sql\OrderSQL();if (isset($this->options['order_by']) &&- ! in_array($this->options['order_by'], ['order_id', 'created_at', 'updated_at'])) {+ !in_array($this->options['order_by'], ['order_id', 'created_at', 'updated_at'])) {unset($this->options['order_by']);}if (isset($this->options['direction']) &&- ! in_array($this->options['direction'], ['asc', 'desc'])) {+ !in_array($this->options['direction'], ['asc', 'desc'])) {unset($this->options['direction']);}@@ -67,7 +72,7 @@ class Orders extends ComponentBase {if (isset($results['order'])) {foreach ($results['order'] as $id => &$order) {if (isset($order['images'])) {- $order['images'] = json_decode($order['images'], 1);+ $order['images'] = json_decode($order['images'], true);foreach ($order['images'] as &$image) {$image = Images::image('order', $image);@@ -82,7 +87,7 @@ class Orders extends ComponentBase {}}- list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);+ [$results] = Event :: trigger(__CLASS__, __FUNCTION__, $results);return $results;}diff --git a/app/component/page.php b/app/component/page.phpdeleted file mode 100755index 61d2b0d..0000000--- a/app/component/page.php+++ /dev/null@@ -1,53 +0,0 @@-<?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\Component;--use Vvveb\System\Component\ComponentBase;-use Vvveb\System\Images;--class Page extends ComponentBase {- public static $defaultOptions = [- 'post_id' => 'url',- 'slug' => 'url',- 'language_id' => 1,- 'site_id' => 1,- ];-- function results() {- $page = new \Vvveb\Sql\PostSQL();-- $results = $page->get($this->options);-- if (isset($results['images'])) {- $results['images'] = Images::images('page', $results['images']);- }-- if (isset($results['image'])) {- $results['images'][] = Images::image('page', $results['image']);- }-- list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);-- return $results;- }-}diff --git a/app/component/post.php b/app/component/post.phpindex 5e9c0c8..31de82f 100755--- a/app/component/post.php+++ b/app/component/post.php@@ -33,33 +33,40 @@ use Vvveb\System\Event;use Vvveb\System\Traits\Post as PostTrait;use Vvveb\System\User\Admin;-class Post extends ComponentBase {+class Post extends ComponentBase {use PostTrait;- public static $defaultOptions = [+ public static array $defaultOptions = ['post_id' => 'url','language_id' => null,'site_id' => null,'slug' => 'url',- 'status' => 'publish', //'publish', 'draft', 'pending', 'private', 'scheduled'- 'comment_count' => 1, // flag to include post comments count- 'comment_status' => 1, // include only comments with status, 1 = published, 0 = unpublished/pending, 2 = spam, 3 = trash- 'type' => null, // filter by post type eg: post- 'image_size' => 'large', //options: xlarge, large, medium, thumb- 'image_resize' => null, //options: cs = Crop & resize, c = crop, r = resize, s = stretch+ 'status' => 'publish',+ 'comment_count' => 1,+ 'comment_status' => 1,+ 'type' => null,+ 'image_size' => 'large',+ 'image_resize' => null,];- public $cacheExpire = 0; //no cache+ public int $cacheExpire = 0;- //called when fetching data, when cache expires- function results() {+ /**+ * Get single post with content, images, and formatting.+ *+ * @return array<string, mixed> Post data with content, images, and metadata.+ */+ public function results(): array {$post = new PostSQL();$results = $post->get($this->options);- //$languages = availableLanguages();- if (! isset($this->options['date_format'])) {- $site = siteSettings();+ if (!isset($results['post_id'])) {+ return [];+ }++ if (!isset($this->options['date_format'])) {+ $site = siteSettings();$this->options['date_format'] = $site['date_format'] ?? 'human';}@@ -67,29 +74,38 @@ class Post extends ComponentBase {$this->post($results, $this->options);}- list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);+ [$results] = Event :: trigger(__CLASS__, __FUNCTION__, $results);return $results;}- //called on each request- function request(&$results, $index = 0) {- $created_at = $this->request->get['created_at'] ?? ''; //revision preview-- if ($results['password']) {+ /**+ * Handle password-protected posts and revision preview on each request.+ *+ * @param array<string, mixed> &$results Post data to modify.+ * @param int $index Request index.+ *+ * @return array<string, mixed> Modified post data.+ */+ public function request(array &$results, int $index = 0): array {+ $created_at = $this->request->get['created_at'] ?? '';++ if (isset($results['password']) && $results['password']) {if (isset($this->request->post['password'])) {- if ($results['password'] == $this->request->post['password']) {+ if ($results['password'] === $this->request->post['password']) {$results['password'] = '';+return $results;} else {$results['content'] = '<p>' . __('Invalid password!') . '</p>';$results['image'] = '';+return $results;}}$results['content'] = '';- $results['image'] = '';+ $results['image'] = '';}if ($created_at && $results['post_id']) {@@ -110,9 +126,16 @@ class Post extends ComponentBase {return $results;}- //called by editor on page save for each component on page- //this method is called from admin app- static function editorSave($id, $fields, $type = 'post') {+ /**+ * Save post content from editor on page save.+ *+ * @param int $id Post ID.+ * @param array<int, array<string, mixed>> $fields Field data from editor.+ * @param string $type Post type identifier.+ *+ * @return void+ */+ public static function editorSave(int $id, array $fields, string $type = 'post'): void {$posts = new PostSQL();$publicPath = \Vvveb\publicUrlPath() . 'media/';@@ -123,17 +146,17 @@ class Post extends ComponentBase {$name = $field['name'];$value = $field['value'];- if ($name == 'content') {+ if ($name === 'content') {$post_content[$name] = sanitizeHTML($value);} else {- if ($name == 'excerpt') {+ if ($name === 'excerpt') {$post_content[$name] = sanitizeHTML($value);} else {- if ($name == 'name') {+ if ($name === 'name') {$post_content[$name] = strip_tags($value);} else {- if ($name == 'image') {- $value = str_replace($publicPath,'', $value);+ if ($name === 'image') {+ $value = str_replace($publicPath, '', $value);}$post[$name] = $value;}@@ -143,13 +166,12 @@ class Post extends ComponentBase {if ($post_content) {$post_content['language_id'] = self :: $global['language_id'];- //$post['post_content']['post_id'] = $id;- $result = $posts->editContent(['post_content' => $post_content, 'post_id' => $id, 'language_id' => self :: $global['language_id']]);+ $result = $posts->editContent(['post_content' => $post_content, 'post_id' => $id, 'language_id' => self :: $global['language_id']]);}if ($post || $post_content) {$post['post_id'] = $id;- $result = $posts->edit(['post' => $post, 'post_content' => [], /* 'post_content' => [$post_content],*/ 'post_id' => $id]);+ $result = $posts->edit(['post' => $post, 'post_content' => [], 'post_id' => $id]);}}}diff --git a/app/component/posts.php b/app/component/posts.phpold mode 100644new mode 100755index 792e09c..881ac75--- a/app/component/posts.php+++ b/app/component/posts.php@@ -22,7 +22,6 @@namespace Vvveb\Component;-use function Vvveb\__;use function Vvveb\get;use function Vvveb\getSetting;use function Vvveb\siteSettings;@@ -34,7 +33,7 @@ use Vvveb\System\Traits\Post;class Posts extends ComponentBase {use Post;- public static $defaultOptions = [+ public static array $defaultOptions = ['page' => ['url'],'post_id' => 'url','language_id' => null,@@ -49,15 +48,14 @@ class Posts extends ComponentBase {'excerpt_limit' => 200,'comment_count' => 1,'comment_status' => 1,- 'taxonomy_item_id' => NULL,- 'taxonomy_item_slug' => NULL,- 'search' => NULL,- 'search_boolean' => NULL,- 'like' => NULL,- 'admin_id' => NULL,- //archive- 'month' => NULL,- 'year' => NULL,+ 'taxonomy_item_id' => null,+ 'taxonomy_item_slug' => null,+ 'search' => null,+ 'search_boolean' => null,+ 'like' => null,+ 'admin_id' => null,+ 'month' => null,+ 'year' => null,'image_size' => 'medium','categories' => null,'tags' => null,@@ -68,9 +66,14 @@ class Posts extends ComponentBase {'404' => null,];- public $options = [];+ public array $options = [];- function __construct($options) {+ /**+ * Initialize posts component with module-specific option overrides.+ *+ * @param array<string, mixed> $options Component options.+ */+ public function __construct(array $options = []) {parent::__construct($options);$module = \Vvveb\getModuleName();@@ -80,11 +83,11 @@ class Posts extends ComponentBase {break;case 'content/category':- if (isset($this->options['taxonomy_item_id']) && $this->options['taxonomy_item_id'] == 'page') {+ if (isset($this->options['taxonomy_item_id']) && $this->options['taxonomy_item_id'] === 'page') {$this->options['taxonomy_item_id'] = get('taxonomy_item_id');}- if (isset($this->options['taxonomy_item_slug']) && $this->options['taxonomy_item_slug'] == 'page') {+ if (isset($this->options['taxonomy_item_slug']) && $this->options['taxonomy_item_slug'] === 'page') {$this->options['taxonomy_item_slug'] = get('slug');}@@ -92,79 +95,87 @@ class Posts extends ComponentBase {}}- function cacheKey() {+ /**+ * Disable caching for search, pagination, or specific post lookups.+ *+ * @return string|null Parent cache key or null to disable caching.+ */+ public function cacheKey(): ?string {if (isset($this->options['search']) || isset($this->options['page']) || isset($this->options['post_id'])) {- return false;+ return null;}return parent::cacheKey();}- function results() {+ /**+ * Get posts list with filtering, sticky posts, pagination, and 404 handling.+ *+ * @return array<string, mixed> Posts data with post list, limit, start, search, and archive info.+ */+ public function results(): array {$posts = new PostSQL();- $this->options['limit'] = (int) ($this->options['limit'] ?? 4 ?: 4);+ $this->options['limit'] = max(1, (int)($this->options['limit'] ?? 4) ?: 4);- if (($page = $this->options['page'] ?? false) && is_numeric($page)) {+ if (($page = $this->options['page'] ?? false) && is_numeric($page) && $page > 0) {$this->options['start'] = ($page - 1) * ($this->options['limit']);}- $this->options['start'] = (int) ($this->options['start'] ?? 0 ?: 0);+ $this->options['start'] = max(0, (int)($this->options['start'] ?? 0) ?: 0);-- if (isset($this->options['post_id']) && is_array($this->options['post_id']) && $this->options['source'] == 'autocomplete') {+ if (isset($this->options['post_id']) && is_array($this->options['post_id']) && $this->options['source'] === 'autocomplete') {$this->options['post_id'] = array_keys($this->options['post_id']);} else {$this->options['post_id'] = [];}if (isset($this->options['order_by']) &&- ! in_array($this->options['order_by'], ['post_id', 'admin_id', 'sort_order', 'parent', 'type', 'created_at', 'updated_at', 'slug', 'name'])) {+ !in_array($this->options['order_by'], ['post_id', 'admin_id', 'sort_order', 'parent', 'type', 'created_at', 'updated_at', 'slug', 'name'])) {unset($this->options['order_by']);}if (isset($this->options['direction']) &&- ! in_array($this->options['direction'], ['asc', 'desc'])) {+ !in_array($this->options['direction'], ['asc', 'desc'])) {unset($this->options['direction']);}//wildcard search for one word search- if (isset($this->options['search']) && strpos($this->options['search'], ' ') == false) {+ if (isset($this->options['search']) && !str_contains($this->options['search'], ' ')) {$this->options['search_boolean'] = true;}- if (isset($this->options['search']) && isset($this->options['search_boolean'])) {+ if (isset($this->options['search'], $this->options['search_boolean'])) {$this->options['search'] .= '*';}- if (! isset($this->options['sticky'])) {- $stickyPosts = getSetting('posts', 'sticky');+ if (!isset($this->options['sticky'])) {+ $stickyPosts = getSetting('posts', 'sticky');$this->options['sticky'] = $stickyPosts;}//if only one taxonomy_item_id is provided then add it to array- if (isset($this->options['taxonomy_item_id']) && ! is_array($this->options['taxonomy_item_id'])) {+ if (isset($this->options['taxonomy_item_id']) && !is_array($this->options['taxonomy_item_id'])) {$this->options['taxonomy_item_id'] = [$this->options['taxonomy_item_id']];}- $results = $posts->getAll($this->options);+ $results = $posts->getAll($this->options);$this->options['type'] = $this->options['type'] ?: 'post';- if (! isset($this->options['date_format'])) {- $site = siteSettings();+ if (!isset($this->options['date_format'])) {+ $site = siteSettings();$this->options['date_format'] = $site['date_format'] ?? 'human';}if ($results && isset($results['post'])) {if ($this->options['sticky']) {- $stickyOptions = $this->options;+ $stickyOptions = $this->options;$stickyOptions['post_id'] = $this->options['sticky'];- $stickyOptions['start'] = 0;+ $stickyOptions['start'] = 0;unset($stickyOptions['limit']);$sticky = $posts->getAll($stickyOptions);if ($sticky && isset($sticky['post'])) {- //$count = count($sticky['post']);$results['post'] = $sticky['post'] + $results['post'];}}@@ -187,27 +198,34 @@ class Posts extends ComponentBase {$results['start'] = $this->options['start'];$results['search'] = $this->options['search'] ?? '';- if (! $results['post'] &&+ if (!$results['post'] &&isset($this->options['page']) &&($this->options['page'] > 1) &&- (isset($this->options['404']) && $this->options['404']) &&- ! $_SERVER['QUERY_STRING']) {+ !empty($this->options['404']) &&+ !($_SERVER['QUERY_STRING'] ?? '')) {$results['404'] = true;}- list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);+ [$results] = Event :: trigger(__CLASS__, __FUNCTION__, $results);return $results;}- //called on each request- function request(&$results, $index = 0) {+ /**+ * Hide password-protected post content on each request.+ *+ * @param array<string, mixed> &$results Posts data to modify.+ * @param int $index Request index.+ *+ * @return void+ */+ public function request(array &$results, int $index = 0): void {if (isset($results['post']) && $results['post']) {foreach ($results['post'] as &$post) {if ($post['password']) {$post['content'] = ''; //__('Password protected!');$post['excerpt'] = ''; //__('Password protected!');- $post['image'] = PUBLIC_PATH . 'media/locked.svg';+ $post['image'] = PUBLIC_PATH . 'media/locked.svg';}}}diff --git a/app/component/product.php b/app/component/product.phpindex 7882335..b47eaef 100755--- a/app/component/product.php+++ b/app/component/product.php@@ -22,9 +22,9 @@namespace Vvveb\Component;-use \Vvveb\Sql\Product_VariantSQL;use function Vvveb\model;use function Vvveb\sanitizeHTML;+use Vvveb\Sql\Product_variantSQL;use Vvveb\Sql\ProductSQL;use Vvveb\System\Cart\Currency;use Vvveb\System\Cart\Tax;@@ -33,40 +33,46 @@ use Vvveb\System\Core\Request;use Vvveb\System\Event;use Vvveb\System\Images;use Vvveb\System\Locale;-use Vvveb\System\Traits\Product as ProductTrait;use Vvveb\System\User\Admin;use function Vvveb\url;class Product extends ComponentBase {- //use ProductTrait;-- public static $defaultOptions = [- 'product_id' => 'url',- 'slug' => 'url',- 'status' => 1,- 'language_id' => null,- 'site_id' => null,- 'user_group_id' => null, // user group id to use to calculate promotional price- 'product_variant_id' => null, // product variant id to display variant as default, for price and product options- 'variant' => null, //[true, false] include variants- 'variant_price' => null, //[true, false] include variants prices- 'promotion' => null, //[true, false] include promotional price- 'points' => null, //[true, false] include points- 'stock_status' => null, //[true, false] include stock status info- 'weight_type' => null, //[true, false] include weight type info- 'length_type' => null, //[true, false] include length type info- 'rating' => null, //[true, false] include rating average- 'reviews' => null, //[true, false] include reviews count- 'image_size' => 'large', //options: xlarge, large, medium, thumb - if null site settings is used- 'image_resize' => null, //options: cs = Crop & resize, c = crop, r = resize, s = stretch - if null site settings is used+ public static array $defaultOptions = [+ 'product_id' => 'url',+ 'slug' => 'url',+ 'status' => 1,+ 'language_id' => null,+ 'site_id' => null,+ 'user_group_id' => null,+ 'product_variant_id' => null,+ 'variant' => null,+ 'variant_price' => null,+ 'promotion' => null,+ 'points' => null,+ 'stock_status' => null,+ 'weight_type' => null,+ 'length_type' => null,+ 'rating' => null,+ 'reviews' => null,+ 'image_size' => 'large', //options: xlarge, large, medium, thumb - if null site settings is used+ 'image_resize' => null, //options: cs = Crop & resize, c = crop, r = resize, s = stretch - if null site settings is used];- public $cacheExpire = 0; //no cache+ public int $cacheExpire = 0;- function results() {+ /**+ * Get single product details with images, variants, pricing, tax, and URLs.+ *+ * @return array<string, mixed> Product data with images, variants, prices, and action URLs.+ */+ public function results(): array {$product = new ProductSQL();$results = $product->get($this->options);+ if (!isset($results['product_id'])) {+ return [];+ }+$results['images'] = [];if (isset($results['product_image'])) {@@ -74,8 +80,7 @@ class Product extends ComponentBase {}if (isset($results['image'])) {- //$results['images'][] = ['image' => Images::image('product', $results['image'])];- $results['image']= Images::image($results['image'], 'product', $this->options['image_size']);+ $results['image'] = Images::image($results['image'], 'product', $this->options['image_size']);}$results['add_cart_url'] = url('cart/cart/add', ['product_id' => $results['product_id']]);@@ -88,14 +93,14 @@ class Product extends ComponentBase {$variants = [];if (isset($this->options['product_id'])) {- $variantSql = new Product_VariantSQL();+ $variantSQL = new Product_variantSQL();$voptions = ['product_id' => $this->options['product_id'], 'start' => 0, 'limit' => 1];if (isset($this->options['product_variant_id'])) {$voptions['product_variant_id'] = [$this->options['product_variant_id']];}- $variants = $variantSql->getAll($voptions);+ $variants = $variantSQL->getAll($voptions);}$defaultVariant = [];@@ -114,7 +119,7 @@ class Product extends ComponentBase {$results['product_variant_id'] = $defaultVariantId;- $this->tax = Tax::getInstance($this->options);+ $this->tax = Tax::getInstance();$this->currency = Currency::getInstance($this->options);$this->currentCurrency = Locale :: getCurrency();@@ -137,19 +142,22 @@ class Product extends ComponentBase {}if (isset($results['promotion']) && $results['promotion']) {- $results['promotion_tax'] = $tax->addTaxes($results['promotion'], $results['tax_type_id']);- $results['promotion_tax_formatted'] = $currency->format($results['promotion_tax']);- $results['promotion_formatted'] = $currency->format($results['promotion']);- $results['promotion_discount'] = 100 - ceil($results['promotion'] * 100 / $results['price']);- }+ $results['promotion_tax'] = $this->tax->addTaxes($results['promotion'], $results['tax_type_id']);+ $results['promotion_tax_formatted'] = $this->currency->format($results['promotion_tax']);+ $results['promotion_formatted'] = $this->currency->format($results['promotion']);+ //guard against division by zero when a product has no base price+ if (!empty($results['price'])) {+ $results['promotion_discount'] = 100 - ceil($results['promotion'] * 100 / $results['price']);+ }+ }- if ($results['language_id'] != $this->options['default_language_id']) {- if ($results['name'] === null && isset($results['product_content'][$this->options['default_language_id']])) {- $langFallback = $results['product_content'][$this->options['default_language_id']];- $results['name'] = $langFallback['name'];- $results['slug'] = $langFallback['slug'];- $results['content'] = $langFallback['content'];+ if ($results['language_id'] != ($this->options['default_language_id'] ?? null)) {+ if ($results['name'] === null && isset($results['product_content'][$this->options['default_language_id'] ?? null])) {+ $langFallback = $results['product_content'][$this->options['default_language_id']];+ $results['name'] = $langFallback['name'];+ $results['slug'] = $langFallback['slug'];+ $results['content'] = $langFallback['content'];$results['language_id'] = $langFallback['language_id'];}}@@ -158,22 +166,29 @@ class Product extends ComponentBase {$results['pubDate'] = date('r', strtotime($results['created_at']));$results['modDate'] = date('r', strtotime($results['updated_at']));- list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);+ [$results] = Event :: trigger(__CLASS__, __FUNCTION__, $results);return $results;}- //called on each request- function request(&$results, $index = 0) {+ /**+ * Handle revision preview for product content on each request.+ *+ * @param array<string, mixed> &$results Product data to modify.+ * @param int $index Request index.+ *+ * @return array<string, mixed> Modified product data.+ */+ public function request(array &$results, int $index = 0): array {$request = Request::getInstance();- $created_at = $request->get['created_at'] ?? ''; //revision preview+ $created_at = $request->get['created_at'] ?? '';if ($created_at && $results['product_id']) {//check if admin user to allow revision preview$admin = Admin::current();if ($admin) {- $revisions = model('post_content_revision');+ $revisions = model('product_content_revision');$revision = $revisions->get(['created_at' => $created_at, 'product_id' => $results['product_id'], 'language_id' => $results['language_id']]);if ($revision && isset($revision['content'])) {@@ -186,11 +201,17 @@ class Product extends ComponentBase {return $results;}- //called by editor on page save for each component on page- //this method is called from admin app- static function editorSave($id, $fields, $type = 'product') {+ /**+ * Save product content from editor on page save.+ *+ * @param int $id Product ID.+ * @param array<int, array<string, mixed>> $fields Field data from editor.+ * @param string $type Product type identifier.+ *+ * @return void+ */+ public static function editorSave(int $id, array $fields, string $type = 'product'): void {$products = new ProductSQL();- $product_content = [];$publicPath = \Vvveb\publicUrlPath() . 'media/';$product = [];@@ -200,32 +221,28 @@ class Product extends ComponentBase {$name = $field['name'];$value = $field['value'];- if ($name == 'name') {+ if ($name === 'name') {$product_content[$name] = strip_tags($value);+ } elseif ($name === 'images') {+ continue;+ } elseif ($name === 'content' || $name === 'excerpt') {+ $product_content[$name] = sanitizeHTML($value);} else {- if ($name == 'images') {- } else {- if ($name == 'content' || $name == 'excerpt') {- $product_content[$name] = sanitizeHTML($value);- } else {- if ($name == 'image') {- $value = str_replace($publicPath,'', $value);- }- $product[$name] = $value;- }+ if ($name === 'image') {+ $value = str_replace($publicPath, '', $value);}+ $product[$name] = $value;}}if ($product_content) {$product_content['language_id'] = self :: $global['language_id'];- //$product['product_id']['post_id'] = $id;- $result = $products->editContent(['product_content' => $product_content, 'product_id' => $id, 'language_id' => self :: $global['language_id']]);+ $result = $products->editContent(['product_content' => $product_content, 'product_id' => $id, 'language_id' => self :: $global['language_id']]);}if ($product) {$product['product_id'] = $id;- $result = $products->edit(['product' => $product, 'product_content' => [], /*'product_content' => [$product_content],*/ 'product_id' => $id]);+ $result = $products->edit(['product' => $product, 'product_content' => [], 'product_id' => $id]);}}}diff --git a/app/component/product/attributes.php b/app/component/product/attributes.phpindex 5fac62a..2115a84 100644--- a/app/component/product/attributes.php+++ b/app/component/product/attributes.php@@ -22,28 +22,33 @@namespace Vvveb\Component\Product;-use \Vvveb\Sql\AttributeSQL;+use Vvveb\Sql\AttributeSQL;use Vvveb\System\Component\ComponentBase;use Vvveb\System\Event;class Attributes extends ComponentBase {- public static $defaultOptions = [+ public static array $defaultOptions = ['start' => 0,'limit' => 100,- 'site_id' => NULL,- 'language_id' => NULL,+ 'site_id' => null,+ 'language_id' => null,'product_id' => 'url',- 'search' => NULL,+ 'search' => null,'image_size' => 'thumb',];- public $cacheExpire = 0; //no cache+ public int $cacheExpire = 0;- function results() {+ /**+ * Get product attributes with product_id filter normalization.+ *+ * @return array<string, mixed> Attributes data with attribute list.+ */+ public function results(): array {$category = new AttributeSQL();if (isset($this->options['product_id'])) {- if (! is_array($this->options['product_id'])) {+ if (!is_array($this->options['product_id'])) {$this->options['product_id'] = [$this->options['product_id']];}}@@ -52,9 +57,9 @@ class Attributes extends ComponentBase {$attributes = [];$group = false;- $results['attribute'] = $results['attribute'] ?? [];+ $results['attribute'] ??= [];- list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);+ [$results] = Event :: trigger(__CLASS__, __FUNCTION__, $results);return $results;}diff --git a/app/component/product/categories.php b/app/component/product/categories.phpindex 2fca449..cfdd6fb 100644--- a/app/component/product/categories.php+++ b/app/component/product/categories.php@@ -28,37 +28,40 @@ use Vvveb\System\Images;use function Vvveb\url;class Categories extends ComponentBase {- public static $defaultOptions = [+ public static array $defaultOptions = ['start' => 0,'limit' => 7,- 'site_id' => NULL,- 'language_id' => NULL,+ 'site_id' => null,+ 'language_id' => null,'order' => ['url', 'price asc'],- 'taxonomy_id' => NULL,- 'product_id' => NULL,- 'parent_id' => NULL,- 'search' => NULL,+ 'taxonomy_id' => null,+ 'product_id' => null,+ 'parent_id' => null,+ 'search' => null,'type' => 'categories','post_type' => 'product',- 'count' => false, //include number of products+ 'count' => false,'parents_only' => false,'parents_children_only' => false,'parents_without_children' => false,];- //public $cacheExpire = 0; //no cache-- function results() {- if (isset($this->options['post_type']) && ! $this->options['post_type']) {+ /**+ * Get product categories with child counts, images, and URLs.+ *+ * @return array<string, mixed> Categories data with nested children counts.+ */+ public function results(): array {+ if (isset($this->options['post_type']) && !$this->options['post_type']) {unset($this->options['post_type']);}$category = new \Vvveb\Sql\CategorySQL();- $results = $category->getCategories($this->options);+ $results = $category->getCategories($this->options);$taxonomy_type = 'category';- if (isset($this->options['type']) && $this->options['type'] == 'tags') {+ if (isset($this->options['type']) && $this->options['type'] === 'tags') {$taxonomy_type = 'tag';}@@ -68,7 +71,7 @@ class Categories extends ComponentBase {$parent_id = $category['parent_id'] ?? false;$category['active'] = false;- if (! isset($category['children'])) {+ if (!isset($category['children'])) {$category['children'] = 0;}@@ -99,13 +102,20 @@ class Categories extends ComponentBase {}}- list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);+ [$results] = Event :: trigger(__CLASS__, __FUNCTION__, $results);return $results;}- //called on each request- function request(&$results, $index = 0) {+ /**+ * Set active category based on current request module and category_id.+ *+ * @param array<string, mixed> &$results Component results to modify.+ * @param int $index Request index.+ *+ * @return array<string, mixed> Modified results with active flags.+ */+ public function request(array &$results, int $index = 0): array {$module = \Vvveb\getModuleName();$categoryId = false;@@ -125,10 +135,9 @@ class Categories extends ComponentBase {if ($categoryId == $category['taxonomy_item_id']) {$key = key($categories);$categories[$key]['active'] = true;- //$category['active'] = true;- $categoryId = $category['parent_id'];+ $categoryId = $category['parent_id'];- if (! $categoryId) {+ if (!$categoryId) {break;}}diff --git a/app/component/product/manufacturers.php b/app/component/product/manufacturers.phpindex 30abee4..b7ef121 100755--- a/app/component/product/manufacturers.php+++ b/app/component/product/manufacturers.php@@ -27,13 +27,12 @@ use Vvveb\System\Event;use function Vvveb\url;class Manufacturers extends ComponentBase {- public static $defaultOptions = [- 'start' => 0,- //'language_id' => 1,+ public static array $defaultOptions = [+ 'start' => 0,'count' => ['url', 4],- 'manufacturer_id' => NULL,+ 'manufacturer_id' => null,'order' => ['url', 'price asc'],- 'category_id' => NULL,+ 'category_id' => null,'limit' => 7,'page' => 1,'type' => 'tags',@@ -43,9 +42,14 @@ class Manufacturers extends ComponentBase {'filter' => null,];- public $cacheExpire = 0; //no cache+ public int $cacheExpire = 0;- function results() {+ /**+ * Get manufacturers list with active filter state and URLs.+ *+ * @return array<string, mixed> Manufacturers data with manufacturer list and active flags.+ */+ public function results(): array {$category = new \Vvveb\Sql\ManufacturerSQL();$results = $category->getAll($this->options);@@ -55,14 +59,14 @@ class Manufacturers extends ComponentBase {$filter = $this->options['filter']['manufacturer_id'] ?? [];}- foreach ($results['manufacturer'] as &$manufacturer) {+ foreach ($results['manufacturer'] as &$manufacturer) {if ($filter) {$manufacturer['active'] = in_array($manufacturer['manufacturer_id'], $filter);}$manufacturer['url'] = url('product/manufacturer/index', $manufacturer);}- list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);+ [$results] = Event :: trigger(__CLASS__, __FUNCTION__, $results);return $results;}diff --git a/app/component/product/options.php b/app/component/product/options.phpindex 5b3c32e..f12d072 100644--- a/app/component/product/options.php+++ b/app/component/product/options.php@@ -22,10 +22,10 @@namespace Vvveb\Component\Product;-use \Vvveb\Sql\Product_Option_ValueSQL;-use \Vvveb\Sql\Product_OptionSQL;-use \Vvveb\Sql\Product_VariantSQL;-use \Vvveb\Sql\ProductSQL;+use Vvveb\Sql\Product_option_valueSQL;+use Vvveb\Sql\Product_optionSQL;+use Vvveb\Sql\Product_variantSQL;+use Vvveb\Sql\ProductSQL;use Vvveb\System\Cart\Currency;use Vvveb\System\Cart\Tax;use Vvveb\System\Component\ComponentBase;@@ -33,88 +33,95 @@ use Vvveb\System\Event;use Vvveb\System\Images;class Options extends ComponentBase {- public static $defaultOptions = [- 'start' => 0,- 'limit' => NULL,- 'site_id' => NULL,- 'language_id' => NULL,- 'product_id' => 'url',- 'product_variant_id' => NULL,- 'parent_id' => NULL,- 'search' => NULL,+ public static array $defaultOptions = [+ 'start' => 0,+ 'limit' => null,+ 'site_id' => null,+ 'language_id' => null,+ 'product_id' => 'url',+ 'product_variant_id' => null,+ 'parent_id' => null,+ 'search' => null,+ 'image_size' => 'thumb',];- public $cacheExpire = 0; //no cache+ public int $cacheExpire = 0;- function results() {- $productSql = new ProductSQL();- $optionSql = new Product_OptionSQL();- $optionValuesSql = new Product_Option_ValueSQL();- $variantSql = new Product_VariantSQL();+ /**+ * Get product options with option values, pricing, tax, and default variant selection.+ *+ * @return array<string, mixed> Options data with count and product_option values.+ */+ public function results(): array {+ $productSQL = new ProductSQL();+ $optionSQL = new Product_optionSQL();+ $optionvaluesSQL = new Product_option_valueSQL();+ $variantSQL = new Product_variantSQL();$product = [];+ $count = 0;- if (isset($this->options['product_id'])) {- $product = $productSql->get(['product_id' => $this->options['product_id']]);- }+ if (isset($this->options['product_id']) && $this->options['product_id']) {+ $product = $productSQL->get(['product_id' => $this->options['product_id']]);- $results = $optionSql->getAll($this->options);- $values = $optionValuesSql->getAll($this->options);+ $results = $optionSQL->getAll($this->options);+ $values = $optionvaluesSQL->getAll($this->options);- $voptions = ['product_id' => $this->options['product_id'], 'start' => 0, 'limit' => 1];+ $voptions = ['product_id' => $this->options['product_id'], 'start' => 0, 'limit' => 1];- if (isset($this->options['product_variant_id'])) {- $voptions['product_variant_id'] = [$this->options['product_variant_id']];- }+ if (isset($this->options['product_variant_id'])) {+ $voptions['product_variant_id'] = [$this->options['product_variant_id']];+ }- $variants = $variantSql->getAll($voptions);+ $variants = $variantSQL->getAll($voptions);- $defaultVariant = [];- $defaultOptions = [];+ $defaultVariant = [];+ $defaultOptions = [];- if ($variants && isset($variants['product_variant'])) {- $defaultVariant = current($variants['product_variant']);- }+ if ($variants && isset($variants['product_variant'])) {+ $defaultVariant = current($variants['product_variant']);+ }- if ($defaultVariant) {- $json = '{' . preg_replace('/(\d+)/', '"\1"', $defaultVariant['options']) . '}';- $defaultOptions = json_decode($json, true);- }+ if ($defaultVariant) {+ $json = '{' . preg_replace('/(\d+)/', '"\1"', $defaultVariant['options']) . '}';+ $defaultOptions = json_decode($json, true);+ }- $count = 0;+ $count = 0;- if ($results && isset($results['product_option'])) {- $options = &$results['product_option'];- $tax = Tax::getInstance($this->options);- $currency = Currency::getInstance($this->options);+ if ($results && isset($results['product_option'])) {+ $options = &$results['product_option'];+ $tax = Tax::getInstance();+ $currency = Currency::getInstance($this->options);- if ($values && isset($values['product_option_value'])) {- foreach ($values['product_option_value'] as &$value) {- $count++;+ if ($values && isset($values['product_option_value'])) {+ foreach ($values['product_option_value'] as &$value) {+ $count++;- if ($value['image']) {- $value['image'] = Images::image($value['image'], 'option', $this->options['image_size']);- }+ if ($value['image']) {+ $value['image'] = Images::image($value['image'], 'option', $this->options['image_size']);+ }- if ($value['price']) {- $value['price_tax'] = $tax->addTaxes($value['price'], $product['tax_type_id'] ?? 0);- $value['price_formatted'] = $value['price_operator'] . $currency->format($value['price_tax']);- }+ if ($value['price']) {+ $value['price_tax'] = $tax->addTaxes($value['price'], $product['tax_type_id'] ?? 0);+ $value['price_formatted'] = $value['price_operator'] . $currency->format($value['price_tax']);+ }- if (isset($defaultOptions[$value['product_option_id']]) &&- $defaultOptions[$value['product_option_id']] == $value['product_option_value_id']) {- $value['checked'] = true;- }+ if (isset($defaultOptions[$value['product_option_id']]) &&+ $defaultOptions[$value['product_option_id']] === $value['product_option_value_id']) {+ $value['checked'] = true;+ }- if (isset($options[$value['product_option_id']])) {- $options[$value['product_option_id']]['values'][] = $value;+ if (isset($options[$value['product_option_id']])) {+ $options[$value['product_option_id']]['values'][] = $value;+ }}}}}$results['count'] = $count;- list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);+ [$results] = Event :: trigger(__CLASS__, __FUNCTION__, $results);return $results;}diff --git a/app/component/product/subscription/plans.php b/app/component/product/subscription/plans.phpold mode 100644new mode 100755index 8557879..3004702--- a/app/component/product/subscription/plans.php+++ b/app/component/product/subscription/plans.php@@ -22,28 +22,33 @@namespace Vvveb\Component\Product\Subscription;-use \Vvveb\Sql\Subscription_PlanSQL;+use Vvveb\Sql\Subscription_planSQL;use Vvveb\System\Component\ComponentBase;use Vvveb\System\Event;class Plans extends ComponentBase {- public static $defaultOptions = [- 'start' => 0,- 'limit' => 7,- 'site_id' => NULL,- 'language_id' => NULL,- 'product_id' => 'url',- 'parent_id' => NULL,- 'search' => NULL,+ public static array $defaultOptions = [+ 'start' => 0,+ 'limit' => 7,+ 'site_id' => null,+ 'language_id' => null,+ 'product_id' => 'url',+ 'parent_id' => null,+ 'search' => null,];- public $cacheExpire = 0; //no cache+ public int $cacheExpire = 0;- function results() {- $category = new Subscription_PlanSQL();+ /**+ * Get subscription plans list.+ *+ * @return array<string, mixed> Plans data from query.+ */+ public function results(): array {+ $category = new Subscription_planSQL();$results = $category->getAll($this->options);- list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);+ [$results] = Event :: trigger(__CLASS__, __FUNCTION__, $results);return $results;}diff --git a/app/component/product/subscriptions.php b/app/component/product/subscriptions.phpindex 486542d..dfbb220 100644--- a/app/component/product/subscriptions.php+++ b/app/component/product/subscriptions.php@@ -22,28 +22,33 @@namespace Vvveb\Component\Product;-use \Vvveb\Sql\Product_SubscriptionSQL;+use Vvveb\Sql\Product_subscriptionSQL;use Vvveb\System\Component\ComponentBase;use Vvveb\System\Event;class Subscriptions extends ComponentBase {- public static $defaultOptions = [+ public static array $defaultOptions = ['start' => 0,'limit' => 7,- 'site_id' => NULL,- 'language_id' => NULL,+ 'site_id' => null,+ 'language_id' => null,'product_id' => 'url',- 'parent_id' => NULL,- 'search' => NULL,+ 'parent_id' => null,+ 'search' => null,];- public $cacheExpire = 0; //no cache+ public int $cacheExpire = 0;- function results() {- $category = new Product_SubscriptionSQL();+ /**+ * Get product subscriptions list.+ *+ * @return array<string, mixed> Subscriptions data from query.+ */+ public function results(): array {+ $category = new Product_subscriptionSQL();$results = $category->getAll($this->options);- list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);+ [$results] = Event :: trigger(__CLASS__, __FUNCTION__, $results);return $results;}diff --git a/app/component/product/variants.php b/app/component/product/variants.phpindex bbf8328..132946e 100644--- a/app/component/product/variants.php+++ b/app/component/product/variants.php@@ -22,63 +22,173 @@namespace Vvveb\Component\Product;-use \Vvveb\Sql\Product_VariantSQL;-use \Vvveb\Sql\ProductSQL;+use function Vvveb\__;+use Vvveb\Sql\Product_variantSQL;+use Vvveb\Sql\ProductSQL;use Vvveb\System\Cart\Currency;use Vvveb\System\Cart\Tax;use Vvveb\System\Component\ComponentBase;use Vvveb\System\Event;use Vvveb\System\Images;+use Vvveb\System\Locale;+use function Vvveb\url;class Variants extends ComponentBase {- public static $defaultOptions = [+ public static array $defaultOptions = ['start' => 0,- 'limit' => NULL,- 'site_id' => NULL,- 'language_id' => NULL,+ 'limit' => null,+ 'site_id' => null,+ 'language_id' => null,'product_id' => 'url',- 'parent_id' => NULL,- 'search' => NULL,+ 'parent_id' => null,+ 'search' => null,+ 'name' => null,+ 'url' => null,];- public $cacheExpire = 0; //no cache+ public int $cacheExpire = 0;- function results() {- $productSql = new ProductSQL();- $variantSql = new Product_VariantSQL();+ /**+ * Get product variants with pricing, tax, option names, and URLs.+ *+ * @return array<string, mixed> Variants data with count and product_variant list.+ */+ public function results(): array {+ $productSQL = new ProductSQL();+ $variantSQL = new Product_variantSQL();- $product = [];+ $product = [];+ $variants = [];+ $count = 0;- if ($this->options['product_id']) {- $product = $productSql->get(['product_id' => $this->options['product_id']]);+ if (isset($this->options['product_id']) && $this->options['product_id']) {+ $product = $productSQL->get(['product_id' => $this->options['product_id']]);+ $variants = $product['product_variant'] ?? [];}- $results = $variantSql->getAll($this->options);- $count = 0;+ if ($variants) {+ $language = [];++ if (($product['language_id'] != ($this->options['default_language_id'] ?? null))) {+ $language = ['language' => $this->options['language']];++ if ($product['name'] === null && isset($product['product_content'][$this->options['default_language_id'] ?? null])) {+ $langFallback = $product['product_content'][$this->options['default_language_id'] ?? null];+ $product['name'] = $langFallback['name'];+ $product['slug'] = $langFallback['slug'];+ $product['content'] = $langFallback['content'];+ $product['language_id'] = $langFallback['language_id'];+ } else {+ if (!$product['name']) {+ $product['name'] = '[' . __('No translation') . ']';+ }+ }+ } else {+ if ($this->options['default_lang_slug']) {+ $language = ['language' => $this->options['language']];+ }+ }++ $optionIds = [];- if ($results && isset($results['product_variant'])) {- $variants = &$results['product_variant'];- $tax = Tax::getInstance($this->options);- $currency = Currency::getInstance($this->options);+ if (isset($this->options['name'])) {+ if (isset($product['option'])) {+ foreach ($product['option'] as $id => &$option) {+ unset($option['array_key']);+ }+ } else {+ $product['option'] = [];+ }++ if (isset($product['product_option'])) {+ $product_option_value = &$product['product_option_value'];+ $product_option = &$product['product_option'];- if ($variants) {- foreach ($variants as &$variant) {- $count++;+ $option_value_content = [];+ $names = [];- if ($variant['image']) {- $variant['image'] = Images::image($variant['image'], 'option', $this->options['image_size']);+ $default = '';++ if ($product['language_id'] != $this->options['default_language_id']) {+ $default = '[' . __('No translation') . ']';}- if ($variant['price']) {- $variant['price_tax'] = $tax->addTaxes($variant['price'], $product['tax_type_id'] ?? 0);- $variant['price_formatted'] = $currency->format($variant['price_tax']);+ foreach ($product['option_value_content'] as &$value) {+ $option_value_content[$value['option_id']][$value['option_value_id']] = $value;+ $names[$value['option_value_id']] = $value['name'] ?? $default;+ }++ foreach ($product_option_value as &$value) {+ if (isset($product_option[$value['product_option_id']])) {+ $product_option[$value['product_option_id']]['values'][$value['product_option_value_id']] = $value;+ $optionIds[$value['product_option_id']][$value['product_option_value_id']] = $names[$value['option_value_id']] ?? $default;+ }+ }++ $product['option_value_content'] = $option_value_content;+ } else {+ $product['product_option'] = [];+ }+ }++ $tax = Tax::getInstance();+ $currency = Currency::getInstance($this->options);+ $currentCurrency = Locale :: getCurrency();++ $url = $language + ['host' => SITE_URL, 'scheme' => $_SERVER['REQUEST_SCHEME'] ?? 'http'];++ if ($product['type'] != 'product') {+ $url['type'] = $product['type'];+ }++ //if translation is missing slug is not available+ if (isset($product['slug'])) {+ $url['slug'] = $product['slug'];+ } else {+ $url['product_id'] = $product['product_id'];+ }++ $product['url'] = url('product/product/index', $url);++ foreach ($variants as $opts => &$variant) {+ $count++;++ if ($variant['image']) {+ $variant['image'] = Images::image($variant['image'], 'option', $this->options['image_size']);+ }++ if ($variant['price']) {+ $variant['price_tax'] = $tax->addTaxes($variant['price'], $product['tax_type_id'] ?? 0);+ $variant['price_formatted'] = $currency->format($variant['price']);+ $variant['price_tax_formatted'] = $currency->format($variant['price_tax']);+ $variant['price_currency'] = $currentCurrency;+ }++ if (isset($this->options['name'])) {+ $keys = explode(',', $opts);+ $name = '';+ foreach ($keys as $key) {+ $r = explode(':', $key);+ $o = $r[0];+ $v = $r[1];++ if ($name) {+ $name .= ' / ';+ }++ $name .= $optionIds[$o][$v];}++ $variant['name'] = $product['name'] . ' - ' . $name;+ $variant['url'] = $product['url'] . '?product_variant_id=' . $variant['product_variant_id'];}}}- $results['count'] = $count;- list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);+ $results['count'] = $count;+ $results['product_variant'] = $variants;++ [$results] = Event :: trigger(__CLASS__, __FUNCTION__, $results);return $results;}diff --git a/app/component/product/vendors.php b/app/component/product/vendors.phpold mode 100644new mode 100755index 7221336..d1d439a--- a/app/component/product/vendors.php+++ b/app/component/product/vendors.php@@ -27,13 +27,12 @@ use Vvveb\System\Event;use function Vvveb\url;class Vendors extends ComponentBase {- public static $defaultOptions = [- 'start' => 0,- //'language_id' => 1,+ public static array $defaultOptions = [+ 'start' => 0,'count' => ['url', 4],- 'vendor_id' => NULL,+ 'vendor_id' => null,'order' => ['url', 'price asc'],- 'category_id' => NULL,+ 'category_id' => null,'limit' => 7,'page' => 1,'type' => 'tags',@@ -43,7 +42,12 @@ class Vendors extends ComponentBase {'filter' => false,];- function results() {+ /**+ * Get vendors list with active filter state and URLs.+ *+ * @return array<string, mixed> Vendors data with vendor list and active flags.+ */+ public function results(): array {$category = new \Vvveb\Sql\VendorSQL();$results = $category->getAll($this->options);@@ -53,14 +57,14 @@ class Vendors extends ComponentBase {$filter = $this->options['filter']['vendor_id'] ?? [];}- foreach ($results['vendor'] as &$vendor) {+ foreach ($results['vendor'] as &$vendor) {if ($filter) {$vendor['active'] = in_array($vendor['vendor_id'], $filter);}$vendor['url'] = url('product/vendor/index', $vendor);}- list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);+ [$results] = Event :: trigger(__CLASS__, __FUNCTION__, $results);return $results;}diff --git a/app/component/products.php b/app/component/products.phpindex d8d99ba..71b1555 100755--- a/app/component/products.php+++ b/app/component/products.php@@ -22,6 +22,8 @@namespace Vvveb\Component;+use Vvveb\System\Cart\Currency;+use Vvveb\System\Cart\Tax;use Vvveb\System\Component\ComponentBase;use Vvveb\System\Event;use Vvveb\System\Traits\Product;@@ -29,7 +31,7 @@ use Vvveb\System\Traits\Product;class Products extends ComponentBase {use Product;- public static $defaultOptions = [+ public static array $defaultOptions = ['start' => 0,'page' => 1,'limit' => 4,@@ -38,60 +40,86 @@ class Products extends ComponentBase {'language_id' => null,'site_id' => null,'type' => 'product', // filter by custom product type- 'manufacturer_id' => NULL, // filter by manufacturer- 'vendor_id' => NULL, // filter by vendor- 'taxonomy_item_id' => NULL, // filter by taxonomy (category/tag)- 'product_image' => true, // include product images/gallery- 'product_id' => [], // show only products with id's in the list, array with product id's [1,2,3]- 'search' => null, // show products that matches the search string, used on search page- 'search_boolean' => null, // use boolean search- 'like' => null, // search using like operator, slower and returns only matches that start with the searched string+ 'manufacturer_id' => null,+ 'vendor_id' => null,+ 'taxonomy_item_id' => null,+ 'product_image' => true,+ 'product_id' => [],+ 'search' => null,+ 'search_boolean' => null,+ 'like' => null,'slug' => null, // show only products with matching slugs, array with product slugs ['one','two']- 'related' => null, // show related products for the products specified at product_id, boolean- 'variant' => null, // [true, false] include variants- 'promotion' => null, // [true, false] include promotional price- 'points' => null, // [true, false] include points- 'stock_status' => null, // [true, false] include stock status info- 'weight_type' => null, // [true, false] include weight type info- 'length_type' => null, // [true, false] include length type info- 'rating' => null, // [true, false] include rating average- 'reviews' => null, // [true, false] include reviews count- 'author' => null, // [true, false] include author/admin info+ 'related' => null,+ 'variant' => null,+ 'promotion' => null,+ 'points' => null,+ 'stock_status' => null,+ 'weight_type' => null,+ 'length_type' => null,+ 'rating' => null,+ 'reviews' => null,+ 'author' => null,'image_size' => 'medium', //options: xlarge, large, medium, thumb - if null site settings is use'image_resize' => null, // options: cs = Crop & resize, c = crop, r = resize, s = stretch- 'variant' => null, //[true, false] include variants- 'variant_price' => NULL, // [true, false] include variants min max prices- 'order_by' => NULL, // default: product_id- 'direction' => NULL, // ['desc', 'asc'], //'ASC', default: 'DESC'- '404' => NULL, // show 404 page if no product returned, used when added to shop/category etc pages+ 'variant' => null,+ 'variant_price' => null,+ 'order_by' => null,+ 'direction' => null,+ '404' => null, // show 404 page if no product returned, used when added to shop/category etc pages];- private $tax;-- private $currency;-- private $currentCurrency;-- public $options = [];-- function cacheKey() {- if (isset($this->options['search']) || isset($this->options['page']) || isset($this->options['product_id'])) {- return false;+ /**+ * Currency code for the current session (e.g. 'USD', 'EUR').+ *+ * @var string+ */+ protected string $currentCurrency = '';++ /**+ * Tax calculator instance.+ *+ * @var \Vvveb\System\Cart\Tax+ */+ protected ?Tax $tax = null;++ /**+ * Currency formatter instance.+ *+ * @var \Vvveb\System\Cart\Currency+ */+ protected ?Currency $currency = null;++ public array $options = [];++ /**+ * Disable caching for search, pagination, or specific product lookups.+ *+ * @return string|null Parent cache key or null to disable caching.+ */+ public function cacheKey(): ?string {+ //page defaults to 1 and product_id to [] so only non-default values disable caching+ if (!empty($this->options['search']) || ($this->options['page'] ?? 1) > 1 || !empty($this->options['product_id'])) {+ return null;}return parent::cacheKey();}- function results() {+ /**+ * Get products list with filtering, sorting, pagination, and 404 handling.+ *+ * @return array<string, mixed> Products data with product list, limit, start, and search.+ */+ public function results(): array {$products = new \Vvveb\Sql\ProductSQL();- $this->options['limit'] = (int) ($this->options['limit'] ?? 4 ?: 4);+ $this->options['limit'] = max(1, (int)($this->options['limit'] ?? 4) ?: 4);- if (($page = $this->options['page'] ?? false) && is_numeric($page)) {+ if (($page = $this->options['page'] ?? false) && is_numeric($page) && $page > 0) {$this->options['start'] = ($page - 1) * ($this->options['limit']);}- $this->options['start'] = (int) ($this->options['start'] ?? 0 ?: 0);+ $this->options['start'] = max(0, (int)($this->options['start'] ?? 0) ?: 0);if ($this->options['filter'] ?? false) {foreach ($this->options['filter'] as $name => $values) {@@ -102,8 +130,8 @@ class Products extends ComponentBase {}if (isset($this->options['product_id']) &&- (isset($this->options['related']) || isset($this->options['variant']) || ($this->options['source'] ?? '' == 'autocomplete'))) {- if (! is_array($this->options['product_id'])) {+ (isset($this->options['related']) || isset($this->options['variant']) || (($this->options['source'] ?? '') === 'autocomplete'))) {+ if (!is_array($this->options['product_id'])) {$this->options['product_id'] = [$this->options['product_id'] => 1];}$this->options['product_id'] = array_keys($this->options['product_id']);@@ -112,41 +140,41 @@ class Products extends ComponentBase {}if (isset($this->options['order_by']) &&- ! in_array($this->options['order_by'], ['product_id', 'price', 'created_at', 'updated_at'])) {+ !in_array($this->options['order_by'], ['product_id', 'price', 'created_at', 'updated_at'])) {unset($this->options['order_by']);}if (isset($this->options['direction']) &&- ! in_array($this->options['direction'], ['asc', 'desc'])) {+ !in_array($this->options['direction'], ['asc', 'desc'])) {unset($this->options['direction']);}//if only one slug is provided then add it to array- if (isset($this->options['slug']) && ! is_array($this->options['slug'])) {+ if (isset($this->options['slug']) && !is_array($this->options['slug'])) {$this->options['slug'] = [$this->options['slug']];}//if only one manufacturer_id is provided then add it to array- if (isset($this->options['manufacturer_id']) && ! is_array($this->options['manufacturer_id'])) {+ if (isset($this->options['manufacturer_id']) && !is_array($this->options['manufacturer_id'])) {$this->options['manufacturer_id'] = [$this->options['manufacturer_id']];}//if only one vendor_id is provided then add it to array- if (isset($this->options['vendor_id']) && ! is_array($this->options['vendor_id'])) {+ if (isset($this->options['vendor_id']) && !is_array($this->options['vendor_id'])) {$this->options['vendor_id'] = [$this->options['vendor_id']];}//if only one taxonomy_item_id is provided then add it to array- if (isset($this->options['taxonomy_item_id']) && ! is_array($this->options['taxonomy_item_id'])) {+ if (isset($this->options['taxonomy_item_id']) && !is_array($this->options['taxonomy_item_id'])) {$this->options['taxonomy_item_id'] = [$this->options['taxonomy_item_id']];}//wildcard search for one word search- if (isset($this->options['search']) && strpos($this->options['search'], ' ') == false) {+ if (isset($this->options['search']) && !str_contains($this->options['search'], ' ')) {$this->options['search_boolean'] = true;}- if (isset($this->options['search']) && isset($this->options['search_boolean'])) {+ if (isset($this->options['search'], $this->options['search_boolean'])) {$this->options['search'] .= '*';}@@ -162,15 +190,15 @@ class Products extends ComponentBase {$results['start'] = $this->options['start'];$results['search'] = $this->options['search'] ?? '';- if (! $results['product'] &&+ if (!$results['product'] &&isset($this->options['page']) &&($this->options['page'] > 1) &&- (isset($this->options['404']) && $this->options['404']) &&- ! $_SERVER['QUERY_STRING']) {+ !empty($this->options['404']) &&+ !($_SERVER['QUERY_STRING'] ?? '')) {$results['404'] = true;}- list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);+ [$results] = Event :: trigger(__CLASS__, __FUNCTION__, $results);return $results;}diff --git a/app/component/questions.php b/app/component/questions.phpold mode 100644new mode 100755index a617c46..f312404--- a/app/component/questions.php+++ b/app/component/questions.php@@ -23,21 +23,21 @@namespace Vvveb\Component;class Questions extends Comments {- protected $type = 'product_question';+ protected string $type = 'product_question';- protected $route = 'product/product/index';+ protected string $route = 'product/product/index';- protected $modelName = 'product_question';+ protected string $modelName = 'product_question';- public static $defaultOptions = [+ public static array $defaultOptions = ['product_id' => 'url','slug' => 'url','product_title' => null, //include post title (for recent questions etc)'status' => 1, //approved questions'start' => 0,'limit' => 10,- 'order' => 'asc', //desc+ 'order' => 'asc',];- public $cacheExpire = 0; //no cache+ public int $cacheExpire = 0;}diff --git a/app/component/reviews.php b/app/component/reviews.phpindex 938a673..8147244 100755--- a/app/component/reviews.php+++ b/app/component/reviews.php@@ -22,31 +22,36 @@namespace Vvveb\Component;-use Vvveb\Sql\Product_Review_MediaSQL;+use Vvveb\Sql\Product_review_mediaSQL;use Vvveb\System\Images;class Reviews extends Comments {- protected $type = 'product_review';+ protected string $type = 'product_review';- protected $route = 'product/product/index';+ protected string $route = 'product/product/index';- protected $modelName = 'product_review';+ protected string $modelName = 'product_review';- public static $defaultOptions = [+ public static array $defaultOptions = ['product_id' => 'url','slug' => 'url',- 'product_title' => NULL, //include product title (for recent reviews etc)- 'user_id' => NULL,- 'status' => 1, //approved reviews+ 'product_title' => null,+ 'user_id' => null,+ 'status' => 1,'start' => 0,'limit' => 10,- 'order' => 'asc', //desc- 'image_size' => 'thumb', //options: xlarge, large, medium, thumb+ 'order' => 'asc',+ 'image_size' => 'thumb',];- public $cacheExpire = 0; //no cache+ public int $cacheExpire = 0;- function results() {+ /**+ * Get product reviews with images, gallery, and rating statistics.+ *+ * @return array<string, mixed> Reviews data with images, rating, summary, and stats.+ */+ public function results(): array {$results = parent::results();//review images@@ -62,11 +67,10 @@ class Reviews extends Comments {}//all product reviews images- $media = new Product_Review_MediaSQL();+ $media = new Product_review_mediaSQL();$gallery = $media->getAll($this->options + ['status' => 1])['product_review_media'] ?? [];if ($gallery) {- //$gallery = Images::images($gallery, 'product', $this->options['image_size']);foreach ($gallery as &$image) {$image['thumb'] = Images::image($image['image'], 'product', $this->options['image_size']);$image['image'] = Images::image($image['image'], 'product', 'xlarge');@@ -81,8 +85,9 @@ class Reviews extends Comments {$results += $stats;}- $results['rating'] = number_format($results['rating'] ?? 0, 1);- $results['rating_int'] = ceil($results['rating']);+ $rating = $results['rating'] ?? 0;+ $results['rating_int'] = ceil($rating);+ $results['rating'] = number_format($rating, 1);//compute width and fill missing ratingsforeach ([1, 2, 3, 4, 5] as $rating) {@@ -96,9 +101,6 @@ class Reviews extends Comments {}}- //$results['buyers'] = 5;- //$results['recommendations'] = 100;-return $results;}}diff --git a/app/component/search.php b/app/component/search.phpdeleted file mode 100755index 4f50e8a..0000000--- a/app/component/search.php+++ /dev/null@@ -1,51 +0,0 @@-<?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\Component;--use Vvveb\System\Component\ComponentBase;-use Vvveb\System\Event;--class Search extends ComponentBase {- public static $defaultOptions = [- 'query' => null,- 'limit' => 1000,- 'page' => 1,- ];-- protected $options = [];-- public $cacheExpire = 0; //seconds-- function cacheKey() {- //disable caching- return false;- }-- function results() {- $results = ['query' => $this->request->request['search'] ?? null];-- list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);-- return $results;- }-}diff --git a/app/component/site.php b/app/component/site.phpindex b6038bb..848f46c 100644--- a/app/component/site.php+++ b/app/component/site.php@@ -29,25 +29,34 @@ use Vvveb\System\Event;use function Vvveb\url;class Site extends ComponentBase {- public static $defaultOptions = [+ public static array $defaultOptions = ['site_id' => null,'language_id' => null,];- protected $options = [];+ protected array $options = [];- public $cacheExpire = 0; //seconds+ public int $cacheExpire = 0;- function cacheKey() {- //disable caching- return false;+ /**+ * Disable caching for site component.+ *+ * @return null Always returns null to disable caching.+ */+ public function cacheKey(): ?string {+ return null;}- function results() {+ /**+ * Get site settings with logos, URLs, and site configuration.+ *+ * @return array<string, mixed> Site data with logo URLs, site URL, and settings.+ */+ public function results(): array {$results = siteSettings($this->options['site_id'], $this->options['language_id']);- if (! $results) {- $results = ['logo'=>'logo.png', 'logo-sticky' => 'logo.png', 'logo-dark' => 'logo-white.png', 'logo-dark-sticky' => 'logo-white.png', 'favicon' => 'favicon.ico'];+ if (!$results) {+ $results = ['logo' => 'logo.png', 'logo-sticky' => 'logo.png', 'logo-dark' => 'logo-white.png', 'logo-dark-sticky' => 'logo-white.png', 'favicon' => 'favicon.ico'];$publicPath = \Vvveb\publicUrlPath() . 'media';foreach ($results as $key => &$value) {@@ -59,21 +68,27 @@ class Site extends ComponentBase {if ($this->options['default_language'] != $this->options['language'] || self :: $global['default_lang_slug']) {$urlOptions = ['language' => $this->options['language']];- } else {}- $results['url'] = (V_SUBDIR_INSTALL ? V_SUBDIR_INSTALL : '') . '/'; //url('index/index');- $results['full-url'] = SITE_URL; //url('index/index', $urlOptions + ['host' => '*.*.*']);+ $results['url'] = V_SUBDIR_INSTALL . '/';+ $results['full-url'] = SITE_URL;$results['site_id'] = $this->options['site_id'];- list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);+ [$results] = Event :: trigger(__CLASS__, __FUNCTION__, $results);return $results;}- //called by editor on page save for each component on page- //this method is called from admin app- static function editorSave($id, $fields, $type = 'site') {+ /**+ * Save site settings from editor on page save.+ *+ * @param int $id Site ID.+ * @param array<int, array<string, mixed>> $fields Field data from editor.+ * @param string $type Site type identifier.+ *+ * @return void+ */+ public static function editorSave(int $id, array $fields, string $type = 'site'): void {$sites = new SiteSQL();$result = [];$site = $sites->get(['site_id' => $id]);@@ -87,8 +102,8 @@ class Site extends ComponentBase {$name = $field['name'];$value = $field['value'];- if ($name == 'favicon' || $name == 'webbanner' || strpos($name, 'logo') !== false) {- $value = str_replace($publicPath,'', $value);+ if ($name === 'favicon' || $name === 'webbanner' || str_contains($name, 'logo')) {+ $value = str_replace($publicPath, '', $value);}$settings[$name] = $value;}diff --git a/app/component/user.php b/app/component/user.phpindex f64328c..d83e292 100755--- a/app/component/user.php+++ b/app/component/user.php@@ -26,24 +26,32 @@ use Vvveb\System\Component\ComponentBase;use Vvveb\System\Event;use Vvveb\System\Images;use Vvveb\System\User\User as UserClass;-use function Vvveb\url;class User extends ComponentBase {- public static $defaultOptions = [+ public static array $defaultOptions = ['user_id' => null,'username' => null,];- protected $options = [];+ protected array $options = [];- public $cacheExpire = 0; //seconds+ public int $cacheExpire = 0;- function cacheKey() {- //disable caching- return false;+ /**+ * Disable caching for user component.+ *+ * @return null Always returns null to disable caching.+ */+ public function cacheKey(): ?string {+ return null;}- function results() {+ /**+ * Get user profile data with avatar/cover images.+ *+ * @return array<string, mixed> User data with image URLs and profile info.+ */+ public function results(): array {if (isset($this->options['user_id']) || isset($this->options['username'])) {$users = new \Vvveb\Sql\UserSQL();@@ -57,20 +65,18 @@ class User extends ComponentBase {foreach (['avatar', 'cover'] as $image) {if (isset($results[$image])) {- $results[$image . '_url']= Images::image($results[$image], 'user');+ $results[$image . '_url'] = Images::image($results[$image], 'user');}}-- //$results['url'] = url('content/user/index', ['username' => $results['username']]);} else {$results = [];}- if (! $results) {+ if (!$results) {$results = [];}- list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);+ [$results] = Event :: trigger(__CLASS__, __FUNCTION__, $results);return $results;}diff --git a/app/component/user/address.php b/app/component/user/address.phpold mode 100755new mode 100644index aa00458..ea356b9--- a/app/component/user/address.php+++ b/app/component/user/address.php@@ -22,28 +22,37 @@namespace Vvveb\Component\User;-use Vvveb\Sql\User_AddressSQL;+use Vvveb\Sql\User_addressSQL;use Vvveb\System\Component\ComponentBase;use Vvveb\System\Event;use function Vvveb\url;class Address extends ComponentBase {- public static $defaultOptions = [+ public static array $defaultOptions = ['user_id' => null,'start' => 0,'limit' => 10,];- //don't cache- function cacheKey() {- return false;+ /**+ * Disable caching for user address component.+ *+ * @return null Always returns null to disable caching.+ */+ public function cacheKey(): ?string {+ return null;}- function results() {+ /**+ * Get user addresses with edit and delete URLs.+ *+ * @return array<string, mixed> Address data with user_address items.+ */+ public function results(): array {$results = [];if (isset($this->options['user_id'])) {- $user_address = new User_AddressSQL();+ $user_address = new User_addressSQL();$results = $user_address->getAll($this->options);if ($results && isset($results['user_address'])) {@@ -54,12 +63,18 @@ class Address extends ComponentBase {}}- list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);+ [$results] = Event :: trigger(__CLASS__, __FUNCTION__, $results);return $results;}- //called on each request- function request($results, $index = 0) {- }+ /**+ * Called on each request (no-op for user address).+ *+ * @param array<string, mixed> $results Component results.+ * @param int $index Request index.+ *+ * @return void+ */+ public function request(array $results, int $index = 0): void {}}diff --git a/app/component/user/wishlist.php b/app/component/user/wishlist.phpindex e550740..b6989f6 100644--- a/app/component/user/wishlist.php+++ b/app/component/user/wishlist.php@@ -22,30 +22,44 @@namespace Vvveb\Component\User;-use Vvveb\Sql\User_WishlistSQL;+use Vvveb\Sql\User_wishlistSQL;use Vvveb\System\Component\ComponentBase;use Vvveb\System\Event;use Vvveb\System\Images;use function Vvveb\url;class Wishlist extends ComponentBase {- public static $defaultOptions = [+ public static array $defaultOptions = ['user_id' => null,'start' => 0,+ 'page' => 1,'limit' => 10,'image_size' => 'thumb',];- //don't cache- function cacheKey() {- return false;+ /**+ * Disable caching for user wishlist component.+ *+ * @return null Always returns null to disable caching.+ */+ public function cacheKey(): ?string {+ return null;}- function results() {+ /**+ * Get user wishlist items with product images and URLs.+ *+ * @return array<string, mixed> Wishlist data with user_wishlist items.+ */+ public function results(): array {$results = [];+ if ($page = $this->options['page']) {+ $this->options['start'] = ($page - 1) * $this->options['limit'];+ }+if ($this->options['user_id']) {- $wishlist = new User_WishlistSQL();+ $wishlist = new User_wishlistSQL();$results = $wishlist->getAll($this->options);if ($results && isset($results['user_wishlist'])) {@@ -61,12 +75,18 @@ class Wishlist extends ComponentBase {}}- list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);+ [$results] = Event :: trigger(__CLASS__, __FUNCTION__, $results);return $results;}- //called on each request- function request($results, $index = 0) {- }+ /**+ * Called on each request (no-op for wishlist).+ *+ * @param array<string, mixed> $results Component results.+ * @param int $index Request index.+ *+ * @return void+ */+ public function request(array $results, int $index = 0): void {}}diff --git a/app/component/users.php b/app/component/users.phpindex b17e146..6c16bd4 100644--- a/app/component/users.php+++ b/app/component/users.php@@ -28,17 +28,22 @@ use Vvveb\System\Images;use function Vvveb\url;class Users extends ComponentBase {- public static $defaultOptions = [- 'start' => 0,- 'limit' => ['url', 4], //default get from url, if missing it will use a default of 4- 'status' => 1, //1 enabled, 0 disabled- 'search' => 1, //search in username and first and last names- 'user_id' => 1, //array list of user_id's to filter+ public static array $defaultOptions = [+ 'start' => 0,+ 'limit' => ['url', 4],+ 'status' => 1,+ 'search' => 1,+ 'user_id' => 1,];- public $options = [];+ public array $options = [];- function results() {+ /**+ * Get users list with avatar images and profile URLs.+ *+ * @return array<string, mixed> Users data with user list and image URLs.+ */+ public function results(): array {$users = new \Vvveb\Sql\UserSQL();$results = $users->getAll($this->options);@@ -53,7 +58,7 @@ class Users extends ComponentBase {}}- list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);+ [$results] = Event :: trigger(__CLASS__, __FUNCTION__, $results);return $results;}diff --git a/app/component/wishlist.php b/app/component/wishlist.phpindex fcd5d2d..e3d954a 100644--- a/app/component/wishlist.php+++ b/app/component/wishlist.php@@ -26,21 +26,26 @@ use Vvveb\System\Component\ComponentBase;use Vvveb\System\Event;class Wishlist extends ComponentBase {- public static $defaultOptions = [- 'start' => 0,- 'page' => 1,- 'limit' => 4,- 'language_id' => null,- 'site_id' => null,- 'user_id' => NULL,- 'image_size' => 'medium',+ public static array $defaultOptions = [+ 'start' => 0,+ 'page' => 1,+ 'limit' => 4,+ 'language_id' => null,+ 'site_id' => null,+ 'user_id' => null,+ 'image_size' => 'medium',];- public $options = [];+ public array $options = [];- public $cacheExpire = 0; //no cache+ public int $cacheExpire = 0;- function results() {+ /**+ * Get wishlist products with pagination and search support.+ *+ * @return array<string, mixed> Wishlist data with product list, limit, start, and search.+ */+ public function results(): array {$products = new \Vvveb\Sql\User_wishlistSQL();if ($page = $this->options['page']) {@@ -59,7 +64,7 @@ class Wishlist extends ComponentBase {$results['start'] = $this->options['start'];$results['search'] = $this->options['search'] ?? '';- list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);+ [$results] = Event :: trigger(__CLASS__, __FUNCTION__, $results);return $results;}diff --git a/app/controller/base.php b/app/controller/base.phpold mode 100755new mode 100644index ea6aead..565b1b8--- a/app/controller/base.php+++ b/app/controller/base.php@@ -22,55 +22,100 @@namespace Vvveb\Controller;-use \Vvveb\System\Core\FrontController;-use \Vvveb\System\Functions\Str;use function Vvveb\filter;use function Vvveb\siteSettings;+use Vvveb\System\Core\FrontController;+use Vvveb\System\Core\Request;+use Vvveb\System\Core\Response;use Vvveb\System\Core\View;use Vvveb\System\Event;+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;use Vvveb\System\User\Admin;use Vvveb\System\User\User;#[\AllowDynamicProperties]class Base {- protected $global;+ /** @var array<string, mixed> */+ protected array $global = [];- protected function language($default_language = false, $default_language_id = false, $default_locale = false, $default_code = false, $languages = null) {- $languages = $languages ?? Locale::availableLanguages();+ /** @var Request Request instance injected by FrontController DI. */+ public Request $request;++ /** @var Response Response instance injected by FrontController DI. */+ public Response $response;++ /** @var View View instance injected by FrontController DI. */+ public View $view;++ /** @var Session Session instance injected by FrontController DI. */+ public Session $session;++ /**+ * Set the current language based on request/session/default values.+ *+ * @param string|false $default_language+ * @param int|false $default_language_id+ * @param string|false $default_locale+ * @param string|false $default_code+ * @param array<string, array<string, mixed>>|null $languages+ *+ * @return void+ */+ protected function language(string|false $default_language = false, int|false $default_language_id = false, string|false $default_locale = false, string|false $default_code = false, ?array $languages = null): void {+ $languages ??= Locale::availableLanguages();$default_rtl = false;- $site_language = false;$language = false;+ $language_id = $default_language_id;+ $locale = $default_locale;+ $code = $default_code;+ $rtl = $default_rtl;- if (($lang = ($this->request->post['language'] ?? false)) && ! is_array($lang)) {- $language = filter('/[A-Za-z_-]+/', $lang, 10);+ //language can be set with a post or get request, post also persists it in the session+ //a get request takes precedence over post for the current page+ $postLanguage = null;+ $getLanguage = null;- if (isset($languages[$language])) {- $this->session->set('language', $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 (($lang = ($this->request->post['language'] ?? false)) && !is_array($lang)) {+ $lang = filter('/[A-Za-z_-]+/', $lang, 10);++ if (isset($languages[$lang])) {+ $postLanguage = $lang;}}- if (($lang = ($this->request->get['language'] ?? false)) && ! is_array($lang)) {- $language = filter('/[A-Za-z_-]+/', $lang, 10);+ if (($lang = ($this->request->get['language'] ?? false)) && !is_array($lang)) {+ $lang = filter('/[A-Za-z_-]+/', $lang, 10);- if (isset($languages[$language])) {- $lg = $languages[$language];- $language_id = $lg['language_id'];- $locale = $lg['locale'];- $code = $lg['code'];- $rtl = $lg['rtl'] ?? false;+ if (isset($languages[$lang])) {+ $getLanguage = $lang;}+ }++ if ($postLanguage) {+ $lg = $languages[$postLanguage];+ $this->session->set('language', $postLanguage);+ $this->session->set('language_id', $lg['language_id']);+ $this->session->set('locale', $lg['locale']);+ $this->session->set('code', $lg['code']);+ $this->session->set('rtl', $lg['rtl'] ?? false);+ }++ if ($requestLanguage = ($getLanguage ?? $postLanguage)) {+ $lg = $languages[$requestLanguage];+ $language = $requestLanguage;+ $language_id = $lg['language_id'];+ $locale = $lg['locale'];+ $code = $lg['code'];+ $rtl = $lg['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') {+ 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;@@ -80,7 +125,7 @@ class Base {}//if no language configured then set default language as current language- if (! $language) {+ if (!$language) {$language = $default_language;$language_id = $default_language_id;$locale = $default_locale;@@ -89,8 +134,8 @@ class Base {}//if no default language configured then set first language as current language- if (! isset($languages[$language])) {- $language = null;+ if (!isset($languages[$language])) {+ $language = null;$default_language = key($languages);$lang = $languages[$default_language] ?? [];@@ -111,11 +156,19 @@ class Base {$this->global['default_locale'] = $default_locale;$this->global['default_language_id'] = $default_language_id;- Locale :: setLanguage($code);+ Locale::setLanguage($code);}- protected function currency($defaultCurrency = false, $defaultCurrencyId = false) {- if (($currency = ($this->request->post['currency'] ?? false)) && ! is_array($currency)) {+ /**+ * Set the current currency based on request/session/default values.+ *+ * @param string|false $defaultCurrency+ * @param int|false $defaultCurrencyId+ *+ * @return void+ */+ protected function currency(string|false $defaultCurrency = false, int|false $defaultCurrencyId = false): void {+ if (($currency = ($this->request->post['currency'] ?? false)) && !is_array($currency)) {$currency = filter('/[A-Za-z_-]+/', $currency, 50);$currencies = Locale::availableCurrencies();@@ -130,13 +183,13 @@ class Base {$currency = $this->session->get('currency');$currency_id = $this->session->get('currency_id');- if (! $currency || ! $currency_id) {+ if (!$currency || !$currency_id) {$currencies = Locale::availableCurrencies();if ($currencies) {foreach ($currencies as $code => $c) {- if ($defaultCurrency && ($defaultCurrency == $c['code']) ||- ($defaultCurrencyId && ($defaultCurrencyId == $c['currency_id']))) {+ if (($defaultCurrency && $defaultCurrency === $c['code']) ||+ ($defaultCurrencyId && $defaultCurrencyId == $c['currency_id'])) {$currency = $c['code'];$currency_id = $c['currency_id'];@@ -145,7 +198,7 @@ class Base {}//if no site currency configured set first available currency- if (! $currency) {+ if (!$currency) {$c = reset($currencies);$currency = $c['code'];$currency_id = $c['currency_id'];@@ -160,17 +213,35 @@ class Base {$this->global['currency_id'] = $currency_id;}- protected function initEcommerce($countryId, $regionId) {+ /**+ * Initialize ecommerce tax settings for the given region.+ *+ * @param int $countryId+ * @param int $regionId+ *+ * @return void+ */+ protected function initEcommerce(int $countryId, int $regionId): void {$tax = \Vvveb\System\Cart\Tax::getInstance();- $tax->setRegionRules($countryId, $regionId, 'store');+ $tax->setRegionRules($countryId, $regionId, 'store', $this->global['user_group_id'] ?? null);}- function getGlobal() {+ /**+ * Get the global template variables.+ *+ * @return array<string, mixed>+ */+ public function getGlobal(): array {return $this->global;}- function init() {- if (! $this->session->get('csrf')) {+ /**+ * Initialize the controller: sets up session, user data, site settings, language, and currency.+ *+ * @return string|null+ */+ public function init(): ?string {+ if (!$this->session->get('csrf')) {$this->session->set('csrf', Str::random());}@@ -186,21 +257,23 @@ class Base {}}- $siteData = Sites :: getSiteData(SITE_ID);+ $siteData = Sites::getSiteData(SITE_ID);- if (isset($siteData['state']) && $siteData['state'] != 'live') {- if (! $admin) {+ if (isset($siteData['state']) && $siteData['state'] !== 'live') {+ if (!$admin) {$template = Sites::getStates()[$siteData['state']]['template'];$this->view->template($template);-- //die($this->view->render());$this->response->output();++ return '';}}$site = siteSettings();- list($site) = Event::trigger(__CLASS__, __FUNCTION__, $site);+ \Vvveb\System\Cart\Tax::getInstance()->pricesIncludeTax = !empty($site['prices_include_tax']);++ [$site] = Event::trigger(__CLASS__, __FUNCTION__, $site);$user = User::current();@@ -208,29 +281,23 @@ class Base {$user['avatar_url'] = Images::image($user['avatar'], 'user');}-if ($admin && isset($admin['avatar'])) {$admin['avatar_url'] = Images::image($admin['avatar'], 'admin');}- /*- $site['url'] = \Vvveb\url('index/index',[- 'host' => $_SERVER['HTTP_HOST'] ?? false,- 'scheme' => $_SERVER['REQUEST_SCHEME'] ?? 'http',- ]);- */+$site['url'] = $siteData['host'] ?? ('//' . ($_SERVER['HTTP_HOST'] ?? ''));- $this->global['site_id'] = SITE_ID ?? 1;+ $this->global['site_id'] = SITE_ID;$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'] = (V_SUBDIR_INSTALL ? V_SUBDIR_INSTALL : '') . (V_SUBDIR_INSTALL && SITE_PATH ? '/' : '' ) . SITE_PATH;- $this->global['user'] = $user ?? [];- $this->global['admin'] = $admin ?? [];+ $this->global['path'] = V_SUBDIR_INSTALL . (V_SUBDIR_INSTALL && SITE_PATH ? '/' : '') . SITE_PATH;+ $this->global['user'] = $user;+ $this->global['admin'] = $admin;$this->global['current_year'] = date('Y');$languages = Locale::availableLanguages();- $language = $languages[$site['language'] ?? 'en'] ?? ['slug' => 'en', 'language_id' => 1, 'locale' => 'en', 'code' => 'en_US', $languages];+ $language = $languages[$site['language'] ?? 'en'] ?? ['slug' => 'en', 'language_id' => 1, 'locale' => 'en', 'code' => 'en_US'];$this->language($language['slug'], $language['language_id'], $language['locale'], $language['code']);$this->currency($site['currency'] ?? false, $site['currency_id'] ?? false);@@ -270,15 +337,25 @@ 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!';- if (! isset($this->view->message)) {+ if (!isset($this->view->message)) {$this->view->message[] = 'This is a dummy message!';}}- list($this->global) = Event::trigger(__CLASS__, __FUNCTION__ . ':after', $this->global);+ [$this->global] = Event::trigger(__CLASS__, __FUNCTION__ . ':after', $this->global);++ return null;}- protected function redirect($url = '/', $parameters = []) {+ /**+ * Redirect to the given URL with optional query parameters.+ *+ * @param string|array<string, mixed> $url+ * @param array<string, mixed> $parameters+ *+ * @return never+ */+ protected function redirect(string|array $url = '/', array $parameters = []): never {$redirect = \Vvveb\url($url, $parameters);if ($redirect) {@@ -294,31 +371,30 @@ class Base {header("Location: $url");- die();+ exit();}/**- * Call this method if the action requires login, if the user is not logged in, a login form will be shown.+ * Call this method if the action requires login; shows a login form if the user is not logged in.*+ * @return never*/- protected function requireLogin() {- $view = view :: getInstance();- $view :: template(DS . 'login.html');-- view :: getInstance()->render();- die();+ protected function requireLogin(): never {+ $this->view->template(DS . 'login.html');+ $this->view->render();+ exit();}/**- * Call this function if the requeste information was not found, for example if the specifed news, image, profile etc is not found then call this function.- * It shows a "Not found" page and it also send 404 http status code, this is usefull for search engines etc.+ * Show a "Not found" page and send a 404 (or other) HTTP status code.+ *+ * @param array<string, mixed>|string|false $message+ * @param int $statusCode+ * @param mixed $service*- * @param unknown_type $code- * @param mixed $service- * @param mixed $statusCode- * @param null|mixed $message+ * @return never*/- protected function notFound($service = false, $message = null, $statusCode = 404) {- return FrontController::notFound($service, $message, $statusCode);+ protected function notFound(string|array|false $message = false, int $statusCode = 404, mixed $service = false): never {+ FrontController::notFound($service, $message, $statusCode);}}diff --git a/app/controller/cart/cart-trait.php b/app/controller/cart/cart-trait.phpnew file mode 100644index 0000000..0c66795--- /dev/null+++ b/app/controller/cart/cart-trait.php@@ -0,0 +1,222 @@+<?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\Cart;++use function Vvveb\siteSettings;+use Vvveb\System\Cart\Tax;+use Vvveb\System\Payment;+use Vvveb\System\Shipping;++trait CartTrait {+ /**+ * Sync posted country/region address fields into checkout info before+ * shipping/payment methods are resolved.+ *+ * Country/region changes arrive via AJAX (see reloadRegions() in+ * checkout.js) without a full checkout submit, so without this sync+ * getMethods() would keep filtering by the stale session country and+ * the cart totals would keep the old shipping method.+ *+ * @param array<string, mixed> $checkoutInfo Checkout data updated in place.+ */+ private function syncCheckoutAddresses(array &$checkoutInfo): void {+ $post = $this->request->post ?? [];++ foreach (['billing_address', 'shipping_address'] as $key) {+ if (isset($post[$key]) && is_array($post[$key])) {+ $checkoutInfo[$key] = array_merge($checkoutInfo[$key] ?? [], $post[$key]);+ }+ }++ if (array_key_exists('different_shipping_address', $post)) {+ $checkoutInfo['different_shipping_address'] = $post['different_shipping_address'];+ }++ //when shipping to the billing address the shipping filter must follow the billing country+ if (empty($checkoutInfo['different_shipping_address']) && !empty($checkoutInfo['billing_address'])) {+ $checkoutInfo['shipping_address'] = $checkoutInfo['billing_address'];+ }++ foreach (['billing' => 'billing_address', 'shipping' => 'shipping_address'] as $prefix => $addressKey) {+ $address = $checkoutInfo[$addressKey] ?? false;++ if (is_array($address)) {+ if (isset($address['country_id']) && $address['country_id'] !== '') {+ $checkoutInfo["{$prefix}_country_id"] = $address['country_id'];+ }++ if (isset($address['region_id']) && $address['region_id'] !== '') {+ $checkoutInfo["{$prefix}_region_id"] = $address['region_id'];+ }+ }+ }++ //fall back to the site default country/region on first load when the session has no address yet+ if (empty($checkoutInfo['shipping_country_id']) && empty($checkoutInfo['billing_country_id'])) {+ $site = $this->global['site'] ?? siteSettings();++ if (!empty($site['country_id'])) {+ $checkoutInfo['billing_country_id'] ??= $site['country_id'];+ $checkoutInfo['shipping_country_id'] ??= $site['country_id'];+ }++ if (!empty($site['region_id'])) {+ $checkoutInfo['billing_region_id'] ??= $site['region_id'];+ $checkoutInfo['shipping_region_id'] ??= $site['region_id'];+ }+ }++ $this->session->set('checkout', $checkoutInfo);+ }++ /**+ * Re-resolve tax rules for the customer addresses.+ *+ * Page init loads store-based rules so browsing prices are taxed.+ * Once addresses are known the destination basis wins: shipping geo+ * with `shipping` rules, otherwise billing geo with `payment` rules.+ * If that matches nothing (e.g. a store configured with store-based+ * rules only) fall back to the legacy store-based set so tax never+ * silently drops to zero. The singleton accumulates across calls,+ * so it is cleared before each resolution.+ *+ * @param array<string, mixed> $checkoutInfo+ * @param bool $hasShipping+ *+ * @return void+ */+ private function refreshTaxRules(array $checkoutInfo, bool $hasShipping): void {+ $site = $this->global['site'] ?? [];+ $storeCountry = (int)($site['country_id'] ?? 0);+ $storeRegion = (int)($site['region_id'] ?? 0);+ $group = $this->global['user_group_id'] ?? null;+ $tax = Tax::getInstance();+ $tax->clear();++ if ($hasShipping && !empty($checkoutInfo['shipping_country_id'])) {+ $tax->setRegionRules(+ (int)$checkoutInfo['shipping_country_id'],+ (int)($checkoutInfo['shipping_region_id'] ?? 0),+ 'shipping',+ $group+ );+ } elseif (!empty($checkoutInfo['billing_country_id'])) {+ $tax->setRegionRules(+ (int)$checkoutInfo['billing_country_id'],+ (int)($checkoutInfo['billing_region_id'] ?? 0),+ 'payment',+ $group+ );+ }++ if (!$tax->hasRates()) {+ $tax->clear();+ $tax->setRegionRules($storeCountry, $storeRegion, 'store', $group);+ }+ }++ /**+ * Resolve default shipping/payment methods from site settings.+ *+ * @param array<string, mixed> $checkoutInfo+ * @param bool $hasShipping+ * @param bool $hasPayment+ *+ * @return array<string, mixed>+ */+ protected function shippingPayment(array &$checkoutInfo, bool $hasShipping, bool $hasPayment): array {+ $this->view->payment = [];+ $this->view->shipping = [];+ $shipping = null;+ $payment = null;++ if ($hasShipping || $hasPayment) {+ $this->syncCheckoutAddresses($checkoutInfo);+ $this->refreshTaxRules($checkoutInfo, $hasShipping);+ }++ if ($hasShipping) {+ $shipping = Shipping::getInstance();+ $this->view->shipping = $shipping->getMethods($checkoutInfo);++ if (isset($this->request->post['shipping_method'])) {+ $checkoutInfo['shipping_method'] = $this->request->post['shipping_method'];+ }++ if (!isset($checkoutInfo['shipping_method']) || !$checkoutInfo['shipping_method']) {+ $checkoutInfo['shipping_method'] = siteSettings()['shipping_method'] ?? '';+ }++ //drop a stale selection (e.g. UK-only method after switching to US) so+ //the first available zone is auto-selected and totals are recalculated+ if (!isset($this->view->shipping[$checkoutInfo['shipping_method']])) {+ $default = siteSettings()['shipping_method'] ?? '';++ if ($default && isset($this->view->shipping[$default])) {+ $checkoutInfo['shipping_method'] = $default;+ } else {+ $checkoutInfo['shipping_method'] = array_key_first($this->view->shipping) ?? '';+ }++ $this->session->set('checkout', $checkoutInfo);+ }+ }++ if ($hasPayment) {+ $payment = Payment::getInstance();+ $this->view->payment = $payment->getMethods($checkoutInfo);++ if (isset($this->request->post['payment_method'])) {+ $checkoutInfo['payment_method'] = $this->request->post['payment_method'];+ }++ if (!isset($checkoutInfo['payment_method']) || !$checkoutInfo['payment_method']) {+ $checkoutInfo['payment_method'] = siteSettings()['payment_method'] ?? '';+ }++ if ($this->view->payment && !isset($this->view->payment[$checkoutInfo['payment_method']])) {+ $default = siteSettings()['payment_method'] ?? '';++ if ($default && isset($this->view->payment[$default])) {+ $checkoutInfo['payment_method'] = $default;+ } else {+ $checkoutInfo['payment_method'] = array_key_first($this->view->payment);+ }++ $this->session->set('checkout', $checkoutInfo);+ }+ }++ if (isset($checkoutInfo['shipping_method']) && $checkoutInfo['shipping_method'] && isset($shipping)) {+ $shipping->setMethod($checkoutInfo['shipping_method']);+ $this->view->shipping_method = $checkoutInfo['shipping_method'];+ }++ if (isset($checkoutInfo['payment_method']) && $checkoutInfo['payment_method'] && isset($payment)) {+ $payment->setMethod($checkoutInfo['payment_method']);+ $this->view->payment_method = $checkoutInfo['payment_method'];+ }++ return ['shipping' => $shipping, 'payment' => $payment];+ }+}diff --git a/app/controller/cart/cart.php b/app/controller/cart/cart.phpindex 9e0a103..e6bba9f 100755--- a/app/controller/cart/cart.php+++ b/app/controller/cart/cart.php@@ -24,23 +24,27 @@ namespace Vvveb\Controller\Cart;use Vvveb\Controller\Base;use Vvveb\System\Cart\Cart as ShoppingCart;-use Vvveb\System\Core\View;use Vvveb\System\Event;-use Vvveb\System\Payment;-use Vvveb\System\Shipping;-//use Vvveb\Trait\Cart as CartTrait;class Cart extends Base {-// use CartTrait;+ use CartTrait;use CouponTrait;- private $cart;+ /** @var ShoppingCart|null Shopping cart instance. */+ private ?ShoppingCart $cart = null;- function init() {+ /**+ * Initialise the cart from session/request data.+ *+ * @return string|null+ */+ public function init(): ?string {parent::init();- $options = array_intersect_key($this->global['site'],- array_flip(['weight_type_id', 'length_type_id', 'currency_id', 'country_id']));+ $options = array_intersect_key(+ $this->global['site'],+ array_flip(['weight_type_id', 'length_type_id', 'currency_id', 'country_id'])+ );$encrypted_cart_id = false;@@ -55,15 +59,17 @@ class Cart extends Base {$this->cart->loadCart($cart_id);}}- }- function index() {- $payment = Payment::getInstance();- $shipping = Shipping::getInstance();+ return null;+ }- $checkoutInfo = [];- $this->view->payment = $payment->getMethods($checkoutInfo);- $this->view->shipping = $shipping->getMethods($checkoutInfo);+ /**+ * Display the shopping cart.+ *+ * @return void+ */+ public function index(): void {+ $checkoutInfo = $this->session->get('checkout') ?? ['user' => $this->global['user']];$product_id = $this->request->post['product_id'] ?? $this->request->get['product_id'] ?? false;$module = $this->request->get['module'] ?? $this->request->post['module'] ?? '';@@ -72,17 +78,23 @@ class Cart extends Base {$this->action('add', $product_id);}+ $hasShipping = $this->cart->hasShipping();+ $subscription = $this->cart->getSubscription();+ $hasPayment = ($this->cart->getGrandTotal() > 0);++ $this->shippingPayment($checkoutInfo, $hasShipping, $hasPayment);+$cart = ['products' => $this->cart->getAll(),'totals' => $this->cart->getAllTotals(),'total_items' => $this->cart->getNoProducts(),'total_weight' => $this->cart->getWeight(),- 'total_price' => $this->cart->getNoProducts(),+ 'subtotal' => $this->cart->getSubTotal(),'total' => $this->cart->getGrandTotal(),'coupons' => $this->cart->getCoupons(),'total_formatted' => $this->cart->getGrandTotalFormatted(),- 'cart_id' => ($cardId = $this->cart->getId()),- 'encrypted_cart_id' => $cardId ? $this->cart->getId() : '',+ 'cart_id' => ($cartId = $this->cart->getId()),+ 'encrypted_cart_id' => $cartId ? $this->cart->getEncryptedId() : '','weight_unit' => $this->global['site']['weight_type'],'length_unit' => $this->global['site']['length_type'],];@@ -90,7 +102,16 @@ class Cart extends Base {$this->view->cart = $cart;}- private function action($action, $productId = null, $quantity = 1) {+ /**+ * Perform a cart action: add, update, or remove.+ *+ * @param string $action+ * @param int|string|null $productId+ * @param int $quantity+ *+ * @return void+ */+ private function action(string $action, int|string|null $productId = null, int $quantity = 1): void {$productId = $this->request->request['product_id'] ?? $productId ?? false;$key = $this->request->request['key'] ?? false;$quantity = $this->request->request['quantity'] ?? $quantity;@@ -98,8 +119,8 @@ class Cart extends Base {$subscriptionPlanId = $this->request->request['subscription_plan_id'] ?? false;$productVariantId = $this->request->request['product_variant_id'] ?? false;- list($action, $productId, $key, $quantity, $option, $subscriptionPlanId) =- Event :: trigger(__CLASS__,__FUNCTION__, $action, $productId, $key, $quantity, $option, $subscriptionPlanId);+ [$action, $productId, $key, $quantity, $option, $subscriptionPlanId] =+ Event::trigger(__CLASS__, __FUNCTION__, $action, $productId, $key, $quantity, $option, $subscriptionPlanId);if ($key || $productId) {switch ($action) {@@ -118,25 +139,39 @@ class Cart extends Base {break;}- //$this->view->success = $this->cart->$action($productId, $quantity);}$this->view->noJson = true;}- function remove() {+ /**+ * Remove an item from the cart and redisplay.+ *+ * @return void+ */+ public function remove(): void {$this->action('remove');- return $this->index();+ $this->index();}- function update() {+ /**+ * Update a cart item quantity and redisplay.+ *+ * @return void+ */+ public function update(): void {$this->action('update');- return $this->index();+ $this->index();}- function add() {- return $this->index();+ /**+ * Add an item to the cart and redisplay.+ *+ * @return void+ */+ public function add(): void {+ $this->index();}}diff --git a/app/controller/cart/compare.php b/app/controller/cart/compare.phpold mode 100644new mode 100755index 53b5700..fefee47--- a/app/controller/cart/compare.php+++ b/app/controller/cart/compare.php@@ -22,21 +22,27 @@namespace Vvveb\Controller\Cart;-use \Vvveb\Sql\AttributeSQL;-use \Vvveb\Sql\ProductSQL;use Vvveb\Controller\Base;use function Vvveb\session as sess;+use Vvveb\Sql\AttributeSQL;+use Vvveb\Sql\ProductSQL;use Vvveb\System\Cart\Currency;use Vvveb\System\Cart\Tax;use Vvveb\System\Images;use function Vvveb\url;class Compare extends Base {- function index() {+ /**+ * Display a side-by-side comparison of selected products.+ *+ * @return void+ */+ public function index(): void {$product_id = $compare = sess('compare'); //[18, 19, 17, 16];$results = [];$names = [];$specs = [];+ $attrs = [];if ($product_id) {$names = [];@@ -55,7 +61,7 @@ class Compare extends Base {}if ($results && isset($results['product'])) {- $tax = Tax::getInstance($this->global);+ $tax = Tax::getInstance();$currency = Currency::getInstance($this->global);foreach ($results['product'] as $id => &$product) {@@ -90,7 +96,14 @@ class Compare extends Base {$this->view->specs = $specs;}- private function action($action) {+ /**+ * Perform a comparison action: add or remove a product.+ *+ * @param string $action+ *+ * @return void+ */+ private function action(string $action): void {$productId = (int)($this->request->get['product_id'] ?? $this->request->post['product_id'] ?? false);if ($productId) {@@ -100,12 +113,12 @@ class Compare extends Base {case 'add':$compare[$productId] = $productId;- break;+ break;case 'remove':unset($compare[$productId]);- break;+ break;}sess(['compare' => $compare]);@@ -114,11 +127,21 @@ class Compare extends Base {$this->index();}- function add() {- return $this->action('add');+ /**+ * Add a product to the comparison list.+ *+ * @return void+ */+ public function add(): void {+ $this->action('add');}- function remove() {- return $this->action('remove');+ /**+ * Remove a product from the comparison list.+ *+ * @return void+ */+ public function remove(): void {+ $this->action('remove');}}diff --git a/app/controller/cart/coupon-trait.php b/app/controller/cart/coupon-trait.phpindex 57e8209..431cee2 100644--- a/app/controller/cart/coupon-trait.php+++ b/app/controller/cart/coupon-trait.php@@ -25,7 +25,12 @@ namespace Vvveb\Controller\Cart;use function Vvveb\__;trait CouponTrait {- function coupon() {+ /**+ * Apply a coupon to the cart.+ *+ * @return void+ */+ public function coupon(): void {$coupon = $this->request->request['coupon'] ?? '';if ($coupon) {@@ -36,10 +41,15 @@ trait CouponTrait {}}- return $this->index();+ $this->index();}- function removeCoupon() {+ /**+ * Remove a coupon from the cart.+ *+ * @return void+ */+ public function removeCoupon(): void {$coupon = $this->request->request['coupon'] ?? '';if ($coupon) {@@ -50,6 +60,6 @@ trait CouponTrait {}}- return $this->index();+ $this->index();}}diff --git a/app/controller/checkout/checkout.php b/app/controller/checkout/checkout.phpindex 08f0569..e221706 100755--- a/app/controller/checkout/checkout.php+++ b/app/controller/checkout/checkout.php@@ -24,48 +24,45 @@ namespace Vvveb\Controller\Checkout;use function Vvveb\__;use Vvveb\Controller\Base;+use Vvveb\Controller\Cart\CartTrait;use Vvveb\Controller\Cart\CouponTrait;use Vvveb\Controller\User\LoginTrait;use function Vvveb\email;+use function Vvveb\model;use function Vvveb\prefixArrayKeys;use function Vvveb\siteSettings;use Vvveb\Sql\CountrySQL;use Vvveb\Sql\RegionSQL;-use Vvveb\Sql\User_AddressSQL;+use Vvveb\Sql\User_addressSQL;use Vvveb\System\CacheManager;use Vvveb\System\Cart\Cart;use Vvveb\System\Cart\Order;use Vvveb\System\Event;-use Vvveb\System\Payment;-use Vvveb\System\Shipping;use Vvveb\System\Sites;use Vvveb\System\User\User;use Vvveb\System\Validator;use function Vvveb\url;class Checkout extends Base {- use LoginTrait, CouponTrait;-- private $cart;-- /*- use LoginTrait {- login as protected loginBase;- }--- function login() {- $this->loginBase();-- return $this->index();- }- */-- function init() {+ use CartTrait;+ use CouponTrait;+ use LoginTrait;++ /** @var Cart|null Shopping cart instance. */+ private ?Cart $cart = null;++ /**+ * Initialise the cart for the checkout process.+ *+ * @return string|null+ */+ public function init(): ?string {parent::init();- $options = array_intersect_key($this->global['site'],- array_flip(['weight_type_id', 'length_type_id', 'currency_id', 'country_id']));+ $options = array_intersect_key(+ $this->global['site'],+ array_flip(['weight_type_id', 'length_type_id', 'currency_id', 'country_id'])+ );$encrypted_cart_id = false;@@ -80,9 +77,16 @@ class Checkout extends Base {$this->cart->loadCart($cart_id);}}++ return null;}- function regions() {+ /**+ * Return regions for a given country as JSON (AJAX endpoint).+ *+ * @return void+ */+ public function regions(): void {$country_id = $this->request->get['country_id'] ?? false;$regions = [];@@ -99,7 +103,14 @@ class Checkout extends Base {$this->response->output($regions);}- private function data(&$checkoutInfo) {+ /**+ * Load shared checkout data: countries and regions for address forms.+ *+ * @param array<string, mixed> &$checkoutInfo+ *+ * @return void+ */+ private function data(array &$checkoutInfo): void {$countryModel = new CountrySQL();$options = $this->global;$options['status'] = 1;@@ -107,23 +118,174 @@ class Checkout extends Base {$country = $countryModel->getAll($options);$this->view->countries = $country['country'] ?? [];- //set default contry and region- $checkoutInfo['billing_country_id'] = $checkoutInfo['billing_country_id'] ?? $this->global['site']['country_id'] ?? false;- $checkoutInfo['shipping_country_id'] = $checkoutInfo['shipping_country_id'] ?? $this->global['site']['country_id'] ?? false;- $checkoutInfo['shipping_region_id'] = $checkoutInfo['shipping_region_id'] ?? $this->global['site']['region_id'] ?? false;- $checkoutInfo['billing_region_id'] = $checkoutInfo['billing_region_id'] ?? $this->global['site']['region_id'] ?? false;- $country_id = $checkoutInfo['billing_country_id'] ?? $checkoutInfo['shipping_country_id'] ?? false;+ //set default country and region+ $checkoutInfo['billing_country_id'] ??= $this->global['site']['country_id'] ?? false;+ $checkoutInfo['shipping_country_id'] ??= $this->global['site']['country_id'] ?? false;+ $checkoutInfo['shipping_region_id'] ??= $this->global['site']['region_id'] ?? false;+ $checkoutInfo['billing_region_id'] ??= $this->global['site']['region_id'] ?? false;+ $country_id = $checkoutInfo['billing_country_id'] ?: $checkoutInfo['shipping_country_id'] ?: false;if ($country_id) {$region = new RegionSQL();- $regions = $region->getAll(['country_id' => $country_id]);+ $regions = $region->getAll(['country_id' => $country_id]);$this->view->regions = $regions['region'] ?? [];}$this->view->regionsUrl = url(['module' => 'checkout/checkout', 'action' => 'regions']);}- function index() {+ /**+ * Create pending core subscription rows for subscription products.+ *+ * Gateway-agnostic: every payment method gets a local pending record at+ * checkout time. Gateway-backed methods (Stripe) claim these rows when+ * provisioning instead of inserting duplicates; manual methods+ * (bank transfer, COD) stay pending until confirmed.+ * Idempotent per order: retried submits skip already created rows.+ *+ * @param int|string $order_id Order id.+ * @param array<string, mixed> $checkoutInfo Checkout information.+ *+ * @return void+ */+ private function createPendingSubscriptions(int|string $order_id, array $checkoutInfo): void {+ $items = $this->cart->getSubscription();++ if (!$items) {+ return;+ }++ try {+ $model = model('subscription');+ $userId = (int)($checkoutInfo['user_id'] ?? $this->global['user_id'] ?? 0);+ $existing = $model->getAll(['user_id' => $userId, 'language_id' => $this->global['language_id'] ?? 1] + $this->global)['subscription'] ?? [];+ $have = [];++ foreach ($existing as $row) {+ if ((int)($row['order_id'] ?? 0) === (int)$order_id) {+ $have[(int)($row['subscription_plan_id'] ?? 0) . ':' . (int)($row['product_id'] ?? 0)] = true;+ }+ }++ foreach ($items as $item) {+ $planId = (int)($item['subscription_plan_id'] ?? 0);+ $productId = (int)($item['product_id'] ?? 0);+ $plan = $item['subscription'] ?? [];++ if (!$planId || !$productId || empty($plan) || isset($have["$planId:$productId"])) {+ continue;+ }++ $period = $plan['period'] ?? 'month';+ $cycle = max(1, (int)($plan['cycle'] ?? 1));++ try {+ $next = (new \DateTime())->modify("+$cycle $period")->format('Y-m-d H:i:s');+ } catch (\Throwable $e) {+ $next = date('Y-m-d H:i:s', strtotime('+1 month'));+ }++ $trialStatus = !empty($plan['trial_status']) && !empty($plan['trial_length']);++ $model->add(['subscription' => [+ 'order_id' => (int)$order_id,+ 'order_product_id' => 0,+ 'site_id' => SITE_ID,+ 'user_id' => $userId,+ 'payment_method' => $checkoutInfo['payment_method'] ?? '',+ 'product_id' => $productId,+ 'quantity' => (int)($item['quantity'] ?? 1),+ 'subscription_plan_id' => $planId,+ 'price' => (float)($item['price'] ?? 0),+ 'period' => $period,+ 'cycle' => $cycle,+ 'length' => (int)($plan['length'] ?? 0),+ 'subscription_status_id' => 1,+ 'date_next' => $next,+ 'trial_status' => $trialStatus ? 1 : 0,+ 'trial_price' => (float)($item['trial_price'] ?? 0),+ 'trial_period' => $plan['trial_period'] ?? 'day',+ 'trial_cycle' => max(1, (int)($plan['trial_cycle'] ?? 1)),+ 'trial_length' => (int)($plan['trial_length'] ?? 0),+ 'trial_left' => (int)($plan['trial_length'] ?? 0),+ 'notes' => '',+ 'created_at' => date('Y-m-d H:i:s'),+ 'updated_at' => date('Y-m-d H:i:s'),+ ]] + $this->global);++ $have["$planId:$productId"] = true;+ }+ } catch (\Throwable $e) {+ //subscription rows are auxiliary, never block the order+ }+ }++ /**+ * Rotate the single-use checkout submit token.+ *+ * @return string New token stored in the session.+ */+ private function rotateCheckoutToken(): string {+ $tokens = $this->session->get('checkout_tokens') ?? [];++ if (!is_array($tokens)) {+ $tokens = [];+ }++ $token = bin2hex(random_bytes(16));+ $tokens[] = $token;+ $this->session->set('checkout_tokens', array_slice($tokens, -5));++ return $token;+ }++ /**+ * Consume a submit token: true once, then spent (double posts fail).+ *+ * @param string $token Posted token.+ *+ * @return bool True when the token was valid and is now spent.+ */+ private function consumeCheckoutToken(string $token): bool {+ $tokens = $this->session->get('checkout_tokens') ?? [];++ if (!is_array($tokens) || $token === '') {+ return false;+ }++ $key = array_search($token, $tokens, true);++ if ($key === false) {+ return false;+ }++ unset($tokens[$key]);+ $this->session->set('checkout_tokens', array_values($tokens));++ return true;+ }++ /**+ * Current (newest) submit token, creating one when the pool is empty.+ *+ * @return string Token for the checkout form.+ */+ private function currentCheckoutToken(): string {+ $tokens = $this->session->get('checkout_tokens') ?? [];++ if (!is_array($tokens) || !$tokens) {+ return $this->rotateCheckoutToken();+ }++ return (string)end($tokens);+ }++ /**+ * Main checkout action — handles the entire checkout flow.+ *+ * @return void+ */+ public function index(): void {//buy now productif (isset($this->request->request['product_id'])) {$productId = $this->request->request['product_id'];@@ -134,12 +296,16 @@ class Checkout extends Base {$this->cart->add($productId, $quantity, $option, $productVariantId, $subscriptionPlanId);}- if (! $this->cart->hasProducts()) {- return $this->redirect('cart/cart/index');+ if (!$this->cart->hasProducts()) {+ $this->redirect('cart/cart/index');++ return;}if (isset($this->request->post['login'])) {- return $this->login();+ $this->login();++ return;}$order = Order::getInstance();@@ -152,26 +318,23 @@ class Checkout extends Base {$this->view->hasShipping = $hasShipping;$this->view->hasPayment = $hasPayment;- $payment = Payment::getInstance();- $this->view->payment = $payment->getMethods($checkoutInfo);-- if ($hasShipping) {- $shipping = Shipping::getInstance();- $this->view->shipping = $shipping->getMethods($checkoutInfo);- }-- if ($hasShipping && isset($this->request->post['shipping_method'])) {- $shipping_method = $this->request->post['shipping_method'];- $shipping->setMethod($shipping_method);- $checkoutInfo['shipping_method'] = $shipping_method;- $this->view->shipping_method = $shipping_method;- }-- if ($hasPayment && isset($this->request->post['payment_method'])) {- $payment_method = $this->request->post['payment_method'];- $payment->setMethod($payment_method);- $checkoutInfo['payment_method'] = $payment_method;- $this->view->payment_method = $payment_method;+ $methods = $this->shippingPayment($checkoutInfo, $hasShipping, $hasPayment);+ $shipping = $methods['shipping'];+ $payment = $methods['payment'];++ //shipping/payment totals are only added to the cart by setMethod() above,+ //so refresh the grand total, otherwise the stored order total and the+ //amount sent to the payment gateway miss shipping (and payment fees).+ $grandTotal = $this->cart->getGrandTotal();++ //a zero sub-total with a paid shipping method still requires payment+ if (!$hasPayment && $grandTotal > 0) {+ $hasPayment = true;+ $this->view->hasPayment = $hasPayment;+ $methods = $this->shippingPayment($checkoutInfo, $hasShipping, $hasPayment);+ $shipping = $methods['shipping'] ?? $shipping;+ $payment = $methods['payment'] ?? $payment;+ $grandTotal = $this->cart->getGrandTotal();}$this->data($checkoutInfo);@@ -179,16 +342,14 @@ class Checkout extends Base {if ($this->request->post) {if (isset($this->request->post['phone_number']) ||isset($this->request->post['billing_address']) ||- isset($this->request->post['billing_address_id']) || /*- isset($this->request->post['shipping_method']) ||- isset($this->request->post['payment_method']) ||*/+ isset($this->request->post['billing_address_id']) ||isset($this->request->post['email'])) {$rules = ['checkout'];// guest checkout- if (! $this->global['user_id']) {+ if (!$this->global['user_id']) {//password is provided- if (isset($this->request->post['register']) && $this->request->post['register'] == 'true') {+ if (isset($this->request->post['register']) && $this->request->post['register'] === 'true') {$rules[] = 'checkout_signup';} else {$rules[] = 'guest';@@ -198,7 +359,7 @@ class Checkout extends Base {$rules[] = 'guest';foreach (['first_name', 'last_name', 'email', 'phone_number'] as $field) {- $this->request->post[$field] = $this->request->post[$field] ?? $this->global['user'][$field];+ $this->request->post[$field] ??= $this->global['user'][$field];}}@@ -208,10 +369,8 @@ class Checkout extends Base {if (isset($this->request->post['billing_address'])) {//if billing name is missing use account name- //$this->request->post['billing_address']['first_name'] ??= $this->request->post['first_name'];- //$this->request->post['billing_address']['last_name'] ??= $this->request->post['last_name'];- $this->request->post['billing_address']['first_name'] = $this->request->post['billing_address']['first_name'] ?? $this->request->post['first_name'] ?? '';- $this->request->post['billing_address']['last_name'] = $this->request->post['billing_address']['last_name'] ?? $this->request->post['last_name'] ?? '';+ $this->request->post['billing_address']['first_name'] ??= $this->request->post['first_name'] ?? '';+ $this->request->post['billing_address']['last_name'] ??= $this->request->post['last_name'] ?? '';$billing_address = $this->request->post['billing_address'];$this->request->post += prefixArrayKeys('billing_', $billing_address);@@ -220,12 +379,11 @@ class Checkout extends Base {//user address$rules[] = 'checkout_billing';$billing_address_id = $this->request->post['billing_address_id'];- $addressSql = new User_AddressSQL();- $address = $addressSql->get($this->global + ['user_address_id' => $billing_address_id]);+ $addressSQL = new User_addressSQL();+ $address = $addressSQL->get($this->global + ['user_address_id' => $billing_address_id]);if ($address) {$this->request->post['billing_address'] = $address;- //$this->request->post += prefixArrayKeys('billing_', $address);}}@@ -236,12 +394,11 @@ class Checkout extends Base {if ($hasShipping) {//different shipping address is selected- if (isset($this->request->post['different_shipping_address']) && ! empty($this->request->post['different_shipping_address'])) {+ if (isset($this->request->post['different_shipping_address']) && !empty($this->request->post['different_shipping_address'])) {$rules[] = 'checkout_shipping';if (isset($this->request->post['shipping_address'])) {$shipping_address = $this->request->post['shipping_address'];- //$this->request->post += prefixArrayKeys('shipping_', $shipping_address);}} else {//use billing address as shipping address@@ -249,7 +406,6 @@ class Checkout extends Base {if (isset($this->request->post['billing_address'])) {$this->request->post['shipping_address'] = $this->request->post['billing_address'];- //$this->request->post += prefixArrayKeys('shipping_', $this->request->post['shipping_address']);}}}@@ -258,47 +414,84 @@ class Checkout extends Base {$post = $this->request->post;$validator = new Validator($rules);- if (! $hasShipping) {+ if (!$hasShipping) {$validator->removeRule('shipping_method');}- if (! $hasPayment) {+ if (!$hasPayment) {$validator->removeRule('payment_method');}- $checkoutInfo = ($validator->filter($this->request->post) ?? []) + $checkoutInfo;+ $checkoutInfo = $validator->filter($this->request->post) + $checkoutInfo;$this->session->set('checkout', $checkoutInfo);+ //nested address arrays are not validation rules so the filter drops them, preserve them from post+ foreach (['billing_address', 'shipping_address'] as $addressKey) {+ if (isset($this->request->post[$addressKey])) {+ $checkoutInfo[$addressKey] = $this->request->post[$addressKey];+ }+ }+if (($errors = $validator->validate($this->request->post)) === true) {+ //single-use submit token: retried posts (double click, back button)+ //must not create duplicate orders. Only enforced when the theme+ //posts the field, so older themes keep working.+ if (isset($this->request->post['submit_token'])) {+ if (!$this->consumeCheckoutToken((string)$this->request->post['submit_token'])) {+ $placedOrder = $this->session->get('order');++ if (!empty($placedOrder['order_id'])) {+ //duplicate of an already placed order+ $this->redirect('checkout/confirm/index');++ return;+ }++ $this->view->errors[] = __('Invalid checkout session! Please try again.');+ $this->session->set('checkout', $checkoutInfo);+ $this->view->checkout = $checkoutInfo;+ $this->view->submit_token = $this->rotateCheckoutToken();++ return;+ }+ }++ $this->view->submit_token = $this->currentCheckoutToken();$checkoutInfo['products'] = $this->cart->getAll();$checkoutInfo['product_options'] = $this->cart->getProductOptions();$checkoutInfo['totals'] = $this->cart->getAllTotals();+ //recalculate after totals (shipping, payment fees, taxes, coupons)+ //were added, the $grandTotal captured before setMethod() is stale+ $grandTotal = $this->cart->getGrandTotal();$checkoutInfo['total'] = $grandTotal;- $checkoutInfo += prefixArrayKeys('shipping_', $checkoutInfo['shipping_address']);- $checkoutInfo += prefixArrayKeys('billing_', $checkoutInfo['billing_address']);+ //shipping address is only present for orders with shipping, billing address is always validated+ $shippingAddress = $checkoutInfo['shipping_address'] ?? [];+ $billingAddress = $checkoutInfo['billing_address'] ?? [];+ $checkoutInfo += prefixArrayKeys('shipping_', $shippingAddress);+ $checkoutInfo += prefixArrayKeys('billing_', $billingAddress);$checkoutInfo += $this->global;//create user account if password is provided- if (isset($checkoutInfo['password']) && ! $this->global['user_id']) {+ if (isset($checkoutInfo['password']) && !$this->global['user_id']) {$userInfo = [];foreach (['first_name', 'last_name', 'email', 'phone_number', 'password'] as $field) {- $userInfo[$field] = $checkoutInfo[$field] ?? NULL;+ $userInfo[$field] = $checkoutInfo[$field] ?? null;}$userInfo['display_name'] = $userInfo['first_name'] . ' ' . $userInfo['last_name'];- $userInfo['username'] = strtolower(str_replace(' ', '', $userInfo['first_name'] . $userInfo['last_name'])) . '-' . rand();+ $userInfo['username'] = strtolower(str_replace(' ', '', $userInfo['first_name'] . $userInfo['last_name'])) . '-' . random_int(1000, 999999);$result = User::add($userInfo);if ($result) {if (isset($result['user'])) {- $checkoutInfo['user_id'] = $result['user'] ?? NULL;+ $checkoutInfo['user_id'] = $result['user'];$userInfo = User::get(['user_id' => $checkoutInfo['user_id']]);//check if user was added before automatic loginif ($userInfo) {\Vvveb\session(['user' => $userInfo]);- $checkoutInfo['user'] = $userInfo;+ $checkoutInfo['user'] = $userInfo;$this->view->global['user_id'] = $userInfo['user_id'];}} else {@@ -317,17 +510,17 @@ class Checkout extends Base {//if new address add to user accountif (empty($this->request->post['billing_address_id']) && $user_id) {- $addressSql = new User_AddressSQL();- $address = $addressSql->add(['user_address' => $this->request->post['billing_address'] + ['user_id' => $user_id]]);+ $addressSQL = new User_addressSQL();+ $address = $addressSQL->add(['user_address' => $this->request->post['billing_address'] + ['user_id' => $user_id]]);}//if account does not have a phone number set add phone number to user profile for next order- if ($this->global['user_id'] && ! $this->global['user']['phone_number']) {+ if ($this->global['user_id'] && !$this->global['user']['phone_number']) {User::update(['phone_number' => $checkoutInfo['phone_number']], ['user_id' => $this->global['user_id']]);User::session(['phone_number' => $checkoutInfo['phone_number']]);}- if (! $checkoutInfo['user_id']) {+ if (!$checkoutInfo['user_id']) {unset($checkoutInfo['user_id']); //if anonymous then unset user_id}@@ -345,7 +538,7 @@ class Checkout extends Base {//default order status$checkoutInfo['order_status_id'] = 1;- $site = Sites :: getSiteData(SITE_ID);+ $site = Sites::getSiteData(SITE_ID);$order_url = url('user/orders', ['host' => $site['host'] ?? false,@@ -357,7 +550,7 @@ class Checkout extends Base {$this->view->errors = [];- list($checkoutInfo) = Event::trigger(__CLASS__, 'add', $checkoutInfo);+ [$checkoutInfo] = Event::trigger(__CLASS__, 'add', $checkoutInfo);$checkoutInfo = $order->add($checkoutInfo);@@ -369,7 +562,7 @@ class Checkout extends Base {$this->view->messages[] = __('Order placed!');$this->session->set('order', $checkoutInfo);- $site = siteSettings();+ $this->createPendingSubscriptions($order_id, $checkoutInfo);$shippingData = $checkoutInfo['shipping_data'];$paymentData = $checkoutInfo['payment_data'];@@ -377,18 +570,79 @@ class Checkout extends Base {try {if ($hasShipping) {$shippingOk = $shipping->ship($checkoutInfo);++ if ($shippingOk !== true) {+ //shipping failed: don't charge, keep the cart, skip mail and confirmation+ $this->view->errors[] = $shipping->getError() ?: __('Shipping failed! Please try again or choose another shipping method.');+ $this->session->delete('order');+ $this->session->set('checkout', $checkoutInfo);+ $this->view->checkout = $checkoutInfo;+ $this->view->submit_token = $this->currentCheckoutToken();++ return;+ }}if ($hasPayment) {- $paymentOk = $payment->authorize($checkoutInfo);+ //idempotency reference so retried submits don't double-charge+ $checkoutInfo['idempotency_key'] ??= hash('sha256', implode('|', [$order_id, $checkoutInfo['payment_method'] ?? '', number_format((float)($checkoutInfo['total'] ?? 0), 2, '.', ''), $checkoutInfo['currency'] ?? '']));+ $paymentResult = $payment->purchase($checkoutInfo);+ $paymentRedirect = $payment->getRedirectUrl();++ if ($paymentRedirect || (is_array($paymentResult) && ($paymentResult['status'] ?? '') === \Vvveb\System\PaymentMethod::STATUS_REDIRECT)) {+ //off-site gateway: persist payment data and hand control to the gateway+ $paymentRedirect = $paymentRedirect ?: ($paymentResult['redirect'] ?? '');+ $this->session->set('order', $checkoutInfo);++ if (($shippingData !== $checkoutInfo['shipping_data']) || ($paymentData !== $checkoutInfo['payment_data'])) {+ $order->edit(['shipping_data' => $checkoutInfo['shipping_data'], 'payment_data' => $checkoutInfo['payment_data']], $order_id);+ }++ if (preg_match('#^https?://#i', $paymentRedirect)) {+ //absolute gateway URL: url() only handles internal routes+ $this->session->close();+ header("Location: $paymentRedirect");++ exit();+ }++ $this->redirect($paymentRedirect);++ return;+ }++ if ($paymentResult !== true) {+ //failed payment: stay on checkout, keep the cart, skip mail and confirmation+ $this->view->errors[] = $payment->getError() ?: __('Payment failed! Please try again or choose another payment method.');+ $this->session->delete('order');++ if (($shippingData !== $checkoutInfo['shipping_data']) || ($paymentData !== $checkoutInfo['payment_data'])) {+ $order->edit(['shipping_data' => $checkoutInfo['shipping_data'], 'payment_data' => $checkoutInfo['payment_data']], $order_id);+ }++ $this->session->set('checkout', $checkoutInfo);+ $this->view->checkout = $checkoutInfo;+ $this->view->submit_token = $this->currentCheckoutToken();++ return;+ }++ $paymentOk = true;}} catch (\Exception $e) {$this->view->errors[] = $e->getMessage();+ $this->session->delete('order');+ $this->session->set('checkout', $checkoutInfo);+ $this->view->checkout = $checkoutInfo;+ $this->view->submit_token = $this->currentCheckoutToken();++ return;}- list($checkoutInfo, $order_id, $site) = Event::trigger(__CLASS__, 'add:after', $checkoutInfo, $order_id, $site);+ $siteSettings = siteSettings();+ [$checkoutInfo, $order_id, $siteSettings] = Event::trigger(__CLASS__, 'add:after', $checkoutInfo, $order_id, $siteSettings);- if (($shippingData != $checkoutInfo['shipping_data']) || ($paymentData != $checkoutInfo['payment_data'])) {+ if (($shippingData !== $checkoutInfo['shipping_data']) || ($paymentData !== $checkoutInfo['payment_data'])) {$order->edit(['shipping_data' => $checkoutInfo['shipping_data'], 'payment_data' => $checkoutInfo['payment_data']], $order_id);}@@ -396,24 +650,47 @@ class Checkout extends Base {$error = __('Error sending order confirmation mail!');$title = sprintf(__('Order confirmation #%s'), $customer_order_id);- if (! email([$checkoutInfo['email'], $site['admin-email']], $title, 'order/new', $checkoutInfo + ['title' => $title])) {+ \Vvveb\System\Notifications::trigger('order.new', $checkoutInfo + [+ 'subject' => $title,+ 'message' => $title,+ ]);++ if (!email([$checkoutInfo['email'], $siteSettings['admin-email']], $title, 'order/new', $checkoutInfo + ['title' => $title])) {$this->session->set('errors', $error);$this->view->errors[] = $error;}} catch (\Exception $e) {- if (DEBUG) {+ $error = __('Error sending order confirmation mail!');++ if (defined('DEBUG') && DEBUG) {$error .= "\n" . $e->getMessage();}$this->session->set('errors', $error);$this->view->errors[] = $error;}+ // check low stock threshold for each ordered product+ foreach ($checkoutInfo['products'] ?? [] as $product) {+ try {+ if (!empty($product['product_id'])) {+ \Vvveb\System\Notifications::checkLowStock([+ 'product_id' => $product['product_id'],+ 'name' => $product['name'] ?? '',+ 'quantity' => $product['stock_quantity'] ?? $product['quantity'] ?? 0,+ ]);+ }+ } catch (\Throwable $e) {+ }+ }+$this->cart->empty();// clear notifications cache- CacheManager :: clearObjectCache('component', 'notifications');+ CacheManager::clearObjectCache('component', 'notifications');++ $this->redirect('checkout/confirm/index');- return $this->redirect('checkout/confirm/index');+ return;} else {$this->view->errors[] = __('Error creating checkout!');}@@ -425,6 +702,7 @@ class Checkout extends Base {$this->session->set('checkout', $checkoutInfo);}- $this->view->checkout = $checkoutInfo;+ $this->view->checkout = $checkoutInfo;+ $this->view->submit_token = $this->currentCheckoutToken();}}diff --git a/app/controller/checkout/confirm.php b/app/controller/checkout/confirm.phpindex 77bba1c..a6566bb 100755--- a/app/controller/checkout/confirm.php+++ b/app/controller/checkout/confirm.php@@ -25,11 +25,25 @@ namespace Vvveb\Controller\Checkout;use Vvveb\Controller\Base;class Confirm extends Base {- function index() {+ /**+ * Display the order confirmation page after checkout.+ *+ * @return void+ */+ public function index(): void {$order = $this->session->get('order');$this->view->order = $order;- if (! $order) {+ if (!$order) {+ $this->notFound();+ }+ }++ public function failed(): void {+ $order = $this->session->get('order');+ $this->view->order = $order;++ if (!$order) {$this->notFound();}}diff --git a/app/controller/content/archive.php b/app/controller/content/archive.phpindex 918c02a..75927e7 100755--- a/app/controller/content/archive.php+++ b/app/controller/content/archive.php@@ -26,7 +26,12 @@ use Vvveb\Controller\Base;use Vvveb\System\Locale;class Archive extends Base {- function index() {+ /**+ * Display the archive page for the given year and/or month.+ *+ * @return void+ */+ public function index(): void {if (isset($this->request->get['month'])) {$month = $this->request->get['month'];$this->view->month = $month;@@ -36,7 +41,7 @@ class Archive extends Base {if (class_exists('\IntlDateFormatter')) {$dt = new \DateTime();$dt->setDate(0, $month, 0);- $df = new \IntlDateFormatter(Locale::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/category.php b/app/controller/content/category.phpindex 5a3f442..f5d9db8 100755--- a/app/controller/content/category.php+++ b/app/controller/content/category.php@@ -25,31 +25,48 @@ namespace Vvveb\Controller\Content;use function Vvveb\__;use Vvveb\Controller\Base;use Vvveb\Sql\CategorySQL;+use Vvveb\System\Event;use Vvveb\System\Images;class Category extends Base {- protected $type = 'category';+ /** @var string Taxonomy type name. */+ protected string $type = 'category';- function index() {+ /** @var string Object type handled by this category. */+ protected string $object = 'post';++ /** @var string Route namespace. */+ protected string $namespace = 'content';++ /** @var string Fully-qualified class name for event dispatching. */+ protected string $class = __CLASS__;++ /**+ * Display posts filtered by category slug.+ *+ * @return void+ */+ public function index(): void {$slug = $this->request->get['slug'] ?? '';- $type = $this->request->get['type'] ?? 'post';+ $type = $this->request->get['type'] ?? $this->object;$this->view->category_name = $slug;if ($slug) {- $categorySql = new CategorySQL();+ $categorySQL = new CategorySQL();$options = $this->global + ['slug' => $slug];if ($type) {$options['post_type'] = $type;}- $category = $categorySql->getCategoryBySlug($options);+ $category = $categorySQL->getCategoryBySlug($options);if ($category) {$this->request->get['category_id'] = $this->request->request['taxonomy_item_id'] = $category['taxonomy_item_id'];$this->request->get['name'] = $category['name'];if (isset($category['image']) && $category['image']) {- $category['image_url'] = Images::image($category['image'], 'product', 'medium');+ $size = [$this->global['site']['category_width'] ?? 150, $this->global['site']['category_height'] ?? 150];+ $category['image_url'] = Images::image($category['image'], 'category', $size, $this->global['site']['category_method'] ?? 'cs');}$category['title'] = $category['name'];@@ -59,19 +76,19 @@ class Category extends Base {$this->request->get['taxonomy_item_id'] = $category['taxonomy_item_id'];$this->request->get['slug'] = $category['slug'];- $this->view->category = $category;- if ($type != 'post') {+ [$category, $type] = Event :: trigger($this->class, __FUNCTION__ . ':after', $category, $type);+ $this->view->category = $category;++ if ($type != $this->object) {//content/category-page.html- $template = 'content/' . $this->type . '-' . $type . '.html';- if ($template) {- $this->view->template($template);- $this->view->tplFile('content/' . $this->type . '.tpl');- }+ $template = $this->namespace . '/' . $this->type . '-' . $type . '.html';+ $this->view->template($template);+ $this->view->tplFile($this->namespace . '/' . $this->type . '.tpl');}} else {$message = sprintf(__('%s not found!'), ucfirst(__($this->type)));- $this->notFound(true, ['message' => $message, 'title' => $message]);+ $this->notFound(['message' => $message, 'title' => $message]);}}}diff --git a/app/controller/content/comment-trait.php b/app/controller/content/comment-trait.phpold mode 100644new mode 100755index 3c4f7ee..bbfa02c--- a/app/controller/content/comment-trait.php+++ b/app/controller/content/comment-trait.php@@ -25,18 +25,27 @@ namespace Vvveb\Controller\Content;use function Vvveb\__;use function Vvveb\model;use function Vvveb\sanitizeHTML;+use function Vvveb\stripChars;use Vvveb\System\CacheManager;use Vvveb\System\Event;trait CommentTrait {- private function insertComment($commentType = 'comment', $commentName = 'comment') {+ /**+ * Insert a comment (or review/question) from the current POST data.+ *+ * @param string $commentType Model name for the comment type (e.g. 'comment', 'product_review').+ * @param string $commentName Human-readable name used in success/error messages.+ *+ * @return array<string, mixed>|bool Insert result array or false on failure.+ */+ private function insertComment(string $commentType = 'comment', string $commentName = 'comment'): array|bool {$result = false;$post = &$this->request->post;- $commentsOpen = $this->global['site']['default_comment_status'] ?? false;+ $commentsOpen = $this->global['site']['default_comment_status'] ?? false;$anonymousComments = $this->global['site']['anonymous_comments'] ?? false;- if (! $commentsOpen || (! $anonymousComments && ! $this->global['user'])) {+ if (!$commentsOpen || (!$anonymousComments && !$this->global['user'])) {return [];}@@ -47,26 +56,41 @@ trait CommentTrait {isset($post['lastname-empty']) && empty($post['lastname-empty']) &&isset($post['subject-empty']) && empty($post['subject-empty']));- $user = $this->global['user'];+ $user = $this->global['user'] ?? false;if ($user) {- $user['author'] = $user['display_name'];+ $post['author'] = $user['display_name'] ?? '';+ $post['email'] = $user['email'] ?? '';+ }++ //author, content and email are required for the comment to be stored+ foreach (['author', 'content', 'email'] as $field) {+ if (!isset($post[$field]) || trim((string)$post[$field]) === '') {+ $this->view->errors[] = __('Please fill in all required fields!');++ return false;+ }+ }++ //never persist the honeypot fields in the stored data+ foreach (['firstname-empty', 'lastname-empty', 'subject-empty'] as $spamField) {+ unset($post[$spamField]);}//sanitize html and inline js code$post['content'] = sanitizeHTML($post['content']);$post['author'] = sanitizeHTML(stripChars($post['author']));- $comment = array_merge($post, $user, [+ $commentData = array_merge($post, is_array($user) ? $user : [], ['created_at' => date('Y-m-d H:i:s'),'status' => 0,'notSpam' => $notSpam,'commentType' => $commentType,'commentName' => $commentName,- 'user_id' => $user['user_id'] ?? false,+ 'user_id' => is_array($user) ? ($user['user_id'] ?? false) : false,]);- list($comment) = Event :: trigger(__CLASS__, __FUNCTION__ , $comment);+ [$comment] = Event::trigger(__CLASS__, __FUNCTION__, $commentData);if ($comment && $comment['notSpam']) {//$sql = new \Vvveb\Sql\CommentSQL();@@ -76,16 +100,17 @@ trait CommentTrait {if ($result[$commentType]) {$comment["{$commentType}_id"] = $result[$commentType];- $comments = $this->session->get('comments', []);- $comments[$comment['slug']][$comment["{$commentType}_id"]] = $comment;+ $slug = $comment['slug'] ?? '';+ $comments = $this->session->get($commentType) ?? [];+ $comments[$slug][$comment["{$commentType}_id"]] = $comment;$this->session->set($commentType, $comments);// clear notifications cache- CacheManager :: clearObjectCache('component', 'notifications');+ CacheManager::clearObjectCache('component', 'notifications');$this->view->success[] = ucfirst($commentName) . __(' was posted!');} else {- $this->view->errors[] = sprintf(__('Error adding %s!'), $text);+ $this->view->errors[] = sprintf(__('Error adding %s!'), $commentType);}} else {//optional add comment with spam statusdiff --git a/app/controller/content/index.php b/app/controller/content/index.phpindex ec1e0f9..d47d711 100755--- a/app/controller/content/index.php+++ b/app/controller/content/index.php@@ -25,6 +25,10 @@ namespace Vvveb\Controller\Content;use Vvveb\Controller\Base;class Index extends Base {- function index() {- }+ /**+ * Render the content listing page.+ *+ * @return void+ */+ public function index(): void {}}diff --git a/app/controller/content/page.php b/app/controller/content/page.phpindex 2674ea0..e49941c 100755--- a/app/controller/content/page.php+++ b/app/controller/content/page.php@@ -23,5 +23,6 @@namespace Vvveb\Controller\Content;class Page extends Post {- public $type = 'page';+ /** @var string Content type identifier. */+ public string $type = 'page';}diff --git a/app/controller/content/post.php b/app/controller/content/post.phpindex 01b8611..9d6766b 100755--- a/app/controller/content/post.php+++ b/app/controller/content/post.php@@ -22,12 +22,11 @@namespace Vvveb\Controller\Content;-use \Vvveb\Sql\PostSQL;use function Vvveb\__;use Vvveb\Controller\Base;-//use Vvveb\System\Component\Component;use function Vvveb\model;use function Vvveb\postTypes;+use Vvveb\Sql\PostSQL;use Vvveb\System\Core\FrontController;use Vvveb\System\Event;use Vvveb\System\Locale;@@ -35,25 +34,35 @@ use Vvveb\System\User\Admin;use function Vvveb\truncateWords;class Post extends Base {- public $type = 'post';-use CommentTrait;-- function addComment() {- return $this->index();+ /** @var string Content type identifier. */+ public string $type = 'post';++ /**+ * Alias for index() — handles comment submission for a post.+ *+ * @return void+ */+ public function addComment(): void {+ $this->index();}- function index() {+ /**+ * Display a single post or page by ID or slug.+ *+ * @return void+ */+ public function index(): void {if (isset($this->request->post['content'])) {$result = $this->insertComment();}- $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- $content = [];+ $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+ $content = [];$languageContent = [];//check for custom post or product@@ -61,29 +70,29 @@ class Post extends Base {$class = '';$postTypes = postTypes('post');- if (isset($postTypes[$type])) {- } else {+ if (!isset($postTypes[$type])) {$postTypes = postTypes('product');if (isset($postTypes[$type])) {$class = 'Product';FrontController::redirect($class, 'index');- die();+ exit();} else {$error = sprintf(__('%s not found!'), ucfirst(__($this->type)));- return $this->notFound(true, ['message' => $error, 'title' => $error]);+ $this->notFound(['message' => $error, 'title' => $error]);}}}if ($post_id || $slug) {- $contentSql = new PostSQL();- $options = $this->global + ['post_id' => $post_id, 'slug' => $slug, 'type' => $type ?? $this->type];- $content = $contentSql->getContent($options) ?? [];+ $contentSQL = new PostSQL();++ $options = $this->global + ['post_id' => $post_id, 'slug' => $slug, 'type' => $type ?? $this->type, 'status' => 'publish'];+ $content = $contentSQL->getContent($options) ?? [];$class = __NAMESPACE__ . '\\' . ucfirst($this->type); //__CLASS__ is always Post- list($content, $language, $slug) = Event :: trigger($class,__FUNCTION__, $content, $language, $slug);+ [$content, $language, $slug] = Event::trigger($class, __FUNCTION__, $content, $language, $slug);if ($content) {if (isset($content[$language])) {@@ -98,7 +107,7 @@ class Post extends Base {if ($languageContent) {if ($this->global['language'] != $languageContent['code']) {- Locale :: setLanguage($languageContent['code']);+ Locale::setLanguage($languageContent['code']);}$this->global['language'] = $languageContent['code'];@@ -131,13 +140,13 @@ class Post extends Base {}if (isset($languageContent['template']) && $languageContent['template']) {- $this->view->template($languageContent['template']);+ $this->view->template($languageContent['template'], "content/{$this->type}.html");//force post template if a different html template is selected$this->view->tplFile("content/{$this->type}.tpl");}} else {$error = sprintf(__('%s not found!'), ucfirst(__($this->type)));- return $this->notFound(true, ['message' => $error, 'title' => $error]);+ $this->notFound(['message' => $error, 'title' => $error]);}$languageContent['title'] = $languageContent['name'];@@ -160,11 +169,11 @@ class Post extends Base {$languageContent['meta_description'] = truncateWords($languageContent['meta_description'], 160);}} else {- $excerpt = ($languageContent['excerpt'] ?? '') ?: $languageContent['content'];+ $excerpt = ($languageContent['excerpt'] ?? '') ?: $languageContent['content'];$languageContent['meta_description'] = truncateWords(strip_tags($excerpt), 160);}- list($content, $languageContent, $language, $slug) = Event :: trigger($class, __FUNCTION__ . ':after', $content, $languageContent, $language, $slug);+ [$content, $languageContent, $language, $slug] = Event::trigger($class, __FUNCTION__ . ':after', $content, $languageContent, $language, $slug);} else {//check for custom post or product$class = '';@@ -184,17 +193,17 @@ class Post extends Base {$this->request->get['type'] = $slug;FrontController::redirect($class, 'index');- die();+ exit();} else {$error = sprintf(__('%s not found!'), ucfirst(__($this->type)));- return $this->notFound(true, ['message' => $error, 'title' => $error]);+ $this->notFound(['message' => $error, 'title' => $error]);}}}- $this->view->post = $languageContent;- $this->view->content = $content;+ $this->view->post = $languageContent;+ $this->view->content = $content;$this->view->default_comment_status = $this->global['site']['default_comment_status'] ?? false;- $this->view->anonymous_comments = $this->global['site']['anonymous_comments'] ?? false;+ $this->view->anonymous_comments = $this->global['site']['anonymous_comments'] ?? false;}}diff --git a/app/controller/content/tag.php b/app/controller/content/tag.phpindex 080bf4c..ab74f6f 100755--- a/app/controller/content/tag.php+++ b/app/controller/content/tag.php@@ -23,5 +23,6 @@namespace Vvveb\Controller\Content;class Tag extends Category {- protected $type = 'tag';+ /** @var string Taxonomy type name. */+ protected string $type = 'tag';}diff --git a/app/controller/content/user.php b/app/controller/content/user.phpold mode 100755new mode 100644index b51ea0c..0c298d3--- a/app/controller/content/user.php+++ b/app/controller/content/user.php@@ -27,7 +27,12 @@ use Vvveb\Controller\Base;use Vvveb\System\User\Admin;class User extends Base {- function index() {+ /**+ * Display the author profile for the given admin_id or username.+ *+ * @return void+ */+ public function index(): void {$admin_id = $this->request->get['admin_id'] ?? '';$username = $this->request->get['username'] ?? '';@@ -40,7 +45,7 @@ class User extends Base {} else {$error = sprintf(__('%s not found!'), ucfirst(__('user')));- return $this->notFound(true, ['message' => $error, 'title' => $error]);+ $this->notFound(['message' => $error, 'title' => $error]);}}}diff --git a/app/controller/cron.php b/app/controller/cron.phpold mode 100755new mode 100644index 48bf813..30404e8--- a/app/controller/cron.php+++ b/app/controller/cron.php@@ -22,19 +22,29 @@namespace Vvveb\Controller;+use Vvveb\System\Core\Request;++/**+ * Cron job controller — invoked via HTTP with a secret key or from CLI.+ */#[\AllowDynamicProperties]class Cron {- function _construct() {- }+ /** @var Request Request instance injected by FrontController DI. */+ public Request $request;- function index() {- if (defined('CLI')) {- } else {- $key = $this->request->get['key'];+ /**+ * Entry point for cron execution. Validates the cron key for HTTP requests+ * then runs all registered cron jobs.+ *+ * @return void+ */+ public function index(): void {+ if (!defined('CLI')) {+ $key = $this->request->get['key'] ?? '';$cronkey = \Vvveb\getConfig('app.cronkey');if ($key != $cronkey) {- die('Invalid key!');+ exit('Invalid key!');}}@@ -47,20 +57,21 @@ class Cron {litespeed_finish_request();}- if (! empty($this->request->post) || defined('CLI')) {- die();- }+ $results = \Vvveb\System\Cron::runAll();- die();- }+ //single background-queue pass for hosts without a persistent worker+ try {+ $results['queue'] = \Vvveb\System\Queue::cronPass();+ } catch (\Throwable $e) {+ \Vvveb\logError('[Queue] Cron pass failed: ' . $e->getMessage());+ }- function call() {- $cronkey = \Vvveb\getConfig('app.cronkey');+ if (defined('CLI')) {+ foreach ($results as $name => $result) {+ echo $name . ': ' . json_encode($result) . "\n";+ }+ }- $options = [- 'timeout' => 0.01,- 'blocking' => false,- 'sslverify' => false,- ];+ exit();}}diff --git a/app/controller/error404.php b/app/controller/error404.phpindex 1b3df36..4b9ed5d 100755--- a/app/controller/error404.php+++ b/app/controller/error404.php@@ -22,8 +22,29 @@namespace Vvveb\Controller;+/**+ * 404 error page controller.+ *+ * Does not extend Base — instantiated standalone by FrontController::notFound().+ */#[\AllowDynamicProperties]-class Error404 extends Base {- function index() {+class Error404 {// extends Base+ /** @var array<string, mixed> */+ public array $global = [];++ /**+ * Get the global template variables (unused — kept for interface compatibility).+ *+ * @return array<string, mixed>+ */+ public function getGlobal(): array {+ return $this->global;}++ /**+ * Render the 404 error page.+ *+ * @return void+ */+ public function index(): void {}}diff --git a/app/controller/error500.php b/app/controller/error500.phpindex 74daa21..5bc6675 100755--- a/app/controller/error500.php+++ b/app/controller/error500.php@@ -22,11 +22,29 @@namespace Vvveb\Controller;+/**+ * 500 error page controller.+ *+ * Does not extend Base — instantiated standalone by FrontController::notFound().+ */#[\AllowDynamicProperties]-class Error500 {/* extends Base */- function getGlobal() {- }+class Error500 {// extends Base+ /** @var array<string, mixed> */+ public array $global = [];- function index() {+ /**+ * Get the global template variables (unused — kept for interface compatibility).+ *+ * @return array<string, mixed>+ */+ public function getGlobal(): array {+ return $this->global;}++ /**+ * Render the 500 error page.+ *+ * @return void+ */+ public function index(): void {}}diff --git a/app/controller/feed/index.php b/app/controller/feed/index.phpindex 1f40f43..4daa7df 100755--- a/app/controller/feed/index.php+++ b/app/controller/feed/index.php@@ -22,11 +22,16 @@namespace Vvveb\Controller\Feed;-use \Vvveb\Controller\Base;+use Vvveb\Controller\Base;use Vvveb\System\Functions\Str;class Index extends Base {- function index() {+ /**+ * Serve RSS or XML feed files from the theme directory.+ *+ * @return string|null Template path when an RSS feed is found.+ */+ public function index(): ?string {$rss = $this->request->get['rss'] ?? false;if ($rss) {@@ -48,7 +53,9 @@ class Index extends Base {}}- $this->notFound(true);+ $this->notFound();}++ return null;}}diff --git a/app/controller/checkout/order.php b/app/controller/feed/llms.phpold mode 100755new mode 100644similarity index 52%rename from app/controller/checkout/order.phprename to app/controller/feed/llms.phpindex 5aa2909..c3cd46a--- a/app/controller/checkout/order.php+++ b/app/controller/feed/llms.php@@ -17,19 +17,36 @@** 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\Checkout;+namespace Vvveb\Controller\Feed;use Vvveb\Controller\Base;-class Order extends Base {- function index() {- $order = $this->session->get('order');+class Llms extends Base {+ /**+ * Output the vllms.html file with absolute sitemap URLs.+ *+ * @return void+ */+ public function index(): void {+ $text = '';+ $robots = DIR_PUBLIC . 'vllms.html';- if (! $order) {- $this->notFound();+ if (file_exists($robots)) {+ $text = @file_get_contents($robots);}++ $path = V_SUBDIR_INSTALL . ($this->global['path'] ?: '');+ $host = 'https://' . ($_SERVER['HTTP_HOST'] ?? '') . $path;++ // change sitemap urls to absolute+ if ($path) {+ $text = preg_replace('@(sitemap):\s+/@', "$1: {$host}/", $text);+ $text = preg_replace('@(disallow):\s+/@', "$1: {$path}/", $text);+ }++ $this->response->setType('text');+ $this->response->output($text);}}diff --git a/app/controller/feed/manifest.php b/app/controller/feed/manifest.phpindex 0c2d211..09f3931 100755--- a/app/controller/feed/manifest.php+++ b/app/controller/feed/manifest.php@@ -22,14 +22,19 @@namespace Vvveb\Controller\Feed;-use \Vvveb\Controller\Base;-use \Vvveb\System\Images;+use Vvveb\Controller\Base;use function Vvveb\siteSettings;+use Vvveb\System\Images;use function Vvveb\url;#[\AllowDynamicProperties]class Manifest extends Base {- function index() {+ /**+ * Output the PWA manifest as JSON.+ *+ * @return void+ */+ public function index(): void {$site = siteSettings();$description = $site['description'][$this->global['language_id']] ?? [];@@ -37,7 +42,6 @@ class Manifest extends Base {$logo = Images::image($site['logo-src'], 'logo', [144, 144]);$logo192 = Images::image($site['logo-src'], 'logo', [192, 192]);$logo512 = Images::image($site['logo-src'], 'logo', [512, 512]);- $logo192 = Images::image($site['logo-src'], 'logo', [144, 144]);$webbanner = Images::image($site['webbanner-src'], 'webbanner', [540, 720]);$webbanner1280 = Images::image($site['webbanner-src'], 'webbanner', [1280, 920]);@@ -58,12 +62,12 @@ class Manifest extends Base {'sizes' => '144x144',],1 => [- 'src' => $logo512,+ 'src' => $logo192,'type' => 'image/png','sizes' => '192x192',],2 => [- 'src' => $logo192,+ 'src' => $logo512,'type' => 'image/png','sizes' => '512x512',],@@ -73,9 +77,9 @@ class Manifest extends Base {'background_color' => '#3367D6','display' => 'standalone',//'orientation' => 'landscape',- 'scope' => '/',- 'theme_color' => '#3367D6',- 'shortcuts' => [+ 'scope' => '/',+ 'theme_color' => '#3367D6',+ 'shortcuts' => [0 => ['name' => $description['description'] ?? '','short_name' => $description['title'] ?? '',diff --git a/app/controller/feed/robots.php b/app/controller/feed/robots.phpindex 571911f..8b03e61 100644--- a/app/controller/feed/robots.php+++ b/app/controller/feed/robots.php@@ -25,7 +25,12 @@ namespace Vvveb\Controller\Feed;use Vvveb\Controller\Base;class Robots extends Base {- function index() {+ /**+ * Output the vrobots.txt file with absolute sitemap URLs.+ *+ * @return void+ */+ public function index(): void {$text = '';$robots = DIR_PUBLIC . 'vrobots.txt';@@ -33,7 +38,7 @@ class Robots extends Base {$text = @file_get_contents($robots);}- $path = (V_SUBDIR_INSTALL ? V_SUBDIR_INSTALL : '') . ($this->global['path'] ? $this->global['path'] : '');+ $path = V_SUBDIR_INSTALL . ($this->global['path'] ?: '');$host = 'https://' . ($_SERVER['HTTP_HOST'] ?? '') . $path;// change sitemap urls to absolutediff --git a/app/controller/index.php b/app/controller/index.phpindex df0caaa..ff78c8d 100755--- a/app/controller/index.php+++ b/app/controller/index.php@@ -29,12 +29,14 @@ class Index extends Base {/*** Homepage.*+ * @return void*/- function index() {- $site = Sites :: getSiteData(SITE_ID);+ public function index(): void {+ $site = Sites::getSiteData(SITE_ID);- if (isset($site['template']) && is_array($site['template'])) {+ if (isset($site['template']) && is_array($site['template']) && $site['state'] === 'live') {$lang = $this->global['language_id'];+if (isset($site['template'][$lang])) {$template = $site['template'][$lang];} else {diff --git a/app/controller/mail/order.php b/app/controller/mail/order.phpindex fe0dc23..44e02ae 100755--- a/app/controller/mail/order.php+++ b/app/controller/mail/order.php@@ -25,6 +25,10 @@ namespace Vvveb\Controller\Mail;use Vvveb\Controller\Base;class Order extends Base {- function index() {- }+ /**+ * Render the order mail template.+ *+ * @return void+ */+ public function index(): void {}}diff --git a/app/controller/mail/user.php b/app/controller/mail/user.phpindex 112bbfa..a89d2f4 100755--- a/app/controller/mail/user.php+++ b/app/controller/mail/user.php@@ -25,6 +25,10 @@ namespace Vvveb\Controller\Mail;use Vvveb\Controller\Base;class User extends Base {- function index() {- }+ /**+ * Render the user mail template.+ *+ * @return void+ */+ public function index(): void {}}diff --git a/app/controller/product/category.php b/app/controller/product/category.phpindex a279841..d13a9d7 100755--- a/app/controller/product/category.php+++ b/app/controller/product/category.php@@ -22,57 +22,18 @@namespace Vvveb\Controller\Product;-use \Vvveb\Sql\CategorySQL;-use function Vvveb\__;-use Vvveb\Controller\Base;-use Vvveb\System\Images;+use Vvveb\Controller\Content\Category as Base;class Category extends Base {- protected $type = 'category';+ /** @var string Taxonomy type name. */+ protected string $type = 'category';- function index() {- $slug = $this->request->get['slug'] ?? '';- $type = $this->request->get['type'] ?? 'product';- $this->view->category_name = $slug;+ /** @var string Object type handled by this category. */+ protected string $object = 'product';- if ($slug) {- $categorySql = new CategorySQL();- $options = $this->global + ['slug' => $slug];- if ($type) {- $options['post_type'] = $type;- }+ /** @var string Route namespace. */+ protected string $namespace = 'product';- $category = $categorySql->getCategoryBySlug($options);-- if ($category) {- $this->request->get['category_id'] = $this->request->request['taxonomy_item_id'] = $category['taxonomy_item_id'];- $this->request->get['name'] = $category['name'];-- if (isset($category['image']) && $category['image']) {- $category['image_url'] = Images::image($category['image'], 'product', 'medium');- }-- $category['title'] = $category['name'];- if (isset($this->global['site']['description']['title'])) {- $category['title'] = $category['title'] . ' - ' . $this->global['site']['description']['title'];- }-- $this->request->get['taxonomy_item_id'] = $category['taxonomy_item_id'];- $this->request->get['slug'] = $category['slug'];- $this->view->category = $category;-- if ($type != 'product') {- //product/category-page.html- $template = 'product/' . $this->type . '-' . $type . '.html';- if ($template) {- $this->view->template($template);- $this->view->tplFile('product/' . $this->type . '.tpl');- }- }- } else {- $message = sprintf(__('%s not found!'), ucfirst(__($this->type)));- $this->notFound(true, ['message' => $message, 'title' => $message]);- }- }- }+ /** @var string Fully-qualified class name for event dispatching. */+ protected string $class = __CLASS__;}diff --git a/app/controller/product/index.php b/app/controller/product/index.phpindex 9d0670d..3c9f579 100755--- a/app/controller/product/index.php+++ b/app/controller/product/index.php@@ -26,9 +26,14 @@ use Vvveb\Controller\Base;use Vvveb\System\Core\View;class Index extends Base {- function index() {- $view = View::getInstance();- $view->order_by = $this->request->get['order_by'] ?? false;+ /**+ * Display the product listing with optional sorting.+ *+ * @return void+ */+ public function index(): void {+ $view = View::getInstance();+ $view->order_by = $this->request->get['order_by'] ?? false;$view->direction = $this->request->get['direction'] ?? false;}}diff --git a/app/controller/product/manufacturer.php b/app/controller/product/manufacturer.phpindex 597924c..c85cc3d 100755--- a/app/controller/product/manufacturer.php+++ b/app/controller/product/manufacturer.php@@ -22,20 +22,25 @@namespace Vvveb\Controller\Product;-use \Vvveb\Sql\ManufacturerSQL;use function Vvveb\__;use Vvveb\Controller\Base;+use Vvveb\Sql\ManufacturerSQL;use Vvveb\System\Images;class Manufacturer extends Base {- function index() {+ /**+ * Display the manufacturer page with their products.+ *+ * @return void+ */+ public function index(): void {$slug = $this->request->get['slug'] ?? '';$this->view->manufacturer_name = $slug;if ($slug) {- $manufacturerSql = new ManufacturerSQL();+ $manufacturerSQL = new ManufacturerSQL();$options = $this->global + ['slug' => $slug];- $manufacturer = $manufacturerSql->get($options);+ $manufacturer = $manufacturerSQL->get($options);if ($manufacturer) {$this->request->get['name'] = $manufacturer['name'];@@ -44,7 +49,6 @@ class Manufacturer extends Base {$manufacturer['image_url'] = Images::image($manufacturer['image'], 'manufacturer');}-$manufacturer['title'] = $manufacturer['name'];if (isset($this->global['site']['description']['title'])) {$manufacturer['title'] = $manufacturer['title'] . ' - ' . $this->global['site']['description']['title'];@@ -55,7 +59,7 @@ class Manufacturer extends Base {$this->view->manufacturer_name = $manufacturer['name'];} else {$message = __('Manufacturer not found!');- $this->notFound(true, $message);+ $this->notFound($message);}}}diff --git a/app/controller/product/product.php b/app/controller/product/product.phpindex 4db9325..a4c2bd6 100755--- a/app/controller/product/product.php+++ b/app/controller/product/product.php@@ -22,12 +22,12 @@namespace Vvveb\Controller\Product;-use \Vvveb\Sql\ProductSQL;use function Vvveb\__;use Vvveb\Controller\Base;use Vvveb\Controller\Content\CommentTrait;use function Vvveb\model;use function Vvveb\postTypes;+use Vvveb\Sql\ProductSQL;use Vvveb\System\Core\FrontController;use Vvveb\System\Event;use Vvveb\System\Locale;@@ -35,19 +35,34 @@ use Vvveb\System\User\Admin;use function Vvveb\truncateWords;class Product extends Base {- public $type = 'product';-use CommentTrait;-- function addReview() {- return $this->index();+ /** @var string Content type identifier. */+ public string $type = 'product';++ /**+ * Handles review submission.+ *+ * @return void+ */+ public function addReview(): void {+ $this->index();}- function addQuestion() {- return $this->index();+ /**+ * Handles question submission.+ *+ * @return void+ */+ public function addQuestion(): void {+ $this->index();}- function index() {+ /**+ * Display a single product by ID or slug.+ *+ * @return void+ */+ public function index(): void {if (isset($this->request->post['content'])) {if (isset($this->request->post['rating'])) {$result = $this->insertComment('product_review', __('review'));@@ -56,12 +71,12 @@ 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- $content = [];+ $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+ $content = [];$languageContent = [];//check for custom post or product@@ -69,29 +84,28 @@ class Product extends Base {$class = '';$postTypes = postTypes('product');- if (isset($postTypes[$type])) {- } else {+ if (!isset($postTypes[$type])) {$postTypes = postTypes('post');if (isset($postTypes[$type])) {$class = 'Content';FrontController::redirect($class, 'index');- die();+ exit();} else {$error = sprintf(__('%s not found!'), ucfirst(__($this->type)));- return $this->notFound(true, ['message' => $error, 'title' => $error]);+ $this->notFound(['message' => $error, 'title' => $error]);}}}if ($product_id || $slug) {- $contentSql = new ProductSQL();- $options = $this->global + ['product_id' => $product_id, 'slug' => $slug, 'type' => $type ?? $this->type, 'status' => 1];- $content = $contentSql->getContent($options);+ $contentSQL = new ProductSQL();+ $options = $this->global + ['product_id' => $product_id, 'slug' => $slug, 'type' => $type ?: $this->type, 'status' => 1];+ $content = $contentSQL->getContent($options);$class = __NAMESPACE__ . '\\' . ucfirst($this->type); //__CLASS__ is always Product- list($content, $language, $slug) = Event :: trigger($class,__FUNCTION__, $content, $language, $slug);+ [$content, $language, $slug] = Event::trigger($class, __FUNCTION__, $content, $language, $slug);if ($content) {if (isset($content[$language])) {@@ -106,7 +120,7 @@ class Product extends Base {if ($languageContent) {if ($this->global['language'] != $languageContent['code']) {- Locale :: setLanguage($languageContent['code']);+ Locale::setLanguage($languageContent['code']);}$this->global['language'] = $languageContent['code'];@@ -145,7 +159,7 @@ class Product extends Base {}} else {$error = sprintf(__('%s not found!'), ucfirst(__($this->type)));- return $this->notFound(true, ['message' => $error, 'title' => $error]);+ $this->notFound(['message' => $error, 'title' => $error]);}$languageContent['title'] = $languageContent['name'];@@ -171,11 +185,11 @@ class Product extends Base {$languageContent['meta_description'] = truncateWords($languageContent['meta_description'], 160);}} else {- $excerpt = ($languageContent['excerpt'] ?? '') ?: $languageContent['content'];+ $excerpt = ($languageContent['excerpt'] ?? '') ?: $languageContent['content'];$languageContent['meta_description'] = truncateWords(strip_tags($excerpt), 160);}- list($content, $languageContent, $language, $slug) = Event :: trigger($class, __FUNCTION__ . ':after', $content, $languageContent, $language, $slug);+ [$content, $languageContent, $language, $slug] = Event::trigger($class, __FUNCTION__ . ':after', $content, $languageContent, $language, $slug);} else {//check for custom post or product$class = '';@@ -195,10 +209,10 @@ class Product extends Base {$this->request->get['type'] = $slug;FrontController::redirect($class, 'index');- die();+ exit();} else {$error = sprintf(__('%s not found!'), ucfirst(__($this->type)));- return $this->notFound(true, ['message' => $error, 'title' => $error]);+ $this->notFound(['message' => $error, 'title' => $error]);}}diff --git a/app/controller/product/tag.php b/app/controller/product/tag.phpindex 2d84532..c71e6f7 100644--- a/app/controller/product/tag.php+++ b/app/controller/product/tag.php@@ -22,6 +22,10 @@namespace Vvveb\Controller\Product;+/**+ * Product tag listing controller — extends category with type 'tag'.+ */class Tag extends Category {- protected $type = 'tag';+ /** @var string Taxonomy type name. */+ protected string $type = 'tag';}diff --git a/app/controller/product/vendor.php b/app/controller/product/vendor.phpold mode 100644new mode 100755index 5efca4a..17fec93--- a/app/controller/product/vendor.php+++ b/app/controller/product/vendor.php@@ -22,20 +22,25 @@namespace Vvveb\Controller\Product;-use \Vvveb\Sql\VendorSQL;use function Vvveb\__;use Vvveb\Controller\Base;+use Vvveb\Sql\VendorSQL;use Vvveb\System\Images;class Vendor extends Base {- function index() {+ /**+ * Display the vendor page with their products.+ *+ * @return void+ */+ public function index(): void {$slug = $this->request->get['slug'] ?? '';$this->view->vendor_name = $slug;if ($slug) {- $vendorSql = new VendorSQL();+ $vendorSQL = new VendorSQL();$options = $this->global + ['slug' => $slug];- $vendor = $vendorSql->get($options);+ $vendor = $vendorSQL->get($options);if ($vendor) {$this->request->get['name'] = $vendor['name'];@@ -52,7 +57,7 @@ class Vendor extends Base {$this->view->vendor = $vendor;} else {$message = __('Vendor not found!');- $this->notFound(true, $message);+ $this->notFound($message);}}}diff --git a/app/controller/search/index.php b/app/controller/search/index.phpindex 3a4a756..d2cfe94 100755--- a/app/controller/search/index.php+++ b/app/controller/search/index.php@@ -25,7 +25,12 @@ namespace Vvveb\Controller\Search;use Vvveb\Controller\Base;class Index extends Base {- function index() {+ /**+ * Display search results.+ *+ * @return void+ */+ public function index(): void {$search = $this->request->get['search'] ?? '';$type = $this->request->get['type'] ?? '';@@ -33,6 +38,10 @@ class Index extends Base {$this->view->type = $type;}- function autocomplete() {- }+ /**+ * Autocomplete endpoint (currently a stub).+ *+ * @return void+ */+ public function autocomplete(): void {}}diff --git a/app/controller/user/address.php b/app/controller/user/address.phpindex 1262974..1431da9 100644--- a/app/controller/user/address.php+++ b/app/controller/user/address.php@@ -24,45 +24,56 @@ namespace Vvveb\Controller\User;use function Vvveb\__;use Vvveb\Sql\CountrySQL;-use Vvveb\Sql\User_AddressSQL;+use Vvveb\Sql\User_addressSQL;use function Vvveb\url;class Address extends Base {- function index() {- }-- private function save() {- }-- private function data() {+ /**+ * Display the address listing page.+ *+ * @return void+ */+ public function index(): void {}++ /**+ * Load shared data for the address forms (countries, regions).+ *+ * @return void+ */+ private function data(): void {$countryModel = new CountrySQL();$options = $this->global;$options['status'] = 1;unset($options['limit']);-- $country = $countryModel->getAll($options);- $this->view->countries = $country['country'] ?? [];-+$country = $countryModel->getAll($options);- $this->view->regions = $country['country'] ?? [];+ $this->view->countries = $country['country'] ?? [];++ $regionModel = new \Vvveb\Sql\RegionSQL();+ $regions = $regionModel->getAll($options);+ $this->view->regions = $regions['region'] ?? [];$this->view->regionsUrl = url(['module' => 'checkout/checkout', 'action' => 'regions']);}- function delete() {+ /**+ * Delete a saved address.+ *+ * @return void+ */+ public function delete(): void {$user_address_id = $this->request->get['user_address_id'] ?? false;- $user_address = [];- $addressModel = new User_AddressSQL();+ $addressModel = new User_addressSQL();if ($user_address_id) {if (is_numeric($user_address_id)) {$user_address_id = [$user_address_id];}-+$options = ['user_address_id' => $user_address_id, 'user_id' => $this->global['user_id']];$result = $addressModel->delete($options);-- if (! $result) {++ if (!$result) {$this->view->errors = [$addressModel->error];} else {$message = __('Address deleted!');@@ -70,18 +81,23 @@ class Address extends Base {}}}-- function edit() {++ /**+ * Edit an existing address or add a new one.+ *+ * @return void+ */+ public function edit(): void {$user_address_id = $this->request->get['user_address_id'] ?? false;$user_address = [];- $addressModel = new User_AddressSQL();+ $addressModel = new User_addressSQL();if ($user_address_id) {$options = ['user_address_id' => $user_address_id, 'user_id' => $this->global['user_id']];$user_address = $addressModel->get($options);- if (! $user_address) {+ if (!$user_address) {$this->notFound();}}@@ -98,7 +114,7 @@ class Address extends Base {$result = $addressModel->add($options);}- if (! $result) {+ if (!$result) {$this->view->errors = [$addressModel->error];} else {$message = __('Address saved!');diff --git a/app/controller/user/base.php b/app/controller/user/base.phpindex 7938a7a..f13083f 100755--- a/app/controller/user/base.php+++ b/app/controller/user/base.php@@ -23,16 +23,21 @@namespace Vvveb\Controller\User;use function Vvveb\session as sess;+use Vvveb\System\User\User;#[\AllowDynamicProperties]class Base extends \Vvveb\Controller\Base {- function __construct() {+ /**+ * Check login status on construction; redirect to login if not authenticated.+ *+ * @return void+ */+ public function __construct() {$user = sess('user');- if (! $user) {+ if (!$user) {$this->redirect('/user/login');-- die(0);+ exit();}if (isset($this->request->post['logout'])) {diff --git a/app/controller/user/comments.php b/app/controller/user/comments.phpold mode 100755new mode 100644index 38ff708..b9e3ead--- a/app/controller/user/comments.php+++ b/app/controller/user/comments.php@@ -23,6 +23,10 @@namespace Vvveb\Controller\User;class Comments extends Base {- function index() {- }+ /**+ * Display the user's comments.+ *+ * @return void+ */+ public function index(): void {}}diff --git a/app/controller/user/downloads.php b/app/controller/user/downloads.phpold mode 100755new mode 100644index ccc2e0b..b4d8238--- a/app/controller/user/downloads.php+++ b/app/controller/user/downloads.php@@ -28,28 +28,38 @@ use Vvveb\Sql\Digital_asset_logSQL;use Vvveb\Sql\Digital_assetSQL;class Downloads extends Base {- function index() {- }+ /**+ * Display the downloads listing page.+ *+ * @return void+ */+ public function index(): void {}- function download() {+ /**+ * Serve a digital asset file for download after verifying access.+ *+ * @return never+ */+ public function download(): never {$public = $this->request->get['public'] ?? false;$digital_asset_id = $this->request->get['digital_asset_id'] ?? false;$userKey = $this->request->get['key'] ?? false;$customerOrderId = $this->request->get['customer_order_id'] ?? false;$key = getConfig('app.key');- if ($digital_asset_id && $public && ($key == $userKey)) {+ if ($digital_asset_id && $public && ($key === $userKey)) {$digital_asset = new Digital_assetSQL();$results = $digital_asset->get(- [- 'digital_asset_id' => $digital_asset_id,- 'language_id' => $this->global['language_id'],- 'user_id' => $this->global['user_id'],- 'order_status_id' => 4,- ]);+ [+ 'digital_asset_id' => $digital_asset_id,+ 'language_id' => $this->global['language_id'],+ 'user_id' => $this->global['user_id'],+ 'order_status_id' => 4,+ ]+ );- if ($results && isset($results['file']) && ($customerOrderId == $results['customer_order_id'])) {+ if ($results && isset($results['file']) && ($customerOrderId === $results['customer_order_id'])) {$digital_asset_log = new Digital_asset_logSQL();$digital_asset_log->add(['digital_asset_log' => [@@ -64,6 +74,10 @@ class Downloads extends Base {$public = $results['public'];$file = DIR_STORAGE . 'digital_assets' . DS . $filename;+ if (!file_exists($file)) {+ exit(__('File not found!'));+ }+header('Content-Description: File Transfer');header('Content-Type: application/octet-stream');header('Content-Disposition: attachment; filename="' . $public . '"');@@ -74,12 +88,12 @@ class Downloads extends Base {readfile($file);} else {- die(__('Invalid download!'));+ exit(__('Invalid download!'));}} else {- die(__('Invalid download!'));+ exit(__('Invalid download!'));}- die(0);+ exit();}}diff --git a/app/controller/user/index.php b/app/controller/user/index.phpindex bd47720..498b924 100755--- a/app/controller/user/index.php+++ b/app/controller/user/index.php@@ -25,7 +25,12 @@ namespace Vvveb\Controller\User;use Vvveb\System\User\User;class Index extends Base {- function index() {+ /**+ * Display the user dashboard, redirect to login if not authenticated.+ *+ * @return void+ */+ public function index(): void {$user = User::current();$message = $this->session->get('message');@@ -34,7 +39,7 @@ class Index extends Base {$this->view->messages[] = $message;}- if (! $user) {+ if (!$user) {$this->redirect('/user/login');}}diff --git a/app/controller/user/login-trait.php b/app/controller/user/login-trait.phpindex 0d47d77..d0d5261 100755--- a/app/controller/user/login-trait.php+++ b/app/controller/user/login-trait.php@@ -22,27 +22,36 @@namespace Vvveb\Controller\User;-use \Vvveb\System\Functions\Str;use function Vvveb\__;-use Vvveb\Sql\User_Failed_LoginSQL;+use Vvveb\Sql\User_failed_loginSQL;use Vvveb\System\Event;+use Vvveb\System\Functions\Str;use Vvveb\System\User\User;use Vvveb\System\Validator;trait LoginTrait {- protected $redirectUrl;+ /** @var string|null URL to redirect to after successful login. */+ protected ?string $redirectUrl = null;- //failed attemps per minute Y-m-d H:i:00- protected $failedTimeInterval = 'Y-m-d H:00:00'; //failed attemps per hour+ /** @var string Date format string for grouping failed login attempts. */+ protected string $failedTimeInterval = 'Y-m-d H:00:00';- protected $failedCount = 10; //the number of failures before account is locked+ /** @var int Maximum failed login attempts before account lockout. */+ protected int $failedCount = 10;- function login() {+ /**+ * Process login form submission: validate credentials, log failures, authenticate.+ *+ * @return void+ */+ public function login(): void {if (isset($this->request->post['logout'])) {$success = __('Logout successful!');$this->view->success = [$success];- return User::logout();+ User::logout();++ return;}$validator = new Validator(['login']);@@ -51,7 +60,7 @@ trait LoginTrait {if (($errors = $validator->validate($this->request->post)) === true) {$userInfo = $this->request->post;- $failedLogin = new User_Failed_LoginSQL();+ $failedLogin = new User_failed_loginSQL();$date = date($this->failedTimeInterval);$lastIp = $_SERVER['REMOTE_ADDR'] ?? '';$failedAttemps = $failedLogin->get(['updated_at' => $date, 'status' => 1] + $userInfo);@@ -63,27 +72,30 @@ trait LoginTrait {return;}- list($userInfo) = Event :: trigger(__CLASS__, __FUNCTION__ , $userInfo);-- if ($userInfo) {- if ($user = User::login($userInfo)) {- $success = __('Login successful!');- $this->session->set('success', ['login' => $success]);- $this->session->close();- $this->view->success['login'] = $success;- $this->view->global['user_id'] = $user['user_id'];- $this->redirect($this->redirectUrl ?? 'user/index');- } else {- //user not found or wrong password- $this->view->errors['login'] = __('Authentication failed, wrong email or password!');- $this->session->set('csrf', Str::random());- //increment failed attempts- $failedLogin->logFailed(['last_ip' => $lastIp, 'updated_at' => $date] + $userInfo);- }+ [$userInfo] = Event::trigger(__CLASS__, __FUNCTION__, $userInfo);++ if (!$userInfo) {+ //cancelled by event listener+ return;+ }++ if ($user = User::login($userInfo)) {+ $success = __('Login successful!');+ $this->session->set('success', ['login' => $success]);+ $this->session->close();+ $this->view->success['login'] = $success;+ $this->view->global['user_id'] = $user['user_id'];+ $this->redirect($this->redirectUrl ?? 'user/index');} else {- if ($errors !== true) {- $this->view->errors['login'] = $errors;- }+ //user not found or wrong password+ $this->view->errors['login'] = __('Authentication failed, wrong email or password!');+ $this->session->set('csrf', Str::random());+ //increment failed attempts+ $failedLogin->logFailed(['last_ip' => $lastIp, 'updated_at' => $date] + $userInfo);+ }+ } else {+ if ($errors != true) {+ $this->view->errors['login'] = $errors;}}}diff --git a/app/controller/user/login.php b/app/controller/user/login.phpindex 9193826..77df096 100755--- a/app/controller/user/login.php+++ b/app/controller/user/login.php@@ -28,11 +28,18 @@ use Vvveb\System\User\User;class Login extends \Vvveb\Controller\Base {use LoginTrait;- function index() {+ /**+ * Handle login form display and logout action.+ *+ * @return void+ */+ public function index(): void {if (isset($this->request->post['logout'])) {User::logout();- return $this->login();+ $this->login();++ return;}$user = sess('user');@@ -61,6 +68,6 @@ class Login extends \Vvveb\Controller\Base {$this->session->delete('success');}- return $this->login();+ $this->login();}}diff --git a/app/controller/user/order-tracking.php b/app/controller/user/order-tracking.phpindex 0926cc4..8380e72 100644--- a/app/controller/user/order-tracking.php+++ b/app/controller/user/order-tracking.php@@ -22,12 +22,17 @@namespace Vvveb\Controller\User;-use function \Vvveb\__;-use function \Vvveb\session as sess;-use \Vvveb\Sql\OrderSQL;+use function Vvveb\__;+use function Vvveb\session as sess;+use Vvveb\Sql\OrderSQL;class OrderTracking extends \Vvveb\Controller\Base {- function order() {+ /**+ * Look up an order by customer_order_id and email.+ *+ * @return void+ */+ public function order(): void {$customer_order_id = trim($this->request->post['customer_order_id'] ?? '');$email = trim($this->request->post['email'] ?? '');$csrf = $this->request->post['csrf'] ?? false;@@ -52,9 +57,13 @@ class OrderTracking extends \Vvveb\Controller\Base {$this->view->errors[] = __('Invalid request!');}- return $this->index();+ $this->index();}- function index() {- }+ /**+ * Display the order tracking form.+ *+ * @return void+ */+ public function index(): void {}}diff --git a/app/controller/user/orders.php b/app/controller/user/orders.phpold mode 100755new mode 100644index ba41b88..e897012--- a/app/controller/user/orders.php+++ b/app/controller/user/orders.php@@ -23,9 +23,17 @@namespace Vvveb\Controller\User;class Orders extends Base {- function index() {- }+ /**+ * Display the user's order history.+ *+ * @return void+ */+ public function index(): void {}- function order() {- }+ /**+ * Display a single order detail (currently a stub).+ *+ * @return void+ */+ public function order(): void {}}diff --git a/app/controller/user/profile.php b/app/controller/user/profile.phpindex a1a8934..8f56aea 100644--- a/app/controller/user/profile.php+++ b/app/controller/user/profile.php@@ -29,38 +29,58 @@ use Vvveb\System\User\User;use Vvveb\System\Validator;class Profile extends Base {- function download() {+ /**+ * Export the current user's data as an XML download.+ *+ * @return never+ */+ public function download(): never {header('Content-Disposition: attachment; filename=user.xml');header('Content-Type: application/octet-stream');$data = User::get(['user_id' => $this->global['user_id']]);++ if (!$data) {+ exit(__('User not found!'));+ }+unset($data['password']);$xml = new \SimpleXMLElement('<root/>');- array_walk_recursive($data, function ($value, $key) use ($xml) {+ array_walk_recursive($data, function($value, $key) use ($xml): void {$xml->addChild($key, $value);});echo $xml->asXML();- die();+ exit();}- function delete() {+ /**+ * Request account deletion (sets status to 3) and log out.+ *+ * @return void+ */+ public function delete(): void {//status set to 3 = request delete$result = User::update(['status' => 3], ['user_id' => $this->global['user_id']]);- if (! $result) {+ if (!$result) {$userModel = new UserSQL();$this->view->errors = [$userModel->error];} else {User::logout();- $message = __('Account deleted!');+ $message = __('Account deletion request submitted!');$this->session->set('success', ['login' => $message]);$this->view->success[] = $message;$this->redirect('/user/login');}}- function save() {+ /**+ * Save profile changes submitted via the profile edit form.+ *+ * @return void+ */+ public function save(): void {$validator = new Validator(['user']);if (isset($this->request->post['user'])) {@@ -69,10 +89,10 @@ class Profile extends Base {$user['user_id'] = $this->global['user_id'];$user['bio'] = sanitizeHTML($user['bio'] ?? '');unset($user['username'], $user['status'], $user['user'], $user['token'], $user['created_at']);-+$result = User::update($user, ['user_id' => $this->global['user_id']]);- if (! $result) {+ if (!$result) {$userModel = new UserSQL();$this->view->errors = [$userModel->error];} else {@@ -87,7 +107,12 @@ class Profile extends Base {$this->index();}- function index() {+ /**+ * Display the current user's profile.+ *+ * @return void+ */+ public function index(): void {$user = User::get(['user_id' => $this->global['user_id']]);unset($user['password']);diff --git a/app/controller/user/reset.php b/app/controller/user/reset.phpindex e7b900e..7c6510a 100644--- a/app/controller/user/reset.php+++ b/app/controller/user/reset.php@@ -41,7 +41,7 @@ class Reset extends Base {** @return void*/- public function reset() : void {+ public function reset(): void {$token = $this->request->get['token'] ?? false;$user = $this->request->get['user'] ?? false;$password = $this->request->post['password'] ?? false;@@ -72,12 +72,12 @@ class Reset extends Base {}}} else {- die($error);+ exit($error);}}- if (! $admin) {- die($error);+ if (!$admin) {+ exit($error);}}@@ -86,14 +86,14 @@ class Reset extends Base {** @return void*/- public function index() : void {+ public function index(): void {$email = $this->request->post['email'] ?? false;$loginData = [];if ($email) {$loginData['email'] = $email;- list($loginData) = Event::trigger(__CLASS__, __FUNCTION__ , $loginData);+ [$loginData] = Event::trigger(__CLASS__, __FUNCTION__, $loginData);if ($loginData) {if (($adminData = User::get($loginData)) != false) {@@ -103,11 +103,11 @@ class Reset extends Base {$agent = $_SERVER['HTTP_USER_AGENT'] ?? '';- if (strpos($agent, 'Linux') !== false) {+ if (str_contains($agent, 'Linux')) {$os = 'Linux';- } elseif (strpos($agent, 'Win') !== false) {+ } elseif (str_contains($agent, 'Win')) {$os = 'Windows';- } elseif (strpos($agent, 'Mac') !== false) {+ } elseif (str_contains($agent, 'Mac')) {$os = 'Mac';} else {$os = 'UnKnown';@@ -129,7 +129,12 @@ class Reset extends Base {'reset_url' => $reset_url,];- if (email($adminData['email'], __('Password reset'),'user/reset', $data)) {+ \Vvveb\System\Notifications::trigger('user.password_reset', $data + [+ 'subject' => __('Password reset'),+ 'message' => __('A password reset was requested for your account.'),+ ]);++ if (email($adminData['email'], __('Password reset'), 'user/reset', $data)) {$success = __('A reset email was sent, please use it to reset your password!');$this->view->success[] = $success;$this->session->set('success', ['login' => $success]);diff --git a/app/controller/user/return-form.php b/app/controller/user/return-form.phpold mode 100755new mode 100644index 31e4eb3..776534d--- a/app/controller/user/return-form.php+++ b/app/controller/user/return-form.php@@ -26,11 +26,16 @@ use function Vvveb\__;use Vvveb\Controller\Base;use function Vvveb\session as sess;use Vvveb\Sql\OrderSQL;-use Vvveb\Sql\Return_ReasonSQL;+use Vvveb\Sql\Return_reasonSQL;use Vvveb\Sql\ReturnSQL;class ReturnForm extends Base {- function save() {+ /**+ * Process a return request submission.+ *+ * @return void+ */+ public function save(): void {$customer_order_id = $this->request->post['customer_order_id'] ?? false;$email = $this->request->post['email'] ?? '';$csrf = $this->request->post['csrf'] ?? false;@@ -45,12 +50,14 @@ class ReturnForm extends Base {if ($results && $results['order']) {$this->request->post['order_id'] = $results['order']['order_id'];$this->request->post['return_resolution_id'] = 1;- $this->request->post['return_status_id'] = 1;- $this->request->post['product_id'] = 1;+ $this->request->post['return_status_id'] ??= 1;+ $this->request->post['product_id'] ??= $results['order']['product_id'] ?? false;} else {$this->view->errors['return'] = sprintf(__('Order %s not found!'), htmlspecialchars($customer_order_id));- return $this->index();+ $this->index();++ return;}$data = $this->request->post + $this->global;@@ -70,11 +77,16 @@ class ReturnForm extends Base {$this->view->errors[] = __('Invalid request!');}- return $this->index();+ $this->index();}- function index() {- $reason = new Return_ReasonSQL();+ /**+ * Display the return form with available return reasons.+ *+ * @return void+ */+ public function index(): void {+ $reason = new Return_reasonSQL();$reasons = $reason->getAll($this->global + ['start' => 0, 'limit' => 100])['return_reason'] ?? [];$this->view->return_reason_id = $reasons;diff --git a/app/controller/user/signup.php b/app/controller/user/signup.phpindex 0913911..5e25472 100755--- a/app/controller/user/signup.php+++ b/app/controller/user/signup.php@@ -35,7 +35,12 @@ use function Vvveb\url;class Signup extends \Vvveb\Controller\Base {use Spam;- function addUser() {+ /**+ * Process user registration form submission.+ *+ * @return void+ */+ public function addUser(): void {//$this->checkAlreadyLoggedIn();$validator = new Validator(['signup']);@@ -47,15 +52,15 @@ class Signup extends \Vvveb\Controller\Base {$userInfo = $validator->filter($this->request->post);$userInfo['display_name'] = $userInfo['username'] ?? '';- if (! isset($userInfo['username']) && isset($userInfo['first_name'])) {- $userInfo['username'] = $userInfo['first_name'] . $userInfo['last_name'];+ if (!isset($userInfo['username']) && isset($userInfo['first_name'])) {+ $userInfo['username'] = $userInfo['first_name'] . ($userInfo['last_name'] ?? '');}$userInfo['spam'] = $isSpam;- list($userInfo) = Event :: trigger(__CLASS__, __FUNCTION__ , $userInfo);+ [$userInfo] = Event::trigger(__CLASS__, __FUNCTION__, $userInfo);//plugins can also be used to detect spam and set the flag- if ($userInfo['spam']) {+ if (isset($userInfo['spam']) && $userInfo['spam']) {$this->view->errors['login'] = __('Spam');return;@@ -69,13 +74,13 @@ class Signup extends \Vvveb\Controller\Base {if ($result) {if (isset($result['user'])) {$message = __('User created!');- $this->session->set('success', ['login' => $message]);+ $this->session->set('success', ['login' => $message]);$this->view->success['login'][] = $message;$user_id = $result['user'];- $this->request->request['user_id'] = $user_id;+ $this->request->get['user_id'] = $user_id;$site = siteSettings();- $siteData = Sites :: getSiteData(SITE_ID);+ $siteData = Sites::getSiteData(SITE_ID);$userInfo['website'] = url('user/index', ['host' => $siteData['host'] ?? false,@@ -85,19 +90,27 @@ class Signup extends \Vvveb\Controller\Base {try {$error = __('Error sending account creation mail!');- if (! email([$userInfo['email'], $site['admin-email']], __('Your account has been created!'), 'user/signup', ['user' => $userInfo] + $this->global)) {+ \Vvveb\System\Notifications::trigger('user.signup', ['user' => $userInfo] + $this->global + [+ 'subject' => __('Your account has been created!'),+ 'message' => __('Your account has been created!'),+ ]);++ if (!email([$userInfo['email'], $site['admin-email']], __('Your account has been created!'), 'user/signup', ['user' => $userInfo] + $this->global)) {$this->session->set('errors', ['login' => $error]);$this->view->errors[] = $error;}} catch (\Exception $e) {- if (DEBUG) {+ $error = __('Error creating user!');++ if (defined('DEBUG') && DEBUG) {$error .= "\n" . $e->getMessage();}+$this->session->set('errors', ['login' => $error]);$this->view->errors['login'] = $error;}- return $this->redirect('user/login/index');+ $this->redirect('user/login/index');} else {$this->view->errors['login'] = '';@@ -116,7 +129,12 @@ class Signup extends \Vvveb\Controller\Base {}}- function index() {+ /**+ * Handle sign-up page request.+ *+ * @return void+ */+ public function index(): void {if ($this->request->post) {$this->addUser();}diff --git a/app/controller/user/subscription.php b/app/controller/user/subscription.phpnew file mode 100755index 0000000..16b10ca--- /dev/null+++ b/app/controller/user/subscription.php@@ -0,0 +1,437 @@+<?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\User;++use function Vvveb\__;+use function Vvveb\model;+use Vvveb\System\SubscriptionManager;+use Vvveb\System\User\User;++#[\AllowDynamicProperties]+class Subscription extends Base {+ /** Subscription status IDs matching the seed data. */+ public const STATUS_PENDING = 1;+ public const STATUS_ACTIVE = 2;+ public const STATUS_FAILED = 3;+ public const STATUS_CANCELLED = 4;+ public const STATUS_DENIED = 5;+ public const STATUS_EXPIRED = 6;++ /**+ * Get the subscription ID from the request.+ *+ * @return int|string|false+ */+ private function getSubscriptionId(): int|string|false {+ return $this->request->get['subscription_id'] ?? false;+ }++ /**+ * Verify that the subscription belongs to the current user.+ *+ * @param int|string $subscriptionId+ *+ * @return array<string, mixed>|false The subscription data or false if not found / not owned.+ */+ private function getOwnedSubscription(int|string $subscriptionId): array|false {+ $user = User::current();+ $userId = $user['user_id'] ?? 0;++ $model = model('subscription');+ $result = $model->get([+ 'subscription_id' => $subscriptionId,+ 'language_id' => $this->global['language_id'] ?? 1,+ ] + $this->global);++ if ($result && (int)($result['user_id'] ?? 0) === (int)$userId) {+ return $result;+ }++ return false;+ }++ /**+ * Change subscription status and record a log entry.+ *+ * @param int $statusId+ * @param string $note+ *+ * @return void+ */+ protected function changeStatus(int $statusId, string $note): void {+ $subscriptionId = $this->getSubscriptionId();++ if (!$subscriptionId) {+ $this->view->errors[] = __('Subscription ID is required!');++ return;+ }++ $subscription = $this->getOwnedSubscription($subscriptionId);++ if (!$subscription) {+ $this->view->errors[] = __('Subscription not found!');++ return;+ }++ $this->writeSubscription($subscriptionId, $statusId, [+ 'subscription_status_id' => $statusId,+ ], $note);+ }++ /**+ * Update subscription fields and record a log entry.+ *+ * @param int|string $subscriptionId+ * @param int $statusId+ * @param array<string, mixed> $fields+ * @param string $note+ *+ * @return void+ */+ protected function writeSubscription(int|string $subscriptionId, int $statusId, array $fields, string $note): void {+ $model = model('subscription');+ $result = $model->edit([+ 'subscription' => $fields + [+ 'updated_at' => date('Y-m-d H:i:s'),+ ],+ 'subscription_id' => $subscriptionId,+ ] + $this->global);++ if ($result) {+ $logModel = model('subscription_log');+ $logModel->add([+ 'subscription_log' => [+ 'subscription_id' => $subscriptionId,+ 'subscription_status_id' => $statusId,+ 'notify' => 1,+ 'note' => $note,+ 'created_at' => date('Y-m-d H:i:s'),+ ],+ ] + $this->global);++ $this->view->success[] = __('Subscription updated!');+ } else {+ $this->view->errors[] = __('Error updating subscription!');+ }+ }++ /**+ * Display subscription detail page.+ *+ * @return void+ */+ public function index(): void {+ $subscriptionId = $this->getSubscriptionId();++ if ($subscriptionId) {+ $subscription = $this->getOwnedSubscription($subscriptionId);++ if ($subscription) {+ $this->view->subscription = $subscription;+ $this->view->plans = $this->productPlans((int)($subscription['product_id'] ?? 0));++ //load subscription logs+ $logModel = model('subscription_log');+ $logs = $logModel->getAll([+ 'subscription_id' => $subscriptionId,+ 'language_id' => $this->global['language_id'] ?? 1,+ ] + $this->global);++ $this->view->subscription_logs = $logs['subscription_log'] ?? [];++ return;+ }+ }++ $this->view->errors[] = __('Subscription not found!');+ }++ /**+ * Load the owned subscription with its original order (if any).+ *+ * @param int|string $subscriptionId Subscription id.+ *+ * @return array{0: array<string, mixed>|false, 1: array<string, mixed>|null} [subscription, order].+ */+ private function loadOwnedSubscription(int|string $subscriptionId): array {+ $subscription = $this->getOwnedSubscription($subscriptionId);+ $order = null;++ if ($subscription && !empty($subscription['order_id'])) {+ try {+ $orderResult = model('order')->get(['order_id' => (int)$subscription['order_id']] + $this->global);+ $order = $orderResult['order'] ?? null;+ } catch (\Throwable $e) {+ }+ }++ return [$subscription, $order];+ }++ /**+ * Validate a state-changing request (POST + CSRF token).+ *+ * Lifecycle actions now propagate to the live gateway, so plain GET+ * links must never trigger them.+ *+ * @return bool True when the request is a valid POST with matching token.+ */+ private function validPost(): bool {+ $token = (string)($this->request->post['csrf'] ?? '');+ $session = (string)$this->session->get('csrf');++ if ($this->request->getMethod() !== 'post' || $session === '' || !hash_equals($session, $token)) {+ $this->view->errors[] = __('Invalid request!');+ $this->index();++ return false;+ }++ return true;+ }++ /**+ * Run a gateway lifecycle operation before changing local status.+ *+ * @param string $operation Gateway operation (cancelSubscription, ...).+ * @param int $statusId Target local status on success.+ * @param string $note Log note.+ *+ * @return void+ */+ private function applyLifecycle(string $operation, int $statusId, string $note): void {+ if (!$this->validPost()) {+ return;+ }++ $subscriptionId = $this->getSubscriptionId();++ if ($subscriptionId) {+ [$subscription, $order] = $this->loadOwnedSubscription($subscriptionId);++ if ($subscription && ($error = SubscriptionManager::gatewayOperation($operation, $subscription, $order))) {+ $this->view->errors[] = $error;+ $this->index();++ return;+ }+ }++ $this->changeStatus($statusId, $note);+ $this->index();+ }++ /**+ * Available plans (with prices) for a product, for the swap selector.+ *+ * @param int $productId Local product id.+ *+ * @return array<int, array<string, mixed>>+ */+ private function productPlans(int $productId): array {+ if (!$productId) {+ return [];+ }++ try {+ $rows = model('product_subscription')->getAll([+ 'product_id' => $productId,+ 'language_id' => $this->global['language_id'] ?? 1,+ ]);+ } catch (\Throwable $e) {+ return [];+ }++ foreach ((array)$rows as $list) {+ if (is_array($list) && $list && is_array(reset($list))) {+ return array_values($list);+ }+ }++ return [];+ }++ /**+ * Swap the subscription to another plan of the same product.+ *+ * Gateway first (price ensured from the plan mapping), then local plan+ * fields. No new trial is granted on swap.+ *+ * @return void+ */+ public function swap(): void {+ if (!$this->validPost()) {+ return;+ }++ $subscriptionId = $this->getSubscriptionId();+ $planId = (int)($this->request->post['subscription_plan_id'] ?? 0);++ if (!$subscriptionId || !$planId) {+ $this->view->errors[] = __('Subscription and plan are required!');+ $this->index();++ return;+ }++ [$subscription, $order] = $this->loadOwnedSubscription($subscriptionId);++ if (!$subscription) {+ $this->view->errors[] = __('Subscription not found!');+ $this->index();++ return;+ }++ if ((int)($subscription['subscription_status_id'] ?? 0) !== self::STATUS_ACTIVE) {+ $this->view->errors[] = __('Only active subscriptions can change plan!');+ $this->index();++ return;+ }++ if ((int)($subscription['subscription_plan_id'] ?? 0) === $planId) {+ $this->view->errors[] = __('Already on this plan!');+ $this->index();++ return;+ }++ $offer = SubscriptionManager::planOffer((int)$subscription['product_id'], $planId, (int)($this->global['language_id'] ?? 1));++ if (!$offer) {+ $this->view->errors[] = __('Plan not available for this product!');+ $this->index();++ return;+ }++ $extra = [+ 'subscription_plan_id' => $planId,+ 'product_id' => (int)$subscription['product_id'],+ 'language_id' => (int)($this->global['language_id'] ?? 1),+ 'currency' => $order['currency'] ?? '',+ ];++ if (($error = SubscriptionManager::gatewayOperation('swapSubscription', $subscription, $order, $extra))) {+ $this->view->errors[] = $error;+ $this->index();++ return;+ }++ $this->writeSubscription($subscriptionId, (int)$subscription['subscription_status_id'], [+ 'subscription_plan_id' => $planId,+ 'price' => $offer['price'] ?? $subscription['price'],+ 'period' => $offer['period'] ?? $subscription['period'],+ 'cycle' => $offer['cycle'] ?? $subscription['cycle'],+ 'length' => $offer['length'] ?? $subscription['length'],+ 'trial_status' => 0,+ 'trial_left' => 0,+ ], sprintf(__('Swapped to plan %s by customer'), $offer['name'] ?? $planId));+ $this->index();+ }++ /**+ * Skip the next payment (push the next billing date out one interval).+ *+ * @return void+ */+ public function skip(): void {+ if (!$this->validPost()) {+ return;+ }++ $subscriptionId = $this->getSubscriptionId();++ if (!$subscriptionId) {+ $this->view->errors[] = __('Subscription ID is required!');+ $this->index();++ return;+ }++ [$subscription, $order] = $this->loadOwnedSubscription($subscriptionId);++ if (!$subscription) {+ $this->view->errors[] = __('Subscription not found!');+ $this->index();++ return;+ }++ if ((int)($subscription['subscription_status_id'] ?? 0) !== self::STATUS_ACTIVE) {+ $this->view->errors[] = __('Only active subscriptions can skip a payment!');+ $this->index();++ return;+ }++ $base = max(strtotime($subscription['date_next'] ?? 'now') ?: time(), time());+ $newDate = SubscriptionManager::addInterval(date('Y-m-d H:i:s', $base), (string)($subscription['period'] ?? 'month'), (int)($subscription['cycle'] ?? 1));++ if (($error = SubscriptionManager::gatewayOperation('skipSubscription', $subscription, $order, ['delay_until' => strtotime($newDate)]))) {+ $this->view->errors[] = $error;+ $this->index();++ return;+ }++ $this->writeSubscription($subscriptionId, (int)$subscription['subscription_status_id'], [+ 'date_next' => $newDate,+ ], sprintf(__('Skipped one payment by customer, next payment %s'), $newDate));+ $this->index();+ }++ /**+ * Cancel the subscription (customer-initiated).+ *+ * @return void+ */+ public function cancel(): void {+ $note = $this->request->post['note'] ?? __('Cancelled by customer');+ $this->applyLifecycle('cancelSubscription', self::STATUS_CANCELLED, $note);+ }++ /**+ * Pause the subscription (customer-initiated).+ *+ * @return void+ */+ public function pause(): void {+ $note = $this->request->post['note'] ?? __('Paused by customer');+ $this->applyLifecycle('pauseSubscription', self::STATUS_PENDING, $note);+ }++ /**+ * Resume the subscription (customer-initiated).+ *+ * @return void+ */+ public function resume(): void {+ $note = $this->request->post['note'] ?? __('Resumed by customer');+ $this->applyLifecycle('resumeSubscription', self::STATUS_ACTIVE, $note);+ }+}diff --git a/app/controller/user/subscriptions.php b/app/controller/user/subscriptions.phpnew file mode 100755index 0000000..192944a--- /dev/null+++ b/app/controller/user/subscriptions.php@@ -0,0 +1,56 @@+<?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\User;++use function Vvveb\model;+use Vvveb\System\User\User;++class Subscriptions extends Base {+ /**+ * Display the customer's subscription list.+ *+ * @return void+ */+ public function index(): void {+ $user = User::current();+ $userId = $user['user_id'] ?? 0;++ $model = model('subscription');+ $page = max((int)($this->request->get['page'] ?? 1), 1);+ $limit = (int)($this->request->get['limit'] ?? 10);+ $start = ($page - 1) * $limit;++ $results = $model->getAll([+ 'user_id' => $userId,+ 'language_id' => $this->global['language_id'] ?? 1,+ 'site_id' => $this->global['site_id'] ?? 1,+ 'start' => $start,+ 'limit' => $limit,+ ]);++ $this->view->subscriptions = $results['subscription'] ?? [];+ $this->view->count = $results['count'] ?? 0;+ $this->view->page = $page;+ $this->view->limit = $limit;+ }+}diff --git a/app/controller/user/wishlist.php b/app/controller/user/wishlist.phpindex 0a265e2..6ffbea0 100755--- a/app/controller/user/wishlist.php+++ b/app/controller/user/wishlist.php@@ -22,39 +22,68 @@namespace Vvveb\Controller\User;+use function Vvveb\__;use Vvveb\Sql\User_wishlistSQL;class Wishlist extends Base {- function index() {- }+ /**+ * Display the wishlist page.+ *+ * @return void+ */+ public function index(): void {}++ /**+ * Perform a wishlist action: add or remove a product.+ *+ * @param string $action+ *+ * @return void+ */+ private function action(string $action): void {+ $productId = (int)($this->request->post['product_id'] ?? false);+ $userId = (int)($this->global['user_id'] ?? 0);- private function action($action) {- $productId = (int) ($this->request->request['product_id'] ?? false);+ if (!$userId) {+ $this->view->errors[] = __('You need to be logged in to use the wishlist!');++ return;+ }if ($productId) {$wishlist = new User_wishlistSQL();switch ($action) {case 'add':- $result = $wishlist->add(['user_id' => $this->global['user_id'], 'product_id' => $productId]);+ $result = $wishlist->add(['user_id' => $userId, 'product_id' => $productId]);- break;+ break;case 'remove':- $result = $wishlist->delete(['user_id' => $this->global['user_id'], 'product_id' => [$productId]]);+ $result = $wishlist->delete(['user_id' => $userId, 'product_id' => [$productId]]);- break;+ break;}- return $this->index();+ $this->index();}}- function add() {- return $this->action('add');+ /**+ * Add a product to the wishlist.+ *+ * @return void+ */+ public function add(): void {+ $this->action('add');}- function remove() {- return $this->action('remove');+ /**+ * Remove a product from the wishlist.+ *+ * @return void+ */+ public function remove(): void {+ $this->action('remove');}}diff --git a/app/template/cart/cart.tpl b/app/template/cart/cart.tplold mode 100644new mode 100755index 0de175e..d69a660--- a/app/template/cart/cart.tpl+++ b/app/template/cart/cart.tpl@@ -1,8 +1,8 @@import(common.tpl)-[data-v-cart-page][data-v-cart-total_items] = $cart['total_items']-//[data-v-cart-page] [data-v-cart-total] = $cart['total']-[data-v-cart-page] [data-v-cart-total_formatted] = $cart['total_formatted']+[data-v-cart-page] [data-v-cart-total_items] = $this->cart['total_items']+[data-v-cart-page] [data-v-cart-total_weight] = $this->cart['total_weight']+[data-v-cart-page] [data-v-cart-total_formatted] = $this->cart['total_formatted']//[data-v-cart-page] [data-v-cart-*]|innerText = $this->cart['@@__data-v-cart-(*)__@@']@cart-product = [data-v-cart] [data-v-cart-product]@@ -10,17 +10,13 @@ import(common.tpl)@cart-product|deleteAllButFirstChild@cart-product|before = <?php-$products = $this->cart['products'];-$_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [0 => ['product_id' => 1, 'product_id' => 1, 'image' => '#']] : false;+$products = $this->cart['products'] ?? [];+$_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [0 => ['product_id' => 1, 'image' => '#']] : false;$products = empty($products) ? $_default : $products;if(is_array($products)) foreach ($products as $key => $product) {?>- //@cart-product [data-v-cart-product-name] = $product['name']- //@cart-product [data-v-cart-product-content] = $product['content']- //@cart-product [data-v-cart-product-amount] = <?php echo htmlspecialchars($product['amount']);?>-@cart-product|data-product_id = $product['product_id']@cart-product|data-key = $key@@ -58,7 +54,7 @@ if($option_value) {@total|deleteAllButFirstChild@total|before = <?php-$totals = $this->cart['totals'];+$totals = $this->cart['totals'] ?? [];$_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [0 => []] : false;$totals = empty($totals) ? $_default : $totals;@@ -78,7 +74,7 @@ if(is_array($totals)) foreach ($totals as $index => $total) {@coupon|deleteAllButFirstChild@coupon|before = <?php-$coupons = $this->cart['coupons'];+$coupons = $this->cart['coupons'] ?? [];$_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [0 => []] : false;$coupons = empty($coupons) ? $_default : $coupons;diff --git a/app/template/cart/compare.tpl b/app/template/cart/compare.tplold mode 100644new mode 100755index 5ebed67..749a170--- a/app/template/cart/compare.tpl+++ b/app/template/cart/compare.tpl@@ -9,7 +9,7 @@ import(common.tpl)@compare-product|before = <?php$products = $this->products['product'] ?? [];-$_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [0 => ['product_id' => 1, 'product_id' => 1, 'image' => '#']] : false;+$_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [0 => ['product_id' => 1, 'image' => '#']] : false;$products = empty($products) ? $_default : $products;if(is_array($products)) foreach ($products as $key => $product) {@@ -67,4 +67,4 @@ if($values) {@compare-spec|after = <?php }}-?>\ No newline at end of file+?>diff --git a/app/template/checkout/checkout.tpl b/app/template/checkout/checkout.tplindex 20f8304..aa37e9a 100755--- a/app/template/checkout/checkout.tpl+++ b/app/template/checkout/checkout.tpl@@ -73,18 +73,18 @@ input[name="different_shipping_address"]|addNewAttribute =?>[data-v-address] input[name="billing_address_id"]|addNewAttribute = <?php- if (isset($_POST['billing_address_id']) && ($_POST['billing_address_id'] == $address['user_address_id'])) echo ' checked';+ if (isset($_POST['billing_address_id']) && isset($address['user_address_id']) && ($_POST['billing_address_id'] == $address['user_address_id'])) echo ' checked';?>[data-v-payment] input[name="payment_method"]|addNewAttribute = <?php$payment_method = $_POST['payment_method'] ?? $this->checkout['payment_method'] ?? '';- if ($payment_method == $payment['name']) echo ' checked';+ if (isset($payment['name']) && $payment_method == $payment['name']) echo ' checked';?>[data-v-shipping] input[name="shipping_method"]|addNewAttribute = <?php$shipping_method = $_POST['shipping_method'] ?? $this->checkout['shipping_method'] ?? '';- if ($shipping_method == $shipping['name']) echo ' checked';+ if (isset($shipping['name']) && $shipping_method == $shipping['name']) echo ' checked';?>@country = [data-v-countries] option[data-v-option]diff --git a/app/template/checkout/order.tpl b/app/template/checkout/order.tpldeleted file mode 100755index 6f14e21..0000000--- a/app/template/checkout/order.tpl+++ /dev/null@@ -1,4 +0,0 @@-//keep post values-input|value = <?php if (isset($_POST['@@__name__@@'])) echo htmlspecialchars($_POST['@@__name__@@']);?>--import(common.tpl)diff --git a/app/template/common.tpl b/app/template/common.tplindex b6961cb..cc1dfba 100755--- a/app/template/common.tpl+++ b/app/template/common.tpl@@ -10,7 +10,7 @@ form[data-v-url-params]|action = <?php echo Vvveb\url('@@__data-v-url__@@' , @@_/* [data-v-img]|href = <?php echo htmlspecialchars(Vvveb\url('@@__data-v-img__@@'));?> */-head base|href = <?php if($vvveb_is_page_edit) echo Vvveb\themeUrlPath()?>+head base|href = <?php if(isset($vvveb_is_page_edit) && $vvveb_is_page_edit) echo Vvveb\themeUrlPath()?>//csrfinput[data-v-csrf]|value = <?php echo \Vvveb\session('csrf');?>diff --git a/app/template/components.tpl b/app/template/components.tplindex 7029562..485edc6 100755--- a/app/template/components.tpl+++ b/app/template/components.tpl@@ -1,4 +1,7 @@import(components/categories.tpl, [data-v-component-categories])+import(components/category.tpl, [data-v-component-category])+import(components/product/category.tpl, [data-v-component-product-category])+import(components/content/category.tpl, [data-v-component-content-category])import(components/categories/pages.tpl, [data-v-component-categories-pages])import(components/menu.tpl, [data-v-component-menu])import(components/product.tpl, [data-v-component-product])@@ -10,13 +13,12 @@ import(components/questions.tpl, [data-v-component-questions])import(components/post.tpl, [data-v-component-post])import(components/filters.tpl, [data-v-component-filters])import(components/cart.tpl, [data-v-component-cart])-import(components/search.tpl, [data-v-component-search])import(components/product_gallery.tpl, [data-v-component-product-gallery])import(components/user.tpl, [data-v-component-user])import(components/admin.tpl, [data-v-component-admin])import(components/admins.tpl, [data-v-component-admin])import(components/checkout.tpl, [data-v-component-checkout])-import(components/manufacturers.tpl, [data-v-component-manufacturers])+import(components/product/manufacturers.tpl, [data-v-component-manufacturers])import(components/breadcrumb.tpl, [data-v-component-breadcrumb])import(components/content/categories.tpl, [data-v-component-content-categories])import(components/product/categories.tpl, [data-v-component-product-categories])diff --git a/app/template/components/admin.tpl b/app/template/components/admin.tplold mode 100644new mode 100755diff --git a/app/template/components/admins.tpl b/app/template/components/admins.tplold mode 100644new mode 100755diff --git a/app/template/components/breadcrumb.tpl b/app/template/components/breadcrumb.tplindex eed18cb..73265e7 100755--- a/app/template/components/breadcrumb.tpl+++ b/app/template/components/breadcrumb.tpl@@ -21,11 +21,12 @@ $_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [0 => []] : f$breadcrumb['breadcrumb'] = empty($breadcrumb['breadcrumb']) ? $_default : $breadcrumb['breadcrumb'];if($breadcrumb && is_array($breadcrumb['breadcrumb'])) {- foreach ($breadcrumb['breadcrumb'] as $index => $breadcrumb) {$index++;?>+ foreach ($breadcrumb['breadcrumb'] as $index => $item) {+ ?>- @item [data-v-breadcrumb-item-*]|innerText = $breadcrumb['@@__data-v-breadcrumb-item-(*)__@@']+ @item [data-v-breadcrumb-item-*]|innerText = $item['@@__data-v-breadcrumb-item-(*)__@@']- @item a[data-v-breadcrumb-item-*]|href = $breadcrumb['@@__data-v-breadcrumb-item-(*)__@@']+ @item a[data-v-breadcrumb-item-*]|href = $item['@@__data-v-breadcrumb-item-(*)__@@']@item|after = <?php}diff --git a/app/template/components/cart.tpl b/app/template/components/cart.tplold mode 100644new mode 100755index cc314d6..d96637f--- a/app/template/components/cart.tpl+++ b/app/template/components/cart.tpl@@ -18,8 +18,6 @@ $products = $cart['products'] ?? [];//[data-v-component-cart] [data-v-cart-total] = $cart['total'][data-v-component-cart] [data-v-cart-total_formatted] = $cart['total_formatted']--@cart-product|before = <?php$_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [0 => ['product_id' => 1, 'image' => '#']] : false;$products = empty($products) ? $_default : $products;@@ -32,10 +30,15 @@ if($products) {//@cart-product [data-v-product-content] = $product['content']//catch all data attributes- @cart-product [data-v-cart-product-*]|innerText = $product['@@__data-v-cart-product-(*)__@@']+ @cart-product [data-v-cart-product-*]:not(a):not(button)|innerText = $product['@@__data-v-cart-product-(*)__@@']+ @cart-product a[data-v-cart-product-*]:empty|innerText = $product['@@__data-v-cart-product-(*)__@@']+ @cart-product button[data-v-cart-product-*]:empty|innerText = $product['@@__data-v-cart-product-(*)__@@']+@cart-product a[data-v-cart-product-*]|href = $product['@@__data-v-cart-product-(*)__@@']+ @product a[data-v-product-*]|href = $prod['@@__data-v-product-(*)__@@']+@cart-product img[data-v-cart-product-*]|src = $product['@@__data-v-cart-product-(*)__@@']- @cart-product input[data-v-cart-product-*]|value = $product['@@__data-v-cart-product-(*)__@@'] @cart-product|data-product_id = $product['product_id']+ @cart-product input[data-v-cart-product-*]|value = $product['@@__data-v-cart-product-(*)__@@']@cart-product|data-product_id = $product['product_id']@cart-product|data-key = $key@@ -106,4 +109,5 @@ if(is_array($coupons)) foreach ($coupons as $index => $coupon) {@coupon|after = <?php }?>-[data-v-component-cart] [data-v-cart-*]|innerText = $cart['@@__data-v-cart-(*)__@@']+[data-v-component-cart] [data-v-cart-*]:not(a):not(button):not(input)|innerText = $cart['@@__data-v-cart-(*)__@@']+diff --git a/app/template/components/categories.tpl b/app/template/components/categories.tplindex 9ba00ba..c248de4 100755--- a/app/template/components/categories.tpl+++ b/app/template/components/categories.tpl@@ -30,7 +30,7 @@ $previous_component = isset($current_component)?$current_component:null;$categories = $current_component = $this->_component['categories'][$_categories_idx] ?? [];$_categories = $categories['categories'] ?? [];-$_pagination_count = $categories['count'] ?? 0;+$_pagination_count = $count = $categories['count'] ?? count($_categories);$_pagination_limit = isset($categories['limit']) ? $categories['limit'] : 5;$parent = 0;diff --git a/app/template/components/categories/pages.tpl b/app/template/components/categories/pages.tplindex 6f73dde..3720dc6 100755--- a/app/template/components/categories/pages.tpl+++ b/app/template/components/categories/pages.tpl@@ -15,8 +15,8 @@ $_categories = [];$previous_component = isset($current_component)?$current_component:null;$categories_pages = $current_component = $this->_component['categories_pages'][$_categories_pages_idx] ?? [];-$_pagination_count = $posts['count'] ?? 0;-$_pagination_limit = isset($posts['limit']) ? $posts['limit'] : 5;+ $_pagination_count = $categories_pages['count'] ?? 0;+$_pagination_limit = $categories_pages['limit'] ?? 5;$_categories = $categories_pages['categories'] ?? [];diff --git a/app/template/components/categories_recursive.tpl b/app/template/components/categories_recursive.tplindex bff2c5e..a016bf6 100755--- a/app/template/components/categories_recursive.tpl+++ b/app/template/components/categories_recursive.tpl@@ -3,6 +3,11 @@[data-v-component-categories] ul|before = <?phpif (isset($_categories_idx)) $_categories_idx++; else $_categories_idx = 0;+$categories = $this->_component['categories'][$_categories_idx];++$_pagination_count = $categories'count'] ?? 0;+$_pagination_limit = $categories['limit'] ?? 5;+if (!function_exists("generate_menu")) {function generate_menu($parent, &$categories){?>@@ -22,7 +27,7 @@ foreach($categories as $id => $category) {[data-v-component-categories] li|after = <?php } }?>//close function-[data-v-component-categories]|after = <?php } } reset($this->categories[$_categories_idx]);generate_menu($this->categories[$_categories_idx][key($this->categories[$_categories_idx])]['parent'], $this->categories[$_categories_idx]);?>+[data-v-component-categories]|after = <?php } } reset($categories);generate_menu($categories[key($categories)]['parent'], $categories);?>//set variable for if macro-[data-v-component-categories] .if_*.tplttmacroif = 'category';\ No newline at end of file+[data-v-component-categories] .if_*.tplttmacroif = 'category';diff --git a/app/template/components/category.tpl b/app/template/components/category.tplindex 6ab671a..996def7 100755--- a/app/template/components/category.tpl+++ b/app/template/components/category.tpl@@ -1,9 +1,22 @@-[data-v-component-category]|before = <?php-if (isset($_category_idx)) $_category_idx++; else $_category_idx = 0;-$_category = $this->_component['category'][$_category_idx];-?>+//set component variables+[data-v-component-category]|prepend = <?php+ $vvveb_is_page_edit = Vvveb\isEditor();++ //use a counter to know which component instance we need to use if there are more than one component on page+ if (isset($category_idx)) $category_idx++; else $category_idx = 0;+ $previous_component = isset($current_component)?$current_component:null;+ $component = $current_component = $this->_component['category'][$category_idx] ?? [];-//[data-v-component-category] [data-v-category-name] = $_category['name']+ $index = 0;+ $count = $component['count'] ?? 0;+ $limit = isset($component['limit'])? $component['limit'] : 5;++ //if page loaded in editor then set a fist empty category if there are no categories+ //to render an empty category to avoid losing the html on edit+ $_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [0 => []] : false;+ //$_default = [0 => []];+ $_category = empty($component) ? $_default : $component;+?>//catch all data attributes[data-v-component-category] [data-v-category-*] = $_category['@@__data-v-category-(*)__@@']diff --git a/app/template/components/checkout/payment.tpl b/app/template/components/checkout/payment.tplindex 4ef41a7..e704db5 100755--- a/app/template/components/checkout/payment.tpl+++ b/app/template/components/checkout/payment.tpl@@ -5,6 +5,7 @@@payments|prepend = <?php$vvveb_is_page_edit = Vvveb\isEditor();+$payment_method = $payment_method ?? '';if (isset($_payments_idx)) $_payments_idx++; else $_payments_idx = 0;$previous_component = isset($current_component)?$current_component:null;$payments = $current_component = $this->_component['checkout_payment'][$_payments_idx] ?? [];@@ -25,7 +26,7 @@ if($payments && is_array($payments['payment'])) {@payment input[data-v-payment-*] = $payment['@@__data-v-payment-(*)__@@']- @payment input[data-v-payment-key][type=radio]|addNewAttribute = <?php if ($payment_method == $key) echo 'checked';?>+ @payment input[data-v-payment-key]|addNewAttribute = <?php if ($payment_method == $key) echo 'checked';?>@payment .collapse|addClass = <?php if (($payment_method == $key) && !$vvveb_is_page_edit) echo 'show';?>diff --git a/app/template/components/checkout/shipping.tpl b/app/template/components/checkout/shipping.tplindex 2618162..2f346ee 100755--- a/app/template/components/checkout/shipping.tpl+++ b/app/template/components/checkout/shipping.tpl@@ -5,6 +5,7 @@@shippings|prepend = <?php$vvveb_is_page_edit = Vvveb\isEditor();+$shipping_method = $shipping_method ?? '';if (isset($_shippings_idx)) $_shippings_idx++; else $_shippings_idx = 0;$previous_component = isset($current_component)?$current_component:null;$shippings = $current_component = $this->_component['checkout_shipping'][$_shippings_idx] ?? [];diff --git a/app/template/components/comments.tpl b/app/template/components/comments.tplindex 1ea8372..d5b612b 100755--- a/app/template/components/comments.tpl+++ b/app/template/components/comments.tpl@@ -31,7 +31,7 @@ if($_comments && is_array($_comments)) {@comment [data-v-comment-content] = $comment['content']@comment img[data-v-comment-*]|src = $comment['@@__data-v-comment-(*)__@@']- @comment img[data-v-comment-*]|width = <?php echo (int)($review['size'] ?? 60);?>+ @comment img[data-v-comment-*]|width = <?php echo (int)($comment['size'] ?? 60);?>@comment [data-v-comment-*]|innerText = $comment['@@__data-v-comment-(*)__@@']@@ -40,4 +40,4 @@ if($_comments && is_array($_comments)) {@comment|after = <?php}}-?>\ No newline at end of file+?>diff --git a/app/template/components/content/categories.tpl b/app/template/components/content/categories.tplindex 4eb82a1..c5fc09d 100755--- a/app/template/components/content/categories.tpl+++ b/app/template/components/content/categories.tpl@@ -30,10 +30,12 @@ $previous_component = isset($current_component)?$current_component:null;$categories = $current_component = $this->_component['content_categories'][$_content_categories_idx] ?? [];$_categories = $categories['categories'] ?? [];-$_pagination_count = $categories['count'] ?? 0;+$_pagination_count = $count = $categories['count'] ?? count($_categories);$_pagination_limit = isset($categories['limit']) ? $categories['limit'] : 5;$parent = 0;$generate_menu = false;+//alias for data-v-if="tags > 0" in single-post templates (in posts loop $tags is a count)+$tags = $count;?>@categories|before = <?phpdiff --git a/app/template/components/content/category.tpl b/app/template/components/content/category.tplnew file mode 100755index 0000000..b338584--- /dev/null+++ b/app/template/components/content/category.tpl@@ -0,0 +1,22 @@+//set component variables+[data-v-component-content-category]|prepend = <?php+ $vvveb_is_page_edit = Vvveb\isEditor();++ //use a counter to know which component instance we need to use if there are more than one component on page+ if (isset($content_category_idx)) $content_category_idx++; else $content_category_idx = 0;+ $previous_component = isset($current_component)?$current_component:null;+ $component = $current_component = $this->_component['content_category'][$content_category_idx] ?? [];++ $index = 0;+ $count = $component['count'] ?? 0;+ $limit = isset($component['limit'])? $component['limit'] : 5;++ //if page loaded in editor then set a fist empty category if there are no categories+ //to render an empty category to avoid losing the html on edit+ $_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [0 => []] : false;+ //$_default = [0 => []];+ $_category = empty($component) ? $_default : $component;+?>++//catch all data attributes+[data-v-component-content-category] [data-v-category-*] = $_category['@@__data-v-category-(*)__@@']diff --git a/app/template/components/content/tags.tpl b/app/template/components/content/tags.tplnew file mode 100755index 0000000..1e18ceb--- /dev/null+++ b/app/template/components/content/tags.tpl@@ -0,0 +1,44 @@+@tags = [data-v-component-content-tags]+@archive = [data-v-component-content-tags] [data-v-tags] [data-v-archive]++@archive|deleteAllButFirstChild++@tags|before = <?php+//make sure that the instance is unique even if the component is added into a loop inside a compomonent like data-v-posts+$line = __LINE__;+if (isset($_content_tags_idx)){+ if (!isset($_content_tags[$line])) {+ $_content_tags_idx++;+ $_content_tags[$line] = $_content_tags_idx;+ }+} else {+ $_content_tags_idx = 0;+ $_content_tags[$line] = $_content_tags_idx;+}++//if (isset($_content_tags_idx)) $_content_tags_idx++; else $_content_tags_idx = 0;+$_tags = [];+++$previous_component = isset($current_component)?$current_component:null;+$content_tags = $current_component = $this->_component['content_tags'][$_content_tags_idx] ?? [];++$_pagination_count = $content_tags['count'] ?? 0;+$_pagination_limit = isset($content_tags['limit']) ? $content_tags['limit'] : 5;+$_tags = $content_tags['tags'] ?? [];+?>++@archive|before = <?php+foreach($_tags as $id => $archive) {?>++ @archive [data-v-archive-*]|innerText = $archive['@@__data-v-archive-(*)__@@']+ @archive a[data-v-archive-*]|href = $archive['@@__data-v-archive-(*)__@@']+ @archive option[data-v-archive-*]|value = $archive['@@__data-v-archive-(*)__@@']+ @archive option[data-v-archive]|value = $archive['url']++ @tags option[data-v-archive]|value = $archive['url']+ @tags option[data-v-archive-*]|value = $archive['@@__data-v-archive-(*)__@@']++@archive|after = <?php+ }+?>diff --git a/app/template/components/currency.tpl b/app/template/components/currency.tplold mode 100644new mode 100755index 5aa3e78..da21093--- a/app/template/components/currency.tpl+++ b/app/template/components/currency.tpl@@ -13,8 +13,8 @@ $currencies = $current_component['currency'] ?? [];$active = $current_component['active'] ?? [];$current = $current_component['current'] ?? [];-$_pagination_count = $currencies['count'] ?? 0;-$_pagination_limit = isset($currencies['limit']) ? $currencies['limit'] : 5;+$_pagination_count = $current_component['count'] ?? 0;+$_pagination_limit = $current_component['limit'] ?? 5;?>[data-v-component-currency] [data-v-currency-info-*] = $current_component['active']['@@__data-v-currency-info-(*)__@@']diff --git a/app/template/components/digital_assets.tpl b/app/template/components/digital_assets.tplold mode 100644new mode 100755diff --git a/app/template/components/fields.tpl b/app/template/components/fields.tplold mode 100644new mode 100755diff --git a/app/template/components/language.tpl b/app/template/components/language.tplold mode 100644new mode 100755index 06a48d3..a02ec3c--- a/app/template/components/language.tpl+++ b/app/template/components/language.tpl@@ -50,4 +50,4 @@ $language['language'] = empty($language['language']) ? $_default : $language['la[data-v-component-language]|append = <?php}-?>+?>\ No newline at end of filediff --git a/app/template/components/menu.tpl b/app/template/components/menu.tplold mode 100644new mode 100755index 61562b0..168439c--- a/app/template/components/menu.tpl+++ b/app/template/components/menu.tpl@@ -67,7 +67,7 @@ if (isset($this->_component['menu']) && isset($this->_component['menu'][$_menu_iif (isset($_categories[$parent_id]['options']['columns'])) echo 'column-count:' . $_categories[$parent_id]['options']['columns'] .';';if (isset($_categories[$parent_id]['options']['width'])) echo 'width:' . $_categories[$parent_id]['options']['width'] .'%;';if (isset($_categories[$parent_id]['options']['sub-padding-x'])) echo 'padding-left:' . $_categories[$parent_id]['options']['sub-padding-x'] . 'px;padding-right:' . $_categories[$parent_id]['options']['sub-padding-x'] .'px;';- if (isset($_categories[$parent_id]['options']['sub-padding-y'])) echo 'padding-top:' . $_categories[$parent_id]['options']['sub-padding-x'] . 'px;padding-bottom:' . $_categories[$parent_id]['options']['sub-padding-x'] .'px;';+ if (isset($_categories[$parent_id]['options']['sub-padding-y'])) echo 'padding-top:' . $_categories[$parent_id]['options']['sub-padding-y'] . 'px;padding-bottom:' . $_categories[$parent_id]['options']['sub-padding-y'] .'px;';echo '"';?>@@ -102,4 +102,4 @@ $generate_menu = function ($parent_id) use (&$_categories, &$generate_menu, &$pa@category-recursive|after = <?php}-?>\ No newline at end of file+?>diff --git a/app/template/components/post.tpl b/app/template/components/post.tplindex 1e8b806..38888fb 100755--- a/app/template/components/post.tpl+++ b/app/template/components/post.tpl@@ -10,18 +10,12 @@ if (isset($post_idx)) $post_idx++; else $post_idx = 0;$post = $this->_component['post'][$post_idx] ?? [];?>-//catch all data attributes-@post [data-v-post-*]|innerText = $post['@@__data-v-post-(*)__@@']-@post input[data-v-post-*]|value = $post['@@__data-v-post-(*)__@@']--//manual echo to avoid html escape@post [data-v-post-content] = <?php if (isset($post['content'])) echo($post['content']);?>//@post [data-v-post-content] = $post['content']-//featured image//catch all data attributes@post [data-v-post-*]|innerText = $post['@@__data-v-post-(*)__@@']@post img[data-v-post-*]|src = $post['@@__data-v-post-(*)__@@']diff --git a/app/template/components/posts.tpl b/app/template/components/posts.tplindex b13afb9..da73041 100755--- a/app/template/components/posts.tpl+++ b/app/template/components/posts.tpl@@ -21,7 +21,7 @@@post|deleteAllButFirstChild-@posts [data-v-posts-category] = <?php $_category = current($posts['posts']);echo htmlspecialchars($_category['category']);?>+@posts [data-v-posts-category] = <?php $_category = current($posts['posts'] ?? []);echo htmlspecialchars($_category['category'] ?? '');?>@posts [data-v-posts-count] = $posts['count']@@ -38,7 +38,10 @@ foreach ($_posts as $id => $post) {?>//@post [data-v-post-excerpt] = $post['excerpt']//catch all data attributes- @post [data-v-post-*]|innerText = $post['@@__data-v-post-(*)__@@']+ @post [data-v-post-*]:not(a):not(button)|innerText = $post['@@__data-v-post-(*)__@@']+ @post a[data-v-post-*]:empty|innerText = $post['@@__data-v-post-(*)__@@']+ @post button[data-v-post-*]:empty|innerText = $post['@@__data-v-post-(*)__@@']+@post img[data-v-post-*]|src = <?php$image = $post['@@__data-v-post-(*)__@@'] ?? '';$size = '@@__data-v-size__@@';@@ -82,12 +85,15 @@ $categories = count($_categories);@post [data-v-categories] [data-v-categories-cat]|deleteAllButFirstChild@post [data-v-categories-cat]|before = <?php- foreach ($_categories as $cat){ $categories_count++;?>+ foreach ($_categories as $cat) {+ $categories_count++;?>- @post [data-v-categories] [data-v-categories-cat] a[data-v-categories-cat-*]|href = $cat['@@__data-v-categories-cat-(*)__@@']- @post [data-v-categories] [data-v-categories-cat] [data-v-categories-cat-*]|innerText = $cat['@@__data-v-categories-cat-(*)__@@']+ @post [data-v-categories] [data-v-categories-cat] a[data-v-categories-cat-*]|href = $cat['@@__data-v-categories-cat-(*)__@@']+ @post [data-v-categories] [data-v-categories-cat] [data-v-categories-cat-*]|innerText = $cat['@@__data-v-categories-cat-(*)__@@']- @post [data-v-categories] [data-v-categories-cat]|after = <?php } ?>+ @post [data-v-categories] [data-v-categories-cat]|after = <?php+ }+ ?>@post [data-v-tags]|before = <?php@@ -102,21 +108,28 @@ $tags = count($_tags);@post [data-v-tags] [data-v-tags-tag]|deleteAllButFirstChild@post [data-v-tags] [data-v-tags-tag]|before = <?php- foreach ($_tags as $tag){ $tags_count++;?>-- @post [data-v-tags] [data-v-tags-tag] a[data-v-tags-tag-*]|href = $tag['@@__data-v-tags-tag-(*)__@@']- @post [data-v-tags] [data-v-tags-tag] [data-v-tags-tag-*]|innerText = $tag['@@__data-v-tags-tag-(*)__@@']+ foreach ($_tags as $tag) {+ $tags_count++;?>- @post [data-v-tags] [data-v-tags-tag]|after = <?php } ?>+ @post [data-v-tags] [data-v-tags-tag] a[data-v-tags-tag-*]|href = $tag['@@__data-v-tags-tag-(*)__@@']+ @post [data-v-tags] [data-v-tags-tag] [data-v-tags-tag-*]|innerText = $tag['@@__data-v-tags-tag-(*)__@@']+ @post [data-v-tags] [data-v-tags-tag]|after = <?php+ }+ ?>@post [data-v-taxonomy] [data-v-tags-tax]|before = <?php$taxonomy_count = 0;- if (isset($post['taxonomy'])) { $taxonomy = count($post['taxonomy']);- foreach ($post['taxonomy'] as $tax){ $taxonomy_count++;?>-- @post [data-v-taxonomy] [data-v-taxonomy-tax] a[data-v-taxonomy-tax-*]|href = $tax['@@__data-v-taxonomy-tax-(*)__@@']- @post [data-v-taxonomy] [data-v-taxonomy-tax] [data-v-taxonomy-tax-*]|innerText = $tax['@@__data-v-taxonomy-tax-(*)__@@']--@post [data-v-taxonomy] [data-v-taxonomy-tax]|after = <?php } } ?>+ if (isset($post['taxonomy'])) {++ $taxonomy = count($post['taxonomy']);+ foreach ($post['taxonomy'] as $tax) {+ $taxonomy_count++;?>++ @post [data-v-taxonomy] [data-v-taxonomy-tax] a[data-v-taxonomy-tax-*]|href = $tax['@@__data-v-taxonomy-tax-(*)__@@']+ @post [data-v-taxonomy] [data-v-taxonomy-tax] [data-v-taxonomy-tax-*]|innerText = $tax['@@__data-v-taxonomy-tax-(*)__@@']++@post [data-v-taxonomy] [data-v-taxonomy-tax]|after = <?php+ }+} ?>diff --git a/app/template/components/posts_taxonomy.tpl b/app/template/components/posts_taxonomy.tplold mode 100644new mode 100755index 51fccb6..3665b95--- a/app/template/components/posts_taxonomy.tpl+++ b/app/template/components/posts_taxonomy.tpl@@ -6,7 +6,7 @@ $categories_count = 0;$_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [0 => []] : [];$_default = [0 => []];-$_categories = $posts['categories'] ?? $_default : $posts['categories'];+$_categories = $posts['categories'] ?? $_default;$categories = count($post['categories']);?>@@ -27,7 +27,7 @@ $categories_count = 0;$_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [0 => []] : [];$_default = [0 => []];-$_tags = $posts['tags'] ?? $_default : $posts['tags'];+$_tags = $posts['tags'] ?? $_default;$tags = count($post['tags']);?>@post [data-v-post-tags] [data-v-post-tags-tag]|before = <?phpdiff --git a/app/template/components/product.tpl b/app/template/components/product.tplindex c5cc18f..04e1569 100755--- a/app/template/components/product.tpl+++ b/app/template/components/product.tpl@@ -21,22 +21,24 @@ $_pagination_limit = isset($product['limit']) ? $product['limit'] : 5;@product|data-v-id = $product['product_id']//manual echo to avoid html escape-@product [data-v-product-content] = <?php echo($product['content']);?>+@product [data-v-product-content] = <?php echo($product['content'] ?? '');?>//catch all data attributes-@product [data-v-product-*]|innerText = $product['@@__data-v-product-(*)__@@']+@product [data-v-product-*]:not(a):not(button)|innerText = $product['@@__data-v-product-(*)__@@']+@product a[data-v-product-*]:empty|innerText = $product['@@__data-v-product-(*)__@@']+@product button[data-v-product-*]:empty|innerText = $product['@@__data-v-product-(*)__@@']++@product input[data-v-product-*]|value = $product['@@__data-v-product-(*)__@@']@product a[data-v-product-*]|href = $product['@@__data-v-product-(*)__@@']-@product button[data-v-product-*]|formaction = $product['@@__data-v-product-(*)__@@']-@product a[data-v-product-*]|href = $product['@@__data-v-product-(*)__@@']@product [name="product_variant_id"] = $product['product_variant_id']@product img[data-v-product-main-image]|src = $product['image']@product [data-v-product-main-image-background-image]|style = <?php echo 'background-image: url(\'' . $product['image'] . '\');';?>-@product a[data-v-product-main-image]|href = <?php echo reset($product['images'])['image'];?>+@product a[data-v-product-main-image]|href = <?php echo $product['images'] ? reset($product['images'])['image'] : '';?>@images [data-v-product-image]|deleteAllButFirstChild@@ -63,7 +65,7 @@ if($_images) {}}-$component = $previous_component;+$current_component = $component = $previous_component;?>diff --git a/app/template/components/product/categories.tpl b/app/template/components/product/categories.tplold mode 100644new mode 100755index 3676e71..5bc059b--- a/app/template/components/product/categories.tpl+++ b/app/template/components/product/categories.tpl@@ -30,7 +30,7 @@ $previous_component = isset($current_component)?$current_component:null;$product_categories = $current_component = $this->_component['product_categories'][$_product_categories_idx] ?? [];$_categories = $product_categories['categories'] ?? [];-$_pagination_count = $product_categories['count'] ?? 0;+$_pagination_count = $count = $product_categories['count'] ?? count($_categories);$_pagination_limit = isset($product_categories['limit']) ? $product_categories['limit'] : 5;$parent = 0;$generate_menu = false;diff --git a/app/template/components/product/category.tpl b/app/template/components/product/category.tplnew file mode 100755index 0000000..5e0ac16--- /dev/null+++ b/app/template/components/product/category.tpl@@ -0,0 +1,22 @@+//set component variables+[data-v-component-product-category]|prepend = <?php+ $vvveb_is_page_edit = Vvveb\isEditor();++ //use a counter to know which component instance we need to use if there are more than one component on page+ if (isset($product_category_idx)) $product_category_idx++; else $product_category_idx = 0;+ $previous_component = isset($current_component)?$current_component:null;+ $component = $current_component = $this->_component['product_category'][$product_category_idx] ?? [];++ $index = 0;+ $count = $component['count'] ?? 0;+ $limit = isset($component['limit'])? $component['limit'] : 5;++ //if page loaded in editor then set a fist empty category if there are no categories+ //to render an empty category to avoid losing the html on edit+ $_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [0 => []] : false;+ //$_default = [0 => []];+ $_category = empty($component) ? $_default : $component;+?>++//catch all data attributes+[data-v-component-product-category] [data-v-category-*] = $_category['@@__data-v-category-(*)__@@']diff --git a/app/template/components/products.tpl b/app/template/components/products.tplindex 928ab93..d4fd62c 100755--- a/app/template/components/products.tpl+++ b/app/template/components/products.tpl@@ -13,30 +13,33 @@//use a counter to know which component instance we need to use if there are more than one component on pageif (isset($products_idx)) $products_idx++; else $products_idx = 0;$previous_component = isset($current_component)?$current_component:null;- $products = $current_component = $this->_component['products'][$products_idx] ?? [];+ $component = $current_component = $this->_component['products'][$products_idx] ?? [];$index = 0;- $count = $products['count'] ?? 0;- $limit = isset($products['limit'])? $products['limit'] : 5;+ $count = $component['count'] ?? 0;+ $limit = isset($component['limit'])? $component['limit'] : 5;//if page loaded in editor then set a fist empty product if there are no products//to render an empty product to avoid losing the html on edit$_default = (isset($vvveb_is_page_edit) && $vvveb_is_page_edit ) ? [0 => []] : false;//$_default = [0 => []];- $prods = empty($products['product']) ? $_default : $products['product'];+ $products = empty($component['product']) ? $_default : $component['product'];?>-@products [data-v-products-category] = <?php $_category = current($products);echo htmlspecialchars($_category['category']);?>-@products [data-v-products-count] = $products['count']-@products [data-v-products-manufacturer] = <?php $_manufacturer = current($products);echo htmlspecialchars($_manufacturer['manufacturer']);?>+@products [data-v-products-category] = <?php $_category = current($component);echo htmlspecialchars($_category['category']);?>+@products [data-v-products-count] = $component['count']+@products [data-v-products-manufacturer] = <?php $_manufacturer = current($component);echo htmlspecialchars($_manufacturer['manufacturer']);?>@product|before = <?php-if ($prods) {- foreach ($prods as $id => $prod) { ?>+if ($products) {+ foreach ($products as $id => $prod) { ?>- @product [data-v-product-*]|innerText = $prod['@@__data-v-product-(*)__@@']+ //catch all data attributes+ @product [data-v-product-*]:not(a):not(button)|innerText = $prod['@@__data-v-product-(*)__@@']+ @product a[data-v-product-*]:empty|innerText = $prod['@@__data-v-product-(*)__@@']+ @product button[data-v-product-*]:empty|innerText = $prod['@@__data-v-product-(*)__@@']@product a[data-v-product-*]|href = $prod['@@__data-v-product-(*)__@@']@@ -102,19 +105,17 @@ if ($prods) {//image gallery@product [data-v-product-images] [data-v-product-image]|before = <?phpif(isset($prod['images']) && is_array($prod['images']))- foreach ($prod['images'] as $prod_image_id => $image) {- ?>+ foreach ($prod['images'] as $prod_image_id => $image) { ?>@product [data-v-product-images] img[data-v-product-image-src]|src = $image['image']@product [data-v-product-images] img[data-v-product-image-src]|data-v-id = $prod_image_id@product [data-v-product-images] img[data-v-product-image-src]|data-v-type = 'product_image'@product [data-v-product-images] a[data-v-product-image-src]|href = $image['image']- @product [data-v-product-images] [data-v-product-image]|after = <?php- } ?>+ @product [data-v-product-images] [data-v-product-image]|after = <?php+ }+ ?>- //catch all data attributes- @product [data-v-product-*]|innerText = $prod['@@__data-v-product-(*)__@@']//echo description directly to avoid htmlspecialchars escape@product [data-v-product-content] = <?php echo($prod['content']);?>diff --git a/app/template/components/questions.tpl b/app/template/components/questions.tplold mode 100644new mode 100755index 8cc5a6f..49443d3--- a/app/template/components/questions.tpl+++ b/app/template/components/questions.tpl@@ -31,7 +31,7 @@ if($questions && is_array($questions)) {@question [data-v-question-content] = $question['content']@question img[data-v-question-*]|src = $question['@@__data-v-question-(*)__@@']- @question img[data-v-question-avatar]|width = <?php echo (int)($review['size'] ?? 60);?>+ @question img[data-v-question-avatar]|width = <?php echo (int)($question['size'] ?? 60);?>@question [data-v-question-*]|innerText = $question['@@__data-v-question-(*)__@@']@@ -40,4 +40,4 @@ if($questions && is_array($questions)) {@question|after = <?php}}-?>\ No newline at end of file+?>diff --git a/app/template/components/search.tpl b/app/template/components/search.tpldeleted file mode 100755index 45b469e..0000000--- a/app/template/components/search.tpl+++ /dev/null@@ -1,25 +0,0 @@-[data-v-component-search] [data-v-product]|deleteAllButFirstChild--[data-v-component-search]|prepend = <?php-if (isset($_search_idx)) $_search_idx++; else $_search_idx = 0;-$previous_component = isset($current_component)?$current_component:null;-$search = $current_component = $this->_component['search'][$_search_idx] ?? [];-$searchTabBtnNo = 0;-$searchTabNo = 0;-//$_pagination_count = $search['count'];-//$_pagination_limit = isset($search['limit'])? $search['limit'] : 5;-?>--#nav-search|prepend = <?php-$searchTabBtnNo = 0;-$searchTabNo = 0;-?>--#nav-search .nav-link|addClass = <?php-- if ($searchTabBtnNo++ == 0) echo 'active';-?>--#nav-searchContent .tab-pane|addClass = <?php- if ($searchTabNo++ == 0) echo 'active';-?>\ No newline at end of filediff --git a/app/template/components/user/address.tpl b/app/template/components/user/address.tplindex 3512b87..1329893 100755--- a/app/template/components/user/address.tpl+++ b/app/template/components/user/address.tpl@@ -1,5 +1,5 @@@addresscomp = [data-v-component-user-address]-@address = [data-v-component-user-address] [data-v-user_address]+@address = [data-v-component-user-address] [data-v-user_address]@address|deleteAllButFirstChilddiff --git a/app/template/components/user/wishlist.tpl b/app/template/components/user/wishlist.tplold mode 100644new mode 100755diff --git a/app/template/content/category.tpl b/app/template/content/category.tplold mode 100644new mode 100755index 7ab9dc9..87b2e7a--- a/app/template/content/category.tpl+++ b/app/template/content/category.tpl@@ -1,5 +1,8 @@import(common.tpl)-head > title = $this->category['title']-[data-v-category-*]|innerText = $this->category['@@__data-v-category-(*)__@@']-img[data-v-category-*]|src = $this->category['@@__data-v-category-(*)__@@']\ No newline at end of file+head > title = $this->category['title']+head > meta[name="keywords"]|content = $this->category['meta_keywords']+head > meta[name="description"]|content = $this->category['meta_description']+[data-v-category-*]|innerText = $this->category['@@__data-v-category-(*)__@@']+img[data-v-category-*]|src = $this->category['@@__data-v-category-(*)__@@']+img[data-v-category-*]|alt = $this->category['meta_description']diff --git a/app/template/editor.tpl b/app/template/editor.tplindex 11b7bdb..4a9164a 100755--- a/app/template/editor.tpl+++ b/app/template/editor.tpl@@ -3,11 +3,16 @@ head|append = <?php$vvveb_is_page_edit = Vvveb\isEditor();$is_admin = \Vvveb\isAdmin();if ($is_admin && $vvveb_is_page_edit) {- $customCssFile = DIR_THEMES . Vvveb\System\Sites::getTheme() . DS . 'css'. DS . 'custom.css';++ $theme = $_GET['theme'] ?? Vvveb\System\Sites::getTheme();+ $customCssFile = DIR_THEMES . $theme . DS . 'css'. DS . 'custom.css';+ $css = '';+if (file_exists($customCssFile)) {- $css = file_get_contents($customCssFile);//'body {background:red}';- echo "<style id=\"vvvebjs-styles\">$css</style>";+ $css = file_get_contents($customCssFile);}++ echo "<style id=\"vvvebjs-styles\">$css</style>";if (isset($_GET['preview'])) {echo '<link data-vvveb-helpers href="' . PUBLIC_PATH . 'css/vvvebjs-editor-helpers.css" rel="stylesheet">';@@ -19,6 +24,6 @@ if ($is_admin && $vvveb_is_page_edit) {body|prepend = <?phpif (isset($is_admin) && $is_admin && !$vvveb_is_page_edit && APP == 'app') {- include_once(DIR_ROOT . '/admin/admin-bar.php');+ include_once(DIR_ROOT . '/admin/admin-bar.php');}?>diff --git a/app/template/email/order/update.txt.tpl b/app/template/email/order/update.txt.tplnew file mode 100755index 0000000..feb4787--- /dev/null+++ b/app/template/email/order/update.txt.tpl@@ -0,0 +1,3 @@+import(email/common.tpl)++[data-v-message] = $this->messagediff --git a/app/template/error404.tpl b/app/template/error404.tplindex ed374e4..3b5f25b 100755--- a/app/template/error404.tpl+++ b/app/template/error404.tpl@@ -18,3 +18,4 @@ foreach ($this->lines as $index => $line) {?>body|prepend = <?php $debug = defined('DEBUG') && DEBUG;?>[data-debug]|if_exists = $debug+[data-no-debug]|if_exists = <?php (!$debug) ?>diff --git a/app/template/error500.tpl b/app/template/error500.tplindex dc84744..1e9844e 100755--- a/app/template/error500.tpl+++ b/app/template/error500.tpl@@ -29,3 +29,4 @@ if (isset($lines) && is_array($lines)) {body|prepend = <?php $debug = defined('DEBUG') && DEBUG;?>[data-debug]|if_exists = $debug+[data-no-debug]|if_exists = <?php (!$debug) ?>diff --git a/app/template/notifications.tpl b/app/template/notifications.tplindex 3b12f44..9743033 100755--- a/app/template/notifications.tpl+++ b/app/template/notifications.tpl@@ -14,7 +14,7 @@ if (isset($this->errors) && is_array($this->errors)) {foreach ($list as $message) {?>- @error [data-v-notification-text] = <?php echo($message);?>+ @error [data-v-notification-text] = $message@error|after = <?php}@@ -36,7 +36,7 @@ if (isset($this->success) && is_array($this->success)) {foreach ($list as $message) {?>- @success [data-v-notification-text] = <?php echo($message);?>+ @success [data-v-notification-text] = $message@success|after = <?php}@@ -58,7 +58,7 @@ if (isset($this->info) && is_array($this->info)) {foreach ($list as $message) {?>- @info [data-v-notification-text] = <?php echo($message);?>+ @info [data-v-notification-text] = $message@info|after = <?php}@@ -72,7 +72,7 @@ if (isset($this->info) && is_array($this->info)) {$type = '@@__data-v-type__@@';if (isset($this->message) && is_array($this->message)) {foreach($this->message as $id => $list) {- if (!empty($type) && $id != $type) continue;+ if (!empty($type) && $id != $type && !$vvveb_is_page_edit) continue;if (!is_array($list)) {$list = [$list];@@ -80,7 +80,7 @@ if (isset($this->message) && is_array($this->message)) {foreach ($list as $message) {?>- @message [data-v-notification-text] = <?php echo($message);?>+ @message [data-v-notification-text] = $message@message|after = <?php}diff --git a/app/template/pagination.tpl b/app/template/pagination.tplold mode 100644new mode 100755index d9a3b71..437b0f3--- a/app/template/pagination.tpl+++ b/app/template/pagination.tpl@@ -10,7 +10,7 @@ $parameters = [];//@@__data-v-parameters__@@;if ($query_string) {$query_string = ($_SERVER['QUERY_STRING'] ?? '');- $query_string = $query_string ? "?$query_string" : '';+ $query_string = $query_string ? '?' . htmlspecialchars($query_string) : '';}if ($parent_component) {@@ -48,19 +48,15 @@ $current_page = max($current_page, 1);if ($pagecount > $maxpages){- if ($current_page > $visible_pages)- {- if (($current_page + $visible_pages) > $pagecount)- {+ if ($current_page > $visible_pages) {+ if (($current_page + $visible_pages) > $pagecount) {$page = $pagecount - $visible_pages - 1;$page_stop = $pagecount;- } else- {+ } else {$page = $current_page - $visible_pages;$page_stop = $current_page + $visible_pages;}- } else- {+ } else {$page = 1;$page_stop = $maxpages;}diff --git a/app/template/product/category.tpl b/app/template/product/category.tplold mode 100644new mode 100755index 7ab9dc9..08cfae0--- a/app/template/product/category.tpl+++ b/app/template/product/category.tpl@@ -1,5 +1 @@-import(common.tpl)--head > title = $this->category['title']-[data-v-category-*]|innerText = $this->category['@@__data-v-category-(*)__@@']-img[data-v-category-*]|src = $this->category['@@__data-v-category-(*)__@@']\ No newline at end of file+import(content/category.tpl)diff --git a/app/template/user/subscription.tpl b/app/template/user/subscription.tplnew file mode 100755index 0000000..9410e69--- /dev/null+++ b/app/template/user/subscription.tpl@@ -0,0 +1,56 @@+import(common.tpl)++[data-v-subscription-*]|innerText = $this->subscription['@@__data-v-subscription-(*)__@@']++//action buttons — only show relevant actions based on current status+form[data-v-action-cancel]|action = <?php echo Vvveb\url('user/subscription/cancel', ['subscription_id' => $this->subscription['subscription_id'] ?? 0]);?>+form[data-v-action-swap]|action = <?php echo Vvveb\url('user/subscription/swap', ['subscription_id' => $this->subscription['subscription_id'] ?? 0]);?>+form[data-v-action-skip]|action = <?php echo Vvveb\url('user/subscription/skip', ['subscription_id' => $this->subscription['subscription_id'] ?? 0]);?>++//swap plan selector+@plan = [data-v-plans] option[data-v-plan]+@plan|deleteAllButFirstChild++@plan|before = <?php+$plans = $this->plans ?? [];+$currentPlan = $this->subscription['subscription_plan_id'] ?? 0;+if (is_array($plans)) foreach ($plans as $index => $plan) {?>++ @plan|innerText = $plan['name']+ @plan|value = $plan['subscription_plan_id']+ @plan|addNewAttribute = <?php if (($plan['subscription_plan_id'] ?? 0) == $currentPlan) echo 'selected';?>++@plan|after = <?php }?>+form[data-v-action-pause]|action = <?php echo Vvveb\url('user/subscription/pause', ['subscription_id' => $this->subscription['subscription_id'] ?? 0]);?>+form[data-v-action-resume]|action = <?php echo Vvveb\url('user/subscription/resume', ['subscription_id' => $this->subscription['subscription_id'] ?? 0]);?>++//action button visibility is handled in markup via data-v-if conditions++//status badge class+[data-v-subscription-status_name]|addClass = <?php+$statusId = $this->subscription['subscription_status_id'] ?? 0;+echo match((int)$statusId) {+ 1 => 'badge bg-warning text-dark',+ 2 => 'badge bg-success',+ 3 => 'badge bg-danger',+ 4 => 'badge bg-secondary',+ 5 => 'badge bg-danger',+ 6 => 'badge bg-dark',+ default => 'badge bg-info',+};+?>++//subscription logs/history+@subscription_logs = [data-v-subscription-logs] [data-v-subscription-log]+@subscription_logs|deleteAllButFirstChild++@subscription_logs|before = <?php+if (isset($this->subscription_logs) && is_array($this->subscription_logs)) {+ foreach ($this->subscription_logs as $log) { ?>++ @subscription_logs [data-v-subscription-log-*]|innerText = $log['@@__data-v-subscription-log-(*)__@@']++ @subscription_logs|after = <?php+ }+} ?>+diff --git a/app/template/user/subscriptions.tpl b/app/template/user/subscriptions.tplnew file mode 100755index 0000000..760b637--- /dev/null+++ b/app/template/user/subscriptions.tpl@@ -0,0 +1,38 @@+import(common.tpl)+import(pagination.tpl)++@subscriptions = [data-v-subscriptions] [data-v-subscription]+@subscriptions|deleteAllButFirstChild++@subscriptions|before = <?php+$count = 0;+if (isset($this->subscriptions) && is_array($this->subscriptions)) {+ foreach ($this->subscriptions as $index => $subscription) { ?>++ @subscriptions [data-v-subscription-subscription_id]|innerText = $subscription['subscription_id']+ @subscriptions [data-v-subscription-subscription_id]|href = <?php echo Vvveb\url('user/subscription/index', ['subscription_id' => $subscription['subscription_id']]);?>+ @subscriptions [data-v-subscription-view]|href = <?php echo Vvveb\url('user/subscription/index', ['subscription_id' => $subscription['subscription_id']]);?>++ @subscriptions [data-v-subscription-*]|innerText = $subscription['@@__data-v-subscription-(*)__@@']+ @subscriptions [data-v-subscription-product_name]|href = <?php echo Vvveb\url('product/product/index', ['slug' => $subscription['product_slug']]);?>+++ //status badge classes+ @subscriptions [data-v-subscription-status_name]|addClass = <?php+ $statusId = $subscription['subscription_status_id'] ?? 0;+ echo match((int)$statusId) {+ 1 => 'badge bg-warning text-dark',+ 2 => 'badge bg-success',+ 3 => 'badge bg-danger',+ 4 => 'badge bg-secondary',+ 5 => 'badge bg-danger',+ 6 => 'badge bg-dark',+ default => 'badge bg-info',+ };+ ?>++ @subscriptions|after = <?php+ $count++;+ }+} ?>+diff --git a/app/validate/card.php b/app/validate/card.phpold mode 100644new mode 100755index c2bbd35..b3bbe67--- a/app/validate/card.php+++ b/app/validate/card.php@@ -22,19 +22,19 @@return ['card.number' => [- 'notEmpty' => '',- 'maxLength' => 19,+ 'notEmpty' => '',+ 'maxLength' => 19,],'card.expiryMonth' => [- 'notEmpty' => '',- 'maxLength' => 2,+ 'notEmpty' => '',+ 'maxLength' => 2,],'card.expiryYear' => [- 'notEmpty' => '',- 'maxLength' => 2,+ 'notEmpty' => '',+ 'maxLength' => 2,],'card.cvv' => [- 'notEmpty' => '',- 'maxLength' => 4,+ 'notEmpty' => '',+ 'maxLength' => 4,],];diff --git a/app/validate/checkout.php b/app/validate/checkout.phpindex 3afd72f..db6e603 100755--- a/app/validate/checkout.php+++ b/app/validate/checkout.php@@ -22,12 +22,12 @@return ['shipping_method' => [- 'notEmpty' => '',+ 'notEmpty' => '',],'payment_method' => [- 'notEmpty' => '',+ 'notEmpty' => '',],'notes' => [- 'optional' => '',+ 'optional' => '',],];diff --git a/app/validate/checkout_billing.php b/app/validate/checkout_billing.phpindex 19f7dca..fe8761d 100755--- a/app/validate/checkout_billing.php+++ b/app/validate/checkout_billing.php@@ -24,18 +24,18 @@ use function Vvveb\__;return ['billing_address.first_name' => [- ['notEmpty' => '',- 'message' => '%s must not be empty', ],+ ['notEmpty' => '',+ 'message' => '%s must not be empty', ],- ['maxLength' => 100,- 'message' => __('%s must not be greater than 100'), ],+ ['maxLength' => 100,+ 'message' => __('%s must not be greater than 100'), ],],'billing_address.last_name' => [- ['notEmpty' => '',- 'message' => '%s must not be empty', ],+ ['notEmpty' => '',+ 'message' => '%s must not be empty', ],- ['maxLength' => 100,- 'message' => __('%s must not be greater than 100'), ],+ ['maxLength' => 100,+ 'message' => __('%s must not be greater than 100'), ],],/*'billing_address.company' => [@@ -46,40 +46,40 @@ return ['message' => __('%s must not be greater than 100'), ],],*/'billing_address.address_1' => [- ['notEmpty' => '',- 'message' => '%s must not be empty', ],+ ['notEmpty' => '',+ 'message' => '%s must not be empty', ],- ['maxLength' => 100,- 'message' => __('%s must not be greater than 100'), ],+ ['maxLength' => 100,+ 'message' => __('%s must not be greater than 100'), ],],'billing_address.address_2' => [- ['notEmpty' => '',- 'message' => '%s must not be empty', ],+ ['notEmpty' => '',+ 'message' => '%s must not be empty', ],- ['maxLength' => 100,- 'message' => __('%s must not be greater than 100'), ],+ ['maxLength' => 100,+ 'message' => __('%s must not be greater than 100'), ],],'billing_address.city' => [- ['notEmpty' => '',- 'message' => '%s must not be empty', ],+ ['notEmpty' => '',+ 'message' => '%s must not be empty', ],- ['maxLength' => 100,- 'message' => __('%s must not be greater than 100'), ],+ ['maxLength' => 100,+ 'message' => __('%s must not be greater than 100'), ],],'billing_address.post_code' => [- ['notEmpty' => '',- 'message' => '%s must not be empty', ],+ ['notEmpty' => '',+ 'message' => '%s must not be empty', ],- ['maxLength' => 100,- 'message' => __('%s must not be greater than 100'), ],+ ['maxLength' => 100,+ 'message' => __('%s must not be greater than 100'), ],],'billing_address.country_id' => [- ['notEmpty' => '',- 'message' => '%s must not be empty', ],+ ['notEmpty' => '',+ 'message' => '%s must not be empty', ],],'billing_address.region_id' => [- ['notEmpty' => '',- 'message' => '%s must not be empty', ],+ ['notEmpty' => '',+ 'message' => '%s must not be empty', ],],/*'billing_address.phone_number' => [diff --git a/app/validate/checkout_shipping.php b/app/validate/checkout_shipping.phpindex 3cc0072..4b31d90 100755--- a/app/validate/checkout_shipping.php+++ b/app/validate/checkout_shipping.php@@ -24,18 +24,18 @@ use function Vvveb\__;return ['shipping_address.first_name' => [- ['notEmpty' => '',- 'message' => '%s must not be empty', ],+ ['notEmpty' => '',+ 'message' => '%s must not be empty', ],- ['maxLength' => 100,- 'message' => __('%s must not be greater than 100'), ],+ ['maxLength' => 100,+ 'message' => __('%s must not be greater than 100'), ],],'shipping_address.last_name' => [- ['notEmpty' => '',- 'message' => '%s must not be empty', ],+ ['notEmpty' => '',+ 'message' => '%s must not be empty', ],- ['maxLength' => 100,- 'message' => __('%s must not be greater than 100'), ],+ ['maxLength' => 100,+ 'message' => __('%s must not be greater than 100'), ],], /*'shipping_address.company' => [['notEmpty' => '',@@ -45,39 +45,39 @@ return ['message' => __('%s must not be greater than 100'), ],],*/'shipping_address.address_1' => [- ['notEmpty' => '',- 'message' => '%s must not be empty', ],+ ['notEmpty' => '',+ 'message' => '%s must not be empty', ],- ['maxLength' => 100,- 'message' => __('%s must not be greater than 100'), ],+ ['maxLength' => 100,+ 'message' => __('%s must not be greater than 100'), ],],'shipping_address.address_2' => [- ['notEmpty' => '',- 'message' => '%s must not be empty', ],+ ['notEmpty' => '',+ 'message' => '%s must not be empty', ],- ['maxLength' => 100,- 'message' => __('%s must not be greater than 100'), ],+ ['maxLength' => 100,+ 'message' => __('%s must not be greater than 100'), ],],'shipping_address.city' => [- ['notEmpty' => '',- 'message' => '%s must not be empty', ],+ ['notEmpty' => '',+ 'message' => '%s must not be empty', ],- ['maxLength' => 100,- 'message' => __('%s must not be greater than 100'), ],+ ['maxLength' => 100,+ 'message' => __('%s must not be greater than 100'), ],],'shipping_address.post_code' => [- ['notEmpty' => '',- 'message' => '%s must not be empty', ],+ ['notEmpty' => '',+ 'message' => '%s must not be empty', ],- ['maxLength' => 100,- 'message' => __('%s must not be greater than 100'), ],+ ['maxLength' => 100,+ 'message' => __('%s must not be greater than 100'), ],],'shipping_address.country_id' => [- ['notEmpty' => '',- 'message' => '%s must not be empty', ],+ ['notEmpty' => '',+ 'message' => '%s must not be empty', ],],'shipping_address.region_id' => [- ['notEmpty' => '',- 'message' => '%s must not be empty', ],+ ['notEmpty' => '',+ 'message' => '%s must not be empty', ],],];diff --git a/app/validate/checkout_signup.php b/app/validate/checkout_signup.phpold mode 100644new mode 100755index e5349de..def7763--- a/app/validate/checkout_signup.php+++ b/app/validate/checkout_signup.php@@ -22,20 +22,24 @@return ['first_name' => [- 'notEmpty' => '',- 'maxLength' => 100,+ 'notEmpty' => '',+ 'maxLength' => 100,],'last_name' => [- 'notEmpty' => '',- 'maxLength' => 100,+ 'notEmpty' => '',+ 'maxLength' => 100,],'email' => [- 'notEmpty' => '',- 'maxLength' => 100,+ 'notEmpty' => '',+ 'maxLength' => 100,],'password' => [//'passwordComplexity' => 'low',- 'minLength' => 6,- 'maxLength' => 32,+ 'minLength' => 6,+ 'maxLength' => 32,+ ],+ 'phone_number' => [+ 'notEmpty' => '',+ 'maxLength' => 100,],];diff --git a/app/validate/guest.php b/app/validate/guest.phpindex 4da21bf..4bc75be 100755--- a/app/validate/guest.php+++ b/app/validate/guest.php@@ -22,19 +22,19 @@return ['first_name' => [- 'notEmpty' => '',- 'maxLength' => 100,+ 'notEmpty' => '',+ 'maxLength' => 100,],'last_name' => [- 'notEmpty' => '',- 'maxLength' => 100,+ 'notEmpty' => '',+ 'maxLength' => 100,],'email' => [- 'notEmpty' => '',- 'maxLength' => 100,+ 'notEmpty' => '',+ 'maxLength' => 100,],'phone_number' => [- 'notEmpty' => '',- 'maxLength' => 100,+ 'notEmpty' => '',+ 'maxLength' => 100,],];diff --git a/app/validate/login.php b/app/validate/login.phpindex bc29a2c..ee1ab6c 100755--- a/app/validate/login.php+++ b/app/validate/login.php@@ -26,11 +26,11 @@ return [],'password' => ['maxLength' => 100,- ],+ ], /*'csrf' => ['session' => 'csrf',- ],- /*+ ],*/+ /*'captcha' => [['captcha' => ''],], */diff --git a/app/validate/signup.php b/app/validate/signup.phpindex dbaca16..5d8850c 100755--- a/app/validate/signup.php+++ b/app/validate/signup.php@@ -32,19 +32,19 @@ return [],*/'username' => [- 'notEmpty' => '',- 'maxLength' => 100,+ 'notEmpty' => '',+ 'maxLength' => 100,],'email' => [- 'notEmpty' => '',- 'maxLength' => 100,+ 'notEmpty' => '',+ 'maxLength' => 100,],'password' => [//'passwordComplexity' => 'low',- 'minLength' => 6,- 'maxLength' => 32,+ 'minLength' => 6,+ 'maxLength' => 32,],'confirm_password' => [- 'match' => 'password',+ 'match' => 'password',],];diff --git a/app/controller/cart/wishlist.php b/app/validate/user.phpsimilarity index 59%rename from app/controller/cart/wishlist.phprename to app/validate/user.phpindex c20382b..6424b13 100755--- a/app/controller/cart/wishlist.php+++ b/app/validate/user.php@@ -20,15 +20,34 @@**/-namespace Vvveb\Controller\Cart;+return [+ /*+ 'username' => [+ 'notEmpty' => ''/*,+ 'maxLength' => 60 /*,+ ],+*/+ 'display_name' => [+ 'notEmpty' => ''/*,+ 'message' => '%s must not be empty'*/,-use Vvveb\Controller\Base;--class Wishlist extends Base {- function index() {- }-- function add() {- $productId = $this->request->request['product_id'];- }-}+ 'maxLength' => 255 /*,+ 'message' => __('%s must not be greater than %d')*/,+ ],+ 'first_name' => [+ 'notEmpty' => '',+ 'maxLength' => 32,+ ],+ 'last_name' => [+ 'notEmpty' => '',+ 'maxLength' => 32,+ ],+ 'email' => [+ 'email' => '',+ 'maxLength' => 100,+ ],+ /*+ 'captcha' => [+ ['captcha' => ''],+ ], */+];