rss_utils.inc 1.9 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. * @package chamilo.include.rss
  16. */
  17. /**
  18. * Function: parse_w3cdtf
  19. * Purpose: parse a W3CDTF date into unix epoch
  20. *
  21. * NOTE: http://www.w3.org/TR/NOTE-datetime
  22. */
  23. function parse_w3cdtf ( $date_str ) {
  24. # regex to match wc3dtf
  25. $pat = "/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(:(\d{2}))?(?:([-+])(\d{2}):?(\d{2})|(Z))?/";
  26. if ( preg_match( $pat, $date_str, $match ) ) {
  27. list( $year, $month, $day, $hours, $minutes, $seconds) =
  28. array( $match[1], $match[2], $match[3], $match[4], $match[5], $match[6]);
  29. # calc epoch for current date assuming GMT
  30. $epoch = gmmktime( $hours, $minutes, $seconds, $month, $day, $year);
  31. $offset = 0;
  32. if ( $match[10] == 'Z' ) {
  33. # zulu time, aka GMT
  34. }
  35. else {
  36. list( $tz_mod, $tz_hour, $tz_min ) =
  37. array( $match[8], $match[9], $match[10]);
  38. # zero out the variables
  39. if ( ! $tz_hour ) { $tz_hour = 0; }
  40. if ( ! $tz_min ) { $tz_min = 0; }
  41. $offset_secs = (($tz_hour*60)+$tz_min)*60;
  42. # is timezone ahead of GMT? then subtract offset
  43. #
  44. if ( $tz_mod == '+' ) {
  45. $offset_secs = $offset_secs * -1;
  46. }
  47. $offset = $offset_secs;
  48. }
  49. $epoch = $epoch + $offset;
  50. return $epoch;
  51. }
  52. else {
  53. return -1;
  54. }
  55. }