Skip to content

Commit

Permalink
webmention receipt: accept more complex mf2 combinations
Browse files Browse the repository at this point in the history
accept "u-in-reply-to h-cite" in addition to "u-in-reply-to" by
checking each property value to see if it is a complex value, and
extracting the "url" property if it is.

should fix idno#701
  • Loading branch information
kylewm committed Jan 18, 2015
1 parent 204c887 commit 27a8b7f
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions Idno/Common/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -1383,6 +1383,27 @@ function getDisplayURL()
return $this->getURL();
}

/**
* Many properties in mf2 can have either a simple string value or a complex
* object value, "u-in-reply-to h-cite" is a common example. This function
* takes a possibly mixed array, and returns an array of only strings.
*
* @return array
*/
static function getStringUrls($arr)
{
$result = [];
foreach($arr as $value) {
if (is_string($value)) {
$result[] = $value;
} else if (is_array($value) && !empty($value['properties']) && !empty($value['properties']['url'])) {
foreach($value['properties']['url'] as $url) {
$result[] = $url;
}
}
}
}

/**
* Add webmentions as annotations based on Microformats 2 data
*
Expand Down Expand Up @@ -1616,17 +1637,17 @@ function addWebmentionItem($item, $mentions, $source, $target, $title = '')
$mention['url'] = $item['properties']['url'];
}
if (!empty($item['properties']['in-reply-to']) && is_array($item['properties']['in-reply-to'])) {
if (in_array($target, $item['properties']['in-reply-to'])) {
if (in_array($target, getStringUrls($item['properties']['in-reply-to']))) {
$mention['type'] = 'reply';
}
}
if (!empty($item['properties']['like']) && is_array($item['properties']['like'])) {
if (in_array($target, $item['properties']['like'])) {
if (in_array($target, getStringUrls($item['properties']['like']))) {
$mention['type'] = 'like';
}
}
if (!empty($item['properties']['like-of']) && is_array($item['properties']['like-of'])) {
if (in_array($target, $item['properties']['like-of'])) {
if (in_array($target, getStringUrls($item['properties']['like-of']))) {
$mention['type'] = 'like';
}
}
Expand All @@ -1636,7 +1657,7 @@ function addWebmentionItem($item, $mentions, $source, $target, $title = '')
}
foreach (array('share', 'repost', 'repost-of') as $verb) {
if (!empty($item['properties'][$verb]) && is_array($item['properties'][$verb])) {
if (in_array($target, $item['properties'][$verb])) {
if (in_array($target, getStringUrls($item['properties'][$verb]))) {
$mention['type'] = 'share';
}
}
Expand Down Expand Up @@ -1939,4 +1960,3 @@ function getAttributes()
}

}

0 comments on commit 27a8b7f

Please sign in to comment.