* @}
*/
+ private static $owner;
+
/**
* Returns true if a user record exists with the provided id
*
* @return integer user id
* @throws Exception
*/
- public static function getIdForURL($url)
+ public static function getIdForURL(string $url)
{
- $self = DBA::selectFirst('contact', ['uid'], ['nurl' => Strings::normaliseLink($url), 'self' => true]);
- if (!DBA::isResult($self)) {
- return false;
- } else {
+ $self = Contact::selectFirst(['uid'], ['self' => true, 'nurl' => Strings::normaliseLink($url)]);
+ if (!empty($self['uid'])) {
+ return $self['uid'];
+ }
+
+ $self = Contact::selectFirst(['uid'], ['self' => true, 'addr' => $url]);
+ if (!empty($self['uid'])) {
return $self['uid'];
}
+
+ $self = Contact::selectFirst(['uid'], ['self' => true, 'alias' => [$url, Strings::normaliseLink($url)]]);
+ if (!empty($self['uid'])) {
+ return $self['uid'];
+ }
+
+ return 0;
}
/**
return DBA::selectFirst('user', $fields, ['email' => $email]);
}
+ /**
+ * Fetch the user array of the administrator. The first one if there are several.
+ *
+ * @param array $fields
+ * @return array user
+ */
+ public static function getFirstAdmin(array $fields = [])
+ {
+ if (!empty(DI::config()->get('config', 'admin_nickname'))) {
+ return self::getByNickname(DI::config()->get('config', 'admin_nickname'), $fields);
+ } elseif (!empty(DI::config()->get('config', 'admin_email'))) {
+ $adminList = explode(',', str_replace(' ', '', DI::config()->get('config', 'admin_email')));
+ return self::getByEmail($adminList[0], $fields);
+ } else {
+ return [];
+ }
+ }
+
/**
* Get owner data by user id
*
* @return boolean|array
* @throws Exception
*/
- public static function getOwnerDataById($uid, $check_valid = true)
+ public static function getOwnerDataById(int $uid, bool $check_valid = true)
{
+ if (!empty(self::$owner[$uid])) {
+ return self::$owner[$uid];
+ }
+
$owner = DBA::selectFirst('owner-view', [], ['uid' => $uid]);
if (!DBA::isResult($owner)) {
if (!DBA::exists('user', ['uid' => $uid]) || !$check_valid) {
$owner = self::getOwnerDataById($uid, false);
}
+ self::$owner[$uid] = $owner;
return $owner;
}
$photo_failure = false;
$filename = basename($photo);
- $curlResult = Network::curl($photo, true);
+ $curlResult = DI::httpRequest()->get($photo, true);
if ($curlResult->isSuccess()) {
$img_str = $curlResult->getBody();
$type = $curlResult->getContentType();
// unique), so it cannot be re-registered in the future.
DBA::insert('userd', ['username' => $user['nickname']]);
- // The user and related data will be deleted in Friendica\Worker\CronJobs::expireAndRemoveUsers()
+ // The user and related data will be deleted in Friendica\Worker\ExpireAndRemoveUsers
DBA::update('user', ['account_removed' => true, 'account_expires_on' => DateTimeFormat::utc('now + 7 day')], ['uid' => $uid]);
Worker::add(PRIORITY_HIGH, 'Notifier', Delivery::REMOVAL, $uid);
'total_users' => 0,
'active_users_halfyear' => 0,
'active_users_monthly' => 0,
+ 'active_users_weekly' => 0,
];
$userStmt = DBA::select('owner-view', ['uid', 'login_date', 'last-item'],
$halfyear = time() - (180 * 24 * 60 * 60);
$month = time() - (30 * 24 * 60 * 60);
+ $week = time() - (7 * 24 * 60 * 60);
while ($user = DBA::fetch($userStmt)) {
$statistics['total_users']++;
) {
$statistics['active_users_monthly']++;
}
+
+ if ((strtotime($user['login_date']) > $week) || (strtotime($user['last-item']) > $week)
+ ) {
+ $statistics['active_users_weekly']++;
+ }
}
DBA::close($userStmt);