see http://phpdocu.sourceforge.net/ // +----------------------------------------------------------------------+ // | Author (TikiWiki): Luis Argerich // | Reworked for Bitweaver (& Undoubtedly Screwed-Up) // | by: StarRider // +----------------------------------------------------------------------+ // $Id: data.code.php,v 1.20 2006/08/27 08:59:33 bitweaver Exp $ /** * definitions */ define( 'PLUGIN_GUID_DATACODE', 'datacode' ); global $gLibertySystem; $pluginParams = array ( 'tag' => 'CODE', 'auto_activate' => TRUE, 'requires_pair' => TRUE, 'load_function' => 'data_code', 'title' => '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}", 'path' => LIBERTY_PKG_PATH.'plugins/data.code.php', 'security' => 'registered', 'plugin_type' => DATA_PLUGIN ); $gLibertySystem->registerPlugin( PLUGIN_GUID_DATACODE, $pluginParams ); $gLibertySystem->registerDataTag( $pluginParams['tag'], PLUGIN_GUID_DATACODE ); // Help Function function data_code_help() { $help = '' .'' .'' .'' .'' .'' .'' .'' .'' .'' .'' .'' .'' .'' .'' .'' .'' .'' .'' .'' .'' .'
' . tra( "Key" ) . '' . tra( "Type" ) . '' . tra( "Comments" ) . '
source' . tra( "key-word") . '
' . tra("(optional)") . '
' . tra( "Defines the format of the Source Code Snippet. Possible values are:"); if( file_exists( UTIL_PKG_PATH.'geshi/geshi.php' ) ) { $help = $help . '
ActionScriptAda • Apache Log File = ApacheAppleScript • ASM (NASM based) = AsmASP • AutoCAD DCL = CadDcl • AutoCAD LISP = CadLispBashBLITZ BASICC • C++ = Cpp • C# = CSharp • C for Macs = C_MacCSSDDelphi • Diff Output = DiffDIVDOSEiffelFreeBasicGML • HTML (4.0.1) = Html4StrictiniInnoJavaJavaScriptLispLuaMatLabMpAsmMySQL • NullSoft Installer = Niss • Objective C = ObjCOCaml • OpenOffice.org Basic = OoBasOracle8PascalPerlPhpPhp_BriefPython • QuickBasic = QBasicRubySchemeSmartySQL • VB.NET = VbNetVHDLVisual Basic • VisualBasic = VbVisualFoxProXML'; } else { $help = $help .'HTML or PHP. '; } $help = $help . '
' . tra("The Default = ") . 'PHP
title'.tra( "string").'
'.tra("(optional)").'
'.tra( "Give the codelisting a title.").'
num' .tra( "boolean/number") .'
'. tra("(optional)") . '
' .tra( "Determins if Line Numbers are displayed with the code. Specifing:") .'TRUE / ON / YES / or a Number ' .tra("will turn Line Numbering On. When a Number is specified - the Number is used for the first ") .tra("line instead of 1. Any other value will turn Line Numbering OFF ") .tra("and only the Code will be displayed.") .'
' . tra("The Default =") .' FALSE ' .tra("Line Numbers are Not displayed.") .'
' . tra("Example: ") . "{CODE source='php' num='on' }" . tra("Sorce Code Snippet") . "{/code}"; return $help; } if( !function_exists( 'unHtmlEntities' )) { // avoid name collisions function unHtmlEntities($str) { $tTbl = get_html_translation_table(HTML_ENTITIES); $tTbl = array_flip($tTbl); return strtr($str, $tTbl); } } if( !function_exists( 'deCodeHTML' )) { // avoid name collisions function deCodeHTML($str) { $str = strtr($str, array_flip(get_html_translation_table(HTML_ENTITIES))); $str = preg_replace("/&#([0-9]+);/me", "chr('\\1')", $str); return $str; } } // Load Function function data_code( $data, $params ) { // Pre-Clyde Changes // Parameters were $In & $Colors // Added testing to maintain Pre-Clyde compatability // $num = NULL; extract ($params, EXTR_SKIP); // This maintains Pre-Clyde Parameters if (isset($colors) and ($colors == 'php') ) $source = 'php'; if (isset($in) ) $source = $in; $source = isset($source) ? strtolower($source) : 'php'; // if not specified the default is HTML if (isset($in)) $num = $in; // This maintains Pre-Clyde Parameters if (isset($num) && (!is_numeric ($num))) { switch (strtoupper($num)) { case 'TRUE': case 'ON': case 'YES': $num = 1; break; default: // could have done FALSE/OFF/NO but we want any other value to be False $num = 0; break; } } $num = (isset($num)) ? $num : FALSE; // trim any trailing spaces $code = ''; $lines = explode("\n", $data); foreach ($lines as $line) { $code .= rtrim($line) . "\n"; } $code = unHtmlEntities( $code ); // Trim any leading blank lines $code = preg_replace('/^[\n\r]+/', "",$code); // Trim any trailing blank lines if( file_exists( UTIL_PKG_PATH.'geshi/geshi.php' ) ) { $code = preg_replace('/[\n\r]+$/', "",$code); } else { $code = preg_replace('/[\n\r]+$/', "\n",$code); } if( file_exists( UTIL_PKG_PATH.'geshi/geshi.php' ) ) { // Include the GeSHi library include_once( UTIL_PKG_PATH.'geshi/geshi.php' ); $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); if (is_numeric($num)) $geshi->start_line_numbers_at($num); } $code = deCodeHTML(htmlentities($geshi->parse_code())); } else { if ($num) { // Line Numbering has been requested $lines = explode("\n", $code); $code = ''; $i = (is_numeric($num)) ? $num : 1; //Line Number foreach ($lines as $line) { if (strlen($line) > 1) { $code .= sprintf("%3d", $i) . ": " . $line . "\n"; $i++; } } } switch (strtoupper($source)) { // I used a switch here to make it easy to expand this plugin for other kinds of source code case 'HTML': $code = highlight_string(deCodeHTML($code),true); if (substr($code, 0, 6) == '') { // Remove the first " tags $code = substr($code, 6, (strlen($code) - 13)); } break; case 'PHP': if(!preg_match( '/^[ 0-9:]*<\?/i', $code ) ) { // Check it if code starts with PHP tags, if not: add 'em. $code = ""; // The require these tags to function } $code = highlight_string($code, true); $convmap = array( // Replacement-map to replace Colors '#000000">' => '#004A4A">', // The Default Color '#006600">' => '#2020FF">', // Color for Functions/Variables/Numbers/&/Constants '#0000CC">' => '#209020">', // Color for KeyWords '#FF9900">' => '#BB4040">', // Color for Constants '#CC0000">' => '#903030">' // Color for Strings );// <-- # 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); // Change the Colors break; default: $code = highlight_string( $code, true ); break; } $code = "
$code
"; } return "".( !empty( $title ) ? '

'.$title.'

' : "" )."
".$code."
"; } ?>