home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / HTML / Template / Flexy / Compiler / Regex / Math.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  2.2 KB  |  74 lines

  1. <?php
  2. //
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.02 of the PHP license,      |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Author:  Alan Knowles <alan@akbkhome.com>
  17. // +----------------------------------------------------------------------+
  18. //
  19.  
  20.  
  21. /**
  22. * A Math Filter 
  23. *
  24. * enable simple maths to be done in the template
  25. *
  26. * TODO: add an {if:t.xxx%2} type syntax.. 
  27. *
  28. * @package    HTML_Template_Flexy
  29. *  
  30. */  
  31.  
  32.  
  33. class HTML_Template_Flexy_Compiler_Regex_Math {
  34.     /*
  35.     *   @var    string   $start    the start tag for the template (escaped for regex)
  36.     */
  37.     var $start = '\{'; 
  38.     /*
  39.     *   @var    string   $stop    the stopt tag for the template (escaped for regex)
  40.     */
  41.     var $stop = '\}';  //ending template tag
  42.      /**
  43.     * Standard Set Engine
  44.     * 
  45.     * 
  46.     * @param   object HTML_Template_Flexy   the main engine
  47.     * @access   private
  48.     */
  49.     function _set_engine(&$engine) {
  50.        
  51.     }
  52.  
  53.     /* 
  54.     * allow simple add multiply, divide and subtraction
  55.     * 
  56.     * eg.
  57.     * {(12+t.somevar)*2} maps to =(12+$t->somevar)*2
  58.     *
  59.     * @param   string The template
  60.     * @access   public
  61.     */
  62.     function variables ($input) {
  63.         $input = preg_replace(
  64.             "/".$this->start."([0-9\(\)+*\/-]*)([a-z0-9]+)([0-9\(\)+*\/-]*)".$this->stop."/ie",
  65.             "'<?=\\1($'.str_replace('.','->','\\2').')\\3?>'",
  66.             $input);
  67.             
  68.         return $input;
  69.     }
  70.   
  71.  
  72. }
  73.  
  74. ?>