[geeklog-hg] geeklog: Improved the affinity of CKEditor for Geeklog

geeklog-cvs at lists.geeklog.net geeklog-cvs at lists.geeklog.net
Sat Jan 25 04:15:14 EST 2014


changeset 9449:99699ad86679
url:  http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/99699ad86679
user: dengen <taharaxp at gmail.com>
date: Sat Jan 25 18:14:29 2014 +0900
description:
Improved the affinity of CKEditor for Geeklog

diffstat:

 public_html/admin/plugins/staticpages/index.php |    2 +-
 public_html/editors/ckeditor/config.js          |  157 ++++++++++++++++++-----
 public_html/lib-common.php                      |   19 ++-
 system/lib-comment.php                          |    5 +-
 4 files changed, 142 insertions(+), 41 deletions(-)

diffs (273 lines):

diff -r 363a28936ff2 -r 99699ad86679 public_html/admin/plugins/staticpages/index.php
--- a/public_html/admin/plugins/staticpages/index.php	Sat Jan 25 12:47:31 2014 +0900
+++ b/public_html/admin/plugins/staticpages/index.php	Sat Jan 25 18:14:29 2014 +0900
@@ -103,7 +103,7 @@
         $sp_template->set_var('noscript', COM_getNoScript(false, '', $link_message));        
         
         // Setup Advanced Editor
-        COM_setupAdvancedEditor('/staticpages/adveditor.js');
+        COM_setupAdvancedEditor('/staticpages/adveditor.js', 'staticpages.edit');
         
         $sp_template->set_var('lang_expandhelp', $LANG24[67]);
         $sp_template->set_var('lang_reducehelp', $LANG24[68]);
diff -r 363a28936ff2 -r 99699ad86679 public_html/editors/ckeditor/config.js
--- a/public_html/editors/ckeditor/config.js	Sat Jan 25 12:47:31 2014 +0900
+++ b/public_html/editors/ckeditor/config.js	Sat Jan 25 18:14:29 2014 +0900
@@ -3,6 +3,81 @@
  * For licensing, see LICENSE.html or http://ckeditor.com/license
  */
 
