*/
/**
- * Installing the Friendika/Facebook connector
+ * Installing the Friendica/Facebook connector
*
* 1. register an API key for your site from developer.facebook.com
- * a. We'd be very happy if you include "Friendika" in the application name
- * to increase name recognition. The Friendika icons are also present
+ * a. We'd be very happy if you include "Friendica" in the application name
+ * to increase name recognition. The Friendica icons are also present
* in the images directory and may be uploaded as a Facebook app icon.
- * Use images/friendika-16.jpg for the Icon and images/friendika-128.jpg for the Logo.
+ * Use images/friendica-16.jpg for the Icon and images/friendica-128.jpg for the Logo.
* b. The url should be your site URL with a trailing slash.
- * You may use http://portal.friendika.com/privacy as the privacy policy
- * URL unless your site has different requirements, and
- * http://portal.friendika.com as the Terms of Service URL unless
- * you have different requirements. (Friendika is a software application
- * and does not require Terms of Service, though your installation of it might).
+ * Friendica is a software application and does not require a Privacy Policy
+ * or Terms of Service, though your installation of it might. Facebook may require
+ * that you provide a Privacy Policy, which we find ironic.
* c. Set the following values in your .htconfig.php file
* $a->config['facebook']['appid'] = 'xxxxxxxxxxx';
* $a->config['facebook']['appsecret'] = 'xxxxxxxxxxxxxxx';
$toplevel = (($b['id'] == $b['parent']) ? true : false);
- if(strstr($b['postopts'],'facebook')) {
- $linking = ((get_pconfig($b['uid'],'facebook','no_linking')) ? 0 : 1);
+ $linking = ((get_pconfig($b['uid'],'facebook','no_linking')) ? 0 : 1);
- if((! $toplevel) && ($linking)) {
- $r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
- intval($b['parent']),
- intval($b['uid'])
- );
- if(count($r) && substr($r[0]['uri'],0,4) === 'fb::')
- $reply = substr($r[0]['uri'],4);
- elseif(count($r) && substr($r[0]['extid'],0,4) === 'fb::')
- $reply = substr($r[0]['extid'],4);
- else
- return;
- logger('facebook reply id=' . $reply);
- }
+ if((! $toplevel) && ($linking)) {
+ $r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
+ intval($b['parent']),
+ intval($b['uid'])
+ );
+ if(count($r) && substr($r[0]['uri'],0,4) === 'fb::')
+ $reply = substr($r[0]['uri'],4);
+ elseif(count($r) && substr($r[0]['extid'],0,4) === 'fb::')
+ $reply = substr($r[0]['extid'],4);
+ else
+ return;
+
+ $u = q("SELECT * FROM user where uid = %d limit 1",
+ intval($b['uid'])
+ );
+ if(! count($u))
+ return;
+
+ // only accept comments from the item owner. Other contacts are unknown to FB.
+
+ if(! link_compare($b['author-link'], $a->get_baseurl() . '/profile/' . $u[0]['nickname']))
+ return;
+
+
+ logger('facebook reply id=' . $reply);
+ }
+
+ if(strstr($b['postopts'],'facebook') || ($b['private']) || ($reply)) {
if($b['private'] && $reply === false) {
$allow_people = expand_acl($b['allow_cid']);
$msg = preg_replace("/\[img\](.*?)\[\/img\]/is", t('Image: ') . '$1', $msg);
if((strpos($link,z_root()) !== false) && (! $image))
- $image = $a->get_baseurl() . '/images/friendika-64.jpg';
+ $image = $a->get_baseurl() . '/images/friendica-64.jpg';
$msg = trim(strip_tags(bbcode($msg)));
$msg = html_entity_decode($msg,ENT_QUOTES,'UTF-8');
$postvars['name'] = $linkname;
}
- if(($b['private']) && (! $b['parent'])) {
+ if(($b['private']) && ($toplevel)) {
$postvars['privacy'] = '{"value": "CUSTOM", "friends": "SOME_FRIENDS"';
if(count($allow_arr))
$postvars['privacy'] .= ',"allow": "' . implode(',',$allow_arr) . '"';
else {
$url = 'https://graph.facebook.com/me/feed';
if($b['plink'])
- $postvars['actions'] = '{"name": "' . t('View on Friendika') . '", "link": "' . $b['plink'] . '"}';
+ $postvars['actions'] = '{"name": "' . t('View on Friendica') . '", "link": "' . $b['plink'] . '"}';
}
logger('facebook: post to ' . $url);
}
+function fb_get_photo($uid,$link) {
+ $access_token = get_pconfig($uid,'facebook','access_token');
+ if(! $access_token || (! stristr($link,'facebook.com/photo.php')))
+ return "\n" . '[url=' . $link . ']' . t('link') . '[/url]';
+ $ret = preg_match('/fbid=([0-9]*)/',$link,$match);
+ if($ret)
+ $photo_id = $match[1];
+ $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]' . $j->picture . '[/img][/url]';
+ else
+ return "\n" . '[url=' . $link . ']' . t('link') . '[/url]';
+}
+
function fb_consume_stream($uid,$j,$wall = false) {
$a = get_app();
else {
if($entry->picture)
$datarray['body'] .= "\n\n" . '[img]' . $entry->picture . '[/img]';
+ // if just a link, it may be a wall photo - check
if($entry->link)
- $datarray['body'] .= "\n" . '[url=' . $entry->link . ']' . t('link') . '[/url]';
+ $datarray['body'] .= fb_get_photo($uid,$entry->link);
}
if($entry->name)
$datarray['body'] .= "\n" . $entry->name;