register_hook('enotify', 'addon/fbpost/fbpost.php', 'fbpost_enotify');
register_hook('queue_predeliver', 'addon/fbpost/fbpost.php', 'fbpost_queue_hook');
register_hook('cron', 'addon/fbpost/fbpost.php', 'fbpost_cron');
+ register_hook('prepare_body', 'addon/fbpost/fbpost.php', 'fbpost_prepare_body');
}
unregister_hook('enotify', 'addon/fbpost/fbpost.php', 'fbpost_enotify');
unregister_hook('queue_predeliver', 'addon/fbpost/fbpost.php', 'fbpost_queue_hook');
unregister_hook('cron', 'addon/fbpost/fbpost.php', 'fbpost_cron');
+ unregister_hook('prepare_body', 'addon/fbpost/fbpost.php', 'fbpost_prepare_body');
}
if ($toplevel) {
require_once("include/plaintext.php");
- $msgarr = plaintext($a, $b, 0, false);
+ $msgarr = plaintext($a, $b, 0, false, 9);
$msg = $msgarr["text"];
$link = $msgarr["url"];
- $image = $msgarr["image"];
$linkname = $msgarr["title"];
+ if ($msgarr["type"] != "video")
+ $image = $msgarr["image"];
+
// Fallback - if message is empty
if(!strlen($msg))
$msg = $linkname;
}
}
+function fbpost_prepare_body(&$a,&$b) {
+ if ($b["item"]["network"] != NETWORK_FACEBOOK)
+ return;
+
+ if ($b["preview"]) {
+ $msg = $b["item"]["body"];
+
+ require_once("include/bbcode.php");
+ require_once("include/html2plain.php");
+ $msg = bb_CleanPictureLinks($msg);
+ $msg = bbcode($msg, false, false, 2, true);
+ $msg = trim(html2plain($msg, 0));
+
+ $b['html'] = nl2br(htmlspecialchars($msg));
+ }
+}
+
function fbpost_cron($a,$b) {
$last = get_config('facebook','last_poll');
$oembed_data = oembed_fetch_url($item->link);
$type = $oembed_data->type;
$content = "[bookmark=".$item->link."]".$item->name."[/bookmark]";
+
+ // If a link is not only attached but also added in the body, look if it can be removed in the body.
+ $removedlink = trim(str_replace($item->link, "", $_REQUEST["body"]));
+
+ if (($removedlink == "") OR strstr($_REQUEST["body"], $removedlink))
+ $_REQUEST["body"] = $removedlink;
+
} elseif (isset($item->name))
$content .= "[b]".$item->name."[/b]";
$type = $item->type;
- if(isset($item->picture) && isset($item->link))
- $content .= "\n".'[url='.$item->link.'][img]'.fpost_cleanpicture($item->picture).'[/img][/url]';
+ if (isset($item->picture))
+ $picture = $item->picture;
+
+ if (($type == "photo") AND isset($item->object_id)) {
+ logger('fbpost_fetchwall: fetching fbid '.$item->object_id, LOGGER_DEBUG);
+ $url = "https://graph.facebook.com/".$item->object_id."?access_token=".$access_token;
+ $feed = fetch_url($url);
+ $data = json_decode($feed);
+ if (isset($data->images)) {
+ $picture = $data->images[0]->source;
+ logger('fbpost_fetchwall: got fbid image '.$preview, LOGGER_DEBUG);
+ }
+ }
+
+ if(($picture != "") && isset($item->link))
+ $content .= "\n".'[url='.$item->link.'][img]'.$picture.'[/img][/url]';
else {
- if (isset($item->picture))
- $content .= "\n".'[img]'.fpost_cleanpicture($item->picture).'[/img]';
+ if ($picture != "")
+ $content .= "\n".'[img]'.$picture.'[/img]';
// if just a link, it may be a wall photo - check
if(isset($item->link))
$content .= fbpost_get_photo($uid,$item->link);
$x = fetch_url('https://graph.facebook.com/'.$photo_id.'?access_token='.$access_token);
$j = json_decode($x);
if($j->picture)
- return "\n\n".'[url='.$link.'][img]'.fpost_cleanpicture($j->picture).'[/img][/url]';
+ return "\n\n".'[url='.$link.'][img]'.$j->picture.'[/img][/url]';
return "";
}