From 0a6d1f9e492459aed2607b2432438b66b50bc4f8 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Wed, 25 Jun 2014 01:20:04 +0200 Subject: [PATCH 01/12] app.net, pump.io, statusnet, twitter: There were situations, when contacts were added by mistake. --- appnet/appnet.php | 11 +++++++++++ fbsync/fbsync.php | 3 +++ pumpio/pumpio.php | 3 +++ statusnet/statusnet.php | 2 ++ twitter/twitter.php | 2 ++ 5 files changed, 21 insertions(+) diff --git a/appnet/appnet.php b/appnet/appnet.php index de1dd970..acbd5ce5 100644 --- a/appnet/appnet.php +++ b/appnet/appnet.php @@ -856,6 +856,8 @@ function appnet_createpost($a, $uid, $post, $me, $user, $ownid, $createuser, $th } } } + // Don't create accounts of people who just comment something + $createuser = false; } else $postarray['thr-parent'] = $postarray['uri']; @@ -1042,6 +1044,8 @@ function appnet_fetchcontact($a, $uid, $contact, $me, $create_user) { if(!count($r) AND !$create_user) return($me); + if ($contact["canonical_url"] == "") + return($me); if (count($r) AND ($r[0]["readonly"] OR $r[0]["blocked"])) { logger("appnet_fetchcontact: Contact '".$r[0]["nick"]."' is blocked or readonly.", LOGGER_DEBUG); @@ -1049,6 +1053,13 @@ function appnet_fetchcontact($a, $uid, $contact, $me, $create_user) { } if(!count($r)) { + + if ($contact["name"] == "") + $contact["name"] = $contact["username"]; + + if ($contact["username"] == "") + $contact["username"] = $contact["name"]; + // create contact record q("INSERT INTO `contact` (`uid`, `created`, `url`, `nurl`, `addr`, `alias`, `notify`, `poll`, `name`, `nick`, `photo`, `network`, `rel`, `priority`, diff --git a/fbsync/fbsync.php b/fbsync/fbsync.php index 85859151..14de4df2 100644 --- a/fbsync/fbsync.php +++ b/fbsync/fbsync.php @@ -278,6 +278,9 @@ function fbsync_createpost($a, $uid, $self, $contacts, $applications, $post, $cr } if ($contact_id <= 0) { + // To-Do: + // $contacts[$post->source_id] seems to be wrong by repeated posts + // must be changed in future $contact_id = fbsync_fetch_contact($uid, $contacts[$post->source_id], $create_user); if ($contact_id == -1) { diff --git a/pumpio/pumpio.php b/pumpio/pumpio.php index 62467414..c9eb0208 100644 --- a/pumpio/pumpio.php +++ b/pumpio/pumpio.php @@ -888,6 +888,9 @@ function pumpio_dolike(&$a, $uid, $self, $post, $own_id) { function pumpio_get_contact($uid, $contact) { + if (($contact->url == "") OR ($contact->id == 0)) + return(false); + $r = q("SELECT id FROM unique_contacts WHERE url='%s' LIMIT 1", dbesc(normalise_link($contact->url))); diff --git a/statusnet/statusnet.php b/statusnet/statusnet.php index 7293f882..2f3f84d2 100644 --- a/statusnet/statusnet.php +++ b/statusnet/statusnet.php @@ -1059,6 +1059,8 @@ function statusnet_createpost($a, $uid, $post, $self, $create_user, $only_existi } else return(array()); } + // Don't create accounts of people who just comment something + $create_user = false; } else $postarray['parent-uri'] = $postarray['uri']; diff --git a/twitter/twitter.php b/twitter/twitter.php index b6d0d3af..d2dc4fd6 100644 --- a/twitter/twitter.php +++ b/twitter/twitter.php @@ -1232,6 +1232,8 @@ function twitter_createpost($a, $uid, $post, $self, $create_user, $only_existing } else return(array()); } + // Don't create accounts of people who just comment something + $create_user = false; } else $postarray['parent-uri'] = $postarray['uri']; -- 2.45.2 From 97fe8aef5cbd8f227c0bb79f3b31e94aab25cb0c Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Wed, 25 Jun 2014 09:11:09 +0200 Subject: [PATCH 02/12] fbsync: prevent falsely added copntacts --- fbsync/fbsync.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/fbsync/fbsync.php b/fbsync/fbsync.php index 14de4df2..bcd4e5a8 100644 --- a/fbsync/fbsync.php +++ b/fbsync/fbsync.php @@ -278,10 +278,19 @@ function fbsync_createpost($a, $uid, $self, $contacts, $applications, $post, $cr } if ($contact_id <= 0) { - // To-Do: - // $contacts[$post->source_id] seems to be wrong by repeated posts - // must be changed in future - $contact_id = fbsync_fetch_contact($uid, $contacts[$post->source_id], $create_user); + if ($post->actor_id != $post->source_id) { + // Testing if we know the source or the actor + $contact_id = fbsync_fetch_contact($uid, $contacts[$post->source_id], false); + + if (($contact_id == 0) and array_key_exists($post->actor_id, $contacts)) + $contact_id = fbsync_fetch_contact($uid, $contacts[$post->actor_id], false); + + // If we don't know anyone, we guess we should know the source. Could be the wrong decision + if ($contact_id == 0) + $contact_id = fbsync_fetch_contact($uid, $contacts[$post->source_id], $create_user); + } else + $contact_id = fbsync_fetch_contact($uid, $contacts[$post->source_id], $create_user); + if ($contact_id == -1) { logger('fbsync_createpost: Contact is blocked. Post not imported '.print_r($post, true), LOGGER_DEBUG); -- 2.45.2 From a2dc41e8de901a5abfc6e146f714ae62c566e1a9 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Wed, 25 Jun 2014 10:29:38 +0200 Subject: [PATCH 03/12] pumpio: Reverting programming that checks for invalid contacts --- pumpio/pumpio.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/pumpio/pumpio.php b/pumpio/pumpio.php index c9eb0208..62467414 100644 --- a/pumpio/pumpio.php +++ b/pumpio/pumpio.php @@ -888,9 +888,6 @@ function pumpio_dolike(&$a, $uid, $self, $post, $own_id) { function pumpio_get_contact($uid, $contact) { - if (($contact->url == "") OR ($contact->id == 0)) - return(false); - $r = q("SELECT id FROM unique_contacts WHERE url='%s' LIMIT 1", dbesc(normalise_link($contact->url))); -- 2.45.2 From 6e298f7e63fac9bd6454d8bef5dd753a9cfee814 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Wed, 25 Jun 2014 19:34:02 +0200 Subject: [PATCH 04/12] app.net: Don't create contacts for threads we only complete --- appnet/appnet.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appnet/appnet.php b/appnet/appnet.php index acbd5ce5..4bf72da5 100644 --- a/appnet/appnet.php +++ b/appnet/appnet.php @@ -851,7 +851,7 @@ function appnet_createpost($a, $uid, $post, $me, $user, $ownid, $createuser, $th } $thread = array_reverse($thread); foreach ($thread AS $tpost) { - $threadpost = appnet_createpost($a, $uid, $tpost, $me, $user, $ownid, $createuser, false); + $threadpost = appnet_createpost($a, $uid, $tpost, $me, $user, $ownid, false, false); $item = item_store($threadpost); } } -- 2.45.2 From f0efa3cae2ce1f3e6ed9a2b016abe96f0ce1b75d Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Fri, 27 Jun 2014 07:59:00 +0200 Subject: [PATCH 05/12] appnet, statusnet: Posts from unknown contacts weren't posted --- appnet/appnet.php | 24 +++++++++++++++--------- statusnet/statusnet.php | 2 +- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/appnet/appnet.php b/appnet/appnet.php index 4bf72da5..62b66c32 100644 --- a/appnet/appnet.php +++ b/appnet/appnet.php @@ -825,13 +825,15 @@ function appnet_createpost($a, $uid, $post, $me, $user, $ownid, $createuser, $th if (isset($post["reply_to"]) AND ($post["reply_to"] != "")) { $postarray['thr-parent'] = "adn::".$post["reply_to"]; - // Complete the thread if the parent doesn't exists + // Complete the thread (if the parent doesn't exists) if ($threadcompletion) { - $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", - dbesc($postarray['thr-parent']), - intval($uid) - ); - if (!count($r)) { + //$r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", + // dbesc($postarray['thr-parent']), + // intval($uid) + // ); + //if (!count($r)) { + logger("appnet_createpost: completing thread ".$post["thread_id"]." for user ".$uid, LOGGER_DEBUG); + require_once("addon/appnet/AppDotNet.php"); $token = get_pconfig($uid,'appnet','token'); @@ -850,11 +852,15 @@ function appnet_createpost($a, $uid, $post, $me, $user, $ownid, $createuser, $th logger("appnet_createpost: Error fetching thread for user ".$uid." ".appnet_error($e->getMessage())); } $thread = array_reverse($thread); + + logger("appnet_createpost: fetched ".count($thread)." items for thread ".$post["thread_id"]." for user ".$uid, LOGGER_DEBUG); + foreach ($thread AS $tpost) { $threadpost = appnet_createpost($a, $uid, $tpost, $me, $user, $ownid, false, false); $item = item_store($threadpost); + logger("appnet_createpost: stored post ".$post["id"]." thread ".$post["thread_id"]." in item ".$item, LOGGER_DEBUG); } - } + //} } // Don't create accounts of people who just comment something $createuser = false; @@ -1042,10 +1048,10 @@ function appnet_fetchcontact($a, $uid, $contact, $me, $create_user) { intval($uid), dbesc("adn::".$contact["id"])); if(!count($r) AND !$create_user) - return($me); + return($me["id"]); if ($contact["canonical_url"] == "") - return($me); + return($me["id"]); if (count($r) AND ($r[0]["readonly"] OR $r[0]["blocked"])) { logger("appnet_fetchcontact: Contact '".$r[0]["nick"]."' is blocked or readonly.", LOGGER_DEBUG); diff --git a/statusnet/statusnet.php b/statusnet/statusnet.php index 2f3f84d2..38381ef3 100644 --- a/statusnet/statusnet.php +++ b/statusnet/statusnet.php @@ -1394,7 +1394,7 @@ function statusnet_complete_conversation($a, $uid, $self, $create_user, $nick, $ $posts = array_reverse($items); foreach($posts AS $post) { - $postarray = statusnet_createpost($a, $uid, $post, $self, $create_user, true); + $postarray = statusnet_createpost($a, $uid, $post, $self, false, false); if (trim($postarray['body']) == "") continue; -- 2.45.2 From d54e2377cdf18448909f13185a199783448e04f9 Mon Sep 17 00:00:00 2001 From: tobiasd Date: Mon, 7 Jul 2014 09:27:31 +0200 Subject: [PATCH 06/12] typo --- newmemberwidget/newmemberwidget.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/newmemberwidget/newmemberwidget.php b/newmemberwidget/newmemberwidget.php index 59e102af..437b47b1 100644 --- a/newmemberwidget/newmemberwidget.php +++ b/newmemberwidget/newmemberwidget.php @@ -51,7 +51,7 @@ function newmemberwidget_plugin_admin(&$a, &$o){ '$submit' => t('Save Settings'), '$freetext' => array( "freetext", t("Message"), get_config( "newmemberwidget", "freetext" ), t("Your message for new members. You can use bbcode here.")), '$linkglobalsupport' => array( "linkglobalsupport", t('Add a link to global support forum'), get_config( 'newmemberwidget', 'linkglobalsupport'), t('Should a link to the global support forum be displayed?')." (@helpers)"), - '$linklocalsupport' => array( "linklocalsupport", t('Add a link to the local support forum'), get_config( 'newmemberwidget', 'linklocalsupport'), t('If you have a local support forum and wand to have a link displayed in the widget, check this box.')), + '$linklocalsupport' => array( "linklocalsupport", t('Add a link to the local support forum'), get_config( 'newmemberwidget', 'linklocalsupport'), t('If you have a local support forum and want to have a link displayed in the widget, check this box.')), '$localsupportname' => array( "localsupportname", t('Name of the local support group'), get_config( 'newmemberwidget', 'localsupport'), t('If you checked the above, specify the nickname of the local support group here (i.e. helpers)')), )); } -- 2.45.2 From f4c9908e0c0778ba99948a36dc18b44315aadaa3 Mon Sep 17 00:00:00 2001 From: tobiasd Date: Mon, 7 Jul 2014 11:17:06 +0200 Subject: [PATCH 07/12] missing "in" --- piwik/piwik.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/piwik/piwik.php b/piwik/piwik.php index 21bc7af2..b7d326e5 100755 --- a/piwik/piwik.php +++ b/piwik/piwik.php @@ -77,7 +77,7 @@ function piwik_analytics($a,&$b) { $b .= t("This website is tracked using the Piwik analytics tool."); $b .= " "; $the_url = "http://".$baseurl ."index.php?module=CoreAdminHome&action=optOut"; - $b .= sprintf(t("If you do not want that your visits are logged this way you can set a cookie to prevent Piwik from tracking further visits of the site (opt-out)."), $the_url); + $b .= sprintf(t("If you do not want that your visits are logged in this way you can set a cookie to prevent Piwik from tracking further visits of the site (opt-out)."), $the_url); $b .= ""; } } @@ -102,3 +102,5 @@ function piwik_plugin_admin_post (&$a) { set_config('piwik', 'async', $async); info( t('Settings updated.'). EOL); } +; + $b .= -- 2.45.2 From 79a8390d2063214795c030e3de7c959a6934b360 Mon Sep 17 00:00:00 2001 From: tobiasd Date: Mon, 7 Jul 2014 11:59:33 +0200 Subject: [PATCH 08/12] typo --- statusnet/statusnet.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/statusnet/statusnet.php b/statusnet/statusnet.php index 7293f882..3b083acd 100644 --- a/statusnet/statusnet.php +++ b/statusnet/statusnet.php @@ -306,7 +306,7 @@ function statusnet_settings(&$a,&$s) { */ if (! $globalsn == null) { $s .= '

