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
Sticky post and post password
givanz2a8dcb5e34ba
diff --git a/admin/template/content/post.tpl b/admin/template/content/post.tplold mode 100755new mode 100644index 34fb1d7..c84139d--- a/admin/template/content/post.tpl+++ b/admin/template/content/post.tpl@@ -11,3 +11,9 @@ import(content/edit.tpl, {"type":"post"})[data-v-type-name] = $this->type_name[data-v-type] = $this->type[data-v-posts-list-url]|href = $this->posts_list_url+++[name="password_protected"]|addNewAttribute = <?php if (isset($this->post['password']) && $this->post['password']) echo 'checked';?>+[name="sticky"]|addNewAttribute = <?php if (isset($this->post['sticky']) && $this->post['sticky']) echo 'checked';?>+#postPassword|addNewAttribute = <?php if (!isset($this->post['password']) || !$this->post['password']) echo 'style="display:none"';?>+#postPassword|addNewAttribute = <?php if (!isset($this->post['password']) || !$this->post['password']) echo 'style="display:none"';?>\ No newline at end of filediff --git a/app/component/post.php b/app/component/post.phpindex 10844e8..8214d84 100755--- a/app/component/post.php+++ b/app/component/post.php@@ -25,15 +25,17 @@ namespace Vvveb\Component;use function Vvveb\__;use function Vvveb\model;use function Vvveb\sanitizeHTML;+use function Vvveb\siteSettings;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\Traits\Post as PostTrait;use Vvveb\System\User\Admin;-use function Vvveb\url;class Post extends ComponentBase {+ use PostTrait;+public static $defaultOptions = ['post_id' => 'url','language_id' => null,@@ -42,6 +44,8 @@ class Post extends ComponentBase {'status' => 'publish','comment_count' => 1,'comment_status' => 1,+ 'type' => null,+ 'image_size' => 'large',//'type' => 'post',];@@ -53,32 +57,16 @@ class Post extends ComponentBase {$results = $post->get($this->options);- //comments translations- if (isset($results['comment_count'])) {- $results['comment_text'] = sprintf(__('%d comment', '%d comments', (int)$results['comment_count']), $results['comment_count']);- }-- if (isset($results['image'])) {- $results['image'] = Images::image($results['image'], 'post');+ //$languages = availableLanguages();+ if (! isset($this->options['date_format'])) {+ $site = siteSettings();+ $this->options['date_format'] = $site['date_format'];}- if (isset($results['avatar'])) {- $results['avatar_url'] = Images::image($results['avatar'], 'admin');+ if ($results) {+ $this->post($results, $this->options);}- //comments translations- $results['comment_count'] = $results['comment_count'] ?? 0;- $results['comment_text'] = sprintf(__('%d comment', '%d comments', (int)$results['comment_count']), $results['comment_count']);-- //url- $results['url'] = url('content/post/index', $results);- $results['author-url'] = url('content/user/index', $results);- $results['comments-url'] = $results['url'] . '#comments';-- //rfc- $results['pubDate'] = date('r', strtotime($results['created_at']));- $results['modDate'] = date('r', strtotime($results['updated_at']));-list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);return $results;@@ -86,8 +74,23 @@ class Post extends ComponentBase {//called on each requestfunction request(&$results, $index = 0) {- $request = Request::getInstance();- $created_at = $request->get['created_at'] ?? ''; //revision preview+ $created_at = $this->request->get['created_at'] ?? ''; //revision preview++ if ($results['password']) {+ if (isset($this->request->post['password'])) {+ if ($results['password'] == $this->request->post['password']) {+ $results['password'] = '';+ return $results;+ } else {+ $results['content'] = '<p>' . __('Invalid password!') . '</p>';+ $results['image'] = '';+ return $results;+ }+ }++ $results['content'] = '';+ $results['image'] = '';+ }if ($created_at && $results['post_id']) {//check if admin user to allow revision previewdiff --git a/app/component/posts.php b/app/component/posts.phpold mode 100755new mode 100644index fbb261b..bf630f3--- a/app/component/posts.php+++ b/app/component/posts.php@@ -22,8 +22,11 @@namespace Vvveb\Component;+use function Vvveb\__;use function Vvveb\availableLanguages;use function Vvveb\get;+use function Vvveb\getSetting;+use function Vvveb\siteSettings;use Vvveb\Sql\PostSQL;use Vvveb\System\Component\ComponentBase;use Vvveb\System\Event;@@ -61,6 +64,9 @@ class Posts extends ComponentBase {'tags' => null,'taxonomy' => null,'username' => null,+ 'date_format' => null,+ 'sticky' => null,+ '404' => null,];public $options = [];@@ -72,7 +78,7 @@ class Posts extends ComponentBase {switch ($module) {case 'content/post':- break;+ break;case 'content/category':if (isset($this->options['taxonomy_item_id']) && $this->options['taxonomy_item_id'] == 'page') {@@ -83,7 +89,7 @@ class Posts extends ComponentBase {$this->options['taxonomy_item_slug'] = get('slug');}- break;+ break;}}@@ -130,6 +136,11 @@ class Posts extends ComponentBase {$this->options['search'] .= '*';}+ if (! isset($this->options['sticky'])) {+ $stickyPosts = getSetting('posts', 'sticky');+ $this->options['sticky'] = $stickyPosts;+ }+//if only one taxonomy_item_id is provided then add it to arrayif (isset($this->options['taxonomy_item_id']) && ! is_array($this->options['taxonomy_item_id'])) {$this->options['taxonomy_item_id'] = [$this->options['taxonomy_item_id']];@@ -139,8 +150,28 @@ class Posts extends ComponentBase {//$languages = availableLanguages();$this->options['type'] = $this->options['type'] ?: 'post';+ if (! isset($this->options['date_format'])) {+ $site = siteSettings();+ $this->options['date_format'] = $site['date_format'];+ }+if ($results && isset($results['post'])) {+ if ($this->options['sticky']) {+ $stickyOptions = $this->options;+ $stickyOptions['post_id'] = $this->options['sticky'];+ $stickyOptions['start'] = 0;+ unset($stickyOptions['limit']);+ $sticky = $posts->getAll($stickyOptions);++ if ($sticky && isset($sticky['post'])) {+ //$count = count($sticky['post']);+ $results['post'] = $sticky['post'] + $results['post'];+ }+ }+$this->posts($results['post'], $this->options);+ } else {+ $results['post'] = [];}//if archive then pass year and month@@ -156,8 +187,29 @@ class Posts extends ComponentBase {$results['start'] = $this->options['start'];$results['search'] = $this->options['search'] ?? '';+ if (! $results['post'] &&+ isset($this->options['page']) &&+ ($this->options['page'] > 1) &&+ (isset($this->options['404']) && $this->options['404']) &&+ ! $_SERVER['QUERY_STRING']) {+ $results['404'] = true;+ }+list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);return $results;}++ //called on each request+ function request(&$results, $index = 0) {+ if (isset($results['post']) && $results['post']) {+ foreach ($results['post'] as &$post) {+ if ($post['password']) {+ $post['content'] = ''; //__('Password protected!');+ $post['excerpt'] = ''; //__('Password protected!');+ $post['image'] = PUBLIC_PATH . 'media/locked.svg';+ }+ }+ }+ }}diff --git a/app/sql/mysqli/post.sql b/app/sql/mysqli/post.sqlold mode 100755new mode 100644index ee72bff..982d0a5--- a/app/sql/mysqli/post.sql+++ b/app/sql/mysqli/post.sql@@ -70,12 +70,12 @@CREATE PROCEDURE getContent(IN post_id INT,IN site_id INT,- IN slug CHAR,+ IN slug CHAR,OUT fetch_all,)BEGIN- SELECT post.*,_.post_id,_.slug,_.name,_.meta_keywords,_.meta_description,_.language_id,post.template,language.code,language.code as array_key+ SELECT post.*,_.post_id,_.slug,_.name,_.content,_.meta_keywords,_.meta_description,_.language_id,post.template,language.code,language.slug as language,language.slug as array_keyFROM post_content AS _LEFT JOIN language ON (language.language_id = _.language_id)LEFT JOIN post ON (post.post_id = _.post_id)@@ -90,17 +90,17 @@@IF isset(:slug) && !(isset(:post_id) && :post_id)THENAND _.post_id = (SELECT post_id FROM post_content WHERE slug = :slug LIMIT 1)- END @IF+ END @IF@IF isset(:post_id) && :post_id > 0THEN- AND _.post_id = :post_id- END @IF+ AND _.post_id = :post_id+ END @IF@IF isset(:site_id)THEN- AND pt.site_id = :site_id- END @IF+ AND pt.site_id = :site_id+ END @IFEND-- Get categoriesdiff --git a/app/sql/pgsql/post.sql b/app/sql/pgsql/post.sqlold mode 100755new mode 100644index 856ea73..d891983--- a/app/sql/pgsql/post.sql+++ b/app/sql/pgsql/post.sql@@ -46,14 +46,14 @@AND pd.slug = :slugEND @IF- @IF isset(:post_id)- THEN- AND _.post_id = :post_id+ @IF isset(:post_id)+ THEN+ AND _.post_id = :post_idEND @IF- @IF isset(:type)- THEN- AND _.type = :type+ @IF isset(:type)+ THEN+ AND _.type = :typeEND @IFLIMIT 1;@@ -75,7 +75,7 @@)BEGIN- SELECT post.*,_.post_id,_.slug,_.name,_.meta_keywords,_.meta_description,_.language_id,post.template,language.code,language.code as array_key+ SELECT post.*,_.post_id,_.slug,_.name,_.content,_.meta_keywords,_.meta_description,_.language_id,post.template,language.code,language.slug as language,language.slug as array_keyFROM post_content AS _LEFT JOIN language ON (language.language_id = _.language_id)LEFT JOIN post ON (post.post_id = _.post_id)diff --git a/app/sql/sqlite/post.sql b/app/sql/sqlite/post.sqlold mode 100755new mode 100644index e470ce0..d5898fb--- a/app/sql/sqlite/post.sql+++ b/app/sql/sqlite/post.sql@@ -46,14 +46,14 @@AND pd.slug = :slugEND @IF- @IF isset(:post_id)- THEN- AND _.post_id = :post_id+ @IF isset(:post_id)+ THEN+ AND _.post_id = :post_idEND @IF- @IF isset(:type)- THEN- AND _.type = :type+ @IF isset(:type)+ THEN+ AND _.type = :typeEND @IFLIMIT 1;@@ -75,7 +75,7 @@)BEGIN- SELECT post.*,_.post_id,_.slug,_.name,_.meta_keywords,_.meta_description,_.language_id,post.template,language.code,language.code as array_key+ SELECT post.*,_.post_id,_.slug,_.name,_.content,_.meta_keywords,_.meta_description,_.language_id,post.template,language.code,language.slug as language,language.slug as array_keyFROM post_content AS _LEFT JOIN language ON (language.language_id = _.language_id)LEFT JOIN post ON (post.post_id = _.post_id)