Documentation TYPO3 par Ameos |
00001 <?php 00002 /* $Id: text_plain__dateformat.inc.php,v 2.3 2003/12/05 11:02:14 garvinhicking Exp $ */ 00003 // vim: expandtab sw=4 ts=4 sts=4: 00004 00005 function PMA_transformation_text_plain__dateformat($buffer, $options = array(), $meta = '') { 00006 // possibly use a global transform and feed it with special options: 00007 // include('./libraries/transformations/global.inc.php'); 00008 00009 // further operations on $buffer using the $options[] array. 00010 if (!isset($options[0]) || $options[0] == '') { 00011 $options[0] = 0; 00012 } 00013 00014 if (!isset($options[1]) || $options[1] == '') { 00015 $options[1] = $GLOBALS['datefmt']; 00016 00017 } 00018 00019 $timestamp = -1; 00020 00021 // Detect TIMESTAMP(6 | 8 | 10 | 12 | 14), (2 | 4) not supported here. 00022 if (preg_match('/^(\d{2}){3,7}$/', $buffer)) { 00023 00024 if (strlen($buffer) == 14 || strlen($buffer) == 8) { 00025 $offset = 4; 00026 } else { 00027 $offset = 2; 00028 } 00029 00030 $d = array(); 00031 $d['year'] = substr($buffer, 0, $offset); 00032 $d['month'] = substr($buffer, $offset, 2); 00033 $d['day'] = substr($buffer, $offset + 2, 2); 00034 $d['hour'] = substr($buffer, $offset + 4, 2); 00035 $d['minute'] = substr($buffer, $offset + 6, 2); 00036 $d['second'] = substr($buffer, $offset + 8, 2); 00037 00038 if (checkdate($d['month'], $d['day'], $d['year'])) { 00039 $timestamp = mktime($d['hour'], $d['minute'], $d['second'], $d['month'], $d['day'], $d['year']); 00040 } 00041 // 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) 00042 } else { 00043 $timestamp = strtotime($buffer); 00044 } 00045 00046 // If all above failed, maybe it's a Unix timestamp already? 00047 if ($timestamp < 0 && preg_match('/^[1-9]\d{1,9}$/', $buffer)) { 00048 $timestamp = $buffer; 00049 } 00050 00051 // Reformat a valid timestamp 00052 if ($timestamp >= 0) { 00053 $timestamp -= $options[0] * 60 * 60; 00054 $source = $buffer; 00055 $buffer = '<dfn onclick="alert(\'' . $source . '\');" title="' . $source . '">' . PMA_localisedDate($timestamp, $options[1]) . '</dfn>'; 00056 } 00057 00058 return $buffer; 00059 } 00060 00061 ?>