' . t('Globally Available StatusNet OAuthKeys') . '

'; - $s .= '

'. t("There are preconfigured OAuth key pairs for some StatusNet servers available. If you are useing one of them, please use these credentials. If not feel free to connect to any other StatusNet instance \x28see below\x29.") .'

'; + $s .= '

'. t("There are preconfigured OAuth key pairs for some StatusNet servers available. If you are using one of them, please use these credentials. If not feel free to connect to any other StatusNet instance \x28see below\x29.") .'

'; $s .= '
'; foreach ($globalsn as $asn) { $s .= ''. $asn['sitename'] .'
'; @@ -1588,3 +1588,9 @@ function statusnet_is_retweet($a, $uid, $body) { logger('statusnet_is_retweet: result '.print_r($result, true), LOGGER_DEBUG); return(isset($result->id)); } +get_hostname(); + + $connection = new StatusNetOAuth($api, $ckey,$csecret,$otoken,$osecret); + + $parameters = array( true); + //$parameters[image/ -- 2.45.2 From f7a444bbbdb005816f77d2c34b7a4978697c7367 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Mon, 7 Jul 2014 14:25:43 +0200 Subject: [PATCH 09/12] fixing mess from online editor --- piwik/piwik.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/piwik/piwik.php b/piwik/piwik.php index b7d326e5..8b19863d 100755 --- a/piwik/piwik.php +++ b/piwik/piwik.php @@ -102,5 +102,3 @@ function piwik_plugin_admin_post (&$a) { set_config('piwik', 'async', $async); info( t('Settings updated.'). EOL); } -; - $b .= -- 2.45.2 From ee428fdcd1570a5b2da1f6bb9ae0ca7ead6f7a59 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Mon, 7 Jul 2014 15:18:15 +0200 Subject: [PATCH 10/12] fixing more webeditor stuff --- statusnet/statusnet.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/statusnet/statusnet.php b/statusnet/statusnet.php index 3b083acd..fc147840 100644 --- a/statusnet/statusnet.php +++ b/statusnet/statusnet.php @@ -1588,9 +1588,3 @@ function statusnet_is_retweet($a, $uid, $body) { logger('statusnet_is_retweet: result '.print_r($result, true), LOGGER_DEBUG); return(isset($result->id)); } -get_hostname(); - - $connection = new StatusNetOAuth($api, $ckey,$csecret,$otoken,$osecret); - - $parameters = array( true); - //$parameters[image/ -- 2.45.2 From 9177ee2ecb07a3b6d0bc0b938ab8c90c62ce7554 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Wed, 9 Jul 2014 22:31:52 +0200 Subject: [PATCH 11/12] app.net, facebook, twitter and statusnet: Preview now shows the post like it will appear on other networks. --- appnet/appnet.php | 41 +++++++++++++++++++++++++++- fbpost/fbpost.php | 23 +++++++++++++++- fbsync/fbsync.php | 3 +++ statusnet/statusnet.php | 60 ++++++++++++++++++++++++++++++++++++++++- twitter/twitter.php | 43 ++++++++++++++++++++++++++++- 5 files changed, 166 insertions(+), 4 deletions(-) diff --git a/appnet/appnet.php b/appnet/appnet.php index 62b66c32..b5765ab5 100644 --- a/appnet/appnet.php +++ b/appnet/appnet.php @@ -23,6 +23,7 @@ function appnet_install() { register_hook('cron', 'addon/appnet/appnet.php', 'appnet_cron'); register_hook('connector_settings', 'addon/appnet/appnet.php', 'appnet_settings'); register_hook('connector_settings_post','addon/appnet/appnet.php', 'appnet_settings_post'); + register_hook('prepare_body', 'addon/appnet/appnet.php', 'appnet_prepare_body'); } @@ -31,8 +32,9 @@ function appnet_uninstall() { unregister_hook('notifier_normal', 'addon/appnet/appnet.php', 'appnet_send'); unregister_hook('jot_networks', 'addon/appnet/appnet.php', 'appnet_jot_nets'); unregister_hook('cron', 'addon/appnet/appnet.php', 'appnet_cron'); - unregister_hook('connector_settings', 'addon/appnet/appnet.php', 'appnet_settings'); + unregister_hook('connector_settings', 'addon/appnet/appnet.php', 'appnet_settings'); unregister_hook('connector_settings_post', 'addon/appnet/appnet.php', 'appnet_settings_post'); + unregister_hook('prepare_body', 'addon/appnet/appnet.php', 'appnet_prepare_body'); } function appnet_module() {} @@ -1174,6 +1176,43 @@ function appnet_fetchcontact($a, $uid, $contact, $me, $create_user) { return($r[0]["id"]); } +function appnet_prepare_body(&$a,&$b) { + if ($b["item"]["network"] != NETWORK_APPNET) + return; + + if ($b["preview"]) { + $max_char = 256; + require_once("include/plaintext.php"); + $item = $b["item"]; + $item["plink"] = $a->get_baseurl()."/display/".$a->user["nickname"]."/".$item["parent"]; + + $r = q("SELECT `author-link` FROM item WHERE item.uri = '%s' AND item.uid = %d LIMIT 1", + dbesc($item["thr-parent"]), + intval(local_user())); + + if(count($r)) { + $orig_post = $r[0]; + + $nicknameplain = preg_replace("=https?://alpha.app.net/(.*)=ism", "$1", $orig_post["author-link"]); + $nickname = "@[url=".$orig_post["author-link"]."]".$nicknameplain."[/url]"; + $nicknameplain = "@".$nicknameplain; + + if ((strpos($item["body"], $nickname) === false) AND (strpos($item["body"], $nicknameplain) === false)) + $item["body"] = $nickname." ".$item["body"]; + } + + + + $msgarr = plaintext($a, $item, $max_char, true); + $msg = appnet_create_entities($a, $item, $msgarr); + + require_once("library/markdown.php"); + $msg = Markdown($msg); + + $b['html'] = $msg; + } +} + function appnet_cron($a,$b) { $last = get_config('appnet','last_poll'); diff --git a/fbpost/fbpost.php b/fbpost/fbpost.php index b554453f..f4f29f1e 100644 --- a/fbpost/fbpost.php +++ b/fbpost/fbpost.php @@ -34,6 +34,7 @@ function fbpost_install() { register_hook('enotify', 'addon/fbpost/fbpost.php', 'fbpost_enotify'); register_hook('queue_predeliver', 'addon/fbpost/fbpost.php', 'fbpost_queue_hook'); register_hook('cron', 'addon/fbpost/fbpost.php', 'fbpost_cron'); + register_hook('prepare_body', 'addon/fbpost/fbpost.php', 'fbpost_prepare_body'); } @@ -45,6 +46,7 @@ function fbpost_uninstall() { unregister_hook('enotify', 'addon/fbpost/fbpost.php', 'fbpost_enotify'); unregister_hook('queue_predeliver', 'addon/fbpost/fbpost.php', 'fbpost_queue_hook'); unregister_hook('cron', 'addon/fbpost/fbpost.php', 'fbpost_cron'); + unregister_hook('prepare_body', 'addon/fbpost/fbpost.php', 'fbpost_prepare_body'); } @@ -565,9 +567,11 @@ function fbpost_post_hook(&$a,&$b) { $msgarr = plaintext($a, $b, 0, false); $msg = $msgarr["text"]; $link = $msgarr["url"]; - $image = $msgarr["image"]; $linkname = $msgarr["title"]; + if ($msgarr["type"] != "video") + $image = $msgarr["image"]; + // Fallback - if message is empty if(!strlen($msg)) $msg = $linkname; @@ -917,6 +921,23 @@ function fbpost_get_app_access_token() { } } +function fbpost_prepare_body(&$a,&$b) { + if ($b["item"]["network"] != NETWORK_FACEBOOK) + return; + + if ($b["preview"]) { + $msg = $b["item"]["body"]; + + require_once("include/bbcode.php"); + require_once("include/html2plain.php"); + $msg = bb_CleanPictureLinks($msg); + $msg = bbcode($msg, false, false, 2, true); + $msg = trim(html2plain($msg, 0)); + + $b['html'] = nl2br(htmlspecialchars($msg)); + } +} + function fbpost_cron($a,$b) { $last = get_config('facebook','last_poll'); diff --git a/fbsync/fbsync.php b/fbsync/fbsync.php index bcd4e5a8..9abac7dc 100644 --- a/fbsync/fbsync.php +++ b/fbsync/fbsync.php @@ -692,6 +692,9 @@ function fbsync_createlike($a, $uid, $self_id, $self, $contacts, $like) { function fbsync_fetch_contact($uid, $contact, $create_user) { + if($contact->url == "") + return(0); + // Check if the unique contact is existing // To-Do: only update once a while $r = q("SELECT id FROM unique_contacts WHERE url='%s' LIMIT 1", diff --git a/statusnet/statusnet.php b/statusnet/statusnet.php index 38381ef3..d03117de 100644 --- a/statusnet/statusnet.php +++ b/statusnet/statusnet.php @@ -118,6 +118,7 @@ function statusnet_install() { register_hook('post_local', 'addon/statusnet/statusnet.php', 'statusnet_post_local'); register_hook('jot_networks', 'addon/statusnet/statusnet.php', 'statusnet_jot_nets'); register_hook('cron', 'addon/statusnet/statusnet.php', 'statusnet_cron'); + register_hook('prepare_body', 'addon/statusnet/statusnet.php', 'statusnet_prepare_body'); logger("installed statusnet"); } @@ -129,6 +130,7 @@ function statusnet_uninstall() { unregister_hook('post_local', 'addon/statusnet/statusnet.php', 'statusnet_post_local'); unregister_hook('jot_networks', 'addon/statusnet/statusnet.php', 'statusnet_jot_nets'); unregister_hook('cron', 'addon/statusnet/statusnet.php', 'statusnet_cron'); + unregister_hook('prepare_body', 'addon/statusnet/statusnet.php', 'statusnet_prepare_body'); // old setting - remove only unregister_hook('post_local_end', 'addon/statusnet/statusnet.php', 'statusnet_post_hook'); @@ -548,6 +550,8 @@ function statusnet_post_hook(&$a,&$b) { $dent = new StatusNetOAuth($api,$ckey,$csecret,$otoken,$osecret); $max_char = $dent->get_maxlength(); // max. length for a dent + set_pconfig($b['uid'], 'statusnet', 'max_char', $max_char); + $tempfile = ""; require_once("include/plaintext.php"); require_once("include/network.php"); @@ -565,7 +569,7 @@ function statusnet_post_hook(&$a,&$b) { $msg .= " \n".short_link($msgarr["url"]); else $msg .= " \n".$msgarr["url"]; - } elseif (isset($msgarr["image"])) + } elseif (isset($msgarr["image"]) AND ($msgarr["type"] != "video")) $image = $msgarr["image"]; if ($image != "") { @@ -675,6 +679,49 @@ function statusnet_plugin_admin(&$a, &$o){ )); } +function statusnet_prepare_body(&$a,&$b) { + if ($b["item"]["network"] != NETWORK_STATUSNET) + return; + + if ($b["preview"]) { + $max_char = get_pconfig(local_user(),'statusnet','max_char'); + if (intval($max_char) == 0) + $max_char = 140; + + require_once("include/plaintext.php"); + $item = $b["item"]; + $item["plink"] = $a->get_baseurl()."/display/".$a->user["nickname"]."/".$item["parent"]; + + $r = q("SELECT `item`.`author-link`, `item`.`uri`, `contact`.`nick` AS contact_nick + FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` + WHERE `item`.`uri` = '%s' AND `item`.`uid` = %d LIMIT 1", + dbesc($item["thr-parent"]), + intval(local_user())); + + if(count($r)) { + $orig_post = $r[0]; + + $nickname = "@[url=".$orig_post["author-link"]."]".$orig_post["contact_nick"]."[/url]"; + $nicknameplain = "@".$orig_post["contact_nick"]; + + if ((strpos($item["body"], $nickname) === false) AND (strpos($item["body"], $nicknameplain) === false)) + $item["body"] = $nickname." ".$item["body"]; + } + + + $msgarr = plaintext($a, $item, $max_char, true); + $msg = $msgarr["text"]; + + if (isset($msgarr["url"])) + $msg .= " ".$msgarr["url"]; + + if (isset($msgarr["image"])) + $msg .= " ".$msgarr["image"]; + + $b['html'] = nl2br(htmlspecialchars($msg)); + } +} + function statusnet_cron($a,$b) { $last = get_config('statusnet','last_poll'); @@ -998,6 +1045,8 @@ function statusnet_createpost($a, $uid, $post, $self, $create_user, $only_existi require_once("include/html2bbcode.php"); + logger("statusnet_createpost: start", LOGGER_DEBUG); + $api = get_pconfig($uid, 'statusnet', 'baseapi'); $hostname = preg_replace("=https?://([\w\.]*)/.*=ism", "$1", $api); @@ -1128,6 +1177,7 @@ function statusnet_createpost($a, $uid, $post, $self, $create_user, $only_existi $postarray['author-link'] = $post->retweeted_status->user->statusnet_profile_url; $postarray['author-avatar'] = $post->retweeted_status->user->profile_image_url; } + logger("statusnet_createpost: end", LOGGER_DEBUG); return($postarray); } @@ -1416,6 +1466,8 @@ function statusnet_convertmsg($a, $body, $no_tags = false) { require_once("include/items.php"); require_once("include/network.php"); + $body = preg_replace("=\[url\=https?://([0-9]*).([0-9]*).([0-9]*).([0-9]*)/([0-9]*)\](.*?)\[\/url\]=ism","$1.$2.$3.$4/$5",$body); + $URLSearchString = "^\[\]"; $links = preg_match_all("/[^!#@]\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", $body,$matches,PREG_SET_ORDER); @@ -1428,10 +1480,16 @@ function statusnet_convertmsg($a, $body, $no_tags = false) { foreach ($matches AS $match) { $search = "[url=".$match[1]."]".$match[2]."[/url]"; + logger("statusnet_convertmsg: expanding url ".$match[1], LOGGER_DEBUG); + $expanded_url = original_url($match[1]); + logger("statusnet_convertmsg: fetching data for ".$expanded_url, LOGGER_DEBUG); + $oembed_data = oembed_fetch_url($expanded_url, true); + logger("statusnet_convertmsg: fetching data: done", LOGGER_DEBUG); + if ($type == "") $type = $oembed_data->type; if ($oembed_data->type == "video") { diff --git a/twitter/twitter.php b/twitter/twitter.php index d2dc4fd6..03bafbaa 100644 --- a/twitter/twitter.php +++ b/twitter/twitter.php @@ -73,6 +73,7 @@ function twitter_install() { register_hook('queue_predeliver', 'addon/twitter/twitter.php', 'twitter_queue_hook'); register_hook('follow', 'addon/twitter/twitter.php', 'twitter_follow'); register_hook('expire', 'addon/twitter/twitter.php', 'twitter_expire'); + register_hook('prepare_body', 'addon/twitter/twitter.php', 'twitter_prepare_body'); logger("installed twitter"); } @@ -87,6 +88,7 @@ function twitter_uninstall() { unregister_hook('queue_predeliver', 'addon/twitter/twitter.php', 'twitter_queue_hook'); unregister_hook('follow', 'addon/twitter/twitter.php', 'twitter_follow'); unregister_hook('expire', 'addon/twitter/twitter.php', 'twitter_expire'); + unregister_hook('prepare_body', 'addon/twitter/twitter.php', 'twitter_prepare_body'); // old setting - remove only unregister_hook('post_local_end', 'addon/twitter/twitter.php', 'twitter_post_hook'); @@ -472,7 +474,7 @@ function twitter_post_hook(&$a,&$b) { if (isset($msgarr["url"])) $msg .= "\n".$msgarr["url"]; - elseif (isset($msgarr["image"])) + elseif (isset($msgarr["image"]) AND ($msgarr["type"] != "video")) $image = $msgarr["image"]; // and now tweet it :-) @@ -652,6 +654,45 @@ function twitter_expire($a,$b) { logger('twitter_expire: expire_end'); } +function twitter_prepare_body(&$a,&$b) { + if ($b["item"]["network"] != NETWORK_TWITTER) + return; + + if ($b["preview"]) { + $max_char = 140; + require_once("include/plaintext.php"); + $item = $b["item"]; + $item["plink"] = $a->get_baseurl()."/display/".$a->user["nickname"]."/".$item["parent"]; + + $r = q("SELECT `author-link` FROM item WHERE item.uri = '%s' AND item.uid = %d LIMIT 1", + dbesc($item["thr-parent"]), + intval(local_user())); + + if(count($r)) { + $orig_post = $r[0]; + + $nicknameplain = preg_replace("=https?://twitter.com/(.*)=ism", "$1", $orig_post["author-link"]); + $nickname = "@[url=".$orig_post["author-link"]."]".$nicknameplain."[/url]"; + $nicknameplain = "@".$nicknameplain; + + if ((strpos($item["body"], $nickname) === false) AND (strpos($item["body"], $nicknameplain) === false)) + $item["body"] = $nickname." ".$item["body"]; + } + + + $msgarr = plaintext($a, $item, $max_char, true); + $msg = $msgarr["text"]; + + if (isset($msgarr["url"])) + $msg .= " ".$msgarr["url"]; + + if (isset($msgarr["image"])) + $msg .= " ".$msgarr["image"]; + + $b['html'] = nl2br(htmlspecialchars($msg)); + } +} + function twitter_fetchtimeline($a, $uid) { $ckey = get_config('twitter', 'consumerkey'); $csecret = get_config('twitter', 'consumersecret'); -- 2.45.2 From c3538fb5380d7c52a6886882f93b40b6a87cedb7 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Wed, 9 Jul 2014 23:35:28 +0200 Subject: [PATCH 12/12] Twitter/Statusnet: Use "RD" and "RT" for repeated messages. --- statusnet/statusnet.php | 4 ++-- twitter/twitter.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/statusnet/statusnet.php b/statusnet/statusnet.php index d03117de..2e68ae89 100644 --- a/statusnet/statusnet.php +++ b/statusnet/statusnet.php @@ -555,7 +555,7 @@ function statusnet_post_hook(&$a,&$b) { $tempfile = ""; require_once("include/plaintext.php"); require_once("include/network.php"); - $msgarr = plaintext($a, $b, $max_char, true); + $msgarr = plaintext($a, $b, $max_char, true, 7); $msg = $msgarr["text"]; if (($msg == "") AND isset($msgarr["title"])) @@ -709,7 +709,7 @@ function statusnet_prepare_body(&$a,&$b) { } - $msgarr = plaintext($a, $item, $max_char, true); + $msgarr = plaintext($a, $item, $max_char, true, 7); $msg = $msgarr["text"]; if (isset($msgarr["url"])) diff --git a/twitter/twitter.php b/twitter/twitter.php index 03bafbaa..c332f7be 100644 --- a/twitter/twitter.php +++ b/twitter/twitter.php @@ -464,7 +464,7 @@ function twitter_post_hook(&$a,&$b) { $max_char = 140; require_once("include/plaintext.php"); - $msgarr = plaintext($a, $b, $max_char, true); + $msgarr = plaintext($a, $b, $max_char, true, 8); $msg = $msgarr["text"]; if (($msg == "") AND isset($msgarr["title"])) @@ -680,7 +680,7 @@ function twitter_prepare_body(&$a,&$b) { } - $msgarr = plaintext($a, $item, $max_char, true); + $msgarr = plaintext($a, $item, $max_char, true, 8); $msg = $msgarr["text"]; if (isset($msgarr["url"])) -- 2.45.2