Version 4.6.0
This commit is contained in:
1 parent
f79dcf067a
commit
517a5e1f70
2036 files changed
+110041
-26162
No files matched your search
@@ -22,13 +22,36 @@ if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
*/
|
||||
class _search extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* @brief Amount of time to cache search result in browser/CDN
|
||||
*/
|
||||
protected $_cacheTimeout = 30 * 60;
|
||||
|
||||
/**
|
||||
* Check if this was a cached result we should just return a 304 against
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _checkCached()
|
||||
{
|
||||
/* Check whether a 304 Not modified response is appropriate */
|
||||
if( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) AND ( new \IPS\DateTime( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) )->getTimestamp() > ( time() - $this->_cacheTimeout ) )
|
||||
{
|
||||
header('HTTP/1.1 304 Not Modified' );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Search Form
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
{
|
||||
{
|
||||
/* Make sure this isn't a cached result we should just honor */
|
||||
$this->_checkCached();
|
||||
|
||||
/* Init stuff for the output */
|
||||
\IPS\Output::i()->sidebar['enabled'] = FALSE;
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'styles/streams.css' ) );
|
||||
@@ -392,7 +415,7 @@ class _search extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
try
|
||||
{
|
||||
$item = $class::loadAndCheckPerms( \IPS\Request::i()->item );
|
||||
$item = $class::loadAndCheckPerms( (int) \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 ) );
|
||||
$titleConditions[] = \IPS\Member::loggedIn()->language()->addToStack( 'search_blurb_in', FALSE, array( 'sprintf' => array( $item->mapped('title') ) ) );
|
||||
@@ -725,13 +748,26 @@ class _search extends \IPS\Dispatcher\Controller
|
||||
/* 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
|
||||
) );
|
||||
try
|
||||
{
|
||||
\IPS\Db::i()->insert( 'core_statistics', array(
|
||||
'type' => 'search',
|
||||
'time' => time(),
|
||||
'value_4' => mb_substr( \IPS\Request::i()->q, 0, 255 ), // Some search queries can be unnecessarily long
|
||||
'value_2' => $count,
|
||||
'extra_data' => md5( \IPS\Member::loggedIn()->email . \IPS\Member::loggedIn()->joined ) // Intentionally anonymized
|
||||
) );
|
||||
}
|
||||
catch( \IPS\Db\Exception $e ) {}
|
||||
}
|
||||
|
||||
/* Enable caching for the search results request */
|
||||
if ( !\IPS\Member::loggedIn()->member_id )
|
||||
{
|
||||
$httpHeaders = array( 'Expires' => \IPS\DateTime::create()->add( new \DateInterval( 'PT3M' ) )->rfc1123(),
|
||||
'Cache-Control' => "max-age=" . $this->_cacheTimeout . ", s-maxage=" . $this->_cacheTimeout . ", public, stale-if-error, stale-while-revalidate" );
|
||||
|
||||
\IPS\Output::i()->httpHeaders += $httpHeaders;
|
||||
}
|
||||
|
||||
/* Display results */
|
||||
@@ -747,11 +783,6 @@ class _search extends \IPS\Dispatcher\Controller
|
||||
}
|
||||
else
|
||||
{
|
||||
$httpHeaders = array( 'Expires' => \IPS\DateTime::create()->add( new \DateInterval( 'PT3M' ) )->rfc1123() ,
|
||||
'Cache-Control' => "max-age=" . 30 * 60 . ", private" );
|
||||
|
||||
\IPS\Output::i()->httpHeaders += $httpHeaders;
|
||||
|
||||
\IPS\Output::i()->title = $title;
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'search' )->search( $this->_splitTermsForDisplay(), $title, $results, $pagination, $baseUrl, $types, $this->_form()->customTemplate( array( \IPS\Theme::i()->getTemplate( 'search' ), 'filters' ), $baseUrl, $count ), $count );
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user