Changeset 3 for branches/rsr.v5.1.dev/web/punbb/misc.php
- Timestamp:
- Nov 14, 2011, 11:17:15 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/rsr.v5.1.dev/web/punbb/misc.php
r1 r3 1 1 <?php 2 /*********************************************************************** 3 4 Copyright (C) 2002-2005 Rickard Andersson (rickard@punbb.org) 5 6 This file is part of PunBB. 7 8 PunBB is free software; you can redistribute it and/or modify it 9 under the terms of the GNU General Public License as published 10 by the Free Software Foundation; either version 2 of the License, 11 or (at your option) any later version. 12 13 PunBB is distributed in the hope that it will be useful, but 14 WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 GNU General Public License for more details. 17 18 You should have received a copy of the GNU General Public License 19 along with this program; if not, write to the Free Software 20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, 21 MA 02111-1307 USA 22 23 ************************************************************************/ 24 2 3 /** 4 * Copyright (C) 2008-2011 FluxBB 5 * based on code by Rickard Andersson copyright (C) 2002-2008 PunBB 6 * License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher 7 */ 25 8 26 9 if (isset($_GET['action'])) 27 10 define('PUN_QUIET_VISIT', 1); 28 11 29 define('PUN_ROOT', './');12 define('PUN_ROOT', dirname(__FILE__).'/'); 30 13 require PUN_ROOT.'include/common.php'; 31 14 … … 39 22 if ($action == 'rules') 40 23 { 24 if ($pun_config['o_rules'] == '0' || ($pun_user['is_guest'] && $pun_user['g_read_board'] == '0' && $pun_config['o_regs_allow'] == '0')) 25 message($lang_common['Bad request']); 26 41 27 // Load the register.php language file 42 28 require PUN_ROOT.'lang/'.$pun_user['language'].'/register.php'; 43 29 44 $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_register['Forum rules']; 30 $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_register['Forum rules']); 31 define('PUN_ACTIVE_PAGE', 'rules'); 45 32 require PUN_ROOT.'header.php'; 46 33 47 34 ?> 48 <div class="block">49 < h2><span><?php echo $lang_register['Forum rules'] ?></span></h2>35 <div id="rules" class="block"> 36 <div class="hd"><h2><span><?php echo $lang_register['Forum rules'] ?></span></h2></div> 50 37 <div class="box"> 51 <div class="inbox">52 < p><?php echo $pun_config['o_rules_message'] ?></p>38 <div id="rules-block" class="inbox"> 39 <div class="usercontent"><?php echo $pun_config['o_rules_message'] ?></div> 53 40 </div> 54 41 </div> … … 65 52 message($lang_common['No permission']); 66 53 67 $db->query('UPDATE '.$db->prefix.'users SET last_visit='.$pun_user['logged'].' WHERE id='.$pun_user['id']) or error('Impossible de modifier les données de derniÚre visite de l\'utilisateur', __FILE__, __LINE__, $db->error()); 54 $db->query('UPDATE '.$db->prefix.'users SET last_visit='.$pun_user['logged'].' WHERE id='.$pun_user['id']) or error('Unable to update user last visit data', __FILE__, __LINE__, $db->error()); 55 56 // Reset tracked topics 57 set_tracked_topics(null); 68 58 69 59 redirect('index.php', $lang_misc['Mark read redirect']); … … 71 61 72 62 63 // Mark the topics/posts in a forum as read? 64 else if ($action == 'markforumread') 65 { 66 if ($pun_user['is_guest']) 67 message($lang_common['No permission']); 68 69 $fid = isset($_GET['fid']) ? intval($_GET['fid']) : 0; 70 if ($fid < 1) 71 message($lang_common['Bad request']); 72 73 $tracked_topics = get_tracked_topics(); 74 $tracked_topics['forums'][$fid] = time(); 75 set_tracked_topics($tracked_topics); 76 77 redirect('viewforum.php?id='.$fid, $lang_misc['Mark forum read redirect']); 78 } 79 80 73 81 else if (isset($_GET['email'])) 74 82 { 75 if ($pun_user['is_guest'] )83 if ($pun_user['is_guest'] || $pun_user['g_send_email'] == '0') 76 84 message($lang_common['No permission']); 77 85 … … 80 88 message($lang_common['Bad request']); 81 89 82 $result = $db->query('SELECT username, email, email_setting FROM '.$db->prefix.'users WHERE id='.$recipient_id) or error(' Impossible de retrouver les informations utilisateur', __FILE__, __LINE__, $db->error());90 $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()); 83 91 if (!$db->num_rows($result)) 84 92 message($lang_common['Bad request']); … … 86 94 list($recipient, $recipient_email, $email_setting) = $db->fetch_row($result); 87 95 88 if ($email_setting == 2 && $pun_user['g_id'] > PUN_MOD)89 message($lang_misc['Form e -mail disabled']);96 if ($email_setting == 2 && !$pun_user['is_admmod']) 97 message($lang_misc['Form email disabled']); 90 98 91 99 … … 97 105 98 106 if ($subject == '') 99 message($lang_misc['No e -mail subject']);107 message($lang_misc['No email subject']); 100 108 else if ($message == '') 101 message($lang_misc['No e-mail message']); 102 else if (strlen($message) > 65535) 103 message($lang_misc['Too long e-mail message']); 104 105 // Load the "form e-mail" template 109 message($lang_misc['No email message']); 110 else if (pun_strlen($message) > PUN_MAX_POSTSIZE) 111 message($lang_misc['Too long email message']); 112 113 if ($pun_user['last_email_sent'] != '' && (time() - $pun_user['last_email_sent']) < $pun_user['g_email_flood'] && (time() - $pun_user['last_email_sent']) >= 0) 114 message(sprintf($lang_misc['Email flood'], $pun_user['g_email_flood'])); 115 116 // Load the "form email" template 106 117 $mail_tpl = trim(file_get_contents(PUN_ROOT.'lang/'.$pun_user['language'].'/mail_templates/form_email.tpl')); 107 118 108 119 // The first row contains the subject 109 120 $first_crlf = strpos($mail_tpl, "\n"); 110 $mail_subject = trim(substr($mail_tpl, 8, $first_crlf-8));111 $mail_message = trim(substr($mail_tpl, $first_crlf));121 $mail_subject = pun_trim(substr($mail_tpl, 8, $first_crlf-8)); 122 $mail_message = pun_trim(substr($mail_tpl, $first_crlf)); 112 123 113 124 $mail_subject = str_replace('<mail_subject>', $subject, $mail_subject); … … 115 126 $mail_message = str_replace('<board_title>', $pun_config['o_board_title'], $mail_message); 116 127 $mail_message = str_replace('<mail_message>', $message, $mail_message); 117 $mail_message = str_replace('<board_mailer>', $pun_config['o_board_title'] .' '.$lang_common['Mailer'], $mail_message);128 $mail_message = str_replace('<board_mailer>', $pun_config['o_board_title'], $mail_message); 118 129 119 130 require_once PUN_ROOT.'include/email.php'; 120 131 121 pun_mail($recipient_email, $mail_subject, $mail_message, '"'.str_replace('"', '', $pun_user['username']).'" <'.$pun_user['email'].'>'); 122 123 redirect($_POST['redirect_url'], $lang_misc['E-mail sent redirect']); 124 } 125 126 127 // Try to determine if the data in HTTP_REFERER is valid (if not, we redirect to the users profile after the e-mail is sent) 128 $redirect_url = (isset($_SERVER['HTTP_REFERER']) && preg_match('#^'.preg_quote($pun_config['o_base_url']).'/(.*?)\.php#i', $_SERVER['HTTP_REFERER'])) ? $_SERVER['HTTP_REFERER'] : 'index.php'; 129 130 $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_misc['Send e-mail to'].' '.pun_htmlspecialchars($recipient); 131 $required_fields = array('req_subject' => $lang_misc['E-mail subject'], 'req_message' => $lang_misc['E-mail message']); 132 pun_mail($recipient_email, $mail_subject, $mail_message, $pun_user['email'], $pun_user['username']); 133 134 $db->query('UPDATE '.$db->prefix.'users SET last_email_sent='.time().' WHERE id='.$pun_user['id']) or error('Unable to update user', __FILE__, __LINE__, $db->error()); 135 136 redirect(htmlspecialchars($_POST['redirect_url']), $lang_misc['Email sent redirect']); 137 } 138 139 140 // Try to determine if the data in HTTP_REFERER is valid (if not, we redirect to the users profile after the email is sent) 141 if (!empty($_SERVER['HTTP_REFERER'])) 142 { 143 $referrer = parse_url($_SERVER['HTTP_REFERER']); 144 // Remove www subdomain if it exists 145 if (strpos($referrer['host'], 'www.') === 0) 146 $referrer['host'] = substr($referrer['host'], 4); 147 148 $valid = parse_url(get_base_url()); 149 // Remove www subdomain if it exists 150 if (strpos($valid['host'], 'www.') === 0) 151 $valid['host'] = substr($valid['host'], 4); 152 153 if ($referrer['host'] == $valid['host'] && preg_match('%^'.preg_quote($valid['path'], '%').'/(.*?)\.php%i', $referrer['path'])) 154 $redirect_url = $_SERVER['HTTP_REFERER']; 155 } 156 157 if (!isset($redirect_url)) 158 $redirect_url = 'profile.php?id='.$recipient_id; 159 160 $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_misc['Send email to'].' '.pun_htmlspecialchars($recipient)); 161 $required_fields = array('req_subject' => $lang_misc['Email subject'], 'req_message' => $lang_misc['Email message']); 132 162 $focus_element = array('email', 'req_subject'); 163 define('PUN_ACTIVE_PAGE', 'index'); 133 164 require PUN_ROOT.'header.php'; 134 165 135 166 ?> 136 <div class="blockform">137 <h2><span><?php echo $lang_misc['Send e -mail to'] ?> <?php echo pun_htmlspecialchars($recipient) ?></span></h2>167 <div id="emailform" class="blockform"> 168 <h2><span><?php echo $lang_misc['Send email to'] ?> <?php echo pun_htmlspecialchars($recipient) ?></span></h2> 138 169 <div class="box"> 139 170 <form id="email" method="post" action="misc.php?email=<?php echo $recipient_id ?>" onsubmit="this.submit.disabled=true;if(process_form(this)){return true;}else{this.submit.disabled=false;return false;}"> 140 171 <div class="inform"> 141 172 <fieldset> 142 <legend><?php echo $lang_misc['Write e -mail'] ?></legend>173 <legend><?php echo $lang_misc['Write email'] ?></legend> 143 174 <div class="infldset txtarea"> 144 175 <input type="hidden" name="form_sent" value="1" /> 145 <input type="hidden" name="redirect_url" value="<?php echo $redirect_url?>" />146 <label ><strong><?php echo $lang_misc['E-mail subject'] ?></strong><br />176 <input type="hidden" name="redirect_url" value="<?php echo pun_htmlspecialchars($redirect_url) ?>" /> 177 <label class="required"><strong><?php echo $lang_misc['Email subject'] ?> <span><?php echo $lang_common['Required'] ?></span></strong><br /> 147 178 <input class="longinput" type="text" name="req_subject" size="75" maxlength="70" tabindex="1" /><br /></label> 148 <label ><strong><?php echo $lang_misc['E-mail message'] ?></strong><br />179 <label class="required"><strong><?php echo $lang_misc['Email message'] ?> <span><?php echo $lang_common['Required'] ?></span></strong><br /> 149 180 <textarea name="req_message" rows="10" cols="75" tabindex="2"></textarea><br /></label> 150 <p><?php echo $lang_misc['E -mail disclosure note'] ?></p>181 <p><?php echo $lang_misc['Email disclosure note'] ?></p> 151 182 </div> 152 183 </fieldset> 153 184 </div> 154 <p ><input type="submit" name="submit" value="<?php echo $lang_common['Submit'] ?>" tabindex="3" accesskey="s" /><a href="javascript:history.go(-1)"><?php echo $lang_common['Go back'] ?></a></p>185 <p class="buttons"><input type="submit" name="submit" value="<?php echo $lang_common['Submit'] ?>" tabindex="3" accesskey="s" /> <a href="javascript:history.go(-1)"><?php echo $lang_common['Go back'] ?></a></p> 155 186 </form> 156 187 </div> … … 177 208 if ($reason == '') 178 209 message($lang_misc['No reason']); 210 else if (strlen($reason) > 65535) // TEXT field can only hold 65535 bytes 211 message($lang_misc['Reason too long']); 212 213 if ($pun_user['last_report_sent'] != '' && (time() - $pun_user['last_report_sent']) < $pun_user['g_report_flood'] && (time() - $pun_user['last_report_sent']) >= 0) 214 message(sprintf($lang_misc['Report flood'], $pun_user['g_report_flood'])); 179 215 180 216 // Get the topic ID … … 186 222 187 223 // Get the subject and forum ID 188 $result = $db->query('SELECT subject, forum_id FROM '.$db->prefix.'topics WHERE id='.$topic_id) or error(' Impossible de retrouver les informations des discussions', __FILE__, __LINE__, $db->error());224 $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()); 189 225 if (!$db->num_rows($result)) 190 226 message($lang_common['Bad request']); … … 193 229 194 230 // Should we use the internal report handling? 195 if ($pun_config['o_report_method'] == 0 || $pun_config['o_report_method'] == 2)231 if ($pun_config['o_report_method'] == '0' || $pun_config['o_report_method'] == '2') 196 232 $db->query('INSERT INTO '.$db->prefix.'reports (post_id, topic_id, forum_id, reported_by, created, message) VALUES('.$post_id.', '.$topic_id.', '.$forum_id.', '.$pun_user['id'].', '.time().', \''.$db->escape($reason).'\')' ) or error('Unable to create report', __FILE__, __LINE__, $db->error()); 197 233 198 // Should we e -mail the report?199 if ($pun_config['o_report_method'] == 1 || $pun_config['o_report_method'] == 2)234 // Should we email the report? 235 if ($pun_config['o_report_method'] == '1' || $pun_config['o_report_method'] == '2') 200 236 { 201 237 // We send it to the complete mailing-list in one swoop 202 238 if ($pun_config['o_mailing_list'] != '') 203 239 { 204 $mail_subject = 'Report('.$forum_id.') - \''.$subject.'\''; 205 $mail_message = 'User \''.$pun_user['username'].'\' has reported the following message:'."\n".$pun_config['o_base_url'].'/viewtopic.php?pid='.$post_id.'#p'.$post_id."\n\n".'Reason:'."\n".$reason; 240 // Load the "new report" template 241 $mail_tpl = trim(file_get_contents(PUN_ROOT.'lang/'.$pun_user['language'].'/mail_templates/new_report.tpl')); 242 243 // The first row contains the subject 244 $first_crlf = strpos($mail_tpl, "\n"); 245 $mail_subject = trim(substr($mail_tpl, 8, $first_crlf-8)); 246 $mail_message = trim(substr($mail_tpl, $first_crlf)); 247 248 $mail_subject = str_replace('<forum_id>', $forum_id, $mail_subject); 249 $mail_subject = str_replace('<topic_subject>', $subject, $mail_subject); 250 $mail_message = str_replace('<username>', $pun_user['username'], $mail_message); 251 $mail_message = str_replace('<post_url>', get_base_url().'/viewtopic.php?pid='.$post_id.'#p'.$post_id, $mail_message); 252 $mail_message = str_replace('<reason>', $reason, $mail_message); 253 $mail_message = str_replace('<board_mailer>', $pun_config['o_board_title'], $mail_message); 206 254 207 255 require PUN_ROOT.'include/email.php'; … … 211 259 } 212 260 261 $db->query('UPDATE '.$db->prefix.'users SET last_report_sent='.time().' WHERE id='.$pun_user['id']) or error('Unable to update user', __FILE__, __LINE__, $db->error()); 262 213 263 redirect('viewtopic.php?pid='.$post_id.'#p'.$post_id, $lang_misc['Report redirect']); 214 264 } 215 265 216 217 $page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_misc['Report post']; 266 // Fetch some info about the post, the topic and the forum 267 $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()); 268 if (!$db->num_rows($result)) 269 message($lang_common['Bad request']); 270 271 $cur_post = $db->fetch_assoc($result); 272 273 if ($pun_config['o_censoring'] == '1') 274 $cur_post['subject'] = censor_words($cur_post['subject']); 275 276 $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_misc['Report post']); 218 277 $required_fields = array('req_reason' => $lang_misc['Reason']); 219 278 $focus_element = array('report', 'req_reason'); 279 define('PUN_ACTIVE_PAGE', 'index'); 220 280 require PUN_ROOT.'header.php'; 221 281 222 282 ?> 223 <div class="blockform"> 283 <div class="linkst"> 284 <div class="inbox"> 285 <ul class="crumbs"> 286 <li><a href="index.php"><?php echo $lang_common['Index'] ?></a></li> 287 <li><span>» </span><a href="viewforum.php?id=<?php echo $cur_post['fid'] ?>"><?php echo pun_htmlspecialchars($cur_post['forum_name']) ?></a></li> 288 <li><span>» </span><a href="viewtopic.php?pid=<?php echo $post_id ?>#p<?php echo $post_id ?>"><?php echo pun_htmlspecialchars($cur_post['subject']) ?></a></li> 289 <li><span>» </span><strong><?php echo $lang_misc['Report post'] ?></strong></li> 290 </ul> 291 </div> 292 </div> 293 294 <div id="reportform" class="blockform"> 224 295 <h2><span><?php echo $lang_misc['Report post'] ?></span></h2> 225 296 <div class="box"> … … 230 301 <div class="infldset txtarea"> 231 302 <input type="hidden" name="form_sent" value="1" /> 232 <label ><strong><?php echo $lang_misc['Reason'] ?></strong><br /><textarea name="req_reason" rows="5" cols="60"></textarea><br /></label>303 <label class="required"><strong><?php echo $lang_misc['Reason'] ?> <span><?php echo $lang_common['Required'] ?></span></strong><br /><textarea name="req_reason" rows="5" cols="60"></textarea><br /></label> 233 304 </div> 234 305 </fieldset> 235 306 </div> 236 <p ><input type="submit" name="submit" value="<?php echo $lang_common['Submit'] ?>" accesskey="s" /><a href="javascript:history.go(-1)"><?php echo $lang_common['Go back'] ?></a></p>307 <p class="buttons"><input type="submit" name="submit" value="<?php echo $lang_common['Submit'] ?>" accesskey="s" /> <a href="javascript:history.go(-1)"><?php echo $lang_common['Go back'] ?></a></p> 237 308 </form> 238 309 </div> … … 244 315 245 316 246 else if (isset($_GET['subscribe'])) 247 { 248 if ($pun_user['is_guest'] || $pun_config['o_subscriptions'] != '1') 249 message($lang_common['No permission']); 250 251 $topic_id = intval($_GET['subscribe']); 252 if ($topic_id < 1) 253 message($lang_common['Bad request']); 254 255 $result = $db->query('SELECT 1 FROM '.$db->prefix.'subscriptions WHERE user_id='.$pun_user['id'].' AND topic_id='.$topic_id) or error('Impossible de retrouver les informations d\'abonnement', __FILE__, __LINE__, $db->error()); 256 if ($db->num_rows($result)) 257 message($lang_misc['Already subscribed']); 258 259 $db->query('INSERT INTO '.$db->prefix.'subscriptions (user_id, topic_id) VALUES('.$pun_user['id'].' ,'.$topic_id.')') or error('UImpossible d\'ajouter l\'abonnement', __FILE__, __LINE__, $db->error()); 260 261 redirect('viewtopic.php?id='.$topic_id, $lang_misc['Subscribe redirect']); 262 } 263 264 265 else if (isset($_GET['unsubscribe'])) 266 { 267 if ($pun_user['is_guest'] || $pun_config['o_subscriptions'] != '1') 268 message($lang_common['No permission']); 269 270 $topic_id = intval($_GET['unsubscribe']); 271 if ($topic_id < 1) 272 message($lang_common['Bad request']); 273 274 $result = $db->query('SELECT 1 FROM '.$db->prefix.'subscriptions WHERE user_id='.$pun_user['id'].' AND topic_id='.$topic_id) or error('Impossible de retrouver les informations d\'abonnement', __FILE__, __LINE__, $db->error()); 275 if (!$db->num_rows($result)) 276 message($lang_misc['Not subscribed']); 277 278 $db->query('DELETE FROM '.$db->prefix.'subscriptions WHERE user_id='.$pun_user['id'].' AND topic_id='.$topic_id) or error('Impossible de supprimer l\'abonnement', __FILE__, __LINE__, $db->error()); 279 280 redirect('viewtopic.php?id='.$topic_id, $lang_misc['Unsubscribe redirect']); 317 else if ($action == 'subscribe') 318 { 319 if ($pun_user['is_guest']) 320 message($lang_common['No permission']); 321 322 $topic_id = isset($_GET['tid']) ? intval($_GET['tid']) : 0; 323 $forum_id = isset($_GET['fid']) ? intval($_GET['fid']) : 0; 324 if ($topic_id < 1 && $forum_id < 1) 325 message($lang_common['Bad request']); 326 327 if ($topic_id) 328 { 329 if ($pun_config['o_topic_subscriptions'] != '1') 330 message($lang_common['No permission']); 331 332 // Make sure the user can view the topic 333 $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()); 334 if (!$db->num_rows($result)) 335 message($lang_common['Bad request']); 336 337 $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()); 338 if ($db->num_rows($result)) 339 message($lang_misc['Already subscribed topic']); 340 341 $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()); 342 343 redirect('viewtopic.php?id='.$topic_id, $lang_misc['Subscribe redirect']); 344 } 345 346 if ($forum_id) 347 { 348 if ($pun_config['o_forum_subscriptions'] != '1') 349 message($lang_common['No permission']); 350 351 // Make sure the user can view the forum 352 $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()); 353 if (!$db->num_rows($result)) 354 message($lang_common['Bad request']); 355 356 $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()); 357 if ($db->num_rows($result)) 358 message($lang_misc['Already subscribed forum']); 359 360 $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()); 361 362 redirect('viewforum.php?id='.$forum_id, $lang_misc['Subscribe redirect']); 363 } 364 } 365 366 367 else if ($action == 'unsubscribe') 368 { 369 if ($pun_user['is_guest']) 370 message($lang_common['No permission']); 371 372 $topic_id = isset($_GET['tid']) ? intval($_GET['tid']) : 0; 373 $forum_id = isset($_GET['fid']) ? intval($_GET['fid']) : 0; 374 if ($topic_id < 1 && $forum_id < 1) 375 message($lang_common['Bad request']); 376 377 if ($topic_id) 378 { 379 if ($pun_config['o_topic_subscriptions'] != '1') 380 message($lang_common['No permission']); 381 382 $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()); 383 if (!$db->num_rows($result)) 384 message($lang_misc['Not subscribed topic']); 385 386 $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()); 387 388 redirect('viewtopic.php?id='.$topic_id, $lang_misc['Unsubscribe redirect']); 389 } 390 391 if ($forum_id) 392 { 393 if ($pun_config['o_forum_subscriptions'] != '1') 394 message($lang_common['No permission']); 395 396 $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()); 397 if (!$db->num_rows($result)) 398 message($lang_misc['Not subscribed forum']); 399 400 $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()); 401 402 redirect('viewforum.php?id='.$forum_id, $lang_misc['Unsubscribe redirect']); 403 } 281 404 } 282 405
Note: See TracChangeset
for help on using the changeset viewer.