Avoiding $db->num_rows() in misc.php
This commit is contained in:
parent
822e808581
commit
faba141ff0
1 changed files with 21 additions and 17 deletions
38
misc.php
38
misc.php
|
@ -120,10 +120,12 @@ else if (isset($_GET['email']))
|
|||
message($lang_common['Bad request'], false, '404 Not Found');
|
||||
|
||||
$result = $db->query('SELECT username, email, email_setting FROM '.$db->prefix.'users WHERE id='.$recipient_id) or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
|
||||
if (!$db->num_rows($result))
|
||||
$user_data = $db->fetch_row($result);
|
||||
|
||||
if (!$user_data)
|
||||
message($lang_common['Bad request'], false, '404 Not Found');
|
||||
|
||||
list($recipient, $recipient_email, $email_setting) = $db->fetch_row($result);
|
||||
list($recipient, $recipient_email, $email_setting) = $user_data;
|
||||
|
||||
if ($email_setting == 2 && !$pun_user['is_admmod'])
|
||||
message($lang_misc['Form email disabled']);
|
||||
|
@ -233,7 +235,7 @@ else if (isset($_GET['report']))
|
|||
{
|
||||
// Make sure they got here from the site
|
||||
confirm_referrer('misc.php');
|
||||
|
||||
|
||||
// Clean up reason from POST
|
||||
$reason = pun_linebreaks(pun_trim($_POST['req_reason']));
|
||||
if ($reason == '')
|
||||
|
@ -246,17 +248,19 @@ else if (isset($_GET['report']))
|
|||
|
||||
// Get the topic ID
|
||||
$result = $db->query('SELECT topic_id FROM '.$db->prefix.'posts WHERE id='.$post_id) or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
|
||||
if (!$db->num_rows($result))
|
||||
message($lang_common['Bad request'], false, '404 Not Found');
|
||||
|
||||
$topic_id = $db->result($result);
|
||||
|
||||
if (!$topic_id)
|
||||
message($lang_common['Bad request'], false, '404 Not Found');
|
||||
|
||||
// Get the subject and forum ID
|
||||
$result = $db->query('SELECT subject, forum_id FROM '.$db->prefix.'topics WHERE id='.$topic_id) or error('Unable to fetch topic info', __FILE__, __LINE__, $db->error());
|
||||
if (!$db->num_rows($result))
|
||||
$topic_data = $db->fetch_row($result);
|
||||
|
||||
if (!$topic_data)
|
||||
message($lang_common['Bad request'], false, '404 Not Found');
|
||||
|
||||
list($subject, $forum_id) = $db->fetch_row($result);
|
||||
list($subject, $forum_id) = $topic_data;
|
||||
|
||||
// Should we use the internal report handling?
|
||||
if ($pun_config['o_report_method'] == '0' || $pun_config['o_report_method'] == '2')
|
||||
|
@ -296,11 +300,11 @@ else if (isset($_GET['report']))
|
|||
|
||||
// Fetch some info about the post, the topic and the forum
|
||||
$result = $db->query('SELECT f.id AS fid, f.forum_name, t.id AS tid, t.subject FROM '.$db->prefix.'posts AS p INNER JOIN '.$db->prefix.'topics AS t ON t.id=p.topic_id INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$pun_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND p.id='.$post_id) or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
|
||||
if (!$db->num_rows($result))
|
||||
message($lang_common['Bad request'], false, '404 Not Found');
|
||||
|
||||
$cur_post = $db->fetch_assoc($result);
|
||||
|
||||
if (!$cur_post)
|
||||
message($lang_common['Bad request'], false, '404 Not Found');
|
||||
|
||||
if ($pun_config['o_censoring'] == '1')
|
||||
$cur_post['subject'] = censor_words($cur_post['subject']);
|
||||
|
||||
|
@ -365,11 +369,11 @@ else if ($action == 'subscribe')
|
|||
|
||||
// Make sure the user can view the topic
|
||||
$result = $db->query('SELECT 1 FROM '.$db->prefix.'topics AS t LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=t.forum_id AND fp.group_id='.$pun_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND t.id='.$topic_id.' AND t.moved_to IS NULL') or error('Unable to fetch topic info', __FILE__, __LINE__, $db->error());
|
||||
if (!$db->num_rows($result))
|
||||
if (!$db->result($result))
|
||||
message($lang_common['Bad request'], false, '404 Not Found');
|
||||
|
||||
$result = $db->query('SELECT 1 FROM '.$db->prefix.'topic_subscriptions WHERE user_id='.$pun_user['id'].' AND topic_id='.$topic_id) or error('Unable to fetch subscription info', __FILE__, __LINE__, $db->error());
|
||||
if ($db->num_rows($result))
|
||||
if ($db->result($result))
|
||||
message($lang_misc['Already subscribed topic']);
|
||||
|
||||
$db->query('INSERT INTO '.$db->prefix.'topic_subscriptions (user_id, topic_id) VALUES('.$pun_user['id'].' ,'.$topic_id.')') or error('Unable to add subscription', __FILE__, __LINE__, $db->error());
|
||||
|
@ -384,11 +388,11 @@ else if ($action == 'subscribe')
|
|||
|
||||
// Make sure the user can view the forum
|
||||
$result = $db->query('SELECT 1 FROM '.$db->prefix.'forums AS f LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$pun_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND f.id='.$forum_id) or error('Unable to fetch forum info', __FILE__, __LINE__, $db->error());
|
||||
if (!$db->num_rows($result))
|
||||
if (!$db->result($result))
|
||||
message($lang_common['Bad request'], false, '404 Not Found');
|
||||
|
||||
$result = $db->query('SELECT 1 FROM '.$db->prefix.'forum_subscriptions WHERE user_id='.$pun_user['id'].' AND forum_id='.$forum_id) or error('Unable to fetch subscription info', __FILE__, __LINE__, $db->error());
|
||||
if ($db->num_rows($result))
|
||||
if ($db->result($result))
|
||||
message($lang_misc['Already subscribed forum']);
|
||||
|
||||
$db->query('INSERT INTO '.$db->prefix.'forum_subscriptions (user_id, forum_id) VALUES('.$pun_user['id'].' ,'.$forum_id.')') or error('Unable to add subscription', __FILE__, __LINE__, $db->error());
|
||||
|
@ -416,7 +420,7 @@ else if ($action == 'unsubscribe')
|
|||
message($lang_common['No permission'], false, '403 Forbidden');
|
||||
|
||||
$result = $db->query('SELECT 1 FROM '.$db->prefix.'topic_subscriptions WHERE user_id='.$pun_user['id'].' AND topic_id='.$topic_id) or error('Unable to fetch subscription info', __FILE__, __LINE__, $db->error());
|
||||
if (!$db->num_rows($result))
|
||||
if (!$db->result($result))
|
||||
message($lang_misc['Not subscribed topic']);
|
||||
|
||||
$db->query('DELETE FROM '.$db->prefix.'topic_subscriptions WHERE user_id='.$pun_user['id'].' AND topic_id='.$topic_id) or error('Unable to remove subscription', __FILE__, __LINE__, $db->error());
|
||||
|
@ -430,7 +434,7 @@ else if ($action == 'unsubscribe')
|
|||
message($lang_common['No permission'], false, '403 Forbidden');
|
||||
|
||||
$result = $db->query('SELECT 1 FROM '.$db->prefix.'forum_subscriptions WHERE user_id='.$pun_user['id'].' AND forum_id='.$forum_id) or error('Unable to fetch subscription info', __FILE__, __LINE__, $db->error());
|
||||
if (!$db->num_rows($result))
|
||||
if (!$db->result($result))
|
||||
message($lang_misc['Not subscribed forum']);
|
||||
|
||||
$db->query('DELETE FROM '.$db->prefix.'forum_subscriptions WHERE user_id='.$pun_user['id'].' AND forum_id='.$forum_id) or error('Unable to remove subscription', __FILE__, __LINE__, $db->error());
|
||||
|
|
Loading…
Reference in a new issue