[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/wact/src/tags/dev/ -> source.tag.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  
  10  /**

  11   * Displays the source code written into the compiled template, for the

  12   * section of the template in contains.

  13   * Note that position of this tag <i>will</i> matter. It cannot be round a

  14   * an input tag in a form tag, for example, where the nesting level will

  15   * result in an error. It may also result in a mess in terms of HTML

  16   * @tag dev:SOURCE

  17   * @package wact
  18   * @version $Id: source.tag.php 5945 2007-06-06 08:31:43Z pachanga $
  19   */
  20  class WactDevSourceTag extends WactCompilerTag {
  21  
  22    /**

  23     * Position in the WactCodeWriter::code string containing the compiled code,

  24     * at which the dev:source tag was inserted.

  25     * @var int

  26     */
  27    protected $startPos;
  28  
  29    /**

  30     * Writing mode the WactCodeWriter was in, when the dev:source tag was

  31     * inserted

  32     * @var int

  33     */
  34    protected $startMode;
  35  
  36    /**

  37     * @param WactCodeWriter

  38     * @return void

  39     */
  40    function generateBeforeContent($code_writer)
  41    {
  42      $this->startPos = strlen($code_writer->getCode());
  43      $this->startMode = $code_writer->getMode();
  44    }
  45  
  46    /**

  47     * @param WactCodeWriter

  48     * @return void

  49     */
  50    function generateAfterContent($code_writer)
  51    {
  52      $source = substr($code_writer->getCode(),$this->startPos);
  53  
  54      if ( !$this->getBoolAttribute('raw') ) {
  55  
  56        // Could do this better,  perhaps with indents. Course that

  57        // needs some kind of parser... or use the Tokenizer.

  58        $tmp_source = str_replace('<?php',"\n<?php\n",$source);
  59        $tmp_source = str_replace(';',";\n",$tmp_source);
  60        $tmp_source = str_replace('{',"{\n",$tmp_source);
  61        $tmp_source = str_replace('}',"}\n",$tmp_source);
  62        $tmp_source = str_replace('?>',"\n?>\n",$tmp_source);
  63  
  64      } else {
  65        $tmp_source = $source;
  66      }
  67  
  68      $html_source = highlight_string($tmp_source, true);
  69  
  70      $html_source = '<div align="left"><hr /><h3>Source Dump:</h3>'
  71      .$html_source;
  72      $html_source .= '<hr /></div><div><h3>Component:</h3>';
  73  
  74      // Have to violate the API so highlighted source

  75      // is placed before real code, in case of PHP parse errors

  76      $code = substr($code_writer->getCode(),0,$this->startPos);
  77      if ( $this->startMode == WactCodeWriter::MODE_PHP ) {
  78        $code .= '?>';
  79        $code .= $html_source;
  80        $code .= '<?php ';
  81        $code .= $source;
  82      } else {
  83        $code .= $html_source;
  84        $code .= $source;
  85      }
  86  
  87      if ( $code_writer->getMode() == WactCodeWriter::MODE_PHP ) {
  88        $code .= '?><br /><hr /></div><?php ';
  89      } else {
  90        $code .=    '<br /><hr /></div>';
  91      }
  92  
  93      $code_writer->setCode($code);
  94    }
  95  }
  96  ?>


Generated: Sat Sep 6 04:46:52 2008 Cross-referenced by PHPXref 0.7