[RC] Hide BBcode

Any abandoned Extensions will be moved to this forum.

WARNING: Extensions in this forum are not currently being supported or maintained by the original Extension author. Proceed at your own risk.
Forum rules
IMPORTANT: Extension Development Forum rules

WARNING: Extensions in this forum are not currently being supported nor updated by the original Extension author. Proceed at your own risk.
marcovo
Registered User
Posts: 239
Joined: Fri Nov 16, 2012 12:19 pm
Location: The Netherlands
Name: Marco

Re: [DEV] Hide BBcode

Post by marcovo »

@alhitary: actually this functionality is already provided by the [hidden] bbcode. I don't know whether it's a good idea to replicate this extension?
User avatar
masterbiz
Registered User
Posts: 65
Joined: Thu Dec 20, 2012 8:31 am

Re: [DEV] Hide BBcode

Post by masterbiz »

thanks ;)
parshakov
Registered User
Posts: 36
Joined: Sun Jul 28, 2013 8:03 pm

Re: [DEV] Hide BBcode

Post by parshakov »

marcovo wrote:@parshavok: I will look into this.
Thank you :-)
Saipen
Registered User
Posts: 5
Joined: Wed Apr 08, 2015 11:19 am

Re: [DEV] Hide BBcode

Post by Saipen »

Hi,
You can unhide after thanking?
Not sending the answers!
parshakov
Registered User
Posts: 36
Joined: Sun Jul 28, 2013 8:03 pm

Re: [DEV] Hide BBcode

Post by parshakov »

I modified marcovo extension to hide content from anyone but a particular group of users named "Trusted Users". It can be easily modified to hide content from guests.

All you need to do is modify the listener.php file:

Code: Select all

<?php
/** 
*
* @package Hide_BBcode
* @copyright (c) 2015 Marco van Oort
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2 
*
*/

namespace marcovo\hide_bbcode\event;

/**
* @ignore
*/
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
* Event listener
*/
class listener implements EventSubscriberInterface
{
	protected $db;
	protected $user;
	protected $template;

	protected $b_hide = true;

	/**
	* Constructor
	*
	* @param \phpbb\db\driver\driver $db Database object
	* @param \phpbb\controller\helper    $helper        Controller helper object
	*/
	public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\user $user, \phpbb\template\template $template)
	{
		$this->db = $db;
		$this->user = $user;
		$this->template = $template;

	}

	static public function getSubscribedEvents()
	{
		return array(
			'core.user_setup'	=> 'load_language_on_setup',

//			'core.modify_posting_parameters'		=> 'check_user_is_trusted',
			'core.modify_text_for_display_after'	=> 'parse_bbcodes_after',
			'core.modify_format_display_text_after'	=> 'parse_bbcodes_topicPreview',
			
//			'core.parse_attachments_modify_template_data'	=> 'check_attachment',

			'test.topic_review_modify_template_vars'	=> 'topic_review_modify_template_vars',
			'core.posting_modify_template_vars'	=> 'posting_modify_template_vars',
		);
	}

	/**
	* Load common files during user setup
	*
	* @param object $event The event object
	* @return null
	* @access public
	*/
	public function load_language_on_setup($event)
	{
		$lang_set_ext = $event['lang_set_ext'];
		$lang_set_ext[] = array(
			'ext_name' => 'marcovo/hide_bbcode',
			'lang_set' => 'hide_bbcode',
		);
		$event['lang_set_ext'] = $lang_set_ext;
		
		$this->check_user_is_trusted();
	}

	/**
	* Alter BBCodes after they are processed by phpBB
	*
	* @param object $event The event object
	*/
	public function topic_review_modify_template_vars($event)
	{
		if ($this->b_hide)
		{
			$event['decoded_message'] = preg_replace("#\[hide\].*?\[/hide\]#is", '{{'.$this->user->lang('HIDEBB_HIDDEN_MESSAGE')."}}\n", $event['decoded_message']);
		}

	}
	/**
	* Alter BBCodes after they are processed by phpBB
	*
	* @param object $event The event object
	*/
	public function posting_modify_template_vars($event)
	{	
		if ($this->b_hide)
		{
			$page_data = $event['page_data'];
			$page_data['MESSAGE'] = preg_replace("#\[hide\].*?\[/hide\]#is", '{{'.$this->user->lang('HIDEBB_HIDDEN_MESSAGE')."}}\n", $page_data['MESSAGE']);
			$event['page_data'] = $page_data;
		}

	}

	/**
	* Alter BBCodes after they are processed by phpBB
	*
	* @param object $event The event object
	*/
	private function check_user_is_trusted()
	{

		// Check if the is in the Trusted group
		$sql = "SELECT group_id	FROM " . USER_GROUP_TABLE . " WHERE group_id = 8 AND user_id = " . $this->user->data['user_id']; 

		$result = $this->db->sql_query($sql);
		$b_hide = $this->db->sql_affectedrows($result) ? false : true;
		$this->db->sql_freeresult($result);
		
		$this->b_hide = $b_hide;
	}

	/**
	* Alter BBCodes after they are processed by phpBB
	*
	* @param object $event The event object
	*/
	/*
	public function check_attachment($event)
	{
		if($this->b_hide)
		{
			$event['attachment'] = array();
			$event['block_array'] = array();
			$event['download_link'] = '';
		}
	}
	*/


	/**
	* Alter BBCodes after they are processed by phpBB
	*
	* @param object $event The event object
	*/
	public function parse_bbcodes_after($event)
	{

		$event['text'] = preg_replace_callback('#<!-- HIDE_BBCODE -->(.*?)<!-- /HIDE_BBCODE -->#s', array($this, 'hidden_pass'), $event['text']);

	}

	/**
	* Alter BBCodes after they are processed by phpBB
	*
	* @param object $event The event object
	*/
	public function parse_bbcodes_topicPreview($event)
	{

		$event['text'] = preg_replace_callback('#<!-- HIDE_BBCODE -->(.*?)<!-- /HIDE_BBCODE -->#s', array($this, 'hidden_pass_topicPreview'), $event['text']);

	}
	
	
	/**
	* Convert Hidden BBCode into its final appearance
	*
	* @param array $matches
	* @return string HTML render of hidden bbcode
	*/
	protected function hidden_pass($matches)
	{
		$this->template->set_style(array('styles', 'ext/marcovo/hide_bbcode/styles'));

		$bbcode = new \bbcode();
		$bbcode->template_filename = $this->template->get_source_file_for_handle('hide_bbcode.html');
		
		if ($this->b_hide) return $bbcode->bbcode_tpl('hide');
		else return $bbcode->bbcode_tpl('unhide_open') . $matches[1] . $bbcode->bbcode_tpl('unhide_close');
	}
	
	/**
	* Convert Hidden BBCode into its final appearance
	*
	* @param array $matches
	* @return string HTML render of hidden bbcode
	*/
	protected function hidden_pass_topicPreview($matches)
	{
		$this->template->set_style(array('styles', 'ext/marcovo/hide_bbcode/styles'));

		$bbcode = new \bbcode();
		$bbcode->template_filename = $this->template->get_source_file_for_handle('hide_bbcode.html');
		
		return $bbcode->bbcode_tpl('unhide_open') . $matches[1] . $bbcode->bbcode_tpl('unhide_close');

	}

}
I had no experience at creating extensions, so it would be great if someone could check the code (functions load_language_on_setup and check_user_is_trusted in particular)!
Last edited by parshakov on Mon May 18, 2015 9:46 pm, edited 1 time in total.
User avatar
uruguayito
Registered User
Posts: 266
Joined: Mon Dec 13, 2010 2:46 pm
Location: Montevideo - Uruguay

