Re-implement "Drafts" as normal posts visible only to the poster

https://www.phpbb.com/ideas/
User avatar
3Di
Former Team Member
Posts: 15031
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: Re-implement "Drafts" as normal posts visible only to the poster

Post by 3Di »

Well, I am not at my PC but you could also use the class="rules" for a light red background.
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
:studio_microphone: Premium extensions @ The Studio

v12mike
Registered User
Posts: 461
Joined: Thu Jul 09, 2015 5:03 pm

Re: Re-implement "Drafts" as normal posts visible only to the poster

Post by v12mike »

I have just updated the demo site ( http://xmv6.uk/new_drafts_demo1/ ) to have "Load Drafts" buttons next to the "New Topic" and "Post reply" buttons. On the viewforum page the new button loads all of the current user's drafts in that forum, and on the viewtopic page, the button loads all of the current user's drafts in that topic.

v12mike
Registered User
Posts: 461
Joined: Thu Jul 09, 2015 5:03 pm

Re: Re-implement "Drafts" as normal posts visible only to the poster

Post by v12mike »

I have updated the demo site with code that re-implements PM drafts. It was actually easier than post drafts because the PM system already has folders and most of the necessary elements in the style templates.

remember that this is currently prototype code, and there is scope for improvement.

v12mike
Registered User
Posts: 461
Joined: Thu Jul 09, 2015 5:03 pm

Re: Re-implement "Drafts" as normal posts visible only to the poster

Post by v12mike »

I updated the demo site http://xmv6.uk/new_drafts_demo1 with some improvements to the UI for navigating draft posts and PMs, there are now buttons for editing or deleting drafts on the draft search results page and the PMs draft box.

I think that the feature is now more or less complete from a functional point of view (subject to feedback). There is still behind the scenes work to be done before it is ready for submission.

User avatar
3Di
Former Team Member
Posts: 15031
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: Re-implement "Drafts" as normal posts visible only to the poster

Post by 3Di »

v12mike wrote:
Fri Oct 25, 2019 8:00 am
I just tested this with some unapproved posts, and (using prosilver) I don't see this red background. Can you give an example of how to show it?
Sorry I was meant to say reported posts - just report a post and you will see.
2019-11-05 02_00_55-(1) test - 328-emoji.png
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
:studio_microphone: Premium extensions @ The Studio

v12mike
Registered User
Posts: 461
Joined: Thu Jul 09, 2015 5:03 pm

Re: Re-implement "Drafts" as normal posts visible only to the poster

Post by v12mike »

OK that makes more sense.

I have however now changed the user interface so that drafts and non-draft messages don't appear on the same page, so the background differentiation seems less beneficial.

The demo site was broken for a couple of days after a minor mishap while editing, no back on-line.

Tarantino
Registered User
Posts: 790
Joined: Sat Feb 18, 2012 1:51 pm
Contact:

Re: Re-implement "Drafts" as normal posts visible only to the poster

Post by Tarantino »

I never use the old draft system, neither my users, it was not intuitive at all. And had many problems as some of you pointed out.

Would be great to see a different way of doing that, like "saving" without really posting.

v12mike
Registered User
Posts: 461
Joined: Thu Jul 09, 2015 5:03 pm

Re: Re-implement "Drafts" as normal posts visible only to the poster

Post by v12mike »

There is now PR 5759 for this change, in the queue for phpBB v4.0

User avatar
JoshyPHP
Code Contributor
Posts: 1106
Joined: Mon Jul 11, 2011 12:28 am

Re: Re-implement "Drafts" as normal posts visible only to the poster

Post by JoshyPHP »

I'd rather have drafts implemented the same way as XenForo, where all drafts (posts, PMs) are stored together in their own table and their content is automatically loaded in the editor.

phpBB's content_visibility class is already too complex in my opinion. Every new case adds complexity both to the PHP class and to the SQL it produces.

Code: Select all

--- a/phpBB/phpbb/content_visibility.php
+++ b/phpBB/phpbb/content_visibility.php
@@ -147,10 +147,8 @@ public function is_visible($mode, $forum_id, $data)
 		$visibility = $data[$mode . '_visibility'];
 		$poster_key = ($mode === 'topic') ? 'topic_poster' : 'poster_id';
 		$is_visible = ($visibility == ITEM_APPROVED) ||
-			($this->config['display_unapproved_posts'] &&
-				($this->user->data['user_id'] != ANONYMOUS) &&
-				($visibility == ITEM_UNAPPROVED || $visibility == ITEM_REAPPROVE) &&
-				($this->user->data['user_id'] == $data[$poster_key])) ||
+			(($this->user->data['user_id'] != ANONYMOUS) && ($this->user->data['user_id'] == $data[$poster_key]) &&
+				($visibility == ITEM_DRAFT) || (($visibility == ITEM_UNAPPROVED || $visibility == ITEM_REAPPROVE) && $this->config['display_unapproved_posts'])) ||
 			 $this->auth->acl_get('m_approve', $forum_id);
 
 		/**
@@ -182,9 +180,10 @@ public function is_visible($mode, $forum_id, $data)
 	* @param $mode			string	Either "topic" or "post"
 	* @param $forum_id		int		The forum id is used for permission checks
 	* @param $table_alias	string	Table alias to prefix in SQL queries
+	* @param $allow_drafts	boolean Allow users to see their own draft posts
 	* @return string	The appropriate combination SQL logic for topic/post_visibility
 	*/
-	public function get_visibility_sql($mode, $forum_id, $table_alias = '')
+	public function get_visibility_sql($mode, $forum_id, $table_alias = '', $allow_drafts = false)
 	{
 		$where_sql = '';
 
@@ -217,19 +216,28 @@ public function get_visibility_sql($mode, $forum_id, $table_alias = '')
 			return $get_visibility_sql_overwrite;
 		}
 
+		$poster_key = ($mode === 'topic') ? 'topic_poster' : 'poster_id' ;
+		$visibility_query = $table_alias . $mode . '_visibility';
 		if ($this->auth->acl_get('m_approve', $forum_id))
 		{
-			$where_sql .= '1 = 1';
+			$where_sql = '(' . $visibility_query . ' != ' . ITEM_DRAFT . ')';
+			if ($allow_drafts)
+			{
+				$where_sql .= ' OR (' . $table_alias . $poster_key . ' = ' . ((int) $this->user->data['user_id']) .')';
+			}
 		}
 		else
 		{
-			$visibility_query = $table_alias . $mode . '_visibility = ';
-
-			$where_sql .= '(' . $visibility_query . ITEM_APPROVED . ')';
+			$where_sql = '(' . $visibility_query . ' = ' . ITEM_APPROVED . ')';
+			if ($allow_drafts && $this->user->data['user_id'] != ANONYMOUS)
+			{
+				$where_sql .= 'OR (';
+				$where_sql .= $visibility_query . ' = ' . ITEM_DRAFT . ' AND ' . $table_alias . $poster_key . ' = ' . ((int) $this->user->data['user_id']);
+				$where_sql .= ')';
+			}
 			if ($this->config['display_unapproved_posts'] && ($this->user->data['user_id'] != ANONYMOUS))
 			{
-				$poster_key = ($mode === 'topic') ? 'topic_poster' : 'poster_id';
-				$where_sql .= ' OR ((' . $visibility_query . ITEM_UNAPPROVED . ' OR ' . $visibility_query . ITEM_REAPPROVE .')';
+				$where_sql .= ' OR ((' . $visibility_query . ' = ' . ITEM_UNAPPROVED . ' OR ' . $visibility_query . ' = ' . ITEM_REAPPROVE .')';
 				$where_sql .= ' AND ' . $table_alias . $poster_key . ' = ' . ((int) $this->user->data['user_id']) . ')';
 			}
 		}
@@ -289,7 +297,8 @@ public function get_forums_visibility_sql($mode, $forum_ids = array(), $table_al
 		}
 
 		// Moderator can view all posts/topics in the moderated forums
-		$where_sql .= '(' . $this->db->sql_in_set($table_alias . 'forum_id', $approve_forums, false, true) . ' OR ';
+		$where_sql .= '((' . $table_alias . $mode . '_visibility != ' . ITEM_DRAFT . '
+            AND ' . $this->db->sql_in_set($table_alias . 'forum_id', $approve_forums, false, true) . ') OR ';
 		// Normal user can view approved items only
 		$where_sql .= '(' . $table_alias . $mode . '_visibility = ' . ITEM_APPROVED . '
 			AND ' . $this->db->sql_in_set($table_alias . 'forum_id', $forum_ids, false, true) . '))';
