Rev Author Line No. Line
250 kaklik 1 <?php
2 /* $Id: text_plain__dateformat.inc.php,v 2.3 2003/12/05 11:02:14 garvinhicking Exp $ */
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 (!isset($options[0]) || $options[0] == '') {
11 $options[0] = 0;
12 }
13  
14 if (!isset($options[1]) || $options[1] == '') {
15 $options[1] = $GLOBALS['datefmt'];
16  
17 }
18  
19 $timestamp = -1;
20  
21 // Detect TIMESTAMP(6 | 8 | 10 | 12 | 14), (2 | 4) not supported here.
22 if (preg_match('/^(\d{2}){3,7}$/', $buffer)) {
23  
24 if (strlen($buffer) == 14 || strlen($buffer) == 8) {
25 $offset = 4;
26 } else {
27 $offset = 2;
28 }
29  
30 $d = array();
31 $d['year'] = substr($buffer, 0, $offset);
32 $d['month'] = substr($buffer, $offset, 2);
33 $d['day'] = substr($buffer, $offset + 2, 2);
34 $d['hour'] = substr($buffer, $offset + 4, 2);
35 $d['minute'] = substr($buffer, $offset + 6, 2);
36 $d['second'] = substr($buffer, $offset + 8, 2);
37  
38 if (checkdate($d['month'], $d['day'], $d['year'])) {
39 $timestamp = mktime($d['hour'], $d['minute'], $d['second'], $d['month'], $d['day'], $d['year']);
40 }
41 // 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)
42 } else {
43 $timestamp = strtotime($buffer);
44 }
45  
46 // If all above failed, maybe it's a Unix timestamp already?
47 if ($timestamp < 0 && preg_match('/^[1-9]\d{1,9}$/', $buffer)) {
48 $timestamp = $buffer;
49 }
50  
51 // Reformat a valid timestamp
52 if ($timestamp >= 0) {
53 $timestamp -= $options[0] * 60 * 60;
54 $source = $buffer;
55 $buffer = '<dfn onclick="alert(\'' . $source . '\');" title="' . $source . '">' . PMA_localisedDate($timestamp, $options[1]) . '</dfn>';
56 }
57  
58 return $buffer;
59 }
60  
61 ?>