Re: [DEV] Hide BBcode

Post by uruguayito »

thanks. Works fine

One suggestion : perhaps the message: 'You need to reply to this topic before you can view the hidden message' could be in bold and red to make it better note
I speak spanish
Sorry for my bad english
Sepp71
Registered User
Posts: 84
Joined: Sat Sep 06, 2008 11:32 pm
Location: Germany

Re: [DEV] Hide BBcode

Post by Sepp71 »

I am interested in the hide-function, too but I would like to have it implemented the official way for extensions (without having to change the code), because I have sworn to myself keep my source-code clean at 3.1 (I manage several boards on different URLs and want don't want to mix it all up as I did with 3.0.
So for the moment just watching this...
parshakov
Registered User
Posts: 36
Joined: Sun Jul 28, 2013 8:03 pm

Re: [DEV] Hide BBcode

Post by parshakov »

Sepp71 wrote:I am interested in the hide-function, too but I would like to have it implemented the official way for extensions (without having to change the code), because I have sworn to myself keep my source-code clean at 3.1 (I manage several boards on different URLs and want don't want to mix it all up as I did with 3.0.
So for the moment just watching this...
This actually is an extension.
Sepp71
Registered User
Posts: 84
Joined: Sat Sep 06, 2008 11:32 pm
Location: Germany

Re: [DEV] Hide BBcode

Post by Sepp71 »

Thanks for your reply!
Maybe I didn't understand it correctly: In the first post it says
The event above is not used any more in this extension. Instead, the following two edits will have to be done to make everything work correctly.
If this is still necessary it means a change to the original files (so not just adding and installing the extension), doesn't it?
Sepp
parshakov
Registered User
Posts: 36
Joined: Sun Jul 28, 2013 8:03 pm

Re: [DEV] Hide BBcode

Post by parshakov »

Oh, sorry, you are right. I forgot.
User avatar
nero
Registered User
Posts: 321
Joined: Fri Mar 13, 2015 8:18 am

Re: [DEV] Hide BBcode

Post by nero »

When will this be BETA?

This would be good for hiding content until someone posts :D
marcovo
Registered User
Posts: 239
Joined: Fri Nov 16, 2012 12:19 pm
Location: The Netherlands
Name: Marco

Re: [DEV] Hide BBcode

Post by marcovo »

With phpBB 3.1.3, not all necessary events were implemented in phpBB yet, so this extension needed an extra edit in the code. In phpBB 3.1.4, all necessary events are available, but this extension still has to adapt to it. I expect I will do this within a month from now.
infinitiv
Registered User
Posts: 166
Joined: Sat Nov 15, 2014 3:47 pm
Location: PL
Name: Ficjusz

Re: [DEV] Hide BBcode

Post by infinitiv »

Well, okay.
User avatar
alhitary
Registered User
Posts: 868
Joined: Wed Jan 17, 2007 7:51 am
Location: ROY
Name: Basil Taha Alhitary
Contact:

Re: [DEV] Hide BBcode

Post by alhitary »

marcovo wrote:With phpBB 3.1.3, not all necessary events were implemented in phpBB yet, so this extension needed an extra edit in the code. In phpBB 3.1.4, all necessary events are available, but this extension still has to adapt to it. I expect I will do this within a month from now.
a month has gone
and it is now 3.1.5
;)
any update ?
Locked

Return to “Abandoned Extensions”