Version 4.7.0
This commit is contained in:
1 parent
517a5e1f70
commit
8ba7d43898
1933 files changed
+65613
-11332
No files matched your search
@@ -476,6 +476,12 @@ class _Stream extends \IPS\Node\Model
|
||||
'unread' => 'stream_read_unread',
|
||||
) ) ) );
|
||||
|
||||
/* Solved */
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'stream_solved', $this->solved, TRUE, array( 'options' => array(
|
||||
'all' => 'stream_solved_all',
|
||||
'solved' => 'stream_solved_solved',
|
||||
'unsolved' => 'stream_solved_unsolved',
|
||||
) ) ) );
|
||||
|
||||
/* Follow */
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'stream_follow', $this->follow, TRUE, array(
|
||||
@@ -940,6 +946,15 @@ class _Stream extends \IPS\Node\Model
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if ( $this->solved == 'unsolved' )
|
||||
{
|
||||
$terms[] = \IPS\Member::loggedIn()->language()->addToStack('stream_blurb_unsolved');
|
||||
}
|
||||
else if ( $this->solved =='solved')
|
||||
{
|
||||
$terms[] = \IPS\Member::loggedIn()->language()->addToStack('stream_blurb_solved');
|
||||
}
|
||||
|
||||
if ( \count( $terms ) )
|
||||
{
|
||||
@@ -971,6 +986,7 @@ class _Stream extends \IPS\Node\Model
|
||||
'stream_ownership' => $this->ownership,
|
||||
'stream_date_type' => $this->date_type,
|
||||
'stream_classes' => NULL,
|
||||
'stream_solved' => $this->solved,
|
||||
'containers' => static::containersToUrl( $this->containers ),
|
||||
);
|
||||
|
||||
@@ -1105,6 +1121,9 @@ class _Stream extends \IPS\Node\Model
|
||||
{
|
||||
/* Init */
|
||||
$query = \IPS\Content\Search\Query::init( $member );
|
||||
|
||||
/* Get Member */
|
||||
$member = $member ?: \IPS\Member::loggedIn();
|
||||
|
||||
/* Content Filters */
|
||||
$filters = array();
|
||||
@@ -1130,15 +1149,16 @@ class _Stream extends \IPS\Node\Model
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Build the filters */
|
||||
foreach ( $classes as $class => $options )
|
||||
{
|
||||
/* Init */
|
||||
if ( ! $this->include_comments or ( isset( $options['items'] ) and !isset( $options['comments'] ) and \in_array( 'IPS\Content\Item', class_parents( $class ) ) and $class::$firstCommentRequired ) )
|
||||
{
|
||||
/* items with no comments are flagged as being the last comment */
|
||||
$filter = \IPS\Content\Search\ContentFilter::init( $class, TRUE, TRUE, TRUE )->onlyLastComment();
|
||||
/* As we do not want comments to appear separately, we want to only show the content item if no comments
|
||||
or the last comment of the content item */
|
||||
$filter= \IPS\Content\Search\ContentFilter::init( $class, TRUE, TRUE, TRUE )->onlyLastComment();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1166,6 +1186,8 @@ class _Stream extends \IPS\Node\Model
|
||||
{
|
||||
if( !$this->include_comments )
|
||||
{
|
||||
/* As we do not want comments to appear separately, we want to only show the content item if no comments
|
||||
or the last comment of the content item */
|
||||
$filters[] = \IPS\Content\Search\ContentFilter::init( $class, TRUE, TRUE, TRUE )->onlyLastComment();
|
||||
}
|
||||
|
||||
@@ -1200,7 +1222,7 @@ class _Stream extends \IPS\Node\Model
|
||||
switch ( $this->ownership )
|
||||
{
|
||||
case 'started':
|
||||
$query->filterByItemAuthor( \IPS\Member::loggedIn() );
|
||||
$query->filterByItemAuthor( $member );
|
||||
break;
|
||||
|
||||
case 'postedin':
|
||||
@@ -1232,7 +1254,7 @@ class _Stream extends \IPS\Node\Model
|
||||
switch ( $this->date_type )
|
||||
{
|
||||
case 'last_visit':
|
||||
$query->$filterDateMethod( \IPS\DateTime::ts( \IPS\Member::loggedIn()->last_visit ) );
|
||||
$query->$filterDateMethod( \IPS\DateTime::ts( $member->last_visit ) );
|
||||
break;
|
||||
case 'relative':
|
||||
if ( \is_array( $this->date_relative_days ) )
|
||||
@@ -1247,6 +1269,16 @@ class _Stream extends \IPS\Node\Model
|
||||
$query->$filterDateMethod( $this->date_start ? \IPS\DateTime::ts( $this->date_start ) : NULL, $this->date_end ? \IPS\DateTime::ts( $this->date_end ) : NULL );
|
||||
break;
|
||||
}
|
||||
|
||||
/* Solved */
|
||||
if ( $this->solved == 'unsolved' )
|
||||
{
|
||||
$query->filterByUnsolved();
|
||||
}
|
||||
else if( $this->solved == 'solved' )
|
||||
{
|
||||
$query->filterBySolved();
|
||||
}
|
||||
|
||||
/* Sort */
|
||||
if ( $this->include_comments )
|
||||
@@ -1315,6 +1347,9 @@ class _Stream extends \IPS\Node\Model
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
/* Delete Subscriptions */
|
||||
\IPS\Db::i()->delete( 'core_stream_subscriptions', ['stream_id=?', $this->id ] );
|
||||
|
||||
if ( $this->member )
|
||||
{
|
||||
parent::delete();
|
||||
@@ -1345,4 +1380,80 @@ class _Stream extends \IPS\Node\Model
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Can the member subscribe to this stream?
|
||||
*
|
||||
* @param \IPS\Member|null $member
|
||||
* @return bool
|
||||
*/
|
||||
public function canSubscribe( \IPS\Member $member = NULL ) : bool
|
||||
{
|
||||
if( !\IPS\Settings::i()->activity_stream_subscriptions )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if( !$this->id )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$member = $member ?: \IPS\Member::loggedIn();
|
||||
|
||||
if( !$member->member_id )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ( \IPS\Db::i()->select( 'COUNT(*)', 'core_stream_subscriptions', array( 'member_id=?', $member->member_id ) )->first() >= \IPS\Settings::i()->activity_stream_subscriptions_max )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return !$this->isSubscribed($member);
|
||||
}
|
||||
|
||||
/**
|
||||
* Can the member unsubscribe from this stream?
|
||||
*
|
||||
* @param \IPS\Member|null $member
|
||||
* @return bool
|
||||
*/
|
||||
public function canUnsubscribe( \IPS\Member $member = NULL ) : bool
|
||||
{
|
||||
$member = $member ?: \IPS\Member::loggedIn();
|
||||
return $this->isSubscribed($member);
|
||||
}
|
||||
|
||||
/**
|
||||
* Are we already subscribed to this stream?
|
||||
*
|
||||
* @param \IPS\Member|null $member
|
||||
* @return bool
|
||||
*/
|
||||
public function isSubscribed( \IPS\Member $member = NULL ) : bool
|
||||
{
|
||||
$member = $member ?: \IPS\Member::loggedIn();
|
||||
return (bool) \IPS\Db::i()->select( 'COUNT(*)', 'core_stream_subscriptions', array( 'stream_id=? AND member_id=?', $this->id, $member->member_id ) )->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Return the custom badge for each row
|
||||
*
|
||||
* @return NULL|array Null for no badge, or an array of badge data (0 => CSS class type, 1 => language string, 2 => optional raw HTML to show instead of language string)
|
||||
*/
|
||||
protected function get__badge()
|
||||
{
|
||||
$badge = NULL;
|
||||
if ( $this->default )
|
||||
{
|
||||
$badge = array(
|
||||
0 => 'positive ipsPos_right',
|
||||
1 => 'default_no_parenthesis'
|
||||
);
|
||||
}
|
||||
|
||||
return $badge;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Content Discovery Stream Subscription
|
||||
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) Invision Power Services, Inc.
|
||||
* @license https://www.invisioncommunity.com/legal/standards/
|
||||
* @package Invision Community
|
||||
* @since 30 Jul 2021
|
||||
*/
|
||||
|
||||
namespace IPS\core\Stream;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Content Discovery Stream Subscription
|
||||
*/
|
||||
class _Subscription extends \IPS\Patterns\ActiveRecord
|
||||
{
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Table
|
||||
*/
|
||||
public static $databaseTable = 'core_stream_subscriptions';
|
||||
|
||||
|
||||
/*
|
||||
* Get the stream object
|
||||
*
|
||||
* return \IPS\core\Stream
|
||||
*/
|
||||
public function get_stream() : \IPS\core\Stream
|
||||
{
|
||||
return \IPS\core\Stream::load( $this->stream_id) ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send Digest
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function send( array $data, $stream, \IPS\Member $recipient, $subscriptionRow, $showMoreLink = FALSE )
|
||||
{
|
||||
$email = \IPS\Email::buildFromTemplate( 'core', 'activity_stream_subscription', array( $stream, $data, $recipient, $subscriptionRow, $showMoreLink ), \IPS\Email::TYPE_LIST );
|
||||
$email->setUnsubscribe( 'core', 'unsubscribeStream', array( $subscriptionRow['id'], $stream->_title, md5( $recipient->email . ';' . $recipient->ip_address . ';' . $recipient->joined->getTimestamp() ) ) );
|
||||
|
||||
$email->send($recipient);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process a batch of digests
|
||||
*
|
||||
* @param string $frequency One of either "daily" or "weekly" to denote the kind of digest to send
|
||||
* @param int $numberToSend The number of digests to send for this batch
|
||||
* @return bool
|
||||
*/
|
||||
public static function sendBatch( $frequency = 'daily', $numberToSend = 25 )
|
||||
{
|
||||
$subscriptions = iterator_to_array(
|
||||
\IPS\Db::i()->select( 'core_stream_subscriptions.*, core_members.last_visit', 'core_stream_subscriptions', array('frequency = ? AND sent < ? and last_visit > ?', $frequency, ( $frequency == 'daily' ) ? time() - 86400 : time() - 604800, time() - \IPS\Settings::i()->activity_stream_subscriptions_inactive_limit * 86400), 'sent ASC', array(0, $numberToSend), NULL, NULL, \IPS\Db::SELECT_DISTINCT | \IPS\Db::SELECT_FROM_WRITE_SERVER )
|
||||
->join( 'core_members', 'core_stream_subscriptions.member_id=core_members.member_id') );
|
||||
|
||||
if ( !\count( $subscriptions ) )
|
||||
{
|
||||
/* Nothing to send */
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$ids = [];
|
||||
foreach ( $subscriptions as $row )
|
||||
{
|
||||
$member = \IPS\Member::load( $row['member_id'] );
|
||||
if ( !$member->email )
|
||||
{
|
||||
/* Update sent time, so the batch doesn't get stuck in a loop */
|
||||
\IPS\Db::i()->update( 'core_stream_subscriptions', array( 'sent' => time() ), array( 'id=?', $row['id'] ) );
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Build it */
|
||||
$mail = new static;
|
||||
$data = $mail->getContentForStream( $row );
|
||||
$ids[] = $row['id'];
|
||||
if( $items = \count( $data ) )
|
||||
{
|
||||
$showMore = FALSE;
|
||||
if( $items > 10 )
|
||||
{
|
||||
$data = \array_slice($data, 0, 10);
|
||||
$showMore = TRUE;
|
||||
}
|
||||
|
||||
$mail->send( $data, \IPS\core\Stream::load( $row['stream_id'] ), \IPS\Member::load( $row['member_id'] ), $row, $showMore );
|
||||
}
|
||||
}
|
||||
|
||||
if( \count( $ids ) )
|
||||
{
|
||||
\IPS\Db::i()->update( 'core_stream_subscriptions', array( 'sent' => time() ), \IPS\Db::i()->in( 'id', $ids ) );
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \IPS\core\Stream $stream
|
||||
* @param \IPS\Member|null $member
|
||||
* @return Subscription|null
|
||||
*/
|
||||
public static function loadByStreamAndMember( \IPS\core\Stream $stream, \IPS\Member $member = NULL ) : ?\IPS\core\Stream\Subscription
|
||||
{
|
||||
$member = $member ?: \IPS\Member::loggedIn();
|
||||
try
|
||||
{
|
||||
return static::constructFromData( \IPS\Db::i()->select('*', static::$databaseTable, ['stream_id=? AND member_id=?', $stream->id, $member->member_id ] )->first() );
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch all the content for the stream
|
||||
*
|
||||
* @param array $subscriptionRow
|
||||
* @return array
|
||||
*/
|
||||
public function getContentForStream( array $subscriptionRow ) : array
|
||||
{
|
||||
$items = [];
|
||||
$stream = \IPS\core\Stream::load( $subscriptionRow['stream_id'] );
|
||||
|
||||
$query = $stream->query( \IPS\Member::load( $subscriptionRow['member_id']) );
|
||||
|
||||
|
||||
/* Override the timeframe and set it to the last sent time */
|
||||
$query->filterByCreateDate( \IPS\DateTime::ts( $subscriptionRow['sent'] ) );
|
||||
/* We want only 10 items for the email, so we'll grab 11 to see if we need to show the "more link" */
|
||||
$query->setLimit(11);
|
||||
|
||||
/* Get the results */
|
||||
$results = $query->search( NULL, $stream->tags ? explode( ',', $stream->tags ) : NULL, ( $stream->include_comments ? \IPS\Content\Search\Query::TAGS_MATCH_ITEMS_ONLY + \IPS\Content\Search\Query::TERM_OR_TAGS : \IPS\Content\Search\Query::TERM_OR_TAGS ) );
|
||||
|
||||
/* Load data we need like the authors, etc */
|
||||
$results->init();
|
||||
|
||||
foreach ( $results as $result )
|
||||
{
|
||||
$data = $result->asArray();
|
||||
$itemClass = $data['indexData']['index_class'];
|
||||
$object = $itemClass::load( $data['indexData']['index_object_id']);
|
||||
|
||||
if( \in_array( 'IPS\Content\Comment', class_parents( $itemClass ) ) )
|
||||
{
|
||||
$itemClass = $itemClass::$itemClass;
|
||||
}
|
||||
|
||||
$containerUrl = NULL;
|
||||
$containerTitle = NULL;
|
||||
if ( isset( $itemClass::$containerNodeClass ) )
|
||||
{
|
||||
$containerClass = $itemClass::$containerNodeClass;
|
||||
$containerTitle = $containerClass::titleFromIndexData( $data['indexData'], $data['itemData'], $data['containerData'] );
|
||||
$containerUrl = $containerClass::urlFromIndexData( $data['indexData'], $data['itemData'], $data['containerData'] );
|
||||
}
|
||||
|
||||
$items[] = array_merge($data, [
|
||||
'title' => $object instanceof \IPS\Content\Comment ? $object->item()->searchIndexTitle() : $object->searchIndexTitle(),
|
||||
'url' => $object->url(),
|
||||
'content' => $object->content(),
|
||||
'object' => $object,
|
||||
'date' => \IPS\DateTime::ts( $object->mapped('date') ),
|
||||
'itemClass' => $itemClass,
|
||||
'containerUrl' => $containerUrl,
|
||||
'containerTitle' => $containerTitle
|
||||
]);
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
/**
|
||||
* Has the member any subscribed streams
|
||||
*
|
||||
* @param \IPS\Member|null $member
|
||||
* @return bool
|
||||
*/
|
||||
public static function hasSubscribedStreams( \IPS\Member $member = NULL ) : bool
|
||||
{
|
||||
$member = $member ?: \IPS\Member::loggedIn();
|
||||
return (bool) \IPS\Db::i()->select( 'COUNT(*)', 'core_stream_subscriptions', array( 'member_id=?', $member->member_id ) )->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* Has the member any subscribed streams
|
||||
*
|
||||
* @param \IPS\Member|null $member
|
||||
* @return \Iterator
|
||||
*/
|
||||
public static function getSubscribedStreams( \IPS\Member $member = NULL )
|
||||
{
|
||||
$member = $member ?: \IPS\Member::loggedIn();
|
||||
return new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'core_stream_subscriptions', array( 'member_id=?', $member->member_id ) ), \get_called_class() );
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user