1 <?php |
1 <?php |
2 |
2 |
3 /* |
3 /* |
4 * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between |
4 * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between |
5 * Version 1.1.6 (Caoineag beta 1) |
5 * Copyright (C) 2006-2009 Dan Fuhry |
6 * Copyright (C) 2006-2008 Dan Fuhry |
|
7 * |
6 * |
8 * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License |
7 * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License |
9 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. |
8 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. |
10 * |
9 * |
11 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied |
10 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied |
256 function enano_date($string, $timestamp = false) |
255 function enano_date($string, $timestamp = false) |
257 { |
256 { |
258 if ( !is_int($timestamp) && !is_double($timestamp) && strval(intval($timestamp)) !== $timestamp ) |
257 if ( !is_int($timestamp) && !is_double($timestamp) && strval(intval($timestamp)) !== $timestamp ) |
259 $timestamp = time(); |
258 $timestamp = time(); |
260 |
259 |
|
260 if ( is_int($string) ) |
|
261 { |
|
262 global $session, $lang; |
|
263 $date_fmt = is_object($session) ? $session->date_format : DATE_4; |
|
264 $time_fmt = is_object($session) ? $session->time_format : TIME_24_NS; |
|
265 |
|
266 // within a week? use a relative date |
|
267 if ( $timestamp + ( 86400 * 7 ) >= time() && $string & ED_DATE && is_object($lang) && is_object($session) ) |
|
268 { |
|
269 $relative_date = get_relative_date($timestamp); |
|
270 if ( $string === ED_DATE ) |
|
271 // why do more work if we're done? |
|
272 return $relative_date; |
|
273 } |
|
274 |
|
275 $flags = $string; |
|
276 $string = array(); |
|
277 if ( $flags & ED_DATE && !isset($relative_date) ) |
|
278 $string[] = $date_fmt; |
|
279 if ( $flags & ED_TIME ) |
|
280 $string[] = $time_fmt; |
|
281 |
|
282 $string = implode(' ', $string); |
|
283 } |
|
284 |
261 // perform timestamp offset |
285 // perform timestamp offset |
262 global $timezone; |
286 global $timezone; |
263 // it's gonna be in minutes, so multiply by 60 to offset the unix timestamp |
287 // it's gonna be in minutes, so multiply by 60 to offset the unix timestamp |
264 $timestamp = $timestamp + ( $timezone * 60 ); |
288 $timestamp = $timestamp + ( $timezone * 60 ); |
265 |
289 |
270 // offset for DST |
294 // offset for DST |
271 $timestamp += ( $dst_params[4] * 60 ); |
295 $timestamp += ( $dst_params[4] * 60 ); |
272 } |
296 } |
273 |
297 |
274 // Let PHP do the work for us =) |
298 // Let PHP do the work for us =) |
275 return gmdate($string, $timestamp); |
299 $result = gmdate($string, $timestamp); |
|
300 if ( isset($relative_date) ) |
|
301 { |
|
302 $result = "$relative_date, $result"; |
|
303 } |
|
304 return $result; |
|
305 } |
|
306 |
|
307 /** |
|
308 * Get a relative date ("Today"/"Yesterday"/"N days ago") |
|
309 * @param int Timestamp |
|
310 * @return string |
|
311 */ |
|
312 |
|
313 function get_relative_date($time) |
|
314 { |
|
315 global $lang, $session; |
|
316 // Our formatting string to pass to enano_date() |
|
317 // This should not include minute/second info, only today's date in whatever format suits your fancy |
|
318 $formatstring = $session->date_format; |
|
319 // Today's date |
|
320 $today = enano_date($formatstring); |
|
321 // Yesterday's date |
|
322 $yesterday = enano_date($formatstring, (time() - (24*60*60))); |
|
323 // Date on the input |
|
324 $then = enano_date($formatstring, $time); |
|
325 // "X days ago" logic |
|
326 for ( $i = 2; $i <= 6; $i++ ) |
|
327 { |
|
328 // hours_in_day * minutes_in_hour * seconds_in_minute * num_days |
|
329 $offset = 24 * 60 * 60 * $i; |
|
330 $days_ago = enano_date($formatstring, (time() - $offset)); |
|
331 // so does the input timestamp match the date from $i days ago? |
|
332 if ( $then == $days_ago ) |
|
333 { |
|
334 // yes, return $i |
|
335 return $lang->get('userfuncs_ml_date_daysago', array('days_ago' => $i)); |
|
336 } |
|
337 } |
|
338 // either yesterday, today, or before 6 days ago |
|
339 switch($then) |
|
340 { |
|
341 case $today: |
|
342 return $lang->get('userfuncs_ml_date_today'); |
|
343 case $yesterday: |
|
344 return $lang->get('userfuncs_ml_date_yesterday'); |
|
345 default: |
|
346 return $then; |
|
347 } |
|
348 // .--. |
|
349 // |o_o | |
|
350 // |!_/ | |
|
351 // // \ \ |
|
352 // (| | ) |
|
353 // /'\_ _/`\ |
|
354 // \___)=(___/ |
|
355 return 'Linux rocks!'; |
276 } |
356 } |
277 |
357 |
278 /** |
358 /** |
279 * Determine if a timestamp is within DST. |
359 * Determine if a timestamp is within DST. |
280 * @param int Timestamp |
360 * @param int Timestamp |
1231 '1.1.1' => 'Caoineag alpha 1', |
1311 '1.1.1' => 'Caoineag alpha 1', |
1232 '1.1.2' => 'Caoineag alpha 2', |
1312 '1.1.2' => 'Caoineag alpha 2', |
1233 '1.1.3' => 'Caoineag alpha 3', |
1313 '1.1.3' => 'Caoineag alpha 3', |
1234 '1.1.4' => 'Caoineag alpha 4', |
1314 '1.1.4' => 'Caoineag alpha 4', |
1235 '1.1.5' => 'Caoineag alpha 5', |
1315 '1.1.5' => 'Caoineag alpha 5', |
1236 '1.1.6' => 'Caoineag beta 1' |
1316 '1.1.6' => 'Caoineag beta 1', |
|
1317 '1.1.7' => 'Caoineag beta 2' |
1237 ); |
1318 ); |
1238 $version = enano_version(); |
1319 $version = enano_version(); |
1239 if ( isset($names[$version]) ) |
1320 if ( isset($names[$version]) ) |
1240 { |
1321 { |
1241 return $names[$version]; |
1322 return $names[$version]; |