From 2333679ee0f8c8afb349fb6321e9590fcb33fd85 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sat, 21 Apr 2012 19:29:46 +0200 Subject: [PATCH 01/12] Re-Added "fromgplus" - Not working by now --- fromgplus/README | 1 + fromgplus/fromgplus.php | 183 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 184 insertions(+) create mode 100644 fromgplus/README create mode 100644 fromgplus/fromgplus.php diff --git a/fromgplus/README b/fromgplus/README new file mode 100644 index 000000000..cecbb2b9d --- /dev/null +++ b/fromgplus/README @@ -0,0 +1 @@ +This extension is a preparation of the upcoming import of items via Google+ diff --git a/fromgplus/fromgplus.php b/fromgplus/fromgplus.php new file mode 100644 index 000000000..88d2622ff --- /dev/null +++ b/fromgplus/fromgplus.php @@ -0,0 +1,183 @@ + + * + */ + +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)); +} +*/ From 7e9b3450c53fcf8d6057d789fbe0ad95b34a90f1 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Mon, 23 Apr 2012 22:58:52 +0200 Subject: [PATCH 02/12] Take the name of the bookmark link as title - when not set. --- tumblr/tumblr.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tumblr/tumblr.php b/tumblr/tumblr.php index 31021842c..3dd4daed7 100755 --- a/tumblr/tumblr.php +++ b/tumblr/tumblr.php @@ -166,8 +166,13 @@ function tumblr_send(&$a,&$b) { } } if(count($tag_arr)) - $tags = implode(',',$tag_arr); + $tags = implode(',',$tag_arr); + if ($b['title'] == '') { + // Take the description from the bookmark + if(preg_match("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/is",$b['body'],$matches)) + $b['title'] = $matches[2]; + } $params = array( 'email' => $tmbl_username, From eeed84f200c44210af3ddd9236d0ef32fecfb56c Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Tue, 24 Apr 2012 00:23:33 +0200 Subject: [PATCH 03/12] Tumblr: Export improved - autodetection of links. --- tumblr/tumblr.php | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/tumblr/tumblr.php b/tumblr/tumblr.php index 3dd4daed7..85191f747 100755 --- a/tumblr/tumblr.php +++ b/tumblr/tumblr.php @@ -168,22 +168,31 @@ function tumblr_send(&$a,&$b) { if(count($tag_arr)) $tags = implode(',',$tag_arr); + $link = ""; if ($b['title'] == '') { // Take the description from the bookmark if(preg_match("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/is",$b['body'],$matches)) - $b['title'] = $matches[2]; + $link = $matches[1]; + $b['title'] = html_entity_decode($matches[2],ENT_QUOTES,'UTF-8'); } $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 != '') { + $params['type'] = "link"; + $params['name'] = $b['title'], + $params['url'] = $link; + $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(); @@ -192,7 +201,7 @@ function tumblr_send(&$a,&$b) { 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)); } } From 8e6f6a14559cc77ebc16005af75ed491d3b3cbe6 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Tue, 24 Apr 2012 00:50:54 +0200 Subject: [PATCH 04/12] Tumblr: Bugfix --- tumblr/tumblr.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tumblr/tumblr.php b/tumblr/tumblr.php index 85191f747..95755e398 100755 --- a/tumblr/tumblr.php +++ b/tumblr/tumblr.php @@ -185,12 +185,12 @@ function tumblr_send(&$a,&$b) { if ($link != '') { $params['type'] = "link"; - $params['name'] = $b['title'], + $params['name'] = $b['title']; $params['url'] = $link; $params['description'] = bbcode($b['body']); } else { $params['type'] = "regular"; - $params['title'] = $b['title'], + $params['title'] = $b['title']; $params['body'] = bbcode($b['body']); } From 64c68ac97815a516d36fa0f6c0b4734adf0f621c Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Tue, 24 Apr 2012 01:42:20 +0200 Subject: [PATCH 05/12] tumblr: Now videos are detected as well. --- tumblr/tumblr.php | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/tumblr/tumblr.php b/tumblr/tumblr.php index 95755e398..42518c050 100755 --- a/tumblr/tumblr.php +++ b/tumblr/tumblr.php @@ -169,11 +169,26 @@ function tumblr_send(&$a,&$b) { $tags = implode(',',$tag_arr); $link = ""; - if ($b['title'] == '') { - // Take the description from the bookmark - if(preg_match("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/is",$b['body'],$matches)) - $link = $matches[1]; + $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( @@ -183,11 +198,15 @@ function tumblr_send(&$a,&$b) { 'generator' => 'Friendica', 'tags' => $tags); - if ($link != '') { + if (($link != '') and $video) { + $params['type'] = "video"; + $params['embed'] = $link; + $params['caption'] = bbcode($body); + } else if (($link != '') and !$video) { $params['type'] = "link"; $params['name'] = $b['title']; $params['url'] = $link; - $params['description'] = bbcode($b['body']); + $params['description'] = bbcode($body); } else { $params['type'] = "regular"; $params['title'] = $b['title']; From 71ec9fdd9893ad429898dd5a6a0b5d1d1ed481c6 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Tue, 24 Apr 2012 02:04:51 +0200 Subject: [PATCH 06/12] Tumblr: The video export now shows the title --- tumblr/tumblr.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tumblr/tumblr.php b/tumblr/tumblr.php index 42518c050..650e0b183 100755 --- a/tumblr/tumblr.php +++ b/tumblr/tumblr.php @@ -201,7 +201,10 @@ function tumblr_send(&$a,&$b) { if (($link != '') and $video) { $params['type'] = "video"; $params['embed'] = $link; - $params['caption'] = bbcode($body); + if ($b['title'] != '') + $params['caption'] = '

'.$b['title']."

".bbcode($body); + else + $params['caption'] = bbcode($body); } else if (($link != '') and !$video) { $params['type'] = "link"; $params['name'] = $b['title']; From a4c505489eea8f1a10145c695a727dda58a1aba3 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Wed, 9 May 2012 14:53:02 +0200 Subject: [PATCH 07/12] Tumblr: Some changes --- tumblr/tumblr.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tumblr/tumblr.php b/tumblr/tumblr.php index 650e0b183..648911ff9 100755 --- a/tumblr/tumblr.php +++ b/tumblr/tumblr.php @@ -202,14 +202,16 @@ function tumblr_send(&$a,&$b) { $params['type'] = "video"; $params['embed'] = $link; if ($b['title'] != '') - $params['caption'] = '

'.$b['title']."

".bbcode($body); + $params['caption'] = '

'.$b['title']. + "

".bbcode($body)."

"; 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($body); + $params['description'] = bbcode($b["body"]); } else { $params['type'] = "regular"; $params['title'] = $b['title']; From ff27645c78bac0bbbbdd5d8c6ef0b0ddc509142b Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Tue, 29 May 2012 16:41:20 +0200 Subject: [PATCH 08/12] This commit is useless :) --- facebook/facebook.php | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/facebook/facebook.php b/facebook/facebook.php index f70524a62..e7e2ab3e9 100644 --- a/facebook/facebook.php +++ b/facebook/facebook.php @@ -79,38 +79,38 @@ function facebook_init(&$a) { 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) { @@ -119,20 +119,20 @@ function facebook_init(&$a) { 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); @@ -146,11 +146,11 @@ function facebook_init(&$a) { } } } - + 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; @@ -162,7 +162,7 @@ function facebook_init(&$a) { } } - + if($a->argc != 2) return; $nick = $a->argv[1]; @@ -188,7 +188,7 @@ function facebook_init(&$a) { $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); @@ -404,6 +404,7 @@ function fb_get_friends($uid, $fullsync = true) { $access_token = get_pconfig($uid,'facebook','access_token'); $no_linking = get_pconfig($uid,'facebook','no_linking'); + if($no_linking) return; @@ -428,7 +429,7 @@ function fb_get_friends($uid, $fullsync = true) { } // 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 @@ -439,7 +440,7 @@ function facebook_post(&$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); @@ -452,7 +453,7 @@ function facebook_post(&$a) { $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']))); @@ -462,7 +463,7 @@ function facebook_post(&$a) { 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 From c43a3773c8337c4efbfa5f963f4cf888029055f3 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 17 Jun 2012 20:35:20 +0200 Subject: [PATCH 09/12] Libertree: Now the title is included in the message as well --- libertree/libertree.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/libertree/libertree.php b/libertree/libertree.php index 4f0c814d2..f57c773b3 100755 --- a/libertree/libertree.php +++ b/libertree/libertree.php @@ -167,16 +167,21 @@ function libertree_send(&$a,&$b) { } } if(count($tag_arr)) - $tags = implode(',',$tag_arr); + $tags = implode(',',$tag_arr); + $title = $b['title']; + $body = $b['body']; + + if(strlen($title)) + $body = "[b]".html_entity_decode($title)."[/b]\n\n".$body; $params = array( - 'text' => bb2diaspora($b['body']) + 'text' => bb2diaspora($body) // 'token' => $ltree_api_token ); $result = post_url($ltree_blog,$params); - logger('libertree: ' . $result); + logger('libertree: ' . $result); } } From 57441b4def0f4bb42044ea444b6c59bcaa166d61 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Mon, 18 Jun 2012 01:30:44 +0200 Subject: [PATCH 10/12] Fixed a bug where a title was set in a way that affected other addons. Additionally some changes to bb2markdown. --- facebook/facebook.php | 8 ++++---- statusnet/statusnet.php | 10 +++++----- tumblr/tumblr.php | 13 +++++++------ twitter/twitter.php | 4 ++-- wppost/wppost.php | 12 +++++++----- 5 files changed, 25 insertions(+), 22 deletions(-) diff --git a/facebook/facebook.php b/facebook/facebook.php index fd9adad53..6ff2a2ef0 100644 --- a/facebook/facebook.php +++ b/facebook/facebook.php @@ -941,7 +941,7 @@ function facebook_post_hook(&$a,&$b) { if($fb_token && ($toplevel || $b['private'] || $reply)) { logger('facebook: able to post'); require_once('library/facebook.php'); - require_once('include/bbcode.php'); + require_once('include/bbcode.php'); $msg = $b['body']; @@ -1016,7 +1016,7 @@ function facebook_post_hook(&$a,&$b) { } // At first convert the text to html - $html = bbcode($body); + $html = bbcode($body, false, false); // Then convert it to plain text $msg = trim($b['title']." \n\n".html2plain($html, 0, true)); @@ -1133,8 +1133,8 @@ function facebook_post_hook(&$a,&$b) { } 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']), + 'access_token' => $fb_token, + 'message' => bbcode($b['body'], false, false), 'subject' => $b['title'], ); $url = 'https://graph.facebook.com/me/notes'; diff --git a/statusnet/statusnet.php b/statusnet/statusnet.php index dd8761680..d7ec4abb3 100755 --- a/statusnet/statusnet.php +++ b/statusnet/statusnet.php @@ -426,15 +426,15 @@ function statusnet_post_hook(&$a,&$b) { if($ckey && $csecret && $otoken && $osecret) { - require_once('include/bbcode.php'); + require_once('include/bbcode.php'); $dent = new StatusNetOAuth($api,$ckey,$csecret,$otoken,$osecret); $max_char = $dent->get_maxlength(); // max. length for a dent // we will only work with up to two times the length of the dent - // we can later send to StatusNet. This way we can "gain" some - // information during shortening of potential links but do not + // we can later send to StatusNet. This way we can "gain" some + // information during shortening of potential links but do not // shorten all the links in a 200000 character long essay. if (! $b['title']=='') { - $tmp = $b['title'] . ' : '. $b['body']; + $tmp = $b['title'].": \n".$b['body']; // $tmp = substr($tmp, 0, 4*$max_char); } else { $tmp = $b['body']; // substr($b['body'], 0, 3*$max_char); @@ -476,7 +476,7 @@ function statusnet_post_hook(&$a,&$b) { } // ok, all the links we want to send out are save, now strip // away the remaining bbcode - $msg = strip_tags(bbcode($tmp)); + $msg = strip_tags(bbcode($tmp, false, false)); // quotes not working - let's try this $msg = html_entity_decode($msg); if (( strlen($msg) > $max_char) && $max_char > 0) { diff --git a/tumblr/tumblr.php b/tumblr/tumblr.php index a39bc9d69..03a67949b 100755 --- a/tumblr/tumblr.php +++ b/tumblr/tumblr.php @@ -170,12 +170,13 @@ function tumblr_send(&$a,&$b) { $link = ""; $video = false; + $title = trim($b['title']); // 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'); + if ($title == '') + $title = html_entity_decode($matches[2],ENT_QUOTES,'UTF-8'); $body = $b['body']; // splitting the text in two parts: @@ -201,20 +202,20 @@ function tumblr_send(&$a,&$b) { if (($link != '') and $video) { $params['type'] = "video"; $params['embed'] = $link; - if ($b['title'] != '') - $params['caption'] = '

'.$b['title']. + if ($title != '') + $params['caption'] = '

'.$title. "

".bbcode($body)."

"; else $params['caption'] = bbcode($body); } else if (($link != '') and !$video) { $params['type'] = "link"; - $params['name'] = $b['title']; + $params['name'] = $title; $params['url'] = $link; //$params['description'] = bbcode($body); $params['description'] = bbcode($b["body"]); } else { $params['type'] = "regular"; - $params['title'] = $b['title']; + $params['title'] = $title; $params['body'] = bbcode($b['body']); } diff --git a/twitter/twitter.php b/twitter/twitter.php index 0ac9396df..8de7d06d6 100755 --- a/twitter/twitter.php +++ b/twitter/twitter.php @@ -290,7 +290,7 @@ function twitter_post_hook(&$a,&$b) { logger('twitter: we have customer key and oauth stuff, going to send.', LOGGER_DEBUG); require_once('library/twitteroauth.php'); - require_once('include/bbcode.php'); + require_once('include/bbcode.php'); $tweet = new TwitterOAuth($ckey,$csecret,$otoken,$osecret); // in theory max char is 140 but T. uses t.co to make links // longer so we give them 10 characters extra @@ -341,7 +341,7 @@ function twitter_post_hook(&$a,&$b) { } // ok, all the links we want to send out are save, now strip // away the remaining bbcode - $msg = strip_tags(bbcode($tmp)); + $msg = strip_tags(bbcode($tmp, false, false)); // quotes not working - let's try this $msg = html_entity_decode($msg); if (( strlen($msg) > $max_char) && $max_char > 0) { diff --git a/wppost/wppost.php b/wppost/wppost.php index ee9acb0d4..e8b6fc6d5 100755 --- a/wppost/wppost.php +++ b/wppost/wppost.php @@ -179,24 +179,26 @@ function wppost_send(&$a,&$b) { require_once('include/bbcode.php'); require_once('include/html2plain.php'); + $wptitle = trim($b['title']); + // If the title is empty then try to guess - if ($b['title'] == '') { + if ($wptitle == '') { // Take the description from the bookmark if(preg_match("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/is",$b['body'],$matches)) - $b['title'] = $matches[2]; + $wptitle = $matches[2]; // If no bookmark is found then take the first line - if ($b['title'] == '') { + if ($wptitle == '') { $title = html2plain(bbcode($b['body']), 0, true); $pos = strpos($title, "\n"); if (($pos == 0) or ($pos > 60)) $pos = 60; - $b['title'] = substr($title, 0, $pos); + $wptitle = substr($title, 0, $pos); } } - $title = '' . (($b['title']) ? $b['title'] : t('Post from Friendica')) . ''; + $title = '' . (($wptitle) ? $wptitle : t('Post from Friendica')) . ''; $post = $title . bbcode($b['body']); $wp_backlink = intval(get_pconfig($b['uid'],'wppost','backlink')); From fe7c741eed1afa26ddab7a07cbe5d1944d3d1584 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Mon, 18 Jun 2012 21:54:35 +0200 Subject: [PATCH 11/12] Libertree: Improve the format of postings --- libertree/libertree.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/libertree/libertree.php b/libertree/libertree.php index f57c773b3..fc9dcc44d 100755 --- a/libertree/libertree.php +++ b/libertree/libertree.php @@ -172,11 +172,25 @@ function libertree_send(&$a,&$b) { $title = $b['title']; $body = $b['body']; + // Insert a newline before and after a quote + $body = str_ireplace("[quote", "\n\n[quote", $body); + $body = str_ireplace("[/quote]", "[/quote]\n\n", $body); + + // remove multiple newlines + do { + $oldbody = $body; + $body = str_replace("\n\n\n", "\n\n", $body); + } while ($oldbody != $body); + + // convert to markdown + $body = bb2diaspora($body); + + // Adding the title if(strlen($title)) - $body = "[b]".html_entity_decode($title)."[/b]\n\n".$body; + $body = "## ".html_entity_decode($title)."\n\n".$body; $params = array( - 'text' => bb2diaspora($body) + 'text' => $body // 'token' => $ltree_api_token ); From 471b5db36feedc9c71ab862a7c35478633bebfa9 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sat, 23 Jun 2012 12:50:48 +0200 Subject: [PATCH 12/12] Twitter, Statusnet: Supress profile link of user whose message was repeated libertree: Design improvement of exported messages privacy_image_cache: quickfix for double encoded urls --- libertree/libertree.php | 8 +++++- privacy_image_cache/privacy_image_cache.php | 30 +++++++++++---------- statusnet/statusnet.php | 14 +++++++--- twitter/twitter.php | 20 +++++++++----- 4 files changed, 46 insertions(+), 26 deletions(-) diff --git a/libertree/libertree.php b/libertree/libertree.php index fc9dcc44d..c117fa811 100755 --- a/libertree/libertree.php +++ b/libertree/libertree.php @@ -118,7 +118,7 @@ function libertree_post_local(&$a,&$b) { if($b['private'] || $b['parent']) return; - $ltree_post = intval(get_pconfig(local_user(),'libertree','post')); + $ltree_post = intval(get_pconfig(local_user(),'libertree','post')); $ltree_enable = (($ltree_post && x($_REQUEST,'libertree_enable')) ? intval($_REQUEST['libertree_enable']) : 0); @@ -176,6 +176,12 @@ function libertree_send(&$a,&$b) { $body = str_ireplace("[quote", "\n\n[quote", $body); $body = str_ireplace("[/quote]", "[/quote]\n\n", $body); + // Removal of tags and mentions + // #-tags + $body = preg_replace('/#\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', '#$2', $body); + // @-mentions + $body = preg_replace('/@\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', '@$2', $body); + // remove multiple newlines do { $oldbody = $body; diff --git a/privacy_image_cache/privacy_image_cache.php b/privacy_image_cache/privacy_image_cache.php index d3202c4d7..b7236d09d 100644 --- a/privacy_image_cache/privacy_image_cache.php +++ b/privacy_image_cache/privacy_image_cache.php @@ -36,16 +36,18 @@ function privacy_image_cache_init() { } $urlhash = 'pic:' . sha1($_REQUEST['url']); - $r = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' LIMIT 1", $urlhash ); - if (count($r)) { - $img_str = $r[0]['data']; + // Double encoded url - happens with Diaspora + $urlhash2 = 'pic:' . sha1(urldecode($_REQUEST['url'])); + + $r = q("SELECT * FROM `photo` WHERE `resource-id` in ('%s', '%s') LIMIT 1", $urlhash, $urlhash2); + if (count($r)) { + $img_str = $r[0]['data']; $mime = $r[0]["desc"]; if ($mime == "") $mime = "image/jpeg"; - } - else { - require_once("Photo.php"); + } else { + require_once("Photo.php"); - $img_str = fetch_url($_REQUEST['url'],true); + $img_str = fetch_url($_REQUEST['url'],true); if (substr($img_str, 0, 6) == "GIF89a") { $mime = "image/gif"; $image = @imagecreatefromstring($img_str); @@ -77,16 +79,16 @@ function privacy_image_cache_init() { } $mime = "image/jpeg"; } - } + } - header("Content-type: $mime"); - header("Expires: " . gmdate("D, d M Y H:i:s", time() + (3600*24)) . " GMT"); - header("Cache-Control: max-age=" . (3600*24)); + header("Content-type: $mime"); + header("Expires: " . gmdate("D, d M Y H:i:s", time() + (3600*24)) . " GMT"); + header("Cache-Control: max-age=" . (3600*24)); - echo $img_str; + echo $img_str; - killme(); + killme(); } /** @@ -210,4 +212,4 @@ function privacy_image_cache_plugin_admin_post(&$a = null, &$o = null){ if (isset($_REQUEST['delete_all'])) { q('DELETE FROM `photo` WHERE `uid` = 0 AND `resource-id` LIKE "pic:%%"'); } -} \ No newline at end of file +} diff --git a/statusnet/statusnet.php b/statusnet/statusnet.php index d7ec4abb3..99e844752 100755 --- a/statusnet/statusnet.php +++ b/statusnet/statusnet.php @@ -453,10 +453,16 @@ function statusnet_post_hook(&$a,&$b) { // that is, don't send if the option is not set in the // connector settings if ($linksenabled=='0') { - // #-tags - $tmp = preg_replace( '/#\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', '#$2', $tmp); - // @-mentions - $tmp = preg_replace( '/@\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', '@$2', $tmp); + // #-tags + $tmp = preg_replace( '/#\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', '#$2', $tmp); + // @-mentions + $tmp = preg_replace( '/@\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', '@$2', $tmp); + // recycle 1 + $recycle = html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8'); + $tmp = preg_replace( '/'.$recycle.'\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', $recycle.'$2', $tmp); + // recycle 2 + //$recycle = html_entity_decode("♻ ", ENT_QUOTES, 'UTF-8'); + //$tmp = preg_replace( '/'.$recycle.'\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', 'RT @$2:', $tmp); } // preserve links to webpages $tmp = preg_replace( '/\[url\=(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)\](\w+.*?)\[\/url\]/i', '$2 $1', $tmp); diff --git a/twitter/twitter.php b/twitter/twitter.php index 8de7d06d6..9984f3695 100755 --- a/twitter/twitter.php +++ b/twitter/twitter.php @@ -316,18 +316,24 @@ function twitter_post_hook(&$a,&$b) { $tmp = preg_replace( '/\[\\/?audio(\\s+.*?\]|\])/i', '', $tmp); $linksenabled = get_pconfig($b['uid'],'twitter','post_taglinks'); // if a #tag is linked, don't send the [url] over to SN - // that is, don't send if the option is not set in the + // that is, don't send if the option is not set in the // connector settings if ($linksenabled=='0') { - // #-tags - $tmp = preg_replace( '/#\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', '#$2', $tmp); - // @-mentions - $tmp = preg_replace( '/@\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', '@$2', $tmp); + // #-tags + $tmp = preg_replace( '/#\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', '#$2', $tmp); + // @-mentions + $tmp = preg_replace( '/@\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', '@$2', $tmp); + // recycle 1 + $recycle = html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8'); + $tmp = preg_replace( '/'.$recycle.'\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', $recycle.'$2', $tmp); + // recycle 2 + //$recycle = html_entity_decode("♻ ", ENT_QUOTES, 'UTF-8'); + //$tmp = preg_replace( '/'.$recycle.'\[url\=(\w+.*?)\](\w+.*?)\[\/url\]/i', 'RT @$2:', $tmp); } $tmp = preg_replace( '/\[url\=(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)\](\w+.*?)\[\/url\]/i', '$2 $1', $tmp); $tmp = preg_replace( '/\[bookmark\=(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)\](\w+.*?)\[\/bookmark\]/i', '$2 $1', $tmp); - // find all http or https links in the body of the entry and - // apply the shortener if the link is longer then 20 characters + // find all http or https links in the body of the entry and + // apply the shortener if the link is longer then 20 characters if (( strlen($tmp)>$max_char ) && ( $max_char > 0 )) { preg_match_all ( '/(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/i', $tmp, $allurls ); foreach ($allurls as $url) {