Version 3.2.3
This commit is contained in:
1 parent
ae5c01cc78
commit
78706903a2
2641 files changed
+228363
-201264
No files matched your search
@@ -2,18 +2,18 @@
|
||||
/**
|
||||
* <pre>
|
||||
* Invision Power Services
|
||||
* IP.Board v3.1.4
|
||||
* IP.Board v3.2.3
|
||||
* Basic Forum Search
|
||||
* Last Updated: $Date: 2010-02-23 12:38:11 +0000 (Tue, 23 Feb 2010) $
|
||||
* Last Updated: $Date: 2011-10-04 16:35:02 -0400 (Tue, 04 Oct 2011) $
|
||||
* </pre>
|
||||
*
|
||||
* @author $Author: matt $
|
||||
* @copyright (c) 2001 - 2009 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/community/board/license.html
|
||||
* @author $Author: bfarber $
|
||||
* @copyright © 2001 - 2009 Invision Power Services, Inc.
|
||||
* @license This is NULLED!
|
||||
* @package IP.Board
|
||||
* @subpackage Forums
|
||||
* @link http://www.invisionpower.com
|
||||
* @version $Rev: 5861 $
|
||||
* @link http://hatynka.in
|
||||
* @version $Rev: 9580 $
|
||||
*/
|
||||
|
||||
if ( ! defined( 'IN_IPB' ) )
|
||||
@@ -24,10 +24,17 @@ if ( ! defined( 'IN_IPB' ) )
|
||||
|
||||
class search_engine_forums extends search_engine
|
||||
{
|
||||
/**
|
||||
* Forum ids to search - set in secondary methods
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $searchForumIds = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @return void
|
||||
* @return @e void
|
||||
*/
|
||||
public function __construct( ipsRegistry $registry )
|
||||
{
|
||||
@@ -39,6 +46,7 @@ class search_engine_forums extends search_engine
|
||||
{
|
||||
$classToLoad = IPSLib::loadLibrary( IPSLib::getAppDir( 'forums' ) . "/sources/classes/forums/class_forums.php", 'class_forums', 'forums' );
|
||||
ipsRegistry::setClass( 'class_forums', new $classToLoad( ipsRegistry::instance() ) );
|
||||
ipsRegistry::getClass('class_forums')->strip_invisible = 1;
|
||||
ipsRegistry::getClass('class_forums')->forumsInit();
|
||||
}
|
||||
|
||||
@@ -61,8 +69,8 @@ class search_engine_forums extends search_engine
|
||||
$sort_by = IPSSearchRegistry::get('in.search_sort_by');
|
||||
$sort_order = IPSSearchRegistry::get('in.search_sort_order');
|
||||
$search_term = IPSSearchRegistry::get('in.clean_search_term');
|
||||
$content_title_only = IPSSearchRegistry::get('opt.searchTitleOnly');
|
||||
$post_search_only = IPSSearchRegistry::get('opt.onlySearchPosts');
|
||||
$search_type = IPSSearchRegistry::get('opt.searchType');
|
||||
$search_tags = IPSSearchRegistry::get('in.raw_search_tags');
|
||||
$search_ids = array();
|
||||
$groupby = false;
|
||||
$cType = IPSSearchRegistry::get('contextual.type');
|
||||
@@ -71,16 +79,21 @@ class search_engine_forums extends search_engine
|
||||
/* Contextual search */
|
||||
if ( $cType == 'topic' )
|
||||
{
|
||||
$content_title_only = false;
|
||||
$post_search_only = true;
|
||||
|
||||
IPSSearchRegistry::set('opt.searchTitleOnly', false);
|
||||
IPSSearchRegistry::set('opt.onlySearchPosts', true);
|
||||
IPSSearchRegistry::set('display.onlyTitles', false);
|
||||
$search_type = 'content';
|
||||
IPSSearchRegistry::set('opt.searchType', 'content');
|
||||
IPSSearchRegistry::set('opt.noPostPreview', false);
|
||||
}
|
||||
|
||||
/* If searching tags, we don't show a preview */
|
||||
if( $search_tags )
|
||||
{
|
||||
IPSSearchRegistry::set('opt.noPostPreview', true);
|
||||
IPSSearchRegistry::set('opt.searchType', 'titles');
|
||||
$search_type = 'titles';
|
||||
}
|
||||
|
||||
/* Permissions */
|
||||
$permissions = array();
|
||||
$permissions['TopicSoftDeleteSee'] = $this->registry->getClass('class_forums')->canSeeSoftDeletedTopics( 0 );
|
||||
$permissions['canQueue'] = $this->registry->getClass('class_forums')->canQueuePosts( 0 );
|
||||
$permissions['PostSoftDeleteSee'] = $this->registry->getClass('class_forums')->canSeeSoftDeletedPosts( 0 );
|
||||
@@ -107,81 +120,86 @@ class search_engine_forums extends search_engine
|
||||
}
|
||||
|
||||
/* Limit Results */
|
||||
$this->sphinxClient->SetLimits( intval($start), intval($perPage) );
|
||||
$this->sphinxClient->SetLimits( intval($start), $perPage );
|
||||
|
||||
/* Loop through the forums and build a list of forums we're allowed access to */
|
||||
$forumIdsOk = array();
|
||||
$forumIdsBad = array();
|
||||
|
||||
if ( ! empty( ipsRegistry::$request['search_app_filters']['forums']['forums'] ) AND count( ipsRegistry::$request['search_app_filters']['forums']['forums'] ) )
|
||||
if( is_array($this->searchForumIds) AND count($this->searchForumIds) )
|
||||
{
|
||||
foreach( ipsRegistry::$request['search_app_filters']['forums']['forums'] as $forum_id )
|
||||
$forumIdsOk = $this->searchForumIds;
|
||||
}
|
||||
else
|
||||
{
|
||||
$forumIdsOk = array();
|
||||
$forumIdsBad = array();
|
||||
|
||||
if ( ! empty( ipsRegistry::$request['search_app_filters']['forums']['forums'] ) AND count( ipsRegistry::$request['search_app_filters']['forums']['forums'] ) )
|
||||
{
|
||||
if( $forum_id )
|
||||
foreach( ipsRegistry::$request['search_app_filters']['forums']['forums'] as $forum_id )
|
||||
{
|
||||
$data = $this->registry->class_forums->forum_by_id[ $forum_id ];
|
||||
|
||||
/* Check for sub forums */
|
||||
$children = ipsRegistry::getClass( 'class_forums' )->forumsGetChildren( $forum_id );
|
||||
|
||||
foreach( $children as $kid )
|
||||
if( $forum_id )
|
||||
{
|
||||
if( ! in_array( $kid, ipsRegistry::$request['search_app_filters']['forums']['forums'] ) )
|
||||
$data = $this->registry->class_forums->forum_by_id[ $forum_id ];
|
||||
|
||||
/* Check for sub forums */
|
||||
$children = ipsRegistry::getClass( 'class_forums' )->forumsGetChildren( $forum_id );
|
||||
|
||||
foreach( $children as $kid )
|
||||
{
|
||||
if( ! $this->registry->permissions->check( 'read', $this->registry->class_forums->forum_by_id[ $kid ] ) )
|
||||
if( ! in_array( $kid, ipsRegistry::$request['search_app_filters']['forums']['forums'] ) )
|
||||
{
|
||||
$forumIdsBad[] = $kid;
|
||||
continue;
|
||||
if( ! $this->registry->permissions->check( 'read', $this->registry->class_forums->forum_by_id[ $kid ] ) )
|
||||
{
|
||||
$forumIdsBad[] = $kid;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Can read, but is it password protected, etc? */
|
||||
if ( ! $this->registry->class_forums->forumsCheckAccess( $kid, 0, 'forum', array(), true ) )
|
||||
{
|
||||
$forumIdsBad[] = $kid;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( ! $this->registry->class_forums->forum_by_id[ $kid ]['sub_can_post'] OR ! $this->registry->class_forums->forum_by_id[ $kid ]['can_view_others'] )
|
||||
{
|
||||
$forumIdsBad[] = $kid;
|
||||
continue;
|
||||
}
|
||||
|
||||
$forumIdsOk[] = $kid;
|
||||
}
|
||||
|
||||
/* Can read, but is it password protected, etc? */
|
||||
if ( ! $this->registry->class_forums->forumsCheckAccess( $kid, 0, 'forum', array(), true ) )
|
||||
{
|
||||
$forumIdsBad[] = $kid;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( ! $this->registry->class_forums->forum_by_id[ $kid ]['sub_can_post'] OR ! $this->registry->class_forums->forum_by_id[ $kid ]['can_view_others'] )
|
||||
{
|
||||
$forumIdsBad[] = $kid;
|
||||
continue;
|
||||
}
|
||||
|
||||
$forumIdsOk[] = $kid;
|
||||
}
|
||||
|
||||
/* Can we read? */
|
||||
if ( ! $this->registry->permissions->check( 'view', $data ) )
|
||||
{
|
||||
$forumIdsBad[] = $forum_id;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Can read, but is it password protected, etc? */
|
||||
if ( ! $this->registry->class_forums->forumsCheckAccess( $forum_id, 0, 'forum', array(), true ) )
|
||||
{
|
||||
$forumIdsBad[] = $forum_id;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( ! $data['sub_can_post'] OR ! $data['can_view_others'] AND !$this->memberData['g_access_cp'] )
|
||||
{
|
||||
$forumIdsBad[] = $forum_id;
|
||||
continue;
|
||||
}
|
||||
|
||||
$forumIdsOk[] = $forum_id;
|
||||
}
|
||||
|
||||
/* Can we read? */
|
||||
if ( ! $this->registry->permissions->check( 'view', $data ) )
|
||||
{
|
||||
$forumIdsBad[] = $forum_id;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Can read, but is it password protected, etc? */
|
||||
if ( ! $this->registry->class_forums->forumsCheckAccess( $forum_id, 0, 'forum', array(), true ) )
|
||||
{
|
||||
$forumIdsBad[] = $forum_id;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( ! $data['sub_can_post'] OR ! $data['can_view_others'] AND !$this->memberData['g_access_cp'] )
|
||||
{
|
||||
$forumIdsBad[] = $forum_id;
|
||||
continue;
|
||||
}
|
||||
|
||||
$forumIdsOk[] = $forum_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! count($forumIdsOk) )
|
||||
{
|
||||
$allowTrashCan = ( $cType == 'forum' ) ? true : false;
|
||||
|
||||
/* Get list of good forum IDs */
|
||||
$forumIdsOk = $this->registry->class_forums->fetchSearchableForumIds( null, array(), $allowTrashCan );
|
||||
$forumIdsOk = $this->registry->class_forums->fetchSearchableForumIds();
|
||||
}
|
||||
|
||||
/* Add allowed forums */
|
||||
@@ -204,7 +222,7 @@ class search_engine_forums extends search_engine
|
||||
}
|
||||
|
||||
/* Exclude some items */
|
||||
if ( ! $content_title_only )
|
||||
if ( $search_type != 'titles' )
|
||||
{
|
||||
if ( $permissions['SoftDeleteContent'] AND $permissions['PostSoftDeleteSee'] AND $permissions['canQueue'] )
|
||||
{
|
||||
@@ -265,7 +283,7 @@ class search_engine_forums extends search_engine
|
||||
$this->search_end_timestamp = time() + 100;
|
||||
}
|
||||
|
||||
if ( $content_title_only )
|
||||
if ( $search_type == 'titles' )
|
||||
{
|
||||
$this->sphinxClient->SetFilterRange( 'start_date', $this->search_begin_timestamp, $this->search_end_timestamp );
|
||||
}
|
||||
@@ -275,70 +293,117 @@ class search_engine_forums extends search_engine
|
||||
}
|
||||
}
|
||||
|
||||
if ( IPSSearchRegistry::get('opt.noPostPreview') OR IPSSearchRegistry::get('display.onlyTitles') )
|
||||
if ( IPSSearchRegistry::get('opt.noPostPreview') OR $search_type == 'titles' )
|
||||
{
|
||||
$groupby = true;
|
||||
}
|
||||
|
||||
if ( $content_title_only )
|
||||
|
||||
/* Check tags */
|
||||
$_tag = '';
|
||||
$tagIds = array();
|
||||
|
||||
if ( $search_tags && $this->settings['tags_enabled'] )
|
||||
{
|
||||
if ( $sort_order == 'asc' )
|
||||
$search_tags = explode( ",", $search_tags );
|
||||
|
||||
$this->DB->build( array( 'select' => 'tag_id',
|
||||
'from' => 'core_tags',
|
||||
'where' => 'tag_meta_app=\'forums\' AND tag_meta_area=\'topics\' AND (' . $this->DB->buildLikeChain( 'tag_text', $search_tags, false ) . ')',
|
||||
'limit' => array( 0, 500 ) ) );
|
||||
|
||||
$o = $this->DB->execute();
|
||||
|
||||
while( $row = $this->DB->fetch( $o ) )
|
||||
{
|
||||
$this->sphinxClient->SetSortMode( SPH_SORT_ATTR_ASC, $sortKey );
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->sphinxClient->SetSortMode( SPH_SORT_ATTR_DESC, $sortKey );
|
||||
$tagIds[] = $row['tag_id'];
|
||||
}
|
||||
|
||||
if ( $groupby )
|
||||
if ( count( $tagIds ) )
|
||||
{
|
||||
$this->sphinxClient->SetGroupBy( 'last_post_group', SPH_GROUPBY_ATTR, '@group ' . $sort_order );
|
||||
$this->sphinxClient->SetFilter( 'tag_id', $tagIds );
|
||||
}
|
||||
|
||||
$_s = ( $search_term ) ? '@title ' . $search_term : '';
|
||||
|
||||
$result = $this->sphinxClient->Query( $_s, 'forums_search_posts_main,forums_search_posts_delta' );
|
||||
|
||||
$this->logSphinxWarnings();
|
||||
}
|
||||
|
||||
/* Set sort order */
|
||||
if ( $sort_order == 'asc' )
|
||||
{
|
||||
$this->sphinxClient->SetSortMode( SPH_SORT_ATTR_ASC, $sortKey );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( $groupby )
|
||||
{
|
||||
$this->sphinxClient->SetGroupBy( 'last_post_group', SPH_GROUPBY_ATTR, '@group DESC');
|
||||
}
|
||||
$this->sphinxClient->SetSortMode( SPH_SORT_ATTR_DESC, $sortKey );
|
||||
}
|
||||
|
||||
/* Generate sphinx search query */
|
||||
switch( $search_type )
|
||||
{
|
||||
case 'titles':
|
||||
/* Group by */
|
||||
if ( $groupby )
|
||||
{
|
||||
/* @link http://community.invisionpower.com/topic/335036-sphinx-vncactive-content-sorting/ */
|
||||
$this->sphinxClient->SetGroupDistinct ( "tid" );
|
||||
$this->sphinxClient->SetGroupBy( 'tid', SPH_GROUPBY_ATTR, '@group ' . $sort_order );
|
||||
}
|
||||
|
||||
$_s = ( $search_term ) ? '@title ' . $search_term : '';
|
||||
break;
|
||||
|
||||
if ( $sort_order == 'asc' )
|
||||
{
|
||||
$this->sphinxClient->SetSortMode( SPH_SORT_ATTR_ASC, $sortKeyPost );
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->sphinxClient->SetSortMode( SPH_SORT_ATTR_DESC, $sortKeyPost );
|
||||
}
|
||||
case 'content':
|
||||
/* Group by */
|
||||
if ( $groupby )
|
||||
{
|
||||
$this->sphinxClient->SetSortMode( SPH_SORT_EXTENDED, $sortKeyPost . ' DESC' );
|
||||
$this->sphinxClient->SetGroupBy( 'tid', SPH_GROUPBY_ATTR, 'last_post ' . $sort_order );
|
||||
|
||||
IPSSearchRegistry::set('set.searchResultType', 'both' );
|
||||
}
|
||||
|
||||
|
||||
if ( $post_search_only )
|
||||
{
|
||||
$_s = ( $search_term ) ? '@post ' . $search_term : '';
|
||||
$result = $this->sphinxClient->Query( $_s, 'forums_search_posts_main,forums_search_posts_delta' );
|
||||
}
|
||||
else
|
||||
{
|
||||
$_s = ( $search_term AND strstr( $search_term, '"' ) ) ? '@post ' . $search_term . ' | @title ' . $search_term : ( $search_term ? '@(post,title) ' . $search_term : '' );
|
||||
$result = $this->sphinxClient->Query( $_s, 'forums_search_posts_main,forums_search_posts_delta' );
|
||||
}
|
||||
break;
|
||||
|
||||
$this->logSphinxWarnings();
|
||||
case 'both':
|
||||
default:
|
||||
/* Group by */
|
||||
if ( $groupby )
|
||||
{
|
||||
$this->sphinxClient->SetSortMode( SPH_SORT_EXTENDED, $sortKeyPost . ' DESC' );
|
||||
$this->sphinxClient->SetGroupBy( 'tid', SPH_GROUPBY_ATTR, 'last_post ' . $sort_order );
|
||||
}
|
||||
|
||||
IPSSearchRegistry::set('set.searchResultType', 'both' );
|
||||
|
||||
$_s = ( $search_term AND strstr( $search_term, '"' ) ) ? '@post ' . $search_term . ' | @title ' . $search_term : ( $search_term ? '@(post,title) ' . $search_term : '' );
|
||||
break;
|
||||
}
|
||||
|
||||
/* Perform search */
|
||||
$result = $this->sphinxClient->Query( $_s . $_tag, $this->settings['sphinx_prefix'] . 'forums_search_posts_main, ' . $this->settings['sphinx_prefix'] . 'forums_search_posts_delta' );
|
||||
|
||||
/* Log errors */
|
||||
$this->logSphinxWarnings();
|
||||
|
||||
/* Get result ids */
|
||||
if ( is_array( $result['matches'] ) && count( $result['matches'] ) )
|
||||
{
|
||||
$c = 0;
|
||||
|
||||
foreach( $result['matches'] as $res )
|
||||
{
|
||||
$search_ids[] = ( $content_title_only ) ? $res['attrs']['tid'] : $res['attrs']['search_id'];
|
||||
$search_ids[] = ( $search_type == 'titles' && IPSSearchRegistry::get('set.searchResultType') != 'both' ) ? $res['attrs']['tid'] : $res['attrs']['search_id'];
|
||||
}
|
||||
}
|
||||
|
||||
/* Set return type */
|
||||
if ( $search_type == 'titles' )
|
||||
{
|
||||
IPSSearchRegistry::set('set.returnType', 'tids' );
|
||||
}
|
||||
else
|
||||
{
|
||||
IPSSearchRegistry::set('set.returnType', 'pids' );
|
||||
}
|
||||
|
||||
/* Return it */
|
||||
return array( 'count' => intval( $result['total_found'] ) > 1000 ? 1000 : $result['total_found'], 'resultSet' => $search_ids );
|
||||
@@ -352,38 +417,53 @@ class search_engine_forums extends search_engine
|
||||
*/
|
||||
public function viewUserContent( $member )
|
||||
{
|
||||
/* Ensure we limit by date */
|
||||
$this->settings['search_ucontent_days'] = ( $this->settings['search_ucontent_days'] ) ? $this->settings['search_ucontent_days'] : 365;
|
||||
|
||||
/* Bit of init */
|
||||
$time = time() - ( 86400 * intval( $this->settings['search_ucontent_days'] ) );
|
||||
$time = ( $member['last_post'] ? $member['last_post'] : time() ) - ( 86400 * intval( $this->settings['search_ucontent_days'] ) );
|
||||
$sort_by = IPSSearchRegistry::get('in.search_sort_by');
|
||||
$sort_order = IPSSearchRegistry::get('in.search_sort_order');
|
||||
|
||||
switch( IPSSearchRegistry::get('in.userMode') )
|
||||
{
|
||||
default:
|
||||
case 'all':
|
||||
IPSSearchRegistry::set('opt.searchTitleOnly', false );
|
||||
IPSSearchRegistry::set('display.onlyTitles' , true );
|
||||
IPSSearchRegistry::set('opt.noPostPreview' , false );
|
||||
IPSSearchRegistry::set('opt.searchType', 'both');
|
||||
IPSSearchRegistry::set('opt.noPostPreview' , true );
|
||||
break;
|
||||
case 'title':
|
||||
IPSSearchRegistry::set('opt.searchTitleOnly', true );
|
||||
IPSSearchRegistry::set('display.onlyTitles' , true );
|
||||
IPSSearchRegistry::set('opt.noPostPreview' , false );
|
||||
IPSSearchRegistry::set('opt.searchType', 'titles');
|
||||
IPSSearchRegistry::set('opt.noPostPreview' , true );
|
||||
break;
|
||||
case 'content':
|
||||
IPSSearchRegistry::set('opt.searchTitleOnly', false );
|
||||
IPSSearchRegistry::set('display.onlyTitles' , false );
|
||||
IPSSearchRegistry::set('opt.searchType', 'content');
|
||||
IPSSearchRegistry::set('opt.noPostPreview' , false );
|
||||
break;
|
||||
}
|
||||
|
||||
/* Sorting */
|
||||
switch( $sort_by )
|
||||
{
|
||||
default:
|
||||
case 'date':
|
||||
$sortKey = 'last_post';
|
||||
$sortKeyPost = 'post_date';
|
||||
break;
|
||||
case 'title':
|
||||
$sortKeyPost = $sortKey = 'tordinal';
|
||||
break;
|
||||
case 'posts':
|
||||
$sortKeyPost = $sortKey = 'posts';
|
||||
break;
|
||||
case 'views':
|
||||
$sortKeyPost = $sortKey = 'views';
|
||||
break;
|
||||
}
|
||||
|
||||
/* Init */
|
||||
$start = IPSSearchRegistry::get('in.start');
|
||||
$perPage = IPSSearchRegistry::get('opt.search_per_page');
|
||||
|
||||
IPSSearchRegistry::set('in.search_sort_by' , 'date' );
|
||||
IPSSearchRegistry::set('in.search_sort_order', 'desc' );
|
||||
|
||||
//IPSSearchRegistry::set('in.search_sort_by' , 'date' );
|
||||
//IPSSearchRegistry::set('in.search_sort_order', 'desc' );
|
||||
|
||||
/* Limit Results */
|
||||
$this->sphinxClient->SetLimits( intval($start), intval($perPage) );
|
||||
@@ -409,6 +489,7 @@ class search_engine_forums extends search_engine
|
||||
}
|
||||
|
||||
/* Set up perms */
|
||||
$permissions = array();
|
||||
$permissions['TopicSoftDeleteSee'] = $this->registry->getClass('class_forums')->canSeeSoftDeletedTopics( 0 );
|
||||
$permissions['canQueue'] = $this->registry->getClass('class_forums')->canQueuePosts( 0 );
|
||||
$permissions['PostSoftDeleteSee'] = $this->registry->getClass('class_forums')->canSeeSoftDeletedPosts( 0 );
|
||||
@@ -459,42 +540,72 @@ class search_engine_forums extends search_engine
|
||||
}
|
||||
}
|
||||
|
||||
if ( IPSSearchRegistry::get('in.userMode') == 'title' )
|
||||
/* Perform 'search' */
|
||||
/* We have to sort by topic last post date for 'both' otherwise the topics will appear in random order. Even though it's correctly ordering by YOUR post
|
||||
date, the user just sees the list of topics with random last post date ordering. In a future version it would be nice to change the last post column
|
||||
on 'view user content' to show something like "you last posted on x date" instead of showing the topic last poster and last post date.
|
||||
@link http://community.invisionpower.com/tracker/issue-33692-my-content-second-page */
|
||||
if ( IPSSearchRegistry::get('in.userMode') == 'title' OR IPSSearchRegistry::get('in.userMode') == 'all' )
|
||||
{
|
||||
/* Set return type */
|
||||
IPSSearchRegistry::set('set.returnType', 'tids' );
|
||||
|
||||
$this->sphinxClient->SetGroupDistinct ( "tid" );
|
||||
$this->sphinxClient->SetGroupBy( 'tid', SPH_GROUPBY_ATTR, '@group DESC' );
|
||||
$this->sphinxClient->SetGroupBy( 'tid', SPH_GROUPBY_ATTR, $sortKey . ' ' . $sort_order );
|
||||
|
||||
$this->sphinxClient->SetSortMode( SPH_SORT_ATTR_DESC, 'last_post' );
|
||||
|
||||
$result = $this->sphinxClient->Query( '', 'forums_search_posts_main,forums_search_posts_delta' );
|
||||
|
||||
$this->logSphinxWarnings();
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( IPSSearchRegistry::get('in.userMode') == 'content' )
|
||||
if ( $sort_order == 'asc' )
|
||||
{
|
||||
$this->sphinxClient->SetSortMode( SPH_SORT_ATTR_DESC, 'post_date' );
|
||||
$this->sphinxClient->SetSortMode( SPH_SORT_ATTR_ASC, $sortKey );
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->sphinxClient->SetSortMode( SPH_SORT_ATTR_DESC, 'post_date' );
|
||||
$this->sphinxClient->SetGroupBy( 'last_post_group', SPH_GROUPBY_ATTR, '@group desc' );
|
||||
$this->sphinxClient->SetSortMode( SPH_SORT_ATTR_DESC, $sortKey );
|
||||
}
|
||||
|
||||
$result = $this->sphinxClient->Query( '', 'forums_search_posts_main,forums_search_posts_delta' );
|
||||
|
||||
$this->logSphinxWarnings();
|
||||
$result = $this->sphinxClient->Query( '', $this->settings['sphinx_prefix'] . 'forums_search_posts_main,' . $this->settings['sphinx_prefix'] . 'forums_search_posts_delta' );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Set return type */
|
||||
if( IPSSearchRegistry::get('in.userMode') == 'all' )
|
||||
{
|
||||
IPSSearchRegistry::set('set.returnType', 'tids' );
|
||||
}
|
||||
else
|
||||
{
|
||||
IPSSearchRegistry::set('set.returnType', 'pids' );
|
||||
}
|
||||
|
||||
if ( $sort_order == 'asc' )
|
||||
{
|
||||
$this->sphinxClient->SetSortMode( SPH_SORT_ATTR_ASC, $sortKeyPost );
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->sphinxClient->SetSortMode( SPH_SORT_ATTR_DESC, $sortKeyPost );
|
||||
}
|
||||
|
||||
if ( IPSSearchRegistry::get('in.userMode') != 'content' )
|
||||
{
|
||||
$this->sphinxClient->SetGroupBy( 'tid', SPH_GROUPBY_ATTR, $sortKeyPost . ' ' . $sort_order );
|
||||
}
|
||||
|
||||
$result = $this->sphinxClient->Query( '', $this->settings['sphinx_prefix'] . 'forums_search_posts_main,' . $this->settings['sphinx_prefix'] . 'forums_search_posts_delta' );
|
||||
}
|
||||
|
||||
/* Log warnings */
|
||||
$this->logSphinxWarnings();
|
||||
|
||||
/* Get result ids */
|
||||
if ( is_array( $result['matches'] ) && count( $result['matches'] ) )
|
||||
{
|
||||
foreach( $result['matches'] as $res )
|
||||
{
|
||||
$search_ids[] = ( IPSSearchRegistry::get('opt.searchTitleOnly') ) ? $res['attrs']['tid'] : $res['attrs']['search_id'];
|
||||
$search_ids[] = ( IPSSearchRegistry::get('set.returnType') == 'tids' ) ? $res['attrs']['tid'] : $res['attrs']['search_id'];
|
||||
}
|
||||
}
|
||||
|
||||
/* Return results */
|
||||
return array( 'count' => intval( $result['total_found'] ) > 1000 ? 1000 : $result['total_found'], 'resultSet' => $search_ids );
|
||||
}
|
||||
|
||||
@@ -507,50 +618,102 @@ class search_engine_forums extends search_engine
|
||||
*/
|
||||
public function viewNewContent()
|
||||
{
|
||||
$tids = $this->registry->getClass('classItemMarking')->fetchCookieData( 'forums', 'items' );
|
||||
$oldStamp = $this->registry->getClass('classItemMarking')->fetchOldestUnreadTimestamp( array(), 'forums' );
|
||||
$check = IPS_UNIX_TIME_NOW - ( 86400 * 90 );
|
||||
$forumIdsOk = array();
|
||||
$oldStamp = $this->registry->getClass('classItemMarking')->fetchOldestUnreadTimestamp( array(), 'forums' );
|
||||
$check = IPS_UNIX_TIME_NOW - ( 86400 * $this->settings['topic_marking_keep_days'] );
|
||||
$forumIdsOk = array();
|
||||
$start = IPSSearchRegistry::get('in.start');
|
||||
$perPage = IPSSearchRegistry::get('opt.search_per_page');
|
||||
$seconds = IPSSearchRegistry::get('in.period_in_seconds');
|
||||
$followedOnly = $this->memberData['member_id'] ? IPSSearchRegistry::get('in.vncFollowFilterOn' ) : false;
|
||||
$permissions = array();
|
||||
|
||||
/* Loop through the forums and build a list of forums we're allowed access to */
|
||||
$bvnp = explode( ',', $this->settings['vnp_block_forums'] );
|
||||
|
||||
IPSSearchRegistry::set('in.search_sort_by' , 'date' );
|
||||
IPSSearchRegistry::set('in.search_sort_order', 'desc' );
|
||||
IPSSearchRegistry::set('opt.searchTitleOnly' , true );
|
||||
IPSSearchRegistry::set('display.onlyTitles' , true );
|
||||
IPSSearchRegistry::set('opt.noPostPreview' , true );
|
||||
IPSSearchRegistry::set('opt.searchType' , 'titles' );
|
||||
|
||||
$followedForums = array();
|
||||
$followedTopics = array();
|
||||
|
||||
//-----------------------------------------
|
||||
// Only content we have participated in?
|
||||
//-----------------------------------------
|
||||
|
||||
if( IPSSearchRegistry::get('in.userMode') )
|
||||
{
|
||||
$_tempResults = $this->viewUserContent( $this->memberData );
|
||||
|
||||
if( $_tempResults['count'] )
|
||||
{
|
||||
$this->sphinxClient->SetFilter( 'tid', $_tempResults['resultSet'] );
|
||||
}
|
||||
else
|
||||
{
|
||||
return array( 'count' => 0, 'resultSet' => array() );
|
||||
}
|
||||
|
||||
switch( IPSSearchRegistry::get('in.userMode') )
|
||||
{
|
||||
default:
|
||||
case 'all':
|
||||
case 'content':
|
||||
IPSSearchRegistry::set('opt.searchType', 'both' );
|
||||
IPSSearchRegistry::set('opt.noPostPreview' , true );
|
||||
break;
|
||||
case 'title':
|
||||
IPSSearchRegistry::set('opt.searchType', 'titles' );
|
||||
IPSSearchRegistry::set('opt.noPostPreview' , false );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Set return type */
|
||||
IPSSearchRegistry::set('set.returnType', 'tids' );
|
||||
|
||||
/* Get list of good forum IDs */
|
||||
$_forumIdsOk = $this->registry->class_forums->fetchSearchableForumIds( $this->memberData['member_id'], $bvnp );
|
||||
|
||||
if ( ! $this->memberData['bw_vnc_type'] )
|
||||
$_forumIdsOk = $this->registry->class_forums->fetchSearchableForumIds( $this->memberData['member_id'], ( $followedOnly ) ? array() : $bvnp );
|
||||
|
||||
/* Fetch forum rel ids */
|
||||
if ( $followedOnly )
|
||||
{
|
||||
$oldStamp = IPSLib::fetchHighestNumber( array( intval( $this->memberData['_cache']['gb_mark__forums'] ), intval( $this->memberData['last_visit'] ) ) );
|
||||
$tids = array();
|
||||
require_once( IPS_ROOT_PATH . 'sources/classes/like/composite.php' );/*noLibHook*/
|
||||
|
||||
$forumIdsOk = $_forumIdsOk;
|
||||
/* @link http://community.invisionpower.com/tracker/issue-33284-view-new-content-just-items-i-follow */
|
||||
//$like = classes_like::bootstrap( 'forums', 'forums' );
|
||||
|
||||
//$followedForums = $like->getDataByMemberIdAndArea( $this->memberData['member_id'] );
|
||||
$followedForums = array(); //( $followedForums === null ) ? array() : array_keys( $followedForums );
|
||||
|
||||
$like = classes_like::bootstrap( 'forums', 'topics' );
|
||||
|
||||
$followedTopics = $like->getDataByMemberIdAndArea( $this->memberData['member_id'] );
|
||||
$followedTopics = ( $followedTopics === null ) ? array() : array_keys( $followedTopics );
|
||||
}
|
||||
|
||||
/* What type of date restriction? */
|
||||
if ( IPSSearchRegistry::get('in.period_in_seconds') !== false )
|
||||
{
|
||||
$oldStamp = ( time() - $seconds );
|
||||
$forumIdsOk = $_forumIdsOk;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach( $_forumIdsOk as $id )
|
||||
{
|
||||
if ( $followedOnly && ! in_array( $id, $followedForums ) )
|
||||
{
|
||||
// We don't want to skip followed topics just because we don't follow the forum
|
||||
//continue;
|
||||
}
|
||||
|
||||
$lMarked = $this->registry->getClass('classItemMarking')->fetchTimeLastMarked( array( 'forumID' => $id ), 'forums' );
|
||||
$fData = $this->registry->getClass('class_forums')->forumsFetchData( $id );
|
||||
|
||||
if ( $fData['last_post'] > $lMarked )
|
||||
{
|
||||
/* Add to tids */
|
||||
$_tids = $this->registry->getClass('classItemMarking')->fetchReadIds( array( 'forumID' => $id ), 'forums', false );
|
||||
|
||||
if ( is_array( $_tids ) )
|
||||
{
|
||||
foreach( $_tids as $k => $v )
|
||||
{
|
||||
$tids[ $k ] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
$forumIdsOk[ $id ] = $id;
|
||||
}
|
||||
}
|
||||
@@ -580,86 +743,137 @@ class search_engine_forums extends search_engine
|
||||
}
|
||||
}
|
||||
|
||||
/* Only show VNC results from specified forums? */
|
||||
if ( is_array(IPSSearchRegistry::get('forums.vncForumFilters')) AND count(IPSSearchRegistry::get('forums.vncForumFilters')) )
|
||||
{
|
||||
$_newIdsOk = array();
|
||||
|
||||
foreach( IPSSearchRegistry::get('forums.vncForumFilters') as $forumId )
|
||||
{
|
||||
if( in_array( $forumId, $forumIdsOk ) )
|
||||
{
|
||||
$_newIdsOk[] = $forumId;
|
||||
}
|
||||
}
|
||||
|
||||
$forumIdsOk = $_newIdsOk;
|
||||
}
|
||||
|
||||
/* Set the timestamps */
|
||||
$this->sphinxClient->SetFilterRange( 'last_post', $oldStamp, time() );
|
||||
$this->setDateRange( 0, 0 );
|
||||
|
||||
/* Force it into filter so that search can pick it up */
|
||||
ipsRegistry::$request['search_app_filters']['forums']['forums'] = $forumIdsOk;
|
||||
|
||||
/* Try and limit the TIDS */
|
||||
if ( is_array( $tids ) AND count( $tids ) )
|
||||
{
|
||||
if ( count( $tids ) > 300 )
|
||||
{
|
||||
/* Sort by last read date */
|
||||
arsort( $tids, SORT_NUMERIC );
|
||||
$tids = array_slice( $tids, 0, 300 );
|
||||
}
|
||||
|
||||
$this->DB->build( array( 'select' => 'tid, last_post',
|
||||
'from' => 'topics',
|
||||
'where' => "tid IN (" . implode( ",", array_keys( $tids ) ) . ')' ) );
|
||||
|
||||
$this->DB->execute();
|
||||
|
||||
while( $row = $this->DB->fetch() )
|
||||
{
|
||||
/* Posted in since last read? */
|
||||
if ( $row['last_post'] > $tids[ $row['tid'] ] )
|
||||
{
|
||||
unset( $tids[ $row['tid'] ] );
|
||||
}
|
||||
}
|
||||
|
||||
if ( count( $tids ) )
|
||||
{
|
||||
$tids = array_keys( $tids );
|
||||
}
|
||||
}
|
||||
|
||||
/* Set read tids */
|
||||
if ( count( $tids ) )
|
||||
{
|
||||
$this->sphinxClient->SetFilter( 'tid', $tids, TRUE );
|
||||
}
|
||||
$this->searchForumIds = $forumIdsOk;
|
||||
|
||||
/* Set up some vars */
|
||||
IPSSearchRegistry::set('set.resultCutToDate', $oldStamp );
|
||||
|
||||
return $this->search();
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform the search
|
||||
* Populates $this->_count and $this->_results
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function viewActiveContent()
|
||||
{
|
||||
$seconds = IPSSearchRegistry::get('in.period_in_seconds');
|
||||
/* Fetch first 300 results */
|
||||
IPSSearchRegistry::set('opt.search_per_page', 300);
|
||||
IPSSearchRegistry::set('in.start', 0);
|
||||
|
||||
/* Run search */
|
||||
$data = $this->search();
|
||||
|
||||
/* Loop through the forums and build a list of forums we're allowed access to */
|
||||
$bvnp = explode( ',', $this->settings['vnp_block_forums'] );
|
||||
/* Reset for display function */
|
||||
IPSSearchRegistry::set('in.start', $start);
|
||||
IPSSearchRegistry::set('opt.search_per_page', $perPage);
|
||||
|
||||
IPSSearchRegistry::set('in.search_sort_by' , 'date' );
|
||||
IPSSearchRegistry::set('in.search_sort_order', 'desc' );
|
||||
IPSSearchRegistry::set('opt.searchTitleOnly' , true );
|
||||
IPSSearchRegistry::set('display.onlyTitles' , true );
|
||||
IPSSearchRegistry::set('opt.noPostPreview' , true );
|
||||
$_ffWhere = '';
|
||||
|
||||
/* Get list of good forum IDs */
|
||||
$forumIdsOk = $this->registry->class_forums->fetchSearchableForumIds( $this->memberData['member_id'], $bvnp );
|
||||
/* Followed topics only */
|
||||
if ( $followedOnly )
|
||||
{
|
||||
if ( ! count( $followedTopics ) && ! count( $followedForums ) )
|
||||
{
|
||||
return array( 'count' => 0, 'resultSet' => array() );
|
||||
}
|
||||
|
||||
if ( count( $followedForums ) )
|
||||
{
|
||||
/* @link http://community.invisionpower.com/tracker/issue-33284-view-new-content-just-items-i-follow */
|
||||
//$_ffWhere = ' OR forum_id IN (' . implode( ',', $followedForums ) . ') ';
|
||||
}
|
||||
}
|
||||
|
||||
/* This method allows us to have just one "tid IN()" clause, instead of two, depending on scenario */
|
||||
if ( count($followedTopics) )
|
||||
{
|
||||
$where[] = "( tid IN(" . implode( ',', $followedTopics ) . ')' . $_ffWhere . ' )';
|
||||
}
|
||||
else
|
||||
{
|
||||
if( !count($data['resultSet']) )
|
||||
{
|
||||
return array( 'count' => 0, 'resultSet' => array() );
|
||||
}
|
||||
|
||||
/* Force it into filter so that search can pick it up */
|
||||
ipsRegistry::$request['search_app_filters']['forums']['forums'] = $forumIdsOk;
|
||||
$where[] = "( tid IN(" . implode( ',', $data['resultSet'] ) . ')' . $_ffWhere . ' )';
|
||||
}
|
||||
|
||||
/* Set the timestamps */
|
||||
$this->sphinxClient->SetFilterRange( 'last_post', intval( time() - $seconds ), time() );
|
||||
$this->setDateRange( 0, 0 );
|
||||
$permissions['TopicSoftDeleteSee'] = $this->registry->getClass('class_forums')->canSeeSoftDeletedTopics( 0 );
|
||||
$permissions['canQueue'] = $this->registry->getClass('class_forums')->canQueuePosts( 0 );
|
||||
|
||||
return $this->search();
|
||||
if ( $permissions['TopicSoftDeleteSee'] AND $permissions['canQueue'] )
|
||||
{
|
||||
$where[] = $this->registry->class_forums->fetchTopicHiddenQuery( array( 'visible', 'hidden', 'sdeleted' ) );
|
||||
}
|
||||
else if ( $permissions['TopicSoftDeleteSee'] )
|
||||
{
|
||||
$where[] = $this->registry->class_forums->fetchTopicHiddenQuery( array( 'visible', 'sdeleted' ) );
|
||||
}
|
||||
else if ( $permissions['canQueue'] )
|
||||
{
|
||||
$where[] = $this->registry->class_forums->fetchTopicHiddenQuery( array( 'visible', 'hidden' ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$where[] = $this->registry->class_forums->fetchTopicHiddenQuery( array( 'visible' ) );
|
||||
}
|
||||
|
||||
$where = implode( " AND ", $where );
|
||||
|
||||
/* Fetch the count */
|
||||
$count = $this->DB->buildAndFetch( array( 'select' => 'count(*) as count',
|
||||
'from' => 'topics',
|
||||
'where' => $where ) );
|
||||
|
||||
/* Fetch the count */
|
||||
if ( $count['count'] )
|
||||
{
|
||||
$limit = ( IPSSearchRegistry::get('in.period') != 'unread' ) ? array( $start, $perPage ) : array( 0, 1200 );
|
||||
|
||||
$this->DB->build( array( 'select' => 'tid, forum_id, last_post',
|
||||
'from' => 'topics',
|
||||
'where' => $where,
|
||||
'order' => 'last_post DESC',
|
||||
'limit' => $limit ) );
|
||||
|
||||
$inner = $this->DB->execute();
|
||||
|
||||
while( $row = $this->DB->fetch( $inner ) )
|
||||
{
|
||||
$rtids[ $row['tid'] ] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
/* Set up some vars */
|
||||
IPSSearchRegistry::set('set.resultCutToDate', $oldStamp );
|
||||
|
||||
if ( IPSSearchRegistry::get('in.period') == 'unread' )
|
||||
{
|
||||
$filter = $this->registry->class_forums->postProcessVncTids( $rtids, array( $start, $perPage ) );
|
||||
$data['count'] = $filter['count'];
|
||||
$data['resultSet'] = $filter['tids'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$data = array( 'count' => $count['count'], 'resultSet' => array_keys( $rtids) );
|
||||
}
|
||||
|
||||
/* Return it */
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -667,7 +881,7 @@ class search_engine_forums extends search_engine
|
||||
*
|
||||
* @param string $column sql table column for this condition
|
||||
* @return string column
|
||||
* @return void
|
||||
* @return @e void
|
||||
*/
|
||||
public function remapColumn( $column )
|
||||
{
|
||||
@@ -681,7 +895,7 @@ class search_engine_forums extends search_engine
|
||||
/**
|
||||
* Returns an array used in the searchplugin's setCondition method
|
||||
*
|
||||
* @param array $data Array of forums to view
|
||||
* @param array $data Array of filters to apply
|
||||
* @return array Array with column, operator, and value keys, for use in the setCondition call
|
||||
*/
|
||||
public function buildFilterSQL( $data )
|
||||
@@ -691,7 +905,11 @@ class search_engine_forums extends search_engine
|
||||
|
||||
/* Set up some defaults */
|
||||
IPSSearchRegistry::set( 'opt.noPostPreview' , true );
|
||||
IPSSearchRegistry::set( 'opt.onlySearchPosts', false );
|
||||
|
||||
if ( ! IPSSearchRegistry::get('opt.searchType' ) )
|
||||
{
|
||||
IPSSearchRegistry::set( 'opt.searchType', 'both' );
|
||||
}
|
||||
|
||||
if( isset( $data ) && is_array( $data ) && count( $data ) )
|
||||
{
|
||||
@@ -703,12 +921,6 @@ class search_engine_forums extends search_engine
|
||||
IPSSearchRegistry::set( 'opt.noPostPreview', false );
|
||||
}
|
||||
|
||||
/* CONTENT ONLY */
|
||||
if ( $field == 'contentOnly' AND $_data['contentOnly'] == 1 )
|
||||
{
|
||||
IPSSearchRegistry::set( 'opt.onlySearchPosts', true );
|
||||
}
|
||||
|
||||
/* POST COUNT */
|
||||
if ( $field == 'pCount' AND intval( $_data['pCount'] ) > 0 )
|
||||
{
|
||||
@@ -726,7 +938,7 @@ class search_engine_forums extends search_engine
|
||||
}
|
||||
else
|
||||
{
|
||||
return '';
|
||||
return array();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user