Version 3.2.3

This commit is contained in:
Neo committed 2025-12-19 00:34:03 -08:00
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-07-28 18:01:32 -0400 (Thu, 28 Jul 2011) $
* </pre>
*
* @author $Author: matt $
* @author $Author: bfarber $
* @copyright (c) 2001 - 2009 Invision Power Services, Inc.
* @license http://www.invisionpower.com/community/board/license.html
* @license This is NULLED!
* @package IP.Board
* @subpackage Forums
* @link http://www.invisionpower.com
* @version $Rev: 5861 $
* @link http://hatynka.in
* @version $Rev: 9330 $
*/
if ( ! defined( 'IN_IPB' ) )
@@ -35,11 +35,13 @@ class search_engine_members extends search_engine
/**
* Decide what type of search we're using
*
* @access public
* @return array
*/
public function search()
{
/* Hard limit */
IPSSearchRegistry::set('set.hardLimit', ( ipsRegistry::$settings['search_hardlimit'] ) ? ipsRegistry::$settings['search_hardlimit'] : 200 );
/* Ok, now because the top bar search box defaults to members default search, which is profile comments, we need
to convince it to default to members if the user used the top search bar with members selected */
if ( $this->request['fromMainBar'] )
@@ -47,13 +49,17 @@ class search_engine_members extends search_engine
IPSSearchRegistry::set('members.searchInKey', 'members');
}
if ( IPSSearchRegistry::get('members.searchInKey') AND IPSSearchRegistry::get('members.searchInKey') != 'comments' )
if ( IPSSearchRegistry::get('members.searchInKey') == 'comments' )
{
return $this->_membersSearch();
$this->request['search_app_filters']['members']['searchInKey'] = 'comments';
return $this->_commentsSearch();
}
else
{
return $this->_commentsSearch();
$this->request['search_app_filters']['members']['searchInKey'] = 'members';
return $this->_membersSearch();
}
}
@@ -64,86 +70,123 @@ class search_engine_members extends search_engine
*
* So if we had 1000 replies, and we are on page 2 of 25 per page, we'd return 25 items offset by 25
*
* @access public
* @return array
*/
public function _commentsSearch()
{
/* INIT */
$count = 0;
$results = array();
$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');
$order_dir = ( $sort_order == 'asc' ) ? 'asc' : 'desc';
$sortKey = '';
$sortType = '';
$rows = array();
$got = 0;
/* Sorting */
switch( $sort_by )
{
default:
case 'date':
$sortKey = 'comment_date';
$sortType = 'numerical';
break;
}
/* Not allowed to see profile information */
if ( ! $this->memberData['g_mem_info'] )
{
return array( 'count' => 0, 'resultSet' => array() );
}
/* Query the count */
$count = $this->DB->buildAndFetch( array('select' => 'COUNT(*) as total_results',
'from' => array( 'profile_comments' => 'c' ),
'where' => $this->_buildCommentsWhereStatement( $search_term, $content_title_only ),
'add_join' => array( array( 'from' => array( 'profile_portal' => 'p' ),
'where' => "p.pp_member_id=c.comment_by_member_id",
'type' => 'left' ) ) ) );
/* INIT */
$sort_order = IPSSearchRegistry::get('in.search_sort_order');
$search_term = IPSSearchRegistry::get('in.clean_search_term');
$rows = array();
/* Fetch data */
$this->DB->build( array('select' => 'c.*',
'from' => array( 'profile_comments' => 'c' ),
'where' => $this->_buildCommentsWhereStatement( $search_term, $content_title_only ),
'order' => $sortKey . ' ' . $sort_order,
'limit' => array( IPSSearchRegistry::get('in.start'), IPSSearchRegistry::get('opt.search_per_page') ),
'add_join' => array( array( 'select' => 'x.members_display_name as members_display_name_from, x.members_seo_name as members_seo_name_from',
'from' => array( 'members' => 'x' ),
'where' => "x.member_id=c.comment_by_member_id",
'type' => 'left' ),
array( 'select' => 'm.*',
'from' => array( 'members' => 'm' ),
'where' => "m.member_id=c.comment_for_member_id",
'type' => 'left' ),
array( 'select' => 'p.*',
'from' => array( 'profile_portal' => 'p' ),
'where' => "p.pp_member_id=c.comment_for_member_id",
'type' => 'left' ) ) ) );
$this->DB->execute();
$this->DB->build( array(
'select' => "s.status_id, s.status_date",
'from' => 'member_status_updates s',
'where' => $this->_buildCommentsWhereStatement( $search_term ),
'limit' => array(0, IPSSearchRegistry::get('set.hardLimit') + 1),
'order' => 's.status_date ' . $sort_order ) );
/* Sort */
while ( $_row = $this->DB->fetch() )
{
$rows[ $got ] = $_row;
$got++;
$DB = $this->DB->execute();
/* Fetch all to sort */
while( $r = $this->DB->fetch( $DB ) )
{
if ( IPSSearchRegistry::get('opt.noPostPreview') )
{
$_rows[ $r['status_id'] ] = $r;
}
else
{
$_rows[ $r['status_id'] ] = $r;
}
}
/* Got any replies? */
if ( count( IPSSearchRegistry::get('_internal.replyIds') ) )
{
$this->DB->build( array(
'select' => "r.*, r.reply_date as status_date",
'from' => array( 'member_status_replies' => 'r' ),
'where' => 'r.reply_id IN( ' . implode( ',', IPSSearchRegistry::get('_internal.replyIds') ) . ')',
'add_join' => array_merge( array( array( 'select' => 's.status_id, s.status_member_id, s.status_author_id',
'from' => array( 'member_status_updates' => 's' ),
'where' => 's.status_id=r.reply_status_id',
'type' => 'left' ),
array( 'select' => 'm.member_id as owner_id, m.members_display_name as owner_display_name, m.members_seo_name as owner_seo_name',
'from' => array( 'members' => 'm' ),
'where' => 'm.member_id=s.status_member_id',
'type' => 'left' ),
array( 'select' => 'mem.member_id as author_id, mem.members_display_name as author_display_name, mem.members_seo_name as author_seo_name',
'from' => array( 'members' => 'mem' ),
'where' => 'mem.member_id=s.status_author_id',
'type' => 'left' ) ) ) ) );
/* Grab data */
$this->DB->execute();
/* Grab the results */
while( $row = $this->DB->fetch() )
{
$_rows[ $row['reply_status_id'] ] = $row;
$_replies[ $row['reply_status_id'] ] = $row;
}
}
/* Store */
IPSSearchRegistry::set('_internal.replyData', $_replies );
/* Fetch count */
$count = count( $_rows );
$c = 0;
$rows = array();
$got = 0;
if ( $count > IPSSearchRegistry::get('set.hardLimit') )
{
$count = IPSSearchRegistry::get('set.hardLimit');
IPSSearchRegistry::set('set.resultsCutToLimit', true );
}
/* Set vars */
IPSSearch::$ask = 'status_date';
IPSSearch::$aso = strtolower( $sort_order );
IPSSearch::$ast = 'numerical';
/* Sort */
if ( count( $_rows ) )
{
usort( $_rows, array("IPSSearch", "usort") );
/* Build result array */
foreach( $_rows as $r )
{
$c++;
if ( IPSSearchRegistry::get('in.start') AND IPSSearchRegistry::get('in.start') >= $c )
{
continue;
}
$rows[ $got ] = $r['status_id'];
$got++;
/* Done? */
if ( IPSSearchRegistry::get('opt.search_per_page') AND $got >= IPSSearchRegistry::get('opt.search_per_page') )
{
break;
}
}
}
/* Return it */
return array( 'count' => $count['total_results'], 'resultSet' => $rows );
return array( 'count' => $count, 'resultSet' => $rows );
}
/**
@@ -153,26 +196,18 @@ class search_engine_members extends search_engine
*
* So if we had 1000 replies, and we are on page 2 of 25 per page, we'd return 25 items offset by 25
*
* @access public
* @return array
*/
public function _membersSearch()
{
/* INIT */
$count = 0;
$results = array();
$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');
$order_dir = ( $sort_order == 'asc' ) ? 'asc' : 'desc';
$sortKey = '';
$sortType = '';
$rows = array();
$got = 0;
/* INIT */
$sort_by = IPSSearchRegistry::get('in.search_sort_by');
$sort_order = IPSSearchRegistry::get('in.search_sort_order');
$search_term = IPSSearchRegistry::get('in.clean_search_term');
$sortKey = '';
$rows = array();
if ( IPSSearchRegistry::get('opt.noPostPreview') OR IPSSearchRegistry::get('display.onlyTitles') )
if ( IPSSearchRegistry::get('opt.noPostPreview') OR IPSSearchRegistry::get('opt.searchType') == 'titles' )
{
$group_by = 'm.member_id';
}
@@ -182,19 +217,17 @@ class search_engine_members extends search_engine
{
default:
case 'date':
$sortKey = ( $content_title_only ) ? 'member_id' : 'member_id';
$sortType = 'numerical';
$sortKey = 'member_id';
break;
case 'title':
$sortKey = 'members_l_display_name';
$sortType = 'string';
break;
}
/* Query the count */
$count = $this->DB->buildAndFetch( array('select' => 'COUNT(*) as total_results',
'from' => array( 'members' => 'm' ),
'where' => $this->_buildWhereStatement( $search_term, $content_title_only ),
'where' => $this->_buildWhereStatement( $search_term ),
'group' => $group_by,
'add_join' => array( array( 'from' => array( 'profile_portal' => 'p' ),
'where' => "p.pp_member_id=m.member_id",
@@ -205,7 +238,7 @@ class search_engine_members extends search_engine
/* Fetch data */
$this->DB->build( array('select' => 'm.*',
'from' => array( 'members' => 'm' ),
'where' => $this->_buildWhereStatement( $search_term, $content_title_only ),
'where' => $this->_buildWhereStatement( $search_term ),
'group' => $group_by,
'order' => $sortKey . ' ' . $sort_order,
'limit' => array( IPSSearchRegistry::get('in.start'), IPSSearchRegistry::get('opt.search_per_page') ),
@@ -213,41 +246,144 @@ class search_engine_members extends search_engine
'from' => array( 'profile_portal' => 'p' ),
'where' => "p.pp_member_id=m.member_id",
'type' => 'left' ) ) ) );
$this->DB->execute();
/* Sort */
/* Get results */
while ( $_row = $this->DB->fetch() )
{
$rows[ $got ] = $_row;
$got++;
$rows[] = IPSMember::buildProfilePhoto( $_row );
}
/* Return it */
return array( 'count' => $count['total_results'], 'resultSet' => $rows );
}
/**
* Perform the viewNewContent search
* Populates $this->_count and $this->_results
*
* @access public
* @return array
* @note Does not support 'Content I have not read' because events are not tracked through topic marker class
* @note Does not support 'Content I am following' because you cannot 'follow' members at this point in time
*/
public function viewNewContent()
{
//-----------------------------------------
// Init
//-----------------------------------------
IPSSearchRegistry::set('in.search_sort_by', 'date' );
IPSSearchRegistry::set('in.search_sort_order', 'desc' );
IPSSearchRegistry::set('opt.searchType', 'titles' );
IPSSearchRegistry::set('opt.noPostPreview', true );
//-----------------------------------------
// Set time limit
//-----------------------------------------
if ( IPSSearchRegistry::get('in.period_in_seconds') !== false )
{
$this->search_begin_timestamp = ( IPS_UNIX_TIME_NOW - IPSSearchRegistry::get('in.period_in_seconds') );
}
else
{
$this->search_begin_timestamp = intval( $this->memberData['last_visit'] ) ? intval( $this->memberData['last_visit'] ) : IPS_UNIX_TIME_NOW;
}
return $this->search();
}
/**
* Builds the where portion of a search string
*
* @access private
* @param string $search_term The string to use in the search
* @param bool $content_title_only Search only title records
* @param string $search_term The string to use in the search
* @param bool $searchType Search only title records
* @return string
**/
private function _buildCommentsWhereStatement( $search_term, $content_title_only=false )
*/
protected function _buildCommentsWhereStatement( $search_term, $searchType=null )
{
/* INI */
$where_clause = array();
if( $search_term )
$where_clause = array();
$searchType = ( $searchType === null ) ? IPSSearchRegistry::get('opt.searchType') : $searchType;
$sort_order = IPSSearchRegistry::get('in.search_sort_order');
if ( $search_term )
{
$where_clause[] = "c.comment_content LIKE '%" . mb_strtolower( $search_term ) . "%'";
if ( $searchType == 'titles' )
{
$where_clause[] = $this->DB->buildSearchStatement( 's.status_content', $search_term, true, false, false );
}
else
{
if ( $searchType == 'content' )
{
$where_clause[] = $this->DB->buildSearchStatement( 'r.reply_content', $search_term, true, false, false );
}
else
{
/* Set vars */
IPSSearch::$ask = 'status_date';
IPSSearch::$aso = strtolower( $sort_order );
IPSSearch::$ast = 'numerical';
/* Find topic ids that match */
$tids = array();
$pids = array();
$this->DB->build( array('select' => "s.status_id, s.status_date",
'from' => 'member_status_updates s',
'where' => $this->_buildCommentsWhereStatement( $search_term, 'titles' ),
'order' => 's.status_date ' . $sort_order,
'limit' => array(0, IPSSearchRegistry::get('set.hardLimit')) ) );
$i = $this->DB->execute();
/* Grab the results */
while( $row = $this->DB->fetch( $i ) )
{
$_rows[ $row['status_id'] ] = $row;
}
/* Sort */
if ( count( $_rows ) )
{
usort( $_rows, array("IPSSearch", "usort") );
foreach( $_rows as $id => $row )
{
$tids[] = $row['status_id'];
}
}
/* Set vars */
IPSSearch::$ask = 'reply_date';
IPSSearch::$aso = strtolower( $sort_order );
IPSSearch::$ast = 'numerical';
$this->DB->build( array( 'select' => "r.reply_id, r.reply_date, r.reply_status_id as status_id",
'from' => 'member_status_replies r',
'where' => $this->_buildCommentsWhereStatement( $search_term, 'content' ),
'order' => IPSSearch::$ask . ' ' . IPSSearch::$aso,
'limit' => array(0, IPSSearchRegistry::get('set.hardLimit') ) ) );
$i = $this->DB->execute();
/* Grab the results */
while( $row = $this->DB->fetch( $i ) )
{
$tids[] = $row['status_id'];
$pids[] = $row['reply_id'];
}
if ( count( $pids ) )
{
IPSSearchRegistry::set('_internal.replyIds', $pids );
}
$where_clause[] = '( s.status_id IN (' . ( count($tids) ? implode( ',', $tids ) : 0 ) .') )';
}
}
}
/* Add in AND where conditions */
@@ -264,51 +400,54 @@ class search_engine_members extends search_engine
/* Date Restrict */
if( $this->search_begin_timestamp && $this->search_end_timestamp )
{
$where_clause[] = $this->DB->buildBetween( "c.comment_date", $this->search_begin_timestamp, $this->search_end_timestamp );
{
$where_clause[] = $this->DB->buildBetween( $searchType == 'content' ? "r.reply_date" : "s.status_date", $this->search_begin_timestamp, $this->search_end_timestamp );
}
else
{
if( $this->search_begin_timestamp )
{
$where_clause[] = "c.comment_date > {$this->search_begin_timestamp}";
$where_clause[] = $searchType == 'content' ? "r.reply_date > {$this->search_begin_timestamp}" : "s.status_date > {$this->search_begin_timestamp}";
}
if( $this->search_end_timestamp )
{
$where_clause[] = "c.comment_date < {$this->search_end_timestamp}";
$where_clause[] = $searchType == 'content' ? "r.reply_date < {$this->search_end_timestamp}" : "s.status_date < {$this->search_end_timestamp}";
}
}
$where_clause[] = "c.comment_approved=1";
/* Build and return the string */
return implode( " AND ", $where_clause );
}
/**
* Builds the where portion of a search string
*
* @access private
* @param string $search_term The string to use in the search
* @param bool $content_title_only Search only title records
* @return string
**/
private function _buildWhereStatement( $search_term, $content_title_only=false )
*/
protected function _buildWhereStatement( $search_term )
{
/* INI */
$where_clause = array();
if( $search_term )
{
if( $content_title_only )
switch( IPSSearchRegistry::get('opt.searchType') )
{
$where_clause[] = "m.members_l_display_name LIKE '%" . mb_strtolower( $search_term ) . "%'";
}
else
{
$where_clause[] = "m.members_l_display_name LIKE '%" . mb_strtolower( $search_term ) . "%' OR p.signature LIKE '%{$search_term}%' OR p.pp_about_me LIKE '%{$search_term}%'";
case 'both':
default:
$where_clause[] = "(m.members_l_display_name LIKE '%" . mb_strtolower( $search_term ) . "%' OR p.signature LIKE '%{$search_term}%' OR p.pp_about_me LIKE '%{$search_term}%')";
break;
case 'titles':
$where_clause[] = "m.members_l_display_name LIKE '%" . mb_strtolower( $search_term ) . "%'";
break;
case 'content':
$where_clause[] = "(p.signature LIKE '%{$search_term}%' OR p.pp_about_me LIKE '%{$search_term}%')";
break;
}
}
@@ -349,16 +488,15 @@ class search_engine_members extends search_engine
/**
* Remap standard columns (Apps can override )
*
* @access public
* @param string $column sql table column for this condition
* @return string column
* @return void
* @return @e void
*/
public function remapColumn( $column )
{
if ( IPSSearchRegistry::get( 'members.searchInKey') == 'comments' )
{
$column = ( $column == 'member_id' ) ? 'c.comment_by_member_id' : '';
$column = ( $column == 'member_id' ) ? 'status_author_id' : '';
}
return $column;
@@ -367,62 +505,21 @@ class search_engine_members extends search_engine
/**
* Returns an array used in the searchplugin's setCondition method
*
* @access public
* @param array $data Array of forums to view
* @return array Array with column, operator, and value keys, for use in the setCondition call
**/
*/
public function buildFilterSQL( $data )
{
/* INIT */
$return = array();
/* Set up some defaults */
IPSSearchRegistry::set( 'opt.noPostPreview' , false );
IPSSearchRegistry::set( 'opt.onlySearchPosts', false );
//IPSSearchRegistry::set( 'members.searchInKey' , 'comments' );
/* member specific search */
/* Make default search type topics */
if( isset( $data ) && is_array( $data ) && count( $data ) )
{
foreach( $data as $field => $_data )
{
/* CONTENT ONLY */
if ( $field == 'searchInKey' AND $_data['searchInKey'] == 'members' )
{
//IPSSearchRegistry::set( 'member.searchType', 'members' );
}
}
}
return array();
}
/**
* Can handle boolean searching
*
* @access public
* @return boolean
*/
public function isBoolean()
{
return false;
}
/**
* Perform the viewNewContent search
* Forum Version
* Populates $this->_count and $this->_results
*
* @access public
* @return nothin'
*/
public function viewNewContent()
{
/* Set up some vars */
IPSSearchRegistry::set('set.resultCutToDate', intval( $this->memberData['last_visit'] ) );
return parent::viewNewContent();
}
}