Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -10,21 +10,30 @@
|
||||
|
||||
namespace IPS\core\modules\admin\settings;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
|
||||
use DateInterval;
|
||||
use Exception;
|
||||
use IPS\core\AdminNotification;
|
||||
use IPS\DateTime;
|
||||
use IPS\Db;
|
||||
use IPS\Dispatcher;
|
||||
use IPS\Email;
|
||||
use IPS\Dispatcher\Controller;
|
||||
use IPS\Email as EmailClass;
|
||||
use IPS\File;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\Color;
|
||||
use IPS\Helpers\Form\Email as FormEmail;
|
||||
use IPS\Helpers\Form\Interval;
|
||||
use IPS\Helpers\Form\Number;
|
||||
use IPS\Helpers\Form\Password;
|
||||
use IPS\Helpers\Form\Radio;
|
||||
use IPS\Helpers\Form\Select;
|
||||
use IPS\Helpers\Form\Text;
|
||||
use IPS\Helpers\Form\TextArea;
|
||||
use IPS\Helpers\Form\Upload;
|
||||
use IPS\Helpers\Form\YesNo;
|
||||
use IPS\Helpers\Table\Db as TableDb;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Member;
|
||||
use IPS\Output;
|
||||
@@ -32,31 +41,35 @@ use IPS\Request;
|
||||
use IPS\Session;
|
||||
use IPS\Settings;
|
||||
use IPS\Theme;
|
||||
use function defined;
|
||||
use function get_class;
|
||||
use function is_string;
|
||||
use const IPS\CIC;
|
||||
use const IPS\DEMO_MODE;
|
||||
use const IPS\Helpers\Table\SEARCH_CONTAINS_TEXT;
|
||||
|
||||
/* 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' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* email
|
||||
*/
|
||||
class _email extends \IPS\Dispatcher\Controller
|
||||
class email 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
|
||||
{
|
||||
Dispatcher::i()->checkAcpPermission( 'email_manage' );
|
||||
parent::execute();
|
||||
@@ -67,33 +80,30 @@ class _email extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
protected function manage() : void
|
||||
{
|
||||
/* Build the settings form */
|
||||
$messageHtml = '';
|
||||
|
||||
$settingsForm = new Form( 'settings_form' );
|
||||
$settingsForm->addHeader( 'basic_settings' );
|
||||
$settingsForm->add( new FormEmail( 'email_out', Settings::i()->email_out, TRUE, [], NULL, NULL, NULL, 'email_out' ) );
|
||||
$settingsForm->add( new FormEmail( 'email_out', Settings::i()->email_out, TRUE, array(), NULL, NULL, NULL, 'email_out' ) );
|
||||
$settingsForm->add( new FormEmail( 'email_in', Settings::i()->email_in, TRUE ) );
|
||||
$settingsForm->add( new Color( 'email_color', Settings::i()->email_color, TRUE ) );
|
||||
$settingsForm->add( new Upload( 'email_logo', Settings::i()->email_logo ? File::get( 'core_Theme', Settings::i()->email_logo ) : NULL, FALSE, [ 'image' => TRUE, 'storageExtension' => 'core_Theme' ] ) );
|
||||
$settingsForm->add( new YesNo( 'social_links_in_email', Settings::i()->social_links_in_email, FALSE, [], NULL, NULL, NULL, 'social_links_in_email' ) );
|
||||
$settingsForm->add( new Upload( 'email_logo', Settings::i()->email_logo ? File::get( 'core_Theme', Settings::i()->email_logo ) : NULL, FALSE, array( 'image' => TRUE, 'storageExtension' => 'core_Theme' ) ) );
|
||||
$settingsForm->add( new YesNo( 'social_links_in_email', Settings::i()->social_links_in_email, FALSE, array(), NULL, NULL, NULL, 'social_links_in_email' ) );
|
||||
$settingsForm->add( new YesNo( 'our_picks_in_email', Settings::i()->our_picks_in_email, FALSE, array(), NULL, NULL, NULL, 'our_picks_in_email' ) );
|
||||
|
||||
if ( Settings::i()->promote_community_enabled )
|
||||
{
|
||||
$settingsForm->add( new YesNo( 'our_picks_in_email', Settings::i()->our_picks_in_email, FALSE, [], NULL, NULL, NULL, 'our_picks_in_email' ) );
|
||||
}
|
||||
|
||||
$settingsForm->add( new YesNo( 'email_truncate', ( Settings::i()->email_truncate ), FALSE, [], NULL, NULL, NULL, 'email_truncate' ) );
|
||||
$settingsForm->add( new YesNo( 'email_log_do', ( Settings::i()->prune_log_emailstats != 0 ), FALSE, [ 'togglesOn' => [ 'prune_log_emailstats' ] ], NULL, NULL, NULL, 'email_log_do' ) );
|
||||
$settingsForm->add( new Interval( 'prune_log_emailstats', Settings::i()->prune_log_emailstats ?: 60, FALSE, [ 'valueAs' => 'd', 'unlimited' => '-1', 'unlimitedLang' => 'never' ], NULL, NULL, NULL, 'prune_log_emailstats' ) );
|
||||
$settingsForm->add( new YesNo( 'email_truncate', ( Settings::i()->email_truncate ), FALSE, array(), NULL, NULL, NULL, 'email_truncate' ) );
|
||||
$settingsForm->add( new YesNo( 'email_log_do', ( Settings::i()->prune_log_emailstats != 0 ), FALSE, array( 'togglesOn' => array( 'prune_log_emailstats' ) ), NULL, NULL, NULL, 'email_log_do' ) );
|
||||
$settingsForm->add( new Interval( 'prune_log_emailstats', Settings::i()->prune_log_emailstats ?: 60, FALSE, array( 'valueAs' => 'd', 'unlimited' => '-1', 'unlimitedLang' => 'never' ), NULL, NULL, NULL, 'prune_log_emailstats' ) );
|
||||
if ( !DEMO_MODE )
|
||||
{
|
||||
$settingsForm->addHeader( 'advanced_settings' );
|
||||
|
||||
$method = Settings::i()->mail_method;
|
||||
$disabled = [];
|
||||
$disabled = array();
|
||||
|
||||
if ( Settings::i()->sendgrid_api_key AND Settings::i()->sendgrid_use_for > 0 )
|
||||
{
|
||||
@@ -113,49 +123,23 @@ class _email extends \IPS\Dispatcher\Controller
|
||||
$method = 'php';
|
||||
}
|
||||
|
||||
$debug = FALSE;
|
||||
if( Email::classToUse( Email::TYPE_TRANSACTIONAL ) == 'IPS\\Email\\Outgoing\\Debug' )
|
||||
$settingsForm->add( new Radio( 'mail_method', $method, TRUE, array(
|
||||
'options' => array( 'php' => ( CIC ? 'mail_method_cic' : 'mail_method_php' ), 'smtp' => 'mail_method_smtp', 'sendgrid' => 'mail_method_sendgrid' ),
|
||||
'disabled' => $disabled,
|
||||
'toggles' => array(
|
||||
'php' => array( 'php_mail_extra' ),
|
||||
'smtp' => array( 'smtp_host', 'smtp_port', 'smtp_user', 'smtp_pass', 'smtp_helo', 'smtp_protocol' ),
|
||||
)
|
||||
) ) );
|
||||
$options = array( 'plain' => 'smtp_plaintext', 'ssl' => 'smtp_ssl', 'tls' => 'smtp_tls' );
|
||||
$settingsForm->add( new Text( 'smtp_host', Settings::i()->smtp_host, FALSE, array(), NULL, NULL, NULL, 'smtp_host' ) );
|
||||
$settingsForm->add( new Select( 'smtp_protocol', Settings::i()->smtp_protocol, FALSE, array( 'options' => $options ), NULL, NULL, NULL, 'smtp_protocol' ) );
|
||||
$settingsForm->add( new Number( 'smtp_port', Settings::i()->smtp_port, FALSE, array(), NULL, NULL, NULL, 'smtp_port' ) );
|
||||
$settingsForm->add( new Text( 'smtp_user', Settings::i()->smtp_user, FALSE, array(), NULL, NULL, NULL, 'smtp_user' ) );
|
||||
$settingsForm->add( new Password( 'smtp_pass', Settings::i()->smtp_pass, FALSE, array( 'enforceMaxLimit' => FALSE ), NULL, NULL, NULL, 'smtp_pass' ) );
|
||||
if ( !CIC )
|
||||
{
|
||||
$debug = true;
|
||||
$method = 'debug';
|
||||
}
|
||||
|
||||
$mailOptions = $toggles = $fields = [];
|
||||
foreach( Email::outgoingHandlers() as $key => $handler )
|
||||
{
|
||||
if( ! $handler::isUsable( Email::TYPE_TRANSACTIONAL ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
$mailOptions[ $key ] = 'mail_method_' . $key;
|
||||
|
||||
$formFields = $handler::form();
|
||||
$toggles[ $key ] = array_keys( $formFields );
|
||||
$fields = $fields + $formFields;
|
||||
}
|
||||
|
||||
/* Change value back to default for platform */
|
||||
if( !\in_array( $method, array_keys( $mailOptions ) ) )
|
||||
{
|
||||
$method = \IPS\CIC ? 'cloud' : 'php';
|
||||
}
|
||||
|
||||
if( !$debug )
|
||||
{
|
||||
$settingsForm->add( new Radio( 'mail_method', $method, TRUE, [
|
||||
'options' => $mailOptions,
|
||||
'disabled' => $disabled,
|
||||
'toggles' => $toggles
|
||||
] ) );
|
||||
|
||||
foreach( $fields as $f )
|
||||
{
|
||||
$settingsForm->add( $f );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$settingsForm->addDummy( 'mail_method', Member::loggedIn()->language()->addToStack('mail_method_debug', false, [ 'sprintf' => [ \IPS\EMAIL_DEBUG_PATH ] ] ) );
|
||||
$settingsForm->add( new Text( 'php_mail_extra', Settings::i()->php_mail_extra, FALSE, array(), NULL, NULL, NULL, 'php_mail_extra' ) );
|
||||
}
|
||||
}
|
||||
if ( $values = $settingsForm->values() )
|
||||
@@ -176,11 +160,14 @@ class _email extends \IPS\Dispatcher\Controller
|
||||
}
|
||||
|
||||
unset( $values['email_log_do'] );
|
||||
|
||||
/* Allow individual handlers to save settings */
|
||||
foreach( Email::outgoingHandlers() as $key => $handler )
|
||||
|
||||
if ( $values['mail_method'] != 'sendgrid' and Settings::i()->sendgrid_use_for == 2 )
|
||||
{
|
||||
$values = $handler::processSettings( $values );
|
||||
$values['sendgrid_use_for'] = 1;
|
||||
}
|
||||
elseif ( $values['mail_method'] == 'sendgrid' )
|
||||
{
|
||||
$values['sendgrid_use_for'] = 2;
|
||||
}
|
||||
|
||||
if ( $values['email_logo'] )
|
||||
@@ -193,27 +180,31 @@ class _email extends \IPS\Dispatcher\Controller
|
||||
|
||||
if( $sendTestEmail )
|
||||
{
|
||||
$email = Email::buildFromContent( Member::loggedIn()->language()->get('email_test_subject'), Member::loggedIn()->language()->addToStack('email_test_message'), Member::loggedIn()->language()->addToStack('email_test_message'), Email::TYPE_BULK );
|
||||
$email = EmailClass::buildFromContent( Member::loggedIn()->language()->get('email_test_subject'), Member::loggedIn()->language()->addToStack('email_test_message'), Member::loggedIn()->language()->addToStack('email_test_message'), EmailClass::TYPE_BULK );
|
||||
|
||||
try
|
||||
{
|
||||
$email->_send( Member::loggedIn(), fromEmail: Settings::i()->email_out );
|
||||
$messageHtml = Theme::i()->getTemplate( 'global', 'core', 'global' )->message( 'email_test_okay_auto', 'success' );
|
||||
$result = $email->send( to: Member::loggedIn(), fromEmail: Settings::i()->email_out, returnException: TRUE );
|
||||
if( $result )
|
||||
{
|
||||
$messageHtml = Theme::i()->getTemplate( 'global', 'core', 'global' )->message( 'email_test_okay_auto', 'success' );
|
||||
}
|
||||
|
||||
/* Sent successfully, remove notification */
|
||||
AdminNotification::remove( 'core', 'ConfigurationError', 'failedMail' );
|
||||
Db::i()->update( 'core_mail_error_logs', [ 'mlog_notification_sent' => TRUE ] );
|
||||
Db::i()->update( 'core_mail_error_logs', array( 'mlog_notification_sent' => TRUE ) );
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
catch ( Exception $e )
|
||||
{
|
||||
$messageHtml = Theme::i()->getTemplate( 'global', 'core', 'global' )->message( 'email_test_error_auto', 'error', $e->getMessage() );
|
||||
$messageHtml = Theme::i()->getTemplate( 'global', 'core', 'global' )->message( $e->getMessage() ?: 'email_test_error_auto', 'error', $e->getMessage() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Build the test form */
|
||||
$testFormHtml = '';
|
||||
if ( !DEMO_MODE AND Member::loggedIn()->hasAcpRestriction( 'core', 'settings', 'email_test' ) )
|
||||
if ( !DEMO_MODE AND Member::loggedIn()->hasAcpRestriction( 'core', 'settings', 'email_test' ) )
|
||||
{
|
||||
Output::i()->sidebar['actions']['test'] = array(
|
||||
'title' => 'email_test',
|
||||
@@ -231,23 +222,26 @@ class _email extends \IPS\Dispatcher\Controller
|
||||
{
|
||||
try
|
||||
{
|
||||
$email = Email::buildFromContent( $values['subject'], $values['message'], $values['message'], Email::TYPE_BULK );
|
||||
$email->_send( $values['to'], fromEmail: $values['from'] );
|
||||
|
||||
$email = EmailClass::buildFromContent( $values['subject'], $values['message'], $values['message'], EmailClass::TYPE_BULK );
|
||||
$result = $email->send( to: $values['to'], fromEmail: $values['from'], returnException: TRUE );
|
||||
|
||||
/* Sent successfully, remove notification */
|
||||
AdminNotification::remove( 'core', 'ConfigurationError', 'failedMail' );
|
||||
Db::i()->update( 'core_mail_error_logs', array( 'mlog_notification_sent' => TRUE ) );
|
||||
if( $result )
|
||||
{
|
||||
$messageHtml = Theme::i()->getTemplate( 'global', 'core', 'global' )->message( 'email_test_okay', 'success' );
|
||||
}
|
||||
|
||||
$messageHtml = Theme::i()->getTemplate( 'global', 'core', 'global' )->message( 'email_test_okay', 'success' );
|
||||
}
|
||||
catch ( \Exception $exception )
|
||||
catch ( Exception $exception )
|
||||
{
|
||||
$content = $exception->getMessage();
|
||||
if ( !( $exception instanceof \IPS\Email\Outgoing\Exception ) )
|
||||
{
|
||||
$content = \get_class( $exception ) . ": " . $exception->getMessage() . " (" . $exception->getCode() . ")";
|
||||
$content = get_class( $exception ) . ": " . $exception->getMessage() . " (" . $exception->getCode() . ")";
|
||||
}
|
||||
$messageHtml = Theme::i()->getTemplate( 'global', 'core', 'global' )->message( $content ?: 'email_test_error_auto', 'error' );
|
||||
$messageHtml = Theme::i()->getTemplate( 'global', 'core', 'global' )->message( $content, 'error' );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -265,7 +259,7 @@ class _email extends \IPS\Dispatcher\Controller
|
||||
}
|
||||
|
||||
/* Display */
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack('email_settings');
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack('email_settings');
|
||||
Output::i()->output = $messageHtml;
|
||||
Output::i()->output .= Theme::i()->getTemplate( 'global' )->block( 'email_settings', $settingsForm );
|
||||
Output::i()->output .= $testFormHtml;
|
||||
@@ -276,7 +270,7 @@ class _email extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function errorLog()
|
||||
protected function errorLog() : void
|
||||
{
|
||||
Dispatcher::i()->checkAcpPermission( 'email_errorlog' );
|
||||
|
||||
@@ -303,12 +297,12 @@ class _email extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @param Url $url Base URL for table
|
||||
* @param array $where Where Array
|
||||
* @return \IPS\Helpers\Table\Db
|
||||
* @return TableDb
|
||||
*/
|
||||
public static function emailErrorLogTable( Url $url, array $where=array() ): \IPS\Helpers\Table\Db
|
||||
public static function emailErrorLogTable( Url $url, array $where=array() ): TableDb
|
||||
{
|
||||
/* Create the table */
|
||||
$table = new \IPS\Helpers\Table\Db( 'core_mail_error_logs', $url, $where );
|
||||
$table = new TableDb( 'core_mail_error_logs', $url, $where );
|
||||
$table->langPrefix = 'emailerrorlogs_';
|
||||
|
||||
/* Columns we need */
|
||||
@@ -322,16 +316,16 @@ class _email extends \IPS\Dispatcher\Controller
|
||||
/* Search */
|
||||
$table->quickSearch = 'mlog_to';
|
||||
$table->advancedSearch = array(
|
||||
'mlog_to' => \IPS\Helpers\Table\SEARCH_CONTAINS_TEXT,
|
||||
'mlog_from' => \IPS\Helpers\Table\SEARCH_CONTAINS_TEXT,
|
||||
'mlog_subject' => \IPS\Helpers\Table\SEARCH_CONTAINS_TEXT,
|
||||
'mlog_msg' => \IPS\Helpers\Table\SEARCH_CONTAINS_TEXT,
|
||||
'mlog_content' => \IPS\Helpers\Table\SEARCH_CONTAINS_TEXT,
|
||||
'mlog_to' => SEARCH_CONTAINS_TEXT,
|
||||
'mlog_from' => SEARCH_CONTAINS_TEXT,
|
||||
'mlog_subject' => SEARCH_CONTAINS_TEXT,
|
||||
'mlog_msg' => SEARCH_CONTAINS_TEXT,
|
||||
'mlog_content' => SEARCH_CONTAINS_TEXT,
|
||||
);
|
||||
|
||||
/* Custom parsers */
|
||||
$table->parsers = array(
|
||||
'mlog_date' => function( $val, $row )
|
||||
'mlog_date' => function( $val )
|
||||
{
|
||||
return DateTime::ts( $val );
|
||||
},
|
||||
@@ -348,7 +342,7 @@ class _email extends \IPS\Dispatcher\Controller
|
||||
/* We may not have a 'message' key if this is an older SendGrid log entry */
|
||||
if( isset( $data['message'] ) )
|
||||
{
|
||||
$val = \is_string( $data['message'] ) ?
|
||||
$val = is_string( $data['message'] ) ?
|
||||
( ( isset( $data['details'] ) AND $data['details'] ) ? Member::loggedIn()->language()->addToStack( $data['message'], FALSE, array( 'sprintf' => $data['details'] ) ) : Member::loggedIn()->language()->addToStack( $data['message'] ) ) :
|
||||
$val;
|
||||
}
|
||||
@@ -394,7 +388,7 @@ class _email extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function errorLogResend()
|
||||
public function errorLogResend() : void
|
||||
{
|
||||
Dispatcher::i()->checkAcpPermission( 'email_errorlog' );
|
||||
Session::i()->csrfCheck();
|
||||
@@ -416,7 +410,7 @@ class _email extends \IPS\Dispatcher\Controller
|
||||
unset( $emailData['headers']['Content-Type'] );
|
||||
unset( $emailData['headers']['Content-Transfer-Encoding'] );
|
||||
|
||||
$email = Email::buildFromContent( $log['mlog_subject'], $emailData['body']['html'], $emailData['body']['plain'], isset( $emailData['type'] ) ? $emailData['type'] : Email::TYPE_TRANSACTIONAL );
|
||||
$email = EmailClass::buildFromContent( $log['mlog_subject'], $emailData['body']['html'], $emailData['body']['plain'], $emailData['type'] ?? EmailClass::TYPE_TRANSACTIONAL );
|
||||
$email->_send(
|
||||
array_map( 'trim', explode( ',', $log['mlog_to'] ) ),
|
||||
isset( $emailData['headers']['Cc'] ) ? array_map( 'trim', explode( ',', $emailData['headers']['Cc'] ) ) : array(),
|
||||
@@ -426,7 +420,7 @@ class _email extends \IPS\Dispatcher\Controller
|
||||
$emailData['headers']
|
||||
);
|
||||
}
|
||||
catch( \Exception $e )
|
||||
catch( Exception $e )
|
||||
{
|
||||
Output::i()->error( $e->getMessage(), '4C143/1', 500, '' );
|
||||
}
|
||||
@@ -434,7 +428,7 @@ class _email extends \IPS\Dispatcher\Controller
|
||||
Db::i()->delete( 'core_mail_error_logs', array( 'mlog_id=?', $id ) );
|
||||
|
||||
/* Remove notification since this was re-sent with success and it is below the recent threshold */
|
||||
if( Email::countFailedMail( DateTime::create()->sub( new \DateInterval( 'P3D' ) ), FALSE, TRUE ) <= 3 )
|
||||
if( EmailClass::countFailedMail( DateTime::create()->sub( new DateInterval( 'P3D' ) ), FALSE, TRUE ) <= 3 )
|
||||
{
|
||||
AdminNotification::remove( 'core', 'ConfigurationError', 'failedMail' );
|
||||
Db::i()->update( 'core_mail_error_logs', array( 'mlog_notification_sent' => TRUE ), array( 'mlog_id=?', $id ) );
|
||||
@@ -448,7 +442,7 @@ class _email extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function errorLogView()
|
||||
public function errorLogView() : void
|
||||
{
|
||||
Dispatcher::i()->checkAcpPermission( 'email_errorlog' );
|
||||
|
||||
@@ -463,7 +457,7 @@ class _email extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function errorLogSettings()
|
||||
protected function errorLogSettings() : void
|
||||
{
|
||||
Dispatcher::i()->checkAcpPermission( 'email_errorlog_prune' );
|
||||
|
||||
|
||||
Reference in new issue
Block a user