Version 3.4.5

This commit is contained in:
Neo committed 2025-12-19 00:38:12 -08:00
1 parent fb6b5baabc
commit e4478369d8
1360 files changed
+228921 -179445

No files matched your search

@@ -3,19 +3,19 @@
/**
* <pre>
* Invision Power Services
* IP.Board v3.3.4
* IP.Board v3.4.5
* Admin forum functions library
* Last Updated: $Date: 2012-06-12 10:14:49 -0400 (Tue, 12 Jun 2012) $
* Last Updated: $Date: 2012-05-22 13:10:11 -0400 (Tue, 22 May 2012) $
* </pre>
*
* @author $Author: bfarber $
* @author $Author: ips_terabyte $
* @copyright (c) 2001 - 2009 Invision Power Services, Inc.
* @license http://www.invisionpower.com/company/standards.php#license
* @package IP.Board
* @subpackage Forums
* @link http://www.invisionpower.com
* @since 26th January 2004
* @version $Rev: 10914 $
* @version $Rev: 10783 $
*
*/
@@ -2,19 +2,19 @@
/**
* <pre>
* Invision Power Services
* IP.Board v3.3.4
* IP.Board v3.4.5
* Forums Class
* Last Updated: $Date: 2012-06-15 10:12:59 -0400 (Fri, 15 Jun 2012) $
* Last Updated: $Date: 2013-03-27 20:18:32 -0400 (Wed, 27 Mar 2013) $
* </pre>
*
* @author $Author: mmecham $
* @author $Author: bfarber $
* @copyright (c) 2001 - 2009 Invision Power Services, Inc.
* @license http://www.invisionpower.com/company/standards.php#license
* @package IP.Board
* @subpackage Forums
* @link http://www.invisionpower.com
* @since 26th January 2004
* @version $Rev: 10931 $
* @version $Rev: 12132 $
*/
if ( ! defined( 'IN_IPB' ) )
@@ -278,6 +278,17 @@ class class_forums
return $canPost;
}
/**
* is the answer system enabled?
* @param int $forumId
*/
public function answerTopicsEnabled( $forumId )
{
$forumData = $this->getForumById( $forumId );
return ( ! empty( $forumData['bw_enable_answers'] ) ) ? true : false;
}
/**
* Returns a list of all forums
*
@@ -331,33 +342,11 @@ class class_forums
/* Reformat the array for a category */
if ( $f['parent_id'] == -1 )
{
$fr['id'] = $f['id'];
$fr['sub_can_post'] = $f['sub_can_post'];
$fr['name'] = $f['name'];
$fr['name_seo'] = $f['name_seo'];
$fr['parent_id'] = $f['parent_id'];
$fr['skin_id'] = $f['skin_id'];
$fr['permission_showtopic'] = $f['permission_showtopic'];
$fr['forums_bitoptions'] = $f['forums_bitoptions'];
$fr = $f;
$fr['parent_id'] = 'root';
$fr['hide_last_info'] = 0;
$fr['can_view_others'] = 0;
$fr['password'] = $f['password'];
/* Permission index columns */
$fr['app'] = $f['app'];
$fr['perm_id'] = $f['perm_id'];
$fr['perm_type'] = $f['perm_type'];
$fr['perm_type_id'] = $f['perm_type_id'];
$fr['perm_view'] = $f['perm_view'];
$fr['perm_2'] = $f['perm_2'];
$fr['perm_3'] = $f['perm_3'];
$fr['perm_4'] = $f['perm_4'];
$fr['perm_5'] = $f['perm_5'];
$fr['perm_6'] = $f['perm_6'];
$fr['perm_7'] = $f['perm_7'];
$fr['owner_only'] = $f['owner_only'];
$fr['friend_only'] = $f['friend_only'];
$fr['authorized_users'] = $f['authorized_users'];
}
else
{
@@ -762,9 +751,9 @@ class class_forums
/* Pass it along */
$this->registry->permissions->setMemberData( $this->getMemberData() );
if ( $this->registry->permissions->check( 'view', $this->forum_by_id[$fid] ) == TRUE )
if ( $this->registry->permissions->check( 'view', $this->allForums[$fid] ) == TRUE )
{
if ( $this->registry->permissions->check( 'read', $this->forum_by_id[$fid] ) == TRUE )
if ( $this->registry->permissions->check( 'read', $this->allForums[$fid] ) == TRUE )
{
$deny_access = 0;
}
@@ -774,7 +763,7 @@ class class_forums
// Can see topics?
//-----------------------------------------
if ( $this->forum_by_id[$fid]['permission_showtopic'] )
if ( $this->allForums[$fid]['permission_showtopic'] )
{
$this->read_topic_only = 1;
@@ -830,11 +819,11 @@ class class_forums
{
$group_exempt = 0;
if ( isset( $this->forum_by_id[$fid]['password'] ) AND $this->forum_by_id[$fid]['password'] != '' AND $this->forum_by_id[$fid]['sub_can_post'] )
if ( isset( $this->allForums[$fid]['password'] ) AND $this->allForums[$fid]['password'] != '' AND $this->allForums[$fid]['sub_can_post'] )
{
if ( isset( $this->forum_by_id[$fid]['password_override'] ) && IPSText::cleanPermString($this->forum_by_id[$fid]['password_override']) != '' )
if ( isset( $this->allForums[$fid]['password_override'] ) && IPSText::cleanPermString($this->allForums[$fid]['password_override']) != '' )
{
if ( IPSMember::isInGroup( $this->_memberData, explode( ",", IPSText::cleanPermString($this->forum_by_id[$fid]['password_override']) ) ) )
if ( IPSMember::isInGroup( $this->_memberData, explode( ",", IPSText::cleanPermString($this->allForums[$fid]['password_override']) ) ) )
{
$group_exempt = 1;
$deny_access = 0;
@@ -876,7 +865,7 @@ class class_forums
$this->registry->getClass('output')->showError( 'forums_no_view_topic', 103136, null, null, 404 );
}
else if( (!$this->forum_by_id[$fid]['can_view_others'] AND !$this->_memberData['is_mod'] ) AND ( $topic['starter_id'] != $this->_memberData['member_id'] ) )
else if( (!$this->allForums[$fid]['can_view_others'] AND !$this->_memberData['is_mod'] ) AND ( $topic['starter_id'] != $this->_memberData['member_id'] ) )
{
if( $return )
{
@@ -887,7 +876,7 @@ class class_forums
}
}
if( $this->forum_by_id[$fid]['min_posts_view'] && $this->forum_by_id[$fid]['min_posts_view'] > $this->_memberData['posts'] && !$this->_memberData['g_is_supmod'] )
if( $this->allForums[$fid]['min_posts_view'] && $this->allForums[$fid]['min_posts_view'] > $this->_memberData['posts'] && !$this->_memberData['g_is_supmod'] )
{
if( $return )
{
@@ -1045,7 +1034,13 @@ class class_forums
{
$forum_data['_has_unread'] = ( $forum_data['last_post'] && $forum_data['last_post'] > $rtime ) ? 1 : 0;
}
/* Let's fix an empty forum ID... Bug #38436 */
if ( empty($forum_data['fid']) && $forum_data['id'] )
{
$forum_data['fid'] = $forum_data['id'];
}
if ( isset( $this->forum_cache[ $root_id ]) AND is_array( $this->forum_cache[ $root_id ] ) )
{
foreach( $this->forum_cache[ $root_id ] as $data )
@@ -1305,7 +1300,7 @@ class class_forums
$forum_data['full_last_title'] = isset( $forum_data['last_title'] ) ? $forum_data['last_title'] : '';
$forum_data['_hide_last_date'] = false;
if (isset($forum_data['last_title']) and $forum_data['last_id'])
if ( isset($forum_data['last_title']) && $forum_data['last_id'] )
{
$forum_data['last_title'] = strip_tags( $forum_data['last_title'] );
$forum_data['last_title'] = str_replace( "&#33;" , "!", $forum_data['last_title'] );
@@ -1329,7 +1324,7 @@ class class_forums
if ( $this->memberData['member_id'] || $this->settings['topic_marking_guests'] )
{
$forum_data['last_topic_title'] = "<a href='" . $this->registry->getClass('output')->formatUrl( $this->registry->getClass('output')->buildUrl( "showtopic={$forum_data['last_id']}&amp;view=getnewpost", 'public' ), $forum_data['seo_last_title'], 'showtopicunread' ) . "' title='{$forum_data['full_last_title']}'>{$forum_data['last_title']}</a>";
$forum_data['last_topic_title'] = "<a href='" . $this->registry->getClass('output')->formatUrl( $this->registry->getClass('output')->buildUrl( "showtopic={$forum_data['last_id']}&amp;view=getnewpost", 'public' ), $forum_data['seo_last_title'], 'showtopic' ) . "' title='{$forum_data['full_last_title']}'>{$forum_data['last_title']}</a>";
}
else
{
@@ -1966,8 +1961,8 @@ class class_forums
* Fetch correct flag
* Pass several or one field through ->fetchTopicHiddenFlag( array('not', 'archived', 'working', 'exclude' ) );
*
* @param array
* @return string
* @param string
* @return integer
*/
public function fetchTopicArchiveFlag( $type )
{
@@ -2219,14 +2214,14 @@ class class_forums
/* Last poster */
$last_post = $this->DB->buildAndFetch( array( 'select' => 'tid, title, last_poster_id, last_poster_name, seo_last_name, last_post',
'from' => 'topics',
'where' => $this->fetchTopicHiddenQuery( array( 'visible' ), '' ) . " and forum_id={$fid}",
'where' => $this->fetchTopicHiddenQuery( array( 'visible' ), '' ) . " and forum_id={$fid}" . " AND state != 'link'",
'order' => 'last_post DESC',
'limit' => array( 1 ) ) );
/* Newest topic */
$newest_topic = $this->DB->buildAndFetch( array( 'select' => 'title, tid, seo_first_name',
'from' => 'topics',
'where' => 'forum_id=' . $fid . ' and ' . $this->fetchTopicHiddenQuery( array( 'visible' ), '' ),
'where' => 'forum_id=' . $fid . ' and ' . $this->fetchTopicHiddenQuery( array( 'visible' ), '' ) . " AND state != 'link'",
'order' => 'start_date desc',
'limit' => array( 1 ) ) );
@@ -2712,6 +2707,28 @@ class class_forums
return array( 'count' => $count, 'tids' => $tids );
}
/**
* Coverts a page number to a start value
* @param int $page
*/
public function pageToSt( $page )
{
$page = intval( $page );
return ( $page > 1 ) ? ( ( $page - 1 ) * $this->settings['display_max_topics'] ) : 0;
}
/**
* Coverts a st value to a page number
* @param int $page
*/
public function stToPage( $st )
{
$st = intval( $st );
return ( $st > 0 ) ? ( ceil( $st / $this->settings['display_max_topics'] ) + 1 ) : 1;
}
/**
* Hook: Facebook sidebar block
*
@@ -2810,7 +2827,7 @@ class class_forums
{
/* Query Topics */
$this->registry->DB()->build( array(
'select' => 't.tid, t.title as topic_title, t.title_seo, t.start_date, t.starter_id, t.starter_name, t.moved_to, t.views, t.posts',
'select' => 't.tid, t.title as topic_title, t.title_seo, t.start_date, t.starter_id, t.starter_name, t.moved_to, t.views, t.posts, t.topic_answered_pid',
'from' => array( 'topics' => 't' ),
'where' => 't.tid IN (' . implode( ',', array_values( $_topics ) ) . ')',
'add_join' => array(
@@ -3,10 +3,10 @@
/**
* <pre>
* Invision Power Services
* IP.Board v3.3.4
* IP.Board v3.4.5
* Forum hook gateway
* Owner: Matt "Oh Lord, why did I get assigned this?" Mecham
* Last Updated: $Date: 2012-06-12 10:14:49 -0400 (Tue, 12 Jun 2012) $
* Last Updated: $Date: 2012-05-10 16:10:13 -0400 (Thu, 10 May 2012) $
* </pre>
*
* @author $Author: bfarber $
@@ -15,7 +15,7 @@
* @package IP.Board
* @link http://www.invisionpower.com
* @since 9th March 2005 11:03
* @version $Revision: 10914 $
* @version $Revision: 10721 $
*/
class forums_hookGateway
{
@@ -2,18 +2,18 @@
/**
* <pre>
* Invision Power Services
* IP.Board v3.3.4
* IP.Board v3.4.5
* Moderator actions
* Last Updated: $Date: 2012-06-27 12:46:44 -0400 (Wed, 27 Jun 2012) $
* Last Updated: $Date: 2012-06-29 10:12:14 -0400 (Fri, 29 Jun 2012) $
* </pre>
*
* @author $Author: AndyMillne $
* @author $Author: bfarber $
* @copyright (c) 2001 - 2009 Invision Power Services, Inc.
* @license http://www.invisionpower.com/company/standards.php#license
* @package IP.Board
* @subpackage Forums
* @link http://www.invisionpower.com
* @version $Revision: 10995 $
* @version $Revision: 11007 $
*
*/
File diff suppressed because it is too large. Load diff
@@ -2,19 +2,19 @@
/**
* <pre>
* Invision Power Services
* IP.Board v3.3.4
* IP.Board v3.4.5
* Posting display formatting methods
* Last Updated: $Date: 2012-07-09 12:56:26 -0400 (Mon, 09 Jul 2012) $
* Last Updated: $Date: 2013-03-20 10:14:51 -0400 (Wed, 20 Mar 2013) $
* </pre>
* File Created By: Matt Mecham
*
* @author $Author: AndyMillne $
* @author $Author: mmecham $
* @copyright (c) 2001 - 2009 Invision Power Services, Inc.
* @license http://www.invisionpower.com/company/standards.php#license
* @package IP.Board
* @subpackage Forums
* @link http://www.invisionpower.com
* @version $Revision: 11047 $
* @version $Revision: 12094 $
*/
if ( ! defined( 'IN_IPB' ) )
@@ -128,6 +128,9 @@ class classPostForms extends classPost
$extraData['reasonForEdit'] = $this->request['post_edit_reason'] ? $this->request['post_edit_reason'] : $this->_originalPost['post_edit_reason'];
$extraData['append_edit'] = $this->request['append_edit'] ? $this->request['append_edit'] : $this->_originalPost['append_edit'];
/* HTML set? */
$this->setSettings( array( 'post_htmlstatus' => $this->_originalPost['post_htmlstate'] ) );
$extraData['checkBoxes'] = $this->_generateCheckBoxes( 'edit', isset( $topic['tid'] ) ? $topic['tid'] : 0, $this->getForumData('id') );
//-----------------------------------------
@@ -138,7 +141,6 @@ class classPostForms extends classPost
$postContent = $this->getPostContentPreFormatted() ? $this->getPostContentPreFormatted() : $this->getPostContent();
$postContent = $this->_afterPostCompile( $postContent, 'edit' );
//-----------------------------------------
// Do we have any posting errors?
//-----------------------------------------
@@ -312,25 +314,35 @@ class classPostForms extends classPost
//-----------------------------------------
// Appending a reason for the edit?
//-----------------------------------------
if ( $this->getAuthor('g_append_edit') )
{
$extraData['showEditOptions'] = 1;
if ( !empty( $this->_originalPost['append_edit'] ) )
$extraData['showAppendEdit'] = 0;
if ( $this->getAuthor('g_append_edit') )
{
$extraData['showEditOptions'] = 1;
$extraData['showAppendEdit'] = 1;
if ( $this->_originalPost['append_edit'] )
{
$extraData['checked'] = "checked";
}
$extraData['checked'] = 'checked';
}
else
{
$extraData['checked'] = '';
}
}
if ( !empty( $this->moderator['edit_post'] ) OR $this->getAuthor('g_is_supmod') )
if ( isset( $this->moderator['edit_post'] ) && $this->moderator['edit_post'] OR $this->getAuthor('g_is_supmod') )
{
$extraData['showEditOptions'] = 1;
$extraData['showReason'] = 1;
}
/* Reset reason for edit */
$extraData['reasonForEdit'] = $this->request['post_edit_reason'] ? $this->request['post_edit_reason'] : $this->_originalPost['post_edit_reason'];
$extraData['reasonForEdit'] = $this->request['post_edit_reason'] ? $this->request['post_edit_reason'] : $this->_originalPost['post_edit_reason'];
$extraData['append_edit'] = $this->request['append_edit'] ? $this->request['append_edit'] : $this->_originalPost['append_edit'];
/* Reset check boxes and such */
$this->setSettings( array( 'enableSignature' => $this->_originalPost['use_sig'],
'enableEmoticons' => $this->_originalPost['use_emo'],
@@ -386,7 +398,7 @@ class classPostForms extends classPost
{
$output .= $this->registry->getClass('output')->getTemplate('post')->preview( $this->_generatePostPreview( $this->getPostContentPreFormatted() ? $this->getPostContentPreFormatted() : $this->getPostContent(), $this->post_key ) );
}
/* Defaults */
if( ! isset( $extraData['checked'] ) )
{
@@ -564,6 +576,13 @@ class classPostForms extends classPost
$postContent = IPSText::stripslashes( $_POST['Post'] );
}
}
else if ( $this->getIsPreview() )
{
if ( isset($_POST['Post']) )
{
$postContent = $_POST['Post'];
}
}
return $postContent;
}
@@ -620,10 +639,12 @@ class classPostForms extends classPost
$_queued = $this->registry->class_forums->fetchPostHiddenQuery( array( 'visible' ), 'p.' );
$sort_field = ($this->settings['post_order_column'] == 'pid') ? 'p.pid' : 'p.post_date';
$this->DB->build( array( 'select' => 'p.*',
'from' => array( 'posts' => 'p' ),
'where' => 'p.topic_id=' . $topicID . ' AND ' . $_queued,
'order' => 'p.pid DESC',
'order' => $sort_field . ' DESC',
'limit' => array( 0, 10 ),
'add_join' => array(
array( 'select' => 'm.members_display_name, m.member_group_id, m.mgroup_others, m.member_id, m.members_seo_name',
@@ -646,25 +667,25 @@ class classPostForms extends classPost
$post_query = $this->DB->execute();
/* Load parser */
$classToLoad = IPSLib::loadLibrary( IPS_ROOT_PATH . 'sources/classes/text/parser.php', 'classes_text_parser' );
$parser = new $classToLoad();
while ( $row = $this->DB->fetch($post_query) )
{
$row['author'] = $row['members_display_name'] ? $row['members_display_name'] : $row['author_name'];
$row['date'] = $this->registry->getClass('class_localization')->getDate( $row['post_date'], 'LONG' );
//-----------------------------------------
// Parse the post
//-----------------------------------------
IPSText::getTextClass( 'bbcode' )->parse_smilies = $row['use_emo'];
IPSText::getTextClass( 'bbcode' )->parse_html = $row['post_htmlstate'];
IPSText::getTextClass( 'bbcode' )->parse_nl2br = $row['post_htmlstate'] == 2 ? 1 : 0;
IPSText::getTextClass( 'bbcode' )->parse_bbcode = $row['use_ibc'];
IPSText::getTextClass( 'bbcode' )->parsing_section = 'topics';
IPSText::getTextClass( 'bbcode' )->parsing_mgroup = $row['member_group_id'];
IPSText::getTextClass( 'bbcode' )->parsing_mgroup_others = $row['mgroup_others'];
$row['post'] = IPSText::getTextClass('bbcode')->preDisplayParse( $row['post'] );
# Config
$parser->set( array( 'memberData' => $this->memberData,
'parseBBCode' => $this->getForumData('use_ibc'),
'parseArea' => 'topics',
'parseHtml' => (intval($row['post_htmlstate']) AND $this->getForumData('use_html') AND $this->getAuthor('g_dohtml')) ? 1 : 0,
'parseEmoticons' => $row['use_emo'] ) );
# Make sure we have the display look
$row['post'] = $parser->display( $row['post'] );
//-----------------------------------------
// Are we giving this bloke a good ignoring?
@@ -754,7 +775,7 @@ class classPostForms extends classPost
{
$return['emo'] = "";
}
if ( $this->_canHtml( $forumID ) )
{
$return['html'] = ( $this->getSettings('post_htmlstatus') ) ? ' checked="checked"' : '';
@@ -861,7 +882,7 @@ class classPostForms extends classPost
{
$selected = ($this->getModOptions() == 'nowt') ? " selected='selected'" : '';
$html = "<select id='forminput' name='mod_options' class='forminput'>\n<option value='nowt'{$selected}>".$this->lang->words['mod_nowt']."</option>\n";
$html = "<select id='forminput' name='mod_options' class='forminput' tabindex='61'>\n<option value='nowt'{$selected}>".$this->lang->words['mod_nowt']."</option>\n";
}
if ($can_pin AND !$topic['pinned'] )
@@ -938,10 +959,10 @@ class classPostForms extends classPost
// Check dates...
//-----------------------------------------
$mytimes['open_time'] = isset($_POST['open_time_time']) ? $_POST['open_time_time'] : '';
$mytimes['open_date'] = isset($_POST['open_time_date']) ? $_POST['open_time_date'] : '';
$mytimes['close_time'] = isset($_POST['close_time_time']) ? $_POST['close_time_time'] : '';
$mytimes['close_date'] = isset($_POST['close_time_date']) ? $_POST['close_time_date'] : '';
$mytimes['open_time'] = isset($_POST['open_time_time']) ? IPSText::parseCleanValue( $_POST['open_time_time'] ) : '';
$mytimes['open_date'] = isset($_POST['open_time_date']) ? IPSText::parseCleanValue( $_POST['open_time_date'] ) : '';
$mytimes['close_time'] = isset($_POST['close_time_time']) ? IPSText::parseCleanValue( $_POST['close_time_time'] ) : '';
$mytimes['close_date'] = isset($_POST['close_time_date']) ? IPSText::parseCleanValue( $_POST['close_time_date'] ) : '';
if( $this->_originalPost['new_topic'] )
{
@@ -1067,7 +1088,7 @@ class classPostForms extends classPost
}
}
if ( $formType == 'edit' AND ( ! isset($_POST['question']) OR ! is_array( $_POST['question'] ) OR ! count( $_POST['question'] ) ) )
if ( $formType == 'edit' AND ( ! isset($_POST['question']) OR ! is_array( $_POST['question'] ) OR ! count( $_POST['question'] ) OR $this->getIsPreview() ) )
{
//-----------------------------------------
// Load the poll from the DB
@@ -1075,11 +1096,11 @@ class classPostForms extends classPost
$this->poll_data = $this->DB->buildAndFetch( array( 'select' => '*', 'from' => 'polls', 'where' => "tid=".$this->getTopicID() ) );
$this->poll_answers = unserialize(stripslashes($this->poll_data['choices']));
$this->poll_answers = IPSLib::safeUnserialize(stripslashes($this->poll_data['choices']));
if( !is_array($this->poll_answers) OR !count($this->poll_answers) )
{
$this->poll_answers = unserialize( preg_replace( '!s:(\d+):"(.*?)";!se', "'s:'.strlen('$2').':\"$2\";'", stripslashes( $this->poll_data['choices'] ) ) );
$this->poll_answers = IPSLib::safeUnserialize( preg_replace( '!s:(\d+):"(.*?)";!se', "'s:'.strlen('$2').':\"$2\";'", stripslashes( $this->poll_data['choices'] ) ) );
}
if ( !is_array($this->poll_answers) OR !count($this->poll_answers) )
{
@@ -1156,17 +1177,19 @@ class classPostForms extends classPost
protected function _generatePostPreview( $postContent="", $post_key='' )
{
$this->registry->class_localization->loadLanguageFile( array( 'public_topic' ) );
IPSText::getTextClass('bbcode')->parse_html = (intval($this->request['post_htmlstatus']) AND $this->getForumData('use_html') AND $this->getAuthor('g_dohtml')) ? 1 : 0;
IPSText::getTextClass('bbcode')->parse_nl2br = $this->request['post_htmlstatus'] == 2 ? 1 : 0;
IPSText::getTextClass('bbcode')->parse_smilies = intval($this->getSettings('enableEmoticons'));
IPSText::getTextClass('bbcode')->parse_bbcode = $this->getForumData('use_ibc');
IPSText::getTextClass('bbcode')->parsing_section = 'topics';
IPSText::getTextClass('bbcode')->parsing_mgroup = $this->memberData['member_group_id'];
IPSText::getTextClass('bbcode' )->parsing_mgroup_others = $this->memberData['mgroup_others'];
# Make sure we have the pre-display look
$postContent = IPSText::getTextClass('bbcode')->preDisplayParse( $postContent );
/* Load parser */
$classToLoad = IPSLib::loadLibrary( IPS_ROOT_PATH . 'sources/classes/text/parser.php', 'classes_text_parser' );
$parser = new $classToLoad();
$parser->set( array( 'memberData' => $this->memberData,
'parseBBCode' => $this->getForumData('use_ibc'),
'parseArea' => 'topics',
'parseHtml' => (intval($this->request['post_htmlstatus']) AND $this->getForumData('use_html') AND $this->getAuthor('g_dohtml')) ? 1 : 0,
'parseEmoticons' => $this->getSettings('enableEmoticons') ) );
# Make sure we have the display look
$postContent = $parser->display( $postContent );
if ( ! is_object( $this->class_attach ) )
{
@@ -2,18 +2,18 @@
/**
* <pre>
* Invision Power Services
* IP.Board v3.3.4
* IP.Board v3.4.5
* Moderator actions
* Last Updated: $Date: 2012-06-15 08:09:05 -0400 (Fri, 15 Jun 2012) $
* Last Updated: $Date: 2013-05-08 12:08:00 -0400 (Wed, 08 May 2013) $
* </pre>
*
* @author $Author: AndyMillne $
* @author $Author: bfarber $
* @copyright (c) 2001 - 2009 Invision Power Services, Inc.
* @license http://www.invisionpower.com/company/standards.php#license
* @package IP.Board
* @subpackage Forums
* @link http://www.invisionpower.com
* @version $Revision: 10929 $
* @version $Revision: 12237 $
*/
if ( ! defined( 'IN_IPB' ) )
@@ -50,7 +50,7 @@ class app_forums_classes_topics
private $_countPosts = 0;
private $_countTopics = 0;
private $_archiveReader = null;
private $_parser = null;
/**
* Return errors, instead of printing
*
@@ -186,7 +186,19 @@ class app_forums_classes_topics
/* May have loaded topic data previously */
if ( empty( $this->registry->class_forums->topic_cache['tid'] ) )
{
$this->DB->build( array( 'select' => '*', 'from' => 'topics', 'where' => 'tid=' . $topicId ) );
/* Load tagging stuff */
if ( ! $this->registry->isClassLoaded('tags') )
{
require_once( IPS_ROOT_PATH . 'sources/classes/tags/bootstrap.php' );/*noLibHook*/
$this->registry->setClass( 'tags', classes_tags_bootstrap::run( 'forums', 'topics' ) );
}
$this->DB->build( array(
'select' => 't.*',
'from' => array( 'topics' => 't' ),
'where' => 't.tid=' . $topicId,
'add_join' => array( $this->registry->tags->getCacheJoin( array( 'meta_id_field' => 't.tid' ) ) )
) );
$this->DB->execute();
$this->setTopicData( $this->DB->fetch() );
@@ -220,7 +232,7 @@ class app_forums_classes_topics
}
/* Set up */
$this->topicData = $this->setUpTopic( $this->topicData );
$this->topicData = $this->setUpTopic( $this->topicData );
}
/**
@@ -245,7 +257,11 @@ class app_forums_classes_topics
/* Got any unread posts? */
$topic['hasUnreadPosts'] = ( $this->registry->classItemMarking->isRead( array( 'forumID' => $topic['forum_id'], 'itemID' => $topic['tid'], 'itemLastUpdate' => $topic['last_post'] ), 'forums' ) ) ? false : true;
$topic['Perms'] = array( 'canQueuePosts' => $this->registry->class_forums->canQueuePosts( $topic['forum_id'] ),
'canAnswerTopic' => $this->registry->topics->canAnswerTopic( $topic ),
'canRateAnswer' => $this->registry->topics->canRateAnsweredPost( $topic ) );
return $topic;
}
@@ -274,16 +290,6 @@ class app_forums_classes_topics
$tid = intval( $tid );
$topicData = $this->getTopicById( $tid );
if ( $this->settings['post_order_column'] != 'post_date' )
{
$this->settings['post_order_column'] = 'pid';
}
if ( $this->settings['post_order_sort'] != 'desc' )
{
$this->settings['post_order_sort'] = 'asc';
}
/* Is this archived? */
if ( $this->isArchived( $topicData ) )
{
@@ -307,8 +313,8 @@ class app_forums_classes_topics
/* Get last post info */
$_post = $this->getPosts( array( 'onlyVisible' => true,
'sortField' => $this->settings['post_order_column'],
'sortOrder' => ( $this->settings['post_order_sort'] == 'asc' ) ? 'desc' : 'asc',
'sortField' => 'post_date',
'sortOrder' => 'desc',
'topicId' => array( $tid ),
'limit' => 1,
'archiveToNative' => true,
@@ -318,8 +324,8 @@ class app_forums_classes_topics
/* Get first post info */
$_post = $this->getPosts( array( 'onlyVisible' => true,
'sortField' => $this->settings['post_order_column'],
'sortOrder' => $this->settings['post_order_sort'],
'sortField' => 'post_date',
'sortOrder' => 'asc',
'topicId' => array( $tid ),
'limit' => 1,
'archiveToNative' => true,
@@ -345,6 +351,9 @@ class app_forums_classes_topics
}
else
{
/* Touch tags to rebuild cache */
$this->registry->getClass('tags')->rebuildCache( array( 'meta_id' => $tid ) );
/* Fetch replies */
$_queued = $this->registry->class_forums->fetchPostHiddenQuery( array( 'visible' ), '' );
$posts = $this->DB->buildAndFetch( array( 'select' => 'COUNT(*) as posts', 'from' => 'posts', 'where' => "topic_id={$tid} and {$_queued}" ) );
@@ -362,8 +371,8 @@ class app_forums_classes_topics
/* Get last post info */
$_post = $this->getPosts( array( 'onlyVisible' => true,
'sortField' => $this->settings['post_order_column'],
'sortOrder' => ( $this->settings['post_order_sort'] == 'asc' ) ? 'desc' : 'asc',
'sortField' => 'post_date',
'sortOrder' => 'desc',
'topicId' => array( $tid ),
'limit' => 1 ) );
@@ -371,8 +380,8 @@ class app_forums_classes_topics
/* Get first post info */
$_post = $this->getPosts( array( 'onlyVisible' => true,
'sortField' => $this->settings['post_order_column'],
'sortOrder' => $this->settings['post_order_sort'],
'sortField' => 'post_date',
'sortOrder' => 'asc',
'topicId' => array( $tid ),
'limit' => 1 ) );
@@ -392,6 +401,7 @@ class app_forums_classes_topics
$this->DB->setDataType( array( 'starter_name', 'last_poster_name' ), 'string' );
$this->DB->update( 'topics', array( 'last_post' => intval($last_post['post_date'] ? $last_post['post_date'] : $first_post['post_date']),
'last_real_post' => intval($last_post['post_date'] ? $last_post['post_date'] : $first_post['post_date']),
'last_poster_id' => intval($last_post['author_id'] ? $last_post['author_id'] : ( $pcount > 0 ? 0 : $first_post['author_id'] )),
'last_poster_name' => $_last_poster_name,
'poll_state' => empty($first_post['has_poll_id']) ? 0 : 1,
@@ -488,19 +498,31 @@ class app_forums_classes_topics
* @param boolean Check for archived topic
* @return array Post Data
*/
public function getPostById( $pid, $checkArchived=false )
public function getPostById( $pid, $checkArchived=false, $additionalFilters=array() )
{
$post = array();
$post = array();
$additionalFilters = ( is_array( $additionalFilters ) ) ? $additionalFilters : array( $additionalFilters );
if ( ! empty($pid) )
{
$posts = $this->getPosts( array( 'postId' => array( $pid ),
'checkArchived' => $checkArchived ) );
$posts = $this->getPosts( array_merge( $additionalFilters, array( 'postId' => array( $pid ),
'checkArchived' => $checkArchived ) ) );
$post = $posts[ $pid ];
}
/* Bitwise options */
$_tmp = IPSBWOptions::thaw( $post['post_bwoptions'], 'posts', 'forums' );
if ( count( $_tmp ) )
{
foreach( $_tmp as $k => $v )
{
$post[ $k ] = $v;
}
}
return $post;
}
@@ -685,7 +707,7 @@ class app_forums_classes_topics
'limit' => $limit ? $limit : '',
'order' => $order ? $order : 't.tid asc',
'add_join' => $joins ) );
$o = $this->DB->execute();
while( $topic = $this->DB->fetch( $o ) )
@@ -726,7 +748,7 @@ class app_forums_classes_topics
/**
* getTopicsCount
* Fetches number of topics based on different critera (useful for pagination when combined with getPosts())
* Fetches number of topics based on different critera (useful for pagination when combined with getTopics())
* @return int
*/
public function getTopicsCount()
@@ -745,6 +767,7 @@ class app_forums_classes_topics
* forumId Get posts matching the (array) forum ids, (int) forum ID
* notForumId Get posts NOT matching the (array) forum ids, (int) forum ID
* postId Get posts matching the (array) post ids, (int) post id
* postDate Get posts matching the (array) post dates, (int) post date
* authorId Get posts matching the (array) author ids, (int) author id
* memberData Set memberData (this->memberData is used otherwise)
* onlyViewable Set whether this member can view them or not. (default is true ) NOTE: Will not check to see if parent topic is viewable!
@@ -786,46 +809,58 @@ class app_forums_classes_topics
}
$posts = $this->_archiveReader->getPosts( $filters );
/* If we just need the count let's go */
if ( $filters['getCountOnly'] )
{
return $posts;
}
/* Fetch topics */
$tids = array();
$mids = array();
foreach( $posts as $id => $post )
if ( !empty( $posts ) )
{
$tids[ $post['topic_id'] ] = $post['topic_id'];
if ( $post['author_id'] )
foreach( $posts as $id => $post )
{
$mids[ $post['author_id'] ] = $post['author_id'];
$tids[ $post['topic_id'] ] = $post['topic_id'];
if ( $post['author_id'] )
{
$mids[ $post['author_id'] ] = $post['author_id'];
}
}
}
$topics = $this->getTopics( array( 'topicId' => $tids ) );
$members = IPSMember::load( $mids );
foreach( $posts as $id => $post )
if ( !empty( $posts ) )
{
$posts[ $id ] = array_merge( $topics[ $post['topic_id'] ], $post );
if ( $post['author_id'] )
foreach( $posts as $id => $post )
{
$_mem = $members[ $post['author_id'] ];
unset( $_mem['title'] );
$posts[ $id ] = array_merge( $_mem, $post );
$posts[ $id ] = array_merge( $topics[ $post['topic_id'] ], $post );
if ( $post['author_id'] )
{
$_mem = $members[ $post['author_id'] ];
unset( $_mem['title'] );
$posts[ $id ] = array_merge( $_mem, $post );
}
if ( ! empty( $filters['parse'] ) )
{
$this->setTopicData( $post );
$this->setPermissionData();
$posts[ $id ] = $this->parsePost( $posts[ $id ] );
}
$posts[ $id ]['tid'] = $post['topic_id'];
$posts[ $id ]['_postType'] = $this->registry->class_forums->fetchHiddenType( $post );
$posts[ $id ]['_topicType'] = $this->registry->class_forums->fetchHiddenTopicType( $post );
}
if ( ! empty( $filters['parse'] ) )
{
$this->setTopicData( $post );
$this->setPermissionData();
$posts[ $id ] = $this->parsePost( $posts[ $id ] );
}
$posts[ $id ]['tid'] = $post['topic_id'];
$posts[ $id ]['_postType'] = $this->registry->class_forums->fetchHiddenType( $post );
$posts[ $id ]['_topicType'] = $this->registry->class_forums->fetchHiddenTopicType( $post );
}
return $posts;
@@ -838,7 +873,14 @@ class app_forums_classes_topics
$filters['postId'] = ( ! is_array( $filters['postId'] ) ) ? array( $filters['postId'] ) : $filters['postId'];
$where[] = "p." . $this->getPostTableField( 'pid', $isArchived ) . " IN (" . implode( ',',$filters['postId'] ) . ")";
}
/* Posts */
if ( ! empty( $filters['postDate'] ) )
{
$filters['postDate'] = ( ! is_array( $filters['postDate'] ) ) ? array( $filters['postDate'] ) : $filters['postDate'];
$where[] = "p." . $this->getPostTableField( 'post_date', $isArchived ) . " IN (" . implode( ',',$filters['postDate'] ) . ")";
}
/* Topics */
if ( ! empty( $filters['topicId'] ) )
{
@@ -879,12 +921,37 @@ class app_forums_classes_topics
$where[] = "p.". $this->getPostTableField( 'pid', $isArchived ) . " < " . intval( $filters['pidIsLess'] );
}
/* Author is ignored */
if ( ! empty( $filters['notIgnored'] ) )
{
$ignoredUsers = array();
foreach( $this->member->ignored_users as $_i )
{
if( $_i['ignore_topics'] )
{
$ignoredUsers[] = $_i['ignore_ignore_id'];
}
}
if ( ! empty( $ignoredUsers ) )
{
$where[] = "p." . $this->getPostTableField( 'author_id', $isArchived ) . " NOT IN (" . implode( ',',$ignoredUsers ) . ")";
}
}
/* Date is greater */
if ( ! empty( $filters['dateIsGreater'] ) )
{
$where[] = "p.". $this->getPostTableField( 'post_date', $isArchived ) . " > " . intval( $filters['dateIsGreater'] );
}
/* Date is less */
if ( ! empty( $filters['dateIsLess'] ) )
{
$where[] = "p.". $this->getPostTableField( 'post_date', $isArchived ) . " < " . intval( $filters['dateIsLess'] );
}
/* Visible / specific filters */
if ( ! empty( $filters['postType'] ) && is_array( $filters['postType'] ) )
{
@@ -1224,6 +1291,8 @@ class app_forums_classes_topics
'where' => "forum_id LIKE '%,{$forumData['id']},%' AND (member_id={$this->memberData['member_id']} OR (is_group=1 AND group_id IN({$member_group_ids})))" ) );
$this->moderatorData = ( is_array( $this->moderatorData ) ) ? $this->moderatorData : array();
$this->moderatorData = array_merge( $this->moderatorData, IPSBWOptions::thaw( $this->moderatorData['mod_bitoptions'], 'moderators', 'forums' ) );
}
return $this->moderatorData;
@@ -1270,18 +1339,17 @@ class app_forums_classes_topics
public function isOnLastPage( $topicData=false )
{
$topicData = ( ! is_array( $topicData ) ) ? $this->getTopicData() : $topicData;
$st = intval( $this->request['st'] );
$page = intval( $this->request['page'] );
$perPage = $this->settings['display_max_posts'];
$posts = intval( $topicData['posts'] ) + 1;
$maxPage = ceil( $posts / $perPage );
if ( $posts <= $perPage )
{
return true;
}
$maxSt = ( ceil( $posts / $perPage ) - 1 ) * $perPage;
if ( $st == $maxSt )
if ( $maxPage == $page )
{
return true;
}
@@ -1509,16 +1577,20 @@ class app_forums_classes_topics
* Can make a reply to this topic
* @return string locked / moved / no_reply / reply
*/
public function getReplyStatus()
public function getReplyStatus( $topicData=array() )
{
if ( empty( $topicData['tid'] ) )
{
$topicData = $this->getTopicData();
}
/* Is we archived? */
if ( $this->isArchived( $this->getTopicData() ) )
if ( $this->isArchived( $topicData ) )
{
return 'archived';
}
/* Init */
$topicData = $this->getTopicData();
$forumData = $this->registry->getClass('class_forums')->getForumbyId( $topicData['forum_id'] );
$status = '';
@@ -1554,7 +1626,7 @@ class app_forums_classes_topics
else
{
if ( $this->memberData['member_id'] AND ( ( ( $this->memberData['member_id'] == $topicData['starter_id'] ) AND ! $this->memberData['g_reply_own_topics'] ) OR ( ( $this->memberData['member_id'] != $topicData['starter_id'] ) AND ! $this->memberData['g_reply_other_topics'] ) ) )
{
{
$status = "no_reply";
}
else if ( $this->registry->permissions->check( 'reply', $forumData ) == TRUE )
@@ -1686,7 +1758,7 @@ class app_forums_classes_topics
// Rebuild SEO title on the fly, if needed
//-----------------------------------------
if( ! $topic['title_seo'] )
if( ! $topic['title_seo'] AND $topic['tid'] )
{
$topic['title_seo'] = IPSText::makeSeoTitle( $topic['title'] );
@@ -1734,7 +1806,7 @@ class app_forums_classes_topics
if ( $topic['_hasUnread'] )
{
$topic['_unreadUrl'] = $this->registry->output->buildSEOUrl( 'showtopic=' . $topic['tid'] . '&amp;view=getnewpost', 'public', $topic['title_seo'], 'showtopicunread' );
$topic['_unreadUrl'] = $this->registry->output->buildSEOUrl( 'showtopic=' . $topic['tid'] . '&amp;view=getnewpost', 'public', $topic['title_seo'], 'showtopic' );
}
$topic['_url'] = $this->registry->output->buildSEOUrl( 'showtopic=' . $topic['tid'], 'public', $topic['title_seo'], 'showtopic' );
@@ -1763,7 +1835,7 @@ class app_forums_classes_topics
else
{
$topic['last_poster_name'] = $this->settings['guest_name_pre'] . $topic['last_poster_name'] . $this->settings['guest_name_suf'];
$topic['last_poster'] = $this->registry->getClass('output')->getTemplate('global')->userHoverCard( array( 'member_id' => 0, 'members_display_name' => $this->settings['guest_name_pre'] . $topic['last_poster_name'] . $this->settings['guest_name_suf'] ) );
$topic['last_poster'] = $this->registry->getClass('output')->getTemplate('global')->userHoverCard( array( 'member_id' => 0, 'members_display_name' => $topic['last_poster_name'] ) );
}
//-----------------------------------------
@@ -1881,6 +1953,9 @@ class app_forums_classes_topics
$topic['tags'] = $this->registry->tags->formatCacheJoinData( $topic );
}
/* Answered */
$topic['_answeredPid'] = $this->getTopicAnswerPid( $topic );
return $topic;
}
@@ -1902,7 +1977,7 @@ class app_forums_classes_topics
$poster = array();
/* Bitwise options */
$_tmp = IPSBWOptions::thaw( $post['post_bwoptions'], 'post', 'forums' );
$_tmp = IPSBWOptions::thaw( $post['post_bwoptions'], 'posts', 'forums' );
if ( count( $_tmp ) )
{
@@ -1948,13 +2023,43 @@ class app_forums_classes_topics
$post['_isHidden'] = ( $this->registry->getClass('class_forums')->fetchHiddenType( $post ) == 'hidden' ) ? true : false;
$post['_isDeleted'] = ( $this->registry->getClass('class_forums')->fetchHiddenType( $post ) == 'sdelete' ) ? true : false;
/* Answered post */
try
{
$post['_isMarkedAnswered'] = ( $this->postIsAnswer( $post, $topicData ) ) ? true : false;
}
catch( Exception $e )
{
$post['_isMarkedAnswered'] = false;
}
$post['_canMarkUnanswered'] = ( $post['_isMarkedAnswered'] === true && $this->canUnanswerTopic( $topicData ) ) ? true : false;
$post['_canAnswer'] = ( $post['_isMarkedAnswered'] === false && $this->canAnswerTopic( $topicData ) ) ? true : false;
$post['PermalinkUrlBit'] = '';
/* Queued */
if ( $topicData['topic_firstpost'] == $post['pid'] and ( $post['_isHidden'] OR $topicData['_isHidden'] ) )
{
$post['queued'] = 1;
$post['_isHidden'] = true;
}
if ( $topicData['topic_queuedposts'] || $topicData['topic_deleted_posts'] )
{
if ( $topicData['topic_queuedposts'] && $topicData['Perms']['canQueuePosts'] )
{
/* We have hidden data that is viewable */
$post['PermalinkUrlBit'] = '&amp;p=' . $post['pid'];
}
if ( $topicData['topic_deleted_posts'] && $post['_softDeleteSee'] )
{
/* We have hidden data that is viewable */
$post['PermalinkUrlBit'] = '&amp;p=' . $post['pid'];
}
}
/* Edited stuff */
$post['edit_by'] = "";
@@ -1970,15 +2075,24 @@ class app_forums_classes_topics
{
$_NOW2 = IPSDebug::getMemoryDebugFlag();
IPSText::getTextClass('bbcode')->parse_smilies = $post['use_emo'];
IPSText::getTextClass('bbcode')->parse_html = ( $forumData['use_html'] and $poster['g_dohtml'] and $post['post_htmlstate'] ) ? 1 : 0;
IPSText::getTextClass('bbcode')->parse_nl2br = $post['post_htmlstate'] == 2 ? 1 : 0;
IPSText::getTextClass('bbcode')->parse_bbcode = $forumData['use_ibc'];
IPSText::getTextClass('bbcode')->parsing_section = 'topics';
IPSText::getTextClass('bbcode')->parsing_mgroup = $post['member_group_id'];
IPSText::getTextClass('bbcode')->parsing_mgroup_others = $post['mgroup_others'];
/* Grab the parser file */
if ( $this->_parser === null )
{
/* Load parser */
$classToLoad = IPSLib::loadLibrary( IPS_ROOT_PATH . 'sources/classes/text/parser.php', 'classes_text_parser' );
$this->_parser = new $classToLoad();
}
/* set up parser */
$this->_parser->set( array( 'memberData' => array( 'member_id' => $post['member_id'],
'member_group_id' => $post['member_group_id'],
'mgroup_others' => $post['mgroup_others'] ),
'parseBBCode' => $forumData['use_ibc'],
'parseHtml' => ( $forumData['use_html'] and $poster['g_dohtml'] and $post['post_htmlstate'] ) ? 1 : 0,
'parseEmoticons' => $post['use_emo'],
'parseArea' => 'topics' ) );
$post['post'] = IPSText::getTextClass('bbcode')->preDisplayParse( $post['post'] );
$post['post'] = $this->_parser->display( $post['post'] );
IPSDebug::setMemoryDebugFlag( "topics::parsePostRow - bbcode parse - Completed", $_NOW2 );
@@ -2059,7 +2173,7 @@ class app_forums_classes_topics
{
if( in_array( $post['author_id'], $topicData['ignoredUsers'] ) )
{
if ( ! strstr( $this->settings['cannot_ignore_groups'], ','.$post['post']['member_group_id'].',' ) )
if ( ! strstr( $this->settings['cannot_ignore_groups'], ','.$post['member_group_id'].',' ) )
{
$post['_ignored'] = 1;
}
@@ -2081,6 +2195,9 @@ class app_forums_classes_topics
/* Memory debug */
IPSDebug::setMemoryDebugFlag( "PID: ".$post['pid']. " - Completed", $_NOW );
/* Excerpt */
$post['_excerpt'] = IPSText::truncate( str_replace( array( '<br />', '<br>', "\n", '</p>', '<p>' ), ' ', $post['post'] ), 500 );
return array( 'post' => $post, 'author' => $poster );
}
@@ -2172,6 +2289,7 @@ class app_forums_classes_topics
$this->DB->loadCacheFile( IPSLib::getAppDir('forums') . '/sql/' . ips_DBRegistry::getDriverType() . '_topics_queries.php', 'topics_sql_queries' );
$this->DB->buildFromCache( 'restoreRecentPost', array( 'query' => $query, 'date' => $date ), 'topics_sql_queries' );
$this->DB->allow_sub_select = true;
$this->DB->execute();
}
}
@@ -2246,6 +2364,329 @@ class app_forums_classes_topics
return $this->fields;
}
/**
* Coverts a page number to a start value
* @param int $page
*/
public function pageToSt( $page )
{
$page = intval( $page );
return ( $page > 1 ) ? ( ( $page - 1 ) * $this->settings['display_max_posts'] ) : 0;
}
/**
* Coverts a st value to a page number
* @param int $page
*/
public function stToPage( $st )
{
$st = intval( $st );
return ( $st > 0 ) ? ( ceil( $st / $this->settings['display_max_posts'] ) + 1 ) : 1;
}
/**
* Returns page number of post
* @param mixed $post
* @return int
*/
public function postToPage( $post )
{
//-----------------------------------------
// Get post...
//-----------------------------------------
$post = is_array( $post ) ? $post : $this->getPostById( $post, false, array( 'onlyViewable' => true ) );
/* Get the correct page number */
$_perms = array( 'visible' );
if ( $this->registry->getClass('class_forums')->canSeeSoftDeletedPosts( $post['forum_id'] ? $post['forum_id'] : false ) )
{
$_perms[] = 'sdelete';
}
if ( $this->registry->getClass('class_forums')->canQueuePosts( $post['forum_id'] ? $post['forum_id'] : false ) )
{
$_perms[] = 'hidden';
}
$query = $this->registry->class_forums->fetchPostHiddenQuery( $_perms );
$sort_value = $post['pid'];
$sort_field = ($this->settings['post_order_column'] == 'pid') ? 'pid' : 'post_date';
if( $sort_field == 'post_date' )
{
if( $post['post_date'] )
{
$sort_value = $post['post_date'];
}
else
{
$date = $this->DB->buildAndFetch( array( 'select' => 'post_date', 'from' => 'posts', 'where' => 'pid=' . $post['pid'] ) );
$sort_value = $date['post_date'];
}
}
$this->DB->build( array( 'select' => 'COUNT(*) as posts', 'from' => 'posts', 'where' => "topic_id={$post['topic_id']} AND {$sort_field} <=" . intval( $sort_value ) . ' AND ' . $query ) );
$this->DB->execute();
$cposts = $this->DB->fetch();
if ( (($cposts['posts']) % $this->settings['display_max_posts']) == 0 )
{
$pages = ($cposts['posts']) / $this->settings['display_max_posts'];
}
else
{
$number = ( ($cposts['posts']) / $this->settings['display_max_posts'] );
$pages = ceil($number);
}
$st = ($pages - 1) * $this->settings['display_max_posts'];
if( $this->settings['post_order_sort'] == 'desc' )
{
$st = (ceil(($cposts['posts']/$this->settings['display_max_posts'])) - $pages) * $this->settings['display_max_posts'];
}
return intval( $this->registry->getClass('topics')->stToPage( $st ) );
}
/**
* Mark a topic as 'answered'
* @param mixed $topic
* @param mixed $post
*/
public function answerTopicSingle( $post, $topic=null )
{
if ( is_numeric( $post ) )
{
$post = $this->getPostById( $post );
}
if ( $topic === null )
{
$topic = $post['topic_id'];
}
if ( is_numeric( $topic ) )
{
$topic = $this->getTopicById( $topic );
}
if ( ! $topic['tid'] || ! $post['pid'] )
{
throw new Exception( 'missing_data' );
}
if ( $this->canAnswerTopic( $topic ) !== true )
{
throw new Exception( 'no_permission' );
}
/* Remove flag for all other posts in this topic */
$sql = IPSBWOptions::sql( 'bw_post_answered', 'post_bwoptions', 'posts', 'forums', 'invert' );
$where = IPSBWOptions::sql( 'bw_post_answered', 'post_bwoptions', 'posts', 'forums', 'has' );
$this->DB->update( 'posts', 'post_bwoptions=' . $sql, 'topic_id=' . $topic['tid'] . ' AND ' . $where, false, true );
/* Update post */
$post['bw_post_answered'] = 1;
$this->DB->update( 'posts', array( 'post_bwoptions' => IPSBWOptions::freeze( $post, 'posts', 'forums' ) ), 'pid=' . $post['pid'] );
/* Update topic */
$this->DB->update( 'topics', array( 'topic_answered_pid' => $post['pid'] ), 'tid=' . $topic['tid'] );
return true;
}
/**
* Mark a topic as 'unAnswered'
* @param mixed $topic
* @param mixed $post
*/
public function unAnswerTopicSingle( $post, $topic=null )
{
if ( is_numeric( $post ) )
{
$post = $this->getPostById( $post );
}
if ( $topic === null )
{
$topic = $post['topic_id'];
}
if ( is_numeric( $topic ) )
{
$topic = $this->getTopicById( $topic );
}
if ( ! $topic['tid'] || ! $post['pid'] )
{
throw new Exception( 'missing_data' );
}
if ( $this->canAnswerTopic( $topic ) !== true )
{
throw new Exception( 'no_permission' );
}
/* Remove flag this post */
$sql = IPSBWOptions::sql( 'bw_post_answered', 'post_bwoptions', 'posts', 'forums', 'invert' );
$where = IPSBWOptions::sql( 'bw_post_answered', 'post_bwoptions', 'posts', 'forums', 'has' );
$this->DB->update( 'posts', 'post_bwoptions=' . $sql, 'pid=' . $post['pid'] . ' AND ' . $where, false, true );
/* Update topic */
$this->DB->update( 'topics', array( 'topic_answered_pid' => 0 ), 'tid=' . $topic['tid'] );
return true;
}
/**
* Get the answered PID (or false if nothing)
* @param mixed $topic
*/
public function getTopicAnswerPid( $topic )
{
if ( is_numeric( $topic ) )
{
$topic = $this->getTopicById( $topic );
}
if ( $this->registry->class_forums->answerTopicsEnabled( $topic['forum_id'] ) !== true )
{
return false;
}
return ( ! empty( $topic['topic_answered_pid'] ) ) ? $topic['topic_answered_pid'] : false;
}
/**
* Is this post the answer?
* @param mixed $post
* @param mixed $topic
*/
public function postIsAnswer( $post, $topic=null )
{
if ( is_numeric( $post ) )
{
$post = $this->getPostById( $post );
}
if ( $topic === null )
{
$topic = $post['topic_id'];
}
if ( is_numeric( $topic ) )
{
$topic = $this->getTopicById( $topic );
}
if ( ! $topic['tid'] || ! $post['pid'] )
{
throw new Exception( 'missing_data' );
}
if ( $this->registry->class_forums->answerTopicsEnabled( $topic['forum_id'] ) !== true )
{
return false;
}
return ( ! empty( $post['bw_post_answered'] ) ) ? true : false;
}
/**
* Can mark a post as answered
* @param mixed Array or int
* @return boolean
*/
public function canAnswerTopic( $topic )
{
if ( is_numeric( $topic ) )
{
$topic = $this->getTopicById( $topic );
}
if ( $this->registry->class_forums->answerTopicsEnabled( $topic['forum_id'] ) !== true )
{
return false;
}
$forumData = $this->registry->class_forums->getForumById( $topic['forum_id'] );
if ( $this->memberData['g_is_supmod'] || ( $forumData['bw_enable_answers_member'] && $topic['starter_id'] && ( $topic['starter_id'] == $this->memberData['member_id'] ) ) )
{
return true;
}
else
{
$moderator = $this->getModeratorData();
return ( $moderator['bw_can_toggle_answered_post'] ) ? true : false;
}
}
/**
* Can mark a post as unanswered
* @param mixed Array or int
* @return boolean
*/
public function canUnanswerTopic( $topic )
{
if ( is_numeric( $topic ) )
{
$topic = $this->getTopicById( $topic );
}
if ( $this->registry->class_forums->answerTopicsEnabled( $topic['forum_id'] ) !== true )
{
return false;
}
$forumData = $this->registry->class_forums->getForumById( $topic['forum_id'] );
if ( $this->memberData['g_is_supmod'] || ( $forumData['bw_enable_answers_member'] && $topic['starter_id'] && ( $topic['starter_id'] == $this->memberData['member_id'] ) ) )
{
return true;
}
else
{
$moderator = $this->getModeratorData();
return ( $moderator['bw_can_toggle_answered_post'] ) ? true : false;
}
}
/**
* @param mixed Array or int
* @return boolean
*/
public function canRateAnsweredPost( $topic )
{
if ( is_numeric( $topic ) )
{
$topic = $this->getTopicById( $topic );
}
if ( $this->registry->class_forums->answerTopicsEnabled( $topic['forum_id'] ) !== true )
{
return false;
}
if ( $this->getReplyStatus( $topic ) == 'reply' )
{
return true;
}
}
/**
* Set post filters
* Takes user input and cleans it up a bit