将文件添加并导入到SVN库中

+YUCHENG HU+

git-svn-id: https://svn.code.sf.net/p/hawebs/svn@42 a2543c7e-f6e9-4f8a-8bff-1ffc34733512
This commit is contained in:
YuCheng Hu
2010-04-24 20:12:25 +00:00
parent bdef5f83ae
commit 39a02a1df9
3 changed files with 426 additions and 0 deletions
+242
View File
@@ -0,0 +1,242 @@
<?php
/**
* CodeCitation 1.3.1
* Joomla plugin
* allow usage of SyntaxHighlighter in WYSIWYG editor
* Usage: {codecitation class="(class params for SyntaxHighlighter)" width="(optional width param for div tag)"} CODE TO HIGHTLIGHT {/codecitation}
* Usage example: {codecitation class="brush: VisualBasic; gutter:true"} VB CODE {/codecitation}
* Copyright 2009 [email protected]. All rights reserved.
* This is a derivative work. Portions are copyright:
* Open Source Matters
* This work is licensed under the GNU/GPL license.
* This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
*/
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport( 'joomla.event.plugin' );
class plgContentCodeCitation extends JPlugin {
const _tag="codecitation";
private static $langAliases = array("as3" => "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|&nbsp;]*(.*?)}([\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 <div><pre></pre></div>
//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", "'\<pre\s*[\s\S]*?/*\s*\>'i","'\<\s*/\s*pre\s*\>'i", "'\<div\s*[\s\S]*?/*\s*\>'i","'\<\s*/\s*div\s*\>'i","'\<\s*/\s*span\s*\>'i", "'\<\s*/\s*p\s*\>'i", "'\<p\s*[\s\S]*?/*\s*\>'i","'\<br\s*\/*\s*\>'i", "'<'i", "'>'i", "'&#39;'", "'&quot;'i", "'&nbsp;'i" );
$html_entities_replace = array("", "", "", "", "", "", "", "", "\n", "\n", '&lt;', '&gt;', "'", '"', ' ' );
$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='<div style="overflow: hidden; display: block; height: auto; width: '.$width.';"><pre class="'.$shclass.'">';
$epilog='</pre></div>';
$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='<script type="text/javascript">
SyntaxHighlighter.config.clipboardSwf = "'.$pluginRoot.'scripts/clipboard.swf";
SyntaxHighlighter.defaults["auto-links"] = '.($this->params->def( 'auto-links', 0) ? 'true' : 'false').';
SyntaxHighlighter.defaults["collapse"] = '.($this->params->def( 'collapse', 0) ? 'true' : 'false').';
SyntaxHighlighter.defaults["gutter"] = '.($this->params->def( 'gutter', 0) ? 'true' : 'false').';
SyntaxHighlighter.defaults["smart-tabs"] = '.($this->params->def( 'smart-tabs', 0) ? 'true' : 'false').';
SyntaxHighlighter.defaults["tab-size"] = '.$this->params->def( 'tab-size', '4').';
SyntaxHighlighter.defaults["toolbar"] = '.($this->params->def( 'toolbar', 0) ? 'true' : 'false').';
SyntaxHighlighter.defaults["wrap-lines"] = '.($this->params->def( 'wrap-lines', 0) ? 'true' : 'false').';
SyntaxHighlighter.all();
</script>';
return $codes;
}
private function updatePageIncludes($fileName)
{
$pluginRoot=self::getPluginRoot();
$tag='<script type="text/javascript" src="'.$pluginRoot.'scripts/'.$fileName.'"></script>';
$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= '<link type="text/css" rel="stylesheet" href="'.$pluginRoot.'styles/shCore.css"/>
<link type="text/css" rel="stylesheet" href="'.$pluginRoot.'styles/'.$this->params->def( 'theme', 'shThemeDefault.css').'"/>
<script type="text/javascript" src="'.$pluginRoot.'scripts/shCore.js"></script>';
$document= & JFactory::getDocument();
if ($document)
{
$document->addCustomTag($tag);
}
return;
}
public static function getPluginRoot()
{
return JURI::root().'plugins/content/codecitation/';
}
}
+120
View File
@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<install version="1.5" type="plugin" group="content">
<name>Content - CodeCitation</name>
<author>Konstantin Nizhegorodov ([email protected])</author>
<creationDate>August 22, 2009</creationDate>
<copyright>Copyright 2009 Konstantin Nizhegorodov. All rights reserved.</copyright>
<license>http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL</license>
<authorUrl>http://www.smartsoftwarebits.com</authorUrl>
<version>1.3.1</version>
<description>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}
</description>
<files>
<filename plugin="CodeCitation">CodeCitation.php</filename>
<filename>CodeCitationREADME.txt</filename>
<filename>codecitation/scripts/clipboard.swf</filename>
<filename>codecitation/scripts/shBrushAS3.js</filename>
<filename>codecitation/scripts/shBrushBash.js</filename>
<filename>codecitation/scripts/shBrushCpp.js</filename>
<filename>codecitation/scripts/shBrushCSharp.js</filename>
<filename>codecitation/scripts/shBrushCss.js</filename>
<filename>codecitation/scripts/shBrushDelphi.js</filename>
<filename>codecitation/scripts/shBrushDiff.js</filename>
<filename>codecitation/scripts/shBrushGroovy.js</filename>
<filename>codecitation/scripts/shBrushJava.js</filename>
<filename>codecitation/scripts/shBrushJavaFX.js</filename>
<filename>codecitation/scripts/shBrushJScript.js</filename>
<filename>codecitation/scripts/shBrushPerl.js</filename>
<filename>codecitation/scripts/shBrushPhp.js</filename>
<filename>codecitation/scripts/shBrushPlain.js</filename>
<filename>codecitation/scripts/shBrushPowerShell.js</filename>
<filename>codecitation/scripts/shBrushPython.js</filename>
<filename>codecitation/scripts/shBrushRuby.js</filename>
<filename>codecitation/scripts/shBrushScala.js</filename>
<filename>codecitation/scripts/shBrushSql.js</filename>
<filename>codecitation/scripts/shBrushVb.js</filename>
<filename>codecitation/scripts/shBrushXml.js</filename>
<filename>codecitation/scripts/shCore.js</filename>
<filename>codecitation/scripts/shLegacy.js</filename>
<filename>codecitation/styles/help.png</filename>
<filename>codecitation/styles/magnifier.png</filename>
<filename>codecitation/styles/page_white_code.png</filename>
<filename>codecitation/styles/page_white_copy.png</filename>
<filename>codecitation/styles/printer.png</filename>
<filename>codecitation/styles/shCore.css</filename>
<filename>codecitation/styles/shThemeDefault.css</filename>
<filename>codecitation/styles/shThemeDjango.css</filename>
<filename>codecitation/styles/shThemeEmacs.css</filename>
<filename>codecitation/styles/shThemeFadeToGrey.css</filename>
<filename>codecitation/styles/shThemeMidnight.css</filename>
<filename>codecitation/styles/shThemeRDark.css</filename>
<filename>codecitation/styles/wrapping.png</filename>
</files>
<languages>
<language tag="en-GB">en-GB.plg_content_CodeCitation.ini</language>
</languages>
<params>
<param name="theme" type="list" default="shThemeDefault.css" label="Color theme" description="Select color theme you preffer for the plugin">
<option value="shThemeDefault.css">Default</option>
<option value="shThemeDjango.css">Django</option>
<option value="shThemeEmacs.css">Emacs</option>
<option value="shThemeFadeToGrey.css">FadeToGrey</option>
<option value="shThemeMidnight.css">Midnight</option>
<option value="shThemeRDark.css">RDark</option>
</param>
<param name="alternativetag" type="text" default="" label="Alternative tag to trigger the plugin usage." description="If you think that {codecitation} is too long and preffer shorter syntax, feel free to specify your own tag. For example: code" />
<param type="spacer" default="&lt;b&gt;Default engine parameters values:&lt;/b&gt;" />
<param name="defaultlang" type="list" default="text" label="Default language to cite" description="If you cite mostly code writen on particular language, you are able to specify it here and ommit brush name in codecitation tag usage (shorten syntax).">
<option value="as3">actionscripts3</option>
<option value="bash">bash</option>
<option value="cpp">cpp</option>
<option value="csharp">csharp</option>
<option value="css">css</option>
<option value="diff">diff</option>
<option value="groovy">groovy</option>
<option value="java">java</option>
<option value="javafx">javafx</option>
<option value="javascript">javascript</option>
<option value="pascal">pascal</option>
<option value="perl">perl</option>
<option value="php">php</option>
<option value="powershell">powershell</option>
<option value="python">python</option>
<option value="ruby">ruby</option>
<option value="scala">scala</option>
<option value="sql">sql</option>
<option value="vb">vb</option>
<option value="xml">xml</option>
<option value="text">plain text</option>
</param>
<param name="auto-links" type="list" default="1" label="Auto-links" description="Allows you to turn detection of links in the codecitation block on and off. If the option is turned off, URLs won't be clickable.">
<option value="0">"false"</option>
<option value="1">"true"</option>
</param>
<param name="collapse" type="list" default="0" label="Collapse" description="Allows you to force citation block on the page to be collapsed by default.">
<option value="0">"false"</option>
<option value="1">"true"</option>
</param>
<param name="gutter" type="list" default="1" label="Gutter" description="Allows you to turn gutter with line numbers on and off by default.">
<option value="0">"false"</option>
<option value="1">"true"</option>
</param>
<param name="smart-tabs" type="list" default="1" label="Smart tabs" description="Allows you to turn smart tabs feature on and off by default.">
<option value="0">"false"</option>
<option value="1">"true"</option>
</param>
<param name="tab-size" type="text" default="4" label="Tab size" decription="Allows you to adjust default tab size." />
<param name="toolbar" type="list" default="1" label="Toolbar" description="Toggles toolbar on/off by default.">
<option value="0">"false"</option>
<option value="1">"true"</option>
</param>
<param name="wrap-lines" type="list" default="1" label="Wrap lines" description="Allows you to turn line wrapping feature on and off by default.">
<option value="0">"false"</option>
<option value="1">"true"</option>
</param>
</params>
</install>
@@ -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="<parameters for SyntaxHighligh engine>"] [width="<>"]}
<text to be formatted goes here>
{/codecitation}
where:
<parameters for SyntaxHighligh engine> is a parameter string for the engine - see http://www.smartsoftwarebits.com/index.php/codecitation/69-supported-brushes-and-parameters
<width> is an optional parameter to specify <div> 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.