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
Autocomplete fix to show posts and products from all site authors/admins
givanz3e44f2681fe8
diff --git a/admin/controller/content/autocomplete-trait.php b/admin/controller/content/autocomplete-trait.phpindex c2cbbbe..3654780 100644--- a/admin/controller/content/autocomplete-trait.php+++ b/admin/controller/content/autocomplete-trait.php@@ -67,9 +67,11 @@ trait AutocompleteTrait {$search = [];- foreach ($results['manufacturer'] as $manufacturer) {- $manufacturer['image'] = Images::image($manufacturer['image'], 'manufacturer');- $search[$manufacturer['manufacturer_id']] = '<img width="32" height="32" src="' . $manufacturer['image'] . '"> ' . $manufacturer['name'];+ if (isset($results['manufacturer'])) {+ foreach ($results['manufacturer'] as $manufacturer) {+ $manufacturer['image'] = Images::image($manufacturer['image'], 'manufacturer');+ $search[$manufacturer['manufacturer_id']] = '<img width="32" height="32" src="' . $manufacturer['image'] . '"> ' . $manufacturer['name'];+ }}//echo json_encode($search);@@ -83,18 +85,20 @@ trait AutocompleteTrait {$vendors = new \Vvveb\Sql\VendorSQL();$options = [- 'start' => 0,- 'limit' => 10,- 'search' => '%' . trim($this->request->get['text']) . '%',+ 'start' => 0,+ 'limit' => 10,+ 'search' => '%' . trim($this->request->get['text']) . '%',] + $this->global;$results = $vendors->getAll($options);$search = [];- foreach ($results['vendor'] as $vendor) {- $vendor['image'] = Images::image($vendor['image'], 'vendor');- $search[$vendor['vendor_id']] = '<img width="32" height="32" src="' . $vendor['image'] . '"> ' . $vendor['name'];+ if (isset($results['vendor'])) {+ foreach ($results['vendor'] as $vendor) {+ $vendor['image'] = Images::image($vendor['image'], 'vendor');+ $search[$vendor['vendor_id']] = '<img width="32" height="32" src="' . $vendor['image'] . '"> ' . $vendor['name'];+ }}//echo json_encode($search);@@ -113,13 +117,16 @@ trait AutocompleteTrait {'search' => trim($this->request->get['text']),] + $this->global;+ unset($options['admin_id']);$results = $products->getAll($options);$search = [];- foreach ($results['products'] as $product) {- $product['image'] = Images::image($product['image'], $this->object);- $search[$product[$this->object . '_id']] = '<img width="32" height="32" src="' . $product['image'] . '"> ' . $product['name'];+ if (isset($results['products'])) {+ foreach ($results['products'] as $product) {+ $product['image'] = Images::image($product['image'], $this->object);+ $search[$product[$this->object . '_id']] = '<img width="32" height="32" src="' . $product['image'] . '"> ' . $product['name'];+ }}//echo json_encode($search);@@ -142,16 +149,18 @@ trait AutocompleteTrait {$search = [];- foreach ($results['admin'] as $admin) {- $text = '';+ if (isset($results['admin'])) {+ foreach ($results['admin'] as $admin) {+ $text = '';- if (isset($admin['avatar'])) {- $admin['avatar'] = Images::image($admin['avatar'], 'admin');- $text = '<img width="32" height="32" src="' . $admin['avatar'] . '"> ';- }- $text .= $admin['username'] . ' (' . $admin['first_name'] . ' ' . $admin['last_name'] . ')';+ if (isset($admin['avatar'])) {+ $admin['avatar'] = Images::image($admin['avatar'], 'admin');+ $text = '<img width="32" height="32" src="' . $admin['avatar'] . '"> ';+ }+ $text .= $admin['username'] . ' (' . $admin['first_name'] . ' ' . $admin['last_name'] . ')';- $search[$admin['admin_id']] = $text;+ $search[$admin['admin_id']] = $text;+ }}//echo json_encode($search);$this->response->setType('json');@@ -173,20 +182,22 @@ trait AutocompleteTrait {$search = [];- foreach ($results['attribute'] as $attribute) {- $text = '';+ if (isset($results['attribute'])) {+ foreach ($results['attribute'] as $attribute) {+ $text = '';- $text .= $attribute['name'] . ' (' . $attribute['group'] . ')';+ $text .= $attribute['name'] . ' (' . $attribute['group'] . ')';- $search[$attribute['attribute_id']] = $text;+ $search[$attribute['attribute_id']] = $text;+ }}//echo json_encode($search);$this->response->setType('json');$this->response->output($search);return false;- }-+ }+function optionValuesAutocomplete() {$values = new \Vvveb\Sql\Option_valueSQL();@@ -198,12 +209,14 @@ trait AutocompleteTrait {$search = [];- foreach ($results['option_value'] as $value) {- $text = '';+ if (isset($results['option_value'])) {+ foreach ($results['option_value'] as $value) {+ $text = '';- $text .= $value['name'];+ $text .= $value['name'];- $search[$value['option_value_id']] = $text;+ $search[$value['option_value_id']] = $text;+ }}//echo json_encode($search);$this->response->setType('json');@@ -225,12 +238,14 @@ trait AutocompleteTrait {$search = [];- foreach ($results['digital_asset'] as $digital_asset) {- $text = '';+ if (isset($results['digital_asset'])) {+ foreach ($results['digital_asset'] as $digital_asset) {+ $text = '';- $text .= $digital_asset['name'] . ' (' . $digital_asset['file'] . ')';+ $text .= $digital_asset['name'] . ' (' . $digital_asset['file'] . ')';- $search[$digital_asset['digital_asset_id']] = $text;+ $search[$digital_asset['digital_asset_id']] = $text;+ }}//echo json_encode($search);$this->response->setType('json');diff --git a/admin/controller/editor/autocomplete.php b/admin/controller/editor/autocomplete.phpindex 364c9b6..d063bc7 100755--- a/admin/controller/editor/autocomplete.php+++ b/admin/controller/editor/autocomplete.php@@ -32,91 +32,97 @@ class Autocomplete extends Base {$text = $this->request->get['text'];$options = [- 'start' => 0,- 'limit' => 10,- 'search' => '%' . $text . '%',+ 'start' => 0,+ 'limit' => 10,+ 'search' => '%' . $text . '%',] + $this->global;+ unset($options['admin_id']);$products = new \Vvveb\Sql\ProductSQL();$results = $products->getAll($options);+ $search = [];+foreach ($results['products'] as $product) {$search[$product['product_id']] = $product['name'];}$this->response->setType('json');$this->response->output($search);-- die();}function categories() {$text = $this->request->get['text'];$options = [- 'start' => 0,- 'limit' => 10,- 'search' => '%' . $text . '%',+ 'start' => 0,+ 'limit' => 10,+ 'search' => '%' . $text . '%',] + $this->global;$categories = new \Vvveb\Sql\CategorySQL();$results = $categories->getCategories($options);+ $search = [];+foreach ($results['categories'] as $category) {$search[$category['taxonomy_item_id']] = $category['name'];}$this->response->setType('json');$this->response->output($search);-- die();}function manufacturers() {$text = $this->request->get['text'];$options = [- 'start' => 0,- 'limit' => 10,- 'search' => '%' . $text . '%',+ 'start' => 0,+ 'limit' => 10,+ 'search' => '%' . $text . '%',] + $this->global;$manufacturers = new \Vvveb\Sql\ManufacturerSQL();$results = $manufacturers->getManufacturers($options);+ $search = [];+foreach ($results['manufacturers'] as $manufacturer) {$search[$manufacturer['manufacturer_id']] = $manufacturer['name'];}$this->response->setType('json');$this->response->output($search);-- die();}function posts() {- $text = $this->request->get['text'];+ $text = $this->request->get['text'];+ $type = $this->request->get['type'] ?? 'post';$options = [- 'start' => 0,- 'limit' => 10,- 'search' => '%' . $text . '%',+ 'start' => 0,+ 'limit' => 10,+ 'type' => $type,+ 'search' => $text,+ //s'like' => '%' . $text . '%',] + $this->global;- $posts = new \Vvveb\Sql\PostSQL();-+ unset($options['admin_id']);+ $posts = new \Vvveb\Sql\PostSQL();$results = $posts->getAll($options);- foreach ($results['posts'] as $post) {- $search[$post['post_id']] = substr($post['name'],0, 50);+ $search = [];++ if (isset($results['posts'])) {+ foreach ($results['posts'] as $post) {+ $search[$post['post_id']] = substr($post['name'],0, 50);+ }}$this->response->setType('json');$this->response->output($search);-- die();}function tags() {@@ -127,24 +133,24 @@ class Autocomplete extends Base {$taxonomy_itemSql = new categorySQL();$options = [- 'post_id' => $post_id,- 'language_id' => 1,- 'site_id' => 1,- 'taxonomy' => $taxonomy,- 'start' => 1,- 'limit' => 100,- 'search' => '%' . $text . '%',+ 'post_id' => $post_id,+ 'language_id' => 1,+ 'site_id' => 1,+ 'taxonomy' => $taxonomy,+ 'start' => 1,+ 'limit' => 100,+ 'search' => '%' . $text . '%',] + $this->global;$results = $taxonomy_itemSql->getCategories($options + ['taxonomy_id' => $taxonomy_id]);+ $search = [];+foreach ($results['categories'] as $id => &$taxonomy_item) {$search[$taxonomy_item['taxonomy_item_id']] = $taxonomy_item['name'];}$this->response->setType('json');$this->response->output($search);-- die();}}