[ Index ]
 

Code source de phpMyAdmin 2.10.3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/libraries/transformations/ -> text_plain__dateformat.inc.php (source)

   1  <?php
   2  /* $Id: text_plain__dateformat.inc.php 9577 2006-10-18 08:09:03Z nijel $ */
   3  // vim: expandtab sw=4 ts=4 sts=4:
   4  
   5  function PMA_transformation_text_plain__dateformat($buffer, $options = array(), $meta = '') {
   6      // possibly use a global transform and feed it with special options:
   7      // include('./libraries/transformations/global.inc.php');
   8  
   9      // further operations on $buffer using the $options[] array.
  10      if (empty($options[0])) {
  11          $options[0] = 0;
  12      }
  13  
  14      if (empty($options[2])) {
  15          $options[2] = 'local';
  16      } else {
  17          $options[2] = strtolower($options[2]);
  18      }
  19  
  20      if (empty($options[1])) {
  21          if ($options[2] == 'local') {
  22              $options[1] = $GLOBALS['datefmt'];
  23          } else {
  24              $options[1] = 'Y-m-d  H:i:s';
  25          }
  26      }
  27  
  28      $timestamp = -1;
  29  
  30      // Detect TIMESTAMP(6 | 8 | 10 | 12 | 14), (2 | 4) not supported here.
  31      if (preg_match('/^(\d{2}){3,7}$/', $buffer)) {
  32  
  33          if (strlen($buffer) == 14 || strlen($buffer) == 8) {
  34              $offset = 4;
  35          } else {
  36              $offset = 2;
  37          }
  38  
  39          $d = array();
  40          $d['year']   = substr($buffer, 0, $offset);
  41          $d['month']  = substr($buffer, $offset, 2);
  42          $d['day']    = substr($buffer, $offset + 2, 2);
  43          $d['hour']   = substr($buffer, $offset + 4, 2);
  44          $d['minute'] = substr($buffer, $offset + 6, 2);
  45          $d['second'] = substr($buffer, $offset + 8, 2);
  46  
  47          if (checkdate($d['month'], $d['day'], $d['year'])) {
  48              $timestamp = mktime($d['hour'], $d['minute'], $d['second'], $d['month'], $d['day'], $d['year']);
  49          }
  50      // If all fails, assume one of the dozens of valid strtime() syntaxes (http://www.gnu.org/manual/tar-1.12/html_chapter/tar_7.html)
  51      } else {
  52          if (preg_match('/^[0-9]\d{1,9}$/', $buffer)) {
  53              $timestamp = (int)$buffer;
  54          } else {
  55              $timestamp = strtotime($buffer);
  56          }
  57      }
  58  
  59      // If all above failed, maybe it's a Unix timestamp already?
  60      if ($timestamp < 0 && preg_match('/^[1-9]\d{1,9}$/', $buffer)) {
  61          $timestamp = $buffer;
  62      }
  63  
  64      // Reformat a valid timestamp
  65      if ($timestamp >= 0) {
  66          $timestamp -= $options[0] * 60 * 60;
  67          $source = $buffer;
  68          if ($options[2] == 'local') {
  69              $text = PMA_localisedDate($timestamp, $options[1]);
  70          } elseif ($options[2] == 'utc') {
  71              $text = gmdate($options[1], $timestamp);
  72          } else {
  73              $text = 'INVALID DATE TYPE';
  74          }
  75          $buffer = '<dfn onclick="alert(\'' . $source . '\');" title="' . $source . '">' . $text . '</dfn>';
  76      }
  77  
  78      return $buffer;
  79  }
  80  
  81  ?>


Généré le : Mon Nov 26 15:18:20 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics