liberty
[ class tree: liberty ] [ index: liberty ] [ all elements ]

Source for file data.code.php

Documentation is available at data.code.php

  1. <?php
  2. /**
  3.  * @version  $Revision$
  4.  * @package  liberty
  5.  * @subpackage plugins_data
  6.  */
  7. // +----------------------------------------------------------------------+
  8. // | Copyright (c) 2004, bitweaver.org
  9. // +----------------------------------------------------------------------+
  10. // | All Rights Reserved. See below for details and a complete list of authors.
  11. // | Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details
  12. // |
  13. // | For comments, please use phpdocu.sourceforge.net documentation standards!!!
  14. // | -> see http://phpdocu.sourceforge.net/
  15. // +----------------------------------------------------------------------+
  16. // | Author (TikiWiki): Luis Argerich <lrargerich@users.sourceforge.net>
  17. // | Reworked for Bitweaver (& Undoubtedly Screwed-Up)
  18. // | by: StarRider <starrrider@users.sourceforge.net>
  19. // +----------------------------------------------------------------------+
  20. // $Id$
  21.  
  22. /**
  23.  * definitions
  24.  */
  25. define'PLUGIN_GUID_DATACODE''datacode' );
  26. global $gLibertySystem;
  27. $pluginParams array (
  28.     'tag'                 => 'CODE',
  29.     'auto_activate'       => TRUE,
  30.     'requires_pair'       => TRUE,
  31.     'load_function'       => 'data_code',
  32.     'title'               => 'Code',
  33.     'help_page'           => 'DataPluginCode',
  34.     'description'         => tra"Displays the Source Code Snippet between {code} blocks." ),
  35.     'help_function'       => 'data_code_help',
  36.     'syntax'              => "{code source= num= }"tra"Sorce Code Snippet" "{/code}",
  37.     'plugin_type'         => DATA_PLUGIN,
  38.     'plugin_settings_url' => LIBERTY_PKG_URL.'admin/plugins/data_code.php',
  39. );
  40. $gLibertySystem->registerPluginPLUGIN_GUID_DATACODE$pluginParams );
  41. $gLibertySystem->registerDataTag$pluginParams['tag']PLUGIN_GUID_DATACODE );
  42.  
  43. // Help Function
  44. function data_code_help({
  45.     $help =
  46.         '<table class="data help">'
  47.             .'<tr>'
  48.                 .'<th>' tra"Key" '</th>'
  49.                 .'<th>' tra"Type" '</th>'
  50.                 .'<th>' tra"Comments" '</th>'
  51.             .'</tr>'
  52.             .'<tr class="odd">'
  53.                 .'<td>source</td>'
  54.                 .'<td>' tra"key-word"'<br />' tra("(optional)"'</td>'
  55.                 .'<td>' tra"Defines the format of the Source Code Snippet. Possible values are:");
  56.     iffile_existsUTIL_PKG_PATH.'geshi/geshi.php' ) ) {
  57.         $help $help '<br />
  58.             <strong>ActionScript</strong> &bull;
  59.             <strong>Ada</strong> &bull;
  60.             Apache Log File = <strong>Apache</strong> &bull;
  61.             <strong>AppleScript</strong> &bull;
  62.             ASM (NASM based) = <strong>Asm</strong> &bull;
  63.             <strong>ASP</strong> &bull;
  64.             AutoCAD DCL = <strong>CadDcl</strong> &bull;
  65.             AutoCAD LISP = <strong>CadLisp</strong> &bull;
  66.             <strong>Bash</strong> &bull;
  67.             <strong>BLITZ BASIC</strong> &bull;
  68.             <strong>C</strong> &bull;
  69.             C++ = <strong>Cpp</strong> &bull;
  70.             C# = <strong>CSharp</strong> &bull;
  71.             C for Macs = <strong>C_Mac</strong> &bull;
  72.             <strong>CSS</strong> &bull;
  73.             <strong>D</strong> &bull;
  74.             <strong>Delphi</strong> &bull;
  75.             Diff Output = <strong>Diff</strong> &bull;
  76.             <strong>DIV</strong> &bull;
  77.             <strong>DOS</strong> &bull;
  78.             <strong>Eiffel</strong> &bull;
  79.             <strong>FreeBasic</strong> &bull;
  80.             <strong>GML</strong> &bull;
  81.             HTML (4.0.1) = <strong>Html4Strict</strong> &bull;
  82.             <strong>ini</strong> &bull;
  83.             <strong>Inno</strong> &bull;
  84.             <strong>Java</strong> &bull;
  85.             <strong>JavaScript</strong> &bull;
  86.             <strong>Lisp</strong> &bull;
  87.             <strong>Lua</strong> &bull;
  88.             <strong>MatLab</strong> &bull;
  89.             <strong>MpAsm</strong> &bull;
  90.             <strong>MySQL</strong> &bull;
  91.             NullSoft Installer = <strong>Niss</strong> &bull;
  92.             Objective C = <strong>ObjC</strong> &bull;
  93.             <strong>OCaml</strong> &bull;
  94.             OpenOffice.org Basic = <strong>OoBas</strong> &bull;
  95.             <strong>Oracle8</strong> &bull;
  96.             <strong>Pascal</strong> &bull;
  97.             <strong>Perl</strong> &bull;
  98.             <strong>Php</strong> &bull;
  99.             <strong>Php_Brief</strong> &bull;
  100.             <strong>Python</strong> &bull;
  101.             QuickBasic = <strong>QBasic</strong> &bull;
  102.             <strong>Ruby</strong> &bull;
  103.             <strong>Scheme</strong> &bull;
  104.             <strong>Smarty</strong> &bull;
  105.             <strong>SQL</strong> &bull;
  106.             VB.NET = <strong>VbNet</strong> &bull;
  107.             <strong>VHDL</strong> &bull;
  108.             <strong>Visual Basic</strong> &bull;
  109.             VisualBasic = <strong>Vb</strong> &bull;
  110.             <strong>VisualFoxPro</strong> &bull;
  111.             <strong>XML</strong>';
  112.     else {
  113.         $help $help .'<strong>HTML</strong> or <strong>PHP</strong>. ';
  114.     }
  115.     $help $help '<br />' tra("The Default = "'<strong>PHP</strong></td>'
  116.             .'</tr>'
  117.             .'<tr class="even">'
  118.                 .'<td>title</td>'
  119.                 .'<td>'.tra"string").'<br />'.tra("(optional)").'</td>'
  120.                 .'<td>'.tra"Give the codelisting a title.").'</td>'
  121.             .'</tr>'
  122.             .'<tr class="odd">'
  123.                 .'<td>num</td>'
  124.                 .'<td>' .tra"boolean/number".'<br />'tra("(optional)"'</td>'
  125.                 .'<td>' .tra"Determins if Line Numbers are displayed with the code. Specifing:")
  126.                     .'<strong>TRUE / ON / YES /</strong> or a <strong>Number</strong> '
  127.                     .tra("will turn <strong>Line Numbering On</strong>. When a Number is specified - the Number is used for the first ")
  128.                     .tra("line instead of <strong>1</strong>. Any other value will turn <strong>Line Numbering OFF</strong> ")
  129.                     .tra("and only the <strong>Code</strong> will be displayed.")
  130.                     .'<br />' tra("The Default =".' <strong>FALSE</strong> ' .tra("Line Numbers are <strong>Not</strong> displayed.")
  131.                 .'</td>'
  132.             .'</tr>'
  133.         .'</table>'
  134.         . tra("Example: ""{code source='php' num='on'}" tra("Sorce Code Snippet""{/code}";
  135.     return $help;
  136. }
  137.  
  138. if!function_exists'unHtmlEntities' )) // avoid name collisions
  139.     function unHtmlEntities$pStr {
  140.         $tTbl get_html_translation_tableHTML_ENTITIES );
  141.         $tTbl array_flip$tTbl );
  142.         return strtr$pStr$tTbl );
  143.     }
  144. }
  145.  
  146. if!function_exists'deCodeHTML' )) // avoid name collisions
  147.     function deCodeHTML$pStr {
  148.         $pStr strtr$pStrarray_flipget_html_translation_tableHTML_ENTITIES )));
  149.         $pStr preg_replace"/&#([0-9]+);/me""chr('\\1')"$pStr );
  150.         return $pStr;
  151.     }
  152. }
  153.  
  154.  
  155. // Load Function
  156. function data_code$pData$pParams // Pre-Clyde Changes
  157.     global $gBitSystem;
  158.     extract$pParamsEXTR_SKIP );
  159.  
  160.     if!empty$colors and $colors == 'php' )) {
  161.         $source 'php';
  162.     }
  163.  
  164.     if!empty$in )) {
  165.         $source $in;
  166.     }
  167.  
  168.     $source = isset$source strtolower$source $gBitSystem->getConfig'liberty_plugin_code_default_source''php' );
  169.  
  170.     if!empty$num && !is_numeric$num )) {
  171.         switchstrtoupper$num )) {
  172.         case 'TRUE'case 'ON'case 'YES':
  173.             $num 1;
  174.             break;
  175.         default:
  176.             $num 0;
  177.             break;
  178.         }
  179.     }
  180.     $num isset$num )) $num FALSE;
  181.  
  182.     // trim any trailing spaces
  183.     $code '';
  184.     $lines explode"\n"$pData );
  185.     foreach$lines as $line {
  186.         $code .=  rtrim$line )."\n";
  187.     }
  188.  
  189.     $code unHtmlEntities$code );
  190.  
  191.     // Trim any leading blank lines
  192.     $code preg_replace'/^[\n\r]+/'""$code );
  193.     // Trim any trailing blank lines
  194.     iffile_existsUTIL_PKG_PATH.'geshi/geshi.php' )) {
  195.         $code preg_replace('/[\n\r]+$/'""$code );
  196.     else {
  197.         $code preg_replace('/[\n\r]+$/'"\n"$code );
  198.     }
  199.  
  200.     iffile_existsUTIL_PKG_PATH.'geshi/geshi.php' ) ) {
  201.         // Include the GeSHi library
  202.         include_onceUTIL_PKG_PATH.'geshi/geshi.php' );
  203.         $geshi new GeSHi($code$sourceUTIL_PKG_PATH.'geshi/geshi' );
  204.         if$num // Line Numbering has been requested
  205.             $geshi->enable_line_numbersGESHI_FANCY_LINE_NUMBERS );
  206.             ifis_numeric$num )) {
  207.                 $geshi->start_line_numbers_at$num );
  208.             }
  209.         }
  210.         $code deCodeHTMLhtmlentities$geshi->parse_code() ));
  211.     else {
  212.         // Line Numbering has been requested
  213.         if$num {
  214.             $lines explode"\n"$code );
  215.             $code '';
  216.             //Line Number
  217.             $i is_numeric$num )) $num 1;
  218.             foreach$lines as $line {
  219.                 ifstrlen$line {
  220.                     $code .= sprintf"%3d"$i ).": ".$line."\n";
  221.                     $i++;
  222.                 }
  223.             }
  224.         }
  225.  
  226.         switchstrtoupper$source )) {
  227.             case 'HTML':
  228.                 $code highlight_stringdeCodeHTML$code )TRUE );
  229.                 // Remove the first <code>" tags
  230.                 ifsubstr$code0== '<code>'{
  231.                     $code substr$code6strlen$code 13 ));
  232.                 }
  233.                 break;
  234.             case 'PHP':
  235.                 // Check it if code starts with PHP tags, if not: add 'em.
  236.                 if!preg_match'/^[ 0-9:]*<\?/i'$code )) {
  237.                     // The require these tags to function
  238.                     $code "<?php\n".$code."?>";
  239.                 }
  240.                 $code highlight_string$codeTRUE );
  241.                 // Replacement-map to replace Colors
  242.                 $convmap array(
  243.                     // The Default Color
  244.                     '#000000">' => '#004A4A">',
  245.                     // Color for Functions/Variables/Numbers/&/Constants
  246.                     '#006600">' => '#2020FF">',
  247.                     // Color for KeyWords
  248.                     '#0000CC">' => '#209020">',
  249.                     // Color for Constants
  250.                     '#FF9900">' => '#BB4040">',
  251.                     // Color for Strings
  252.                     '#CC0000">' => '#903030">'
  253.                 );
  254.                 // <-- # Assigned by HighLight_String / --> # Color to be Displayed
  255.                 // NOTE: The colors assigned by HighLight_String have changed with different versions of PHP - these are for PHP 4.3.4
  256.                 // Change the Colors
  257.                 $code strtr$code$convmap );
  258.                 break;
  259.             default:
  260.                 $code highlight_string$codeTRUE );
  261.                 break;
  262.         }
  263.  
  264.         $code "<pre>$code</pre>";
  265.     }
  266.  
  267.     return !empty$title '<p class="codetitle">'.$title.'</p>' "" )."<div class='codelisting'>".$code."</div>";
  268. }
  269. ?>

Documentation generated on Wed, 29 Jul 2015 13:56:18 +0000 by phpDocumentor 1.5.0-lsces