Skip to content

armgit / Vvveb

Public Imported from GitHub
0

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

Include id for post and product urls to have working urls if slug changes to avoid adding redirects

givanz1f9d8eb3a779
diff --git a/admin/controller/content/autocomplete-trait.php b/admin/controller/content/autocomplete-trait.php
index 0118dfe..6c4a4bd 100644
--- a/admin/controller/content/autocomplete-trait.php
+++ b/admin/controller/content/autocomplete-trait.php
@@ -47,8 +47,6 @@ trait AutocompleteTrait {
$this->response->setType('json');
$this->response->output($search);
-
- return false;
}
function manufacturersAutocomplete() {
@@ -72,8 +70,6 @@ trait AutocompleteTrait {
$this->response->setType('json');
$this->response->output($search);
-
- return false;
}
function vendorsAutocomplete() {
@@ -97,8 +93,6 @@ trait AutocompleteTrait {
$this->response->setType('json');
$this->response->output($search);
-
- return false;
}
function urlAutocomplete() {
@@ -122,7 +116,7 @@ trait AutocompleteTrait {
'type' => 'cardimage',
'src' => $product['image'],
'text' => $product['name'],
- 'value'=> '<a href="' . url('product/product/index', ['slug'=> $product['slug']]) . '">' . $product['name'] . '</a>',
+ 'value'=> '<a href="' . url('product/product/index', ['slug'=> $product['slug'], 'product_id' => $post['product_id']]) . '">' . $product['name'] . '</a>',
];
}
}
@@ -138,12 +132,12 @@ trait AutocompleteTrait {
'type' => 'cardimage',
'src' => $post['image'],
'text' => $post['name'],
- 'value'=> '<a href="' . url('content/post/index', ['slug'=> $post['slug']]) . '">' . $post['name'] . '</a>',
+ 'value'=> '<a href="' . url('content/post/index', ['slug'=> $post['slug'], 'post_id' => $post['post_id']]) . '">' . $post['name'] . '</a>',
];
}
}
}
-
+
$this->response->setType('json');
$this->response->output($search);
}
diff --git a/admin/controller/content/edit.php b/admin/controller/content/edit.php
index 6677ea0..4aedf9b 100644
--- a/admin/controller/content/edit.php
+++ b/admin/controller/content/edit.php
@@ -181,10 +181,10 @@ class Edit extends Base {
if (isset($post[$this->object . '_content'])) {
foreach ($post[$this->object . '_content'] as &$content) {
if (! isset($post['url'])) {
- $post['url'] = \Vvveb\url($route, ['slug'=> $content['slug']] + $url);
+ $post['url'] = \Vvveb\url($route, ['slug'=> $content['slug'], 'post_id'=> $post_id] + $url);
if (! $post['url']) {
- $post['url'] = \Vvveb\url($altRoute, ['slug'=> $content['slug']] + $url);
+ $post['url'] = \Vvveb\url($altRoute, ['slug'=> $content['slug'], 'post_id'=> $post_id] + $url);
}
}
$language = [];
diff --git a/app/controller/content/page.php b/app/controller/content/page.php
index ff2f8ff..2674ea0 100755
--- a/app/controller/content/page.php
+++ b/app/controller/content/page.php
@@ -24,8 +24,4 @@ namespace Vvveb\Controller\Content;
class Page extends Post {
public $type = 'page';
-
- function index() {
- parent::index();
- }
}
diff --git a/app/controller/content/post.php b/app/controller/content/post.php
index 577ba4e..ab20cfa 100755
--- a/app/controller/content/post.php
+++ b/app/controller/content/post.php
@@ -46,16 +46,18 @@ class Post extends Base {
}
$language = $this->request->get['language'] ?? $this->global['language'] ?? $this->global['default_language'];
+ $post_id = $this->request->get['post_id'] ?? '';
$slug = $this->request->get['slug'] ?? '';
$created_at = $this->request->get['created_at'] ?? ''; //revision preview
- if ($slug) {
+ if ($post_id || $slug) {
$contentSql = new PostSQL();
- $options = $this->global + ['slug' => $slug, 'type' => $this->type];
+ $options = $this->global + ['post_id' => $post_id, 'slug' => $slug, 'type' => $this->type];
$content = $contentSql->getContent($options) ?? [];
+ $class = __NAMESPACE__ . '\\' . ucfirst($this->type); //__CLASS__ is always Post
$error = __('Post not found!');
- list($content, $language, $slug) = Event :: trigger(__CLASS__,__FUNCTION__, $content, $language, $slug);
+ list($content, $language, $slug) = Event :: trigger($class,__FUNCTION__, $content, $language, $slug);
if ($content) {
if (isset($content[$language])) {
@@ -72,7 +74,7 @@ class Post extends Base {
if ($this->global['language'] != $languageContent['code']) {
setLanguage($languageContent['code']);
}
-
+
$this->global['language'] = $languageContent['code'];
$this->global['language_id'] = $languageContent['language_id'];
@@ -85,7 +87,7 @@ class Post extends Base {
$this->request->request['name'] = $languageContent['name'];
$this->request->request['code'] = $languageContent['code'];
$this->request->request['language_id'] = $languageContent['language_id'];
-
+
if ($created_at) {
//check if admin user to allow revision preview
$admin = Admin::current();
@@ -106,13 +108,15 @@ class Post extends Base {
$this->view->tplFile("content/{$this->type}.tpl");
}
} else {
- $this->notFound(true, ['message' => $error, 'title' => $error]);
+ return $this->notFound(true, ['message' => $error, 'title' => $error]);
}
+
+ list($content, $languageContent, $language, $slug) = Event :: trigger($class, __FUNCTION__ . ':after', $content, $languageContent, $language, $slug);
} else {
- $this->notFound(true, ['message' => $error, 'title' => $error]);
+ return $this->notFound(true, ['message' => $error, 'title' => $error]);
}
- $this->view->post = $languageContent;
+ $this->view->post = $languageContent;
$this->view->content = $content;
}
}
diff --git a/app/sql/mysqli/post.sql b/app/sql/mysqli/post.sql
index 3d42da7..ee72bff 100755
--- a/app/sql/mysqli/post.sql
+++ b/app/sql/mysqli/post.sql
@@ -41,19 +41,19 @@
LEFT JOIN admin ad ON (_.admin_id = ad.admin_id)
WHERE 1 = 1
- @IF isset(:slug)
- THEN
- AND pd.slug = :slug
+ @IF isset(:slug) && !(isset(:post_id) && :post_id)
+ THEN
+ AND pd.slug = :slug
END @IF
- @IF isset(:post_id)
- THEN
- AND _.post_id = :post_id
+ @IF isset(:post_id)
+ THEN
+ AND _.post_id = :post_id
END @IF
- @IF isset(:type)
- THEN
- AND _.type = :type
+ @IF isset(:type)
+ THEN
+ AND _.type = :type
END @IF
LIMIT 1;
@@ -87,12 +87,12 @@
WHERE 1 = 1
- @IF isset(:slug)
+ @IF isset(:slug) && !(isset(:post_id) && :post_id)
THEN
AND _.post_id = (SELECT post_id FROM post_content WHERE slug = :slug LIMIT 1)
END @IF
- @IF isset(:post_id)
+ @IF isset(:post_id) && :post_id > 0
THEN
AND _.post_id = :post_id
END @IF
diff --git a/app/sql/mysqli/product.sql b/app/sql/mysqli/product.sql
index 34953dd..cfa07a8 100755
--- a/app/sql/mysqli/product.sql
+++ b/app/sql/mysqli/product.sql
@@ -13,24 +13,24 @@
)
BEGIN
- SELECT _.product_id,_.slug,_.name,_.meta_keywords,_.meta_description,_.language_id,product.template,language.code,language.code as array_key
+ SELECT product.*, _.product_id,_.slug,_.name,_.meta_keywords,_.meta_description,_.language_id,product.template,language.code,language.code as array_key
FROM product_content AS _
LEFT JOIN language ON (language.language_id = _.language_id)
LEFT JOIN product ON (product.product_id = _.product_id)
WHERE 1 = 1
- @IF isset(:status)
- THEN
- AND product.status = :status
+ @IF isset(:status)
+ THEN
+ AND product.status = :status
END @IF
- @IF isset(:slug)
- THEN
- AND _.product_id = (SELECT product_id FROM product_content WHERE slug = :slug LIMIT 1)
+ @IF isset(:slug) && !(isset(:product_id) && :product_id)
+ THEN
+ AND _.product_id = (SELECT product_id FROM product_content WHERE slug = :slug LIMIT 1)
END @IF
- @IF isset(:product_id)
- THEN
- AND _.product_id = :product_id
+ @IF isset(:product_id) && :product_id > 0
+ THEN
+ AND _.product_id = :product_id
END @IF
END
diff --git a/app/sql/pgsql/post.sql b/app/sql/pgsql/post.sql
index f3f95a0..856ea73 100755
--- a/app/sql/pgsql/post.sql
+++ b/app/sql/pgsql/post.sql
@@ -41,9 +41,9 @@
LEFT JOIN admin ad ON (_.admin_id = ad.admin_id)
WHERE 1 = 1
- @IF isset(:slug)
- THEN
- AND pd.slug = :slug
+ @IF isset(:slug) && !(isset(:post_id) && :post_id)
+ THEN
+ AND pd.slug = :slug
END @IF
@IF isset(:post_id)
@@ -87,14 +87,14 @@
WHERE 1 = 1
- @IF isset(:slug)
- THEN
- AND _.post_id = (SELECT post_id FROM post_content WHERE slug = :slug LIMIT 1)
+ @IF isset(:slug) && !(isset(:post_id) && :post_id)
+ THEN
+ AND _.post_id = (SELECT post_id FROM post_content WHERE slug = :slug LIMIT 1)
END @IF
- @IF isset(:post_id)
- THEN
- AND _.post_id = :post_id
+ @IF isset(:post_id) && :post_id > 0
+ THEN
+ AND _.post_id = :post_id
END @IF
@IF isset(:site_id)
diff --git a/app/sql/pgsql/product.sql b/app/sql/pgsql/product.sql
index 1934025..d88a7b9 100755
--- a/app/sql/pgsql/product.sql
+++ b/app/sql/pgsql/product.sql
@@ -19,14 +19,14 @@
LEFT JOIN product ON (product.product_id = _.product_id)
WHERE 1 = 1
- @IF isset(:status)
- THEN
- AND product.status = :status
+ @IF isset(:status)
+ THEN
+ AND product.status = :status
END @IF
- @IF isset(:slug)
- THEN
- AND _.product_id = (SELECT product_id FROM product_content WHERE slug = :slug LIMIT 1)
+ @IF isset(:slug) && !(isset(:product_id) && :product_id)
+ THEN
+ AND _.product_id = (SELECT product_id FROM product_content WHERE slug = :slug LIMIT 1)
END @IF
@IF isset(:product_id)
diff --git a/app/sql/sqlite/post.sql b/app/sql/sqlite/post.sql
index 6b25250..e470ce0 100755
--- a/app/sql/sqlite/post.sql
+++ b/app/sql/sqlite/post.sql
@@ -41,9 +41,9 @@
LEFT JOIN admin ad ON (_.admin_id = ad.admin_id)
WHERE 1 = 1
- @IF isset(:slug)
- THEN
- AND pd.slug = :slug
+ @IF isset(:slug) && !(isset(:post_id) && :post_id)
+ THEN
+ AND pd.slug = :slug
END @IF
@IF isset(:post_id)
@@ -87,14 +87,14 @@
WHERE 1 = 1
- @IF isset(:slug)
- THEN
- AND _.post_id = (SELECT post_id FROM post_content WHERE slug = :slug LIMIT 1)
+ @IF isset(:slug) && !(isset(:post_id) && :post_id)
+ THEN
+ AND _.post_id = (SELECT post_id FROM post_content WHERE slug = :slug LIMIT 1)
END @IF
- @IF isset(:post_id)
- THEN
- AND _.post_id = :post_id
+ @IF isset(:post_id) && :post_id > 0
+ THEN
+ AND _.post_id = :post_id
END @IF
@IF isset(:site_id)
diff --git a/app/sql/sqlite/product.sql b/app/sql/sqlite/product.sql
index 1934025..9f95687 100755
--- a/app/sql/sqlite/product.sql
+++ b/app/sql/sqlite/product.sql
@@ -24,13 +24,13 @@
AND product.status = :status
END @IF
- @IF isset(:slug)
- THEN
- AND _.product_id = (SELECT product_id FROM product_content WHERE slug = :slug LIMIT 1)
+ @IF isset(:slug) && !(isset(:product_id) && :product_id)
+ THEN
+ AND _.product_id = (SELECT product_id FROM product_content WHERE slug = :slug LIMIT 1)
END @IF
- @IF isset(:product_id)
- THEN
- AND _.product_id = :product_id
+ @IF isset(:product_id) && :product_id > 0
+ THEN
+ AND _.product_id = :product_id
END @IF
END
diff --git a/app/template/components/post.tpl b/app/template/components/post.tpl
index 7cdb08c..1c23f9b 100755
--- a/app/template/components/post.tpl
+++ b/app/template/components/post.tpl
@@ -17,7 +17,7 @@ $post = $this->_component['post'][$post_idx] ?? [];
//manual echo to avoid html escape
-@post [data-v-post-content] = <?php if (isset($post['content'])) echo $post['content'];?>
+@post [data-v-post-content] = <?php if (isset($post['content'])) echo($post['content']);?>
//@post [data-v-post-content] = $post['content']
@@ -42,4 +42,4 @@ foreach ($post['images'] as $image) { ?>
@image|after = <?php
}
-?>
\ No newline at end of file
+?>
diff --git a/app/template/components/product.tpl b/app/template/components/product.tpl
index 37202ab..783d7ae 100755
--- a/app/template/components/product.tpl
+++ b/app/template/components/product.tpl
@@ -22,13 +22,14 @@ $_pagination_limit = isset($product['limit']) ? $product['limit'] : 5;
@product|data-v-id = $product['product_id']
@product|data-v-type = 'product'
+//manual echo to avoid html escape
+@product [data-v-product-content] = <?php echo($product['content']);?>
+
//catch all data attributes
@product [data-v-product-*]|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-(*)__@@']
-//manual echo to avoid html escape
-@product [data-v-product-content] = <?php echo $product['content'];?>
@product button[data-v-product-*]|formaction = $product['@@__data-v-product-(*)__@@']
@product a[data-v-product-*]|href = $product['@@__data-v-product-(*)__@@']
diff --git a/install/sql/insert/menu/menu_item.sql b/install/sql/insert/menu/menu_item.sql
index 14c41e2..bb85b24 100755
--- a/install/sql/insert/menu/menu_item.sql
+++ b/install/sql/insert/menu/menu_item.sql
@@ -50,29 +50,29 @@ INSERT INTO `menu_item` (`menu_item_id`, `menu_id`, `type`, `url`, `parent_id`,
-- (47,1,'link','//github.com/givanz/Vvveb/discussions',44,null,0,1),
-- (48,1,'link','//dev.*.*',44,null,3,1),
-(49,1,'link','/page/contact',0,null,6,1),
-(59,1,'link','/page/about',0,null,1,1),
--- (60,1,'link','/page/contact',59,null,0,1),
--- (61,1,'link','/page/contact',59,null,3,1),
--- (62,1,'link','/page/contact',59,null,2,1),
+(49,1,'link','/page/contact-7',0,null,6,1),
+(59,1,'link','/page/about-11',0,null,1,1),
+-- (60,1,'link','/page/contact-7',59,null,0,1),
+-- (61,1,'link','/page/contact-7',59,null,3,1),
+-- (62,1,'link','/page/contact-7',59,null,2,1),
-(63,1,'link','/page/services',0,null,4,1),
-(64,1,'link','/page/pricing',63,null,0,1),
-(65,1,'link','/page/services',63,null,0,1),
-(66,1,'link','/page/portfolio',63,null,0,1),
-(67,1,'text','/page/portfolio',0,NULL,3, 0),
-(68,1,'text','/page/about',67,NULL,0,0),
+(63,1,'link','/page/services-12',0,null,4,1),
+(64,1,'link','/page/pricing-13',63,null,0,1),
+(65,1,'link','/page/services-12',63,null,0,1),
+(66,1,'link','/page/portfolio-14',63,null,0,1),
+(67,1,'text','/page/portfolio-14',0,NULL,3, 0),
+(68,1,'text','/page/about-11',67,NULL,0,0),
-- footer
(50,5,'link','',0,null,0,1),
(51,5,'link','/',50,null,0,1),
(52,5,'link','/shop',50,null,0,1),
(53,5,'link','/',0,null,0,1),
-(54,5,'link','/page/shipping-delivery',53,null,0,1),
-(55,5,'link','/page/terms-conditions',53,null,0,1),
-(56,5,'link','/page/contact',0,null,0,1),
-(57,5,'link','/page/contact',56,null,0,1),
-(58,5,'link','/page/portfolio',56,null,0,1),
+(54,5,'link','/page/shipping-delivery-8',53,null,0,1),
+(55,5,'link','/page/terms-conditions-9',53,null,0,1),
+(56,5,'link','/page/contact-7',0,null,0,1),
+(57,5,'link','/page/contact-7',56,null,0,1),
+(58,5,'link','/page/portfolio-14',56,null,0,1),
(73,5,'link','/user/return-form',56,null,0,1),
@@ -85,7 +85,7 @@ INSERT INTO `menu_item` (`menu_item_id`, `menu_id`, `type`, `url`, `parent_id`,
(74,5,'link','/blog',50,null,0,1),
-(75,5,'link','/page/services',50,null,0,1),
-(76,5,'link','/page/about',56,null,0,1),
+(75,5,'link','/page/services-12',50,null,0,1),
+(76,5,'link','/page/about-11',56,null,0,1),
(77,5,'link','/brand',53,null,0,1),
(78,5,'link','/vendor',53,null,0,1);