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,52 @@
namespace IPS\core\modules\admin\customization;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use InvalidArgumentException;
use IPS\Data\Store;
use IPS\Db;
use IPS\Dispatcher;
use IPS\Dispatcher\Controller;
use IPS\Email;
use IPS\Helpers\Form;
use IPS\Helpers\Form\Codemirror;
use IPS\Helpers\Form\TextArea;
use IPS\Helpers\Form\Upload;
use IPS\Http\Url;
use IPS\Member;
use IPS\Output;
use IPS\Request;
use IPS\Session;
use IPS\Theme;
use IPS\Xml\SimpleXML;
use UnderflowException;
use function count;
use function defined;
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 template management
*/
class _emails extends \IPS\Dispatcher\Controller
class emails 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( 'emails_manage' );
Dispatcher::i()->checkAcpPermission( 'emails_manage' );
parent::execute();
}
@@ -43,14 +65,13 @@ class _emails extends \IPS\Dispatcher\Controller
*
* @return void
*/
public function manage()
public function manage() : void
{
/* Create the table */
$table = new \IPS\Helpers\Table\Db( 'core_email_templates', \IPS\Http\Url::internal( 'app=core&module=customization&controller=emails' ), array( array( "template_parent=?", 0 ) ) );
$table = new \IPS\Helpers\Table\Db( 'core_email_templates', Url::internal( 'app=core&module=customization&controller=emails' ), array( array( "template_parent=?", 0 ) ) );
$table->langPrefix = 'emailtpl_';
$table->mainColumn = 'template_name';
$table->include = array( 'template_name', 'template_app' );
$table->quickSearch = 'template_name';
$table->limit = 100;
/* Primary Sort */
@@ -64,14 +85,14 @@ class _emails extends \IPS\Dispatcher\Controller
$table->quickSearch = function( $val )
{
$matches = \IPS\Member::loggedIn()->language()->searchCustom( 'emailtpl_', $val, TRUE );
if ( \count( $matches ) )
$matches = Member::loggedIn()->language()->searchCustom( 'emailtpl_', $val, TRUE );
if ( count( $matches ) )
{
return '(' . \IPS\Db::i()->in( '`template_name`', array_keys( $matches ) ) . " OR `template_name` LIKE '%{$val}%')";
return '(' . Db::i()->in( '`template_name`', array_keys( $matches ) ) . " OR `template_name` LIKE '%{$val}%')";
}
else
{
return "`template_name` LIKE '%" . \IPS\Db::i()->escape_string( $val ) . "%'";
return "`template_name` LIKE '%" . Db::i()->escape_string( $val ) . "%'";
}
};
@@ -79,11 +100,11 @@ class _emails extends \IPS\Dispatcher\Controller
$table->parsers = array(
'template_name' => function( $val, $row )
{
return \IPS\Member::loggedIn()->language()->addToStack( 'emailtpl_' . $val );
return Member::loggedIn()->language()->addToStack( 'emailtpl_' . $val );
},
'template_app' => function( $val, $row )
{
return \IPS\Member::loggedIn()->language()->addToStack( '__app_' . $val );
return Member::loggedIn()->language()->addToStack( '__app_' . $val );
}
);
@@ -95,7 +116,7 @@ class _emails extends \IPS\Dispatcher\Controller
$return['edit'] = array(
'icon' => 'pencil',
'title' => 'edit',
'link' => \IPS\Http\Url::internal( 'app=core&module=customization&controller=emails&do=form&key=' ) . $row['template_key'],
'link' => Url::internal( 'app=core&module=customization&controller=emails&do=form&key=' ) . $row['template_key'],
);
if( $row['template_edited'] )
@@ -103,14 +124,14 @@ class _emails extends \IPS\Dispatcher\Controller
$return['revert'] = array(
'icon' => 'undo',
'title' => 'revert',
'link' => \IPS\Http\Url::internal( 'app=core&module=customization&controller=emails&do=revert&key=' . $row['template_key'] )->csrf(),
'data' => array( 'confirm' => '', 'confirmMessage' => \IPS\Member::loggedIn()->language()->addToStack('email_revert_confirm') )
'link' => Url::internal( 'app=core&module=customization&controller=emails&do=revert&key=' . $row['template_key'] )->csrf(),
'data' => array( 'confirm' => '', 'confirmMessage' => Member::loggedIn()->language()->addToStack('email_revert_confirm') )
);
$return['export'] = array(
'icon' => 'download',
'title' => 'download',
'link' => \IPS\Http\Url::internal( 'app=core&module=customization&controller=emails&do=export&key=' ) . $row['template_key'],
'link' => Url::internal( 'app=core&module=customization&controller=emails&do=export&key=' ) . $row['template_key'],
);
}
@@ -118,24 +139,24 @@ class _emails extends \IPS\Dispatcher\Controller
};
/* Buttons */
\IPS\Output::i()->sidebar['actions'] = array(
Output::i()->sidebar['actions'] = array(
'upload' => array(
'title' => 'upload_email_template',
'icon' => 'upload',
'link' => \IPS\Http\Url::internal( 'app=core&module=customization&controller=emails&do=import' ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('upload_email_template') )
'link' => Url::internal( 'app=core&module=customization&controller=emails&do=import' ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => Member::loggedIn()->language()->addToStack('upload_email_template') )
),
'preview' => array(
'title' => 'preview_email_wrapper',
'icon' => 'search',
'link' => \IPS\Http\Url::internal( 'app=core&module=customization&controller=emails&do=preview' ),
'data' => array( 'ipsDialog' => \IPS\Http\Url::internal( 'app=core&module=customization&controller=emails&do=preview' ), 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('preview_email_wrapper') )
'link' => Url::internal( 'app=core&module=customization&controller=emails&do=preview' ),
'data' => array( 'ipsDialog' => Url::internal( 'app=core&module=customization&controller=emails&do=preview' ), 'ipsDialog-title' => Member::loggedIn()->language()->addToStack('preview_email_wrapper') )
),
);
/* Display */
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('emailtpl_header');
\IPS\Output::i()->output = (string) $table;
Output::i()->title = Member::loggedIn()->language()->addToStack('emailtpl_header');
Output::i()->output = (string) $table;
}
/**
@@ -143,19 +164,19 @@ class _emails extends \IPS\Dispatcher\Controller
*
* @return void
*/
public function export()
public function export() : void
{
/* Get the template info */
try
{
$template = \IPS\Db::i()->select( '*', 'core_email_templates', array( 'template_parent>0 AND template_key=?', \IPS\Request::i()->key ) )->first();
$template = Db::i()->select( '*', 'core_email_templates', array( 'template_parent>0 AND template_key=?', Request::i()->key ) )->first();
}
catch ( \UnderflowException $e )
catch ( UnderflowException $e )
{
\IPS\Output::i()->error( 'email_template_not_found', '3S128/3', 403, '' );
Output::i()->error( 'email_template_not_found', '3S128/3', 403, '' );
}
$xml = \IPS\Xml\SimpleXML::create('emails');
$xml = SimpleXML::create('emails');
$xml->addChild( 'template', array(
'template_app' => $template['template_app'],
@@ -168,7 +189,7 @@ class _emails extends \IPS\Dispatcher\Controller
$name = addslashes( str_replace( array( ' ', '.', ',' ), '_', $template['template_name'] ) . '.xml' );
\IPS\Output::i()->sendOutput( $xml->asXML(), 200, 'application/xml', array( 'Content-Disposition' => \IPS\Output::getContentDisposition( 'attachment', $name ) ) );
Output::i()->sendOutput( $xml->asXML(), 200, 'application/xml', array( 'Content-Disposition' => Output::getContentDisposition( 'attachment', $name ) ) );
}
/**
@@ -176,27 +197,27 @@ class _emails extends \IPS\Dispatcher\Controller
*
* @return void
*/
public function import()
public function import() : void
{
$form = new \IPS\Helpers\Form( 'form', 'upload' );
$form = new Form( 'form', 'upload' );
$form->add( new \IPS\Helpers\Form\Upload( 'email_template_file', NULL, TRUE, array( 'allowedFileTypes' => array( 'xml' ), 'temporary' => TRUE ) ) );
$form->add( new Upload( 'email_template_file', NULL, TRUE, array( 'allowedFileTypes' => array( 'xml' ), 'temporary' => TRUE ) ) );
if ( $values = $form->values() )
{
/* Open XML file */
try
{
$xml = \IPS\Xml\SimpleXML::loadFile( $values['email_template_file'] );
$xml = SimpleXML::loadFile( $values['email_template_file'] );
if( !\count($xml->template) )
if( !count($xml->template) )
{
\IPS\Output::i()->error( 'email_template_badform', '1S128/4', 403, '' );
Output::i()->error( 'email_template_badform', '1S128/4', 403, '' );
}
}
catch( \InvalidArgumentException $e )
catch( InvalidArgumentException $e )
{
\IPS\Output::i()->error( 'email_template_badform', '1C373/1', 403, '' );
Output::i()->error( 'email_template_badform', '1C373/1', 403, '' );
}
foreach( $xml->template as $template )
@@ -212,25 +233,25 @@ class _emails extends \IPS\Dispatcher\Controller
try
{
$existing = \IPS\Db::i()->select( '*', 'core_email_templates', array( 'template_parent=0 AND template_key=?', $update['template_key'] ) )->first();
$existing = Db::i()->select( '*', 'core_email_templates', array( 'template_parent=0 AND template_key=?', $update['template_key'] ) )->first();
}
catch ( \UnderflowException $e )
catch ( UnderflowException $e )
{
\IPS\Output::i()->error( \IPS\Member::loggedIn()->language()->addToStack('email_template_noexist', FALSE, array( 'sprintf' => array( $update['template_name'] ) ) ), '1S128/5', 403, '' );
Output::i()->error( Member::loggedIn()->language()->addToStack('email_template_noexist', FALSE, array( 'sprintf' => array( $update['template_name'] ) ) ), '1S128/5', 403, '' );
}
$update['template_parent'] = $existing['template_id'];
\IPS\Db::i()->replace( 'core_email_templates', $update );
\IPS\Db::i()->update( 'core_email_templates', array( 'template_edited' => 1 ), array( 'template_id=?', $existing['template_id'] ) );
Db::i()->replace( 'core_email_templates', $update );
Db::i()->update( 'core_email_templates', array( 'template_edited' => 1 ), array( 'template_id=?', $existing['template_id'] ) );
}
/* Redirect */
\IPS\Session::i()->log( 'acplogs__emailtemplate_updated' );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=customization&controller=emails' ), 'email_template_uploaded' );
Session::i()->log( 'acplogs__emailtemplate_updated' );
Output::i()->redirect( Url::internal( 'app=core&module=customization&controller=emails' ), 'email_template_uploaded' );
}
/* Display */
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global' )->block( \IPS\Member::loggedIn()->language()->addToStack('upload_email_template'), $form, FALSE );
Output::i()->output = Theme::i()->getTemplate( 'global' )->block( Member::loggedIn()->language()->addToStack('upload_email_template'), $form, FALSE );
}
/**
@@ -238,26 +259,26 @@ class _emails extends \IPS\Dispatcher\Controller
*
* @return void
*/
public function revert()
public function revert() : void
{
/* Make sure the user confirmed the deletion */
\IPS\Request::i()->confirmedDelete();
Request::i()->confirmedDelete();
/* Get the template info for the log */
$template = \IPS\Db::i()->select( '*', 'core_email_templates', array( 'template_parent=0 AND template_key=?', \IPS\Request::i()->key ) )->first();
$template = Db::i()->select( '*', 'core_email_templates', array( 'template_parent=0 AND template_key=?', Request::i()->key ) )->first();
/* Revert any user-edited copies of the specified template */
\IPS\Db::i()->delete( 'core_email_templates', array( 'template_parent>0 AND template_key=?', \IPS\Request::i()->key ) );
Db::i()->delete( 'core_email_templates', array( 'template_parent>0 AND template_key=?', Request::i()->key ) );
/* Reset edited flag on parent */
\IPS\Db::i()->update( 'core_email_templates', array( 'template_edited' => 0 ), array( 'template_id=?', $template['template_id'] ) );
Db::i()->update( 'core_email_templates', array( 'template_edited' => 0 ), array( 'template_id=?', $template['template_id'] ) );
/* Rebuild template */
$this->_buildTemplate( $template );
/* Log and redirect */
\IPS\Session::i()->log( 'acplog__emailtpl_reverted', array( $template['template_name'] => FALSE ) );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=customization&controller=emails' ), 'reverted_emailtpl' );
Session::i()->log( 'acplog__emailtpl_reverted', array( $template['template_name'] => FALSE ) );
Output::i()->redirect( Url::internal( 'app=core&module=customization&controller=emails' ), 'reverted_emailtpl' );
}
/**
@@ -265,21 +286,21 @@ class _emails extends \IPS\Dispatcher\Controller
*
* @return void
*/
public function form()
public function form() : void
{
/* Get the template */
if( empty( \IPS\Request::i()->key ) )
if( empty( Request::i()->key ) )
{
\IPS\Output::i()->error( 'emailtpl_nofind', '3S128/1', 403, '' );
Output::i()->error( 'emailtpl_nofind', '3S128/1', 403, '' );
}
try
{
$template = \IPS\Db::i()->select( '*', 'core_email_templates', array( 'template_key=?', \IPS\Request::i()->key ), 'template_parent DESC', 1 )->first();
$template = Db::i()->select( '*', 'core_email_templates', array( 'template_key=?', Request::i()->key ), 'template_parent DESC', 1 )->first();
}
catch ( \UnderflowException $e )
catch ( UnderflowException $e )
{
\IPS\Output::i()->error( 'emailtpl_nofind', '3S128/2', 403, '' );
Output::i()->error( 'emailtpl_nofind', '3S128/2', 403, '' );
}
/* Figure out tags for form helpers */
@@ -294,10 +315,10 @@ class _emails extends \IPS\Dispatcher\Controller
}
/* Start the form */
$form = new \IPS\Helpers\Form;
$form->class = 'ipsForm_vertical';
$form->add( new \IPS\Helpers\Form\Codemirror( 'content_html', $template['template_content_html'], TRUE, array( 'tags' => $tags ) ) );
$form->add( new \IPS\Helpers\Form\TextArea( 'content_plaintext', $template['template_content_plaintext'], FALSE, array( 'tags' => $tags, 'rows' => 14 ) ) );
$form = new Form;
$form->class = 'ipsForm--vertical ipsForm--edit-email';
$form->add( new Codemirror( 'content_html', $template['template_content_html'], TRUE, array( 'tags' => $tags ) ) );
$form->add( new TextArea( 'content_plaintext', $template['template_content_plaintext'], FALSE, array( 'tags' => $tags, 'rows' => 14 ) ) );
/* Handle submissions */
if ( $values = $form->values() )
@@ -314,25 +335,25 @@ class _emails extends \IPS\Dispatcher\Controller
if ( !empty($template['template_parent']) )
{
\IPS\Db::i()->update( 'core_email_templates', $save, array( 'template_id=?', $template['template_id'] ) );
Db::i()->update( 'core_email_templates', $save, array( 'template_id=?', $template['template_id'] ) );
}
else
{
\IPS\Db::i()->insert( 'core_email_templates', $save );
\IPS\Db::i()->update( 'core_email_templates', array( 'template_edited' => 1 ), array( 'template_id=?', $template['template_id'] ) );
Db::i()->insert( 'core_email_templates', $save );
Db::i()->update( 'core_email_templates', array( 'template_edited' => 1 ), array( 'template_id=?', $template['template_id'] ) );
}
$this->_buildTemplate( $save );
\IPS\Session::i()->log( 'acplogs__emailtpl_edited', array( $template['template_name'] => FALSE ) );
Session::i()->log( 'acplogs__emailtpl_edited', array( $template['template_name'] => FALSE ) );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=customization&controller=emails' ), 'saved' );
Output::i()->redirect( Url::internal( 'app=core&module=customization&controller=emails' ), 'saved' );
}
/* Output */
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('emailtpl_edit', FALSE, array('sprintf' => \IPS\Member::loggedIn()->language()->addToStack( 'emailtpl_' . $template['template_name']) ) );
\IPS\Output::i()->output = $form->customTemplate( array( \IPS\Theme::i()->getTemplate( 'customization', 'core', 'admin' ), 'email' ) );;
Output::i()->title = Member::loggedIn()->language()->addToStack('emailtpl_edit', FALSE, array('sprintf' => Member::loggedIn()->language()->addToStack( 'emailtpl_' . $template['template_name']) ) );
Output::i()->output = $form->customTemplate( array( Theme::i()->getTemplate( 'customization', 'core', 'admin' ), 'email' ) );
}
/**
@@ -341,16 +362,16 @@ class _emails extends \IPS\Dispatcher\Controller
* @param array $template Template data from core_email_templates
* @return void
*/
protected function _buildTemplate( $template )
protected function _buildTemplate( array $template ) : void
{
$htmlFunction = 'namespace IPS\Theme;' . "\n" . \IPS\Theme::compileTemplate( $template['template_content_html'], "email_html_{$template['template_app']}_{$template['template_name']}", $template['template_data'] );
$ptFunction = 'namespace IPS\Theme;' . "\n" . \IPS\Theme::compileTemplate( $template['template_content_plaintext'], "email_plaintext_{$template['template_app']}_{$template['template_name']}", $template['template_data'] );
$htmlFunction = 'namespace IPS\Theme;' . "\n" . Theme::compileTemplate( $template['template_content_html'], "email_html_{$template['template_app']}_{$template['template_name']}", $template['template_data'] );
$ptFunction = 'namespace IPS\Theme;' . "\n" . Theme::compileTemplate( $template['template_content_plaintext'], "email_plaintext_{$template['template_app']}_{$template['template_name']}", $template['template_data'] );
$key = $template['template_key'] . '_email_html';
\IPS\Data\Store::i()->$key = $htmlFunction;
Store::i()->$key = $htmlFunction;
$key = $template['template_key'] . '_email_plaintext';
\IPS\Data\Store::i()->$key = $ptFunction;
Store::i()->$key = $ptFunction;
}
/**
@@ -358,10 +379,10 @@ class _emails extends \IPS\Dispatcher\Controller
*
* @return void
*/
public function preview()
public function preview() : void
{
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('emailtpl_edit');
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'customization', 'core', 'admin' )->emailFrame( \IPS\Http\Url::internal( 'app=core&module=customization&controller=emails&do=emailPreview' ) );
Output::i()->title = Member::loggedIn()->language()->addToStack('emailtpl_edit');
Output::i()->output = Theme::i()->getTemplate( 'customization', 'core', 'admin' )->emailFrame( Url::internal( 'app=core&module=customization&controller=emails&do=emailPreview' ) );
}
/**
@@ -369,9 +390,9 @@ class _emails extends \IPS\Dispatcher\Controller
*
* @return void
*/
public function emailPreview()
public function emailPreview() : void
{
$email = \IPS\Email::buildFromContent( '', \IPS\Member::loggedIn()->language()->addToStack( 'email_preview_content' ), NULL, \IPS\Email::TYPE_TRANSACTIONAL );
\IPS\Output::i()->sendOutput( $email->compileContent( 'html' ) );
$email = Email::buildFromContent( '', Member::loggedIn()->language()->addToStack( 'email_preview_content' ), NULL, Email::TYPE_TRANSACTIONAL );
Output::i()->sendOutput( $email->compileContent( 'html' ) );
}
}