Used more dbm::is_result() instead of (!$r) or (!count($r)), still there are

more pending ...

Also put SQL table columns into back-ticks.

Signed-off-by: Roland Häder <roland@mxchange.org>
This commit is contained in:
Roland Häder 2016-12-19 14:42:20 +01:00
parent c43389f79a
commit a96eb3428d
11 changed files with 20 additions and 19 deletions

View File

@ -229,14 +229,14 @@ function get_contact_details_by_url($url, $uid = -1, $default = array()) {
dbesc(normalise_link($url)), intval($uid)); dbesc(normalise_link($url)), intval($uid));
// Fetch the data from the contact table with "uid=0" (which is filled automatically) // Fetch the data from the contact table with "uid=0" (which is filled automatically)
if (!$r) if (!dbm::is_result($r))
$r = q("SELECT `id`, 0 AS `cid`, `id` AS `zid`, 0 AS `gid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, `xmpp`, $r = q("SELECT `id`, 0 AS `cid`, `id` AS `zid`, 0 AS `gid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, `xmpp`,
`keywords`, `gender`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, 0 AS `self` `keywords`, `gender`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, 0 AS `self`
FROM `contact` WHERE `nurl` = '%s' AND `uid` = 0", FROM `contact` WHERE `nurl` = '%s' AND `uid` = 0",
dbesc(normalise_link($url))); dbesc(normalise_link($url)));
// Fetch the data from the gcontact table // Fetch the data from the gcontact table
if (!$r) if (!dbm::is_result($r))
$r = q("SELECT 0 AS `id`, 0 AS `cid`, `id` AS `gid`, 0 AS `zid`, 0 AS `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, '' AS `xmpp`, $r = q("SELECT 0 AS `id`, 0 AS `cid`, `id` AS `gid`, 0 AS `zid`, 0 AS `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, '' AS `xmpp`,
`keywords`, `gender`, `photo`, `photo` AS `thumb`, `photo` AS `micro`, `community` AS `forum`, 0 AS `prv`, `community`, `contact-type`, `birthday`, 0 AS `self` `keywords`, `gender`, `photo`, `photo` AS `thumb`, `photo` AS `micro`, `community` AS `forum`, 0 AS `prv`, `community`, `contact-type`, `birthday`, 0 AS `self`
FROM `gcontact` WHERE `nurl` = '%s'", FROM `gcontact` WHERE `nurl` = '%s'",

View File

@ -3590,7 +3590,7 @@
intval($gid), intval($gid),
dbesc($name)); dbesc($name));
// error message if specified gid is not in database // error message if specified gid is not in database
if (count($rname) == 0) if (!dbm::is_result($rname))
throw new BadRequestException('wrong group name'); throw new BadRequestException('wrong group name');
// delete group // delete group
@ -3629,7 +3629,7 @@
intval($uid), intval($uid),
dbesc($name)); dbesc($name));
// error message if specified group name already exists // error message if specified group name already exists
if (count($rname) != 0) if (dbm::is_result($rname))
throw new BadRequestException('group name already exists'); throw new BadRequestException('group name already exists');
// check if specified group name is a deleted group // check if specified group name is a deleted group
@ -3637,7 +3637,7 @@
intval($uid), intval($uid),
dbesc($name)); dbesc($name));
// error message if specified group name already exists // error message if specified group name already exists
if (count($rname) != 0) if (dbm::is_result($rname))
$reactivate_group = true; $reactivate_group = true;
// create group // create group

View File

