Upgraded phpmyadmin to 4.0.4 (All Languages) - No modifications yet
[openemr.git] / phpmyadmin / libraries / plugins / transformations / abstract / DateFormatTransformationsPlugin.class.php
blob530379f10d875c891b00dfe06e54b6d197710748
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Abstract class for the date format transformations plugins
6 * @package PhpMyAdmin-Transformations
7 * @subpackage DateFormat
8 */
9 if (! defined('PHPMYADMIN')) {
10 exit;
13 /* Get the transformations interface */
14 require_once 'libraries/plugins/TransformationsPlugin.class.php';
16 /**
17 * Provides common methods for all of the date format transformations plugins.
19 * @package PhpMyAdmin
21 abstract class DateFormatTransformationsPlugin extends TransformationsPlugin
23 /**
24 * Gets the transformation description of the specific plugin
26 * @return string
28 public static function getInfo()
30 return __(
31 'Displays a TIME, TIMESTAMP, DATETIME or numeric unix timestamp'
32 . ' column as formatted date. The first option is the offset (in'
33 . ' hours) which will be added to the timestamp (Default: 0). Use'
34 . ' second option to specify a different date/time format string.'
35 . ' Third option determines whether you want to see local date or'
36 . ' UTC one (use "local" or "utc" strings) for that. According to'
37 . ' that, date format has different value - for "local" see the'
38 . ' documentation for PHP\'s strftime() function and for "utc" it'
39 . ' is done using gmdate() function.'
43 /**
44 * Does the actual work of each specific transformations plugin.
46 * @param string $buffer text to be transformed
47 * @param array $options transformation options
48 * @param string $meta meta information
50 * @return void
52 public function applyTransformation($buffer, $options = array(), $meta = '')
54 // possibly use a global transform and feed it with special options
56 // further operations on $buffer using the $options[] array.
57 if (empty($options[0])) {
58 $options[0] = 0;
61 if (empty($options[2])) {
62 $options[2] = 'local';
63 } else {
64 $options[2] = strtolower($options[2]);
67 if (empty($options[1])) {
68 if ($options[2] == 'local') {
69 $options[1] = __('%B %d, %Y at %I:%M %p');
70 } else {
71 $options[1] = 'Y-m-d H:i:s';
75 $timestamp = -1;
77 // INT columns will be treated as UNIX timestamps
78 // and need to be detected before the verification for
79 // MySQL TIMESTAMP
80 if ($meta->type == 'int') {
81 $timestamp = $buffer;
83 // Detect TIMESTAMP(6 | 8 | 10 | 12 | 14)
84 // TIMESTAMP (2 | 4) not supported here.
85 // (Note: prior to MySQL 4.1, TIMESTAMP has a display size
86 // for example TIMESTAMP(8) means YYYYMMDD)
87 } else if (preg_match('/^(\d{2}){3,7}$/', $buffer)) {
89 if (strlen($buffer) == 14 || strlen($buffer) == 8) {
90 $offset = 4;
91 } else {
92 $offset = 2;
95 $d = array();
96 $d['year'] = substr($buffer, 0, $offset);
97 $d['month'] = substr($buffer, $offset, 2);
98 $d['day'] = substr($buffer, $offset + 2, 2);
99 $d['hour'] = substr($buffer, $offset + 4, 2);
100 $d['minute'] = substr($buffer, $offset + 6, 2);
101 $d['second'] = substr($buffer, $offset + 8, 2);
103 if (checkdate($d['month'], $d['day'], $d['year'])) {
104 $timestamp = mktime(
105 $d['hour'],
106 $d['minute'],
107 $d['second'],
108 $d['month'],
109 $d['day'],
110 $d['year']
113 // If all fails, assume one of the dozens of valid strtime() syntaxes
114 // (http://www.gnu.org/manual/tar-1.12/html_chapter/tar_7.html)
115 } else {
116 if (preg_match('/^[0-9]\d{1,9}$/', $buffer)) {
117 $timestamp = (int)$buffer;
118 } else {
119 $timestamp = strtotime($buffer);
123 // If all above failed, maybe it's a Unix timestamp already?
124 if ($timestamp < 0 && preg_match('/^[1-9]\d{1,9}$/', $buffer)) {
125 $timestamp = $buffer;
128 // Reformat a valid timestamp
129 if ($timestamp >= 0) {
130 $timestamp -= $options[0] * 60 * 60;
131 $source = $buffer;
132 if ($options[2] == 'local') {
133 $text = PMA_Util::localisedDate(
134 $timestamp,
135 $options[1]
137 } elseif ($options[2] == 'utc') {
138 $text = gmdate($options[1], $timestamp);
139 } else {
140 $text = 'INVALID DATE TYPE';
142 $buffer = '<dfn onclick="alert(\'' . $source . '\');" title="'
143 . $source . '">' . $text . '</dfn>';
146 return $buffer;
150 * This method is called when any PluginManager to which the observer
151 * is attached calls PluginManager::notify()
153 * @param SplSubject $subject The PluginManager notifying the observer
154 * of an update.
156 * @todo implement
157 * @return void
159 public function update (SplSubject $subject)
165 /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
169 * Gets the transformation name of the specific plugin
171 * @return string
173 public static function getName()
175 return "Date Format";