Version 4.1.19
This commit is contained in:
1 parent
28bd025b35
commit
2bd5025018
2674 files changed
+233518
-77766
No files matched your search
+114
-24
@@ -2,9 +2,9 @@
|
||||
/**
|
||||
* @brief Abstract Search Index
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @package IPS Community Suite
|
||||
* @since 21 Aug 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
@@ -81,8 +81,9 @@ abstract class _Index extends \IPS\Patterns\Singleton
|
||||
/* Init */
|
||||
$class = get_class( $object );
|
||||
$idColumn = $class::$databaseColumnId;
|
||||
$tags = ( $object instanceof \IPS\Content\Tags ) ? implode( ',', array_filter( array_merge( array( $object->prefix() ), $object->tags() ) ) ) : NULL;
|
||||
|
||||
$tags = ( $object instanceof \IPS\Content\Tags and \IPS\Settings::i()->tags_enabled ) ? implode( ',', array_filter( $object->tags() ) ) : NULL;
|
||||
$prefix = ( $object instanceof \IPS\Content\Tags and \IPS\Settings::i()->tags_enabled ) ? $object->prefix() : NULL;
|
||||
|
||||
/* If this is an item where the first comment is required, don't index because the comment will serve as both */
|
||||
if ( $object instanceof \IPS\Content\Item and $class::$firstCommentRequired )
|
||||
{
|
||||
@@ -104,7 +105,8 @@ abstract class _Index extends \IPS\Patterns\Singleton
|
||||
if ( $itemClass::$firstCommentRequired and $object->isFirst() )
|
||||
{
|
||||
$title = $object->item()->mapped('title');
|
||||
$tags = ( $object->item() instanceof \IPS\Content\Tags ) ? implode( ',', array_filter( array_merge( array( $object->item()->prefix() ), $object->item()->tags() ) ) ) : NULL;
|
||||
$tags = ( $object->item() instanceof \IPS\Content\Tags and \IPS\Settings::i()->tags_enabled ) ? implode( ',', array_filter( $object->item()->tags() ) ) : NULL;
|
||||
$prefix = ( $object->item() instanceof \IPS\Content\Tags and \IPS\Settings::i()->tags_enabled ) ? $object->item()->prefix() : NULL;
|
||||
$isForItem = TRUE;
|
||||
}
|
||||
}
|
||||
@@ -116,14 +118,23 @@ abstract class _Index extends \IPS\Patterns\Singleton
|
||||
}
|
||||
else
|
||||
{
|
||||
$dateUpdated = ( $object instanceof \IPS\Content\Item ) ? $object->mapped('last_comment') : $object->mapped('edit_time');
|
||||
$dateUpdated = ( $object instanceof \IPS\Content\Item ) ? $object->mapped('last_comment') : $object->mapped('date');
|
||||
}
|
||||
|
||||
/* Is the the latest content? */
|
||||
$isLastComment = 0;
|
||||
if ( $object instanceof \IPS\Content\Comment )
|
||||
{
|
||||
$item = $object->item();
|
||||
try
|
||||
{
|
||||
$item = $object->item();
|
||||
}
|
||||
catch( \OutOfRangeException $ex )
|
||||
{
|
||||
/* Comment has no parent item, return */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$latestThing = 0;
|
||||
foreach ( array( 'updated', 'last_comment', 'last_review' ) as $k )
|
||||
{
|
||||
@@ -137,16 +148,55 @@ abstract class _Index extends \IPS\Patterns\Singleton
|
||||
{
|
||||
$isLastComment = 1;
|
||||
}
|
||||
|
||||
/* If we are re-indexing the first post of an item, which is triggered by a comment being added to a $itemClass::$firstCommentRequired,
|
||||
then ensure that the isLastComment flag is not added as we index the comment first, which means the index_is_last_comment is incorrectly reset to 0 for the comment itself */
|
||||
if ( $isForItem and $isLastComment )
|
||||
{
|
||||
if ( isset( $item::$databaseColumnMap['num_comments'] ) and $item->mapped('num_comments') > 1 )
|
||||
{
|
||||
$isLastComment = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ( $object instanceof \IPS\Content\Item and ! $class::$firstCommentRequired )
|
||||
{
|
||||
/* If this is item itself and not a comment, then we will store it as the last comment so the activity stream fetches the data correctly */
|
||||
$isLastComment = 1;
|
||||
|
||||
if ( isset( $class::$databaseColumnMap['num_comments'] ) and $object->mapped('num_comments') )
|
||||
{
|
||||
$isLastComment = 0;
|
||||
}
|
||||
else if ( isset( $class::$databaseColumnMap['num_reviews'] ) and $object->mapped('num_reviews') )
|
||||
{
|
||||
$isLastComment = 0;
|
||||
}
|
||||
|
||||
/* Is the item itself searchable but the comment not? */
|
||||
$commentClass = $object::$commentClass;
|
||||
if ( ! ( is_subclass_of( $commentClass, 'IPS\Content\Searchable' ) ) )
|
||||
{
|
||||
/* Then make this the last comment so it remains searchable */
|
||||
$isLastComment = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Take the HTML out of the content */
|
||||
$content = trim( strip_tags( preg_replace( "/(<br(?: \/)?>|<\/p>)/i", ' ', preg_replace( "#<blockquote(.*?)>(.*)</blockquote>#uis", "", preg_replace( "#<script(.*?)>(.*)</script>#uis", "", ' ' . $object->mapped('content') . ' ' ) ) ) ) );
|
||||
|
||||
/* Strip spoilers */
|
||||
$content = $object->mapped('content');
|
||||
if ( preg_match( '#<div\s+?class=["\']ipsSpoiler["\']#', $content ) )
|
||||
{
|
||||
$content = \IPS\Text\Parser::removeElements( $content, array( 'div[class=ipsSpoiler]' ) );
|
||||
}
|
||||
|
||||
/* Take the HTML out of the content */
|
||||
$content = trim( str_replace( chr(0xC2) . chr(0xA0), ' ', strip_tags( preg_replace( "/(<br(?: \/)?>|<\/p>)/i", ' ', preg_replace( "#<blockquote(?:[^>]+?)>.+?(?<!<blockquote)</blockquote>#s", " ", preg_replace( "#<script(.*?)>(.*)</script>#uis", "", ' ' . $content . ' ' ) ) ) ) ) );
|
||||
|
||||
/* Work out the hidden status */
|
||||
$hiddenStatus = $object->hidden();
|
||||
if ( $hiddenStatus === 0 and method_exists( $object, 'item' ) and $object->item()->hidden() )
|
||||
{
|
||||
$hiddenStatus = $isForItem ? 1 : 2;
|
||||
$hiddenStatus = $isForItem ? $object->item()->hidden() : 2;
|
||||
}
|
||||
if ( $hiddenStatus !== 0 and method_exists( $object, 'item' ) and $object->item()->isFutureDate() )
|
||||
{
|
||||
@@ -162,16 +212,45 @@ abstract class _Index extends \IPS\Patterns\Singleton
|
||||
{
|
||||
try
|
||||
{
|
||||
$itemIndexId = $this->getIndexId( $object::load( $object->item()->mapped('first_comment_id') ) );
|
||||
$itemIndexId = $this->getIndexId( $object->item()->firstComment() );
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
}
|
||||
else
|
||||
{
|
||||
$itemIndexId = $this->getIndexId( $object->item() );
|
||||
try
|
||||
{
|
||||
$itemIndexId = $this->getIndexId( $object->item() );
|
||||
}
|
||||
catch ( \UnderflowException $e )
|
||||
{
|
||||
try
|
||||
{
|
||||
/* Try and index parent */
|
||||
\IPS\Content\Search\Index::i()->index( $object->item() );
|
||||
$itemIndexId = $this->getIndexId( $object->item() );
|
||||
}
|
||||
catch( \Exception $ex )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else if ( $object instanceof \IPS\Content\Item )
|
||||
{
|
||||
if ( ! $object::$firstCommentRequired )
|
||||
{
|
||||
/* See if this has already been indexed */
|
||||
try
|
||||
{
|
||||
/* Good, we need the index_item_index_id so this is not wiped on re-index */
|
||||
$itemIndexId = $this->getIndexId( $object );
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
}
|
||||
}
|
||||
|
||||
/* Return */
|
||||
return array(
|
||||
'index_class' => $class,
|
||||
@@ -185,6 +264,7 @@ abstract class _Index extends \IPS\Patterns\Singleton
|
||||
'index_date_updated' => intval( $dateUpdated ?: $object->mapped('date') ),
|
||||
'index_author' => (int) $object->mapped('author'),
|
||||
'index_tags' => $tags,
|
||||
'index_prefix' => $prefix,
|
||||
'index_hidden' => $hiddenStatus,
|
||||
'index_item_index_id' => $itemIndexId,
|
||||
'index_item_author' => intval( ( $object instanceof \IPS\Content\Item ) ? $object->mapped('author') : $object->item()->mapped('author') ),
|
||||
@@ -266,18 +346,19 @@ abstract class _Index extends \IPS\Patterns\Singleton
|
||||
/**
|
||||
* Mass Update (when permissions change, for example)
|
||||
*
|
||||
* @param string $class The class
|
||||
* @param int|NULL $containerId The container ID to update, or NULL
|
||||
* @param int|NULL $itemId The item ID to update, or NULL
|
||||
* @param string|NULL $newPermissions New permissions (if applicable)
|
||||
* @param int|NULL $newHiddenStatus New hidden status (if applicable) special value 2 can be used to indicate hidden only by parent
|
||||
* @param int|NULL $newContainer New container ID (if applicable)
|
||||
* @param int|NULL $authorId The author ID to update, or NULL
|
||||
* @param int|NULL $newItemId The new item ID (if applicable)
|
||||
* @param int|NULL $$newItemAuthorId The new item author ID (if applicable)
|
||||
* @param string $class The class
|
||||
* @param int|NULL $containerId The container ID to update, or NULL
|
||||
* @param int|NULL $itemId The item ID to update, or NULL
|
||||
* @param string|NULL $newPermissions New permissions (if applicable)
|
||||
* @param int|NULL $newHiddenStatus New hidden status (if applicable) special value 2 can be used to indicate hidden only by parent
|
||||
* @param int|NULL $newContainer New container ID (if applicable)
|
||||
* @param int|NULL $authorId The author ID to update, or NULL
|
||||
* @param int|NULL $newItemId The new item ID (if applicable)
|
||||
* @param int|NULL $newItemAuthorId The new item author ID (if applicable)
|
||||
* @param bool $addAuthorToPermissions If true, the index_author_id will be added to $newPermissions - used when changing the permissions for a node which allows access only to author's items
|
||||
* @return void
|
||||
*/
|
||||
abstract public function massUpdate( $class, $containerId = NULL, $itemId = NULL, $newPermissions = NULL, $newHiddenStatus = NULL, $newContainer = NULL, $authorId = NULL, $newItemId = NULL, $newItemAuthorId = NULL );
|
||||
abstract public function massUpdate( $class, $containerId = NULL, $itemId = NULL, $newPermissions = NULL, $newHiddenStatus = NULL, $newContainer = NULL, $authorId = NULL, $newItemId = NULL, $newItemAuthorId = NULL, $addAuthorToPermissions = FALSE );
|
||||
|
||||
/**
|
||||
* Update data for the first and last comment after a merge
|
||||
@@ -295,4 +376,13 @@ abstract class _Index extends \IPS\Patterns\Singleton
|
||||
* @return void
|
||||
*/
|
||||
abstract public function prune( \IPS\DateTime $cutoff = NULL );
|
||||
|
||||
/**
|
||||
* Reset the last comment flag in any given class/index_item_id
|
||||
*
|
||||
* @param string $class The class
|
||||
* @param int|NULL $indexItemId The index item ID
|
||||
* @return void
|
||||
*/
|
||||
abstract public function resetLastComment( $class, $indexItemId );
|
||||
}
|
||||
Reference in new issue
Block a user