From a8a37ee6fc9e43ec6671ae9bac497165abc126fa Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Fri, 9 Jan 2015 07:07:07 +0100 Subject: [PATCH 1/5] app.net, acebook, pumpio, statusnet, twitter: Support for the new database fields in contact and unique_contacts. --- appnet/appnet.php | 54 +++++++++++++++++++++++++++++++++++++++++ diaspora/diasphp.php | 7 ++++++ fbsync/fbsync.php | 15 ++++++++++++ pumpio/pumpio.php | 42 ++++++++++++++++++++++++++++++-- statusnet/statusnet.php | 38 +++++++++++++++++++++++++++++ twitter/twitter.php | 39 ++++++++++++++++++++++++++++- 6 files changed, 192 insertions(+), 3 deletions(-) diff --git a/appnet/appnet.php b/appnet/appnet.php index 7e80c6ab..c327bd7d 100644 --- a/appnet/appnet.php +++ b/appnet/appnet.php @@ -1082,6 +1082,30 @@ function appnet_expand_annotations($a, $annotations) { } function appnet_fetchcontact($a, $uid, $contact, $me, $create_user) { + + $r = q("SELECT id FROM unique_contacts WHERE url='%s' LIMIT 1", + dbesc(normalise_link($contact["canonical_url"]))); + + if (count($r) == 0) + q("INSERT INTO unique_contacts (url, name, nick, avatar) VALUES ('%s', '%s', '%s', '%s')", + dbesc(normalise_link($contact["canonical_url"])), + dbesc($contact["name"]), + dbesc($contact["username"]), + dbesc($contact["avatar_image"]["url"])); + else + q("UPDATE unique_contacts SET name = '%s', nick = '%s', avatar = '%s' WHERE url = '%s'", + dbesc($contact["name"]), + dbesc($contact["username"]), + dbesc($contact["avatar_image"]["url"]), + dbesc(normalise_link($contact["canonical_url"]))); + + if (DB_UPDATE_VERSION >= "1177") + q("UPDATE `unique_contacts` SET `location` = '%s', `about` = '%s' WHERE url = '%s'", + dbesc(""), + dbesc($contact["description"]["text"]), + dbesc(normalise_link($contact["canonical_url"]))); + + $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `alias` = '%s' LIMIT 1", intval($uid), dbesc("adn::".$contact["id"])); @@ -1165,6 +1189,14 @@ function appnet_fetchcontact($a, $uid, $contact, $me, $create_user) { intval($contact_id) ); + if (DB_UPDATE_VERSION >= "1177") + q("UPDATE `contact` SET `location` = '%s', + `about` = '%s' + WHERE `id` = %d", + dbesc(""), + dbesc($contact["description"]["text"]), + intval($contact_id) + ); } else { // update profile photos once every two weeks as we have no notification of when they change. @@ -1206,6 +1238,14 @@ function appnet_fetchcontact($a, $uid, $contact, $me, $create_user) { dbesc($contact["username"]), intval($r[0]['id']) ); + if (DB_UPDATE_VERSION >= "1177") + q("UPDATE `contact` SET `location` = '%s', + `about` = '%s' + WHERE `id` = %d", + dbesc(""), + dbesc($contact["description"]["text"]), + intval($r[0]['id']) + ); } } @@ -1265,9 +1305,23 @@ function appnet_cron($a,$b) { } logger('appnet_cron: cron_start'); + $abandon_days = intval(get_config('system','account_abandon_days')); + if ($abandon_days < 1) + $abandon_days = 0; + + $abandon_limit = date("Y-m-d H:i:s", time() - $abandon_days * 86400); + $r = q("SELECT * FROM `pconfig` WHERE `cat` = 'appnet' AND `k` = 'import' AND `v` = '1' ORDER BY RAND()"); if(count($r)) { foreach($r as $rr) { + if ($abandon_days != 0) { + $user = q("SELECT `login_date` FROM `user` WHERE uid=%d AND `login_date` >= '%s'", $rr['uid'], $abandon_limit); + if (!count($user)) { + logger('abandoned account: timeline from user '.$rr['uid'].' will not be imported'); + continue; + } + } + logger('appnet_cron: importing timeline from user '.$rr['uid']); appnet_fetchstream($a, $rr["uid"]); } diff --git a/diaspora/diasphp.php b/diaspora/diasphp.php index 589a5810..6ed0c8ce 100644 --- a/diaspora/diasphp.php +++ b/diaspora/diasphp.php @@ -5,6 +5,8 @@ */ class Diasphp { + private $cookiejar; + function __construct($pod) { $this->token_regex = '/content="(.*?)" name="csrf-token/'; @@ -12,6 +14,11 @@ class Diasphp { $this->cookiejar = tempnam(sys_get_temp_dir(), 'cookies'); } + function __destruct() { + if (file_exists($this->cookiejar)) + unlink($this->cookiejar); + } + function _fetch_token() { $ch = curl_init(); diff --git a/fbsync/fbsync.php b/fbsync/fbsync.php index 39931d5b..20762e9b 100644 --- a/fbsync/fbsync.php +++ b/fbsync/fbsync.php @@ -172,9 +172,24 @@ function fbsync_cron($a,$b) { } logger('fbsync_cron: cron_start'); + $abandon_days = intval(get_config('system','account_abandon_days')); + if ($abandon_days < 1) + $abandon_days = 0; + + $abandon_limit = date("Y-m-d H:i:s", time() - $abandon_days * 86400); + $r = q("SELECT * FROM `pconfig` WHERE `cat` = 'fbsync' AND `k` = 'sync' AND `v` = '1' ORDER BY RAND()"); if(count($r)) { foreach($r as $rr) { + + if ($abandon_days != 0) { + $user = q("SELECT `login_date` FROM `user` WHERE uid=%d AND `login_date` >= '%s'", $rr['uid'], $abandon_limit); + if (!count($user)) { + logger('abandoned account: timeline from user '.$rr['uid'].' will not be imported'); + continue; + } + } + fbsync_get_self($rr['uid']); logger('fbsync_cron: importing timeline from user '.$rr['uid']); diff --git a/pumpio/pumpio.php b/pumpio/pumpio.php index 48dbab74..cb2ee000 100644 --- a/pumpio/pumpio.php +++ b/pumpio/pumpio.php @@ -624,9 +624,23 @@ function pumpio_cron(&$a,$b) { } } + $abandon_days = intval(get_config('system','account_abandon_days')); + if ($abandon_days < 1) + $abandon_days = 0; + + $abandon_limit = date("Y-m-d H:i:s", time() - $abandon_days * 86400); + $r = q("SELECT * FROM `pconfig` WHERE `cat` = 'pumpio' AND `k` = 'import' AND `v` = '1' ORDER BY RAND() "); if(count($r)) { foreach($r as $rr) { + if ($abandon_days != 0) { + $user = q("SELECT `login_date` FROM `user` WHERE uid=%d AND `login_date` >= '%s'", $rr['uid'], $abandon_limit); + if (!count($user)) { + logger('abandoned account: timeline from user '.$rr['uid'].' will not be imported'); + continue; + } + } + logger('pumpio: importing timeline from user '.$rr['uid']); pumpio_fetchinbox($a, $rr['uid']); @@ -919,6 +933,12 @@ function pumpio_get_contact($uid, $contact) { dbesc($contact->image->url), dbesc(normalise_link($contact->url))); + if (DB_UPDATE_VERSION >= "1177") + q("UPDATE `unique_contacts` SET `location` = '%s', `about` = '%s' WHERE url = '%s'", + dbesc($contact->location->displayName), + dbesc($contact->summary), + dbesc(normalise_link($contact->url))); + $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `url` = '%s' LIMIT 1", intval($uid), dbesc($contact->url)); @@ -984,10 +1004,19 @@ function pumpio_get_contact($uid, $contact) { dbesc(datetime_convert()), intval($contact_id) ); + + if (DB_UPDATE_VERSION >= "1177") + q("UPDATE `contact` SET `location` = '%s', + `about` = '%s' + WHERE `id` = %d", + dbesc($contact->location->displayName), + dbesc($contact->summary), + intval($contact_id) + ); } else { // update profile photos once every two weeks as we have no notification of when they change. - - $update_photo = (($r[0]['avatar-date'] < datetime_convert('','','now -14 days')) ? true : false); + //$update_photo = (($r[0]['avatar-date'] < datetime_convert('','','now -14 days')) ? true : false); + $update_photo = ($r[0]['avatar-date'] < datetime_convert('','','now -12 hours')); // check that we have all the photos, this has been known to fail on occasion @@ -1016,6 +1045,15 @@ function pumpio_get_contact($uid, $contact) { dbesc($contact->preferredUsername), intval($r[0]['id']) ); + + if (DB_UPDATE_VERSION >= "1177") + q("UPDATE `contact` SET `location` = '%s', + `about` = '%s' + WHERE `id` = %d", + dbesc($contact->location->displayName), + dbesc($contact->summary), + intval($r[0]['id']) + ); } } diff --git a/statusnet/statusnet.php b/statusnet/statusnet.php index 7d0f80c3..f4dc7553 100644 --- a/statusnet/statusnet.php +++ b/statusnet/statusnet.php @@ -758,9 +758,23 @@ function statusnet_cron($a,$b) { } } + $abandon_days = intval(get_config('system','account_abandon_days')); + if ($abandon_days < 1) + $abandon_days = 0; + + $abandon_limit = date("Y-m-d H:i:s", time() - $abandon_days * 86400); + $r = q("SELECT * FROM `pconfig` WHERE `cat` = 'statusnet' AND `k` = 'import' AND `v` = '1' ORDER BY RAND()"); if(count($r)) { foreach($r as $rr) { + if ($abandon_days != 0) { + $user = q("SELECT `login_date` FROM `user` WHERE uid=%d AND `login_date` >= '%s'", $rr['uid'], $abandon_limit); + if (!count($user)) { + logger('abandoned account: timeline from user '.$rr['uid'].' will not be imported'); + continue; + } + } + logger('statusnet: importing timeline from user '.$rr['uid']); statusnet_fetchhometimeline($a, $rr["uid"]); } @@ -898,6 +912,12 @@ function statusnet_fetch_contact($uid, $contact, $create_user) { dbesc($contact->profile_image_url), dbesc(normalise_link($contact->statusnet_profile_url))); + if (DB_UPDATE_VERSION >= "1177") + q("UPDATE `unique_contacts` SET `location` = '%s', `about` = '%s' WHERE url = '%s'", + dbesc($contact->location), + dbesc($contact->description), + dbesc(normalise_link($contact->statusnet_profile_url))); + $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `alias` = '%s' LIMIT 1", intval($uid), dbesc(normalise_link($contact->statusnet_profile_url))); @@ -967,6 +987,15 @@ function statusnet_fetch_contact($uid, $contact, $create_user) { intval($contact_id) ); + if (DB_UPDATE_VERSION >= "1177") + q("UPDATE `contact` SET `location` = '%s', + `about` = '%s' + WHERE `id` = %d", + dbesc($contact->location), + dbesc($contact->description), + intval($contact_id) + ); + } else { // update profile photos once every two weeks as we have no notification of when they change. @@ -1008,6 +1037,15 @@ function statusnet_fetch_contact($uid, $contact, $create_user) { dbesc($contact->screen_name), intval($r[0]['id']) ); + + if (DB_UPDATE_VERSION >= "1177") + q("UPDATE `contact` SET `location` = '%s', + `about` = '%s' + WHERE `id` = %d", + dbesc($contact->location), + dbesc($contact->description), + intval($r[0]['id']) + ); } } diff --git a/twitter/twitter.php b/twitter/twitter.php index 380121c2..2482a30c 100644 --- a/twitter/twitter.php +++ b/twitter/twitter.php @@ -603,10 +603,23 @@ function twitter_cron($a,$b) { } } + $abandon_days = intval(get_config('system','account_abandon_days')); + if ($abandon_days < 1) + $abandon_days = 0; + + $abandon_limit = date("Y-m-d H:i:s", time() - $abandon_days * 86400); $r = q("SELECT * FROM `pconfig` WHERE `cat` = 'twitter' AND `k` = 'import' AND `v` = '1' ORDER BY RAND()"); if(count($r)) { foreach($r as $rr) { + if ($abandon_days != 0) { + $user = q("SELECT `login_date` FROM `user` WHERE uid=%d AND `login_date` >= '%s'", $rr['uid'], $abandon_limit); + if (!count($user)) { + logger('abandoned account: timeline from user '.$rr['uid'].' will not be imported'); + continue; + } + } + logger('twitter: importing timeline from user '.$rr['uid']); twitter_fetchhometimeline($a, $rr["uid"]); @@ -924,6 +937,12 @@ function twitter_fetch_contact($uid, $contact, $create_user) { dbesc($avatar), dbesc(normalise_link("https://twitter.com/".$contact->screen_name))); + if (DB_UPDATE_VERSION >= "1177") + q("UPDATE `unique_contacts` SET `location` = '%s', `about` = '%s' WHERE url = '%s'", + dbesc($contact->location), + dbesc($contact->description), + 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)); @@ -940,7 +959,7 @@ function twitter_fetch_contact($uid, $contact, $create_user) { q("INSERT INTO `contact` ( `uid`, `created`, `url`, `nurl`, `addr`, `alias`, `notify`, `poll`, `name`, `nick`, `photo`, `network`, `rel`, `priority`, `writable`, `blocked`, `readonly`, `pending` ) - VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, 0, 0, 0 ) ", + VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, 0, 0, 0) ", intval($uid), dbesc(datetime_convert()), dbesc("https://twitter.com/".$contact->screen_name), @@ -997,6 +1016,15 @@ function twitter_fetch_contact($uid, $contact, $create_user) { intval($contact_id) ); + if (DB_UPDATE_VERSION >= "1177") + q("UPDATE `contact` SET `location` = '%s', + `about` = '%s' + WHERE `id` = %d", + dbesc($contact->location), + dbesc($contact->description), + intval($contact_id) + ); + } else { // update profile photos once every two weeks as we have no notification of when they change. @@ -1038,6 +1066,15 @@ function twitter_fetch_contact($uid, $contact, $create_user) { dbesc($contact->screen_name), intval($r[0]['id']) ); + + if (DB_UPDATE_VERSION >= "1177") + q("UPDATE `contact` SET `location` = '%s', + `about` = '%s' + WHERE `id` = %d", + dbesc($contact->location), + dbesc($contact->description), + intval($r[0]['id']) + ); } } -- 2.43.4 From 7ba157a68d195a75fee5363112cff1eb13108816 Mon Sep 17 00:00:00 2001 From: gerhard6380 Date: Sat, 17 Jan 2015 21:58:18 +0100 Subject: [PATCH 2/5] windowsphonepush Version 2.0 add functionality to highlight new entries in Windows Phone app, bugfix on sql for counter (likes/dislikes now excluded) --- windowsphonepush/windowsphonepush.php | 50 ++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/windowsphonepush/windowsphonepush.php b/windowsphonepush/windowsphonepush.php index 9938edc7..21f986e0 100644 --- a/windowsphonepush/windowsphonepush.php +++ b/windowsphonepush/windowsphonepush.php @@ -2,7 +2,7 @@ /** * Name: WindowsPhonePush * Description: Enable push notification to send information to Friendica Mobile app on Windows phone (count of unread timeline entries, text of last posting - if wished by user) - * Version: 1.1 + * Version: 2.0 * Author: Gerhard Seeber * * @@ -18,6 +18,11 @@ * Version history: * 1.1 : addon crashed on php versions >= 5.4 as of removed deprecated call-time * pass-by-reference used in function calls within function windowsphonepush_content + * 2.0 : adaption for supporting emphasizing new entries in app (count on tile cannot be read out, + * so we need to retrieve counter through show_settings secondly). Provide new function for + * calling from app to set the counter back after start (if user starts again before cronjob + * sets the counter back + * count only unseen elements which are not type=activity (likes and dislikes not seen as new elements) */ @@ -81,8 +86,13 @@ function windowsphonepush_module() {} function windowsphonepush_settings_post($a,$post) { if(! local_user() || (! x($_POST,'windowsphonepush-submit'))) return; + $enable = intval($_POST['windowsphonepush']); + set_pconfig(local_user(),'windowsphonepush','enable',$enable); + + if($enable) { + set_pconfig(local_user(),'windowsphonepush','counterunseen', 0); + } - set_pconfig(local_user(),'windowsphonepush','enable',intval($_POST['windowsphonepush'])); set_pconfig(local_user(),'windowsphonepush','senditemtext',intval($_POST['windowsphonepush-senditemtext'])); info( t('WindowsPhonePush settings updated.') . EOL); @@ -164,7 +174,7 @@ function windowsphonepush_cron() { } else { // retrieve the number of unseen items and the id of the latest one (if there are more than // one new entries since last poller run, only the latest one will be pushed) - $count = q("SELECT count(`id`) as count, max(`id`) as max FROM `item` WHERE `unseen` = 1 AND `uid` = %d", + $count = q("SELECT count(`id`) as count, max(`id`) as max FROM `item` WHERE `unseen` = 1 AND `type` <> 'activity' AND `uid` = %d", intval($rr['uid']) ); @@ -174,7 +184,8 @@ function windowsphonepush_cron() { $res_tile = send_tile_update($device_url, "", $count[0]['count'], ""); switch (trim($res_tile)) { case "Received": - // ok, count has been pushed + // ok, count has been pushed, let's save it in personal settings + set_pconfig($rr['uid'], 'windowsphonepush', 'counterunseen', $count[0]['count']); break; case "QueueFull": // maximum of 30 messages reached, server rejects any further push notification until device reconnects @@ -342,6 +353,7 @@ function get_header_value($content, $header) { * reading information from url and deciding which function to start * show_settings = delivering settings to check * update_settings = set the device_url + * update_counterunseen = set counter for unseen elements to zero * */ function windowsphonepush_content(&$a) { @@ -362,6 +374,12 @@ function windowsphonepush_content(&$a) { echo json_encode(array('status' => $ret)); killme(); break; + case "update_counterunseen": + $ret = windowsphonepush_updatecounterunseen(); + header("Content-Type: application/json; charset=utf-8"); + echo json_encode(array('status' => $ret)); + killme(); + break; default: echo "Fehler"; } @@ -379,6 +397,8 @@ function windowsphonepush_showsettings(&$a) { $device_url = get_pconfig(local_user(), 'windowsphonepush', 'device_url'); $senditemtext = get_pconfig(local_user(), 'windowsphonepush', 'senditemtext'); $lastpushid = get_pconfig(local_user(), 'windowsphonepush', 'lastpushid'); + $counterunseen = get_pconfig(local_user(), 'windowsphonepush', 'counterunseen'); + $addonversion = "2.0"; if (!$device_url) $device_url = ""; @@ -391,7 +411,9 @@ function windowsphonepush_showsettings(&$a) { 'enable' => $enable, 'device_url' => $device_url, 'senditemtext' => $senditemtext, - 'lastpushid' => $lastpushid)); + 'lastpushid' => $lastpushid, + 'counterunseen' => $counterunseen, + 'addonversion' => $addonversion)); } /* @@ -437,6 +459,24 @@ function windowsphonepush_updatesettings(&$a) { return "Device-URL updated successfully!"; } +/* + * update_counterunseen is used to reset the counter to zero from Windows Phone app + */ +function windowsphonepush_updatecounterunseen() { + if(! local_user()) { + return "Not Authenticated"; + } + + // no updating if user hasn't enabled the plugin + $enable = get_pconfig(local_user(), 'windowsphonepush', 'enable'); + if(! $enable) { + return "Plug-in not enabled"; + } + + set_pconfig(local_user(),'windowsphonepush','counterunseen', 0); + return "Counter set to zero"; +} + /* * helper function to login to the server with the specified Network credentials * (mainly copied from api.php) -- 2.43.4 From b3fef08d41d9468cba4af898ab856a500eca60f2 Mon Sep 17 00:00:00 2001 From: Keith Fernie Date: Mon, 19 Jan 2015 19:46:37 +0000 Subject: [PATCH 3/5] modified: bufferapp.php Now begins with Date: Tue, 20 Jan 2015 00:05:38 +0000 Subject: [PATCH 4/5] merge bufferapp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Eric Côté --- dav/friendica/main.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dav/friendica/main.php b/dav/friendica/main.php index 0fe939eb..1025a786 100644 --- a/dav/friendica/main.php +++ b/dav/friendica/main.php @@ -253,6 +253,7 @@ function dav_cron(&$a, &$b) dav_include_files(); $r = q("SELECT * FROM %s%snotifications WHERE `notified` = 0 AND `alert_date` <= NOW()", CALDAV_SQL_DB, CALDAV_SQL_PREFIX); + if (is_array($r)) { foreach ($r as $not) { q("UPDATE %s%snotifications SET `notified` = 1 WHERE `id` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, $not["id"]); $event = q("SELECT * FROM %s%sjqcalendar WHERE `calendarobject_id` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, $not["calendarobject_id"]); @@ -290,6 +291,7 @@ function dav_cron(&$a, &$b) break; } } + } } -- 2.43.4 From e5ced279be55dfeb5315cb216065d96b8e2b4e20 Mon Sep 17 00:00:00 2001 From: fabrixxm Date: Tue, 20 Jan 2015 19:27:00 +0100 Subject: [PATCH 5/5] securemail: null html body send encrpyted mail only as text --- securemail/securemail.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/securemail/securemail.php b/securemail/securemail.php index 306d12b4..27b638f9 100644 --- a/securemail/securemail.php +++ b/securemail/securemail.php @@ -85,9 +85,8 @@ function securemail_emailer_send_prepare(&$a, &$b) { # using the key, encrypt your plain text using the public key $txt_encrypted = $gpg->encrypt($pub_key,$b['textVersion']); - $html_encrypted = $gpg->encrypt($pub_key,$b['htmlVersion']); + #$html_encrypted = $gpg->encrypt($pub_key,$b['htmlVersion']); $b['textVersion'] = $txt_encrypted; - $b['htmlVersion'] = $html_encrypted; - #var_dump($b); + $b['htmlVersion'] = null; } -- 2.43.4