forked from friendica/friendica-addons
More replaced "q" calls
This commit is contained in:
parent
24ffee74d7
commit
16d7eafd41
|
@ -14,6 +14,7 @@ use Friendica\Core\Renderer;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
use Friendica\Model\Notification;
|
use Friendica\Model\Notification;
|
||||||
|
use Friendica\Model\User;
|
||||||
use Friendica\Util\ConfigFileLoader;
|
use Friendica\Util\ConfigFileLoader;
|
||||||
use Friendica\Util\DateTimeFormat;
|
use Friendica\Util\DateTimeFormat;
|
||||||
use Friendica\Util\Strings;
|
use Friendica\Util\Strings;
|
||||||
|
@ -50,13 +51,9 @@ function public_server_cron($a, $b)
|
||||||
{
|
{
|
||||||
Logger::log("public_server: cron start");
|
Logger::log("public_server: cron start");
|
||||||
|
|
||||||
$r = q("SELECT * FROM `user` WHERE `account_expires_on` < UTC_TIMESTAMP() + INTERVAL 5 DAY AND
|
$users = DBA::selectToArray('user', [], ["`account_expires_on` < UTC_TIMESTAMP() + INTERVAL ? DAY AND
|
||||||
`account_expires_on` > '%s' AND
|
`account_expires_on` > ? AND `expire_notification_sent` <= ?", 5, DBA::NULL_DATETIME, DBA::NULL_DATETIME]);
|
||||||
`expire_notification_sent` <= '%s'",
|
foreach ($users as $rr) {
|
||||||
DBA::NULL_DATETIME, DBA::NULL_DATETIME);
|
|
||||||
|
|
||||||
if (DBA::isResult($r)) {
|
|
||||||
foreach ($r as $rr) {
|
|
||||||
notification([
|
notification([
|
||||||
'type' => Notification\Type::SYSTEM,
|
'type' => Notification\Type::SYSTEM,
|
||||||
'uid' => $rr['uid'],
|
'uid' => $rr['uid'],
|
||||||
|
@ -69,43 +66,36 @@ function public_server_cron($a, $b)
|
||||||
$fields = ['expire_notification_sent' => DateTimeFormat::utcNow()];
|
$fields = ['expire_notification_sent' => DateTimeFormat::utcNow()];
|
||||||
DBA::update('user', $fields, ['uid' => $rr['uid']]);
|
DBA::update('user', $fields, ['uid' => $rr['uid']]);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$nologin = DI::config()->get('public_server', 'nologin', false);
|
$nologin = DI::config()->get('public_server', 'nologin', false);
|
||||||
if ($nologin) {
|
if ($nologin) {
|
||||||
$r = q("SELECT `uid` FROM `user` WHERE NOT `account_expired` AND `login_date` <= '%s' AND `register_date` < UTC_TIMESTAMP() - INTERVAL %d DAY AND `account_expires_on` <= '%s'",
|
$users = DBA::selectToArray('user', [], ["NOT `account_expired` AND `login_date` <= ? AND `register_date` < UTC_TIMESTAMP() - INTERVAL ? DAY AND `account_expires_on` <= ?",
|
||||||
DBA::NULL_DATETIME, intval($nologin), DBA::NULL_DATETIME);
|
DBA::NULL_DATETIME, $nologin, DBA::NULL_DATETIME]);
|
||||||
if (DBA::isResult($r)) {
|
foreach ($users as $rr) {
|
||||||
foreach ($r as $rr) {
|
|
||||||
$fields = ['account_expires_on' => DateTimeFormat::utc('now +6 days')];
|
$fields = ['account_expires_on' => DateTimeFormat::utc('now +6 days')];
|
||||||
DBA::update('user', $fields, ['uid' => $rr['uid']]);
|
DBA::update('user', $fields, ['uid' => $rr['uid']]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$flagusers = DI::config()->get('public_server', 'flagusers', false);
|
$flagusers = DI::config()->get('public_server', 'flagusers', false);
|
||||||
if ($flagusers) {
|
if ($flagusers) {
|
||||||
$r = q("SELECT `uid` FROM `user` WHERE NOT `account_expired` AND `login_date` < UTC_TIMESTAMP() - INTERVAL %d DAY AND `account_expires_on` <= '%s' AND `page-flags` = 0",
|
$users = DBA::selectToArray('user', [], ["NOT `account_expired` AND `login_date` < UTC_TIMESTAMP() - INTERVAL ? DAY AND `account_expires_on` <= ? AND `page-flags` = ?",
|
||||||
intval($flagusers), DBA::NULL_DATETIME);
|
$flagusers, DBA::NULL_DATETIME, User::PAGE_FLAGS_NORMAL]);
|
||||||
if (DBA::isResult($r)) {
|
foreach ($users as $rr) {
|
||||||
foreach ($r as $rr) {
|
|
||||||
$fields = ['account_expires_on' => DateTimeFormat::utc('now +6 days')];
|
$fields = ['account_expires_on' => DateTimeFormat::utc('now +6 days')];
|
||||||
DBA::update('user', $fields, ['uid' => $rr['uid']]);
|
DBA::update('user', $fields, ['uid' => $rr['uid']]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$flagposts = DI::config()->get('public_server', 'flagposts');
|
$flagposts = DI::config()->get('public_server', 'flagposts');
|
||||||
$flagpostsexpire = DI::config()->get('public_server', 'flagpostsexpire');
|
$flagpostsexpire = DI::config()->get('public_server', 'flagpostsexpire');
|
||||||
if ($flagposts && $flagpostsexpire) {
|
if ($flagposts && $flagpostsexpire) {
|
||||||
$r = q("SELECT `uid` FROM `user` WHERE NOT `account_expired` AND `login_date` < UTC_TIMESTAMP() - INTERVAL %d DAY AND `account_expires_on` <= '%s' and `expire` = 0 AND `page-flags` = 0",
|
$users = DBA::selectToArray('user', [], ["NOT `account_expired` AND `login_date` < UTC_TIMESTAMP() - INTERVAL ? DAY AND `account_expires_on` <= ? AND NOT `expire` AND `page-flags` = ?",
|
||||||
intval($flagposts), DBA::NULL_DATETIME);
|
$flagposts, DBA::NULL_DATETIME, User::PAGE_FLAGS_NORMAL]);
|
||||||
if (DBA::isResult($r)) {
|
foreach ($users as $rr) {
|
||||||
foreach ($r as $rr) {
|
|
||||||
DBA::update('user', ['expire' => $flagpostsexpire], ['uid' => $rr['uid']]);
|
DBA::update('user', ['expire' => $flagpostsexpire], ['uid' => $rr['uid']]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Logger::log("public_server: cron end");
|
Logger::log("public_server: cron end");
|
||||||
}
|
}
|
||||||
|
|
|
@ -767,13 +767,11 @@ function statusnet_cron(App $a, $b)
|
||||||
}
|
}
|
||||||
Logger::notice('statusnet: cron_start');
|
Logger::notice('statusnet: cron_start');
|
||||||
|
|
||||||
$r = q("SELECT * FROM `pconfig` WHERE `cat` = 'statusnet' AND `k` = 'mirror_posts' AND `v` = '1' ORDER BY RAND() ");
|
$pconfigs = DBA::selectToArray('pconfig', [], ['cat' => 'statusnet', 'k' => 'mirror_posts', 'v' => true]);
|
||||||
if (DBA::isResult($r)) {
|
foreach ($pconfigs as $rr) {
|
||||||
foreach ($r as $rr) {
|
|
||||||
Logger::notice('statusnet: fetching for user ' . $rr['uid']);
|
Logger::notice('statusnet: fetching for user ' . $rr['uid']);
|
||||||
statusnet_fetchtimeline($a, $rr['uid']);
|
statusnet_fetchtimeline($a, $rr['uid']);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$abandon_days = intval(DI::config()->get('system', 'account_abandon_days'));
|
$abandon_days = intval(DI::config()->get('system', 'account_abandon_days'));
|
||||||
if ($abandon_days < 1) {
|
if ($abandon_days < 1) {
|
||||||
|
@ -782,12 +780,10 @@ function statusnet_cron(App $a, $b)
|
||||||
|
|
||||||
$abandon_limit = date(DateTimeFormat::MYSQL, time() - $abandon_days * 86400);
|
$abandon_limit = date(DateTimeFormat::MYSQL, time() - $abandon_days * 86400);
|
||||||
|
|
||||||
$r = q("SELECT * FROM `pconfig` WHERE `cat` = 'statusnet' AND `k` = 'import' AND `v` ORDER BY RAND()");
|
$pconfigs = DBA::selectToArray('pconfig', [], ['cat' => 'statusnet', 'k' => 'import', 'v' => true]);
|
||||||
if (DBA::isResult($r)) {
|
foreach ($pconfigs as $rr) {
|
||||||
foreach ($r as $rr) {
|
|
||||||
if ($abandon_days != 0) {
|
if ($abandon_days != 0) {
|
||||||
$user = q("SELECT `login_date` FROM `user` WHERE uid=%d AND `login_date` >= '%s'", $rr['uid'], $abandon_limit);
|
if (!DBA::exists('user', ["`uid` = ? AND `login_date` >= ?", $rr['uid'], $abandon_limit])) {
|
||||||
if (!DBA::isResult($user)) {
|
|
||||||
Logger::notice('abandoned account: timeline from user ' . $rr['uid'] . ' will not be imported');
|
Logger::notice('abandoned account: timeline from user ' . $rr['uid'] . ' will not be imported');
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -796,7 +792,6 @@ function statusnet_cron(App $a, $b)
|
||||||
Logger::notice('statusnet: importing timeline from user ' . $rr['uid']);
|
Logger::notice('statusnet: importing timeline from user ' . $rr['uid']);
|
||||||
statusnet_fetchhometimeline($a, $rr["uid"], $rr["v"]);
|
statusnet_fetchhometimeline($a, $rr["uid"], $rr["v"]);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Logger::notice('statusnet: cron_end');
|
Logger::notice('statusnet: cron_end');
|
||||||
|
|
||||||
|
@ -929,112 +924,89 @@ function statusnet_fetch_contact($uid, $contact, $create_user)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `alias` = '%s' AND `network` = '%s'LIMIT 1", intval($uid), DBA::escape(Strings::normaliseLink($contact->statusnet_profile_url)), DBA::escape(Protocol::STATUSNET));
|
$contact_record = Contact::selectFirst([],
|
||||||
|
['alias' => Strings::normaliseLink($contact->statusnet_profile_url), 'uid' => $uid, 'network' => Protocol::STATUSNET]);
|
||||||
|
|
||||||
if (!DBA::isResult($r) && !$create_user) {
|
if (!DBA::isResult($contact_record) && !$create_user) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DBA::isResult($r) && ($r[0]["readonly"] || $r[0]["blocked"])) {
|
if (DBA::isResult($contact_record) && ($contact_record["readonly"] || $contact_record["blocked"])) {
|
||||||
Logger::info("statusnet_fetch_contact: Contact '" . $r[0]["nick"] . "' is blocked or readonly.");
|
Logger::info("statusnet_fetch_contact: Contact '" . $contact_record["nick"] . "' is blocked or readonly.");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!DBA::isResult($r)) {
|
if (!DBA::isResult($contact_record)) {
|
||||||
// create contact record
|
// create contact record
|
||||||
q("INSERT INTO `contact` ( `uid`, `created`, `url`, `nurl`, `addr`, `alias`, `notify`, `poll`,
|
$fields['uid'] = $uid;
|
||||||
`name`, `nick`, `photo`, `network`, `rel`, `priority`,
|
$fields['created'] = DateTimeFormat::utcNow();
|
||||||
`location`, `about`, `writable`, `blocked`, `readonly`, `pending` )
|
$fields['url'] = $contact->statusnet_profile_url;
|
||||||
VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', '%s', %d, 0, 0, 0 ) ",
|
$fields['nurl'] = Strings::normaliseLink($contact->statusnet_profile_url);
|
||||||
intval($uid),
|
$fields['addr'] = statusnet_address($contact);
|
||||||
DBA::escape(DateTimeFormat::utcNow()),
|
$fields['alias'] = Strings::normaliseLink($contact->statusnet_profile_url);
|
||||||
DBA::escape($contact->statusnet_profile_url),
|
$fields['notify'] = '';
|
||||||
DBA::escape(Strings::normaliseLink($contact->statusnet_profile_url)),
|
$fields['poll'] = '';
|
||||||
DBA::escape(statusnet_address($contact)),
|
$fields['name'] = $contact->name;
|
||||||
DBA::escape(Strings::normaliseLink($contact->statusnet_profile_url)),
|
$fields['nick'] = $contact->screen_name;
|
||||||
DBA::escape(''),
|
$fields['photo'] = $contact->profile_image_url;
|
||||||
DBA::escape(''),
|
$fields['network'] = Protocol::STATUSNET;
|
||||||
DBA::escape($contact->name),
|
$fields['rel'] = Contact::FRIEND;
|
||||||
DBA::escape($contact->screen_name),
|
$fields['priority'] = 1;
|
||||||
DBA::escape($contact->profile_image_url),
|
$fields['location'] = $contact->location;
|
||||||
DBA::escape(Protocol::STATUSNET),
|
$fields['about'] = $contact->description;
|
||||||
intval(Contact::FRIEND),
|
$fields['writable'] = true;
|
||||||
intval(1),
|
$fields['blocked'] = false;
|
||||||
DBA::escape($contact->location),
|
$fields['readonly'] = false;
|
||||||
DBA::escape($contact->description),
|
$fields['pending'] = false;
|
||||||
intval(1)
|
|
||||||
);
|
|
||||||
|
|
||||||
$r = q("SELECT * FROM `contact` WHERE `alias` = '%s' AND `uid` = %d AND `network` = '%s' LIMIT 1",
|
if (!Contact::insert($fields)) {
|
||||||
DBA::escape($contact->statusnet_profile_url),
|
|
||||||
intval($uid),
|
|
||||||
DBA::escape(Protocol::STATUSNET));
|
|
||||||
|
|
||||||
if (!DBA::isResult($r)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$contact_id = $r[0]['id'];
|
$contact_record = Contact::selectFirst([],
|
||||||
|
['alias' => Strings::normaliseLink($contact->statusnet_profile_url), 'uid' => $uid, 'network' => Protocol::STATUSNET]);
|
||||||
|
if (!DBA::isResult($contact_record)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$contact_id = $contact_record['id'];
|
||||||
|
|
||||||
Group::addMember(User::getDefaultGroup($uid), $contact_id);
|
Group::addMember(User::getDefaultGroup($uid), $contact_id);
|
||||||
|
|
||||||
$photos = Photo::importProfilePhoto($contact->profile_image_url, $uid, $contact_id);
|
$photos = Photo::importProfilePhoto($contact->profile_image_url, $uid, $contact_id);
|
||||||
|
|
||||||
q("UPDATE `contact` SET `photo` = '%s',
|
Contact::update(['photo' => $photos[0], 'thumb' => $photos[1],
|
||||||
`thumb` = '%s',
|
'micro' => $photos[2], 'avatar-date' => DateTimeFormat::utcNow()], ['id' => $contact_id]);
|
||||||
`micro` = '%s',
|
|
||||||
`avatar-date` = '%s'
|
|
||||||
WHERE `id` = %d",
|
|
||||||
DBA::escape($photos[0]),
|
|
||||||
DBA::escape($photos[1]),
|
|
||||||
DBA::escape($photos[2]),
|
|
||||||
DBA::escape(DateTimeFormat::utcNow()),
|
|
||||||
intval($contact_id)
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
// update profile photos once every two weeks as we have no notification of when they change.
|
// update profile photos once every two weeks as we have no notification of when they change.
|
||||||
//$update_photo = (($r[0]['avatar-date'] < DateTimeFormat::convert('now -2 days', '', '', )) ? true : false);
|
//$update_photo = (($contact_record['avatar-date'] < DateTimeFormat::convert('now -2 days', '', '', )) ? true : false);
|
||||||
$update_photo = ($r[0]['avatar-date'] < DateTimeFormat::utc('now -12 hours'));
|
$update_photo = ($contact_record['avatar-date'] < DateTimeFormat::utc('now -12 hours'));
|
||||||
|
|
||||||
// check that we have all the photos, this has been known to fail on occasion
|
// check that we have all the photos, this has been known to fail on occasion
|
||||||
if ((!$r[0]['photo']) || (!$r[0]['thumb']) || (!$r[0]['micro']) || ($update_photo)) {
|
if ((!$contact_record['photo']) || (!$contact_record['thumb']) || (!$contact_record['micro']) || ($update_photo)) {
|
||||||
Logger::info("statusnet_fetch_contact: Updating contact " . $contact->screen_name);
|
Logger::info("statusnet_fetch_contact: Updating contact " . $contact->screen_name);
|
||||||
|
|
||||||
$photos = Photo::importProfilePhoto($contact->profile_image_url, $uid, $r[0]['id']);
|
$photos = Photo::importProfilePhoto($contact->profile_image_url, $uid, $contact_record['id']);
|
||||||
|
|
||||||
q("UPDATE `contact` SET `photo` = '%s',
|
Contact::update([
|
||||||
`thumb` = '%s',
|
'photo' => $photos[0],
|
||||||
`micro` = '%s',
|
'thumb' => $photos[1],
|
||||||
`name-date` = '%s',
|
'micro' => $photos[2],
|
||||||
`uri-date` = '%s',
|
'name-date' => DateTimeFormat::utcNow(),
|
||||||
`avatar-date` = '%s',
|
'uri-date' => DateTimeFormat::utcNow(),
|
||||||
`url` = '%s',
|
'avatar-date' => DateTimeFormat::utcNow(),
|
||||||
`nurl` = '%s',
|
'url' => $contact->statusnet_profile_url,
|
||||||
`addr` = '%s',
|
'nurl' => Strings::normaliseLink($contact->statusnet_profile_url),
|
||||||
`name` = '%s',
|
'addr' => statusnet_address($contact),
|
||||||
`nick` = '%s',
|
'name' => $contact->name,
|
||||||
`location` = '%s',
|
'nick' => $contact->screen_name,
|
||||||
`about` = '%s'
|
'location' => $contact->location,
|
||||||
WHERE `id` = %d",
|
'about' => $contact->description
|
||||||
DBA::escape($photos[0]),
|
], ['id' => $contact_record['id']]);
|
||||||
DBA::escape($photos[1]),
|
|
||||||
DBA::escape($photos[2]),
|
|
||||||
DBA::escape(DateTimeFormat::utcNow()),
|
|
||||||
DBA::escape(DateTimeFormat::utcNow()),
|
|
||||||
DBA::escape(DateTimeFormat::utcNow()),
|
|
||||||
DBA::escape($contact->statusnet_profile_url),
|
|
||||||
DBA::escape(Strings::normaliseLink($contact->statusnet_profile_url)),
|
|
||||||
DBA::escape(statusnet_address($contact)),
|
|
||||||
DBA::escape($contact->name),
|
|
||||||
DBA::escape($contact->screen_name),
|
|
||||||
DBA::escape($contact->location),
|
|
||||||
DBA::escape($contact->description),
|
|
||||||
intval($r[0]['id'])
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $r[0]["id"];
|
return $contact_record["id"];
|
||||||
}
|
}
|
||||||
|
|
||||||
function statusnet_fetchuser(App $a, $uid, $screen_name = "", $user_id = "")
|
function statusnet_fetchuser(App $a, $uid, $screen_name = "", $user_id = "")
|
||||||
|
@ -1051,12 +1023,8 @@ function statusnet_fetchuser(App $a, $uid, $screen_name = "", $user_id = "")
|
||||||
$cb->setConsumerKey($ckey, $csecret);
|
$cb->setConsumerKey($ckey, $csecret);
|
||||||
$cb->setToken($otoken, $osecret);
|
$cb->setToken($otoken, $osecret);
|
||||||
|
|
||||||
$r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1",
|
$self = Contact::selectFirst([], ['self' => true, 'uid' => $uid]);
|
||||||
intval($uid));
|
if (!DBA::isResult($self)) {
|
||||||
|
|
||||||
if (DBA::isResult($r)) {
|
|
||||||
$self = $r[0];
|
|
||||||
} else {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1128,15 +1096,13 @@ function statusnet_createpost(App $a, $uid, $post, $self, $create_user, $only_ex
|
||||||
$own_url = DI::pConfig()->get($uid, 'statusnet', 'own_url');
|
$own_url = DI::pConfig()->get($uid, 'statusnet', 'own_url');
|
||||||
|
|
||||||
if ($content->user->id == $own_url) {
|
if ($content->user->id == $own_url) {
|
||||||
$r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1",
|
$self = DBA::selectFirst([], ['self' => true, 'uid' => $uid]);
|
||||||
intval($uid));
|
if (DBA::isResult($self)) {
|
||||||
|
$contactid = $self["id"];
|
||||||
|
|
||||||
if (DBA::isResult($r)) {
|
$postarray['owner-name'] = $self["name"];
|
||||||
$contactid = $r[0]["id"];
|
$postarray['owner-link'] = $self["url"];
|
||||||
|
$postarray['owner-avatar'] = $self["photo"];
|
||||||
$postarray['owner-name'] = $r[0]["name"];
|
|
||||||
$postarray['owner-link'] = $r[0]["url"];
|
|
||||||
$postarray['owner-avatar'] = $r[0]["photo"];
|
|
||||||
} else {
|
} else {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
@ -1230,30 +1196,22 @@ function statusnet_fetchhometimeline(App $a, $uid, $mode = 1)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
|
$contact = Contact::selectFirst([], ['id' => $own_contact, 'uid' => $uid]);
|
||||||
intval($own_contact),
|
if (DBA::isResult($contact)) {
|
||||||
intval($uid));
|
$nick = $contact["nick"];
|
||||||
|
|
||||||
if (DBA::isResult($r)) {
|
|
||||||
$nick = $r[0]["nick"];
|
|
||||||
} else {
|
} else {
|
||||||
Logger::info("statusnet_fetchhometimeline: Own GNU Social contact not found for user " . $uid);
|
Logger::info("statusnet_fetchhometimeline: Own GNU Social contact not found for user " . $uid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1",
|
$self = Contact::selectFirst([], ['self' => true, 'uid' => $uid]);
|
||||||
intval($uid));
|
if (!DBA::isResult($self)) {
|
||||||
|
|
||||||
if (DBA::isResult($r)) {
|
|
||||||
$self = $r[0];
|
|
||||||
} else {
|
|
||||||
Logger::info("statusnet_fetchhometimeline: Own contact not found for user " . $uid);
|
Logger::info("statusnet_fetchhometimeline: Own contact not found for user " . $uid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$u = q("SELECT * FROM user WHERE uid = %d LIMIT 1",
|
$user = User::getById($uid);
|
||||||
intval($uid));
|
if (!DBA::isResult($user)) {
|
||||||
if (!DBA::isResult($u)) {
|
|
||||||
Logger::info("statusnet_fetchhometimeline: Own user not found for user " . $uid);
|
Logger::info("statusnet_fetchhometimeline: Own user not found for user " . $uid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1519,10 +1477,9 @@ function statusnet_fetch_own_contact(App $a, $uid)
|
||||||
|
|
||||||
$contact_id = statusnet_fetch_contact($uid, $user, true);
|
$contact_id = statusnet_fetch_contact($uid, $user, true);
|
||||||
} else {
|
} else {
|
||||||
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `alias` = '%s' LIMIT 1",
|
$contact = Contact::selectFirst([], ['uid' => $uid, 'alias' => $own_url]);
|
||||||
intval($uid), DBA::escape($own_url));
|
if (DBA::isResult($contact)) {
|
||||||
if (DBA::isResult($r)) {
|
$contact_id = $contact["id"];
|
||||||
$contact_id = $r[0]["id"];
|
|
||||||
} else {
|
} else {
|
||||||
DI::pConfig()->delete($uid, 'statusnet', 'own_url');
|
DI::pConfig()->delete($uid, 'statusnet', 'own_url');
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,20 +43,14 @@ function testdrive_register_account($a,$b) {
|
||||||
if(! $days)
|
if(! $days)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
$r = q("UPDATE user set account_expires_on = '%s' where uid = %d",
|
DBA::update('user', ['account_expires_on' => DateTimeFormat::convert('now +' . $days . ' days')], ['uid' => $uid]);
|
||||||
DBA::escape(DateTimeFormat::convert('now +' . $days . ' days')),
|
|
||||||
intval($uid)
|
|
||||||
);
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
function testdrive_cron($a,$b) {
|
function testdrive_cron($a,$b) {
|
||||||
$r = q("select * from user where account_expires_on < UTC_TIMESTAMP() + INTERVAL 5 DAY and
|
$users = DBA::selectToArray('user', [], ["`account_expires_on` < UTC_TIMESTAMP() + INTERVAL ? DAY AND `expire_notification_sent` <= ?",
|
||||||
expire_notification_sent = '0000-00-00 00:00:00' ");
|
5, DBA::NULL_DATETIME]);
|
||||||
|
foreach($users as $rr) {
|
||||||
if(count($r)) {
|
|
||||||
foreach($r as $rr) {
|
|
||||||
notification([
|
notification([
|
||||||
'type' => Notification\Type::SYSTEM,
|
'type' => Notification\Type::SYSTEM,
|
||||||
'uid' => $rr['uid'],
|
'uid' => $rr['uid'],
|
||||||
|
@ -66,20 +60,13 @@ function testdrive_cron($a,$b) {
|
||||||
'source_photo' => DI::baseUrl()->get() . '/images/person-80.jpg',
|
'source_photo' => DI::baseUrl()->get() . '/images/person-80.jpg',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
q("update user set expire_notification_sent = '%s' where uid = %d",
|
DBA::update('user', ['expire_notification_sent' => DateTimeFormat::utcNow()], ['uid' => $rr['uid']]);
|
||||||
DBA::escape(DateTimeFormat::utcNow()),
|
|
||||||
intval($rr['uid'])
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$r = q("select * from user where account_expired = 1 and account_expires_on < UTC_TIMESTAMP() - INTERVAL 5 DAY ");
|
$users = DBA::selectToArray('user', [], ["`account_expired` AND `account_expires_on` < UTC_TIMESTAMP() - INTERVAL ? DAY", 5]);
|
||||||
if(count($r)) {
|
foreach($users as $rr) {
|
||||||
foreach($r as $rr) {
|
|
||||||
User::remove($rr['uid']);
|
User::remove($rr['uid']);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function testdrive_enotify(&$a, &$b) {
|
function testdrive_enotify(&$a, &$b) {
|
||||||
|
|
|
@ -126,15 +126,11 @@ function twitter_load_config(App $a, ConfigFileLoader $loader)
|
||||||
|
|
||||||
function twitter_check_item_notification(App $a, array &$notification_data)
|
function twitter_check_item_notification(App $a, array &$notification_data)
|
||||||
{
|
{
|
||||||
$own_id = DI::pConfig()->get($notification_data["uid"], 'twitter', 'own_id');
|
$own_id = DI::pConfig()->get($notification_data['uid'], 'twitter', 'own_id');
|
||||||
|
|
||||||
$own_user = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `alias` = '%s' LIMIT 1",
|
|
||||||
intval($notification_data["uid"]),
|
|
||||||
DBA::escape("twitter::".$own_id)
|
|
||||||
);
|
|
||||||
|
|
||||||
|
$own_user = Contact::selectFirst(['url'], ['uid' => $notification_data['uid'], 'alias' => 'twitter::'.$own_id]);
|
||||||
if ($own_user) {
|
if ($own_user) {
|
||||||
$notification_data["profiles"][] = $own_user[0]["url"];
|
$notification_data['profiles'][] = $own_user['url'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -525,7 +521,7 @@ function twitter_probe_detect(App $a, array &$hookData)
|
||||||
function twitter_api_post(string $apiPath, string $pid, int $uid)
|
function twitter_api_post(string $apiPath, string $pid, int $uid)
|
||||||
{
|
{
|
||||||
if (empty($pid)) {
|
if (empty($pid)) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$ckey = DI::config()->get('twitter', 'consumerkey');
|
$ckey = DI::config()->get('twitter', 'consumerkey');
|
||||||
|
@ -829,13 +825,11 @@ function twitter_cron(App $a)
|
||||||
}
|
}
|
||||||
Logger::notice('twitter: cron_start');
|
Logger::notice('twitter: cron_start');
|
||||||
|
|
||||||
$r = q("SELECT * FROM `pconfig` WHERE `cat` = 'twitter' AND `k` = 'mirror_posts' AND `v` = '1'");
|
$pconfigs = DBA::selectToArray('pconfig', [], ['cat' => 'twitter', 'k' => 'mirror_posts', 'v' => true]);
|
||||||
if (DBA::isResult($r)) {
|
foreach ($pconfigs as $rr) {
|
||||||
foreach ($r as $rr) {
|
|
||||||
Logger::notice('Fetching', ['user' => $rr['uid']]);
|
Logger::notice('Fetching', ['user' => $rr['uid']]);
|
||||||
Worker::add(['priority' => PRIORITY_MEDIUM, 'force_priority' => true], "addon/twitter/twitter_sync.php", 1, (int) $rr['uid']);
|
Worker::add(['priority' => PRIORITY_MEDIUM, 'force_priority' => true], "addon/twitter/twitter_sync.php", 1, (int) $rr['uid']);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$abandon_days = intval(DI::config()->get('system', 'account_abandon_days'));
|
$abandon_days = intval(DI::config()->get('system', 'account_abandon_days'));
|
||||||
if ($abandon_days < 1) {
|
if ($abandon_days < 1) {
|
||||||
|
@ -844,12 +838,10 @@ function twitter_cron(App $a)
|
||||||
|
|
||||||
$abandon_limit = date(DateTimeFormat::MYSQL, time() - $abandon_days * 86400);
|
$abandon_limit = date(DateTimeFormat::MYSQL, time() - $abandon_days * 86400);
|
||||||
|
|
||||||
$r = q("SELECT * FROM `pconfig` WHERE `cat` = 'twitter' AND `k` = 'import' AND `v` = '1'");
|
$pconfigs = DBA::selectToArray('pconfig', [], ['cat' => 'twitter', 'k' => 'import', 'v' => true]);
|
||||||
if (DBA::isResult($r)) {
|
foreach ($pconfigs as $rr) {
|
||||||
foreach ($r as $rr) {
|
|
||||||
if ($abandon_days != 0) {
|
if ($abandon_days != 0) {
|
||||||
$user = q("SELECT `login_date` FROM `user` WHERE uid=%d AND `login_date` >= '%s'", $rr['uid'], $abandon_limit);
|
if (!DBA::exists('user', ["`uid` = ? AND `login_date` >= ?", $rr['uid'], $abandon_limit])) {
|
||||||
if (!DBA::isResult($user)) {
|
|
||||||
Logger::notice('abandoned account: timeline from user will not be imported', ['user' => $rr['uid']]);
|
Logger::notice('abandoned account: timeline from user will not be imported', ['user' => $rr['uid']]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -872,7 +864,6 @@ function twitter_cron(App $a)
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Logger::notice('twitter: cron_end');
|
Logger::notice('twitter: cron_end');
|
||||||
|
|
||||||
|
@ -900,13 +891,11 @@ function twitter_expire(App $a)
|
||||||
|
|
||||||
Logger::notice('Start expiry');
|
Logger::notice('Start expiry');
|
||||||
|
|
||||||
$r = q("SELECT * FROM `pconfig` WHERE `cat` = 'twitter' AND `k` = 'import' AND `v` = '1' ORDER BY RAND()");
|
$pconfigs = DBA::selectToArray('pconfig', [], ['cat' => 'twitter', 'k' => 'import', 'v' => true]);
|
||||||
if (DBA::isResult($r)) {
|
foreach ($pconfigs as $rr) {
|
||||||
foreach ($r as $rr) {
|
|
||||||
Logger::notice('twitter_expire', ['user' => $rr['uid']]);
|
Logger::notice('twitter_expire', ['user' => $rr['uid']]);
|
||||||
Item::expire($rr['uid'], $days, Protocol::TWITTER, true);
|
Item::expire($rr['uid'], $days, Protocol::TWITTER, true);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Logger::notice('End expiry');
|
Logger::notice('End expiry');
|
||||||
}
|
}
|
||||||
|
@ -1279,7 +1268,7 @@ function twitter_fetch_contact($uid, $data, $create_user)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($cid)) {
|
if (!empty($cid)) {
|
||||||
DBA::update('contact', $fields, ['id' => $cid]);
|
Contact::update($fields, ['id' => $cid]);
|
||||||
Contact::updateAvatar($cid, $avatar);
|
Contact::updateAvatar($cid, $avatar);
|
||||||
} else {
|
} else {
|
||||||
Logger::warning('No contact found', ['fields' => $fields]);
|
Logger::warning('No contact found', ['fields' => $fields]);
|
||||||
|
@ -1308,7 +1297,7 @@ function twitter_fetch_contact($uid, $data, $create_user)
|
||||||
$fields['readonly'] = false;
|
$fields['readonly'] = false;
|
||||||
$fields['pending'] = false;
|
$fields['pending'] = false;
|
||||||
|
|
||||||
if (!DBA::insert('contact', $fields)) {
|
if (!Contact::insert($fields)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1350,7 +1339,7 @@ function twitter_fetch_contact($uid, $data, $create_user)
|
||||||
|
|
||||||
if ($update) {
|
if ($update) {
|
||||||
$fields['updated'] = DateTimeFormat::utcNow();
|
$fields['updated'] = DateTimeFormat::utcNow();
|
||||||
DBA::update('contact', $fields, ['id' => $contact['id']]);
|
Contact::update($fields, ['id' => $contact['id']]);
|
||||||
Logger::info('Updated contact', ['id' => $contact['id'], 'nick' => $data->screen_name]);
|
Logger::info('Updated contact', ['id' => $contact['id'], 'nick' => $data->screen_name]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1663,15 +1652,13 @@ function twitter_createpost(App $a, $uid, $post, array $self, $create_user, $onl
|
||||||
$own_id = DI::pConfig()->get($uid, 'twitter', 'own_id');
|
$own_id = DI::pConfig()->get($uid, 'twitter', 'own_id');
|
||||||
|
|
||||||
if ($post->user->id_str == $own_id) {
|
if ($post->user->id_str == $own_id) {
|
||||||
$r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1",
|
$self = Contact::selectFirst(['id', 'name', 'url', 'photo'], ['self' => true, 'uid' => $uid]);
|
||||||
intval($uid));
|
if (DBA::isResult($self)) {
|
||||||
|
$contactid = $self['id'];
|
||||||
|
|
||||||
if (DBA::isResult($r)) {
|
$postarray['owner-name'] = $self['name'];
|
||||||
$contactid = $r[0]["id"];
|
$postarray['owner-link'] = $self['url'];
|
||||||
|
$postarray['owner-avatar'] = $self['photo'];
|
||||||
$postarray['owner-name'] = $r[0]["name"];
|
|
||||||
$postarray['owner-link'] = $r[0]["url"];
|
|
||||||
$postarray['owner-avatar'] = $r[0]["photo"];
|
|
||||||
} else {
|
} else {
|
||||||
Logger::error('No self contact found', ['uid' => $uid]);
|
Logger::error('No self contact found', ['uid' => $uid]);
|
||||||
return [];
|
return [];
|
||||||
|
@ -1910,12 +1897,9 @@ function twitter_fetchhometimeline(App $a, $uid)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
|
$contact = Contact::selectFirst(['nick'], ['id' => $own_contact, 'uid' => $uid]);
|
||||||
intval($own_contact),
|
if (DBA::isResult($contact)) {
|
||||||
intval($uid));
|
$own_id = $contact['nick'];
|
||||||
|
|
||||||
if (DBA::isResult($r)) {
|
|
||||||
$own_id = $r[0]["nick"];
|
|
||||||
} else {
|
} else {
|
||||||
Logger::warning('Own twitter contact not found', ['uid' => $uid]);
|
Logger::warning('Own twitter contact not found', ['uid' => $uid]);
|
||||||
return;
|
return;
|
||||||
|
@ -2093,11 +2077,9 @@ function twitter_fetch_own_contact(App $a, $uid)
|
||||||
|
|
||||||
$contact_id = twitter_fetch_contact($uid, $user, true);
|
$contact_id = twitter_fetch_contact($uid, $user, true);
|
||||||
} else {
|
} else {
|
||||||
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `alias` = '%s' LIMIT 1",
|
$contact = Contact::selectFirst(['id'], ['uid' => $uid, 'alias' => 'twitter::' . $own_id]);
|
||||||
intval($uid),
|
if (DBA::isResult($contact)) {
|
||||||
DBA::escape("twitter::" . $own_id));
|
$contact_id = $contact['id'];
|
||||||
if (DBA::isResult($r)) {
|
|
||||||
$contact_id = $r[0]["id"];
|
|
||||||
} else {
|
} else {
|
||||||
DI::pConfig()->delete($uid, 'twitter', 'own_id');
|
DI::pConfig()->delete($uid, 'twitter', 'own_id');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue