diff --git a/news/trunk/plugins/content/CodeCitation.php b/news/trunk/plugins/content/CodeCitation.php new file mode 100644 index 00000000..f2f5114e --- /dev/null +++ b/news/trunk/plugins/content/CodeCitation.php @@ -0,0 +1,242 @@ + "as3", "actionscript3" => "as3", + "bash" => "bash", "shell" => "bash", + "cpp" => "cpp", "c" => "cpp", + "csharp" => "csharp", "c#" => "csharp", "c-sharp" => "csharp", + "css" => "css", + "pascal" => "pascal", "delphi" => "pascal", + "diff" => "diff", "patch" => "diff", + "groovy" => "groovy", + "java" => "java", + "javafx" => "javafx", "jfx" => "javafx", + "js" => "javascript", "javascript" => "javascript", "jscript" => "javascript", + "perl" => "perl", "pl" => "perl", "Perl" => "perl", + "php" => "php", + "text" => "text", "plain" => "text", + "powershell" => "powershell", "ps" => "powershell", + "python" => "python", "py" => "python", + "ruby" => "ruby", "rails" => "ruby", "ror" => "ruby", + "scala" => "scala", + "sql" => "sql", + "vb" => "vb", "vbnet" => "vb", "VisualBasic" => "vb", + "xml" => "xml", "xhtml" => "xml", "xslt" => "xml", "html" => "xml" ); + + private static $langFiles = array( "as3" => "shBrushAS3.js", + "bash" => "shBrushBash.js", + "cpp" => "shBrushCpp.js", + "csharp" => "shBrushCSharp.js", + "css" => "shBrushCss.js", + "pascal" => "shBrushDelphi.js", + "diff" => "shBrushDiff.js", + "groovy" => "shBrushGroovy.js", + "java" => "shBrushJava.js", + "javafx" => "shBrushJavaFX.js", + "javascript" => "shBrushJScript.js", + "perl" => "shBrushPerl.js", + "php" => "shBrushPhp.js", + "text" => "shBrushPlain.js", + "powershell" => "shBrushPowerShell.js", + "python" => "shBrushPython.js", + "ruby" => "shBrushRuby.js", + "scala" => "shBrushScala.js", + "sql" => "shBrushSql.js", + "vb" => "shBrushVb.js", + "xml" => "shBrushXml.js" + ); + + private $_includeCSSOnce = False; + private $_includedScripts = array(); + private $_runHighlighterOnce=False; + + function plgContentCodeCitation( &$subject, $params ){ + parent::__construct( $subject, $params ); + } + + //onPrepareContent event handler. Replace all entries of {codecitation} tag and load necessary scripts + function onPrepareContent( &$row, &$params, $page=0 ) { + $tag=self::_tag; + $alternativetag=$this->params->def( 'alternativetag', ''); + if ($alternativetag!='') + { + $tag='('.$tag.'|'.$alternativetag.')'; + } + else + { + $tag='('.$tag.')'; + } + $regex = "#{".$tag."[\s| ]*(.*?)}([\s\S]*?){/\\1}#s"; + // register the regular expresstion to invoke our replacer in case Joomla finds the matches + $row->text = preg_replace_callback( $regex, array($this,'replacer'), $row->text ); + return true; + } + + //Do the replacement work to replace {codecitation}{/codecitation} into
+ //and include scripts as necessary + private function replacer( &$matches ) { + jimport('domit.xml_saxy_shared'); + + //adjust document header to include SyntaxHighlighter styles and core + $this->includeCSSOnce(); + $html_entities_match = array( "'\n'", "'\<\s*span\s*[\s\S]*?/*\s*\>'i", "'\'i","'\<\s*/\s*pre\s*\>'i", "'\'i","'\<\s*/\s*div\s*\>'i","'\<\s*/\s*span\s*\>'i", "'\<\s*/\s*p\s*\>'i", "'\'i","'\'i", "'<'i", "'>'i", "'''", "'"'i", "' 'i" ); + $html_entities_replace = array("", "", "", "", "", "", "", "", "\n", "\n", '<', '>', "'", '"', ' ' ); + + $matches[2]=preg_replace($html_entities_match, $html_entities_replace, $matches[2] ); + $matches[3]=preg_replace($html_entities_match, $html_entities_replace, $matches[3] ); + $text = $matches[3]; + + $args = SAXY_Parser_Base::parseAttributes( $matches[2] ); + + $shclass = JArrayHelper::getValue( $args, 'class', '' ); + $width = JArrayHelper::getValue( $args, 'width', 'inherit' ); + + //determine language to show + $langAlias=""; + $regexLangAlias="#brush\s*:\s*(\S[^;]*[^;\s])#s"; + + if (preg_match($regexLangAlias,$shclass,$langAliasMatches)>0) + { + $langAlias=$langAliasMatches[1]; + } + else + { + $langAlias=$this->params->def( 'defaultlang', 'text'); + $shclass='brush:'.$langAlias.';'.$shclass; + } + //determine if we need to include xml markup parser for html scripts + $htmlScriptMode=False; + $regexHtmlScriptMode="#html-script\s*:\s*(\S[^;]*[^;\s])#s"; + if (preg_match($regexHtmlScriptMode,$shclass,$htmlScriptModeMatches)>0) + { + $htmlScriptMode=strtoupper($htmlScriptModeMatches[1]); + } + else + { + $htmlScriptMode="FALSE"; + } + + //include Java script that is necessary to show the code (if we have not already did it for this language) + $codes=$this->includeScript($langAlias,$htmlScriptMode); + + $prolog='
';
+    $epilog='
'; + + $text = $codes.$prolog.$text.$epilog; + + return $text; + } + + private function includeScript($langAlias, $htmlScriptMode) { + //get then lanuage name for the alias + $langName="text"; //IN CASE OF WRONG ALIAS WE WILL TREAT IT AS PLAIN TEXT + + if (isset(self::$langAliases[$langAlias])) + { + $langName=self::$langAliases[$langAlias]; + } + //get the filename for the language + $fileName=""; + if (isset(self::$langFiles[$langName])) + { + $fileName=self::$langFiles[$langName]; + } + else + { + $fileName=self::$langFiles["text"]; + } + //check if we have already embeeded file into the page + if (!isset($this->_includedScripts[$fileName])) + { + $this->_includedScripts[$fileName]="1"; + $this->updatePageIncludes($fileName); + } + if($htmlScriptMode=="TRUE") + { + //embeed xml lang file if necessary for html-script mode + if (!isset($this->_includedScripts[self::$langFiles[self::$langAliases["xml"]]])) + { + $this->_includedScripts[self::$langFiles[self::$langAliases["xml"]]]="1"; + $this->updatePageIncludes(self::$langFiles[self::$langAliases["xml"]]); + } + } + + //since we are here, we need to embeed styles and scripts into document + if ($this->_runHighlighterOnce) return ""; + $this->_runHighlighterOnce=True; + $pluginRoot=self::getPluginRoot(); + //TODO: Handle plugin parameters and set default SyntaxHighlighter values according to the plugin params vaules + $codes=''; + return $codes; + } + + private function updatePageIncludes($fileName) + { + $pluginRoot=self::getPluginRoot(); + $tag=''; + $document= & JFactory::getDocument(); + if ($document) + { + $document->addCustomTag($tag); + } + return; + } + + //include necessary styles into page only once + private function includeCSSOnce() { + //since we are here, we need to embeed styles and scripts into document + if ($this->_includeCSSOnce) return; + // we want only one link to the CSS + $this->_includeCSSOnce = True; + $pluginRoot=self::getPluginRoot(); + $tag= ' + +'; + $document= & JFactory::getDocument(); + if ($document) + { + $document->addCustomTag($tag); + } + return; + } + + public static function getPluginRoot() + { + return JURI::root().'plugins/content/codecitation/'; + } + +} \ No newline at end of file diff --git a/news/trunk/plugins/content/CodeCitation.xml b/news/trunk/plugins/content/CodeCitation.xml new file mode 100644 index 00000000..3833e61a --- /dev/null +++ b/news/trunk/plugins/content/CodeCitation.xml @@ -0,0 +1,120 @@ + + + Content - CodeCitation + Konstantin Nizhegorodov (konstantin.nizhegorodov@gmail.com) + August 22, 2009 + Copyright 2009 Konstantin Nizhegorodov. All rights reserved. + http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL + http://www.smartsoftwarebits.com + 1.3.1 + The CodeCitation plugin allows you to include code sections in your Joomla 1.5 content using {codecitation} or custom tag. + Use of the {codecitation} tag allows you to work with code sections in your Joomla WYSIWIG editors. + Plugin uses SyntaxHighlighter 2.0 library from http://alexgorbatchev.com/wiki/SyntaxHighlighter + Supports: syntax highlighting for ActionScript3, Bash/shell, C#, C++, CSS, Delphi, Diff, Groovy, JavaScript, Java, JavaFX, Perl, PHP, Plain Text, PowerShell, Python, Ruby, Scala, SQL, Visual Basic, XML, HTML, XSLT + Usage example: {codecitation style="brush: xml;"}CODE HERE{/codecitation} + + +CodeCitation.php +CodeCitationREADME.txt +codecitation/scripts/clipboard.swf +codecitation/scripts/shBrushAS3.js +codecitation/scripts/shBrushBash.js +codecitation/scripts/shBrushCpp.js +codecitation/scripts/shBrushCSharp.js +codecitation/scripts/shBrushCss.js +codecitation/scripts/shBrushDelphi.js +codecitation/scripts/shBrushDiff.js +codecitation/scripts/shBrushGroovy.js +codecitation/scripts/shBrushJava.js +codecitation/scripts/shBrushJavaFX.js +codecitation/scripts/shBrushJScript.js +codecitation/scripts/shBrushPerl.js +codecitation/scripts/shBrushPhp.js +codecitation/scripts/shBrushPlain.js +codecitation/scripts/shBrushPowerShell.js +codecitation/scripts/shBrushPython.js +codecitation/scripts/shBrushRuby.js +codecitation/scripts/shBrushScala.js +codecitation/scripts/shBrushSql.js +codecitation/scripts/shBrushVb.js +codecitation/scripts/shBrushXml.js +codecitation/scripts/shCore.js +codecitation/scripts/shLegacy.js +codecitation/styles/help.png +codecitation/styles/magnifier.png +codecitation/styles/page_white_code.png +codecitation/styles/page_white_copy.png +codecitation/styles/printer.png +codecitation/styles/shCore.css +codecitation/styles/shThemeDefault.css +codecitation/styles/shThemeDjango.css +codecitation/styles/shThemeEmacs.css +codecitation/styles/shThemeFadeToGrey.css +codecitation/styles/shThemeMidnight.css +codecitation/styles/shThemeRDark.css +codecitation/styles/wrapping.png + + + en-GB.plg_content_CodeCitation.ini + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/news/trunk/plugins/content/CodeCitationREADME.txt b/news/trunk/plugins/content/CodeCitationREADME.txt new file mode 100644 index 00000000..44338f97 --- /dev/null +++ b/news/trunk/plugins/content/CodeCitationREADME.txt @@ -0,0 +1,64 @@ +codecitationREADME.txt + +The CodeCitation plugin allows you to include code sections in your Joomla 1.5 content using {codecitation} or custom tag. +Use of the {codecitation} tag allows you to work with code sections in your Joomla WYSIWIG editors. + +Plugin uses SyntaxHighlighter 2.0 library from http://alexgorbatchev.com/wiki/SyntaxHighlighter + +Supports: syntax highlighting for ActionScript3, Bash/shell, C#, C++, CSS, Delphi, Diff, Groovy, JavaScript, Java, JavaFX, Perl, PHP, Plain Text, PowerShell, Python, Ruby, Scala, SQL, Visual Basic, XML, HTML, XSLT + +INSTALLATION INSTRUCTIONS: +==================== + +- download the codecitation plugin. +- install the plugin using the Joomla Extensions install utility. +- ENABLE the new CodeCitation plugin with the Joomla 1.5 backend plugin manager. +- Set default parameters for the plugin engine. + +USING THE PLUGIN: +The syntax for the usage is: + +{codecitation [class=""] [width="<>"]} + +{/codecitation} + +where: + is a parameter string for the engine - see http://www.smartsoftwarebits.com/index.php/codecitation/69-supported-brushes-and-parameters + is an optional parameter to specify
width (fix code in some cases into your template) +For more information about SintaxHighlighter engine parameters please visit http://www.smartsoftwarebits.com/index.php/codecitation + +EXAMPLES +{codecitation class="brush: xml; gutter: false;" width="500px"} +xlm goes here +{/codecitation} + +OR (if you set default language to C++, for example): + +{codecitation} +C++ code goes here +{/codecitation} + +OR if you set custom tag=code in plugin parameters and default language=C++: +{code} +C++ code goes here +{/code} + +VERSION 1.0 +======== + - initial release + +VERSION 1.1.0 +======== + - PHP 5.2.3 callback syntax workaround + +VERSION 1.2.0 +======== + - Core engine updated to version 2.0.320 of SyntaxHighlighter + +VERSION 1.3.1 +======== + - Page load speed improved and page size redused. Only necessary scripts are loaded. + - Custom tag support implemented. Plugin supports custom plugin invocation tag in case "codecitation" seems to long for somebody (i use "code" tag time to time). + - Default language parameter implemented and can be set on the plugin's parameters page. It allows simplified plugin invocation systax. + - Default engine parameters values can be set on the plugin's parameters page. + - Themes are changeble on plugin paameters page.