Skip to content

armgit / Vvveb

Public Imported from GitHub
0

Powerful and easy to use cms to build websites, blogs or ecommerce stores.

Don't cache components that are not usually global/reused

givanz3897719fce37
diff --git a/app/component/admins.php b/app/component/admins.php
new file mode 100644
index 0000000..225a4a8
--- /dev/null
+++ b/app/component/admins.php
@@ -0,0 +1,58 @@
+<?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;
+use Vvveb\System\Images;
+use function Vvveb\url;
+
+class Admins extends ComponentBase {
+ public static $defaultOptions = [
+ 'start' => 0,
+ 'limit' => ['url', 4],
+ 'status' => 1,
+ ];
+
+ public $options = [];
+
+ function results() {
+ $admins = new \Vvveb\Sql\AdminSQL();
+
+ $results = $admins->getAll($this->options);
+
+ if (isset($results['admin'])) {
+ foreach ($results['admin'] as $id => &$admin) {
+ if (isset($admin['avatar'])) {
+ $admin['avatar_url'] = Images::image($admin['avatar'], 'admin');
+ }
+ unset($admin['password']);
+ $admin['url'] = url('content/user/index', ['admin_id' => $admin['admin_id']]);
+ }
+ }
+
+ list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);
+
+ return $results;
+ }
+}
diff --git a/app/component/checkout/payment.php b/app/component/checkout/payment.php
index e38bb88..9aee77f 100755
--- a/app/component/checkout/payment.php
+++ b/app/component/checkout/payment.php
@@ -32,6 +32,8 @@ class Payment extends ComponentBase {
'checkout' => null,
];
+ public $cacheExpire = 0; //no cache
+
function cacheKey() {
//disable caching
return false;
diff --git a/app/component/checkout/shipping.php b/app/component/checkout/shipping.php
index 498e29e..cabc807 100755
--- a/app/component/checkout/shipping.php
+++ b/app/component/checkout/shipping.php
@@ -32,6 +32,8 @@ class Shipping extends ComponentBase {
'checkout' => null,
];
+ public $cacheExpire = 0; //no cache
+
function cacheKey() {
//disable caching
return false;
diff --git a/app/component/comments.php b/app/component/comments.php
index 85cdb53..4297201 100755
--- a/app/component/comments.php
+++ b/app/component/comments.php
@@ -49,6 +49,8 @@ class Comments extends ComponentBase {
'order' => 'asc', //desc
];
+ public $cacheExpire = 0; //no cache
+
//called when fetching data, when cache expires
function results() {
$this->modelInstance = model($this->modelName); //new CommentSQL();
diff --git a/app/component/content/archives.php b/app/component/content/archives.php
index ef15862..d9f39ce 100755
--- a/app/component/content/archives.php
+++ b/app/component/content/archives.php
@@ -75,7 +75,7 @@ class Archives extends ComponentBase {
$archive['month'] = sprintf('%02d', $archive['month']);
- $archive['url'] = htmlentities(\Vvveb\url('content/archive/index', $archive));
+ $archive['url'] = htmlspecialchars(\Vvveb\url('content/archive/index', $archive));
}
list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);
diff --git a/app/component/content/tags.php b/app/component/content/tags.php
index 197e16a..ec75ac4 100644
--- a/app/component/content/tags.php
+++ b/app/component/content/tags.php
@@ -28,7 +28,7 @@ use Vvveb\System\Event;
class Tags extends ComponentBase {
public static $defaultOptions = [
'language_id' => NULL,
- 'count' => ['url', 4],
+ 'count' => NULL,
'id_manufacturer' => NULL,
'order' => ['url', 'price asc'],
'id_category' => NULL,
diff --git a/app/component/currency.php b/app/component/currency.php
index ed6b9e1..be0825d 100755
--- a/app/component/currency.php
+++ b/app/component/currency.php
@@ -23,6 +23,7 @@
namespace Vvveb\Component;
use function Vvveb\availableCurrencies;
+use function Vvveb\session;
use Vvveb\System\Component\ComponentBase;
use Vvveb\System\Event;
use Vvveb\System\Session;
@@ -44,7 +45,7 @@ class Currency extends ComponentBase {
$results['currency'] = availableCurrencies();
if (isset($results['currency']) && $results['currency']) {
- $code = Session::getInstance()->get('currency');
+ $code = session('currency');
$currency = $results['currency'][$code] ?? [];
if ($currency) {
diff --git a/app/component/digital_assets.php b/app/component/digital_assets.php
index 2d96376..d0825f4 100644
--- a/app/component/digital_assets.php
+++ b/app/component/digital_assets.php
@@ -40,6 +40,8 @@ class Digital_assets extends ComponentBase {
public $options = [];
+ public $cacheExpire = 0; //no cache
+
function results() {
$digital_asset = new Digital_assetSQL();
diff --git a/app/component/fields.php b/app/component/fields.php
new file mode 100644
index 0000000..2c90b83
--- /dev/null
+++ b/app/component/fields.php
@@ -0,0 +1,96 @@
+<?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 function Vvveb\model;
+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 $cacheExpire = 0; //no cache
+
+ function results() {
+ $model = false;
+ $field_type = trim($this->options['type'] ?? '');
+
+ if (in_array($field_type, ['post', 'product', 'user', 'order', 'taxonomy_item'])) {
+ $modelName = $field_type . '_field_value';
+ $model = model($field_type . '_field_value');
+ }
+
+ if (! $model) {
+ return [];
+ }
+
+ if (! $this->options['subtype']) {
+ unset($this->options['subtype']);
+ }
+
+ $results = $model->getAll($this->options);
+
+ if (isset($results[$modelName])) {
+ foreach ($results[$modelName] as $field_id => &$field) {
+ $field['settings'] = json_decode($field['settings'], true);
+ $field['name'] = $field['settings']['name'];
+ $field['type'] = $field['settings']['type'];
+
+ if ($field['value'] && $field['value'][0] == '{') {
+ $field['value'] = json_decode($field['value'], true);
+ }
+ }
+ }
+
+ $results['field'] = $results[$modelName] ?? [];
+ unset($results[$modelName]);
+
+ list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);
+
+ return $results;
+ }
+
+ //called on each request
+ function request(&$results, $index = 0) {
+ if (isset($this->options['field_id']) && is_array($this->options['field_id'])) {
+ $results = array_intersect_key($results, $this->options['field_id']);
+ }
+
+ return $results;
+ }
+}
diff --git a/app/component/language.php b/app/component/language.php
index f2783db..4b2b7b3 100755
--- a/app/component/language.php
+++ b/app/component/language.php
@@ -25,6 +25,7 @@ namespace Vvveb\Component;
use function Vvveb\availableLanguages;
use function Vvveb\getCurrentUrl;
use function Vvveb\isSecure;
+use function Vvveb\session;
use Vvveb\Sql\LanguageSQL;
use Vvveb\System\Cache;
use Vvveb\System\Component\ComponentBase;
@@ -68,7 +69,7 @@ class Language extends ComponentBase {
$view = View::getInstance();
if ($results) {
- $results['current'] = $code = $request->request['language'] ?? Session::getInstance()->get('language') ?? 'en_US';
+ $results['current'] = $code = $request->request['language'] ?? session('language', 'en_US');
$language = $results['language'][$code] ?? [];
if (! $language) {
diff --git a/app/component/order.php b/app/component/order.php
index e23eaeb..a28e580 100755
--- a/app/component/order.php
+++ b/app/component/order.php
@@ -41,6 +41,8 @@ class Order extends ComponentBase {
public $options = [];
+ public $cacheExpire = 0; //no cache
+
function results() {
$results = [];
diff --git a/app/component/product/attributes.php b/app/component/product/attributes.php
index 2a0776f..5fac62a 100644
--- a/app/component/product/attributes.php
+++ b/app/component/product/attributes.php
@@ -37,6 +37,8 @@ class Attributes extends ComponentBase {
'image_size' => 'thumb',
];
+ public $cacheExpire = 0; //no cache
+
function results() {
$category = new AttributeSQL();
diff --git a/app/component/product/categories.php b/app/component/product/categories.php
index 689d1f9..8181242 100755
--- a/app/component/product/categories.php
+++ b/app/component/product/categories.php
@@ -24,6 +24,7 @@ namespace Vvveb\Component\Product;
use Vvveb\System\Component\ComponentBase;
use Vvveb\System\Event;
+use Vvveb\System\Images;
use function Vvveb\url;
class Categories extends ComponentBase {
@@ -43,6 +44,8 @@ class Categories extends ComponentBase {
'parents_without_children' => false,
];
+ //public $cacheExpire = 0; //no cache
+
function results() {
$category = new \Vvveb\Sql\CategorySQL();
$results = $category->getCategories($this->options);
@@ -57,8 +60,16 @@ class Categories extends ComponentBase {
$category['children'] = 0;
}
+ if (isset($this->options['post_type'])) {
+ $category['type'] = $this->options['post_type'];
+ }
+
$category['url'] = url('product/category/index', $category);
+ if (isset($category['image'])) {
+ $category['image_url'] = Images::image($category['image'], 'taxonomy_item');
+ }
+
if ($parent_id > 0 && isset($results['categories'][$parent_id])) {
$parent = &$results['categories'][$parent_id];
diff --git a/app/component/product/manufacturers.php b/app/component/product/manufacturers.php
index 7d970a7..30abee4 100755
--- a/app/component/product/manufacturers.php
+++ b/app/component/product/manufacturers.php
@@ -43,13 +43,15 @@ class Manufacturers extends ComponentBase {
'filter' => null,
];
+ public $cacheExpire = 0; //no cache
+
function results() {
$category = new \Vvveb\Sql\ManufacturerSQL();
$results = $category->getAll($this->options);
$filter = [];
- if ($this->options['filter']) {
+ if (isset($this->options['filter'])) {
$filter = $this->options['filter']['manufacturer_id'] ?? [];
}
diff --git a/app/component/product/options.php b/app/component/product/options.php
index ac4734a..5b3c32e 100644
--- a/app/component/product/options.php
+++ b/app/component/product/options.php
@@ -44,6 +44,8 @@ class Options extends ComponentBase {
'search' => NULL,
];
+ public $cacheExpire = 0; //no cache
+
function results() {
$productSql = new ProductSQL();
$optionSql = new Product_OptionSQL();
@@ -52,7 +54,7 @@ class Options extends ComponentBase {
$product = [];
- if ($this->options['product_id']) {
+ if (isset($this->options['product_id'])) {
$product = $productSql->get(['product_id' => $this->options['product_id']]);
}
@@ -61,7 +63,7 @@ class Options extends ComponentBase {
$voptions = ['product_id' => $this->options['product_id'], 'start' => 0, 'limit' => 1];
- if ($this->options['product_variant_id']) {
+ if (isset($this->options['product_variant_id'])) {
$voptions['product_variant_id'] = [$this->options['product_variant_id']];
}
diff --git a/app/component/product/subscription/plans.php b/app/component/product/subscription/plans.php
index cd31198..8557879 100644
--- a/app/component/product/subscription/plans.php
+++ b/app/component/product/subscription/plans.php
@@ -37,6 +37,8 @@ class Plans extends ComponentBase {
'search' => NULL,
];
+ public $cacheExpire = 0; //no cache
+
function results() {
$category = new Subscription_PlanSQL();
$results = $category->getAll($this->options);
diff --git a/app/component/product/subscriptions.php b/app/component/product/subscriptions.php
index c500899..486542d 100644
--- a/app/component/product/subscriptions.php
+++ b/app/component/product/subscriptions.php
@@ -37,6 +37,8 @@ class Subscriptions extends ComponentBase {
'search' => NULL,
];
+ public $cacheExpire = 0; //no cache
+
function results() {
$category = new Product_SubscriptionSQL();
$results = $category->getAll($this->options);
diff --git a/app/component/product/variants.php b/app/component/product/variants.php
index 341cd19..bbf8328 100644
--- a/app/component/product/variants.php
+++ b/app/component/product/variants.php
@@ -41,6 +41,8 @@ class Variants extends ComponentBase {
'search' => NULL,
];
+ public $cacheExpire = 0; //no cache
+
function results() {
$productSql = new ProductSQL();
$variantSql = new Product_VariantSQL();
diff --git a/app/component/product/vendors.php b/app/component/product/vendors.php
index 0ab5c8a..7221336 100644
--- a/app/component/product/vendors.php
+++ b/app/component/product/vendors.php
@@ -49,7 +49,7 @@ class Vendors extends ComponentBase {
$filter = [];
- if ($this->options['filter']) {
+ if (isset($this->options['filter'])) {
$filter = $this->options['filter']['vendor_id'] ?? [];
}
diff --git a/app/component/questions.php b/app/component/questions.php
index 31cfaf8..a617c46 100644
--- a/app/component/questions.php
+++ b/app/component/questions.php
@@ -38,4 +38,6 @@ class Questions extends Comments {
'limit' => 10,
'order' => 'asc', //desc
];
+
+ public $cacheExpire = 0; //no cache
}
diff --git a/app/component/reviews.php b/app/component/reviews.php
index 9512fa8..d3ef806 100755
--- a/app/component/reviews.php
+++ b/app/component/reviews.php
@@ -44,6 +44,8 @@ class Reviews extends Comments {
'order' => 'asc', //desc
];
+ public $cacheExpire = 0; //no cache
+
function results() {
$results = parent::results();
diff --git a/app/component/site.php b/app/component/site.php
index e12ccee..65f1725 100755
--- a/app/component/site.php
+++ b/app/component/site.php
@@ -62,7 +62,7 @@ class Site extends ComponentBase {
} else {
}
- $results['url'] = url('index/index');
+ $results['url'] = (V_SUBDIR_INSTALL ? V_SUBDIR_INSTALL : '') . '/'; //url('index/index');
$results['full-url'] = SITE_URL; //url('index/index', $urlOptions + ['host' => '*.*.*']);
$results['site_id'] = $this->options['site_id'];
diff --git a/app/component/user/address.php b/app/component/user/address.php
index 2ef8f37..aa00458 100755
--- a/app/component/user/address.php
+++ b/app/component/user/address.php
@@ -42,7 +42,7 @@ class Address extends ComponentBase {
function results() {
$results = [];
- if ($this->options['user_id']) {
+ if (isset($this->options['user_id'])) {
$user_address = new User_AddressSQL();
$results = $user_address->getAll($this->options);
diff --git a/app/component/wishlist.php b/app/component/wishlist.php
index 5721ada..b63de20 100644
--- a/app/component/wishlist.php
+++ b/app/component/wishlist.php
@@ -46,6 +46,8 @@ class Wishlist extends ComponentBase {
public $options = [];
+ public $cacheExpire = 0; //no cache
+
function results() {
$products = new \Vvveb\Sql\User_wishlistSQL();