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

@@ -11,30 +11,56 @@
namespace IPS\core\modules\admin\membersettings;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use DateInterval;
use DomainException;
use IPS\Application;
use IPS\DateTime;
use IPS\Db;
use IPS\Dispatcher;
use IPS\Dispatcher\Controller;
use IPS\Helpers\Form;
use IPS\Helpers\Form\Interval;
use IPS\Helpers\Form\Radio;
use IPS\Helpers\Form\YesNo;
use IPS\Helpers\Table\Custom;
use IPS\Http\Url;
use IPS\Member;
use IPS\Notification;
use IPS\Output;
use IPS\Request;
use IPS\Session;
use IPS\Settings;
use IPS\Task;
use IPS\Theme;
use function defined;
use function in_array;
use const IPS\CIC;
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;
}
/**
* Notification Settings
*/
class _notifications extends \IPS\Dispatcher\Controller
class notifications extends Controller
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
public static bool $csrfProtected = TRUE;
/**
* Execute
*
* @return void
*/
public function execute()
public function execute() : void
{
\IPS\Dispatcher::i()->checkAcpPermission( 'notifications_manage' );
Dispatcher::i()->checkAcpPermission( 'notifications_manage' );
parent::execute();
}
@@ -43,58 +69,58 @@ class _notifications extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function manage()
protected function manage() : void
{
$types = array();
foreach ( \IPS\Application::allExtensions( 'core', 'Notifications' ) as $k => $extension )
foreach ( Application::allExtensions( 'core', 'Notifications' ) as $k => $extension )
{
$types[ $k ] = array(
'title' => \IPS\Member::loggedIn()->language()->get('notifications__' . $k)
'title' => Member::loggedIn()->language()->get('notifications__' . $k)
);
}
$typeTable = new \IPS\Helpers\Table\Custom( $types, \IPS\Http\Url::internal( 'app=core&module=membersettings&controller=notifications', 'admin' ) );
$typeTable = new Custom( $types, Url::internal( 'app=core&module=membersettings&controller=notifications', 'admin' ) );
$typeTable->langPrefix = 'notificationsettings_';
$typeTable->rowButtons = function( $row, $k ) {
return array(
'edit' => array(
'title' => 'edit',
'link' => \IPS\Http\Url::internal( 'app=core&module=membersettings&controller=notifications&do=edit', 'admin' )->setQueryString( 'id', $k ),
'link' => Url::internal( 'app=core&module=membersettings&controller=notifications&do=edit', 'admin' )->setQueryString( 'id', $k ),
'icon' => 'pencil'
)
);
};
if( !\IPS\CIC )
if( !CIC )
{
\IPS\Output::i()->sidebar['actions'] = array(
Output::i()->sidebar['actions'] = array(
'settings' => array(
'title' => 'prunesettings',
'icon' => 'cog',
'link' => \IPS\Http\Url::internal( 'app=core&module=membersettings&controller=notifications&do=pruneSettings' ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('prunesettings') )
'link' => Url::internal( 'app=core&module=membersettings&controller=notifications&do=pruneSettings' ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => Member::loggedIn()->language()->addToStack('prunesettings') )
),
);
}
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'membersettings', 'profiles_manage' ) )
if ( Member::loggedIn()->hasAcpRestriction( 'core', 'membersettings', 'profiles_manage' ) )
{
\IPS\Output::i()->sidebar['actions']['reset'] = array(
Output::i()->sidebar['actions']['reset'] = array(
'icon' => 'undo',
'title' => 'notification_prefs_reset',
'link' => \IPS\Http\Url::internal( 'app=core&module=membersettings&controller=notifications&do=updateMemberFollowPrefs' )->csrf(),
'data' => array( 'confirm' => '', 'confirmSubMessage' => \IPS\Member::loggedIn()->language()->addToStack('notification_prefs_reset_confirm') )
'link' => Url::internal( 'app=core&module=membersettings&controller=notifications&do=updateMemberFollowPrefs' )->csrf(),
'data' => array( 'confirm' => '', 'confirmSubMessage' => Member::loggedIn()->language()->addToStack('notification_prefs_reset_confirm') )
);
}
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('notifications');
Output::i()->title = Member::loggedIn()->language()->addToStack('notifications');
if ( ! \IPS\Notification::canUseWebPush() )
if ( ! Notification::canUseWebPush() )
{
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('global')->message( 'acp_notifications_cannot_use_web_push', 'general' );
Output::i()->output = Theme::i()->getTemplate('global')->message( 'acp_notifications_cannot_use_web_push', 'general' );
}
\IPS\Output::i()->output .= $typeTable;
Output::i()->output .= $typeTable;
}
/**
@@ -102,52 +128,52 @@ class _notifications extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function pruneSettings()
protected function pruneSettings() : void
{
if( \IPS\CIC )
if( CIC )
{
\IPS\Output::i()->error( 'node_error', '2C413/1', 403, '' );
Output::i()->error( 'node_error', '2C413/1', 403, '' );
}
$form = new \IPS\Helpers\Form;
$form->add( new \IPS\Helpers\Form\Interval( 'prune_follows', \IPS\Settings::i()->prune_follows, FALSE, array( 'valueAs' => \IPS\Helpers\Form\Interval::DAYS, 'unlimited' => 0, 'unlimitedLang' => 'never' ), function( $val ) {
$form = new Form;
$form->add( new Interval( 'prune_follows', Settings::i()->prune_follows, FALSE, array( 'valueAs' => Interval::DAYS, 'unlimited' => 0, 'unlimitedLang' => 'never' ), function( $val ) {
if( $val > 0 AND $val < 30 )
{
throw new \DomainException( \IPS\Member::loggedIn()->language()->addToStack( 'form_interval_min_d', FALSE, array( 'pluralize' => array( 29 ) ) ) );
throw new DomainException( Member::loggedIn()->language()->addToStack( 'form_interval_min_d', FALSE, array( 'pluralize' => array( 29 ) ) ) );
}
}, \IPS\Member::loggedIn()->language()->addToStack('after'), NULL, 'prune_follows' ) );
$form->add( new \IPS\Helpers\Form\Interval( 'prune_notifications', \IPS\Settings::i()->prune_notifications, FALSE, array( 'valueAs' => \IPS\Helpers\Form\Interval::DAYS, 'unlimited' => 0, 'unlimitedLang' => 'never' ), function( $val ) {
}, Member::loggedIn()->language()->addToStack('after'), NULL, 'prune_follows' ) );
$form->add( new Interval( 'prune_notifications', Settings::i()->prune_notifications, FALSE, array( 'valueAs' => Interval::DAYS, 'unlimited' => 0, 'unlimitedLang' => 'never' ), function( $val ) {
if( $val > 0 AND $val < 7 )
{
throw new \DomainException( \IPS\Member::loggedIn()->language()->addToStack( 'form_interval_min_d', FALSE, array( 'pluralize' => array( 6 ) ) ) );
throw new DomainException( Member::loggedIn()->language()->addToStack( 'form_interval_min_d', FALSE, array( 'pluralize' => array( 6 ) ) ) );
}
}, \IPS\Member::loggedIn()->language()->addToStack('after') ) );
}, Member::loggedIn()->language()->addToStack('after') ) );
if ( $values = $form->values() )
{
/* If we're enabling pruning on a potentially large table, handle that */
if( !\IPS\Settings::i()->prune_follows AND $values['prune_follows'] )
if( !Settings::i()->prune_follows AND $values['prune_follows'] )
{
\IPS\Task::queue( 'core', 'PruneLargeTable', array(
Task::queue( 'core', 'PruneLargeTable', array(
'table' => 'core_follow',
'where' => array( 'follow_app!=? AND follow_area!=? AND follow_member_id IN(?)', 'core', 'member', \IPS\Db::i()->select( 'member_id', 'core_members', array( 'last_activity < ?', \IPS\DateTime::create()->sub( new \DateInterval( 'P' . $values['prune_follows'] . 'D' ) )->getTimestamp() ) ) ),
'where' => array( 'follow_app!=? AND follow_area!=? AND follow_member_id IN(?)', 'core', 'member', Db::i()->select( 'member_id', 'core_members', array( 'last_activity < ?', DateTime::create()->sub( new DateInterval( 'P' . $values['prune_follows'] . 'D' ) )->getTimestamp() ) ) ),
'setting' => 'prune_follows',
'deleteJoin' => array(
'column' => 'member_id',
'table' => 'core_members',
'where' => array( 'last_activity < ?', \IPS\DateTime::create()->sub( new \DateInterval( 'P' . $values['prune_follows'] . 'D' ) )->getTimestamp() ),
'where' => array( 'last_activity < ?', DateTime::create()->sub( new DateInterval( 'P' . $values['prune_follows'] . 'D' ) )->getTimestamp() ),
'outerColumn' => 'follow_member_id'
)
), 4 );
}
$form->saveAsSettings( $values );
\IPS\Session::i()->log( 'acplog__follow_settings' );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=membersettings&controller=notifications' ), 'saved' );
Session::i()->log( 'acplog__follow_settings' );
Output::i()->redirect( Url::internal( 'app=core&module=membersettings&controller=notifications' ), 'saved' );
}
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('notification_pruning');
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('global')->block( 'notification_pruning', $form, FALSE );
Output::i()->title = Member::loggedIn()->language()->addToStack('notification_pruning');
Output::i()->output = Theme::i()->getTemplate('global')->block( 'notification_pruning', $form, FALSE );
}
/**
@@ -155,20 +181,20 @@ class _notifications extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function edit()
protected function edit() : void
{
$extensions = \IPS\Application::allExtensions( 'core', 'Notifications' );
if ( !isset( $extensions[ \IPS\Request::i()->id ] ) )
$extensions = Application::allExtensions( 'core', 'Notifications' );
if ( !isset( $extensions[ Request::i()->id ] ) )
{
\IPS\Output::i()->error( 'node_error', '2C404/2', 404, '' );
Output::i()->error( 'node_error', '2C404/2', 404, '' );
}
$extension = $extensions[ \IPS\Request::i()->id ];
$extension = $extensions[ Request::i()->id ];
$defaultConfiguration = \IPS\Notification::defaultConfiguration();
$defaultConfiguration = Notification::defaultConfiguration();
$form = new \IPS\Helpers\Form;
$form = new Form;
foreach ( \IPS\Notification::availableOptions( NULL, $extension ) as $key => $option )
foreach ( Notification::availableOptions( NULL, $extension ) as $key => $option )
{
if ( $option['type'] === 'standard' )
{
@@ -182,13 +208,13 @@ class _notifications extends \IPS\Dispatcher\Controller
$form->addMessage( $option['description'] );
}
if ( !\in_array( 'inline', $option['disabled'] ) or ( \IPS\Notification::webPushEnabled() and !\in_array( 'push', $option['disabled'] ) ) or !\in_array( 'email', $option['disabled'] ) )
if ( !in_array( 'inline', $option['disabled'] ) or ( Notification::webPushEnabled() and !in_array( 'push', $option['disabled'] ) ) or !in_array( 'email', $option['disabled'] ) )
{
$canEditField = new \IPS\Helpers\Form\YesNo( 'notificationsettings_editable_' . $key, $defaultConfiguration[ $key ]['editable'], FALSE, array(
$canEditField = new YesNo( 'notificationsettings_editable_' . $key, $defaultConfiguration[ $key ]['editable'], FALSE, array(
'togglesOn' => array( "member_notifications_{$key}_inline_editable", "member_notifications_{$key}_push", "member_notifications_{$key}_email_editable" ),
'togglesOff' => array( "member_notifications_{$key}_inline", "member_notifications_{$key}_email" )
) );
$canEditField->label = \IPS\Member::loggedIn()->language()->addToStack('notificationsettings_editable');
$canEditField->label = Member::loggedIn()->language()->addToStack('notificationsettings_editable');
$form->add( $canEditField );
}
@@ -198,17 +224,17 @@ class _notifications extends \IPS\Dispatcher\Controller
{
if ( isset( $extra['adminCanSetDefault'] ) and $extra['adminCanSetDefault'] )
{
$field = new \IPS\Helpers\Form\Radio( 'member_notifications_' . $key . '_' . $k, $extra['default'] ? 'default' : 'optional', FALSE, array( 'options' => array(
$field = new Radio( 'member_notifications_' . $key . '_' . $k, $extra['default'] ? 'default' : 'optional', FALSE, array( 'options' => array(
'default' => isset( $extra['admin_lang'] ) ? $extra['admin_lang']['default'] : 'admin_notification_pref_default',
'optional' => isset( $extra['admin_lang'] ) ? $extra['admin_lang']['optional'] : 'admin_notification_pref_optional',
) ), NULL, NULL, NULL, 'member_notifications_' . $k );
$field->label = \IPS\Member::loggedIn()->language()->addToStack( isset( $extra['admin_lang'] ) ? $extra['admin_lang']['title'] : $extra['title'] );
$field->label = Member::loggedIn()->language()->addToStack( isset( $extra['admin_lang'] ) ? $extra['admin_lang']['title'] : $extra['title'] );
$form->add( $field );
}
}
}
if ( \IPS\Notification::canUseWebPush() )
if ( Notification::canUseWebPush() )
{
$types = array( 'inline', 'push', 'email' );
}
@@ -218,16 +244,16 @@ class _notifications extends \IPS\Dispatcher\Controller
}
foreach ( $types as $k )
{
if ( !\in_array( $k, $option['disabled'] ) )
if ( !in_array( $k, $option['disabled'] ) )
{
$editableFieldValue = \in_array( $k, $defaultConfiguration[ $key ]['default'] ) ? 'default' : 'optional';
if ( \in_array( $k, $defaultConfiguration[ $key ]['disabled'] ) )
$editableFieldValue = in_array( $k, $defaultConfiguration[ $key ]['default'] ) ? 'default' : 'optional';
if ( in_array( $k, $defaultConfiguration[ $key ]['disabled'] ) )
{
$editableFieldValue = 'disabled';
}
if ( $k !== 'push' )
{
$editableField = new \IPS\Helpers\Form\Radio( 'member_notifications_' . $key . '_' . $k . '_editable', $editableFieldValue, FALSE, array(
$editableField = new Radio( 'member_notifications_' . $key . '_' . $k . '_editable', $editableFieldValue, FALSE, array(
'options' => array(
'default' => 'admin_notification_pref_default',
'optional' => 'admin_notification_pref_optional',
@@ -238,15 +264,15 @@ class _notifications extends \IPS\Dispatcher\Controller
'optional' => array( 'member_notifications_' . $key . '_push' ),
) : array()
), NULL, NULL, NULL, 'member_notifications_' . $key . '_' . $k . '_editable' );
$editableField->label = \IPS\Member::loggedIn()->language()->addToStack( 'member_notifications_' . $k );
$editableField->label = Member::loggedIn()->language()->addToStack( 'member_notifications_' . $k );
$form->add( $editableField );
}
$nonEditableField = new \IPS\Helpers\Form\Radio( 'member_notifications_' . $key . '_' . $k, \in_array( $k, $defaultConfiguration[ $key ]['disabled'] ) ? 'disabled' : 'default', FALSE, array( 'options' => array(
$nonEditableField = new Radio( 'member_notifications_' . $key . '_' . $k, in_array( $k, $defaultConfiguration[ $key ]['disabled'] ) ? 'disabled' : 'default', FALSE, array( 'options' => array(
'default' => $k === 'push' ? 'admin_notification_pref_available' : 'admin_notification_pref_force',
'disabled' => 'admin_notification_pref_disabled'
) ), NULL, NULL, NULL, 'member_notifications_' . $key . '_' . $k );
$nonEditableField->label = \IPS\Member::loggedIn()->language()->addToStack( 'member_notifications_' . $k );
$nonEditableField->label = Member::loggedIn()->language()->addToStack( 'member_notifications_' . $k );
$form->add( $nonEditableField );
}
}
@@ -266,7 +292,7 @@ class _notifications extends \IPS\Dispatcher\Controller
if ( $values = $form->values() )
{
foreach ( \IPS\Notification::availableOptions( NULL, $extension ) as $key => $option )
foreach ( Notification::availableOptions( NULL, $extension ) as $key => $option )
{
if ( $option['type'] === 'standard' )
{
@@ -281,7 +307,7 @@ class _notifications extends \IPS\Dispatcher\Controller
}
}
if ( !\in_array( 'inline', $option['disabled'] ) or ( \IPS\Notification::webPushEnabled()and !\in_array( 'push', $option['disabled'] ) ) or !\in_array( 'email', $option['disabled'] ) )
if ( !in_array( 'inline', $option['disabled'] ) or ( Notification::webPushEnabled()and !in_array( 'push', $option['disabled'] ) ) or !in_array( 'email', $option['disabled'] ) )
{
$row = array(
'notification_key' => $key,
@@ -292,11 +318,11 @@ class _notifications extends \IPS\Dispatcher\Controller
foreach ( array( 'inline', 'push', 'email' ) as $k )
{
if ( !\in_array( $k, $option['disabled'] ) )
if ( !in_array( $k, $option['disabled'] ) )
{
if ( $k === 'push' )
{
if ( !\IPS\Notification::webPushEnabled() )
if ( !Notification::webPushEnabled() )
{
continue;
}
@@ -321,7 +347,7 @@ class _notifications extends \IPS\Dispatcher\Controller
$row['default'] = implode( ',', $row['default'] );
$row['disabled'] = implode( ',', $row['disabled'] );
\IPS\Db::i()->replace( 'core_notification_defaults', $row, array( 'notification_key=?', $key ) );
Db::i()->replace( 'core_notification_defaults', $row );
$extensionConfiguration = $extension->configurationOptions();
if ( isset( $extensionConfiguration[ $key ] ) and $extensionConfiguration[ $key ]['type'] === 'standard' )
@@ -329,7 +355,7 @@ class _notifications extends \IPS\Dispatcher\Controller
foreach ( $extensionConfiguration[ $key ]['notificationTypes'] as $notificationType )
{
$row['notification_key'] = $notificationType;
\IPS\Db::i()->replace( 'core_notification_defaults', $row, array( 'notification_key=?', $notificationType ) );
Db::i()->replace( 'core_notification_defaults', $row );
}
}
}
@@ -343,13 +369,13 @@ class _notifications extends \IPS\Dispatcher\Controller
}
}
\IPS\Session::i()->log( 'acplog__notifications_edited' );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=membersettings&controller=notifications' ), 'saved' );
Session::i()->log( 'acplog__notifications_edited' );
Output::i()->redirect( Url::internal( 'app=core&module=membersettings&controller=notifications' ), 'saved' );
}
\IPS\Output::i()->breadcrumb[] = array( \IPS\Http\Url::internal( 'app=core&module=membersettings&controller=notifications' ), \IPS\Member::loggedIn()->language()->addToStack( 'menu__core_membersettings_notifications' ) );
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'notifications__' . \IPS\Request::i()->id );
\IPS\Output::i()->output = $form;
Output::i()->breadcrumb[] = array( Url::internal( 'app=core&module=membersettings&controller=notifications' ), Member::loggedIn()->language()->addToStack( 'menu__core_membersettings_notifications' ) );
Output::i()->title = Member::loggedIn()->language()->addToStack( 'notifications__' . Request::i()->id );
Output::i()->output = $form;
}
/**
@@ -357,25 +383,22 @@ class _notifications extends \IPS\Dispatcher\Controller
*
* @return void
*/
protected function updateMemberFollowPrefs()
protected function updateMemberFollowPrefs() : void
{
\IPS\Dispatcher::i()->checkAcpPermission( 'profiles_manage' );
\IPS\Session::i()->csrfCheck();
Dispatcher::i()->checkAcpPermission( 'profiles_manage' );
Session::i()->csrfCheck();
/* Do standard preferences */
\IPS\Db::i()->delete( 'core_notification_preferences' );
Db::i()->delete( 'core_notification_preferences' );
/* Do "extra" preferences */
foreach ( \IPS\Application::allExtensions( 'core', 'Notifications' ) as $k => $extension )
foreach ( Application::allExtensions( 'core', 'Notifications' ) as $k => $extension )
{
if ( method_exists( $extension, 'resetExtra' ) )
{
$extension->resetExtra();
}
$extension->resetExtra();
}
/* Log and redirect */
\IPS\Session::i()->log( 'acplog__notification_settings_existing' );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=membersettings&controller=notifications' ), 'reset' );
Session::i()->log( 'acplog__notification_settings_existing' );
Output::i()->redirect( Url::internal( 'app=core&module=membersettings&controller=notifications' ), 'reset' );
}
}