IPB - hidden content
#1

Ok so I have tried to disable when you post it unhides the hide tags

 

Here is where I think the edit needs to be

 

 

<?php
/**
 * (TB) Hide Content
 * @file tbHideContent.php BBcode custom plugin
 *
 * @copyright © 2006 - 2013 Invision Byte
 * @link http://www.invisionbyte.net/
 * @author Terabyte
 * @since 01/07/2009
 * @updated 09/12/2012
 * @version 3.0.7 (30007)
 */
 
/* Load the parent class if it is not available at this point */
if( !class_exists('bbcode_parent_class') )
{
require_once( IPS_ROOT_PATH.'sources/classes/bbcode/custom/defaults.php');
}
 
/**
 * @class bbcode_hide
 * @brief BBcode custom plugin
 */
class bbcode_hide extends bbcode_parent_class implements bbcodePlugin
{
/**
* Topic Data
*
* @var $topic
*/
private $topic;
 
/**
* Can bypass the check or not
*
* @var $bypass
*/
private $bypass = FALSE;
 
/**
* Constructor
*
* @param object $registry Registry object
* @param object $_parent Parent bbcode class
* @return @e void
*/
public function __construct( ipsRegistry $registry, $_parent=null )
{
$this->currentBbcode = 'hide';
 
parent::__construct( $registry, $_parent );
 
if ( $_parent->parsing_section != 'topics' )
{
$this->topic = array( 'tid' => 0 );
}
 
/* Init our code */
$this->cache->updateCacheWithoutSaving( '_tmp_bbcode_hide', array() );
 
/* Can bypass the check? */
$this->settings['tb_hc_groups']  = IPSText::cleanPermString( trim($this->settings['tb_hc_groups']) );
$this->settings['tb_hc_members'] = IPSText::cleanPermString( trim($this->settings['tb_hc_members']) );
 
if ( $this->settings['tb_hc_groups'] != '' && IPSMember::isInGroup( $this->memberData, explode(',', $this->settings['tb_hc_groups']) ) )
{
$this->bypass = TRUE;
}
elseif ( $this->memberData['member_id'] > 0 && $this->settings['tb_hc_members'] != '' && in_array( $this->memberData['member_id'], array_map( 'trim', explode(",", $this->settings['tb_hc_members']) ) ) )
{
$this->bypass = TRUE;
}
 
ipsRegistry::getAppClass('forums');
}
 
/**
* Setup the topic ID
*
* @return @e boolean Returns FALSE if check fails otherwise returns true
*/
private function _setupTopic()
{
// Topic is already setup?
if ( !isset($this->topic['tid']) )
{
if ( $this->cache->exists('tb_hide_topic') && !empty($this->caches['tb_hide_topic']['tid']) )
{
$this->topic = $this->cache->getCache('tb_hide_topic', false);
$this->cache->updateCacheWithoutSaving( 'tb_hide_topic', array() );
}
elseif ( isset($this->registry->class_forums->topic_cache['tid']) && $this->registry->class_forums->topic_cache['tid'] )
{
$this->topic['tid'] = $this->registry->class_forums->topic_cache['tid'];
$this->topic['starter_id'] = $this->registry->class_forums->topic_cache['starter_id'];
$this->topic['last_poster_id'] = $this->registry->class_forums->topic_cache['last_poster_id'];
}
else
{
/* If we are here we are not parsing a topic or something is wrong :| */
$this->topic = array( 'tid' => 0 );
}
}
 
return TRUE;
}
 
/**
* Do the actual replacement
*
* @param string $txt Parsed text from database to be edited
* @return @e string BBCode content, ready for editing
*/
protected function _replaceText( $txt )
{
# Setup the topic
$this->_setupTopic();
 
//-----------------------------------------
// Get all our aliases :|
//-----------------------------------------
$_tags = $this->_retrieveTags();
 
foreach( $_tags as $_tag )
{
//-----------------------------------------
// Start building open/close tag
//-----------------------------------------
$open_tag = '[' . $_tag . ']';
$close_tag = '[/' . $_tag . ']';
 
/* Infinite loop catcher */
$_iteration = 0;
 
//-----------------------------------------
// Doz I can haz opin tag? Loopy loo
//-----------------------------------------
while( ( $this->cur_pos = stripos( $txt, $open_tag, $this->cur_pos ) ) !== false )
{
/* Stop infinite loops */
if( $_iteration > $this->settings['max_bbcodes_per_post'] )
{
break;
}
 
$_iteration++;
 
/* Grab the new position to jump to */
$new_pos = strpos( $txt, ']', $this->cur_pos ) ? strpos( $txt, ']', $this->cur_pos ) : $this->cur_pos + 1;
 
/* No closing tag */
if( stripos( $txt, $close_tag, $new_pos ) === false )
{
break;
}
 
/* Different topic ID? */
if ( isset($this->caches['tb_hide_topic']['tid']) && $this->topic['tid'] != $this->caches['tb_hide_topic']['tid'] )
{
$this->topic = $this->cache->getCache('tb_hide_topic', false);
}
 
// Init cache things =O
$existing = $this->cache->getCache('_tmp_bbcode_hide', false);
 
if( !isset($existing[ $this->topic['tid'] ]))
{
$existing[ $this->topic['tid'] ] = false;
 
# Bypass
if ( $this->bypass )
{
$existing[ $this->topic['tid'] ] = true;
}
# Topic starter/Last Poster
elseif ( $this->memberData['member_id'] )
{
if ( $this->topic['starter_id'] == $this->memberData['member_id'] || $this->topic['last_poster_id'] == $this->memberData['member_id'] )
{
$existing[ $this->topic['tid'] ] = true;
}
# Get from DB
elseif ( $this->topic['tid'] > 0 )
{
$hideCheck = $this->DB->buildAndFetch( array( 'select' => 'pid',
 'from'   => 'posts',
 'where'  => 'topic_id=' . $this->topic['tid'] . ' AND author_id=' . $this->memberData['member_id'] . ' AND ' . $this->registry->class_forums->fetchPostHiddenQuery('visible'),
 'limit'  => array( 0, 1 )
 ) );
 
$existing[ $this->topic['tid'] ] = ( intval($hideCheck['pid']) > 0 ) ? true : false;
 
// [EN34] Ajax Thanks v1.0.7
 
if ( $this->settings['en30_ajaxthanks'] && $this->settings['en30_ajaxthankshidehack'] && ! $existing[ $this->topic['tid'] ] && $this->memberData['member_id'] )
{
$this->DB->build( array( 'select' => 'thankers', 'from' => 'posts', 'where' => 'topic_id='.$this->topic['tid'] ) );
$this->DB->execute();
 
while( $row = $this->DB->fetch() )
{
if ( $row['thankers'] != "" )
{
$thankers = unserialize( stripslashes( $row['thankers'] ) );
 
foreach ( $thankers as $id => $name )
{
if ( $id == $this->memberData['member_id'] )
{
$existing[ $this->topic['tid'] ] = true;
break;
}
}
}
 
if ( $existing[ $this->topic['tid'] ] )
{
break;
}
}
}
 
// [EN34] Ajax Thanks v1.0.7
 
}
}
 
/* Update our cache */
$this->cache->updateCacheWithoutSaving( '_tmp_bbcode_hide', $existing );
}
 
/* Grab content */
$_content = substr( $txt, ($this->cur_pos + strlen($open_tag)), (stripos( $txt, $close_tag, $this->cur_pos ) - ($this->cur_pos + strlen($open_tag))) );
 
/* Replace time */
if( $_content )
{
$txt = substr_replace( $txt, $this->_buildOutput( $_content, $existing[ $this->topic['tid'] ] ), $this->cur_pos, (stripos( $txt, $close_tag, $this->cur_pos ) + strlen($close_tag) - $this->cur_pos) );
}
else
{
$txt = substr_replace( $txt, '', $this->cur_pos, (stripos( $txt, $close_tag, $this->cur_pos ) + strlen($close_tag) - $this->cur_pos) );
}
 
/* Reset current position */
$this->cur_pos = stripos( $txt, $open_tag ) ? stripos( $txt, $open_tag ) : $this->cur_pos + 1;
 
if( $this->cur_pos > strlen($txt) )
{
$this->cur_pos = 0;
break;
}
}
}
 
return $txt;
}
 
/**
* Build the actual output to show

* @param string $content This is the contents of the quote
* @param bool $hasReplied TRUE if the member has replied to the topic or can bypass
* @return @e string Content to replace bbcode with
*/
private function _buildOutput( $content, $hasReplied=false )
{
//-----------------------------------------
// Build output and return it
//-----------------------------------------
$output = '<!--TB_HIDE_CONTENT-->';
 
/* Init our state, yay! */
$hideState = $this->cache->getCache( 'tb_hide_topicState', false );
$hideState = is_array($hideState) ? $hideState : array();
 
/* Has replied to the topic already? */
 
if ( $hasReplied )
{
$hideState[ $this->topic['tid'] ] = false;
 
//$output .= $this->registry->getClass('output')->getTemplate('post')->tbUnhiddenContent( $content );
$output .= $this->registry->getClass('output')->getTemplate('post')->tbHiddenContent();
}
else
{
$hideState[ $this->topic['tid'] ] = false;
 
/* Sort if we have attachments to remove.. */
if ( stripos( $content, '[attachment=' ) !== FALSE )
{
preg_match_all( "#\[attachment=(\d+?)\Sad?:[^\]]+?)\]#is", $content, $match );
 
if ( is_array($match[0]) and count($match[0]) )
{
/* No cache setup yet? */
if ( $this->cache->exists('tb_hide_attachs') )
{
$_currentAttachs = $this->cache->getCache('tb_hide_attachs', false);
}
else
{
$_currentAttachs = array();
}
 
/* Cycle through attachments */
for ( $i = 0 ; $i < count($match[0]) ; $i++ )
{
if ( intval($match[1][$i]) == $match[1][$i] )
{
$_currentAttachs[ $match[1][$i] ] = $match[1][$i];
}
}
 
$this->cache->updateCacheWithoutSaving( 'tb_hide_attachs' , $_currentAttachs );
}
}
 
/* ..and take care of the output */
$output .= $this->registry->getClass('output')->getTemplate('post')->tbHiddenContent();
}
 
/* Save our topic status, yup save it here! */
$this->cache->updateCacheWithoutSaving( 'tb_hide_topicState', $hideState );
 
return $output;
}
}

#2

I changed this:

 

 

/* Has replied to the topic already? */
 
if ( $hasReplied )
{
//$hideState[ $this->topic['tid'] ] = true;  <--- OLD
$hideState[ $this->topic['tid'] ] = false;
 
//$output .= $this->registry->getClass('output')->getTemplate('post')->tbUnhiddenContent( $content );   <---- OLD
$output .= $this->registry->getClass('output')->getTemplate('post')->tbHiddenContent();
}
but posting still unhides the hide tags any help would be great Smile


Forum Jump:


Users browsing this thread: 1 Guest(s)