Subdomain Posts
None | 2 days ago
Python | 19 days ago
C# | 24 days ago
C# | 25 days ago
C# | 26 days ago
C# | 26 days ago
C | 170 days ago
Python | 173 days ago
C++ | 194 days ago
PHP | 258 days ago
Recent Posts
None | 2 sec ago
C# | 14 sec ago
None | 21 sec ago
None | 27 sec ago
Delphi | 31 sec ago
C# | 1 min ago
FreeBasic | 1 min ago
None | 1 min ago
None | 1 min ago
None | 1 min ago
Sitereport
Find cool info about any domain on the internet?
visit sitereport
Free Subdomains
Want a pastebin.com sub-domain for your community?
learn more...
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
Learn a little bit about the new Pastebin.com on our help page. hide message
By IceDragon on the 15th of Feb 2009 08:37:45 AM Download | Raw | Embed | Report
  1. <?php                                                                                                      
  2.  
  3. /* .-= ds_lib.php4 =======================================================-. *\
  4.  * | DragonSpeak Manipulation Library 1.0                                  | *
  5.  * |=======================================================================| *
  6.  * | This library was derived from Ecu's DragonSpeak parser and provides   | *
  7.  * | functions to display DragonSpeak with HTML-based syntax hilighting    | *
  8.  * | along with possible some other features.                              | *
  9.  * |                                                                       | *
  10.  * | Rewritten by Artex <artex@furcadia.com> http://icerealm.quickfox.org/ | *
  11. \* '-=====================================================================-' */
  12.  
  13. /*** Configuration ***/
  14. // These colors will be used in syntax hilighting. If you don't want to use
  15. // them, but would rather rely on custom CSS, use ds_hilight($data,true).  
  16. $ds_colors = array(                                                        
  17.         'ds_line'     => '#409070',                                        
  18.         'ds_variable' => '#904090',                                        
  19.         'ds_number'   => '#907040',                                        
  20.         'ds_remark'   => '#4070A0'                                        
  21. );                                                                        
  22.  
  23.  
  24. /*** Functions ***/
  25.  
  26. // Purpose: Application of syntax hilighting on specific DragonSpeak data.
  27. // Returns: A string with the DragonSpeak syntax hilighting applied to it.
  28. function ds_hilight( $data, $custom_css = false )                        
  29. {                                                                        
  30.         global $ds_colors;                                                
  31.  
  32.         // Setting the <span/> tags.
  33.         if( $custom_css )          
  34.         {                          
  35.                 $span_ds_line     = "<span class='ds_line'>";
  36.                 $span_ds_variable = "<span class='ds_variable'>";
  37.                 $span_ds_number   = "<span class='ds_number'>";  
  38.                 $span_ds_remark   = "<span class='ds_remark'>";  
  39.         }                                                        
  40.         else                                                    
  41.         {                                                        
  42.                 $span_ds_line     = "<span style='color: $ds_colors[ds_line];'>";
  43.                 $span_ds_variable = "<span style='color: $ds_colors[ds_variable];'>";
  44.                 $span_ds_number   = "<span style='color: $ds_colors[ds_number];'>";  
  45.                 $span_ds_remark   = "<span style='color: $ds_colors[ds_remark]; font-style: italic;'>";
  46.         }                                                                                              
  47.         $span_off = "</span>";                                                                        
  48.  
  49.         // If this is a string, turn this into an array.
  50.         if( !is_array( $data ) )                        
  51.                 $data = explode( "\n", str_replace( "\r", "", $data ) );
  52.  
  53.         $buffer = '';
  54.  
  55.         // Parsing line-by-line.
  56.         foreach( $data as $line )
  57.         {                        
  58.                 // Converting all <, > and & so they're not mistaken with HTML.
  59.                 $order   = array( "<",    ">" );                              
  60.                 $replace = array( "&lt;", "&gt;" );                            
  61.                 $line    = str_replace( "&", "&amp;", $line );                
  62.                 $line    = str_replace( $order, $replace, $line );            
  63.  
  64.                 // Marking remarked text for the future so it won't be colored - we already did.
  65.                 $order   = '/^(\s*)([\*&a-zA-Z].*)/';                                          
  66.                 $replace = "*\\1$span_ds_remark\\2$span_off";                                  
  67.                 $line    = preg_replace( $order, $replace, $line );                            
  68.  
  69.                 // Spaces
  70.                 $order   = array( "  ", "    ", "     ", "      ", "       " );
  71.                 $replace = "&nbsp;&nbsp;";                                    
  72.                 $line    = str_replace( $order, $replace, $line );            
  73.                 $line    = str_replace( "\t", "&nbsp;&nbsp;&nbsp;&nbsp;", $line );
  74.  
  75.                 // Handle DSPK & Endtriggers Line
  76.                 if( $line[0] != '*' )            
  77.                 {                                
  78.                         $order  = array(        
  79.                           '/(?<=[^\d])(\d+)(?=[^\d])(?![^()\r\n]{0,10}\))(?![^{}\r\n]{0,10}\})/',
  80.                           '/(\(\s*\d+\s*:\s*\d+\s*\))/',                                          
  81.                           '/(\(\s*(?:\d+|%\w+(?:\.[xy]))\s*(?:,\s*(?:\d+|%\w+(?:\.[xy]))\s*)?\))/',
  82.                           '/(%\w+(?:\.[xy]))/',                                                    
  83.                           '/(%\w+(?:))/',                                                          
  84.                           '/({.*?})/',                                                              
  85.                           '/^\s/',                                                                  
  86.                           "/\n/"                                                                    
  87.                         );                                                                          
  88.                         $replace = array(                                                          
  89.                           "$span_ds_number\\0$span_off",                                            
  90.                           "$span_ds_line\\0$span_off",                                              
  91.                           "$span_ds_number\\0$span_off",                                            
  92.                           "$span_ds_variable\\0$span_off",                                          
  93.                           "$span_ds_variable\\0$span_off",                                          
  94.                           "$span_ds_number\\0$span_off",                                            
  95.                           "&nbsp;",
  96.                           ""
  97.                         );
  98.                         $line = preg_replace( $order, $replace, $line."\n" );
  99.                 }
  100.                 else
  101.                 {
  102.                         $line = substr( $line, 1 );
  103.                         $line = preg_replace( '/^\s/', "&nbsp;", $line );
  104.                 }
  105.  
  106.                 // End of line.
  107.                 $buffer .= stripslashes( $line."<br />\n" );
  108.         }
  109.  
  110.         // Returning converted data.
  111.         return $buffer;
  112. }
  113.  
  114. ?>
Submit a correction or amendment below. Make A New Post
To highlight particular lines, prefix each line with @h@
Syntax highlighting:
Post expiration:
Post exposure:
Name / Title:
Email: