1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43:
44:
45:
46: 47: 48: 49: 50:
51: class SimplePie_Parse_Date
52: {
53: 54: 55: 56: 57: 58:
59: var $date;
60:
61: 62: 63: 64: 65: 66:
67: var $day = array(
68:
69: 'mon' => 1,
70: 'monday' => 1,
71: 'tue' => 2,
72: 'tuesday' => 2,
73: 'wed' => 3,
74: 'wednesday' => 3,
75: 'thu' => 4,
76: 'thursday' => 4,
77: 'fri' => 5,
78: 'friday' => 5,
79: 'sat' => 6,
80: 'saturday' => 6,
81: 'sun' => 7,
82: 'sunday' => 7,
83:
84: 'maandag' => 1,
85: 'dinsdag' => 2,
86: 'woensdag' => 3,
87: 'donderdag' => 4,
88: 'vrijdag' => 5,
89: 'zaterdag' => 6,
90: 'zondag' => 7,
91:
92: 'lundi' => 1,
93: 'mardi' => 2,
94: 'mercredi' => 3,
95: 'jeudi' => 4,
96: 'vendredi' => 5,
97: 'samedi' => 6,
98: 'dimanche' => 7,
99:
100: 'montag' => 1,
101: 'dienstag' => 2,
102: 'mittwoch' => 3,
103: 'donnerstag' => 4,
104: 'freitag' => 5,
105: 'samstag' => 6,
106: 'sonnabend' => 6,
107: 'sonntag' => 7,
108:
109: 'lunedì' => 1,
110: 'martedì' => 2,
111: 'mercoledì' => 3,
112: 'giovedì' => 4,
113: 'venerdì' => 5,
114: 'sabato' => 6,
115: 'domenica' => 7,
116:
117: 'lunes' => 1,
118: 'martes' => 2,
119: 'miércoles' => 3,
120: 'jueves' => 4,
121: 'viernes' => 5,
122: 'sábado' => 6,
123: 'domingo' => 7,
124:
125: 'maanantai' => 1,
126: 'tiistai' => 2,
127: 'keskiviikko' => 3,
128: 'torstai' => 4,
129: 'perjantai' => 5,
130: 'lauantai' => 6,
131: 'sunnuntai' => 7,
132:
133: 'hétfő' => 1,
134: 'kedd' => 2,
135: 'szerda' => 3,
136: 'csütörtok' => 4,
137: 'péntek' => 5,
138: 'szombat' => 6,
139: 'vasárnap' => 7,
140:
141: 'Δευ' => 1,
142: 'Τρι' => 2,
143: 'Τετ' => 3,
144: 'Πεμ' => 4,
145: 'Παρ' => 5,
146: 'Σαβ' => 6,
147: 'Κυρ' => 7,
148: );
149:
150: 151: 152: 153: 154: 155:
156: var $month = array(
157:
158: 'jan' => 1,
159: 'january' => 1,
160: 'feb' => 2,
161: 'february' => 2,
162: 'mar' => 3,
163: 'march' => 3,
164: 'apr' => 4,
165: 'april' => 4,
166: 'may' => 5,
167:
168: 'jun' => 6,
169: 'june' => 6,
170: 'jul' => 7,
171: 'july' => 7,
172: 'aug' => 8,
173: 'august' => 8,
174: 'sep' => 9,
175: 'september' => 8,
176: 'oct' => 10,
177: 'october' => 10,
178: 'nov' => 11,
179: 'november' => 11,
180: 'dec' => 12,
181: 'december' => 12,
182:
183: 'januari' => 1,
184: 'februari' => 2,
185: 'maart' => 3,
186: 'april' => 4,
187: 'mei' => 5,
188: 'juni' => 6,
189: 'juli' => 7,
190: 'augustus' => 8,
191: 'september' => 9,
192: 'oktober' => 10,
193: 'november' => 11,
194: 'december' => 12,
195:
196: 'janvier' => 1,
197: 'février' => 2,
198: 'mars' => 3,
199: 'avril' => 4,
200: 'mai' => 5,
201: 'juin' => 6,
202: 'juillet' => 7,
203: 'août' => 8,
204: 'septembre' => 9,
205: 'octobre' => 10,
206: 'novembre' => 11,
207: 'décembre' => 12,
208:
209: 'januar' => 1,
210: 'februar' => 2,
211: 'märz' => 3,
212: 'april' => 4,
213: 'mai' => 5,
214: 'juni' => 6,
215: 'juli' => 7,
216: 'august' => 8,
217: 'september' => 9,
218: 'oktober' => 10,
219: 'november' => 11,
220: 'dezember' => 12,
221:
222: 'gennaio' => 1,
223: 'febbraio' => 2,
224: 'marzo' => 3,
225: 'aprile' => 4,
226: 'maggio' => 5,
227: 'giugno' => 6,
228: 'luglio' => 7,
229: 'agosto' => 8,
230: 'settembre' => 9,
231: 'ottobre' => 10,
232: 'novembre' => 11,
233: 'dicembre' => 12,
234:
235: 'enero' => 1,
236: 'febrero' => 2,
237: 'marzo' => 3,
238: 'abril' => 4,
239: 'mayo' => 5,
240: 'junio' => 6,
241: 'julio' => 7,
242: 'agosto' => 8,
243: 'septiembre' => 9,
244: 'setiembre' => 9,
245: 'octubre' => 10,
246: 'noviembre' => 11,
247: 'diciembre' => 12,
248:
249: 'tammikuu' => 1,
250: 'helmikuu' => 2,
251: 'maaliskuu' => 3,
252: 'huhtikuu' => 4,
253: 'toukokuu' => 5,
254: 'kesäkuu' => 6,
255: 'heinäkuu' => 7,
256: 'elokuu' => 8,
257: 'suuskuu' => 9,
258: 'lokakuu' => 10,
259: 'marras' => 11,
260: 'joulukuu' => 12,
261:
262: 'január' => 1,
263: 'február' => 2,
264: 'március' => 3,
265: 'április' => 4,
266: 'május' => 5,
267: 'június' => 6,
268: 'július' => 7,
269: 'augusztus' => 8,
270: 'szeptember' => 9,
271: 'október' => 10,
272: 'november' => 11,
273: 'december' => 12,
274:
275: 'Ιαν' => 1,
276: 'Φεβ' => 2,
277: 'Μάώ' => 3,
278: 'Μαώ' => 3,
279: 'Απρ' => 4,
280: 'Μάι' => 5,
281: 'Μαϊ' => 5,
282: 'Μαι' => 5,
283: 'Ιούν' => 6,
284: 'Ιον' => 6,
285: 'Ιούλ' => 7,
286: 'Ιολ' => 7,
287: 'Αύγ' => 8,
288: 'Αυγ' => 8,
289: 'Σεπ' => 9,
290: 'Οκτ' => 10,
291: 'Νοέ' => 11,
292: 'Δεκ' => 12,
293: );
294:
295: 296: 297: 298: 299: 300:
301: var $timezone = array(
302: 'ACDT' => 37800,
303: 'ACIT' => 28800,
304: 'ACST' => 34200,
305: 'ACT' => -18000,
306: 'ACWDT' => 35100,
307: 'ACWST' => 31500,
308: 'AEDT' => 39600,
309: 'AEST' => 36000,
310: 'AFT' => 16200,
311: 'AKDT' => -28800,
312: 'AKST' => -32400,
313: 'AMDT' => 18000,
314: 'AMT' => -14400,
315: 'ANAST' => 46800,
316: 'ANAT' => 43200,
317: 'ART' => -10800,
318: 'AZOST' => -3600,
319: 'AZST' => 18000,
320: 'AZT' => 14400,
321: 'BIOT' => 21600,
322: 'BIT' => -43200,
323: 'BOT' => -14400,
324: 'BRST' => -7200,
325: 'BRT' => -10800,
326: 'BST' => 3600,
327: 'BTT' => 21600,
328: 'CAST' => 18000,
329: 'CAT' => 7200,
330: 'CCT' => 23400,
331: 'CDT' => -18000,
332: 'CEDT' => 7200,
333: 'CET' => 3600,
334: 'CGST' => -7200,
335: 'CGT' => -10800,
336: 'CHADT' => 49500,
337: 'CHAST' => 45900,
338: 'CIST' => -28800,
339: 'CKT' => -36000,
340: 'CLDT' => -10800,
341: 'CLST' => -14400,
342: 'COT' => -18000,
343: 'CST' => -21600,
344: 'CVT' => -3600,
345: 'CXT' => 25200,
346: 'DAVT' => 25200,
347: 'DTAT' => 36000,
348: 'EADT' => -18000,
349: 'EAST' => -21600,
350: 'EAT' => 10800,
351: 'ECT' => -18000,
352: 'EDT' => -14400,
353: 'EEST' => 10800,
354: 'EET' => 7200,
355: 'EGT' => -3600,
356: 'EKST' => 21600,
357: 'EST' => -18000,
358: 'FJT' => 43200,
359: 'FKDT' => -10800,
360: 'FKST' => -14400,
361: 'FNT' => -7200,
362: 'GALT' => -21600,
363: 'GEDT' => 14400,
364: 'GEST' => 10800,
365: 'GFT' => -10800,
366: 'GILT' => 43200,
367: 'GIT' => -32400,
368: 'GST' => 14400,
369: 'GST' => -7200,
370: 'GYT' => -14400,
371: 'HAA' => -10800,
372: 'HAC' => -18000,
373: 'HADT' => -32400,
374: 'HAE' => -14400,
375: 'HAP' => -25200,
376: 'HAR' => -21600,
377: 'HAST' => -36000,
378: 'HAT' => -9000,
379: 'HAY' => -28800,
380: 'HKST' => 28800,
381: 'HMT' => 18000,
382: 'HNA' => -14400,
383: 'HNC' => -21600,
384: 'HNE' => -18000,
385: 'HNP' => -28800,
386: 'HNR' => -25200,
387: 'HNT' => -12600,
388: 'HNY' => -32400,
389: 'IRDT' => 16200,
390: 'IRKST' => 32400,
391: 'IRKT' => 28800,
392: 'IRST' => 12600,
393: 'JFDT' => -10800,
394: 'JFST' => -14400,
395: 'JST' => 32400,
396: 'KGST' => 21600,
397: 'KGT' => 18000,
398: 'KOST' => 39600,
399: 'KOVST' => 28800,
400: 'KOVT' => 25200,
401: 'KRAST' => 28800,
402: 'KRAT' => 25200,
403: 'KST' => 32400,
404: 'LHDT' => 39600,
405: 'LHST' => 37800,
406: 'LINT' => 50400,
407: 'LKT' => 21600,
408: 'MAGST' => 43200,
409: 'MAGT' => 39600,
410: 'MAWT' => 21600,
411: 'MDT' => -21600,
412: 'MESZ' => 7200,
413: 'MEZ' => 3600,
414: 'MHT' => 43200,
415: 'MIT' => -34200,
416: 'MNST' => 32400,
417: 'MSDT' => 14400,
418: 'MSST' => 10800,
419: 'MST' => -25200,
420: 'MUT' => 14400,
421: 'MVT' => 18000,
422: 'MYT' => 28800,
423: 'NCT' => 39600,
424: 'NDT' => -9000,
425: 'NFT' => 41400,
426: 'NMIT' => 36000,
427: 'NOVST' => 25200,
428: 'NOVT' => 21600,
429: 'NPT' => 20700,
430: 'NRT' => 43200,
431: 'NST' => -12600,
432: 'NUT' => -39600,
433: 'NZDT' => 46800,
434: 'NZST' => 43200,
435: 'OMSST' => 25200,
436: 'OMST' => 21600,
437: 'PDT' => -25200,
438: 'PET' => -18000,
439: 'PETST' => 46800,
440: 'PETT' => 43200,
441: 'PGT' => 36000,
442: 'PHOT' => 46800,
443: 'PHT' => 28800,
444: 'PKT' => 18000,
445: 'PMDT' => -7200,
446: 'PMST' => -10800,
447: 'PONT' => 39600,
448: 'PST' => -28800,
449: 'PWT' => 32400,
450: 'PYST' => -10800,
451: 'PYT' => -14400,
452: 'RET' => 14400,
453: 'ROTT' => -10800,
454: 'SAMST' => 18000,
455: 'SAMT' => 14400,
456: 'SAST' => 7200,
457: 'SBT' => 39600,
458: 'SCDT' => 46800,
459: 'SCST' => 43200,
460: 'SCT' => 14400,
461: 'SEST' => 3600,
462: 'SGT' => 28800,
463: 'SIT' => 28800,
464: 'SRT' => -10800,
465: 'SST' => -39600,
466: 'SYST' => 10800,
467: 'SYT' => 7200,
468: 'TFT' => 18000,
469: 'THAT' => -36000,
470: 'TJT' => 18000,
471: 'TKT' => -36000,
472: 'TMT' => 18000,
473: 'TOT' => 46800,
474: 'TPT' => 32400,
475: 'TRUT' => 36000,
476: 'TVT' => 43200,
477: 'TWT' => 28800,
478: 'UYST' => -7200,
479: 'UYT' => -10800,
480: 'UZT' => 18000,
481: 'VET' => -14400,
482: 'VLAST' => 39600,
483: 'VLAT' => 36000,
484: 'VOST' => 21600,
485: 'VUT' => 39600,
486: 'WAST' => 7200,
487: 'WAT' => 3600,
488: 'WDT' => 32400,
489: 'WEST' => 3600,
490: 'WFT' => 43200,
491: 'WIB' => 25200,
492: 'WIT' => 32400,
493: 'WITA' => 28800,
494: 'WKST' => 18000,
495: 'WST' => 28800,
496: 'YAKST' => 36000,
497: 'YAKT' => 32400,
498: 'YAPT' => 36000,
499: 'YEKST' => 21600,
500: 'YEKT' => 18000,
501: );
502:
503: 504: 505: 506: 507: 508:
509: var $day_pcre;
510:
511: 512: 513: 514: 515: 516:
517: var $month_pcre;
518:
519: 520: 521: 522: 523: 524:
525: var $built_in = array();
526:
527: 528: 529: 530: 531: 532:
533: var $user = array();
534:
535: 536: 537: 538: 539: 540:
541: public function __construct()
542: {
543: $this->day_pcre = '(' . implode(array_keys($this->day), '|') . ')';
544: $this->month_pcre = '(' . implode(array_keys($this->month), '|') . ')';
545:
546: static $cache;
547: if (!isset($cache[get_class($this)]))
548: {
549: $all_methods = get_class_methods($this);
550:
551: foreach ($all_methods as $method)
552: {
553: if (strtolower(substr($method, 0, 5)) === 'date_')
554: {
555: $cache[get_class($this)][] = $method;
556: }
557: }
558: }
559:
560: foreach ($cache[get_class($this)] as $method)
561: {
562: $this->built_in[] = $method;
563: }
564: }
565:
566: 567: 568: 569: 570:
571: public static function get()
572: {
573: static $object;
574: if (!$object)
575: {
576: $object = new SimplePie_Parse_Date;
577: }
578: return $object;
579: }
580:
581: 582: 583: 584: 585: 586: 587: 588:
589: public function parse($date)
590: {
591: foreach ($this->user as $method)
592: {
593: if (($returned = call_user_func($method, $date)) !== false)
594: {
595: return $returned;
596: }
597: }
598:
599: foreach ($this->built_in as $method)
600: {
601: if (($returned = call_user_func(array(&$this, $method), $date)) !== false)
602: {
603: return $returned;
604: }
605: }
606:
607: return false;
608: }
609:
610: 611: 612: 613: 614: 615: 616:
617: public function add_callback($callback)
618: {
619: if (is_callable($callback))
620: {
621: $this->user[] = $callback;
622: }
623: else
624: {
625: trigger_error('User-supplied function must be a valid callback', E_USER_WARNING);
626: }
627: }
628:
629: 630: 631: 632: 633: 634: 635: 636:
637: public function date_w3cdtf($date)
638: {
639: static $pcre;
640: if (!$pcre)
641: {
642: $year = '([0-9]{4})';
643: $month = $day = $hour = $minute = $second = '([0-9]{2})';
644: $decimal = '([0-9]*)';
645: $zone = '(?:(Z)|([+\-])([0-9]{1,2}):?([0-9]{1,2}))';
646: $pcre = '/^' . $year . '(?:-?' . $month . '(?:-?' . $day . '(?:[Tt\x09\x20]+' . $hour . '(?::?' . $minute . '(?::?' . $second . '(?:.' . $decimal . ')?)?)?' . $zone . ')?)?)?$/';
647: }
648: if (preg_match($pcre, $date, $match))
649: {
650: 651: 652: 653: 654: 655: 656: 657: 658: 659: 660: 661: 662: 663:
664:
665:
666: for ($i = count($match); $i <= 3; $i++)
667: {
668: $match[$i] = '1';
669: }
670:
671: for ($i = count($match); $i <= 7; $i++)
672: {
673: $match[$i] = '0';
674: }
675:
676:
677: if (isset($match[9]) && $match[9] !== '')
678: {
679: $timezone = $match[10] * 3600;
680: $timezone += $match[11] * 60;
681: if ($match[9] === '-')
682: {
683: $timezone = 0 - $timezone;
684: }
685: }
686: else
687: {
688: $timezone = 0;
689: }
690:
691:
692: $second = round($match[6] + $match[7] / pow(10, strlen($match[7])));
693:
694: return gmmktime($match[4], $match[5], $second, $match[2], $match[3], $match[1]) - $timezone;
695: }
696: else
697: {
698: return false;
699: }
700: }
701:
702: 703: 704: 705: 706: 707: 708:
709: public function remove_rfc2822_comments($string)
710: {
711: $string = (string) $string;
712: $position = 0;
713: $length = strlen($string);
714: $depth = 0;
715:
716: $output = '';
717:
718: while ($position < $length && ($pos = strpos($string, '(', $position)) !== false)
719: {
720: $output .= substr($string, $position, $pos - $position);
721: $position = $pos + 1;
722: if ($string[$pos - 1] !== '\\')
723: {
724: $depth++;
725: while ($depth && $position < $length)
726: {
727: $position += strcspn($string, '()', $position);
728: if ($string[$position - 1] === '\\')
729: {
730: $position++;
731: continue;
732: }
733: elseif (isset($string[$position]))
734: {
735: switch ($string[$position])
736: {
737: case '(':
738: $depth++;
739: break;
740:
741: case ')':
742: $depth--;
743: break;
744: }
745: $position++;
746: }
747: else
748: {
749: break;
750: }
751: }
752: }
753: else
754: {
755: $output .= '(';
756: }
757: }
758: $output .= substr($string, $position);
759:
760: return $output;
761: }
762:
763: 764: 765: 766: 767: 768:
769: public function date_rfc2822($date)
770: {
771: static $pcre;
772: if (!$pcre)
773: {
774: $wsp = '[\x09\x20]';
775: $fws = '(?:' . $wsp . '+|' . $wsp . '*(?:\x0D\x0A' . $wsp . '+)+)';
776: $optional_fws = $fws . '?';
777: $day_name = $this->day_pcre;
778: $month = $this->month_pcre;
779: $day = '([0-9]{1,2})';
780: $hour = $minute = $second = '([0-9]{2})';
781: $year = '([0-9]{2,4})';
782: $num_zone = '([+\-])([0-9]{2})([0-9]{2})';
783: $character_zone = '([A-Z]{1,5})';
784: $zone = '(?:' . $num_zone . '|' . $character_zone . ')';
785: $pcre = '/(?:' . $optional_fws . $day_name . $optional_fws . ',)?' . $optional_fws . $day . $fws . $month . $fws . $year . $fws . $hour . $optional_fws . ':' . $optional_fws . $minute . '(?:' . $optional_fws . ':' . $optional_fws . $second . ')?' . $fws . $zone . '/i';
786: }
787: if (preg_match($pcre, $this->remove_rfc2822_comments($date), $match))
788: {
789: 790: 791: 792: 793: 794: 795: 796: 797: 798: 799: 800: 801: 802:
803:
804:
805: $month = $this->month[strtolower($match[3])];
806:
807:
808: if ($match[8] !== '')
809: {
810: $timezone = $match[9] * 3600;
811: $timezone += $match[10] * 60;
812: if ($match[8] === '-')
813: {
814: $timezone = 0 - $timezone;
815: }
816: }
817:
818: elseif (isset($this->timezone[strtoupper($match[11])]))
819: {
820: $timezone = $this->timezone[strtoupper($match[11])];
821: }
822:
823: else
824: {
825: $timezone = 0;
826: }
827:
828:
829: if ($match[4] < 50)
830: {
831: $match[4] += 2000;
832: }
833: elseif ($match[4] < 1000)
834: {
835: $match[4] += 1900;
836: }
837:
838:
839: if ($match[7] !== '')
840: {
841: $second = $match[7];
842: }
843: else
844: {
845: $second = 0;
846: }
847:
848: return gmmktime($match[5], $match[6], $second, $month, $match[2], $match[4]) - $timezone;
849: }
850: else
851: {
852: return false;
853: }
854: }
855:
856: 857: 858: 859: 860: 861:
862: public function date_rfc850($date)
863: {
864: static $pcre;
865: if (!$pcre)
866: {
867: $space = '[\x09\x20]+';
868: $day_name = $this->day_pcre;
869: $month = $this->month_pcre;
870: $day = '([0-9]{1,2})';
871: $year = $hour = $minute = $second = '([0-9]{2})';
872: $zone = '([A-Z]{1,5})';
873: $pcre = '/^' . $day_name . ',' . $space . $day . '-' . $month . '-' . $year . $space . $hour . ':' . $minute . ':' . $second . $space . $zone . '$/i';
874: }
875: if (preg_match($pcre, $date, $match))
876: {
877: 878: 879: 880: 881: 882: 883: 884: 885: 886: 887:
888:
889:
890: $month = $this->month[strtolower($match[3])];
891:
892:
893: if (isset($this->timezone[strtoupper($match[8])]))
894: {
895: $timezone = $this->timezone[strtoupper($match[8])];
896: }
897:
898: else
899: {
900: $timezone = 0;
901: }
902:
903:
904: if ($match[4] < 50)
905: {
906: $match[4] += 2000;
907: }
908: else
909: {
910: $match[4] += 1900;
911: }
912:
913: return gmmktime($match[5], $match[6], $match[7], $month, $match[2], $match[4]) - $timezone;
914: }
915: else
916: {
917: return false;
918: }
919: }
920:
921: 922: 923: 924: 925: 926:
927: public function date_asctime($date)
928: {
929: static $pcre;
930: if (!$pcre)
931: {
932: $space = '[\x09\x20]+';
933: $wday_name = $this->day_pcre;
934: $mon_name = $this->month_pcre;
935: $day = '([0-9]{1,2})';
936: $hour = $sec = $min = '([0-9]{2})';
937: $year = '([0-9]{4})';
938: $terminator = '\x0A?\x00?';
939: $pcre = '/^' . $wday_name . $space . $mon_name . $space . $day . $space . $hour . ':' . $min . ':' . $sec . $space . $year . $terminator . '$/i';
940: }
941: if (preg_match($pcre, $date, $match))
942: {
943: 944: 945: 946: 947: 948: 949: 950: 951: 952:
953:
954: $month = $this->month[strtolower($match[2])];
955: return gmmktime($match[4], $match[5], $match[6], $month, $match[3], $match[7]);
956: }
957: else
958: {
959: return false;
960: }
961: }
962:
963: 964: 965: 966: 967: 968:
969: public function date_strtotime($date)
970: {
971: $strtotime = strtotime($date);
972: if ($strtotime === -1 || $strtotime === false)
973: {
974: return false;
975: }
976: else
977: {
978: return $strtotime;
979: }
980: }
981: }
982:
983: