rss_utils.inc 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /*
  3. * Project: MagpieRSS: a simple RSS integration tool
  4. * File: rss_utils.inc, utility methods for working with RSS
  5. * Author: Kellan Elliott-McCrea <kellan@protest.net>
  6. * Version: 0.51
  7. * License: GPL
  8. *
  9. * The lastest version of MagpieRSS can be obtained from:
  10. * http://magpierss.sourceforge.net
  11. *
  12. * For questions, help, comments, discussion, etc., please join the
  13. * Magpie mailing list:
  14. * magpierss-general@lists.sourceforge.net
  15. */
  16. /*======================================================================*\
  17. Function: parse_w3cdtf
  18. Purpose: parse a W3CDTF date into unix epoch
  19. NOTE: http://www.w3.org/TR/NOTE-datetime
  20. \*======================================================================*/
  21. function parse_w3cdtf ( $date_str ) {
  22. # regex to match wc3dtf
  23. $pat = "/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(:(\d{2}))?(?:([-+])(\d{2}):?(\d{2})|(Z))?/";
  24. if ( preg_match( $pat, $date_str, $match ) ) {
  25. list( $year, $month, $day, $hours, $minutes, $seconds) =
  26. array( $match[1], $match[2], $match[3], $match[4], $match[5], $match[6]);
  27. # calc epoch for current date assuming GMT
  28. $epoch = gmmktime( $hours, $minutes, $seconds, $month, $day, $year);
  29. $offset = 0;
  30. if ( $match[10] == 'Z' ) {
  31. # zulu time, aka GMT
  32. }
  33. else {
  34. list( $tz_mod, $tz_hour, $tz_min ) =
  35. array( $match[8], $match[9], $match[10]);
  36. # zero out the variables
  37. if ( ! $tz_hour ) { $tz_hour = 0; }
  38. if ( ! $tz_min ) { $tz_min = 0; }
  39. $offset_secs = (($tz_hour*60)+$tz_min)*60;
  40. # is timezone ahead of GMT? then subtract offset
  41. #
  42. if ( $tz_mod == '+' ) {
  43. $offset_secs = $offset_secs * -1;
  44. }
  45. $offset = $offset_secs;
  46. }
  47. $epoch = $epoch + $offset;
  48. return $epoch;
  49. }
  50. else {
  51. return -1;
  52. }
  53. }