@ -264,7 +264,7 @@ function cron_poll_contacts($argc, $argv) {
intval($c['id']) intval($c['id'])
); );
if((! $res) || (! count($res))) if (dbm::is_result($res))
continue; continue;
foreach($res as $contact) { foreach($res as $contact) {

View File

@ -956,8 +956,8 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
// in it. // in it.
if (!$deleted AND !$dontcache) { if (!$deleted AND !$dontcache) {
$r = q('SELECT * FROM `item` WHERE id = %d', intval($current_post)); $r = q('SELECT * FROM `item` WHERE `id` = %d', intval($current_post));
if (count($r) == 1) { if ((dbm::is_result($r)) && (count($r) == 1)) {
if ($notify) if ($notify)
call_hooks('post_local_end', $r[0]); call_hooks('post_local_end', $r[0]);
else else
@ -2230,7 +2230,7 @@ function posted_date_widget($url,$uid,$wall) {
$ret = list_post_dates($uid,$wall); $ret = list_post_dates($uid,$wall);
if (! count($ret)) if (! dbm::is_result($ret))
return $o; return $o;
$cutoff_year = intval(datetime_convert('',date_default_timezone_get(),'now','Y')) - $visible_years; $cutoff_year = intval(datetime_convert('',date_default_timezone_get(),'now','Y')) - $visible_years;

View File

@ -23,7 +23,8 @@ function lock_function($fn_name, $block = true, $wait_sec = 2, $timeout = 30) {
); );
$got_lock = true; $got_lock = true;
} }
elseif(! dbm::is_result($r)) { // the Boolean value for count($r) should be equivalent to the Boolean value of $r elseif(! dbm::is_result($r)) {
/// @TODO the Boolean value for count($r) should be equivalent to the Boolean value of $r
q("INSERT INTO `locks` (`name`, `created`, `locked`) VALUES ('%s', '%s', 1)", q("INSERT INTO `locks` (`name`, `created`, `locked`) VALUES ('%s', '%s', 1)",
dbesc($fn_name), dbesc($fn_name),
dbesc(datetime_convert()) dbesc(datetime_convert())

View File

@ -129,7 +129,7 @@ function reload_plugins() {
*/ */
function plugin_enabled($plugin) { function plugin_enabled($plugin) {
$r = q("SELECT * FROM `addon` WHERE `installed` = 1 AND `name` = '%s'", $plugin); $r = q("SELECT * FROM `addon` WHERE `installed` = 1 AND `name` = '%s'", $plugin);
return((bool)(count($r) > 0)); return ((dbm::is_result($r)) && (count($r) > 0));
} }

View File

@ -213,7 +213,7 @@ function poller_max_connections_reached() {
// The processlist only shows entries of the current user // The processlist only shows entries of the current user
if ($max != 0) { if ($max != 0) {
$r = q("SHOW PROCESSLIST"); $r = q("SHOW PROCESSLIST");
if (!$r) if (!dbm::is_result($r))
return false; return false;
$used = count($r); $used = count($r);

View File

@ -1558,7 +1558,7 @@ function get_gcontact_id($contact) {
proc_run(PRIORITY_LOW, 'include/gprobe.php', bin2hex($contact["url"])); proc_run(PRIORITY_LOW, 'include/gprobe.php', bin2hex($contact["url"]));
} }
if ((count($r) > 1) AND ($gcontact_id > 0) AND ($contact["url"] != "")) if ((dbm::is_result($r)) AND (count($r) > 1) AND ($gcontact_id > 0) AND ($contact["url"] != ""))
q("DELETE FROM `gcontact` WHERE `nurl` = '%s' AND `id` != %d", q("DELETE FROM `gcontact` WHERE `nurl` = '%s' AND `id` != %d",
dbesc(normalise_link($contact["url"])), dbesc(normalise_link($contact["url"])),
intval($gcontact_id)); intval($gcontact_id));

View File

@ -241,7 +241,7 @@ function create_user($arr) {
WHERE `nickname` = '%s' ", WHERE `nickname` = '%s' ",
dbesc($nickname) dbesc($nickname)
); );
if((count($r) > 1) && $newuid) { if ((dbm::is_result($r)) && (count($r) > 1) && $newuid) {
$result['message'] .= t('Nickname is already registered. Please choose another.') . EOL; $result['message'] .= t('Nickname is already registered. Please choose another.') . EOL;
q("DELETE FROM `user` WHERE `uid` = %d", q("DELETE FROM `user` WHERE `uid` = %d",
intval($newuid) intval($newuid)

View File

@ -92,7 +92,7 @@ function profiles_init(&$a) {
intval(local_user()), intval(local_user()),
intval($a->argv[2]) intval($a->argv[2])
); );
if(! count($r1)) { if(! dbm::is_result($r1)) {
notice( t('Profile unavailable to clone.') . EOL); notice( t('Profile unavailable to clone.') . EOL);
killme(); killme();
return; return;
@ -116,7 +116,7 @@ function profiles_init(&$a) {
dbesc($name) dbesc($name)
); );
info( t('New profile created.') . EOL); info( t('New profile created.') . EOL);
if(count($r3) == 1) if ((dbm::is_result($r3)) && (count($r3) == 1))
goaway('profiles/'.$r3[0]['id']); goaway('profiles/'.$r3[0]['id']);
goaway('profiles'); goaway('profiles');

View File

@ -12,14 +12,14 @@ function user_allow($hash) {
); );
if(! count($register)) if(! dbm::is_result($register))
return false; return false;
$user = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", $user = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
intval($register[0]['uid']) intval($register[0]['uid'])
); );
if(! count($user)) if(! dbm::is_result($user))
killme(); killme();
$r = q("DELETE FROM `register` WHERE `hash` = '%s'", $r = q("DELETE FROM `register` WHERE `hash` = '%s'",
@ -69,7 +69,7 @@ function user_deny($hash) {
dbesc($hash) dbesc($hash)
); );
if(! count($register)) if(! dbm::is_result($register))
return false; return false;
$user = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", $user = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",