Version 4.5.0

This commit is contained in:
Neo committed 2025-12-19 05:51:58 -08:00
1 parent 1a0c7fd3c2
commit f79dcf067a
3791 files changed
+248032 -76372

No files matched your search

@@ -11,7 +11,7 @@
namespace IPS\core\modules\front\system;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -31,6 +31,13 @@ class _notifications extends \IPS\Dispatcher\Controller
{
\IPS\Output::i()->error( 'no_module_permission_guest', '2C154/2', 403, '' );
}
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js('front_system.js', 'core' ) );
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'styles/notification_settings.css' ) );
if ( \IPS\Theme::i()->settings['responsive'] )
{
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'styles/notification_settings_responsive.css' ) );
}
}
/**
@@ -49,7 +56,7 @@ class _notifications extends \IPS\Dispatcher\Controller
$notifications = $table->getRows();
\IPS\Db::i()->update( 'core_notifications', array( 'read_time' => time() ), array( 'member=?', \IPS\Member::loggedIn()->member_id ) );
\IPS\Db::i()->update( 'core_notifications', array( 'read_time' => time() ), array( '`member`=?', \IPS\Member::loggedIn()->member_id ) );
\IPS\Member::loggedIn()->recountNotifications();
if ( \IPS\Request::i()->isAjax() )
@@ -65,98 +72,162 @@ class _notifications extends \IPS\Dispatcher\Controller
}
/**
* Options
* Options: Dispatcher
*
* @return void
*/
protected function options()
{
/* Check we're logged in */
$this->_checkLoggedIn();
/* Build form */
$form = new \IPS\Helpers\Form;
$form->add( new \IPS\Helpers\Form\Checkbox( 'allow_admin_mails', \IPS\Member::loggedIn()->allow_admin_mails ) );
$_autoTrack = array();
if( \IPS\Member::loggedIn()->auto_follow['content'] )
{
$_autoTrack[] = 'content';
}
if( \IPS\Member::loggedIn()->auto_follow['comments'] )
{
$_autoTrack[] = 'comments';
}
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'auto_track', $_autoTrack, FALSE, array( 'options' => array( 'content' => 'auto_track_content', 'comments' => 'auto_track_comments' ), 'multiple' => TRUE ) ) );
$form->add( new \IPS\Helpers\Form\Radio( 'auto_track_type', \IPS\Member::loggedIn()->auto_follow['method'] ?: 'immediate', FALSE, array( 'options' => array(
'immediate' => \IPS\Member::loggedIn()->language()->addToStack('follow_type_immediate'),
'daily' => \IPS\Member::loggedIn()->language()->addToStack('follow_type_daily'),
'weekly' => \IPS\Member::loggedIn()->language()->addToStack('follow_type_weekly'),
'none' => \IPS\Member::loggedIn()->language()->addToStack('follow_type_none')
) ), NULL, NULL, NULL, 'auto_track_type' ) );
/* Changed in 4.1: since email_notifications_once is new, combined show_pm_popup in and made a checkbox set for better organization */
$notificationPrefValues = array();
if ( \IPS\Member::loggedIn()->members_bitoptions['show_pm_popup'] )
{
$notificationPrefValues[] = 'show_pm_popup';
}
if ( \IPS\Member::loggedIn()->members_bitoptions['email_notifications_once'] )
{
$notificationPrefValues[] = 'email_notifications_once';
}
if ( !\IPS\Member::loggedIn()->members_bitoptions['disable_notification_sounds'] )
{
$notificationPrefValues[] = 'enable_notification_sounds';
}
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'notification_prefs', $notificationPrefValues, FALSE, array( 'options' => array( 'show_pm_popup' => 'show_pm_popup', 'email_notifications_once' => 'email_notifications_once', 'enable_notification_sounds' => 'enable_notification_sounds' ), 'multiple' => TRUE ) ) );
$form->addMatrix( 'notifications', \IPS\Notification::buildMatrix( \IPS\Member::loggedIn() ) );
/* Handle submissions */
if ( $values = $form->values() )
/* Init breadcrumb */
$extensions = \IPS\Application::allExtensions( 'core', 'Notifications' );
\IPS\Output::i()->breadcrumb[] = array( \IPS\Http\Url::internal( 'app=core&module=system&controller=notifications', 'front', 'notifications' ), \IPS\Member::loggedIn()->language()->addToStack('notifications') );
\IPS\Output::i()->breadcrumb[] = array( \IPS\Http\Url::internal( 'app=core&module=system&controller=notifications&do=options', 'front', 'notifications_options' ), \IPS\Member::loggedIn()->language()->addToStack('options') );
/* Are we viewing a particular type? */
if ( isset( \IPS\Request::i()->type ) and array_key_exists( \IPS\Request::i()->type, $extensions ) )
{
/* Log if admin mail setting is changed */
if ( \IPS\Member::loggedIn()->allow_admin_mails !== $values['allow_admin_mails'] )
{
\IPS\Member::loggedIn()->logHistory( 'core', 'admin_mails', array( 'enabled' => $values['allow_admin_mails'] ) );
}
\IPS\Member::loggedIn()->allow_admin_mails = $values['allow_admin_mails'];
\IPS\Member::loggedIn()->auto_track = json_encode( array(
'content' => ( is_array( $values['auto_track'] ) AND in_array( 'content', $values['auto_track'] ) ) ? 1 : 0,
'comments' => ( is_array( $values['auto_track'] ) AND in_array( 'comments', $values['auto_track'] ) ) ? 1 : 0,
'method' => $values['auto_track_type']
) );
\IPS\Member::loggedIn()->members_bitoptions['show_pm_popup'] = ( is_array( $values['notification_prefs'] ) AND in_array( 'show_pm_popup', $values['notification_prefs'] ) ) ? 1 : 0;
\IPS\Member::loggedIn()->members_bitoptions['email_notifications_once'] = ( is_array( $values['notification_prefs'] ) AND in_array( 'email_notifications_once', $values['notification_prefs'] ) ) ? 1 : 0;
\IPS\Member::loggedIn()->members_bitoptions['disable_notification_sounds'] = ( is_array( $values['notification_prefs'] ) AND in_array( 'enable_notification_sounds', $values['notification_prefs'] ) ) ? 0 : 1;
\IPS\Notification::saveMatrix( \IPS\Member::loggedIn(), $values );
/* Refetch config to see if inline report center notification is set. We have to do this because if toggling report center
option is disabled but inline is forced on by the admin, the setting won't be included in the $values array but the saveMatrix()
method will automatically set it and calling notificationsConfiguration() will pull the data directly from the db. */
$config = \IPS\Member::loggedIn()->notificationsConfiguration();
if ( isset( $config['report_center'] ) and !in_array( 'inline', $config['report_center'] ) )
{
\IPS\Member::loggedIn()->members_bitoptions['no_report_count'] = TRUE;
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( "notifications__" . \IPS\Request::i()->type );
\IPS\Output::i()->breadcrumb[] = array( NULL, \IPS\Member::loggedIn()->language()->addToStack( "notifications__" . \IPS\Request::i()->type ) );
return $this->_optionsType( \IPS\Request::i()->type, $extensions[ \IPS\Request::i()->type ] );
}
/* Nope, viewing the index */
else
{
return $this->_optionsIndex( $extensions );
}
}
/**
* Options: Index
*
* @param array $extensions The extensions
* @return void
*/
protected function _optionsIndex( $extensions )
{
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('notification_options');
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('system')->notificationSettingsIndex( \IPS\Notification::membersOptionCategories( \IPS\Member::loggedIn(), $extensions ) );
\IPS\Output::i()->globalControllers[] = 'core.front.system.notificationSettings';
}
/**
* Options: Index
*
* @param string $extensionKey The extension key
* @param object $extension The extension
* @return void
*/
protected function _optionsType( $extensionKey, $extension )
{
$form = \IPS\Notification::membersTypeForm( \IPS\Member::loggedIn(), $extension );
if ( $form === TRUE )
{
if ( \IPS\Request::i()->isAjax() )
{
\IPS\Member::loggedIn()->notificationsConfiguration = NULL;
$categories = \IPS\Notification::membersOptionCategories( \IPS\Member::loggedIn(), array( $extensionKey => $extension ) );
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate('system')->notificationSettingsIndexRowDetails( $extensionKey, $categories[ $extensionKey ] ), 200, 'text/html', \IPS\Output::i()->httpHeaders );
}
else
{
\IPS\Member::loggedIn()->members_bitoptions['no_report_count'] = FALSE;
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=system&controller=notifications&do=options', 'front', 'notifications_options' ), 'saved' );
}
\IPS\Member::loggedIn()->save();
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=system&controller=notifications&do=options', 'front', 'notifications_options' ), 'saved' );
}
elseif ( $form )
{
$form->class = 'ipsForm_vertical';
}
/* Display */
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js('front_system.js', 'core' ) );
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'styles/notification_settings.css' ) );
\IPS\Output::i()->output = $form->customTemplate( array( \IPS\Theme::i()->getTemplate( 'system' ), 'notificationsSettings' ) );
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('notification_options');
\IPS\Output::i()->breadcrumb[] = array( \IPS\Http\Url::internal( 'app=core&module=system&controller=notifications', 'front', 'notifications' ), \IPS\Member::loggedIn()->language()->addToStack('notifications') );
\IPS\Output::i()->breadcrumb[] = array( NULL, \IPS\Member::loggedIn()->language()->addToStack('options') );
if ( \IPS\Request::i()->isAjax() )
{
$form->actionButtons = array();
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate('system')->notificationSettingsType( \IPS\Member::loggedIn()->language()->addToStack("notifications__{$extensionKey}"), $form, TRUE ), 200, 'text/html', \IPS\Output::i()->httpHeaders );
}
else
{
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('system')->notificationSettingsType( \IPS\Member::loggedIn()->language()->addToStack("notifications__{$extensionKey}"), $form, FALSE );
}
}
/**
* Enable/Disable Sounds
*
* @param array $extensions The extensions
* @return void
*/
protected function sounds()
{
$this->_checkLoggedIn();
\IPS\Session::i()->csrfCheck();
\IPS\Member::loggedIn()->members_bitoptions['disable_notification_sounds'] = ( \IPS\Request::i()->enable ? false : true );
\IPS\Member::loggedIn()->save();
if ( \IPS\Request::i()->isAjax() )
{
\IPS\Output::i()->json( 'ok' );
}
else
{
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=system&controller=notifications&do=options', 'front', 'notifications_options' ) );
}
}
/**
* Stop receiving all notifications to a particular method
*
* @return void
*/
protected function disable()
{
$this->_checkLoggedIn();
\IPS\Session::i()->csrfCheck();
foreach ( \IPS\Application::allExtensions( 'core', 'Notifications' ) as $extension )
{
$options = \IPS\Notification::availableOptions( \IPS\Member::loggedIn(), $extension );
foreach ( $options as $option )
{
if ( $option['type'] === 'standard' )
{
$value = array();
foreach ( $option['options'] as $k => $optionDetails )
{
if ( ( $optionDetails['editable'] and $k !== \IPS\Request::i()->type and $optionDetails['value'] ) or ( !$optionDetails['editable'] and $optionDetails['value'] ) )
{
$value[] = $k;
}
}
foreach ( $option['notificationTypes'] as $notificationKey )
{
\IPS\Db::i()->insert( 'core_notification_preferences', array(
'member_id' => \IPS\Member::loggedIn()->member_id,
'notification_key' => $notificationKey,
'preference' => implode( ',', $value )
), TRUE );
}
}
}
if ( method_exists( $extension, 'disableExtra' ) )
{
$extension::disableExtra( \IPS\Member::loggedIn(), \IPS\Request::i()->type );
}
}
if ( \IPS\Request::i()->isAjax() )
{
\IPS\Output::i()->json( 'ok' );
}
else
{
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=system&controller=notifications&do=options', 'front', 'notifications_options' ) );
}
}
/**
@@ -236,7 +307,7 @@ class _notifications extends \IPS\Dispatcher\Controller
$thing = NULL;
try
{
if ( in_array( 'IPS\Node\Model', class_parents( $class ) ) )
if ( \in_array( 'IPS\Node\Model', class_parents( $class ) ) )
{
$thing = $class::loadAndCheckPerms( \IPS\Request::i()->follow_id );
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'follow_thing', FALSE, array( 'sprintf' => array( $thing->_title ) ) );
@@ -312,7 +383,7 @@ class _notifications extends \IPS\Dispatcher\Controller
{
$type = 'follower_content';
}
elseif ( $class == 'IPS\Member\Club' or in_array( 'IPS\Content\Item', class_parents( $class ) ) )
elseif ( $class == 'IPS\Member\Club' or \in_array( 'IPS\Content\Item', class_parents( $class ) ) )
{
$type = 'new_comment';
}
@@ -323,11 +394,11 @@ class _notifications extends \IPS\Dispatcher\Controller
$notificationConfiguration = \IPS\Member::loggedIn()->notificationsConfiguration();
$notificationConfiguration = isset( $notificationConfiguration[ $type ] ) ? $notificationConfiguration[ $type ] : array();
$lang = 'follow_type_immediate';
if ( in_array( 'email', $notificationConfiguration ) and in_array( 'inline', $notificationConfiguration ) )
if ( \in_array( 'email', $notificationConfiguration ) and \in_array( 'inline', $notificationConfiguration ) )
{
$lang = 'follow_type_immediate_inline_email';
}
elseif ( in_array( 'email', $notificationConfiguration ) )
elseif ( \in_array( 'email', $notificationConfiguration ) )
{
$lang = 'follow_type_immediate_email';
}
@@ -339,11 +410,11 @@ class _notifications extends \IPS\Dispatcher\Controller
if ( empty( $notificationConfiguration ) )
{
\IPS\Member::loggedIn()->language()->words[ $lang . '_desc' ] = \IPS\Member::loggedIn()->language()->addToStack( 'follow_type_immediate_none', FALSE ) . ' <a href="' . \IPS\Http\Url::internal( 'app=core&module=system&controller=notifications&do=options&type=' . $type, 'front', 'notifications_options' ) . '">' . \IPS\Member::loggedIn()->language()->addToStack( 'notification_options', FALSE ) . '</a>';
\IPS\Member::loggedIn()->language()->words[ $lang . '_desc' ] = \IPS\Member::loggedIn()->language()->addToStack( 'follow_type_immediate_none', FALSE ) . ' <a href="' . \IPS\Http\Url::internal( 'app=core&module=system&controller=notifications&do=options&type=core_Content', 'front', 'notifications_options' ) . '">' . \IPS\Member::loggedIn()->language()->addToStack( 'notification_options', FALSE ) . '</a>';
}
else
{
\IPS\Member::loggedIn()->language()->words[ $lang . '_desc' ] = '<a href="' . \IPS\Http\Url::internal( 'app=core&module=system&controller=notifications&do=options&type=' . $type, 'front', 'notifications_options' ) . '">' . \IPS\Member::loggedIn()->language()->addToStack( 'follow_type_immediate_change', FALSE ) . '</a>';
\IPS\Member::loggedIn()->language()->words[ $lang . '_desc' ] = '<a href="' . \IPS\Http\Url::internal( 'app=core&module=system&controller=notifications&do=options&type=core_Content', 'front', 'notifications_options' ) . '">' . \IPS\Member::loggedIn()->language()->addToStack( 'follow_type_immediate_change', FALSE ) . '</a>';
}
/* Build form */
@@ -368,7 +439,7 @@ class _notifications extends \IPS\Dispatcher\Controller
$options['none'] = \IPS\Member::loggedIn()->language()->addToStack('follow_type_no_notification');
}
if ( count( $options ) > 1 )
if ( \count( $options ) > 1 )
{
$form->add( new \IPS\Helpers\Form\Radio( 'follow_type', $current ? $current['follow_notify_freq'] : NULL, TRUE, array(
'options' => $options,
@@ -382,12 +453,12 @@ class _notifications extends \IPS\Dispatcher\Controller
$form->hiddenValues[ $k ] = $v;
if ( empty( $notificationConfiguration ) )
{
$form->addMessage( \IPS\Member::loggedIn()->language()->addToStack( 'follow_type_no_config' ) . ' <a href="' . \IPS\Http\Url::internal( 'app=core&module=system&controller=notifications&do=options&type=' . $type, 'front', 'notifications_options' ) . '">' . \IPS\Member::loggedIn()->language()->addToStack( 'notification_options', FALSE ) . '</a>', '', FALSE );
$form->addMessage( \IPS\Member::loggedIn()->language()->addToStack( 'follow_type_no_config' ) . ' <a href="' . \IPS\Http\Url::internal( 'app=core&module=system&controller=notifications&do=options&type=' . $type, 'front', 'notifications_options' ) . '">' . \IPS\Member::loggedIn()->language()->addToStack( 'notification_options', FALSE ) . '</a>', 'ipsPadding:none', FALSE );
}
else
{
$form->addMessage( \IPS\Member::loggedIn()->language()->addToStack( $v ) . '<br>' . \IPS\Member::loggedIn()->language()->addToStack( $lang . '_desc' ), '', FALSE );
$form->addMessage( \IPS\Member::loggedIn()->language()->addToStack( $v ) . '<br>' . \IPS\Member::loggedIn()->language()->addToStack( $lang . '_desc' ), 'ipsPadding:none', FALSE );
}
}
}
@@ -396,7 +467,12 @@ class _notifications extends \IPS\Dispatcher\Controller
) ) );
if ( $current )
{
$form->addButton( 'unfollow', 'link', \IPS\Http\Url::internal( "app=core&module=system&section=notifications&do=unfollow&id={$current['follow_id']}&follow_app={$current['follow_app']}&follow_area={$current['follow_area']}" )->csrf(), 'ipsButton ipsButton_negative ipsPos_right', array('data-action' => 'unfollow') );
$unfollowUrl = \IPS\Http\Url::internal( "app=core&module=system&controller=notifications&do=unfollow&id={$current['follow_id']}&follow_app={$current['follow_app']}&follow_area={$current['follow_area']}" )->csrf();
if ( method_exists( $thing, 'url' ) AND $thing->url() )
{
$unfollowUrl = $unfollowUrl->addRef( (string) $thing->url() );
}
$form->addButton( 'unfollow', 'link', $unfollowUrl, 'ipsButton ipsButton_link ipsPos_left ipsButton_narrow', array('data-action' => 'unfollow') );
}
/* Handle submissions */
@@ -426,6 +502,9 @@ class _notifications extends \IPS\Dispatcher\Controller
\IPS\Db::i()->insert( 'core_follow', $save );
}
/* Remove cached */
\IPS\Db::i()->delete( 'core_follow_count_cache', array( 'id=? AND class=?', \IPS\Request::i()->follow_id, 'IPS\\' . \IPS\Request::i()->follow_app . '\\' . mb_ucfirst( \IPS\Request::i()->follow_area ) ) );
/* Also follow all nodes if following club */
if( $class == "IPS\Member\Club" )
{
@@ -473,11 +552,11 @@ class _notifications extends \IPS\Dispatcher\Controller
}
/* Display */
$output = $form->customTemplate( array( call_user_func_array( array( \IPS\Theme::i(), 'getTemplate' ), array( 'system', 'core' ) ), 'followForm' ) );
$output = $form->customTemplate( array( \IPS\Theme::i()->getTemplate( 'system', 'core' ), 'followForm' ) );
if( \IPS\Request::i()->isAjax() )
{
\IPS\Output::i()->sendOutput( $output, 200, 'text/html', \IPS\Output::i()->httpHeaders );
\IPS\Output::i()->sendOutput( $output, 200, 'text/html' );
}
else
{
@@ -500,80 +579,36 @@ class _notifications extends \IPS\Dispatcher\Controller
{
$follow = \IPS\Db::i()->select( '*', 'core_follow', array( 'follow_id=? AND follow_member_id=?', \IPS\Request::i()->id, \IPS\Member::loggedIn()->member_id ) )->first();
}
catch ( \OutOfRangeException $e ) {}
catch ( \UnderflowException $e )
{
\IPS\Output::i()->error( 'cant_find_unfollow', '2C154/D', 404, '' );
}
\IPS\Db::i()->delete( 'core_follow', array( 'follow_id=? AND follow_member_id=?', \IPS\Request::i()->id, \IPS\Member::loggedIn()->member_id ) );
/* Get class */
if( \IPS\Request::i()->follow_app == 'core' and \IPS\Request::i()->follow_area == 'member' )
{
$class = 'IPS\\Member';
}
elseif( \IPS\Request::i()->follow_app == 'core' and \IPS\Request::i()->follow_area == 'club' )
\IPS\Db::i()->delete( 'core_follow_count_cache', array( 'id=? AND class=?', $follow['follow_rel_id'], 'IPS\\' . \IPS\Request::i()->follow_app . '\\' . mb_ucfirst( \IPS\Request::i()->follow_area ) ) );
/* If we are unfollowing a club, unfollow all of its nodes */
if( \IPS\Request::i()->follow_app == 'core' and \IPS\Request::i()->follow_area == 'club' )
{
$class = 'IPS\\Member\Club';
}
else
{
$class = NULL;
foreach ( \IPS\Application::load( \IPS\Request::i()->follow_app )->extensions( 'core', 'ContentRouter' ) as $ext )
{
foreach ( $ext->classes as $classname )
{
if ( $classname == 'IPS\\' . \IPS\Request::i()->follow_app . '\\' . mb_ucfirst( \IPS\Request::i()->follow_area ) )
{
$class = $classname;
break;
}
if ( isset( $classname::$containerNodeClass ) and $classname::$containerNodeClass == 'IPS\\' . \IPS\Request::i()->follow_app . '\\' . mb_ucfirst( \IPS\Request::i()->follow_area ) )
{
$class = $classname::$containerNodeClass;
break;
}
if( isset( $classname::$containerFollowClasses ) )
{
foreach( $classname::$containerFollowClasses as $followClass )
{
if( $followClass == 'IPS\\' . \IPS\Request::i()->follow_app . '\\' . mb_ucfirst( \IPS\Request::i()->follow_area ) )
{
$class = $followClass;
break;
}
}
}
}
}
}
/* Get thing */
$thing = NULL;
/* Get thing */
$thing = NULL;
try
{
if ( $class != "IPS\Member" )
try
{
$thing = $class::loadAndCheckPerms( $follow['follow_rel_id'] );
foreach ( $thing->nodes() as $node )
{
$itemClass = $node['node_class']::$contentItemClass;
$followApp = $itemClass::$application;
$followArea = mb_strtolower( mb_substr( $node['node_class'], mb_strrpos( $node['node_class'], '\\' ) + 1 ) );
\IPS\Db::i()->delete( 'core_follow', array( 'follow_id=? AND follow_member_id=?', md5( $followApp . ';' . $followArea . ';' . $node['node_id'] . ';' . \IPS\Member::loggedIn()->member_id ), \IPS\Member::loggedIn()->member_id ) );
}
}
else if( !in_array( 'IPS\Node\Model', class_parents( $class ) ) )
{
$thing = $class::load( $follow['follow_rel_id'] );
}
}
catch ( \OutOfRangeException $e )
{
}
/* Unfollow club areas */
if( $class == "IPS\Member\Club" )
{
foreach ( $thing->nodes() as $node )
{
$itemClass = $node['node_class']::$contentItemClass;
$followApp = $itemClass::$application;
$followArea = mb_strtolower( mb_substr( $node['node_class'], mb_strrpos( $node['node_class'], '\\' ) + 1 ) );
\IPS\Db::i()->delete( 'core_follow', array( 'follow_id=? AND follow_member_id=?', md5( $followApp . ';' . $followArea . ';' . $node['node_id'] . ';' . \IPS\Member::loggedIn()->member_id ), \IPS\Member::loggedIn()->member_id ) );
}
catch ( \OutOfRangeException $e ) {}
}
if ( \IPS\Request::i()->isAjax() )
@@ -582,7 +617,7 @@ class _notifications extends \IPS\Dispatcher\Controller
}
else
{
\IPS\Output::i()->redirect( ( !empty( $_SERVER['HTTP_REFERER'] ) ) ? \IPS\Http\Url::external( $_SERVER['HTTP_REFERER'] ) : \IPS\Http\Url::internal( '' ) );
\IPS\Output::i()->redirect( \IPS\Request::i()->referrer() ?: \IPS\Http\Url::internal( '' ) );
}
}
@@ -596,15 +631,20 @@ class _notifications extends \IPS\Dispatcher\Controller
$perPage = 50;
$thisPage = isset( \IPS\Request::i()->followerPage ) ? \IPS\Request::i()->followerPage : 1;
$thisPage = ( $thisPage > 0 ) ? $thisPage : 1;
if( !\IPS\Request::i()->follow_app OR !\IPS\Request::i()->follow_area )
{
\IPS\Output::i()->error( 'node_error', '2C154/E', 404, '' );
}
/* Get class */
if( \IPS\Request::i()->follow_app == 'core' and \IPS\Request::i()->follow_area == 'member' )
{
$class = 'IPS\\Member';
$class = 'IPS\Member';
}
else if( \IPS\Request::i()->follow_app == 'core' and \IPS\Request::i()->follow_area == 'club' )
{
$class = 'IPS\\Member\Club';
$class = 'IPS\Member\Club';
}
else
{
@@ -621,34 +661,38 @@ class _notifications extends \IPS\Dispatcher\Controller
$anonymous = 0;
try
{
if ( in_array( 'IPS\Node\Model', class_parents( $class ) ) )
if ( \in_array( 'IPS\Node\Model', class_parents( $class ) ) )
{
$classname = $class::$contentItemClass;
$containerClass = $class;
$thing = $containerClass::loadAndCheckPerms( \IPS\Request::i()->follow_id );
$followers = $classname::containerFollowers( $thing, $classname::FOLLOW_PUBLIC, array( 'none', 'immediate', 'daily', 'weekly' ), NULL, array( ( $thisPage - 1 ) * $perPage, $perPage ), 'name' );
$anonymous = $classname::containerFollowers( $thing, $classname::FOLLOW_ANONYMOUS )->count( TRUE );
$followersCount = $classname::containerFollowerCount( $thing );
$anonymous = $classname::containerFollowerCount( $thing, $classname::FOLLOW_ANONYMOUS );
$title = $thing->_title;
}
else if ( $class == "IPS\Member\Club" )
{
$thing = $class::loadAndCheckPerms( \IPS\Request::i()->follow_id );
$followers = $thing->followers( $class::FOLLOW_PUBLIC, array( 'none', 'immediate', 'daily', 'weekly' ), NULL, array( ( $thisPage - 1 ) * $perPage, $perPage ), 'name' );
$anonymous = $thing->followers( $class::FOLLOW_ANONYMOUS )->count( TRUE );
$followersCount = $thing->followersCount();
$anonymous = $thing->followersCount( $class::FOLLOW_ANONYMOUS );
$title = $thing->_title;
}
else if ( $class != "IPS\Member" )
{
$thing = $class::loadAndCheckPerms( \IPS\Request::i()->follow_id );
$followers = $thing->followers( $class::FOLLOW_PUBLIC, array( 'none', 'immediate', 'daily', 'weekly' ), NULL, array( ( $thisPage - 1 ) * $perPage, $perPage ), 'name' );
$anonymous = $thing->followers( $class::FOLLOW_ANONYMOUS )->count( TRUE );
$followersCount = $thing->followersCount();
$anonymous = $thing->followersCount( $class::FOLLOW_ANONYMOUS );
$title = $thing->mapped('title');
}
else
{
$thing = $class::load( \IPS\Request::i()->follow_id );
$followers = $thing->followers( $class::FOLLOW_PUBLIC, array( 'none', 'immediate', 'daily', 'weekly' ), NULL, array( ( $thisPage - 1 ) * $perPage, $perPage ), 'name' );
$anonymous = $thing->followers( $class::FOLLOW_ANONYMOUS )->count( TRUE );
$followersCount = $thing->followersCount();
$anonymous = $thing->followersCount( $class::FOLLOW_ANONYMOUS );
$title = $thing->name;
}
}
@@ -664,17 +708,167 @@ class _notifications extends \IPS\Dispatcher\Controller
}
else
{
$url = \IPS\Http\Url::internal( "app=core&module=system&section=notifications&do=followers&follow_app=". \IPS\Request::i()->follow_app ."&follow_area=". \IPS\Request::i()->follow_area ."&follow_id=" . \IPS\Request::i()->follow_id . "&_infScroll=1" );
$removeAllUrl = \IPS\Http\Url::internal( "app=core&module=system&section=notifications&do=removeFollowers&follow_app=". \IPS\Request::i()->follow_app ."&follow_area=". \IPS\Request::i()->follow_area ."&follow_id=" . \IPS\Request::i()->follow_id )->csrf();
$url = \IPS\Http\Url::internal( "app=core&module=system&controller=notifications&do=followers&follow_app=". \IPS\Request::i()->follow_app ."&follow_area=". \IPS\Request::i()->follow_area ."&follow_id=" . \IPS\Request::i()->follow_id . "&_infScroll=1" );
$removeAllUrl = \IPS\Http\Url::internal( "app=core&module=system&controller=notifications&do=removeFollowers&follow_app=". \IPS\Request::i()->follow_app ."&follow_area=". \IPS\Request::i()->follow_area ."&follow_id=" . \IPS\Request::i()->follow_id )->csrf();
if ( method_exists( $thing, 'url' ) AND $thing->url() )
{
$removeAllUrl = $removeAllUrl->addRef( (string) $thing->url() );
}
$pagination = \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->pagination( $url, ceil( $followers->count( TRUE ) / $perPage ), $thisPage, $perPage, FALSE, 'followerPage' );
$pagination = \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->pagination( $url, ceil( $followersCount / $perPage ), $thisPage, $perPage, FALSE, 'followerPage' );
/* Instruct bots not to index this page */
\IPS\Output::i()->metaTags['robots'] = 'noindex';
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('item_followers', FALSE, array( 'sprintf' => array( $title ) ) );
\IPS\Output::i()->breadcrumb[] = array( $thing->url(), $title );
\IPS\Output::i()->breadcrumb[] = array( NULL, \IPS\Member::loggedIn()->language()->addToStack('who_follows_this') );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'system' )->followers( $url, $pagination, $followers, $anonymous, $removeAllUrl );
}
}
/**
* Unfollow from email
* If we're logged in, we can send them right to the normal follow form.
* Otherwise, they get a special guest page using the gkey as an authentication key.
*
* @return void
*/
protected function unfollowFromEmail()
{
/* Logged in? */
if ( \IPS\Member::loggedIn()->member_id )
{
/* Go to the normal page */
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=core&module=system&controller=notifications&do=follow&follow_app=". \IPS\Request::i()->follow_app ."&follow_area=". \IPS\Request::i()->follow_area ."&follow_id=" . \IPS\Request::i()->follow_id ) );
}
if ( ! empty( \IPS\Request::i()->gkey ) )
{
list( $followKey, $memberKey ) = explode( '-', \IPS\Request::i()->gkey );
/* Do we follow it? */
try
{
$current = \IPS\Db::i()->select( '*', 'core_follow', array( 'MD5( CONCAT_WS( \';\', follow_app, follow_area, follow_rel_id, follow_member_id, follow_added ) )=?', $followKey ) )->first();
/* Already no subs? */
if ( $current['follow_notify_freq'] === 'none' )
{
\IPS\Output::i()->error( 'follow_guest_not_notified', '2C154/C', 404, '' );
}
$member = \IPS\Member::load( $current['follow_member_id'] );
if ( md5( $member->email . ';' . $member->ip_address . ';' . $member->joined->getTimestamp() ) != $memberKey )
{
throw new \Exception;
}
/* Get class */
if( \IPS\Request::i()->follow_app == 'core' and \IPS\Request::i()->follow_area == 'member' )
{
$class = 'IPS\\Member';
}
elseif( \IPS\Request::i()->follow_app == 'core' and \IPS\Request::i()->follow_area == 'club' )
{
$class = 'IPS\\Member\Club';
}
else
{
$class = 'IPS\\' . \IPS\Request::i()->follow_app . '\\' . mb_ucfirst( \IPS\Request::i()->follow_area );
}
if ( !class_exists( $class ) )
{
throw new \Exception;
}
/* Get thing */
$thing = NULL;
if ( \in_array( 'IPS\Node\Model', class_parents( $class ) ) )
{
$classname = $class::$contentItemClass;
$containerClass = $class;
$thing = $containerClass::load( \IPS\Request::i()->follow_id );
$title = $thing->_title;
}
else if ( $class == "IPS\Member\Club" )
{
$thing = $class::load( \IPS\Request::i()->follow_id );
$title = $thing->_title;
}
else if ( $class != "IPS\Member" )
{
$thing = $class::load( \IPS\Request::i()->follow_id );
$title = $thing->mapped('title');
}
else
{
$thing = $class::load( \IPS\Request::i()->follow_id );
$title = $thing->name;
}
/* Grab a count */
$count = \IPS\Db::i()->select( 'COUNT(*)', 'core_follow', array( 'follow_member_id=? and follow_notify_freq != ?', $member->member_id, 'none' ) )->first();
$form = new \IPS\Helpers\Form( 'unfollowFromEmail', 'update_follow' );
$form->class = 'ipsForm_vertical';
if ( $count == 1 )
{
$form->add( new \IPS\Helpers\Form\Checkbox( 'guest_unfollow_single', 'single', FALSE, array( 'disabled' => true ) ) );
\IPS\Member::loggedIn()->language()->words['guest_unfollow_single'] = \IPS\Member::loggedIn()->language()->addToStack('follow_guest_unfollow_thing', FALSE, array( 'sprintf' => array( $title ) ) );
}
else
{
$form->add( new \IPS\Helpers\Form\Radio( 'guest_unfollow_choice', 'single', FALSE, array(
'options' => array(
'single' => \IPS\Member::loggedIn()->language()->addToStack('follow_guest_unfollow_thing', FALSE, array( 'sprintf' => array( $title ) ) ),
'all' => \IPS\Member::loggedIn()->language()->addToStack('follow_guest_unfollow_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 ( $values['guest_unfollow_choice'] == 'single' or isset( $values['guest_unfollow_single'] ) )
{
\IPS\Db::i()->update( 'core_follow', array( 'follow_notify_freq' => 'none' ), array( 'follow_id=? AND follow_member_id=?', $current['follow_id'], $member->member_id ) );
/* Unfollow club areas */
if ( $class == "IPS\Member\Club" )
{
foreach ( $thing->nodes() as $node )
{
$itemClass = $node['node_class']::$contentItemClass;
$followApp = $itemClass::$application;
$followArea = mb_strtolower( mb_substr( $node['node_class'], mb_strrpos( $node['node_class'], '\\' ) + 1 ) );
\IPS\Db::i()->update( 'core_follow', array( 'follow_notify_freq' => 'none' ), array( 'follow_id=? AND follow_member_id=?', md5( $followApp . ';' . $followArea . ';' . $node['node_id'] . ';' . $member->member_id ), $member->member_id ) );
}
}
}
else
{
\IPS\Db::i()->update( 'core_follow', array( 'follow_notify_freq' => 'none' ), array( 'follow_member_id=?', $member->member_id ) );
}
}
\IPS\Output::i()->sidebar['enabled'] = FALSE;
\IPS\Output::i()->bodyClasses[] = 'ipsLayout_minimal';
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'system' )->unfollowFromEmail( $title, $member, $form, ! isset( \IPS\Request::i()->guest_unfollow_choice ) ? FALSE : \IPS\Request::i()->guest_unfollow_choice );
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('follow_guest_unfollow_thing', FALSE, array( 'sprintf' => array( $title ) ) );
}
catch ( \Exception $e )
{
\IPS\Output::i()->error( 'follow_guest_key_not_found', '2C154/B', 404, '' );
}
}
}
/**
* Follow button
@@ -705,7 +899,7 @@ class _notifications extends \IPS\Dispatcher\Controller
$thing = NULL;
try
{
if ( in_array( 'IPS\Node\Model', class_parents( $class ) ) )
if ( \in_array( 'IPS\Node\Model', class_parents( $class ) ) )
{
$classname = $class::$contentItemClass;
$containerClass = $class;
@@ -715,12 +909,12 @@ class _notifications extends \IPS\Dispatcher\Controller
else if ( $class != "IPS\Member" )
{
$thing = $class::loadAndCheckPerms( \IPS\Request::i()->follow_id );
$count = $thing->followers()->count( TRUE );
$count = $thing->followersCount();
}
else
{
$thing = $class::load( \IPS\Request::i()->follow_id );
$count = $thing->followers()->count( TRUE );
$count = $thing->followersCount();
}
}
catch ( \OutOfRangeException $e )
@@ -784,7 +978,9 @@ class _notifications extends \IPS\Dispatcher\Controller
}
catch ( \OutOfRangeException $e ) { }
}
\IPS\Session::i()->modLog( 'modlog__item_follow_removed', array( \IPS\Request::i()->follow_app => FALSE, \IPS\Request::i()->follow_area=> FALSE, \IPS\Request::i()->follow_id => FALSE ) );
\IPS\Output::i()->redirect( ( !empty( $_SERVER['HTTP_REFERER'] ) ) ? \IPS\Http\Url::createFromString( $_SERVER['HTTP_REFERER'] ) : \IPS\Http\Url::internal( '' ), 'followers_removed' );
\IPS\Output::i()->redirect( \IPS\Request::i()->referrer() ?: \IPS\Http\Url::internal( '' ), 'followers_removed' );
}
}