if (x($_REQUEST, "realtime_cb") && x($_REQUEST, "realtime_cb")) {
logger("facebook_init: Facebook Real-Time callback called", LOGGER_DEBUG);
-
+
if (x($_REQUEST, "hub_verify_token")) {
// this is the verification callback while registering for real time updates
-
+
$verify_token = get_config('facebook', 'cb_verify_token');
if ($verify_token != $_REQUEST["hub_verify_token"]) {
logger('facebook_init: Wrong Facebook Callback Verifier - expected ' . $verify_token . ', got ' . $_REQUEST["hub_verify_token"]);
return;
}
-
+
if (x($_REQUEST, "hub_challenge")) {
logger('facebook_init: Answering Challenge: ' . $_REQUEST["hub_challenge"], LOGGER_DATA);
echo $_REQUEST["hub_challenge"];
die();
}
}
-
+
require_once('include/items.php');
-
+
// this is a status update
$content = file_get_contents("php://input");
if (is_numeric($content)) $content = file_get_contents("php://input");
$js = json_decode($content);
logger(print_r($js, true), LOGGER_DATA);
-
+
if (!isset($js->object) || $js->object != "user" || !isset($js->entry)) {
logger('facebook_init: Could not parse Real-Time Update data', LOGGER_DEBUG);
return;
}
-
+
$affected_users = array("feed" => array(), "friends" => array());
-
+
foreach ($js->entry as $entry) {
$fbuser = $entry->uid;
foreach ($entry->changed_fields as $field) {
continue;
}
if (in_array($fbuser, $affected_users[$field])) continue;
-
+
$r = q("SELECT `uid` FROM `pconfig` WHERE `cat` = 'facebook' AND `k` = 'self_id' AND `v` = '%s' LIMIT 1", dbesc($fbuser));
if(! count($r))
continue;
$uid = $r[0]['uid'];
-
+
$access_token = get_pconfig($uid,'facebook','access_token');
if(! $access_token)
return;
-
+
switch ($field) {
case "feed":
logger('facebook_init: FB-User ' . $fbuser . ' / feed', LOGGER_DEBUG);
-
+
if(! get_pconfig($uid,'facebook','no_wall')) {
$private_wall = intval(get_pconfig($uid,'facebook','private_wall'));
$s = fetch_url('https://graph.facebook.com/me/feed?access_token=' . $access_token);
}
}
}
-
+
break;
case "friends":
logger('facebook_init: FB-User ' . $fbuser . ' / friends', LOGGER_DEBUG);
-
+
fb_get_friends($uid, false);
set_pconfig($uid,'facebook','friend_check',time());
break;
}
}
-
+
if($a->argc != 2)
return;
$nick = $a->argv[1];
$x = fetch_url('https://graph.facebook.com/oauth/access_token?client_id='
. $appid . '&client_secret=' . $appsecret . '&redirect_uri='
- . urlencode($a->get_baseurl() . '/facebook/' . $nick)
+ . urlencode($a->get_baseurl() . '/facebook/' . $nick)
. '&code=' . $auth_code);
logger('facebook_init: returned access token: ' . $x, LOGGER_DATA);
$access_token = get_pconfig($uid,'facebook','access_token');
$no_linking = get_pconfig($uid,'facebook','no_linking');
+
if($no_linking)
return;
}
// This is the POST method to the facebook settings page
-// Content is posted to Facebook in the function facebook_post_hook()
+// Content is posted to Facebook in the function facebook_post_hook()
/**
* @param App $a
if($uid){
- $fb_limited = get_config('facebook','restrict');
+ $fb_limited = get_config('facebook','crestrict');
$value = ((x($_POST,'post_by_default')) ? intval($_POST['post_by_default']) : 0);
$private_wall = ((x($_POST,'facebook_private_wall')) ? intval($_POST['facebook_private_wall']) : 0);
set_pconfig($uid,'facebook','private_wall',$private_wall);
-
+
set_pconfig($uid,'facebook','blocked_apps',escape_tags(trim($_POST['blocked_apps'])));
if($linkvalue == 0)
set_pconfig($uid,'facebook','no_linking', 1);
}
- else
+ else
set_pconfig($uid,'facebook','no_linking', (($linkvalue) ? 0 : 1));
// FB linkage was allowed but has just been turned off - remove all FB contacts and posts
--- /dev/null
+This extension is a preparation of the upcoming import of items via Google+
--- /dev/null
+<?php
+/**
+ * Name: From GPlus
+ * Description: Imports posts from a Google+ account and repeats them - not working by now
+ * Version: 0.1
+ * Author: Michael Vogel <ike@piratenpartei.de>
+ *
+ */
+
+function fromgplus_install() {
+ register_hook('plugin_settings', 'addon/fromgplus/fromgplus.php', 'fromgplus_addon_settings');
+ register_hook('plugin_settings_post', 'addon/fromgplus/fromgplus.php', 'fromgplus_addon_settings_post');
+}
+
+function fromgplus_uninstall() {
+ unregister_hook('plugin_settings', 'addon/fromgplus/fromgplus.php', 'fromgplus_addon_settings');
+ unregister_hook('plugin_settings_post', 'addon/fromgplus/fromgplus.php', 'fromgplus_addon_settings_post');
+}
+
+function fromgplus_addon_settings(&$a,&$s) {
+
+ if(! local_user())
+ return;
+
+ $enable_checked = (intval(get_pconfig(local_user(),'fromgplus','enable')) ? ' checked="checked"' : '');
+ $account = get_pconfig(local_user(),'fromgplus','account');
+
+ $s .= '<div class="settings-block">';
+ $s .= '<h3>' . t('Google+ Import Settings').'</h3>';
+ $s .= '<div id="fromgplus-wrapper">';
+
+ $s .= '<label id="fromgplus-enable-label" for="fromgplus-enable">'.t('Enable Google+ Import').'</label>';
+ $s .= '<input id="fromgplus-enable" type="checkbox" name="fromgplus-enable" value="1"'.$enable_checked.' />';
+ $s .= '<div class="clear"></div>';
+ $s .= '<label id="fromgplus-label" for="fromgplus-account">'.t('Google Account ID').' </label>';
+ $s .= '<input id="fromgplus-account" type="text" name="fromgplus-account" value="'.$account.'" />';
+ $s .= '</div><div class="clear"></div>';
+
+ $s .= '<div class="settings-submit-wrapper" ><input type="submit" id="fromgplus-submit" name="fromgplus-submit"
+class="settings-submit" value="' . t('Submit') . '" /></div>';
+ $s .= '</div>';
+
+ return;
+}
+
+function fromgplus_addon_settings_post(&$a,&$b) {
+
+ if(! local_user())
+ return;
+
+ if($_POST['fromgplus-submit']) {
+ set_pconfig(local_user(),'fromgplus','account',trim($_POST['fromgplus-account']));
+ $enable = ((x($_POST,'fromgplus-enable')) ? intval($_POST['fromgplus-enable']) : 0);
+ set_pconfig(local_user(),'fromgplus','enable', $enable);
+ info( t('Google+ Import Settings saved.') . EOL);
+ }
+}
+/*
+function html2bbcode($html) {
+
+ $bbcode = html_entity_decode($html, ENT_QUOTES, 'UTF-8');
+
+ $bbcode = str_replace(array("\n"), array(""), $bbcode);
+ $bbcode = str_replace(array("<b>", "</b>"), array("[b]", "[/b]"), $bbcode);
+ $bbcode = str_replace(array("<i>", "</i>"), array("[i]", "[/i]"), $bbcode);
+ $bbcode = str_replace(array("<s>", "</s>"), array("[s]", "[/s]"), $bbcode);
+ $bbcode = str_replace(array("<br />"), array("\n"), $bbcode);
+
+ $bbcode = trim(strip_tags($bbcode));
+ return($bbcode);
+}
+
+function friendicapost($post) {
+ global $friendica;
+
+ $api = new Statusnet($friendica["user"], $friendica["pw"], "GooglePlus", $friendica["server"]);
+ $ret = $api->updateStatus($post);
+ $api->endSession();
+}
+
+function handleattachments($item) {
+ $post = "";
+
+ foreach ($item->object->attachments as $attachment) {
+ switch($attachment->objectType) {
+ case "video":
+ //$post .= "\n\n[url=".$attachment->url."]".
+ // "[size=large][b]".html2bbcode($attachment->displayName)."[/b][/size][/url]\n";
+ $post .= "\n\n[bookmark=".$attachment->url."]".html2bbcode($attachment->displayName)."[/bookmark]\n";
+
+ //if (strpos($attachment->embed->url, "youtube.com"))
+ // $post .= "[youtube]".$attachment->url."[/youtube]\n";
+ //else
+ /// $post .= "[url=".$attachment->url."][img]".$attachment->image->url."[/img][/url]\n";
+
+ ///$post .= "[quote]".trim(html2bbcode($attachment->content))."[/quote]";
+ break;
+
+ case "article":
+ //$post .= "\n\n[url=".$attachment->url."]".
+ // "[size=large][b]".html2bbcode($attachment->displayName)."[/b][/size][/url]\n";
+ $post .= "\n\n[bookmark=".$attachment->url."]".html2bbcode($attachment->displayName)."[/bookmark]\n";
+ $post .= "[quote]".trim(html2bbcode($attachment->content))."[/quote]";
+ break;
+
+ case "photo":
+ //$post .= "\n\n[url=".$attachment->fullImage->url."]".
+ // "[img]".$attachment->fullImage->url."[/img][/url]\n";
+ $post .= "\n\n[img]".$attachment->fullImage->url."[/img]\n";
+ if ($attachment->displayName != "")
+ $post .= html2bbcode($attachment->displayName)."\n";
+ break;
+
+ case "photo-album":
+ $post .= "\n\n[url=".$attachment->url."]".
+ "[size=large][b]".html2bbcode($attachment->displayName)."[/b][/size][/url]\n";
+ break;
+
+ default:
+ print_r($attachment);
+ die();
+ break;
+ }
+ }
+ return($post);
+}
+
+$result =
+file_get_contents("https://www.googleapis.com/plus/v1/people/".$google["id"]."/activities/public?alt=json&pp=1&key=".$google["key"]."&maxResults=".$google["maxfetch"]);
+$activities = json_decode($result);
+
+$state = array("lastid"=>'');
+if (file_exists($statefile))
+ $state = unserialize(file_get_contents($statefile));
+
+$lastid = "";
+
+foreach($activities->items as $item) {
+ if ($item->id == $state["lastid"])
+ break;
+
+ if ($lastid == "")
+ $lastid = $item->id;
+
+ switch($item->object->objectType) {
+ case "note":
+ $post = html2bbcode($item->object->content);
+
+ if (is_array($item->object->attachments))
+ $post .= handleattachments($item);
+ friendicapost($post);
+ break;
+
+ case "activity":
+ $post = html2bbcode($item->annotation)."\n";
+ //$post .= html2bbcode("♲ ");
+ $post .= html2bbcode("♻ ");
+ $post .= "[url=".$item->object->actor->url."]".$item->object->actor->displayName."[/url]";
+ $post .= " \n";
+ //$post .= "[quote]";
+
+ $post .= html2bbcode($item->object->content);
+
+ if (is_array($item->object->attachments))
+ $post .= "\n".trim(handleattachments($item));
+
+ //$post .= "[/quote]";
+
+ friendicapost($post);
+ break;
+
+ default:
+ print_r($item);
+ die();
+ break;
+ }
+}
+
+if ($lastid != "") {
+ $state['lastid'] = $lastid;
+ file_put_contents($statefile, serialize($state));
+}
+*/
}
}
if(count($tag_arr))
- $tags = implode(',',$tag_arr);
+ $tags = implode(',',$tag_arr);
+ $link = "";
+ $video = false;
+
+ // Checking for a bookmark
+ if(preg_match("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/is",$b['body'],$matches)) {
+ $link = $matches[1];
+ if ($b['title'] == '')
+ $b['title'] = html_entity_decode($matches[2],ENT_QUOTES,'UTF-8');
+
+ $body = $b['body'];
+ // splitting the text in two parts:
+ // before and after the bookmark
+ $pos = strpos($body, "[bookmark");
+ $body1 = substr($body, 0, $pos);
+ $body2 = substr($body, $pos);
+
+ // Removing the bookmark
+ $body2 = preg_replace("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism",'',$body2);
+ $body = $body1.$body2;
+
+ $video = ((stristr($link,'youtube')) || (stristr($link,'youtu.be')) || (stristr($mtch[1],'vimeo')));
+ }
$params = array(
'email' => $tmbl_username,
'password' => $tmbl_password,
- 'title' => $b['title'],
- 'type' => 'regular',
'format' => 'html',
'generator' => 'Friendica',
- 'tags' => $tags,
- 'body' => bbcode($b['body'])
- );
+ 'tags' => $tags);
+
+ if (($link != '') and $video) {
+ $params['type'] = "video";
+ $params['embed'] = $link;
+ if ($b['title'] != '')
+ $params['caption'] = '<h1><a href="'.$link.'">'.$b['title'].
+ "</a></h1><p>".bbcode($body)."</p>";
+ else
+ $params['caption'] = bbcode($body);
+ } else if (($link != '') and !$video) {
+ $params['type'] = "link";
+ $params['name'] = $b['title'];
+ $params['url'] = $link;
+ //$params['description'] = bbcode($body);
+ $params['description'] = bbcode($b["body"]);
+ } else {
+ $params['type'] = "regular";
+ $params['title'] = $b['title'];
+ $params['body'] = bbcode($b['body']);
+ }
$x = post_url($tmbl_blog,$params);
$ret_code = $a->get_curl_code();
elseif($ret_code == 403)
logger('tumblr_send: authentication failure');
else
- logger('tumblr_send: general error: ' . print_r($x,true));
+ logger('tumblr_send: general error: ' . print_r($x,true));
}
}