]> git.mxchange.org Git - friendica.git/commitdiff
Improve dba::selectFirst calls
authorHypolite Petovan <mrpetovan@gmail.com>
Thu, 11 Jan 2018 08:26:30 +0000 (03:26 -0500)
committerHypolite Petovan <mrpetovan@gmail.com>
Thu, 11 Jan 2018 08:43:57 +0000 (03:43 -0500)
- Fix remaining $r[0] references
- Rename $r to meaningful names

29 files changed:
include/api.php
include/contact_widgets.php
include/conversation.php
include/enotify.php
include/identity.php
include/message.php
include/nav.php
include/session.php
index.php
mod/contacts.php
mod/hovercard.php
mod/network.php
mod/proxy.php
mod/xrd.php
src/Content/OEmbed.php
src/Core/Cache.php
src/Core/Config.php
src/Core/PConfig.php
src/Core/Worker.php
src/Model/Contact.php
src/Model/GContact.php
src/Model/Photo.php
src/Network/FKOAuth1.php
src/Network/FKOAuthDataStore.php
src/Object/Post.php
src/Protocol/PortableContact.php
src/Worker/OnePoll.php
src/Worker/Queue.php
util/global_community_silence.php

index 36e38a86e1eff7f6c69ca5fe58075928deff53e8..740acea50b2b4e3aa8ec4aeddd8eb6b897488edb 100644 (file)
@@ -226,7 +226,7 @@ function api_login(App $a)
                }
        }
 
