@@ -76,14 +76,27 @@ public function set_registry(SimplePie_Registry $registry)
7676
7777 public function parse (&$ data , $ encoding , $ url = '' )
7878 {
79- $ position = 0 ;
80- while ($ position = strpos ($ data , 'h-entry ' , $ position )) {
81- $ start = $ position < 200 ? 0 : $ position - 200 ;
82- $ check = substr ($ data , $ start , 400 );
83- if (preg_match ('/class="[^"]*h-entry/ ' , $ check )) {
84- return $ this ->parse_microformats ($ data , $ url );
79+ if (function_exists ('Mf2\parse ' )) {
80+ // Check for both h-feed and h-entry, as both a feed with no entries
81+ // and a list of entries without an h-feed wrapper are both valid.
82+ $ position = 0 ;
83+ while ($ position = strpos ($ data , 'h-feed ' , $ position )) {
84+ $ start = $ position < 200 ? 0 : $ position - 200 ;
85+ $ check = substr ($ data , $ start , 400 );
86+ if (preg_match ('/class="[^"]*h-feed/ ' , $ check )) {
87+ return $ this ->parse_microformats ($ data , $ url );
88+ }
89+ $ position += 7 ;
90+ }
91+ $ position = 0 ;
92+ while ($ position = strpos ($ data , 'h-entry ' , $ position )) {
93+ $ start = $ position < 200 ? 0 : $ position - 200 ;
94+ $ check = substr ($ data , $ start , 400 );
95+ if (preg_match ('/class="[^"]*h-entry/ ' , $ check )) {
96+ return $ this ->parse_microformats ($ data , $ url );
97+ }
98+ $ position += 7 ;
8599 }
86- $ position += 7 ;
87100 }
88101
89102 // Use UTF-8 if we get passed US-ASCII, as every US-ASCII character is a UTF-8 character
@@ -439,10 +452,8 @@ private function parse_hcard($data, $category = false) {
439452 }
440453
441454 private function parse_microformats (&$ data , $ url ) {
442- if (!function_exists ('Mf2\parse ' )) return false ;
443-
444455 $ feed_title = '' ;
445- $ icon = '' ;
456+ $ feed_author = NULL ;
446457 $ author_cache = array ();
447458 $ items = array ();
448459 $ entries = array ();
@@ -458,23 +469,20 @@ private function parse_microformats(&$data, $url) {
458469 if (!isset ($ mf_item ['children ' ][0 ]['type ' ])) continue ;
459470 if (in_array ('h-feed ' , $ mf_item ['children ' ][0 ]['type ' ])) {
460471 $ h_feed = $ mf_item ['children ' ][0 ];
472+ // In this case the parent of the h-feed may be an h-card, so use it as
473+ // the feed_author.
474+ if (in_array ('h-card ' , $ mf_item ['type ' ])) $ feed_author = $ mf_item ;
461475 break ;
462476 }
463477 }
464478 if (isset ($ h_feed ['children ' ])) {
465479 $ entries = $ h_feed ['children ' ];
466- // Also set the feed title and icon from the h-feed if available.
480+ // Also set the feed title and store author from the h-feed if available.
467481 if (isset ($ mf ['items ' ][0 ]['properties ' ]['name ' ][0 ])) {
468482 $ feed_title = $ mf ['items ' ][0 ]['properties ' ]['name ' ][0 ];
469483 }
470484 if (isset ($ mf ['items ' ][0 ]['properties ' ]['author ' ][0 ])) {
471- $ author = $ mf ['items ' ][0 ]['properties ' ]['author ' ][0 ];
472- if (is_array ($ author ) &&
473- isset ($ author ['type ' ]) && in_array ('h-card ' , $ author ['type ' ])) {
474- if (isset ($ author ['properties ' ]['photo ' ][0 ])) {
475- $ icon = $ author ['properties ' ]['photo ' ][0 ];
476- }
477- }
485+ $ feed_author = $ mf ['items ' ][0 ]['properties ' ]['author ' ][0 ];
478486 }
479487 }
480488 else {
@@ -501,12 +509,13 @@ private function parse_microformats(&$data, $url) {
501509 if (isset ($ title ['value ' ])) $ title = $ title ['value ' ];
502510 $ item ['title ' ] = array (array ('data ' => $ title ));
503511 }
504- if (isset ($ entry ['properties ' ]['author ' ][0 ])) {
512+ if (isset ($ entry ['properties ' ]['author ' ][0 ]) || isset ( $ feed_author ) ) {
505513 // author is a special case, it can be plain text or an h-card array.
506514 // If it's plain text it can also be a url that should be followed to
507515 // get the actual h-card.
508- $ author = $ entry ['properties ' ]['author ' ][0 ];
509- if (is_array ($ author )) {
516+ $ author = isset ($ entry ['properties ' ]['author ' ][0 ]) ?
517+ $ entry ['properties ' ]['author ' ][0 ] : $ feed_author ;
518+ if (!is_string ($ author )) {
510519 $ author = $ this ->parse_hcard ($ author );
511520 }
512521 else if (strpos ($ author , 'http ' ) === 0 ) {
@@ -574,6 +583,11 @@ private function parse_microformats(&$data, $url) {
574583 $ item ['title ' ] = array (array ('data ' => $ title ));
575584 }
576585 $ description .= $ entry ['properties ' ]['content ' ][0 ]['html ' ];
586+ if (isset ($ entry ['properties ' ]['in-reply-to ' ][0 ]['value ' ])) {
587+ $ in_reply_to = $ entry ['properties ' ]['in-reply-to ' ][0 ]['value ' ];
588+ $ description .= '<p><span class="in-reply-to"></span> ' .
589+ '<a href=" ' .$ in_reply_to .'"> ' .$ in_reply_to .'</a><p> ' ;
590+ }
577591 $ item ['description ' ] = array (array ('data ' => $ description ));
578592 }
579593 if (isset ($ entry ['properties ' ]['category ' ])) {
@@ -608,9 +622,10 @@ private function parse_microformats(&$data, $url) {
608622 // Mimic RSS data format when storing microformats.
609623 $ link = array (array ('data ' => $ url ));
610624 $ image = '' ;
611- if ($ icon !== '' ) {
612- array (array ('child ' => array ('' =>
613- array ('url ' => array (array ('data ' => $ icon ))))));
625+ if (!is_string ($ feed_author ) &&
626+ isset ($ feed_author ['properties ' ]['photo ' ][0 ])) {
627+ $ image = array (array ('child ' => array ('' => array ('url ' =>
628+ array (array ('data ' => $ feed_author ['properties ' ]['photo ' ][0 ]))))));
614629 }
615630 // Use the a name given for the h-feed, or get the title from the html.
616631 if ($ feed_title !== '' ) {
0 commit comments