@@ -920,9 +920,10 @@ private function removeTags(\DOMElement &$e, $tagName) {
920920 *
921921 * @param DOMElement $e The element to parse
922922 * @param bool $is_backcompat Whether using backcompat parsing or not
923+ * @param bool $has_nested_mf Whether this microformat has a nested microformat
923924 * @return array A representation of the values contained within microformat $e
924925 */
925- public function parseH (\DOMElement $ e , $ is_backcompat = false ) {
926+ public function parseH (\DOMElement $ e , $ is_backcompat = false , $ has_nested_mf = false ) {
926927 // If it’s already been parsed (e.g. is a child mf), skip
927928 if ($ this ->parsed ->contains ($ e )) {
928929 return null ;
@@ -958,6 +959,7 @@ public function parseH(\DOMElement $e, $is_backcompat = false) {
958959 continue ;
959960 }
960961
962+ $ prefixes [] = 'p- ' ;
961963 $ pValue = $ this ->parseP ($ p );
962964
963965 // Add the value to the array for it’s p- properties
@@ -982,6 +984,7 @@ public function parseH(\DOMElement $e, $is_backcompat = false) {
982984 continue ;
983985 }
984986
987+ $ prefixes [] = 'u- ' ;
985988 $ uValue = $ this ->parseU ($ u );
986989
987990 // Add the value to the array for it’s property types
@@ -1006,6 +1009,7 @@ public function parseH(\DOMElement $e, $is_backcompat = false) {
10061009 continue ;
10071010 }
10081011
1012+ $ prefixes [] = 'dt- ' ;
10091013 $ dtValue = $ this ->parseDT ($ dt , $ dates , $ impliedTimezone );
10101014
10111015 if ($ dtValue ) {
@@ -1040,6 +1044,7 @@ public function parseH(\DOMElement $e, $is_backcompat = false) {
10401044 continue ;
10411045 }
10421046
1047+ $ prefixes [] = 'e- ' ;
10431048 $ eValue = $ this ->parseE ($ em );
10441049
10451050 if ($ eValue ) {
@@ -1052,9 +1057,10 @@ public function parseH(\DOMElement $e, $is_backcompat = false) {
10521057 $ this ->elementPrefixParsed ($ em , 'e ' );
10531058 }
10541059
1055- // Implied Properties
1056- // Check for p-name
1057- if (!array_key_exists ('name ' , $ return ) && !$ is_backcompat ) {
1060+ // Imply 'name' only under specific conditions
1061+ $ imply_name = (!$ has_nested_mf && !array_key_exists ('name ' , $ return ) && !$ is_backcompat && !in_array ('p- ' , $ prefixes ) && !in_array ('e- ' , $ prefixes ));
1062+
1063+ if ($ imply_name ) {
10581064 try {
10591065 // Look for img @alt
10601066 if (($ e ->tagName == 'img ' or $ e ->tagName == 'area ' ) and $ e ->getAttribute ('alt ' ) != '' ) {
@@ -1337,7 +1343,7 @@ public function parse($convertClassic = true, DOMElement $context = null) {
13371343 * Parse microformats recursively
13381344 * Keeps track of whether inside a backcompat root or not
13391345 * @param DOMElement $context: node to start with
1340- * @param int $depth: recusion depth
1346+ * @param int $depth: recursion depth
13411347 * @return array
13421348 */
13431349 public function parse_recursive (DOMElement $ context = null , $ depth = 0 ) {
@@ -1380,8 +1386,11 @@ public function parse_recursive(DOMElement $context = null, $depth = 0) {
13801386
13811387 }
13821388
1389+ // set bool flag for nested mf
1390+ $ has_nested_mf = ($ children || $ merge_properties );
1391+
13831392 // parse for root mf
1384- $ result = $ this ->parseH ($ node , $ is_backcompat );
1393+ $ result = $ this ->parseH ($ node , $ is_backcompat, $ has_nested_mf );
13851394
13861395 // merge nested mf properties
13871396 if ( $ merge_properties && isset ($ result ['properties ' ]) ) {
@@ -1402,7 +1411,7 @@ public function parse_recursive(DOMElement $context = null, $depth = 0) {
14021411 // Note: handling microformat nesting under multiple conflicting prefixes is not currently specified by the mf2 parsing spec.
14031412 $ prefixSpecificResult = $ result ;
14041413 if (in_array ('p- ' , $ prefixes )) {
1405- $ prefixSpecificResult ['value ' ] = $ prefixSpecificResult ['properties ' ]['name ' ][0 ];
1414+ $ prefixSpecificResult ['value ' ] = ( empty ( $ prefixSpecificResult [ ' properties ' ][ ' name ' ][ 0 ])) ? '' : $ prefixSpecificResult ['properties ' ]['name ' ][0 ];
14061415 } elseif (in_array ('e- ' , $ prefixes )) {
14071416 $ eParsedResult = $ this ->parseE ($ node );
14081417 $ prefixSpecificResult ['html ' ] = $ eParsedResult ['html ' ];
0 commit comments