+var tools = {
+	items: {
+		'source': ['Source'],
+		'clipboard': ['Cut', 'Copy', 'Paste', 'PasteText'],
+		'undo': ['Undo', 'Redo'],
+		'editing': ['Find', 'Replace', '-', 'SelectAll', '-', 'Scayt'],
+		'links': ['Link', 'Unlink'],
+		'basicstyles': ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat'],
+		'insert': ['Image', 'Table', 'HorizontalRule', 'SpecialChar'],
+		'paragraph': ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote', 'CreateDiv', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', '-', 'BidiLtr', 'BidiRtl'],
+		'styles': ['Styles', 'Format', 'Font', 'FontSize'],
+		'colors': ['TextColor', 'BGColor'],
+		'tools': ['Maximize', 'ShowBlocks'],
+		'about': ['About'],
+
+		'basicstyles_basic': ['Bold', 'Italic'],
+		'paragraph_basic': ['NumberedList', 'BulletedList'],
+
+		'insert_advanced': ['Image', 'Flash', 'Table', 'HorizontalRule', 'Smiley', 'SpecialChar']
+	},
+
+	allowed: function(tag, attr) {
+		var undefined;
+		if (tag === undefined) {
+			return undefined;
+		}
+		if (geeklogAllowedHtml[tag] === undefined) {
+			return false;
+		}
+		if (attr === 1) {
+			return true;
+		}
+		for (var i in attr) {
+			if (geeklogAllowedHtml[tag][i] === undefined) {
+				return false;
+			}
+		}
+		return true;
+	},
+
+	remove_one: function(ary, target) {
+		ary = this.items[ary];
+		for (var i = ary.length - 1; i >= 0; i--) {
+			if (ary[i] === target) ary.splice(i, 1);
+		}
+	},
+
+	remove: function(pattern, target) {
+		for (var i in pattern) {
+			if (!this.allowed(i, pattern[i])) {
+				for (var j in target) {
+					for (var k in target[j]) {
+						this.remove_one(j, target[j][k]);
+					}
+				}
+			}
+		}
+	}
+};
+
+tools.remove({'strong':1}, {'basicstyles':['Bold'], 'basicstyles_basic':['Bold']});
+tools.remove({'em':1}, {'basicstyles':['Italic'], 'basicstyles_basic':['Italic']});
+tools.remove({'u':1}, {'basicstyles':['Underline']});
+tools.remove({'s':1}, {'basicstyles':['Strike']});
+tools.remove({'sub':1}, {'basicstyles':['Subscript']});
+tools.remove({'sup':1}, {'basicstyles':['Superscript']});
+tools.remove({'img':1}, {'insert':['Image'], 'insert_advanced':['Image']});
+tools.remove({'table':1,'tr':1,'th':1,'td':1}, {'insert':['Table'], 'insert_advanced':['Table']});
+tools.remove({'hr':1}, {'insert':['HorizontalRule'], 'insert_advanced':['HorizontalRule']});
+tools.remove({'p':{'style':1}}, {'paragraph':['Outdent','Indent','JustifyLeft','JustifyCenter','JustifyRight']});
+tools.remove({'p':{'dir':1}}, {'paragraph':['BidiLtr','BidiRtl']});
+tools.remove({'blockquote':1}, {'paragraph':['Blockquote']});
+tools.remove({'div':1}, {'paragraph':['CreateDiv']});
+tools.remove({'span':{'style':1}}, {'styles':['Font','FontSize'], 'colors':['TextColor','BGColor']});
+
 CKEDITOR.editorConfig = function( config ) {
 	// Define changes to default configuration here. For example:
 	// config.language = 'fr';
@@ -11,6 +86,21 @@
 	// Disable Advanced Content Filter
 	config.allowedContent = true;
 
+	// Whether to escape basic HTML entities in the document
+	config.basicEntities = false;
+
+	// Whether to use HTML entities in the output.
+	config.entities = false;
+
+	// Whether to convert some symbols, mathematical symbols, and Greek letters to HTML entities.
+	config.entities_greek = false;
+
+	// Whether to convert some Latin characters (Latin alphabet No. 1, ISO 8859-1) to HTML entities.
+	config.entities_latin = false;
+
+	// Whether automatically create wrapping blocks around inline contents
+	config.autoParagraph = false;
+
 	config.protectedSource.push(/<pre[\s\S]+?\/pre>/g);
 	config.protectedSource.push(/\[code[^:][\s\S]+?\/code\]/g);
 	config.protectedSource.push(/\[code:[a-z0-9_]+[\s\S]+?\/code:[a-z0-9_]+\]/g);
@@ -20,46 +110,39 @@
 	config.toolbar = 'toolbar1';
 
 	config.toolbar_toolbar1 = [
-		{ name: 'document', items : [ 'Source' ] },
-		{ name: 'clipboard', items : [ 'Undo','Redo' ] },
-		{ name: 'links', items : [ 'Link','Unlink' ] },
-		{ name: 'basicstyles', items : [ 'Bold','Italic' ] },
-		{ name: 'paragraph', groups: [ 'list', 'indent', 'align' ], items: [ 'NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight' ] },
-		{ name: 'tools', items : [ 'Maximize','-','About' ] }
+		tools.items['source'],
+		tools.items['undo'],
+		tools.items['basicstyles_basic'],
+		tools.items['links'],
+		tools.items['paragraph_basic'],
+		tools.items['insert'],
+		tools.items['tools']
 	];
 
 	config.toolbar_toolbar2 = [
-		{ name: 'document', groups: [ 'mode', 'document', 'doctools' ], items: [ 'Source' ] },
-		{ name: 'clipboard', groups: [ 'clipboard', 'undo' ], items: [ 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo' ] },
-		{ name: 'editing', groups: [ 'find', 'selection', 'spellchecker' ], items: [ 'Find', 'Replace', '-', 'SelectAll', '-', 'Scayt' ] },
-
-		{ name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ], items: [ 'Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat' ] },
-		{ name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align', 'bidi' ], items: [ 'NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote', 'CreateDiv', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', '-', 'BidiLtr', 'BidiRtl' ] },
-		{ name: 'links', items: [ 'Link', 'Unlink', 'Anchor' ] },
-		{ name: 'insert', items: [ 'Image', 'Flash', 'Table', 'HorizontalRule', 'Smiley', 'SpecialChar', 'PageBreak', 'Iframe' ] },
-
-		{ name: 'styles', items: [ 'Styles', 'Format', 'FontSize' ] },
-		{ name: 'colors', items: [ 'TextColor', 'BGColor' ] },
-		{ name: 'tools', items: [ 'Maximize', 'ShowBlocks' ] },
-		{ name: 'about', items: [ 'About' ] }
+		tools.items['source'],
+		tools.items['clipboard'],
+		tools.items['undo'],
+		tools.items['editing'],
+		tools.items['basicstyles'],
+		tools.items['links'],
+		tools.items['paragraph'],
+		tools.items['insert'],
+		tools.items['tools']
 	];
 
 	config.toolbar_toolbar3 = [
-		{ name: 'document', groups: [ 'mode', 'document', 'doctools' ], items: [ 'Source', '-', 'Save', 'NewPage', 'Preview', 'Print', '-', 'Templates' ] },
-		{ name: 'clipboard', groups: [ 'clipboard', 'undo' ], items: [ 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo' ] },
-		{ name: 'editing', groups: [ 'find', 'selection', 'spellchecker' ], items: [ 'Find', 'Replace', '-', 'SelectAll', '-', 'Scayt' ] },
-		{ name: 'forms', items: [ 'Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField' ] },
-		'/',
-		{ name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ], items: [ 'Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat' ] },
-		{ name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align', 'bidi' ], items: [ 'NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote', 'CreateDiv', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', '-', 'BidiLtr', 'BidiRtl' ] },
-		{ name: 'links', items: [ 'Link', 'Unlink', 'Anchor' ] },
-		{ name: 'insert', items: [ 'Image', 'Flash', 'Table', 'HorizontalRule', 'Smiley', 'SpecialChar', 'PageBreak', 'Iframe' ] },
-		'/',
-		{ name: 'styles', items: [ 'Styles', 'Format', 'Font', 'FontSize' ] },
-		{ name: 'colors', items: [ 'TextColor', 'BGColor' ] },
-		{ name: 'tools', items: [ 'Maximize', 'ShowBlocks' ] },
-		{ name: 'others', items: [ '-' ] },
-		{ name: 'about', items: [ 'About' ] }
+		tools.items['source'],
+		tools.items['clipboard'],
+		tools.items['undo'],
+		tools.items['editing'],
+		tools.items['basicstyles'],
+		tools.items['links'],
+		tools.items['paragraph'],
+		tools.items['insert_advanced'],
+		tools.items['colors'],
+		tools.items['tools'],
+		tools.items['styles']
 	];
 
 	config.toolbar_full = [
@@ -86,3 +169,9 @@
 	config.filebrowserImageBrowseUrl = geeklog.site_url + '/filemanager/index.php?Type=Image';
 	config.filebrowserFlashBrowseUrl = geeklog.site_url + '/filemanager/index.php?Type=Flash';
 };
+
+
+CKEDITOR.on('instanceReady', function(ev) {
+	// Fix ends of self closing tags
+	ev.editor.dataProcessor.writer.selfClosingEnd = geeklog.xhtml + '>';
+});
diff -r 363a28936ff2 -r 99699ad86679 public_html/lib-common.php
--- a/public_html/lib-common.php	Sat Jan 25 12:47:31 2014 +0900
+++ b/public_html/lib-common.php	Sat Jan 25 18:14:29 2014 +0900
@@ -8914,12 +8914,13 @@
 /**
 * Setup Advanced Editor
 *
-* @param   string   $custom    location of custom script file relative to
-*                              public_html directory. Include '/' at beginning
-* @param   string   $myeditor  
+* @param   string   $custom       location of custom script file relative to
+*                                 public_html directory. Include '/' at beginning
+* @param   string   $permissions  comma-separated list of rights which identify the current user as an "Admin"
+* @param   string   $myeditor     
 * @return  void
 */
-function COM_setupAdvancedEditor($custom, $myeditor='')
+function COM_setupAdvancedEditor($custom, $permissions = 'story.edit', $myeditor='')
 {
     global $_CONF, $_USER, $_SCRIPTS;
 
@@ -8953,9 +8954,19 @@
     if (empty($footer))   $footer   = true;
     if (empty($priority)) $priority = 100;
 
+    if (empty($permissions) || !SEC_hasRights($permissions) ||
+            empty($_CONF['admin_html'])) {
+        $html = $_CONF['user_html'];
+    } else {
+        $html = array_merge_recursive($_CONF['user_html'],
+                                      $_CONF['admin_html'],
+                                      $_CONF['advanced_html']);
+    }
+
     // Add core JavaScript global variables
     $script  = '<script type="text/javascript">' . LB
              . 'var geeklogEditorName = "' . $name . '";' . LB
+             . 'var geeklogAllowedHtml = ' . json_encode($html) . ';' . LB
              . '</script>' . LB;
     $_SCRIPTS->setJavaScript($script);
 
diff -r 363a28936ff2 -r 99699ad86679 system/lib-comment.php
--- a/system/lib-comment.php	Sat Jan 25 12:47:31 2014 +0900
+++ b/system/lib-comment.php	Sat Jan 25 18:14:29 2014 +0900
@@ -1028,6 +1028,8 @@
                 $mode = 'error';
             }
 
+            $permission = ($type == 'article') ? 'story.edit' : "$type.edit";
+
             $comment_template = COM_newTemplate($_CONF['path_layout'] . 'comment');
             if ($_CONF['advanced_editor'] && $_USER['advanced_editor']) {
                 $comment_template->set_file('form', 'commentform_advanced.thtml');
@@ -1040,7 +1042,7 @@
                 $comment_template->set_var('noscript', COM_getNoScript(false, '', $link_message));
                 
                 // Setup Advanced Editor
-                COM_setupAdvancedEditor('/javascript/submitcomment_adveditor.js');
+                COM_setupAdvancedEditor('/javascript/submitcomment_adveditor.js', $permission);
 
             } else {
                 $comment_template->set_file('form', 'commentform.thtml');
@@ -1177,7 +1179,6 @@
             $comment_template->set_var('postmode_options',
                 COM_optionList($_TABLES['postmodes'], 'code,name', $postmode));
             $allowed_html = '';
-            $permission = ($type == 'article') ? 'story.edit' : "$type.edit";
             foreach (array('plaintext', 'html') as $pm) {
                 $allowed_html .= COM_allowedHTML($permission, false, 1, $pm);
             }



More information about the geeklog-cvs mailing list