'cols' => '80',
'rows' => '8',
'onkeyup' => "return verify(this)",
- 'class' => 'crm-wysiwyg-fullpage',
+ 'preset' => 'civimail',
)
);
}
*/
class CRM_Admin_Page_CKEditorConfig extends CRM_Core_Page {
- const CONFIG_FILENAME = '[civicrm.files]/persist/crm-ckeditor-config.js';
+ const CONFIG_FILEPATH = '[civicrm.files]/persist/crm-ckeditor-';
/**
* Settings that cannot be configured in "advanced options"
'filebrowserFlashUploadUrl',
);
+ public $preset;
+
/**
* Run page.
*
* @return string
*/
public function run() {
+ $this->preset = CRM_Utils_Array::value('preset', $_REQUEST, 'default');
+
// If the form was submitted, take appropriate action.
if (!empty($_POST['revert'])) {
- self::deleteConfigFile();
+ self::deleteConfigFile($this->preset);
}
elseif (!empty($_POST['config'])) {
$this->save($_POST);
'settings' => $settings,
));
+ $configUrl = self::getConfigUrl($this->preset);
+ if (!$configUrl) {
+ $configUrl = self::getConfigUrl('default');
+ }
+
+ $this->assign('preset', $this->preset);
+ $this->assign('presets', CRM_Core_OptionGroup::values('wysiwyg_presets', FALSE, FALSE, FALSE, NULL, 'label', TRUE, FALSE, 'name'));
$this->assign('skins', $this->getCKSkins());
$this->assign('skin', CRM_Utils_Array::value('skin', $settings));
$this->assign('extraPlugins', CRM_Utils_Array::value('extraPlugins', $settings));
- $this->assign('configUrl', self::getConfigUrl());
+ $this->assign('configUrl', $configUrl);
$this->assign('revertConfirm', htmlspecialchars(ts('Are you sure you want to revert all changes?', array('escape' => 'js'))));
CRM_Utils_System::appendBreadCrumb(array(array(
$config = substr_replace($config, $setting, $pos, 0);
}
}
- self::saveConfigFile($config);
+ self::saveConfigFile($this->preset, $config);
if (!empty($params['save'])) {
CRM_Core_Session::setStatus(ts("You may need to clear your browser's cache to see the changes in CiviCRM."), ts('CKEditor Saved'), 'success');
}
*/
private function getConfigSettings() {
$matches = $result = array();
- $file = self::getConfigFile();
+ $file = self::getConfigFile($this->preset);
$result['skin'] = 'moono';
if ($file) {
$contents = file_get_contents($file);
}
/**
- * @return null|string
+ * @param string $preset
+ * Omit to get an array of all presets
+ * @return array|null|string
*/
- public static function getConfigUrl() {
- if (self::getConfigFile()) {
- return Civi::paths()->getUrl(self::CONFIG_FILENAME, 'absolute');
+ public static function getConfigUrl($preset = NULL) {
+ $items = array();
+ $presets = CRM_Core_OptionGroup::values('wysiwyg_presets', FALSE, FALSE, FALSE, NULL, 'name');
+ foreach ($presets as $key => $name) {
+ if (self::getConfigFile($name)) {
+ $items[$name] = Civi::paths()->getUrl(self::CONFIG_FILEPATH . $name . '.js', 'absolute');
+ }
}
- return NULL;
+ return $preset ? CRM_Utils_Array::value($preset, $items) : $items;
}
/**
- * @param bool $checkIfFileExists
- * If false, this fn will return fileName even if it doesn't exist
+ * @param string $preset
*
* @return null|string
*/
- public static function getConfigFile($checkIfFileExists = TRUE) {
- $fileName = Civi::paths()->getPath(self::CONFIG_FILENAME);
- return !$checkIfFileExists || is_file($fileName) ? $fileName : NULL;
+ public static function getConfigFile($preset = 'default') {
+ $fileName = Civi::paths()->getPath(self::CONFIG_FILEPATH . $preset . '.js');
+ return is_file($fileName) ? $fileName : NULL;
}
/**
* @param string $contents
*/
- public static function saveConfigFile($contents) {
- $file = self::getConfigFile(FALSE);
+ public static function saveConfigFile($preset, $contents) {
+ $file = Civi::paths()->getPath(self::CONFIG_FILEPATH . $preset . '.js');
file_put_contents($file, $contents);
}
/**
* Delete config file.
*/
- public static function deleteConfigFile() {
- $file = self::getConfigFile();
+ public static function deleteConfigFile($preset) {
+ $file = self::getConfigFile($preset);
if ($file) {
unlink($file);
}
if ($type == 'wysiwyg' || in_array($type, self::$html5Types)) {
$attributes = ($attributes ? $attributes : array()) + array('class' => '');
$attributes['class'] = ltrim($attributes['class'] . " crm-form-$type");
+ if ($type == 'wysiwyg' && isset($attributes['preset'])) {
+ $attributes['data-preset'] = $attributes['preset'];
+ unset($attributes['preset']);
+ }
$type = $type == 'wysiwyg' ? 'textarea' : 'text';
}
// @see http://wiki.civicrm.org/confluence/display/CRMDOC/crmDatepicker
$editor = Civi::settings()->get('editor_id');
if ($editor == "CKEditor") {
$items[] = "js/wysiwyg/crm.ckeditor.js";
- $ckConfig = CRM_Admin_Page_CKEditorConfig::getConfigUrl();
- if ($ckConfig) {
- $items[] = array('config' => array('CKEditorCustomConfig' => $ckConfig));
- }
+ $items[] = array('config' => array('CKEditorCustomConfig' => CRM_Admin_Page_CKEditorConfig::getConfigUrl()));
}
// These scripts are only needed by back-office users
$this->addSelect('participant_listing_id', array('placeholder' => ts('Disabled'), 'option_url' => NULL));
$this->add('textarea', 'summary', ts('Event Summary'), $attributes['summary']);
- $this->add('wysiwyg', 'description', ts('Complete Description'), $attributes['event_description']);
+ $this->add('wysiwyg', 'description', ts('Complete Description'), $attributes['event_description'] + array('preset' => 'civievent'));
$this->addElement('checkbox', 'is_public', ts('Public Event'));
$this->addElement('checkbox', 'is_share', ts('Allow sharing through social media?'));
$this->addElement('checkbox', 'is_map', ts('Include Map to Event Location'));
*
*/
public function buildRegistrationBlock(&$form) {
- $attributes = CRM_Core_DAO::getAttribute('CRM_Event_DAO_Event', 'intro_text') + array('class' => 'collapsed');
+ $attributes = CRM_Core_DAO::getAttribute('CRM_Event_DAO_Event', 'intro_text') + array('class' => 'collapsed', 'preset' => 'civievent');
$form->add('wysiwyg', 'intro_text', ts('Introductory Text'), $attributes);
$form->add('wysiwyg', 'footer_text', ts('Footer Text'), $attributes);
$form->addYesNo('is_confirm_enabled', ts('Use a confirmation screen?'), NULL, NULL, array('onclick' => "return showHideByValue('is_confirm_enabled','','confirm_screen_settings','block','radio',false);"));
}
$form->add('text', 'confirm_title', ts('Title'), $attributes['confirm_title']);
- $form->add('wysiwyg', 'confirm_text', ts('Introductory Text'), $attributes['confirm_text'] + array('class' => 'collapsed'));
- $form->add('wysiwyg', 'confirm_footer_text', ts('Footer Text'), $attributes['confirm_text'] + array('class' => 'collapsed'));
+ $form->add('wysiwyg', 'confirm_text', ts('Introductory Text'), $attributes['confirm_text'] + array('class' => 'collapsed', 'preset' => 'civievent'));
+ $form->add('wysiwyg', 'confirm_footer_text', ts('Footer Text'), $attributes['confirm_text'] + array('class' => 'collapsed', 'preset' => 'civievent'));
}
/**
public function buildThankYouBlock(&$form) {
$attributes = CRM_Core_DAO::getAttribute('CRM_Event_DAO_Event');
$form->add('text', 'thankyou_title', ts('Title'), $attributes['thankyou_title']);
- $form->add('wysiwyg', 'thankyou_text', ts('Introductory Text'), $attributes['thankyou_text'] + array('class' => 'collapsed'));
- $form->add('wysiwyg', 'thankyou_footer_text', ts('Footer Text'), $attributes['thankyou_text'] + array('class' => 'collapsed'));
+ $form->add('wysiwyg', 'thankyou_text', ts('Introductory Text'), $attributes['thankyou_text'] + array('class' => 'collapsed', 'preset' => 'civievent'));
+ $form->add('wysiwyg', 'thankyou_footer_text', ts('Footer Text'), $attributes['thankyou_text'] + array('class' => 'collapsed', 'preset' => 'civievent'));
}
/**
$this->addTask('Add column to allow for payment processors to set what card types are accepted', 'addAcceptedCardTypesField');
}
+ /**
+ * Upgrade function.
+ *
+ * @param string $rev
+ */
+ public function upgrade_4_7_14($rev) {
+ $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev);
+ $this->addTask('Add WYSIWYG Editor Presets', 'addWysiwygPresets');
+ }
/*
* Important! All upgrade functions MUST add a 'runSql' task.
return TRUE;
}
+ /**
+ * CRM-19372 Add field to store accepted credit credit cards for a payment processor.
+ * @return bool
+ */
+ public static function addWysiwygPresets() {
+ CRM_Core_BAO_OptionGroup::ensureOptionGroupExists(array(
+ 'name' => 'wysiwyg_presets',
+ 'title' => ts('WYSIWYG Editor Presets'),
+ 'is_reserved' => 1,
+ ));
+ $values = array(
+ 'default' => array('label' => ts('Default'), 'is_default' => 1),
+ 'civimail' => array('label' => ts('CiviMail'), 'component_id' => 'CiviMail'),
+ 'civievent' => array('label' => ts('CiviEvent'), 'component_id' => 'CiviEvent'),
+ );
+ foreach ($values as $name => $value) {
+ civicrm_api3('OptionValue', 'create', $value + array(
+ 'options' => array('match' => array('name', 'option_group_id')),
+ 'name' => $name,
+ 'option_group_id' => 'wysiwyg_presets',
+ ));
+ }
+ $fileName = Civi::paths()->getPath('[civicrm.files]/persist/crm-ckeditor-config.js');
+ if (file_exists($fileName)) {
+ $config = file_get_contents($fileName);
+ $pos = strrpos($config, '};');
+ $setting = "\n\tconfig.allowedContent = true;\n";
+ $config = substr_replace($config, $setting, $pos, 0);
+ unlink($fileName);
+ }
+ else {
+ $config = "CKEDITOR.editorConfig = function( config ) {\n\tconfig.allowedContent = true;\n};\n";
+ }
+ $newFileName = Civi::paths()->getPath('[civicrm.files]/persist/crm-ckeditor-default.js');
+ file_put_contents($newFileName, $config);
+ return TRUE;
+ }
+
}
crm-ui-insert-rx="insert:body_html"
ng-model="mailing.body_html"
ng-blur="checkTokens(mailing, 'body_html', 'insert:body_html')"
- class="crm-wysiwyg-fullpage"
+ data-preset="civimail"
></textarea>
<span ng-model="body_html_tokens" crm-ui-validate="hasAllTokens(mailing, 'body_html')"></span>
<div ng-show="htmlForm.$error.crmUiValidate" class="crmMailing-error-link">
function initialize() {
var
browseUrl = CRM.config.resourceBase + "packages/kcfinder/browse.php?cms=civicrm",
- uploadUrl = CRM.config.resourceBase + "packages/kcfinder/upload.php?cms=civicrm";
+ uploadUrl = CRM.config.resourceBase + "packages/kcfinder/upload.php?cms=civicrm",
+ preset = $(item).data('preset') || 'default',
+ // This variable is always an array but a legacy extension could be setting it as a string.
+ customConfig = (typeof CRM.config.CKEditorCustomConfig === 'string') ? CRM.config.CKEditorCustomConfig :
+ (CRM.config.CKEditorCustomConfig[preset] || CRM.config.CKEditorCustomConfig.default);
$(item).addClass('crm-wysiwyg-enabled');
- var isFullPage = $(item).hasClass('crm-wysiwyg-fullpage');
-
CKEDITOR.replace($(item)[0], {
filebrowserBrowseUrl: browseUrl + '&type=files',
filebrowserImageBrowseUrl: browseUrl + '&type=images',
filebrowserUploadUrl: uploadUrl + '&type=files',
filebrowserImageUploadUrl: uploadUrl + '&type=images',
filebrowserFlashUploadUrl: uploadUrl + '&type=flash',
- allowedContent: true, // For CiviMail!
- fullPage: isFullPage,
- customConfig: CRM.config.CKEditorCustomConfig,
+ customConfig: customConfig,
on: {
instanceReady: onReady
}
#crm-custom-config-options > div {
margin: .5em .2em;
}
+ #crm-container .ui-tabs-nav {
+ padding-bottom: 0;
+ }
+ #crm-container .ui-tabs-nav li {
+ margin-left: .3em;
+ }
+ #crm-container .ui-tabs-nav a {
+ font-size: 1.1em;
+ border-bottom: 0 none;
+ padding: 3px 10px 1px !important;
+ }
{/literal}</style>
{* Force the custom config file to reload by appending a new query string *}
<script type="text/javascript">
{if $configUrl}CKEDITOR.config.customConfig = '{$configUrl}?{php}print str_replace(array(' ', '.'), array('', '='), microtime());{/php}'{/if};
</script>
+<div class="ui-tabs">
+ <ul class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header">
+ <li>{ts}Preset:{/ts}</li>
+ {foreach from=$presets key='k' item='p'}
+ <li class="ui-tabs-tab ui-corner-top ui-state-default ui-tab {if $k == $preset}ui-tabs-active ui-state-active{/if}">
+ <a class="ui-tabs-anchor" href="{crmURL q="preset=$k"}">{$p}</a>
+ </li>
+ {/foreach}
+ </ul>
+</div>
<form method="post" action="{crmURL}" id="toolbarModifierForm">
- <div class="crm-block crm-form-block">
- <label for="skin">{ts}Skin{/ts}</label>
- <select id="skin" name="config_skin" class="crm-select2 eight config-param">
- {foreach from=$skins item='s'}
- <option value="{$s}" {if $s == $skin}selected{/if}>{$s|ucfirst}</option>
- {/foreach}
- </select>
-
- <label for="extraPlugins">{ts}Plugins{/ts}</label>
- <input id="extraPlugins" name="config_extraPlugins" class="huge config-param" value="{$extraPlugins}" placeholder="{ts}Select optional extra features{/ts}">
- </div>
+ <fieldset>
+ <div class="crm-block crm-form-block">
+ <label for="skin">{ts}Skin{/ts}</label>
+ <select id="skin" name="config_skin" class="crm-select2 eight config-param">
+ {foreach from=$skins item='s'}
+ <option value="{$s}" {if $s == $skin}selected{/if}>{$s|ucfirst}</option>
+ {/foreach}
+ </select>
+
+ <label for="extraPlugins">{ts}Plugins{/ts}</label>
+ <input id="extraPlugins" name="config_extraPlugins" class="huge config-param" value="{$extraPlugins}" placeholder="{ts}Select optional extra features{/ts}">
+ </div>
- <div class="editors-container">
- <div id="editor-basic"></div>
- <div id="editor-advanced"></div>
- </div>
+ <div class="editors-container">
+ <div id="editor-basic"></div>
+ <div id="editor-advanced"></div>
+ </div>
- <div class="configurator">
- <div>
- <div id="toolbarModifierWrapper" class="active"></div>
+ <div class="configurator">
+ <div>
+ <div id="toolbarModifierWrapper" class="active"></div>
+ </div>
</div>
- </div>
- <div class="crm-block crm-form-block">
- <fieldset>
- <legend>{ts}Advanced Options{/ts}</legend>
- <div class="description">{ts 1='href="http://docs.ckeditor.com/#!/api/CKEDITOR.config" target="_blank"'}Refer to the <a %1>CKEditor Api Documentation</a> for details.{/ts}</div>
- <div id="crm-custom-config-options"></div>
- </fieldset>
- </div>
+ <div class="crm-block crm-form-block">
+ <fieldset>
+ <legend>{ts}Advanced Options{/ts}</legend>
+ <div class="description">{ts 1='href="http://docs.ckeditor.com/#!/api/CKEDITOR.config" target="_blank"'}Refer to the <a %1>CKEditor Api Documentation</a> for details.{/ts}</div>
+ <div id="crm-custom-config-options"></div>
+ </fieldset>
+ </div>
- <div class="crm-submit-buttons">
- <span class="crm-button crm-i-button">
- <i class="crm-i fa-wrench"></i> <input type="submit" value="{ts}Save{/ts}" name="save" class="crm-form-submit" accesskey="S"/>
- </span>
- <span class="crm-button crm-i-button">
- <i class="crm-i fa-times"></i> <input type="submit" value="{ts}Revert to Default{/ts}" name="revert" class="crm-form-submit" onclick="return confirm('{$revertConfirm}');"/>
- </span>
- </div>
+ <div class="crm-submit-buttons">
+ <span class="crm-button crm-i-button">
+ <i class="crm-i fa-wrench"></i> <input type="submit" value="{ts}Save{/ts}" name="save" class="crm-form-submit" accesskey="S"/>
+ </span>
+ <span class="crm-button crm-i-button">
+ <i class="crm-i fa-times"></i> <input type="submit" value="{ts}Revert to Default{/ts}" name="revert" class="crm-form-submit" onclick="return confirm('{$revertConfirm}');"/>
+ </span>
+ </div>
+ <input type="hidden" value="{$preset}" name="preset" />
+ </fieldset>
</form>
<script type="text/template" id="config-row-tpl">
<div class="crm-config-option-row">
('communication_style' , '{ts escape="sql"}Communication Style{/ts}' , NULL, 1, 1, 0),
('msg_mode' , '{ts escape="sql"}Message Mode{/ts}' , NULL, 1, 1, 0),
('contact_date_reminder_options' , '{ts escape="sql"}Contact Date Reminder Options{/ts}' , NULL, 1, 1, 1),
+ ('wysiwyg_presets' , '{ts escape="sql"}WYSIWYG Editor Presets{/ts}' , NULL, 1, 1, 0),
('relative_date_filters' , '{ts escape="sql"}Relative Date Filters{/ts}' , NULL, 1, 1, 0);
SELECT @option_group_id_pcm := max(id) from civicrm_option_group where name = 'preferred_communication_method';
SELECT @option_group_id_msg_mode := max(id) from civicrm_option_group where name = 'msg_mode';
SELECT @option_group_id_contactDateMode := max(id) from civicrm_option_group where name = 'contact_date_reminder_options';
SELECT @option_group_id_date_filter := max(id) from civicrm_option_group where name = 'relative_date_filters';
+SELECT @option_group_id_wysiwyg_presets := max(id) from civicrm_option_group where name = 'wysiwyg_presets';
SELECT @contributeCompId := max(id) FROM civicrm_component where name = 'CiviContribute';
SELECT @eventCompId := max(id) FROM civicrm_component where name = 'CiviEvent';
(@option_group_id_contactDateMode, '{ts escape="sql"}Actual date only{/ts}', '1', 'Actual date only', NULL, NULL, 0, 1, NULL, 0, 1, 1, NULL, NULL),
(@option_group_id_contactDateMode, '{ts escape="sql"}Each anniversary{/ts}', '2', 'Each anniversary', NULL, NULL, 0, 2, NULL, 0, 1, 1, NULL, NULL),
+-- WYSIWYG Editor Presets
+(@option_group_id_wysiwyg_presets, '{ts escape="sql"}Default{/ts}', '1', 'default', NULL, NULL, 1, 1, NULL, 0, 1, 1, NULL, NULL),
+(@option_group_id_wysiwyg_presets, '{ts escape="sql"}CiviMail{/ts}', '2', 'civimail', NULL, NULL, 0, 2, NULL, 0, 1, 1, @contributeCompId, NULL),
+(@option_group_id_wysiwyg_presets, '{ts escape="sql"}CiviEvent{/ts}', '3', 'civievent', NULL, NULL, 0, 3, NULL, 0, 1, 1, @eventCompId, NULL),
+
-- Relative Date Filters
(@option_group_id_date_filter, '{ts escape="sql"}Today{/ts}', 'this.day', 'this.day', NULL, NULL, NULL,1, NULL, 0, 0, 1, NULL, NULL),
(@option_group_id_date_filter, '{ts escape="sql"}This week{/ts}', 'this.week', 'this.week', NULL, NULL, NULL,2, NULL, 0, 0, 1, NULL, NULL),