From 0e7875a6b3d373106988ddd8f447db5bef4ddb30 Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Thu, 7 Oct 2010 19:41:28 -0400 Subject: [PATCH] add ckeditor plugin for syntaxhighlighter blocks, and intial Jonah support. Need to figure out a clean way of getting the code type from the jonah story, thinking of using a regex for the
 elements. For now, hard code
php only.
---
 .../Core/lib/Horde/Core/Ui/VarRenderer/Html.php    |   5 +-
 framework/Editor/js/config.js                      |   2 +-
 .../syntaxhighlight/dialogs/syntaxhighlight.js     |   1 +
 .../syntaxhighlight/images/syntaxhighlight.gif     | Bin 0 -> 94 bytes
 .../Editor/js/plugins/syntaxhighlight/lang/en.js   |   1 +
 .../Editor/js/plugins/syntaxhighlight/plugin.js    |   1 +
 framework/Editor/lib/Horde/Editor/Ckeditor.php     |   4 +-
 framework/Editor/package.xml                       | 988 +++++++++++----------
 jonah/lib/View/StoryView.php                       |  16 +
 9 files changed, 538 insertions(+), 480 deletions(-)
 create mode 100644 framework/Editor/js/plugins/syntaxhighlight/dialogs/syntaxhighlight.js
 create mode 100644 framework/Editor/js/plugins/syntaxhighlight/images/syntaxhighlight.gif
 create mode 100644 framework/Editor/js/plugins/syntaxhighlight/lang/en.js
 create mode 100644 framework/Editor/js/plugins/syntaxhighlight/plugin.js

