]> git.mxchange.org Git - friendica-addons.git/blobdiff - facebook/facebook.php
fb private messages not posting
[friendica-addons.git] / facebook / facebook.php
index 22cefc0302d7aa39c3fd7f00580c6c4720cf22d0..845ddd9e816f4afde3a0bd4e75a685aca308d594 100644 (file)
@@ -6,19 +6,17 @@
  */
 
 /**
- * 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';
@@ -145,7 +143,7 @@ function fb_get_self($uid) {
 
 function fb_get_friends($uid) {
 
-       $r = q("SELECT `id` FROM `user` WHERE `uid` = %d AND `account_expired` = 0 LIMIT 1",
+       $r = q("SELECT `uid` FROM `user` WHERE `uid` = %d AND `account_expired` = 0 LIMIT 1",
                intval($uid)
        );
        if(! count($r))
@@ -214,13 +212,14 @@ function fb_get_friends($uid) {
                                else {
 
                                        // create contact record 
-                                       $r = q("INSERT INTO `contact` ( `uid`, `created`, `url`, `addr`, `alias`, `notify`, `poll`, 
+                                       $r = q("INSERT INTO `contact` ( `uid`, `created`, `url`, `nurl`, `addr`, `alias`, `notify`, `poll`, 
                                                `name`, `nick`, `photo`, `network`, `rel`, `priority`,
                                                `writable`, `blocked`, `readonly`, `pending` )
-                                               VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, 0, 0, 0 ) ",
+                                               VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, 0, 0, 0 ) ",
                                                intval($uid),
                                                dbesc(datetime_convert()),
                                                dbesc($jp->link),
+                                               dbesc(normalise_link($jp->link)),
                                                dbesc(''),
                                                dbesc(''),
                                                dbesc($jp->id),
@@ -293,6 +292,8 @@ function facebook_post(&$a) {
                set_pconfig($uid,'facebook','private_wall',$private_wall);
        
 
+               set_pconfig($uid,'facebook','blocked_apps',escape_tags(trim($_POST['blocked_apps'])));
+
                $linkvalue = ((x($_POST,'facebook_linking')) ? intval($_POST['facebook_linking']) : 0);
                set_pconfig($uid,'facebook','no_linking', (($linkvalue) ? 0 : 1));
 
@@ -400,6 +401,12 @@ function facebook_content(&$a) {
 
                $o .= '<p>' . t('If you choose to link conversations and leave both of these boxes unchecked, your Facebook profile wall will be merged with your profile wall on this website and your privacy settings on this website will be used to determine who may see the conversations.') . '</p>';
 
+
+               $blocked_apps = get_pconfig(local_user(),'facebook','blocked_apps');
+
+               $o .= '<div><label id="blocked-apps-label" for="blocked-apps">' . t('Comma separated applications to ignore') . ' </label></div>';
+       $o .= '<div><textarea id="blocked-apps" name="blocked_apps" >' . htmlspecialchars($blocked_apps) . '</textarea></div>';
+
                $o .= '<input type="submit" name="submit" value="' . t('Submit') . '" /></form></div>';
        }
 
@@ -504,23 +511,24 @@ function facebook_post_hook(&$a,&$b) {
 
        $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;
+               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']);
@@ -623,7 +631,7 @@ function facebook_post_hook(&$a,&$b) {
                                $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');
@@ -696,7 +704,7 @@ function facebook_post_hook(&$a,&$b) {
                                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);
@@ -718,15 +726,8 @@ function facebook_post_hook(&$a,&$b) {
                                        else {
                                                if(! $likes) {
                                                        $s = serialize(array('url' => $url, 'item' => $b['id'], 'post' => $postvars));
-                                                       q("INSERT INTO `queue` ( `network`, `cid`, `created`, `last`, `content`)
-                                                               VALUES ( '%s', %d, '%s', '%s', '%s') ",
-                                                               dbesc(NETWORK_FACEBOOK),
-                                                               intval($a->contact),
-                                                               dbesc(datetime_convert()),
-                                                               dbesc(datetime_convert()),
-                                                               dbesc($s)
-                                                       );                                                              
-
+                                                       require_once('include/queue_fn.php');
+                                                       add_to_queue($a->contact,NETWORK_FACEBOOK,$s);
                                                        notice( t('Facebook post failed. Queued for retry.') . EOL);
                                                }
                                        }
@@ -749,10 +750,10 @@ function facebook_post_local(&$a,&$b) {
        if((local_user()) && (local_user() == $b['uid'])) {
 
                $fb_post   = intval(get_pconfig(local_user(),'facebook','post'));
-               $fb_enable = (($fb_post && x($_POST,'facebook_enable')) ? intval($_POST['facebook_enable']) : 0);
+               $fb_enable = (($fb_post && x($_REQUEST,'facebook_enable')) ? intval($_REQUEST['facebook_enable']) : 0);
 
                // if API is used, default to the chosen settings
-               if($_POST['api_source'] && intval(get_pconfig(local_user(),'facebook','post_by_default')))
+               if($_REQUEST['api_source'] && intval(get_pconfig(local_user(),'facebook','post_by_default')))
                        $fb_enable = 1;
 
                if(! $fb_enable)
@@ -870,6 +871,8 @@ function fb_consume_stream($uid,$j,$wall = false) {
                intval($uid)
        );
 
+       $blocked_apps = get_pconfig($uid,'facebook','blocked_apps');
+       $blocked_apps_arr = explode(',',$blocked_apps);
 
        $self_id = get_pconfig($uid,'facebook','self_id');
        if(! count($j->data) || (! strlen($self_id)))
@@ -928,16 +931,38 @@ function fb_consume_stream($uid,$j,$wall = false) {
                                $datarray['app'] = strip_tags($entry->application->name);
                        else
                                $datarray['app'] = 'facebook';
+
+                       $found_blocked = false;
+
+                       if(count($blocked_apps_arr)) {
+                               foreach($blocked_apps_arr as $bad_appl) {
+                                       if(strlen(trim($bad_appl)) && (stristr($datarray['app'],trim($bad_appl)))) {
+                                               $found_blocked = true;
+                                       }
+                               }
+                       }
+                               
+                       if($found_blocked) {
+                               logger('facebook: blocking application: ' . $datarray['app']);
+                               continue;
+                       }
+
                        $datarray['author-name'] = $from->name;
                        $datarray['author-link'] = 'http://facebook.com/profile.php?id=' . $from->id;
                        $datarray['author-avatar'] = 'https://graph.facebook.com/' . $from->id . '/picture';
                        $datarray['plink'] = $datarray['author-link'] . '&v=wall&story_fbid=' . substr($entry->id,strpos($entry->id,'_') + 1);
 
-                       $datarray['body'] = $entry->message;
-                       if($entry->picture)
-                               $datarray['body'] .= "\n\n" . '[img]' . $entry->picture . '[/img]';
-                       if($entry->link)
-                               $datarray['body'] .= "\n" . linkify($entry->link);
+                       $datarray['body'] = escape_tags($entry->message);
+
+                       if($entry->picture && $entry->link) {
+                               $datarray['body'] .= "\n\n" . '[url=' . $entry->link . '][img]' . $entry->picture . '[/img][/url]';
+                       }
+                       else {
+                               if($entry->picture)
+                                       $datarray['body'] .= "\n\n" . '[img]' . $entry->picture . '[/img]';
+                               if($entry->link)
+                                       $datarray['body'] .= "\n" . '[url=' . $entry->link . ']' . t('link') . '[/url]';
+                       }
                        if($entry->name)
                                $datarray['body'] .= "\n" . $entry->name;
                        if($entry->caption)