[ Index ]
 

Code source de eGroupWare 1.2.106-2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/phpgwapi/inc/savant2/Savant2/ -> Savant2_Plugin_dateformat.php (source)

   1  <?php
   2  
   3  /**
   4  * Base plugin class.
   5  */
   6  require_once 'Savant2/Plugin.php';
   7  
   8  /**
   9  * 
  10  * Outputs a formatted date using strftime() conventions.
  11  * 
  12  * $Id: Savant2_Plugin_dateformat.php 18360 2005-05-26 19:38:09Z mipmip $
  13  * 
  14  * @author Paul M. Jones <pmjones@ciaweb.net>
  15  * 
  16  * @package Savant2
  17  * 
  18  * @license http://www.gnu.org/copyleft/lesser.html LGPL
  19  * 
  20  * This program is free software; you can redistribute it and/or modify
  21  * it under the terms of the GNU Lesser General Public License as
  22  * published by the Free Software Foundation; either version 2.1 of the
  23  * License, or (at your option) any later version.
  24  * 
  25  * This program is distributed in the hope that it will be useful, but
  26  * WITHOUT ANY WARRANTY; without even the implied warranty of
  27  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  28  * Lesser General Public License for more details.
  29  * 
  30  */
  31  
  32  class Savant2_Plugin_dateformat extends Savant2_Plugin {
  33      
  34      /**
  35      * 
  36      * The default strftime() format string to use for dates.
  37      * 
  38      * You can preset the default format string via Savant::loadPlugin().
  39      * 
  40      * $conf = array(
  41      *     'format' => '%Y-%m-%d %H:%M:%S'
  42      * );
  43      * 
  44      * $Savant->loadPlugin('dateformat', $conf);
  45      * 
  46      * ... and in your template, to use the default format string:
  47      * 
  48      *     $this->plugin('date', $datestring);
  49      * 
  50      * ... or, to use a custom string at call-time:
  51      * 
  52      *     $this->plugin('date', $datestring, '%b');
  53      * 
  54      * @access public
  55      * 
  56      * @var string
  57      * 
  58      */
  59      
  60      var $format = '%c';
  61      
  62      
  63      /**
  64      * 
  65      * The default strftime() format string to use for dates.
  66      * 
  67      * You can preset the custom format strings via Savant::loadPlugin().
  68      * 
  69      * $conf = array(
  70      *     'custom' => array(
  71      *         'mydate' => '%Y-%m-%d',
  72      *         'mytime' => '%R'
  73      *     )
  74      * );
  75      * 
  76      * $Savant->loadPlugin('dateformat', $conf);
  77      * 
  78      * ... and in your template, to use a preset custom string by name:
  79      * 
  80      *     $this->plugin('date', $datestring, 'mydate');
  81      * 
  82      * @access public
  83      * 
  84      * @var array
  85      * 
  86      */
  87      
  88      var $custom = array(
  89          'date' => '%Y-%m-%d',
  90          'time' => '%H:%M:%S'
  91      );
  92      
  93      
  94      /**
  95      * 
  96      * Outputs a formatted date using strftime() conventions.
  97      * 
  98      * @access public
  99      * 
 100      * @param string $datestring Any date-time string suitable for
 101      * strtotime().
 102      * 
 103      * @param string $format The strftime() formatting string, or a named
 104      * custom string key from $this->custom.
 105      * 
 106      * @return string
 107      * 
 108      */
 109      
 110  	function plugin($datestring, $format = null)
 111      {
 112          settype($format, 'string');
 113          
 114          // does the format string have a % sign in it?
 115          if (strpos($format, '%') === false) {
 116              // no, look for a custom format string
 117              if (isset($this->custom[$format])) {
 118                  // found a custom format string
 119                  $format = $this->custom[$format];
 120              } else {
 121                  // did not find the custom format, revert to default
 122                  $format = $this->format;
 123              }
 124          }
 125          
 126          // convert the date string to the specified format
 127          if (trim($datestring != '')) {
 128              return strftime($format, strtotime($datestring));
 129          } else {
 130              // no datestring, return VOID
 131              return;
 132          }
 133      }
 134  
 135  }
 136  ?>


Généré le : Sun Feb 25 17:20:01 2007 par Balluche grâce à PHPXref 0.7