Version 4.7.0
This commit is contained in:
1 parent
517a5e1f70
commit
8ba7d43898
1933 files changed
+65613
-11332
No files matched your search
@@ -22,6 +22,14 @@ if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
*/
|
||||
class _streams extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
/**
|
||||
* @brief These properties are used to specify datalayer context properties.
|
||||
*
|
||||
*/
|
||||
public static $dataLayerContext = array(
|
||||
'community_area' => [ 'value' => 'activity_stream', 'odkUpdate' => 'true']
|
||||
);
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
@@ -73,16 +81,26 @@ class _streams extends \IPS\Dispatcher\Controller
|
||||
|
||||
/* RSS validate? */
|
||||
$member = NULL;
|
||||
|
||||
|
||||
if ( isset( \IPS\Request::i()->rss ) )
|
||||
{
|
||||
$member = \IPS\Member::load( \IPS\Request::i()->member );
|
||||
if ( !\IPS\Login::compareHashes( md5( ( $member->members_pass_hash ?: $member->email ) . $member->members_pass_salt ), (string) \IPS\Request::i()->key ) )
|
||||
if ( isset( \IPS\Request::i()->member ) AND isset( \IPS\Request::i()->key ) )
|
||||
{
|
||||
$member = NULL;
|
||||
$member = \IPS\Member::load( \IPS\Request::i()->member );
|
||||
|
||||
if ( !$member->member_id OR !\IPS\Login::compareHashes( $member->getUniqueMemberHash(), (string) \IPS\Request::i()->key ) )
|
||||
{
|
||||
$member = NULL;
|
||||
}
|
||||
|
||||
/* If we do not have a specific member, and this member is not allowed to view the site, throw an error as they do not have permission */
|
||||
if ( ! $member and ! \IPS\Member::loggedIn()->group['g_view_board'] )
|
||||
{
|
||||
\IPS\Output::i()->error( 'stream_no_permission', '2C280/G', 403, '' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$form = NULL;
|
||||
/* Viewing a particular stream? */
|
||||
if ( isset( \IPS\Request::i()->id ) )
|
||||
@@ -205,7 +223,7 @@ class _streams extends \IPS\Dispatcher\Controller
|
||||
/* but only if we haven't submitted the form on this request */
|
||||
if( !\IPS\Request::i()->stream_submitted )
|
||||
{
|
||||
$streamFields = array( 'include_comments', 'classes', 'ownership', 'custom_members', 'read', 'follow', 'followed_types', 'date_type', 'date_start', 'date_end', 'date_relative_days', 'sort', 'tags' );
|
||||
$streamFields = array( 'include_comments', 'classes', 'ownership', 'custom_members', 'read', 'follow', 'followed_types', 'date_type', 'date_start', 'date_end', 'date_relative_days', 'sort', 'tags', 'solved' );
|
||||
|
||||
/* Clubs enabled? */
|
||||
if( \IPS\Settings::i()->clubs )
|
||||
@@ -296,10 +314,40 @@ class _streams extends \IPS\Dispatcher\Controller
|
||||
$form = $this->_buildForm( $stream );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Condensed or expanded? */
|
||||
$view = 'expanded';
|
||||
$streamID = ( \IPS\Request::i()->id ) ? \IPS\Request::i()->id : 'all';
|
||||
|
||||
if( isset( \IPS\Request::i()->view ) AND \IPS\Login::compareHashes( (string) \IPS\Session::i()->csrfKey, (string) \IPS\Request::i()->csrfKey ) )
|
||||
{
|
||||
$view = \IPS\Request::i()->view;
|
||||
|
||||
\IPS\Request::i()->setCookie( 'stream_view_' . $streamID, \IPS\Request::i()->view, \IPS\DateTime::create()->add( new \DateInterval( 'P1Y' ) ) );
|
||||
|
||||
if( !\IPS\Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->redirect( $stream->url() );
|
||||
}
|
||||
}
|
||||
elseif ( isset( \IPS\Request::i()->cookie['stream_view_' . $streamID] ) )
|
||||
{
|
||||
$view = \IPS\Request::i()->cookie['stream_view_' . $streamID];
|
||||
}
|
||||
else
|
||||
{
|
||||
$view = $stream->default_view;
|
||||
}
|
||||
|
||||
/* Ensure correct params are set for view mode */
|
||||
if ( $view === 'condensed' )
|
||||
{
|
||||
$stream->include_comments = FALSE;
|
||||
}
|
||||
|
||||
/* Build the query */
|
||||
$query = $stream->query( $member );
|
||||
|
||||
|
||||
/* Set page or the before/after date */
|
||||
$currentPage = 1;
|
||||
if ( isset( \IPS\Request::i()->page ) AND \intval( \IPS\Request::i()->page ) > 0 )
|
||||
@@ -308,8 +356,8 @@ class _streams extends \IPS\Dispatcher\Controller
|
||||
$query->setPage( $currentPage );
|
||||
}
|
||||
|
||||
$before = isset( \IPS\Request::i()->before ) ? \IPS\Request::i()->before : null;
|
||||
$after = isset( \IPS\Request::i()->after ) ? \IPS\Request::i()->after : null;
|
||||
$before = ( isset( \IPS\Request::i()->before ) and \is_numeric( \IPS\Request::i()->before ) ) ? (int) \IPS\Request::i()->before : null;
|
||||
$after = ( isset( \IPS\Request::i()->after ) and \is_numeric( \IPS\Request::i()->after ) ) ? (int) \IPS\Request::i()->after : null;
|
||||
|
||||
/* If we sort by oldest, then we need to switch these values */
|
||||
if ( $stream->sort == 'oldest' )
|
||||
@@ -380,30 +428,6 @@ class _streams extends \IPS\Dispatcher\Controller
|
||||
$results = $results->addExtraItems( $extra, NULL, ( \IPS\Request::i()->isAjax() and isset( \IPS\Request::i()->after ) ) ? \IPS\DateTime::ts( \IPS\Request::i()->after ) : NULL, ( \IPS\Request::i()->isAjax() and isset( \IPS\Request::i()->before ) ) ? \IPS\DateTime::ts( \IPS\Request::i()->before ) : NULL );
|
||||
}
|
||||
}
|
||||
|
||||
/* Condensed or expanded? */
|
||||
$view = 'expanded';
|
||||
$streamID = ( \IPS\Request::i()->id ) ? \IPS\Request::i()->id : 'all';
|
||||
|
||||
if( isset( \IPS\Request::i()->view ) AND \IPS\Login::compareHashes( (string) \IPS\Session::i()->csrfKey, (string) \IPS\Request::i()->csrfKey ) )
|
||||
{
|
||||
$view = \IPS\Request::i()->view;
|
||||
|
||||
\IPS\Request::i()->setCookie( 'stream_view_' . $streamID, \IPS\Request::i()->view, \IPS\DateTime::create()->add( new \DateInterval( 'P1Y' ) ) );
|
||||
|
||||
if( !\IPS\Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->redirect( $stream->url() );
|
||||
}
|
||||
}
|
||||
elseif ( isset( \IPS\Request::i()->cookie['stream_view_' . $streamID] ) )
|
||||
{
|
||||
$view = \IPS\Request::i()->cookie['stream_view_' . $streamID];
|
||||
}
|
||||
else
|
||||
{
|
||||
$view = $stream->default_view;
|
||||
}
|
||||
|
||||
/* If this is an AJAX request, just show the results */
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
@@ -453,7 +477,7 @@ class _streams extends \IPS\Dispatcher\Controller
|
||||
$rssLink = \IPS\Http\Url::internal( "app=core&module=discover&controller=streams&id={$stream->id}", 'front', 'discover_rss' );
|
||||
if ( \IPS\Member::loggedIn()->member_id )
|
||||
{
|
||||
$rssLink = $rssLink->setQueryString( 'member', \IPS\Member::loggedIn()->member_id )->setQueryString( 'key', md5( ( \IPS\Member::loggedIn()->members_pass_hash ?: \IPS\Member::loggedIn()->email ) . \IPS\Member::loggedIn()->members_pass_salt ) );
|
||||
$rssLink = $rssLink->setQueryString( 'member', \IPS\Member::loggedIn()->member_id )->setQueryString( 'key', \IPS\Member::loggedIn()->getUniqueMemberHash() );
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -634,7 +658,7 @@ class _streams extends \IPS\Dispatcher\Controller
|
||||
$url = $stream ? $stream->baseUrl->setQueryString( 'className', $class ) : \IPS\Request::i()->url()->setQueryString( 'className', $class );
|
||||
$containerClass = $class::$containerNodeClass;
|
||||
$field = new \IPS\Helpers\Form\Node( 'stream_containers_' . $class::$title, isset( $currentContainers[ $class ] ) ? $currentContainers[ $class ] : array(), NULL, array( 'url' => $url, 'class' => $class::$containerNodeClass, 'multiple' => TRUE, 'permissionCheck' => $containerClass::searchableNodesPermission(), 'clubs' => ( \IPS\Settings::i()->clubs AND \IPS\IPS::classUsesTrait( $containerClass, 'IPS\Content\ClubContainer' ) ) ), NULL, NULL, NULL, 'stream_containers_' . $class::$title );
|
||||
$field->label = \IPS\Member::loggedIn()->language()->addToStack( 'stream_narrow_by_container_label', NULL, array( 'sprintf' => array( \IPS\Member::loggedIn()->language()->addToStack( $containerClass::$nodeTitle ) ) ) );
|
||||
$field->label = \IPS\Member::loggedIn()->language()->addToStack( 'stream_narrow_by_container_label', FALSE, array( 'sprintf' => array( \IPS\Member::loggedIn()->language()->addToStack( $containerClass::$nodeTitle ) ) ) );
|
||||
|
||||
return \IPS\Output::i()->json( array( 'node' => \IPS\Theme::i()->getTemplate('streams')->filterFormContentTypeContent( $field, $class, \IPS\Request::i()->key ) ) );
|
||||
}
|
||||
@@ -761,7 +785,7 @@ class _streams extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
$formattedValues = $stream->formatFormValues( $values );
|
||||
|
||||
foreach ( array( 'include_comments', 'classes', 'containers', 'clubs', 'ownership', 'custom_members', 'read', 'follow', 'followed_types', 'date_type', 'date_start', 'date_end', 'date_relative_days', 'sort', 'tags' ) as $k )
|
||||
foreach ( array( 'include_comments', 'classes', 'containers', 'clubs', 'ownership', 'custom_members', 'read', 'follow', 'followed_types', 'date_type', 'date_start', 'date_end', 'date_relative_days', 'sort', 'tags', 'solved' ) as $k )
|
||||
{
|
||||
$requestKey = 'stream_' . $k;
|
||||
|
||||
@@ -802,6 +826,172 @@ class _streams extends \IPS\Dispatcher\Controller
|
||||
/* Display */
|
||||
return $form->customTemplate( array( \IPS\Theme::i()->getTemplate( 'streams', 'core' ), $stream->id ? 'filterInlineForm' : 'filterCreateForm' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function subscribe()
|
||||
{
|
||||
/* Get it */
|
||||
try
|
||||
{
|
||||
$stream = \IPS\core\Stream::load( \IPS\Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2C280/C', 404, '' );
|
||||
}
|
||||
|
||||
if( !$stream->canSubscribe() )
|
||||
{
|
||||
\IPS\Output::i()->error( 'stream_no_permission', '2C280/D', 403, '' );
|
||||
}
|
||||
|
||||
$form = new \IPS\Helpers\Form('subscribe', 'stream_subscribe_button');
|
||||
$form->class = 'ipsForm_vertical';
|
||||
$form->add( new \IPS\Helpers\Form\Radio('stream_subscription_frequency', NULL , TRUE, ['options' => ['daily' => 'stream_daily', 'weekly' => 'stream_weekly']] ));
|
||||
|
||||
if( $values = $form->values() )
|
||||
{
|
||||
$streamSub = new \IPS\core\Stream\Subscription();
|
||||
$streamSub->member_id = \IPS\Member::loggedIn()->member_id;
|
||||
$streamSub->stream_id = $stream->id;
|
||||
$streamSub->frequency = $values['stream_subscription_frequency'];
|
||||
|
||||
/* Set the fake last sent time to get the next run populated correct */
|
||||
$streamSub->sent = $values['stream_subscription_frequency'] == 'daily' ? \IPS\DateTime::create()->sub( new \DateInterval( 'P1D' ) )->getTimestamp() : \IPS\DateTime::create()->sub( new \DateInterval( 'P1W' ) )->getTimestamp();
|
||||
$streamSub->added = time();
|
||||
$streamSub->save();
|
||||
|
||||
/* Enable the task */
|
||||
$taskKey = $values['stream_subscription_frequency'] == 'daily' ? 'dailyStreamSubscriptions' : 'weeklyStreamSubscriptions';
|
||||
|
||||
\IPS\Db::i()->update( 'core_tasks', array( 'enabled' => 1 ), array( '`key`=?', $taskKey ) );
|
||||
|
||||
\IPS\Output::i()->redirect( $stream->url(), 'subscribed' );
|
||||
}
|
||||
\IPS\Output::i()->output = $form->customTemplate( array( \IPS\Theme::i()->getTemplate( 'forms', 'core' ), 'popupTemplate' ) );
|
||||
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->sendOutput( \IPS\Output::i()->output );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate( 'global', 'core' )->globalTemplate( \IPS\Output::i()->title, \IPS\Output::i()->output, array( 'app' => \IPS\Dispatcher::i()->application->directory, 'module' => \IPS\Dispatcher::i()->module->key, 'controller' => \IPS\Dispatcher::i()->controller ) ), 200, 'text/html' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsubscribe from a stream
|
||||
*/
|
||||
protected function unsubscribe()
|
||||
{
|
||||
/* Get it */
|
||||
try
|
||||
{
|
||||
$stream = \IPS\core\Stream::load( \IPS\Request::i()->id );
|
||||
}
|
||||
catch ( \OutOfRangeException|\UnderflowException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2C280/F', 404, '' );
|
||||
}
|
||||
\IPS\Request::i()->confirmedDelete( 'stream_unsubscribe', 'confirm_stream_unsubscribe', 'stream_unsubscribe_button');
|
||||
if ( $streamSubscription = \IPS\core\Stream\Subscription::loadByStreamAndMember( $stream ) )
|
||||
{
|
||||
$streamSubscription->delete();
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->error( 'stream_no_permission', '2C280/E', 403, '' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->redirect( $stream->url(), 'unsubscribed' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsubscribe from a stream or from all streams from email
|
||||
* If we're logged in, we can send them right to the normal form.
|
||||
* Otherwise, they get a special guest page using the gkey as an authentication key.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function unSubscribeFromEmail()
|
||||
{
|
||||
/* Logged in? */
|
||||
if ( \IPS\Member::loggedIn()->member_id )
|
||||
{
|
||||
/* Go to the normal page */
|
||||
\IPS\Output::i()->redirect( $this->url->setQueryString('do','unsubscribe')->setQueryString('id', \IPS\Request::i()->id));
|
||||
}
|
||||
|
||||
if ( !empty( \IPS\Request::i()->gkey ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
$current = \IPS\Db::i()->select( '*', 'core_stream_subscriptions', [ 'id=?', \IPS\Request::i()->id ])->first();
|
||||
}
|
||||
catch ( \UnderFlowException $e )
|
||||
{
|
||||
\IPS\Output::i()->error('node_error', '2C280/E');
|
||||
}
|
||||
|
||||
$member = \IPS\Member::load( $current['member_id'] );
|
||||
|
||||
if ( md5( $member->email . ';' . $member->ip_address . ';' . $member->joined->getTimestamp() ) != \IPS\Request::i()->gkey )
|
||||
{
|
||||
\IPS\Output::i()->error( 'stream_no_permission', '2C280/E', 403, '' );
|
||||
}
|
||||
|
||||
$form = new \IPS\Helpers\Form( '', 'update_stream_subscriptions' );
|
||||
$form->class = 'ipsForm_vertical';
|
||||
|
||||
if ( $streams = \IPS\core\Stream\Subscription::getSubscribedStreams( $member ) AND $count = \count( $streams ) AND $count == 1 )
|
||||
{
|
||||
$title = \IPS\core\Stream\Subscription::constructFromData($current)->stream->_title;
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'streamsubscription_guest_thing', FALSE, array('sprintf' => array($title)) );
|
||||
$form->add( new \IPS\Helpers\Form\Checkbox( 'guest_unsubscribe_single', 'single', FALSE, array('disabled' => true) ) );
|
||||
\IPS\Member::loggedIn()->language()->words['guest_unsubscribe_single'] = \IPS\Member::loggedIn()->language()->addToStack( 'stream_subscription_unsubscribe_thing', FALSE, array('sprintf' => array($title)) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$title = \IPS\Member::loggedIn()->language()->addToStack( 'stream_subscriptions');
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'streamsubscription_guest_all' );
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'guest_unsubscribe_choice', 'single', FALSE, array(
|
||||
'options' => array(
|
||||
'single' => \IPS\Member::loggedIn()->language()->addToStack( 'streamsubscription_guest_thing', FALSE, array('sprintf' => array( \IPS\core\Stream\Subscription::constructFromData($current)->stream->_title ) ) ),
|
||||
'all' => \IPS\Member::loggedIn()->language()->addToStack( 'streamsubscription_guest_all', FALSE, array('pluralize' => array( $count )) ),
|
||||
),
|
||||
'descriptions' => array(
|
||||
'single' => \IPS\Member::loggedIn()->language()->addToStack( 'follow_guest_unfollow_thing_desc' ),
|
||||
'all' => \IPS\Member::loggedIn()->language()->addToStack( 'follow_guest_unfollow_all_desc', FALSE, array('sprintf' => array(base64_encode( \IPS\Http\Url::internal( 'app=core&module=system&controller=followed' ) ))) )
|
||||
)
|
||||
) ) );
|
||||
}
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
if( isset( $values['guest_unsubscribe_choice'] ) and $values['guest_unsubscribe_choice'] == 'all' )
|
||||
{
|
||||
foreach ( \IPS\core\Stream\Subscription::getSubscribedStreams( $member ) as $subscription )
|
||||
{
|
||||
$subscription->delete();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$subscription = \IPS\core\Stream\Subscription::loadByStreamAndMember( \IPS\core\Stream::load( $current['stream_id'] ), $member );
|
||||
$subscription->delete();
|
||||
}
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( '' ), 'unsubscribed' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->sidebar['enabled'] = FALSE;
|
||||
\IPS\Output::i()->bodyClasses[] = 'ipsLayout_minimal';
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'streams' )->unsubscribeStream( $title, $member, $form, !isset( \IPS\Request::i()->activity_stream_subscription ) ? FALSE : \IPS\Request::i()->activity_stream_subscription );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Rebuild logged in member's streams
|
||||
@@ -814,4 +1004,4 @@ class _streams extends \IPS\Dispatcher\Controller
|
||||
\IPS\Member::loggedIn()->member_streams = json_encode( array( 'default' => $default, 'streams' => iterator_to_array( \IPS\Db::i()->select( 'id, title', 'core_streams', array( '`member`=?', \IPS\Member::loggedIn()->member_id ), NULL, NULL, NULL, NULL, \IPS\Db::SELECT_FROM_WRITE_SERVER )->setKeyField('id')->setValueField('title') ) ) );
|
||||
\IPS\Member::loggedIn()->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user