Source for file data.code.php
Documentation is available at data.code.php
* @subpackage plugins_data
// +----------------------------------------------------------------------+
// | Copyright (c) 2004, bitweaver.org
// +----------------------------------------------------------------------+
// | All Rights Reserved. See below for details and a complete list of authors.
// | Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details
// | For comments, please use phpdocu.sourceforge.net documentation standards!!!
// | -> see http://phpdocu.sourceforge.net/
// +----------------------------------------------------------------------+
// | Author (TikiWiki): Luis Argerich <lrargerich@users.sourceforge.net>
// | Reworked for Bitweaver (& Undoubtedly Screwed-Up)
// | by: StarRider <starrrider@users.sourceforge.net>
// +----------------------------------------------------------------------+
define( 'PLUGIN_GUID_DATACODE', 'datacode' );
'load_function' => 'data_code',
'help_page' => 'DataPluginCode',
'description' => tra( "Displays the Source Code Snippet between {code} blocks." ),
'help_function' => 'data_code_help',
'syntax' => "{code source= num= }". tra( "Sorce Code Snippet" ) . "{/code}",
'<table class="data help">'
. '<th>' . tra( "Key" ) . '</th>'
. '<th>' . tra( "Type" ) . '</th>'
. '<th>' . tra( "Comments" ) . '</th>'
. '<td>' . tra( "key-word") . '<br />' . tra("(optional)") . '</td>'
. '<td>' . tra( "Defines the format of the Source Code Snippet. Possible values are:");
<strong>ActionScript</strong> •
<strong>Ada</strong> •
Apache Log File = <strong>Apache</strong> •
<strong>AppleScript</strong> •
ASM (NASM based) = <strong>Asm</strong> •
<strong>ASP</strong> •
AutoCAD DCL = <strong>CadDcl</strong> •
AutoCAD LISP = <strong>CadLisp</strong> •
<strong>Bash</strong> •
<strong>BLITZ BASIC</strong> •
<strong>C</strong> •
C++ = <strong>Cpp</strong> •
C# = <strong>CSharp</strong> •
C for Macs = <strong>C_Mac</strong> •
<strong>CSS</strong> •
<strong>D</strong> •
<strong>Delphi</strong> •
Diff Output = <strong>Diff</strong> •
<strong>DIV</strong> •
<strong>DOS</strong> •
<strong>Eiffel</strong> •
<strong>FreeBasic</strong> •
<strong>GML</strong> •
HTML (4.0.1) = <strong>Html4Strict</strong> •
<strong>ini</strong> •
<strong>Inno</strong> •
<strong>Java</strong> •
<strong>JavaScript</strong> •
<strong>Lisp</strong> •
<strong>Lua</strong> •
<strong>MatLab</strong> •
<strong>MpAsm</strong> •
<strong>MySQL</strong> •
NullSoft Installer = <strong>Niss</strong> •
Objective C = <strong>ObjC</strong> •
<strong>OCaml</strong> •
OpenOffice.org Basic = <strong>OoBas</strong> •
<strong>Oracle8</strong> •
<strong>Pascal</strong> •
<strong>Perl</strong> •
<strong>Php</strong> •
<strong>Php_Brief</strong> •
<strong>Python</strong> •
QuickBasic = <strong>QBasic</strong> •
<strong>Ruby</strong> •
<strong>Scheme</strong> •
<strong>Smarty</strong> •
<strong>SQL</strong> •
VB.NET = <strong>VbNet</strong> •
<strong>VHDL</strong> •
<strong>Visual Basic</strong> •
VisualBasic = <strong>Vb</strong> •
<strong>VisualFoxPro</strong> •
$help = $help . '<strong>HTML</strong> or <strong>PHP</strong>. ';
$help = $help . '<br />' . tra("The Default = ") . '<strong>PHP</strong></td>'
. '<td>'. tra( "string"). '<br />'. tra("(optional)"). '</td>'
. '<td>'. tra( "Give the codelisting a title."). '</td>'
. '<td>' . tra( "boolean/number") . '<br />'. tra("(optional)") . '</td>'
. '<td>' . tra( "Determins if Line Numbers are displayed with the code. Specifing:")
. '<strong>TRUE / ON / YES /</strong> or a <strong>Number</strong> '
. tra("will turn <strong>Line Numbering On</strong>. When a Number is specified - the Number is used for the first ")
. tra("line instead of <strong>1</strong>. Any other value will turn <strong>Line Numbering OFF</strong> ")
. tra("and only the <strong>Code</strong> will be displayed.")
. '<br />' . tra("The Default =") . ' <strong>FALSE</strong> ' . tra("Line Numbers are <strong>Not</strong> displayed.")
. tra("Example: ") . "{code source='php' num='on'}" . tra("Sorce Code Snippet") . "{/code}";
return strtr( $pStr, $tTbl );
$pStr = preg_replace( "/&#([0-9]+);/me", "chr('\\1')", $pStr );
function data_code( $pData, $pParams ) { // Pre-Clyde Changes
if( !empty( $colors ) and ( $colors == 'php' )) {
$source = isset ( $source ) ? strtolower( $source ) : $gBitSystem->getConfig( 'liberty_plugin_code_default_source', 'php' );
case 'TRUE': case 'ON': case 'YES':
$num = ( isset ( $num )) ? $num : FALSE;
// trim any trailing spaces
foreach( $lines as $line ) {
$code .= rtrim( $line ). "\n";
// Trim any leading blank lines
// Trim any trailing blank lines
// Include the GeSHi library
$geshi = new GeSHi($code, $source, UTIL_PKG_PATH. 'geshi/geshi' );
if( $num ) { // Line Numbering has been requested
$geshi->enable_line_numbers( GESHI_FANCY_LINE_NUMBERS );
$geshi->start_line_numbers_at( $num );
// Line Numbering has been requested
foreach( $lines as $line ) {
$code .= sprintf( "%3d", $i ). ": ". $line. "\n";
// Remove the first <code>" tags
if( substr( $code, 0, 6 ) == '<code>') {
// Check it if code starts with PHP tags, if not: add 'em.
// The require these tags to function
$code = "<?php\n". $code. "?>";
// Replacement-map to replace Colors
'#000000">' => '#004A4A">',
// Color for Functions/Variables/Numbers/&/Constants
'#006600">' => '#2020FF">',
'#0000CC">' => '#209020">',
'#FF9900">' => '#BB4040">',
'#CC0000">' => '#903030">'
// <-- # Assigned by HighLight_String / --> # Color to be Displayed
// NOTE: The colors assigned by HighLight_String have changed with different versions of PHP - these are for PHP 4.3.4
$code = strtr( $code, $convmap );
$code = "<pre>$code</pre>";
return ( !empty( $title ) ? '<p class="codetitle">'. $title. '</p>' : "" ). "<div class='codelisting'>". $code. "</div>";
|