@@ -306,12 +315,11 @@ public function get_forums_visibility_sql($mode, $forum_ids = array(), $table_al
 	* @param $mode				string	Either "topic" or "post"
 	* @param $exclude_forum_ids	array	Array of forum ids which are excluded
 	* @param $table_alias		string	Table alias to prefix in SQL queries
+	* @param $visibility		int		ITEM_visibility filter
 	* @return string	The appropriate combination SQL logic for topic/post_visibility
 	*/
-	public function get_global_visibility_sql($mode, $exclude_forum_ids = array(), $table_alias = '')
+	public function get_global_visibility_sql($mode, $exclude_forum_ids = array(), $table_alias = '', $visibility = ITEM_APPROVED)
 	{
-		$where_sqls = array();
-
 		$approve_forums = array_diff(array_keys($this->auth->acl_getf('m_approve', true)), $exclude_forum_ids);
 
 		$visibility_sql_overwrite = null;
@@ -344,13 +352,23 @@ public function get_global_visibility_sql($mode, $exclude_forum_ids = array(), $
 		}
 
 		// Include approved items in all forums but the excluded
-		$where_sqls[] = '(' . $this->db->sql_in_set($table_alias . 'forum_id', $exclude_forum_ids, true, true) . '
-			AND ' . $table_alias . $mode . '_visibility = ' . ITEM_APPROVED . ')';
+		if ($visibility == ITEM_DRAFT)
+		{
+			$poster_key = ($mode === 'topic') ? 'topic_poster' : 'poster_id' ;
+			$where_sqls[] = '(' . $this->db->sql_in_set($table_alias . 'forum_id', $exclude_forum_ids, true, true) . '
+				AND ' . $table_alias . $mode . '_visibility = ' . ITEM_DRAFT . ' AND ' . $table_alias . $poster_key . ' = ' . ((int) $this->user->data['user_id']) . ' )';
+		}
+		else
+		{
+			$where_sqls[] = '(' . $this->db->sql_in_set($table_alias . 'forum_id', $exclude_forum_ids, true, true) . '
+				AND ' . $table_alias . $mode . '_visibility = ' . ITEM_APPROVED . ')';
+		}
 
-		// If user has moderator permissions, add everything in the moderated forums
-		if (count($approve_forums))
+		// If user has moderator permissions, add everything (except drafts) in the moderated forums (not applicable for draftsearch)
+		if (count($approve_forums) && ($visibility != ITEM_DRAFT))
 		{
-			$where_sqls[] = $this->db->sql_in_set($table_alias . 'forum_id', $approve_forums);
+			$where_sqls[] = '(' . $this->db->sql_in_set($table_alias . 'forum_id', $approve_forums) . '
+				AND ' . $table_alias . $mode . '_visibility <> ' . ITEM_DRAFT . ')';
I wrote the thing that does BBCodes in 3.2+.

Post Reply

Return to “phpBB Ideas”