Version 4.0.13.1

This commit is contained in:
Neo committed 2025-12-19 04:57:54 -08:00
1 parent f9e857d255
commit c6a86f0d9b
7517 files changed
+597400 -668041

No files matched your search

@@ -0,0 +1,365 @@
<?php
/**
* @brief Emoticons
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @since 02 May 2013
* @version SVN_VERSION_NUMBER
*/
namespace IPS\core\modules\admin\editor;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Emoticons
*/
class _emoticons extends \IPS\Dispatcher\Controller
{
/**
* Execute
*
* @return void
*/
public function execute()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'emoticons_manage' );
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'customization/emoticons.css', 'core', 'admin' ) );
parent::execute();
}
/**
* Manage
*
* @return void
*/
protected function manage()
{
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__core_editor_emoticons');
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global' )->block( 'menu__core_editor_emoticons', \IPS\Theme::i()->getTemplate( 'customization' )->emoticons( $this->_getEmoticons() ) );
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'editor', 'emoticons_edit' ) )
{
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js('admin_customization.js', 'core', 'admin') );
}
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'editor', 'emoticons_add' ) )
{
\IPS\Output::i()->sidebar['actions'] = array(
'add' => array(
'icon' => 'plus-circle',
'title' => 'emoticons_add',
'link' => \IPS\Http\Url::internal( 'app=core&module=editor&controller=emoticons&do=add' ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('emoticons_add') )
),
);
}
}
/**
* Add
*
* @return void
*/
protected function add()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'emoticons_add' );
$groups = iterator_to_array( \IPS\Db::i()->select( "emo_set, CONCAT( 'core_emoticon_group_', emo_set ) as emo_set_name", 'core_emoticons', null, null, null, 'emo_set' )->setKeyField('emo_set')->setValueField('emo_set_name') );
$form = new \IPS\Helpers\Form;
$form->add( new \IPS\Helpers\Form\Upload( 'emoticons_upload', NULL, TRUE, array( 'multiple' => TRUE, 'image' => TRUE, 'storageExtension' => 'core_Emoticons', 'storageContainer' => 'emoticons', 'obscure' => FALSE ) ) );
$form->add( new \IPS\Helpers\Form\Radio( 'emoticons_add_group', 'create', TRUE, array(
'options' => array( 'create' => 'emoticons_add_create', 'existing' => 'emoticons_add_existing' ),
'toggles' => array( 'create' => array( 'emoticons_add_newgroup' ), 'existing' => array( 'emoticons_add_choosegroup' ) ),
'disabled' => empty($groups)
) ) );
$form->add( new \IPS\Helpers\Form\Translatable( 'emoticons_add_newgroup', NULL, FALSE, array(), NULL, NULL, NULL, 'emoticons_add_newgroup' ) );
$form->add( new \IPS\Helpers\Form\Select( 'emoticons_add_choosegroup', NULL, FALSE, array( 'options' => $groups ), NULL, NULL, NULL, 'emoticons_add_choosegroup' ) );
if ( $values = $form->values() )
{
if ( $values['emoticons_add_group'] === 'create' )
{
foreach ( \IPS\Lang::languages() as $lang )
{
if ( $lang->default )
{
if( !$values['emoticons_add_newgroup'][ $lang->id ] )
{
$form->elements['']['emoticons_add_newgroup']->error = \IPS\Member::loggedIn()->language()->addToStack( 'emoticon_group_name_error' );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->block( 'emoticons_add', $form, FALSE );
return;
}
}
}
$position = 0;
$setId = md5( uniqid() );
\IPS\Lang::saveCustom( 'core', "core_emoticon_group_{$setId}", $values['emoticons_add_newgroup'] );
\IPS\Session::i()->log( 'acplog__emoticon_group_created', array( "core_emoticon_group_{$setId}" => TRUE ) );
}
else
{
$setId = $values['emoticons_add_choosegroup'];
$position = \IPS\Db::i()->select( 'MAX(emo_position)', 'core_emoticons', array( 'emo_set=?', $setId ) )->first( );
$position = $position['pos'];
}
if ( !is_array( $values['emoticons_upload'] ) )
{
$values['emoticons_upload'] = array( $values['emoticons_upload'] );
}
$inserts = array();
foreach ( $values['emoticons_upload'] as $file )
{
$filename = preg_replace( "/^(.+?)\.[0-9a-f]{32}(?:\..+?)$/i", "$1", $file->filename );
$inserts[] = array(
'typed' => ':' . mb_substr( $filename, 0, mb_strrpos( $filename, '.' ) ) . ':',
'image' => (string) $file,
'clickable' => TRUE,
'emo_set' => $setId,
'emo_position' => ++$position,
);
}
\IPS\Db::i()->insert( 'core_emoticons', $inserts );
unset( \IPS\Data\Store::i()->emoticons );
/* Clear guest page caches */
\IPS\Data\Cache::i()->clearAll();
\IPS\Session::i()->log( 'acplog__emoticons_added', array( "core_emoticon_group_{$setId}" => TRUE ) );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=editor&controller=emoticons' ), 'saved' );
}
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global' )->block( 'emoticons_add', $form, FALSE );
}
/**
* Edit
*
* @return void
*/
protected function edit()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'emoticons_edit' );
$position = 0;
$set = NULL;
if ( \IPS\Request::i()->isAjax() )
{
$i = 1;
if ( isset( \IPS\Request::i()->setOrder ) )
{
foreach ( \IPS\Request::i()->setOrder as $set )
{
$set = preg_replace( '/^core_emoticon_group_/', '', $set );
\IPS\Db::i()->update( 'core_emoticons', array( 'emo_set_position' => $i ), array( 'emo_set=?', $set ) );
$i++;
}
}
else
{
$emoticons = $this->_getEmoticons( TRUE );
foreach ( $emoticons as $group => $emos )
{
if( isset( \IPS\Request::i()->$group ) AND is_array( \IPS\Request::i()->$group ) )
{
foreach( \IPS\Request::i()->$group as $id )
{
\IPS\Db::i()->update( 'core_emoticons', array( 'emo_position' => $i, 'emo_set' => str_replace( 'core_emoticon_group_', '', $group ) ), array( 'id=?', $id ) );
$i++;
}
}
}
}
unset( \IPS\Data\Store::i()->emoticons );
\IPS\Output::i()->json( 'OK' );
return;
}
$emoticons = $this->_getEmoticons( FALSE );
foreach ( \IPS\Request::i()->emo as $id => $data )
{
if ( isset( $data['__set__'] ) )
{
$set = mb_substr( $data['__set__'], \strlen( 'core_emoticon_group_' ) );
continue;
}
if ( isset( $emoticons[ $id ] ) )
{
if ( !isset( $data['order'] ) )
{
if ( !isset( $orders[ $set ] ) )
{
$orders[ $set ] = 0;
}
$data['order'] = ++$orders[ $set ];
}
if ( $emoticons[ $id ]['typed'] !== $data['name'] or $data['order'] != $emoticons[ $id ]['emo_position'] )
{
$save = array( 'typed' => $data['name'] );
if ( isset( $data['order'] ) )
{
$save['emo_position'] = $data['order'];
}
if ( $set !== NULL )
{
$save['emo_set'] = $set;
}
\IPS\Db::i()->update( 'core_emoticons', $save, array( 'id=?', $id ) );
}
}
}
unset( \IPS\Data\Store::i()->emoticons );
/* Clear guest page caches */
\IPS\Data\Cache::i()->clearAll();
\IPS\Session::i()->log( 'acplog__emoticons_edited' );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=editor&controller=emoticons' ), 'saved' );
}
/**
* Delete
*
* @return void
*/
protected function delete()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'emoticons_delete' );
try
{
$emoticon = \IPS\Db::i()->select( '*', 'core_emoticons', array( 'id=?', \IPS\Request::i()->id ) )->first();
if ( $emoticon['id'] )
{
\IPS\File::get( 'core_Emoticons', $emoticon['image'] )->delete();
}
\IPS\Db::i()->delete( 'core_emoticons', array( 'id=?', (int) \IPS\Request::i()->id ) );
/* delete the group name, if there are no other emoticons in this group */
$emoticons = \IPS\Db::i()->select( 'COUNT(*) as count', 'core_emoticons', array( 'emo_set =?', $emoticon['emo_set'] ) )->first();
if ( $emoticons == 0 )
{
\IPS\Lang::deleteCustom( 'core', 'core_emoticon_group_'. $emoticon['emo_set'] );
}
\IPS\Session::i()->log( 'acplog__emoticon_deleted' );
unset( \IPS\Data\Store::i()->emoticons );
/* Clear guest page caches */
\IPS\Data\Cache::i()->clearAll();
}
catch ( \UnderflowException $e ) { }
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=editor&controller=emoticons' ), 'saved' );
}
/**
* Delete set
*
* @return void
*/
public function deleteSet()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'emoticons_delete' );
$set = preg_replace( '/^core_emoticon_group_/', '', \IPS\Request::i()->key );
foreach ( \IPS\Db::i()->select( '*', 'core_emoticons', array( 'emo_set=?', $set ) ) as $emoticon )
{
try
{
\IPS\File::get( 'core_Emoticons', $emoticon['image'] )->delete();
}
catch ( \UnderflowException $e ) { }
}
\IPS\Db::i()->delete( 'core_emoticons', array( 'emo_set=?', $set ) );
\IPS\Lang::deleteCustom( 'core', 'core_emoticon_group_'. $set );
unset( \IPS\Data\Store::i()->emoticons );
/* Clear guest page caches */
\IPS\Data\Cache::i()->clearAll();
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=editor&controller=emoticons' ), 'saved' );
}
/**
* Edit group title
*
* @return void
*/
protected function editTitle()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'emoticons_edit' );
$form = new \IPS\Helpers\Form;
$form->add( new \IPS\Helpers\Form\Translatable( 'emoticons_add_newgroup', NULL, FALSE, array( 'app' => 'core', 'key' => \IPS\Request::i()->key ), NULL, NULL, NULL, 'emoticons_add_newgroup' ) );
if ( $values = $form->values() )
{
\IPS\Lang::saveCustom( 'core', \IPS\Request::i()->key, $values['emoticons_add_newgroup'] );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=editor&controller=emoticons' ), 'saved' );
}
if( \IPS\Request::i()->isAjax() )
{
\IPS\Output::i()->output = $form;
return;
}
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global' )->block( 'emoticons_edit_groupname', $form, FALSE );
}
/**
* Get Emoticons
*
* @param bool $group Group by their group?
* @return array
*/
protected function _getEmoticons( $group=TRUE )
{
$emoticons = array();
foreach ( \IPS\Db::i()->select( '*', 'core_emoticons', NULL, 'emo_set_position,emo_position' ) as $row )
{
if ( $group )
{
$emoticons[ 'core_emoticon_group_' . $row['emo_set'] ][ $row['id'] ] = $row;
}
else
{
$emoticons[ $row['id'] ] = $row;
}
}
return $emoticons;
}
}
Whitespace-only changes.
@@ -0,0 +1,828 @@
<?php
/**
* @brief Editor Toolbars
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @since 30 Apr 2013
* @version SVN_VERSION_NUMBER
*/
namespace IPS\core\modules\admin\editor;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Editor Toolbars
*/
class _toolbar extends \IPS\Dispatcher\Controller
{
/**
* Execute
*
* @return void
*/
public function execute()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'toolbar_manage' );
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'customization/toolbars.css', 'core', 'admin' ) );
\IPS\Output::i()->responsive = FALSE;
parent::execute();
}
/**
* Editor Toolbars
*
* @return void
*/
protected function manage()
{
$config = array(
'desktop' => array( array( 'name' => 'row1', 'items' => array() ) ),
'tablet' => array( array( 'name' => 'row1', 'items' => array() ) ),
'phone' => array( array( 'name' => 'row1', 'items' => array() ) ),
);
$_config = json_decode( \IPS\Settings::i()->ckeditor_toolbars, true );
foreach ( array( 'desktop', 'tablet', 'phone' ) as $device )
{
if ( isset( $_config[ $device ] ) )
{
$config[ $device ] = $_config[ $device ];
}
}
$dummy = new \IPS\Helpers\Form\Editor( 'editor', NULL, FALSE, array( 'autoSaveKey' => md5( uniqid() ), 'allButtons' => TRUE ) );
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__core_editor_toolbar');
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js('admin_customization.js', 'core', 'admin') );
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, array( \IPS\Http\Url::internal( 'applications/core/interface/ckeditor/ckeditor/skins/' . \IPS\Theme::i()->editor_skin . '/editor.css', 'none' ) ) );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'customization' )->editor( $config, $dummy );
\IPS\Output::i()->sidebar['actions'] = array(
'add' => array(
'icon' => 'plus-circle',
'title' => 'editor_new_plugin',
'link' => \IPS\Http\Url::internal( 'app=core&module=editor&controller=toolbar&do=addPlugin' ),
),
'revert' => array(
'icon' => 'refresh',
'title' => 'editor_revert',
'link' => \IPS\Http\Url::internal( "app=core&module=editor&controller=toolbar&do=revert" ),
'data' => array( 'confirm' => '', 'confirmSubMessage' => \IPS\Member::loggedIn()->language()->addToStack('editor_revert_confirm' ) )
),
'edit' => array(
'icon' => 'cog',
'title' => 'editor_advanced_config',
'link' => \IPS\Http\Url::internal( "app=core&module=editor&controller=toolbar&do=advanced" ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('editor_advanced_config') )
),
);
}
/**
* Advanced ckeditor configuration options
*
* @return void
*/
public function advanced()
{
$form = new \IPS\Helpers\Form( 'form' );
$form->addMessage( \IPS\Member::loggedIn()->language()->addToStack('editor_allowed_formmsg') );
$form->add( new \IPS\Helpers\Form\Stack( 'editor_allowed_classes', \IPS\Settings::i()->editor_allowed_classes ? explode( ',', \IPS\Settings::i()->editor_allowed_classes ) : array(), FALSE ) );
$form->add( new \IPS\Helpers\Form\Stack( 'editor_allowed_datacontrollers', \IPS\Settings::i()->editor_allowed_datacontrollers ? explode( ',', \IPS\Settings::i()->editor_allowed_datacontrollers ) : array(), FALSE ) );
if ( $values = $form->values() )
{
$form->saveAsSettings();
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=core&module=editor&controller=toolbar" ), 'saved' );
}
/* Display */
\IPS\Output::i()->output = $form;
}
/**
* Save
*
* @return void
*/
protected function save()
{
$save = array();
$toolbars = json_decode( \IPS\Request::i()->toolbars, TRUE );
foreach ( array( 'desktop', 'tablet', 'phone' ) as $device )
{
$i = 1;
foreach ( $toolbars[ $device ] as $row )
{
if ( !empty( $row ) )
{
$save[ $device ][] = array(
'name' => "row{$i}",
'items' => array_filter( $row )
);
$save[ $device ][] = '/';
$i++;
}
}
}
\IPS\Db::i()->update( 'core_sys_conf_settings', array( 'conf_value' => json_encode( $save ) ), array( 'conf_key=?', 'ckeditor_toolbars' ) );
unset( \IPS\Data\Store::i()->settings );
}
/**
* Button Permissions
*
* @return void
*/
protected function permissions()
{
/* Get current settings */
$button = \IPS\Request::i()->button;
$current = json_decode( \IPS\Settings::i()->ckeditor_permissions, TRUE );
/* Get areas */
$areas = array_combine( array_keys( \IPS\Application::allExtensions( 'core', 'EditorLocations', FALSE ) ), array_map( function( $v )
{
return 'editor__' . $v;
}, array_keys( \IPS\Application::allExtensions( 'core', 'EditorLocations', FALSE ) ) ) );
/* Build Form */
$b64Button = base64_encode( $button );
$form = new \IPS\Helpers\Form;
/* Custom Plugin */
if ( preg_match( '/^custom-(\w{32})$/i', $button, $matches ) and !\IPS\IN_DEV )
{
$code = file_get_contents( \IPS\ROOT_PATH . "/applications/core/interface/ckeditor/ckeditor/plugins/{$matches[0]}/plugin.js" );
$type = 'inline';
if ( mb_strpos( $code, 'ips.utils.defaultEditorPlugins.singleblock' ) !== FALSE )
{
$type = 'singleblock';
}
if ( mb_strpos( $code, 'ips.utils.defaultEditorPlugins.block' ) !== FALSE )
{
$type = 'block';
}
$option = file_exists( \IPS\ROOT_PATH . "/applications/core/interface/ckeditor/ckeditor/plugins/{$matches[0]}/dialogs/{$matches[0]}.js" );
if ( $option )
{
$code = file_get_contents( \IPS\ROOT_PATH . "/applications/core/interface/ckeditor/ckeditor/plugins/{$matches[0]}/dialogs/{$matches[0]}.js" );
}
if ( $type == 'block' or $type == 'singleblock' )
{
preg_match( "/ips.utils.defaultEditorPlugins.{$type}\( '{$matches[0]}', '(.+?)', ([{\[].*[}\]]), (\".*\"), (true|false), (\".*\") \)/", $code, $matches2 );
$attributes = array();
foreach ( json_decode( $matches2[2] ) as $k => $v )
{
$attributes[] = "{$k}='{$v}'";
}
$attributes = count( $attributes ) ? ( ' ' . implode( ' ', $attributes ) ) : '';
$content = ( $matches2[4] === 'true' ) ? '{content}' : '';
$matches2[3] = json_decode( $matches2[3] );
$matches2[5] = json_decode( $matches2[5] );
$code = "<{$matches2[1]}{$attributes}>{$matches2[3]}{$content}{$matches2[5]}</{$matches2[1]}>";
}
else
{
preg_match( "/ips.utils.defaultEditorPlugins.inline\( '{$matches[0]}', \"(.*)\"/", $code, $matches2 );
$code = json_decode( '"' . $matches2[1] . '"' );
}
$form->addTab('custom_button');
$form->add( new \IPS\Helpers\Form\Translatable( 'editor_button_name', NULL, TRUE, array( 'app' => 'core', 'key' => 'editorbutton_' . $matches[0] ) ) );
$form->add( new \IPS\Helpers\Form\Upload( 'editor_button_image', NULL, FALSE, array( 'image' => TRUE, 'multiple' => FALSE, 'allowedFileTypes' => array( 'png' ), 'temporary' => TRUE ) ) );
$form->add( new \IPS\Helpers\Form\Radio( 'editor_button_type', $type, TRUE, array( 'options' => array( 'inline' => 'editor_button_type_inline', 'singleblock' => 'editor_button_type_singleblock', 'block' => 'editor_button_type_block' ) ) ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'editor_button_option_on', $option, FALSE, array( 'togglesOn' => array( 'editor_button_option_label' ) ) ) );
$form->add( new \IPS\Helpers\Form\Translatable( 'editor_button_option_label', NULL, FALSE, array( 'app' => 'core', 'key' => 'editoroption_' . $matches[0] ), NULL, NULL, NULL, 'editor_button_option_label' ) );
$form->add( new \IPS\Helpers\Form\Codemirror( 'editor_button_html', $code, TRUE, array( 'placeholder' => "<div class='{option}'>{content}</div>" ) ) );
$form->addTab('permissions');
}
$form->add( new \IPS\Helpers\Form\Select( 'editor_permission_groups', isset( $current[ $button ] ) ? $current[ $button ]['groups'] : '*', TRUE, array( 'options' => \IPS\Member\Group::groups(), 'parse' => 'normal', 'multiple' => TRUE, 'unlimited' => '*', 'unlimitedLang' => 'everyone' ), NULL, NULL, NULL, $b64Button ) );
$form->add( new \IPS\Helpers\Form\Select( 'editor_permission_areas', isset( $current[ $button ] ) ? $current[ $button ]['areas'] : '*', TRUE, array( 'options' => $areas, 'multiple' => TRUE, 'unlimited' => '*', 'unlimitedLang' => 'everywhere' ), NULL, NULL, NULL, 'l' . $b64Button ) );
/* If this is a custom one, add a delete button */
if ( in_array( mb_strtolower( $button ), explode( ',', mb_strtolower( \IPS\Settings::i()->ckeditor_extraPlugins ) ) ) or preg_match( '/^custom-\w{32}$/i', $button ) )
{
$form->addButton( 'delete', 'link', (string) \IPS\Http\Url::internal( "app=core&module=editor&controller=toolbar&do=deletePlugin&key={$button}" ), 'ipsButton_alternate' );
}
/* Handle Saves */
if ( $values = $form->values() )
{
if ( preg_match( '/^custom-(\w{32})$/i', $button, $matches ) and !\IPS\IN_DEV )
{
$this->_saveCustomPlugin( $matches[0], $values );
}
$current[ $button ] = array(
'groups' => $values['editor_permission_groups'],
'areas' => $values['editor_permission_areas'],
);
\IPS\Db::i()->update( 'core_sys_conf_settings', array( 'conf_value' => json_encode( $current ) ), array( 'conf_key=?', 'ckeditor_permissions' ) );
unset( \IPS\Data\Store::i()->settings );
/* Clear guest page caches */
\IPS\Data\Cache::i()->clearAll();
\IPS\Output::i()->redirect( \IPS\Http\Url::internal('app=core&module=editor&controller=toolbar') );
}
/* Display */
\IPS\Output::i()->title = \IPS\Request::i()->title;
\IPS\Output::i()->output = $form;
}
/**
* Add Plugin
*
* @return void
*/
protected function addPlugin()
{
/* If IN_DEV, we cannot manage plugins */
if ( \IPS\IN_DEV )
{
\IPS\Output::i()->error( 'editor_in_dev', '1C120/1', 403, '' );
}
/* We also need writes */
if ( \IPS\NO_WRITES )
{
\IPS\Output::i()->error( 'no_writes', '1C120/A', 403, '' );
}
/* Custom */
$form = new \IPS\Helpers\Form;
if ( \IPS\Request::i()->tab === 'custom' )
{
/* Build Form */
$form->add( new \IPS\Helpers\Form\Translatable( 'editor_button_name', NULL, TRUE ) );
$form->add( new \IPS\Helpers\Form\Upload( 'editor_button_image', NULL, TRUE, array( 'image' => TRUE, 'multiple' => FALSE, 'allowedFileTypes' => array( 'png' ), 'temporary' => TRUE ) ) );
$form->add( new \IPS\Helpers\Form\Radio( 'editor_button_type', NULL, TRUE, array( 'options' => array( 'inline' => 'editor_button_type_inline', 'singleblock' => 'editor_button_type_singleblock', 'block' => 'editor_button_type_block' ) ) ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'editor_button_option_on', NULL, FALSE, array( 'togglesOn' => array( 'editor_button_option_label' ) ) ) );
$form->add( new \IPS\Helpers\Form\Translatable( 'editor_button_option_label', NULL, FALSE, array(), NULL, NULL, NULL, 'editor_button_option_label' ) );
$form->add( new \IPS\Helpers\Form\Codemirror( 'editor_button_html', NULL, TRUE, array( 'placeholder' => "<div class='{option}'>{content}</div>" ) ) );
/* Handle Submissions */
if ( $values = $form->values() )
{
/* Write */
$key = 'custom-' . md5( uniqid() );
$this->_saveCustomPlugin( $key, $values );
/* Save */
$extraPlugins = explode( ',', \IPS\Settings::i()->ckeditor_extraPlugins );
$extraPlugins[] = $key;
\IPS\Db::i()->update( 'core_sys_conf_settings', array( 'conf_value' => implode( ',', array_filter( array_unique( $extraPlugins ) ) ) ), array( 'conf_key=?', 'ckeditor_extraPlugins' ) );
unset( \IPS\Data\Store::i()->settings );
/* Clear guest page caches */
\IPS\Data\Cache::i()->clearAll();
/* Redirect */
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=editor&controller=toolbar' ), 'saved' );
}
}
/* CKEditor Plugin */
else
{
/* Build Form */
if ( class_exists( 'ZipArchive', FALSE ) )
{
if ( !is_writable( \IPS\ROOT_PATH . '/applications/core/interface/ckeditor/ckeditor/plugins' ) )
{
\IPS\Output::i()->error( 'editor_plugin_nowrite', '4C120/2', 403, '' );
}
$form->add( new \IPS\Helpers\Form\Upload( 'editor_plugin_zip', NULL, TRUE, array( 'allowedFileTypes' => array( 'zip' ), 'temporary' => TRUE ) ) );
}
else
{
$plugins = array();
foreach ( new \DirectoryIterator( \IPS\ROOT_PATH . '/applications/core/interface/ckeditor/ckeditor/plugins' ) as $f )
{
if ( !$f->isDot() and $f->isDir() and $f !== 'index.html' and !in_array( (string) $f, array_merge( array( 'autogrow', 'basicstyles', 'button', 'clipboard', 'colorbutton', 'dialog', 'dialogui', 'enterkey', 'entities', 'fakeobjects', 'floatingspace', 'floatpanel', 'font', 'indent', 'indentblock', 'indentlist', 'index.html', 'ipsattach', 'ipsautolink', 'ipsemoticon', 'ipsimage', 'ipslink', 'ipsmentions', 'ipspage', 'ipsprefs', 'ipsquote', 'ipsspoiler', 'justify', 'link', 'list', 'listblock', 'magicline', 'panel', 'panelbutton', 'pastetext', 'pbckcode', 'removeformat', 'richcombo', 'sourcearea', 'toolbar', 'undo', 'wysiwygarea' ), explode( ',', \IPS\Settings::i()->ckeditor_extraPlugins ) ) ) )
{
$plugins[ (string) $f ] = (string) $f;
}
}
$form->add( new \IPS\Helpers\Form\Select( 'editor_plugin_folder', NULL, TRUE, array( 'options' => $plugins ) ) );
}
/* Handle Submissions */
if ( $values = $form->values() )
{
/* Get the folder */
if ( isset( $values['editor_plugin_zip'] ) )
{
/* Not all plugins are created equal - some are created with the contents of the zip file as pluginname/plugincontents, whereas others are just the plugin contents in the root */
foreach( \IPS\File::normalizeFilesArray( $_FILES['editor_plugin_zip'] ) AS $file )
{
$fileName = $file['name'];
break;
}
/* Get the plugin name */
$inRoot = TRUE;
$zip = zip_open( $values['editor_plugin_zip'] );
while( $resource = zip_read( $zip ) )
{
$name = mb_substr( zip_entry_name( $resource ), 0, -1 );
$name = explode( '/', $name );
$name = array_shift( $name );
if ( strstr( $fileName, $name ) !== FALSE )
{
$inRoot = FALSE;
break;
}
}
zip_close( $zip );
/* If the content of the plugin is in the root of the zip, then we need to manually create the folder and key */
$extractTo = \IPS\ROOT_PATH . '/applications/core/interface/ckeditor/ckeditor/plugins';
if ( $inRoot === TRUE )
{
/* Remove the .zip extension from the filename */
$name = explode( '_', $fileName );
$name = array_shift( $name );
$extractTo .= '/' . $name;
}
/* Extract it */
$zip = new \ZipArchive;
$zip->open( $values['editor_plugin_zip'] );
$zip->extractTo( $extractTo );
$zip->close();
/* Delete the temp file */
unlink( $values['editor_plugin_zip'] );
}
else
{
$name = $values['editor_plugin_folder'];
if ( !file_exists( \IPS\ROOT_PATH . '/applications/core/interface/ckeditor/ckeditor/plugins/' . $name . '/plugin.js' ) )
{
\IPS\Output::i()->error( 'editor_bad_plugin_directory', '1C120/9', 400, '' );
}
}
/* See if we can sniff out requirements for this plugin. */
if ( !file_exists( \IPS\ROOT_PATH . '/applications/core/interface/ckeditor/ckeditor/plugins/' . $name . '/plugin.js' ) )
{
\IPS\Output::i()->error( 'editor_bad_plugin', '1C120/9', 400, '' );
}
$file = \file_get_contents( \IPS\ROOT_PATH . '/applications/core/interface/ckeditor/ckeditor/plugins/' . $name . '/plugin.js' );
preg_match( "#requires: \'(.+?)\',#i", $file, $matches );
if ( isset( $matches[1] ) )
{
$required = explode( ',', $matches[1] );
$current = array_merge( array( 'basicstyles', 'button', 'panelbutton', 'panel', 'floatpanel', 'colorbutton', 'dialogui', 'enterkey', 'entities', 'fakeobjects', 'floatingspace', 'listblock', 'richcombo', 'font', 'indent', 'indentblock', 'indentlist', 'justify', 'list', 'magicline', 'dialog', 'clipboard', 'pastetext', 'pbckcode', 'removeformat', 'sourcearea', 'toolbar', 'undo', 'wysiwygarea', 'ipsattach', 'ipsautolink', 'ipsemoticon', 'ipsimage', 'ipslink', 'ipsmentions', 'ipsquote', 'ipsspoiler', 'ipsprefs' ), explode( ',', \IPS\Settings::i()->ckeditor_extraPlugins ) );
$missing = array_diff( $required, $current );
if ( count( $missing ) > 0 )
{
\IPS\Output::i()->error( \IPS\Member::loggedIn()->language()->addToStack( 'editor_missing_requirements', FALSE, array( 'sprintf' => array( count( $missing ), implode( ', ', $missing ) ) ) ), '2C120/5', 404, '' );
}
}
/* Save */
$extraPlugins = explode( ',', \IPS\Settings::i()->ckeditor_extraPlugins );
$extraPlugins[] = $name;
\IPS\Db::i()->update( 'core_sys_conf_settings', array( 'conf_value' => implode( ',', array_filter( array_unique( $extraPlugins ) ) ) ), array( 'conf_key=?', 'ckeditor_extraPlugins' ) );
unset( \IPS\Data\Store::i()->settings );
/* Clear guest page caches */
\IPS\Data\Cache::i()->clearAll();
/* Redirect */
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=editor&controller=toolbar' ), 'saved' );
}
}
/* If this is an AJAX request, just return it */
if( \IPS\Request::i()->isAjax() )
{
if ( \IPS\Request::i()->existing )
{
\IPS\Output::i()->output = $form;
return;
}
}
/* Display */
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('editor_new_plugin');
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global' )->tabs( array( 'ckeditor' => \IPS\Member::loggedIn()->language()->addToStack('editor_button_ckeditor'), 'custom' => \IPS\Member::loggedIn()->language()->addToStack('editor_button_custom') ), \IPS\Request::i()->tab ?: 'ckeditor', $form, \IPS\Http\Url::internal( "app=core&module=editor&controller=toolbar&do=addPlugin&existing=1" ) );
}
/**
* Save custom plugin
*
* @param string $key The key
* @param array $values Values from form
* @return void
*/
protected function _saveCustomPlugin( $key, $values )
{
/* Work out the plugin file contents */
if ( $values['editor_button_type'] === 'block' or $values['editor_button_type'] === 'singleblock' )
{
if ( !preg_match( '/^<(.+?)([^>]*?)>(.*?)<\/\1>$/s', trim( $values['editor_button_html'] ), $matches ) )
{
$values['editor_button_html'] = "<div>{$values['editor_button_html']}</div>";
preg_match( '/^<(.+?)([^>]*?)>(.*?)<\/\1>$/s', trim( $values['editor_button_html'] ), $matches );
}
$attributes = array();
if ( $matches[2] )
{
preg_match_all( '/(.+?)=([\'"])(.+?)\\2/', trim( $matches[2] ), $attribMatches );
foreach ( $attribMatches[1] as $k => $v )
{
$attributes[ trim( $v ) ] = $attribMatches[3][ $k ];
}
}
/* Figure out css classes */
$cssClasses = array();
preg_match_all( '/class=([\'"])(.+?)\\1/i', trim( $matches[0] ), $cssMatches );
if( $cssMatches[2] )
{
foreach ( $cssMatches[2] as $match )
{
$classes = explode( ' ', $match );
$cssClasses = array_merge( $cssClasses, $classes );
}
}
/* Automatically detect and allow custom css classes */
if( count( $cssClasses ) )
{
$settingClasses = \IPS\Settings::i()->editor_allowed_classes ? explode( ',', \IPS\Settings::i()->editor_allowed_classes ) : array();
$settingClasses = array_unique( array_merge( $settingClasses, $cssClasses ) );
\IPS\Db::i()->update( 'core_sys_conf_settings', array( 'conf_value' => implode( ',', $settingClasses ) ), array( 'conf_key=?', 'editor_allowed_classes' ) );
unset( \IPS\Data\Store::i()->settings );
}
/* Figure out data-controllers classes */
$dataControllers = array();
preg_match_all( '/data-controller=([\'"])(.+?)\\1/i', trim( $matches[0] ), $controllerMatches );
if( $controllerMatches[2] )
{
foreach ( $controllerMatches[2] as $match )
{
$controllers = array_map( 'trim', explode( ',', $match ) );
$dataControllers = array_merge( $dataControllers, $controllers );
}
}
/* Automatically detect and allow custom css classes */
if( count( $dataControllers ) )
{
$settingControllers = \IPS\Settings::i()->editor_allowed_datacontrollers ? explode( ',', \IPS\Settings::i()->editor_allowed_datacontrollers ) : array();
$settingControllers = array_unique( array_merge( $settingControllers, $dataControllers ) );
\IPS\Db::i()->update( 'core_sys_conf_settings', array( 'conf_value' => implode( ',', $settingControllers ) ), array( 'conf_key=?', 'editor_allowed_datacontrollers' ) );
unset( \IPS\Data\Store::i()->settings );
}
$attributes = json_encode( $attributes );
$contentPos = mb_strpos( $matches[3], '{content}' );
if ( $contentPos === FALSE )
{
$before = json_encode( $matches[3] );
$content = 'false';
$after = '""';
}
else
{
$before = json_encode( mb_substr( $matches[3], 0, $contentPos ) );
$content = 'true';
$after = json_encode( mb_substr( $matches[3], $contentPos + 9 ) );
}
$dialogFile = NULL;
$dialogLine = '';
if ( $values['editor_button_option_on'] )
{
\IPS\Lang::saveCustom( 'core', "editoroption_{$key}", $values['editor_button_option_label'], TRUE );
$command = "new CKEDITOR.dialogCommand( '{$key}' )";
$dialogLine = "CKEDITOR.dialog.add( '{$key}', this.path + 'dialogs/{$key}.js' );";
$dialogFile = <<<JS
CKEDITOR.dialog.add( '{$key}', function( editor ) {
return {
title: ips.getString('editorbutton_{$key}'),
minWidth: 400,
minHeight: 200,
contents: [
{
id: 'tab',
label: ips.getString('editorbutton_{$key}'),
elements: [
{
type: 'text',
id: 'option',
label: ips.getString('editoroption_{$key}')
}
]
}
],
onOk: function() {
var cmd = ips.utils.defaultEditorPlugins.{$values['editor_button_type']}( '{$key}', '{$matches[1]}', {$attributes}, {$before}, {$content}, {$after}, this.getValueOf( 'tab', 'option' ) );
cmd.exec( editor );
}
};
});
JS;
}
else
{
$command = "ips.utils.defaultEditorPlugins.{$values['editor_button_type']}( '{$key}', '{$matches[1]}', {$attributes}, {$before}, {$content}, {$after} )";
}
$pluginFile = <<<JS
(function() {
CKEDITOR.plugins.add( '{$key}', {
icons: '{$key}',
init: function( editor ) {
editor.addCommand( '{$key}', {$command} );
editor.ui.addButton && editor.ui.addButton( '{$key}', {
label: ips.getString('editorbutton_{$key}'),
command: '{$key}',
toolbar: ''
});
{$dialogLine}
}
});
})();
JS;
}
else
{
$dialogLine = '';
$dialogFile = NULL;
$html = json_encode( $values['editor_button_html'] );
if ( $values['editor_button_option_on'] )
{
\IPS\Lang::saveCustom( 'core', "editoroption_{$key}", $values['editor_button_option_label'], TRUE );
$command = "new CKEDITOR.dialogCommand( '{$key}' )";
$dialogLine = "CKEDITOR.dialog.add( '{$key}', this.path + 'dialogs/{$key}.js' );";
$dialogFile = <<<JS
CKEDITOR.dialog.add( '{$key}', function( editor ) {
return {
title: ips.getString('editorbutton_{$key}'),
minWidth: 400,
minHeight: 200,
contents: [
{
id: 'tab',
label: ips.getString('editorbutton_{$key}'),
elements: [
{
type: 'text',
id: 'option',
label: ips.getString('editoroption_{$key}')
}
]
}
],
onOk: function() {
var cmd = ips.utils.defaultEditorPlugins.inline( '{$key}', {$html}.replace( '{option}', this.getValueOf( 'tab', 'option' ) ) );
cmd.exec( editor );
}
};
});
JS;
}
else
{
$command = "ips.utils.defaultEditorPlugins.inline( '{$key}', {$html} )";
}
$pluginFile = <<<JS
(function() {
CKEDITOR.plugins.add( '{$key}', {
icons: '{$key}',
init: function( editor ) {
editor.addCommand( '{$key}', {$command} );
editor.ui.addButton && editor.ui.addButton( '{$key}', {
label: ips.getString('editorbutton_{$key}'),
command: '{$key}',
toolbar: ''
});
{$dialogLine}
}
});
})();
JS;
}
/* Write it */
$dir = \IPS\ROOT_PATH . '/applications/core/interface/ckeditor/ckeditor/plugins/' . $key;
if ( !is_dir( $dir ) )
{
mkdir( $dir );
chmod( $dir, \IPS\IPS_FOLDER_PERMISSION );
}
\file_put_contents( $dir . '/plugin.js', $pluginFile );
if ( $values['editor_button_image'] )
{
if ( !is_dir( $dir . '/icons' ) )
{
mkdir( $dir . '/icons' );
chmod( $dir . '/icons', \IPS\IPS_FOLDER_PERMISSION );
}
\file_put_contents( "{$dir}/icons/{$key}.png", file_get_contents( $values['editor_button_image'] ) );
}
if ( $dialogFile )
{
if ( !is_dir( $dir . '/dialogs' ) )
{
mkdir( $dir . '/dialogs' );
chmod( $dir . '/dialogs', \IPS\IPS_FOLDER_PERMISSION );
}
\file_put_contents( "{$dir}/dialogs/{$key}.js", $dialogFile );
}
/* Save name */
\IPS\Lang::saveCustom( 'core', "editorbutton_{$key}", $values['editor_button_name'], TRUE );
}
/**
* Delete Plugin
*
* @return void
*/
public function deletePlugin()
{
/* Check */
if ( \IPS\IN_DEV )
{
\IPS\Output::i()->error( 'editor_in_dev', '1C120/4', 403, '' );
}
if ( \IPS\NO_WRITES )
{
\IPS\Output::i()->error( 'no_writes', '1C120/3', 403, '' );
}
/* Check it's not required for something else */
foreach ( new \DirectoryIterator( \IPS\ROOT_PATH . '/applications/core/interface/ckeditor/ckeditor/plugins' ) as $file )
{
if ( $file->isDir() and mb_substr( $file, 0, 1 ) !== '.' and file_exists( \IPS\ROOT_PATH . '/applications/core/interface/ckeditor/ckeditor/plugins/' . $file . '/plugin.js' ) )
{
$jsFile = file_get_contents( \IPS\ROOT_PATH . '/applications/core/interface/ckeditor/ckeditor/plugins/' . $file . '/plugin.js' );
if ( preg_match( '/requires:\"(.+?)\"/i', $jsFile, $matches ) )
{
if ( in_array( mb_strtolower( \IPS\Request::i()->key ), explode( ',', mb_strtolower( $matches[1] ) ) ) )
{
\IPS\Output::i()->error( \IPS\Member::loggedIn()->language()->addToStack( 'editor_plugin_requirements', FALSE, array( 'sprintf' => array( $file ) ) ), '1C120/3', 403, '' );
}
}
}
}
/* Delete it */
$key = \IPS\Request::i()->key;
$dir = \IPS\ROOT_PATH . '/applications/core/interface/ckeditor/ckeditor/plugins/' . $key;
if ( is_dir( $dir ) )
{
$this->_recursiveDelete( $dir );
}
/* Remove from plugin list */
$extraPlugins = explode( ',', \IPS\Settings::i()->ckeditor_extraPlugins );
foreach ( $extraPlugins as $k => $v )
{
if ( $v == $key )
{
unset( $extraPlugins[ $k ] );
}
}
\IPS\Db::i()->update( 'core_sys_conf_settings', array( 'conf_value' => implode( ',', array_filter( array_unique( $extraPlugins ) ) ) ), array( 'conf_key=?', 'ckeditor_extraPlugins' ) );
unset( \IPS\Data\Store::i()->settings );
/* Clear guest page caches */
\IPS\Data\Cache::i()->clearAll();
/* Redirect */
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=core&module=editor&controller=toolbar' ), 'saved' );
}
/**
* Recursive delete
*
* @param string $dir Directory
* @return void
*/
protected function _recursiveDelete( $dir )
{
foreach ( new \DirectoryIterator( $dir ) as $file )
{
if ( !$file->isDot() )
{
if ( $file->isDir() )
{
$this->_recursiveDelete( $file->getPathname() );
}
else
{
unlink( $file->getPathname() );
}
}
}
$handle = opendir( $dir );
closedir ( $handle );
rmdir( $dir );
}
/**
* Revert Editor back to default
*
* @return void
*/
public function revert()
{
if ( !empty( \IPS\Settings::i()->ckeditor_extraPlugins ) and !\IPS\NO_WRITES )
{
$extraPlugins = explode( ',', \IPS\Settings::i()->ckeditor_extraPlugins );
$dir = \IPS\ROOT_PATH . '/applications/core/interface/ckeditor/ckeditor/plugins/';
foreach( $extraPlugins AS $key )
{
if ( is_dir( $dir . $key ) )
{
$this->_recursiveRmDir( $dir . $key );
}
}
\IPS\Db::i()->update( 'core_sys_conf_settings', array( 'conf_value' => '' ), array( 'conf_key=?', 'ckeditor_extraPlugins' ) );
}
\IPS\Db::i()->update( 'core_sys_conf_settings', array( 'conf_value' => '' ), array( 'conf_key=?', 'ckeditor_toolbars' ) );
unset( \IPS\Data\Store::i()->settings );
/* Clear guest page caches */
\IPS\Data\Cache::i()->clearAll();
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=core&module=editor&controller=toolbar" ), 'saved' );
}
/**
* Recursive Subdirectory Removal
*
* @param $dir The directory
* @return void
*/
protected function _recursiveRmDir( $dir )
{
if ( is_dir( $dir ) )
{
foreach( new \GlobIterator( $dir . '/*' ) AS $file )
{
if ( $file->isDir() )
{
$this->_recursiveRmDir( $dir . '/' . $file->getFilename() );
}
else
{
@unlink( $dir . '/' . $file->getFilename() );
}
}
$handle = opendir( $dir );
closedir ( $handle );
@rmdir( $dir );
}
}
}