[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.
parshakov
Registered User
Posts: 35
Joined: Sun Jul 28, 2013 8:03 pm

Re: [RC] Hide BBcode

Post by parshakov » Sun Nov 08, 2015 9:47 pm

Cl0wnie wrote:
parshakov wrote:Cl0wnie, try this:

ext/marcovo/hide_bbcode/event/listener.php

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 && in_array($event['mode'], array('reply', 'quote')) && !$event['preview'] && $event['draft_id'] == 0)	
		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 don't mean any offense by this but do you even know what you're doing? By that I mean are you even testing this yourself on your own board or you're just changing codes and hoping for the best?
Works perfectly on my forum. Maybe in your case the code doesn't work because you are using a newer version of the extension.

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

Re: [RC] Hide BBcode

Post by Tarantino » Mon Nov 16, 2015 2:32 pm

I installed this, but I it doesn't appear on "extension" list. Why? How can I configure it?

John45
Registered User
Posts: 199
Joined: Sat Jun 08, 2013 2:54 am

Re: [RC] Hide BBcode

Post by John45 » Sat Nov 28, 2015 10:45 pm

The admin can see the Hidden Content without replying. How can I let VIP users do the same thing?

Please help.

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

Re: [RC] Hide BBcode

Post by Tarantino » Sun Nov 29, 2015 4:07 am

Give them permission.

BF79
Registered User
Posts: 244
Joined: Fri Feb 13, 2015 1:28 pm

Re: [RC] Hide BBcode

Post by BF79 » Mon Dec 07, 2015 7:29 pm

PLZ guys I need help to edit and add some lines...

right now when I have bbcode hide..
the message is
You need to reply to this topic before you can view the hidden message
I want to add two or three message in same hide code ENGLISH already have + I want to add russian and Portugal
the message will show
You need to reply to this topic before you can view the hidden message
Вы должны ответить на эту тему, прежде чем вы можете просмотреть скрытый сообщение
Você precisa responder a este tópico antes de poder ver a mensagem escondida

parshakov
Registered User
Posts: 35
Joined: Sun Jul 28, 2013 8:03 pm

Re: [RC] Hide BBcode

Post by parshakov » Mon Dec 07, 2015 9:45 pm

BF79,

Go to /ext/marcovo/hide_bbcode/language, create a new folder there named 'ru', and copy hide_bbcode.php from /ext/marcovo/hide_bbcode/language/en to /ext/marcovo/hide_bbcode/language/ru. Now open that file in your editor and simply translate the four lines inside array_merge into Russian.

BF79
Registered User
Posts: 244
Joined: Fri Feb 13, 2015 1:28 pm

Re: [RC] Hide BBcode

Post by BF79 » Tue Dec 08, 2015 8:07 pm

parshakov wrote:BF79,

Go to /ext/marcovo/hide_bbcode/language, create a new folder there named 'ru', and copy hide_bbcode.php from /ext/marcovo/hide_bbcode/language/en to /ext/marcovo/hide_bbcode/language/ru. Now open that file in your editor and simply translate the four lines inside array_merge into Russian.
done !!

THANKS :)

John45
Registered User
Posts: 199
Joined: Sat Jun 08, 2013 2:54 am

Re: [RC] Hide BBcode

Post by John45 » Mon Dec 21, 2015 3:13 am

Tarantino wrote:Give them permission.
I would, but it's not there. :(

Jermin
Registered User
Posts: 25
Joined: Mon Feb 09, 2015 7:46 am

Re: [RC] Hide BBcode

Post by Jermin » Wed Jan 27, 2016 12:48 pm

My forum won't recognize the Chinese language files (in zh_CN folder). Other extensions all use the zh_cmn_hans folder. However, when I changed the folder name and refresh the page, I goet a 500 error. Any ideas? :roll:

Tekamei
Registered User
Posts: 8
Joined: Sat Apr 25, 2015 8:24 pm

Re: [RC] Hide BBcode

Post by Tekamei » Sat May 28, 2016 5:16 pm

Is it possible to hide content of the post from the users except admins and moderators (all not only global)?

parshakov and Cl0wnie posted the code to do something similar but how to add "2 hides" - 1st until reply (normal) 2nd only to moderators and admins?

User avatar
david63
Jr. Extension Validator
Posts: 12948
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Name: David Wood
Contact:

Re: [RC] Hide BBcode

Post by david63 » Sat May 28, 2016 6:12 pm

Tekamei wrote:Is it possible to hide content of the post from the users except admins and moderators (all not only global)?
Yes - just set the correct permissions
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email or as they will be ignored

Tekamei
Registered User
Posts: 8
Joined: Sat Apr 25, 2015 8:24 pm

Re: [RC] Hide BBcode

Post by Tekamei » Sat May 28, 2016 6:32 pm

david63 wrote:
Tekamei wrote:Is it possible to hide content of the post from the users except admins and moderators (all not only global)?
Yes - just set the correct permissions
Where can I do this and which code should I get?

Sepp71
Registered User
Posts: 75
Joined: Sat Sep 06, 2008 11:32 pm
Location: Germany

Re: [RC] Hide BBcode

Post by Sepp71 » Sat Jun 18, 2016 2:26 pm

Tekamei wrote:
david63 wrote:
Tekamei wrote:Is it possible to hide content of the post from the users except admins and moderators (all not only global)?
Yes - just set the correct permissions
Where can I do this and which code should I get?
I would like to help you, but I couldn't find permissions like this either. And there ist definitely nothing like a description of permissions in the language folder.
Sepp

parshakov
Registered User
Posts: 35
Joined: Sun Jul 28, 2013 8:03 pm

Re: [RC] Hide BBcode

Post by parshakov » Sat Jun 18, 2016 10:09 pm

Tekamei wrote:
david63 wrote:
Tekamei wrote:Is it possible to hide content of the post from the users except admins and moderators (all not only global)?
Yes - just set the correct permissions
Where can I do this and which code should I get?
To hide content from all but admins and moderators, change the code in /ext/marcovo/hide_bbcode/event/listener.php
to this:

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_text_for_display_after'	=> 'parse_bbcodes_after',
			'core.modify_format_display_text_after'	=> 'parse_bbcodes_topicPreview',

			'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()
	{

		// Allow only groups with group_id specified below to see the content
		$sql = "SELECT group_id	FROM " . USER_GROUP_TABLE . " WHERE (group_id = 4 OR group_id = 5) 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');

	}
}
This code might not hide attachments though and will not hide content from users who haven't posted in the thread. To make sure it works, find the next line after "// Allow only groups with group_id specified below to see the content" and check if group_id matches group ids for admins and moderators on your forum. Let me know if you need help finding the Group ID's.

Tested on phpBB 3.1.9.


Locked

Return to “Abandoned Extensions”

Who is online

Users browsing this forum: No registered users and 3 guests