[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/view/src/wact/ -> lmbWactHighlightHandler.class.php (source)

   1  <?php
   2  /*
   3   * Limb PHP Framework
   4   *
   5   * @link http://limb-project.com 
   6   * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
   7   * @license    LGPL http://www.gnu.org/copyleft/lesser.html 
   8   */
   9  @define('XML_HTMLSAX3', 'limb/view/lib/XML/');
  10  
  11  require_once(XML_HTMLSAX3 . '/HTMLSax3.php');
  12  
  13  /**

  14   * class lmbWactHighlightHandler.

  15   *

  16   * @package view

  17   * @version $Id$

  18   */
  19  class lmbWactHighlightHandler
  20  {
  21    protected $html = '';
  22    protected $current_tag = '';
  23    protected $self_closing_tag = false;
  24    protected $template_path_history = array();
  25    protected $tag_dictionary = null;
  26    protected $highlight_page_url;
  27  
  28    function __construct($tag_dictionary, $highlight_page_url)
  29    {
  30      $this->tag_dictionary = $tag_dictionary;
  31      $this->highlight_page_url = $highlight_page_url;
  32    }
  33  
  34    function setTemplatePathHistory($history)
  35    {
  36      $this->template_path_history = $history;
  37    }
  38  
  39    function writeAttributes($attributes)
  40    {
  41      if(!is_array($attributes))
  42        return;
  43  
  44      foreach ($attributes as $name => $value)
  45      {
  46        $name_html = $name;
  47        $value_html = $value;
  48  
  49        if($this->tag_dictionary->getWactTagInfo($this->current_tag))
  50        {
  51          $name_html = "<span class='wact_attr'>{$name}</span>";
  52          $value_html = "<span class='wact_attr_name'>{$value}</span>";
  53        }
  54  
  55        if($this->current_tag == 'core:wrap' ||  $this->current_tag == 'core:include')
  56        {
  57          if($name == 'file')
  58          {
  59            $history = array();
  60            $history = $this->template_path_history;
  61            $history[] = $value;
  62  
  63            $history_string = 't[]=' . implode('&t[]=', $history);
  64  
  65            $href = $this->highlight_page_url . "?{$history_string}";
  66  
  67            $value_html = "<a class='template_path' href={$href}>{$value}</a>";
  68          }
  69        }
  70  
  71        $this->html .= ' ' . $name_html . '="' . $value_html . '"';
  72      }
  73    }
  74  
  75    function openHandler($parser, $name, $attrs)
  76    {
  77      if($this->self_closing_tag)
  78        $this->html .= '&gt;';
  79  
  80      $this->self_closing_tag = true;
  81  
  82      $this->current_tag = strtolower($name);
  83  
  84      if($this->tag_dictionary->getWactTagInfo($name))
  85        $this->html .= '&lt;<span class="wact_tag">' . $name . '</span>';
  86      else
  87        $this->html .= '&lt;<span class="html_tag">' . $name . '</span>';
  88  
  89      $this->writeAttributes($attrs);
  90    }
  91  
  92    function closeHandler($parser, $name)
  93    {
  94      if($this->self_closing_tag)
  95      {
  96        $this->html .= '/&gt;';
  97        $this->self_closing_tag = false;
  98        return;
  99      }
 100  
 101      if($this->tag_dictionary->getWactTagInfo($name))
 102        $this->html .= '&lt;/<span class="wact_tag">' . $name . '</span>&gt;';
 103      else
 104        $this->html .= '&lt;/<span class="html_tag">' . $name . '</span>&gt;';
 105    }
 106  
 107    function dataHandler($parser, $data)
 108    {
 109      if($this->self_closing_tag)
 110      {
 111        $this->self_closing_tag = false;
 112        $this->html .= '&gt;';
 113      }
 114  
 115      $data = str_replace("\t", '  ', $data);
 116      $this->html .= $data;
 117    }
 118  
 119    function escapeHandler($parser, $data)
 120    {
 121      $this->html .= '<span class="comment">&lt;!' . $data . '&gt;</span>';
 122    }
 123  
 124    function getHtml()
 125    {
 126      $this->html = preg_replace('~(\{(\$|\^|#)[^\}]+\})~', "<span class='expression'>\\1</span>", $this->html);
 127  
 128      $lines = preg_split( "#\r\n|\r|\n#", $this->html);
 129  
 130      $content = '';
 131      $max = sizeof($lines);
 132      $digits = strlen("{$max}");
 133  
 134      for($i=0; $i < $max; $i++)
 135      {
 136        $j = $i + 1;
 137        $content .= "<span class='line_number'>{$j}" . str_repeat('&nbsp;', $digits - strlen("{$j}")) . "</span> " .  $lines[$i] . "\n";
 138      }
 139  
 140      return $content;
 141    }
 142  }
 143  ?>


Generated: Tue Dec 2 03:54:09 2008 Cross-referenced by PHPXref 0.7