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);
//read_stream,publish_stream,manage_pages,photo_upload,user_groups,offline_access
$o .= '<a href="https://www.facebook.com/dialog/oauth?client_id=' . $appid . '&redirect_uri='
- . $a->get_baseurl() . '/fbpost/' . $a->user['nickname'] . '&scope=export_stream,read_stream,publish_stream,manage_pages,photo_upload,user_groups,publish_actions,user_friends,create_note,share_item,video_upload,status_update">' . t('Install Facebook Post connector for this account.') . '</a>';
+ . $a->get_baseurl() . '/fbpost/' . $a->user['nickname'] . '&scope=export_stream,read_stream,publish_stream,manage_pages,photo_upload,user_groups,publish_actions,user_friends,share_item,video_upload,status_update">' . t('Install Facebook Post connector for this account.') . '</a>';
$o .= '</div>';
}
$o .= '<div id="fbpost-enable-wrapper">';
$o .= '<a href="https://www.facebook.com/dialog/oauth?client_id=' . $appid . '&redirect_uri='
- . $a->get_baseurl() . '/fbpost/' . $a->user['nickname'] . '&scope=export_stream,read_stream,publish_stream,manage_pages,photo_upload,user_groups,publish_actions,user_friends,create_note,share_item,video_upload,status_update">' . t('Re-authenticate [This is necessary whenever your Facebook password is changed.]') . '</a>';
+ . $a->get_baseurl() . '/fbpost/' . $a->user['nickname'] . '&scope=export_stream,read_stream,publish_stream,manage_pages,photo_upload,user_groups,publish_actions,user_friends,share_item,video_upload,status_update">' . t('Re-authenticate [This is necessary whenever your Facebook password is changed.]') . '</a>';
$o .= '</div>';
$o .= '<div id="fbpost-post-default-form">';
$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;
$postvars['message'] = $msg;
$url = 'https://graph.facebook.com/'.$target.'/photos';
- } else if (($link != "") or ($image != "") or ($b['title'] == '') or (strlen($msg) < 500)) {
+ //} else if (($link != "") or ($image != "") or ($b['title'] == '') or (strlen($msg) < 500)) {
+ } else {
$url = 'https://graph.facebook.com/'.$target.'/feed';
if (!get_pconfig($b['uid'],'facebook','suppress_view_on_friendica') and $b['plink'])
$postvars['actions'] = '{"name": "' . t('View on Friendica') . '", "link": "' . $b['plink'] . '"}';
- } else {
+ }
+/* } else {
// if its only a message and a subject and the message is larger than 500 characters then post it as note
$postvars = array(
'access_token' => $fb_token,
'subject' => $b['title'],
);
$url = 'https://graph.facebook.com/'.$target.'/notes';
- }
+ } */
// Post to page?
if (!$reply and ($target != "me") and $page_access_token)
}
}
+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');
function fbpost_fetchwall($a, $uid) {
require_once("include/oembed.php");
+ require_once('mod/item.php');
$access_token = get_pconfig($uid,'facebook','access_token');
$post_to_page = get_pconfig($uid,'facebook','post_to_page');
$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);
//print_r($_REQUEST);
logger('facebook: posting for user '.$uid);
-
- require_once('mod/item.php');
item_post($a);
}
$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 "";
}