equal
deleted
inserted
replaced
3 * SimplePie |
3 * SimplePie |
4 * |
4 * |
5 * A PHP-Based RSS and Atom Feed Framework. |
5 * A PHP-Based RSS and Atom Feed Framework. |
6 * Takes the hard work out of managing a complete RSS/Atom solution. |
6 * Takes the hard work out of managing a complete RSS/Atom solution. |
7 * |
7 * |
8 * Copyright (c) 2004-2012, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors |
8 * Copyright (c) 2004-2016, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors |
9 * All rights reserved. |
9 * All rights reserved. |
10 * |
10 * |
11 * Redistribution and use in source and binary forms, with or without modification, are |
11 * Redistribution and use in source and binary forms, with or without modification, are |
12 * permitted provided that the following conditions are met: |
12 * permitted provided that the following conditions are met: |
13 * |
13 * |
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
32 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
32 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
33 * POSSIBILITY OF SUCH DAMAGE. |
33 * POSSIBILITY OF SUCH DAMAGE. |
34 * |
34 * |
35 * @package SimplePie |
35 * @package SimplePie |
36 * @version 1.3.1 |
36 * @copyright 2004-2016 Ryan Parman, Sam Sneddon, Ryan McCue |
37 * @copyright 2004-2012 Ryan Parman, Geoffrey Sneddon, Ryan McCue |
|
38 * @author Ryan Parman |
37 * @author Ryan Parman |
39 * @author Geoffrey Sneddon |
38 * @author Sam Sneddon |
40 * @author Ryan McCue |
39 * @author Ryan McCue |
41 * @link http://simplepie.org/ SimplePie |
40 * @link http://simplepie.org/ SimplePie |
42 * @license http://www.opensource.org/licenses/bsd-license.php BSD License |
41 * @license http://www.opensource.org/licenses/bsd-license.php BSD License |
43 */ |
42 */ |
44 |
43 |
97 'vendredi' => 5, |
96 'vendredi' => 5, |
98 'samedi' => 6, |
97 'samedi' => 6, |
99 'dimanche' => 7, |
98 'dimanche' => 7, |
100 // German |
99 // German |
101 'montag' => 1, |
100 'montag' => 1, |
|
101 'mo' => 1, |
102 'dienstag' => 2, |
102 'dienstag' => 2, |
|
103 'di' => 2, |
103 'mittwoch' => 3, |
104 'mittwoch' => 3, |
|
105 'mi' => 3, |
104 'donnerstag' => 4, |
106 'donnerstag' => 4, |
|
107 'do' => 4, |
105 'freitag' => 5, |
108 'freitag' => 5, |
|
109 'fr' => 5, |
106 'samstag' => 6, |
110 'samstag' => 6, |
|
111 'sa' => 6, |
107 'sonnabend' => 6, |
112 'sonnabend' => 6, |
|
113 // AFAIK no short form for sonnabend |
|
114 'so' => 7, |
108 'sonntag' => 7, |
115 'sonntag' => 7, |
109 // Italian |
116 // Italian |
110 'lunedì' => 1, |
117 'lunedì' => 1, |
111 'martedì' => 2, |
118 'martedì' => 2, |
112 'mercoledì' => 3, |
119 'mercoledì' => 3, |
144 'Τετ' => 3, |
151 'Τετ' => 3, |
145 'Πεμ' => 4, |
152 'Πεμ' => 4, |
146 'Παρ' => 5, |
153 'Παρ' => 5, |
147 'Σαβ' => 6, |
154 'Σαβ' => 6, |
148 'Κυρ' => 7, |
155 'Κυρ' => 7, |
|
156 // Russian |
|
157 'Пн.' => 1, |
|
158 'Вт.' => 2, |
|
159 'Ср.' => 3, |
|
160 'Чт.' => 4, |
|
161 'Пт.' => 5, |
|
162 'Сб.' => 6, |
|
163 'Вс.' => 7, |
149 ); |
164 ); |
150 |
165 |
151 /** |
166 /** |
152 * List of months, calendar month name => calendar month number |
167 * List of months, calendar month name => calendar month number |
153 * |
168 * |
171 'jul' => 7, |
186 'jul' => 7, |
172 'july' => 7, |
187 'july' => 7, |
173 'aug' => 8, |
188 'aug' => 8, |
174 'august' => 8, |
189 'august' => 8, |
175 'sep' => 9, |
190 'sep' => 9, |
176 'september' => 8, |
191 'september' => 9, |
177 'oct' => 10, |
192 'oct' => 10, |
178 'october' => 10, |
193 'october' => 10, |
179 'nov' => 11, |
194 'nov' => 11, |
180 'november' => 11, |
195 'november' => 11, |
181 'dec' => 12, |
196 'dec' => 12, |
206 'octobre' => 10, |
221 'octobre' => 10, |
207 'novembre' => 11, |
222 'novembre' => 11, |
208 'décembre' => 12, |
223 'décembre' => 12, |
209 // German |
224 // German |
210 'januar' => 1, |
225 'januar' => 1, |
|
226 'jan' => 1, |
211 'februar' => 2, |
227 'februar' => 2, |
|
228 'feb' => 2, |
212 'märz' => 3, |
229 'märz' => 3, |
|
230 'mär' => 3, |
213 'april' => 4, |
231 'april' => 4, |
214 'mai' => 5, |
232 'apr' => 4, |
|
233 'mai' => 5, // no short form for may |
215 'juni' => 6, |
234 'juni' => 6, |
|
235 'jun' => 6, |
216 'juli' => 7, |
236 'juli' => 7, |
|
237 'jul' => 7, |
217 'august' => 8, |
238 'august' => 8, |
|
239 'aug' => 8, |
218 'september' => 9, |
240 'september' => 9, |
|
241 'sep' => 9, |
219 'oktober' => 10, |
242 'oktober' => 10, |
|
243 'okt' => 10, |
220 'november' => 11, |
244 'november' => 11, |
|
245 'nov' => 11, |
221 'dezember' => 12, |
246 'dezember' => 12, |
|
247 'dez' => 12, |
222 // Italian |
248 // Italian |
223 'gennaio' => 1, |
249 'gennaio' => 1, |
224 'febbraio' => 2, |
250 'febbraio' => 2, |
225 'marzo' => 3, |
251 'marzo' => 3, |
226 'aprile' => 4, |
252 'aprile' => 4, |
288 'Αύγ' => 8, |
314 'Αύγ' => 8, |
289 'Αυγ' => 8, |
315 'Αυγ' => 8, |
290 'Σεπ' => 9, |
316 'Σεπ' => 9, |
291 'Οκτ' => 10, |
317 'Οκτ' => 10, |
292 'Νοέ' => 11, |
318 'Νοέ' => 11, |
293 'Δεκ' => 12, |
319 'Δεκ' => 12, |
|
320 // Russian |
|
321 'Янв' => 1, |
|
322 'января' => 1, |
|
323 'Фев' => 2, |
|
324 'февраля' => 2, |
|
325 'Мар' => 3, |
|
326 'марта' => 3, |
|
327 'Апр' => 4, |
|
328 'апреля' => 4, |
|
329 'Май' => 5, |
|
330 'мая' => 5, |
|
331 'Июн' => 6, |
|
332 'июня' => 6, |
|
333 'Июл' => 7, |
|
334 'июля' => 7, |
|
335 'Авг' => 8, |
|
336 'августа' => 8, |
|
337 'Сен' => 9, |
|
338 'сентября' => 9, |
|
339 'Окт' => 10, |
|
340 'октября' => 10, |
|
341 'Ноя' => 11, |
|
342 'ноября' => 11, |
|
343 'Дек' => 12, |
|
344 'декабря' => 12, |
|
345 |
294 ); |
346 ); |
295 |
347 |
296 /** |
348 /** |
297 * List of timezones, abbreviation => offset from UTC |
349 * List of timezones, abbreviation => offset from UTC |
298 * |
350 * |
540 * |
592 * |
541 * @access private |
593 * @access private |
542 */ |
594 */ |
543 public function __construct() |
595 public function __construct() |
544 { |
596 { |
545 $this->day_pcre = '(' . implode(array_keys($this->day), '|') . ')'; |
597 $this->day_pcre = '(' . implode('|', array_keys($this->day)) . ')'; |
546 $this->month_pcre = '(' . implode(array_keys($this->month), '|') . ')'; |
598 $this->month_pcre = '(' . implode('|', array_keys($this->month)) . ')'; |
547 |
599 |
548 static $cache; |
600 static $cache; |
549 if (!isset($cache[get_class($this)])) |
601 if (!isset($cache[get_class($this)])) |
550 { |
602 { |
551 $all_methods = get_class_methods($this); |
603 $all_methods = get_class_methods($this); |
612 /** |
664 /** |
613 * Add a callback method to parse a date |
665 * Add a callback method to parse a date |
614 * |
666 * |
615 * @final |
667 * @final |
616 * @access public |
668 * @access public |
617 * @param callable $callback |
669 * @param callback $callback |
618 */ |
670 */ |
619 public function add_callback($callback) |
671 public function add_callback($callback) |
620 { |
672 { |
621 if (is_callable($callback)) |
673 if (is_callable($callback)) |
622 { |
674 { |
629 } |
681 } |
630 |
682 |
631 /** |
683 /** |
632 * Parse a superset of W3C-DTF (allows hyphens and colons to be omitted, as |
684 * Parse a superset of W3C-DTF (allows hyphens and colons to be omitted, as |
633 * well as allowing any of upper or lower case "T", horizontal tabs, or |
685 * well as allowing any of upper or lower case "T", horizontal tabs, or |
634 * spaces to be used as the time seperator (including more than one)) |
686 * spaces to be used as the time separator (including more than one)) |
635 * |
687 * |
636 * @access protected |
688 * @access protected |
637 * @return int Timestamp |
689 * @return int Timestamp |
638 */ |
690 */ |
639 public function date_w3cdtf($date) |
691 public function date_w3cdtf($date) |
689 { |
741 { |
690 $timezone = 0; |
742 $timezone = 0; |
691 } |
743 } |
692 |
744 |
693 // Convert the number of seconds to an integer, taking decimals into account |
745 // Convert the number of seconds to an integer, taking decimals into account |
694 $second = round($match[6] + $match[7] / pow(10, strlen($match[7]))); |
746 $second = round((int)$match[6] + (int)$match[7] / (10 ** strlen($match[7]))); |
695 |
747 |
696 return gmmktime($match[4], $match[5], $second, $match[2], $match[3], $match[1]) - $timezone; |
748 return gmmktime($match[4], $match[5], $second, $match[2], $match[3], $match[1]) - $timezone; |
697 } |
749 } |
698 else |
750 |
699 { |
751 return false; |
700 return false; |
|
701 } |
|
702 } |
752 } |
703 |
753 |
704 /** |
754 /** |
705 * Remove RFC822 comments |
755 * Remove RFC822 comments |
706 * |
756 * |
719 |
769 |
720 while ($position < $length && ($pos = strpos($string, '(', $position)) !== false) |
770 while ($position < $length && ($pos = strpos($string, '(', $position)) !== false) |
721 { |
771 { |
722 $output .= substr($string, $position, $pos - $position); |
772 $output .= substr($string, $position, $pos - $position); |
723 $position = $pos + 1; |
773 $position = $pos + 1; |
724 if ($string[$pos - 1] !== '\\') |
774 if ($pos === 0 || $string[$pos - 1] !== '\\') |
725 { |
775 { |
726 $depth++; |
776 $depth++; |
727 while ($depth && $position < $length) |
777 while ($depth && $position < $length) |
728 { |
778 { |
729 $position += strcspn($string, '()', $position); |
779 $position += strcspn($string, '()', $position); |
847 $second = 0; |
897 $second = 0; |
848 } |
898 } |
849 |
899 |
850 return gmmktime($match[5], $match[6], $second, $month, $match[2], $match[4]) - $timezone; |
900 return gmmktime($match[5], $match[6], $second, $month, $match[2], $match[4]) - $timezone; |
851 } |
901 } |
852 else |
902 |
853 { |
903 return false; |
854 return false; |
|
855 } |
|
856 } |
904 } |
857 |
905 |
858 /** |
906 /** |
859 * Parse RFC850's date format |
907 * Parse RFC850's date format |
860 * |
908 * |
912 $match[4] += 1900; |
960 $match[4] += 1900; |
913 } |
961 } |
914 |
962 |
915 return gmmktime($match[5], $match[6], $match[7], $month, $match[2], $match[4]) - $timezone; |
963 return gmmktime($match[5], $match[6], $match[7], $month, $match[2], $match[4]) - $timezone; |
916 } |
964 } |
917 else |
965 |
918 { |
966 return false; |
919 return false; |
|
920 } |
|
921 } |
967 } |
922 |
968 |
923 /** |
969 /** |
924 * Parse C99's asctime()'s date format |
970 * Parse C99's asctime()'s date format |
925 * |
971 * |
954 */ |
1000 */ |
955 |
1001 |
956 $month = $this->month[strtolower($match[2])]; |
1002 $month = $this->month[strtolower($match[2])]; |
957 return gmmktime($match[4], $match[5], $match[6], $month, $match[3], $match[7]); |
1003 return gmmktime($match[4], $match[5], $match[6], $month, $match[3], $match[7]); |
958 } |
1004 } |
959 else |
1005 |
960 { |
1006 return false; |
961 return false; |
|
962 } |
|
963 } |
1007 } |
964 |
1008 |
965 /** |
1009 /** |
966 * Parse dates using strtotime() |
1010 * Parse dates using strtotime() |
967 * |
1011 * |
973 $strtotime = strtotime($date); |
1017 $strtotime = strtotime($date); |
974 if ($strtotime === -1 || $strtotime === false) |
1018 if ($strtotime === -1 || $strtotime === false) |
975 { |
1019 { |
976 return false; |
1020 return false; |
977 } |
1021 } |
978 else |
1022 |
979 { |
1023 return $strtotime; |
980 return $strtotime; |
|
981 } |
|
982 } |
1024 } |
983 } |
1025 } |
984 |
|