@@ -920,9 +920,10 @@ private function removeTags(\DOMElement &$e, $tagName) {
920
920
*
921
921
* @param DOMElement $e The element to parse
922
922
* @param bool $is_backcompat Whether using backcompat parsing or not
923
+ * @param bool $has_nested_mf Whether this microformat has a nested microformat
923
924
* @return array A representation of the values contained within microformat $e
924
925
*/
925
- public function parseH (\DOMElement $ e , $ is_backcompat = false ) {
926
+ public function parseH (\DOMElement $ e , $ is_backcompat = false , $ has_nested_mf = false ) {
926
927
// If it’s already been parsed (e.g. is a child mf), skip
927
928
if ($ this ->parsed ->contains ($ e )) {
928
929
return null ;
@@ -958,6 +959,7 @@ public function parseH(\DOMElement $e, $is_backcompat = false) {
958
959
continue ;
959
960
}
960
961
962
+ $ prefixes [] = 'p- ' ;
961
963
$ pValue = $ this ->parseP ($ p );
962
964
963
965
// Add the value to the array for it’s p- properties
@@ -982,6 +984,7 @@ public function parseH(\DOMElement $e, $is_backcompat = false) {
982
984
continue ;
983
985
}
984
986
987
+ $ prefixes [] = 'u- ' ;
985
988
$ uValue = $ this ->parseU ($ u );
986
989
987
990
// Add the value to the array for it’s property types
@@ -1006,6 +1009,7 @@ public function parseH(\DOMElement $e, $is_backcompat = false) {
1006
1009
continue ;
1007
1010
}
1008
1011
1012
+ $ prefixes [] = 'dt- ' ;
1009
1013
$ dtValue = $ this ->parseDT ($ dt , $ dates , $ impliedTimezone );
1010
1014
1011
1015
if ($ dtValue ) {
@@ -1040,6 +1044,7 @@ public function parseH(\DOMElement $e, $is_backcompat = false) {
1040
1044
continue ;
1041
1045
}
1042
1046
1047
+ $ prefixes [] = 'e- ' ;
1043
1048
$ eValue = $ this ->parseE ($ em );
1044
1049
1045
1050
if ($ eValue ) {
@@ -1052,9 +1057,10 @@ public function parseH(\DOMElement $e, $is_backcompat = false) {
1052
1057
$ this ->elementPrefixParsed ($ em , 'e ' );
1053
1058
}
1054
1059
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 ) {
1058
1064
try {
1059
1065
// Look for img @alt
1060
1066
if (($ e ->tagName == 'img ' or $ e ->tagName == 'area ' ) and $ e ->getAttribute ('alt ' ) != '' ) {
@@ -1337,7 +1343,7 @@ public function parse($convertClassic = true, DOMElement $context = null) {
1337
1343
* Parse microformats recursively
1338
1344
* Keeps track of whether inside a backcompat root or not
1339
1345
* @param DOMElement $context: node to start with
1340
- * @param int $depth: recusion depth
1346
+ * @param int $depth: recursion depth
1341
1347
* @return array
1342
1348
*/
1343
1349
public function parse_recursive (DOMElement $ context = null , $ depth = 0 ) {
@@ -1380,8 +1386,11 @@ public function parse_recursive(DOMElement $context = null, $depth = 0) {
1380
1386
1381
1387
}
1382
1388
1389
+ // set bool flag for nested mf
1390
+ $ has_nested_mf = ($ children || $ merge_properties );
1391
+
1383
1392
// parse for root mf
1384
- $ result = $ this ->parseH ($ node , $ is_backcompat );
1393
+ $ result = $ this ->parseH ($ node , $ is_backcompat, $ has_nested_mf );
1385
1394
1386
1395
// merge nested mf properties
1387
1396
if ( $ merge_properties && isset ($ result ['properties ' ]) ) {
@@ -1402,7 +1411,7 @@ public function parse_recursive(DOMElement $context = null, $depth = 0) {
1402
1411
// Note: handling microformat nesting under multiple conflicting prefixes is not currently specified by the mf2 parsing spec.
1403
1412
$ prefixSpecificResult = $ result ;
1404
1413
if (in_array ('p- ' , $ prefixes )) {
1405
- $ prefixSpecificResult ['value ' ] = $ prefixSpecificResult ['properties ' ]['name ' ][0 ];
1414
+ $ prefixSpecificResult ['value ' ] = ( empty ( $ prefixSpecificResult [ ' properties ' ][ ' name ' ][ 0 ])) ? '' : $ prefixSpecificResult ['properties ' ]['name ' ][0 ];
1406
1415
} elseif (in_array ('e- ' , $ prefixes )) {
1407
1416
$ eParsedResult = $ this ->parseE ($ node );
1408
1417
$ prefixSpecificResult ['html ' ] = $ eParsedResult ['html ' ];
0 commit comments