@ -2,7 +2,6 @@
namespace p3k\XRay\Formats ;
namespace p3k\XRay\Formats ;
use HTMLPurifier , HTMLPurifier_Config ;
use HTMLPurifier , HTMLPurifier_Config ;
use Parse ;
class Mf2 {
class Mf2 {
@ -14,31 +13,31 @@ class Mf2 {
if ( count ( $mf2 [ 'items' ]) == 1 ) {
if ( count ( $mf2 [ 'items' ]) == 1 ) {
$item = $mf2 [ 'items' ][ 0 ];
$item = $mf2 [ 'items' ][ 0 ];
if ( in_array ( 'h-entry' , $item [ 'type' ]) || in_array ( 'h-cite' , $item [ 'type' ])) {
if ( in_array ( 'h-entry' , $item [ 'type' ]) || in_array ( 'h-cite' , $item [ 'type' ])) {
Parse :: debug ( " mf2:0: Recognized $url as an h-entry it is the only item on the page " );
#Parse::debug("mf2:0: Recognized $url as an h-entry it is the only item on the page");
return self :: parseAsHEntry ( $mf2 , $item , $http );
return self :: parseAsHEntry ( $mf2 , $item , $http );
}
}
if ( in_array ( 'h-event' , $item [ 'type' ])) {
if ( in_array ( 'h-event' , $item [ 'type' ])) {
Parse :: debug ( " mf2:0: Recognized $url as an h-event it is the only item on the page " );
#Parse::debug("mf2:0: Recognized $url as an h-event it is the only item on the page");
return self :: parseAsHEvent ( $mf2 , $item , $http );
return self :: parseAsHEvent ( $mf2 , $item , $http );
}
}
if ( in_array ( 'h-review' , $item [ 'type' ])) {
if ( in_array ( 'h-review' , $item [ 'type' ])) {
Parse :: debug ( " mf2:0: Recognized $url as an h-review it is the only item on the page " );
#Parse::debug("mf2:0: Recognized $url as an h-review it is the only item on the page");
return self :: parseAsHReview ( $mf2 , $item , $http );
return self :: parseAsHReview ( $mf2 , $item , $http );
}
}
if ( in_array ( 'h-recipe' , $item [ 'type' ])) {
if ( in_array ( 'h-recipe' , $item [ 'type' ])) {
Parse :: debug ( " mf2:0: Recognized $url as an h-recipe it is the only item on the page " );
#Parse::debug("mf2:0: Recognized $url as an h-recipe it is the only item on the page");
return self :: parseAsHRecipe ( $mf2 , $item , $http );
return self :: parseAsHRecipe ( $mf2 , $item , $http );
}
}
if ( in_array ( 'h-product' , $item [ 'type' ])) {
if ( in_array ( 'h-product' , $item [ 'type' ])) {
Parse :: debug ( " mf2:0: Recognized $url as an h-product it is the only item on the page " );
#Parse::debug("mf2:0: Recognized $url as an h-product it is the only item on the page");
return self :: parseAsHProduct ( $mf2 , $item , $http );
return self :: parseAsHProduct ( $mf2 , $item , $http );
}
}
if ( in_array ( 'h-feed' , $item [ 'type' ])) {
if ( in_array ( 'h-feed' , $item [ 'type' ])) {
Parse :: debug ( " mf2:0: Recognized $url as an h-feed because it is the only item on the page ");
#Parse::debug("mf2:0: Recognized $url as an h-feed because it is the only item on the page");
return self :: parseAsHFeed ( $mf2 , $http );
return self :: parseAsHFeed ( $mf2 , $http );
}
}
if ( in_array ( 'h-card' , $item [ 'type' ])) {
if ( in_array ( 'h-card' , $item [ 'type' ])) {
Parse :: debug ( " mf2:0: Recognized $url as an h-card it is the only item on the page " );
#Parse::debug("mf2:0: Recognized $url as an h-card it is the only item on the page");
return self :: parseAsHCard ( $item , $http , $url );
return self :: parseAsHCard ( $item , $http , $url );
}
}
}
}
@ -50,7 +49,7 @@ class Mf2 {
$urls = $item [ 'properties' ][ 'url' ];
$urls = $item [ 'properties' ][ 'url' ];
$urls = array_map ( '\p3k\XRay\normalize_url' , $urls );
$urls = array_map ( '\p3k\XRay\normalize_url' , $urls );
if ( in_array ( $url , $urls )) {
if ( in_array ( $url , $urls )) {
Parse :: debug ( " mf2:1: Recognized $url as a permalink because an object on the page matched the URL of the request ");
#Parse::debug("mf2:1: Recognized $url as a permalink because an object on the page matched the URL of the request");
if ( in_array ( 'h-card' , $item [ 'type' ])) {
if ( in_array ( 'h-card' , $item [ 'type' ])) {
return self :: parseAsHCard ( $item , $http , $url );
return self :: parseAsHCard ( $item , $http , $url );
} elseif ( in_array ( 'h-entry' , $item [ 'type' ]) || in_array ( 'h-cite' , $item [ 'type' ])) {
} elseif ( in_array ( 'h-entry' , $item [ 'type' ]) || in_array ( 'h-cite' , $item [ 'type' ])) {
@ -64,7 +63,7 @@ class Mf2 {
} elseif ( in_array ( 'h-product' , $item [ 'type' ])) {
} elseif ( in_array ( 'h-product' , $item [ 'type' ])) {
return self :: parseAsHProduct ( $mf2 , $item , $http );
return self :: parseAsHProduct ( $mf2 , $item , $http );
} else {
} else {
Parse :: debug ( 'This object was not a recognized type.' );
#Parse::debug('This object was not a recognized type.');
return false ;
return false ;
}
}
}
}
@ -106,7 +105,7 @@ class Mf2 {
if ( count ( array_filter ( $mf2 [ 'items' ], function ( $item ){
if ( count ( array_filter ( $mf2 [ 'items' ], function ( $item ){
return in_array ( 'h-entry' , $item [ 'type' ]);
return in_array ( 'h-entry' , $item [ 'type' ]);
})) > 1 ) {
})) > 1 ) {
Parse :: debug ( " mf2:2: Recognized $url as an h-feed because there are more than one object on the page ");
#Parse::debug("mf2:2: Recognized $url as an h-feed because there are more than one object on the page");
return self :: parseAsHFeed ( $mf2 , $http );
return self :: parseAsHFeed ( $mf2 , $http );
}
}
}
}
@ -114,7 +113,7 @@ class Mf2 {
// If the first item is an h-feed, parse as a feed
// If the first item is an h-feed, parse as a feed
$first = $mf2 [ 'items' ][ 0 ];
$first = $mf2 [ 'items' ][ 0 ];
if ( in_array ( 'h-feed' , $first [ 'type' ])) {
if ( in_array ( 'h-feed' , $first [ 'type' ])) {
Parse :: debug ( " mf2:3: Recognized $url as an h-feed because the first item is an h-feed " );
#Parse::debug("mf2:3: Recognized $url as an h-feed because the first item is an h-feed");
return self :: parseAsHFeed ( $mf2 , $http );
return self :: parseAsHFeed ( $mf2 , $http );
}
}
@ -122,24 +121,24 @@ class Mf2 {
foreach ( $mf2 [ 'items' ] as $item ) {
foreach ( $mf2 [ 'items' ] as $item ) {
// Otherwise check for a recognized h-entr* object
// Otherwise check for a recognized h-entr* object
if ( in_array ( 'h-entry' , $item [ 'type' ]) || in_array ( 'h-cite' , $item [ 'type' ])) {
if ( in_array ( 'h-entry' , $item [ 'type' ]) || in_array ( 'h-cite' , $item [ 'type' ])) {
Parse :: debug ( " mf2:6: $url is falling back to the first h-entry on the page " );
#Parse::debug("mf2:6: $url is falling back to the first h-entry on the page");
return self :: parseAsHEntry ( $mf2 , $item , $http );
return self :: parseAsHEntry ( $mf2 , $item , $http );
} elseif ( in_array ( 'h-event' , $item [ 'type' ])) {
} elseif ( in_array ( 'h-event' , $item [ 'type' ])) {
Parse :: debug ( " mf2:6: $url is falling back to the first h-event on the page " );
#Parse::debug("mf2:6: $url is falling back to the first h-event on the page");
return self :: parseAsHEvent ( $mf2 , $item , $http );
return self :: parseAsHEvent ( $mf2 , $item , $http );
} elseif ( in_array ( 'h-review' , $item [ 'type' ])) {
} elseif ( in_array ( 'h-review' , $item [ 'type' ])) {
Parse :: debug ( " mf2:6: $url is falling back to the first h-review on the page ");
#Parse::debug("mf2:6: $url is falling back to the first h-review on the page");
return self :: parseAsHReview ( $mf2 , $item , $http );
return self :: parseAsHReview ( $mf2 , $item , $http );
} elseif ( in_array ( 'h-recipe' , $item [ 'type' ])) {
} elseif ( in_array ( 'h-recipe' , $item [ 'type' ])) {
Parse :: debug ( " mf2:6: $url is falling back to the first h-recipe on the page ");
#Parse::debug("mf2:6: $url is falling back to the first h-recipe on the page");
return self :: parseAsHReview ( $mf2 , $item , $http );
return self :: parseAsHReview ( $mf2 , $item , $http );
} elseif ( in_array ( 'h-product' , $item [ 'type' ])) {
} elseif ( in_array ( 'h-product' , $item [ 'type' ])) {
Parse :: debug ( " mf2:6: $url is falling back to the first h-product on the page ");
#Parse::debug("mf2:6: $url is falling back to the first h-product on the page");
return self :: parseAsHProduct ( $mf2 , $item , $http );
return self :: parseAsHProduct ( $mf2 , $item , $http );
}
}
}
}
Parse :: debug ( " mf2:E: No object at $url was recognized " );
#Parse::debug("mf2:E: No object at $url was recognized");
return false ;
return false ;
}
}
@ -311,7 +310,7 @@ class Mf2 {
];
];
if ( count ( $refs )) {
if ( count ( $refs )) {
$response [ 'refs' ] = $refs ;
$response [ 'data' ][ ' refs' ] = $refs ;
}
}
return $response ;
return $response ;
@ -345,7 +344,7 @@ class Mf2 {
];
];
if ( count ( $refs )) {
if ( count ( $refs )) {
$response [ 'refs' ] = $refs ;
$response [ 'data' ][ ' refs' ] = $refs ;
}
}
return $response ;
return $response ;
@ -376,7 +375,7 @@ class Mf2 {
];
];
if ( count ( $refs )) {
if ( count ( $refs )) {
$response [ 'refs' ] = $refs ;
$response [ 'data' ][ ' refs' ] = $refs ;
}
}
return $response ;
return $response ;
@ -403,7 +402,7 @@ class Mf2 {
];
];
if ( count ( $refs )) {
if ( count ( $refs )) {
$response [ 'refs' ] = $refs ;
$response [ 'data' ][ ' refs' ] = $refs ;
}
}
return $response ;
return $response ;
@ -457,7 +456,7 @@ class Mf2 {
];
];
if ( count ( $refs )) {
if ( count ( $refs )) {
$response [ 'refs' ] = $refs ;
$response [ 'data' ][ ' refs' ] = $refs ;
}
}
return $response ;
return $response ;