]> git.mxchange.org Git - friendica.git/commitdiff
Owner-view added
authorMichael <heluecht@pirati.ca>
Fri, 24 Apr 2020 11:04:50 +0000 (11:04 +0000)
committerMichael <heluecht@pirati.ca>
Fri, 24 Apr 2020 11:04:50 +0000 (11:04 +0000)
src/Model/Tag.php
src/Model/User.php
src/Module/Admin/Users.php
static/dbview.config.php

index e2ce5ad0d581b2a4ca193c56bf98962751f32329..cf453f2431356ec6e9498b3662050cae36ce773b 100644 (file)
@@ -231,13 +231,18 @@ class Tag
         */
        public static function remove(int $uriid, int $type, string $name, string $url = '')
        {
-               $tag = DBA::fetchFirst("SELECT `id` FROM `tag` INNER JOIN `post-tag` ON `post-tag`.`tid` = `tag`.`id`
-                       WHERE `uri-id` = ? AND `type` = ? AND `name` = ? AND `url` = ?", $uriid, $type, $name, $url);
+               $condition = ['uri-id' => $uriid, 'type' => $type, 'url' => $url];
+               if ($type == self::HASHTAG) {
+                       $condition['name'] = $name;
+               }
+
+               $tag = DBA::selectFirst('tag-view', ['tid', 'cid'], $condition);
                if (!DBA::isResult($tag)) {
                        return;
                }
-               Logger::info('Removing tag/mention', ['uri-id' => $uriid, 'tid' => $tag['id'], 'name' => $name, 'url' => $url, 'callstack' => System::callstack(8)]);
-               DBA::delete('post-tag', ['uri-id' => $uriid, 'tid' => $tag['id']]);
+
+               Logger::info('Removing tag/mention', ['uri-id' => $uriid, 'tid' => $tag['tid'], 'name' => $name, 'url' => $url, 'callstack' => System::callstack(8)]);
+               DBA::delete('post-tag', ['uri-id' => $uriid, 'type' => $type, 'tid' => $tag['tid'], 'cid' => $tag['cid']]);
        }
 
        /**
index 4ef5ffa33c05dba68c5b0698d58e357b79c58ba1..e7f2f89ad6f09bddcdb568fef7372710a0220f59 100644 (file)
@@ -195,66 +195,46 @@ class User
         */
        public static function getOwnerDataById($uid, $check_valid = true)
        {
-               $r = DBA::fetchFirst(
-                       "SELECT
-                       `contact`.*,
-                       `user`.`prvkey` AS `uprvkey`,
-                       `user`.`timezone`,
-                       `user`.`nickname`,
-                       `user`.`sprvkey`,
-                       `user`.`spubkey`,
-                       `user`.`page-flags`,
-                       `user`.`account-type`,
-                       `user`.`prvnets`,
-                       `user`.`account_removed`,
-                       `user`.`hidewall`
-                       FROM `contact`
-                       INNER JOIN `user`
-                               ON `user`.`uid` = `contact`.`uid`
-                       WHERE `contact`.`uid` = ?
-                       AND `contact`.`self`
-                       LIMIT 1",
-                       $uid
-               );
-               if (!DBA::isResult($r)) {
+               $owner = DBA::selectFirst('owner-view', [], ['uid' => $uid]);
+               if (!DBA::isResult($owner)) {
                        return false;
                }
 
-               if (empty($r['nickname'])) {
+               if (empty($owner['nickname'])) {
                        return false;
                }
 
                if (!$check_valid) {
-                       return $r;
+                       return $owner;
                }
 
                // Check if the returned data is valid, otherwise fix it. See issue #6122
 
                // Check for correct url and normalised nurl
-               $url = DI::baseUrl() . '/profile/' . $r['nickname'];
-               $repair = ($r['url'] != $url) || ($r['nurl'] != Strings::normaliseLink($r['url']));
+               $url = DI::baseUrl() . '/profile/' . $owner['nickname'];
+               $repair = ($owner['url'] != $url) || ($owner['nurl'] != Strings::normaliseLink($owner['url']));
 
                if (!$repair) {
                        // Check if "addr" is present and correct
-                       $addr = $r['nickname'] . '@' . substr(DI::baseUrl(), strpos(DI::baseUrl(), '://') + 3);
-                       $repair = ($addr != $r['addr']);
+                       $addr = $owner['nickname'] . '@' . substr(DI::baseUrl(), strpos(DI::baseUrl(), '://') + 3);
+                       $repair = ($addr != $owner['addr']);
                }
 
                if (!$repair) {
                        // Check if the avatar field is filled and the photo directs to the correct path
                        $avatar = Photo::selectFirst(['resource-id'], ['uid' => $uid, 'profile' => true]);
                        if (DBA::isResult($avatar)) {
-                               $repair = empty($r['avatar']) || !strpos($r['photo'], $avatar['resource-id']);
+                               $repair = empty($owner['avatar']) || !strpos($owner['photo'], $avatar['resource-id']);
                        }
                }
 
                if ($repair) {
                        Contact::updateSelfFromUserID($uid);
                        // Return the corrected data and avoid a loop
-                       $r = self::getOwnerDataById($uid, false);
+                       $owner = self::getOwnerDataById($uid, false);
                }
 
-               return $r;
+               return $owner;
        }
 
        /**
@@ -1290,17 +1270,10 @@ class User
                        'active_users_monthly'  => 0,
                ];
 
-               $userStmt = DBA::p("SELECT `user`.`uid`, `user`.`login_date`, `contact`.`last-item`
-                       FROM `user`
-                       INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`
-                       WHERE `user`.`verified`
-                               AND `user`.`login_date` > ?
-                               AND NOT `user`.`blocked`
-                               AND NOT `user`.`account_removed`
-                               AND NOT `user`.`account_expired`",
-                               DBA::NULL_DATETIME
-               );
-
+               $userStmt = DBA::select('owner-view', ['uid', 'login_date', 'last-item'],
+                       ["`verified` AND `login_date` > ? AND NOT `blocked`
+                       AND NOT `account_removed` AND NOT `account_expired`",
+                       DBA::NULL_DATETIME]);
                if (!DBA::isResult($userStmt)) {
                        return $statistics;
                }
@@ -1332,39 +1305,27 @@ class User
         * @param int    $count Count of the items per page (Default is @see Pager::ITEMS_PER_PAGE)
         * @param string $type  The type of users, which should get (all, bocked, removed)
         * @param string $order Order of the user list (Default is 'contact.name')
-        * @param string $order_direction Order direction (Default is ASC)
+        * @param bool   $descending Order direction (Default is ascending)
         *
         * @return array The list of the users
         * @throws Exception
         */
-       public static function getList($start = 0, $count = Pager::ITEMS_PER_PAGE, $type = 'all', $order = 'contact.name', $order_direction = '+')
+       public static function getList($start = 0, $count = Pager::ITEMS_PER_PAGE, $type = 'all', $order = 'name', bool $descending = false)
        {
-               $sql_order           = '`' . str_replace('.', '`.`', $order) . '`';
-               $sql_order_direction = ($order_direction === '+') ? 'ASC' : 'DESC';
-
+               $param = ['limit' => [$start, $count], 'order' => [$order => $descending]];
+               $condition = [];
                switch ($type) {
                        case 'active':
-                               $sql_extra = 'AND `user`.`blocked` = 0';
+                               $condition['blocked'] = false;
                                break;
                        case 'blocked':
-                               $sql_extra = 'AND `user`.`blocked` = 1';
+                               $condition['blocked'] = true;
                                break;
                        case 'removed':
-                               $sql_extra = 'AND `user`.`account_removed` = 1';
-                               break;
-                       case 'all':
-                       default:
-                               $sql_extra = '';
+                               $condition['account_removed'] = true;
                                break;
                }
 
-               $usersStmt = DBA::p("SELECT `user`.*, `contact`.`name`, `contact`.`url`, `contact`.`micro`, `user`.`account_expired`, `contact`.`last-item` AS `lastitem_date`, `contact`.`nick`, `contact`.`created`
-                               FROM `user`
-                               INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`
-                               WHERE `user`.`verified` $sql_extra
-                               ORDER BY $sql_order $sql_order_direction LIMIT ?, ?", $start, $count
-               );
-
-               return DBA::toArray($usersStmt);
+               return DBA::selectToArray('owner-view', [], $condition, $param);
        }
 }
index 3ef91aadf72e159c3c22e6336bd5cac5488c67aa..822ac0c013f742a852c17277edce390debdc61f0 100644 (file)
@@ -157,15 +157,15 @@ class Users extends BaseAdmin
                $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 100);
 
                $valid_orders = [
-                       'contact.name',
-                       'user.email',
-                       'user.register_date',
-                       'user.login_date',
+                       'name',
+                       'email',
+                       'register_date',
+                       'login_date',
                        'lastitem_date',
-                       'user.page-flags'
+                       'page-flags'
                ];
 
-               $order = 'contact.name';
+               $order = 'name';
                $order_direction = '+';
                if (!empty($_GET['o'])) {
                        $new_order = $_GET['o'];
@@ -179,7 +179,7 @@ class Users extends BaseAdmin
                        }
                }
 
-               $users = User::getList($pager->getStart(), $pager->getItemsPerPage(), 'all', $order, $order_direction);
+               $users = User::getList($pager->getStart(), $pager->getItemsPerPage(), 'all', $order, ($order_direction == '-'));
 
                $adminlist = explode(',', str_replace(' ', '', DI::config()->get('config', 'admin_email')));
                $_setup_users = function ($e) use ($adminlist) {
index ad33a78823c2adff6af07a7e933736aad8076514..0d44df03111afeb676b55b31a82c701743f3e260 100755 (executable)
@@ -53,5 +53,104 @@ return [
                        LEFT JOIN `tag` ON `post-tag`.`tid` = `tag`.`id`
                        LEFT JOIN `contact` ON `post-tag`.`cid` = `contact`.`id`"
        ],
+       "owner-view" => [
+               "fields" => [
+                       "id" => ["contact", "id"],
+                       "uid" => ["contact", "uid"],
+                       "created" => ["contact", "created"],
+                       "updated" => ["contact", "updated"],
+                       "self" => ["contact", "self"],
+                       "remote_self" => ["contact", "remote_self"],
+                       "rel" => ["contact", "rel"],
+                       "duplex" => ["contact", "duplex"],
+                       "network" => ["contact", "network"],
+                       "protocol" => ["contact", "protocol"],
+                       "name" => ["contact", "name"],
+                       "nick" => ["contact", "nick"],
+                       "location" => ["contact", "location"],
+                       "about" => ["contact", "about"],
+                       "keywords" => ["contact", "keywords"],
+                       "gender" => ["contact", "gender"],
+                       "xmpp" => ["contact", "xmpp"],
+                       "attag" => ["contact", "attag"],
+                       "avatar" => ["contact", "avatar"],
+                       "photo" => ["contact", "photo"],
+                       "thumb" => ["contact", "thumb"],
+                       "micro" => ["contact", "micro"],
+                       "site-pubkey" => ["contact", "site-pubkey"],
+                       "issued-id" => ["contact", "issued-id"],
+                       "dfrn-id" => ["contact", "dfrn-id"],
+                       "url" => ["contact", "url"],
+                       "nurl" => ["contact", "nurl"],
+                       "addr" => ["contact", "addr"],
+                       "alias" => ["contact", "alias"],
+                       "pubkey" => ["contact", "pubkey"],
+                       "prvkey" => ["contact", "prvkey"],
+                       "batch" => ["contact", "batch"],
+                       "request" => ["contact", "request"],
+                       "notify" => ["contact", "notify"],
+                       "poll" => ["contact", "poll"],
+                       "confirm" => ["contact", "confirm"],
+                       "poco" => ["contact", "poco"],
+                       "aes_allow" => ["contact", "aes_allow"],
+                       "ret-aes" => ["contact", "ret-aes"],
+                       "usehub" => ["contact", "usehub"],
+                       "subhub" => ["contact", "subhub"],
+                       "hub-verify" => ["contact", "hub-verify"],
+                       "last-update" => ["contact", "last-update"],
+                       "success_update" => ["contact", "success_update"],
+                       "failure_update" => ["contact", "failure_update"],
+                       "name-date" => ["contact", "name-date"],
+                       "uri-date" => ["contact", "uri-date"],
+                       "avatar-date" => ["contact", "avatar-date"],
+                       "term-date" => ["contact", "term-date"],
+                       "last-item" => ["contact", "last-item"],                        
+                       "lastitem_date" => ["contact", "last-item"],
+                       "priority" => ["contact", "priority"],
+                       "blocked" => ["contact", "blocked"],
+                       "block_reason" => ["contact", "block_reason"],
+                       "readonly" => ["contact", "readonly"],
+                       "writable" => ["contact", "writable"],
+                       "forum" => ["contact", "forum"],
+                       "prv" => ["contact", "prv"],
+                       "contact-type" => ["contact", "contact-type"],
+                       "hidden" => ["contact", "hidden"],
+                       "archive" => ["contact", "archive"],
+                       "pending" => ["contact", "pending"],
+                       "deleted" => ["contact", "deleted"],
+                       "rating" => ["contact", "rating"],
+                       "unsearchable" => ["contact", "unsearchable"],
+                       "sensitive" => ["contact", "sensitive"],
+                       "baseurl" => ["contact", "baseurl"],
+                       "reason" => ["contact", "reason"],
+                       "closeness" => ["contact", "closeness"],
+                       "info" => ["contact", "info"],
+                       "profile-id" => ["contact", "profile-id"],
+                       "bdyear" => ["contact", "bdyear"],
+                       "bd" => ["contact", "bd"],
+                       "notify_new_posts" => ["notify_new_posts"],
+                       "fetch_further_information" => ["fetch_further_information"],
+                       "ffi_keyword_blacklist" => ["ffi_keyword_blacklist"],
+                       "email" => ["user", "email"],
+                       "uprvkey" => ["user", "prvkey"],
+                       "timezone" => ["user", "timezone"],
+                       "nickname" => ["user", "nickname"],
+                       "sprvkey" => ["user", "sprvkey"],
+                       "spubkey" => ["user", "spubkey"],
+                       "page-flags" => ["user", "page-flags"],
+                       "account-type" => ["user", "account-type"],
+                       "prvnets" => ["user", "prvnets"],
+                       "account_removed" => ["user", "account_removed"],
+                       "hidewall" => ["user", "hidewall"],
+                       "login_date" => ["user", "login_date"],
+                       "register_date" => ["user", "register_date"],
+                       "verified" => ["user", "verified"],
+                       "account_removed" => ["user", "account_removed"],
+                       "account_expired" => ["user", "account_expired"],
+                       "account_expires_on" => ["user", "account_expires_on"],
+               ],
+               "query" => "FROM `user`
+                       INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`"
+       ]
 ];