Warning: file_get_contents(/home/fann/kksou.com/php-gtk2/products/include_code_listing/samples/sample4.php) [function.file-get-contents]: failed to open stream: No such file or directory in /home/fann/kksou.com/php-gtk2/mambots/content/include_code_listing.php on line 161


Include Code Listing plugin - More Tips and Techniques
Written by kksou   
Friday, 02 May 2008

In this article, I will show you more tips and techniques in using the Include Code Listing plugin.


  1. Change the font and font size of the line numbers. You can specify your preferred font and font size for the line numbers by defining the style IncludeCodeListing_linenum using css. For example, if you define IncludeCodeListing_linenum as the following:
  2. <style type="text/css">
    <!--
    .IncludeCodeListing_linenum {
    	font-family: Times New Roman Bold Italic;
    	font-size: 16px;
    	color: #0000ff;
    }
    -->
    </style>
    

    To use the above style, you have to use the setting use_css=1. Don't forget to enclose this in square brackets.

    {include_code_listing sample1.1.php [use_css=1]}
    

    You will get this:

     1 
     2 
     3 
     4 
     5 
     6 
     7 
     8 
    <?php
    # sample1.php
    echo "now = ".date('F j, Y H:i:s')."\n";

    for (
    $i=0$i<10; ++$i) {
        print 
    "$i: ".$i*$i."\n";
    }
    ?>

  3. Set the background color for the line numbers. You can set a different color for the line numbers by defining the style td.IncludeCodeListing_linenum_td using css. For example, if you define td.IncludeCodeListing_linenum_td as the following:
  4. <style type="text/css">
    <!--
    .IncludeCodeListing_linenum {
    	font-family: "Courier New", Courier, monospace;
    	font-size: 9px;
    	font-style: italic;
    	color: #FF3399;
    }
    
    td.IncludeCodeListing_linenum_td {
    	background-color: #99E9FF;
    }
    -->
    </style>
    

    To use the above style, you have to use the setting use_css=1. Don't forget to enclose this in square brackets.

    {include_code_listing sample1.1.php [use_css=1]}
    

    You will get this:

     1 
     2 
     3 
     4 
     5 
     6 
     7 
     8 
    <?php
    # sample1.php
    echo "now = ".date('F j, Y H:i:s')."\n";

    for (
    $i=0$i<10; ++$i) {
        print 
    "$i: ".$i*$i."\n";
    }
    ?>

  5. Change the font and style of the code display. The codes are displayed using the standard HTML tag <code>. So if you wish to change the font or style of the code display, you do this by changing the style of the HTML tag <code> using the style sheet. For example, let's define <code> as follows:
  6. <style type="text/css">
    <!--
    code {
    	font-family: "Times New Roman", Times, serif;
    	font-size: 16px;
    	font-style: italic;
    	color: #FF3399;
    }
    -->
    </style>
    

    Note that for this to work, you do not need the setting use_css=1. (Unless, of course, if you intend to specify the font of the line number, you will then need to use the setting use_css=1 as outlined in (1) above.)

    {include_code_listing sample1.1.php}
    

    You will get this:

     1 
     2 
     3 
     4 
     5 
     6 
     7 
     8 
    <?php
    # sample1.php
    echo "now = ".date('F j, Y H:i:s')."\n";

    for (
    $i=0$i<10; ++$i) {
        print 
    "$i: ".$i*$i."\n";
    }
    ?>

  7. Suppress line numbers. If you prefer without the line numbers, use the following syntax. Note that all settings should reside within the square brackets, delimited by commas.
  8. {include_code_listing c:\sample apps\php\sample1.1.php [show_linenum=0]}
    

    <?php
    # sample1.php
    echo "now = ".date('F j, Y H:i:s')."\n";

    for (
    $i=0$i<10; ++$i) {
        print 
    "$i: ".$i*$i."\n";
    }
    ?>

  9. Specifying the indent for multi-lines. When there is a word wrap, I give a 2-space indent for the second and subsequent lines. To change this, use the setting multiline_indent.
  10. Compare this with indent=2 (the default)

    {include_code_listing c:\sample apps\php\sample3.php [wrap_column=40,  multiline_indent=2]}
    

      1 
      2 
      3 
      4 
      5 
      6 
      7 
      8 

      9 


     10 

     11 


     12 
     13 
     14 
     15 
     16 
     17 
     18 

     19 

     20 





     21 

     22 
     23 
     24 
    <?php
    # sample3.php
    # from joomla index.php

    // Set flag that this is a parent file
    define'_VALID_MOS');

    // checks for configuration file, if 
      none found loads installation page
    if (!file_exists'configuration.php' 
      || 
    filesize'configuration.php' ) < 
      10
    ) {
        
    $self rtrimdirname$_SERVER[
          'PHP_SELF'
    ] ), '/\\' ) . '/';
        
    header("Location: http://" 
          $_SERVER
    ['HTTP_HOST'] . $self 
          "installation/index.php" 
    );
        exit();
    }

    require( 
    'globals.php' );
    require( 
    'configuration.php' );

    // SSL check - $http_host returns <live 
      site url>:<port number if it is 443>
    $http_host explode(':'$_SERVER[
      'HTTP_HOST'
    ] );
    if( (!empty( 
    $_SERVER['HTTPS'] ) && 
      strtolower
    $_SERVER['HTTPS'] ) != 
      'off' 
    || isset( $http_host[1] ) && 
      $http_host
    [1] == 443) && substr
      $mosConfig_live_site
    0) != 
      'https://' 
    ) {
        
    $mosConfig_live_site 'https://'.
          substr
    $mosConfig_live_site);
    }

    ?>

    and this with indent=0

    {include_code_listing c:\sample apps\php\sample3.php [wrap_column=40,  multiline_indent=0]}
    

      1 
      2 
      3 
      4 
      5 
      6 
      7 
      8 

      9 


     10 

     11 


     12 
     13 
     14 
     15 
     16 
     17 
     18 

     19 

     20 





     21 

     22 
     23 
     24 
    <?php
    # sample3.php
    # from joomla index.php

    // Set flag that this is a parent file
    define'_VALID_MOS');

    // checks for configuration file, if 
    none found loads installation page
    if (!file_exists'configuration.php' 
    || 
    filesize'configuration.php' ) < 10)
    {
        
    $self rtrimdirname$_SERVER[
        'PHP_SELF'
    ] ), '/\\' ) . '/';
        
    header("Location: http://" 
        $_SERVER
    ['HTTP_HOST'] . $self 
        "installation/index.php" 
    );
        exit();
    }

    require( 
    'globals.php' );
    require( 
    'configuration.php' );

    // SSL check - $http_host returns <live 
    site url>:<port number if it is 443>
    $http_host explode(':'$_SERVER[
    'HTTP_HOST'
    ] );
    if( (!empty( 
    $_SERVER['HTTPS'] ) && 
    strtolower
    $_SERVER['HTTPS'] ) != 'off'
    || isset( 
    $http_host[1] ) && $http_host[
    1
    ] == 443) && substr
    $mosConfig_live_site
    0) != 
    'https://' 
    ) {
        
    $mosConfig_live_site 'https://'.
        substr
    $mosConfig_live_site);
    }

    ?>

  11. Force wrap. If a line exceeds the wrap column, you can choose to force wrap the line with the setting force_wrap=1.
  12. {include_code_listing c:\sample apps\php\sample4.php [wrap_column=40, force_wrap=1]}
    

     1 

    The force_wrap is turned on by default. You could turn it off with force_wrap=0:

    {include_code_listing c:\sample apps\php\sample4.php [wrap_column=40, force_wrap=0]}
    

    I will not show it here as it would mess up the layout of this page.


 

Add comment


Security code
Refresh

< Prev   Next >

Blog - Forum - Privacy Policy - Contact Us
Links - Classes - Social Business - BPM - Web - General
Copyright © 2006-2013. kksou.com. All Rights Reserved