[ Index ]
 

Code source de b2evolution 2.1.0-beta

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/blogs/plugins/code_highlight_plugin/highlighters/ -> xml.highlighter.php (source)

   1  <?php
   2  /**

   3   * This file is part of the AstonishMe Code plugin.

   4   *

   5   * This file is part of the b2evolution project - {@link http://b2evolution.net/}

   6   *

   7   * @copyright (c)2003-2007 by Francois PLANQUE - {@link http://fplanque.net/}

   8   * Parts of this file are copyright (c)2005-2007 by Yabba/Scott - {@link http://astonishme.co.uk/contact/}.

   9   *

  10   * {@internal License choice

  11   * - If you have received this file as part of a package, please find the license.txt file in

  12   *   the same folder or the closest folder above for complete license terms.

  13   * - If you have received this file individually (e-g: from http://cvs.sourceforge.net/viewcvs.py/evocms/)

  14   *   then you must choose one of the following licenses before using the file:

  15   *   - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php

  16   *   - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php

  17   * }}

  18   *

  19   * {@internal Open Source relicensing agreement:

  20   * Yabba/Scott grant Francois PLANQUE the right to license

  21   * Yabba's/Scott's contributions to this file and the b2evolution project

  22   * under any OSI approved OSS license (http://www.opensource.org/licenses/).

  23   * }}

  24   *

  25   * @package plugins

  26   *

  27   * @author Yabba: Paul Jones - {@link http://astonishme.co.uk/}

  28   * @author Stk: Scott Kimler - {@link http://astonishme.co.uk/}

  29   *

  30   */
  31  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  32  
  33  /**

  34   * @package plugins

  35   */
  36  class am_xml_highlighter
  37  {
  38      /**

  39       * Text name of language for display

  40       *

  41       * This is unused whilst "Experimental" as it requires a modification of the plugin

  42       * it would be used to replace the text output above the codeblock instead of ucfirst( language )

  43       *

  44       */
  45      var $language_title = 'XML';
  46  
  47  
  48      /**

  49       * Boolean are we in strict mode ?

  50       *

  51       */
  52      var $strict_mode = false;
  53  
  54  
  55      /**

  56       * Called automatically on class innit

  57       *

  58       * @param object $parent

  59       * @return object am_xml_highlighter

  60       */
  61  	function am_xml_highlighter( & $parent )
  62      {
  63          $this->parent = & $parent;
  64          return $this;
  65      }
  66  
  67  
  68      /**

  69       * Highlights code ready for displaying

  70       *

  71       * @param string $block - the code

  72       * @return string highlighted code

  73       */
  74  	function highlight_code( $block )
  75      {
  76          // highlight all < ?xml - ? >, CDATA and comment blocks

  77          $block = preg_replace( array(
  78                          '¤(&lt;\!--(.*?)--&gt;)¤',
  79                          '¤(&lt;\!\[CDATA\[([\s\S]*?)]]&gt;)¤',
  80                          '¤(&lt;\?(.*?)\?&gt;)¤' ),
  81                      array(
  82                          '<span class="amc_comment">&lt;!&#8722;&#8722;$2&#8722;&#8722;&gt;</span>',
  83                          '<span class="amc_comment">$1</span>',
  84                          '<span class="amc_keyword">$1</span>' ),
  85                           $block );
  86          // highlight remaining tags, attributes and strings

  87          $block = callback_on_non_matching_blocks(  $block, '¤<span([\s\S]+?)</span>¤', array( $this, 'highlight_xml_tags' ) );
  88  
  89  
  90          return $this->parent->tidy_code_output( '<span class="amc_default">'.$block.'</span>' );
  91      }
  92  
  93  
  94      /**

  95       * Highlights xml declarations

  96       *

  97       * @param string $block : 2 - the code

  98       * @return string highlighted declarations

  99       */
 100  	function highlight_xml_tags( $block )
 101      {
 102          $block = preg_replace_callback( '¤(&lt;(.*?)&gt;)¤', array( $this, 'highlight_xml' ), $block );
 103          return '<span class="amc_default">'.$block.'</span>';
 104      }
 105  
 106  
 107      /**

 108       * Highlights xml tags, attributes and values

 109       *

 110       * @param string $block : 2 - the code

 111       * @return string highlighted xml code

 112       */
 113  	function highlight_xml( $block )
 114      {
 115          $block[2] = preg_replace(
 116                  array( '#^([^\s]+?)(\s)#','#(\s)([^\s]+?)=#i', '#(["\'])([^\1]+?)\1#' ),
 117                  array( '$1</span><default>$2', '$1<attrib>$2</span>=', '<string>$1$2$1</span>' ),
 118                  $block[2] );
 119  
 120          return '<span class="amc_keyword">&lt;'.str_replace(
 121                  array( '<default>', '<attrib>', '<string>' ),
 122                  array( '<span class="amc_default">', '<span class="amc_attribute">', '<span class="amc_string">' ),
 123                  $block[2] ).'&gt;</span>';
 124      }
 125  
 126  
 127  }
 128  /**

 129   * $Log: xml.highlighter.php,v $

 130   * Revision 1.6  2007/06/26 02:40:54  fplanque

 131   * security checks

 132   *

 133   * Revision 1.5  2007/06/20 21:33:23  blueyed

 134   * fixed doc

 135   *

 136   * Revision 1.4  2007/06/20 19:16:36  blueyed

 137   * Fixed doc

 138   *

 139   * Revision 1.3  2007/06/17 13:28:22  blueyed

 140   * Fixed doc

 141   *

 142   * Revision 1.2  2007/05/04 20:43:09  fplanque

 143   * MFB

 144   *

 145   * Revision 1.1.2.6  2007/04/23 12:00:36  yabs

 146   * removed "extend Plugins"

 147   *

 148   * Revision 1.1.2.5  2007/04/21 08:43:37  yabs

 149   * minor docs and code

 150   *

 151   * Revision 1.1.2.4  2007/04/21 07:40:36  yabs

 152   * added in highlighting for comments, cdata & xml declarations

 153   *

 154   * Revision 1.1.2.3  2007/04/20 12:02:25  yabs

 155   * Added in some highlighting for attributes, tags and strings

 156   *

 157   *

 158   */
 159  ?>


Généré le : Thu Nov 29 23:58:50 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics