Overview

Packages

  • None
  • SimplePie

Classes

  • SimplePie
  • SimplePie_Author
  • SimplePie_Autoloader
  • SimplePie_Cache
  • SimplePie_Cache_DB
  • SimplePie_Cache_File
  • SimplePie_Cache_Memcache
  • SimplePie_Cache_MySQL
  • SimplePie_Caption
  • SimplePie_Category
  • SimplePie_Content_Type_Sniffer
  • SimplePie_Copyright
  • SimplePie_Core
  • SimplePie_Credit
  • SimplePie_Decode_HTML_Entities
  • SimplePie_Enclosure
  • SimplePie_File
  • SimplePie_gzdecode
  • SimplePie_HTTP_Parser
  • SimplePie_IRI
  • SimplePie_Item
  • SimplePie_Locator
  • SimplePie_Misc
  • SimplePie_Net_IPv6
  • SimplePie_Parse_Date
  • SimplePie_Parser
  • SimplePie_Rating
  • SimplePie_Registry
  • SimplePie_Restriction
  • SimplePie_Sanitize
  • SimplePie_Source
  • SimplePie_XML_Declaration_Parser

Interfaces

  • SimplePie_Cache_Base
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * SimplePie
  4:  *
  5:  * A PHP-Based RSS and Atom Feed Framework.
  6:  * Takes the hard work out of managing a complete RSS/Atom solution.
  7:  *
  8:  * Copyright (c) 2004-2012, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
  9:  * All rights reserved.
 10:  *
 11:  * Redistribution and use in source and binary forms, with or without modification, are
 12:  * permitted provided that the following conditions are met:
 13:  *
 14:  *  * Redistributions of source code must retain the above copyright notice, this list of
 15:  *    conditions and the following disclaimer.
 16:  *
 17:  *  * Redistributions in binary form must reproduce the above copyright notice, this list
 18:  *    of conditions and the following disclaimer in the documentation and/or other materials
 19:  *    provided with the distribution.
 20:  *
 21:  *  * Neither the name of the SimplePie Team nor the names of its contributors may be used
 22:  *    to endorse or promote products derived from this software without specific prior
 23:  *    written permission.
 24:  *
 25:  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
 26:  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
 27:  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
 28:  * AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 29:  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 30:  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 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
 33:  * POSSIBILITY OF SUCH DAMAGE.
 34:  *
 35:  * @package SimplePie
 36:  * @version 1.3-dev
 37:  * @copyright 2004-2012 Ryan Parman, Geoffrey Sneddon, Ryan McCue
 38:  * @author Ryan Parman
 39:  * @author Geoffrey Sneddon
 40:  * @author Ryan McCue
 41:  * @link http://simplepie.org/ SimplePie
 42:  * @license http://www.opensource.org/licenses/bsd-license.php BSD License
 43:  */
 44: 
 45: 
 46: /**
 47:  * Date Parser
 48:  *
 49:  * @package SimplePie
 50:  */
 51: class SimplePie_Parse_Date
 52: {
 53:     /**
 54:      * Input data
 55:      *
 56:      * @access protected
 57:      * @var string
 58:      */
 59:     var $date;
 60: 
 61:     /**
 62:      * List of days, calendar day name => ordinal day number in the week
 63:      *
 64:      * @access protected
 65:      * @var array
 66:      */
 67:     var $day = array(
 68:         // English
 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:         // Dutch
 84:         'maandag' => 1,
 85:         'dinsdag' => 2,
 86:         'woensdag' => 3,
 87:         'donderdag' => 4,
 88:         'vrijdag' => 5,
 89:         'zaterdag' => 6,
 90:         'zondag' => 7,
 91:         // French
 92:         'lundi' => 1,
 93:         'mardi' => 2,
 94:         'mercredi' => 3,
 95:         'jeudi' => 4,
 96:         'vendredi' => 5,
 97:         'samedi' => 6,
 98:         'dimanche' => 7,
 99:         // German
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:         // Italian
109:         'lunedì' => 1,
110:         'martedì' => 2,
111:         'mercoledì' => 3,
112:         'giovedì' => 4,
113:         'venerdì' => 5,
114:         'sabato' => 6,
115:         'domenica' => 7,
116:         // Spanish
117:         'lunes' => 1,
118:         'martes' => 2,
119:         'miércoles' => 3,
120:         'jueves' => 4,
121:         'viernes' => 5,
122:         'sábado' => 6,
123:         'domingo' => 7,
124:         // Finnish
125:         'maanantai' => 1,
126:         'tiistai' => 2,
127:         'keskiviikko' => 3,
128:         'torstai' => 4,
129:         'perjantai' => 5,
130:         'lauantai' => 6,
131:         'sunnuntai' => 7,
132:         // Hungarian
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:         // Greek
141:         'Δευ' => 1,
142:         'Τρι' => 2,
143:         'Τετ' => 3,
144:         'Πεμ' => 4,
145:         'Παρ' => 5,
146:         'Σαβ' => 6,
147:         'Κυρ' => 7,
148:     );
149: 
150:     /**
151:      * List of months, calendar month name => calendar month number
152:      *
153:      * @access protected
154:      * @var array
155:      */
156:     var $month = array(
157:         // English
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:         // No long form of May
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:         // Dutch
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:         // French
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:         // German
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:         // Italian
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:         // Spanish
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:         // Finnish
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:         // Hungarian
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:         // Greek
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:      * List of timezones, abbreviation => offset from UTC
297:      *
298:      * @access protected
299:      * @var array
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:      * Cached PCRE for SimplePie_Parse_Date::$day
505:      *
506:      * @access protected
507:      * @var string
508:      */
509:     var $day_pcre;
510: 
511:     /**
512:      * Cached PCRE for SimplePie_Parse_Date::$month
513:      *
514:      * @access protected
515:      * @var string
516:      */
517:     var $month_pcre;
518: 
519:     /**
520:      * Array of user-added callback methods
521:      *
522:      * @access private
523:      * @var array
524:      */
525:     var $built_in = array();
526: 
527:     /**
528:      * Array of user-added callback methods
529:      *
530:      * @access private
531:      * @var array
532:      */
533:     var $user = array();
534: 
535:     /**
536:      * Create new SimplePie_Parse_Date object, and set self::day_pcre,
537:      * self::month_pcre, and self::built_in
538:      *
539:      * @access private
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:      * Get the object
568:      *
569:      * @access public
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:      * Parse a date
583:      *
584:      * @final
585:      * @access public
586:      * @param string $date Date to parse
587:      * @return int Timestamp corresponding to date string, or false on failure
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:      * Add a callback method to parse a date
612:      *
613:      * @final
614:      * @access public
615:      * @param callback $callback
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:      * Parse a superset of W3C-DTF (allows hyphens and colons to be omitted, as
631:      * well as allowing any of upper or lower case "T", horizontal tabs, or
632:      * spaces to be used as the time seperator (including more than one))
633:      *
634:      * @access protected
635:      * @return int Timestamp
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:             Capturing subpatterns:
652:             1: Year
653:             2: Month
654:             3: Day
655:             4: Hour
656:             5: Minute
657:             6: Second
658:             7: Decimal fraction of a second
659:             8: Zulu
660:             9: Timezone ±
661:             10: Timezone hours
662:             11: Timezone minutes
663:             */
664: 
665:             // Fill in empty matches
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:             // Numeric timezone
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:             // Convert the number of seconds to an integer, taking decimals into account
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:      * Remove RFC822 comments
704:      *
705:      * @access protected
706:      * @param string $data Data to strip comments from
707:      * @return string Comment stripped string
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:      * Parse RFC2822's date format
765:      *
766:      * @access protected
767:      * @return int Timestamp
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:             Capturing subpatterns:
791:             1: Day name
792:             2: Day
793:             3: Month
794:             4: Year
795:             5: Hour
796:             6: Minute
797:             7: Second
798:             8: Timezone ±
799:             9: Timezone hours
800:             10: Timezone minutes
801:             11: Alphabetic timezone
802:             */
803: 
804:             // Find the month number
805:             $month = $this->month[strtolower($match[3])];
806: 
807:             // Numeric timezone
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:             // Character timezone
818:             elseif (isset($this->timezone[strtoupper($match[11])]))
819:             {
820:                 $timezone = $this->timezone[strtoupper($match[11])];
821:             }
822:             // Assume everything else to be -0000
823:             else
824:             {
825:                 $timezone = 0;
826:             }
827: 
828:             // Deal with 2/3 digit years
829:             if ($match[4] < 50)
830:             {
831:                 $match[4] += 2000;
832:             }
833:             elseif ($match[4] < 1000)
834:             {
835:                 $match[4] += 1900;
836:             }
837: 
838:             // Second is optional, if it is empty set it to zero
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:      * Parse RFC850's date format
858:      *
859:      * @access protected
860:      * @return int Timestamp
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:             Capturing subpatterns:
879:             1: Day name
880:             2: Day
881:             3: Month
882:             4: Year
883:             5: Hour
884:             6: Minute
885:             7: Second
886:             8: Timezone
887:             */
888: 
889:             // Month
890:             $month = $this->month[strtolower($match[3])];
891: 
892:             // Character timezone
893:             if (isset($this->timezone[strtoupper($match[8])]))
894:             {
895:                 $timezone = $this->timezone[strtoupper($match[8])];
896:             }
897:             // Assume everything else to be -0000
898:             else
899:             {
900:                 $timezone = 0;
901:             }
902: 
903:             // Deal with 2 digit year
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:      * Parse C99's asctime()'s date format
923:      *
924:      * @access protected
925:      * @return int Timestamp
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:             Capturing subpatterns:
945:             1: Day name
946:             2: Month
947:             3: Day
948:             4: Hour
949:             5: Minute
950:             6: Second
951:             7: Year
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:      * Parse dates using strtotime()
965:      *
966:      * @access protected
967:      * @return int Timestamp
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: 
SimplePie Documentation API documentation generated by ApiGen 2.4.0