* 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
*/
/**
}
}
-
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)
`name-date` = '%s',
`uri-date` = '%s',
`avatar-date` = '%s'
- WHERE `id` = %d LIMIT 1
+ WHERE `id` = %d
",
dbesc($photos[0]),
dbesc($photos[1]),
`name-date` = '%s',
`uri-date` = '%s',
`avatar-date` = '%s'
- WHERE `id` = %d LIMIT 1
+ WHERE `id` = %d
",
dbesc($photos[0]),
dbesc($photos[1]),
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));
+ }
+ }
}
}
}
$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;
$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();
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;">';
if(preg_match("/\[img\](.*?)\[\/img\]/is",$b['body'],$matches))
$image = $matches[1];
+ // When saved into the database the content is sent through htmlspecialchars
+ // That means that we have to decode all image-urls
+ $image = htmlspecialchars_decode($image);
+
// Checking for a bookmark element
$body = $b['body'];
if (strpos($body, "[bookmark") !== false) {
// Fallback - if message is empty
if(!strlen($msg))
- $msg = $link;
+ $msg = $linkname;
if(!strlen($msg))
- $msg = $image;
+ $msg = $link;
if(!strlen($msg))
- $msg = $linkname;
+ $msg = $image;
// If there is nothing to post then exit
if(!strlen($msg))
'access_token' => $fb_token,
'message' => $msg
);
- if(isset($image)) {
+ if(trim($image) != "") {
$postvars['picture'] = $image;
}
- if(isset($link)) {
+ if(trim($link) != "") {
$postvars['link'] = $link;
// The following doesn't work - why?
$postvars['source'] = $link;
}
}
- if(isset($linkname))
+ if(trim($linkname) != "")
$postvars['name'] = $linkname;
}
$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'])
);
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'],
'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);
}
$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;
$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 {