[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/libraries/pattemplate/patTemplate/InputFilter/ -> ShortModifiers.php (source)

   1  <?PHP
   2  /**
   3   * patTemplate input filter to allow the short modifier syntax
   4   * that is used by Smarty
   5   *
   6   * $Id: ShortModifiers.php 10381 2008-06-01 03:35:53Z pasamio $
   7   *
   8   * @package        patTemplate
   9   * @subpackage    Filters
  10   * @author        Stephan Schmidt <schst@php.net>
  11   */
  12  
  13  // Check to ensure this file is within the rest of the framework
  14  defined('JPATH_BASE') or die();
  15  
  16  /**
  17   * patTemplate input filter to allow the short modifier syntax
  18   * that is used by Smarty
  19   *
  20   * $Id: ShortModifiers.php 10381 2008-06-01 03:35:53Z pasamio $
  21   *
  22   * This will replace the variables with patTemplate:var/> tags that
  23   * have the name and the modifier attribute set.
  24   *
  25   * @package        patTemplate
  26   * @subpackage    Filters
  27   * @author        Stephan Schmidt <schst@php.net>
  28   */
  29  class patTemplate_InputFilter_ShortModifiers extends patTemplate_InputFilter
  30  {
  31      /**
  32      * filter name
  33      *
  34      * @access    private
  35      * @var        string
  36      */
  37      var    $_name = 'ShortModifiers';
  38  
  39      /**
  40      * parameters of the filter
  41      *
  42      * @access  private
  43      * @var     array
  44      */
  45      var $_params = array(
  46                              'copyVars' => true
  47                          );
  48  
  49      /**
  50      * namespace
  51      *
  52      * @access    private
  53      * @var        string
  54      */
  55      var    $_ns = null;
  56  
  57      /**
  58      * reference to the patTemplate object
  59      *
  60      * @var       object patTemplate
  61      * @access  private
  62      */
  63      var $_tmpl = null;
  64  
  65      /**
  66      * set the template reference
  67      *
  68      * @access    public
  69      * @param    object patTemplate
  70      */
  71  	function setTemplateReference(&$tmpl)
  72      {
  73          $this->_tmpl = &$tmpl;
  74      }
  75  
  76      /**
  77      * generate the <patTemplate:var/> tag
  78      *
  79      * @access    public
  80      * @param    array       matches from preg_replace
  81      * @return    string        tag
  82      */
  83  	function _generateReplace($matches)
  84      {
  85          if ($this->getParam('copyVars') === true) {
  86              $newName = $matches[2] . '_' . $matches[3];
  87              if (isset( $matches[4] )) {
  88                  $newName .= $matches[4];
  89              }
  90              $replace = $matches[1] . '<' . $this->_ns . ':var copyFrom="' . $matches[2] . '" name="' . $newName . '" modifier="' . $matches[3] . '"';
  91          } else {
  92              $replace = $matches[1] . '<' . $this->_ns . ':var name="' . $matches[2] . '" modifier="' . $matches[3] . '"';
  93          }
  94  
  95          $n = count($matches) - 1;
  96          for ($i = 4; $i < $n; $i++ ) {
  97              $replace .= ' ' . $matches[++$i] . '="' . $matches[++$i] . '"';
  98          }
  99          $replace .= '/>';
 100          return $replace;
 101      }
 102  
 103      /**
 104      * replace the variables
 105      *
 106      * @access    public
 107      * @param    string        data
 108      * @return    string        data with variables replaced
 109      */
 110  	function apply($data)
 111      {
 112          $startTag = $this->_tmpl->getStartTag();
 113          $endTag   = $this->_tmpl->getEndTag();
 114  
 115          $this->_ns = $this->_tmpl->getNamespace();
 116          if (is_array($this->_ns)) {
 117              $this->_ns = array_shift($this->_ns);
 118          }
 119          $regex = chr( 1 ) . "([^\\\])" . $startTag . "([^a-z]+)\|(.+[^\\\])(\|(.+):(.+[^\\\]))*" . $endTag . chr( 1 ) . "U";
 120          $data = preg_replace_callback($regex, array( $this, '_generateReplace' ), $data);
 121          return $data;
 122      }
 123  }
 124  ?>


Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1