]> git.mxchange.org Git - friendica-addons.git/blobdiff - facebook/facebook.php
Merge pull request #272 from tobiasd/20150706-mods
[friendica-addons.git] / facebook / facebook.php
index b9f4285957a6039e4b6732cd1c5d6c1c0545c0a5..66f52af37742940ac9fe0475f7646f57f13bca08 100644 (file)
@@ -3,7 +3,8 @@
  * Name: Facebook Connector
  * Version: 1.3
  * Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
- *         Tobias Hößl <https://github.com/CatoTH/>
+ * Author: Tobias Hößl <https://github.com/CatoTH/>
+ * Status: Unsupported
  */
 
 /**
@@ -162,10 +163,11 @@ function facebook_init(&$a) {
                }
        }
 
-
        if($a->argc != 2)
                return;
+
        $nick = $a->argv[1];
+
        if(strlen($nick))
                $r = q("SELECT `uid` FROM `user` WHERE `nickname` = '%s' LIMIT 1",
                                dbesc($nick)
@@ -287,7 +289,7 @@ function fb_get_friends_sync_parsecontact($uid, $contact) {
                                         `name-date` = '%s',
                                         `uri-date` = '%s',
                                         `avatar-date` = '%s'
-                                        WHERE `id` = %d LIMIT 1
+                                        WHERE `id` = %d
                                 ",
                 dbesc($photos[0]),
                 dbesc($photos[1]),
@@ -354,7 +356,7 @@ function fb_get_friends_sync_parsecontact($uid, $contact) {
                         `name-date` = '%s',
                         `uri-date` = '%s',
                         `avatar-date` = '%s'
-                        WHERE `id` = %d LIMIT 1
+                        WHERE `id` = %d
                 ",
         dbesc($photos[0]),
         dbesc($photos[1]),
@@ -381,10 +383,12 @@ function fb_get_friends_sync_full($uid, $access_token, $persons) {
         if($s) {
             $results = json_decode($s);
             logger('fb_get_friends: info: ' . print_r($results,true), LOGGER_DATA);
-            foreach ($results as $contact) {
-                if ($contact->code != 200) logger('fb_get_friends: not found: ' . print_r($contact,true), LOGGER_DEBUG);
-                else fb_get_friends_sync_parsecontact($uid, json_decode($contact->body));
-            }
+                       if(count($results)) {
+                   foreach ($results as $contact) {
+                   if ($contact->code != 200) logger('fb_get_friends: not found: ' . print_r($contact,true), LOGGER_DEBUG);
+                       else fb_get_friends_sync_parsecontact($uid, json_decode($contact->body));
+               }
+                       }
         }
     }
 }
@@ -614,7 +618,7 @@ function facebook_content(&$a) {
                $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>';
+               $o .= '<input type="submit" name="submit" value="' . t('Save Settings') . '" /></form></div>';
        }
 
        return $o;
@@ -738,19 +742,19 @@ function facebook_plugin_admin(&$a, &$o){
 
 
        $o = '<input type="hidden" name="form_security_token" value="' . get_form_security_token("fbsave") . '">';
-       
+
        $o .= '<h4>' . t('Facebook API Key') . '</h4>';
-       
+
        $appid  = get_config('facebook', 'appid'  );
        $appsecret = get_config('facebook', 'appsecret' );
        $poll_interval = get_config('facebook', 'poll_interval' );
        $sync_comments = get_config('facebook', 'sync_comments' );
        if (!$poll_interval) $poll_interval = FACEBOOK_DEFAULT_POLL_INTERVAL;
-       
+
        $ret1 = q("SELECT `v` FROM `config` WHERE `cat` = 'facebook' AND `k` = 'appid' LIMIT 1");
        $ret2 = q("SELECT `v` FROM `config` WHERE `cat` = 'facebook' AND `k` = 'appsecret' LIMIT 1");
        if ((count($ret1) > 0 && $ret1[0]['v'] != $appid) || (count($ret2) > 0 && $ret2[0]['v'] != $appsecret)) $o .= t('Error: it appears that you have specified the App-ID and -Secret in your .htconfig.php file. As long as they are specified there, they cannot be set using this form.<br><br>');
-       
+
        $working_connection = false;
        if ($appid && $appsecret) {
                $subs = facebook_subscriptions_get();
@@ -758,9 +762,9 @@ function facebook_plugin_admin(&$a, &$o){
                elseif (is_array($subs)) {
                        $o .= t('The given API Key seems to work correctly.') . '<br>';
                        $working_connection = true;
-               } else $o .= t('The correctness of the API Key could not be detected. Somthing strange\'s going on.') . '<br>';
+               } else $o .= t('The correctness of the API Key could not be detected. Something strange\'s going on.') . '<br>';
        }
-       
+
        $o .= '<label for="fb_appid">' . t('App-ID / API-Key') . '</label><input id="fb_appid" name="appid" type="text" value="' . escape_tags($appid ? $appid : "") . '"><br style="clear: both;">';
        $o .= '<label for="fb_appsecret">' . t('Application secret') . '</label><input id="fb_appsecret" name="appsecret" type="text" value="' . escape_tags($appsecret ? $appsecret : "") . '"><br style="clear: both;">';
        $o .= '<label for="fb_poll_interval">' . sprintf(t('Polling Interval in minutes (minimum %1$s minutes)'), FACEBOOK_MIN_POLL_INTERVAL) . '</label><input name="poll_interval" id="fb_poll_interval" type="number" min="' . FACEBOOK_MIN_POLL_INTERVAL . '" value="' . $poll_interval . '"><br style="clear: both;">';
@@ -1167,7 +1171,7 @@ function facebook_post_hook(&$a,&$b) {
 
                                        $retj = json_decode($x);
                                        if($retj->id) {
-                                               q("UPDATE `item` SET `extid` = '%s' WHERE `id` = %d LIMIT 1",
+                                               q("UPDATE `item` SET `extid` = '%s' WHERE `id` = %d",
                                                        dbesc('fb::' . $retj->id),
                                                        intval($b['id'])
                                                );
@@ -1179,14 +1183,14 @@ function facebook_post_hook(&$a,&$b) {
                                                        add_to_queue($a->contact,NETWORK_FACEBOOK,$s);
                                                        notice( t('Facebook post failed. Queued for retry.') . EOL);
                                                }
-                                               
+
                                                if (isset($retj->error) && $retj->error->type == "OAuthException" && $retj->error->code == 190) {
                                                        logger('Facebook session has expired due to changed password.', LOGGER_DEBUG);
-                                                       
+
                                                        $last_notification = get_pconfig($b['uid'], 'facebook', 'session_expired_mailsent');
                                                        if (!$last_notification || $last_notification < (time() - FACEBOOK_SESSION_ERR_NOTIFICATION_INTERVAL)) {
                                                                require_once('include/enotify.php');
-                                                       
+
                                                                $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", intval($b['uid']) );
                                                                notification(array(
                                                                        'uid' => $b['uid'],
@@ -1199,7 +1203,7 @@ function facebook_post_hook(&$a,&$b) {
                                                                        'source_link'  => $a->config["system"]["url"],
                                                                        'source_photo' => $a->config["system"]["url"] . '/images/person-80.jpg',
                                                                ));
-                                                               
+
                                                                set_pconfig($b['uid'], 'facebook', 'session_expired_mailsent', time());
                                                        } else logger('Facebook: No notification, as the last one was sent on ' . $last_notification, LOGGER_DEBUG);
                                                }
@@ -1240,8 +1244,12 @@ function facebook_post_local(&$a,&$b) {
                $fb_enable = (($fb_post && x($_REQUEST,'facebook_enable')) ? intval($_REQUEST['facebook_enable']) : 0);
 
                // if API is used, default to the chosen settings
-               if($_REQUEST['api_source'] && intval(get_pconfig(local_user(),'facebook','post_by_default')))
-                       $fb_enable = 1;
+               // but allow a specific override
+
+               if($_REQUEST['api_source'] && intval(get_pconfig(local_user(),'facebook','post_by_default'))) {
+                       if(! x($_REQUEST,'facebook_enable'))
+                               $fb_enable = 1;
+               }
 
                if(! $fb_enable)
                        return;
@@ -1299,11 +1307,11 @@ function fb_queue_hook(&$a,&$b) {
 
                                $retj = json_decode($j);
                                if($retj->id) {
-                                       q("UPDATE `item` SET `extid` = '%s' WHERE `id` = %d LIMIT 1",
+                                       q("UPDATE `item` SET `extid` = '%s' WHERE `id` = %d",
                                                dbesc('fb::' . $retj->id),
                                                intval($item)
                                        );
-                                       logger('facebook_queue: success: ' . $j); 
+                                       logger('facebook_queue: success: ' . $j);
                                        remove_queue_item($x['id']);
                                }
                                else {