Version 5.0.0 beta 1

This commit is contained in:
Neo committed 2025-12-19 16:27:35 -08:00
1 parent 25ddeb65d6
commit 15c7beabc5
6736 files changed
+627902 -497943

No files matched your search

+54 -24
View File
@@ -11,46 +11,67 @@
namespace IPS\Content\Search\Result;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use Exception;
use IPS\Content\Comment;
use IPS\Content\Search\Result;
use IPS\Content\Search\SearchContent;
use IPS\DateTime;
use IPS\File;
use IPS\Xml\Rss;
use OutOfRangeException;
use function defined;
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Search Result
*/
class _Content extends \IPS\Content\Search\Result
class Content extends Result
{
/**
* Index Data
*/
protected $indexData;
protected array $indexData;
/**
* Author Data
*/
protected $authorData;
protected array $authorData;
/**
* Item Data
*/
protected $itemData;
protected array $itemData;
/**
* Author Data
*/
protected $containerData;
protected array|null $containerData;
/**
* Reputation Data
*/
protected array|null $reputationData;
/**
* Review Rating
*/
protected $reviewRating;
protected int|null $reviewRating;
/**
* If the user has posted in the item
*/
protected $iPostedIn;
protected mixed $iPostedIn = array();
/**
* Reactions
*/
protected array $reactions;
/**
* Constructor
@@ -65,10 +86,10 @@ class _Content extends \IPS\Content\Search\Result
* @param array $reactions Reaction Data
* @return void
*/
public function __construct( array $indexData, array $authorData, array $itemData, ?array $containerData, array $reputationData, $reviewRating = NULL, $iPostedIn = FALSE, $reactions=array() )
public function __construct( array $indexData, array $authorData, array $itemData, array|null $containerData, array $reputationData, int|null $reviewRating = NULL, bool $iPostedIn = FALSE, array $reactions=array() )
{
$this->createdDate = \IPS\DateTime::ts( $indexData['index_date_created'] );
$this->lastUpdatedDate = \IPS\DateTime::ts( $indexData['index_date_updated'] );
$this->createdDate = DateTime::ts( $indexData['index_date_created'] );
$this->lastUpdatedDate = DateTime::ts( $indexData['index_date_updated'] );
$this->indexData = $indexData;
$this->authorData = $authorData;
$this->itemData = $itemData;
@@ -88,10 +109,14 @@ class _Content extends \IPS\Content\Search\Result
* @param array|NULL $template Optional custom template
* @return string
*/
public function html( $view = 'expanded', $asItem = FALSE, $canIgnoreComments=FALSE, $template=NULL )
public function html( string $view = 'expanded', bool $asItem = FALSE, bool $canIgnoreComments=FALSE, array|null $template=NULL ): string
{
$searchResultTemplate = array( $this->indexData['index_class'], 'searchResult' );
return $searchResultTemplate( $this->indexData, $this->authorData, $this->itemData, $this->containerData, $this->reputationData, $this->reviewRating, $this->iPostedIn, $view, $asItem, $canIgnoreComments, $template, $this->reactions );
if( $extension = SearchContent::extension( $this->indexData['index_class'] ) )
{
$searchResultTemplate = array( $extension, 'searchResult' );
return $searchResultTemplate( $this->indexData, $this->authorData, $this->itemData, $this->containerData, $this->reputationData, $this->reviewRating, $this->iPostedIn, $view, $asItem, $canIgnoreComments, $template, $this->reactions );
}
return "";
}
/**
@@ -99,8 +124,10 @@ class _Content extends \IPS\Content\Search\Result
*
* @return array( 'indexData' => array() ... )
*/
public function asArray()
public function asArray(): array
{
$extension = SearchContent::extension( $this->indexData['index_class'] );
return array(
'indexData' => $this->indexData,
'authorData' => $this->authorData,
@@ -108,17 +135,20 @@ class _Content extends \IPS\Content\Search\Result
'containerData' => $this->containerData,
'reputationData' => $this->reputationData,
'reviewRating' => $this->reviewRating,
'iPostedIn' => $this->iPostedIn
'iPostedIn' => $this->iPostedIn,
'template' => $extension ? $extension::searchResultBlock() : null,
'url' => $extension ? $extension::urlFromIndexData( $this->indexData, $this->itemData ) : null,
'searchResultClassName' => $extension ? $extension::$searchResultClassName : ''
);
}
/**
* Add to RSS feed
*
* @param \IPS\Xml\Rss $document Document to add to
* @return string
* @param Rss $document Document to add to
* @return void
*/
public function addToRssFeed( \IPS\Xml\Rss $document )
public function addToRssFeed( Rss $document ): void
{
try
{
@@ -133,14 +163,14 @@ class _Content extends \IPS\Content\Search\Result
try
{
$enclosure = \IPS\File::get( $key, $data[ $key ] );
$enclosure = File::get( $key, $data[ $key ] );
}
catch( \Exception $ex ) { }
catch( Exception ) { }
}
$document->addItem( $object instanceof \IPS\Content\Comment ? $object->item()->searchIndexTitle() : $object->searchIndexTitle(), $object->url(), \IPS\Content\Search\Result::preDisplay( $this->indexData['index_content'] ), \IPS\DateTime::ts( $this->indexData['index_date_created'] ), NULL, $enclosure );
$document->addItem( $object instanceof Comment ? $object->item()->mapped( 'title' ) : $object->mapped( 'title' ), $object->url(), Result::preDisplay( $this->indexData['index_content'] ), DateTime::ts( $this->indexData['index_date_created'] ), NULL, $enclosure );
}
/* If the search result was orphaned, let us continue */
catch( \OutOfRangeException $e ){}
catch( OutOfRangeException ){}
}
}
+18 -12
View File
@@ -11,42 +11,48 @@
namespace IPS\Content\Search\Result;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Content\Search\Result;
use IPS\DateTime;
use IPS\Theme;
use function defined;
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Search Result not from Index
*/
class _Custom extends \IPS\Content\Search\Result
class Custom extends Result
{
/**
* @brief HTML
*/
protected $html;
protected string $html;
/**
* @brief Image
*/
protected $image;
protected string|null $image;
/**
* @brief Data used for merging multiple extra items
*/
protected $mergeData;
protected array $mergeData;
/**
* Constructor
*
* @param \IPS\DateTime $time The time for this result
* @param DateTime $time The time for this result
* @param string $html HTML to display
* @param string|NULL $image HTML for image to display
* @param string|NULL $mergeData Data for merging
* @return void
*/
public function __construct( \IPS\DateTime $time, $html, $image = NULL, $mergeData = NULL )
public function __construct( DateTime $time, string $html, string|null $image = NULL, string|null $mergeData = NULL )
{
$this->createdDate = $time;
$this->lastUpdatedDate = $time;
@@ -62,7 +68,7 @@ class _Custom extends \IPS\Content\Search\Result
* @param string|NULL $mergeData Data for merging
* @return void
*/
public function mergeInData( $html, $mergeData = NULL )
public function mergeInData( string $html, string|null $mergeData = NULL ): void
{
$this->html = $html;
$this->mergeData[] = $mergeData;
@@ -73,7 +79,7 @@ class _Custom extends \IPS\Content\Search\Result
*
* @return array
*/
public function getMergeData()
public function getMergeData(): array
{
return $this->mergeData ?: array();
}
@@ -84,8 +90,8 @@ class _Custom extends \IPS\Content\Search\Result
* @param string $view The view to use (expanded or condensed)
* @return string
*/
public function html( $view = 'expanded' )
public function html( string $view = 'expanded' ): string
{
return \IPS\Theme::i()->getTemplate( 'streams', 'core' )->extraItem( $this->createdDate, $this->image, $this->html, $view );
return Theme::i()->getTemplate( 'streams', 'core' )->extraItem( $this->createdDate, $this->image, $this->html, $view );
}
}
+25 -14
View File
@@ -11,16 +11,25 @@
namespace IPS\Content\Search;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use DateInterval;
use IPS\DateTime;
use IPS\Member;
use IPS\Settings;
use IPS\Text\Parser;
use function defined;
use function preg_replace;
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Search Result
*/
abstract class _Result
abstract class Result
{
/**
* Pre-Display logic for search index content
@@ -28,7 +37,7 @@ abstract class _Result
* @param string $content The search result content
* @return string
*/
public static function preDisplay( $content )
public static function preDisplay( string $content ): string
{
/* We cannot use images (or *anything* other than text) in search results as it messes with the truncation
logic. All HTML (including emoticons) are already stripped before they go into the search index
@@ -36,23 +45,24 @@ abstract class _Result
with one of the alternative Emoji style images though because that re-introduces images, so we
just strip them out (making them behave like emoticons) */
if ( \IPS\Settings::i()->emoji_style == 'twemoji' )
if ( Settings::i()->emoji_style == 'twemoji' )
{
$content = preg_replace( '/(?:' . \IPS\Text\Parser::EMOJI_REGEX . '|\x{200d})+/u', '', $content );
$content = preg_replace( '/(?:' . Parser::getEmojiRegex() . '|\x{200d})+/u', '', $content );
}
return $content;
/* We need to strip the image labels as returned by the AI image scanner */
return preg_replace('#<i\s+?l="([^<]+?)</i>#', '', $content);
}
/**
* @brief Created Date
*/
public $createdDate;
public DateTime $createdDate;
/**
* @brief Last Updated Date
*/
public $lastUpdatedDate;
public DateTime $lastUpdatedDate;
/**
* Separator for activity streams - "past hour", "today", etc.
@@ -60,13 +70,13 @@ abstract class _Result
* @param bool $createdDate If TRUE, uses $createdDate, otherwise uses $lastUpdatedDate
* @return string
*/
public function streamSeparator( $createdDate=TRUE )
public function streamSeparator( bool $createdDate=TRUE ): string
{
$date = $createdDate ? $this->createdDate : $this->lastUpdatedDate;
$now = \IPS\DateTime::ts( time() );
$now = DateTime::ts( time() );
$yesterday = clone $now;
$yesterday = $yesterday->sub( new \DateInterval('P1D') );
$yesterday = $yesterday->sub( new DateInterval('P1D') );
$diff = $date->diff( $now );
if ( $date->format('Y-m-d') == $yesterday->format('Y-m-d') )
@@ -94,7 +104,7 @@ abstract class _Result
/**
* Get output for API
*
* @param \IPS\Member|NULL $authorizedMember The member making the API request or NULL for API Key / client_credentials
* @param Member|NULL $authorizedMember The member making the API request or NULL for API Key / client_credentials
* @return array
* @apiresponse string title Title of search result
* @apiresponse string content Content of search result
@@ -117,8 +127,9 @@ abstract class _Result
* @apiresponse string authorPhotoThumbnail URL to author's profile photo thumbnail
* @apiresponse array tags Array of tags associated with the search result
*/
public function apiOutput( \IPS\Member $authorizedMember = NULL )
public function apiOutput( Member|null $authorizedMember = NULL ): array
{
/* @note This is only here to populate the AdminCP reference tab - the array of search result entries is built manually */
return [];
}
}