diff --git a/framework/Core/lib/Horde/Core/Ui/VarRenderer/Html.php b/framework/Core/lib/Horde/Core/Ui/VarRenderer/Html.php
index a558b3b7c..e9eea05a6 100644
--- a/framework/Core/lib/Horde/Core/Ui/VarRenderer/Html.php
+++ b/framework/Core/lib/Horde/Core/Ui/VarRenderer/Html.php
@@ -290,7 +290,10 @@ class Horde_Core_Ui_VarRenderer_Html extends Horde_Core_Ui_VarRenderer
                         @htmlspecialchars($var->getValue($vars), ENT_QUOTES, $this->_charset));
 
         if ($var->type->hasHelper('rte')) {
-            $GLOBALS['injector']->getInstance('Horde_Editor')->initialize(array('id' => $varname, 'relativelinks' => $var->type->hasHelper('relativelinks')));
+            $GLOBALS['injector']->getInstance('Horde_Editor')->initialize(
+                array('id' => $varname,
+                      'relativelinks' => $var->type->hasHelper('relativelinks'),
+                      'config' => array('extraPlugins' => 'syntaxhighlight')));
         }
 
         if ($var->type->hasHelper() && $browser->hasFeature('javascript')) {
diff --git a/framework/Editor/js/config.js b/framework/Editor/js/config.js
index 2ef3c9633..35a3167f4 100644
--- a/framework/Editor/js/config.js
+++ b/framework/Editor/js/config.js
@@ -1 +1 @@
-CKEDITOR.editorConfig=function(a){a.scayt_autoStartup=false};
\ No newline at end of file
+CKEDITOR.editorConfig=function(a){a.scayt_autoStartup=false;a.toolbar_Full.push(['Code'])};
\ No newline at end of file
diff --git a/framework/Editor/js/plugins/syntaxhighlight/dialogs/syntaxhighlight.js b/framework/Editor/js/plugins/syntaxhighlight/dialogs/syntaxhighlight.js
new file mode 100644
index 000000000..946c4c6a2
--- /dev/null
+++ b/framework/Editor/js/plugins/syntaxhighlight/dialogs/syntaxhighlight.js
@@ -0,0 +1 @@
+CKEDITOR.dialog.add("syntaxhighlight",function(c){var a=function(f){f=f.replace(/
/g,"\n");f=f.replace(/&/g,"&");f=f.replace(/</g,"<");f=f.replace(/>/g,">");f=f.replace(/"/g,'"');return f};var e=function(f){var f=new Object();f.hideGutter=false;f.hideControls=false;f.collapse=false;f.showColumns=false;f.noWrap=false;f.firstLineChecked=false;f.firstLine=0;f.highlightChecked=false;f.highlight=null;f.lang=null;f.code="";return f};var b=function(i){var h=e();if(i){if(i.indexOf("brush")>-1){var g=/brush:[ ]{0,1}(\w*)/.exec(i);if(g!=null&&g.length>0){h.lang=g[1].replace(/^\s+|\s+$/g,"")}}if(i.indexOf("gutter")>-1){h.hideGutter=true}if(i.indexOf("toolbar")>-1){h.hideControls=true}if(i.indexOf("collapse")>-1){h.collapse=true}if(i.indexOf("first-line")>-1){var g=/first-line:[ ]{0,1}([0-9]{1,4})/.exec(i);if(g!=null&&g.length>0&&g[1]>1){h.firstLineChecked=true;h.firstLine=g[1]}}if(i.indexOf("highlight")>-1){if(i.match(/highlight:[ ]{0,1}\[[0-9]+(,[0-9]+)*\]/)){var f=/highlight:[ ]{0,1}\[(.*)\]/.exec(i);if(f!=null&&f.length>0){h.highlightChecked=true;h.highlight=f[1]}}}if(i.indexOf("ruler")>-1){h.showColumns=true}if(i.indexOf("wrap-lines")>-1){h.noWrap=true}}return h};var d=function(g){var f="brush:"+g.lang+";";if(g.hideGutter){f+="gutter:false;"}if(g.hideControls){f+="toolbar:false;"}if(g.collapse){f+="collapse:true;"}if(g.showColumns){f+="ruler:true;"}if(g.noWrap){f+="wrap-lines:false;"}if(g.firstLineChecked&&g.firstLine>1){f+="first-line:"+g.firstLine+";"}if(g.highlightChecked&&g.highlight!=""){f+="highlight: ["+g.highlight.replace(/\s/gi,"")+"];"}return f};return{title:c.lang.syntaxhighlight.title,minWidth:500,minHeight:400,onShow:function(){var i=this.getParentEditor();var h=i.getSelection();var g=h.getStartElement();var k=g&&g.getAscendant("pre",true);var j="";var f=null;if(k){code=a(k.getHtml());f=b(k.getAttribute("class"));f.code=code}else{f=e()}this.setupContent(f)},onOk:function(){var h=this.getParentEditor();var g=h.getSelection();var f=g.getStartElement();var k=f&&f.getAscendant("pre",true);var i=e();this.commitContent(i);var j=d(i);if(k){k.setAttribute("class",j);k.setText(i.code)}else{var l=new CKEDITOR.dom.element("pre");l.setAttribute("class",j);l.setText(i.code);h.insertElement(l)}},contents:[{id:"source",label:c.lang.syntaxhighlight.sourceTab,accessKey:"S",elements:[{type:"vbox",children:[{id:"cmbLang",type:"select",labelLayout:"horizontal",label:c.lang.syntaxhighlight.langLbl,"default":"java",widths:["25%","75%"],items:[["Bash (Shell)","bash"],["C#","csharp"],["C++","cpp"],["CSS","css"],["Delphi","delphi"],["Diff","diff"],["Groovy","groovy"],["Javascript","jscript"],["Java","java"],["Java FX","javafx"],["Perl","perl"],["PHP","php"],["Plain (Text)","plain"],["Python","python"],["Ruby","ruby"],["Scala","scala"],["SQL","sql"],["VB","vb"],["XML/XHTML","xml"]],setup:function(f){if(f.lang){this.setValue(f.lang)}},commit:function(f){f.lang=this.getValue()}}]},{type:"textarea",id:"hl_code",rows:22,style:"width: 100%",setup:function(f){if(f.code){this.setValue(f.code)}},commit:function(f){f.code=this.getValue()}}]},{id:"advanced",label:c.lang.syntaxhighlight.advancedTab,accessKey:"A",elements:[{type:"vbox",children:[{type:"html",html:""+c.lang.syntaxhighlight.hideGutter+""},{type:"checkbox",id:"hide_gutter",label:c.lang.syntaxhighlight.hideGutterLbl,setup:function(f){this.setValue(f.hideGutter)},commit:function(f){f.hideGutter=this.getValue()}},{type:"html",html:""+c.lang.syntaxhighlight.hideControls+""},{type:"checkbox",id:"hide_controls",label:c.lang.syntaxhighlight.hideControlsLbl,setup:function(f){this.setValue(f.hideControls)},commit:function(f){f.hideControls=this.getValue()}},{type:"html",html:""+c.lang.syntaxhighlight.collapse+""},{type:"checkbox",id:"collapse",label:c.lang.syntaxhighlight.collapseLbl,setup:function(f){this.setValue(f.collapse)},commit:function(f){f.collapse=this.getValue()}},{type:"html",html:""+c.lang.syntaxhighlight.showColumns+""},{type:"checkbox",id:"show_columns",label:c.lang.syntaxhighlight.showColumnsLbl,setup:function(f){this.setValue(f.showColumns)},commit:function(f){f.showColumns=this.getValue()}},{type:"html",html:""+c.lang.syntaxhighlight.lineWrap+""},{type:"checkbox",id:"line_wrap",label:c.lang.syntaxhighlight.lineWrapLbl,setup:function(f){this.setValue(f.noWrap)},commit:function(f){f.noWrap=this.getValue()}},{type:"html",html:""+c.lang.syntaxhighlight.lineCount+""},{type:"hbox",widths:["5%","95%"],children:[{type:"checkbox",id:"lc_toggle",label:"",setup:function(f){this.setValue(f.firstLineChecked)},commit:function(f){f.firstLineChecked=this.getValue()}},{type:"text",id:"default_lc",style:"width: 15%;",label:"",setup:function(f){if(f.firstLine>1){this.setValue(f.firstLine)}},commit:function(f){if(this.getValue()&&this.getValue()!=""){f.firstLine=this.getValue()}}}]},{type:"html",html:""+c.lang.syntaxhighlight.highlight+""},{type:"hbox",widths:["5%","95%"],children:[{type:"checkbox",id:"hl_toggle",label:"",setup:function(f){this.setValue(f.highlightChecked)},commit:function(f){f.highlightChecked=this.getValue()}},{type:"text",id:"default_hl",style:"width: 40%;",label:"",setup:function(f){if(f.highlight!=null){this.setValue(f.highlight)}},commit:function(f){if(this.getValue()&&this.getValue()!=""){f.highlight=this.getValue()}}}]},{type:"hbox",widths:["5%","95%"],children:[{type:"html",html:""},{type:"html",html:""+c.lang.syntaxhighlight.highlightLbl+""}]}]}]}]}}); \ No newline at end of file diff --git a/framework/Editor/js/plugins/syntaxhighlight/images/syntaxhighlight.gif b/framework/Editor/js/plugins/syntaxhighlight/images/syntaxhighlight.gif new file mode 100644 index 0000000000000000000000000000000000000000..dd94ded5c49d869d0257ecddeebf9f2e8acb87e8 GIT binary patch literal 94 zcmZ?wbhEHb6krfwn8?JyVEq3K0~9F!WMO1rU}De#@j>zoO!`y$SI&O;rm4~=fJ=2< q{_53{i&7@WCC{52wUucB!-wh3,10,15."}}); \ No newline at end of file diff --git a/framework/Editor/js/plugins/syntaxhighlight/plugin.js b/framework/Editor/js/plugins/syntaxhighlight/plugin.js new file mode 100644 index 000000000..a94864af5 --- /dev/null +++ b/framework/Editor/js/plugins/syntaxhighlight/plugin.js @@ -0,0 +1 @@ +CKEDITOR.plugins.add("syntaxhighlight",{requires:["dialog"],lang:["en"],init:function(a){var b="syntaxhighlight";var c=a.addCommand(b,new CKEDITOR.dialogCommand(b));c.modes={wysiwyg:1,source:1};c.canUndo=false;a.ui.addButton("Code",{label:a.lang.syntaxhighlight.title,command:b,icon:this.path+"images/syntaxhighlight.gif"});CKEDITOR.dialog.add(b,this.path+"dialogs/syntaxhighlight.js")}}); \ No newline at end of file diff --git a/framework/Editor/lib/Horde/Editor/Ckeditor.php b/framework/Editor/lib/Horde/Editor/Ckeditor.php index 13b3b008f..0a937153d 100644 --- a/framework/Editor/lib/Horde/Editor/Ckeditor.php +++ b/framework/Editor/lib/Horde/Editor/Ckeditor.php @@ -40,7 +40,7 @@ class Horde_Editor_Ckeditor extends Horde_Editor $ck_file = empty($params['basic']) ? 'ckeditor.js' : 'ckeditor_basic.js'; - $ck_path = $GLOBALS['registry']->get('jsuri', 'horde') . '/ckeditor/'; + $ck_path = $GLOBALS['registry']->get('jsuri', 'horde') . '/'; /* Globally disable spell check as you type. */ $params['config']['scayt_autoStartup'] = false; @@ -55,7 +55,7 @@ class Horde_Editor_Ckeditor extends Horde_Editor } else { $this->_js = ''; if (isset($params['id'])) { - $this->_js .= Horde::wrapInlineScript(array('CKEDITOR.replace("' . $params['id'] . '",' . $params['config'] . ')'), 'load'); + $this->_js .= Horde::wrapInlineScript(array('CKEDITOR.replace("' . $params['id'] . '",' . $params['config'] . ');config.toolbar_Full.push(["Code"]);'), 'load'); } } } diff --git a/framework/Editor/package.xml b/framework/Editor/package.xml index 2a4707e97..567bb987b 100644 --- a/framework/Editor/package.xml +++ b/framework/Editor/package.xml @@ -1,13 +1,9 @@ - + Editor pear.horde.org Horde Editor API - The Horde_Editor:: package provides an API to generate the code necessary for embedding javascript RTE editors in a web page. - + The Horde_Editor:: package provides an API to generate the code necessary for embedding javascript RTE editors in a web page. Chuck Hagenbuch chuck @@ -20,7 +16,8 @@ http://pear.php.net/dtd/package-2.0.xsd"> slusarz@horde.org yes - 2009-01-19 + 2010-10-07 + 0.1.0 0.1.0 @@ -30,351 +27,365 @@ http://pear.php.net/dtd/package-2.0.xsd"> beta LGPL - * Removed Xinha driver. + +* Removed Xinha driver. * Added CKEditor driver. * Removed FCKEditor driver * Initial Horde 4 package. - + - - - - - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - - - - + + + + - - - - + + + + - - - + + + - - - + + + - - + + - - - + + + - - - + + + - - + + - - - + + + - - - - - - - - - + + + + + + + + + - - - + + + - - + + - - - + + + - - - + + + - - - + + + - - - + + + + - - - + + + - - - + + + - - - + + + - - - - + + + + - - - - - - - - - - - - - + + + + + + + + + + + + + - - + + - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - - - + + + - - - + + + + + + + + + + + + + + + - - - + + + - - - + + + - - + + - - - - - - - + + + + + + + - - + + - - - - + + - - - - - - - - - + + + + + + + + + + + - - - - - - - + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - - - - + + + + + + + + + @@ -419,206 +430,226 @@ http://pear.php.net/dtd/package-2.0.xsd"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0.0.1 + 0.0.1 + + + alpha + alpha + + 2004-02-11 + LGPL + +Initial packaging + + + + 0.0.2 0.0.2 @@ -629,22 +660,27 @@ http://pear.php.net/dtd/package-2.0.xsd"> 2006-05-08 LGPL - * Removed TinyMCE driver. + +* Removed TinyMCE driver. * Converted to package.xml 2.0 for pear.horde.org - 0.0.1 - 0.0.1 + 0.1.0 + 0.1.0 - alpha - alpha + beta + beta - 2004-02-11 + 2010-10-07 LGPL - Initial packaging + +* Removed Xinha driver. + * Added CKEditor driver. + * Removed FCKEditor driver + * Initial Horde 4 package. diff --git a/jonah/lib/View/StoryView.php b/jonah/lib/View/StoryView.php index 8edc8ceb0..e4839559a 100644 --- a/jonah/lib/View/StoryView.php +++ b/jonah/lib/View/StoryView.php @@ -26,6 +26,22 @@ class Jonah_View_StoryView extends Jonah_View_Base { extract($this->_params, EXTR_REFS); + Horde::addScriptFile('syntaxhighlighter/scripts/shCore.js', 'horde', true); + Horde::addInlineScript(array( + 'SyntaxHighlighter.defaults[\'toolbar\'] = false', + 'SyntaxHighlighter.all()', + ), 'dom'); + + // TODO: Need a way to figure out what language the code block is... + // probably a regex to look for the
 tags?
+        $sh_js_fs = $GLOBALS['registry']->get('jsfs', 'horde') . '/syntaxhighlighter/styles/';
+        $sh_js_uri = Horde::url($GLOBALS['registry']->get('jsuri', 'horde'), false, -1) . '/syntaxhighlighter/styles/';
+        Horde_Themes::includeStylesheetFiles(array('additional' => array(
+            array('f' => $sh_js_fs . 'shCoreEclipse.css', 'u' => $sh_js_uri . 'shCoreEclipse.css'),
+            array('f' => $sh_js_fs . 'shThemeEclipse.css', 'u' => $sh_js_uri . 'shThemeEclipse.css'),
+        )));
+        Horde::addScriptFile('syntaxhighlighter/scripts/shBrush' . 'php' . '.js', 'horde', true);
+
         $driver = $GLOBALS['injector']->getInstance('Jonah_Driver');
         try {
             $story = $driver->getStory($channel_id, $story_id, !$browser->isRobot());
-- 
2.11.0