Support Joomla!

Joomla! 1.5 Documentation

Packages

Package: patTemplate

Developer Network License

The Joomla! Developer Network content is © copyright 2006 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution- NonCommercial- ShareAlike 2.5
Source code for file /pattemplate/patTemplate/InputFilter/ShortModifiers.php

Documentation is available at ShortModifiers.php

  1. <?PHP
  2. /**
  3.  * patTemplate input filter to allow the short modifier syntax
  4.  * that is used by Smarty
  5.  *
  6.  * $Id: ShortModifiers.php 47 2005-09-15 02:55:27Z rhuk $
  7.  *
  8.  * @package        patTemplate
  9.  * @subpackage    Filters
  10.  * @author        Stephan Schmidt <[email protected]>
  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 47 2005-09-15 02:55:27Z rhuk $
  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 <[email protected]>
  28.  */
  29. {
  30.    /**
  31.     * filter name
  32.     *
  33.     * @access    private
  34.     * @var        string 
  35.     */
  36.     var    $_name = 'ShortModifiers';
  37.  
  38.    /**
  39.     * parameters of the filter
  40.     *
  41.     * @access  private
  42.     * @var     array 
  43.     */
  44.     var $_params = array(
  45.                             'copyVars' => true
  46.                         );
  47.  
  48.    /**
  49.     * namespace
  50.     *
  51.     * @access    private
  52.     * @var        string 
  53.     */
  54.     var    $_ns null;
  55.  
  56.    /**
  57.     * reference to the patTemplate object
  58.     *
  59.     * @var       object patTemplate 
  60.     * @access  private
  61.     */
  62.     var $_tmpl null;
  63.  
  64.    /**
  65.     * set the template reference
  66.     *
  67.     * @access    public
  68.     * @param    object patTemplate 
  69.     */
  70.     function setTemplateReference(&$tmpl)
  71.     {
  72.         $this->_tmpl &$tmpl;
  73.     }
  74.  
  75.    /**
  76.     * generate the <patTemplate:var/> tag
  77.     *
  78.     * @access    public
  79.     * @param    array       matches from preg_replace
  80.     * @return    string        tag
  81.     */
  82.     function _generateReplace($matches)
  83.     {
  84.         if ($this->getParam('copyVars'=== true{
  85.             $newName $matches[2'_' $matches[3];
  86.             if (isset$matches[4)) {
  87.                 $newName .= $matches[4];
  88.             }
  89.             $replace $matches[1'<' $this->_ns ':var copyFrom="' $matches[2'" name="' $newName '" modifier="' $matches[3'"';
  90.         else {
  91.             $replace $matches[1'<' $this->_ns ':var name="' $matches[2'" modifier="' $matches[3'"';
  92.         }
  93.  
  94.         $n count($matches1;
  95.         for ($i 4$i $n$i++ {
  96.             $replace .= ' ' $matches[++$i'="' $matches[++$i'"';
  97.         }
  98.         $replace .= '/>';
  99.         return $replace;
  100.     }
  101.  
  102.    /**
  103.     * replace the variables
  104.     *
  105.     * @access    public
  106.     * @param    string        data
  107.     * @return    string        data with variables replaced
  108.     */
  109.     function apply($data)
  110.     {
  111.         $startTag $this->_tmpl->getStartTag();
  112.         $endTag   $this->_tmpl->getEndTag();
  113.  
  114.         $this->_ns $this->_tmpl->getNamespace();
  115.         if (is_array($this->_ns)) {
  116.             $this->_ns array_shift($this->_ns);
  117.         }
  118.         $regex chr"([^\\\])" $startTag "([^a-z]+)\|(.+[^\\\])(\|(.+):(.+[^\\\]))*" $endTag chr"U";
  119.         $data preg_replace_callback($regexarray$this'_generateReplace' )$data);
  120.         return $data;
  121.     }
  122. }
  123. ?>

Documentation generated on Mon, 05 Mar 2007 21:21:46 +0000 by phpDocumentor 1.3.1