Version 4.5.0
This commit is contained in:
1 parent
1a0c7fd3c2
commit
f79dcf067a
3791 files changed
+248032
-76372
No files matched your search
@@ -11,7 +11,7 @@
|
||||
namespace IPS\core\modules\front\search;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -38,6 +38,12 @@ class _search extends \IPS\Dispatcher\Controller
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'styles/search_responsive.css' ) );
|
||||
}
|
||||
|
||||
/* Add any global CSS from other apps */
|
||||
foreach( \IPS\Application::applications() as $app )
|
||||
{
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'global.css', $app->directory, 'front' ) );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'front_search.js', 'core' ) );
|
||||
\IPS\Output::i()->metaTags['robots'] = 'noindex'; // Tell search engines not to index search pages
|
||||
|
||||
@@ -53,7 +59,14 @@ class _search extends \IPS\Dispatcher\Controller
|
||||
/* If we have the term, show the results */
|
||||
if ( \IPS\Request::i()->isAjax() or isset( \IPS\Request::i()->q ) or isset( \IPS\Request::i()->tags ) or ( \IPS\Request::i()->type == 'core_members' and \IPS\Member::loggedIn()->canAccessModule( \IPS\Application\Module::get( 'core', 'members', 'front' ) ) ) )
|
||||
{
|
||||
if ( !\IPS\Request::i()->isAjax() and !\IPS\Request::i()->q and !\IPS\Request::i()->tags and \IPS\Request::i()->type !== 'core_members' and \IPS\Member::loggedIn()->canAccessModule( \IPS\Application\Module::get( 'core', 'members', 'front' ) ) )
|
||||
$showForm = ( \IPS\Request::i()->type == 'core_members' ) ? FALSE : ( !\IPS\Request::i()->isAjax() and !\IPS\Request::i()->q and !\IPS\Request::i()->tags );
|
||||
|
||||
if( \IPS\Request::i()->type == 'core_members' AND !\IPS\Member::loggedIn()->canAccessModule( \IPS\Application\Module::get( 'core', 'members', 'front' ) ) )
|
||||
{
|
||||
$showForm = TRUE;
|
||||
}
|
||||
|
||||
if ( $showForm )
|
||||
{
|
||||
if ( isset( \IPS\Request::i()->csrfKey ) )
|
||||
{
|
||||
@@ -94,24 +107,28 @@ class _search extends \IPS\Dispatcher\Controller
|
||||
*/
|
||||
protected function _results()
|
||||
{
|
||||
/* Make sure we are not doing anything nefarious like passing an array the the "q" parameter, which generates errors */
|
||||
/* Make sure we are not doing anything nefarious like passing an array as the "q" parameter, which generates errors */
|
||||
foreach( array( 'q', 'type' ) AS $parameter )
|
||||
{
|
||||
if ( isset( \IPS\Request::i()->$parameter ) AND is_array( \IPS\Request::i()->$parameter ) )
|
||||
if ( isset( \IPS\Request::i()->$parameter ) AND \is_array( \IPS\Request::i()->$parameter ) )
|
||||
{
|
||||
\IPS\Request::i()->$parameter = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* Init */
|
||||
$baseUrl = \IPS\Http\Url::internal( 'app=core&module=search&controller=search', 'front', 'search' );
|
||||
if( \IPS\Request::i()->q )
|
||||
{
|
||||
$baseUrl = $baseUrl->setQueryString( 'q', \IPS\Request::i()->q );
|
||||
$baseUrl = \IPS\Http\Url::internal( 'app=core&module=search&controller=search', 'front', 'search' );
|
||||
if( \IPS\Request::i()->q )
|
||||
{
|
||||
$baseUrl = $baseUrl->setQueryString( 'q', \IPS\Request::i()->q );
|
||||
}
|
||||
if ( \IPS\Request::i()->tags )
|
||||
{
|
||||
$baseUrl = $baseUrl->setQueryString( 'tags', \IPS\Request::i()->tags );
|
||||
}
|
||||
elseif ( \IPS\Request::i()->tags )
|
||||
{
|
||||
$baseUrl = $baseUrl->setQueryString( 'tags', \IPS\Request::i()->tags );
|
||||
if (isset( \IPS\Request::i()->eitherTermsOrTags))
|
||||
{
|
||||
$baseUrl = $baseUrl->setQueryString( 'eitherTermsOrTags', \IPS\Request::i()->eitherTermsOrTags );
|
||||
}
|
||||
|
||||
$types = static::contentTypes();
|
||||
@@ -129,11 +146,13 @@ class _search extends \IPS\Dispatcher\Controller
|
||||
}
|
||||
else
|
||||
{
|
||||
$where = array( array( 'core_members.name<>?', '' ) );
|
||||
$where = array( array( 'core_members.completed=?', true ) );
|
||||
}
|
||||
|
||||
if ( isset( \IPS\Request::i()->joinedDate ) and !isset( \IPS\Request::i()->start_after ) )
|
||||
{
|
||||
$baseUrl = $baseUrl->setQueryString( 'joinedDate', \IPS\Request::i()->joinedDate );
|
||||
|
||||
\IPS\Request::i()->start_after = \IPS\Request::i()->joinedDate;
|
||||
}
|
||||
if ( isset( \IPS\Request::i()->start_before ) or isset( \IPS\Request::i()->start_after ) )
|
||||
@@ -186,9 +205,9 @@ class _search extends \IPS\Dispatcher\Controller
|
||||
if ( isset( \IPS\Request::i()->group ) )
|
||||
{
|
||||
/* Only exclude by group if the only value isn't __EMPTY **/
|
||||
if( !is_array( \IPS\Request::i()->group ) OR ( count( \IPS\Request::i()->group ) > 1 OR !isset( \IPS\Request::i()->group['__EMPTY'] ) ) )
|
||||
if( !\is_array( \IPS\Request::i()->group ) OR ( \count( \IPS\Request::i()->group ) > 1 OR !isset( \IPS\Request::i()->group['__EMPTY'] ) ) )
|
||||
{
|
||||
$groups = ( is_array( \IPS\Request::i()->group ) ) ? array_filter( array_keys( \IPS\Request::i()->group ), function( $val ){
|
||||
$groups = ( \is_array( \IPS\Request::i()->group ) ) ? array_filter( array_keys( \IPS\Request::i()->group ), function( $val ){
|
||||
if( $val == '__EMPTY' )
|
||||
{
|
||||
return false;
|
||||
@@ -228,7 +247,7 @@ class _search extends \IPS\Dispatcher\Controller
|
||||
}
|
||||
}
|
||||
|
||||
if ( count( $exclude ) )
|
||||
if ( \count( $exclude ) )
|
||||
{
|
||||
$where[] = \IPS\Db::i()->in( 'core_members.member_group_id', $exclude, TRUE );
|
||||
}
|
||||
@@ -241,7 +260,7 @@ class _search extends \IPS\Dispatcher\Controller
|
||||
foreach ( $fields as $id => $field )
|
||||
{
|
||||
/* Work out the object type so we can show the appropriate field */
|
||||
$type = get_class( $field );
|
||||
$type = \get_class( $field );
|
||||
|
||||
switch ( $type )
|
||||
{
|
||||
@@ -257,17 +276,33 @@ class _search extends \IPS\Dispatcher\Controller
|
||||
|
||||
if( isset( \IPS\Request::i()->$fieldName ) )
|
||||
{
|
||||
$where[] = array( 'LOWER(core_pfields_content.field_' . $id . ') LIKE ?', '%' . mb_strtolower( \IPS\Request::i()->$fieldName ) . '%' );
|
||||
if( \IPS\Data\Store::i()->profileFields['fields'][$group][$id]['pf_search_type'] == 'loose' )
|
||||
{
|
||||
$where[] = array( 'LOWER(core_pfields_content.field_' . $id . ') LIKE ?', '%' . mb_strtolower( \IPS\Request::i()->$fieldName ) . '%' );
|
||||
}
|
||||
else
|
||||
{
|
||||
$where[] = array( 'LOWER(core_pfields_content.field_' . $id . ') = ?', mb_strtolower( \IPS\Request::i()->$fieldName ) );
|
||||
}
|
||||
$baseUrl = $baseUrl->setQueryString( $fieldName, \IPS\Request::i()->$fieldName );
|
||||
}
|
||||
break;
|
||||
case 'IPS\Helpers\Form\Select':
|
||||
case 'IPS\Helpers\Form\CheckboxSet':
|
||||
case 'IPS\Helpers\Form\Radio':
|
||||
$fieldName = 'core_pfield_' . $id;
|
||||
|
||||
if( isset( \IPS\Request::i()->$fieldName ) )
|
||||
{
|
||||
$where[] = array( 'core_pfields_content.field_' . $id . ' = ?', mb_strtolower( \IPS\Request::i()->$fieldName ) );
|
||||
if ( ( $type === 'IPS\Helpers\Form\CheckboxSet' ) or ( isset( $field->options['multiple'] ) AND $field->options['multiple'] == 1 ) )
|
||||
{
|
||||
$where[] = \IPS\Db::i()->findInSet( 'core_pfields_content.field_' . $id ,array( mb_strtolower( \IPS\Request::i()->$fieldName ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$where[] = array( 'core_pfields_content.field_' . $id . ' = ?', mb_strtolower( \IPS\Request::i()->$fieldName ) );
|
||||
}
|
||||
|
||||
$baseUrl = $baseUrl->setQueryString( $fieldName, \IPS\Request::i()->$fieldName );
|
||||
}
|
||||
break;
|
||||
@@ -275,9 +310,9 @@ class _search extends \IPS\Dispatcher\Controller
|
||||
}
|
||||
}
|
||||
|
||||
if( isset( \IPS\Request::i()->sortby ) AND in_array( mb_strtolower( \IPS\Request::i()->sortby ), array( 'joined', 'name', 'member_posts', 'pp_reputation_points' ) ) )
|
||||
if( isset( \IPS\Request::i()->sortby ) AND \in_array( mb_strtolower( \IPS\Request::i()->sortby ), array( 'joined', 'name', 'member_posts', 'pp_reputation_points' ) ) )
|
||||
{
|
||||
$direction = ( isset( \IPS\Request::i()->sortdirection ) AND in_array( mb_strtolower( \IPS\Request::i()->sortdirection ), array( 'asc', 'desc' ) ) ) ? \IPS\Request::i()->sortdirection : 'asc';
|
||||
$direction = ( isset( \IPS\Request::i()->sortdirection ) AND \in_array( mb_strtolower( \IPS\Request::i()->sortdirection ), array( 'asc', 'desc' ) ) ) ? \IPS\Request::i()->sortdirection : 'asc';
|
||||
$order = mb_strtolower( \IPS\Request::i()->sortby ) . ' ' . $direction;
|
||||
|
||||
$baseUrl = $baseUrl->setQueryString( array( 'sortby' => \IPS\Request::i()->sortby, 'sortdirection' => \IPS\Request::i()->sortdirection ) );
|
||||
@@ -296,19 +331,23 @@ class _search extends \IPS\Dispatcher\Controller
|
||||
}
|
||||
}
|
||||
|
||||
$page = isset( \IPS\Request::i()->page ) ? intval( \IPS\Request::i()->page ) : 1;
|
||||
$page = isset( \IPS\Request::i()->page ) ? \intval( \IPS\Request::i()->page ) : 1;
|
||||
|
||||
if( $page < 1 )
|
||||
{
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$where[] = array( "( core_validating.vid IS NULL ) " );
|
||||
|
||||
$select = \IPS\Db::i()->select( 'COUNT(*)', 'core_members', $where );
|
||||
$select->join( 'core_pfields_content', 'core_pfields_content.member_id=core_members.member_id' );
|
||||
$select->join( 'core_validating', 'core_validating.member_id=core_members.member_id AND core_validating.new_reg = 1' );
|
||||
$count = $select->first();
|
||||
|
||||
$select = \IPS\Db::i()->select( 'core_members.*', 'core_members', $where, $order, array( ( $page - 1 ) * $this->memberSearchResults, $this->memberSearchResults ) );
|
||||
$select->join( 'core_pfields_content', 'core_pfields_content.member_id=core_members.member_id' );
|
||||
$select->join( 'core_validating', 'core_validating.member_id=core_members.member_id AND core_validating.new_reg = 1' );
|
||||
|
||||
$results = new \IPS\Patterns\ActiveRecordIterator( $select, 'IPS\Member' );
|
||||
|
||||
@@ -355,7 +394,7 @@ class _search extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
$item = $class::loadAndCheckPerms( \IPS\Request::i()->item );
|
||||
$query->filterByContent( array( \IPS\Content\Search\ContentFilter::init( $class )->onlyInItems( array( \IPS\Request::i()->item ) ) ) );
|
||||
$baseUrl = $baseUrl->setQueryString( 'item', intval( \IPS\Request::i()->item ) );
|
||||
$baseUrl = $baseUrl->setQueryString( 'item', \intval( \IPS\Request::i()->item ) );
|
||||
$titleConditions[] = \IPS\Member::loggedIn()->language()->addToStack( 'search_blurb_in', FALSE, array( 'sprintf' => array( $item->mapped('title') ) ) );
|
||||
$baseUrl = $baseUrl->setQueryString( 'type', \IPS\Request::i()->type );
|
||||
}
|
||||
@@ -368,16 +407,30 @@ class _search extends \IPS\Dispatcher\Controller
|
||||
|
||||
if ( isset( \IPS\Request::i()->nodes ) )
|
||||
{
|
||||
$filter->onlyInContainers( explode( ',', \IPS\Request::i()->nodes ) );
|
||||
/* It's ok to just pass the (potential) parent IDs into the URL */
|
||||
$baseUrl = $baseUrl->setQueryString( 'nodes', \IPS\Request::i()->nodes );
|
||||
|
||||
|
||||
$nodeIds = explode( ',', \IPS\Request::i()->nodes );
|
||||
$nodes = array();
|
||||
$nodeClass = $types[ \IPS\Request::i()->type ]::$containerNodeClass;
|
||||
foreach ( explode( ',', \IPS\Request::i()->nodes ) as $id )
|
||||
foreach ( $nodeIds as $id )
|
||||
{
|
||||
try
|
||||
{
|
||||
$nodes[] = $nodeClass::loadAndCheckPerms( $id )->_title;
|
||||
$thisNode = $nodeClass::loadAndCheckPerms( $id );
|
||||
$nodes[] = $thisNode->_title;
|
||||
|
||||
if ( isset( \IPS\Request::i()->quick ) AND $thisNode->childrenCount() )
|
||||
{
|
||||
foreach( $thisNode->children() as $child )
|
||||
{
|
||||
/* Avoid going too deep. Stop laughing at the back */
|
||||
if ( \count( $nodeIds ) < 200 )
|
||||
{
|
||||
$nodeIds[] = $child->_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( \OutOfRangeException $e ) { }
|
||||
}
|
||||
@@ -387,6 +440,8 @@ class _search extends \IPS\Dispatcher\Controller
|
||||
\IPS\Output::i()->error( 'search_invalid_nodes', '2C205/5', 404, '' );
|
||||
}
|
||||
|
||||
$filter->onlyInContainers( $nodeIds );
|
||||
|
||||
$nodes = \IPS\Member::loggedIn()->language()->formatList( $nodes );
|
||||
$titleConditions[] = \IPS\Member::loggedIn()->language()->addToStack( 'search_blurb_in', FALSE, array( 'sprintf' => array( $nodes ) ) );
|
||||
}
|
||||
@@ -413,7 +468,7 @@ class _search extends \IPS\Dispatcher\Controller
|
||||
$baseUrl = $baseUrl->setQueryString( 'search_min_reviews', \IPS\Request::i()->search_min_reviews );
|
||||
$titleConditions[] = \IPS\Member::loggedIn()->language()->addToStack( 'search_blurb_min_reviews', FALSE, array( 'sprintf' => array( \IPS\Request::i()->search_min_reviews ) ) );
|
||||
}
|
||||
if ( isset( \IPS\Request::i()->search_min_views ) AND isset( $class::$databaseColumnMap['views'] ) )
|
||||
if ( isset( \IPS\Request::i()->search_min_views ) AND isset( $class::$databaseColumnMap['views'] ) AND \IPS\Content\Search\Index::i()->supportViewFiltering() )
|
||||
{
|
||||
$filter->minimumViews( \IPS\Request::i()->search_min_views );
|
||||
$baseUrl = $baseUrl->setQueryString( 'search_min_views', \IPS\Request::i()->search_min_views );
|
||||
@@ -428,7 +483,7 @@ class _search extends \IPS\Dispatcher\Controller
|
||||
/* Filter by author */
|
||||
if ( isset( \IPS\Request::i()->author ) )
|
||||
{
|
||||
$author = \IPS\Member::load( \IPS\Request::i()->author, 'name' );
|
||||
$author = \IPS\Member::load( html_entity_decode( \IPS\Request::i()->author, ENT_QUOTES, 'UTF-8' ), 'name' );
|
||||
if ( $author->member_id )
|
||||
{
|
||||
$query->filterByAuthor( $author );
|
||||
@@ -457,7 +512,7 @@ class _search extends \IPS\Dispatcher\Controller
|
||||
catch ( \OutOfRangeException $e ) { }
|
||||
}
|
||||
|
||||
if ( count( $clubIds ) )
|
||||
if ( \count( $clubIds ) )
|
||||
{
|
||||
$query->filterByClub( $clubIds );
|
||||
$baseUrl = $baseUrl->setQueryString( 'club', \IPS\Request::i()->club );
|
||||
@@ -470,11 +525,22 @@ class _search extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
$beforeKey = "{$k}_before";
|
||||
$afterKey = "{$k}_after";
|
||||
|
||||
if ( isset( \IPS\Request::i()->$beforeKey ) )
|
||||
{
|
||||
$baseUrl = $baseUrl->setQueryString( $beforeKey, \IPS\Request::i()->$beforeKey );
|
||||
}
|
||||
|
||||
if ( isset( \IPS\Request::i()->$afterKey ) )
|
||||
{
|
||||
$baseUrl = $baseUrl->setQueryString( $afterKey, \IPS\Request::i()->$afterKey );
|
||||
}
|
||||
|
||||
if ( isset( \IPS\Request::i()->$beforeKey ) and \IPS\Request::i()->$beforeKey != 'any' and isset( \IPS\Request::i()->$afterKey ) and \IPS\Request::i()->$afterKey != 'any' )
|
||||
{
|
||||
$after = \IPS\DateTime::ts( \IPS\Request::i()->$afterKey );
|
||||
$before = \IPS\DateTime::ts( \IPS\Request::i()->$beforeKey );
|
||||
/* Javascript takes a date and turns it into a timestamp but does not apply any timezone offsetting, so we don't want to do so here or else the date we create may not be the same one the user chose. */
|
||||
$after = \IPS\DateTime::ts( \IPS\Request::i()->$afterKey, TRUE );
|
||||
$before = \IPS\DateTime::ts( \IPS\Request::i()->$beforeKey, TRUE );
|
||||
$titleConditions[] = \IPS\Member::loggedIn()->language()->addToStack( "search_blurb_date_$k", FALSE, array( 'sprintf' => array( \IPS\Member::loggedIn()->language()->addToStack( "search_blurb_date_between", FALSE, array( 'sprintf' => array( $after->localeDate(), $before->localeDate() ) ) ) ) ) );
|
||||
|
||||
$query->$method( $after, $before );
|
||||
@@ -487,6 +553,11 @@ class _search extends \IPS\Dispatcher\Controller
|
||||
$key = "{$l}Key";
|
||||
if ( isset( \IPS\Request::i()->$$key ) AND \IPS\Request::i()->$$key != 'any' )
|
||||
{
|
||||
if ( \IPS\Content\Search\Index::i()->supportViewFiltering() )
|
||||
{
|
||||
$baseUrl = $baseUrl->setQueryString( 'search_min_views', \IPS\Request::i()->search_min_views );
|
||||
}
|
||||
|
||||
switch ( \IPS\Request::i()->$$key )
|
||||
{
|
||||
case 'day':
|
||||
@@ -570,7 +641,7 @@ class _search extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
$title = \IPS\Member::loggedIn()->language()->addToStack( 'search_blurb_tag', FALSE, array( 'sprintf' => array( \IPS\Member::loggedIn()->language()->formatList( $tagList, \IPS\Member::loggedIn()->language()->get('or_list_format') ) ) ) );
|
||||
}
|
||||
if ( count( $titleConditions ) )
|
||||
if ( \count( $titleConditions ) )
|
||||
{
|
||||
$title = \IPS\Member::loggedIn()->language()->addToStack( 'search_blurb_conditions', FALSE, array( 'sprintf' => array( $title, \IPS\Member::loggedIn()->language()->addToStack( $titleType ), \IPS\Member::loggedIn()->language()->formatList( $titleConditions ) ) ) );
|
||||
}
|
||||
@@ -584,10 +655,10 @@ class _search extends \IPS\Dispatcher\Controller
|
||||
}
|
||||
|
||||
/* Set page */
|
||||
if ( isset( \IPS\Request::i()->page ) AND intval( \IPS\Request::i()->page ) > 0 )
|
||||
if ( isset( \IPS\Request::i()->page ) AND \intval( \IPS\Request::i()->page ) > 0 )
|
||||
{
|
||||
$query->setPage( intval( \IPS\Request::i()->page ) );
|
||||
$baseUrl = $baseUrl->setQueryString( 'page', intval( \IPS\Request::i()->page ) );
|
||||
$query->setPage( \intval( \IPS\Request::i()->page ) );
|
||||
$baseUrl = $baseUrl->setQueryString( 'page', \intval( \IPS\Request::i()->page ) );
|
||||
}
|
||||
|
||||
/* Set Order */
|
||||
@@ -612,7 +683,7 @@ class _search extends \IPS\Dispatcher\Controller
|
||||
$flags = ( isset( \IPS\Request::i()->eitherTermsOrTags ) and \IPS\Request::i()->eitherTermsOrTags === 'and' ) ? \IPS\Content\Search\Query::TERM_AND_TAGS : \IPS\Content\Search\Query::TERM_OR_TAGS;
|
||||
$operator = NULL;
|
||||
|
||||
if ( isset( \IPS\Request::i()->search_and_or ) and in_array( \IPS\Request::i()->search_and_or, array( \IPS\Content\Search\Query::OPERATOR_OR, \IPS\Content\Search\Query::OPERATOR_AND ) ) )
|
||||
if ( isset( \IPS\Request::i()->search_and_or ) and \in_array( \IPS\Request::i()->search_and_or, array( \IPS\Content\Search\Query::OPERATOR_OR, \IPS\Content\Search\Query::OPERATOR_AND ) ) )
|
||||
{
|
||||
$operator = \IPS\Request::i()->search_and_or;
|
||||
$baseUrl = $baseUrl->setQueryString( 'search_and_or', \IPS\Request::i()->search_and_or );
|
||||
@@ -633,7 +704,7 @@ class _search extends \IPS\Dispatcher\Controller
|
||||
);
|
||||
|
||||
/* Get pagination */
|
||||
$page = isset( \IPS\Request::i()->page ) ? intval( \IPS\Request::i()->page ) : 1;
|
||||
$page = isset( \IPS\Request::i()->page ) ? \intval( \IPS\Request::i()->page ) : 1;
|
||||
$count = $results->count( TRUE );
|
||||
$pages = ceil( $results->count( TRUE ) / $query->resultsToGet );
|
||||
|
||||
@@ -642,15 +713,27 @@ class _search extends \IPS\Dispatcher\Controller
|
||||
/* Enforce that we're on page 1 if there are no results to prevent page tampering */
|
||||
$page = 1;
|
||||
}
|
||||
else if( $count and ( $page < 1 or $page > $pages ) )
|
||||
else if( $count and $pages and ( $page < 1 or $page > $pages ) )
|
||||
{
|
||||
/* There's no point resetting the page at this point as the search query has been run and no results have been found */
|
||||
$_SESSION['lastSearch'] = 0;
|
||||
\IPS\Output::i()->redirect( $baseUrl->setQueryString( 'page', 1 ), NULL, 303 );
|
||||
\IPS\Request::i()->setCookie( 'lastSearch', 0 );
|
||||
\IPS\Output::i()->redirect( $baseUrl->setPage( 'page', 1 ), NULL, 303 );
|
||||
}
|
||||
|
||||
$pagination = trim( \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->pagination( $baseUrl, $pages, $page, $query->resultsToGet ) );
|
||||
|
||||
/* Search tracking, only if there's a term for a non-member search and we're on the first page */
|
||||
if( \IPS\Request::i()->q AND $page == 1 )
|
||||
{
|
||||
\IPS\Db::i()->insert( 'core_statistics', array(
|
||||
'type' => 'search',
|
||||
'time' => time(),
|
||||
'value_4' => \IPS\Request::i()->q,
|
||||
'value_2' => $count,
|
||||
'extra_data' => md5( \IPS\Member::loggedIn()->email . \IPS\Member::loggedIn()->joined ) // Intentionally anonymized
|
||||
) );
|
||||
}
|
||||
|
||||
/* Display results */
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
@@ -742,7 +825,7 @@ class _search extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
foreach ( $fields as $id => $field )
|
||||
{
|
||||
switch ( get_class( $field ) )
|
||||
switch ( \get_class( $field ) )
|
||||
{
|
||||
case 'IPS\Helpers\Form\Text':
|
||||
case 'IPS\Helpers\Form\Tel':
|
||||
@@ -753,6 +836,7 @@ class _search extends \IPS\Dispatcher\Controller
|
||||
case 'IPS\Helpers\Form\Date':
|
||||
case 'IPS\Helpers\Form\Number':
|
||||
case 'IPS\Helpers\Form\Select':
|
||||
case 'IPS\Helpers\Form\CheckboxSet':
|
||||
case 'IPS\Helpers\Form\Radio':
|
||||
$memberToggles[] = 'core_pfield_' . $id;
|
||||
break;
|
||||
@@ -768,7 +852,7 @@ class _search extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
$typeFieldToggles[ $k ][] = $k . '_node';
|
||||
|
||||
if( isset( $class::$databaseColumnMap['views'] ) )
|
||||
if( isset( $class::$databaseColumnMap['views'] ) and \IPS\Content\Search\Index::i()->supportViewFiltering() )
|
||||
{
|
||||
$typeFieldToggles[ $k ][] = 'search_min_views';
|
||||
}
|
||||
@@ -798,7 +882,7 @@ class _search extends \IPS\Dispatcher\Controller
|
||||
/* Term */
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'q' ), NULL, 'search_tab_all' );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'tags', \IPS\Request::i()->tags, FALSE, array( 'autocomplete' => array( 'minimized' => FALSE ) ), NULL, NULL, NULL, 'tags' ), NULL, 'search_tab_content' );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'tags', \IPS\Request::i()->tags, FALSE, array( 'autocomplete' => array( 'minimized' => FALSE, 'forceLower' => ( \IPS\Settings::i()->tags_force_lower ) ? TRUE : FALSE ) ), NULL, NULL, NULL, 'tags' ), NULL, 'search_tab_content' );
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'eitherTermsOrTags', \IPS\Request::i()->eitherTermsOrTags, FALSE, array( 'options' => array( 'or' => 'termsortags_or_desc', 'and' => 'termsortags_and_desc' ) ), NULL, NULL, NULL, 'eitherTermsOrTags' ), NULL, 'search_tab_content' );
|
||||
|
||||
/* Author */
|
||||
@@ -807,9 +891,10 @@ class _search extends \IPS\Dispatcher\Controller
|
||||
/* Club */
|
||||
if( \IPS\Settings::i()->clubs )
|
||||
{
|
||||
$clubs = \IPS\Member\Club::clubs( \IPS\Member::loggedIn(), NULL, 'name', TRUE );
|
||||
if ( is_object( $clubs ) AND $clubs->count( TRUE ) )
|
||||
if ( \IPS\Member\Club::clubs( \IPS\Member::loggedIn(), NULL, 'name', TRUE, array(), NULL, TRUE ) )
|
||||
{
|
||||
$clubs = \IPS\Member\Club::clubs( \IPS\Member::loggedIn(), NULL, 'name', TRUE );
|
||||
|
||||
$clubOptions = array();
|
||||
foreach ( $clubs as $club )
|
||||
{
|
||||
@@ -821,10 +906,10 @@ class _search extends \IPS\Dispatcher\Controller
|
||||
}
|
||||
|
||||
/* Dates */
|
||||
$form->add( new \IPS\Helpers\Form\Select( 'startDate', ( isset( \IPS\Request::i()->start_before ) or ( isset( \IPS\Request::i()->start_after ) and is_numeric( \IPS\Request::i()->start_after ) ) ) ? 'custom' : \IPS\Request::i()->start_after, FALSE, array( 'options' => $dateOptions, 'toggles' => array( 'custom' => array( 'elCustomDate_startDate' ) ) ), NULL, NULL, NULL, 'startDate' ), NULL, 'search_tab_content' );
|
||||
$form->add( new \IPS\Helpers\Form\DateRange( 'startDateCustom', array( 'start' => ( isset( \IPS\Request::i()->start_after ) and is_numeric( \IPS\Request::i()->start_after ) ) ? \IPS\DateTime::ts( \IPS\Request::i()->start_after ) : NULL, 'end' => isset( \IPS\Request::i()->start_before ) ? \IPS\DateTime::ts( \IPS\Request::i()->start_before ) : NULL ) ), NULL, 'search_tab_content' );
|
||||
$form->add( new \IPS\Helpers\Form\Select( 'updatedDate', ( isset( \IPS\Request::i()->updated_before ) or ( isset( \IPS\Request::i()->updated_after ) and is_numeric( \IPS\Request::i()->updated_after ) ) ) ? 'custom' : \IPS\Request::i()->updated_after, FALSE, array( 'options' => $dateOptions, 'toggles' => array( 'custom' => array( 'elCustomDate_updatedDate' ) ) ), NULL, NULL, NULL, 'updatedDate' ), NULL, 'search_tab_content' );
|
||||
$form->add( new \IPS\Helpers\Form\DateRange( 'updatedDateCustom', array( 'start' => ( isset( \IPS\Request::i()->updated_after ) and is_numeric( \IPS\Request::i()->updated_after ) ) ? \IPS\DateTime::ts( \IPS\Request::i()->updated_after ) : NULL, 'end' => isset( \IPS\Request::i()->updated_before ) ? \IPS\DateTime::ts( \IPS\Request::i()->updated_before ) : NULL ) ), NULL, 'search_tab_content' );
|
||||
$form->add( new \IPS\Helpers\Form\Select( 'startDate', ( isset( \IPS\Request::i()->start_before ) or ( isset( \IPS\Request::i()->start_after ) and \is_numeric( \IPS\Request::i()->start_after ) ) ) ? 'custom' : \IPS\Request::i()->start_after, FALSE, array( 'options' => $dateOptions, 'toggles' => array( 'custom' => array( 'elCustomDate_startDate' ) ) ), NULL, NULL, NULL, 'startDate' ), NULL, 'search_tab_content' );
|
||||
$form->add( new \IPS\Helpers\Form\DateRange( 'startDateCustom', array( 'start' => ( isset( \IPS\Request::i()->start_after ) and \is_numeric( \IPS\Request::i()->start_after ) ) ? \IPS\DateTime::ts( \IPS\Request::i()->start_after ) : NULL, 'end' => isset( \IPS\Request::i()->start_before ) ? \IPS\DateTime::ts( \IPS\Request::i()->start_before ) : NULL ) ), NULL, 'search_tab_content' );
|
||||
$form->add( new \IPS\Helpers\Form\Select( 'updatedDate', ( isset( \IPS\Request::i()->updated_before ) or ( isset( \IPS\Request::i()->updated_after ) and \is_numeric( \IPS\Request::i()->updated_after ) ) ) ? 'custom' : \IPS\Request::i()->updated_after, FALSE, array( 'options' => $dateOptions, 'toggles' => array( 'custom' => array( 'elCustomDate_updatedDate' ) ) ), NULL, NULL, NULL, 'updatedDate' ), NULL, 'search_tab_content' );
|
||||
$form->add( new \IPS\Helpers\Form\DateRange( 'updatedDateCustom', array( 'start' => ( isset( \IPS\Request::i()->updated_after ) and \is_numeric( \IPS\Request::i()->updated_after ) ) ? \IPS\DateTime::ts( \IPS\Request::i()->updated_after ) : NULL, 'end' => isset( \IPS\Request::i()->updated_before ) ? \IPS\DateTime::ts( \IPS\Request::i()->updated_before ) : NULL ) ), NULL, 'search_tab_content' );
|
||||
|
||||
/* Other filters */
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'search_in', \IPS\Request::i()->search_in, FALSE, array( 'options' => array( 'all' => 'titles_and_body', 'titles' => 'titles_only' ) ), NULL, NULL, NULL, 'searchIn' ), NULL, 'search_tab_content' );
|
||||
@@ -872,15 +957,18 @@ class _search extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'search_min_reviews', isset( \IPS\Request::i()->search_min_reviews ) ? \IPS\Request::i()->search_min_reviews : 0, FALSE, array(), NULL, NULL, NULL, 'search_min_reviews' ), NULL, 'search_tab_content' );
|
||||
}
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'search_min_views', isset( \IPS\Request::i()->search_min_views ) ? \IPS\Request::i()->search_min_views : 0, FALSE, array(), NULL, NULL, NULL, 'search_min_views' ), NULL, 'search_tab_content' );
|
||||
if ( \IPS\Content\Search\Index::i()->supportViewFiltering() )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'search_min_views', isset( \IPS\Request::i()->search_min_views ) ? \IPS\Request::i()->search_min_views : 0, FALSE, array(), NULL, NULL, NULL, 'search_min_views' ), NULL, 'search_tab_content' );
|
||||
}
|
||||
}
|
||||
|
||||
/* Member group and joined */
|
||||
$groups = \IPS\Member\Group::groups( TRUE, FALSE, TRUE );
|
||||
|
||||
$form->add(new \IPS\Helpers\Form\CheckboxSet('group', ( isset( \IPS\Request::i()->group ) ) ? is_array( \IPS\Request::i()->group) ? array_keys( \IPS\Request::i()->group) : array( \IPS\Request::i()->group ) : array_keys( $groups ), FALSE, array('options' => $groups, 'parse' => 'normal'), NULL, NULL, NULL, 'core_members_group'), NULL, 'search_tab_member' );
|
||||
$form->add(new \IPS\Helpers\Form\Select('joinedDate', (isset(\IPS\Request::i()->start_before) or (isset(\IPS\Request::i()->start_after) and is_numeric(\IPS\Request::i()->start_after))) ? 'custom' : \IPS\Request::i()->start_after, FALSE, array('options' => $dateOptions, 'toggles' => array('custom' => array('elCustomDate_joinedDate'))), NULL, NULL, NULL, 'joinedDate'), NULL, 'search_tab_member' );
|
||||
$form->add(new \IPS\Helpers\Form\DateRange('joinedDateCustom', array('start' => (isset(\IPS\Request::i()->start_after) and is_numeric(\IPS\Request::i()->start_after)) ? \IPS\DateTime::ts(\IPS\Request::i()->start_after) : NULL, 'end' => isset(\IPS\Request::i()->start_before) ? \IPS\DateTime::ts(\IPS\Request::i()->start_before) : NULL)), NULL, 'search_tab_member' );
|
||||
$form->add(new \IPS\Helpers\Form\CheckboxSet('group', ( isset( \IPS\Request::i()->group ) ) ? \is_array( \IPS\Request::i()->group) ? array_keys( \IPS\Request::i()->group) : array( \IPS\Request::i()->group ) : array_keys( $groups ), FALSE, array('options' => $groups, 'parse' => 'normal'), NULL, NULL, NULL, 'core_members_group'), NULL, 'search_tab_member' );
|
||||
$form->add(new \IPS\Helpers\Form\Select('joinedDate', (isset(\IPS\Request::i()->start_before) or (isset(\IPS\Request::i()->start_after) and \is_numeric(\IPS\Request::i()->start_after))) ? 'custom' : \IPS\Request::i()->start_after, FALSE, array('options' => $dateOptions, 'toggles' => array('custom' => array('elCustomDate_joinedDate'))), NULL, NULL, NULL, 'joinedDate'), NULL, 'search_tab_member' );
|
||||
$form->add(new \IPS\Helpers\Form\DateRange('joinedDateCustom', array('start' => (isset(\IPS\Request::i()->start_after) and \is_numeric(\IPS\Request::i()->start_after)) ? \IPS\DateTime::ts(\IPS\Request::i()->start_after) : NULL, 'end' => isset(\IPS\Request::i()->start_before) ? \IPS\DateTime::ts(\IPS\Request::i()->start_before) : NULL)), NULL, 'search_tab_member' );
|
||||
|
||||
/* Profile fields for member searches */
|
||||
$memberFields = array();
|
||||
@@ -895,7 +983,7 @@ class _search extends \IPS\Dispatcher\Controller
|
||||
$realLangKey = "core_pfield_{$id}";
|
||||
|
||||
/* Work out the object type so we can show the appropriate field */
|
||||
$type = get_class( $field );
|
||||
$type = \get_class( $field );
|
||||
$helper = NULL;
|
||||
|
||||
switch ( $type )
|
||||
@@ -918,13 +1006,14 @@ class _search extends \IPS\Dispatcher\Controller
|
||||
$memberFields[] = 'core_pfield_' . $id;
|
||||
break;
|
||||
case 'IPS\Helpers\Form\Select':
|
||||
case 'IPS\Helpers\Form\CheckboxSet':
|
||||
case 'IPS\Helpers\Form\Radio':
|
||||
$options = array( '' => "" );
|
||||
if( count( $field->options['options'] ) )
|
||||
if( \count( $field->options['options'] ) )
|
||||
{
|
||||
foreach ($field->options['options'] as $option)
|
||||
foreach ($field->options['options'] as $optionKey => $option )
|
||||
{
|
||||
$options[$option] = $option;
|
||||
$options[ $type === 'IPS\Helpers\Form\CheckboxSet' ? $optionKey : $option ] = $option;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -939,7 +1028,7 @@ class _search extends \IPS\Dispatcher\Controller
|
||||
}
|
||||
}
|
||||
|
||||
if( count( $fieldsToAdd ) )
|
||||
if( \count( $fieldsToAdd ) )
|
||||
{
|
||||
foreach( $fieldsToAdd as $field )
|
||||
{
|
||||
@@ -988,7 +1077,7 @@ class _search extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
$url = $url->setQueryString( 'reviews', $values['search_min_reviews'] );
|
||||
}
|
||||
if ( isset( $values['search_min_views'] ) and $values['search_min_views'] )
|
||||
if ( isset( $values['search_min_views'] ) and $values['search_min_views'] and \IPS\Content\Search\Index::i()->supportViewFiltering() )
|
||||
{
|
||||
$url = $url->setQueryString( 'views', $values['search_min_views'] );
|
||||
}
|
||||
@@ -1077,6 +1166,7 @@ class _search extends \IPS\Dispatcher\Controller
|
||||
if ( \IPS\Request::i()->q )
|
||||
{
|
||||
$query['q'] = \IPS\Request::i()->q;
|
||||
$query['quick'] = 1;
|
||||
|
||||
if ( \IPS\Request::i()->type != 'all' )
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user