function linkback_get_source($source, $target) {
// Check if we are pinging ourselves and ignore
$localprefix = common_config('site', 'server') . '/' . common_config('site', 'path');
- if(linkback_lenient_target_match($source, $localprefix)) {
+ if(linkback_lenient_target_match($source, $localprefix) === 0) {
common_debug('Ignoring self ping from ' . $source . ' to ' . $target);
return NULL;
}
$body = htmlspecialchars_decode($response->getBody());
// We're slightly more lenient in our link detection than the spec requires
- if(!linkback_lenient_target_match($body, $target)) {
+ if(linkback_lenient_target_match($body, $target) === FALSE) {
return NULL;
}
}
if(!$user) {
preg_match('/\/([^\/\?#]+)(?:#.*)?$/', $response->getEffectiveUrl(), $match);
- if(linkback_lenient_target_match(common_profile_url($match[1]), $response->getEffectiveUrl())) {
+ if(linkback_lenient_target_match(common_profile_url($match[1]), $response->getEffectiveUrl()) !== FALSE) {
$user = User::getKV('nickname', $match[1]);
}
}
function linkback_is_contained_in($entry, $target) {
foreach ((array)$entry['properties'] as $key => $values) {
- if(count(array_filter($values, function($x) use ($target) { return linkback_lenient_target_match($x, $target); })) > 0) {
+ if(count(array_filter($values, function($x) use ($target) { return linkback_lenient_target_match($x, $target) !== FALSE; })) > 0) {
return $entry['properties'];
}
if(isset($obj['type']) && array_intersect(array('h-cite', 'h-entry'), $obj['type']) &&
isset($obj['properties']) && isset($obj['properties']['url']) &&
count(array_filter($obj['properties']['url'],
- function($x) use ($target) { return linkback_lenient_target_match($x, $target); })) > 0
+ function($x) use ($target) { return linkback_lenient_target_match($x, $target) !== FALSE; })) > 0
) {
return $entry['properties'];
}
if($mf2['rels'] && $mf2['rels']['in-reply-to']) {
foreach($mf2['rels']['in-reply-to'] as $url) {
- if(linkback_lenient_target_match($url, $target)) {
+ if(linkback_lenient_target_match($url, $target) !== FALSE) {
return 'reply';
}
}
);
foreach((array)$entry as $key => $values) {
- if(count(array_filter($values, function($x) use ($target) { return linkback_lenient_target_match($x, $target); })) > 0) {
+ if(count(array_filter($values, function($x) use ($target) { return linkback_lenient_target_match($x, $target) != FALSE; })) > 0) {
if($classes[$key]) { return $classes[$key]; }
}
if(isset($obj['type']) && array_intersect(array('h-cite', 'h-entry'), $obj['type']) &&
isset($obj['properties']) && isset($obj['properties']['url']) &&
count(array_filter($obj['properties']['url'],
- function($x) use ($target) { return linkback_lenient_target_match($x, $target); })) > 0
+ function($x) use ($target) { return linkback_lenient_target_match($x, $target) != FALSE; })) > 0
) {
if($classes[$key]) { return $classes[$key]; }
}
if (isset($entry['published']) || isset($entry['updated'])) {
$options['created'] = isset($entry['published'])
- ? common_sql_date($entry['published'][0])
- : common_sql_date($entry['updated'][0]);
+ ? common_sql_date(strtotime($entry['published'][0]))
+ : common_sql_date(strtotime($entry['updated'][0]));
}
if (isset($entry['photo']) && common_valid_http_url($entry['photo'])) {
return array($content, $options);
}
+function linkback_avatar($profile, $url) {
+ // Ripped from OStatus plugin for now
+ $temp_filename = tempnam(sys_get_temp_dir(), 'linback_avatar');
+ try {
+ $imgData = HTTPClient::quickGet($url);
+ // Make sure it's at least an image file. ImageFile can do the rest.
+ if (false === getimagesizefromstring($imgData)) {
+ return false;
+ }
+ file_put_contents($temp_filename, $imgData);
+ unset($imgData); // No need to carry this in memory.
+
+ $imagefile = new ImageFile(null, $temp_filename);
+ $filename = Avatar::filename($profile->id,
+ image_type_to_extension($imagefile->type),
+ null,
+ common_timestamp());
+ rename($temp_filename, Avatar::path($filename));
+ } catch (Exception $e) {
+ unlink($temp_filename);
+ throw $e;
+ }
+ // @todo FIXME: Hardcoded chmod is lame, but seems to be necessary to
+ // keep from accidentally saving images from command-line (queues)
+ // that can't be read from web server, which causes hard-to-notice
+ // problems later on:
+ //
+ // http://status.net/open-source/issues/2663
+ chmod(Avatar::path($filename), 0644);
+
+ $profile->setOriginal($filename);
+}
+
function linkback_profile($entry, $mf2, $response, $target) {
- if(isset($entry['properties']['author']) && isset($entry['properties']['author'][0]['properties'])) {
- $author = $entry['properties']['author'][0]['properties'];
+ if(isset($entry['author']) && isset($entry['author'][0]['properties'])) {
+ $author = $entry['author'][0]['properties'];
} else {
$author = linkback_hcard($mf2, $response->getEffectiveUrl());
}
$profile->nickname = isset($author['nickname']) ? $author['nickname'][0] : str_replace(' ', '', $author['name'][0]);
$profile->created = common_sql_now();
$profile->insert();
+
+ if($author['photo'] && $author['photo'][0]) {
+ linkback_avatar($profile, $author['photo'][0]);
+ }
}
return array($profile, $author);
try { $dupe->saveKnownTags($options['tags']); } catch (ServerException $ex) {}
try { $dupe->saveKnownUrls($options['urls']); } catch (ServerException $ex) {}
- if($options['reply_to']) { $dupe->reply_to = $options['reply_to']; }
- if($options['repeat_of']) { $dupe->repeat_of = $options['repeat_of']; }
- if($dupe->reply_to != $orig->reply_to || $dupe->repeat_of != $orig->repeat_of) {
- $parent = Notice::getKV('id', $dupe->repost_of ? $dupe->repost_of : $dupe->reply_to);
+ if (isset($options['reply_to'])) {
+ $dupe->reply_to = $options['reply_to'];
+ }
+ if (isset($options['repeat_of'])) {
+ $dupe->repeat_of = $options['repeat_of'];
+ }
+ if ($dupe->reply_to != $orig->reply_to || $dupe->repeat_of != $orig->repeat_of) {
+ $parent = Notice::getKV('id', $dupe->repeat_of ?: $dupe->reply_to);
if($parent instanceof Notice) {
// If we changed the reply_to or repeat_of we might live in a new conversation now
$dupe->conversation = $parent->conversation;