From 0a134a819878fe0be19ba16cd9712d3c47dd8e4d Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Fri, 20 Dec 2013 09:44:51 +0100 Subject: [PATCH 1/9] Public Server: indented the example options in the README --- public_server.tgz | Bin 3814 -> 3834 bytes public_server/README.md | 22 +++++++++++----------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/public_server.tgz b/public_server.tgz index ec9c0177f7e926dfdd3ea96f763bf0469f80cd31..ad51b9a3b5afbd1d3f983f1138046c620900343e 100755 GIT binary patch literal 3834 zcmVVh2W7*Us&;EJDe3Q(>B{ z)F?4jr=e(Mr>WGML}?i+Ycb6R9LLsM)P{DnR?{8LCKrjJTQ*@248?>8x<)LW*iC8! zJxj3}Y0);RGU8ZFCKS22ZW*x|G^@hR9mQ@ElgUmEF3=2cVFNdyl_Zf!xe2my@mjj9 z)D=Jifi2{u*MSowNJ%!8ZRUwROBQdE)thBfyjEViQ!JNAu}sSEmB@N=r9{e0@T0iS zZ zNlm$56VMrkLUN+hG;y`2Yjvfu5%Wc6Y;z;V8!?%-t=J}6AX(|MC&)UpIXjuvsiWEi zQAk}kxz;UW>n=Y=n#^S5^5Ja<7_G6EzRk^KT3~k_Is=y)L+4QSMgw{d4ngZSTx&Yq zQ8X^h!8|?egZQZw{GrE5N5*xPHe3weZ`#lgX4h@Q8K!e{9gf#QYX`G)_1a-aEYN?? z!Q1Ww(0Uiu)#!L)_4NKzPY>fYae4Im6Y;#lVkmlBcTAFO+Af`>(KJY1QCX6_)9$*B zrrS+LYoN2jEk$!XU86t&y~_)CjIx@oY;!*c*H>f+L#nE6h{JM|wV{EAv8=aRip^ue zFbVj^4J^0Gp;P3oP@lVr{;sWqwAU|tU? zifmzYBqN;IV1R+tjv;fIcQ9&0kl3efNsT2bP(fU$`$$eZVH61f3Qcm(* z5D6#$`^SIZ6?(};c=*PDsP+86(=gU&Vf;@QvbniTE{FBs98?7%kN>8w+xy`i^!zo2 zD?bA(MKr?dCkW!I02(1~JI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l#oA7(T4$^f7M0M#XhT>t<8 diff --git a/public_server/README.md b/public_server/README.md index 44b29f8e..d323ff0f 100644 --- a/public_server/README.md +++ b/public_server/README.md @@ -7,17 +7,17 @@ test bed with reduced data retention. This is a modified version of the testdrive plugin, DO NOT ACTIVATE AT THE SAME TIME AS THE TESTDRIVE PLUGIN. -//When an account is created on the site, it is given a hard expiration date of -$a->config['public_server']['expiredays'] = 30; -//Set the default days for posts to expire here -$a->config['public_server']['expireposts'] = 30; -//Remove users who have never logged in after nologin days -$a->config['public_server']['nologin'] = 30; -//Remove users who last logged in over flagusers days ago -$a->config['public_server']['flagusers'] = 146; -//For users who last logged in over flagposts days ago set post expiry days to flagpostsexpire -$a->config['public_server']['flagposts'] = 90; -$a->config['public_server']['flagpostsexpire'] = 146; + //When an account is created on the site, it is given a hard expiration date of + $a->config['public_server']['expiredays'] = 30; + //Set the default days for posts to expire here + $a->config['public_server']['expireposts'] = 30; + //Remove users who have never logged in after nologin days + $a->config['public_server']['nologin'] = 30; + //Remove users who last logged in over flagusers days ago + $a->config['public_server']['flagusers'] = 146; + //For users who last logged in over flagposts days ago set post expiry days to flagpostsexpire + $a->config['public_server']['flagposts'] = 90; + $a->config['public_server']['flagpostsexpire'] = 146; Set these in your .htconfig.php file. By default nothing is defined in case the plugin is activated accidentally. They can be ommitted or set to 0 to disable each option. -- 2.43.0 From 44cf9c2016856892513a586f645e36a6a5f7bcf8 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Fri, 20 Dec 2013 18:52:14 +0100 Subject: [PATCH 2/9] public server: added template for the admin panel --- public_server/templates/admin.tpl | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 public_server/templates/admin.tpl diff --git a/public_server/templates/admin.tpl b/public_server/templates/admin.tpl new file mode 100644 index 00000000..7781c2f4 --- /dev/null +++ b/public_server/templates/admin.tpl @@ -0,0 +1,10 @@ +

{{$infotext}}

+{{include file="field_input.tpl" field=$expiredays}} +{{include file="field_input.tpl" field=$expireposts}} +{{include file="field_input.tpl" field=$nologin}} +{{include file="field_input.tpl" field=$flagusers}} +{{include file="field_input.tpl" field=$flagposts}} +{{include file="field_input.tpl" field=$flagpostsexpire}} + + +
-- 2.43.0 From 60f261b4902e27e37b32a339ea150e433ee5dac1 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Fri, 20 Dec 2013 18:58:50 +0100 Subject: [PATCH 3/9] public server: added form to admin panel --- public_server/public_server.php | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/public_server/public_server.php b/public_server/public_server.php index becf96c3..27e219f6 100644 --- a/public_server/public_server.php +++ b/public_server/public_server.php @@ -3,7 +3,7 @@ /** * Name: public_server * Description: Friendica plugin/addon with functions suitable for a public server. - * Version: 1.0 + * Version: 1.1 * Author: Keith Fernie */ @@ -141,3 +141,23 @@ function public_server_login($a,$b) { local_user() ); } + +function public_server_plugin_admin_post ( &$a ) { + check_form_security_token_redirectOnErr('/admin/plugins/publicserver', 'publicserver'); +} +function public_server_plugin_admin ( &$a, &$o) { + $token = get_form_security_token("publicserver"); + $t = get_markup_template( "admin.tpl", "addon/public_server"); + $o = replace_macros($t, array( + '$submit' => t('Save Settings'), + '$form_security_token' => $token, + '$infotext' => t('Set any of these options to 0 to deactivate it.'), + '$expiredays' => Array( "expiredays","Expire Days", intval(get_config('public_server', 'expiredays')), "When an account is created on the site, it is given a hard "), + '$expireposts' => Array( "expireposts", "Expire Posts", intval(get_config('public_server','expireposts')), "Set the default days for posts to expire here"), + '$nologin' => Array( "nologin", "No Login", intval(get_config('public_server','nologin')), "Remove users who have never logged in after nologin days "), + '$flagusers' => Array( "flagusers", "Flag users", intval(get_config('public_server','flagusers')), "Remove users who last logged in over flagusers days ago"), + '$flagposts' => Array( "flagposts", "Flag posts", intval(get_config('public_server','flagposts')), "For users who last logged in over flagposts days ago set post expiry days to flagpostsexpire "), + '$flagpostsexpire' => Array( "flagpostsexpire", "Flag posts expire", intval(get_config('public_server','flagpostsexpire'))), + )); +} + -- 2.43.0 From 457b980de370e3b763a93932aed3d750b9ec1d09 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Fri, 20 Dec 2013 19:58:27 +0100 Subject: [PATCH 4/9] public server: save the settings --- public_server/public_server.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/public_server/public_server.php b/public_server/public_server.php index 27e219f6..8dacc916 100644 --- a/public_server/public_server.php +++ b/public_server/public_server.php @@ -144,6 +144,19 @@ function public_server_login($a,$b) { function public_server_plugin_admin_post ( &$a ) { check_form_security_token_redirectOnErr('/admin/plugins/publicserver', 'publicserver'); + $expiredays = (( x($_POST, 'expiredays') ) ? notags(trim($_POST['expiredays'] )) : ''); + $expireposts = (( x($_POST, 'expireposts') ) ? notags(trim($_POST['expireposts'] )) : ''); + $nologin = (( x($_POST, 'nologin') ) ? notags(trim($_POST['nologin'] )) : ''); + $flagusers = (( x($_POST, 'flagusers') ) ? notags(trim($_POST['flagusers'] )) : ''); + $flagposts = (( x($_POST, 'flagposts') ) ? notags(trim($_POST['flagposts'] )) : ''); + $flagpostsexpire = (( x($_POST, 'flagpostsexpire') ) ? notags(trim($_POST['flagpostsexpire'] )) : ''); + set_config( 'public_server','expiredays',$expiredays ); + set_config( 'public_server','expireposts',$expireposts ); + set_config( 'public_server','nologin',$nologin ); + set_config( 'public_server','flagusers',$flagusers); + set_config( 'public_server','flagposts',$flagposts ); + set_config( 'public_server','flagpostsexpire',$flagpostsexpire ); + info( t('Settings saved').EOL ); } function public_server_plugin_admin ( &$a, &$o) { $token = get_form_security_token("publicserver"); -- 2.43.0 From ab9b0848866d7accb9daa1ae4a27b439463af334 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Fri, 20 Dec 2013 20:01:49 +0100 Subject: [PATCH 5/9] public server tar ball --- public_server.tgz | Bin 3834 -> 4577 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/public_server.tgz b/public_server.tgz index ad51b9a3b5afbd1d3f983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r}Jz^;#?(ai5>ws%KlF#FY wK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1e_B1KOsJ|NC2P!05mzKJpcdz -- 2.43.0 From 5eb18422c4ad564be5dc3fd700f21aa06cbedc92 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Fri, 27 Dec 2013 02:02:48 +0100 Subject: [PATCH 6/9] Support of "unique contacts" for the new API --- fbsync/fbsync.php | 24 ++++++++++++++++++++++-- twitter/twitter.php | 36 +++++++++++++++++++++++++++++++++--- 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/fbsync/fbsync.php b/fbsync/fbsync.php index 32f62a4a..561cabad 100644 --- a/fbsync/fbsync.php +++ b/fbsync/fbsync.php @@ -200,6 +200,7 @@ function fbsync_createpost($a, $uid, $self, $contacts, $applications, $post, $cr $postarray['wall'] = 0; $postarray['verb'] = ACTIVITY_POST; + $postarray['network'] = dbesc(NETWORK_FACEBOOK); $postarray['uri'] = "fb::".$post->post_id; $postarray['thr-parent'] = $postarray['uri']; @@ -414,6 +415,7 @@ function fbsync_createcomment($a, $uid, $self_id, $self, $user, $contacts, $appl $postarray['wall'] = 0; $postarray['verb'] = ACTIVITY_POST; + $postarray['network'] = dbesc(NETWORK_FACEBOOK); $postarray['uri'] = "fb::".$comment->id; $postarray['thr-parent'] = $parent_uri; @@ -548,13 +550,13 @@ function fbsync_createlike($a, $uid, $self_id, $self, $contacts, $like) { $likedata = array(); $likedata['parent'] = $orig_post['id']; $likedata['verb'] = ACTIVITY_LIKE; + $likedate['network'] = dbesc(NETWORK_FACEBOOK); $likedata['gravity'] = 3; $likedata['uid'] = $uid; $likedata['wall'] = 0; $likedata['uri'] = item_new_uri($a->get_baseurl(), $uid); $likedata['parent-uri'] = $orig_post["uri"]; $likedata['app'] = "Facebook"; - $likedata['verb'] = ACTIVITY_LIKE; if ($like->user_id != $self_id) { $likedata['contact-id'] = $contact_id; @@ -598,6 +600,24 @@ function fbsync_createlike($a, $uid, $self_id, $self, $contacts, $like) { function fbsync_fetch_contact($uid, $contact, $create_user) { + // 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", + dbesc(normalise_link($contact->url))); + + if (count($r) == 0) + q("INSERT INTO unique_contacts (url, name, nick, avatar) VALUES ('%s', '%s', '%s', '%s')", + dbesc(normalise_link($contact->url)), + dbesc($contact->name), + dbesc($contact->username), + dbesc($contact->pic_square)); + else + q("UPDATE unique_contacts SET name = '%s', nick = '%s', avatar = '%s' WHERE url = '%s'", + dbesc($contact->name), + dbesc($contact->username), + dbesc($contact->pic_square), + dbesc(normalise_link($contact->url))); + $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `alias` = '%s' LIMIT 1", intval($uid), dbesc("facebook::".$contact->id)); @@ -834,7 +854,7 @@ function fbsync_fetchfeed($a, $uid) { require_once('include/items.php'); - if ($last_updated == "") + //if ($last_updated == "") $last_updated = 0; logger("fbsync_fetchfeed: fetching content for user ".$self_id); diff --git a/twitter/twitter.php b/twitter/twitter.php index 7364547a..281f0787 100755 --- a/twitter/twitter.php +++ b/twitter/twitter.php @@ -169,6 +169,7 @@ function twitter_settings_post ($a,$post) { del_pconfig(local_user(), 'twitter', 'intelligent_shortening'); del_pconfig(local_user(), 'twitter', 'import'); del_pconfig(local_user(), 'twitter', 'create_user'); + del_pconfig(local_user(), 'twitter', 'own_id'); } else { if (isset($_POST['twitter-pin'])) { // if the user supplied us with a PIN from Twitter, let the magic of OAuth happen @@ -632,8 +633,12 @@ function twitter_post_hook(&$a,&$b) { $orig_post = $r[0]; } - // To-Do: Ab dem letzten / nehmen - $b["body"] = "@".substr($orig_post["author-link"], 20)." ".$b["body"]; + $nickname = preg_replace("=https?://twitter.com/(.*)=ism", "$1", $orig_post["author-link"]); + $nickname = "@[url=".$orig_post["author-link"]."]".$nickname."[/url]"; + + logger("twitter_post_hook: comparing ".$nickname." with ".$b["body"], LOGGER_DEBUG); + if (strpos($b["body"], $nickname) === false) + $b["body"] = $nickname." ".$b["body"]; logger("twitter_post_hook: parent found ".print_r($orig_post, true), LOGGER_DATA); } else { @@ -1119,6 +1124,24 @@ function twitter_queue_hook(&$a,&$b) { function twitter_fetch_contact($uid, $contact, $create_user) { + // 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", + dbesc(normalise_link("https://twitter.com/".$contact->screen_name))); + + if (count($r) == 0) + q("INSERT INTO unique_contacts (url, name, nick, avatar) VALUES ('%s', '%s', '%s', '%s')", + dbesc(normalise_link("https://twitter.com/".$contact->screen_name)), + dbesc($contact->name), + dbesc($contact->screen_name), + dbesc($contact->profile_image_url_https)); + else + q("UPDATE unique_contacts SET name = '%s', nick = '%s', avatar = '%s' WHERE url = '%s'", + dbesc($contact->name), + dbesc($contact->screen_name), + dbesc($contact->profile_image_url_https), + dbesc(normalise_link("https://twitter.com/".$contact->screen_name))); + $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `alias` = '%s' LIMIT 1", intval($uid), dbesc("twitter::".$contact->id_str)); @@ -1191,6 +1214,7 @@ function twitter_fetch_contact($uid, $contact, $create_user) { dbesc(datetime_convert()), intval($contact_id) ); + } else { // update profile photos once every two weeks as we have no notification of when they change. @@ -1282,6 +1306,7 @@ function twitter_createpost($a, $uid, $post, $self, $create_user, $only_existing $has_picture = false; $postarray = array(); + $postarray['network'] = NETWORK_TWITTER; $postarray['gravity'] = 0; $postarray['uid'] = $uid; $postarray['wall'] = 0; @@ -1425,6 +1450,7 @@ function twitter_createpost($a, $uid, $post, $self, $create_user, $only_existing $postarray['body'] = $converted["body"]; $postarray['tag'] = $converted["tags"]; + twitter_fetch_contact($uid, $post->retweeted_status->user, false); // Deactivated at the moment, since there are problems with answers to retweets if (false AND !intval(get_config('system','wall-to-wall_share'))) { @@ -1757,7 +1783,8 @@ function twitter_siteinfo($url, $dontincludemedia) { if (sizeof($data["images"]) > 0) { $imagedata = $data["images"][0]; - $text .= '[img='.$imagedata["width"].'x'.$imagedata["height"].']'.$imagedata["src"].'[/img]' . "\n"; + //$text .= '[img='.$imagedata["width"].'x'.$imagedata["height"].']'.$imagedata["src"].'[/img]' . "\n"; + $text .= '[img]'.$imagedata["src"].'[/img]'."\n"; } if (is_string($data["text"])) @@ -1914,6 +1941,9 @@ function twitter_fetch_own_contact($a, $uid) { intval($uid), dbesc("twitter::".$own_id)); if(count($r)) $contact_id = $r[0]["id"]; + else + del_pconfig($uid, 'twitter', 'own_id'); + } return($contact_id); -- 2.43.0 From 4436168b2600ebb7f7b53fdd8b943173a93770fe Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Fri, 27 Dec 2013 02:04:48 +0100 Subject: [PATCH 7/9] fbpost: queueing of facebook comments didn't worked at every time. --- fbpost/fbpost.php | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/fbpost/fbpost.php b/fbpost/fbpost.php index 092d5f70..48865f04 100644 --- a/fbpost/fbpost.php +++ b/fbpost/fbpost.php @@ -293,8 +293,8 @@ function fbpost_content(&$a) { function fbpost_plugin_settings(&$a,&$b) { $b .= '
'; - $b .= '

' . t('Facebook Post Settings') . '

'; - $b .= '' . t('Facebook Post Settings') . '
'; + //$b .= '

' . t('Facebook Post Settings') . '

'; + $b .= '

' . t('Facebook Post Settings') . '

'; $b .= '
'; } @@ -765,6 +765,10 @@ function fbpost_post_hook(&$a,&$b) { } else { if(! $likes) { + $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `self`", intval($b['uid'])); + if (count($r)) + $a->contact = $r[0]["id"]; + $s = serialize(array('url' => $url, 'item' => $b['id'], 'post' => $postvars)); require_once('include/queue_fn.php'); add_to_queue($a->contact,NETWORK_FACEBOOK,$s); @@ -867,14 +871,17 @@ function fbpost_queue_hook(&$a,&$b) { if($x['network'] !== NETWORK_FACEBOOK) continue; - logger('facebook_queue: run'); + logger('fbpost_queue_hook: run'); $r = q("SELECT `user`.* FROM `user` LEFT JOIN `contact` on `contact`.`uid` = `user`.`uid` WHERE `contact`.`self` = 1 AND `contact`.`id` = %d LIMIT 1", intval($x['cid']) ); - if(! count($r)) + if(! count($r)) { + logger('fbpost_queue_hook: no user found for entry '.print_r($x, true)); + update_queue_time($x['id']); continue; + } $user = $r[0]; @@ -908,7 +915,13 @@ function fbpost_queue_hook(&$a,&$b) { logger('fbpost_queue_hook: failed: ' . $j); update_queue_time($x['id']); } + } else { + logger('fbpost_queue_hook: No fb_post or fb_token.'); + update_queue_time($x['id']); } + } else { + logger('fbpost_queue_hook: No appid or secret.'); + update_queue_time($x['id']); } } } -- 2.43.0 From 6de8e467287e6fed9380e72cd9c8af8e4ad3a8a9 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Fri, 27 Dec 2013 02:05:46 +0100 Subject: [PATCH 8/9] privacy_image_cache: avatar pictures of wall-to-wall-posts are now cached as well. And it is cached now at only one location --- privacy_image_cache/privacy_image_cache.php | 107 ++++++++++++-------- 1 file changed, 65 insertions(+), 42 deletions(-) diff --git a/privacy_image_cache/privacy_image_cache.php b/privacy_image_cache/privacy_image_cache.php index b0909e81..6122b9ed 100644 --- a/privacy_image_cache/privacy_image_cache.php +++ b/privacy_image_cache/privacy_image_cache.php @@ -34,6 +34,13 @@ function privacy_image_cache_module() {} function privacy_image_cache_init() { global $a, $_SERVER; + // The code needs to be reworked, it is too complicated + // + // it is doing the following: + // 1. If a folder "privacy_image_cache" exists and is writeable, then use this for caching + // 2. If a cache path is defined, use this + // 3. If everything else failed, cache into the database + if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) { header('HTTP/1.1 304 Not Modified'); header("Last-Modified: " . gmdate("D, d M Y H:i:s", time()) . " GMT"); @@ -55,6 +62,14 @@ function privacy_image_cache_init() { $thumb = false; + // If the cache path isn't there, try to create it + if (!is_dir($_SERVER["DOCUMENT_ROOT"]."/privacy_image_cache")) + if (is_writable($_SERVER["DOCUMENT_ROOT"])) + mkdir($_SERVER["DOCUMENT_ROOT"]."/privacy_image_cache"); + + // Checking if caching into a folder in the webroot is activated and working + $direct_cache = (is_dir($_SERVER["DOCUMENT_ROOT"]."/privacy_image_cache") AND is_writable($_SERVER["DOCUMENT_ROOT"]."/privacy_image_cache")); + // Look for filename in the arguments if (isset($a->argv[1]) OR isset($a->argv[2]) OR isset($a->argv[3])) { if (isset($a->argv[3])) @@ -77,50 +92,53 @@ function privacy_image_cache_init() { $thumb = (isset($a->argv[3]) and ($a->argv[3] == "thumb")); } - $urlhash = 'pic:' . sha1($_REQUEST['url']); - // Double encoded url - happens with Diaspora - $urlhash2 = 'pic:' . sha1(urldecode($_REQUEST['url'])); + if (!$direct_cache) { + $urlhash = 'pic:' . sha1($_REQUEST['url']); + // Double encoded url - happens with Diaspora + $urlhash2 = 'pic:' . sha1(urldecode($_REQUEST['url'])); - $cachefile = get_cachefile(hash("md5", $_REQUEST['url'])); - if ($cachefile != '') { - if (file_exists($cachefile)) { - $img_str = file_get_contents($cachefile); - $mime = image_type_to_mime_type(exif_imagetype($cachefile)); + $cachefile = get_cachefile(hash("md5", $_REQUEST['url'])); + if ($cachefile != '') { + if (file_exists($cachefile)) { + $img_str = file_get_contents($cachefile); + $mime = image_type_to_mime_type(exif_imagetype($cachefile)); - header("Content-type: $mime"); - header("Last-Modified: " . gmdate("D, d M Y H:i:s", time()) . " GMT"); - header('Etag: "'.md5($img_str).'"'); - header("Expires: " . gmdate("D, d M Y H:i:s", time() + (31536000)) . " GMT"); - header("Cache-Control: max-age=31536000"); + header("Content-type: $mime"); + header("Last-Modified: " . gmdate("D, d M Y H:i:s", time()) . " GMT"); + header('Etag: "'.md5($img_str).'"'); + header("Expires: " . gmdate("D, d M Y H:i:s", time() + (31536000)) . " GMT"); + header("Cache-Control: max-age=31536000"); - // reduce quality - if it isn't a GIF - if ($mime != "image/gif") { - $img = new Photo($img_str, $mime); - if($img->is_valid()) - $img_str = $img->imageString(); + // reduce quality - if it isn't a GIF + if ($mime != "image/gif") { + $img = new Photo($img_str, $mime); + if($img->is_valid()) { + $img_str = $img->imageString(); + } + } + + echo $img_str; + killme(); } - - echo $img_str; - - if (is_dir($_SERVER["DOCUMENT_ROOT"]."/privacy_image_cache")) - file_put_contents($_SERVER["DOCUMENT_ROOT"]."/privacy_image_cache/".privacy_image_cache_cachename($_REQUEST['url'], true), $img_str); - - killme(); } - } + } else + $cachefile = ""; $valid = true; - $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"; + if (!$direct_cache AND ($cachefile == "")) { + $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 + $r = array(); - } else { + if (!count($r)) { // It shouldn't happen but it does - spaces in URL $_REQUEST['url'] = str_replace(" ", "+", $_REQUEST['url']); - $redirects = 0; $img_str = fetch_url($_REQUEST['url'],true, $redirects, 10); @@ -140,7 +158,7 @@ function privacy_image_cache_init() { $img->scaleImage(10); $img_str = $img->imageString(); } - } else if ($mime != "image/jpeg") { + } else if (($mime != "image/jpeg") AND !$direct_cache AND ($cachefile == "")) { $image = @imagecreatefromstring($img_str); if($image === FALSE) die(); @@ -165,25 +183,31 @@ function privacy_image_cache_init() { } else { $img = new Photo($img_str, $mime); if($img->is_valid()) { - $img->store(0, 0, $urlhash, $_REQUEST['url'], '', 100); - if ($thumb) + if (!$direct_cache AND ($cachefile == "")) + $img->store(0, 0, $urlhash, $_REQUEST['url'], '', 100); + + if ($thumb) { $img->scaleImage(200); // Test - $img_str = $img->imageString(); + $img_str = $img->imageString(); + } } //$mime = "image/jpeg"; } } + // reduce quality - if it isn't a GIF if ($mime != "image/gif") { $img = new Photo($img_str, $mime); - if($img->is_valid()) + if($img->is_valid()) { + $img->scaleImage(1024); // Test $img_str = $img->imageString(); + } } // If there is a real existing directory then put the cache file there // advantage: real file access is really fast // Otherwise write in cachefile - if ($valid AND is_dir($_SERVER["DOCUMENT_ROOT"]."/privacy_image_cache")) + if ($valid AND $direct_cache) file_put_contents($_SERVER["DOCUMENT_ROOT"]."/privacy_image_cache/".privacy_image_cache_cachename($_REQUEST['url'], true), $img_str); elseif ($cachefile != '') file_put_contents($cachefile, $img_str); @@ -306,13 +330,12 @@ function privacy_image_cache_display_item_hook(&$a, &$o) { if (isset($o["output"])) { if (isset($o["output"]["thumb"]) && !privacy_image_cache_is_local_image($o["output"]["thumb"])) $o["output"]["thumb"] = $a->get_baseurl() . "/privacy_image_cache/".privacy_image_cache_cachename($o["output"]["thumb"]); - //$o["output"]["thumb"] = $a->get_baseurl() . "/privacy_image_cache/?url=" . escape_tags(addslashes(rawurlencode($o["output"]["thumb"]))); if (isset($o["output"]["author-avatar"]) && !privacy_image_cache_is_local_image($o["output"]["author-avatar"])) $o["output"]["author-avatar"] = $a->get_baseurl() . "/privacy_image_cache/".privacy_image_cache_cachename($o["output"]["author-avatar"]); - //$o["output"]["author-avatar"] = $a->get_baseurl() . "/privacy_image_cache/?url=" . escape_tags(addslashes(rawurlencode($o["output"]["author-avatar"]))); if (isset($o["output"]["owner-avatar"]) && !privacy_image_cache_is_local_image($o["output"]["owner-avatar"])) $o["output"]["owner-avatar"] = $a->get_baseurl() . "/privacy_image_cache/".privacy_image_cache_cachename($o["output"]["owner-avatar"]); - //$o["output"]["owner-avatar"] = $a->get_baseurl() . "/privacy_image_cache/?url=" . escape_tags(addslashes(rawurlencode($o["output"]["owner-avatar"]))); + if (isset($o["output"]["owner_photo"]) && !privacy_image_cache_is_local_image($o["output"]["owner_photo"])) + $o["output"]["owner_photo"] = $a->get_baseurl() . "/privacy_image_cache/".privacy_image_cache_cachename($o["output"]["owner_photo"]); } } -- 2.43.0 From a5ad8f947bac9caf4efc4ef604f0bdb06fd9ffeb Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 29 Dec 2013 17:49:29 +0100 Subject: [PATCH 9/9] twitter: Repeating twitter items now does a native twitter retweet --- twitter/twitter.php | 77 ++++++++++++++++++++++++++++++++------------- 1 file changed, 56 insertions(+), 21 deletions(-) diff --git a/twitter/twitter.php b/twitter/twitter.php index 281f0787..0043a3a9 100755 --- a/twitter/twitter.php +++ b/twitter/twitter.php @@ -685,9 +685,14 @@ function twitter_post_hook(&$a,&$b) { if($ckey && $csecret && $otoken && $osecret) { logger('twitter: we have customer key and oauth stuff, going to send.', LOGGER_DEBUG); + // If it's a repeated message from twitter then do a native retweet and exit + if (twitter_is_retweet($a, $b['uid'], $b['body'])) + return; + require_once('library/twitteroauth.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 if (!$intelligent_shortening) { @@ -772,6 +777,7 @@ function twitter_post_hook(&$a,&$b) { $msg = $msgarr["msg"]; $image = $msgarr["image"]; } + // and now tweet it :-) if(strlen($msg) and ($image != "")) { $img_str = fetch_url($image); @@ -797,16 +803,6 @@ function twitter_post_hook(&$a,&$b) { $result = $cb->statuses_updateWithMedia($post); unlink($tempfile); - /* - // Old Code - $mime = image_type_to_mime_type(exif_imagetype($tempfile)); - unlink($tempfile); - - $filename = "upload"; - - $result = $tweet->post('statuses/update_with_media', array('media[]' => "{$img_str};type=".$mime.";filename={$filename}" , 'status' => $msg)); - */ - logger('twitter_post_with_media send, result: ' . print_r($result, true), LOGGER_DEBUG); if ($result->errors OR $result->error) { logger('Send to Twitter failed: "' . print_r($result->errors, true) . '"'); @@ -1465,6 +1461,10 @@ function twitter_createpost($a, $uid, $post, $self, $create_user, $only_existing $postarray['author-name'] = $post->retweeted_status->user->name; $postarray['author-link'] = "https://twitter.com/".$post->retweeted_status->user->screen_name; $postarray['author-avatar'] = $post->retweeted_status->user->profile_image_url_https; + //if (($post->retweeted_status->user->screen_name != "") AND ($post->retweeted_status->id_str != "")) { + // $postarray['plink'] = "https://twitter.com/".$post->retweeted_status->user->screen_name."/status/".$post->retweeted_status->id_str; + // $postarray['uri'] = "twitter::".$post->retweeted_status->id_str; + //} } } @@ -1816,17 +1816,6 @@ function twitter_convertmsg($a, $body, $no_tags = false, $dontincludemedia) { if ($type == "") $type = $oembed_data->type; - // To-Do: - // Twitlonger - -// if (strstr($expanded_url, "//www.youtube.com/")) -// $body = str_replace($match[2], "\n[youtube]".$expanded_url."[/youtube]\n", $body); -// elseif (strstr($expanded_url, "//player.vimeo.com/")) -// $body = str_replace($match[2], "\n[vimeo]".$expanded_url."[/vimeo]\n", $body); -// elseif (strstr($expanded_url, "//twitpic.com/")) // Test -// $body = str_replace($match[2], "\n[url]".$expanded_url."[/url]\n", $body); -// elseif (strstr($expanded_url, "//instagram.com/")) -// $body = str_replace($match[2], "\n[url]".$expanded_url."[/url]\n", $body); if ($oembed_data->type != "link") $body = str_replace($match[2], "\n[url]".$expanded_url."[/url]\n", $body); else { @@ -1948,4 +1937,50 @@ function twitter_fetch_own_contact($a, $uid) { return($contact_id); } + +function twitter_is_retweet($a, $uid, $body) { + $body = trim($body); + + // Skip if it isn't a pure repeated messages + // Does it start with a share? + if (strpos($body, "[share") > 0) + return(false); + + // Does it end with a share? + if (strlen($body) > (strrpos($body, "[/share]") + 8)) + return(false); + + $attributes = preg_replace("/\[share(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism","$1",$body); + // Skip if there is no shared message in there + if ($body == $attributes) + return(false); + + $link = ""; + preg_match("/link='(.*?)'/ism", $attributes, $matches); + if ($matches[1] != "") + $link = $matches[1]; + + preg_match('/link="(.*?)"/ism', $attributes, $matches); + if ($matches[1] != "") + $link = $matches[1]; + + $id = preg_replace("=https?://twitter.com/(.*)/status/(.*)=ism", "$2", $link); + if ($id == $link) + return(false); + + logger('twitter_is_retweet: Retweeting id '.$id.' for user '.$uid, LOGGER_DEBUG); + + $ckey = get_config('twitter', 'consumerkey'); + $csecret = get_config('twitter', 'consumersecret'); + $otoken = get_pconfig($uid, 'twitter', 'oauthtoken'); + $osecret = get_pconfig($uid, 'twitter', 'oauthsecret'); + + require_once('library/twitteroauth.php'); + $connection = new TwitterOAuth($ckey,$csecret,$otoken,$osecret); + + $result = $connection->post('statuses/retweet/'.$id); + + return(!isset($result->errors)); +} + ?> -- 2.43.0