Skip to content

Commit

Permalink
Adds CKEditor custom style, paragraph format, & font name dropdown li…
Browse files Browse the repository at this point in the history
…sts. Also provides a better implementation of displaying the theme style inside the editor itself, inlcuding the auto-additon of theme based styles parsed fro the editor stylesheet. simpletheme and simpletheme Fall editor stylesheets included. still need editor stylesheets for other included themes. [#411 #412]
  • Loading branch information
dleffler committed Jan 5, 2012
1 parent 064c4a7 commit 8ebaa02
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 78 deletions.
29 changes: 20 additions & 9 deletions framework/core/controllers/expHTMLEditorController.php
Expand Up @@ -30,11 +30,14 @@ function description() { return "Mostly for CKEditor"; }
function author() { return "Phillip Ball"; }
function hasSources() { return false; }
function hasContent() { return false; }
protected $add_permissions = array('activate'=>"activate",'preview'=>"preview CKEditor toolbars");
protected $add_permissions = array(
'activate'=>"activate",
'preview'=>"preview CKEditor toolbars"
);

function manage () {
global $db;
// yet more gluecode

if (SITE_WYSIWYG_EDITOR=="FCKeditor") {
flash('error',gt('FCKeditor is deprecated!'));
redirect_to(array("module"=>"administration","action"=>"configure_site"));
Expand All @@ -48,15 +51,19 @@ function manage () {

function update () {
global $db;

$obj = $db->selectObject('htmleditor_ckeditor',"id=".$this->params['id']);
$obj->name = $this->params['name'];
$obj->data = stripSlashes($this->params['data']);
$obj->skin = $this->params['skin'];
$obj->scayt_on = $this->params['scayt_on'];
$obj->paste_word = $this->params['paste_word'];
$obj->plugins = stripSlashes($this->params['plugins']);
$obj->stylesset = stripSlashes($this->params['stylesset']);
$obj->formattags = stripSlashes($this->params['formattags']);
$obj->fontnames = stripSlashes($this->params['fontnames']);
if (empty($this->params['id'])) {
$db->insertObject($obj,'htmleditor_ckeditor');
$this->params['id'] = $db->insertObject($obj,'htmleditor_ckeditor');
} else {
$db->updateObject($obj,'htmleditor_ckeditor',null,'id');
}
Expand All @@ -68,17 +75,22 @@ function update () {

function edit() {
global $db;

expHistory::set('editable', $this->params);
$tool = @$db->selectObject('htmleditor_ckeditor',"id=".$this->params['id']);
$tool->data = @stripSlashes($tool->data);
$tool->plugins = @stripSlashes($tool->plugins);
$tool->stylesset = @stripSlashes($tool->stylesset);
$tool->formattags = @stripSlashes($tool->formattags);
$tool->fontnames = @stripSlashes($tool->fontnames);
assign_to_template(array('record'=>$tool));
}

function delete() {
global $db;

expHistory::set('editable', $this->params);
@$db->delete('htmleditor_ckeditor',"id=".$this->params['id']);

expHistory::returnTo('manageable');
}

Expand All @@ -89,19 +101,18 @@ function activate () {
if ($this->params['id']!="default") {
$active = $db->selectObject('htmleditor_ckeditor',"id=".$this->params['id']);
$active->active = 1;

$db->updateObject($active,'htmleditor_ckeditor',null,'id');
}

expHistory::returnTo('manageable');
}

function preview () {
global $db;
if ($this->params['id']=="default") {

if ($this->params['id']==0) { // we want the default editor
$demo->id=0;
$demo->name="Default";
$demo->data="default";
$demo->skin = 'kama';
$demo->skin='kama';
} else {
$demo = $db->selectObject('htmleditor_ckeditor',"id=".$this->params['id']);
}
Expand Down
11 changes: 10 additions & 1 deletion framework/core/definitions/htmleditor_ckeditor.php
Expand Up @@ -41,7 +41,16 @@
'paste_word'=>array(
DB_FIELD_TYPE=>DB_DEF_BOOLEAN),
'active'=>array(
DB_FIELD_TYPE=>DB_DEF_BOOLEAN)
DB_FIELD_TYPE=>DB_DEF_BOOLEAN),
'stylesset'=>array(
DB_FIELD_TYPE=>DB_DEF_STRING,
DB_FIELD_LEN=>255),
'formattags'=>array(
DB_FIELD_TYPE=>DB_DEF_STRING,
DB_FIELD_LEN=>255),
'fontnames'=>array(
DB_FIELD_TYPE=>DB_DEF_STRING,
DB_FIELD_LEN=>255),
);

?>
112 changes: 67 additions & 45 deletions framework/core/subsystems/forms/controls/ckeditorcontrol.php
Expand Up @@ -45,67 +45,89 @@ function __construct ($default="",$rows = 5,$cols = 45) {

function controlToHTML($name) {
global $db;
$toolbar = 'def';
if (empty($this->toolbar)) $toolbar = $db->selectObject('htmleditor_ckeditor','active=1');
if (empty($toolbar) || $this->toolbar=="default" || (isset($this->toolbar->data) && $this->toolbar->data=="default")) {
$tb = "
['Source','-','Preview','-','Templates'],
['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print','SpellChecker','Scayt'],
['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
'/',
['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
['NumberedList','BulletedList','-','Outdent','Indent','Blockquote','CreateDiv'],
['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
['Link','Unlink','Anchor'],
['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak','Iframe'],
'/',
['Styles','Format','Font','FontSize'],
['TextColor','BGColor'],
['Maximize', 'ShowBlocks','-','About']
";
$skin = 'kama';
$scayt_on = 'true';
$paste_word = 'forcePasteAsPlainText : true,';
$plugins = '';
} else {
// $tb = !empty($this->toolbar) ? $this->toolbar->data : $toolbar->data;
// $skin = !empty($toolbar->skin) ? $toolbar->skin : 'kama';
if (!empty($this->toolbar)) {
$tb = $this->toolbar->data;
$skin = $this->toolbar->skin;
$scayt_on = $this->toolbar->scayt_on ? 'true' : 'false';
$paste_word = $this->toolbar->paste_word ? 'pasteFromWordPromptCleanup : true,' : 'forcePasteAsPlainText : true,';
$plugins = $this->toolbar->plugins;
} else {
$tb = $toolbar->data;
$skin = $toolbar->skin;
$scayt_on = $toolbar->scayt_on ? 'true' : 'false';
$paste_word = $toolbar->paste_word ? 'pasteFromWordPromptCleanup : true,' : 'forcePasteAsPlainText : true,';
$plugins = $toolbar->plugins;

$contentCSS = '';
$cssabs = BASE.'themes/'.DISPLAY_THEME.'/editors/ckeditor/ckeditor.css';
$css = PATH_RELATIVE.'themes/'.DISPLAY_THEME.'/editors/ckeditor/ckeditor.css';
if (THEME_STYLE!="") {
$cssabs = BASE.'themes/'.DISPLAY_THEME.'/editors/ckeditor/ckeditor_'.THEME_STYLE.'.css';
$css = PATH_RELATIVE.'themes/'.DISPLAY_THEME.'/editors/ckeditor/ckeditor_'.THEME_STYLE.'.css';
}
if (is_file($cssabs)) {
$contentCSS = "contentsCss : '".$css."',";
}
if (empty($this->toolbar)) {
$settings = $db->selectObject('htmleditor_ckeditor','active=1');
} elseif ($this->toolbar!=0) {
$settings = $db->selectObject('htmleditor_ckeditor','id='.$this->toolbar);
if (!empty($settings)) {
$tb = stripSlashes($settings->data);
$skin = $settings->skin;
$scayt_on = $settings->scayt_on ? 'true' : 'false';
$paste_word = $settings->paste_word ? 'pasteFromWordPromptCleanup : true,' : 'forcePasteAsPlainText : true,';
$plugins = stripSlashes($settings->plugins);
$stylesset = stripSlashes($settings->stylesset);
$formattags = stripSlashes($settings->formattags);
$fontnames = stripSlashes($settings->fontnames);
}
}


// set defaults
if (empty($tb)) $tb = "
['Source','-','Preview','-','Templates'],
['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print','SpellChecker','Scayt'],
['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
'/',
['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
['NumberedList','BulletedList','-','Outdent','Indent','Blockquote','CreateDiv'],
['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
['Link','Unlink','Anchor'],
['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak','Iframe'],
'/',
['Styles','Format','Font','FontSize'],
['TextColor','BGColor'],
['Maximize', 'ShowBlocks','-','About']";
if (empty($skin)) $skin = 'kama';
if (empty($scayt_on)) $scayt_on = 'true';
if (empty($paste_word)) $paste_word = 'forcePasteAsPlainText : true,';
if (empty($plugins)) $plugins = '';
if (empty($stylesset)) $stylesset = "'default'";
if (empty($formattags)) $formattags = "'p;h1;h2;h3;h4;h5;h6;pre;address;div'";
if (empty($fontnames)) $fontnames = "'Arial/Arial, Helvetica, sans-serif;' +
'Comic Sans MS/Comic Sans MS, cursive;' +
'Courier New/Courier New, Courier, monospace;' +
'Georgia/Georgia, serif;' +
'Lucida Sans Unicode/Lucida Sans Unicode, Lucida Grande, sans-serif;' +
'Tahoma/Tahoma, Geneva, sans-serif;' +
'Times New Roman/Times New Roman, Times, serif;' +
'Trebuchet MS/Trebuchet MS, Helvetica, sans-serif;' +
'Verdana/Verdana, Geneva, sans-serif'";
$content = "
YUI(EXPONENT.YUI3_CONFIG).use('yui', function(Y) {
// Y.on('readyforcke', function () {
EXPONENT.editor".createValidId($name)." = CKEDITOR.replace('".createValidId($name)."',
{
skin : '".$skin."',
toolbar : [".stripSlashes($tb)."],
toolbar : [".$tb."],
".$paste_word."
scayt_autoStartup : ".$scayt_on.",
filebrowserBrowseUrl : '".makelink(array("controller"=>"file", "action"=>"picker", "ajax_action"=>1, "ck"=>1, "update"=>"fck"))."',
filebrowserWindowWidth : '640',
filebrowserWindowHeight : '480',
filebrowserWindowWidth : '800',
filebrowserWindowHeight : '600',
filebrowserLinkBrowseUrl : '".PATH_RELATIVE."external/editors/connector/CKeditor_link.php',
filebrowserLinkWindowWidth : '320',
filebrowserLinkWindowHeight : '600',
filebrowserImageBrowseLinkUrl : '".PATH_RELATIVE."external/editors/connector/CKeditor_link.php',
extraPlugins : '".$plugins."',
extraPlugins : 'stylesheetparser,autogrow,tableresize,".$plugins."',
autoGrow_maxHeight : 400,
entities_additional : '',
contentsCSS : '".THEME_RELATIVE."css/base-styles.css',
uiColor : '#dedede',
baseHref : '".URL_FULL."'
".$contentCSS."
stylesSet : ".$stylesset.",
format_tags : ".$formattags.",
font_names :
".$fontnames.",
uiColor : '#aaaaaa',
baseHref : '".URL_FULL."'
});
CKEDITOR.on( 'instanceReady', function( ev ) {
Expand Down
11 changes: 8 additions & 3 deletions framework/modules/core/views/expHTMLEditor/edit.tpl
Expand Up @@ -30,11 +30,16 @@
{control type=hidden name=id value=$record->id}
{control type=text name=name label="Configuration Name"|gettext value=$record->name}
{control type="checkbox" postfalse=1 name=active label="Make this Configuration Active?"|gettext checked=$record->active value=1}
{control type=dropdown name=skin label="Toolbar Skin"|gettext items="Kama, Office 2003, Version 2" values="kama,office2003,v2" value=$record->skin}
{control type="checkbox" postfalse=1 name=scayt_on label="Autostart SpellCheck"|gettext checked=$record->scayt_on value=1}
{control type=dropdown name=skin label="Toolbar Skin"|gettext items="Kama, Office 2003, Version 2" values="kama,office2003,v2" value=$record->skin default='kama'}
{control type="checkbox" postfalse=1 name=scayt_on label="Autostart SpellCheck"|gettext checked=$record->scayt_on value=1 checked=1}
{control type="checkbox" postfalse=1 name=paste_word label="Allow Formatted Pasting from MS Word"|gettext checked=$record->paste_word value=1}
<h3><em>({'Blank or empty entries in the following text boxes result in using the default setting'|gettext})</em></h3>
<p><em>({'Please visit the help page for entry format requirements!'|gettext})</em></p>
{control type=textarea cols=80 rows=20 name=data label="Toolbar Button Configuration"|gettext value=$record->data}
{control type=textarea cols=80 rows=2 name=plugins label="Load Custom Plugins (comma separated) MUST be installed first!"|gettext value=$record->plugins}
{control type=textarea cols=80 rows=2 name=stylesset label="Styles List (plus style sheet styles)"|gettext value=$record->stylesset}
{control type=textarea cols=80 rows=2 name=formattags label="Formats List"|gettext value=$record->formattags}
{control type=textarea cols=80 rows=2 name=fontnames label="Fonts List"|gettext value=$record->fontnames}
{control type=textarea cols=80 rows=2 name=plugins label="Load Custom Plugins (comma separated) MUST be installed first!"|gettext value=$record->plugins}
{control type=buttongroup submit="Save Toolbar"|gettext cancel="Cancel"|gettext returntype="manageable"}
{/form}
</div>
23 changes: 5 additions & 18 deletions framework/modules/core/views/expHTMLEditor/manage.tpl
Expand Up @@ -43,13 +43,10 @@
{"Skin"|gettext}
</th>
<th>
{"SpellCheck"|gettext}
{"Custom Toolbar"|gettext}
</th>
<th>
{"Word Pasting"|gettext}
</th>
<th>
{"Custom Plugins"|gettext}
{"Other Customizations"|gettext}
</th>
<th width="20%">
{"Action"|gettext}
Expand All @@ -72,14 +69,11 @@
{/if}
</td>
<td>
<a href="{link module="expHTMLEditor" action=preview id="default"}" title="Preview this Toolbar"|gettext>{"Default"|gettext}</a>
<a href="{link module="expHTMLEditor" action=preview id=0}" title="Preview this Toolbar"|gettext>{"Default"|gettext}</a>
</td>
<td>
kama
</td>
<td>
{'On'|gettext}
</td>
<td>
{'No'|gettext}
</td>
Expand All @@ -106,21 +100,14 @@
{$cfg->skin}
</td>
<td>
{if $cfg->scayt_on}
{'On'|gettext}
{else}
{'Off'|gettext}
{/if}
</td>
<td>
{if $cfg->paste_word}
{if $cfg->data}
{'Yes'|gettext}
{else}
{'No'|gettext}
{/if}
</td>
<td>
{if $cfg->plugins}
{if !$cfg->scayt_on || $cfg->plugins || $cfg->paste_word || $cfg->stylesset || $cfg->formattags || $cfg->fontnames}
{'Yes'|gettext}
{else}
{'No'|gettext}
Expand Down
4 changes: 2 additions & 2 deletions framework/modules/core/views/expHTMLEditor/preview.tpl
@@ -1,4 +1,4 @@
<h1>{$demo->name} {'Toolbar Configuration'|gettext}</h1>
<h1>{$demo->name} {'Toolbar Configuration Preview'|gettext}</h1>
<p>Using the '{$demo->skin}' skin.<p>
{control type="editor" name="xxx" label="" value="this is an example of what this editor toolbar configuration looks like"|gettext toolbar=$demo}
{control type="editor" name="xxx" label="" value="This is an example of what this editor toolbar configuration looks and works like"|gettext toolbar=$demo->id}
{control type="buttongroup" name="done" cancel="Done"|gettext returntype="manageable"}

0 comments on commit 8ebaa02

Please sign in to comment.