forked from friendica/friendica-addons
Merge pull request #231 from annando/master
Support for the new database fields in contact and unique_contacts
This commit is contained in:
commit
b93b298bbc
|
@ -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"]);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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']);
|
||||
|
|
|
@ -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'])
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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'])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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));
|
||||
|
||||
|
@ -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'])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue