Skip to content

Commit

Permalink
Closes idno#431 & idno#420: Profile icons in webmentions are now cach…
Browse files Browse the repository at this point in the history
…ed and served from the local server.

Refs idno#203
  • Loading branch information
mapkyca committed Sep 2, 2014
1 parent e91948d commit 93de5c7
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions Idno/Common/Entity.php
Expand Up @@ -1361,7 +1361,24 @@ function addWebmentions($source, $target, $source_content, $source_mf2)
if (!empty($item['properties'])) {
if (!empty($item['properties']['name'])) $mentions['owner']['name'] = $item['properties']['name'][0];
if (!empty($item['properties']['url'])) $mentions['owner']['url'] = $item['properties']['url'][0];
if (!empty($item['properties']['photo'])) $mentions['owner']['photo'] = $item['properties']['photo'][0];
if (!empty($item['properties']['photo'])) {
//$mentions['owner']['photo'] = $item['properties']['photo'][0];

$tmpfname = tempnam(sys_get_temp_dir(), 'webmention_avatar');
file_put_contents($tmpfname, \Idno\Core\Webservice::file_get_contents($item['properties']['photo'][0]));

$name = md5($item['properties']['url'][0]);

// TODO: Don't update the cache image for every webmention

if ($icon = \Idno\Entities\File::createThumbnailFromFile($tmpfname, $name, 300)) {
$mentions['owner']['photo'] = \Idno\Core\site()->config()->url . 'file/' . (string)$icon;
} else if ($icon = \Idno\Entities\File::createFromFile($tmpfname, $name)) {
$mentions['owner']['photo'] = \Idno\Core\site()->config()->url . 'file/' . (string)$icon;
}

unlink($tmpfname);
}
}
break;
}
Expand Down Expand Up @@ -1452,7 +1469,24 @@ function addWebmentionItem($item, $mentions, $source, $target)
if ($type == 'h-card') {
if (!empty($author['properties']['name'])) $mentions['owner']['name'] = $author['properties']['name'][0];
if (!empty($author['properties']['url'])) $mentions['owner']['url'] = $author['properties']['url'][0];
if (!empty($author['properties']['photo'])) $mentions['owner']['photo'] = $author['properties']['photo'][0];
if (!empty($author['properties']['photo'])) {
//$mentions['owner']['photo'] = $author['properties']['photo'][0];

$tmpfname = tempnam(sys_get_temp_dir(), 'webmention_avatar');
file_put_contents($tmpfname, \Idno\Core\Webservice::file_get_contents($author['properties']['photo'][0]));

$name = md5($author['properties']['url'][0]);

// TODO: Don't update the cache image for every webmention

if ($icon = \Idno\Entities\File::createThumbnailFromFile($tmpfname, $name, 300)) {
$mentions['owner']['photo'] = \Idno\Core\site()->config()->url . 'file/' . (string)$icon;
} else if ($icon = \Idno\Entities\File::createFromFile($tmpfname, $name)) {
$mentions['owner']['photo'] = \Idno\Core\site()->config()->url . 'file/' . (string)$icon;
}

unlink($tmpfname);
}
}
}
}
Expand Down

0 comments on commit 93de5c7

Please sign in to comment.