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(strlen($nick))
$r = q("SELECT `uid` FROM `user` WHERE `nickname` = '%s' LIMIT 1",
- dbesc($nick)
+ dbesc($nick)
);
if(!(isset($r) && count($r)))
return;
$result = q("SELECT `installed` FROM `addon` WHERE `name` = 'fbsync' AND `installed`");
if (count($result) > 0) {
set_pconfig(local_user(),'fbsync','sync',intval($_POST['fbsync']));
- set_pconfig(local_user(),'fbsync','create_user',intval($_POST['create_user']));
+ set_pconfig(local_user(),'fbsync','create_user',intval($_POST['create_user']));
}
info( t('Settings updated.') . EOL);
$o .= '<div class="clear"></div>';
- $sync_enabled = get_pconfig(local_user(),'fbsync','sync');
+ $sync_enabled = get_pconfig(local_user(),'fbsync','sync');
$checked = (($sync_enabled) ? ' checked="checked" ' : '');
$o .= '<input type="checkbox" name="fbsync" value="1"' . $checked . '/>' . ' ' . t('Import Facebook newsfeed.') . EOL;
- $create_user = get_pconfig(local_user(),'fbsync','create_user');
+ $create_user = get_pconfig(local_user(),'fbsync','create_user');
$checked = (($create_user) ? ' checked="checked" ' : '');
$o .= '<input type="checkbox" name="create_user" value="1"' . $checked . '/>' . ' ' . t('Automatically create contacts.') . EOL;
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 "";
}