From c9ccd91dd96baa61e4c075ab4e099ce436a584ec Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Mon, 9 Apr 2012 21:28:11 +0200 Subject: [PATCH 1/6] New addon "convpath": It converts all local links according to the current scheme (http/https) --- convpath/README | 7 ++++++ convpath/convpath.php | 50 +++++++++++++++++++++++++++++++++++++++++++ facebook/facebook.php | 10 +++++---- 3 files changed, 63 insertions(+), 4 deletions(-) create mode 100755 convpath/README create mode 100644 convpath/convpath.php diff --git a/convpath/README b/convpath/README new file mode 100755 index 00000000..9d1c3072 --- /dev/null +++ b/convpath/README @@ -0,0 +1,7 @@ +convpath + +This addon converts all internal paths according to the current scheme. + +That means that if a page is called via https then all internal links are also converted into https. + +Same happens when you call your page with http. diff --git a/convpath/convpath.php b/convpath/convpath.php new file mode 100644 index 00000000..5ad7fbcb --- /dev/null +++ b/convpath/convpath.php @@ -0,0 +1,50 @@ + + * + */ + +function convpath_install() { + register_hook('page_end', 'addon/convpath/convpath.php', 'convpath_page_end'); + register_hook('page_header', 'addon/convpath/convpath.php', 'convpath_page_header'); +} + + +function convpath_uninstall() { + unregister_hook('page_end', 'addon/convpath/convpath.php', 'convpath_page_end'); + unregister_hook('page_header', 'addon/convpath/convpath.php', 'convpath_page_header'); +} + +function convpath_page_header(&$a, &$o){ + $o = convpath_convert($o); +} + +function convpath_page_end(&$a, &$o){ + $o = convpath_convert($o); + $a->page['aside'] = convpath_convert($a->page['aside']); +} + +/* +Converts a given path according to the current scheme +*/ +function convpath_convert($path) { + global $a; + + if ($path == "") + return(""); + + $ssl = (substr($a->get_baseurl(), 0, 8) == "https://"); + + if ($ssl) { + $search = "http://".$a->get_hostname(); + $replace = "https://".$a->get_hostname(); + } else { + $search = "https://".$a->get_hostname(); + $replace = "http://".$a->get_hostname(); + } + $path = str_replace($search, $replace, $path); + return($path); +} diff --git a/facebook/facebook.php b/facebook/facebook.php index 70a353dd..5990a99e 100755 --- a/facebook/facebook.php +++ b/facebook/facebook.php @@ -1447,11 +1447,13 @@ function fb_consume_stream($uid,$j,$wall = false) { //if(($datarray['body'] != '') and ($uid == 1)) // $datarray['body'] .= "[noparse]".print_r($entry, true)."[/noparse]"; - if ($entry->place->name) - $datarray['coord'] = $entry->place->name; - else if ($entry->place->location->street or $entry->place->location->city or $entry->place->location->Denmark) { + if ($entry->place->name or $entry->place->location->street or + $entry->place->location->city or $entry->place->location->Denmark) { + $datarray['coord'] = ''; + if ($entry->place->name) + $datarray['coord'] .= $entry->place->name; if ($entry->place->location->street) - $datarray['coord'] = $entry->place->location->street; + $datarray['coord'] .= $entry->place->location->street; if ($entry->place->location->city) $datarray['coord'] .= " ".$entry->place->location->city; if ($entry->place->location->country) From acebf88aa5ceb6a613232c4bedbb3822c592f92d Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Mon, 9 Apr 2012 22:05:22 +0200 Subject: [PATCH 2/6] =?UTF-8?q?New=20addon=20"fromgplus".=20Should=20impor?= =?UTF-8?q?t=20=C3posts=20from=20Google+.=20Not=20working=20by=20now.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fromgplus/fromgplus.php | 181 ++++++++++++++++++++++++++++++++++++++ fromgplus/tofriendica.php | 128 +++++++++++++++++++++++++++ 2 files changed, 309 insertions(+) create mode 100755 fromgplus/fromgplus.php create mode 100644 fromgplus/tofriendica.php diff --git a/fromgplus/fromgplus.php b/fromgplus/fromgplus.php new file mode 100755 index 00000000..09b6c605 --- /dev/null +++ b/fromgplus/fromgplus.php @@ -0,0 +1,181 @@ + + * + */ + +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 .= '
'; + $s .= '

' . t('Google+ Import Settings').'

'; + $s .= '
'; + + $s .= ''; + $s .= ''; + $s .= '
'; + $s .= ''; + $s .= ''; + $s .= '
'; + + $s .= '
'; + $s .= '
'; + + 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("", ""), array("[b]", "[/b]"), $bbcode); + $bbcode = str_replace(array("", ""), array("[i]", "[/i]"), $bbcode); + $bbcode = str_replace(array("", ""), array("[s]", "[/s]"), $bbcode); + $bbcode = str_replace(array("
"), 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)); +} +*/ diff --git a/fromgplus/tofriendica.php b/fromgplus/tofriendica.php new file mode 100644 index 00000000..b185ecc1 --- /dev/null +++ b/fromgplus/tofriendica.php @@ -0,0 +1,128 @@ +", ""), array("[b]", "[/b]"), $bbcode); + $bbcode = str_replace(array("", ""), array("[i]", "[/i]"), $bbcode); + $bbcode = str_replace(array("", ""), array("[s]", "[/s]"), $bbcode); + $bbcode = str_replace(array("
"), 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)); +} +?> From 6f27beb728c444c908fdfbea818c612b2ae01a74 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Tue, 10 Apr 2012 23:09:06 +0200 Subject: [PATCH 3/6] Facebook: Don't add "story". Convpath now converts only pictures --- convpath/convpath.php | 7 ++++++- facebook/facebook.php | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/convpath/convpath.php b/convpath/convpath.php index 5ad7fbcb..e5dc0b36 100644 --- a/convpath/convpath.php +++ b/convpath/convpath.php @@ -45,6 +45,11 @@ function convpath_convert($path) { $search = "https://".$a->get_hostname(); $replace = "http://".$a->get_hostname(); } - $path = str_replace($search, $replace, $path); + $searcharr = array("src='".$search, 'src="'.$search); + $replacearr = array("src='".$replace, 'src="'.$replace); + $path = str_replace($searcharr, $replacearr, $path); + + //$path = str_replace($search, $replace, $path); + return($path); } diff --git a/facebook/facebook.php b/facebook/facebook.php index 5990a99e..1e961fda 100755 --- a/facebook/facebook.php +++ b/facebook/facebook.php @@ -1423,10 +1423,19 @@ function fb_consume_stream($uid,$j,$wall = false) { } } + if (($datarray['app'] == "Events") and $entry->actions) + foreach ($entry->actions as $action) + if ($action->name == "View") + $datarray['body'] .= " [url=".$action->link."]".$entry->story."[/url]"; + // Just as a test - to see if these are the missing entries //if(trim($datarray['body']) == '') // $datarray['body'] = $entry->story; + // Adding the "story" text to see if there are useful data in it (testing) + //if (($datarray['app'] != "Events") and $entry->story) + // $datarray['body'] .= "\n".$entry->story; + if(trim($datarray['body']) == '') { logger('facebook: empty body '.$entry->id.' '.print_r($entry, true)); continue; From 40ce1054b77fc4df2c9840ffdf04bb32b35996c0 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Thu, 12 Apr 2012 16:39:36 +0200 Subject: [PATCH 4/6] Facebook: Images weren't posted in some cases --- facebook/facebook.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/facebook/facebook.php b/facebook/facebook.php index b6e40654..6b9ee736 100755 --- a/facebook/facebook.php +++ b/facebook/facebook.php @@ -558,6 +558,9 @@ function facebook_content(&$a) { function facebook_cron($a,$b) { +//del_config('facebook', 'realtime_active'); +//del_config('facebook', 'realtime_err_mailsent'); +//del_config('facebook', 'cb_verify_token'); $last = get_config('facebook','last_poll'); @@ -896,7 +899,7 @@ function facebook_post_hook(&$a,&$b) { if(preg_match("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/is",$b['body'],$matches)) $image = $matches[3]; - if ($image != '') + if ($image == '') if(preg_match("/\[img\](.*?)\[\/img\]/is",$b['body'],$matches)) $image = $matches[1]; @@ -1436,8 +1439,8 @@ function fb_consume_stream($uid,$j,$wall = false) { // $datarray['body'] = $entry->story; // Adding the "story" text to see if there are useful data in it (testing) - //if (($datarray['app'] != "Events") and $entry->story) - // $datarray['body'] .= "\n".$entry->story; + if (($datarray['app'] != "Events") and $entry->story) + $datarray['body'] .= "\n".$entry->story; if(trim($datarray['body']) == '') { logger('facebook: empty body '.$entry->id.' '.print_r($entry, true)); From 977ac72f66fbbb23699767228e67c6051bc5f11e Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Fri, 13 Apr 2012 08:32:17 +0200 Subject: [PATCH 5/6] Facebook: Messages without images and links but with a subject and a text larger than 500 characters will be posted as notes. --- facebook/facebook.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/facebook/facebook.php b/facebook/facebook.php index 6b9ee736..a90445db 100755 --- a/facebook/facebook.php +++ b/facebook/facebook.php @@ -1009,10 +1009,14 @@ function facebook_post_hook(&$a,&$b) { 'access_token' => $fb_token, 'message' => $msg ); - if(isset($image)) + if(isset($image)) { $postvars['picture'] = $image; - if(isset($link)) + //$postvars['type'] = "photo"; + } + if(isset($link)) { $postvars['link'] = $link; + //$postvars['type'] = "link"; + } if(isset($linkname)) $postvars['name'] = $linkname; } @@ -1029,11 +1033,18 @@ function facebook_post_hook(&$a,&$b) { if($reply) { $url = 'https://graph.facebook.com/' . $reply . '/' . (($likes) ? 'likes' : 'comments'); - } - else { + } else if (($link != "") or ($image != "") or ($b['title'] == '') or (strlen($msg) < 500)) { $url = 'https://graph.facebook.com/me/feed'; if($b['plink']) $postvars['actions'] = '{"name": "' . t('View on Friendica') . '", "link": "' . $b['plink'] . '"}'; + } else { + // if its only a message and a subject and the message is larger than 500 characters then post it as note + $postvars = array( + 'access_token' => $fb_token, + 'message' => bbcode($b['body']), + 'subject' => $b['title'], + ); + $url = 'https://graph.facebook.com/me/notes'; } logger('facebook: post to ' . $url); From 5938e5185a25e17803b81180c7665a4eb9c6d3a6 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 15 Apr 2012 16:46:55 +0200 Subject: [PATCH 6/6] Facebook: Deactivated the test output of messages without content. --- facebook/facebook.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/facebook/facebook.php b/facebook/facebook.php index a90445db..397c104e 100755 --- a/facebook/facebook.php +++ b/facebook/facebook.php @@ -1450,8 +1450,8 @@ function fb_consume_stream($uid,$j,$wall = false) { // $datarray['body'] = $entry->story; // Adding the "story" text to see if there are useful data in it (testing) - if (($datarray['app'] != "Events") and $entry->story) - $datarray['body'] .= "\n".$entry->story; + //if (($datarray['app'] != "Events") and $entry->story) + // $datarray['body'] .= "\n".$entry->story; if(trim($datarray['body']) == '') { logger('facebook: empty body '.$entry->id.' '.print_r($entry, true));