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
Wildcard search if only search has only one word
givanzc411e339386a
diff --git a/app/component/posts.php b/app/component/posts.phpindex bf630f3..792e09c 100644--- a/app/component/posts.php+++ b/app/component/posts.php@@ -23,7 +23,6 @@namespace Vvveb\Component;use function Vvveb\__;-use function Vvveb\availableLanguages;use function Vvveb\get;use function Vvveb\getSetting;use function Vvveb\siteSettings;@@ -43,7 +42,7 @@ class Posts extends ComponentBase {'type' => 'post','site_id' => null,'start' => null,- 'limit' => ['url', 8],+ 'limit' => ['url', 4],'order_by' => 'post_id','direction' => 'desc','status' => 'publish',@@ -53,7 +52,7 @@ class Posts extends ComponentBase {'taxonomy_item_id' => NULL,'taxonomy_item_slug' => NULL,'search' => NULL,- 'search_boolean' => true,+ 'search_boolean' => NULL,'like' => NULL,'admin_id' => NULL,//archive@@ -94,7 +93,7 @@ class Posts extends ComponentBase {}function cacheKey() {- if (isset($this->options['search'])) {+ if (isset($this->options['search']) || isset($this->options['page']) || isset($this->options['post_id'])) {return false;}@@ -104,18 +103,15 @@ class Posts extends ComponentBase {function results() {$posts = new PostSQL();- if (! isset($this->options['page']) && ! isset($this->options['start'])) {- $this->options['page'] = 1;- }+ $this->options['limit'] = (int) ($this->options['limit'] ?? 4 ?: 4);- if ($page = ($this->options['page'] ?? false)) {- $this->options['start'] = ($page - 1) * ((int) ($this->options['limit'] ?? 4));- }- /*- if ($this->options['limit'] && ! $page) {- $this->options['start'] = 0;+ if (($page = $this->options['page'] ?? false) && is_numeric($page)) {+ $this->options['start'] = ($page - 1) * ($this->options['limit']);}- */++ $this->options['start'] = (int) ($this->options['start'] ?? 0 ?: 0);++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 {@@ -132,6 +128,11 @@ class Posts extends ComponentBase {unset($this->options['direction']);}+ //wildcard search for one word search+ if (isset($this->options['search']) && strpos($this->options['search'], ' ') == false) {+ $this->options['search_boolean'] = true;+ }+if (isset($this->options['search']) && isset($this->options['search_boolean'])) {$this->options['search'] .= '*';}@@ -147,12 +148,11 @@ class Posts extends ComponentBase {}$results = $posts->getAll($this->options);- //$languages = availableLanguages();$this->options['type'] = $this->options['type'] ?: 'post';if (! isset($this->options['date_format'])) {$site = siteSettings();- $this->options['date_format'] = $site['date_format'];+ $this->options['date_format'] = $site['date_format'] ?? 'human';}if ($results && isset($results['post'])) {@@ -192,7 +192,7 @@ class Posts extends ComponentBase {($this->options['page'] > 1) &&(isset($this->options['404']) && $this->options['404']) &&! $_SERVER['QUERY_STRING']) {- $results['404'] = true;+ $results['404'] = true;}list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);diff --git a/app/component/products.php b/app/component/products.phpindex ab9c1f1..d8d99ba 100755--- a/app/component/products.php+++ b/app/component/products.php@@ -25,7 +25,6 @@ namespace Vvveb\Component;use Vvveb\System\Component\ComponentBase;use Vvveb\System\Event;use Vvveb\System\Traits\Product;-use function Vvveb\url;class Products extends ComponentBase {use Product;@@ -34,37 +33,37 @@ class Products extends ComponentBase {'start' => 0,'page' => 1,'limit' => 4,- 'status' => 1,+ 'status' => 1, // 1 = enabled, 0 disabled'source' => 'autocomplete','language_id' => null,'site_id' => null,- 'type' => 'product',- 'parent' => null,- 'manufacturer_id' => NULL,- 'vendor_id' => NULL,- 'taxonomy_item_id' => NULL,- 'product_image' => true,- 'product_id' => [],- 'search' => null,- 'search_boolean' => true,- 'like' => null,- 'slug' => null,- 'related' => 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+ '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+ '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- '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- 'image_size' => 'medium',- 'filter' => null, //[true, false] include variants- 'variant_price' => NULL,- 'order_by' => NULL,- 'direction' => ['desc', 'asc'], //'url','asc', 'desc'- '404' => NULL,+ '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];private $tax;@@ -76,7 +75,7 @@ class Products extends ComponentBase {public $options = [];function cacheKey() {- if (isset($this->options['search'])) {+ if (isset($this->options['search']) || isset($this->options['page']) || isset($this->options['product_id'])) {return false;}@@ -86,13 +85,17 @@ class Products extends ComponentBase {function results() {$products = new \Vvveb\Sql\ProductSQL();+ $this->options['limit'] = (int) ($this->options['limit'] ?? 4 ?: 4);+if (($page = $this->options['page'] ?? false) && is_numeric($page)) {- $this->options['start'] = ($page - 1) * ((int) ($this->options['limit'] ?? 4));+ $this->options['start'] = ($page - 1) * ($this->options['limit']);}+ $this->options['start'] = (int) ($this->options['start'] ?? 0 ?: 0);+if ($this->options['filter'] ?? false) {foreach ($this->options['filter'] as $name => $values) {- if ($name == 'manufacturer_id' || $name == 'vendor_id') {+ if (in_array($name, ['attribute_id', 'option_value_id', 'field_id', 'manufacturer_id', 'vendor_id'])) {$this->options[$name] = $values;}}@@ -138,6 +141,11 @@ class Products extends ComponentBase {$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) {+ $this->options['search_boolean'] = true;+ }+if (isset($this->options['search']) && isset($this->options['search_boolean'])) {$this->options['search'] .= '*';}