home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / phpMyAdmin / libraries / transformations / text_plain__dateformat.inc.php < prev    next >
Encoding:
PHP Script  |  2008-06-23  |  2.9 KB  |  97 lines

  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4.  *
  5.  * @version $Id: text_plain__dateformat.inc.php 11084 2008-01-27 14:07:50Z lem9 $
  6.  */
  7.  
  8. /**
  9.  *
  10.  */
  11. function PMA_transformation_text_plain__dateformat($buffer, $options = array(), $meta = '') {
  12.     // possibly use a global transform and feed it with special options:
  13.     // include './libraries/transformations/global.inc.php';
  14.  
  15.     // further operations on $buffer using the $options[] array.
  16.     if (empty($options[0])) {
  17.         $options[0] = 0;
  18.     }
  19.  
  20.     if (empty($options[2])) {
  21.         $options[2] = 'local';
  22.     } else {
  23.         $options[2] = strtolower($options[2]);
  24.     }
  25.  
  26.     if (empty($options[1])) {
  27.         if ($options[2] == 'local') {
  28.             $options[1] = $GLOBALS['datefmt'];
  29.         } else {
  30.             $options[1] = 'Y-m-d  H:i:s';
  31.         }
  32.     }
  33.  
  34.     $timestamp = -1;
  35.  
  36.     // INT columns will be treated as UNIX timestamps
  37.     // and need to be detected before the verification for
  38.     // MySQL TIMESTAMP
  39.     if ($meta->type == 'int') {
  40.         $timestamp = $buffer;
  41.  
  42.     // Detect TIMESTAMP(6 | 8 | 10 | 12 | 14)
  43.     // TIMESTAMP (2 | 4) not supported here.
  44.     // (Note: prior to MySQL 4.1, TIMESTAMP has a display size, for example
  45.     // TIMESTAMP(8) means YYYYMMDD)
  46.     } else if (preg_match('/^(\d{2}){3,7}$/', $buffer)) {
  47.  
  48.         if (strlen($buffer) == 14 || strlen($buffer) == 8) {
  49.             $offset = 4;
  50.         } else {
  51.             $offset = 2;
  52.         }
  53.  
  54.         $d = array();
  55.         $d['year']   = substr($buffer, 0, $offset);
  56.         $d['month']  = substr($buffer, $offset, 2);
  57.         $d['day']    = substr($buffer, $offset + 2, 2);
  58.         $d['hour']   = substr($buffer, $offset + 4, 2);
  59.         $d['minute'] = substr($buffer, $offset + 6, 2);
  60.         $d['second'] = substr($buffer, $offset + 8, 2);
  61.  
  62.         if (checkdate($d['month'], $d['day'], $d['year'])) {
  63.             $timestamp = mktime($d['hour'], $d['minute'], $d['second'], $d['month'], $d['day'], $d['year']);
  64.         }
  65.     // 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)
  66.     } else {
  67.         if (preg_match('/^[0-9]\d{1,9}$/', $buffer)) {
  68.             $timestamp = (int)$buffer;
  69.         } else {
  70.             $timestamp = strtotime($buffer);
  71.         }
  72.     }
  73.  
  74.     // If all above failed, maybe it's a Unix timestamp already?
  75.     if ($timestamp < 0 && preg_match('/^[1-9]\d{1,9}$/', $buffer)) {
  76.         $timestamp = $buffer;
  77.     }
  78.  
  79.     // Reformat a valid timestamp
  80.     if ($timestamp >= 0) {
  81.         $timestamp -= $options[0] * 60 * 60;
  82.         $source = $buffer;
  83.         if ($options[2] == 'local') {
  84.             $text = PMA_localisedDate($timestamp, $options[1]);
  85.         } elseif ($options[2] == 'utc') {
  86.             $text = gmdate($options[1], $timestamp);
  87.         } else {
  88.             $text = 'INVALID DATE TYPE';
  89.         }
  90.         $buffer = '<dfn onclick="alert(\'' . $source . '\');" title="' . $source . '">' . $text . '</dfn>';
  91.     }
  92.  
  93.     return $buffer;
  94. }
  95.  
  96. ?>
  97.