-       if (!$record || !count($record)) {
+       if (DBM::is_result($record)) {
                logger('API_login failure: ' . print_r($_SERVER, true), LOGGER_DEBUG);
                header('WWW-Authenticate: Basic realm="Friendica"');
                //header('HTTP/1.0 401 Unauthorized');
@@ -4870,22 +4870,22 @@ function api_friendica_remoteauth()
 
        // traditional DFRN
 
-       $r = dba::selectFirst('contact', [], ['uid' => api_user(), 'nurl' => $c_url]);
+       $contact = dba::selectFirst('contact', [], ['uid' => api_user(), 'nurl' => $c_url]);
 
-       if (!DBM::is_result($r) || ($r['network'] !== NETWORK_DFRN)) {
+       if (!DBM::is_result($contact) || ($contact['network'] !== NETWORK_DFRN)) {
                throw new BadRequestException("Unknown contact");
        }
 
-       $cid = $r['id'];
+       $cid = $contact['id'];
 
-       $dfrn_id = defaults($r, 'issued-id', $r['dfrn-id']);
+       $dfrn_id = defaults($contact, 'issued-id', $contact['dfrn-id']);
 
-       if ($r['duplex'] && $r['issued-id']) {
-               $orig_id = $r['issued-id'];
+       if ($contact['duplex'] && $contact['issued-id']) {
+               $orig_id = $contact['issued-id'];
                $dfrn_id = '1:' . $orig_id;
        }
-       if ($r['duplex'] && $r['dfrn-id']) {
-               $orig_id = $r['dfrn-id'];
+       if ($contact['duplex'] && $contact['dfrn-id']) {
+               $orig_id = $contact['dfrn-id'];
                $dfrn_id = '0:' . $orig_id;
        }
 
@@ -4901,10 +4901,10 @@ function api_friendica_remoteauth()
                intval(time() + 45)
        );
 
-       logger($r['name'] . ' ' . $sec, LOGGER_DEBUG);
+       logger($contact['name'] . ' ' . $sec, LOGGER_DEBUG);
        $dest = ($url ? '&destination_url=' . $url : '');
        goaway(
-               $r['poll'] . '?dfrn_id=' . $dfrn_id
+               $contact['poll'] . '?dfrn_id=' . $dfrn_id
                . '&dfrn_version=' . DFRN_PROTOCOL_VERSION
                . '&type=profile&sec=' . $sec . $dest . $quiet
        );
index cc25c88ed52bfccf2b3d74efba259e688f710a05..aa1bc2436a940d8c5983de6a5425d6f9b5bfb5b7 100644 (file)
@@ -224,14 +224,14 @@ function common_friends_visitor_widget($profile_uid)
 
        if (!$cid) {
                if (get_my_url()) {
-                       $r = dba::selectFirst('contact', ['id'],
+                       $contact = dba::selectFirst('contact', ['id'],
                                        ['nurl' => normalise_link(get_my_url()), 'uid' => $profile_uid]);
-                       if (DBM::is_result($r)) {
-                               $cid = $r['id'];
+                       if (DBM::is_result($contact)) {
+                               $cid = $contact['id'];
                        } else {
-                               $r = dba::selectFirst('gcontact', ['id'], ['nurl' => normalise_link(get_my_url())]);
-                               if (DBM::is_result($r)) {
-                                       $zcid = $r['id'];
+                               $gcontact = dba::selectFirst('gcontact', ['id'], ['nurl' => normalise_link(get_my_url())]);
+                               if (DBM::is_result($gcontact)) {
+                                       $zcid = $gcontact['id'];
                                }
                        }
                }
index 228e90598b7626b615fda89f186c21c9ebd21efb..0e45de5587ecccfb436317a8b29cf0b18163e00a 100644 (file)
@@ -968,10 +968,15 @@ function best_link_url($item, &$sparkle, $url = '') {
        $clean_url = normalise_link($item['author-link']);
 
        if (local_user()) {
-               $r = dba::selectFirst('contact', ['id'],
-                       ['network' => NETWORK_DFRN, 'uid' => local_user(), 'nurl' => normalise_link($clean_url), 'pending' => false]);
-               if (DBM::is_result($r)) {
-                       $best_url = 'redir/' . $r['id'];
+               $condition = [
+                       'network' => NETWORK_DFRN,
+                       'uid' => local_user(),
+                       'nurl' => normalise_link($clean_url),
+                       'pending' => false
+               ];
+               $contact = dba::selectFirst('contact', ['id'], $condition);
+               if (DBM::is_result($contact)) {
+                       $best_url = 'redir/' . $contact['id'];
                        $sparkle = true;
                        if ($url != '') {
                                $hostname = get_app()->get_hostname();
@@ -1019,11 +1024,12 @@ function item_photo_menu($item) {
        $cid = 0;
        $network = '';
        $rel = 0;
-       $r = dba::selectFirst('contact', array('id', 'network', 'rel'), array('uid' => local_user(), 'nurl' => normalise_link($item['author-link'])));
-       if (DBM::is_result($r)) {
-               $cid = $r['id'];
-               $network = $r['network'];
-               $rel = $r['rel'];
+       $condition = ['uid' => local_user(), 'nurl' => normalise_link($item['author-link'])];
+       $contact = dba::selectFirst('contact', ['id', 'network', 'rel'], $condition);
+       if (DBM::is_result($contact)) {
+               $cid = $contact['id'];
+               $network = $contact['network'];
+               $rel = $contact['rel'];
        }
 
        if ($sparkle) {
index 2869572562fd6cc258b5ead042ea0f787a04de92..51e25572d3aa7560765236b44aa0ff85eecf0d38 100644 (file)
@@ -106,8 +106,8 @@ function notification($params)
        }
 
        if ($params['type'] == NOTIFY_COMMENT) {
-               $p = dba::selectFirst('thread', ['ignored'], ['iid' => $parent_id]);
-               if (DBM::is_result($p) && $p["ignored"]) {
+               $thread = dba::selectFirst('thread', ['ignored'], ['iid' => $parent_id]);
+               if (DBM::is_result($thread) && $thread["ignored"]) {
                        logger("Thread ".$parent_id." will be ignored", LOGGER_DEBUG);
                        return;
                }
@@ -128,13 +128,13 @@ function notification($params)
 
                // if it's a post figure out who's post it is.
 
-               $p = null;
+               $item = null;
 
                if ($params['otype'] === 'item' && $parent_id) {
-                       $p = dba::selectFirst('item', [], ['id' => $parent_id]);
+                       $item = dba::selectFirst('item', [], ['id' => $parent_id]);
                }
 
-               $item_post_type = item_post_type($p);
+               $item_post_type = item_post_type($item);
 
                // "a post"
                $dest_str = sprintf(t('%1$s commented on [url=%2$s]a %3$s[/url]'),
@@ -143,7 +143,7 @@ function notification($params)
                                                                $item_post_type);
 
                // "George Bull's post"
-               if ($p) {
+               if ($item) {
                        $dest_str = sprintf(t('%1$s commented on [url=%2$s]%3$s\'s %4$s[/url]'),
                                                '[url='.$params['source_link'].']'.$params['source_name'].'[/url]',
                                                $itemlink,
@@ -152,7 +152,7 @@ function notification($params)
                }
 
                // "your post"
-               if ($p['owner-name'] == $p['author-name'] && $p['wall']) {
+               if (DBM::is_result($item) && $item['owner-name'] == $item['author-name'] && $item['wall']) {
                        $dest_str = sprintf(t('%1$s commented on [url=%2$s]your %3$s[/url]'),
                                                                '[url='.$params['source_link'].']'.$params['source_name'].'[/url]',
                                                                $itemlink,
index 0c6224594234814b32cc32ec30447899fd507b20..f370a9aec0cb200df027a5c5b5d8c97bb4ff89ff 100644 (file)
@@ -154,28 +154,27 @@ function profile_load(App $a, $nickname, $profile = 0, $profiledata = array(), $
  *
  * @param string $nickname nick
  * @param int    $uid      uid
- * @param int    $profile  ID of the profile
+ * @param int    $profile_id  ID of the profile
  * @returns array
  */
-function get_profiledata_by_nick($nickname, $uid = 0, $profile = 0)
+function get_profiledata_by_nick($nickname, $uid = 0, $profile_id = 0)
 {
        if (remote_user() && count($_SESSION['remote'])) {
                foreach ($_SESSION['remote'] as $visitor) {
                        if ($visitor['uid'] == $uid) {
-                               $r = dba::selectFirst('contact', ['profile-id'], ['id' => $visitor['cid']]);
-                               if (DBM::is_result($r)) {
-                                       $profile = $r['profile-id'];
+                               $contact = dba::selectFirst('contact', ['profile-id'], ['id' => $visitor['cid']]);
+                               if (DBM::is_result($contact)) {
+                                       $profile_id = $contact['profile-id'];
                                }
                                break;
                        }
                }
        }
 
-       $r = null;
+       $profile = null;
 
-       if ($profile) {
-               $profile_int = intval($profile);
-               $r = dba::fetch_first(
+       if ($profile_id) {
+               $profile = dba::fetch_first(
                        "SELECT `contact`.`id` AS `contact_id`, `contact`.`photo` AS `contact_photo`,
                                `contact`.`thumb` AS `contact_thumb`, `contact`.`micro` AS `contact_micro`,
                                `profile`.`uid` AS `profile_uid`, `profile`.*,
@@ -185,11 +184,11 @@ function get_profiledata_by_nick($nickname, $uid = 0, $profile = 0)
                        INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
                        WHERE `user`.`nickname` = ? AND `profile`.`id` = ? LIMIT 1",
                        $nickname,
-                       $profile_int
+                       intval($profile_id)
                );
        }
-       if (!DBM::is_result($r)) {
-               $r = dba::fetch_first(
+       if (!DBM::is_result($profile)) {
+               $profile = dba::fetch_first(
                        "SELECT `contact`.`id` AS `contact_id`, `contact`.`photo` as `contact_photo`,
                                `contact`.`thumb` AS `contact_thumb`, `contact`.`micro` AS `contact_micro`,
                                `profile`.`uid` AS `profile_uid`, `profile`.*,
@@ -202,7 +201,7 @@ function get_profiledata_by_nick($nickname, $uid = 0, $profile = 0)
                );
        }
 
-       return $r;
+       return $profile;
 }
 
 /**
@@ -215,7 +214,7 @@ function get_profiledata_by_nick($nickname, $uid = 0, $profile = 0)
  * @param int $block
  * @param boolean $show_connect Show connect link
  *
- * @return HTML string stuitable for sidebar inclusion
+ * @return HTML string suitable for sidebar inclusion
  *
  * @note Returns empty string if passed $profile is wrong type or not populated
  *
index 189de2aef9fffc08009fda553d728e3308afb365..146643b2e6397e4a39e42c4b4ffbb022a8cc40fe 100644 (file)
@@ -68,11 +68,7 @@ function send_message($recipient = 0, $body = '', $subject = '', $replyto = '')
                        'created' => datetime_convert(), 'updated' => datetime_convert(),
                        'subject' => $subject, 'recips' => $handles);
                dba::insert('conv', $fields);
-
-               $r = dba::selectFirst('conv', ['id'], ['guid' => $conv_guid, 'uid' => local_user()]);
-               if (DBM::is_result($r)) {
-                       $convid = $r['id'];
-               }
+               $convid = dba::lastInsertId();
        }
 
        if (!$convid) {
@@ -103,15 +99,7 @@ function send_message($recipient = 0, $body = '', $subject = '', $replyto = '')
                dbesc($replyto),
                datetime_convert()
        );
-
-
-       $r = q("SELECT * FROM `mail` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
-               dbesc($uri),
-               intval(local_user())
-       );
-       if (DBM::is_result($r)) {
-               $post_id = $r[0]['id'];
-       }
+       $post_id = dba::lastInsertId();
 
        /**
         *
@@ -187,15 +175,13 @@ function send_wallmessage($recipient = '', $body = '', $subject = '', $replyto =
                'created' => datetime_convert(), 'updated' => datetime_convert(),
                'subject' => $subject, 'recips' => $handles);
        dba::insert('conv', $fields);
-
-       $r = dba::selectFirst('conv', ['id'], ['guid' => $conv_guid, 'uid' => $recipient['uid']]);
-       if (!DBM::is_result($r)) {
+       $convid = dba::lastInsertId();
+       
+       if (!$convid) {
                logger('send message: conversation not found.');
                return -4;
        }
 
-       $convid = $r['id'];
-
        q("INSERT INTO `mail` ( `uid`, `guid`, `convid`, `from-name`, `from-photo`, `from-url`,
                `contact-id`, `title`, `body`, `seen`, `reply`, `replied`, `uri`, `parent-uri`, `created`, `unknown`)
                VALUES ( %d, '%s', %d, '%s', '%s', '%s', %d, '%s', '%s', %d, %d, %d, '%s', '%s', '%s', %d )",
index ac76dd5aaa250da317257e3ab8280fb9741935d4..312e3de521211803d3e0a3b36675ff96d9ab0ca1 100644 (file)
@@ -94,9 +94,9 @@ function nav_info(App $a)
                $nav['usermenu'][] = array('notes/', t('Personal notes'), '', t('Your personal notes'));
 
                // user info
-               $r = dba::selectFirst('contact', ['micro'], ['uid' => $a->user['uid'], 'self' => true]);
+               $contact = dba::selectFirst('contact', ['micro'], ['uid' => $a->user['uid'], 'self' => true]);
                $userinfo = array(
-                       'icon' => (DBM::is_result($r) ? $a->remove_baseurl($r['micro']) : 'images/person-48.jpg'),
+                       'icon' => (DBM::is_result($contact) ? $a->remove_baseurl($contact['micro']) : 'images/person-48.jpg'),
                        'name' => $a->user['username'],
                );
        } else {
index cf51518f20203621ca12be650264a2e94d8946e9..3e58623cc0fda3ba5251f82bd886e5929908bd30 100644 (file)
@@ -33,10 +33,10 @@ function ref_session_read($id)
                return '';
        }
 
-       $r = dba::selectFirst('session', ['data'], ['sid' => $id]);
-       if (DBM::is_result($r)) {
+       $session = dba::selectFirst('session', ['data'], ['sid' => $id]);
+       if (DBM::is_result($session)) {
                $session_exists = true;
-               return $r['data'];
+               return $session['data'];
        } else {
                logger("no data for session $id", LOGGER_TRACE);
        }
index f966279940ac87e53e349803d227538097bf26fb..7436a51125ebbb52a323ca14a16551a311b732c9 100644 (file)
--- a/index.php
+++ b/index.php
@@ -107,11 +107,11 @@ if (!$a->is_backend()) {
  * We have to do it here because the session was just now opened.
  */
 if (x($_SESSION, 'authenticated') && !x($_SESSION, 'language')) {
-       // we didn't loaded user data yet, but we need user language
-       $r = dba::selectFirst('user', ['language'], ['uid' => $_SESSION['uid']]);
+       // we haven't loaded user data yet, but we need user language
+       $user = dba::selectFirst('user', ['language'], ['uid' => $_SESSION['uid']]);
        $_SESSION['language'] = $lang;
        if (DBM::is_result($r)) {
-               $_SESSION['language'] = $r['language'];
+               $_SESSION['language'] = $user['language'];
        }
 }
 
index 90c4af7d1bcbe967d4cd2fd267245dfdc6969fd4..54e9b5b644aa14279ae8f5815f376ab9fabba0f6 100644 (file)
@@ -30,7 +30,7 @@ function contacts_init(App $a)
                $a->page['aside'] = '';
        }
 
-       $contact = [];
+       $contact = null;
        if ((($a->argc == 2) && intval($a->argv[1])) || (($a->argc == 3) && intval($a->argv[1]) && ($a->argv[2] == "posts"))) {
                $contact_id = intval($a->argv[1]);
                $contact = dba::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user()]);
@@ -240,7 +240,7 @@ function _contact_update($contact_id)
 
        $uid = $contact["uid"];
 
-       if ($r[0]["network"] == NETWORK_OSTATUS) {
+       if ($contact["network"] == NETWORK_OSTATUS) {
                $result = Contact::createFromProbe($uid, $contact["url"], false, $contact["network"]);
 
                if ($result['success']) {
index a9cd95f58753c75ca8da80009545967d5c0eaccc..d7ba0f4f583e3b05618c4260bff68feefa5a6708 100644 (file)
@@ -44,8 +44,8 @@ function hovercard_content()
        $cid = 0;
        if (local_user() && strpos($profileurl, 'redir/') === 0) {
                $cid = intval(substr($profileurl, 6));
-               $r = dba::selectFirst('contact', ['nurl'], ['id' => $cid]);
-               $profileurl = defaults($r, 'nurl', '');
+               $remote_contact = dba::selectFirst('contact', ['nurl'], ['id' => $cid]);
+               $profileurl = defaults($remote_contact, 'nurl', '');
        }
 
        $contact = [];
index 84dc9255e2df5ec235e15cc07352211e22f6c632..1e6832541a49132496169c657f67361f9f0c4de7 100644 (file)
@@ -517,7 +517,7 @@ function networkThreadedView(App $a, $update = 0) {
 
        $datequery = $datequery2 = '';
 
-       $group = 0;
+       $gid = 0;
 
        if ($a->argc > 1) {
                for ($x = 1; $x < $a->argc; $x ++) {
@@ -529,8 +529,8 @@ function networkThreadedView(App $a, $update = 0) {
                                        $_GET['order'] = 'post';
                                }
                        } elseif (intval($a->argv[$x])) {
-                               $group = intval($a->argv[$x]);
-                               $def_acl = array('allow_gid' => '<' . $group . '>');
+                               $gid = intval($a->argv[$x]);
+                               $def_acl = array('allow_gid' => '<' . $gid . '>');
                        }
                }
        }
@@ -565,8 +565,8 @@ function networkThreadedView(App $a, $update = 0) {
                $tabs = network_tabs($a);
                $o .= $tabs;
 
-               if ($group) {
-                       if (($t = Contact::getOStatusCountByGroupId($group)) && !PConfig::get(local_user(), 'system', 'nowarn_insecure')) {
+               if ($gid) {
+                       if (($t = Contact::getOStatusCountByGroupId($gid)) && !PConfig::get(local_user(), 'system', 'nowarn_insecure')) {
                                notice(tt("Warning: This group contains %s member from a network that doesn't allow non public messages.",
                                                "Warning: This group contains %s members from a network that doesn't allow non public messages.",
                                                $t) . EOL);
@@ -596,12 +596,12 @@ function networkThreadedView(App $a, $update = 0) {
                        'allow_location' => $a->user['allow_location'],
                        'default_location' => $a->user['default-location'],
                        'nickname' => $a->user['nickname'],
-                       'lockstate'=> ((($group) || ($cid) || ($nets) || (is_array($a->user) &&
+                       'lockstate'=> ((($gid) || ($cid) || ($nets) || (is_array($a->user) &&
                                        ((strlen($a->user['allow_cid'])) || (strlen($a->user['allow_gid'])) ||
                                        (strlen($a->user['deny_cid'])) || (strlen($a->user['deny_gid']))))) ? 'lock' : 'unlock'),
                        'default_perms' => get_acl_permissions($a->user),
-                       'acl'   => populate_acl((($group || $cid || $nets) ? $def_acl : $a->user), true),
-                       'bang'  => (($group || $cid || $nets) ? '!' : ''),
+                       'acl'   => populate_acl((($gid || $cid || $nets) ? $def_acl : $a->user), true),
+                       'bang'  => (($gid || $cid || $nets) ? '!' : ''),
                        'visitor' => 'block',
                        'profile_uid' => local_user(),
                        'content' => $content,
@@ -631,17 +631,18 @@ function networkThreadedView(App $a, $update = 0) {
 
        $sql_nets = (($nets) ? sprintf(" and $sql_table.`network` = '%s' ", dbesc($nets)) : '');
 
-       if ($group) {
-               $r = dba::selectFirst('group', ['name'], ['id' => $group, 'uid' => $_SESSION['uid']]);
-               if (!DBM::is_result($r)) {
-                       if ($update)
+       if ($gid) {
+               $group = dba::selectFirst('group', ['name'], ['id' => $gid, 'uid' => $_SESSION['uid']]);
+               if (!DBM::is_result($group)) {
+                       if ($update) {
                                killme();
+                       }
                        notice(t('No such group') . EOL);
                        goaway('network/0');
                        // NOTREACHED
                }
 
-               $contacts = Group::expand(array($group));
+               $contacts = Group::expand(array($gid));
 
                if ((is_array($contacts)) && count($contacts)) {
                        $contact_str_self = "";
@@ -654,40 +655,40 @@ function networkThreadedView(App $a, $update = 0) {
 
                        $sql_post_table .= " INNER JOIN `item` AS `temp1` ON `temp1`.`id` = ".$sql_table.".".$sql_parent;
                        $sql_extra3 .= " AND (`thread`.`contact-id` IN ($contact_str) ";
-                       $sql_extra3 .= " OR (`thread`.`contact-id` = '$contact_str_self' AND `temp1`.`allow_gid` LIKE '".protect_sprintf('%<'.intval($group).'>%')."' AND `temp1`.`private`))";
+                       $sql_extra3 .= " OR (`thread`.`contact-id` = '$contact_str_self' AND `temp1`.`allow_gid` LIKE '".protect_sprintf('%<'.intval($gid).'>%')."' AND `temp1`.`private`))";
                } else {
                        $sql_extra3 .= " AND false ";
                        info(t('Group is empty'));
                }
 
                $o = replace_macros(get_markup_template("section_title.tpl"),array(
-                       '$title' => t('Group: %s', $r['name'])
+                       '$title' => t('Group: %s', $group['name'])
                )) . $o;
 
        } elseif ($cid) {
                $fields = ['id', 'name', 'network', 'writable', 'nurl',
                                'forum', 'prv', 'contact-type', 'addr', 'thumb', 'location'];
                $condition = ["`id` = ? AND (NOT `blocked` OR `pending`)", $cid];
-               $r = dba::selectFirst('contact', $fields, $condition);
-               if (DBM::is_result($r)) {
+               $contact = dba::selectFirst('contact', $fields, $condition);
+               if (DBM::is_result($contact)) {
                        $sql_extra = " AND ".$sql_table.".`contact-id` = ".intval($cid);
 
                        $entries[0] = array(
                                'id' => 'network',
-                               'name' => htmlentities($r['name']),
-                               'itemurl' => (($r['addr']) ? ($r['addr']) : ($r['nurl'])),
-                               'thumb' => proxy_url($r['thumb'], false, PROXY_SIZE_THUMB),
-                               'details' => $r['location'],
+                               'name' => htmlentities($contact['name']),
+                               'itemurl' => defaults($contact, 'addr', $contact['nurl']),
+                               'thumb' => proxy_url($contact['thumb'], false, PROXY_SIZE_THUMB),
+                               'details' => $contact['location'],
                        );
 
-                       $entries[0]["account_type"] = Contact::getAccountType($r);
+                       $entries[0]["account_type"] = Contact::getAccountType($contact);
 
                        $o = replace_macros(get_markup_template("viewcontact_template.tpl"),array(
                                'contacts' => $entries,
                                'id' => 'network',
                        )) . $o;
 
-                       if ($r['network'] === NETWORK_OSTATUS && $r['writable'] && !PConfig::get(local_user(),'system','nowarn_insecure')) {
+                       if ($contact['network'] === NETWORK_OSTATUS && $contact['writable'] && !PConfig::get(local_user(),'system','nowarn_insecure')) {
                                notice(t('Private messages to this person are at risk of public disclosure.') . EOL);
                        }
 
@@ -698,7 +699,7 @@ function networkThreadedView(App $a, $update = 0) {
                }
        }
 
-       if (!$group && !$cid && !$update && !Config::get('theme','hide_eventlist')) {
+       if (!$gid && !$cid && !$update && !Config::get('theme','hide_eventlist')) {
                $o .= get_birthdays();
                $o .= get_events();
        }
@@ -887,7 +888,7 @@ function networkThreadedView(App $a, $update = 0) {
        // level which items you've seen and which you haven't. If you're looking
        // at the top level network page just mark everything seen.
 
-       if (!$group && !$cid && !$star) {
+       if (!$gid && !$cid && !$star) {
                $condition = array('unseen' => true, 'uid' => local_user());
                networkSetSeen($condition);
        } elseif ($parents_str) {
index 80a84a165fc3cf84a38d7849a45b432bf0fe72cb..db0a615244a9fde2896add0d59e84835cdb0d34e 100644 (file)
@@ -145,20 +145,19 @@ function proxy_init(App $a) {
        }
 
        $valid = true;
-       $r = array();
-
+       $photo = null;
        if (!$direct_cache && ($cachefile == '')) {
-               $r = dba::selectFirst('photo', ['data', 'desc'], ['resource-id' => $urlhash]);
-               if (DBM::is_result($r)) {
-                       $img_str = $r['data'];
-                       $mime = $r['desc'];
+               $photo = dba::selectFirst('photo', ['data', 'desc'], ['resource-id' => $urlhash]);
+               if (DBM::is_result($photo)) {
+                       $img_str = $photo['data'];
+                       $mime = $photo['desc'];
                        if ($mime == '') {
                                $mime = 'image/jpeg';
                        }
                }
        }
 
-       if (!DBM::is_result($r)) {
+       if (!DBM::is_result($photo)) {
                // It shouldn't happen but it does - spaces in URL
                $_REQUEST['url'] = str_replace(' ', '+', $_REQUEST['url']);
                $redirects = 0;
index af1167581f080ac34fac7e511e605420de031e61..05b07dc162505a1bc76248a90ab686081f253123 100644 (file)
@@ -36,24 +36,24 @@ function xrd_init(App $a)
                $name = substr($local, 0, strpos($local, '@'));
        }
 
-       $r = dba::selectFirst('user', [], ['nickname' => $name]);
-       if (!DBM::is_result($r)) {
+       $user = dba::selectFirst('user', [], ['nickname' => $name]);
+       if (!DBM::is_result($user)) {
                killme();
        }
 
-       $profile_url = System::baseUrl().'/profile/'.$r['nickname'];
+       $profile_url = System::baseUrl().'/profile/'.$user['nickname'];
 
        $alias = str_replace('/profile/', '/~', $profile_url);
 
-       $addr = 'acct:'.$r['nickname'].'@'.$a->get_hostname();
+       $addr = 'acct:'.$user['nickname'].'@'.$a->get_hostname();
        if ($a->get_path()) {
                $addr .= '/'.$a->get_path();
        }
 
        if ($mode == 'xml') {
-               xrd_xml($a, $addr, $alias, $profile_url, $r);
+               xrd_xml($a, $addr, $alias, $profile_url, $user);
        } else {
-               xrd_json($a, $addr, $alias, $profile_url, $r);
+               xrd_json($a, $addr, $alias, $profile_url, $user);
        }
 }
 
index 364648d071fa42776e0b160821f968e4a6da1510..1b21dbf036473a42cc59dac81ed5c4e30d311c98 100644 (file)
@@ -58,9 +58,9 @@ class OEmbed
                $a = get_app();
 
                $condition = ['url' => normalise_link($embedurl), 'maxwidth' => $a->videowidth];
-               $r = dba::selectFirst('oembed', ['content'], $condition);
-               if (DBM::is_result($r)) {
-                       $txt = $r["content"];
+               $oembed = dba::selectFirst('oembed', ['content'], $condition);
+               if (DBM::is_result($oembed)) {
+                       $txt = $oembed["content"];
                } else {
                        $txt = Cache::get($a->videowidth . $embedurl);
                }
index dfb6591b9d5f0371fb4d78a5c43f50bb5c072c39..0d3c2ebe9348d0f433b43f7e926792c74b5fe24e 100644 (file)
@@ -109,10 +109,10 @@ class Cache
                // Frequently clear cache
                self::clear();
 
-               $r = dba::selectFirst('cache', ['v'], ['k' => $key]);
+               $cache = dba::selectFirst('cache', ['v'], ['k' => $key]);
 
-               if (DBM::is_result($r)) {
-                       $cached = $r['v'];
+               if (DBM::is_result($cache)) {
+                       $cached = $cache['v'];
                        $value = @unserialize($cached);
 
                        // Only return a value if the serialized value is valid.
index 3b08dee6b659aee9c71879d2e405bf1816cba329..b0c05fff8d4f1eb17714ff899ba19b85dd940dbd 100644 (file)
@@ -97,10 +97,10 @@ class Config
                        }
                }
 
-               $ret = dba::selectFirst('config', ['v'], ['cat' => $family, 'k' => $key]);
-               if (DBM::is_result($ret)) {
+               $config = dba::selectFirst('config', ['v'], ['cat' => $family, 'k' => $key]);
+               if (DBM::is_result($config)) {
                        // manage array value
-                       $val = (preg_match("|^a:[0-9]+:{.*}$|s", $ret['v']) ? unserialize($ret['v']) : $ret['v']);
+                       $val = (preg_match("|^a:[0-9]+:{.*}$|s", $config['v']) ? unserialize($config['v']) : $config['v']);
 
                        // Assign the value from the database to the cache
                        self::$cache[$family][$key] = $val;
index 50fea0446914f437170d410286ec8bafd1fe5c13..ad658f8f8ad77ebcdab8ae1ad61cba9b3bf3b07d 100644 (file)
@@ -90,9 +90,9 @@ class PConfig
                        }
                }
 
-               $ret = dba::selectFirst('pconfig', ['v'], ['uid' => $uid, 'cat' => $family, 'k' => $key]);
-               if (DBM::is_result($ret)) {
-                       $val = (preg_match("|^a:[0-9]+:{.*}$|s", $ret['v']) ? unserialize($ret['v']) : $ret['v']);
+               $pconfig = dba::selectFirst('pconfig', ['v'], ['uid' => $uid, 'cat' => $family, 'k' => $key]);
+               if (DBM::is_result($pconfig)) {
+                       $val = (preg_match("|^a:[0-9]+:{.*}$|s", $pconfig['v']) ? unserialize($pconfig['v']) : $pconfig['v']);
                        $a->config[$uid][$family][$key] = $val;
                        self::$in_db[$uid][$family][$key] = true;
 
index 96e4a5bb16f9cc0d6a84174e0e43945ac1b2ec67..48f689d61dea81d5fe43bf047c92e92991aa463e 100644 (file)
@@ -165,9 +165,9 @@ class Worker
        private static function highestPriority()
        {
                $condition = array("`executed` <= ? AND NOT `done`", NULL_DATE);
-               $s = dba::selectFirst('workerqueue', ['priority'], $condition, ['order' => ['priority']]);
-               if (DBM::is_result($s)) {
-                       return $s["priority"];
+               $workerqueue = dba::selectFirst('workerqueue', ['priority'], $condition, ['order' => ['priority']]);
+               if (DBM::is_result($workerqueue)) {
+                       return $workerqueue["priority"];
                } else {
                        return 0;
                }
index d92d4dd1d2678e89d557ebd161415981803cd385..4cec36c9ea5c6902d99cfeba725495f289826ab5 100644 (file)
@@ -145,13 +145,12 @@ class Contact extends BaseObject
        public static function remove($id)
        {
                // We want just to make sure that we don't delete our "self" contact
-               $r = dba::selectFirst('contact', ['uid'], ['id' => $id, 'self' => false]);
-
-               if (!DBM::is_result($r) || !intval($r['uid'])) {
+               $contact = dba::selectFirst('contact', ['uid'], ['id' => $id, 'self' => false]);
+               if (!DBM::is_result($contact) || !intval($contact['uid'])) {
                        return;
                }
 
-               $archive = PConfig::get($r['uid'], 'system', 'archive_removed_contacts');
+               $archive = PConfig::get($contact['uid'], 'system', 'archive_removed_contacts');
                if ($archive) {
                        dba::update('contact', array('archive' => true, 'network' => 'none', 'writable' => false), array('id' => $id));
                        return;
@@ -490,9 +489,10 @@ class Contact extends BaseObject
                                return $menu;
                        }
 
-                       $r = dba::selectFirst('contact', [], ['nurl' => $contact['nurl'], 'network' => $contact['network'], 'uid' => $uid]);
-                       if ($r) {
-                               return self::photoMenu($r, $uid);
+                       // Look for our own contact if the uid doesn't match and isn't public
+                       $contact_own = dba::selectFirst('contact', [], ['nurl' => $contact['nurl'], 'network' => $contact['network'], 'uid' => $uid]);
+                       if (DBM::is_result($contact_own)) {
+                               return self::photoMenu($contact_own, $uid);
                        } else {
                                $profile_link = zrl($contact['url']);
                                $connlnk = 'follow/?url=' . $contact['url'];
@@ -664,9 +664,8 @@ class Contact extends BaseObject
                if (!DBM::is_result($contact)) {
                        // The link could be provided as http although we stored it as https
                        $ssl_url = str_replace('http://', 'https://', $url);
-                       $r = dba::selectFirst('contact', ['id', 'avatar', 'avatar-date'], ['`alias` IN (?, ?, ?) AND `uid` = ?', $url, normalise_link($url), $ssl_url, $uid]);
-                       $contact = dba::fetch($r);
-                       dba::close($r);
+                       $condition = ['`alias` IN (?, ?, ?) AND `uid` = ?', $url, normalise_link($url), $ssl_url, $uid];
+                       $contact = dba::selectFirst('contact', ['id', 'avatar', 'avatar-date'], $condition);
                }
 
                if (DBM::is_result($contact)) {
@@ -697,12 +696,12 @@ class Contact extends BaseObject
                        }
 
                        // Get data from the gcontact table
-                       $gcontacts = dba::selectFirst('gcontact', ['name', 'nick', 'url', 'photo', 'addr', 'alias', 'network'], ['nurl' => normalise_link($url)]);
-                       if (!DBM::is_result($gcontacts)) {
+                       $gcontact = dba::selectFirst('gcontact', ['name', 'nick', 'url', 'photo', 'addr', 'alias', 'network'], ['nurl' => normalise_link($url)]);
+                       if (!DBM::is_result($gcontact)) {
                                return 0;
                        }
 
-                       $data = array_merge($data, $gcontacts);
+                       $data = array_merge($data, $gcontact);
                }
 
                if (!$contact_id && ($data["alias"] != '') && ($data["alias"] != $url)) {
@@ -726,7 +725,7 @@ class Contact extends BaseObject
                                'readonly' => 0, 'pending' => 0)
                        );
 
-                       $s = dba::select('contact', array('id'), array('nurl' => normalise_link($data["url"]), 'uid' => $uid), array('order' => array('id'), 'limit' => 2));
+                       $s = dba::select('contact', ['id'], ['nurl' => normalise_link($data["url"]), 'uid' => $uid], ['order' => ['id'], 'limit' => 2]);
                        $contacts = dba::inArray($s);
                        if (!DBM::is_result($contacts)) {
                                return 0;
@@ -979,15 +978,14 @@ class Contact extends BaseObject
         */
        public static function updateAvatar($avatar, $uid, $cid, $force = false)
        {
-               // Limit = 1 returns the row so no need for dba:inArray()
-               $r = dba::selectFirst('contact', ['avatar', 'photo', 'thumb', 'micro', 'nurl'], ['id' => $cid]);
-               if (!DBM::is_result($r)) {
+               $contact = dba::selectFirst('contact', ['avatar', 'photo', 'thumb', 'micro', 'nurl'], ['id' => $cid]);
+               if (!DBM::is_result($contact)) {
                        return false;
                } else {
-                       $data = array($r["photo"], $r["thumb"], $r["micro"]);
+                       $data = array($contact["photo"], $contact["thumb"], $contact["micro"]);
                }
 
-               if (($r["avatar"] != $avatar) || $force) {
+               if (($contact["avatar"] != $avatar) || $force) {
                        $photos = Photo::importProfilePhoto($avatar, $uid, $cid, true);
 
                        if ($photos) {
@@ -999,7 +997,7 @@ class Contact extends BaseObject
 
                                // Update the public contact (contact id = 0)
                                if ($uid != 0) {
-                                       $pcontact = dba::selectFirst('contact', ['id'], ['nurl' => $r[0]['nurl']]);
+                                       $pcontact = dba::selectFirst('contact', ['id'], ['nurl' => $contact['nurl']]);
                                        if (DBM::is_result($pcontact)) {
                                                self::updateAvatar($avatar, 0, $pcontact['id'], $force);
                                        }
@@ -1023,15 +1021,16 @@ class Contact extends BaseObject
                This will reliably kill your communication with Friendica contacts.
                */
 
-               $r = dba::selectFirst('contact', ['url', 'nurl', 'addr', 'alias', 'batch', 'notify', 'poll', 'poco', 'network'], ['id' => $id]);
-               if (!DBM::is_result($r)) {
+               $fields = ['url', 'nurl', 'addr', 'alias', 'batch', 'notify', 'poll', 'poco', 'network'];
+               $contact = dba::selectFirst('contact', $fields, ['id' => $id]);
+               if (!DBM::is_result($contact)) {
                        return false;
                }
 
-               $ret = Probe::uri($r["url"]);
+               $ret = Probe::uri($contact["url"]);
 
                // If Probe::uri fails the network code will be different
-               if ($ret["network"] != $r["network"]) {
+               if ($ret["network"] != $contact["network"]) {
                        return false;
                }
 
@@ -1039,11 +1038,13 @@ class Contact extends BaseObject
 
                // make sure to not overwrite existing values with blank entries
                foreach ($ret as $key => $val) {
-                       if (isset($r[$key]) && ($r[$key] != "") && ($val == ""))
-                               $ret[$key] = $r[$key];
+                       if (isset($contact[$key]) && ($contact[$key] != "") && ($val == "")) {
+                               $ret[$key] = $contact[$key];
+                       }
 
-                       if (isset($r[$key]) && ($ret[$key] != $r[$key]))
+                       if (isset($contact[$key]) && ($ret[$key] != $contact[$key])) {
                                $update = true;
+                       }
                }
 
                if (!$update) {
index 510afdf164c0ccf9a4bf847044fb40c2537781f4..f7984f0d37203dcfa6c2e2da44503a72fe93b7d5 100644 (file)
@@ -766,7 +766,7 @@ class GContact
                        return false;
                }
 
-               $r = q(
+               $public_contact = q(
                        "SELECT `name`, `nick`, `photo`, `location`, `about`, `addr`, `generation`, `birthday`, `gender`, `keywords`,
                                `contact-type`, `hide`, `nsfw`, `network`, `alias`, `notify`, `server_url`, `connect`, `updated`, `url`
                        FROM `gcontact` WHERE `id` = %d LIMIT 1",
@@ -775,7 +775,7 @@ class GContact
 
                // Get all field names
                $fields = array();
-               foreach ($r[0] as $field => $data) {
+               foreach ($public_contact[0] as $field => $data) {
                        $fields[$field] = $data;
                }
 
@@ -789,22 +789,22 @@ class GContact
                        unset($contact["keywords"]);
                }
 
-               if ($r[0]["keywords"] == "0") {
-                       $r[0]["keywords"] = "";
+               if ($public_contact[0]["keywords"] == "0") {
+                       $public_contact[0]["keywords"] = "";
                }
 
                // assign all unassigned fields from the database entry
                foreach ($fields as $field => $data) {
                        if (!isset($contact[$field]) || ($contact[$field] == "")) {
-                               $contact[$field] = $r[0][$field];
+                               $contact[$field] = $public_contact[0][$field];
                        }
                }
 
                if (!isset($contact["hide"])) {
-                       $contact["hide"] = $r[0]["hide"];
+                       $contact["hide"] = $public_contact[0]["hide"];
                }
 
-               $fields["hide"] = $r[0]["hide"];
+               $fields["hide"] = $public_contact[0]["hide"];
 
                if ($contact["network"] == NETWORK_STATUSNET) {
                        $contact["network"] = NETWORK_OSTATUS;
@@ -839,16 +839,16 @@ class GContact
                $update = false;
                unset($fields["generation"]);
 
-               if ((($contact["generation"] > 0) && ($contact["generation"] <= $r[0]["generation"])) || ($r[0]["generation"] == 0)) {
+               if ((($contact["generation"] > 0) && ($contact["generation"] <= $public_contact[0]["generation"])) || ($public_contact[0]["generation"] == 0)) {
                        foreach ($fields as $field => $data) {
-                               if ($contact[$field] != $r[0][$field]) {
-                                       logger("Difference for contact ".$contact["url"]." in field '".$field."'. New value: '".$contact[$field]."', old value '".$r[0][$field]."'", LOGGER_DEBUG);
+                               if ($contact[$field] != $public_contact[0][$field]) {
+                                       logger("Difference for contact ".$contact["url"]." in field '".$field."'. New value: '".$contact[$field]."', old value '".$public_contact[0][$field]."'", LOGGER_DEBUG);
                                        $update = true;
                                }
                        }
 
-                       if ($contact["generation"] < $r[0]["generation"]) {
-                               logger("Difference for contact ".$contact["url"]." in field 'generation'. new value: '".$contact["generation"]."', old value '".$r[0]["generation"]."'", LOGGER_DEBUG);
+                       if ($contact["generation"] < $public_contact[0]["generation"]) {
+                               logger("Difference for contact ".$contact["url"]." in field 'generation'. new value: '".$contact["generation"]."', old value '".$public_contact[0]["generation"]."'", LOGGER_DEBUG);
                                $update = true;
                        }
                }
@@ -874,21 +874,18 @@ class GContact
 
                        // Now update the contact entry with the user id "0" as well.
                        // This is used for the shadow copies of public items.
-                       $r = q(
-                               "SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = 0 ORDER BY `id` LIMIT 1",
-                               dbesc(normalise_link($contact["url"]))
-                       );
-
-                       if (DBM::is_result($r)) {
-                               logger("Update public contact ".$r[0]["id"], LOGGER_DEBUG);
+                       
+                       $public_contact = dba::selectFirst('contact', ['id'], ['nurl' => normalise_link($contact["url"]), 'uid' => 0]);
+                       if (DBM::is_result($public_contact)) {
+                               logger("Update public contact ".$public_contact["id"], LOGGER_DEBUG);
 
-                               Contact::updateAvatar($contact["photo"], 0, $r[0]["id"]);
+                               Contact::updateAvatar($contact["photo"], 0, $public_contact["id"]);
 
                                $fields = array('name', 'nick', 'addr',
                                                'network', 'bd', 'gender',
                                                'keywords', 'alias', 'contact-type',
                                                'url', 'location', 'about');
-                               $old_contact = dba::selectFirst('contact', $fields, ['id' => $r[0]["id"]]);
+                               $old_contact = dba::selectFirst('contact', $fields, ['id' => $public_contact["id"]]);
 
                                // Update it with the current values
                                $fields = array('name' => $contact['name'], 'nick' => $contact['nick'],
@@ -898,7 +895,7 @@ class GContact
                                                'contact-type' => $contact['contact-type'], 'url' => $contact['url'],
                                                'location' => $contact['location'], 'about' => $contact['about']);
 
-                               dba::update('contact', $fields, array('id' => $r[0]["id"]), $old_contact);
+                               dba::update('contact', $fields, array('id' => $public_contact["id"]), $old_contact);
                        }
                }
 
index a91636b6726e6c0556432e433acc628d0cdd3b25..62b6088d974bcbc6c8240b075f8815a26f26332b 100644 (file)
@@ -38,16 +38,16 @@ class Photo
         */
        public static function store(Image $Image, $uid, $cid, $rid, $filename, $album, $scale, $profile = 0, $allow_cid = '', $allow_gid = '', $deny_cid = '', $deny_gid = '', $desc = '')
        {
-               $r = dba::selectFirst('photo', ['guid'], ["`resource-id` = ? AND `guid` != ?", $rid, '']);
-               if (DBM::is_result($r)) {
-                       $guid = $r['guid'];
+               $photo = dba::selectFirst('photo', ['guid'], ["`resource-id` = ? AND `guid` != ?", $rid, '']);
+               if (DBM::is_result($photo)) {
+                       $guid = $photo['guid'];
                } else {
                        $guid = get_guid();
                }
 
-               $x = dba::selectFirst('photo', ['id'], ['resource-id' => $rid, 'uid' => $uid, 'contact-id' => $cid, 'scale' => $scale]);
+               $existing_photo = dba::selectFirst('photo', ['id'], ['resource-id' => $rid, 'uid' => $uid, 'contact-id' => $cid, 'scale' => $scale]);
 
-               $fields = array(
+               $fields = [
                        'uid' => $uid,
                        'contact-id' => $cid,
                        'guid' => $guid,
@@ -68,10 +68,10 @@ class Photo
                        'deny_cid' => $deny_cid,
                        'deny_gid' => $deny_gid,
                        'desc' => $desc
-               );
+               ];
 
-               if (DBM::is_result($x)) {
-                       $r = dba::update('photo', $fields, array('id' => $x['id']));
+               if (DBM::is_result($existing_photo)) {
+                       $r = dba::update('photo', $fields, ['id' => $existing_photo['id']]);
                } else {
                        $r = dba::insert('photo', $fields);
                }
@@ -80,34 +80,33 @@ class Photo
        }
 
        /**
-        * @param string  $photo         photo
+        * @param string  $image_url     Remote URL
         * @param integer $uid           user id
         * @param integer $cid           contact id
         * @param boolean $quit_on_error optional, default false
         * @return array
         */
-       public static function importProfilePhoto($photo, $uid, $cid, $quit_on_error = false)
+       public static function importProfilePhoto($image_url, $uid, $cid, $quit_on_error = false)
        {
-               $r = dba::selectFirst(
+               $photo = dba::selectFirst(
                        'photo', ['resource-id'], ['uid' => $uid, 'contact-id' => $cid, 'scale' => 4, 'album' => 'Contact Photos']
                );
-
-               if (DBM::is_result($r) && strlen($r['resource-id'])) {
-                       $hash = $r['resource-id'];
+               if (x($photo['resource-id'])) {
+                       $hash = $photo['resource-id'];
                } else {
                        $hash = photo_new_resource();
                }
 
                $photo_failure = false;
 
-               $filename = basename($photo);
-               $img_str = fetch_url($photo, true);
+               $filename = basename($image_url);
+               $img_str = fetch_url($image_url, true);
 
                if ($quit_on_error && ($img_str == "")) {
                        return false;
                }
 
-               $type = Image::guessType($photo, true);
+               $type = Image::guessType($image_url, true);
                $Image = new Image($img_str, $type);
                if ($Image->isValid()) {
                        $Image->scaleToSquare(175);
@@ -136,7 +135,7 @@ class Photo
 
                        $suffix = '?ts=' . time();
 
-                       $photo = System::baseUrl() . '/photo/' . $hash . '-4.' . $Image->getExt() . $suffix;
+                       $image_url = System::baseUrl() . '/photo/' . $hash . '-4.' . $Image->getExt() . $suffix;
                        $thumb = System::baseUrl() . '/photo/' . $hash . '-5.' . $Image->getExt() . $suffix;
                        $micro = System::baseUrl() . '/photo/' . $hash . '-6.' . $Image->getExt() . $suffix;
 
@@ -167,12 +166,12 @@ class Photo
                }
 
                if ($photo_failure) {
-                       $photo = System::baseUrl() . '/images/person-175.jpg';
+                       $image_url = System::baseUrl() . '/images/person-175.jpg';
                        $thumb = System::baseUrl() . '/images/person-80.jpg';
                        $micro = System::baseUrl() . '/images/person-48.jpg';
                }
 
-               return array($photo, $thumb, $micro);
+               return array($image_url, $thumb, $micro);
        }
 
        /**
index 07e15ad51ee72a2fd0f8659a7a27b8beea092f74..64ae3374a987c5ab25ef68c24609299612bfcfe0 100644 (file)
@@ -63,11 +63,10 @@ class FKOAuth1 extends OAuthServer
                        $a->timezone = $a->user['timezone'];
                }
 
-               $r = dba::selectFirst('contact', [], ['uid' => $_SESSION['uid'], 'self' => 1]);
-               
-               if (DBM::is_result($r)) {
-                       $a->contact = $r;
-                       $a->cid = $r['id'];
+               $contact = dba::selectFirst('contact', [], ['uid' => $_SESSION['uid'], 'self' => 1]);
+               if (DBM::is_result($contact)) {
+                       $a->contact = $contact;
+                       $a->cid = $contact['id'];
                        $_SESSION['cid'] = $a->cid;
                }
 
index ccb08ccbbaa3b0302939af4d35688f182737bbd8..ec6e1b59f1d22077f8d504a6c5f920319133a0ed 100644 (file)
@@ -88,10 +88,9 @@ class FKOAuthDataStore extends OAuthDataStore
         */
        public function lookup_nonce($consumer, $token, $nonce, $timestamp)
        {
-               $r = dba::selectFirst('tokens', ['id', 'secret'], ['client_id' => $consumer->key, 'id' => $nonce, 'expires' => $timestamp]);
-
-               if (DBM::is_result($r)) {
-                       return new \OAuthToken($r['id'], $r['secret']);
+               $token = dba::selectFirst('tokens', ['id', 'secret'], ['client_id' => $consumer->key, 'id' => $nonce, 'expires' => $timestamp]);
+               if (DBM::is_result($token)) {
+                       return new \OAuthToken($token['id'], $token['secret']);
                }
 
                return null;
index c5b97fc1361f944187313dbcae0a2a4b1170ab9d..dada4dd651ae3bab35ab510c4d3888201b683da8 100644 (file)
@@ -261,14 +261,14 @@ class Post extends BaseObject
                                        'classundo' => $item['starred'] ? "" : "hidden",
                                        'starred'   => t('starred'),
                                );
-                               $r = dba::selectFirst('thread', ['ignored'], ['uid' => $item['uid'], 'iid' => $item['id']]);
-                               if (DBM::is_result($r)) {
+                               $thread = dba::selectFirst('thread', ['ignored'], ['uid' => $item['uid'], 'iid' => $item['id']]);
+                               if (DBM::is_result($thread)) {
                                        $ignore = array(
                                                'do'        => t("ignore thread"),
                                                'undo'      => t("unignore thread"),
                                                'toggle'    => t("toggle ignore status"),
-                                               'classdo'   => $r['ignored'] ? "hidden" : "",
-                                               'classundo' => $r['ignored'] ? "" : "hidden",
+                                               'classdo'   => $thread['ignored'] ? "hidden" : "",
+                                               'classundo' => $thread['ignored'] ? "" : "hidden",
                                                'ignored'   => t('ignored'),
                                        );
                                }
index f579a40190814feab791e73cb75f524da7344a09..d60fe3fc82448f671df55cc342748cde9d36c29a 100644 (file)
@@ -66,10 +66,10 @@ class PortableContact
 
                if ($cid) {
                        if (!$url || !$uid) {
-                               $r = dba::selectFirst('contact', ['poco', 'uid'], ['id' => $cid]);
-                               if (DBM::is_result($r)) {
-                                       $url = $r['poco'];
-                                       $uid = $r['uid'];
+                               $contact = dba::selectFirst('contact', ['poco', 'uid'], ['id' => $cid]);
+                               if (DBM::is_result($contact)) {
+                                       $url = $contact['poco'];
+                                       $uid = $contact['uid'];
                                }
                        }
                        if (!$uid) {
@@ -813,30 +813,30 @@ class PortableContact
                        return false;
                }
 
-               $servers = dba::selectFirst('gserver', [], ['nurl' => normalise_link($server_url)]);
-               if (DBM::is_result($servers)) {
-                       if ($servers["created"] <= NULL_DATE) {
+               $gserver = dba::selectFirst('gserver', [], ['nurl' => normalise_link($server_url)]);
+               if (DBM::is_result($gserver)) {
+                       if ($gserver["created"] <= NULL_DATE) {
                                $fields = ['created' => datetime_convert()];
                                $condition = ['nurl' => normalise_link($server_url)];
                                dba::update('gserver', $fields, $condition);
                        }
-                       $poco = $servers["poco"];
-                       $noscrape = $servers["noscrape"];
+                       $poco = $gserver["poco"];
+                       $noscrape = $gserver["noscrape"];
 
                        if ($network == "") {
-                               $network = $servers["network"];
+                               $network = $gserver["network"];
                        }
 
-                       $last_contact = $servers["last_contact"];
-                       $last_failure = $servers["last_failure"];
-                       $version = $servers["version"];
-                       $platform = $servers["platform"];
-                       $site_name = $servers["site_name"];
-                       $info = $servers["info"];
-                       $register_policy = $servers["register_policy"];
-                       $registered_users = $servers["registered-users"];
+                       $last_contact = $gserver["last_contact"];
+                       $last_failure = $gserver["last_failure"];
+                       $version = $gserver["version"];
+                       $platform = $gserver["platform"];
+                       $site_name = $gserver["site_name"];
+                       $info = $gserver["info"];
+                       $register_policy = $gserver["register_policy"];
+                       $registered_users = $gserver["registered-users"];
 
-                       if (!$force && !self::updateNeeded($servers["created"], "", $last_failure, $last_contact)) {
+                       if (!$force && !self::updateNeeded($gserver["created"], "", $last_failure, $last_contact)) {
                                logger("Use cached data for server ".$server_url, LOGGER_DEBUG);
                                return ($last_contact >= $last_failure);
                        }
@@ -853,7 +853,7 @@ class PortableContact
                        $last_contact = NULL_DATE;
                        $last_failure = NULL_DATE;
                }
-               logger("Server ".$server_url." is outdated or unknown. Start discovery. Force: ".$force." Created: ".$servers["created"]." Failure: ".$last_failure." Contact: ".$last_contact, LOGGER_DEBUG);
+               logger("Server ".$server_url." is outdated or unknown. Start discovery. Force: ".$force." Created: ".$gserver["created"]." Failure: ".$last_failure." Contact: ".$last_contact, LOGGER_DEBUG);
 
                $failure = false;
                $possible_failure = false;
@@ -876,7 +876,7 @@ class PortableContact
 
                // Quit if there is a timeout.
                // But we want to make sure to only quit if we are mostly sure that this server url fits.
-               if (DBM::is_result($servers) && ($orig_server_url == $server_url) &&
+               if (DBM::is_result($gserver) && ($orig_server_url == $server_url) &&
                        ($serverret['errno'] == CURLE_OPERATION_TIMEDOUT)) {
                        logger("Connection to server ".$server_url." timed out.", LOGGER_DEBUG);
                        dba::update('gserver', array('last_failure' => datetime_convert()), array('nurl' => normalise_link($server_url)));
index 08dd23ad8b86a6106fe3aaf08071d1097673bd0f..093d78baae66f573a96c13ce277ada30fa5ed4c8 100644 (file)
@@ -384,16 +384,15 @@ Class OnePoll
                                                        // Have we seen it before?
                                                        $fields = ['deleted', 'id'];
                                                        $condition = ['uid' => $importer_uid, 'uri' => $datarray['uri']];
-                                                       $r = dba::selectFirst('item', $fields, $condition);
-
-                                                       if (DBM::is_result($r)) {
+                                                       $item = dba::selectFirst('item', $fields, $condition);
+                                                       if (DBM::is_result($item)) {
                                                                logger("Mail: Seen before ".$msg_uid." for ".$mailconf['user']." UID: ".$importer_uid." URI: ".$datarray['uri'],LOGGER_DEBUG);
 
                                                                // Only delete when mails aren't automatically moved or deleted
                                                                if (($mailconf['action'] != 1) && ($mailconf['action'] != 3))
-                                                                       if ($meta->deleted && ! $r['deleted']) {
+                                                                       if ($meta->deleted && ! $item['deleted']) {
                                                                                $fields = array('deleted' => true, 'changed' => datetime_convert());
-                                                                               dba::update('item', $fields, array('id' => $r['id']));
+                                                                               dba::update('item', $fields, array('id' => $item['id']));
                                                                        }
 
                                                                switch ($mailconf['action']) {
index 1b8620a9d396dadd2b48f0d131f98dde0594652b..d9ffb69d07c58d20d527fa1184f1f66c658b091f 100644 (file)
@@ -68,18 +68,11 @@ class Queue
 
 
                // delivering
-
-               $r = q(
-                       "SELECT * FROM `queue` WHERE `id` = %d LIMIT 1",
-                       intval($queue_id)
-               );
-
-               if (!DBM::is_result($r)) {
+               $q_item = dba::selectFirst('queue', [], ['id' => $queue_id]);
+               if (!DBM::is_result($q_item)) {
                        return;
                }
 
-               $q_item = $r[0];
-
                $contact = dba::selectFirst('contact', [], ['id' => $q_item['cid']]);
                if (!DBM::is_result($contact)) {
                        remove_queue_item($q_item['id']);
index 14cd06e7aa458ae5611f880f447a6b0d92c59503..26fc04d8dd93bcdcfd5ce0edb6b7a86c8c358bd7 100755 (executable)
@@ -57,8 +57,8 @@ if (in_array($net['network'], array(NETWORK_PHANTOM, NETWORK_MAIL))) {
        exit(1);
 }
 $nurl = normalise_link($net['url']);
-$r = dba::selectFirst("contact", ["id"], ["nurl" => $nurl, "uid" => 0]);
-if (DBM::is_result($r)) {
+$contact = dba::selectFirst("contact", ["id"], ["nurl" => $nurl, "uid" => 0]);
+if (DBM::is_result($contact)) {
        dba::update("contact", array("hidden" => true), array("id" => $r["id"]));
        echo "NOTICE: The account should be silenced from the global community page\r\n";
 } else {