[ Index ]

PHP Cross Reference of Web Application Component Toolkit

title

Body

[close]

/framework/template/tags/core/ -> date.filter.php (source)

   1  <?php
   2  //--------------------------------------------------------------------------------
   3  // Copyright 2004 Procata, Inc.
   4  // Released under the LGPL license (http://www.gnu.org/copyleft/lesser.html)
   5  //--------------------------------------------------------------------------------
   6  /**
   7  * @package WACT_FILTER
   8  * @author    Jason E. Sweat < jsweat_php AT yahoo DOT com >
   9  * @version $Id: date.filter.php,v 1.4 2004/11/18 04:22:47 jeffmoore Exp $
  10  */
  11  
  12  FilterDictionary::registerFilter(
  13      new FilterInfo('date', 'DateFilter', 0, 1), __FILE__);
  14  FilterDictionary::registerFilter(
  15      new FilterInfo('todate', 'ToDateFilter', 0, 1), __FILE__);
  16  
  17  class DateFilter extends CompilerFilter {
  18  
  19      /**
  20      * Return this value as a PHP value
  21      * @return String
  22      * @access public
  23      */
  24  	function getValue() {
  25          if ($this->isConstant()) {
  26              $value = $this->base->getValue();
  27              $exp = $this->parameters[0]->getValue();
  28              return date($exp, $value);
  29          } else {
  30              RaiseError('compiler', 'UNRESOLVED_BINDING');
  31          }
  32      }
  33  
  34      /**
  35      * Generate the code to read the data value at run time
  36      * Must generate only a valid PHP Expression.
  37      * @param CodeWriter
  38      * @return void
  39      * @access protected
  40      */
  41  	function generateExpression(&$code) {
  42          //$code->registerInclude(WACT_ROOT . 'template/components/core/date_filter.inc.php');
  43          $code->writePHP('date(');
  44          $this->parameters[0]->generateExpression($code);
  45          $code->writePHP(',');
  46          $this->base->generateExpression($code);
  47          $code->writePHP(')');
  48      }
  49  
  50  }
  51  
  52  class ToDateFilter extends CompilerFilter {
  53      var $input;
  54      /**
  55      * Return this value as a PHP value
  56      * @return String
  57      * @access public
  58      */
  59  	function getValue() {
  60          if ($this->isConstant()) {
  61              if ($value = $this->base->getValue()) {
  62                  return strtotime($value);
  63              }
  64          } else {
  65              RaiseError('compiler', 'UNRESOLVED_BINDING');
  66          }
  67      }
  68  
  69      /**
  70      * Generate setup code for an expression reference
  71      * @param CodeWriter
  72      * @return void
  73      * @access protected
  74      */
  75  	function generatePreStatement(&$code) {
  76          parent::generatePreStatement($code);
  77          $this->input = $code->getTempVarRef();
  78          $code->writePHP($this->input.'=');
  79          $this->base->generateExpression($code);
  80          $code->writePHP(';');
  81          //$code->writePHP($this->input.'=('.$this->input.')?'.$this->input.':mktime();');
  82      }
  83      /**
  84      * Generate the code to read the data value at run time
  85      * Must generate only a valid PHP Expression.
  86      * @param CodeWriter
  87      * @return void
  88      * @access protected
  89      */
  90  	function generateExpression(&$code) {
  91          //$code->registerInclude(WACT_ROOT . 'template/components/core/date_filter.inc.php');
  92          $code->writePHP('(('.$this->input.')?strtotime('.$this->input.'):"")');
  93      }
  94  
  95  }
  96  
  97  ?>


Generated: Sun Nov 28 19:36:09 2004 Cross-referenced by PHPXref 0.5