From a00464cd984ee824a7a4d5a95ece66841d6dfb7d Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 14 Jul 2013 14:58:12 +0200 Subject: [PATCH 1/6] twitter and statusnet: Now Newlines are transmitted. wppost: The title is now shortened with a "..." --- statusnet/statusnet.php | 2 +- twitter/twitter.php | 2 +- wppost/wppost.php | 11 +++++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/statusnet/statusnet.php b/statusnet/statusnet.php index b3450d95..2171acf4 100755 --- a/statusnet/statusnet.php +++ b/statusnet/statusnet.php @@ -563,7 +563,7 @@ function statusnet_shortenmsg($b, $max_char) { else if ($lastchar != "\n") $msg = substr($msg, 0, -3)."..."; } - $msg = str_replace("\n", " ", $msg); + //$msg = str_replace("\n", " ", $msg); // Removing multiple spaces - again while (strpos($msg, " ") !== false) diff --git a/twitter/twitter.php b/twitter/twitter.php index 1b9f2c1b..29f3795b 100755 --- a/twitter/twitter.php +++ b/twitter/twitter.php @@ -445,7 +445,7 @@ function twitter_shortenmsg($b) { else if ($lastchar != "\n") $msg = substr($msg, 0, -3)."..."; } - $msg = str_replace("\n", " ", $msg); + //$msg = str_replace("\n", " ", $msg); // Removing multiple spaces - again while (strpos($msg, " ") !== false) diff --git a/wppost/wppost.php b/wppost/wppost.php index e8b6fc6d..b0c3dd91 100755 --- a/wppost/wppost.php +++ b/wppost/wppost.php @@ -189,12 +189,15 @@ function wppost_send(&$a,&$b) { // If no bookmark is found then take the first line if ($wptitle == '') { - $title = html2plain(bbcode($b['body']), 0, true); + $title = html2plain(bbcode($b['body']), 0, true)."\n"; $pos = strpos($title, "\n"); - if (($pos == 0) or ($pos > 60)) - $pos = 60; + $trailer = ""; + if (($pos == 0) or ($pos > 100)) { + $pos = 100; + $trailer = "..."; + } - $wptitle = substr($title, 0, $pos); + $wptitle = substr($title, 0, $pos).$trailer; } } From 37940d007028a0233f13da9c65eddccdc8575e3e Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 14 Jul 2013 16:26:18 +0200 Subject: [PATCH 2/6] Twitter+Statusnet: Between message and link there is now a linefeed. --- statusnet/statusnet.php | 2 +- twitter/twitter.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/statusnet/statusnet.php b/statusnet/statusnet.php index 2171acf4..6b4c8010 100755 --- a/statusnet/statusnet.php +++ b/statusnet/statusnet.php @@ -569,7 +569,7 @@ function statusnet_shortenmsg($b, $max_char) { while (strpos($msg, " ") !== false) $msg = str_replace(" ", " ", $msg); - return(array("msg"=>trim($msg." ".$msglink), "image"=>$image)); + return(array("msg"=>trim($msg."\n".$msglink), "image"=>$image)); } function statusnet_post_hook(&$a,&$b) { diff --git a/twitter/twitter.php b/twitter/twitter.php index 29f3795b..775072e0 100755 --- a/twitter/twitter.php +++ b/twitter/twitter.php @@ -452,7 +452,7 @@ function twitter_shortenmsg($b) { $msg = str_replace(" ", " ", $msg); //return(trim($msg." ".$msglink)); - return(trim($msg." ".$orig_link)); + return(trim($msg."\n".$orig_link)); } function twitter_post_hook(&$a,&$b) { From e7f5f0cf200407bac24af30e818f2d11378b8e30 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Mon, 15 Jul 2013 06:56:23 +0200 Subject: [PATCH 3/6] pumpio: Changed nonce for oAuth from md5 to sha1 - hopefully now more posts come through --- pumpio/oauth/oauth_client.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pumpio/oauth/oauth_client.php b/pumpio/oauth/oauth_client.php index 5047e0e9..2a709aab 100644 --- a/pumpio/oauth/oauth_client.php +++ b/pumpio/oauth/oauth_client.php @@ -1013,7 +1013,8 @@ class oauth_client_class { $values = array( 'oauth_consumer_key'=>$this->client_id, - 'oauth_nonce'=>md5(uniqid(rand(), true)), + //'oauth_nonce'=>md5(uniqid(rand(), true)), + 'oauth_nonce'=>sha1(uniqid(mt_rand(), true).uniqid(mt_rand(), true)), 'oauth_signature_method'=>$this->signature_method, 'oauth_timestamp'=>time(), 'oauth_version'=>'1.0', @@ -2173,4 +2174,4 @@ class oauth_client_class */ -?> \ No newline at end of file +?> From 804bc7a0673cab728195aa538fdd924dff2f0a6c Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Fri, 19 Jul 2013 23:34:54 +0200 Subject: [PATCH 4/6] Mirroring: There was a problem that the title variable wasn't cleared so it could be fetched from a previous post. Statusnet: The activity messages are now suppressed --- fbpost/fbpost.php | 3 +++ fromgplus/fromgplus.php | 1 + public_server/public_server.php | 5 ++++- pumpio/pumpio.php | 13 ++++++++++--- statusnet/statusnet.php | 6 ++++++ twitter/twitter.php | 3 +++ 6 files changed, 27 insertions(+), 4 deletions(-) diff --git a/fbpost/fbpost.php b/fbpost/fbpost.php index ba60f4e6..1167376a 100644 --- a/fbpost/fbpost.php +++ b/fbpost/fbpost.php @@ -1052,11 +1052,14 @@ function fbpost_fetchwall($a, $uid) { $_SESSION["authenticated"] = true; $_SESSION["uid"] = $uid; + unset($_REQUEST); $_REQUEST["type"] = "wall"; $_REQUEST["api_source"] = true; $_REQUEST["profile_uid"] = $uid; $_REQUEST["source"] = "Facebook"; + $_REQUEST["title"] = ""; + $_REQUEST["body"] = (isset($item->message) ? escape_tags($item->message) : ''); if(isset($item->name) and isset($item->link)) diff --git a/fromgplus/fromgplus.php b/fromgplus/fromgplus.php index 5d0e86c3..fdd0b579 100644 --- a/fromgplus/fromgplus.php +++ b/fromgplus/fromgplus.php @@ -109,6 +109,7 @@ function fromgplus_post($a, $uid, $source, $body, $location) { $_SESSION['authenticated'] = true; $_SESSION['uid'] = $uid; + unset($_REQUEST); $_REQUEST['type'] = 'wall'; $_REQUEST['api_source'] = true; diff --git a/public_server/public_server.php b/public_server/public_server.php index 3711854f..becf96c3 100644 --- a/public_server/public_server.php +++ b/public_server/public_server.php @@ -43,9 +43,11 @@ function public_server_register_account($a,$b) { ); }; - + function public_server_cron($a,$b) { + logger("public_server: cron start"); + require_once('include/enotify.php'); $r = q("select * from user where account_expires_on < UTC_TIMESTAMP() + INTERVAL 5 DAY and account_expires_on > '0000-00-00 00:00:00' and expire_notification_sent = '0000-00-00 00:00:00' "); @@ -116,6 +118,7 @@ function public_server_cron($a,$b) { } } + logger("public_server: cron end"); } diff --git a/pumpio/pumpio.php b/pumpio/pumpio.php index da723eca..f85e8bd9 100755 --- a/pumpio/pumpio.php +++ b/pumpio/pumpio.php @@ -385,14 +385,16 @@ function pumpio_send(&$a,&$b) { $client->client_id = $consumer_key; $client->client_secret = $consumer_secret; + $username = $user.'@'.$host; + $success = $client->CallAPI( 'https://'.$host.'/api/user/'.$user.'/feed', 'POST', $params, array('FailOnAccessError'=>true, 'RequestContentType'=>'application/json'), $user); if($success) - logger('pumpio_send: success'); + logger('pumpio_send '.$username.': success'); else - logger('pumpio_send: general error: ' . print_r($user,true)); + logger('pumpio_send '.$username.': general error: ' . print_r($user,true)); } } @@ -456,10 +458,12 @@ function pumpio_fetchtimeline($a, $uid) { logger('pumpio: fetching for user '.$uid.' '.$url.' C:'.$client->client_id.' CS:'.$client->client_secret.' T:'.$client->access_token.' TS:'.$client->access_token_secret); + $username = $user.'@'.$host; + $success = $client->CallAPI($url, 'GET', array(), array('FailOnAccessError'=>true), $user); if (!$success) { - logger('pumpio: error fetching posts for user '.$uid." ".print_r($user, true)); + logger('pumpio: error fetching posts for user '.$uid." ".$username." ".print_r($user, true)); return; } @@ -498,6 +502,7 @@ function pumpio_fetchtimeline($a, $uid) { $_SESSION["authenticated"] = true; $_SESSION["uid"] = $uid; + unset($_REQUEST); $_REQUEST["type"] = "wall"; $_REQUEST["api_source"] = true; $_REQUEST["profile_uid"] = $uid; @@ -505,6 +510,8 @@ function pumpio_fetchtimeline($a, $uid) { if ($post->object->displayName != "") $_REQUEST["title"] = html2bbcode($post->object->displayName); + else + $_REQUEST["title"] = ""; $_REQUEST["body"] = html2bbcode($post->object->content); diff --git a/statusnet/statusnet.php b/statusnet/statusnet.php index 6b4c8010..bd2312f7 100755 --- a/statusnet/statusnet.php +++ b/statusnet/statusnet.php @@ -855,6 +855,9 @@ function statusnet_fetchtimeline($a, $uid) { if ($first_time) continue; + if ($post->source == "activity") + continue; + if (is_object($post->retweeted_status)) continue; @@ -865,6 +868,7 @@ function statusnet_fetchtimeline($a, $uid) { $_SESSION["authenticated"] = true; $_SESSION["uid"] = $uid; + unset($_REQUEST); $_REQUEST["type"] = "wall"; $_REQUEST["api_source"] = true; $_REQUEST["profile_uid"] = $uid; @@ -872,6 +876,8 @@ function statusnet_fetchtimeline($a, $uid) { //$_REQUEST["date"] = $post->created_at; + $_REQUEST["title"] = ""; + $_REQUEST["body"] = $post->text; if (is_string($post->place->name)) $_REQUEST["location"] = $post->place->name; diff --git a/twitter/twitter.php b/twitter/twitter.php index 775072e0..5e01db95 100755 --- a/twitter/twitter.php +++ b/twitter/twitter.php @@ -678,6 +678,7 @@ function twitter_fetchtimeline($a, $uid) { $_SESSION["authenticated"] = true; $_SESSION["uid"] = $uid; + unset($_REQUEST); $_REQUEST["type"] = "wall"; $_REQUEST["api_source"] = true; $_REQUEST["profile_uid"] = $uid; @@ -685,6 +686,8 @@ function twitter_fetchtimeline($a, $uid) { //$_REQUEST["date"] = $post->created_at; + $_REQUEST["title"] = ""; + $_REQUEST["body"] = $post->text; if (is_string($post->place->name)) $_REQUEST["location"] = $post->place->name; From aaee2a92604f299f2291f57ee8e177399d72978a Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sat, 20 Jul 2013 14:28:17 +0200 Subject: [PATCH 5/6] wppost: Posting a youtube video now embeds it. --- fbpost/fbpost.php | 34 ---------------------------------- wppost/wppost.php | 12 +++++++++--- 2 files changed, 9 insertions(+), 37 deletions(-) diff --git a/fbpost/fbpost.php b/fbpost/fbpost.php index 1167376a..be9fc290 100644 --- a/fbpost/fbpost.php +++ b/fbpost/fbpost.php @@ -529,40 +529,6 @@ function fbpost_post_hook(&$a,&$b) { // if($b['verb'] == ACTIVITY_DISLIKE) // $msg = trim(strip_tags(bbcode($msg))); - // Old code - /*$search_str = $a->get_baseurl() . '/search'; - - if(preg_match("/\[url=(.*?)\](.*?)\[\/url\]/is",$msg,$matches)) { - - // don't use hashtags for message link - - if(strpos($matches[2],$search_str) === false) { - $link = $matches[1]; - if(substr($matches[2],0,5) != '[img]') - $linkname = $matches[2]; - } - } - - // strip tag links to avoid link clutter, this really should be - // configurable because we're losing information - - $msg = preg_replace("/\#\[url=(.*?)\](.*?)\[\/url\]/is",'#$2',$msg); - - // provide the link separately for normal links - $msg = preg_replace("/\[url=(.*?)\](.*?)\[\/url\]/is",'$2 $1',$msg); - - if(preg_match("/\[img\](.*?)\[\/img\]/is",$msg,$matches)) - $image = $matches[1]; - - $msg = preg_replace("/\[img\](.*?)\[\/img\]/is", t('Image: ') . '$1', $msg); - - if((strpos($link,z_root()) !== false) && (! $image)) - $image = $a->get_baseurl() . '/images/friendica-64.jpg'; - - $msg = trim(strip_tags(bbcode($msg)));*/ - - // New code - // Looking for the first image $image = ''; if(preg_match("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/is",$b['body'],$matches)) diff --git a/wppost/wppost.php b/wppost/wppost.php index b0c3dd91..a6574cc2 100755 --- a/wppost/wppost.php +++ b/wppost/wppost.php @@ -189,7 +189,7 @@ function wppost_send(&$a,&$b) { // If no bookmark is found then take the first line if ($wptitle == '') { - $title = html2plain(bbcode($b['body']), 0, true)."\n"; + $title = html2plain(bbcode($b['body'], false, false), 0, true)."\n"; $pos = strpos($title, "\n"); $trailer = ""; if (($pos == 0) or ($pos > 100)) { @@ -202,11 +202,17 @@ function wppost_send(&$a,&$b) { } $title = '' . (($wptitle) ? $wptitle : t('Post from Friendica')) . ''; - $post = $title . bbcode($b['body']); + $post = bbcode($b['body'], false, false); + + // If a link goes to youtube then remove the stuff around it. Wordpress detects youtube links and embeds it + $post = preg_replace('/(.*?)<\/a>/ism',"\n$1\n",$post); + $post = preg_replace('/(.*?)<\/a>/ism',"\n$1\n",$post); + + $post = $title.$post; $wp_backlink = intval(get_pconfig($b['uid'],'wppost','backlink')); if($wp_backlink && $b['plink']) - $post .= EOL . EOL . '' + $post .= EOL . EOL . '' . t('Read the original post and comment stream on Friendica') . '' . EOL . EOL; $post = xmlify($post); From 3d83a2415c96417b8be8ce1772de674f896bfce3 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sat, 20 Jul 2013 14:58:42 +0200 Subject: [PATCH 6/6] pumpio: Youtube- and vimeo videos have now a preview image. --- pumpio/pumpio.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pumpio/pumpio.php b/pumpio/pumpio.php index f85e8bd9..60d8e82f 100755 --- a/pumpio/pumpio.php +++ b/pumpio/pumpio.php @@ -363,13 +363,24 @@ function pumpio_send(&$a,&$b) { if ($title != '') $title = "

".$title."

"; + $content = bbcode($b['body'], false, false); + + // Enhance the way, videos are displayed + $content = preg_replace('/(.*?)<\/a>/ism',"\n[url]$1[/url]\n",$content); + $content = preg_replace('/(.*?)<\/a>/ism',"\n$1\n",$content); + $content = preg_replace('/(.*?)<\/a>/ism',"\n$1\n",$content); + $content = preg_replace('/(.*?)<\/a>/ism',"\n$1\n",$content); + + $URLSearchString = "^\[\]"; + $content = preg_replace_callback("/\[url\]([$URLSearchString]*)\[\/url\]/ism",'tryoembed',$content); + $params = array(); $params["verb"] = "post"; $params["object"] = array( 'objectType' => "note", - 'content' => $title.bbcode($b['body'], false, false)); + 'content' => $title.$content); if ($public) $params["to"] = array(Array(