How to Fix Dean Lee’s Source Code Highlight Plugin

Ron Fredericks writes: In my previous post, I discuss Dean Lee‘s source code syntax highlighting plugin for WordPress. It delivers all the great features of the GeSHi open-source highlight project for Wordress bloggers.

Yet some source code displayed badly – turning a developer’s nice clean style into a chaotic and messy format. I demonstrated the display problem using a perl sendmail script I plan to discuss in a future blog post. The problem had to do with some kind of whitespace word wrap issue.

I tested various features of CSS and DIV tag attributes created by Dean’s plugin and the GeSHi php code. I am happy to say, I found a simple one-line solution. My solution is in updating Dean’s CSS container class to force white space not to wrap.

Here is my solution:
Add this property to Dean’s “ch_code_container” CSS class:

white-space: nowrap;


Here is the complete update I made to my WordPress template:
wp-content/themes/eciWidget/style.css

code=css
  1.  
  2. /* Add the following CSS styles modified from Dean’s code Highlighter */
  3. /* Embedded Components, Inc. CSS classes update: version 1.0          */
  4. .ch_code_container {
  5. background-color: #f0f0f0;
  6. border: 1px solid #C3CED9;
  7. padding: 0px 0px 0 0;
  8. width: 100%;
  9. text-align: left;
  10. font-size:1.00em;
  11. overflow:auto;
  12. white-space: nowrap;
  13. }
  14. .ch_code_container .head
  15. {
  16. color: #808080;
  17. font-weight: bold;
  18. background-color: #f0f0ff;
  19. border-bottom: 1px solid #d0d0d0;
  20. padding: 2px;
  21. }
  22.  

So now let’s see how this change affects the source code highlight format using my sendmail perl script example. Compared to the image shown in my previous post, the updated highlight plugin CSS style change solved the problem. Now all lines of source code display as one line each, with the horizontal scroll bar used to see the full text:

