Merge pull request #4206 from MrPetovan/task/fix-scrutinizer-issues
Improve dba::selectFirst calls
This commit is contained in:
commit
91198cb53d
30 changed files with 438 additions and 444 deletions
|
@ -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']) {
|
||||
|
|
|
@ -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 = [];
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
12
mod/xrd.php
12
mod/xrd.php
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue