Skip to content

armgit / Vvveb

Public Imported from GitHub
0

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

Revision preview for post and product components

givanzb75de2ec1237
diff --git a/admin/controller/content/revisions.php b/admin/controller/content/revisions.php
index 06b472c..cf3f7b0 100644
--- a/admin/controller/content/revisions.php
+++ b/admin/controller/content/revisions.php
@@ -97,7 +97,7 @@ class Revisions extends Base {
$view = $this->view;
$results = $this->revisions->get($this->options);
$revision = [];
-
+
if ($results && $results['content']) {
foreach (['content', 'created_at', 'display_name'] as $key) {
$revision[$key] = $results[$key];
@@ -109,11 +109,13 @@ class Revisions extends Base {
}
function index() {
- $view = $this->view;
- $revisions = model($this->object . '_content_revision');
+ $view = $this->view;
+ $revisions = model($this->object . '_content_revision');
$this->options += $this->global;
+ $allOptions = $this->options;
+ unset($allOptions['created_at']);
- $revisions = $this->revisions->getAll($this->options); // all post/product revisions
+ $revisions = $this->revisions->getAll($allOptions); // all post/product revisions
$revision = $this->revisions->get($this->options); // latest or selected revision
$post = $this->post->get($this->options); // post/product content
@@ -131,7 +133,13 @@ class Revisions extends Base {
$view->limit = $this->options['limit'];
$view->type = $this->type;
- $view->revisionUrl = \Vvveb\url(['module' => 'content/revisions', 'action' => 'revision', 'type' => $this->type, 'object' => $this->object]);
+ $view->options = $this->options;
+ $view->revisionUrl = \Vvveb\url([
+ 'module' => 'content/revisions',
+ 'action' => 'revision',
+ 'type' => $this->type,
+ 'object' => $this->object,
+ $this->object . '_id' => $this->options[$this->object . '_id'], ]);
$view->type_name = humanReadable(__($this->type));
$view->type_name_plural = humanReadable(__($view->type . 's'));
}
diff --git a/app/component/post.php b/app/component/post.php
index a5b159d..88c86ad 100755
--- a/app/component/post.php
+++ b/app/component/post.php
@@ -23,17 +23,20 @@
namespace Vvveb\Component;
use function Vvveb\__;
+use function Vvveb\model;
use function Vvveb\sanitizeHTML;
use Vvveb\Sql\PostSQL;
use Vvveb\System\Component\ComponentBase;
+use Vvveb\System\Core\Request;
use Vvveb\System\Event;
use Vvveb\System\Images;
+use Vvveb\System\User\Admin;
use function Vvveb\url;
class Post extends ComponentBase {
public static $defaultOptions = [
'post_id' => 'url',
- 'language_id' => null,
+ 'language_id' => 'url',
'site_id' => null,
'slug' => 'url',
'status' => 'publish',
@@ -76,7 +79,26 @@ class Post extends ComponentBase {
}
//called on each request
- function request($results, $index = 0) {
+ function request(&$results, $index = 0) {
+ $request = Request::getInstance();
+ $created_at = $request->get['created_at'] ?? ''; //revision preview
+
+ if ($created_at && $results['post_id']) {
+ //check if admin user to allow revision preview
+ $admin = Admin::current();
+
+ if ($admin) {
+ $revisions = model('post_content_revision');
+ $revision = $revisions->get(['created_at' => $created_at, 'post_id' => $results['post_id'], 'language_id' => $results['language_id']]);
+
+ if ($revision && isset($revision['content'])) {
+ $results['content'] = $revision['content'];
+ $results['created_at'] = $revision['created_at'];
+ }
+ }
+ }
+
+ return $results;
}
//called by editor on page save for each component on page
diff --git a/app/component/product.php b/app/component/product.php
index 4bc5bb6..ba8c84c 100755
--- a/app/component/product.php
+++ b/app/component/product.php
@@ -22,13 +22,16 @@
namespace Vvveb\Component;
+use function Vvveb\model;
use function Vvveb\sanitizeHTML;
use Vvveb\Sql\ProductSQL;
use Vvveb\System\Cart\Currency;
use Vvveb\System\Cart\Tax;
use Vvveb\System\Component\ComponentBase;
+use Vvveb\System\Core\Request;
use Vvveb\System\Event;
use Vvveb\System\Images;
+use Vvveb\System\User\Admin;
use function Vvveb\url;
class Product extends ComponentBase {
@@ -36,7 +39,7 @@ class Product extends ComponentBase {
'product_id' => 'url',
'slug' => 'url',
'status' => 1,
- 'language_id' => null,
+ 'language_id' => 'url',
'site_id' => null,
'user_id' => null,
'user_group_id' => null,
@@ -86,6 +89,29 @@ class Product extends ComponentBase {
return $results;
}
+ //called on each request
+ function request(&$results, $index = 0) {
+ $request = Request::getInstance();
+ $created_at = $request->get['created_at'] ?? ''; //revision preview
+
+ if ($created_at && $results['product_id']) {
+ //check if admin user to allow revision preview
+ $admin = Admin::current();
+
+ if ($admin) {
+ $revisions = model('post_content_revision');
+ $revision = $revisions->get(['created_at' => $created_at, 'product_id' => $results['product_id'], 'language_id' => $results['language_id']]);
+
+ if ($revision && isset($revision['content'])) {
+ $results['content'] = $revision['content'];
+ $results['created_at'] = $revision['created_at'];
+ }
+ }
+ }
+
+ 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') {