see http://phpdocu.sourceforge.net/ // +----------------------------------------------------------------------+ // | Author (TikiWiki): Luis Argerich // | Reworked for Bitweaver (& Undoubtedly Screwed-Up) // | by: StarRider // +----------------------------------------------------------------------+ // $Id$ /** * definitions */ define( 'PLUGIN_GUID_DATACODE', 'datacode' ); global $gLibertySystem; $pluginParams = [ 'tag' => 'CODE', 'auto_activate' => true, 'requires_pair' => true, 'load_function' => 'data_code', 'title' => 'Code', 'help_page' => 'DataPluginCode', 'description' => KernelTools::tra( "Displays the Source Code Snippet between {code} blocks." ), 'help_function' => 'data_code_help', 'syntax' => "{code source= num= }". KernelTools::tra( "Sorce Code Snippet" ) . "{/code}", 'plugin_type' => DATA_PLUGIN, 'plugin_settings_url' => LIBERTY_PKG_URL.'admin/plugins/data_code.php', ]; $gLibertySystem->registerPlugin( PLUGIN_GUID_DATACODE, $pluginParams ); $gLibertySystem->registerDataTag( $pluginParams['tag'], PLUGIN_GUID_DATACODE ); // Help Function function data_code_help(): string { $help = '' .'' .'' .'' .'' .'' .'' .'' .'' .'' .'' .'' .'' .'' .'' .'' .'' .'' .'' .'' .'' .'
' . KernelTools::tra( "Key" ) . '' . KernelTools::tra( "Type" ) . '' . KernelTools::tra( "Comments" ) . '
source' . KernelTools::tra( "key-word") . '
' . KernelTools::tra("(optional)") . '
' . KernelTools::tra( "Defines the format of the Source Code Snippet. Possible values are:"); if( file_exists( UTIL_PKG_INCLUDE_PATH.'geshi/geshi.php' ) ) { $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 .= 'HTML or PHP. '; } $help = $help . '
' . KernelTools::tra("The Default = ") . 'PHP
title'.KernelTools::tra( "string").'
'.KernelTools::tra("(optional)").'
'.KernelTools::tra( "Give the codelisting a title.").'
num' .KernelTools::tra( "boolean/number") .'
'. KernelTools::tra("(optional)") . '
' .KernelTools::tra( "Determins if Line Numbers are displayed with the code. Specifing:") .'true / ON / YES / or a Number ' .KernelTools::tra("will turn Line Numbering On. When a Number is specified - the Number is used for the first ") .KernelTools::tra("line instead of 1. Any other value will turn Line Numbering OFF ") .KernelTools::tra("and only the Code will be displayed.") .'
' . KernelTools::tra("The Default =") .' false ' .KernelTools::tra("Line Numbers are Not displayed.") .'
' . KernelTools::tra("Example: ") . "{code source='php' num='on'}" . KernelTools::tra("Sorce Code Snippet") . "{/code}"; return $help; } if( !function_exists( 'unHtmlEntities' )) { // avoid name collisions function unHtmlEntities( $pStr ) { $tTbl = get_html_translation_table( HTML_ENTITIES ); $tTbl = array_flip( $tTbl ); return strtr( $pStr, $tTbl ); } } if( !function_exists( 'deCodeHTML' )) { // avoid name collisions function deCodeHTML( $pStr ) { $pStr = strtr( $pStr, array_flip( get_html_translation_table( HTML_ENTITIES ))); $pStr = preg_replace_callback( "/&#([0-9]+);/m", function($matches){ foreach($matches as $match){ return chr($match); } }, $pStr ); return $pStr; } } // Load Function function data_code( $pData, $pParams ) { // Pre-Clyde Changes global $gBitSystem; extract( $pParams, EXTR_SKIP ); if( !empty( $colors ) and ( $colors == 'php' )) { $source = 'php'; } if( !empty( $in )) { $source = $in; } $source = isset( $source ) ? strtolower( $source ) : $gBitSystem->getConfig( 'liberty_plugin_code_default_source', 'php' ); if( !empty( $num ) && !is_numeric( $num )) { switch( strtoupper( $num )) { case 'true': case 'ON': case 'YES': $num = 1; break; default: $num = 0; break; } } $num = $num ?? false; // trim any trailing spaces $code = ''; $lines = explode( "\n", $pData ); 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 $code = file_exists( UTIL_PKG_INCLUDE_PATH.'geshi/geshi.php' ) ? preg_replace('/[\n\r]+$/', "", $code ) : preg_replace('/[\n\r]+$/', "\n", $code ); if( file_exists( UTIL_PKG_INCLUDE_PATH.'geshi/geshi.php' ) ) { // Include the GeSHi library include_once UTIL_PKG_INCLUDE_PATH.'geshi/geshi.php'; $geshi = new \GeSHi($code, $source, UTIL_PKG_INCLUDE_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 { // Line Numbering has been requested if( $num ) { $lines = explode( "\n", $code ); $code = ''; //Line Number $i = ( is_numeric( $num )) ? $num : 1; foreach( $lines as $line ) { if( strlen( $line ) > 1 ) { $code .= sprintf( "%3d", $i ).": ".$line."\n"; $i++; } } } switch( strtoupper( $source )) { case 'HTML': $code = highlight_string( deCodeHTML( $code ), true ); // Remove the first " tags if( substr( $code, 0, 6 ) == '') { $code = substr( $code, 6, strlen( $code ) - 13); } break; case 'PHP': // Check it if code starts with PHP tags, if not: add 'em. if( !preg_match( '/^[ 0-9:]*<\?/i', $code )) { // The require these tags to function $code = ""; } $code = highlight_string( $code, true ); // Replacement-map to replace Colors $convmap = [ // The Default Color '#000000">' => '#004A4A">', // Color for Functions/Variables/Numbers/&/Constants '#006600">' => '#2020FF">', // Color for KeyWords '#0000CC">' => '#209020">', // Color for Constants '#FF9900">' => '#BB4040">', // Color for Strings '#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 // Change the Colors $code = strtr( $code, $convmap ); break; default: $code = highlight_string( $code, true ); break; } // highlight_string() already wraps in
 in PHP 8.x
		if( strpos( $code, '
' ) === false ) {
			$code = "
$code
"; } } return ( !empty( $title ) ? '

'.$title.'

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