code=perl
  1.  
  2. #!/usr/bin/perl
  3. ##############################################################################
  4. # FormMail                        Version 1.92                               #
  5. # Copyright 1995-2002 Matt Wright mattw@scriptarchive.com                    #
  6. # Created 06/09/95                Last Modified 04/21/02                     #
  7. # Matt’s  Script Archive, Inc.:    http://www.scriptarchive.com/             #
  8. #                                                                            #
  9. ##############################################################################
  10. # SPAM FIX                                                                   #
  11. # Embedded Components, Inc.:      http://www.embeddedcomponents.com          #
  12. # Ron Fredericks                  ronf@embeddedcomponents.com                #
  13. # Created 05/18/07                Last Modified 05/23/07                     #
  14. #                                                                            #
  15. # Logic: if number of Internet links exceed $spamChunksMax,                  #
  16. # then print a default error message instead of sending email.               #
  17. #                                                                            #
  18. # define number of links that can appear in an email                         #
  19. $spamChunksMax = 4;                                                          #
  20. # define web address to include in "too many links error message"            #
  21. $spamChunkErrorLink = "http://www.embeddedcomponents.com";                   #
  22. # define the spam error message                                              #
  23. $spamMessage = "Sorry, no spam today please…";                             #
  24. #                                                                            #
  25. # server-side spam test (search this phrase to find all script edits)        # 
  26. #                                                                            #
  27. ##############################################################################
  28. # COPYRIGHT NOTICE                                                           #
  29. # Copyright 1995-2002 Matthew M. Wright  All Rights Reserved.                #
  30. #                                                                            #
  31. # FormMail may be used and modified free of charge by anyone so long as this #
  32. # copyright notice and the comments above remain intact.  By using this      #
  33. # code you agree to indemnify Matthew M. Wright from any liability that      #
  34. # might arise from its use.                                                  #
  35. #                                                                            #
  36. # Selling the code for this program without prior written consent is         #
  37. # expressly forbidden.  In other words, please ask first before you try and  #
  38. # make money off of my program.                                              #
  39. #                                                                            #
  40. # Obtain permission before redistributing this software over the Internet or #
  41. # in any other medium. In all cases copyright and header must remain intact. #
  42. ##############################################################################
  43. # ACCESS CONTROL FIX: Peter D. Thompson Yezek                                #
  44. #                     http://www.securityfocus.com/archive/1/62033           #
  45. ##############################################################################
  46. # Define Variables                                                           #
  47. #      Detailed Information Found In README File.                            #
  48.  
  49. # $mailprog defines the location of your sendmail program on your unix       #
  50. # system. The flags -i and -t should be passed to sendmail in order to       #
  51. # have it ignore single dots on a line and to read message for recipients    #
  52.  
  53. $mailprog = ‘/usr/lib/sendmail -i -t’;
  54.  
  55. # @referers allows forms to be located only on servers which are defined     #
  56. # in this field.  This security fix from the last version which allowed      #
  57. # anyone on any server to use your FormMail script on their web site.        #
  58.  
  59. @referers = (‘scriptarchive.com’,‘embeddedcomponents.com’);
  60.  
  61. # @recipients defines the e-mail addresses or domain names that e-mail can   #
  62. # be sent to.  This must be filled in correctly to prevent SPAM and allow    #
  63. # valid addresses to receive e-mail.  Read the documentation to find out how #
  64. # this variable works!!!  It is EXTREMELY IMPORTANT.                         #
  65. # @recipients = &fill_recipients(@referers);
  66. @recipients = (‘^ronf\@embeddedcomponents\.com’);
  67.  
  68. # ACCESS CONTROL FIX: Peter D. Thompson Yezek                                #
  69. # @valid_ENV allows the sysadmin to define what environment variables can    #
  70. # be reported via the env_report directive.  This was implemented to fix     #
  71. # the problem reported at http://www.securityfocus.com/bid/1187              #
  72.  
  73. @valid_ENV = (‘REMOTE_HOST’,‘REMOTE_ADDR’,‘REMOTE_USER’,‘HTTP_USER_AGENT’);
  74. #@valid_ENV = (‘REMOTE_HOST’,’REMOTE_ADDR’,’REMOTE_USER’,’HTTP_USER_AGENT’,’HTTP_REFERER’);
  75.  
  76. # Done                                                                       #
  77. ##############################################################################
  78.  
  79. # Check Referring URL
  80. &check_url;
  81.  
  82. # Retrieve Date
  83. &get_date;
  84.  
  85. # Parse Form Contents
  86. &parse_form;
  87.  
  88. # Check Required Fields
  89. &check_required;
  90.  
  91. # Send E-Mail
  92. &send_mail;
  93.  
  94. # Return HTML Page or Redirect User
  95. &return_html;
  96.  
  97. # NOTE rev1.91: This function is no longer intended to stop abuse, that      #
  98. #    functionality is now embedded in the checks made on @recipients and the #
  99. #    recipient form field.                                                   #
  100.  
  101. sub check_url {
  102.  
  103.     # Localize the check_referer flag which determines if user is valid.     #
  104.     local($check_referer) = 0;
  105.  
  106.     # If a referring URL was specified, for each valid referer, make sure    #
  107.     # that a valid referring URL was passed to FormMail.                     #
  108.  
  109.     if ($ENV{‘HTTP_REFERER’}) {
  110.         foreach $referer (@referers) {
  111.             if ($ENV{‘HTTP_REFERER’} =~ m|https?://([^/]*)$referer|i) {
  112.                 $check_referer = 1;
  113.                 last;
  114.             }
  115.         }
  116.     }
  117.     else {
  118.         $check_referer = 1;
  119.     }
  120.  
  121.     # If the HTTP_REFERER was invalid, send back an error.                   #
  122.     if ($check_referer != 1) { &error(‘bad_referer’) }
  123. }
  124.  
  125. sub get_date {
  126.  
  127.     # Define arrays for the day of the week and month of the year.           #
  128.     @days   = (‘Sunday’,‘Monday’,‘Tuesday’,‘Wednesday’,
  129.                ‘Thursday’,‘Friday’,‘Saturday’);
  130.     @months = (‘January’,‘February’,‘March’,‘April’,‘May’,‘June’,‘July’,
  131.                ‘August’,‘September’,‘October’,‘November’,‘December’);
  132.  
  133.     # Get the current time and format the hour, minutes and seconds.  Add    #
  134.     # 1900 to the year to get the full 4 digit year.                         #
  135.     ($sec,$min,$hour,$mday,$mon,$year,$wday) = (localtime(time))[0,1,2,3,4,5,6];
  136.     $time = sprintf("%02d:%02d:%02d",$hour,$min,$sec);
  137.     $year += 1900;
  138.  
  139.     # Format the date.                                                       #
  140.     $date = "$days[$wday], $months[$mon] $mday, $year at $time";
  141.  
  142. }
  143.  
  144. sub parse_form {
  145.  
  146.     # part of server-side spam test
  147.     # initialize our antispam counter
  148.     $spamChunkCount = 0;
  149.  
  150.     # Define the configuration associative array.                            #
  151.     %Config = (‘recipient’,,          ‘subject’,,
  152.                ‘email’,,              ‘realname’,,
  153.                ‘redirect’,,           ‘bgcolor’,,
  154.                ‘background’,,         ‘link_color’,,
  155.                ‘vlink_color’,,        ‘text_color’,,
  156.                ‘alink_color’,,        ‘title’,,
  157.                ‘sort’,,               ‘print_config’,,
  158.                ‘required’,,           ‘env_report’,,
  159.                ‘return_link_title’,‘return_link_url’,,
  160.                ‘print_blank_fields’,, ‘missing_fields_redirect’,);
  161.  
  162.     # Determine the form’s REQUEST_METHOD (GET or POST) and split the form   #
  163.     # fields up into their name-value pairs.  If the REQUEST_METHOD was      #
  164.     # not GET or POST, send an error.                                        #
  165.     if ($ENV{‘REQUEST_METHOD’} eq ‘GET’) {
  166.         # Split the name-value pairs
  167.         @pairs = split(/&/, $ENV{‘QUERY_STRING’});
  168.     }
  169.     elsif ($ENV{‘REQUEST_METHOD’} eq ‘POST’) {
  170.         # Get the input
  171.         read(STDIN, $buffer, $ENV{‘CONTENT_LENGTH’});
  172.  
  173.         # Split the name-value pairs
  174.         @pairs = split(/&/, $buffer);
  175.     }
  176.     else {
  177.         &error(‘request_method’);
  178.     }
  179.  
  180.     # For each name-value pair:                                              #
  181.     foreach $pair (@pairs) {
  182.  
  183.         # Split the pair up into individual variables.                       #
  184.         local($name, $value) = split(/=/, $pair);
  185.  
  186.         # Decode the form encoding on the name and value variables.          #
  187.         # v1.92: remove null bytes                                           #
  188.         $name =~ tr/+/ /;
  189.         $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  190.         $name =~ tr/\0//d;
  191.  
  192.         $value =~ tr/+/ /;
  193.         $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  194.         $value =~ tr/\0//d;
  195.        
  196.         # part of server-side spam test
  197.         # count number of accesses to internet this email message might have…
  198.         $spamChunkCount = $spamChunkCount + &count_chunks($value, "href=");
  199.         $spamChunkCount = $spamChunkCount + &count_chunks($value, "http:");
  200.         $spamChunkCount = $spamChunkCount + &count_chunks($value, "https:");
  201.         $spamChunkCount = $spamChunkCount + &count_chunks($value, "ftp:");
  202.         $spamChunkCount = $spamChunkCount + &count_chunks($value, "mailto:");
  203.  
  204.         # If the field name has been specified in the %Config array, it will #
  205.         # return a 1 for defined($Config{$name}}) and we should associate    #
  206.         # this value with the appropriate configuration variable.  If this   #
  207.         # is not a configuration form field, put it into the associative     #
  208.         # array %Form, appending the value with a ‘, ‘ if there is already a #
  209.         # value present.  We also save the order of the form fields in the   #
  210.         # @Field_Order array so we can use this order for the generic sort.  #
  211.         if (defined($Config{$name})) {
  212.             $Config{$name} = $value;
  213.         }
  214.         else {
  215.             if ($Form{$name} ne ) {
  216.                 $Form{$name} = "$Form{$name}, $value";
  217.             }
  218.             else {
  219.                 push(@Field_Order,$name);
  220.                 $Form{$name} = $value;
  221.             }
  222.         }
  223.     }
  224.  
  225.     # The next six lines remove any extra spaces or new lines from the       #
  226.     # configuration variables, which may have been caused if your editor     #
  227.     # wraps lines after a certain length or if you used spaces between field #
  228.     # names or environment variables.                                        #
  229.     $Config{‘required’} =~ s/(\s+|\n)?,(\s+|\n)?/,/g;
  230.     $Config{‘required’} =~ s/(\s+)?\n+(\s+)?//g;
  231.     $Config{‘env_report’} =~ s/(\s+|\n)?,(\s+|\n)?/,/g;
  232.     $Config{‘env_report’} =~ s/(\s+)?\n+(\s+)?//g;
  233.     $Config{‘print_config’} =~ s/(\s+|\n)?,(\s+|\n)?/,/g;
  234.     $Config{‘print_config’} =~ s/(\s+)?\n+(\s+)?//g;
  235.  
  236.     # Split the configuration variables into individual field names.         #
  237.     @Required = split(/,/,$Config{‘required’});
  238.     @Env_Report = split(/,/,$Config{‘env_report’});
  239.     @Print_Config = split(/,/,$Config{‘print_config’});
  240.  
  241.     # ACCESS CONTROL FIX: Only allow ENV variables in @valid_ENV in          #
  242.     # @Env_Report for security reasons.                                      #
  243.     foreach $env_item (@Env_Report) {
  244.         foreach $valid_item (@valid_ENV) {
  245.             if ( $env_item eq $valid_item ) { push(@temp_array, $env_item) }
  246.         }
  247.     }
  248.     @Env_Report = @temp_array;
  249. }
  250.  
  251. sub check_required {
  252.  
  253.     # Localize the variables used in this subroutine.                        #
  254.     local($require, @error);
  255.  
  256.     # The following insures that there were no newlines in any fields which  #
  257.     # will be used in the header.                                            #
  258.     if ($Config{‘subject’} =~ /(\n|\r)/m || $Config{‘email’} =~ /(\n|\r)/m ||
  259.         $Config{‘realname’} =~ /(\n|\r)/m || $Config{‘recipient’} =~ /(\n|\r)/m) {
  260.         &error(‘invalid_headers’);
  261.     }
  262.  
  263.     if (!$Config{‘recipient’}) {
  264.         if (!defined(%Form)) { &error(‘bad_referer’) }
  265.         else                 { &error(‘no_recipient’) }
  266.     }
  267.     else {
  268.         # This block of code requires that the recipient address end with    #
  269.         # a valid domain or e-mail address as defined in @recipients.        #
  270.         $valid_recipient = 0;
  271.         foreach $send_to (split(/,/,$Config{‘recipient’})) {
  272.             foreach $recipient (@recipients) {
  273.                 if ($send_to =~ /$recipient$/i) {
  274.                     push(@send_to,$send_to); last;
  275.                 }
  276.             }
  277.         }
  278.         if ($#send_to < 0) { &error(‘no_recipient’) }
  279.         $Config{‘recipient’} = join(‘,’,@send_to);
  280.     }
  281.  
  282.     # For each require field defined in the form:                            #
  283.     foreach $require (@Required) {
  284.  
  285.         # If the required field is the email field, the syntax of the email  #
  286.         # address if checked to make sure it passes a valid syntax.          #
  287.         if ($require eq ‘email’ && !&check_email($Config{$require})) {
  288.             push(@error,$require);
  289.         }
  290.  
  291.         # Otherwise, if the required field is a configuration field and it   #
  292.         # has no value or has been filled in with a space, send an error.    #
  293.         elsif (defined($Config{$require})) {
  294.             if ($Config{$require} eq ) { push(@error,$require); }
  295.         }
  296.  
  297.         # If it is a regular form field which has not been filled in or      #
  298.         # filled in with a space, flag it as an error field.                 #
  299.         elsif (!defined($Form{$require}) || $Form{$require} eq ) {
  300.             push(@error,$require);
  301.         }
  302.     }
  303.  
  304.     # If any error fields have been found, send error message to the user.   #
  305.     if (@error) { &error(‘missing_fields’, @error) }
  306. }
  307.  
  308. sub return_html {
  309.     # Local variables used in this subroutine initialized.                   #
  310.     local($key,$sort_order,$sorted_field);
  311.  
  312.     # Now that we have finished using form values for any e-mail related     #
  313.     # reasons, we will convert all of the form fields and config values      #
  314.     # to remove any cross-site scripting security holes.                     #
  315.     local($field);
  316.     foreach $field (keys %Config) {
  317.         $safeConfig{$field} = &clean_html($Config{$field});
  318.     }
  319.  
  320.     foreach $field (keys %Form) {
  321.         $Form{$field} = &clean_html($Form{$field});
  322.     }
  323.  
  324.  
  325.     # If redirect option is used, print the redirectional location header.   #
  326.     if ($Config{‘redirect’}) {
  327.         print "Location: $safeConfig{‘redirect’}\n\n";
  328.     }
  329.  
  330.     # Otherwise, begin printing the response page.                           #
  331.     else {
  332.  
  333.         # Print HTTP header and opening HTML tags.                           #
  334.         print "Content-type: text/html\n\n";
  335.         print "<html>\n <head>\n";
  336.  
  337.         # Print out title of page                                            #
  338.         if ($Config{‘title’}) { print "<title>$safeConfig{‘title’}</title>\n" }
  339.         else                  { print "<title>Thank You</title>\n"        }
  340.  
  341.         print " </head>\n <body";
  342.  
  343.         # Get Body Tag Attributes                                            #
  344.         &body_attributes;
  345.  
  346.         # Close Body Tag                                                     #
  347.         print ">\n  <center>\n";
  348.  
  349.         # Print custom or generic title.                                     #
  350.         if ($Config{‘title’}) { print "<h1>$safeConfig{‘title’}</h1>\n" }
  351.         else { print "<h1>Thank You For Filling Out This Form</h1>\n" }
  352.  
  353.         print "</center>\n";
  354.  
  355.         print "Below is what you submitted to $safeConfig{‘recipient’} on ";
  356.         print "$date<p><hr size=1 width=75\%><p>\n";
  357.  
  358.         # If a sort order is specified, sort the form fields based on that.  #
  359.         if ($Config{‘sort’} =~ /^order:.*,.*/) {
  360.  
  361.             # Set the temporary $sort_order variable to the sorting order,   #
  362.             # remove extraneous line breaks and spaces, remove the order:    #
  363.             # directive and split the sort fields into an array.             #
  364.             $sort_order = $Config{‘sort’};
  365.             $sort_order =~ s/(\s+|\n)?,(\s+|\n)?/,/g;
  366.             $sort_order =~ s/(\s+)?\n+(\s+)?//g;
  367.             $sort_order =~ s/order://;
  368.             @sorted_fields = split(/,/, $sort_order);
  369.  
  370.             # For each sorted field, if it has a value or the print blank    #
  371.             # fields option is turned on print the form field and value.     #
  372.             foreach $sorted_field (@sorted_fields) {
  373.                 local $sfname = &clean_html($sorted_field);
  374.  
  375.                 if ($Config{‘print_blank_fields’} || $Form{$sorted_field} ne ) {
  376.                     print "<b>$sfname:</b> $Form{$sorted_field}<p>\n";
  377.                 }
  378.             }
  379.         }
  380.  
  381.         # Otherwise, use the order the fields were sent, or alphabetic.      #
  382.         else {
  383.  
  384.             # Sort alphabetically if requested.
  385.             if ($Config{‘sort’} eq ‘alphabetic’) {
  386.                 @Field_Order = sort @Field_Order;
  387.             }
  388.  
  389.             # For each form field, if it has a value or the print blank      #
  390.             # fields option is turned on print the form field and value.     #
  391.             foreach $field (@Field_Order) {
  392.                 local $fname = &clean_html($field);
  393.  
  394.                 if ($Config{‘print_blank_fields’} || $Form{$field} ne ) {
  395.                     print "<b>$fname:</b> $Form{$field}<p>\n";
  396.                 }
  397.             }
  398.         }
  399.  
  400.         print "<p><hr size=1 width=75%><p>\n";
  401.  
  402.         # Check for a Return Link and print one if found.                    #
  403.         if ($Config{‘return_link_url’} && $Config{‘return_link_title’}) {
  404.             print "<ul>\n";
  405.             print "<li><a href=\"$safeConfig{‘return_link_url’}\">$safeConfig{‘return_link_title’}</a>\n";
  406.             print "</ul>\n";
  407.         }
  408.  
  409.         # Print the page footer.                                             #
  410.         print <<"(END HTML FOOTER)";
  411.         <hr size=1 width=75%><p>
  412.         <center><font size=-1><a href="http://www.scriptarchive.com/formmail.html">FormMail</a> V1.92 &copy; 19952002  Matt Wright
  413. A Free Product of <a href="http://www.scriptarchive.com/">Matt‘s  Script Archive, Inc.</a></font></center>
  414.         </body>
  415.        </html>
  416. (END HTML FOOTER)
  417.     }
  418. }
  419.  
  420. sub send_mail {
  421.     # Localize variables used in this subroutine.                            #
  422.     local($print_config,$key,$sort_order,$sorted_field,$env_report);
  423.  
  424.     # part of server-side spam test
  425.     # Decide if we should skip sending this email because it could be spam
  426.     if ( $spamChunkCount > $spamChunksMax ) {
  427.         print "
  428. <!DOCTYPE HTML PUBLIC ‘-//W3C//DTD HTML 4.0 Transitional//EN‘>
  429. <html>
  430. <head>
  431. <title>Error: Request Method</title>
  432. </head>
  433. <body bgcolor=#FFFFFF text=#000000>
  434. <p>$spamMessage</p>
  435. <p><form>
  436. <input type=\"Button\" value=\"Go back and try again\" onclick=\"history.back()\">
  437. </form></p>
  438. <p><a href=\"$spamChunkErrorLink\">$spamChunkErrorLink</a></p>
  439. </body>
  440. </html>";     
  441.         exit;
  442.     }
  443.  
  444.  
  445.     # Open The Mail Program
  446.     open(MAIL,"|$mailprog");
  447.  
  448.     print MAIL "To: $Config{‘recipient‘}\n";
  449.     print MAIL "From: $Config{‘email‘} ($Config{‘realname‘})\n";
  450.  
  451.     # Check for Message Subject
  452.     if ($Config{‘subject‘}) { print MAIL "Subject: $Config{‘subject‘}\n\n" }
  453.     else                    { print MAIL "Subject: WWW Form Submission\n\n" }
  454.  
  455.     print MAIL "Below is the result of your feedback form.  It was submitted by\n";
  456.     print MAIL "$Config{‘realname‘} ($Config{‘email‘}) on $date\n";
  457.     print MAIL "-" x 75 . "\n\n";
  458.        
  459.     # part of server-side spam test
  460.     # uncomment this next line to view details of antispam logic in action
  461.     # print MAIL "ANTISPAM_URLCOUNT = " .  $spamChunkCount. " diff= ". ($spamChunkCount-$spamChunksMax). "\n\n";
  462.        
  463.  
  464.     if (@Print_Config) {
  465.         foreach $print_config (@Print_Config) {
  466.             if ($Config{$print_config}) {
  467.                 print MAIL "$print_config: $Config{$print_config}\n\n";
  468.             }
  469.         }
  470.     }
  471.  
  472.     # If a sort order is specified, sort the form fields based on that.      #
  473.     if ($Config{‘sort‘} =~ /^order:.*,.*/) {
  474.  
  475.         # Remove extraneous line breaks and spaces, remove the order:        #
  476.         # directive and split the sort fields into an array.                 #
  477.         local $sort_order = $Config{‘sort‘};
  478.         $sort_order =~ s/(\s+|\n)?,(\s+|\n)?/,/g;
  479.         $sort_order =~ s/(\s+)?\n+(\s+)?//g;
  480.         $sort_order =~ s/order://;
  481.         @sorted_fields = split(/,/, $sort_order);
  482.  
  483.         # For each sorted field, if it has a value or the print blank        #
  484.         # fields option is turned on print the form field and value.         #
  485.         foreach $sorted_field (@sorted_fields) {
  486.             if ($Config{‘print_blank_fields‘} || $Form{$sorted_field} ne ‘‘) {
  487.                 print MAIL "$sorted_field: $Form{$sorted_field}\n\n";
  488.             }
  489.         }
  490.     }
  491.  
  492.     # Otherwise, print fields in order they were sent or alphabetically.     #
  493.     else {
  494.  
  495.         # Sort alphabetically if specified:                                  #
  496.         if ($Config{‘sort‘} eq ‘alphabetic‘) {
  497.             @Field_Order = sort @Field_Order;
  498.         }
  499.  
  500.         # For each form field, if it has a value or the print blank          #
  501.         # fields option is turned on print the form field and value.         #
  502.         foreach $field (@Field_Order) {
  503.             if ($Config{‘print_blank_fields‘} || $Form{$field} ne ‘‘) {
  504.                 print MAIL "$field: $Form{$field}\n\n";
  505.             }
  506.         }
  507.     }
  508.  
  509.     print MAIL "-" x 75 . "\n\n";
  510.  
  511.     # Send any specified Environment Variables to recipient.                 #
  512.     foreach $env_report (@Env_Report) {
  513.         if ($ENV{$env_report}) {
  514.             print MAIL "$env_report: $ENV{$env_report}\n";
  515.         }
  516.     }
  517.  
  518.     close (MAIL);
  519. }
  520.  
  521. sub check_email {
  522.     # Initialize local email variable with input to subroutine.              #
  523.     $email = $_[0];
  524.  
  525.     # If the e-mail address contains:                                        #
  526.     if ($email =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/ ||
  527.  
  528.         # the e-mail address contains an invalid syntax.  Or, if the         #
  529.         # syntax does not match the following regular expression pattern     #
  530.         # it fails basic syntax verification.                                #
  531.  
  532.         $email !~ /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z0-9]+)(\]?)$/) {
  533.  
  534.         # Basic syntax requires:  one or more characters before the @ sign,  #
  535.         # followed by an optional ‘[‘, then any number of letters, numbers,  #
  536.         # dashes or periods (valid domain/IP characters) ending in a period  #
  537.         # and then 2 or 3 letters (for domain suffixes) or 1 to 3 numbers    #
  538.         # (for IP addresses).  An ending bracket is also allowed as it is    #
  539.         # valid syntax to have an email address like: user@[255.255.255.0]   #
  540.  
  541.         # Return a false value, since the e-mail address did not pass valid  #
  542.         # syntax.                                                            #
  543.         return 0;
  544.     }
  545.  
  546.     else {
  547.  
  548.         # Return a true value, e-mail verification passed.                   #
  549.         return 1;
  550.     }
  551. }
  552.  
  553. # This was added into v1.91 to further secure the recipients array.  Now, by #
  554. # default it will assume that valid recipients include only users with       #
  555. # usernames A-Z, a-z, 0-9, _ and – that match your domain exactly.  If this  #
  556. # is not what you want, you should read more detailed instructions regarding #
  557. # the configuration of the @recipients variable in the documentation.        #
  558. sub fill_recipients {
  559.     local(@domains) = @_;
  560.     local($domain,@return_recips);
  561.  
  562.     foreach $domain (@domains) {
  563.         if ($domain =~ /^\d+\.\d+\.\d+\.\d+$/) {
  564.             $domain =~ s/\./\\\./g;
  565.             push(@return_recips,’^[\w\-\.]+\@\[‘ . $domain . ‘\]‘);
  566.         }
  567.         else {
  568.             $domain =~ s/\./\\\./g;
  569.             $domain =~ s/\-/\\\-/g;
  570.             push(@return_recips,’^[\w\-\.]+\@‘ . $domain);
  571.         }
  572.     }
  573.  
  574.     return @return_recips;
  575. }
  576.  
  577. # This function will convert <, >, & and " to their HTML equivalents.        #
  578. sub clean_html {
  579.     local $value = $_[0];
  580.     $value =~ s/\&/\&/g;
  581.     $value =~ s/</\</g;
  582.     $value =~ s/>/\>/g;
  583.     $value =~ s/"/\"/g;
  584.     return $value;
  585. }
  586.  
  587.  
  588. # This function returns the number of text chucks in a string
  589. sub count_chunks {
  590.     # Usage: &count_chunks("string","substring")
  591.     # Returns: the number of substring chunks found in a string
  592.     # part of server-side spam test
  593.     # reference: http://www.blazonry.com/perl/linkcount_pl.txt
  594.     my $myString;
  595.     my $myChunk;
  596.     my $myInd;
  597.     my $myInd2;
  598.     my $myCount;
  599.     $myString = $_[0];
  600.     $myChunk = $_[1];
  601.    
  602.     #convert text to lowercase
  603.     $myString =~ tr/[A-Z]/[a-z]/;     
  604.     $myInd = 0;   $myInd2 = 0; $myCount = 0;
  605.     while ($myInd >= 0) {       
  606.         # get index place of href=
  607.         $myInd = index($myString, $myChunk, $myInd2);           
  608.         if ($myInd  >= 0) {
  609.             $myInd2 = $myInd + 1;
  610.             $myCount = $myCount + 1;
  611.         }
  612.     }
  613.     return $myCount;
  614. }
  615.  
  616. sub body_attributes {
  617.     # Check for Background Color
  618.     if ($Config{‘bgcolor‘}) { print " bgcolor=\"$safeConfig{‘bgcolor‘}\"" }
  619.  
  620.     # Check for Background Image
  621.     if ($Config{‘background‘}) { print " background=\"$safeConfig{‘background‘}\"" }
  622.  
  623.     # Check for Link Color
  624.     if ($Config{‘link_color‘}) { print " link=\"$safeConfig{‘link_color‘}\"" }
  625.  
  626.     # Check for Visited Link Color
  627.     if ($Config{‘vlink_color‘}) { print " vlink=\"$safeConfig{‘vlink_color‘}\"" }
  628.  
  629.     # Check for Active Link Color
  630.     if ($Config{‘alink_color‘}) { print " alink=\"$safeConfig{‘alink_color‘}\"" }
  631.  
  632.     # Check for Body Text Color
  633.     if ($Config{‘text_color‘}) { print " text=\"$safeConfig{‘text_color‘}\"" }
  634. }
  635.  
  636. sub error {
  637.     # Localize variables and assign subroutine input.                        #
  638.     local($error,@error_fields) = @_;
  639.     local($host,$missing_field,$missing_field_list);
  640.  
  641.     if ($error eq ‘bad_referer‘) {
  642.         if ($ENV{‘HTTP_REFERER‘} =~ m|^https?://([\w\.]+)|i) {
  643.             $host = $1;
  644.             my $referer = &clean_html($ENV{‘HTTP_REFERER‘});
  645.             print <<"(END ERROR HTML)";
  646. Content-type: text/html
  647.  
  648. <html>
  649. <head>
  650.   <title>Bad Referrer – Access Denied</title>
  651. </head>
  652. <body bgcolor=#FFFFFF text=#000000>
  653.   <center>
  654.    <table border=0 width=600 bgcolor=#9C9C9C>
  655.     <tr><th><font size=+2>Bad Referrer – Access Denied</font></th></tr>
  656.    </table>
  657.    <table border=0 width=600 bgcolor=#CFCFCF>
  658.     <tr><td>The form attempting to use
  659.      <a href="http://www.scriptarchive.com/formmail.html">FormMail</a>
  660.      resides at <tt>$referer</tt>, which is not allowed to access
  661.      this cgi script.<p>
  662.  
  663.      If you are attempting to configure FormMail to run with this form, you need
  664.      to add the following to \@referers, explained in detail in the
  665.      <a href="http://www.scriptarchive.com/readme/formmail.html">README</a> file.<p>
  666.  
  667.      Add <tt>’$host‘</tt> to your <tt><b>\@referers</b></tt> array.<hr size=1>
  668.      <center><font size=-1>
  669.       <a href="http://www.scriptarchive.com/formmail.html">FormMail</a> V1.92 &copy; 1995 – 2002  Matt Wright
  670.       A Free Product of <a href="http://www.scriptarchive.com/">Matt’s  Script Archive, Inc.</a>
  671.      </font></center>
  672.     </td></tr>
  673.    </table>
  674.   </center>
  675.  </body>
  676. </html>
  677. (END ERROR HTML)
  678.         }
  679.         else {
  680.             print <<"(END ERROR HTML)";
  681. Content-type: text/html
  682.  
  683. <html>
  684.  <head>
  685.   <title>FormMail v1.92</title>
  686.  </head>
  687.  <body bgcolor=#FFFFFF text=#000000>
  688.   <center>
  689.    <table border=0 width=600 bgcolor=#9C9C9C>
  690.     <tr><th><font size=+2>FormMail</font></th></tr>
  691.    </table>
  692.    <table border=0 width=600 bgcolor=#CFCFCF>
  693.     <tr><th><tt><font size=+1>Copyright 19952002 Matt Wright
  694.         Version 1.92 – Released April 21, 2002
  695.         A Free Product of <a href="http://www.scriptarchive.com/">Matt‘s  Script Archive,
  696.         Inc.</a></font></tt></th></tr>
  697.    </table>
  698.   </center>
  699. </body>
  700. </html>
  701. (END ERROR HTML)
  702.         }
  703.     }
  704.  
  705.     elsif ($error eq ‘request_method‘) {
  706.             print <<"(END ERROR HTML)";
  707. Content-type: text/html
  708.  
  709. <html>
  710. <head>
  711.   <title>Error: Request Method</title>
  712. </head>
  713. <body bgcolor=#FFFFFF text=#000000>
  714.   <center>
  715.    <table border=0 width=600 bgcolor=#9C9C9C>
  716.     <tr><th><font size=+2>Error: Request Method</font></th></tr>
  717.    </table>
  718.    <table border=0 width=600 bgcolor=#CFCFCF>
  719.     <tr><td>The Request Method of the Form you submitted did not match
  720.      either <tt>GET</tt> or <tt>POST</tt>.  Please check the form and make sure the
  721.      <tt>method=</tt> statement is in upper case and matches <tt>GET</tt> or <tt>POST</tt>.<p>
  722.  
  723.      <center><font size=-1>
  724.       <a href="http://www.scriptarchive.com/formmail.html">FormMail</a> V1.92 &copy; 1995 – 2002  Matt Wright
  725.       A Free Product of <a href="http://www.scriptarchive.com/">Matt’s  Script Archive, Inc.</a>
  726.      </font></center>
  727.     </td></tr>
  728.    </table>
  729.   </center>
  730.  </body>
  731. </html>
  732. (END ERROR HTML)
  733.     }
  734.  
  735.     elsif ($error eq ‘no_recipient’) {
  736.             print <<"(END ERROR HTML)";
  737. Content-type: text/html
  738.  
  739. <html>
  740.  <head>
  741.   <title>Error: Bad/No Recipient</title>
  742.  </head>
  743.  <body bgcolor=#FFFFFF text=#000000>
  744.   <center>
  745.    <table border=0 width=600 bgcolor=#9C9C9C>
  746.     <tr><th><font size=+2>Error: Bad/No Recipient</font></th></tr>
  747.    </table>
  748.    <table border=0 width=600 bgcolor=#CFCFCF>
  749.     <tr><td>There was no recipient or an invalid recipient specified in the data sent to FormMail.  Please
  750.      make sure you have filled in the <tt>recipient</tt> form field with an e-mail
  751.      address that has been configured in <tt>\@recipients</tt>.  More information on filling in <tt>recipient</tt> form fields and variables can be
  752.      found in the <a href="http://www.scriptarchive.com/readme/formmail.html">README</a> file.<hr size=1>
  753.  
  754.      <center><font size=-1>
  755.       <a href="http://www.scriptarchive.com/formmail.html">FormMail</a> V1.92 &copy; 19952002  Matt Wright
  756.       A Free Product of <a href="http://www.scriptarchive.com/">Matt‘s  Script Archive, Inc.</a>
  757.      </font></center>
  758.     </td></tr>
  759.    </table>
  760.   </center>
  761. </body>
  762. </html>
  763. (END ERROR HTML)
  764.     }
  765.  
  766.     elsif ($error eq ‘invalid_headers‘) {
  767.             print <<"(END ERROR HTML)";
  768. Content-type: text/html
  769.  
  770. <html>
  771. <head>
  772.   <title>Error: Bad Header Fields</title>
  773. </head>
  774. <body bgcolor=#FFFFFF text=#000000>
  775.   <center>
  776.    <table border=0 width=600 bgcolor=#9C9C9C>
  777.     <tr><th><font size=+2>Error: Bad Header Fields</font></th></tr>
  778.    </table>
  779.    <table border=0 width=600 bgcolor=#CFCFCF>
  780.     <tr><td>The header fields, which include <tt>recipient</tt>, <tt>email</tt>, <tt>realname</tt> and <tt>subject</tt> were
  781.      filled in with invalid values. You may not include any newline characters in these parameters.
  782.      More information on filling in these form fields and variables can be
  783.      found in the <a href="http://www.scriptarchive.com/readme/formmail.html">README</a> file.<hr size=1>
  784.  
  785.      <center><font size=-1>
  786.       <a href="http://www.scriptarchive.com/formmail.html">FormMail</a> V1.92 &copy; 1995 – 2002  Matt Wright
  787.       A Free Product of <a href="http://www.scriptarchive.com/">Matt’s  Script Archive, Inc.</a>
  788.      </font></center>
  789.     </td></tr>
  790.    </table>
  791.   </center>
  792.  </body>
  793. </html>
  794. (END ERROR HTML)
  795.     }
  796.  
  797.     elsif ($error eq ‘missing_fields’) {
  798.         if ($Config{‘missing_fields_redirect’}) {
  799.             print "Location: " . &clean_html($Config{‘missing_fields_redirect’}) . "\n\n";
  800.         }
  801.         else {
  802.             foreach $missing_field (@error_fields) {
  803.                 $missing_field_list .= "<li>" . &clean_html($missing_field) . "\n";
  804.             }
  805.  
  806.             print <<"(END ERROR HTML)";
  807. Content-type: text/html
  808.  
  809. <html>
  810.  <head>
  811.   <title>Error: Blank Fields</title>
  812.  </head>
  813.   <center>
  814.    <table border=0 width=600 bgcolor=#9C9C9C>
  815.     <tr><th><font size=+2>Error: Blank Fields</font></th></tr>
  816.    </table>
  817.    <table border=0 width=600 bgcolor=#CFCFCF>
  818.     <tr><td>The following fields were left blank in your submission form:<p>
  819.      <ul>
  820. $missing_field_list
  821.      </ul>
  822.  
  823.      These fields must be filled in before you can successfully submit the form.<p>
  824.      Please use your browser‘s back button to return to the form and try again.<hr size=1>
  825.      <center><font size=-1>
  826.       <a href="http://www.scriptarchive.com/formmail.html">FormMail</a> V1.92 &copy; 1995 – 2002  Matt Wright
  827.       A Free Product of <a href="http://www.scriptarchive.com/">Matt’s  Script Archive, Inc.</a>
  828.      </font></center>
  829.     </td></tr>
  830.    </table>
  831.   </center>
  832.  </body>
  833. </html>
  834. (END ERROR HTML)
  835.         }
  836.     }
  837.  
  838.     exit;
  839. }
  840.  

Technorati Tags: , , , , , , ,

6 Responses to “How to Fix Dean Lee’s Source Code Highlight Plugin”

  1. Embedded Components and Tools Blog Center » Blog Archive » How to build Dean Lee’s Syntax Highlighter from latest components Says:

    [...] New CSS classes for WordPress template style.css file Version 1.0 from Embedded Components http://www.embeddedcomponents.com/blogs/2007/05/how-to-fix-dean-lees-source-code-highlight-plugin/#sample [...]

  2. hiutopor Says:

    Hi

    Very interesting information! Thanks!

    Bye

  3. Joel Cochran Says:

    I accomplished the same thing, but by a slightly different route.

    First, the wrap/nowrap issue is a configuration option in WordPress, so I just unchecked the wrap option.

    Second, in geshi.css, I just added “overflow:auto;” to the dean_ch style section. I originally had “overflow:scroll;”, but that made the scroll bars appear constantly, even when not needed. I saw “overflow: auto;” in your example above, and I like it much better. Thanks!

  4. Ron Fredericks Says:

    Thanks Joel for the update.

  5. Cercernvesrow Says:

    Hello
    nice site

  6. assistencia samsung Says:

    good article, i will add my feeds.

Leave a Reply

What is 7 + 6 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)