fluxbb-1.4-beta2 to fluxbb-1.4.1 Legend
Lines removed 
Lines changed
 Lines added

/dev/null b/.gitignore
   1: cache/cache_*.php
   2: include/user/*
   3: img/avatars/*.png
   4: img/avatars/*.jpg
   5: img/avatars/*.gif
   6: config.php


/dev/null b/admin_bans.php
   1: <?php
   2: 
   3: /**
   4:  * Copyright (C) 2008-2010 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:  */
   8: 
   9: // Tell header.php to use the admin template
  10: define('PUN_ADMIN_CONSOLE', 1);
  11: 
  12: define('PUN_ROOT', './');
  13: require PUN_ROOT.'include/common.php';
  14: require PUN_ROOT.'include/common_admin.php';
  15: 
  16: 
  17: if ($pun_user['g_id'] != PUN_ADMIN && ($pun_user['g_moderator'] != '1' || $pun_user['g_mod_ban_users'] == '0'))
  18:     message($lang_common['No permission']);
  19: 
  20: // Load the admin_bans.php language file
  21: require PUN_ROOT.'lang/'.$admin_language.'/admin_bans.php';
  22: 
  23: // Add/edit a ban (stage 1)
  24: if (isset($_REQUEST['add_ban']) || isset($_GET['edit_ban']))
  25: {
  26:     if (isset($_GET['add_ban']) || isset($_POST['add_ban']))
  27:     {
  28:         // If the ID of the user to ban was provided through GET (a link from profile.php)
  29:         if (isset($_GET['add_ban']))
  30:         {
  31:             $user_id = intval($_GET['add_ban']);
  32:             if ($user_id < 2)
  33:                 message($lang_common['Bad request']);
  34: 
  35:             $result = $db->query('SELECT group_id, username, email FROM '.$db->prefix.'users WHERE id='.$user_id) or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
  36:             if ($db->num_rows($result))
  37:                 list($group_id, $ban_user, $ban_email) = $db->fetch_row($result);
  38:             else
  39:                 message($lang_admin_bans['No user ID message']);
  40:         }
  41:         else // Otherwise the username is in POST
  42:         {
  43:             $ban_user = pun_trim($_POST['new_ban_user']);
  44: 
  45:             if ($ban_user != '')
  46:             {
  47:                 $result = $db->query('SELECT id, group_id, username, email FROM '.$db->prefix.'users WHERE username=\''.$db->escape($ban_user).'\' AND id>1') or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
  48:                 if ($db->num_rows($result))
  49:                     list($user_id, $group_id, $ban_user, $ban_email) = $db->fetch_row($result);
  50:                 else
  51:                     message($lang_admin_bans['No user message']);
  52:             }
  53:         }
  54: 
  55:         // Make sure we're not banning an admin
  56:         if (isset($group_id) && $group_id == PUN_ADMIN)
  57:             message(sprintf($lang_admin_bans['User is admin message'], pun_htmlspecialchars($ban_user)));
  58: 
  59:         // If we have a $user_id, we can try to find the last known IP of that user
  60:         if (isset($user_id))
  61:         {
  62:             $result = $db->query('SELECT poster_ip FROM '.$db->prefix.'posts WHERE poster_id='.$user_id.' ORDER BY posted DESC LIMIT 1') or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
  63:             $ban_ip = ($db->num_rows($result)) ? $db->result($result) : '';
  64:         }
  65: 
  66:         $mode = 'add';
  67:     }
  68:     else // We are editing a ban
  69:     {
  70:         $ban_id = intval($_GET['edit_ban']);
  71:         if ($ban_id < 1)
  72:             message($lang_common['Bad request']);
  73: 
  74:         $result = $db->query('SELECT username, ip, email, message, expire FROM '.$db->prefix.'bans WHERE id='.$ban_id) or error('Unable to fetch ban info', __FILE__, __LINE__, $db->error());
  75:         if ($db->num_rows($result))
  76:             list($ban_user, $ban_ip, $ban_email, $ban_message, $ban_expire) = $db->fetch_row($result);
  77:         else
  78:             message($lang_common['Bad request']);
  79: 
  80:         $diff = ($pun_user['timezone'] + $pun_user['dst']) * 3600;
  81:         $ban_expire = ($ban_expire != '') ? gmdate('Y-m-d', $ban_expire + $diff) : '';
  82: 
  83:         $mode = 'edit';
  84:     }
  85: 
  86:     $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_admin_common['Admin'], $lang_admin_common['Bans']);
  87:     $focus_element = array('bans2', 'ban_user');
  88:     define('PUN_ACTIVE_PAGE', 'admin');
  89:     require PUN_ROOT.'header.php';
  90: 
  91:     generate_admin_menu('bans');
  92: 
  93: ?>
  94:     <div class="blockform">
  95:         <h2><span><?php echo $lang_admin_bans['Ban advanced head'] ?></span></h2>
  96:         <div class="box">
  97:             <form id="bans2" method="post" action="admin_bans.php">
  98:                 <div class="inform">
  99:                 <input type="hidden" name="mode" value="<?php echo $mode ?>" />
 100: <?php if ($mode == 'edit'): ?>                <input type="hidden" name="ban_id" value="<?php echo $ban_id ?>" />
 101: <?php endif; ?>                <fieldset>
 102:                         <legend><?php echo $lang_admin_bans['Ban advanced subhead'] ?></legend>
 103:                         <div class="infldset">
 104:                             <table class="aligntop" cellspacing="0">
 105:                                 <tr>
 106:                                     <th scope="row"><?php echo $lang_admin_bans['Username label'] ?></th>
 107:                                     <td>
 108:                                         <input type="text" name="ban_user" size="25" maxlength="25" value="<?php if (isset($ban_user)) echo pun_htmlspecialchars($ban_user); ?>" tabindex="1" />
 109:                                         <span><?php echo $lang_admin_bans['Username help'] ?></span>
 110:                                     </td>
 111:                                 </tr>
 112:                                 <tr>
 113:                                     <th scope="row"><?php echo $lang_admin_bans['IP label'] ?></th>
 114:                                     <td>
 115:                                         <input type="text" name="ban_ip" size="45" maxlength="255" value="<?php if (isset($ban_ip)) echo $ban_ip; ?>" tabindex="2" />
 116:                                         <span><?php echo $lang_admin_bans['IP help'] ?><?php if ($ban_user != '' && isset($user_id)) printf(' '.$lang_admin_bans['IP help link'], '<a href="admin_users.php?ip_stats='.$user_id.'">'.$lang_admin_common['here'].'</a>') ?></span>
 117:                                     </td>
 118:                                 </tr>
 119:                                 <tr>
 120:                                     <th scope="row"><?php echo $lang_admin_bans['E-mail label'] ?></th>
 121:                                     <td>
 122:                                         <input type="text" name="ban_email" size="40" maxlength="80" value="<?php if (isset($ban_email)) echo $ban_email; ?>" tabindex="3" />
 123:                                         <span><?php echo $lang_admin_bans['E-mail help'] ?></span>
 124:                                     </td>
 125:                                 </tr>
 126:                             </table>
 127:                             <p class="topspace"><strong class="warntext"><?php echo $lang_admin_bans['Ban IP range info'] ?></strong></p>
 128:                         </div>
 129:                     </fieldset>
 130:                 </div>
 131:                 <div class="inform">
 132:                     <fieldset>
 133:                         <legend><?php echo $lang_admin_bans['Message expiry subhead'] ?></legend>
 134:                         <div class="infldset">
 135:                             <table class="aligntop" cellspacing="0">
 136:                                 <tr>
 137:                                     <th scope="row"><?php echo $lang_admin_bans['Ban message label'] ?></th>
 138:                                     <td>
 139:                                         <input type="text" name="ban_message" size="50" maxlength="255" value="<?php if (isset($ban_message)) echo pun_htmlspecialchars($ban_message); ?>" tabindex="4" />
 140:                                         <span><?php echo $lang_admin_bans['Ban message help'] ?></span>
 141:                                     </td>
 142:                                 </tr>
 143:                                 <tr>
 144:                                     <th scope="row"><?php echo $lang_admin_bans['Expire date label'] ?></th>
 145:                                     <td>
 146:                                         <input type="text" name="ban_expire" size="17" maxlength="10" value="<?php if (isset($ban_expire)) echo $ban_expire; ?>" tabindex="5" />
 147:                                         <span><?php echo $lang_admin_bans['Expire date help'] ?></span>
 148:                                     </td>
 149:                                 </tr>
 150:                             </table>
 151:                         </div>
 152:                     </fieldset>
 153:                 </div>
 154:                 <p class="submitend"><input type="submit" name="add_edit_ban" value="<?php echo $lang_admin_common['Save'] ?>" tabindex="6" /></p>
 155:             </form>
 156:         </div>
 157:     </div>
 158:     <div class="clearer"></div>
 159: </div>
 160: <?php
 161: 
 162:     require PUN_ROOT.'footer.php';
 163: }
 164: 
 165: // Add/edit a ban (stage 2)
 166: else if (isset($_POST['add_edit_ban']))
 167: {
 168:     confirm_referrer('admin_bans.php');
 169: 
 170:     $ban_user = pun_trim($_POST['ban_user']);
 171:     $ban_ip = trim($_POST['ban_ip']);
 172:     $ban_email = strtolower(trim($_POST['ban_email']));
 173:     $ban_message = pun_trim($_POST['ban_message']);
 174:     $ban_expire = trim($_POST['ban_expire']);
 175: 
 176:     if ($ban_user == '' && $ban_ip == '' && $ban_email == '')
 177:         message($lang_admin_bans['Must enter message']);
 178:     else if (strtolower($ban_user) == 'guest')
 179:         message($lang_admin_bans['Cannot ban guest message']);
 180: 
 181:     // Validate IP/IP range (it's overkill, I know)
 182:     if ($ban_ip != '')
 183:     {
 184:         $ban_ip = preg_replace('/\s{2,}/S', ' ', $ban_ip);
 185:         $addresses = explode(' ', $ban_ip);
 186:         $addresses = array_map('pun_trim', $addresses);
 187: 
 188:         for ($i = 0; $i < count($addresses); ++$i)
 189:         {
 190:             if (strpos($addresses[$i], ':') !== false)
 191:             {
 192:                 $octets = explode(':', $addresses[$i]);
 193: 
 194:                 for ($c = 0; $c < count($octets); ++$c)
 195:                 {
 196:                     $octets[$c] = ltrim($octets[$c], "0");
 197: 
 198:                     if ($c > 7 || (!empty($octets[$c]) && !ctype_xdigit($octets[$c])) || intval($octets[$c], 16) > 65535)
 199:                         message($lang_admin_bans['Invalid IP message']);
 200:                 }
 201: 
 202:                 $cur_address = implode(':', $octets);
 203:                 $addresses[$i] = $cur_address;
 204:             }
 205:             else
 206:             {
 207:                 $octets = explode('.', $addresses[$i]);
 208: 
 209:                 for ($c = 0; $c < count($octets); ++$c)
 210:                 {
 211:                     $octets[$c] = (strlen($octets[$c]) > 1) ? ltrim($octets[$c], "0") : $octets[$c];
 212: 
 213:                     if ($c > 3 || preg_match('/[^0-9]/', $octets[$c]) || intval($octets[$c]) > 255)
 214:                         message($lang_admin_bans['Invalid IP message']);
 215:                 }
 216: 
 217:                 $cur_address = implode('.', $octets);
 218:                 $addresses[$i] = $cur_address;
 219:             }
 220:         }
 221: 
 222:         $ban_ip = implode(' ', $addresses);
 223:     }
 224: 
 225:     require PUN_ROOT.'include/email.php';
 226:     if ($ban_email != '' && !is_valid_email($ban_email))
 227:     {
 228:         if (!preg_match('/^[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/', $ban_email))
 229:             message($lang_admin_bans['Invalid e-mail message']);
 230:     }
 231: 
 232:     if ($ban_expire != '' && $ban_expire != 'Never')
 233:     {
 234:         $ban_expire = strtotime($ban_expire.' GMT');
 235: 
 236:         if ($ban_expire == -1 || !$ban_expire)
 237:             message($lang_admin_bans['Invalid date message'].' '.$lang_admin_bans['Invalid date reasons']);
 238: 
 239:         $diff = ($pun_user['timezone'] + $pun_user['dst']) * 3600;
 240:         $ban_expire -= $diff;
 241: 
 242:         if ($ban_expire <= time())
 243:             message($lang_admin_bans['Invalid date message'].' '.$lang_admin_bans['Invalid date reasons']);
 244:     }
 245:     else
 246:         $ban_expire = 'NULL';
 247: 
 248:     $ban_user = ($ban_user != '') ? '\''.$db->escape($ban_user).'\'' : 'NULL';
 249:     $ban_ip = ($ban_ip != '') ? '\''.$db->escape($ban_ip).'\'' : 'NULL';
 250:     $ban_email = ($ban_email != '') ? '\''.$db->escape($ban_email).'\'' : 'NULL';
 251:     $ban_message = ($ban_message != '') ? '\''.$db->escape($ban_message).'\'' : 'NULL';
 252: 
 253:     if ($_POST['mode'] == 'add')
 254:         $db->query('INSERT INTO '.$db->prefix.'bans (username, ip, email, message, expire, ban_creator) VALUES('.$ban_user.', '.$ban_ip.', '.$ban_email.', '.$ban_message.', '.$ban_expire.', '.$pun_user['id'].')') or error('Unable to add ban', __FILE__, __LINE__, $db->error());
 255:     else
 256:         $db->query('UPDATE '.$db->prefix.'bans SET username='.$ban_user.', ip='.$ban_ip.', email='.$ban_email.', message='.$ban_message.', expire='.$ban_expire.' WHERE id='.intval($_POST['ban_id'])) or error('Unable to update ban', __FILE__, __LINE__, $db->error());
 257: 
 258:     // Regenerate the bans cache
 259:     if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
 260:         require PUN_ROOT.'include/cache.php';
 261: 
 262:     generate_bans_cache();
 263: 
 264:     if ($_POST['mode'] == 'edit')
 265:         redirect('admin_bans.php', $lang_admin_bans['Ban edited redirect']);
 266:     else
 267:         redirect('admin_bans.php', $lang_admin_bans['Ban added redirect']);
 268: }
 269: 
 270: // Remove a ban
 271: else if (isset($_GET['del_ban']))
 272: {
 273:     confirm_referrer('admin_bans.php');
 274: 
 275:     $ban_id = intval($_GET['del_ban']);
 276:     if ($ban_id < 1)
 277:         message($lang_common['Bad request']);
 278: 
 279:     $db->query('DELETE FROM '.$db->prefix.'bans WHERE id='.$ban_id) or error('Unable to delete ban', __FILE__, __LINE__, $db->error());
 280: 
 281:     // Regenerate the bans cache
 282:     if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
 283:         require PUN_ROOT.'include/cache.php';
 284: 
 285:     generate_bans_cache();
 286: 
 287:     redirect('admin_bans.php', $lang_admin_bans['Ban removed redirect']);
 288: }
 289: 
 290: // Find bans
 291: else if (isset($_GET['find_ban']))
 292: {
 293:     $form = isset($_GET['form']) ? $_GET['form'] : array();
 294: 
 295:     // trim() all elements in $form
 296:     $form = array_map('pun_trim', $form);
 297:     $conditions = $query_str = array();
 298: 
 299:     $expire_after = isset($_GET['expire_after']) ? trim($_GET['expire_after']) : '';
 300:     $expire_before = isset($_GET['expire_before']) ? trim($_GET['expire_before']) : '';
 301:     $order_by = isset($_GET['order_by']) && in_array($_GET['order_by'], array('username', 'ip', 'email', 'expire')) ? $_GET['order_by'] : 'username';
 302:     $direction = isset($_GET['direction']) && $_GET['direction'] == 'DESC' ? 'DESC' : 'ASC';
 303: 
 304:     $query_str[] = 'order_by='.$order_by;
 305:     $query_str[] = 'direction='.$direction;
 306: 
 307:     // Try to convert date/time to timestamps
 308:     if ($expire_after != '')
 309:     {
 310:         $query_str[] = 'expire_after='.$expire_after;
 311: 
 312:         $expire_after = strtotime($expire_after);
 313:         if ($expire_after === false || $expire_after == -1)
 314:             message($lang_admin_bans['Invalid date message']);
 315: 
 316:         $conditions[] = 'expire>'.$expire_after;
 317:     }
 318:     if ($expire_before != '')
 319:     {
 320:         $query_str[] = 'expire_before='.$expire_before;
 321: 
 322:         $expire_before = strtotime($expire_before);
 323:         if ($expire_before === false || $expire_before == -1)
 324:             message($lang_admin_bans['Invalid date message']);
 325: 
 326:         $conditions[] = 'expire<'.$expire_before;
 327:     }
 328: 
 329:     $like_command = ($db_type == 'pgsql') ? 'ILIKE' : 'LIKE';
 330:     foreach ($form as $key => $input)
 331:     {
 332:         if ($input != '' && in_array($key, array('username', 'ip', 'email', 'message')))
 333:         {
 334:             $conditions[] = 'b.'.$db->escape($key).' '.$like_command.' \''.$db->escape(str_replace('*', '%', $input)).'\'';
 335:             $query_str[] = 'form%5B'.$key.'%5D='.urlencode($input);
 336:         }
 337:     }
 338: 
 339:     // Fetch ban count
 340:     $result = $db->query('SELECT COUNT(id) FROM '.$db->prefix.'bans as b WHERE b.id>0'.(!empty($conditions) ? ' AND '.implode(' AND ', $conditions) : '')) or error('Unable to fetch ban list', __FILE__, __LINE__, $db->error());
 341:     $num_bans = $db->result($result);
 342: 
 343:     // Determine the ban offset (based on $_GET['p'])
 344:     $num_pages = ceil($num_bans / 50);
 345: 
 346:     $p = (!isset($_GET['p']) || $_GET['p'] <= 1 || $_GET['p'] > $num_pages) ? 1 : intval($_GET['p']);
 347:     $start_from = 50 * ($p - 1);
 348: 
 349:     // Generate paging links
 350:     $paging_links = '<span class="pages-label">'.$lang_common['Pages'].' </span>'.paginate($num_pages, $p, 'admin_bans.php?find_ban=&amp;'.implode('&amp;', $query_str));
 351: 
 352:     $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_admin_common['Admin'], $lang_admin_common['Bans'], $lang_admin_bans['Results head']);
 353:     define('PUN_ACTIVE_PAGE', 'admin');
 354:     require PUN_ROOT.'header.php';
 355: 
 356: ?>
 357: <div class="linkst">
 358:     <div class="inbox crumbsplus">
 359:         <ul class="crumbs">
 360:             <li><a href="admin_index.php"><?php echo $lang_admin_common['Admin'].' '.$lang_admin_common['Index'] ?></a></li>
 361:             <li><span>»&#160;</span><a href="admin_bans.php"><?php echo $lang_admin_common['Bans'] ?></a></li>
 362:             <li><span>»&#160;</span><strong><?php echo $lang_admin_bans['Results head'] ?></strong></li>
 363:         </ul>
 364:         <div class="pagepost">
 365:             <p class="pagelink"><?php echo $paging_links ?></p>
 366:         </div>
 367:         <div class="clearer"></div>
 368:     </div>
 369: </div>
 370: 
 371: 
 372: <div id="bans1" class="blocktable">
 373:     <h2><span><?php echo $lang_admin_bans['Results head'] ?></span></h2>
 374:     <div class="box">
 375:         <div class="inbox">
 376:             <table cellspacing="0">
 377:             <thead>
 378:                 <tr>
 379:                     <th class="tcl" scope="col"><?php echo $lang_admin_bans['Results username head'] ?></th>
 380:                     <th class="tc2" scope="col"><?php echo $lang_admin_bans['Results e-mail head'] ?></th>
 381:                     <th class="tc3" scope="col"><?php echo $lang_admin_bans['Results IP address head'] ?></th>
 382:                     <th class="tc4" scope="col"><?php echo $lang_admin_bans['Results expire head'] ?></th>
 383:                     <th class="tc5" scope="col"><?php echo $lang_admin_bans['Results message head'] ?></th>
 384:                     <th class="tc6" scope="col"><?php echo $lang_admin_bans['Results banned by head'] ?></th>
 385:                     <th class="tcr" scope="col"><?php echo $lang_admin_bans['Results actions head'] ?></th>
 386:                 </tr>
 387:             </thead>
 388:             <tbody>
 389: <?php
 390: 
 391:     $result = $db->query('SELECT b.id, b.username, b.ip, b.email, b.message, b.expire, b.ban_creator, u.username AS ban_creator_username FROM '.$db->prefix.'bans AS b LEFT JOIN '.$db->prefix.'users AS u ON b.ban_creator=u.id WHERE b.id>0'.(!empty($conditions) ? ' AND '.implode(' AND ', $conditions) : '').' ORDER BY '.$db->escape($order_by).' '.$db->escape($direction).' LIMIT '.$start_from.', 50') or error('Unable to fetch ban list', __FILE__, __LINE__, $db->error());
 392:     if ($db->num_rows($result))
 393:     {
 394:         while ($ban_data = $db->fetch_assoc($result))
 395:         {
 396: 
 397:             $actions = '<a href="admin_bans.php?edit_ban='.$ban_data['id'].'">'.$lang_admin_common['Edit'].'</a> | <a href="admin_bans.php?del_ban='.$ban_data['id'].'">'.$lang_admin_common['Remove'].'</a>';
 398:             $expire = format_time($ban_data['expire'], true);
 399: 
 400: ?>
 401:                 <tr>
 402:                     <td class="tcl"><?php echo ($ban_data['username'] != '') ? pun_htmlspecialchars($ban_data['username']) : '&#160;' ?></td>
 403:                     <td class="tc2"><?php echo ($ban_data['email'] != '') ? $ban_data['email'] : '&#160;' ?></td>
 404:                     <td class="tc3"><?php echo ($ban_data['ip'] != '') ? $ban_data['ip'] : '&#160;' ?></td>
 405:                     <td class="tc4"><?php echo $expire ?></td>
 406:                     <td class="tc5"><?php echo ($ban_data['message'] != '') ? pun_htmlspecialchars($ban_data['message']) : '&#160;' ?></td>
 407:                     <td class="tc6"><?php echo ($ban_data['ban_creator_username'] != '') ? '<a href="profile.php?id='.$ban_data['ban_creator'].'">'.pun_htmlspecialchars($ban_data['ban_creator_username']).'</a>' : $lang_admin_bans['Unknown'] ?></td>
 408:                     <td class="tcr"><?php echo $actions ?></td>
 409:                 </tr>
 410: <?php
 411: 
 412:         }
 413:     }
 414:     else
 415:         echo "\t\t\t\t".'<tr><td class="tcl" colspan="7">'.$lang_admin_bans['No match'].'</td></tr>'."\n";
 416: 
 417: ?>
 418:             </tbody>
 419:             </table>
 420:         </div>
 421:     </div>
 422: </div>
 423: 
 424: <div class="linksb">
 425:     <div class="inbox crumbsplus">
 426:         <div class="pagepost">
 427:             <p class="pagelink"><?php echo $paging_links ?></p>
 428:         </div>
 429:         <ul class="crumbs">
 430:             <li><a href="admin_index.php"><?php echo $lang_admin_common['Admin'].' '.$lang_admin_common['Index'] ?></a></li>
 431:             <li><span>»&#160;</span><a href="admin_bans.php"><?php echo $lang_admin_common['Bans'] ?></a></li>
 432:             <li><span>»&#160;</span><strong><?php echo $lang_admin_bans['Results head'] ?></strong></li>
 433:         </ul>
 434:         <div class="clearer"></div>
 435:     </div>
 436: </div>
 437: <?php
 438: 
 439:     require PUN_ROOT.'footer.php';
 440: }
 441: 
 442: $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_admin_common['Admin'], $lang_admin_common['Bans']);
 443: $focus_element = array('bans', 'new_ban_user');
 444: define('PUN_ACTIVE_PAGE', 'admin');
 445: require PUN_ROOT.'header.php';
 446: 
 447: generate_admin_menu('bans');
 448: 
 449: ?>
 450:     <div class="blockform">
 451:         <h2><span><?php echo $lang_admin_bans['New ban head'] ?></span></h2>
 452:         <div class="box">
 453:             <form id="bans" method="post" action="admin_bans.php?action=more">
 454:                 <div class="inform">
 455:                     <fieldset>
 456:                         <legend><?php echo $lang_admin_bans['Add ban subhead'] ?></legend>
 457:                         <div class="infldset">
 458:                             <table class="aligntop" cellspacing="0">
 459:                                 <tr>
 460:                                     <th scope="row"><?php echo $lang_admin_bans['Username label'] ?><div><input type="submit" name="add_ban" value="<?php echo $lang_admin_common['Add'] ?>" tabindex="2" /></div></th>
 461:                                     <td>
 462:                                         <input type="text" name="new_ban_user" size="25" maxlength="25" tabindex="1" />
 463:                                         <span><?php echo $lang_admin_bans['Username advanced help'] ?></span>
 464:                                     </td>
 465:                                 </tr>
 466:                             </table>
 467:                         </div>
 468:                     </fieldset>
 469:                 </div>
 470:             </form>
 471:         </div>
 472: 
 473:         <h2 class="block2"><span><?php echo $lang_admin_bans['Ban search head'] ?></span></h2>
 474:         <div class="box">
 475:             <form id="find_band" method="get" action="admin_bans.php">
 476:                 <p class="submittop"><input type="submit" name="find_ban" value="<?php echo $lang_admin_bans['Submit search'] ?>" tabindex="3" /></p>
 477:                 <div class="inform">
 478:                     <fieldset>
 479:                         <legend><?php echo $lang_admin_bans['Ban search subhead'] ?></legend>
 480:                         <div class="infldset">
 481:                             <p><?php echo $lang_admin_bans['Ban search info'] ?></p>
 482:                             <table class="aligntop" cellspacing="0">
 483:                                 <tr>
 484:                                     <th scope="row"><?php echo $lang_admin_bans['Username label'] ?></th>
 485:                                     <td><input type="text" name="form[username]" size="25" maxlength="25" tabindex="4" /></td>
 486:                                 </tr>
 487:                                 <tr>
 488:                                     <th scope="row"><?php echo $lang_admin_bans['IP label'] ?></th>
 489:                                     <td><input type="text" name="form[ip]" size="30" maxlength="255" tabindex="5" /></td>
 490:                                 </tr>
 491:                                 <tr>
 492:                                     <th scope="row"><?php echo $lang_admin_bans['E-mail label'] ?></th>
 493:                                     <td><input type="text" name="form[email]" size="30" maxlength="80" tabindex="6" /></td>
 494:                                 </tr>
 495:                                 <tr>
 496:                                     <th scope="row"><?php echo $lang_admin_bans['Message label'] ?></th>
 497:                                     <td><input type="text" name="form[message]" size="30" maxlength="255" tabindex="7" /></td>
 498:                                 </tr>
 499:                                 <tr>
 500:                                     <th scope="row"><?php echo $lang_admin_bans['Expire after label'] ?></th>
 501:                                     <td><input type="text" name="expire_after" size="10" maxlength="10" tabindex="8" />
 502:                                     <span><?php echo $lang_admin_bans['Date help'] ?></span></td>
 503:                                 </tr>
 504:                                 <tr>
 505:                                     <th scope="row"><?php echo $lang_admin_bans['Expire before label'] ?></th>
 506:                                     <td><input type="text" name="expire_before" size="10" maxlength="10" tabindex="9" />
 507:                                     <span><?php echo $lang_admin_bans['Date help'] ?></span></td>
 508:                                 </tr>
 509:                                 <tr>
 510:                                     <th scope="row"><?php echo $lang_admin_bans['Order by label'] ?></th>
 511:                                     <td>
 512:                                         <select name="order_by" tabindex="10">
 513:                                             <option value="username" selected="selected"><?php echo $lang_admin_bans['Order by username'] ?></option>
 514:                                             <option value="ip"><?php echo $lang_admin_bans['Order by ip'] ?></option>
 515:                                             <option value="email"><?php echo $lang_admin_bans['Order by e-mail'] ?></option>
 516:                                             <option value="expire"><?php echo $lang_admin_bans['Order by expire'] ?></option>
 517:                                         </select>&#160;&#160;&#160;<select name="direction" tabindex="11">
 518:                                             <option value="ASC" selected="selected"><?php echo $lang_admin_bans['Ascending'] ?></option>
 519:                                             <option value="DESC"><?php echo $lang_admin_bans['Descending'] ?></option>
 520:                                         </select>
 521:                                     </td>
 522:                                 </tr>
 523:                             </table>
 524:                         </div>
 525:                     </fieldset>
 526:                 </div>
 527:                 <p class="submitend"><input type="submit" name="find_ban" value="<?php echo $lang_admin_bans['Submit search'] ?>" tabindex="12" /></p>
 528:             </form>
 529:         </div>
 530:     </div>
 531:     <div class="clearer"></div>
 532: </div>
 533: <?php
 534: 
 535: require PUN_ROOT.'footer.php';


/dev/null b/admin_categories.php
   1: <?php
   2: 
   3: /**
   4:  * Copyright (C) 2008-2010 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:  */
   8: 
   9: // Tell header.php to use the admin template
  10: define('PUN_ADMIN_CONSOLE', 1);
  11: 
  12: define('PUN_ROOT', './');
  13: require PUN_ROOT.'include/common.php';
  14: require PUN_ROOT.'include/common_admin.php';
  15: 
  16: 
  17: if ($pun_user['g_id'] != PUN_ADMIN)
  18:     message($lang_common['No permission']);
  19: 
  20: // Load the admin_categories.php language file
  21: require PUN_ROOT.'lang/'.$admin_language.'/admin_categories.php';
  22: 
  23: // Add a new category
  24: if (isset($_POST['add_cat']))
  25: {
  26:     confirm_referrer('admin_categories.php');
  27: 
  28:     $new_cat_name = pun_trim($_POST['new_cat_name']);
  29:     if ($new_cat_name == '')
  30:         message($lang_admin_categories['Must enter name message']);
  31: 
  32:     $db->query('INSERT INTO '.$db->prefix.'categories (cat_name) VALUES(\''.$db->escape($new_cat_name).'\')') or error('Unable to create category', __FILE__, __LINE__, $db->error());
  33: 
  34:     redirect('admin_categories.php', $lang_admin_categories['Category added redirect']);
  35: }
  36: 
  37: // Delete a category
  38: else if (isset($_POST['del_cat']) || isset($_POST['del_cat_comply']))
  39: {
  40:     confirm_referrer('admin_categories.php');
  41: 
  42:     $cat_to_delete = intval($_POST['cat_to_delete']);
  43:     if ($cat_to_delete < 1)
  44:         message($lang_common['Bad request']);
  45: 
  46:     if (isset($_POST['del_cat_comply'])) // Delete a category with all forums and posts
  47:     {
  48:         @set_time_limit(0);
  49: 
  50:         $result = $db->query('SELECT id FROM '.$db->prefix.'forums WHERE cat_id='.$cat_to_delete) or error('Unable to fetch forum list', __FILE__, __LINE__, $db->error());
  51:         $num_forums = $db->num_rows($result);
  52: 
  53:         for ($i = 0; $i < $num_forums; ++$i)
  54:         {
  55:             $cur_forum = $db->result($result, $i);
  56: 
  57:             // Prune all posts and topics
  58:             prune($cur_forum, 1, -1);
  59: 
  60:             // Delete the forum
  61:             $db->query('DELETE FROM '.$db->prefix.'forums WHERE id='.$cur_forum) or error('Unable to delete forum', __FILE__, __LINE__, $db->error());
  62:         }
  63: 
  64:         // Locate any "orphaned redirect topics" and delete them
  65:         $result = $db->query('SELECT t1.id FROM '.$db->prefix.'topics AS t1 LEFT JOIN '.$db->prefix.'topics AS t2 ON t1.moved_to=t2.id WHERE t2.id IS NULL AND t1.moved_to IS NOT NULL') or error('Unable to fetch redirect topics', __FILE__, __LINE__, $db->error());
  66:         $num_orphans = $db->num_rows($result);
  67: 
  68:         if ($num_orphans)
  69:         {
  70:             for ($i = 0; $i < $num_orphans; ++$i)
  71:                 $orphans[] = $db->result($result, $i);
  72: 
  73:             $db->query('DELETE FROM '.$db->prefix.'topics WHERE id IN('.implode(',', $orphans).')') or error('Unable to delete redirect topics', __FILE__, __LINE__, $db->error());
  74:         }
  75: 
  76:         // Delete the category
  77:         $db->query('DELETE FROM '.$db->prefix.'categories WHERE id='.$cat_to_delete) or error('Unable to delete category', __FILE__, __LINE__, $db->error());
  78: 
  79:         // Regenerate the quick jump cache
  80:         if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
  81:             require PUN_ROOT.'include/cache.php';
  82: 
  83:         generate_quickjump_cache();
  84: 
  85:         redirect('admin_categories.php', $lang_admin_categories['Category deleted redirect']);
  86:     }
  87:     else // If the user hasn't comfirmed the delete
  88:     {
  89:         $result = $db->query('SELECT cat_name FROM '.$db->prefix.'categories WHERE id='.$cat_to_delete) or error('Unable to fetch category info', __FILE__, __LINE__, $db->error());
  90:         $cat_name = $db->result($result);
  91: 
  92:         $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_admin_common['Admin'], $lang_admin_common['Categories']);
  93:         define('PUN_ACTIVE_PAGE', 'admin');
  94:         require PUN_ROOT.'header.php';
  95: 
  96:         generate_admin_menu('categories');
  97: 
  98: ?>
  99:     <div class="blockform">
 100:         <h2><span><?php echo $lang_admin_categories['Delete category head'] ?></span></h2>
 101:         <div class="box">
 102:             <form method="post" action="admin_categories.php">
 103:                 <div class="inform">
 104:                 <input type="hidden" name="cat_to_delete" value="<?php echo $cat_to_delete ?>" />
 105:                     <fieldset>
 106:                         <legend><?php echo $lang_admin_categories['Confirm delete subhead'] ?></legend>
 107:                         <div class="infldset">
 108:                             <p><?php printf($lang_admin_categories['Confirm delete info'], pun_htmlspecialchars($cat_name)) ?></p>
 109:                             <p class="warntext"><?php echo $lang_admin_categories['Delete category warn'] ?></p>
 110:                         </div>
 111:                     </fieldset>
 112:                 </div>
 113:                 <p class="buttons"><input type="submit" name="del_cat_comply" value="<?php echo $lang_admin_common['Delete'] ?>" /><a href="javascript:history.go(-1)"><?php echo $lang_admin_common['Go back'] ?></a></p>
 114:             </form>
 115:         </div>
 116:     </div>
 117:     <div class="clearer"></div>
 118: </div>
 119: <?php
 120: 
 121:         require PUN_ROOT.'footer.php';
 122:     }
 123: }
 124: 
 125: else if (isset($_POST['update'])) // Change position and name of the categories
 126: {
 127:     confirm_referrer('admin_categories.php');
 128: 
 129:     $cat_order = array_map('trim', $_POST['cat_order']);
 130:     $cat_name = array_map('pun_trim', $_POST['cat_name']);
 131: 
 132:     $result = $db->query('SELECT id, disp_position FROM '.$db->prefix.'categories ORDER BY disp_position') or error('Unable to fetch category list', __FILE__, __LINE__, $db->error());
 133:     $num_cats = $db->num_rows($result);
 134: 
 135:     for ($i = 0; $i < $num_cats; ++$i)
 136:     {
 137:         if ($cat_name[$i] == '')
 138:             message($lang_admin_categories['Must enter name message']);
 139: 
 140:         if ($cat_order[$i] == '' || preg_match('/[^0-9]/', $cat_order[$i]))
 141:             message($lang_admin_categories['Must enter integer message']);
 142: 
 143:         list($cat_id, $position) = $db->fetch_row($result);
 144: 
 145:         $db->query('UPDATE '.$db->prefix.'categories SET cat_name=\''.$db->escape($cat_name[$i]).'\', disp_position='.$cat_order[$i].' WHERE id='.$cat_id) or error('Unable to update category', __FILE__, __LINE__, $db->error());
 146:     }
 147: 
 148:     // Regenerate the quick jump cache
 149:     if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
 150:         require PUN_ROOT.'include/cache.php';
 151: 
 152:     generate_quickjump_cache();
 153: 
 154:     redirect('admin_categories.php', $lang_admin_categories['Categories updated redirect']);
 155: }
 156: 
 157: // Generate an array with all categories
 158: $result = $db->query('SELECT id, cat_name, disp_position FROM '.$db->prefix.'categories ORDER BY disp_position') or error('Unable to fetch category list', __FILE__, __LINE__, $db->error());
 159: $num_cats = $db->num_rows($result);
 160: 
 161: for ($i = 0; $i < $num_cats; ++$i)
 162:     $cat_list[] = $db->fetch_row($result);
 163: 
 164: $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_admin_common['Admin'], $lang_admin_common['Categories']);
 165: define('PUN_ACTIVE_PAGE', 'admin');
 166: require PUN_ROOT.'header.php';
 167: 
 168: generate_admin_menu('categories');
 169: 
 170: ?>
 171:     <div class="blockform">
 172:         <h2><span><?php echo $lang_admin_categories['Add categories head'] ?></span></h2>
 173:         <div class="box">
 174:             <form method="post" action="admin_categories.php?action=foo">
 175:                 <div class="inform">
 176:                     <fieldset>
 177:                         <legend><?php echo $lang_admin_categories['Add categories subhead'] ?></legend>
 178:                         <div class="infldset">
 179:                             <table class="aligntop" cellspacing="0">
 180:                                 <tr>
 181:                                     <th scope="row"><?php echo $lang_admin_categories['Add category label'] ?><div><input type="submit" name="add_cat" value="<?php echo $lang_admin_categories['Add new submit'] ?>" tabindex="2" /></div></th>
 182:                                     <td>
 183:                                         <input type="text" name="new_cat_name" size="35" maxlength="80" tabindex="1" />
 184:                                         <span><?php printf($lang_admin_categories['Add category help'], '<a href="admin_forums.php">'.$lang_admin_common['Forums'].'</a>') ?></span>
 185:                                     </td>
 186:                                 </tr>
 187:                             </table>
 188:                         </div>
 189:                     </fieldset>
 190:                 </div>
 191:             </form>
 192:         </div>
 193: 
 194: <?php if ($num_cats): ?>        <h2 class="block2"><span><?php echo $lang_admin_categories['Delete categories head'] ?></span></h2>
 195:         <div class="box">
 196:             <form method="post" action="admin_categories.php?action=foo">
 197:                 <div class="inform">
 198:                     <fieldset>
 199:                         <legend><?php echo $lang_admin_categories['Delete categories subhead'] ?></legend>
 200:                         <div class="infldset">
 201:                             <table class="aligntop" cellspacing="0">
 202:                                 <tr>
 203:                                     <th scope="row"><?php echo $lang_admin_categories['Delete category label'] ?><div><input type="submit" name="del_cat" value="<?php echo $lang_admin_common['Delete'] ?>" tabindex="4" /></div></th>
 204:                                     <td>
 205:                                         <select name="cat_to_delete" tabindex="3">
 206: <?php
 207: 
 208:     foreach ($cat_list as $category)
 209:         echo "\t\t\t\t\t\t\t\t\t\t\t".'<option value="'.$category[0].'">'.pun_htmlspecialchars($category[1]).'</option>'."\n";
 210: 
 211: ?>
 212:                                         </select>
 213:                                         <span><?php echo $lang_admin_categories['Delete category help'] ?></span>
 214:                                     </td>
 215:                                 </tr>
 216:                             </table>
 217:                         </div>
 218:                     </fieldset>
 219:                 </div>
 220:             </form>
 221:         </div>
 222: <?php endif; ?>
 223: 
 224: <?php if ($num_cats): ?>        <h2 class="block2"><span><?php echo $lang_admin_categories['Edit categories head'] ?></span></h2>
 225:         <div class="box">
 226:             <form method="post" action="admin_categories.php?action=foo">
 227:                 <div class="inform">
 228:                     <fieldset>
 229:                         <legend><?php echo $lang_admin_categories['Edit categories subhead'] ?></legend>
 230:                         <div class="infldset">
 231:                             <table id="categoryedit" cellspacing="0" >
 232:                             <thead>
 233:                                 <tr>
 234:                                     <th class="tcl" scope="col"><?php echo $lang_admin_categories['Category name label'] ?></th>
 235:                                     <th scope="col"><?php echo $lang_admin_categories['Category position label'] ?></th>
 236:                                 </tr>
 237:                             </thead>
 238:                             <tbody>
 239: <?php
 240: 
 241:     foreach ($cat_list as $i => $category)
 242:     {
 243: 
 244: ?>
 245:                                 <tr>
 246:                                     <td class="tcl"><input type="text" name="cat_name[<?php echo $i ?>]" value="<?php echo pun_htmlspecialchars($category[1]) ?>" size="35" maxlength="80" /></td>
 247:                                     <td><input type="text" name="cat_order[<?php echo $i ?>]" value="<?php echo $category[2] ?>" size="3" maxlength="3" /></td>
 248:                                 </tr>
 249: <?php
 250: 
 251:     }
 252: 
 253: ?>
 254:                             </tbody>
 255:                             </table>
 256:                             <div class="fsetsubmit"><input type="submit" name="update" value="<?php echo $lang_admin_common['Update'] ?>" /></div>
 257:                         </div>
 258:                     </fieldset>
 259:                 </div>
 260:             </form>
 261:         </div>
 262: <?php endif; ?>    </div>
 263:     <div class="clearer"></div>
 264: </div>
 265: <?php
 266: 
 267: require PUN_ROOT.'footer.php';


/dev/null b/admin_censoring.php
   1: <?php
   2: 
   3: /**
   4:  * Copyright (C) 2008-2010 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:  */
   8: 
   9: // Tell header.php to use the admin template
  10: define('PUN_ADMIN_CONSOLE', 1);
  11: 
  12: define('PUN_ROOT', './');
  13: require PUN_ROOT.'include/common.php';
  14: require PUN_ROOT.'include/common_admin.php';
  15: 
  16: 
  17: if (!$pun_user['is_admmod'] || ($pun_user['g_moderator'] == '1' && $pun_config['o_censoring'] == '0'))
  18:     message($lang_common['No permission']);
  19: 
  20: // Load the admin_censoring.php language file
  21: require PUN_ROOT.'lang/'.$admin_language.'/admin_censoring.php';
  22: 
  23: // Add a censor word
  24: if (isset($_POST['add_word']))
  25: {
  26:     confirm_referrer('admin_censoring.php');
  27: 
  28:     $search_for = pun_trim($_POST['new_search_for']);
  29:     $replace_with = pun_trim($_POST['new_replace_with']);
  30: 
  31:     if ($search_for == '' || $replace_with == '')
  32:         message($lang_admin_censoring['Must enter both message']);
  33: 
  34:     $db->query('INSERT INTO '.$db->prefix.'censoring (search_for, replace_with) VALUES (\''.$db->escape($search_for).'\', \''.$db->escape($replace_with).'\')') or error('Unable to add censor word', __FILE__, __LINE__, $db->error());
  35: 
  36:     redirect('admin_censoring.php', $lang_admin_censoring['Word added redirect']);
  37: }
  38: 
  39: // Update a censor word
  40: else if (isset($_POST['update']))
  41: {
  42:     confirm_referrer('admin_censoring.php');
  43: 
  44:     $id = intval(key($_POST['update']));
  45: 
  46:     $search_for = pun_trim($_POST['search_for'][$id]);
  47:     $replace_with = pun_trim($_POST['replace_with'][$id]);
  48: 
  49:     if ($search_for == '' || $replace_with == '')
  50:         message($lang_admin_censoring['Must search both message']);
  51: 
  52:     $db->query('UPDATE '.$db->prefix.'censoring SET search_for=\''.$db->escape($search_for).'\', replace_with=\''.$db->escape($replace_with).'\' WHERE id='.$id) or error('Unable to update censor word', __FILE__, __LINE__, $db->error());
  53: 
  54:     redirect('admin_censoring.php', $lang_admin_censoring['Word updated redirect']);
  55: }
  56: 
  57: // Remove a censor word
  58: else if (isset($_POST['remove']))
  59: {
  60:     confirm_referrer('admin_censoring.php');
  61: 
  62:     $id = intval(key($_POST['remove']));
  63: 
  64:     $db->query('DELETE FROM '.$db->prefix.'censoring WHERE id='.$id) or error('Unable to delete censor word', __FILE__, __LINE__, $db->error());
  65: 
  66:     redirect('admin_censoring.php',  $lang_admin_censoring['Word removed redirect']);
  67: }
  68: 
  69: $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_admin_common['Admin'], $lang_admin_common['Censoring']);
  70: $focus_element = array('censoring', 'new_search_for');
  71: define('PUN_ACTIVE_PAGE', 'admin');
  72: require PUN_ROOT.'header.php';
  73: 
  74: generate_admin_menu('censoring');
  75: 
  76: ?>
  77:     <div class="blockform">
  78:         <h2><span><?php echo $lang_admin_censoring['Censoring head'] ?></span></h2>
  79:         <div class="box">
  80:             <form id="censoring" method="post" action="admin_censoring.php?action=foo">
  81:                 <div class="inform">
  82:                     <fieldset>
  83:                         <legend><?php echo $lang_admin_censoring['Add word subhead'] ?></legend>
  84:                         <div class="infldset">
  85:                             <p><?php echo $lang_admin_censoring['Add word info'].($pun_user['g_id'] != PUN_ADMIN ? '' : ' '.($pun_config['o_censoring'] == '1' ? sprintf($lang_admin_censoring['Censoring enabled'], '<a href="admin_options.php#censoring">'.$lang_admin_common['Options'].'</a>') : sprintf($lang_admin_censoring['Censoring disabled'], '<a href="admin_options.php#censoring">'.$lang_admin_common['Options'].'</a>'))) ?></p>
  86:                             <table cellspacing="0">
  87:                             <thead>
  88:                                 <tr>
  89:                                     <th class="tcl" scope="col"><?php echo $lang_admin_censoring['Censored word label'] ?></th>
  90:                                     <th class="tc2" scope="col"><?php echo $lang_admin_censoring['Replacement label'] ?></th>
  91:                                     <th class="hidehead" scope="col"><?php echo $lang_admin_censoring['Action label'] ?></th>
  92:                                 </tr>
  93:                             </thead>
  94:                             <tbody>
  95:                                 <tr>
  96:                                     <td class="tcl"><input type="text" name="new_search_for" size="24" maxlength="60" tabindex="1" /></td>
  97:                                     <td class="tc2"><input type="text" name="new_replace_with" size="24" maxlength="60" tabindex="2" /></td>
  98:                                     <td><input type="submit" name="add_word" value="<?php echo $lang_admin_common['Add'] ?>" tabindex="3" /></td>
  99:                                 </tr>
 100:                             </tbody>
 101:                             </table>
 102:                         </div>
 103:                     </fieldset>
 104:                 </div>
 105:                 <div class="inform">
 106:                     <fieldset>
 107:                         <legend><?php echo $lang_admin_censoring['Edit remove subhead'] ?></legend>
 108:                         <div class="infldset">
 109: <?php
 110: 
 111: $result = $db->query('SELECT id, search_for, replace_with FROM '.$db->prefix.'censoring ORDER BY id') or error('Unable to fetch censor word list', __FILE__, __LINE__, $db->error());
 112: if ($db->num_rows($result))
 113: {
 114: 
 115: ?>
 116:                             <table cellspacing="0" >
 117:                             <thead>
 118:                                 <tr>
 119:                                     <th class="tcl" scope="col"><?php echo $lang_admin_censoring['Censored word label'] ?></th>
 120:                                     <th class="tc2" scope="col"><?php echo $lang_admin_censoring['Replacement label'] ?></th>
 121:                                     <th class="hidehead" scope="col"><?php echo $lang_admin_censoring['Action label'] ?></th>
 122:                                 </tr>
 123:                             </thead>
 124:                             <tbody>
 125: <?php
 126: 
 127:     while ($cur_word = $db->fetch_assoc($result))
 128:         echo "\t\t\t\t\t\t\t\t".'<tr><td class="tcl"><input type="text" name="search_for['.$cur_word['id'].']" value="'.pun_htmlspecialchars($cur_word['search_for']).'" size="24" maxlength="60" /></td><td class="tc2"><input type="text" name="replace_with['.$cur_word['id'].']" value="'.pun_htmlspecialchars($cur_word['replace_with']).'" size="24" maxlength="60" /></td><td><input type="submit" name="update['.$cur_word['id'].']" value="'.$lang_admin_common['Update'].'" />&#160;<input type="submit" name="remove['.$cur_word['id'].']" value="'.$lang_admin_common['Remove'].'" /></td></tr>'."\n";
 129: 
 130: ?>
 131:                             </tbody>
 132:                             </table>
 133: <?php
 134: 
 135: }
 136: else
 137:     echo "\t\t\t\t\t\t\t".'<p>'.$lang_admin_censoring['No words in list'].'</p>'."\n";
 138: 
 139: ?>
 140:                         </div>
 141:                     </fieldset>
 142:                 </div>
 143:             </form>
 144:         </div>
 145:     </div>
 146:     <div class="clearer"></div>
 147: </div>
 148: <?php
 149: 
 150: require PUN_ROOT.'footer.php';


/dev/null b/admin_forums.php
   1: <?php
   2: 
   3: /**
   4:  * Copyright (C) 2008-2010 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:  */
   8: 
   9: // Tell header.php to use the admin template
  10: define('PUN_ADMIN_CONSOLE', 1);
  11: 
  12: define('PUN_ROOT', './');
  13: require PUN_ROOT.'include/common.php';
  14: require PUN_ROOT.'include/common_admin.php';
  15: 
  16: 
  17: if ($pun_user['g_id'] != PUN_ADMIN)
  18:     message($lang_common['No permission']);
  19: 
  20: // Load the admin_forums.php language file
  21: require PUN_ROOT.'lang/'.$admin_language.'/admin_forums.php';
  22: 
  23: // Add a "default" forum
  24: if (isset($_POST['add_forum']))
  25: {
  26:     confirm_referrer('admin_forums.php');
  27: 
  28:     $add_to_cat = intval($_POST['add_to_cat']);
  29:     if ($add_to_cat < 1)
  30:         message($lang_common['Bad request']);
  31: 
  32:     $db->query('INSERT INTO '.$db->prefix.'forums (cat_id) VALUES('.$add_to_cat.')') or error('Unable to create forum', __FILE__, __LINE__, $db->error());
  33: 
  34:     // Regenerate the quick jump cache
  35:     if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
  36:         require PUN_ROOT.'include/cache.php';
  37: 
  38:     generate_quickjump_cache();
  39: 
  40:     redirect('admin_forums.php', $lang_admin_forums['Forum added redirect']);
  41: }
  42: 
  43: // Delete a forum
  44: else if (isset($_GET['del_forum']))
  45: {
  46:     confirm_referrer('admin_forums.php');
  47: 
  48:     $forum_id = intval($_GET['del_forum']);
  49:     if ($forum_id < 1)
  50:         message($lang_common['Bad request']);
  51: 
  52:     if (isset($_POST['del_forum_comply'])) // Delete a forum with all posts
  53:     {
  54:         @set_time_limit(0);
  55: 
  56:         // Prune all posts and topics
  57:         prune($forum_id, 1, -1);
  58: 
  59:         // Locate any "orphaned redirect topics" and delete them
  60:         $result = $db->query('SELECT t1.id FROM '.$db->prefix.'topics AS t1 LEFT JOIN '.$db->prefix.'topics AS t2 ON t1.moved_to=t2.id WHERE t2.id IS NULL AND t1.moved_to IS NOT NULL') or error('Unable to fetch redirect topics', __FILE__, __LINE__, $db->error());
  61:         $num_orphans = $db->num_rows($result);
  62: 
  63:         if ($num_orphans)
  64:         {
  65:             for ($i = 0; $i < $num_orphans; ++$i)
  66:                 $orphans[] = $db->result($result, $i);
  67: 
  68:             $db->query('DELETE FROM '.$db->prefix.'topics WHERE id IN('.implode(',', $orphans).')') or error('Unable to delete redirect topics', __FILE__, __LINE__, $db->error());
  69:         }
  70: 
  71:         // Delete the forum and any forum specific group permissions
  72:         $db->query('DELETE FROM '.$db->prefix.'forums WHERE id='.$forum_id) or error('Unable to delete forum', __FILE__, __LINE__, $db->error());
  73:         $db->query('DELETE FROM '.$db->prefix.'forum_perms WHERE forum_id='.$forum_id) or error('Unable to delete group forum permissions', __FILE__, __LINE__, $db->error());
  74: 
  75:         // Regenerate the quick jump cache
  76:         if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
  77:             require PUN_ROOT.'include/cache.php';
  78: 
  79:         generate_quickjump_cache();
  80: 
  81:         redirect('admin_forums.php', $lang_admin_forums['Forum deleted redirect']);
  82:     }
  83:     else // If the user hasn't confirmed the delete
  84:     {
  85:         $result = $db->query('SELECT forum_name FROM '.$db->prefix.'forums WHERE id='.$forum_id) or error('Unable to fetch forum info', __FILE__, __LINE__, $db->error());
  86:         $forum_name = pun_htmlspecialchars($db->result($result));
  87: 
  88:         $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_admin_common['Admin'], $lang_admin_common['Forums']);
  89:         define('PUN_ACTIVE_PAGE', 'admin');
  90:         require PUN_ROOT.'header.php';
  91: 
  92:         generate_admin_menu('forums');
  93: 
  94: ?>
  95:     <div class="blockform">
  96:         <h2><span><?php echo $lang_admin_forums['Confirm delete head'] ?></span></h2>
  97:         <div class="box">
  98:             <form method="post" action="admin_forums.php?del_forum=<?php echo $forum_id ?>">
  99:                 <div class="inform">
 100:                     <fieldset>
 101:                         <legend><?php echo $lang_admin_forums['Confirm delete subhead'] ?></legend>
 102:                         <div class="infldset">
 103:                             <p><?php printf($lang_admin_forums['Confirm delete info'], $forum_name) ?></p>
 104:                             <p class="warntext"><?php echo $lang_admin_forums['Confirm delete warn'] ?></p>
 105:                         </div>
 106:                     </fieldset>
 107:                 </div>
 108:                 <p class="buttons"><input type="submit" name="del_forum_comply" value="<?php echo $lang_admin_common['Delete'] ?>" /><a href="javascript:history.go(-1)"><?php echo $lang_admin_common['Go back'] ?></a></p>
 109:             </form>
 110:         </div>
 111:     </div>
 112:     <div class="clearer"></div>
 113: </div>
 114: <?php
 115: 
 116:         require PUN_ROOT.'footer.php';
 117:     }
 118: }
 119: 
 120: // Update forum positions
 121: else if (isset($_POST['update_positions']))
 122: {
 123:     confirm_referrer('admin_forums.php');
 124: 
 125:     foreach ($_POST['position'] as $forum_id => $disp_position)
 126:     {
 127:         $disp_position = trim($disp_position);
 128:         if ($disp_position == '' || preg_match('/[^0-9]/', $disp_position))
 129:             message($lang_admin_forums['Must be integer message']);
 130: 
 131:         $db->query('UPDATE '.$db->prefix.'forums SET disp_position='.$disp_position.' WHERE id='.intval($forum_id)) or error('Unable to update forum', __FILE__, __LINE__, $db->error());
 132:     }
 133: 
 134:     // Regenerate the quick jump cache
 135:     if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
 136:         require PUN_ROOT.'include/cache.php';
 137: 
 138:     generate_quickjump_cache();
 139: 
 140:     redirect('admin_forums.php', $lang_admin_forums['Forums updated redirect']);
 141: }
 142: 
 143: else if (isset($_GET['edit_forum']))
 144: {
 145:     $forum_id = intval($_GET['edit_forum']);
 146:     if ($forum_id < 1)
 147:         message($lang_common['Bad request']);
 148: 
 149:     // Update group permissions for $forum_id
 150:     if (isset($_POST['save']))
 151:     {
 152:         confirm_referrer('admin_forums.php');
 153: 
 154:         // Start with the forum details
 155:         $forum_name = pun_trim($_POST['forum_name']);
 156:         $forum_desc = pun_linebreaks(pun_trim($_POST['forum_desc']));
 157:         $cat_id = intval($_POST['cat_id']);
 158:         $sort_by = intval($_POST['sort_by']);
 159:         $redirect_url = isset($_POST['redirect_url']) ? trim($_POST['redirect_url']) : null;
 160: 
 161:         if ($forum_name == '')
 162:             message($lang_admin_forums['Must enter name message']);
 163: 
 164:         if ($cat_id < 1)
 165:             message($lang_common['Bad request']);
 166: 
 167:         $forum_desc = ($forum_desc != '') ? '\''.$db->escape($forum_desc).'\'' : 'NULL';
 168:         $redirect_url = ($redirect_url != '') ? '\''.$db->escape($redirect_url).'\'' : 'NULL';
 169: 
 170:         $db->query('UPDATE '.$db->prefix.'forums SET forum_name=\''.$db->escape($forum_name).'\', forum_desc='.$forum_desc.', redirect_url='.$redirect_url.', sort_by='.$sort_by.', cat_id='.$cat_id.' WHERE id='.$forum_id) or error('Unable to update forum', __FILE__, __LINE__, $db->error());
 171: 
 172:         // Now let's deal with the permissions
 173:         if (isset($_POST['read_forum_old']))
 174:         {
 175:             $result = $db->query('SELECT g_id, g_read_board, g_post_replies, g_post_topics FROM '.$db->prefix.'groups WHERE g_id!='.PUN_ADMIN) or error('Unable to fetch user group list', __FILE__, __LINE__, $db->error());
 176:             while ($cur_group = $db->fetch_assoc($result))
 177:             {
 178:                 $read_forum_new = ($cur_group['g_read_board'] == '1') ? isset($_POST['read_forum_new'][$cur_group['g_id']]) ? '1' : '0' : intval($_POST['read_forum_old'][$cur_group['g_id']]);
 179:                 $post_replies_new = isset($_POST['post_replies_new'][$cur_group['g_id']]) ? '1' : '0';
 180:                 $post_topics_new = isset($_POST['post_topics_new'][$cur_group['g_id']]) ? '1' : '0';
 181: 
 182:                 // Check if the new settings differ from the old
 183:                 if ($read_forum_new != $_POST['read_forum_old'][$cur_group['g_id']] || $post_replies_new != $_POST['post_replies_old'][$cur_group['g_id']] || $post_topics_new != $_POST['post_topics_old'][$cur_group['g_id']])
 184:                 {
 185:                     // If the new settings are identical to the default settings for this group, delete it's row in forum_perms
 186:                     if ($read_forum_new == '1' && $post_replies_new == $cur_group['g_post_replies'] && $post_topics_new == $cur_group['g_post_topics'])
 187:                         $db->query('DELETE FROM '.$db->prefix.'forum_perms WHERE group_id='.$cur_group['g_id'].' AND forum_id='.$forum_id) or error('Unable to delete group forum permissions', __FILE__, __LINE__, $db->error());
 188:                     else
 189:                     {
 190:                         // Run an UPDATE and see if it affected a row, if not, INSERT
 191:                         $db->query('UPDATE '.$db->prefix.'forum_perms SET read_forum='.$read_forum_new.', post_replies='.$post_replies_new.', post_topics='.$post_topics_new.' WHERE group_id='.$cur_group['g_id'].' AND forum_id='.$forum_id) or error('Unable to insert group forum permissions', __FILE__, __LINE__, $db->error());
 192:                         if (!$db->affected_rows())
 193:                             $db->query('INSERT INTO '.$db->prefix.'forum_perms (group_id, forum_id, read_forum, post_replies, post_topics) VALUES('.$cur_group['g_id'].', '.$forum_id.', '.$read_forum_new.', '.$post_replies_new.', '.$post_topics_new.')') or error('Unable to insert group forum permissions', __FILE__, __LINE__, $db->error());
 194:                     }
 195:                 }
 196:             }
 197:         }
 198: 
 199:         // Regenerate the quick jump cache
 200:         if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
 201:             require PUN_ROOT.'include/cache.php';
 202: 
 203:         generate_quickjump_cache();
 204: 
 205:         redirect('admin_forums.php', $lang_admin_forums['Forum updated redirect']);
 206:     }
 207:     else if (isset($_POST['revert_perms']))
 208:     {
 209:         confirm_referrer('admin_forums.php');
 210: 
 211:         $db->query('DELETE FROM '.$db->prefix.'forum_perms WHERE forum_id='.$forum_id) or error('Unable to delete group forum permissions', __FILE__, __LINE__, $db->error());
 212: 
 213:         // Regenerate the quick jump cache
 214:         if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
 215:             require PUN_ROOT.'include/cache.php';
 216: 
 217:         generate_quickjump_cache();
 218: 
 219:         redirect('admin_forums.php?edit_forum='.$forum_id, $lang_admin_forums['Perms reverted redirect']);
 220:     }
 221: 
 222:     // Fetch forum info
 223:     $result = $db->query('SELECT id, forum_name, forum_desc, redirect_url, num_topics, sort_by, cat_id FROM '.$db->prefix.'forums WHERE id='.$forum_id) or error('Unable to fetch forum info', __FILE__, __LINE__, $db->error());
 224:     if (!$db->num_rows($result))
 225:         message($lang_common['Bad request']);
 226: 
 227:     $cur_forum = $db->fetch_assoc($result);
 228: 
 229:     $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_admin_common['Admin'], $lang_admin_common['Forums']);
 230:     define('PUN_ACTIVE_PAGE', 'admin');
 231:     require PUN_ROOT.'header.php';
 232: 
 233:     generate_admin_menu('forums');
 234: 
 235: ?>
 236:     <div class="blockform">
 237:         <h2><span><?php echo $lang_admin_forums['Edit forum head'] ?></span></h2>
 238:         <div class="box">
 239:             <form id="edit_forum" method="post" action="admin_forums.php?edit_forum=<?php echo $forum_id ?>">
 240:                 <p class="submittop"><input type="submit" name="save" value="<?php echo $lang_admin_common['Save changes'] ?>" tabindex="6" /></p>
 241:                 <div class="inform">
 242:                     <fieldset>
 243:                         <legend><?php echo $lang_admin_forums['Edit details subhead'] ?></legend>
 244:                         <div class="infldset">
 245:                             <table class="aligntop" cellspacing="0">
 246:                                 <tr>
 247:                                     <th scope="row"><?php echo $lang_admin_forums['Forum name label'] ?></th>
 248:                                     <td><input type="text" name="forum_name" size="35" maxlength="80" value="<?php echo pun_htmlspecialchars($cur_forum['forum_name']) ?>" tabindex="1" /></td>
 249:                                 </tr>
 250:                                 <tr>
 251:                                     <th scope="row"><?php echo $lang_admin_forums['Forum description label'] ?></th>
 252:                                     <td><textarea name="forum_desc" rows="3" cols="50" tabindex="2"><?php echo pun_htmlspecialchars($cur_forum['forum_desc']) ?></textarea></td>
 253:                                 </tr>
 254:                                 <tr>
 255:                                     <th scope="row"><?php echo $lang_admin_forums['Category label'] ?></th>
 256:                                     <td>
 257:                                         <select name="cat_id" tabindex="3">
 258: <?php
 259: 
 260:     $result = $db->query('SELECT id, cat_name FROM '.$db->prefix.'categories ORDER BY disp_position') or error('Unable to fetch category list', __FILE__, __LINE__, $db->error());
 261:     while ($cur_cat = $db->fetch_assoc($result))
 262:     {
 263:         $selected = ($cur_cat['id'] == $cur_forum['cat_id']) ? ' selected="selected"' : '';
 264:         echo "\t\t\t\t\t\t\t\t\t\t\t".'<option value="'.$cur_cat['id'].'"'.$selected.'>'.pun_htmlspecialchars($cur_cat['cat_name']).'</option>'."\n";
 265:     }
 266: 
 267: ?>
 268:                                         </select>
 269:                                     </td>
 270:                                 </tr>
 271:                                 <tr>
 272:                                     <th scope="row"><?php echo $lang_admin_forums['Sort by label'] ?></th>
 273:                                     <td>
 274:                                         <select name="sort_by" tabindex="4">
 275:                                             <option value="0"<?php if ($cur_forum['sort_by'] == '0') echo ' selected="selected"' ?>><?php echo $lang_admin_forums['Last post'] ?></option>
 276:                                             <option value="1"<?php if ($cur_forum['sort_by'] == '1') echo ' selected="selected"' ?>><?php echo $lang_admin_forums['Topic start'] ?></option>
 277:                                         </select>
 278:                                     </td>
 279:                                 </tr>
 280:                                 <tr>
 281:                                     <th scope="row"><?php echo $lang_admin_forums['Redirect label'] ?></th>
 282:                                     <td><?php echo ($cur_forum['num_topics']) ? $lang_admin_forums['Redirect help'] : '<input type="text" name="redirect_url" size="45" maxlength="100" value="'.pun_htmlspecialchars($cur_forum['redirect_url']).'" tabindex="5" />'; ?></td>
 283:                                 </tr>
 284:                             </table>
 285:                         </div>
 286:                     </fieldset>
 287:                 </div>
 288:                 <div class="inform">
 289:                     <fieldset>
 290:                         <legend><?php echo $lang_admin_forums['Group permissions subhead'] ?></legend>
 291:                         <div class="infldset">
 292:                             <p><?php printf($lang_admin_forums['Group permissions info'], '<a href="admin_groups.php">'.$lang_admin_common['User groups'].'</a>') ?></p>
 293:                             <table id="forumperms" cellspacing="0">
 294:                             <thead>
 295:                                 <tr>
 296:                                     <th class="atcl">&#160;</th>
 297:                                     <th><?php echo $lang_admin_forums['Read forum label'] ?></th>
 298:                                     <th><?php echo $lang_admin_forums['Post replies label'] ?></th>
 299:                                     <th><?php echo $lang_admin_forums['Post topics label'] ?></th>
 300:                                 </tr>
 301:                             </thead>
 302:                             <tbody>
 303: <?php
 304: 
 305:     $result = $db->query('SELECT g.g_id, g.g_title, g.g_read_board, g.g_post_replies, g.g_post_topics, fp.read_forum, fp.post_replies, fp.post_topics FROM '.$db->prefix.'groups AS g LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (g.g_id=fp.group_id AND fp.forum_id='.$forum_id.') WHERE g.g_id!='.PUN_ADMIN.' ORDER BY g.g_id') or error('Unable to fetch group forum permission list', __FILE__, __LINE__, $db->error());
 306: 
 307:     while ($cur_perm = $db->fetch_assoc($result))
 308:     {
 309:         $read_forum = ($cur_perm['read_forum'] != '0') ? true : false;
 310:         $post_replies = (($cur_perm['g_post_replies'] == '0' && $cur_perm['post_replies'] == '1') || ($cur_perm['g_post_replies'] == '1' && $cur_perm['post_replies'] != '0')) ? true : false;
 311:         $post_topics = (($cur_perm['g_post_topics'] == '0' && $cur_perm['post_topics'] == '1') || ($cur_perm['g_post_topics'] == '1' && $cur_perm['post_topics'] != '0')) ? true : false;
 312: 
 313:         // Determine if the current settings differ from the default or not
 314:         $read_forum_def = ($cur_perm['read_forum'] == '0') ? false : true;
 315:         $post_replies_def = (($post_replies && $cur_perm['g_post_replies'] == '0') || (!$post_replies && ($cur_perm['g_post_replies'] == '' || $cur_perm['g_post_replies'] == '1'))) ? false : true;
 316:         $post_topics_def = (($post_topics && $cur_perm['g_post_topics'] == '0') || (!$post_topics && ($cur_perm['g_post_topics'] == '' || $cur_perm['g_post_topics'] == '1'))) ? false : true;
 317: 
 318: ?>
 319:                                 <tr>
 320:                                     <th class="atcl"><?php echo pun_htmlspecialchars($cur_perm['g_title']) ?></th>
 321:                                     <td<?php if (!$read_forum_def) echo ' class="nodefault"'; ?>>
 322:                                         <input type="hidden" name="read_forum_old[<?php echo $cur_perm['g_id'] ?>]" value="<?php echo ($read_forum) ? '1' : '0'; ?>" />
 323:                                         <input type="checkbox" name="read_forum_new[<?php echo $cur_perm['g_id'] ?>]" value="1"<?php echo ($read_forum) ? ' checked="checked"' : ''; ?><?php echo ($cur_perm['g_read_board'] == '0') ? ' disabled="disabled"' : ''; ?> />
 324:                                     </td>
 325:                                     <td<?php if (!$post_replies_def && $cur_forum['redirect_url'] == '') echo ' class="nodefault"'; ?>>
 326:                                         <input type="hidden" name="post_replies_old[<?php echo $cur_perm['g_id'] ?>]" value="<?php echo ($post_replies) ? '1' : '0'; ?>" />
 327:                                         <input type="checkbox" name="post_replies_new[<?php echo $cur_perm['g_id'] ?>]" value="1"<?php echo ($post_replies) ? ' checked="checked"' : ''; ?><?php echo ($cur_forum['redirect_url'] != '') ? ' disabled="disabled"' : ''; ?> />
 328:                                     </td>
 329:                                     <td<?php if (!$post_topics_def && $cur_forum['redirect_url'] == '') echo ' class="nodefault"'; ?>>
 330:                                         <input type="hidden" name="post_topics_old[<?php echo $cur_perm['g_id'] ?>]" value="<?php echo ($post_topics) ? '1' : '0'; ?>" />
 331:                                         <input type="checkbox" name="post_topics_new[<?php echo $cur_perm['g_id'] ?>]" value="1"<?php echo ($post_topics) ? ' checked="checked"' : ''; ?><?php echo ($cur_forum['redirect_url'] != '') ? ' disabled="disabled"' : ''; ?> />
 332:                                     </td>
 333:                                 </tr>
 334: <?php
 335: 
 336:     }
 337: 
 338: ?>
 339:                             </tbody>
 340:                             </table>
 341:                             <div class="fsetsubmit"><input type="submit" name="revert_perms" value="<?php echo $lang_admin_forums['Revert to default'] ?>" /></div>
 342:                         </div>
 343:                     </fieldset>
 344:                 </div>
 345:                 <p class="submitend"><input type="submit" name="save" value="<?php echo $lang_admin_common['Save changes'] ?>" /></p>
 346:             </form>
 347:         </div>
 348:     </div>
 349:     <div class="clearer"></div>
 350: </div>
 351: 
 352: <?php
 353: 
 354:     require PUN_ROOT.'footer.php';
 355: }
 356: 
 357: $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_admin_common['Admin'], $lang_admin_common['Forums']);
 358: define('PUN_ACTIVE_PAGE', 'admin');
 359: require PUN_ROOT.'header.php';
 360: 
 361: generate_admin_menu('forums');
 362: 
 363: ?>
 364:     <div class="blockform">
 365:         <h2><span><?php echo $lang_admin_forums['Add forum head'] ?></span></h2>
 366:         <div class="box">
 367:             <form method="post" action="admin_forums.php?action=adddel">
 368:                 <div class="inform">
 369:                     <fieldset>
 370:                         <legend><?php echo $lang_admin_forums['Create new subhead'] ?></legend>
 371:                         <div class="infldset">
 372:                             <table class="aligntop" cellspacing="0">
 373:                                 <tr>
 374:                                     <th scope="row"><?php echo $lang_admin_forums['Add forum label'] ?><div><input type="submit" name="add_forum" value="<?php echo $lang_admin_forums['Add forum'] ?>" tabindex="2" /></div></th>
 375:                                     <td>
 376:                                         <select name="add_to_cat" tabindex="1">
 377: <?php
 378: 
 379:     $result = $db->query('SELECT id, cat_name FROM '.$db->prefix.'categories ORDER BY disp_position') or error('Unable to fetch category list', __FILE__, __LINE__, $db->error());
 380:     if ($db->num_rows($result) > 0)
 381:     {
 382:         while ($cur_cat = $db->fetch_assoc($result))
 383:             echo "\t\t\t\t\t\t\t\t\t\t\t".'<option value="'.$cur_cat['id'].'">'.pun_htmlspecialchars($cur_cat['cat_name']).'</option>'."\n";
 384:     }
 385:     else
 386:         echo "\t\t\t\t\t\t\t\t\t\t\t".'<option value="0" disabled="disabled">'.$lang_admin_forums['No categories exist'].'</option>'."\n";
 387: 
 388: ?>
 389:                                         </select>
 390:                                         <span><?php echo $lang_admin_forums['Add forum help'] ?></span>
 391:                                     </td>
 392:                                 </tr>
 393:                             </table>
 394:                         </div>
 395:                     </fieldset>
 396:                 </div>
 397:             </form>
 398:         </div>
 399: <?php
 400: 
 401: // Display all the categories and forums
 402: $result = $db->query('SELECT c.id AS cid, c.cat_name, f.id AS fid, f.forum_name, f.disp_position FROM '.$db->prefix.'categories AS c INNER JOIN '.$db->prefix.'forums AS f ON c.id=f.cat_id ORDER BY c.disp_position, c.id, f.disp_position') or error('Unable to fetch category/forum list', __FILE__, __LINE__, $db->error());
 403: 
 404: if ($db->num_rows($result) > 0)
 405: {
 406: 
 407: ?>
 408:         <h2 class="block2"><span><?php echo $lang_admin_forums['Edit forums head'] ?></span></h2>
 409:         <div class="box">
 410:             <form id="edforum" method="post" action="admin_forums.php?action=edit">
 411:                 <p class="submittop"><input type="submit" name="update_positions" value="<?php echo $lang_admin_forums['Update positions'] ?>" tabindex="3" /></p>
 412: <?php
 413: 
 414: $tabindex_count = 4;
 415: 
 416: $cur_category = 0;
 417: while ($cur_forum = $db->fetch_assoc($result))
 418: {
 419:     if ($cur_forum['cid'] != $cur_category) // A new category since last iteration?
 420:     {
 421:         if ($cur_category != 0)
 422:             echo "\t\t\t\t\t\t\t".'</tbody>'."\n\t\t\t\t\t\t\t".'</table>'."\n\t\t\t\t\t\t".'</div>'."\n\t\t\t\t\t".'</fieldset>'."\n\t\t\t\t".'</div>'."\n";
 423: 
 424: ?>
 425:                 <div class="inform">
 426:                     <fieldset>
 427:                         <legend><?php echo $lang_admin_forums['Category subhead'] ?> <?php echo pun_htmlspecialchars($cur_forum['cat_name']) ?></legend>
 428:                         <div class="infldset">
 429:                             <table cellspacing="0">
 430:                             <thead>
 431:                                 <tr>
 432:                                     <th class="tcl"><?php echo $lang_admin_common['Action'] ?></th>
 433:                                     <th class="tc2"><?php echo $lang_admin_forums['Position label'] ?></th>
 434:                                     <th class="tcr"><?php echo $lang_admin_forums['Forum label'] ?></th>
 435:                                 </tr>
 436:                             </thead>
 437:                             <tbody>
 438: <?php
 439: 
 440:         $cur_category = $cur_forum['cid'];
 441:     }
 442: 
 443: ?>
 444:                                 <tr>
 445:                                     <td class="tcl"><a href="admin_forums.php?edit_forum=<?php echo $cur_forum['fid'] ?>"><?php echo $lang_admin_forums['Edit link'] ?></a> | <a href="admin_forums.php?del_forum=<?php echo $cur_forum['fid'] ?>"><?php echo $lang_admin_forums['Delete link'] ?></a></td>
 446:                                     <td class="tc2"><input type="text" name="position[<?php echo $cur_forum['fid'] ?>]" size="3" maxlength="3" value="<?php echo $cur_forum['disp_position'] ?>" tabindex="<?php echo $tabindex_count ?>" /></td>
 447:                                     <td class="tcr"><strong><?php echo pun_htmlspecialchars($cur_forum['forum_name']) ?></strong></td>
 448:                                 </tr>
 449: <?php
 450: 
 451:     $tabindex_count += 2;
 452: }
 453: 
 454: ?>
 455:                             </tbody>
 456:                             </table>
 457:                         </div>
 458:                     </fieldset>
 459:                 </div>
 460:                 <p class="submitend"><input type="submit" name="update_positions" value="<?php echo $lang_admin_forums['Update positions'] ?>" tabindex="<?php echo $tabindex_count ?>" /></p>
 461:             </form>
 462:         </div>
 463: <?php
 464: 
 465: }
 466: 
 467: ?>
 468:     </div>
 469:     <div class="clearer"></div>
 470: </div>
 471: <?php
 472: 
 473: require PUN_ROOT.'footer.php';


/dev/null b/admin_groups.php
   1: <?php
   2: 
   3: /**
   4:  * Copyright (C) 2008-2010 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:  */
   8: 
   9: // Tell header.php to use the admin template
  10: define('PUN_ADMIN_CONSOLE', 1);
  11: 
  12: define('PUN_ROOT', './');
  13: require PUN_ROOT.'include/common.php';
  14: require PUN_ROOT.'include/common_admin.php';
  15: 
  16: 
  17: if ($pun_user['g_id'] != PUN_ADMIN)
  18:     message($lang_common['No permission']);
  19: 
  20: // Load the admin_censoring.php language file
  21: require PUN_ROOT.'lang/'.$admin_language.'/admin_groups.php';
  22: 
  23: // Add/edit a group (stage 1)
  24: if (isset($_POST['add_group']) || isset($_GET['edit_group']))
  25: {
  26:     if (isset($_POST['add_group']))
  27:     {
  28:         $base_group = intval($_POST['base_group']);
  29: 
  30:         $result = $db->query('SELECT * FROM '.$db->prefix.'groups WHERE g_id='.$base_group) or error('Unable to fetch user group info', __FILE__, __LINE__, $db->error());
  31:         $group = $db->fetch_assoc($result);
  32: 
  33:         $mode = 'add';
  34:     }
  35:     else // We are editing a group
  36:     {
  37:         $group_id = intval($_GET['edit_group']);
  38:         if ($group_id < 1)
  39:             message($lang_common['Bad request']);
  40: 
  41:         $result = $db->query('SELECT * FROM '.$db->prefix.'groups WHERE g_id='.$group_id) or error('Unable to fetch user group info', __FILE__, __LINE__, $db->error());
  42:         if (!$db->num_rows($result))
  43:             message($lang_common['Bad request']);
  44: 
  45:         $group = $db->fetch_assoc($result);
  46: 
  47:         $mode = 'edit';
  48:     }
  49: 
  50: 
  51:     $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_admin_common['Admin'], $lang_admin_common['User groups']);
  52:     $required_fields = array('req_title' => $lang_admin_groups['Group title label']);
  53:     $focus_element = array('groups2', 'req_title');
  54:     define('PUN_ACTIVE_PAGE', 'admin');
  55:     require PUN_ROOT.'header.php';
  56: 
  57:     generate_admin_menu('groups');
  58: 
  59: ?>
  60:     <div class="blockform">
  61:         <h2><span><?php echo $lang_admin_groups['Group settings head'] ?></span></h2>
  62:         <div class="box">
  63:             <form id="groups2" method="post" action="admin_groups.php" onsubmit="return process_form(this)">
  64:                 <p class="submittop"><input type="submit" name="add_edit_group" value="<?php echo $lang_admin_common['Save'] ?>" /></p>
  65:                 <div class="inform">
  66:                     <input type="hidden" name="mode" value="<?php echo $mode ?>" />
  67: <?php if ($mode == 'edit'): ?>                    <input type="hidden" name="group_id" value="<?php echo $group_id ?>" />
  68: <?php endif; ?><?php if ($mode == 'add'): ?>                    <input type="hidden" name="base_group" value="<?php echo $base_group ?>" />
  69: <?php endif; ?>                    <fieldset>
  70:                         <legend><?php echo $lang_admin_groups['Group settings subhead'] ?></legend>
  71:                         <div class="infldset">
  72:                             <p><?php echo $lang_admin_groups['Group settings info'] ?></p>
  73:                             <table class="aligntop" cellspacing="0">
  74:                                 <tr>
  75:                                     <th scope="row"><?php echo $lang_admin_groups['Group title label'] ?></th>
  76:                                     <td>
  77:                                         <input type="text" name="req_title" size="25" maxlength="50" value="<?php if ($mode == 'edit') echo pun_htmlspecialchars($group['g_title']); ?>" tabindex="1" />
  78:                                     </td>
  79:                                 </tr>
  80:                                 <tr>
  81:                                     <th scope="row"><?php echo $lang_admin_groups['User title label'] ?></th>
  82:                                     <td>
  83:                                         <input type="text" name="user_title" size="25" maxlength="50" value="<?php echo pun_htmlspecialchars($group['g_user_title']) ?>" tabindex="2" />
  84:                                         <span><?php echo $lang_admin_groups['User title help'] ?></span>
  85:                                     </td>
  86:                                 </tr>
  87: <?php if ($group['g_id'] != PUN_ADMIN): if ($group['g_id'] != PUN_GUEST): if ($mode != 'edit' || $pun_config['o_default_user_group'] != $group['g_id']): ?>                                <tr>
  88:                                     <th scope="row"> <?php echo $lang_admin_groups['Mod privileges label'] ?></th>
  89:                                     <td>
  90:                                         <input type="radio" name="moderator" value="1"<?php if ($group['g_moderator'] == '1') echo ' checked="checked"' ?> tabindex="3" />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="moderator" value="0"<?php if ($group['g_moderator'] == '0') echo ' checked="checked"' ?> tabindex="4" />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
  91:                                         <span><?php echo $lang_admin_groups['Mod privileges help'] ?></span>
  92:                                     </td>
  93:                                 </tr>
  94:                                 <tr>
  95:                                     <th scope="row"><?php echo $lang_admin_groups['Edit profile label'] ?></th>
  96:                                     <td>
  97:                                         <input type="radio" name="mod_edit_users" value="1"<?php if ($group['g_mod_edit_users'] == '1') echo ' checked="checked"' ?> tabindex="5" />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="mod_edit_users" value="0"<?php if ($group['g_mod_edit_users'] == '0') echo ' checked="checked"' ?> tabindex="6" />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
  98:                                         <span><?php echo $lang_admin_groups['Edit profile help'] ?></span>
  99:                                     </td>
 100:                                 </tr>
 101:                                 <tr>
 102:                                     <th scope="row"><?php echo $lang_admin_groups['Rename users label'] ?></th>
 103:                                     <td>
 104:                                         <input type="radio" name="mod_rename_users" value="1"<?php if ($group['g_mod_rename_users'] == '1') echo ' checked="checked"' ?> tabindex="5" />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="mod_rename_users" value="0"<?php if ($group['g_mod_rename_users'] == '0') echo ' checked="checked"' ?> tabindex="6" />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
 105:                                         <span><?php echo $lang_admin_groups['Rename users help'] ?></span>
 106:                                     </td>
 107:                                 </tr>
 108:                                 <tr>
 109:                                     <th scope="row"><?php echo $lang_admin_groups['Change passwords label'] ?></th>
 110:                                     <td>
 111:                                         <input type="radio" name="mod_change_passwords" value="1"<?php if ($group['g_mod_change_passwords'] == '1') echo ' checked="checked"' ?> tabindex="5" />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="mod_change_passwords" value="0"<?php if ($group['g_mod_change_passwords'] == '0') echo ' checked="checked"' ?> tabindex="6" />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
 112:                                         <span><?php echo $lang_admin_groups['Change passwords help'] ?></span>
 113:                                     </td>
 114:                                 </tr>
 115:                                 <tr>
 116:                                     <th scope="row"><?php echo $lang_admin_groups['Ban users label'] ?></th>
 117:                                     <td>
 118:                                         <input type="radio" name="mod_ban_users" value="1"<?php if ($group['g_mod_ban_users'] == '1') echo ' checked="checked"' ?> tabindex="5" />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="mod_ban_users" value="0"<?php if ($group['g_mod_ban_users'] == '0') echo ' checked="checked"' ?> tabindex="6" />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
 119:                                         <span><?php echo $lang_admin_groups['Ban users help'] ?></span>
 120:                                     </td>
 121:                                 </tr>
 122: <?php endif; endif; ?>                                <tr>
 123:                                     <th scope="row"><?php echo $lang_admin_groups['Read board label'] ?></th>
 124:                                     <td>
 125:                                         <input type="radio" name="read_board" value="1"<?php if ($group['g_read_board'] == '1') echo ' checked="checked"' ?> tabindex="3" />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="read_board" value="0"<?php if ($group['g_read_board'] == '0') echo ' checked="checked"' ?> tabindex="4" />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
 126:                                         <span><?php echo $lang_admin_groups['Read board help'] ?></span>
 127:                                     </td>
 128:                                 </tr>
 129:                                 <tr>
 130:                                     <th scope="row"><?php echo $lang_admin_groups['View user info label'] ?></th>
 131:                                     <td>
 132:                                         <input type="radio" name="view_users" value="1"<?php if ($group['g_view_users'] == '1') echo ' checked="checked"' ?> tabindex="3" />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="view_users" value="0"<?php if ($group['g_view_users'] == '0') echo ' checked="checked"' ?> tabindex="4" />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
 133:                                         <span><?php echo $lang_admin_groups['View user info help'] ?></span>
 134:                                     </td>
 135:                                 </tr>
 136:                                 <tr>
 137:                                     <th scope="row"><?php echo $lang_admin_groups['Post replies label'] ?></th>
 138:                                     <td>
 139:                                         <input type="radio" name="post_replies" value="1"<?php if ($group['g_post_replies'] == '1') echo ' checked="checked"' ?> tabindex="5" />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="post_replies" value="0"<?php if ($group['g_post_replies'] == '0') echo ' checked="checked"' ?> tabindex="6" />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
 140:                                         <span><?php echo $lang_admin_groups['Post replies help'] ?></span>
 141:                                     </td>
 142:                                 </tr>
 143:                                 <tr>
 144:                                     <th scope="row"><?php echo $lang_admin_groups['Post topics label'] ?></th>
 145:                                     <td>
 146:                                         <input type="radio" name="post_topics" value="1"<?php if ($group['g_post_topics'] == '1') echo ' checked="checked"' ?> tabindex="7" />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="post_topics" value="0"<?php if ($group['g_post_topics'] == '0') echo ' checked="checked"' ?> tabindex="8" />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
 147:                                         <span><?php echo $lang_admin_groups['Post topics help'] ?></span>
 148:                                     </td>
 149:                                 </tr>
 150: <?php if ($group['g_id'] != PUN_GUEST): ?>                                <tr>
 151:                                     <th scope="row"><?php echo $lang_admin_groups['Edit posts label'] ?></th>
 152:                                     <td>
 153:                                         <input type="radio" name="edit_posts" value="1"<?php if ($group['g_edit_posts'] == '1') echo ' checked="checked"' ?> tabindex="11" />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="edit_posts" value="0"<?php if ($group['g_edit_posts'] == '0') echo ' checked="checked"' ?> tabindex="12" />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
 154:                                         <span><?php echo $lang_admin_groups['Edit posts help'] ?></span>
 155:                                     </td>
 156:                                 </tr>
 157:                                 <tr>
 158:                                     <th scope="row"><?php echo $lang_admin_groups['Delete posts label'] ?></th>
 159:                                     <td>
 160:                                         <input type="radio" name="delete_posts" value="1"<?php if ($group['g_delete_posts'] == '1') echo ' checked="checked"' ?> tabindex="13" />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="delete_posts" value="0"<?php if ($group['g_delete_posts'] == '0') echo ' checked="checked"' ?> tabindex="14" />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
 161:                                         <span><?php echo $lang_admin_groups['Delete posts help'] ?></span>
 162:                                     </td>
 163:                                 </tr>
 164:                                 <tr>
 165:                                     <th scope="row"><?php echo $lang_admin_groups['Delete topics label'] ?></th>
 166:                                     <td>
 167:                                         <input type="radio" name="delete_topics" value="1"<?php if ($group['g_delete_topics'] == '1') echo ' checked="checked"' ?> tabindex="15" />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="delete_topics" value="0"<?php if ($group['g_delete_topics'] == '0') echo ' checked="checked"' ?> tabindex="16" />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
 168:                                         <span><?php echo $lang_admin_groups['Delete topics help'] ?></span>
 169:                                     </td>
 170:                                 </tr>
 171:                                 <tr>
 172:                                     <th scope="row"><?php echo $lang_admin_groups['Set own title label'] ?></th>
 173:                                     <td>
 174:                                         <input type="radio" name="set_title" value="1"<?php if ($group['g_set_title'] == '1') echo ' checked="checked"' ?> tabindex="17" />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="set_title" value="0"<?php if ($group['g_set_title'] == '0') echo ' checked="checked"' ?> tabindex="18" />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
 175:                                         <span><?php echo $lang_admin_groups['Set own title help'] ?></span>
 176:                                     </td>
 177:                                 </tr>
 178: <?php endif; ?>                                <tr>
 179:                                     <th scope="row"><?php echo $lang_admin_groups['User search label'] ?></th>
 180:                                     <td>
 181:                                         <input type="radio" name="search" value="1"<?php if ($group['g_search'] == '1') echo ' checked="checked"' ?> tabindex="19" />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="search" value="0"<?php if ($group['g_search'] == '0') echo ' checked="checked"' ?> tabindex="20" />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
 182:                                         <span><?php echo $lang_admin_groups['User search help'] ?></span>
 183:                                     </td>
 184:                                 </tr>
 185:                                 <tr>
 186:                                     <th scope="row"><?php echo $lang_admin_groups['User list search label'] ?></th>
 187:                                     <td>
 188:                                         <input type="radio" name="search_users" value="1"<?php if ($group['g_search_users'] == '1') echo ' checked="checked"' ?> tabindex="21" />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="search_users" value="0"<?php if ($group['g_search_users'] == '0') echo ' checked="checked"' ?> tabindex="22" />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
 189:                                         <span><?php echo $lang_admin_groups['User list search help'] ?></span>
 190:                                     </td>
 191:                                 </tr>
 192: <?php if ($group['g_id'] != PUN_GUEST): ?>                                <tr>
 193:                                     <th scope="row"><?php echo $lang_admin_groups['Send e-mails label'] ?></th>
 194:                                     <td>
 195:                                         <input type="radio" name="send_email" value="1"<?php if ($group['g_send_email'] == '1') echo ' checked="checked"' ?> tabindex="21" />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="send_email" value="0"<?php if ($group['g_send_email'] == '0') echo ' checked="checked"' ?> tabindex="22" />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
 196:                                         <span><?php echo $lang_admin_groups['Send e-mails help'] ?></span>
 197:                                     </td>
 198:                                 </tr>
 199: <?php endif; ?>                                <tr>
 200:                                     <th scope="row"><?php echo $lang_admin_groups['Post flood label'] ?></th>
 201:                                     <td>
 202:                                         <input type="text" name="post_flood" size="5" maxlength="4" value="<?php echo $group['g_post_flood'] ?>" tabindex="24" />
 203:                                         <span><?php echo $lang_admin_groups['Post flood help'] ?></span>
 204:                                     </td>
 205:                                 </tr>
 206:                                 <tr>
 207:                                     <th scope="row"><?php echo $lang_admin_groups['Search flood label'] ?></th>
 208:                                     <td>
 209:                                         <input type="text" name="search_flood" size="5" maxlength="4" value="<?php echo $group['g_search_flood'] ?>" tabindex="25" />
 210:                                         <span><?php echo $lang_admin_groups['Search flood help'] ?></span>
 211:                                     </td>
 212:                                 </tr>
 213: <?php if ($group['g_id'] != PUN_GUEST): ?>                                <tr>
 214:                                     <th scope="row"><?php echo $lang_admin_groups['E-mail flood label'] ?></th>
 215:                                     <td>
 216:                                         <input type="text" name="email_flood" size="5" maxlength="4" value="<?php echo $group['g_email_flood'] ?>" tabindex="26" />
 217:                                         <span><?php echo $lang_admin_groups['E-mail flood help'] ?></span>
 218:                                     </td>
 219:                                 </tr>
 220: <?php endif; endif; ?>                            </table>
 221: <?php if ($group['g_moderator'] == '1' ): ?>                            <p class="warntext"><?php echo $lang_admin_groups['Moderator info'] ?></p>
 222: <?php endif; ?>                        </div>
 223:                     </fieldset>
 224:                 </div>
 225:                 <p class="submitend"><input type="submit" name="add_edit_group" value="<?php echo $lang_admin_common['Save'] ?>" tabindex="26" /></p>
 226:             </form>
 227:         </div>
 228:     </div>
 229:     <div class="clearer"></div>
 230: </div>
 231: <?php
 232: 
 233:     require PUN_ROOT.'footer.php';
 234: }
 235: 
 236: 
 237: // Add/edit a group (stage 2)
 238: else if (isset($_POST['add_edit_group']))
 239: {
 240:     confirm_referrer('admin_groups.php');
 241: 
 242:     // Is this the admin group? (special rules apply)
 243:     $is_admin_group = (isset($_POST['group_id']) && $_POST['group_id'] == PUN_ADMIN) ? true : false;
 244: 
 245:     $title = pun_trim($_POST['req_title']);
 246:     $user_title = pun_trim($_POST['user_title']);
 247:     $moderator = isset($_POST['moderator']) && $_POST['moderator'] == '1' ? '1' : '0';
 248:     $mod_edit_users = $moderator == '1' && isset($_POST['mod_edit_users']) && $_POST['mod_edit_users'] == '1' ? '1' : '0';
 249:     $mod_rename_users = $moderator == '1' && isset($_POST['mod_rename_users']) && $_POST['mod_rename_users'] == '1' ? '1' : '0';
 250:     $mod_change_passwords = $moderator == '1' && isset($_POST['mod_change_passwords']) && $_POST['mod_change_passwords'] == '1' ? '1' : '0';
 251:     $mod_ban_users = $moderator == '1' && isset($_POST['mod_ban_users']) && $_POST['mod_ban_users'] == '1' ? '1' : '0';
 252:     $read_board = isset($_POST['read_board']) ? intval($_POST['read_board']) : '1';
 253:     $view_users = (isset($_POST['view_users']) && $_POST['view_users'] == '1') || $is_admin_group ? '1' : '0';
 254:     $post_replies = isset($_POST['post_replies']) ? intval($_POST['post_replies']) : '1';
 255:     $post_topics = isset($_POST['post_topics']) ? intval($_POST['post_topics']) : '1';
 256:     $edit_posts = isset($_POST['edit_posts']) ? intval($_POST['edit_posts']) : ($is_admin_group) ? '1' : '0';
 257:     $delete_posts = isset($_POST['delete_posts']) ? intval($_POST['delete_posts']) : ($is_admin_group) ? '1' : '0';
 258:     $delete_topics = isset($_POST['delete_topics']) ? intval($_POST['delete_topics']) : ($is_admin_group) ? '1' : '0';
 259:     $set_title = isset($_POST['set_title']) ? intval($_POST['set_title']) : ($is_admin_group) ? '1' : '0';
 260:     $search = isset($_POST['search']) ? intval($_POST['search']) : '1';
 261:     $search_users = isset($_POST['search_users']) ? intval($_POST['search_users']) : '1';
 262:     $send_email = (isset($_POST['send_email']) && $_POST['send_email'] == '1') || $is_admin_group ? '1' : '0';
 263:     $post_flood = isset($_POST['post_flood']) ? intval($_POST['post_flood']) : '0';
 264:     $search_flood = isset($_POST['search_flood']) ? intval($_POST['search_flood']) : '0';
 265:     $email_flood = isset($_POST['email_flood']) ? intval($_POST['email_flood']) : '0';
 266: 
 267:     if ($title == '')
 268:         message($lang_admin_groups['Must enter title message']);
 269: 
 270:     $user_title = ($user_title != '') ? '\''.$db->escape($user_title).'\'' : 'NULL';
 271: 
 272:     if ($_POST['mode'] == 'add')
 273:     {
 274:         $result = $db->query('SELECT 1 FROM '.$db->prefix.'groups WHERE g_title=\''.$db->escape($title).'\'') or error('Unable to check group title collision', __FILE__, __LINE__, $db->error());
 275:         if ($db->num_rows($result))
 276:             message(sprintf($lang_admin_groups['Title already exists message'], pun_htmlspecialchars($title)));
 277: 
 278:         $db->query('INSERT INTO '.$db->prefix.'groups (g_title, g_user_title, g_moderator, g_mod_edit_users, g_mod_rename_users, g_mod_change_passwords, g_mod_ban_users, g_read_board, g_view_users, g_post_replies, g_post_topics, g_edit_posts, g_delete_posts, g_delete_topics, g_set_title, g_search, g_search_users, g_send_email, g_post_flood, g_search_flood, g_email_flood) VALUES(\''.$db->escape($title).'\', '.$user_title.', '.$moderator.', '.$mod_edit_users.', '.$mod_rename_users.', '.$mod_change_passwords.', '.$mod_ban_users.', '.$read_board.', '.$view_users.', '.$post_replies.', '.$post_topics.', '.$edit_posts.', '.$delete_posts.', '.$delete_topics.', '.$set_title.', '.$search.', '.$search_users.', '.$send_email.', '.$post_flood.', '.$search_flood.', '.$email_flood.')') or error('Unable to add group', __FILE__, __LINE__, $db->error());
 279:         $new_group_id = $db->insert_id();
 280: 
 281:         // Now lets copy the forum specific permissions from the group which this group is based on
 282:         $result = $db->query('SELECT forum_id, read_forum, post_replies, post_topics FROM '.$db->prefix.'forum_perms WHERE group_id='.intval($_POST['base_group'])) or error('Unable to fetch group forum permission list', __FILE__, __LINE__, $db->error());
 283:         while ($cur_forum_perm = $db->fetch_assoc($result))
 284:             $db->query('INSERT INTO '.$db->prefix.'forum_perms (group_id, forum_id, read_forum, post_replies, post_topics) VALUES('.$new_group_id.', '.$cur_forum_perm['forum_id'].', '.$cur_forum_perm['read_forum'].', '.$cur_forum_perm['post_replies'].', '.$cur_forum_perm['post_topics'].')') or error('Unable to insert group forum permissions', __FILE__, __LINE__, $db->error());
 285:     }
 286:     else
 287:     {
 288:         $result = $db->query('SELECT 1 FROM '.$db->prefix.'groups WHERE g_title=\''.$db->escape($title).'\' AND g_id!='.intval($_POST['group_id'])) or error('Unable to check group title collision', __FILE__, __LINE__, $db->error());
 289:         if ($db->num_rows($result))
 290:             message(sprintf($lang_admin_groups['Title already exists message'], pun_htmlspecialchars($title)));
 291: 
 292:         $db->query('UPDATE '.$db->prefix.'groups SET g_title=\''.$db->escape($title).'\', g_user_title='.$user_title.', g_moderator='.$moderator.', g_mod_edit_users='.$mod_edit_users.', g_mod_rename_users='.$mod_rename_users.', g_mod_change_passwords='.$mod_change_passwords.', g_mod_ban_users='.$mod_ban_users.', g_read_board='.$read_board.', g_view_users='.$view_users.', g_post_replies='.$post_replies.', g_post_topics='.$post_topics.', g_edit_posts='.$edit_posts.', g_delete_posts='.$delete_posts.', g_delete_topics='.$delete_topics.', g_set_title='.$set_title.', g_search='.$search.', g_search_users='.$search_users.', g_send_email='.$send_email.', g_post_flood='.$post_flood.', g_search_flood='.$search_flood.', g_email_flood='.$email_flood.' WHERE g_id='.intval($_POST['group_id'])) or error('Unable to update group', __FILE__, __LINE__, $db->error());
 293:     }
 294: 
 295:     // Regenerate the quick jump cache
 296:     if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
 297:         require PUN_ROOT.'include/cache.php';
 298: 
 299:     generate_quickjump_cache();
 300: 
 301:     if ($_POST['mode'] == 'edit')
 302:         redirect('admin_groups.php', $lang_admin_groups['Group edited redirect']);
 303:     else
 304:         redirect('admin_groups.php', $lang_admin_groups['Group added redirect']);
 305: }
 306: 
 307: 
 308: // Set default group
 309: else if (isset($_POST['set_default_group']))
 310: {
 311:     confirm_referrer('admin_groups.php');
 312: 
 313:     $group_id = intval($_POST['default_group']);
 314: 
 315:     // Make sure it's not the admin or guest groups
 316:     if ($group_id == PUN_ADMIN || $group_id == PUN_GUEST)
 317:         message($lang_common['Bad request']);
 318: 
 319:     // Make sure it's not a moderator group
 320:     $result = $db->query('SELECT 1 FROM '.$db->prefix.'groups WHERE g_id='.$group_id.' AND g_moderator=0') or error('Unable to check group moderator status', __FILE__, __LINE__, $db->error());
 321:     if (!$db->num_rows($result))
 322:         message($lang_common['Bad request']);
 323: 
 324:     $db->query('UPDATE '.$db->prefix.'config SET conf_value='.$group_id.' WHERE conf_name=\'o_default_user_group\'') or error('Unable to update board config', __FILE__, __LINE__, $db->error());
 325: 
 326:     // Regenerate the config cache
 327:     if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
 328:         require PUN_ROOT.'include/cache.php';
 329: 
 330:     generate_config_cache();
 331: 
 332:     redirect('admin_groups.php', $lang_admin_groups['Default group redirect']);
 333: }
 334: 
 335: 
 336: // Remove a group
 337: else if (isset($_GET['del_group']))
 338: {
 339:     confirm_referrer('admin_groups.php');
 340: 
 341:     $group_id = isset($_POST['group_to_delete']) ? intval($_POST['group_to_delete']) : intval($_GET['del_group']);
 342:     if ($group_id < 5)
 343:         message($lang_common['Bad request']);
 344: 
 345:     // Make sure we don't remove the default group
 346:     if ($group_id == $pun_config['o_default_user_group'])
 347:         message($lang_admin_groups['Cannot remove default message']);
 348: 
 349:     // Check if this group has any members
 350:     $result = $db->query('SELECT g.g_title, COUNT(u.id) FROM '.$db->prefix.'groups AS g INNER JOIN '.$db->prefix.'users AS u ON g.g_id=u.group_id WHERE g.g_id='.$group_id.' GROUP BY g.g_id, g_title') or error('Unable to fetch group info', __FILE__, __LINE__, $db->error());
 351: 
 352:     // If the group doesn't have any members or if we've already selected a group to move the members to
 353:     if (!$db->num_rows($result) || isset($_POST['del_group']))
 354:     {
 355:         if (isset($_POST['del_group_comply']) || isset($_POST['del_group']))
 356:         {
 357:             if (isset($_POST['del_group']))
 358:             {
 359:                 $move_to_group = intval($_POST['move_to_group']);
 360:                 $db->query('UPDATE '.$db->prefix.'users SET group_id='.$move_to_group.' WHERE group_id='.$group_id) or error('Unable to move users into group', __FILE__, __LINE__, $db->error());
 361:             }
 362: 
 363:             // Delete the group and any forum specific permissions
 364:             $db->query('DELETE FROM '.$db->prefix.'groups WHERE g_id='.$group_id) or error('Unable to delete group', __FILE__, __LINE__, $db->error());
 365:             $db->query('DELETE FROM '.$db->prefix.'forum_perms WHERE group_id='.$group_id) or error('Unable to delete group forum permissions', __FILE__, __LINE__, $db->error());
 366: 
 367:             // Regenerate the quick jump cache
 368:             if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
 369:                 require PUN_ROOT.'include/cache.php';
 370: 
 371:             generate_quickjump_cache();
 372: 
 373:             redirect('admin_groups.php', $lang_admin_groups['Group removed redirect']);
 374:         }
 375:         else
 376:         {
 377:             $result = $db->query('SELECT g_title FROM '.$db->prefix.'groups WHERE g_id='.$group_id) or error('Unable to fetch group title', __FILE__, __LINE__, $db->error());
 378:             $group_title = $db->result($result);
 379: 
 380:             $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_admin_common['Admin'], $lang_admin_common['User groups']);
 381:             define('PUN_ACTIVE_PAGE', 'admin');
 382:             require PUN_ROOT.'header.php';
 383: 
 384:             generate_admin_menu('groups');
 385: 
 386: ?>
 387:     <div class="blockform">
 388:         <h2><span><?php echo $lang_admin_groups['Group delete head'] ?></span></h2>
 389:         <div class="box">
 390:             <form method="post" action="admin_groups.php?del_group=<?php echo $group_id ?>">
 391:                 <div class="inform">
 392:                 <input type="hidden" name="group_to_delete" value="<?php echo $group_id ?>" />
 393:                     <fieldset>
 394:                         <legend><?php echo $lang_admin_groups['Confirm delete subhead'] ?></legend>
 395:                         <div class="infldset">
 396:                             <p><?php printf($lang_admin_groups['Confirm delete info'], pun_htmlspecialchars($group_title)) ?></p>
 397:                             <p class="warntext"><?php echo $lang_admin_groups['Confirm delete warn'] ?></p>
 398:                         </div>
 399:                     </fieldset>
 400:                 </div>
 401:                 <p class="buttons"><input type="submit" name="del_group_comply" value="<?php echo $lang_admin_common['Delete'] ?>" /><a href="javascript:history.go(-1)"><?php echo $lang_admin_common['Go back'] ?></a></p>
 402:             </form>
 403:         </div>
 404:     </div>
 405:     <div class="clearer"></div>
 406: </div>
 407: <?php
 408: 
 409:             require PUN_ROOT.'footer.php';
 410:         }
 411:     }
 412: 
 413:     list($group_title, $group_members) = $db->fetch_row($result);
 414: 
 415:     $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_admin_common['Admin'], $lang_admin_common['User groups']);
 416:     define('PUN_ACTIVE_PAGE', 'admin');
 417:     require PUN_ROOT.'header.php';
 418: 
 419:     generate_admin_menu('groups');
 420: 
 421: ?>
 422:     <div class="blockform">
 423:         <h2><span><?php echo $lang_admin_groups['Delete group head'] ?></span></h2>
 424:         <div class="box">
 425:             <form id="groups" method="post" action="admin_groups.php?del_group=<?php echo $group_id ?>">
 426:                 <div class="inform">
 427:                     <fieldset>
 428:                         <legend><?php echo $lang_admin_groups['Move users subhead'] ?></legend>
 429:                         <div class="infldset">
 430:                             <p><?php printf($lang_admin_groups['Move users info'], pun_htmlspecialchars($group_title), forum_number_format($group_members)) ?></p>
 431:                             <label><?php echo $lang_admin_groups['Move users label'] ?>
 432:                             <select name="move_to_group">
 433: <?php
 434: 
 435:     $result = $db->query('SELECT g_id, g_title FROM '.$db->prefix.'groups WHERE g_id!='.PUN_GUEST.' AND g_id!='.$group_id.' ORDER BY g_title') or error('Unable to fetch user group list', __FILE__, __LINE__, $db->error());
 436: 
 437:     while ($cur_group = $db->fetch_assoc($result))
 438:     {
 439:         if ($cur_group['g_id'] == PUN_MEMBER) // Pre-select the pre-defined Members group
 440:             echo "\t\t\t\t\t\t\t\t\t\t".'<option value="'.$cur_group['g_id'].'" selected="selected">'.pun_htmlspecialchars($cur_group['g_title']).'</option>'."\n";
 441:         else
 442:             echo "\t\t\t\t\t\t\t\t\t\t".'<option value="'.$cur_group['g_id'].'">'.pun_htmlspecialchars($cur_group['g_title']).'</option>'."\n";
 443:     }
 444: 
 445: ?>
 446:                             </select>
 447:                             <br /></label>
 448:                         </div>
 449:                     </fieldset>
 450:                 </div>
 451:                 <p class="buttons"><input type="submit" name="del_group" value="<?php echo $lang_admin_groups['Delete group'] ?>" /><a href="javascript:history.go(-1)"><?php echo $lang_admin_common['Go back'] ?></a></p>
 452:             </form>
 453:         </div>
 454:     </div>
 455:     <div class="clearer"></div>
 456: </div>
 457: <?php
 458: 
 459:     require PUN_ROOT.'footer.php';
 460: }
 461: 
 462: 
 463: $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_admin_common['Admin'], $lang_admin_common['User groups']);
 464: define('PUN_ACTIVE_PAGE', 'admin');
 465: require PUN_ROOT.'header.php';
 466: 
 467: generate_admin_menu('groups');
 468: 
 469: ?>
 470:     <div class="blockform">
 471:         <h2><span><?php echo $lang_admin_groups['Add groups head'] ?></span></h2>
 472:         <div class="box">
 473:             <form id="groups" method="post" action="admin_groups.php?action=foo">
 474:                 <div class="inform">
 475:                     <fieldset>
 476:                         <legend><?php echo $lang_admin_groups['Add group subhead'] ?></legend>
 477:                         <div class="infldset">
 478:                             <table class="aligntop" cellspacing="0">
 479:                                 <tr>
 480:                                     <th scope="row"><?php echo $lang_admin_groups['New group label'] ?><div><input type="submit" name="add_group" value="<?php echo $lang_admin_common['Add'] ?>" tabindex="2" /></div></th>
 481:                                     <td>
 482:                                         <select id="base_group" name="base_group" tabindex="1">
 483: <?php
 484: 
 485: $result = $db->query('SELECT g_id, g_title FROM '.$db->prefix.'groups WHERE g_id!='.PUN_ADMIN.' AND g_id!='.PUN_GUEST.' ORDER BY g_title') or error('Unable to fetch user group list', __FILE__, __LINE__, $db->error());
 486: 
 487: while ($cur_group = $db->fetch_assoc($result))
 488: {
 489:     if ($cur_group['g_id'] == $pun_config['o_default_user_group'])
 490:         echo "\t\t\t\t\t\t\t\t\t\t\t".'<option value="'.$cur_group['g_id'].'" selected="selected">'.pun_htmlspecialchars($cur_group['g_title']).'</option>'."\n";
 491:     else
 492:         echo "\t\t\t\t\t\t\t\t\t\t\t".'<option value="'.$cur_group['g_id'].'">'.pun_htmlspecialchars($cur_group['g_title']).'</option>'."\n";
 493: }
 494: 
 495: ?>
 496:                                         </select>
 497:                                         <span><?php echo $lang_admin_groups['New group help'] ?></span>
 498:                                     </td>
 499:                                 </tr>
 500:                             </table>
 501:                         </div>
 502:                     </fieldset>
 503:                 </div>
 504:                 <div class="inform">
 505:                     <fieldset>
 506:                         <legend><?php echo $lang_admin_groups['Default group subhead'] ?></legend>
 507:                         <div class="infldset">
 508:                             <table class="aligntop" cellspacing="0">
 509:                                 <tr>
 510:                                     <th scope="row"><?php echo $lang_admin_groups['Default group label'] ?><div><input type="submit" name="set_default_group" value="<?php echo $lang_admin_common['Save'] ?>" tabindex="4" /></div></th>
 511:                                     <td>
 512:                                         <select id="default_group" name="default_group" tabindex="3">
 513: <?php
 514: 
 515: $result = $db->query('SELECT g_id, g_title FROM '.$db->prefix.'groups WHERE g_id>'.PUN_GUEST.' AND g_moderator=0 ORDER BY g_title') or error('Unable to fetch user group list', __FILE__, __LINE__, $db->error());
 516: 
 517: while ($cur_group = $db->fetch_assoc($result))
 518: {
 519:     if ($cur_group['g_id'] == $pun_config['o_default_user_group'])
 520:         echo "\t\t\t\t\t\t\t\t\t\t\t".'<option value="'.$cur_group['g_id'].'" selected="selected">'.pun_htmlspecialchars($cur_group['g_title']).'</option>'."\n";
 521:     else
 522:         echo "\t\t\t\t\t\t\t\t\t\t\t".'<option value="'.$cur_group['g_id'].'">'.pun_htmlspecialchars($cur_group['g_title']).'</option>'."\n";
 523: }
 524: 
 525: ?>
 526:                                         </select>
 527:                                         <span><?php echo $lang_admin_groups['Default group help'] ?></span>
 528:                                     </td>
 529:                                 </tr>
 530:                             </table>
 531:                         </div>
 532:                     </fieldset>
 533:                 </div>
 534:             </form>
 535:         </div>
 536: 
 537:         <h2 class="block2"><span><?php echo $lang_admin_groups['Existing groups head'] ?></span></h2>
 538:         <div class="box">
 539:             <div class="fakeform">
 540:                 <div class="inform">
 541:                     <fieldset>
 542:                         <legend><?php echo $lang_admin_groups['Edit groups subhead'] ?></legend>
 543:                         <div class="infldset">
 544:                             <p><?php echo $lang_admin_groups['Edit groups info'] ?></p>
 545:                             <table cellspacing="0">
 546: <?php
 547: 
 548: $result = $db->query('SELECT g_id, g_title FROM '.$db->prefix.'groups ORDER BY g_id') or error('Unable to fetch user group list', __FILE__, __LINE__, $db->error());
 549: 
 550: while ($cur_group = $db->fetch_assoc($result))
 551:     echo "\t\t\t\t\t\t\t\t".'<tr><th scope="row"><a href="admin_groups.php?edit_group='.$cur_group['g_id'].'">'.$lang_admin_groups['Edit link'].'</a>'.(($cur_group['g_id'] > PUN_MEMBER) ? ' | <a href="admin_groups.php?del_group='.$cur_group['g_id'].'">'.$lang_admin_groups['Delete link'].'</a>' : '').'</th><td>'.pun_htmlspecialchars($cur_group['g_title']).'</td></tr>'."\n";
 552: 
 553: ?>
 554:                             </table>
 555:                         </div>
 556:                     </fieldset>
 557:                 </div>
 558:             </div>
 559:         </div>
 560:     </div>
 561:     <div class="clearer"></div>
 562: </div>
 563: <?php
 564: 
 565: require PUN_ROOT.'footer.php';


/dev/null b/admin_index.php
   1: <?php
   2: 
   3: /**
   4:  * Copyright (C) 2008-2010 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:  */
   8: 
   9: // Tell header.php to use the admin template
  10: define('PUN_ADMIN_CONSOLE', 1);
  11: 
  12: define('PUN_ROOT', './');
  13: require PUN_ROOT.'include/common.php';
  14: require PUN_ROOT.'include/common_admin.php';
  15: 
  16: 
  17: if (!$pun_user['is_admmod'])
  18:     message($lang_common['No permission']);
  19: 
  20: // Load the admin_index.php language file
  21: require PUN_ROOT.'lang/'.$admin_language.'/admin_index.php';
  22: 
  23: $action = isset($_GET['action']) ? $_GET['action'] : null;
  24: 
  25: // Check for upgrade
  26: if ($action == 'check_upgrade')
  27: {
  28:     if (!ini_get('allow_url_fopen'))
  29:         message($lang_admin_index['fopen disabled message']);
  30: 
  31:     $latest_version = trim(@file_get_contents('http://fluxbb.org/latest_version'));
  32:     if (empty($latest_version))
  33:         message($lang_admin_index['Upgrade check failed message']);
  34: 
  35:     if (version_compare($pun_config['o_cur_version'], $latest_version, '>='))
  36:         message($lang_admin_index['Running latest version message']);
  37:     else
  38:         message(sprintf($lang_admin_index['New version available message'], '<a href="http://fluxbb.org/">FluxBB.org</a>'));
  39: }
  40: 
  41: 
  42: // Show phpinfo() output
  43: else if ($action == 'phpinfo' && $pun_user['g_id'] == PUN_ADMIN)
  44: {
  45:     // Is phpinfo() a disabled function?
  46:     if (strpos(strtolower((string) ini_get('disable_functions')), 'phpinfo') !== false)
  47:         message($lang_admin_index['PHPinfo disabled message']);
  48: 
  49:     phpinfo();
  50:     exit;
  51: }
  52: 
  53: 
  54: // Get the server load averages (if possible)
  55: if (@file_exists('/proc/loadavg') && is_readable('/proc/loadavg'))
  56: {
  57:     // We use @ just in case
  58:     $fh = @fopen('/proc/loadavg', 'r');
  59:     $load_averages = @fread($fh, 64);
  60:     @fclose($fh);
  61: 
  62:     if (($fh = @fopen('/proc/loadavg', 'r')))
  63:     {
  64:         $load_averages = fread($fh, 64);
  65:         fclose($fh);
  66:     }
  67:     else
  68:         $load_averages = '';
  69: 
  70:     $load_averages = @explode(' ', $load_averages);
  71:     $server_load = isset($load_averages[2]) ? $load_averages[0].' '.$load_averages[1].' '.$load_averages[2] : $lang_admin_index['Not available'];
  72: }
  73: else if (!in_array(PHP_OS, array('WINNT', 'WIN32')) && preg_match('/averages?: ([0-9\.]+),?\s+([0-9\.]+),?\s+([0-9\.]+)/i', @exec('uptime'), $load_averages))
  74:     $server_load = $load_averages[1].' '.$load_averages[2].' '.$load_averages[3];
  75: else
  76:     $server_load = $lang_admin_index['Not available'];
  77: 
  78: 
  79: // Get number of current visitors
  80: $result = $db->query('SELECT COUNT(user_id) FROM '.$db->prefix.'online WHERE idle=0') or error('Unable to fetch online count', __FILE__, __LINE__, $db->error());
  81: $num_online = $db->result($result);
  82: 
  83: 
  84: // Collect some additional info about MySQL
  85: if ($db_type == 'mysql' || $db_type == 'mysqli' || $db_type == 'mysql_innodb' || $db_type == 'mysqli_innodb')
  86: {
  87:     // Calculate total db size/row count
  88:     $result = $db->query('SHOW TABLE STATUS FROM `'.$db_name.'`LIKE \''.$db->prefix.'%\'') or error('Unable to fetch table status', __FILE__, __LINE__, $db->error());
  89: 
  90:     $total_records = $total_size = 0;
  91:     while ($status = $db->fetch_assoc($result))
  92:     {
  93:         $total_records += $status['Rows'];
  94:         $total_size += $status['Data_length'] + $status['Index_length'];
  95:     }
  96: 
  97:     $total_size = file_size($total_size);
  98: }
  99: 
 100: 
 101: // Check for the existence of various PHP opcode caches/optimizers
 102: if (function_exists('mmcache'))
 103:     $php_accelerator = '<a href="http://'.$lang_admin_index['Turck MMCache link'].'">'.$lang_admin_index['Turck MMCache'].'</a>';
 104: else if (isset($_PHPA))
 105:     $php_accelerator = '<a href="http://'.$lang_admin_index['ionCube PHP Accelerator link'].'">'.$lang_admin_index['ionCube PHP Accelerator'].'</a>';
 106: else if (ini_get('apc.enabled'))
 107:     $php_accelerator ='<a href="http://'.$lang_admin_index['Alternative PHP Cache (APC) link'].'">'.$lang_admin_index['Alternative PHP Cache (APC)'].'</a>';
 108: else if (ini_get('zend_optimizer.optimization_level'))
 109:     $php_accelerator = '<a href="http://'.$lang_admin_index['Zend Optimizer link'].'">'.$lang_admin_index['Zend Optimizer'].'</a>';
 110: else if (ini_get('eaccelerator.enable'))
 111:     $php_accelerator = '<a href="http://'.$lang_admin_index['eAccelerator link'].'">'.$lang_admin_index['eAccelerator'].'</a>';
 112: else if (ini_get('xcache.cacher'))
 113:     $php_accelerator = '<a href="http://'.$lang_admin_index['XCache link'].'">'.$lang_admin_index['XCache'].'</a>';
 114: else
 115:     $php_accelerator = $lang_admin_index['NA'];
 116: 
 117: 
 118: $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_admin_common['Admin'], $lang_admin_common['Index']);
 119: define('PUN_ACTIVE_PAGE', 'admin');
 120: require PUN_ROOT.'header.php';
 121: 
 122: generate_admin_menu('index');
 123: 
 124: ?>
 125:     <div class="block">
 126:         <h2><span><?php echo $lang_admin_index['Forum admin head'] ?></span></h2>
 127:         <div id="adintro" class="box">
 128:             <div class="inbox">
 129:                 <p>
 130:                     <?php echo $lang_admin_index['Welcome to admin'] ?><br /><br />
 131:                     &#160;- <?php echo $lang_admin_index['Welcome 1'] ?><br />
 132:                     &#160;- <?php echo $lang_admin_index['Welcome 2'] ?><br />
 133:                     &#160;- <?php echo $lang_admin_index['Welcome 3'] ?><br />
 134:                     &#160;- <?php echo $lang_admin_index['Welcome 4'] ?><br />
 135:                     &#160;- <?php echo $lang_admin_index['Welcome 5'] ?><br />
 136:                     &#160;- <?php echo $lang_admin_index['Welcome 6'] ?><br />
 137:                     &#160;- <?php echo $lang_admin_index['Welcome 7'] ?><br />
 138:                     &#160;- <?php echo $lang_admin_index['Welcome 8'] ?><br />
 139:                     &#160;- <?php echo $lang_admin_index['Welcome 9'] ?>
 140:                 </p>
 141:             </div>
 142:         </div>
 143: 
 144:         <h2 class="block2"><span><?php echo $lang_admin_index['Statistics head'] ?></span></h2>
 145:         <div id="adstats" class="box">
 146:             <div class="inbox">
 147:                 <dl>
 148:                     <dt><?php echo $lang_admin_index['FluxBB version label'] ?></dt>
 149:                     <dd>
 150:                         <?php printf($lang_admin_index['FluxBB version data'], $pun_config['o_cur_version'], '<a href="admin_index.php?action=check_upgrade">'.$lang_admin_index['Check for upgrade'].'</a>') ?><br />
 151:                     </dd>
 152:                     <dt><?php echo $lang_admin_index['Server load label'] ?></dt>
 153:                     <dd>
 154:                         <?php printf($lang_admin_index['Server load data'], $server_load, $num_online) ?>
 155:                     </dd>
 156: <?php if ($pun_user['g_id'] == PUN_ADMIN): ?>                    <dt><?php echo $lang_admin_index['Environment label'] ?></dt>
 157:                     <dd>
 158:                         <?php printf($lang_admin_index['Environment data OS'], PHP_OS) ?><br />
 159:                         <?php printf($lang_admin_index['Environment data version'], phpversion(), '<a href="admin_index.php?action=phpinfo">'.$lang_admin_index['Show info'].'</a>') ?><br />
 160:                         <?php printf($lang_admin_index['Environment data acc'], $php_accelerator) ?>
 161:                     </dd>
 162:                     <dt><?php echo $lang_admin_index['Database label'] ?></dt>
 163:                     <dd>
 164:                         <?php echo implode(' ', $db->get_version())."\n" ?>
 165: <?php if (isset($total_records) && isset($total_size)): ?>                        <br /><?php printf($lang_admin_index['Database data rows'], forum_number_format($total_records)) ?>
 166:                         <br /><?php printf($lang_admin_index['Database data size'], $total_size) ?>
 167: <?php endif; endif; ?>                    </dd>
 168:                 </dl>
 169:             </div>
 170:         </div>
 171:     </div>
 172:     <div class="clearer"></div>
 173: </div>
 174: <?php
 175: 
 176: require PUN_ROOT.'footer.php';


/dev/null b/admin_loader.php
   1: <?php
   2: 
   3: /**
   4:  * Copyright (C) 2008-2010 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:  */
   8: 
   9: // Tell header.php to use the admin template
  10: define('PUN_ADMIN_CONSOLE', 1);
  11: 
  12: define('PUN_ROOT', './');
  13: require PUN_ROOT.'include/common.php';
  14: require PUN_ROOT.'include/common_admin.php';
  15: 
  16: 
  17: if (!$pun_user['is_admmod'])
  18:     message($lang_common['No permission']);
  19: 
  20: // The plugin to load should be supplied via GET
  21: $plugin = isset($_GET['plugin']) ? $_GET['plugin'] : '';
  22: if (!preg_match('/^AM?P_(\w*?)\.php$/i', $plugin))
  23:     message($lang_common['Bad request']);
  24: 
  25: // AP_ == Admins only, AMP_ == admins and moderators
  26: $prefix = substr($plugin, 0, strpos($plugin, '_'));
  27: if ($pun_user['g_moderator'] == '1' && $prefix == 'AP')
  28:     message($lang_common['No permission']);
  29: 
  30: // Make sure the file actually exists
  31: if (!file_exists(PUN_ROOT.'plugins/'.$plugin))
  32:     message(sprintf($lang_admin_common['No plugin message'], $plugin));
  33: 
  34: // Construct REQUEST_URI if it isn't set
  35: if (!isset($_SERVER['REQUEST_URI']))
  36:     $_SERVER['REQUEST_URI'] = (isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : '').'?'.(isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '');
  37: 
  38: $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_common['Admin'], str_replace('_', ' ', substr($plugin, strpos($plugin, '_') + 1, -4)));
  39: define('PUN_ACTIVE_PAGE', 'admin');
  40: require PUN_ROOT.'header.php';
  41: 
  42: // Attempt to load the plugin. We don't use @ here to supress error messages,
  43: // because if we did and a parse error occurred in the plugin, we would only
  44: // get the "blank page of death"
  45: include PUN_ROOT.'plugins/'.$plugin;
  46: if (!defined('PUN_PLUGIN_LOADED'))
  47:     message(sprintf($lang_admin_common['Plugin failed message'], $plugin));
  48: 
  49: // Output the clearer div
  50: ?>
  51:     <div class="clearer"></div>
  52: </div>
  53: <?php
  54: 
  55: require PUN_ROOT.'footer.php';


/dev/null b/admin_maintenance.php
   1: <?php
   2: 
   3: /**
   4:  * Copyright (C) 2008-2010 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:  */
   8: 
   9: // Tell header.php to use the admin template
  10: define('PUN_ADMIN_CONSOLE', 1);
  11: // Tell common.php that we don't want output buffering
  12: define('PUN_DISABLE_BUFFERING', 1);
  13: 
  14: define('PUN_ROOT', './');
  15: require PUN_ROOT.'include/common.php';
  16: require PUN_ROOT.'include/common_admin.php';
  17: 
  18: 
  19: if ($pun_user['g_id'] != PUN_ADMIN)
  20:     message($lang_common['No permission']);
  21: 
  22: // Load the admin_maintenance.php language file
  23: require PUN_ROOT.'lang/'.$admin_language.'/admin_maintenance.php';
  24: 
  25: if (isset($_GET['i_per_page']) && isset($_GET['i_start_at']))
  26: {
  27:     $per_page = intval($_GET['i_per_page']);
  28:     $start_at = intval($_GET['i_start_at']);
  29:     if ($per_page < 1 || $start_at < 1)
  30:         message($lang_common['Bad request']);
  31: 
  32:     @set_time_limit(0);
  33: 
  34:     // If this is the first cycle of posts we empty the search index before we proceed
  35:     if (isset($_GET['i_empty_index']))
  36:     {
  37:         // This is the only potentially "dangerous" thing we can do here, so we check the referer
  38:         confirm_referrer('admin_maintenance.php');
  39: 
  40:         $db->truncate_table('search_matches') or error('Unable to empty search index match table', __FILE__, __LINE__, $db->error());
  41:         $db->truncate_table('search_words') or error('Unable to empty search index words table', __FILE__, __LINE__, $db->error());
  42: 
  43:         // Reset the sequence for the search words (not needed for SQLite)
  44:         switch ($db_type)
  45:         {
  46:             case 'mysql':
  47:             case 'mysqli':
  48:             case 'mysql_innodb':
  49:             case 'mysqli_innodb':
  50:                 $result = $db->query('ALTER TABLE '.$db->prefix.'search_words auto_increment=1') or error('Unable to update table auto_increment', __FILE__, __LINE__, $db->error());
  51:                 break;
  52: 
  53:             case 'pgsql';
  54:                 $result = $db->query('SELECT setval(\''.$db->prefix.'search_words_id_seq\', 1, false)') or error('Unable to update sequence', __FILE__, __LINE__, $db->error());
  55:         }
  56:     }
  57: 
  58:     $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_admin_maintenance['Rebuilding search index']);
  59: 
  60: ?>
  61: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  62: 
  63: <html>
  64: <head>
  65: <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  66: <title><?php echo generate_page_title($page_title) ?></title>
  67: <style type="text/css">
  68: body {
  69:     font: 12px Verdana, Arial, Helvetica, sans-serif;
  70:     color: #333333;
  71:     background-color: #FFFFFF
  72: }
  73: 
  74: h1 {
  75:     font-size: 16px;
  76:     font-weight: normal;
  77: }
  78: </style>
  79: </head>
  80: <body>
  81: 
  82: <h1><?php echo $lang_admin_maintenance['Rebuilding index info'] ?></h1>
  83: <hr />
  84: 
  85: <?php
  86: 
  87:     $query_str = '';
  88: 
  89:     require PUN_ROOT.'include/search_idx.php';
  90: 
  91:     // Fetch posts to process this cycle
  92:     $result = $db->query('SELECT p.id, p.message, t.subject, t.first_post_id FROM '.$db->prefix.'posts AS p INNER JOIN '.$db->prefix.'topics AS t ON t.id=p.topic_id WHERE p.id >= '.$start_at.' ORDER BY p.id ASC LIMIT '.$per_page) or error('Unable to fetch posts', __FILE__, __LINE__, $db->error());
  93: 
  94:     $end_at = 0;
  95:     while ($cur_item = $db->fetch_assoc($result))
  96:     {
  97:         echo '<p><span>'.sprintf($lang_admin_maintenance['Processing post'], $cur_item['id']).'</span></p>'."\n";
  98: 
  99:         if ($cur_item['id'] == $cur_item['first_post_id'])
 100:             update_search_index('post', $cur_item['id'], $cur_item['message'], $cur_item['subject']);
 101:         else
 102:             update_search_index('post', $cur_item['id'], $cur_item['message']);
 103: 
 104:         $end_at = $cur_item['id'];
 105:     }
 106: 
 107:     // Check if there is more work to do
 108:     if ($end_at > 0)
 109:     {
 110:         $result = $db->query('SELECT id FROM '.$db->prefix.'posts WHERE id > '.$end_at.' ORDER BY id ASC LIMIT 1') or error('Unable to fetch next ID', __FILE__, __LINE__, $db->error());
 111: 
 112:         if ($db->num_rows($result) > 0)
 113:             $query_str = '?i_per_page='.$per_page.'&i_start_at='.$db->result($result);
 114:     }
 115: 
 116:     $db->end_transaction();
 117:     $db->close();
 118: 
 119:     exit('<script type="text/javascript">window.location="admin_maintenance.php'.$query_str.'"</script><hr /><p>'.sprintf($lang_admin_maintenance['Javascript redirect failed'], '<a href="admin_maintenance.php'.$query_str.'">'.$lang_admin_maintenance['Click here'].'</a>').'</p>');
 120: }
 121: 
 122: 
 123: // Get the first post ID from the db
 124: $result = $db->query('SELECT id FROM '.$db->prefix.'posts ORDER BY id ASC LIMIT 1') or error('Unable to fetch topic info', __FILE__, __LINE__, $db->error());
 125: if ($db->num_rows($result))
 126:     $first_id = $db->result($result);
 127: 
 128: $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_admin_common['Admin'], $lang_admin_common['Maintenance']);
 129: define('PUN_ACTIVE_PAGE', 'admin');
 130: require PUN_ROOT.'header.php';
 131: 
 132: generate_admin_menu('maintenance');
 133: 
 134: ?>
 135:     <div class="blockform">
 136:         <h2><span><?php echo $lang_admin_maintenance['Maintenance head'] ?></span></h2>
 137:         <div class="box">
 138:             <form method="get" action="admin_maintenance.php">
 139:                 <div class="inform">
 140:                     <fieldset>
 141:                         <legend><?php echo $lang_admin_maintenance['Rebuild index subhead'] ?></legend>
 142:                         <div class="infldset">
 143:                             <p><?php printf($lang_admin_maintenance['Rebuild index info'], '<a href="admin_options.php#maintenance">'.$lang_admin_common['Maintenance mode'].'</a>') ?></p>
 144:                             <table class="aligntop" cellspacing="0">
 145:                                 <tr>
 146:                                     <th scope="row"><?php echo $lang_admin_maintenance['Posts per cycle label'] ?></th>
 147:                                     <td>
 148:                                         <input type="text" name="i_per_page" size="7" maxlength="7" value="300" tabindex="1" />
 149:                                         <span><?php echo $lang_admin_maintenance['Posts per cycle help'] ?></span>
 150:                                     </td>
 151:                                 </tr>
 152:                                 <tr>
 153:                                     <th scope="row"><?php echo $lang_admin_maintenance['Starting post label'] ?></th>
 154:                                     <td>
 155:                                         <input type="text" name="i_start_at" size="7" maxlength="7" value="<?php echo (isset($first_id)) ? $first_id : 0 ?>" tabindex="2" />
 156:                                         <span><?php echo $lang_admin_maintenance['Starting post help'] ?></span>
 157:                                     </td>
 158:                                 </tr>
 159:                                 <tr>
 160:                                     <th scope="row"><?php echo $lang_admin_maintenance['Empty index label'] ?></th>
 161:                                     <td class="inputadmin">
 162:                                         <span><input type="checkbox" name="i_empty_index" value="1" tabindex="3" checked="checked" />&#160;&#160;<?php echo $lang_admin_maintenance['Empty index help'] ?></span>
 163:                                     </td>
 164:                                 </tr>
 165:                             </table>
 166:                             <p class="topspace"><?php echo $lang_admin_maintenance['Rebuild completed info'] ?></p>
 167:                             <div class="fsetsubmit"><input type="submit" name="rebuild_index" value="<?php echo $lang_admin_maintenance['Rebuild index'] ?>" tabindex="4" /></div>
 168:                         </div>
 169:                     </fieldset>
 170:                 </div>
 171:             </form>
 172:         </div>
 173:     </div>
 174:     <div class="clearer"></div>
 175: </div>
 176: <?php
 177: 
 178: require PUN_ROOT.'footer.php';


/dev/null b/admin_options.php
   1: <?php
   2: 
   3: /**
   4:  * Copyright (C) 2008-2010 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:  */
   8: 
   9: // Tell header.php to use the admin template
  10: define('PUN_ADMIN_CONSOLE', 1);
  11: 
  12: define('PUN_ROOT', './');
  13: require PUN_ROOT.'include/common.php';
  14: require PUN_ROOT.'include/common_admin.php';
  15: 
  16: 
  17: if ($pun_user['g_id'] != PUN_ADMIN)
  18:     message($lang_common['No permission']);
  19: 
  20: // Load the admin_options.php language file
  21: require PUN_ROOT.'lang/'.$admin_language.'/admin_options.php';
  22: 
  23: if (isset($_POST['form_sent']))
  24: {
  25:     // Custom referrer check (so we can output a custom error message)
  26:     if (!preg_match('#^'.preg_quote(str_replace('www.', '', $pun_config['o_base_url']).'/admin_options.php', '#').'#i', str_replace('www.', '', (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''))))
  27:         message($lang_admin_options['Bad HTTP Referer message']);
  28: 
  29:     $form = array(
  30:         'board_title'            => pun_trim($_POST['form']['board_title']),
  31:         'board_desc'            => pun_trim($_POST['form']['board_desc']),
  32:         'base_url'                => pun_trim($_POST['form']['base_url']),
  33:         'default_timezone'        => floatval($_POST['form']['default_timezone']),
  34:         'default_dst'            => $_POST['form']['default_dst'] != '1' ? '0' : '1',
  35:         'default_lang'            => preg_replace('#[\.\\\/]#', '', pun_trim($_POST['form']['default_lang'])),
  36:         'default_style'            => preg_replace('#[\.\\\/]#', '', pun_trim($_POST['form']['default_style'])),
  37:         'time_format'            => pun_trim($_POST['form']['time_format']),
  38:         'date_format'            => pun_trim($_POST['form']['date_format']),
  39:         'timeout_visit'            => intval($_POST['form']['timeout_visit']),
  40:         'timeout_online'        => intval($_POST['form']['timeout_online']),
  41:         'redirect_delay'        => intval($_POST['form']['redirect_delay']),
  42:         'show_version'            => $_POST['form']['show_version'] != '1' ? '0' : '1',
  43:         'show_user_info'        => $_POST['form']['show_user_info'] != '1' ? '0' : '1',
  44:         'show_post_count'        => $_POST['form']['show_post_count'] != '1' ? '0' : '1',
  45:         'smilies'                => $_POST['form']['smilies'] != '1' ? '0' : '1',
  46:         'smilies_sig'            => $_POST['form']['smilies_sig'] != '1' ? '0' : '1',
  47:         'make_links'            => $_POST['form']['make_links'] != '1' ? '0' : '1',
  48:         'topic_review'            => intval($_POST['form']['topic_review']),
  49:         'disp_topics_default'    => intval($_POST['form']['disp_topics_default']),
  50:         'disp_posts_default'    => intval($_POST['form']['disp_posts_default']),
  51:         'indent_num_spaces'        => intval($_POST['form']['indent_num_spaces']),
  52:         'quote_depth'            => intval($_POST['form']['quote_depth']),
  53:         'quickpost'                => $_POST['form']['quickpost'] != '1' ? '0' : '1',
  54:         'users_online'            => $_POST['form']['users_online'] != '1' ? '0' : '1',
  55:         'censoring'                => $_POST['form']['censoring'] != '1' ? '0' : '1',
  56:         'signatures'            => $_POST['form']['signatures'] != '1' ? '0' : '1',
  57:         'ranks'                    => $_POST['form']['ranks'] != '1' ? '0' : '1',
  58:         'show_dot'                => $_POST['form']['show_dot'] != '1' ? '0' : '1',
  59:         'topic_views'            => $_POST['form']['topic_views'] != '1' ? '0' : '1',
  60:         'quickjump'                => $_POST['form']['quickjump'] != '1' ? '0' : '1',
  61:         'gzip'                    => $_POST['form']['gzip'] != '1' ? '0' : '1',
  62:         'search_all_forums'        => $_POST['form']['search_all_forums'] != '1' ? '0' : '1',
  63:         'additional_navlinks'    => pun_trim($_POST['form']['additional_navlinks']),
  64:         'feed_type'                => intval($_POST['form']['feed_type']),
  65:         'report_method'            => intval($_POST['form']['report_method']),
  66:         'mailing_list'            => pun_trim($_POST['form']['mailing_list']),
  67:         'avatars'                => $_POST['form']['avatars'] != '1' ? '0' : '1',
  68:         'avatars_dir'            => pun_trim($_POST['form']['avatars_dir']),
  69:         'avatars_width'            => intval($_POST['form']['avatars_width']),
  70:         'avatars_height'        => intval($_POST['form']['avatars_height']),
  71:         'avatars_size'            => intval($_POST['form']['avatars_size']),
  72:         'admin_email'            => strtolower(pun_trim($_POST['form']['admin_email'])),
  73:         'webmaster_email'        => strtolower(pun_trim($_POST['form']['webmaster_email'])),
  74:         'subscriptions'            => $_POST['form']['subscriptions'] != '1' ? '0' : '1',
  75:         'smtp_host'                => pun_trim($_POST['form']['smtp_host']),
  76:         'smtp_user'                => pun_trim($_POST['form']['smtp_user']),
  77:         'smtp_pass'                => pun_trim($_POST['form']['smtp_pass']),
  78:         'smtp_ssl'                => $_POST['form']['smtp_ssl'] != '1' ? '0' : '1',
  79:         'regs_allow'            => $_POST['form']['regs_allow'] != '1' ? '0' : '1',
  80:         'regs_verify'            => $_POST['form']['regs_verify'] != '1' ? '0' : '1',
  81:         'regs_report'            => $_POST['form']['regs_report'] != '1' ? '0' : '1',
  82:         'rules'                    => $_POST['form']['rules'] != '1' ? '0' : '1',
  83:         'rules_message'            => pun_trim($_POST['form']['rules_message']),
  84:         'default_email_setting'    => intval($_POST['form']['default_email_setting']),
  85:         'announcement'            => $_POST['form']['announcement'] != '1' ? '0' : '1',
  86:         'announcement_message'    => pun_trim($_POST['form']['announcement_message']),
  87:         'maintenance'            => $_POST['form']['maintenance'] != '1' ? '0' : '1',
  88:         'maintenance_message'    => pun_trim($_POST['form']['maintenance_message']),
  89:     );
  90: 
  91:     if ($form['board_title'] == '')
  92:         message($lang_admin_options['Must enter title message']);
  93: 
  94:     // Make sure base_url doesn't end with a slash
  95:     if (substr($form['base_url'], -1) == '/')
  96:         $form['base_url'] = substr($form['base_url'], 0, -1);
  97: 
  98:     if (!file_exists(PUN_ROOT.'lang/'.$form['default_lang'].'/common.php'))
  99:         message($lang_common['Bad request']);
 100:     if (!file_exists(PUN_ROOT.'style/'.$form['default_style'].'.css'))
 101:         message($lang_common['Bad request']);
 102: 
 103:     if ($form['time_format'] == '')
 104:         $form['time_format'] = 'H:i:s';
 105: 
 106:     if ($form['date_format'] == '')
 107:         $form['date_format'] = 'Y-m-d';
 108: 
 109: 
 110:     require PUN_ROOT.'include/email.php';
 111: 
 112:     if (!is_valid_email($form['admin_email']))
 113:         message($lang_admin_options['Invalid e-mail message']);
 114: 
 115:     if (!is_valid_email($form['webmaster_email']))
 116:         message($lang_admin_options['Invalid webmaster e-mail message']);
 117: 
 118:     if ($form['mailing_list'] != '')
 119:         $form['mailing_list'] = strtolower(preg_replace('/\s/S', '', $form['mailing_list']));
 120: 
 121:     // Make sure avatars_dir doesn't end with a slash
 122:     if (substr($form['avatars_dir'], -1) == '/')
 123:         $form['avatars_dir'] = substr($form['avatars_dir'], 0, -1);
 124: 
 125:     if ($form['additional_navlinks'] != '')
 126:         $form['additional_navlinks'] = pun_trim(pun_linebreaks($form['additional_navlinks']));
 127: 
 128:     if ($form['announcement_message'] != '')
 129:         $form['announcement_message'] = pun_linebreaks($form['announcement_message']);
 130:     else
 131:     {
 132:         $form['announcement_message'] = $lang_admin_options['Enter announcement here'];
 133:         $form['announcement'] = '0';
 134:     }
 135: 
 136:     if ($form['rules_message'] != '')
 137:         $form['rules_message'] = pun_linebreaks($form['rules_message']);
 138:     else
 139:     {
 140:         $form['rules_message'] = $lang_admin_options['Enter rules here'];
 141:         $form['rules'] = '0';
 142:     }
 143: 
 144:     if ($form['maintenance_message'] != '')
 145:         $form['maintenance_message'] = pun_linebreaks($form['maintenance_message']);
 146:     else
 147:     {
 148:         $form['maintenance_message'] = $lang_admin_options['Default maintenance message'];
 149:         $form['maintenance'] = '0';
 150:     }
 151: 
 152:     // Make sure the number of displayed topics and posts is between 3 and 75
 153:     if ($form['disp_topics_default'] < 3)
 154:         $form['disp_topics_default'] = 3;
 155:     else if ($form['disp_topics_default'] > 75)
 156:         $form['disp_topics_default'] = 75;
 157: 
 158:     if ($form['disp_posts_default'] < 3)
 159:         $form['disp_posts_default'] = 3;
 160:     else if ($form['disp_posts_default'] > 75)
 161:         $form['disp_posts_default'] = 75;
 162: 
 163:     if ($form['feed_type'] < 0 || $form['feed_type'] > 2)
 164:         message($lang_common['Bad request']);
 165: 
 166:     if ($form['report_method'] < 0 || $form['report_method'] > 2)
 167:         message($lang_common['Bad request']);
 168: 
 169:     if ($form['default_email_setting'] < 0 || $form['default_email_setting'] > 2)
 170:         message($lang_common['Bad request']);
 171: 
 172:     if ($form['timeout_online'] >= $form['timeout_visit'])
 173:         message($lang_admin_options['Timeout error message']);
 174: 
 175:     foreach ($form as $key => $input)
 176:     {
 177:         // Only update values that have changed
 178:         if (array_key_exists('o_'.$key, $pun_config) && $pun_config['o_'.$key] != $input)
 179:         {
 180:             if ($input != '' || is_int($input))
 181:                 $value = '\''.$db->escape($input).'\'';
 182:             else
 183:                 $value = 'NULL';
 184: 
 185:             $db->query('UPDATE '.$db->prefix.'config SET conf_value='.$value.' WHERE conf_name=\'o_'.$db->escape($key).'\'') or error('Unable to update board config', __FILE__, __LINE__, $db->error());
 186:         }
 187:     }
 188: 
 189:     // Regenerate the config cache
 190:     if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
 191:         require PUN_ROOT.'include/cache.php';
 192: 
 193:     generate_config_cache();
 194: 
 195:     redirect('admin_options.php', $lang_admin_options['Options updated redirect']);
 196: }
 197: 
 198: $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_admin_common['Admin'], $lang_admin_common['Options']);
 199: define('PUN_ACTIVE_PAGE', 'admin');
 200: require PUN_ROOT.'header.php';
 201: 
 202: generate_admin_menu('options');
 203: 
 204: ?>
 205:     <div class="blockform">
 206:         <h2><span><?php echo $lang_admin_options['Options head'] ?></span></h2>
 207:         <div class="box">
 208:             <form method="post" action="admin_options.php?action=foo">
 209:                 <p class="submittop"><input type="submit" name="save" value="<?php echo $lang_admin_common['Save changes'] ?>" /></p>
 210:                 <div class="inform">
 211:                     <input type="hidden" name="form_sent" value="1" />
 212:                     <fieldset>
 213:                         <legend><?php echo $lang_admin_options['Essentials subhead'] ?></legend>
 214:                         <div class="infldset">
 215:                             <table class="aligntop" cellspacing="0">
 216:                                 <tr>
 217:                                     <th scope="row"><?php echo $lang_admin_options['Board title label'] ?></th>
 218:                                     <td>
 219:                                         <input type="text" name="form[board_title]" size="50" maxlength="255" value="<?php echo pun_htmlspecialchars($pun_config['o_board_title']) ?>" />
 220:                                         <span><?php echo $lang_admin_options['Board title help'] ?></span>
 221:                                     </td>
 222:                                 </tr>
 223:                                 <tr>
 224:                                     <th scope="row"><?php echo $lang_admin_options['Board desc label'] ?></th>
 225:                                     <td>
 226:                                         <input type="text" name="form[board_desc]" size="50" maxlength="255" value="<?php echo pun_htmlspecialchars($pun_config['o_board_desc']) ?>" />
 227:                                         <span><?php echo $lang_admin_options['Board desc help'] ?></span>
 228:                                     </td>
 229:                                 </tr>
 230:                                 <tr>
 231:                                     <th scope="row"><?php echo $lang_admin_options['Base URL label'] ?></th>
 232:                                     <td>
 233:                                         <input type="text" name="form[base_url]" size="50" maxlength="100" value="<?php echo $pun_config['o_base_url'] ?>" />
 234:                                         <span><?php echo $lang_admin_options['Base URL help'] ?></span>
 235:                                     </td>
 236:                                 </tr>
 237:                                 <tr>
 238:                                     <th scope="row"><?php echo $lang_admin_options['Timezone label'] ?></th>
 239:                                     <td>
 240:                                         <select name="form[default_timezone]">
 241:                                             <option value="-12"<?php if ($pun_config['o_default_timezone'] == -12) echo ' selected="selected"' ?>><?php echo $lang_admin_options['UTC-12:00'] ?></option>
 242:                                             <option value="-11"<?php if ($pun_config['o_default_timezone'] == -11) echo ' selected="selected"' ?>><?php echo $lang_admin_options['UTC-11:00'] ?></option>
 243:                                             <option value="-10"<?php if ($pun_config['o_default_timezone'] == -10) echo ' selected="selected"' ?>><?php echo $lang_admin_options['UTC-10:00'] ?></option>
 244:                                             <option value="-9.5"<?php if ($pun_config['o_default_timezone'] == -9.5) echo ' selected="selected"' ?>><?php echo $lang_admin_options['UTC-09:30'] ?></option>
 245:                                             <option value="-9"<?php if ($pun_config['o_default_timezone'] == -9) echo ' selected="selected"' ?>><?php echo $lang_admin_options['UTC-09:00'] ?></option>
 246:                                             <option value="-8.5"<?php if ($pun_config['o_default_timezone'] == -8.5) echo ' selected="selected"' ?>><?php echo $lang_admin_options['UTC-08:30'] ?></option>
 247:                                             <option value="-8"<?php if ($pun_config['o_default_timezone'] == -8) echo ' selected="selected"' ?>><?php echo $lang_admin_options['UTC-08:00'] ?></option>
 248:                                             <option value="-7"<?php if ($pun_config['o_default_timezone'] == -7) echo ' selected="selected"' ?>><?php echo $lang_admin_options['UTC-07:00'] ?></option>
 249:                                             <option value="-6"<?php if ($pun_config['o_default_timezone'] == -6) echo ' selected="selected"' ?>><?php echo $lang_admin_options['UTC-06:00'] ?></option>
 250:                                             <option value="-5"<?php if ($pun_config['o_default_timezone'] == -5) echo ' selected="selected"' ?>><?php echo $lang_admin_options['UTC-05:00'] ?></option>
 251:                                             <option value="-4"<?php if ($pun_config['o_default_timezone'] == -4) echo ' selected="selected"' ?>><?php echo $lang_admin_options['UTC-04:00'] ?></option>
 252:                                             <option value="-3.5"<?php if ($pun_config['o_default_timezone'] == -3.5) echo ' selected="selected"' ?>><?php echo $lang_admin_options['UTC-03:30'] ?></option>
 253:                                             <option value="-3"<?php if ($pun_config['o_default_timezone'] == -3) echo ' selected="selected"' ?>><?php echo $lang_admin_options['UTC-03:00'] ?></option>
 254:                                             <option value="-2"<?php if ($pun_config['o_default_timezone'] == -2) echo ' selected="selected"' ?>><?php echo $lang_admin_options['UTC-02:00'] ?></option>
 255:                                             <option value="-1"<?php if ($pun_config['o_default_timezone'] == -1) echo ' selected="selected"' ?>><?php echo $lang_admin_options['UTC-01:00'] ?></option>
 256:                                             <option value="0"<?php if ($pun_config['o_default_timezone'] == 0) echo ' selected="selected"' ?>><?php echo $lang_admin_options['UTC'] ?></option>
 257:                                             <option value="1"<?php if ($pun_config['o_default_timezone'] == 1) echo ' selected="selected"' ?>><?php echo $lang_admin_options['UTC+01:00'] ?></option>
 258:                                             <option value="2"<?php if ($pun_config['o_default_timezone'] == 2) echo ' selected="selected"' ?>><?php echo $lang_admin_options['UTC+02:00'] ?></option>
 259:                                             <option value="3"<?php if ($pun_config['o_default_timezone'] == 3) echo ' selected="selected"' ?>><?php echo $lang_admin_options['UTC+03:00'] ?></option>
 260:                                             <option value="3.5"<?php if ($pun_config['o_default_timezone'] == 3.5) echo ' selected="selected"' ?>><?php echo $lang_admin_options['UTC+03:30'] ?></option>
 261:                                             <option value="4"<?php if ($pun_config['o_default_timezone'] == 4) echo ' selected="selected"' ?>><?php echo $lang_admin_options['UTC+04:00'] ?></option>
 262:                                             <option value="4.5"<?php if ($pun_config['o_default_timezone'] == 4.5) echo ' selected="selected"' ?>><?php echo $lang_admin_options['UTC+04:30'] ?></option>
 263:                                             <option value="5"<?php if ($pun_config['o_default_timezone'] == 5) echo ' selected="selected"' ?>><?php echo $lang_admin_options['UTC+05:00'] ?></option>
 264:                                             <option value="5.5"<?php if ($pun_config['o_default_timezone'] == 5.5) echo ' selected="selected"' ?>><?php echo $lang_admin_options['UTC+05:30'] ?></option>
 265:                                             <option value="5.75"<?php if ($pun_config['o_default_timezone'] == 5.75) echo ' selected="selected"' ?>><?php echo $lang_admin_options['UTC+05:45'] ?></option>
 266:                                             <option value="6"<?php if ($pun_config['o_default_timezone'] == 6) echo ' selected="selected"' ?>><?php echo $lang_admin_options['UTC+06:00'] ?></option>
 267:                                             <option value="6.5"<?php if ($pun_config['o_default_timezone'] == 6.5) echo ' selected="selected"' ?>><?php echo $lang_admin_options['UTC+06:30'] ?></option>
 268:                                             <option value="7"<?php if ($pun_config['o_default_timezone'] == 7) echo ' selected="selected"' ?>><?php echo $lang_admin_options['UTC+07:00'] ?></option>
 269:                                             <option value="8"<?php if ($pun_config['o_default_timezone'] == 8) echo ' selected="selected"' ?>><?php echo $lang_admin_options['UTC+08:00'] ?></option>
 270:                                             <option value="8.75"<?php if ($pun_config['o_default_timezone'] == 8.75) echo ' selected="selected"' ?>><?php echo $lang_admin_options['UTC+08:45'] ?></option>
 271:                                             <option value="9"<?php if ($pun_config['o_default_timezone'] == 9) echo ' selected="selected"' ?>><?php echo $lang_admin_options['UTC+09:00'] ?></option>
 272:                                             <option value="9.5"<?php if ($pun_config['o_default_timezone'] == 9.5) echo ' selected="selected"' ?>><?php echo $lang_admin_options['UTC+09:30'] ?></option>
 273:                                             <option value="10"<?php if ($pun_config['o_default_timezone'] == 10) echo ' selected="selected"' ?>><?php echo $lang_admin_options['UTC+10:00'] ?></option>
 274:                                             <option value="10.5"<?php if ($pun_config['o_default_timezone'] == 10.5) echo ' selected="selected"' ?>><?php echo $lang_admin_options['UTC+10:30'] ?></option>
 275:                                             <option value="11"<?php if ($pun_config['o_default_timezone'] == 11) echo ' selected="selected"' ?>><?php echo $lang_admin_options['UTC+11:00'] ?></option>
 276:                                             <option value="11.5"<?php if ($pun_config['o_default_timezone'] == 11.5) echo ' selected="selected"' ?>><?php echo $lang_admin_options['UTC+11:30'] ?></option>
 277:                                             <option value="12"<?php if ($pun_config['o_default_timezone'] == 12) echo ' selected="selected"' ?>><?php echo $lang_admin_options['UTC+12:00'] ?></option>
 278:                                             <option value="12.75"<?php if ($pun_config['o_default_timezone'] == 12.75) echo ' selected="selected"' ?>><?php echo $lang_admin_options['UTC+12:45'] ?></option>
 279:                                             <option value="13"<?php if ($pun_config['o_default_timezone'] == 13) echo ' selected="selected"' ?>><?php echo $lang_admin_options['UTC+13:00'] ?></option>
 280:                                             <option value="14"<?php if ($pun_config['o_default_timezone'] == 14) echo ' selected="selected"' ?>><?php echo $lang_admin_options['UTC+14:00'] ?></option>
 281:                                         </select>
 282:                                         <span><?php echo $lang_admin_options['Timezone help'] ?></span>
 283:                                     </td>
 284:                                 </tr>
 285:                                 <tr>
 286:                                     <th scope="row"><?php echo $lang_admin_options['DST label'] ?></th>
 287:                                     <td>
 288:                                         <input type="radio" name="form[default_dst]" value="1"<?php if ($pun_config['o_default_dst'] == '1') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="form[default_dst]" value="0"<?php if ($pun_config['o_default_dst'] == '0') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
 289:                                         <span><?php echo $lang_admin_options['DST help'] ?></span>
 290:                                     </td>
 291:                                 </tr>
 292:                                 <tr>
 293:                                     <th scope="row"><?php echo $lang_admin_options['Language label'] ?></th>
 294:                                     <td>
 295:                                         <select name="form[default_lang]">
 296: <?php
 297: 
 298:         $languages = forum_list_langs();
 299: 
 300:         foreach ($languages as $temp)
 301:         {
 302:             if ($pun_config['o_default_lang'] == $temp)
 303:                 echo "\t\t\t\t\t\t\t\t\t\t\t".'<option value="'.$temp.'" selected="selected">'.$temp.'</option>'."\n";
 304:             else
 305:                 echo "\t\t\t\t\t\t\t\t\t\t\t".'<option value="'.$temp.'">'.$temp.'</option>'."\n";
 306:         }
 307: 
 308: ?>
 309:                                         </select>
 310:                                         <span><?php echo $lang_admin_options['Language help'] ?></span>
 311:                                     </td>
 312:                                 </tr>
 313:                                 <tr>
 314:                                     <th scope="row"><?php echo $lang_admin_options['Default style label'] ?></th>
 315:                                     <td>
 316:                                         <select name="form[default_style]">
 317: <?php
 318: 
 319:         $styles = forum_list_styles();
 320: 
 321:         foreach ($styles as $temp)
 322:         {
 323:             if ($pun_config['o_default_style'] == $temp)
 324:                 echo "\t\t\t\t\t\t\t\t\t\t\t".'<option value="'.$temp.'" selected="selected">'.str_replace('_', ' ', $temp).'</option>'."\n";
 325:             else
 326:                 echo "\t\t\t\t\t\t\t\t\t\t\t".'<option value="'.$temp.'">'.str_replace('_', ' ', $temp).'</option>'."\n";
 327:         }
 328: 
 329: ?>
 330:                                         </select>
 331:                                         <span><?php echo $lang_admin_options['Default style help'] ?></span>
 332:                                     </td>
 333:                                 </tr>
 334:                             </table>
 335:                         </div>
 336:                     </fieldset>
 337:                 </div>
 338: <?php
 339: 
 340:     $diff = ($pun_user['timezone'] + $pun_user['dst']) * 3600;
 341:     $timestamp = time() + $diff;
 342: 
 343: ?>
 344:                 <div class="inform">
 345:                     <fieldset>
 346:                         <legend><?php echo $lang_admin_options['Timeouts subhead'] ?></legend>
 347:                         <div class="infldset">
 348:                             <table class="aligntop" cellspacing="0">
 349:                                 <tr>
 350:                                     <th scope="row"><?php echo $lang_admin_options['Time format label'] ?></th>
 351:                                     <td>
 352:                                         <input type="text" name="form[time_format]" size="25" maxlength="25" value="<?php echo pun_htmlspecialchars($pun_config['o_time_format']) ?>" />
 353:                                         <span><?php printf($lang_admin_options['Time format help'], gmdate($pun_config['o_time_format'], $timestamp), '<a href="http://www.php.net/manual/en/function.date.php">'.$lang_admin_options['PHP manual'].'</a>') ?></span>
 354:                                     </td>
 355:                                 </tr>
 356:                                 <tr>
 357:                                     <th scope="row"><?php echo $lang_admin_options['Date format label'] ?></th>
 358:                                     <td>
 359:                                         <input type="text" name="form[date_format]" size="25" maxlength="25" value="<?php echo pun_htmlspecialchars($pun_config['o_date_format']) ?>" />
 360:                                         <span><?php printf($lang_admin_options['Date format help'], gmdate($pun_config['o_date_format'], $timestamp), '<a href="http://www.php.net/manual/en/function.date.php">'.$lang_admin_options['PHP manual'].'</a>') ?></span>
 361:                                     </td>
 362:                                 </tr>
 363:                                 <tr>
 364:                                     <th scope="row"><?php echo $lang_admin_options['Visit timeout label'] ?></th>
 365:                                     <td>
 366:                                         <input type="text" name="form[timeout_visit]" size="5" maxlength="5" value="<?php echo $pun_config['o_timeout_visit'] ?>" />
 367:                                         <span><?php echo $lang_admin_options['Visit timeout help'] ?></span>
 368:                                     </td>
 369:                                 </tr>
 370:                                 <tr>
 371:                                     <th scope="row"><?php echo $lang_admin_options['Online timeout label'] ?></th>
 372:                                     <td>
 373:                                         <input type="text" name="form[timeout_online]" size="5" maxlength="5" value="<?php echo $pun_config['o_timeout_online'] ?>" />
 374:                                         <span><?php echo $lang_admin_options['Online timeout help'] ?></span>
 375:                                     </td>
 376:                                 </tr>
 377:                                 <tr>
 378:                                     <th scope="row"><?php echo $lang_admin_options['Redirect time label'] ?></th>
 379:                                     <td>
 380:                                         <input type="text" name="form[redirect_delay]" size="3" maxlength="3" value="<?php echo $pun_config['o_redirect_delay'] ?>" />
 381:                                         <span><?php echo $lang_admin_options['Redirect time help'] ?></span>
 382:                                     </td>
 383:                                 </tr>
 384:                             </table>
 385:                         </div>
 386:                     </fieldset>
 387:                 </div>
 388:                 <div class="inform">
 389:                     <fieldset>
 390:                         <legend><?php echo $lang_admin_options['Display subhead'] ?></legend>
 391:                         <div class="infldset">
 392:                             <table class="aligntop" cellspacing="0">
 393:                                 <tr>
 394:                                     <th scope="row"><?php echo $lang_admin_options['Version number label'] ?></th>
 395:                                     <td>
 396:                                         <input type="radio" name="form[show_version]" value="1"<?php if ($pun_config['o_show_version'] == '1') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="form[show_version]" value="0"<?php if ($pun_config['o_show_version'] == '0') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
 397:                                         <span><?php echo $lang_admin_options['Version number help'] ?></span>
 398:                                     </td>
 399:                                 </tr>
 400:                                 <tr>
 401:                                     <th scope="row"><?php echo $lang_admin_options['Info in posts label'] ?></th>
 402:                                     <td>
 403:                                         <input type="radio" name="form[show_user_info]" value="1"<?php if ($pun_config['o_show_user_info'] == '1') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="form[show_user_info]" value="0"<?php if ($pun_config['o_show_user_info'] == '0') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
 404:                                         <span><?php echo $lang_admin_options['Info in posts help'] ?></span>
 405:                                     </td>
 406:                                 </tr>
 407:                                 <tr>
 408:                                     <th scope="row"><?php echo $lang_admin_options['Post count label'] ?></th>
 409:                                     <td>
 410:                                         <input type="radio" name="form[show_post_count]" value="1"<?php if ($pun_config['o_show_post_count'] == '1') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="form[show_post_count]" value="0"<?php if ($pun_config['o_show_post_count'] == '0') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
 411:                                         <span><?php echo $lang_admin_options['Post count help'] ?></span>
 412:                                     </td>
 413:                                 </tr>
 414:                                 <tr>
 415:                                     <th scope="row"><?php echo $lang_admin_options['Smilies label'] ?></th>
 416:                                     <td>
 417:                                         <input type="radio" name="form[smilies]" value="1"<?php if ($pun_config['o_smilies'] == '1') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="form[smilies]" value="0"<?php if ($pun_config['o_smilies'] == '0') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
 418:                                         <span><?php echo $lang_admin_options['Smilies help'] ?></span>
 419:                                     </td>
 420:                                 </tr>
 421:                                 <tr>
 422:                                     <th scope="row"><?php echo $lang_admin_options['Smilies sigs label'] ?></th>
 423:                                     <td>
 424:                                         <input type="radio" name="form[smilies_sig]" value="1"<?php if ($pun_config['o_smilies_sig'] == '1') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="form[smilies_sig]" value="0"<?php if ($pun_config['o_smilies_sig'] == '0') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
 425:                                         <span><?php echo $lang_admin_options['Smilies sigs help'] ?></span>
 426:                                     </td>
 427:                                 </tr>
 428:                                 <tr>
 429:                                     <th scope="row"><?php echo $lang_admin_options['Clickable links label'] ?></th>
 430:                                     <td>
 431:                                         <input type="radio" name="form[make_links]" value="1"<?php if ($pun_config['o_make_links'] == '1') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="form[make_links]" value="0"<?php if ($pun_config['o_make_links'] == '0') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
 432:                                         <span><?php echo $lang_admin_options['Clickable links help'] ?></span>
 433:                                     </td>
 434:                                 </tr>
 435:                                 <tr>
 436:                                     <th scope="row"><?php echo $lang_admin_options['Topic review label'] ?></th>
 437:                                     <td>
 438:                                         <input type="text" name="form[topic_review]" size="3" maxlength="3" value="<?php echo $pun_config['o_topic_review'] ?>" />
 439:                                         <span><?php echo $lang_admin_options['Topic review help'] ?></span>
 440:                                     </td>
 441:                                 </tr>
 442:                                 <tr>
 443:                                     <th scope="row"><?php echo $lang_admin_options['Topics per page label'] ?></th>
 444:                                     <td>
 445:                                         <input type="text" name="form[disp_topics_default]" size="3" maxlength="3" value="<?php echo $pun_config['o_disp_topics_default'] ?>" />
 446:                                         <span><?php echo $lang_admin_options['Topics per page help'] ?></span>
 447:                                     </td>
 448:                                 </tr>
 449:                                 <tr>
 450:                                     <th scope="row"><?php echo $lang_admin_options['Posts per page label'] ?></th>
 451:                                     <td>
 452:                                         <input type="text" name="form[disp_posts_default]" size="3" maxlength="3" value="<?php echo $pun_config['o_disp_posts_default'] ?>" />
 453:                                         <span><?php echo $lang_admin_options['Posts per page help'] ?></span>
 454:                                     </td>
 455:                                 </tr>
 456:                                 <tr>
 457:                                     <th scope="row"><?php echo $lang_admin_options['Indent label'] ?></th>
 458:                                     <td>
 459:                                         <input type="text" name="form[indent_num_spaces]" size="3" maxlength="3" value="<?php echo $pun_config['o_indent_num_spaces'] ?>" />
 460:                                         <span><?php echo $lang_admin_options['Indent help'] ?></span>
 461:                                     </td>
 462:                                 </tr>
 463:                                 <tr>
 464:                                     <th scope="row"><?php echo $lang_admin_options['Quote depth label'] ?></th>
 465:                                     <td>
 466:                                         <input type="text" name="form[quote_depth]" size="3" maxlength="3" value="<?php echo $pun_config['o_quote_depth'] ?>" />
 467:                                         <span><?php echo $lang_admin_options['Quote depth help'] ?></span>
 468:                                     </td>
 469:                                 </tr>
 470:                             </table>
 471:                         </div>
 472:                     </fieldset>
 473:                 </div>
 474:                 <div class="inform">
 475:                     <fieldset>
 476:                         <legend><?php echo $lang_admin_options['Features subhead'] ?></legend>
 477:                         <div class="infldset">
 478:                             <table class="aligntop" cellspacing="0">
 479:                                 <tr>
 480:                                     <th scope="row"><?php echo $lang_admin_options['Quick post label'] ?></th>
 481:                                     <td>
 482:                                         <input type="radio" name="form[quickpost]" value="1"<?php if ($pun_config['o_quickpost'] == '1') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="form[quickpost]" value="0"<?php if ($pun_config['o_quickpost'] == '0') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
 483:                                         <span><?php echo $lang_admin_options['Quick post help'] ?></span>
 484:                                     </td>
 485:                                 </tr>
 486:                                 <tr>
 487:                                     <th scope="row"><?php echo $lang_admin_options['Users online label'] ?></th>
 488:                                     <td>
 489:                                         <input type="radio" name="form[users_online]" value="1"<?php if ($pun_config['o_users_online'] == '1') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="form[users_online]" value="0"<?php if ($pun_config['o_users_online'] == '0') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
 490:                                         <span><?php echo $lang_admin_options['Users online help'] ?></span>
 491:                                     </td>
 492:                                 </tr>
 493:                                 <tr>
 494:                                     <th scope="row"><a name="censoring"><?php echo $lang_admin_options['Censor words label'] ?></a></th>
 495:                                     <td>
 496:                                         <input type="radio" name="form[censoring]" value="1"<?php if ($pun_config['o_censoring'] == '1') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="form[censoring]" value="0"<?php if ($pun_config['o_censoring'] == '0') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
 497:                                         <span><?php printf($lang_admin_options['Censor words help'], '<a href="admin_censoring.php">'.$lang_admin_common['Censoring'].'</a>') ?></span>
 498:                                     </td>
 499:                                 </tr>
 500:                                 <tr>
 501:                                     <th scope="row"><a name="signatures"><?php echo $lang_admin_options['Signatures label'] ?></a></th>
 502:                                     <td>
 503:                                         <input type="radio" name="form[signatures]" value="1"<?php if ($pun_config['o_signatures'] == '1') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="form[signatures]" value="0"<?php if ($pun_config['o_signatures'] == '0') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
 504:                                         <span><?php echo $lang_admin_options['Signatures help'] ?></span>
 505:                                     </td>
 506:                                 </tr>
 507:                                 <tr>
 508:                                     <th scope="row"><a name="ranks"><?php echo $lang_admin_options['User ranks label'] ?></a></th>
 509:                                     <td>
 510:                                         <input type="radio" name="form[ranks]" value="1"<?php if ($pun_config['o_ranks'] == '1') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="form[ranks]" value="0"<?php if ($pun_config['o_ranks'] == '0') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
 511:                                         <span><?php printf($lang_admin_options['User ranks help'], '<a href="admin_ranks.php">'.$lang_admin_common['Ranks'].'</a>') ?></span>
 512:                                     </td>
 513:                                 </tr>
 514:                                 <tr>
 515:                                     <th scope="row"><?php echo $lang_admin_options['User has posted label'] ?></th>
 516:                                     <td>
 517:                                         <input type="radio" name="form[show_dot]" value="1"<?php if ($pun_config['o_show_dot'] == '1') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="form[show_dot]" value="0"<?php if ($pun_config['o_show_dot'] == '0') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
 518:                                         <span><?php echo $lang_admin_options['User has posted help'] ?></span>
 519:                                     </td>
 520:                                 </tr>
 521:                                 <tr>
 522:                                     <th scope="row"><?php echo $lang_admin_options['Topic views label'] ?></th>
 523:                                     <td>
 524:                                         <input type="radio" name="form[topic_views]" value="1"<?php if ($pun_config['o_topic_views'] == '1') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="form[topic_views]" value="0"<?php if ($pun_config['o_topic_views'] == '0') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
 525:                                         <span><?php echo $lang_admin_options['Topic views help'] ?></span>
 526:                                     </td>
 527:                                 </tr>
 528:                                 <tr>
 529:                                     <th scope="row"><?php echo $lang_admin_options['Quick jump label'] ?></th>
 530:                                     <td>
 531:                                         <input type="radio" name="form[quickjump]" value="1"<?php if ($pun_config['o_quickjump'] == '1') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="form[quickjump]" value="0"<?php if ($pun_config['o_quickjump'] == '0') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
 532:                                         <span><?php echo $lang_admin_options['Quick jump help'] ?></span>
 533:                                     </td>
 534:                                 </tr>
 535:                                 <tr>
 536:                                     <th scope="row"><?php echo $lang_admin_options['GZip label'] ?></th>
 537:                                     <td>
 538:                                         <input type="radio" name="form[gzip]" value="1"<?php if ($pun_config['o_gzip'] == '1') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="form[gzip]" value="0"<?php if ($pun_config['o_gzip'] == '0') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
 539:                                         <span><?php echo $lang_admin_options['GZip help'] ?></span>
 540:                                     </td>
 541:                                 </tr>
 542:                                 <tr>
 543:                                     <th scope="row"><?php echo $lang_admin_options['Search all label'] ?></th>
 544:                                     <td>
 545:                                         <input type="radio" name="form[search_all_forums]" value="1"<?php if ($pun_config['o_search_all_forums'] == '1') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="form[search_all_forums]" value="0"<?php if ($pun_config['o_search_all_forums'] == '0') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
 546:                                         <span><?php echo $lang_admin_options['Search all help'] ?></span>
 547:                                     </td>
 548:                                 </tr>
 549:                                 <tr>
 550:                                     <th scope="row"><?php echo $lang_admin_options['Menu items label'] ?></th>
 551:                                     <td>
 552:                                         <textarea name="form[additional_navlinks]" rows="3" cols="55"><?php echo pun_htmlspecialchars($pun_config['o_additional_navlinks']) ?></textarea>
 553:                                         <span><?php echo $lang_admin_options['Menu items help'] ?></span>
 554:                                     </td>
 555:                                 </tr>
 556:                                 <tr>
 557:                                     <th scope="row"><?php echo $lang_admin_options['Default feed label'] ?></th>
 558:                                     <td>
 559:                                         <input type="radio" name="form[feed_type]" value="0"<?php if ($pun_config['o_feed_type'] == '0') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_options['None'] ?></strong>&#160;&#160;&#160;<input type="radio" name="form[feed_type]" value="1"<?php if ($pun_config['o_feed_type'] == '1') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_options['RSS'] ?></strong>&#160;&#160;&#160;<input type="radio" name="form[feed_type]" value="2"<?php if ($pun_config['o_feed_type'] == '2') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_options['Atom'] ?></strong>
 560:                                         <span><?php echo $lang_admin_options['Default feed help'] ?></span>
 561:                                     </td>
 562:                                 </tr>
 563:                             </table>
 564:                         </div>
 565:                     </fieldset>
 566:                 </div>
 567:                 <div class="inform">
 568:                     <fieldset>
 569:                         <legend><?php echo $lang_admin_options['Reports subhead'] ?></legend>
 570:                         <div class="infldset">
 571:                             <table class="aligntop" cellspacing="0">
 572:                                 <tr>
 573:                                     <th scope="row"><?php echo $lang_admin_options['Reporting method label'] ?></th>
 574:                                     <td>
 575:                                         <input type="radio" name="form[report_method]" value="0"<?php if ($pun_config['o_report_method'] == '0') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_options['Internal'] ?></strong>&#160;&#160;&#160;<input type="radio" name="form[report_method]" value="1"<?php if ($pun_config['o_report_method'] == '1') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_options['By e-mail'] ?></strong>&#160;&#160;&#160;<input type="radio" name="form[report_method]" value="2"<?php if ($pun_config['o_report_method'] == '2') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_options['Both'] ?></strong>
 576:                                         <span><?php echo $lang_admin_options['Reporting method help'] ?></span>
 577:                                     </td>
 578:                                 </tr>
 579:                                 <tr>
 580:                                     <th scope="row"><?php echo $lang_admin_options['Mailing list label'] ?></th>
 581:                                     <td>
 582:                                         <textarea name="form[mailing_list]" rows="5" cols="55"><?php echo pun_htmlspecialchars($pun_config['o_mailing_list']) ?></textarea>
 583:                                         <span><?php echo $lang_admin_options['Mailing list help'] ?></span>
 584:                                     </td>
 585:                                 </tr>
 586:                             </table>
 587:                         </div>
 588:                     </fieldset>
 589:                 </div>
 590:                 <div class="inform">
 591:                     <fieldset>
 592:                         <legend><?php echo $lang_admin_options['Avatars subhead'] ?></legend>
 593:                         <div class="infldset">
 594:                             <table class="aligntop" cellspacing="0">
 595:                                 <tr>
 596:                                     <th scope="row"><?php echo $lang_admin_options['Use avatars label'] ?></th>
 597:                                     <td>
 598:                                         <input type="radio" name="form[avatars]" value="1"<?php if ($pun_config['o_avatars'] == '1') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="form[avatars]" value="0"<?php if ($pun_config['o_avatars'] == '0') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
 599:                                         <span><?php echo $lang_admin_options['Use avatars help'] ?></span>
 600:                                     </td>
 601:                                 </tr>
 602:                                 <tr>
 603:                                     <th scope="row"><?php echo $lang_admin_options['Upload directory label'] ?></th>
 604:                                     <td>
 605:                                         <input type="text" name="form[avatars_dir]" size="35" maxlength="50" value="<?php echo pun_htmlspecialchars($pun_config['o_avatars_dir']) ?>" />
 606:                                         <span><?php echo $lang_admin_options['Upload directory help'] ?></span>
 607:                                     </td>
 608:                                 </tr>
 609:                                 <tr>
 610:                                     <th scope="row"><?php echo $lang_admin_options['Max width label'] ?></th>
 611:                                     <td>
 612:                                         <input type="text" name="form[avatars_width]" size="5" maxlength="5" value="<?php echo $pun_config['o_avatars_width'] ?>" />
 613:                                         <span><?php echo $lang_admin_options['Max width help'] ?></span>
 614:                                     </td>
 615:                                 </tr>
 616:                                 <tr>
 617:                                     <th scope="row"><?php echo $lang_admin_options['Max height label'] ?></th>
 618:                                     <td>
 619:                                         <input type="text" name="form[avatars_height]" size="5" maxlength="5" value="<?php echo $pun_config['o_avatars_height'] ?>" />
 620:                                         <span><?php echo $lang_admin_options['Max height help'] ?></span>
 621:                                     </td>
 622:                                 </tr>
 623:                                 <tr>
 624:                                     <th scope="row"><?php echo $lang_admin_options['Max size label'] ?></th>
 625:                                     <td>
 626:                                         <input type="text" name="form[avatars_size]" size="6" maxlength="6" value="<?php echo $pun_config['o_avatars_size'] ?>" />
 627:                                         <span><?php echo $lang_admin_options['Max size help'] ?></span>
 628:                                     </td>
 629:                                 </tr>
 630:                             </table>
 631:                         </div>
 632:                     </fieldset>
 633:                 </div>
 634:                 <div class="inform">
 635:                     <fieldset>
 636:                         <legend><?php echo $lang_admin_options['E-mail subhead'] ?></legend>
 637:                         <div class="infldset">
 638:                             <table class="aligntop" cellspacing="0">
 639:                                 <tr>
 640:                                     <th scope="row"><?php echo $lang_admin_options['Admin e-mail label'] ?></th>
 641:                                     <td>
 642:                                         <input type="text" name="form[admin_email]" size="50" maxlength="80" value="<?php echo $pun_config['o_admin_email'] ?>" />
 643:                                         <span><?php echo $lang_admin_options['Admin e-mail help'] ?></span>
 644:                                     </td>
 645:                                 </tr>
 646:                                 <tr>
 647:                                     <th scope="row"><?php echo $lang_admin_options['Webmaster e-mail label'] ?></th>
 648:                                     <td>
 649:                                         <input type="text" name="form[webmaster_email]" size="50" maxlength="80" value="<?php echo $pun_config['o_webmaster_email'] ?>" />
 650:                                         <span><?php echo $lang_admin_options['Webmaster e-mail help'] ?></span>
 651:                                     </td>
 652:                                 </tr>
 653:                                 <tr>
 654:                                     <th scope="row"><?php echo $lang_admin_options['Subscriptions label'] ?></th>
 655:                                     <td>
 656:                                         <input type="radio" name="form[subscriptions]" value="1"<?php if ($pun_config['o_subscriptions'] == '1') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="form[subscriptions]" value="0"<?php if ($pun_config['o_subscriptions'] == '0') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
 657:                                         <span><?php echo $lang_admin_options['Subscriptions help'] ?></span>
 658:                                     </td>
 659:                                 </tr>
 660:                                 <tr>
 661:                                     <th scope="row"><?php echo $lang_admin_options['SMTP address label'] ?></th>
 662:                                     <td>
 663:                                         <input type="text" name="form[smtp_host]" size="30" maxlength="100" value="<?php echo pun_htmlspecialchars($pun_config['o_smtp_host']) ?>" />
 664:                                         <span><?php echo $lang_admin_options['SMTP address help'] ?></span>
 665:                                     </td>
 666:                                 </tr>
 667:                                 <tr>
 668:                                     <th scope="row"><?php echo $lang_admin_options['SMTP username label'] ?></th>
 669:                                     <td>
 670:                                         <input type="text" name="form[smtp_user]" size="25" maxlength="50" value="<?php echo pun_htmlspecialchars($pun_config['o_smtp_user']) ?>" />
 671:                                         <span><?php echo $lang_admin_options['SMTP username help'] ?></span>
 672:                                     </td>
 673:                                 </tr>
 674:                                 <tr>
 675:                                     <th scope="row"><?php echo $lang_admin_options['SMTP password label'] ?></th>
 676:                                     <td>
 677:                                         <input type="text" name="form[smtp_pass]" size="25" maxlength="50" value="<?php echo pun_htmlspecialchars($pun_config['o_smtp_pass']) ?>" />
 678:                                         <span><?php echo $lang_admin_options['SMTP password help'] ?></span>
 679:                                     </td>
 680:                                 </tr>
 681:                                 <tr>
 682:                                     <th scope="row"><?php echo $lang_admin_options['SMTP SSL label'] ?></th>
 683:                                     <td>
 684:                                         <input type="radio" name="form[smtp_ssl]" value="1"<?php if ($pun_config['o_smtp_ssl'] == '1') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="form[smtp_ssl]" value="0"<?php if ($pun_config['o_smtp_ssl'] == '0') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
 685:                                         <span><?php echo $lang_admin_options['SMTP SSL help'] ?></span>
 686:                                     </td>
 687:                                 </tr>
 688:                             </table>
 689:                         </div>
 690:                     </fieldset>
 691:                 </div>
 692:                 <div class="inform">
 693:                     <fieldset>
 694:                         <legend><?php echo $lang_admin_options['Registration subhead'] ?></legend>
 695:                         <div class="infldset">
 696:                             <table class="aligntop" cellspacing="0">
 697:                                 <tr>
 698:                                     <th scope="row"><?php echo $lang_admin_options['Allow new label'] ?></th>
 699:                                     <td>
 700:                                         <input type="radio" name="form[regs_allow]" value="1"<?php if ($pun_config['o_regs_allow'] == '1') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="form[regs_allow]" value="0"<?php if ($pun_config['o_regs_allow'] == '0') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
 701:                                         <span><?php echo $lang_admin_options['Allow new help'] ?></span>
 702:                                     </td>
 703:                                 </tr>
 704:                                 <tr>
 705:                                     <th scope="row"><?php echo $lang_admin_options['Verify label'] ?></th>
 706:                                     <td>
 707:                                         <input type="radio" name="form[regs_verify]" value="1"<?php if ($pun_config['o_regs_verify'] == '1') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="form[regs_verify]" value="0"<?php if ($pun_config['o_regs_verify'] == '0') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
 708:                                         <span><?php echo $lang_admin_options['Verify help'] ?></span>
 709:                                     </td>
 710:                                 </tr>
 711:                                 <tr>
 712:                                     <th scope="row"><?php echo $lang_admin_options['Report new label'] ?></th>
 713:                                     <td>
 714:                                         <input type="radio" name="form[regs_report]" value="1"<?php if ($pun_config['o_regs_report'] == '1') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="form[regs_report]" value="0"<?php if ($pun_config['o_regs_report'] == '0') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
 715:                                         <span><?php echo $lang_admin_options['Report new help'] ?></span>
 716:                                     </td>
 717:                                 </tr>
 718:                                 <tr>
 719:                                     <th scope="row"><?php echo $lang_admin_options['Use rules label'] ?></th>
 720:                                     <td>
 721:                                         <input type="radio" name="form[rules]" value="1"<?php if ($pun_config['o_rules'] == '1') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="form[rules]" value="0"<?php if ($pun_config['o_rules'] == '0') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
 722:                                         <span><?php echo $lang_admin_options['Use rules help'] ?></span>
 723:                                     </td>
 724:                                 </tr>
 725:                                 <tr>
 726:                                     <th scope="row"><?php echo $lang_admin_options['Rules label'] ?></th>
 727:                                     <td>
 728:                                         <textarea name="form[rules_message]" rows="10" cols="55"><?php echo pun_htmlspecialchars($pun_config['o_rules_message']) ?></textarea>
 729:                                         <span><?php echo $lang_admin_options['Rules help'] ?></span>
 730:                                     </td>
 731:                                 </tr>
 732:                                 <tr>
 733:                                     <th scope="row"><?php echo $lang_admin_options['E-mail default label'] ?></th>
 734:                                     <td>
 735:                                         <span><?php echo $lang_admin_options['E-mail default help'] ?></span>
 736:                                         <input type="radio" name="form[default_email_setting]" value="0"<?php if ($pun_config['o_default_email_setting'] == '0') echo ' checked="checked"' ?> />&#160;<?php echo $lang_admin_options['Display e-mail label'] ?><br />
 737:                                         <input type="radio" name="form[default_email_setting]" value="1"<?php if ($pun_config['o_default_email_setting'] == '1') echo ' checked="checked"' ?> />&#160;<?php echo $lang_admin_options['Hide allow form label'] ?><br />
 738:                                         <input type="radio" name="form[default_email_setting]" value="2"<?php if ($pun_config['o_default_email_setting'] == '2') echo ' checked="checked"' ?> />&#160;<?php echo $lang_admin_options['Hide both label'] ?><br />
 739:                                     </td>
 740:                                 </tr>
 741:                             </table>
 742:                         </div>
 743:                     </fieldset>
 744:                 </div>
 745:                 <div class="inform">
 746:                     <fieldset>
 747:                         <legend><?php echo $lang_admin_options['Announcement subhead'] ?></legend>
 748:                         <div class="infldset">
 749:                             <table class="aligntop" cellspacing="0">
 750:                                 <tr>
 751:                                     <th scope="row"><?php echo $lang_admin_options['Display announcement label'] ?></th>
 752:                                     <td>
 753:                                         <input type="radio" name="form[announcement]" value="1"<?php if ($pun_config['o_announcement'] == '1') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="form[announcement]" value="0"<?php if ($pun_config['o_announcement'] == '0') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
 754:                                         <span><?php echo $lang_admin_options['Display announcement help'] ?></span>
 755:                                     </td>
 756:                                 </tr>
 757:                                 <tr>
 758:                                     <th scope="row"><?php echo $lang_admin_options['Announcement message label'] ?></th>
 759:                                     <td>
 760:                                         <textarea name="form[announcement_message]" rows="5" cols="55"><?php echo pun_htmlspecialchars($pun_config['o_announcement_message']) ?></textarea>
 761:                                         <span><?php echo $lang_admin_options['Announcement message help'] ?></span>
 762:                                     </td>
 763:                                 </tr>
 764:                             </table>
 765:                         </div>
 766:                     </fieldset>
 767:                 </div>
 768:                 <div class="inform">
 769:                     <fieldset>
 770:                         <legend><?php echo $lang_admin_options['Maintenance subhead'] ?></legend>
 771:                         <div class="infldset">
 772:                             <table class="aligntop" cellspacing="0">
 773:                                 <tr>
 774:                                     <th scope="row"><a name="maintenance"><?php echo $lang_admin_options['Maintenance mode label'] ?></a></th>
 775:                                     <td>
 776:                                         <input type="radio" name="form[maintenance]" value="1"<?php if ($pun_config['o_maintenance'] == '1') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="form[maintenance]" value="0"<?php if ($pun_config['o_maintenance'] == '0') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
 777:                                         <span><?php echo $lang_admin_options['Maintenance mode help'] ?></span>
 778:                                     </td>
 779:                                 </tr>
 780:                                 <tr>
 781:                                     <th scope="row"><?php echo $lang_admin_options['Maintenance message label'] ?></th>
 782:                                     <td>
 783:                                         <textarea name="form[maintenance_message]" rows="5" cols="55"><?php echo pun_htmlspecialchars($pun_config['o_maintenance_message']) ?></textarea>
 784:                                         <span><?php echo $lang_admin_options['Maintenance message help'] ?></span>
 785:                                     </td>
 786:                                 </tr>
 787:                             </table>
 788:                         </div>
 789:                     </fieldset>
 790:                 </div>
 791:                 <p class="submitend"><input type="submit" name="save" value="<?php echo $lang_admin_common['Save changes'] ?>" /></p>
 792:             </form>
 793:         </div>
 794:     </div>
 795:     <div class="clearer"></div>
 796: </div>
 797: <?php
 798: 
 799: require PUN_ROOT.'footer.php';


/dev/null b/admin_permissions.php
   1: <?php
   2: 
   3: /**
   4:  * Copyright (C) 2008-2010 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:  */
   8: 
   9: // Tell header.php to use the admin template
  10: define('PUN_ADMIN_CONSOLE', 1);
  11: 
  12: define('PUN_ROOT', './');
  13: require PUN_ROOT.'include/common.php';
  14: require PUN_ROOT.'include/common_admin.php';
  15: 
  16: 
  17: if ($pun_user['g_id'] != PUN_ADMIN)
  18:     message($lang_common['No permission']);
  19: 
  20: // Load the admin_permissions.php language file
  21: require PUN_ROOT.'lang/'.$admin_language.'/admin_permissions.php';
  22: 
  23: if (isset($_POST['form_sent']))
  24: {
  25:     confirm_referrer('admin_permissions.php');
  26: 
  27:     $form = array_map('intval', $_POST['form']);
  28: 
  29:     foreach ($form as $key => $input)
  30:     {
  31:         // Only update values that have changed
  32:         if (array_key_exists('p_'.$key, $pun_config) && $pun_config['p_'.$key] != $input)
  33:             $db->query('UPDATE '.$db->prefix.'config SET conf_value='.$input.' WHERE conf_name=\'p_'.$db->escape($key).'\'') or error('Unable to update board config', __FILE__, __LINE__, $db->error());
  34:     }
  35: 
  36:     // Regenerate the config cache
  37:     if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
  38:         require PUN_ROOT.'include/cache.php';
  39: 
  40:     generate_config_cache();
  41: 
  42:     redirect('admin_permissions.php', $lang_admin_permissions['Perms updated redirect']);
  43: }
  44: 
  45: $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_admin_common['Admin'], $lang_admin_common['Permissions']);
  46: define('PUN_ACTIVE_PAGE', 'admin');
  47: require PUN_ROOT.'header.php';
  48: 
  49: generate_admin_menu('permissions');
  50: 
  51: ?>
  52:     <div class="blockform">
  53:         <h2><span><?php echo $lang_admin_permissions['Permissions head'] ?></span></h2>
  54:         <div class="box">
  55:             <form method="post" action="admin_permissions.php">
  56:                 <p class="submittop"><input type="submit" name="save" value="<?php echo $lang_admin_common['Save changes'] ?>" /></p>
  57:                 <div class="inform">
  58:                     <input type="hidden" name="form_sent" value="1" />
  59:                     <fieldset>
  60:                         <legend><?php echo $lang_admin_permissions['Posting subhead'] ?></legend>
  61:                         <div class="infldset">
  62:                             <table class="aligntop" cellspacing="0">
  63:                                 <tr>
  64:                                     <th scope="row"><?php echo $lang_admin_permissions['BBCode label'] ?></th>
  65:                                     <td>
  66:                                         <input type="radio" name="form[message_bbcode]" value="1"<?php if ($pun_config['p_message_bbcode'] == '1') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="form[message_bbcode]" value="0"<?php if ($pun_config['p_message_bbcode'] == '0') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
  67:                                         <span><?php echo $lang_admin_permissions['BBCode help'] ?></span>
  68:                                     </td>
  69:                                 </tr>
  70:                                 <tr>
  71:                                     <th scope="row"><?php echo $lang_admin_permissions['Image tag label'] ?></th>
  72:                                     <td>
  73:                                         <input type="radio" name="form[message_img_tag]" value="1"<?php if ($pun_config['p_message_img_tag'] == '1') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="form[message_img_tag]" value="0"<?php if ($pun_config['p_message_img_tag'] == '0') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
  74:                                         <span><?php echo $lang_admin_permissions['Image tag help'] ?></span>
  75:                                     </td>
  76:                                 </tr>
  77:                                 <tr>
  78:                                     <th scope="row"><?php echo $lang_admin_permissions['All caps message label'] ?></th>
  79:                                     <td>
  80:                                         <input type="radio" name="form[message_all_caps]" value="1"<?php if ($pun_config['p_message_all_caps'] == '1') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="form[message_all_caps]" value="0"<?php if ($pun_config['p_message_all_caps'] == '0') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
  81:                                         <span><?php echo $lang_admin_permissions['All caps message help'] ?></span>
  82:                                     </td>
  83:                                 </tr>
  84:                                 <tr>
  85:                                     <th scope="row"><?php echo $lang_admin_permissions['All caps subject label'] ?></th>
  86:                                     <td>
  87:                                         <input type="radio" name="form[subject_all_caps]" value="1"<?php if ($pun_config['p_subject_all_caps'] == '1') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="form[subject_all_caps]" value="0"<?php if ($pun_config['p_subject_all_caps'] == '0') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
  88:                                         <span><?php echo $lang_admin_permissions['All caps subject help'] ?></span>
  89:                                     </td>
  90:                                 </tr>
  91:                                 <tr>
  92:                                     <th scope="row"><?php echo $lang_admin_permissions['Require e-mail label'] ?></th>
  93:                                     <td>
  94:                                         <input type="radio" name="form[force_guest_email]" value="1"<?php if ($pun_config['p_force_guest_email'] == '1') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="form[force_guest_email]" value="0"<?php if ($pun_config['p_force_guest_email'] == '0') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
  95:                                         <span><?php echo $lang_admin_permissions['Require e-mail help'] ?></span>
  96:                                     </td>
  97:                                 </tr>
  98:                             </table>
  99:                         </div>
 100:                     </fieldset>
 101:                 </div>
 102:                 <div class="inform">
 103:                     <fieldset>
 104:                         <legend><?php echo $lang_admin_permissions['Signatures subhead'] ?></legend>
 105:                         <div class="infldset">
 106:                             <table class="aligntop" cellspacing="0">
 107:                                 <tr>
 108:                                     <th scope="row"><?php echo $lang_admin_permissions['BBCode sigs label'] ?></th>
 109:                                     <td>
 110:                                         <input type="radio" name="form[sig_bbcode]" value="1"<?php if ($pun_config['p_sig_bbcode'] == '1') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="form[sig_bbcode]" value="0"<?php if ($pun_config['p_sig_bbcode'] == '0') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
 111:                                         <span><?php echo $lang_admin_permissions['BBCode sigs help'] ?></span>
 112:                                     </td>
 113:                                 </tr>
 114:                                 <tr>
 115:                                     <th scope="row"><?php echo $lang_admin_permissions['Image tag sigs label'] ?></th>
 116:                                     <td>
 117:                                         <input type="radio" name="form[sig_img_tag]" value="1"<?php if ($pun_config['p_sig_img_tag'] == '1') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="form[sig_img_tag]" value="0"<?php if ($pun_config['p_sig_img_tag'] == '0') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
 118:                                         <span><?php echo $lang_admin_permissions['Image tag sigs help'] ?></span>
 119:                                     </td>
 120:                                 </tr>
 121:                                 <tr>
 122:                                     <th scope="row"><?php echo $lang_admin_permissions['All caps sigs label'] ?></th>
 123:                                     <td>
 124:                                         <input type="radio" name="form[sig_all_caps]" value="1"<?php if ($pun_config['p_sig_all_caps'] == '1') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="form[sig_all_caps]" value="0"<?php if ($pun_config['p_sig_all_caps'] == '0') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
 125:                                         <span><?php echo $lang_admin_permissions['All caps sigs help'] ?></span>
 126:                                     </td>
 127:                                 </tr>
 128:                                 <tr>
 129:                                     <th scope="row"><?php echo $lang_admin_permissions['Max sig length label'] ?></th>
 130:                                     <td>
 131:                                         <input type="text" name="form[sig_length]" size="5" maxlength="5" value="<?php echo $pun_config['p_sig_length'] ?>" />
 132:                                         <span><?php echo $lang_admin_permissions['Max sig length help'] ?></span>
 133:                                     </td>
 134:                                 </tr>
 135:                                 <tr>
 136:                                     <th scope="row"><?php echo $lang_admin_permissions['Max sig lines label'] ?></th>
 137:                                     <td>
 138:                                         <input type="text" name="form[sig_lines]" size="3" maxlength="3" value="<?php echo $pun_config['p_sig_lines'] ?>" />
 139:                                         <span><?php echo $lang_admin_permissions['Max sig lines help'] ?></span>
 140:                                     </td>
 141:                                 </tr>
 142:                             </table>
 143:                         </div>
 144:                     </fieldset>
 145:                 </div>
 146:                 <div class="inform">
 147:                     <fieldset>
 148:                         <legend><?php echo $lang_admin_permissions['Registration subhead'] ?></legend>
 149:                         <div class="infldset">
 150:                             <table class="aligntop" cellspacing="0">
 151:                                 <tr>
 152:                                     <th scope="row"><?php echo $lang_admin_permissions['Banned e-mail label'] ?></th>
 153:                                     <td>
 154:                                         <input type="radio" name="form[allow_banned_email]" value="1"<?php if ($pun_config['p_allow_banned_email'] == '1') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="form[allow_banned_email]" value="0"<?php if ($pun_config['p_allow_banned_email'] == '0') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
 155:                                         <span><?php echo $lang_admin_permissions['Banned e-mail help'] ?></span>
 156:                                     </td>
 157:                                 </tr>
 158:                                 <tr>
 159:                                     <th scope="row"><?php echo $lang_admin_permissions['Duplicate e-mail label'] ?></th>
 160:                                     <td>
 161:                                         <input type="radio" name="form[allow_dupe_email]" value="1"<?php if ($pun_config['p_allow_dupe_email'] == '1') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="form[allow_dupe_email]" value="0"<?php if ($pun_config['p_allow_dupe_email'] == '0') echo ' checked="checked"' ?> />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
 162:                                         <span><?php echo $lang_admin_permissions['Duplicate e-mail help'] ?></span>
 163:                                     </td>
 164:                                 </tr>
 165:                             </table>
 166:                         </div>
 167:                     </fieldset>
 168:                 </div>
 169:                 <p class="submitend"><input type="submit" name="save" value="<?php echo $lang_admin_common['Save changes'] ?>" /></p>
 170:             </form>
 171:         </div>
 172:     </div>
 173:     <div class="clearer"></div>
 174: </div>
 175: <?php
 176: 
 177: require PUN_ROOT.'footer.php';


/dev/null b/admin_prune.php
   1: <?php
   2: 
   3: /**
   4:  * Copyright (C) 2008-2010 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:  */
   8: 
   9: // Tell header.php to use the admin template
  10: define('PUN_ADMIN_CONSOLE', 1);
  11: 
  12: define('PUN_ROOT', './');
  13: require PUN_ROOT.'include/common.php';
  14: require PUN_ROOT.'include/common_admin.php';
  15: 
  16: 
  17: if ($pun_user['g_id'] != PUN_ADMIN)
  18:     message($lang_common['No permission']);
  19: 
  20: // Load the admin_prune.php language file
  21: require PUN_ROOT.'lang/'.$admin_language.'/admin_prune.php';
  22: 
  23: if (isset($_GET['action']) || isset($_POST['prune']) || isset($_POST['prune_comply']))
  24: {
  25:     $prune_from = trim($_POST['prune_from']);
  26:     $prune_sticky = intval($_POST['prune_sticky']);
  27: 
  28:     if (isset($_POST['prune_comply']))
  29:     {
  30:         confirm_referrer('admin_prune.php');
  31: 
  32:         $prune_days = intval($_POST['prune_days']);
  33:         $prune_date = ($prune_days) ? time() - ($prune_days * 86400) : -1;
  34: 
  35:         @set_time_limit(0);
  36: 
  37:         if ($prune_from == 'all')
  38:         {
  39:             $result = $db->query('SELECT id FROM '.$db->prefix.'forums') or error('Unable to fetch forum list', __FILE__, __LINE__, $db->error());
  40:             $num_forums = $db->num_rows($result);
  41: 
  42:             for ($i = 0; $i < $num_forums; ++$i)
  43:             {
  44:                 $fid = $db->result($result, $i);
  45: 
  46:                 prune($fid, $prune_sticky, $prune_date);
  47:                 update_forum($fid);
  48:             }
  49:         }
  50:         else
  51:         {
  52:             $prune_from = intval($prune_from);
  53:             prune($prune_from, $prune_sticky, $prune_date);
  54:             update_forum($prune_from);
  55:         }
  56: 
  57:         // Locate any "orphaned redirect topics" and delete them
  58:         $result = $db->query('SELECT t1.id FROM '.$db->prefix.'topics AS t1 LEFT JOIN '.$db->prefix.'topics AS t2 ON t1.moved_to=t2.id WHERE t2.id IS NULL AND t1.moved_to IS NOT NULL') or error('Unable to fetch redirect topics', __FILE__, __LINE__, $db->error());
  59:         $num_orphans = $db->num_rows($result);
  60: 
  61:         if ($num_orphans)
  62:         {
  63:             for ($i = 0; $i < $num_orphans; ++$i)
  64:                 $orphans[] = $db->result($result, $i);
  65: 
  66:             $db->query('DELETE FROM '.$db->prefix.'topics WHERE id IN('.implode(',', $orphans).')') or error('Unable to delete redirect topics', __FILE__, __LINE__, $db->error());
  67:         }
  68: 
  69:         redirect('admin_prune.php', $lang_admin_prune['Posts pruned redirect']);
  70:     }
  71: 
  72:     $prune_days = trim($_POST['req_prune_days']);
  73:     if ($prune_days == '' || preg_match('/[^0-9]/', $prune_days))
  74:         message($lang_admin_prune['Must be integer message']);
  75: 
  76:     $prune_date = time() - ($prune_days * 86400);
  77: 
  78:     // Concatenate together the query for counting number of topics to prune
  79:     $sql = 'SELECT COUNT(id) FROM '.$db->prefix.'topics WHERE last_post<'.$prune_date.' AND moved_to IS NULL';
  80: 
  81:     if ($prune_sticky == '0')
  82:         $sql .= ' AND sticky=\'0\'';
  83: 
  84:     if ($prune_from != 'all')
  85:     {
  86:         $prune_from = intval($prune_from);
  87:         $sql .= ' AND forum_id='.$prune_from;
  88: 
  89:         // Fetch the forum name (just for cosmetic reasons)
  90:         $result = $db->query('SELECT forum_name FROM '.$db->prefix.'forums WHERE id='.$prune_from) or error('Unable to fetch forum name', __FILE__, __LINE__, $db->error());
  91:         $forum = '"'.pun_htmlspecialchars($db->result($result)).'"';
  92:     }
  93:     else
  94:         $forum = $lang_admin_prune['All forums'];
  95: 
  96:     $result = $db->query($sql) or error('Unable to fetch topic prune count', __FILE__, __LINE__, $db->error());
  97:     $num_topics = $db->result($result);
  98: 
  99:     if (!$num_topics)
 100:         message(sprintf($lang_admin_prune['No old topics message'], $prune_days));
 101: 
 102: 
 103:     $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_admin_common['Admin'], $lang_admin_common['Prune']);
 104:     define('PUN_ACTIVE_PAGE', 'admin');
 105:     require PUN_ROOT.'header.php';
 106: 
 107:     generate_admin_menu('prune');
 108: 
 109: ?>
 110:     <div class="blockform">
 111:         <h2><span><?php echo $lang_admin_prune['Prune head'] ?></span></h2>
 112:         <div class="box">
 113:             <form method="post" action="admin_prune.php?action=foo">
 114:                 <div class="inform">
 115:                     <input type="hidden" name="prune_days" value="<?php echo $prune_days ?>" />
 116:                     <input type="hidden" name="prune_sticky" value="<?php echo $prune_sticky ?>" />
 117:                     <input type="hidden" name="prune_from" value="<?php echo $prune_from ?>" />
 118:                     <fieldset>
 119:                         <legend><?php echo $lang_admin_prune['Confirm prune subhead'] ?></legend>
 120:                         <div class="infldset">
 121:                             <p><?php printf($lang_admin_prune['Confirm prune info'], $prune_days, $forum, forum_number_format($num_topics)) ?></p>
 122:                             <p class="warntext"><?php echo $lang_admin_prune['Confirm prune warn'] ?></p>
 123:                         </div>
 124:                     </fieldset>
 125:                 </div>
 126:                 <p class="buttons"><input type="submit" name="prune_comply" value="<?php echo $lang_admin_common['Prune'] ?>" /><a href="javascript:history.go(-1)"><?php echo $lang_admin_common['Go back'] ?></a></p>
 127:             </form>
 128:         </div>
 129:     </div>
 130:     <div class="clearer"></div>
 131: </div>
 132: <?php
 133: 
 134:     require PUN_ROOT.'footer.php';
 135: }
 136: 
 137: 
 138: else
 139: {
 140:     $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_admin_common['Admin'], $lang_admin_common['Prune']);
 141:     $required_fields = array('req_prune_days' => $lang_admin_prune['Days old label']);
 142:     $focus_element = array('prune', 'req_prune_days');
 143:     define('PUN_ACTIVE_PAGE', 'admin');
 144:     require PUN_ROOT.'header.php';
 145: 
 146:     generate_admin_menu('prune');
 147: 
 148: ?>
 149:     <div class="blockform">
 150:         <h2><span><?php echo $lang_admin_prune['Prune head'] ?></span></h2>
 151:         <div class="box">
 152:             <form id="prune" method="post" action="admin_prune.php?action=foo" onsubmit="return process_form(this)">
 153:                 <div class="inform">
 154:                     <input type="hidden" name="form_sent" value="1" />
 155:                     <fieldset>
 156:                         <legend><?php echo $lang_admin_prune['Prune subhead'] ?></legend>
 157:                         <div class="infldset">
 158:                             <table class="aligntop" cellspacing="0">
 159:                                 <tr>
 160:                                     <th scope="row"><?php echo $lang_admin_prune['Days old label'] ?></th>
 161:                                     <td>
 162:                                         <input type="text" name="req_prune_days" size="3" maxlength="3" tabindex="1" />
 163:                                         <span><?php echo $lang_admin_prune['Days old help'] ?></span>
 164:                                     </td>
 165:                                 </tr>
 166:                                 <tr>
 167:                                     <th scope="row"><?php echo $lang_admin_prune['Prune sticky label'] ?></th>
 168:                                     <td>
 169:                                         <input type="radio" name="prune_sticky" value="1" tabindex="2" checked="checked" />&#160;<strong><?php echo $lang_admin_common['Yes'] ?></strong>&#160;&#160;&#160;<input type="radio" name="prune_sticky" value="0" />&#160;<strong><?php echo $lang_admin_common['No'] ?></strong>
 170:                                         <span><?php echo $lang_admin_prune['Prune sticky help'] ?></span>
 171:                                     </td>
 172:                                 </tr>
 173:                                 <tr>
 174:                                     <th scope="row"><?php echo $lang_admin_prune['Prune from label'] ?></th>
 175:                                     <td>
 176:                                         <select name="prune_from" tabindex="3">
 177:                                             <option value="all"><?php echo $lang_admin_prune['All forums'] ?></option>
 178: <?php
 179: 
 180:     $result = $db->query('SELECT c.id AS cid, c.cat_name, f.id AS fid, f.forum_name FROM '.$db->prefix.'categories AS c INNER JOIN '.$db->prefix.'forums AS f ON c.id=f.cat_id WHERE f.redirect_url IS NULL ORDER BY c.disp_position, c.id, f.disp_position') or error('Unable to fetch category/forum list', __FILE__, __LINE__, $db->error());
 181: 
 182:     $cur_category = 0;
 183:     while ($forum = $db->fetch_assoc($result))
 184:     {
 185:         if ($forum['cid'] != $cur_category) // Are we still in the same category?
 186:         {
 187:             if ($cur_category)
 188:                 echo "\t\t\t\t\t\t\t\t\t\t\t".'</optgroup>'."\n";
 189: 
 190:             echo "\t\t\t\t\t\t\t\t\t\t\t".'<optgroup label="'.pun_htmlspecialchars($forum['cat_name']).'">'."\n";
 191:             $cur_category = $forum['cid'];
 192:         }
 193: 
 194:         echo "\t\t\t\t\t\t\t\t\t\t\t\t".'<option value="'.$forum['fid'].'">'.pun_htmlspecialchars($forum['forum_name']).'</option>'."\n";
 195:     }
 196: 
 197: ?>
 198:                                             </optgroup>
 199:                                         </select>
 200:                                         <span><?php echo $lang_admin_prune['Prune from help'] ?></span>
 201:                                     </td>
 202:                                 </tr>
 203:                             </table>
 204:                             <p class="topspace"><?php printf($lang_admin_prune['Prune info'], '<a href="admin_options.php#maintenance">'.$lang_admin_common['Maintenance mode'].'</a>') ?></p>
 205:                             <div class="fsetsubmit"><input type="submit" name="prune" value="<?php echo $lang_admin_common['Prune'] ?>" tabindex="5" /></div>
 206:                         </div>
 207:                     </fieldset>
 208:                 </div>
 209:             </form>
 210:         </div>
 211:     </div>
 212:     <div class="clearer"></div>
 213: </div>
 214: <?php
 215: 
 216:     require PUN_ROOT.'footer.php';
 217: }


/dev/null b/admin_ranks.php
   1: <?php
   2: 
   3: /**
   4:  * Copyright (C) 2008-2010 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:  */
   8: 
   9: // Tell header.php to use the admin template
  10: define('PUN_ADMIN_CONSOLE', 1);
  11: 
  12: define('PUN_ROOT', './');
  13: require PUN_ROOT.'include/common.php';
  14: require PUN_ROOT.'include/common_admin.php';
  15: 
  16: 
  17: if ($pun_user['g_id'] != PUN_ADMIN)
  18:     message($lang_common['No permission']);
  19: 
  20: // Load the admin_ranks.php language file
  21: require PUN_ROOT.'lang/'.$admin_language.'/admin_ranks.php';
  22: 
  23: // Add a rank
  24: if (isset($_POST['add_rank']))
  25: {
  26:     confirm_referrer('admin_ranks.php');
  27: 
  28:     $rank = pun_trim($_POST['new_rank']);
  29:     $min_posts = trim($_POST['new_min_posts']);
  30: 
  31:     if ($rank == '')
  32:         message($lang_admin_ranks['Must enter title message']);
  33: 
  34:     if ($min_posts == '' || preg_match('/[^0-9]/', $min_posts))
  35:         message($lang_admin_ranks['Must be integer message']);
  36: 
  37:     // Make sure there isn't already a rank with the same min_posts value
  38:     $result = $db->query('SELECT 1 FROM '.$db->prefix.'ranks WHERE min_posts='.$min_posts) or error('Unable to fetch rank info', __FILE__, __LINE__, $db->error());
  39:     if ($db->num_rows($result))
  40:         message(sprintf($lang_admin_ranks['Dupe min posts message'], $min_posts));
  41: 
  42:     $db->query('INSERT INTO '.$db->prefix.'ranks (rank, min_posts) VALUES(\''.$db->escape($rank).'\', '.$min_posts.')') or error('Unable to add rank', __FILE__, __LINE__, $db->error());
  43: 
  44:     // Regenerate the ranks cache
  45:     if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
  46:         require PUN_ROOT.'include/cache.php';
  47: 
  48:     generate_ranks_cache();
  49: 
  50:     redirect('admin_ranks.php', $lang_admin_ranks['Rank added redirect']);
  51: }
  52: 
  53: 
  54: // Update a rank
  55: else if (isset($_POST['update']))
  56: {
  57:     confirm_referrer('admin_ranks.php');
  58: 
  59:     $id = intval(key($_POST['update']));
  60: 
  61:     $rank = pun_trim($_POST['rank'][$id]);
  62:     $min_posts = trim($_POST['min_posts'][$id]);
  63: 
  64:     if ($rank == '')
  65:         message($lang_admin_ranks['Must enter title message']);
  66: 
  67:     if ($min_posts == '' || preg_match('/[^0-9]/', $min_posts))
  68:         message($lang_admin_ranks['Must be integer message']);
  69: 
  70:     // Make sure there isn't already a rank with the same min_posts value
  71:     $result = $db->query('SELECT 1 FROM '.$db->prefix.'ranks WHERE id!='.$id.' AND min_posts='.$min_posts) or error('Unable to fetch rank info', __FILE__, __LINE__, $db->error());
  72:     if ($db->num_rows($result))
  73:         message(sprintf($lang_admin_ranks['Dupe min posts message'], $min_posts));
  74: 
  75:     $db->query('UPDATE '.$db->prefix.'ranks SET rank=\''.$db->escape($rank).'\', min_posts='.$min_posts.' WHERE id='.$id) or error('Unable to update rank', __FILE__, __LINE__, $db->error());
  76: 
  77:     // Regenerate the ranks cache
  78:     if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
  79:         require PUN_ROOT.'include/cache.php';
  80: 
  81:     generate_ranks_cache();
  82: 
  83:     redirect('admin_ranks.php', $lang_admin_ranks['Rank updated redirect']);
  84: }
  85: 
  86: 
  87: // Remove a rank
  88: else if (isset($_POST['remove']))
  89: {
  90:     confirm_referrer('admin_ranks.php');
  91: 
  92:     $id = intval(key($_POST['remove']));
  93: 
  94:     $db->query('DELETE FROM '.$db->prefix.'ranks WHERE id='.$id) or error('Unable to delete rank', __FILE__, __LINE__, $db->error());
  95: 
  96:     // Regenerate the ranks cache
  97:     if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
  98:         require PUN_ROOT.'include/cache.php';
  99: 
 100:     generate_ranks_cache();
 101: 
 102:     redirect('admin_ranks.php', $lang_admin_ranks['Rank removed redirect']);
 103: }
 104: 
 105: $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_admin_common['Admin'], $lang_admin_common['Ranks']);
 106: $focus_element = array('ranks', 'new_rank');
 107: define('PUN_ACTIVE_PAGE', 'admin');
 108: require PUN_ROOT.'header.php';
 109: 
 110: generate_admin_menu('ranks');
 111: 
 112: ?>
 113:     <div class="blockform">
 114:         <h2><span><?php echo $lang_admin_ranks['Ranks head'] ?></span></h2>
 115:         <div class="box">
 116:             <form id="ranks" method="post" action="admin_ranks.php?action=foo">
 117:                 <div class="inform">
 118:                     <fieldset>
 119:                         <legend><?php echo $lang_admin_ranks['Add rank subhead'] ?></legend>
 120:                         <div class="infldset">
 121:                             <p><?php echo $lang_admin_ranks['Add rank info'].' '.($pun_config['o_ranks'] == '1' ? sprintf($lang_admin_ranks['Ranks enabled'], '<a href="admin_options.php#ranks">'.$lang_admin_common['Options'].'</a>') : sprintf($lang_admin_ranks['Ranks disabled'], '<a href="admin_options.php#ranks">'.$lang_admin_common['Options'].'</a>')) ?></p>
 122:                             <table cellspacing="0">
 123:                             <thead>
 124:                                 <tr>
 125:                                     <th class="tcl" scope="col"><?php echo $lang_admin_ranks['Rank title label'] ?></th>
 126:                                     <th class="tc2" scope="col"><?php echo $lang_admin_ranks['Minimum posts label'] ?></th>
 127:                                     <th class="hidehead" scope="col"><?php echo $lang_admin_ranks['Actions label'] ?></th>
 128:                                 </tr>
 129:                             </thead>
 130:                             <tbody>
 131:                                 <tr>
 132:                                     <td class="tcl"><input type="text" name="new_rank" size="24" maxlength="50" tabindex="1" /></td>
 133:                                     <td class="tc2"><input type="text" name="new_min_posts" size="7" maxlength="7" tabindex="2" /></td>
 134:                                     <td><input type="submit" name="add_rank" value="<?php echo $lang_admin_common['Add'] ?>" tabindex="3" /></td>
 135:                                 </tr>
 136:                             </tbody>
 137:                             </table>
 138:                         </div>
 139:                     </fieldset>
 140:                 </div>
 141:                 <div class="inform">
 142:                     <fieldset>
 143:                         <legend><?php echo $lang_admin_ranks['Edit remove subhead'] ?></legend>
 144:                         <div class="infldset">
 145: <?php
 146: 
 147: $result = $db->query('SELECT id, rank, min_posts FROM '.$db->prefix.'ranks ORDER BY min_posts') or error('Unable to fetch rank list', __FILE__, __LINE__, $db->error());
 148: if ($db->num_rows($result))
 149: {
 150: 
 151: ?>
 152:                             <table cellspacing="0">
 153:                             <thead>
 154:                                 <tr>
 155:                                     <th class="tcl" scope="col"><?php echo $lang_admin_ranks['Rank title label'] ?></th>
 156:                                     <th class="tc2" scope="col"><?php echo $lang_admin_ranks['Minimum posts label'] ?></th>
 157:                                     <th class="hidehead" scope="col"><?php echo $lang_admin_ranks['Actions label'] ?></th>
 158:                                 </tr>
 159:                             </thead>
 160:                             <tbody>
 161: <?php
 162: 
 163:     while ($cur_rank = $db->fetch_assoc($result))
 164:         echo "\t\t\t\t\t\t\t\t".'<tr><td class="tcl"><input type="text" name="rank['.$cur_rank['id'].']" value="'.pun_htmlspecialchars($cur_rank['rank']).'" size="24" maxlength="50" /></td><td class="tc2"><input type="text" name="min_posts['.$cur_rank['id'].']" value="'.$cur_rank['min_posts'].'" size="7" maxlength="7" /></td><td><input type="submit" name="update['.$cur_rank['id'].']" value="'.$lang_admin_common['Update'].'" />&#160;<input type="submit" name="remove['.$cur_rank['id'].']" value="'.$lang_admin_common['Remove'].'" /></td></tr>'."\n";
 165: 
 166: ?>
 167:                             </tbody>
 168:                             </table>
 169: <?php
 170: 
 171: }
 172: else
 173:     echo "\t\t\t\t\t\t\t".'<p>'.$lang_admin_ranks['No ranks in list'].'</p>'."\n";
 174: 
 175: ?>
 176:                         </div>
 177:                     </fieldset>
 178:                 </div>
 179:             </form>
 180:         </div>
 181:     </div>
 182:     <div class="clearer"></div>
 183: </div>
 184: <?php
 185: 
 186: require PUN_ROOT.'footer.php';


/dev/null b/admin_reports.php
   1: <?php
   2: 
   3: /**
   4:  * Copyright (C) 2008-2010 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:  */
   8: 
   9: // Tell header.php to use the admin template
  10: define('PUN_ADMIN_CONSOLE', 1);
  11: 
  12: define('PUN_ROOT', './');
  13: require PUN_ROOT.'include/common.php';
  14: require PUN_ROOT.'include/common_admin.php';
  15: 
  16: 
  17: if (!$pun_user['is_admmod'])
  18:     message($lang_common['No permission']);
  19: 
  20: // Load the admin_reports.php language file
  21: require PUN_ROOT.'lang/'.$admin_language.'/admin_reports.php';
  22: 
  23: // Zap a report
  24: if (isset($_POST['zap_id']))
  25: {
  26:     confirm_referrer('admin_reports.php');
  27: 
  28:     $zap_id = intval(key($_POST['zap_id']));
  29: 
  30:     $result = $db->query('SELECT zapped FROM '.$db->prefix.'reports WHERE id='.$zap_id) or error('Unable to fetch report info', __FILE__, __LINE__, $db->error());
  31:     $zapped = $db->result($result);
  32: 
  33:     if ($zapped == '')
  34:         $db->query('UPDATE '.$db->prefix.'reports SET zapped='.time().', zapped_by='.$pun_user['id'].' WHERE id='.$zap_id) or error('Unable to zap report', __FILE__, __LINE__, $db->error());
  35: 
  36:     redirect('admin_reports.php', $lang_admin_reports['Report zapped redirect']);
  37: }
  38: 
  39: 
  40: $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_admin_common['Admin'], $lang_admin_common['Reports']);
  41: define('PUN_ACTIVE_PAGE', 'admin');
  42: require PUN_ROOT.'header.php';
  43: 
  44: generate_admin_menu('reports');
  45: 
  46: ?>
  47:     <div class="blockform">
  48:         <h2><span><?php echo $lang_admin_reports['New reports head'] ?></span></h2>
  49:         <div class="box">
  50:             <form method="post" action="admin_reports.php?action=zap">
  51: <?php
  52: 
  53: $result = $db->query('SELECT r.id, r.topic_id, r.forum_id, r.reported_by, r.created, r.message, p.id AS pid, t.subject, f.forum_name, u.username AS reporter FROM '.$db->prefix.'reports AS r LEFT JOIN '.$db->prefix.'posts AS p ON r.post_id=p.id LEFT JOIN '.$db->prefix.'topics AS t ON r.topic_id=t.id LEFT JOIN '.$db->prefix.'forums AS f ON r.forum_id=f.id LEFT JOIN '.$db->prefix.'users AS u ON r.reported_by=u.id WHERE r.zapped IS NULL ORDER BY created DESC') or error('Unable to fetch report list', __FILE__, __LINE__, $db->error());
  54: 
  55: if ($db->num_rows($result))
  56: {
  57:     while ($cur_report = $db->fetch_assoc($result))
  58:     {
  59:         $reporter = ($cur_report['reporter'] != '') ? '<a href="profile.php?id='.$cur_report['reported_by'].'">'.pun_htmlspecialchars($cur_report['reporter']).'</a>' : $lang_admin_reports['Deleted user'];
  60:         $forum = ($cur_report['forum_name'] != '') ? '<span><a href="viewforum.php?id='.$cur_report['forum_id'].'">'.pun_htmlspecialchars($cur_report['forum_name']).'</a></span>' : '<span>'.$lang_admin_reports['Deleted'].'</span>';
  61:         $topic = ($cur_report['subject'] != '') ? '<span>»&#160;<a href="viewtopic.php?id='.$cur_report['topic_id'].'">'.pun_htmlspecialchars($cur_report['subject']).'</a></span>' : '<span>»&#160;'.$lang_admin_reports['Deleted'].'</span>';
  62:         $post = str_replace("\n", '<br />', pun_htmlspecialchars($cur_report['message']));
  63:         $post_id = ($cur_report['pid'] != '') ? '<span>»&#160;<a href="viewtopic.php?pid='.$cur_report['pid'].'#p'.$cur_report['pid'].'">Post #'.$cur_report['pid'].'</a></span>' : '<span>»&#160;'.$lang_admin_reports['Deleted'].'</span>';
  64:         $report_location = array($forum, $topic, $post_id);
  65: 
  66: ?>
  67:                 <div class="inform">
  68:                     <fieldset>
  69:                         <legend><?php printf($lang_admin_reports['Report subhead'], format_time($cur_report['created'])) ?></legend>
  70:                         <div class="infldset">
  71:                             <table class="aligntop" cellspacing="0">
  72:                                 <tr>
  73:                                     <th scope="row"><?php printf($lang_admin_reports['Reported by'], $reporter) ?></th>
  74:                                     <td class="location"><?php echo implode(' ', $report_location) ?></td>
  75:                                 </tr>
  76:                                 <tr>
  77:                                     <th scope="row"><?php echo $lang_admin_reports['Reason'] ?><div><input type="submit" name="zap_id[<?php echo $cur_report['id'] ?>]" value="<?php echo $lang_admin_reports['Zap'] ?>" /></div></th>
  78:                                     <td><?php echo $post ?></td>
  79:                                 </tr>
  80:                             </table>
  81:                         </div>
  82:                     </fieldset>
  83:                 </div>
  84: <?php
  85: 
  86:     }
  87: }
  88: else
  89: {
  90: 
  91: ?>
  92:                 <div class="inform">
  93:                     <fieldset>
  94:                         <legend><?php echo $lang_admin_common['None'] ?></legend>
  95:                         <div class="infldset">
  96:                             <p><?php echo $lang_admin_reports['No new reports'] ?></p>
  97:                         </div>
  98:                     </fieldset>
  99:                 </div>
 100: <?php
 101: 
 102: }
 103: 
 104: ?>
 105:             </form>
 106:         </div>
 107:     </div>
 108: 
 109:     <div class="blockform block2">
 110:         <h2><span><?php echo $lang_admin_reports['Last 10 head'] ?></span></h2>
 111:         <div class="box">
 112:             <div class="fakeform">
 113: <?php
 114: 
 115: $result = $db->query('SELECT r.id, r.topic_id, r.forum_id, r.reported_by, r.message, r.zapped, r.zapped_by AS zapped_by_id, p.id AS pid, t.subject, f.forum_name, u.username AS reporter, u2.username AS zapped_by FROM '.$db->prefix.'reports AS r LEFT JOIN '.$db->prefix.'posts AS p ON r.post_id=p.id LEFT JOIN '.$db->prefix.'topics AS t ON r.topic_id=t.id LEFT JOIN '.$db->prefix.'forums AS f ON r.forum_id=f.id LEFT JOIN '.$db->prefix.'users AS u ON r.reported_by=u.id LEFT JOIN '.$db->prefix.'users AS u2 ON r.zapped_by=u2.id WHERE r.zapped IS NOT NULL ORDER BY zapped DESC LIMIT 10') or error('Unable to fetch report list', __FILE__, __LINE__, $db->error());
 116: 
 117: if ($db->num_rows($result))
 118: {
 119:     while ($cur_report = $db->fetch_assoc($result))
 120:     {
 121:         $reporter = ($cur_report['reporter'] != '') ? '<a href="profile.php?id='.$cur_report['reported_by'].'">'.pun_htmlspecialchars($cur_report['reporter']).'</a>' : $lang_admin_reports['Deleted user'];
 122:         $forum = ($cur_report['forum_name'] != '') ? '<span><a href="viewforum.php?id='.$cur_report['forum_id'].'">'.pun_htmlspecialchars($cur_report['forum_name']).'</a></span>' : '<span>'.$lang_admin_reports['Deleted'].'</span>';
 123:         $topic = ($cur_report['subject'] != '') ? '<span>»&#160;<a href="viewtopic.php?id='.$cur_report['topic_id'].'">'.pun_htmlspecialchars($cur_report['subject']).'</a></span>' : '<span>»&#160;'.$lang_admin_reports['Deleted'].'</span>';
 124:         $post = str_replace("\n", '<br />', pun_htmlspecialchars($cur_report['message']));
 125:         $post_id = ($cur_report['pid'] != '') ? '<span>»&#160;<a href="viewtopic.php?pid='.$cur_report['pid'].'#p'.$cur_report['pid'].'">Post #'.$cur_report['pid'].'</a></span>' : '<span>»&#160;'.$lang_admin_reports['Deleted'].'</span>';
 126:         $zapped_by = ($cur_report['zapped_by'] != '') ? '<a href="profile.php?id='.$cur_report['zapped_by_id'].'">'.pun_htmlspecialchars($cur_report['zapped_by']).'</a>' : $lang_admin_reports['NA'];
 127:         $zapped_by = ($cur_report['zapped_by'] != '') ? '<strong>'.pun_htmlspecialchars($cur_report['zapped_by']).'</strong>' : $lang_admin_reports['NA'];
 128:         $report_location = array($forum, $topic, $post_id);
 129: 
 130: ?>
 131:                 <div class="inform">
 132:                     <fieldset>
 133:                         <legend><?php printf($lang_admin_reports['Zapped subhead'], format_time($cur_report['zapped']), $zapped_by) ?></legend>
 134:                         <div class="infldset">
 135:                             <table class="aligntop" cellspacing="0">
 136:                                 <tr>
 137:                                     <th scope="row"><?php printf($lang_admin_reports['Reported by'], $reporter) ?></th>
 138:                                     <td class="location"><?php echo implode(' ', $report_location) ?></td>
 139:                                 </tr>
 140:                                 <tr>
 141:                                     <th scope="row"><?php echo $lang_admin_reports['Reason'] ?></th>
 142:                                     <td><?php echo $post ?></td>
 143:                                 </tr>
 144:                             </table>
 145:                         </div>
 146:                     </fieldset>
 147:                 </div>
 148: <?php
 149: 
 150:     }
 151: }
 152: else
 153: {
 154: 
 155: ?>
 156:                 <div class="inform">
 157:                     <fieldset>
 158:                         <legend><?php echo $lang_admin_common['None'] ?></legend>
 159:                         <div class="infldset">
 160:                             <p><?php echo $lang_admin_reports['No zapped reports'] ?></p>
 161:                         </div>
 162:                     </fieldset>
 163:                 </div>
 164: <?php
 165: 
 166: }
 167: 
 168: ?>
 169:             </div>
 170:         </div>
 171:     </div>
 172:     <div class="clearer"></div>
 173: </div>
 174: <?php
 175: 
 176: require PUN_ROOT.'footer.php';
  0: 177: 


/dev/null b/admin_users.php
   1: <?php
   2: 
   3: /**
   4:  * Copyright (C) 2008-2010 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:  */
   8: 
   9: // Tell header.php to use the admin template
  10: define('PUN_ADMIN_CONSOLE', 1);
  11: 
  12: define('PUN_ROOT', './');
  13: require PUN_ROOT.'include/common.php';
  14: require PUN_ROOT.'include/common_admin.php';
  15: 
  16: 
  17: if (!$pun_user['is_admmod'])
  18:     message($lang_common['No permission']);
  19: 
  20: // Load the admin_users.php language file
  21: require PUN_ROOT.'lang/'.$admin_language.'/admin_users.php';
  22: 
  23: // Show IP statistics for a certain user ID
  24: if (isset($_GET['ip_stats']))
  25: {
  26:     $ip_stats = intval($_GET['ip_stats']);
  27:     if ($ip_stats < 1)
  28:         message($lang_common['Bad request']);
  29: 
  30:     // Fetch ip count
  31:     $result = $db->query('SELECT poster_ip, MAX(posted) AS last_used FROM '.$db->prefix.'posts WHERE poster_id='.$ip_stats.' GROUP BY poster_ip') or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
  32:     $num_ips = $db->num_rows($result);
  33: 
  34:     // Determine the ip offset (based on $_GET['p'])
  35:     $num_pages = ceil($num_ips / 50);
  36: 
  37:     $p = (!isset($_GET['p']) || $_GET['p'] <= 1 || $_GET['p'] > $num_pages) ? 1 : intval($_GET['p']);
  38:     $start_from = 50 * ($p - 1);
  39: 
  40:     // Generate paging links
  41:     $paging_links = '<span class="pages-label">'.$lang_common['Pages'].' </span>'.paginate($num_pages, $p, 'admin_users.php?ip_stats='.$ip_stats );
  42: 
  43:     $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_admin_common['Admin'], $lang_admin_common['Users'], $lang_admin_users['Results head']);
  44:     define('PUN_ACTIVE_PAGE', 'admin');
  45:     require PUN_ROOT.'header.php';
  46: 
  47: ?>
  48: <div class="linkst">
  49:     <div class="inbox crumbsplus">
  50:         <ul class="crumbs">
  51:             <li><a href="admin_index.php"><?php echo $lang_admin_common['Admin'].' '.$lang_admin_common['Index'] ?></a></li>
  52:             <li><span>»&#160;</span><a href="admin_users.php"><?php echo $lang_admin_common['Users'] ?></a></li>
  53:             <li><span>»&#160;</span><strong><?php echo $lang_admin_users['Results head'] ?></strong></li>
  54:         </ul>
  55:         <div class="pagepost">
  56:             <p class="pagelink"><?php echo $paging_links ?></p>
  57:         </div>
  58:         <div class="clearer"></div>
  59:     </div>
  60: </div>
  61: 
  62: <div id="users1" class="blocktable">
  63:     <h2><span><?php echo $lang_admin_users['Results head'] ?></span></h2>
  64:     <div class="box">
  65:         <div class="inbox">
  66:             <table cellspacing="0">
  67:             <thead>
  68:                 <tr>
  69:                     <th class="tcl" scope="col"><?php echo $lang_admin_users['Results IP address head'] ?></th>
  70:                     <th class="tc2" scope="col"><?php echo $lang_admin_users['Results last used head'] ?></th>
  71:                     <th class="tc3" scope="col"><?php echo $lang_admin_users['Results times found head'] ?></th>
  72:                     <th class="tcr" scope="col"><?php echo $lang_admin_users['Results action head'] ?></th>
  73:                 </tr>
  74:             </thead>
  75:             <tbody>
  76: <?php
  77: 
  78:     $result = $db->query('SELECT poster_ip, MAX(posted) AS last_used, COUNT(id) AS used_times FROM '.$db->prefix.'posts WHERE poster_id='.$ip_stats.' GROUP BY poster_ip ORDER BY last_used DESC LIMIT '.$start_from.', 50') or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
  79:     if ($db->num_rows($result))
  80:     {
  81:         while ($cur_ip = $db->fetch_assoc($result))
  82:         {
  83: 
  84: ?>
  85:                 <tr>
  86:                     <td class="tcl"><a href="moderate.php?get_host=<?php echo $cur_ip['poster_ip'] ?>"><?php echo $cur_ip['poster_ip'] ?></a></td>
  87:                     <td class="tc2"><?php echo format_time($cur_ip['last_used']) ?></td>
  88:                     <td class="tc3"><?php echo $cur_ip['used_times'] ?></td>
  89:                     <td class="tcr"><a href="admin_users.php?show_users=<?php echo $cur_ip['poster_ip'] ?>"><?php echo $lang_admin_users['Results find more link'] ?></a></td>
  90:                 </tr>
  91: <?php
  92: 
  93:         }
  94:     }
  95:     else
  96:         echo "\t\t\t\t".'<tr><td class="tcl" colspan="4">'.$lang_admin_users['Results no posts found'].'</td></tr>'."\n";
  97: 
  98: ?>
  99:             </tbody>
 100:             </table>
 101:         </div>
 102:     </div>
 103: </div>
 104: 
 105: <div class="linksb">
 106:     <div class="inbox crumbsplus">
 107:         <div class="pagepost">
 108:             <p class="pagelink"><?php echo $paging_links ?></p>
 109:         </div>
 110:         <ul class="crumbs">
 111:             <li><a href="admin_index.php"><?php echo $lang_admin_common['Admin'].' '.$lang_admin_common['Index'] ?></a></li>
 112:             <li><span>»&#160;</span><a href="admin_users.php"><?php echo $lang_admin_common['Users'] ?></a></li>
 113:             <li><span>»&#160;</span><strong><?php echo $lang_admin_users['Results head'] ?></strong></li>
 114:         </ul>
 115:         <div class="clearer"></div>
 116:     </div>
 117: </div>
 118: <?php
 119: 
 120:     require PUN_ROOT.'footer.php';
 121: }
 122: 
 123: 
 124: if (isset($_GET['show_users']))
 125: {
 126:     $ip = trim($_GET['show_users']);
 127: 
 128:     if (!@preg_match('/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $ip) && !@preg_match('/^((([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(([0-9A-Fa-f]{1,4}:){0,5}:((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(::([0-9A-Fa-f]{1,4}:){0,5}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))$/', $ip))
 129:         message($lang_admin_users['Bad IP message']);
 130: 
 131:     // Fetch user count
 132:     $result = $db->query('SELECT DISTINCT poster_id, poster FROM '.$db->prefix.'posts WHERE poster_ip=\''.$db->escape($ip).'\'') or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
 133:     $num_users = $db->num_rows($result);
 134: 
 135:     // Determine the user offset (based on $_GET['p'])
 136:     $num_pages = ceil($num_users / 50);
 137: 
 138:     $p = (!isset($_GET['p']) || $_GET['p'] <= 1 || $_GET['p'] > $num_pages) ? 1 : intval($_GET['p']);
 139:     $start_from = 50 * ($p - 1);
 140: 
 141:     // Generate paging links
 142:     $paging_links = '<span class="pages-label">'.$lang_common['Pages'].' </span>'.paginate($num_pages, $p, 'admin_users.php?show_users='.$ip);
 143: 
 144:     $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_admin_common['Admin'], $lang_admin_common['Users'], $lang_admin_users['Results head']);
 145:     define('PUN_ACTIVE_PAGE', 'admin');
 146:     require PUN_ROOT.'header.php';
 147: 
 148: ?>
 149: <div class="linkst">
 150:     <div class="inbox crumbsplus">
 151:         <ul class="crumbs">
 152:             <li><a href="admin_index.php"><?php echo $lang_admin_common['Admin'].' '.$lang_admin_common['Index'] ?></a></li>
 153:             <li><span>»&#160;</span><a href="admin_users.php"><?php echo $lang_admin_common['Users'] ?></a></li>
 154:             <li><span>»&#160;</span><strong><?php echo $lang_admin_users['Results head'] ?></strong></li>
 155:         </ul>
 156:         <div class="pagepost">
 157:             <p class="pagelink"><?php echo $paging_links ?></p>
 158:         </div>
 159:         <div class="clearer"></div>
 160:     </div>
 161: </div>
 162: 
 163: <div id="users2" class="blocktable">
 164:     <h2><span><?php echo $lang_admin_users['Results head'] ?></span></h2>
 165:     <div class="box">
 166:         <div class="inbox">
 167:             <table cellspacing="0">
 168:             <thead>
 169:                 <tr>
 170:                     <th class="tcl" scope="col"><?php echo $lang_admin_users['Results username head'] ?></th>
 171:                     <th class="tc2" scope="col"><?php echo $lang_admin_users['Results e-mail head'] ?></th>
 172:                     <th class="tc3" scope="col"><?php echo $lang_admin_users['Results title head'] ?></th>
 173:                     <th class="tc4" scope="col"><?php echo $lang_admin_users['Results posts head'] ?></th>
 174:                     <th class="tc5" scope="col"><?php echo $lang_admin_users['Results admin note head'] ?></th>
 175:                     <th class="tcr" scope="col"><?php echo $lang_admin_users['Results actions head'] ?></th>
 176:                 </tr>
 177:             </thead>
 178:             <tbody>
 179: <?php
 180: 
 181:     $result = $db->query('SELECT DISTINCT poster_id, poster FROM '.$db->prefix.'posts WHERE poster_ip=\''.$db->escape($ip).'\' ORDER BY poster DESC') or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
 182:     $num_posts = $db->num_rows($result);
 183: 
 184:     if ($num_posts)
 185:     {
 186:         // Loop through users and print out some info
 187:         for ($i = 0; $i < $num_posts; ++$i)
 188:         {
 189:             list($poster_id, $poster) = $db->fetch_row($result);
 190: 
 191:             $result2 = $db->query('SELECT u.id, u.username, u.email, u.title, u.num_posts, u.admin_note, g.g_id, g.g_user_title FROM '.$db->prefix.'users AS u INNER JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id WHERE u.id>1 AND u.id='.$poster_id) or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
 192: 
 193:             if (($user_data = $db->fetch_assoc($result2)))
 194:             {
 195:                 $user_title = get_title($user_data);
 196: 
 197:                 $actions = '<a href="admin_users.php?ip_stats='.$user_data['id'].'">'.$lang_admin_users['Results view IP link'].'</a> | <a href="search.php?action=show_user&amp;user_id='.$user_data['id'].'">'.$lang_admin_users['Results show posts link'].'</a>';
 198: 
 199: ?>
 200:                 <tr>
 201:                     <td class="tcl"><?php echo '<a href="profile.php?id='.$user_data['id'].'">'.pun_htmlspecialchars($user_data['username']).'</a>' ?></td>
 202:                     <td class="tc2"><a href="mailto:<?php echo $user_data['email'] ?>"><?php echo $user_data['email'] ?></a></td>
 203:                     <td class="tc3"><?php echo $user_title ?></td>
 204:                     <td class="tc4"><?php echo forum_number_format($user_data['num_posts']) ?></td>
 205:                     <td class="tc5"><?php echo ($user_data['admin_note'] != '') ? pun_htmlspecialchars($user_data['admin_note']) : '&#160;' ?></td>
 206:                     <td class="tcr"><?php echo $actions ?></td>
 207:                 </tr>
 208: <?php
 209: 
 210:             }
 211:             else
 212:             {
 213: 
 214: ?>
 215:                 <tr>
 216:                     <td class="tcl"><?php echo pun_htmlspecialchars($poster) ?></td>
 217:                     <td class="tc2">&#160;</td>
 218:                     <td class="tc3"><?php echo $lang_admin_users['Results guest'] ?></td>
 219:                     <td class="tc4">&#160;</td>
 220:                     <td class="tc5">&#160;</td>
 221:                     <td class="tcr">&#160;</td>
 222:                 </tr>
 223: <?php
 224: 
 225:             }
 226:         }
 227:     }
 228:     else
 229:         echo "\t\t\t\t".'<tr><td class="tcl" colspan="6">'.$lang_admin_users['Results no IP found'].'</td></tr>'."\n";
 230: 
 231: ?>
 232:             </tbody>
 233:             </table>
 234:         </div>
 235:     </div>
 236: </div>
 237: 
 238: <div class="linksb">
 239:     <div class="inbox crumbsplus">
 240:         <div class="pagepost">
 241:             <p class="pagelink"><?php echo $paging_links ?></p>
 242:         </div>
 243:         <ul class="crumbs">
 244:             <li><a href="admin_index.php"><?php echo $lang_admin_common['Admin'].' '.$lang_admin_common['Index'] ?></a></li>
 245:             <li><span>»&#160;</span><a href="admin_users.php"><?php echo $lang_admin_common['Users'] ?></a></li>
 246:             <li><span>»&#160;</span><strong><?php echo $lang_admin_users['Results head'] ?></strong></li>
 247:         </ul>
 248:         <div class="clearer"></div>
 249:     </div>
 250: </div>
 251: <?php
 252:     require PUN_ROOT.'footer.php';
 253: }
 254: 
 255: 
 256: else if (isset($_GET['find_user']))
 257: {
 258:     $form = isset($_GET['form']) ? $_GET['form'] : array();
 259: 
 260:     // trim() all elements in $form
 261:     $form = array_map('pun_trim', $form);
 262:     $conditions = $query_str = array();
 263: 
 264:     $posts_greater = isset($_GET['posts_greater']) ? trim($_GET['posts_greater']) : '';
 265:     $posts_less = isset($_GET['posts_less']) ? trim($_GET['posts_less']) : '';
 266:     $last_post_after = isset($_GET['last_post_after']) ? trim($_GET['last_post_after']) : '';
 267:     $last_post_before = isset($_GET['last_post_before']) ? trim($_GET['last_post_before']) : '';
 268:     $registered_after = isset($_GET['registered_after']) ? trim($_GET['registered_after']) : '';
 269:     $registered_before = isset($_GET['registered_before']) ? trim($_GET['registered_before']) : '';
 270:     $order_by = isset($_GET['order_by']) && in_array($_GET['order_by'], array('username', 'email', 'num_posts', 'last_post', 'registered')) ? $_GET['order_by'] : 'username';
 271:     $direction = isset($_GET['direction']) && $_GET['direction'] == 'DESC' ? 'DESC' : 'ASC';
 272:     $user_group = isset($_GET['user_group']) ? intval($_GET['user_group']) : -1;
 273: 
 274:     $query_str[] = 'order_by='.$order_by;
 275:     $query_str[] = 'direction='.$direction;
 276:     $query_str[] = 'user_group='.$user_group;
 277: 
 278:     if (preg_match('/[^0-9]/', $posts_greater.$posts_less))
 279:         message($lang_admin_users['Non numeric message']);
 280: 
 281:     // Try to convert date/time to timestamps
 282:     if ($last_post_after != '')
 283:     {
 284:         $query_str[] = 'last_post_after='.$last_post_after;
 285: 
 286:         $last_post_after = strtotime($last_post_after);
 287:         if ($last_post_after === false || $last_post_after == -1)
 288:             message($lang_admin_users['Invalid date time message']);
 289: 
 290:         $conditions[] = 'u.last_post>'.$last_post_after;
 291:     }
 292:     if ($last_post_before != '')
 293:     {
 294:         $query_str[] = 'last_post_before='.$last_post_before;
 295: 
 296:         $last_post_before = strtotime($last_post_before);
 297:         if ($last_post_before === false || $last_post_before == -1)
 298:             message($lang_admin_users['Invalid date time message']);
 299: 
 300:         $conditions[] = 'u.last_post<'.$last_post_before;
 301:     }
 302:     if ($registered_after != '')
 303:     {
 304:         $query_str[] = 'registered_after='.$registered_after;
 305: 
 306:         $registered_after = strtotime($registered_after);
 307:         if ($registered_after === false || $registered_after == -1)
 308:             message($lang_admin_users['Invalid date time message']);
 309: 
 310:         $conditions[] = 'u.registered>'.$registered_after;
 311:     }
 312:     if ($registered_before != '')
 313:     {
 314:         $query_str[] = 'registered_before='.$registered_before;
 315: 
 316:         $registered_before = strtotime($registered_before);
 317:         if ($registered_before === false || $registered_before == -1)
 318:             message($lang_admin_users['Invalid date time message']);
 319: 
 320:         $conditions[] = 'u.registered<'.$registered_before;
 321:     }
 322: 
 323:     $like_command = ($db_type == 'pgsql') ? 'ILIKE' : 'LIKE';
 324:     foreach ($form as $key => $input)
 325:     {
 326:         if ($input != '' && in_array($key, array('username', 'email', 'title', 'realname', 'url', 'jabber', 'icq', 'msn', 'aim', 'yahoo', 'location', 'signature', 'admin_note')))
 327:         {
 328:             $conditions[] = 'u.'.$db->escape($key).' '.$like_command.' \''.$db->escape(str_replace('*', '%', $input)).'\'';
 329:             $query_str[] = 'form%5B'.$key.'%5D='.urlencode($input);
 330:         }
 331:     }
 332: 
 333:     if ($posts_greater != '')
 334:     {
 335:         $query_str[] = 'posts_greater='.$posts_greater;
 336:         $conditions[] = 'u.num_posts>'.$posts_greater;
 337:     }
 338:     if ($posts_less != '')
 339:     {
 340:         $query_str[] = 'posts_less='.$posts_less;
 341:         $conditions[] = 'u.num_posts<'.$posts_less;
 342:     }
 343: 
 344:     if ($user_group > -1)
 345:         $conditions[] = 'u.group_id='.$user_group;
 346: 
 347:     // Fetch user count
 348:     $result = $db->query('SELECT COUNT(id) FROM '.$db->prefix.'users AS u LEFT JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id WHERE u.id>1'.(!empty($conditions) ? ' AND '.implode(' AND ', $conditions) : '')) or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
 349:     $num_users = $db->result($result);
 350: 
 351:     // Determine the user offset (based on $_GET['p'])
 352:     $num_pages = ceil($num_users / 50);
 353: 
 354:     $p = (!isset($_GET['p']) || $_GET['p'] <= 1 || $_GET['p'] > $num_pages) ? 1 : intval($_GET['p']);
 355:     $start_from = 50 * ($p - 1);
 356: 
 357:     // Generate paging links
 358:     $paging_links = '<span class="pages-label">'.$lang_common['Pages'].' </span>'.paginate($num_pages, $p, 'admin_users.php?find_user=&amp;'.implode('&amp;', $query_str));
 359: 
 360:     $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_admin_common['Admin'], $lang_admin_common['Users'], $lang_admin_users['Results head']);
 361:     define('PUN_ACTIVE_PAGE', 'admin');
 362:     require PUN_ROOT.'header.php';
 363: 
 364: ?>
 365: <div class="linkst">
 366:     <div class="inbox crumbsplus">
 367:         <ul class="crumbs">
 368:             <li><a href="admin_index.php"><?php echo $lang_admin_common['Admin'].' '.$lang_admin_common['Index'] ?></a></li>
 369:             <li><span>»&#160;</span><a href="admin_users.php"><?php echo $lang_admin_common['Users'] ?></a></li>
 370:             <li><span>»&#160;</span><strong><?php echo $lang_admin_users['Results head'] ?></strong></li>
 371:         </ul>
 372:         <div class="pagepost">
 373:             <p class="pagelink"><?php echo $paging_links ?></p>
 374:         </div>
 375:         <div class="clearer"></div>
 376:     </div>
 377: </div>
 378: 
 379: 
 380: <div id="users2" class="blocktable">
 381:     <h2><span><?php echo $lang_admin_users['Results head'] ?></span></h2>
 382:     <div class="box">
 383:         <div class="inbox">
 384:             <table cellspacing="0">
 385:             <thead>
 386:                 <tr>
 387:                     <th class="tcl" scope="col"><?php echo $lang_admin_users['Results username head'] ?></th>
 388:                     <th class="tc2" scope="col"><?php echo $lang_admin_users['Results e-mail head'] ?></th>
 389:                     <th class="tc3" scope="col"><?php echo $lang_admin_users['Results title head'] ?></th>
 390:                     <th class="tc4" scope="col"><?php echo $lang_admin_users['Results posts head'] ?></th>
 391:                     <th class="tc5" scope="col"><?php echo $lang_admin_users['Results admin note head'] ?></th>
 392:                     <th class="tcr" scope="col"><?php echo $lang_admin_users['Results actions head'] ?></th>
 393:                 </tr>
 394:             </thead>
 395:             <tbody>
 396: <?php
 397: 
 398:     $result = $db->query('SELECT u.id, u.username, u.email, u.title, u.num_posts, u.admin_note, g.g_id, g.g_user_title FROM '.$db->prefix.'users AS u LEFT JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id WHERE u.id>1'.(!empty($conditions) ? ' AND '.implode(' AND ', $conditions) : '').' ORDER BY '.$db->escape($order_by).' '.$db->escape($direction).' LIMIT '.$start_from.', 50') or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
 399:     if ($db->num_rows($result))
 400:     {
 401:         while ($user_data = $db->fetch_assoc($result))
 402:         {
 403:             $user_title = get_title($user_data);
 404: 
 405:             // This script is a special case in that we want to display "Not verified" for non-verified users
 406:             if (($user_data['g_id'] == '' || $user_data['g_id'] == PUN_UNVERIFIED) && $user_title != $lang_common['Banned'])
 407:                 $user_title = '<span class="warntext">'.$lang_admin_users['Not verified'].'</span>';
 408: 
 409:             $actions = '<a href="admin_users.php?ip_stats='.$user_data['id'].'">'.$lang_admin_users['Results view IP link'].'</a> | <a href="search.php?action=show_user&amp;user_id='.$user_data['id'].'">'.$lang_admin_users['Results show posts link'].'</a>';
 410: 
 411: ?>
 412:                 <tr>
 413:                     <td class="tcl"><?php echo '<a href="profile.php?id='.$user_data['id'].'">'.pun_htmlspecialchars($user_data['username']).'</a>' ?></td>
 414:                     <td class="tc2"><a href="mailto:<?php echo $user_data['email'] ?>"><?php echo $user_data['email'] ?></a></td>
 415:                     <td class="tc3"><?php echo $user_title ?></td>
 416:                     <td class="tc4"><?php echo forum_number_format($user_data['num_posts']) ?></td>
 417:                     <td class="tc5"><?php echo ($user_data['admin_note'] != '') ? pun_htmlspecialchars($user_data['admin_note']) : '&#160;' ?></td>
 418:                     <td class="tcr"><?php echo $actions ?></td>
 419:                 </tr>
 420: <?php
 421: 
 422:         }
 423:     }
 424:     else
 425:         echo "\t\t\t\t".'<tr><td class="tcl" colspan="6">'.$lang_admin_users['No match'].'</td></tr>'."\n";
 426: 
 427: ?>
 428:             </tbody>
 429:             </table>
 430:         </div>
 431:     </div>
 432: </div>
 433: 
 434: <div class="linksb">
 435:     <div class="inbox crumbsplus">
 436:         <div class="pagepost">
 437:             <p class="pagelink"><?php echo $paging_links ?></p>
 438:         </div>
 439:         <ul class="crumbs">
 440:             <li><a href="admin_index.php"><?php echo $lang_admin_common['Admin'].' '.$lang_admin_common['Index'] ?></a></li>
 441:             <li><span>»&#160;</span><a href="admin_users.php"><?php echo $lang_admin_common['Users'] ?></a></li>
 442:             <li><span>»&#160;</span><strong><?php echo $lang_admin_users['Results head'] ?></strong></li>
 443:         </ul>
 444:         <div class="clearer"></div>
 445:     </div>
 446: </div>
 447: <?php
 448: 
 449:     require PUN_ROOT.'footer.php';
 450: }
 451: 
 452: 
 453: else
 454: {
 455:     $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_admin_common['Admin'], $lang_admin_common['Users']);
 456:     $focus_element = array('find_user', 'username');
 457:     define('PUN_ACTIVE_PAGE', 'admin');
 458:     require PUN_ROOT.'header.php';
 459: 
 460:     generate_admin_menu('users');
 461: 
 462: ?>
 463:     <div class="blockform">
 464:         <h2><span><?php echo $lang_admin_users['User search head'] ?></span></h2>
 465:         <div class="box">
 466:             <form id="find_user" method="get" action="admin_users.php">
 467:                 <p class="submittop"><input type="submit" name="find_user" value="<?php echo $lang_admin_users['Submit search'] ?>" tabindex="1" /></p>
 468:                 <div class="inform">
 469:                     <fieldset>
 470:                         <legend><?php echo $lang_admin_users['User search subhead'] ?></legend>
 471:                         <div class="infldset">
 472:                             <p><?php echo $lang_admin_users['User search info'] ?></p>
 473:                             <table class="aligntop" cellspacing="0">
 474:                                 <tr>
 475:                                     <th scope="row"><?php echo $lang_admin_users['Username label'] ?></th>
 476:                                     <td><input type="text" name="form[username]" size="25" maxlength="25" tabindex="2" /></td>
 477:                                 </tr>
 478:                                 <tr>
 479:                                     <th scope="row"><?php echo $lang_admin_users['E-mail address label'] ?></th>
 480:                                     <td><input type="text" name="form[email]" size="30" maxlength="80" tabindex="3" /></td>
 481:                                 </tr>
 482:                                 <tr>
 483:                                     <th scope="row"><?php echo $lang_admin_users['Title label'] ?></th>
 484:                                     <td><input type="text" name="form[title]" size="30" maxlength="50" tabindex="4" /></td>
 485:                                 </tr>
 486:                                 <tr>
 487:                                     <th scope="row"><?php echo $lang_admin_users['Real name label'] ?></th>
 488:                                     <td><input type="text" name="form[realname]" size="30" maxlength="40" tabindex="5" /></td>
 489:                                 </tr>
 490:                                 <tr>
 491:                                     <th scope="row"><?php echo $lang_admin_users['Website label'] ?></th>
 492:                                     <td><input type="text" name="form[url]" size="35" maxlength="100" tabindex="6" /></td>
 493:                                 </tr>
 494:                                 <tr>
 495:                                     <th scope="row"><?php echo $lang_admin_users['Jabber label'] ?></th>
 496:                                     <td><input type="text" name="form[jabber]" size="30" maxlength="75" tabindex="7" /></td>
 497:                                 </tr>
 498:                                 <tr>
 499:                                     <th scope="row"><?php echo $lang_admin_users['ICQ label'] ?></th>
 500:                                     <td><input type="text" name="form[icq]" size="12" maxlength="12" tabindex="8" /></td>
 501:                                 </tr>
 502:                                 <tr>
 503:                                     <th scope="row"><?php echo $lang_admin_users['MSN label'] ?></th>
 504:                                     <td><input type="text" name="form[msn]" size="30" maxlength="50" tabindex="9" /></td>
 505:                                 </tr>
 506:                                 <tr>
 507:                                     <th scope="row"><?php echo $lang_admin_users['AOL label'] ?></th>
 508:                                     <td><input type="text" name="form[aim]" size="20" maxlength="20" tabindex="10" /></td>
 509:                                 </tr>
 510:                                 <tr>
 511:                                     <th scope="row"><?php echo $lang_admin_users['Yahoo label'] ?></th>
 512:                                     <td><input type="text" name="form[yahoo]" size="20" maxlength="20" tabindex="11" /></td>
 513:                                 </tr>
 514:                                 <tr>
 515:                                     <th scope="row"><?php echo $lang_admin_users['Location label'] ?></th>
 516:                                     <td><input type="text" name="form[location]" size="30" maxlength="30" tabindex="12" /></td>
 517:                                 </tr>
 518:                                 <tr>
 519:                                     <th scope="row"><?php echo $lang_admin_users['Signature label'] ?></th>
 520:                                     <td><input type="text" name="form[signature]" size="35" maxlength="512" tabindex="13" /></td>
 521:                                 </tr>
 522:                                 <tr>
 523:                                     <th scope="row"><?php echo $lang_admin_users['Admin note label'] ?></th>
 524:                                     <td><input type="text" name="form[admin_note]" size="30" maxlength="30" tabindex="14" /></td>
 525:                                 </tr>
 526:                                 <tr>
 527:                                     <th scope="row"><?php echo $lang_admin_users['Posts more than label'] ?></th>
 528:                                     <td><input type="text" name="posts_greater" size="5" maxlength="8" tabindex="15" /></td>
 529:                                 </tr>
 530:                                 <tr>
 531:                                     <th scope="row"><?php echo $lang_admin_users['Posts less than label'] ?></th>
 532:                                     <td><input type="text" name="posts_less" size="5" maxlength="8" tabindex="16" /></td>
 533:                                 </tr>
 534:                                 <tr>
 535:                                     <th scope="row"><?php echo $lang_admin_users['Last post after label'] ?></th>
 536:                                     <td><input type="text" name="last_post_after" size="24" maxlength="19" tabindex="17" />
 537:                                     <span><?php echo $lang_admin_users['Date help'] ?></span></td>
 538:                                 </tr>
 539:                                 <tr>
 540:                                     <th scope="row"><?php echo $lang_admin_users['Last post before label'] ?></th>
 541:                                     <td><input type="text" name="last_post_before" size="24" maxlength="19" tabindex="18" />
 542:                                     <span><?php echo $lang_admin_users['Date help'] ?></span></td>
 543:                                 </tr>
 544:                                 <tr>
 545:                                     <th scope="row"><?php echo $lang_admin_users['Registered after label'] ?></th>
 546:                                     <td><input type="text" name="registered_after" size="24" maxlength="19" tabindex="19" />
 547:                                     <span><?php echo $lang_admin_users['Date help'] ?></span></td>
 548:                                 </tr>
 549:                                 <tr>
 550:                                     <th scope="row"><?php echo $lang_admin_users['Registered before label'] ?></th>
 551:                                     <td><input type="text" name="registered_before" size="24" maxlength="19" tabindex="20" />
 552:                                     <span><?php echo $lang_admin_users['Date help'] ?></span></td>
 553:                                 </tr>
 554:                                 <tr>
 555:                                     <th scope="row"><?php echo $lang_admin_users['Order by label'] ?></th>
 556:                                     <td>
 557:                                         <select name="order_by" tabindex="21">
 558:                                             <option value="username" selected="selected"><?php echo $lang_admin_users['Order by username'] ?></option>
 559:                                             <option value="email"><?php echo $lang_admin_users['Order by e-mail'] ?></option>
 560:                                             <option value="num_posts"><?php echo $lang_admin_users['Order by posts'] ?></option>
 561:                                             <option value="last_post"><?php echo $lang_admin_users['Order by last post'] ?></option>
 562:                                             <option value="registered"><?php echo $lang_admin_users['Order by registered'] ?></option>
 563:                                         </select>&#160;&#160;&#160;<select name="direction" tabindex="22">
 564:                                             <option value="ASC" selected="selected"><?php echo $lang_admin_users['Ascending'] ?></option>
 565:                                             <option value="DESC"><?php echo $lang_admin_users['Descending'] ?></option>
 566:                                         </select>
 567:                                     </td>
 568:                                 </tr>
 569:                                 <tr>
 570:                                     <th scope="row"><?php echo $lang_admin_users['User group label'] ?></th>
 571:                                     <td>
 572:                                         <select name="user_group" tabindex="23">
 573:                                             <option value="-1" selected="selected"><?php echo $lang_admin_users['All groups'] ?></option>
 574:                                             <option value="0"><?php echo $lang_admin_users['Unverified users'] ?></option>
 575: <?php
 576: 
 577:     $result = $db->query('SELECT g_id, g_title FROM '.$db->prefix.'groups WHERE g_id!='.PUN_GUEST.' ORDER BY g_title') or error('Unable to fetch user group list', __FILE__, __LINE__, $db->error());
 578: 
 579:     while ($cur_group = $db->fetch_assoc($result))
 580:         echo "\t\t\t\t\t\t\t\t\t\t\t".'<option value="'.$cur_group['g_id'].'">'.pun_htmlspecialchars($cur_group['g_title']).'</option>'."\n";
 581: 
 582: ?>
 583:                                         </select>
 584:                                     </td>
 585:                                 </tr>
 586:                             </table>
 587:                         </div>
 588:                     </fieldset>
 589:                 </div>
 590:                 <p class="submitend"><input type="submit" name="find_user" value="<?php echo $lang_admin_users['Submit search'] ?>" tabindex="25" /></p>
 591:             </form>
 592:         </div>
 593: 
 594:         <h2 class="block2"><span><?php echo $lang_admin_users['IP search head'] ?></span></h2>
 595:         <div class="box">
 596:             <form method="get" action="admin_users.php">
 597:                 <div class="inform">
 598:                     <fieldset>
 599:                         <legend><?php echo $lang_admin_users['IP search subhead'] ?></legend>
 600:                         <div class="infldset">
 601:                             <table class="aligntop" cellspacing="0">
 602:                                 <tr>
 603:                                     <th scope="row"><?php echo $lang_admin_users['IP address label'] ?><div><input type="submit" value="<?php echo $lang_admin_users['Find IP address'] ?>" tabindex="26" /></div></th>
 604:                                     <td><input type="text" name="show_users" size="18" maxlength="15" tabindex="24" />
 605:                                     <span><?php echo $lang_admin_users['IP address help'] ?></span></td>
 606:                                 </tr>
 607:                             </table>
 608:                         </div>
 609:                     </fieldset>
 610:                 </div>
 611:             </form>
 612:         </div>
 613:     </div>
 614:     <div class="clearer"></div>
 615: </div>
 616: <?php
 617: 
 618:     require PUN_ROOT.'footer.php';
 619: }


/dev/null b/cache/.htaccess
   1: <Limit GET POST PUT>
   2: Order Allow,Deny
   3: Deny from All
   4: </Limit>


/dev/null b/cache/index.html
   1: <html><head><title>.</title></head><body>.</body></html>


/dev/null b/db_update.php
   1: <?php
   2: 
   3: /**
   4:  * Copyright (C) 2008-2010 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:  */
   8: 
   9: // The FluxBB version this script updates to
  10: define('UPDATE_TO', '1.4.1');
  11: 
  12: define('UPDATE_TO_DB_REVISION', 7);
  13: define('UPDATE_TO_SI_REVISION', 1);
  14: define('UPDATE_TO_PARSER_REVISION', 1);
  15: 
  16: define('MIN_PHP_VERSION', '4.3.0');
  17: define('MIN_MYSQL_VERSION', '4.1.2');
  18: define('MIN_PGSQL_VERSION', '7.0.0');
  19: define('PUN_SEARCH_MIN_WORD', 3);
  20: define('PUN_SEARCH_MAX_WORD', 20);
  21: 
  22: // The MySQL connection character set that was used for FluxBB 1.2 - in 99% of cases this should be detected automatically,
  23: // but can be overridden using the below constant if required.
  24: //define('FORUM_DEFAULT_CHARSET', 'latin1');
  25: 
  26: 
  27: // The number of items to process per page view (lower this if the update script times out during UTF-8 conversion)
  28: define('PER_PAGE', 300);
  29: 
  30: // Don't set to UTF-8 until after we've found out what the default character set is
  31: define('FORUM_NO_SET_NAMES', 1);
  32: 
  33: // Make sure we are running at least MIN_PHP_VERSION
  34: if (!function_exists('version_compare') || version_compare(PHP_VERSION, MIN_PHP_VERSION, '<'))
  35:     exit('You are running PHP version '.PHP_VERSION.'. FluxBB '.UPDATE_TO.' requires at least PHP '.MIN_PHP_VERSION.' to run properly. You must upgrade your PHP installation before you can continue.');
  36: 
  37: define('PUN_ROOT', './');
  38: 
  39: // Attempt to load the configuration file config.php
  40: if (file_exists(PUN_ROOT.'config.php'))
  41:     include PUN_ROOT.'config.php';
  42: 
  43: // If we have the 1.3-legacy constant defined, define the proper 1.4 constant so we don't get an incorrect "need to install" message
  44: if (defined('FORUM'))
  45:     define('PUN', FORUM);
  46: 
  47: // If PUN isn't defined, config.php is missing or corrupt or we are outside the root directory
  48: if (!defined('PUN'))
  49:     exit('This file must be run from the forum root directory.');
  50: 
  51: // Enable debug mode
  52: if (!defined('PUN_DEBUG'))
  53:     define('PUN_DEBUG', 1);
  54: 
  55: // Load the functions script
  56: require PUN_ROOT.'include/functions.php';
  57: 
  58: // Load UTF-8 functions
  59: require PUN_ROOT.'include/utf8/utf8.php';
  60: 
  61: // Strip out "bad" UTF-8 characters
  62: forum_remove_bad_characters();
  63: 
  64: // Reverse the effect of register_globals
  65: forum_unregister_globals();
  66: 
  67: // Turn on full PHP error reporting
  68: error_reporting(E_ALL);
  69: 
  70: // Force POSIX locale (to prevent functions such as strtolower() from messing up UTF-8 strings)
  71: setlocale(LC_CTYPE, 'C');
  72: 
  73: // Turn off magic_quotes_runtime
  74: if (get_magic_quotes_runtime())
  75:     set_magic_quotes_runtime(0);
  76: 
  77: // Strip slashes from GET/POST/COOKIE (if magic_quotes_gpc is enabled)
  78: if (get_magic_quotes_gpc())
  79: {
  80:     function stripslashes_array($array)
  81:     {
  82:         return is_array($array) ? array_map('stripslashes_array', $array) : stripslashes($array);
  83:     }
  84: 
  85:     $_GET = stripslashes_array($_GET);
  86:     $_POST = stripslashes_array($_POST);
  87:     $_COOKIE = stripslashes_array($_COOKIE);
  88:     $_REQUEST = stripslashes_array($_REQUEST);
  89: }
  90: 
  91: // If a cookie name is not specified in config.php, we use the default (forum_cookie)
  92: if (empty($cookie_name))
  93:     $cookie_name = 'pun_cookie';
  94: 
  95: // If the cache directory is not specified, we use the default setting
  96: if (!defined('FORUM_CACHE_DIR'))
  97:     define('FORUM_CACHE_DIR', PUN_ROOT.'cache/');
  98: 
  99: // Turn off PHP time limit
 100: @set_time_limit(0);
 101: 
 102: // Load DB abstraction layer and try to connect
 103: require PUN_ROOT.'include/dblayer/common_db.php';
 104: 
 105: // Check what the default character set is - since 1.2 didn't specify any we will use whatever the default was (usually latin1)
 106: $old_connection_charset = defined('FORUM_DEFAULT_CHARSET') ? FORUM_DEFAULT_CHARSET : $db->get_names();
 107: 
 108: // Set the connection to UTF-8 now
 109: $db->set_names('utf8');
 110: 
 111: // Check current version
 112: $result = $db->query('SELECT conf_value FROM '.$db->prefix.'config WHERE conf_name=\'o_cur_version\'') or error('Unable to fetch version info.', __FILE__, __LINE__, $db->error());
 113: $cur_version = $db->result($result);
 114: 
 115: if (version_compare($cur_version, '1.2', '<'))
 116:     exit('Version mismatch. The database \''.$db_name.'\' doesn\'t seem to be running a FluxBB database schema supported by this update script.');
 117: 
 118: // Do some DB type specific checks
 119: $mysql = false;
 120: switch ($db_type)
 121: {
 122:     case 'mysql':
 123:     case 'mysqli':
 124:     case 'mysql_innodb':
 125:     case 'mysqli_innodb':
 126:         $mysql_info = $db->get_version();
 127:         if (version_compare($mysql_info['version'], MIN_MYSQL_VERSION, '<'))
 128:             error('You are running MySQL version '.$mysql_version.'. FluxBB '.UPDATE_TO.' requires at least MySQL '.MIN_MYSQL_VERSION.' to run properly. You must upgrade your MySQL installation before you can continue.');
 129: 
 130:         $mysql = true;
 131:         break;
 132: 
 133:     case 'pgsql':
 134:         $pgsql_info = $db->get_version();
 135:         if (version_compare($pgsql_info['version'], MIN_PGSQL_VERSION, '<'))
 136:             error('You are running PostgreSQL version '.$pgsql_info.'. FluxBB '.UPDATE_TO.' requires at least PostgreSQL '.MIN_PGSQL_VERSION.' to run properly. You must upgrade your PostgreSQL installation before you can continue.');
 137: 
 138:         break;
 139: }
 140: 
 141: // Get the forum config
 142: $result = $db->query('SELECT * FROM '.$db->prefix.'config') or error('Unable to fetch config.', __FILE__, __LINE__, $db->error());
 143: while ($cur_config_item = $db->fetch_row($result))
 144:     $pun_config[$cur_config_item[0]] = $cur_config_item[1];
 145: 
 146: // Check the database revision and the current version
 147: if (isset($pun_config['o_database_revision']) && $pun_config['o_database_revision'] >= UPDATE_TO_DB_REVISION &&
 148:         isset($pun_config['o_searchindex_revision']) && $pun_config['o_searchindex_revision'] >= UPDATE_TO_SI_REVISION &&
 149:         isset($pun_config['o_parser_revision']) && $pun_config['o_parser_revision'] >= UPDATE_TO_PARSER_REVISION &&
 150:         version_compare($pun_config['o_cur_version'], UPDATE_TO, '>='))
 151:     exit('Your database is already as up-to-date as this script can make it.');
 152: 
 153: $default_style = $pun_config['o_default_style'];
 154: if (!file_exists(PUN_ROOT.'style/'.$default_style.'.css'))
 155:     $default_style = 'Air';
 156: 
 157: //
 158: // Determines whether $str is UTF-8 encoded or not
 159: //
 160: function seems_utf8($str)
 161: {
 162:     $str_len = strlen($str);
 163:     for ($i = 0; $i < $str_len; ++$i)
 164:     {
 165:         if (ord($str[$i]) < 0x80) continue; # 0bbbbbbb
 166:         else if ((ord($str[$i]) & 0xE0) == 0xC0) $n=1; # 110bbbbb
 167:         else if ((ord($str[$i]) & 0xF0) == 0xE0) $n=2; # 1110bbbb
 168:         else if ((ord($str[$i]) & 0xF8) == 0xF0) $n=3; # 11110bbb
 169:         else if ((ord($str[$i]) & 0xFC) == 0xF8) $n=4; # 111110bb
 170:         else if ((ord($str[$i]) & 0xFE) == 0xFC) $n=5; # 1111110b
 171:         else return false; # Does not match any model
 172: 
 173:         for ($j = 0; $j < $n; ++$j) # n bytes matching 10bbbbbb follow ?
 174:         {
 175:             if ((++$i == strlen($str)) || ((ord($str[$i]) & 0xC0) != 0x80))
 176:                 return false;
 177:         }
 178:     }
 179: 
 180:     return true;
 181: }
 182: 
 183: 
 184: //
 185: // Translates the number from a HTML numeric entity into an UTF-8 character
 186: //
 187: function dcr2utf8($src)
 188: {
 189:     $dest = '';
 190:     if ($src < 0)
 191:         return false;
 192:     else if ($src <= 0x007f)
 193:         $dest .= chr($src);
 194:     else if ($src <= 0x07ff)
 195:     {
 196:         $dest .= chr(0xc0 | ($src >> 6));
 197:         $dest .= chr(0x80 | ($src & 0x003f));
 198:     }
 199:     else if ($src == 0xFEFF)
 200:     {
 201:         // nop -- zap the BOM
 202:     }
 203:     else if ($src >= 0xD800 && $src <= 0xDFFF)
 204:     {
 205:         // found a surrogate
 206:         return false;
 207:     }
 208:     else if ($src <= 0xffff)
 209:     {
 210:         $dest .= chr(0xe0 | ($src >> 12));
 211:         $dest .= chr(0x80 | (($src >> 6) & 0x003f));
 212:         $dest .= chr(0x80 | ($src & 0x003f));
 213:     }
 214:     else if ($src <= 0x10ffff)
 215:     {
 216:         $dest .= chr(0xf0 | ($src >> 18));
 217:         $dest .= chr(0x80 | (($src >> 12) & 0x3f));
 218:         $dest .= chr(0x80 | (($src >> 6) & 0x3f));
 219:         $dest .= chr(0x80 | ($src & 0x3f));
 220:     }
 221:     else
 222:     {
 223:         // out of range
 224:         return false;
 225:     }
 226: 
 227:     return $dest;
 228: }
 229: 
 230: 
 231: //
 232: // Attempts to convert $str from $old_charset to UTF-8. Also converts HTML entities (including numeric entities) to UTF-8 characters
 233: //
 234: function convert_to_utf8(&$str, $old_charset)
 235: {
 236:     if ($str === null || $str == '')
 237:         return false;
 238: 
 239:     $save = $str;
 240: 
 241:     // Replace literal entities (for non-UTF-8 compliant html_entity_encode)
 242:     if (version_compare(PHP_VERSION, '5.0.0', '<') && $old_charset == 'ISO-8859-1' || $old_charset == 'ISO-8859-15')
 243:         $str = html_entity_decode($str, ENT_QUOTES, $old_charset);
 244: 
 245:     if ($old_charset != 'UTF-8' && !seems_utf8($str))
 246:     {
 247:         if (function_exists('iconv'))
 248:             $str = iconv($old_charset == 'ISO-8859-1' ? 'WINDOWS-1252' : 'ISO-8859-1', 'UTF-8', $str);
 249:         else if (function_exists('mb_convert_encoding'))
 250:             $str = mb_convert_encoding($str, 'UTF-8', $old_charset == 'ISO-8859-1' ? 'WINDOWS-1252' : 'ISO-8859-1');
 251:         else if ($old_charset == 'ISO-8859-1')
 252:             $str = utf8_encode($str);
 253:     }
 254: 
 255:     // Replace literal entities (for UTF-8 compliant html_entity_encode)
 256:     if (version_compare(PHP_VERSION, '5.0.0', '>='))
 257:         $str = html_entity_decode($str, ENT_QUOTES, 'UTF-8');
 258: 
 259:     // Replace numeric entities
 260:     $str = preg_replace_callback('/&#([0-9]+);/', 'utf8_callback_1', $str);
 261:     $str = preg_replace_callback('/&#x([a-f0-9]+);/i', 'utf8_callback_2', $str);
 262: 
 263:     // Remove "bad" characters
 264:     $str = remove_bad_characters($str);
 265: 
 266:     return ($save != $str);
 267: }
 268: 
 269: 
 270: function utf8_callback_1($matches)
 271: {
 272:     return dcr2utf8($matches[1]);
 273: }
 274: 
 275: 
 276: function utf8_callback_2($matches)
 277: {
 278:     return dcr2utf8(hexdec($matches[1]));
 279: }
 280: 
 281: 
 282: //
 283: // Alter a table to be utf8. MySQL only
 284: // Function based on update_convert_table_utf8() from the Drupal project (http://drupal.org/)
 285: //
 286: function alter_table_utf8($table)
 287: {
 288:     global $mysql, $db;
 289:     static $types;
 290: 
 291:     if (!$mysql)
 292:         return;
 293: 
 294:     if (!isset($types))
 295:     {
 296:         $types = array(
 297:             'char'            => 'binary',
 298:             'varchar'        => 'varbinary',
 299:             'tinytext'        => 'tinyblob',
 300:             'mediumtext'    => 'mediumblob',
 301:             'text'            => 'blob',
 302:             'longtext'        => 'longblob'
 303:         );
 304:     }
 305: 
 306:     // Set table default charset to utf8
 307:     $db->query('ALTER TABLE '.$table.' CHARACTER SET utf8') or error('Unable to set table character set', __FILE__, __LINE__, $db->error());
 308: 
 309:     // Find out which columns need converting and build SQL statements
 310:     $result = $db->query('SHOW FULL COLUMNS FROM '.$table) or error('Unable to fetch column information', __FILE__, __LINE__, $db->error());
 311:     while ($cur_column = $db->fetch_assoc($result))
 312:     {
 313:         if ($cur_column['Collation'] === null)
 314:             continue;
 315: 
 316:         list($type) = explode('(', $cur_column['Type']);
 317:         if (isset($types[$type]) && strpos($cur_column['Collation'], 'utf8') === false)
 318:         {
 319:             $allow_null = ($cur_column['Null'] == 'YES');
 320:             $collate = (substr($cur_column['Collation'], -3) == 'bin') ? 'utf8_bin' : 'utf8_general_ci';
 321: 
 322:             $db->alter_field($table, $cur_column['Field'], preg_replace('/'.$type.'/i', $types[$type], $cur_column['Type']), $allow_null, $cur_column['Default'], null, true) or error('Unable to alter field to binary', __FILE__, __LINE__, $db->error());
 323:             $db->alter_field($table, $cur_column['Field'], $cur_column['Type'].' CHARACTER SET utf8 COLLATE '.$collate, $allow_null, $cur_column['Default'], null, true) or error('Unable to alter field to utf8', __FILE__, __LINE__, $db->error());
 324:         }
 325:     }
 326: }
 327: 
 328: //
 329: // Safely converts text type columns into utf8
 330: // If finished returns true, otherwise returns $end_at
 331: //
 332: function convert_table_utf8($table, $callback, $old_charset, $key = null, $start_at = null)
 333: {
 334:     global $mysql, $db, $old_connection_charset;
 335: 
 336:     $finished = true;
 337:     $end_at = 0;
 338:     if ($mysql)
 339:     {
 340:         // Only set up the tables if we are doing this in 1 go, or its the first go
 341:         if ($start_at === null || $start_at == 0)
 342:         {
 343:             // Drop any temp table that exists, in-case it's left over from a failed update
 344:             $db->drop_table($table.'_utf8', true) or error('Unable to drop left over temp table', __FILE__, __LINE__, $db->error());
 345: 
 346:             // Copy the table
 347:             $db->query('CREATE TABLE '.$table.'_utf8 LIKE '.$table) or error('Unable to create new table', __FILE__, __LINE__, $db->error());
 348: 
 349:             // Set table default charset to utf8
 350:             alter_table_utf8($table.'_utf8');
 351:         }
 352: 
 353:         // Change to the old character set so MySQL doesn't attempt to perform conversion on the data from the old table
 354:         $db->set_names($old_connection_charset);
 355: 
 356:         // Move & Convert everything
 357:         $result = $db->query('SELECT * FROM '.$table.($start_at === null ? '' : ' WHERE '.$key.'>'.$start_at).' ORDER BY '.$key.' ASC'.($start_at === null ? '' : ' LIMIT '.PER_PAGE), false) or error('Unable to select from old table', __FILE__, __LINE__, $db->error());
 358: 
 359:         // Change back to utf8 mode so we can insert it into the new table
 360:         $db->set_names('utf8');
 361: 
 362:         while ($cur_item = $db->fetch_assoc($result))
 363:         {
 364:             $cur_item = call_user_func($callback, $cur_item, $old_charset);
 365: 
 366:             $temp = array();
 367:             foreach ($cur_item as $idx => $value)
 368:                 $temp[$idx] = $value === null ? 'NULL' : '\''.$db->escape($value).'\'';
 369: 
 370:             $db->query('INSERT INTO '.$table.'_utf8('.implode(',', array_keys($temp)).') VALUES ('.implode(',', array_values($temp)).')') or error('Unable to insert data to new table', __FILE__, __LINE__, $db->error());
 371: 
 372:             $end_at = $cur_item[$key];
 373:         }
 374: 
 375:         // If we aren't doing this all in 1 go and $end_at has a value (i.e. we have processed at least 1 row), figure out if we have more to do or not
 376:         if ($start_at !== null && $end_at > 0)
 377:         {
 378:             $result = $db->query('SELECT 1 FROM '.$table.' WHERE '.$key.'>'.$end_at.' ORDER BY '.$key.' ASC LIMIT 1') or error('Unable to check for next row', __FILE__, __LINE__, $db->error());
 379:             $finished = $db->num_rows($result) == 0;
 380:         }
 381: 
 382:         // Only swap the tables if we are doing this in 1 go, or its the last go
 383:         if ($finished)
 384:         {
 385:             // Delete old table
 386:             $db->drop_table($table, true) or error('Unable to drop old table', __FILE__, __LINE__, $db->error());
 387: 
 388:             // Rename table
 389:             $db->query('ALTER TABLE '.$table.'_utf8 RENAME '.$table) or error('Unable to rename new table', __FILE__, __LINE__, $db->error());
 390: 
 391:             return true;
 392:         }
 393: 
 394:         return $end_at;
 395:     }
 396:     else
 397:     {
 398:         // Convert everything
 399:         $result = $db->query('SELECT * FROM '.$table.($start_at === null ? '' : ' WHERE '.$key.'>'.$start_at).' ORDER BY '.$key.' ASC'.($start_at === null ? '' : ' LIMIT '.PER_PAGE)) or error('Unable to select from table', __FILE__, __LINE__, $db->error());
 400:         while ($cur_item = $db->fetch_assoc($result))
 401:         {
 402:             $cur_item = call_user_func($callback, $cur_item, $old_charset);
 403: 
 404:             $temp = array();
 405:             foreach ($cur_item as $idx => $value)
 406:                 $temp[] = $idx.'='.($value === null ? 'NULL' : '\''.$db->escape($value).'\'');
 407: 
 408:             if (!empty($temp))
 409:                 $db->query('UPDATE '.$table.' SET '.implode(', ', $temp).' WHERE '.$key.'=\''.$db->escape($cur_item[$key]).'\'') or error('Unable to update data', __FILE__, __LINE__, $db->error());
 410: 
 411:             $end_at = $cur_item[$key];
 412:         }
 413: 
 414:         if ($start_at !== null && $end_at > 0)
 415:         {
 416:             $result = $db->query('SELECT 1 FROM '.$table.' WHERE '.$key.'>'.$end_at.' ORDER BY '.$key.' ASC LIMIT 1') or error('Unable to check for next row', __FILE__, __LINE__, $db->error());
 417:             if ($db->num_rows($result) == 0)
 418:                 return true;
 419: 
 420:             return $end_at;
 421:         }
 422: 
 423:         return true;
 424:     }
 425: }
 426: 
 427: 
 428: header('Content-type: text/html; charset=utf-8');
 429: 
 430: // Empty all output buffers and stop buffering
 431: while (@ob_end_clean());
 432: 
 433: 
 434: $stage = isset($_GET['stage']) ? $_GET['stage'] : '';
 435: $old_charset = isset($_GET['req_old_charset']) ? str_replace('ISO8859', 'ISO-8859', strtoupper($_GET['req_old_charset'])) : 'ISO-8859-1';
 436: $start_at = isset($_GET['start_at']) ? intval($_GET['start_at']) : 0;
 437: $query_str = '';
 438: 
 439: switch ($stage)
 440: {
 441:     // Show form
 442:     case '':
 443: 
 444: ?>
 445: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 446: 
 447: <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
 448: <head>
 449: <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 450: <title>FluxBB Database Update</title>
 451: <link rel="stylesheet" type="text/css" href="style/<?php echo $default_style ?>.css" />
 452: </head>
 453: <body>
 454: 
 455: <div id="pundb_update" class="pun">
 456: <div class="top-box"><div><!-- Top Corners --></div></div>
 457: <div class="punwrap">
 458: 
 459: <div class="blockform">
 460:     <h2><span>FluxBB Update</span></h2>
 461:     <div class="box">
 462:         <form method="get" action="<?php echo pun_htmlspecialchars($_SERVER['REQUEST_URI']) ?>" onsubmit="this.start.disabled=true">
 463:         <input type="hidden" name="stage" value="start" />
 464:             <div class="inform">
 465:                 <div class="forminfo">
 466:                     <p style="font-size: 1.1em">This script will update your forum database. The update procedure might take anything from a second to hours depending on the speed of the server and the size of the forum database. Don't forget to make a backup of the database before continuing.</p>
 467:                     <p style="font-size: 1.1em">Did you read the update instructions in the documentation? If not, start there.</p>
 468: <?php
 469: 
 470: if (strpos($cur_version, '1.2') === 0)
 471: {
 472:     if (!function_exists('iconv') && !function_exists('mb_convert_encoding'))
 473:     {
 474: 
 475: ?>
 476:                     <p style="font-size: 1.1em"><strong>IMPORTANT!</strong> FluxBB has detected that this PHP environment does not have support for the encoding mechanisms required to do UTF-8 conversion from character sets other than ISO-8859-1. What this means is that if the current character set is not ISO-8859-1, FluxBB won't be able to convert your forum database to UTF-8 and you will have to do it manually. Instructions for doing manual charset conversion can be found in the update instructions.</p>
 477: <?php
 478: 
 479:     }
 480: 
 481: ?>
 482:                 </div>
 483:             </div>
 484:             <div class="inform">
 485:                 <div class="forminfo">
 486:                     <p style="font-size: 1.1em"><strong>Enable conversion:</strong> When enabled this update script will, after it has made the required structural changes to the database, convert all text in the database from the current character set to UTF-8. This conversion is required if you're upgrading from version 1.2.</p>
 487:                     <p style="font-size: 1.1em"><strong>Current character set:</strong> If the primary language in your forum is English, you can leave this at the default value. However, if your forum is non-English, you should enter the character set of the primary language pack used in the forum. <i>Getting this wrong can corrupt your database so don't just guess!</i> Note: This is required even if the old database is UTF-8.</p>
 488:                 </div>
 489:                 <fieldset>
 490:                     <legend>Charset conversion</legend>
 491:                     <div class="infldset">
 492:                         <div class="rbox">
 493:                             <label><input type="checkbox" name="convert_charset" value="1" checked="checked" /><strong>Enable conversion</strong> (perform database charset conversion).<br /></label>
 494:                         </div>
 495:                         <label>
 496:                             <strong>Current character set</strong><br />Accept default for English forums otherwise the character set of the primary language pack.<br />
 497:                             <input type="text" name="req_old_charset" size="12" maxlength="20" value="<?php echo $old_charset ?>" /><br />
 498:                         </label>
 499:                     </div>
 500:                 </fieldset>
 501: <?php
 502: 
 503: }
 504: else
 505:     echo "\t\t\t\t".'</div>'."\n";
 506: 
 507: ?>
 508:             </div>
 509:             <p class="buttons"><input type="submit" name="start" value="Start update" /></p>
 510:         </form>
 511:     </div>
 512: </div>
 513: 
 514: </div>
 515: <div class="end-box"><div><!-- Bottom Corners --></div></div>
 516: </div>
 517: 
 518: </body>
 519: </html>
 520: <?php
 521: 
 522:         break;
 523: 
 524: 
 525:     // Start by updating the database structure
 526:     case 'start':
 527:         $query_str = '?stage=preparse_posts';
 528: 
 529:         // If we don't need to update the database, skip this stage
 530:         if (isset($pun_config['o_database_revision']) && $pun_config['o_database_revision'] >= UPDATE_TO_DB_REVISION)
 531:             break;
 532: 
 533:         // Make all email fields VARCHAR(80)
 534:         $db->alter_field('bans', 'email', 'VARCHAR(80)', true) or error('Unable to alter email field', __FILE__, __LINE__, $db->error());
 535:         $db->alter_field('posts', 'poster_email', 'VARCHAR(80)', true) or error('Unable to alter poster_email field', __FILE__, __LINE__, $db->error());
 536:         $db->alter_field('users', 'email', 'VARCHAR(80)', false, '') or error('Unable to alter email field', __FILE__, __LINE__, $db->error());
 537:         $db->alter_field('users', 'jabber', 'VARCHAR(80)', true) or error('Unable to alter jabber field', __FILE__, __LINE__, $db->error());
 538:         $db->alter_field('users', 'msn', 'VARCHAR(80)', true) or error('Unable to alter msn field', __FILE__, __LINE__, $db->error());
 539:         $db->alter_field('users', 'activate_string', 'VARCHAR(80)', true) or error('Unable to alter activate_string field', __FILE__, __LINE__, $db->error());
 540: 
 541:         // Make all IP fields VARCHAR(39) to support IPv6
 542:         $db->alter_field('posts', 'poster_ip', 'VARCHAR(39)', true) or error('Unable to alter poster_ip field', __FILE__, __LINE__, $db->error());
 543:         $db->alter_field('users', 'registration_ip', 'VARCHAR(39)', false, '0.0.0.0') or error('Unable to alter registration_ip field', __FILE__, __LINE__, $db->error());
 544: 
 545:         // Add the DST option to the users table
 546:         $db->add_field('users', 'dst', 'TINYINT(1)', false, 0, 'timezone') or error('Unable to add dst field', __FILE__, __LINE__, $db->error());
 547: 
 548:         // Add the last_post field to the online table
 549:         $db->add_field('online', 'last_post', 'INT(10) UNSIGNED', true, null, null) or error('Unable to add last_post field', __FILE__, __LINE__, $db->error());
 550: 
 551:         // Add the last_search field to the online table
 552:         $db->add_field('online', 'last_search', 'INT(10) UNSIGNED', true, null, null) or error('Unable to add last_search field', __FILE__, __LINE__, $db->error());
 553: 
 554:         // Add the last_search column to the users table
 555:         $db->add_field('users', 'last_search', 'INT(10) UNSIGNED', true, null, 'last_post') or error('Unable to add last_search field', __FILE__, __LINE__, $db->error());
 556: 
 557:         // Drop use_avatar column from users table
 558:         $db->drop_field('users', 'use_avatar') or error('Unable to drop use_avatar field', __FILE__, __LINE__, $db->error());
 559: 
 560:         // Drop save_pass column from users table
 561:         $db->drop_field('users', 'save_pass') or error('Unable to drop save_pass field', __FILE__, __LINE__, $db->error());
 562: 
 563:         // Drop g_edit_subjects_interval column from groups table
 564:         $db->drop_field('groups', 'g_edit_subjects_interval');
 565: 
 566:         // Add database revision number
 567:         if (!array_key_exists('o_database_revision', $pun_config))
 568:             $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'o_database_revision\', \'0\')') or error('Unable to insert config value \'o_database_revision\'', __FILE__, __LINE__, $db->error());
 569: 
 570:         // Add search index revision number
 571:         if (!array_key_exists('o_searchindex_revision', $pun_config))
 572:             $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'o_searchindex_revision\', \'0\')') or error('Unable to insert config value \'o_searchindex_revision\'', __FILE__, __LINE__, $db->error());
 573: 
 574:         // Add parser revision number
 575:         if (!array_key_exists('o_parser_revision', $pun_config))
 576:             $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'o_parser_revision\', \'0\')') or error('Unable to insert config value \'o_parser_revision\'', __FILE__, __LINE__, $db->error());
 577: 
 578:         // Add default email setting option
 579:         if (!array_key_exists('o_default_email_setting', $pun_config))
 580:             $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'o_default_email_setting\', \'1\')') or error('Unable to insert config value \'o_default_email_setting\'', __FILE__, __LINE__, $db->error());
 581: 
 582:         // Make sure we have o_additional_navlinks (was added in 1.2.1)
 583:         if (!array_key_exists('o_additional_navlinks', $pun_config))
 584:             $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'o_additional_navlinks\', \'\')') or error('Unable to insert config value \'o_additional_navlinks\'', __FILE__, __LINE__, $db->error());
 585: 
 586:         // Insert new config option o_topic_views
 587:         if (!array_key_exists('o_topic_views', $pun_config))
 588:             $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'o_topic_views\', \'1\')') or error('Unable to insert config value \'o_topic_views\'', __FILE__, __LINE__, $db->error());
 589: 
 590:         // Insert new config option o_signatures
 591:         if (!array_key_exists('o_signatures', $pun_config))
 592:             $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'o_signatures\', \'1\')') or error('Unable to insert config value \'o_signatures\'', __FILE__, __LINE__, $db->error());
 593: 
 594:         // Insert new config option o_smtp_ssl
 595:         if (!array_key_exists('o_smtp_ssl', $pun_config))
 596:             $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'o_smtp_ssl\', \'0\')') or error('Unable to insert config value \'o_smtp_ssl\'', __FILE__, __LINE__, $db->error());
 597: 
 598:         // Insert new config option o_default_dst
 599:         if (!array_key_exists('o_default_dst', $pun_config))
 600:             $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'o_default_dst\', \'0\')') or error('Unable to insert config value \'o_default_dst\'', __FILE__, __LINE__, $db->error());
 601: 
 602:         // Insert new config option o_quote_depth
 603:         if (!array_key_exists('o_quote_depth', $pun_config))
 604:             $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'o_quote_depth\', \'3\')') or error('Unable to insert config value \'o_quote_depth\'', __FILE__, __LINE__, $db->error());
 605: 
 606:         // Insert new config option o_feed_type
 607:         if (!array_key_exists('o_feed_type', $pun_config))
 608:             $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'o_feed_type\', \'2\')') or error('Unable to insert config value \'o_feed_type\'', __FILE__, __LINE__, $db->error());
 609: 
 610:         // Insert config option o_base_url which was removed in 1.3
 611:         if (!array_key_exists('o_base_url', $pun_config))
 612:         {
 613:             // If it isn't in $pun_config['o_base_url'] it should be in $base_url, but just in-case it isn't we can make a guess at it
 614:             if (!isset($base_url))
 615:             {
 616:                 // Make an educated guess regarding base_url
 617:                 $base_url  = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://';    // protocol
 618:                 $base_url .= preg_replace('/:(80|443)$/', '', $_SERVER['HTTP_HOST']);                            // host[:port]
 619:                 $base_url .= str_replace('\\', '/', dirname($_SERVER['SCRIPT_NAME']));                            // path
 620:             }
 621: 
 622:             if (substr($base_url, -1) == '/')
 623:                 $base_url = substr($base_url, 0, -1);
 624: 
 625:             $db->query('INSERT INTO '.$db->prefix.'config (conf_name, conf_value) VALUES (\'o_base_url\', \''.$db->escape($base_url).'\')') or error('Unable to insert config value \'o_quote_depth\'', __FILE__, __LINE__, $db->error());
 626:         }
 627: 
 628:         if (strpos($cur_version, '1.2') === 0)
 629:         {
 630:             // Groups are almost the same as 1.2:
 631:             // unverified:    32000 -> 0
 632: 
 633:             $db->query('UPDATE '.$db->prefix.'users SET group_id = 0 WHERE group_id = 32000') or error('Unable to update unverified users', __FILE__, __LINE__, $db->error());
 634:         }
 635:         else if (strpos($cur_version, '1.3') === 0)
 636:         {
 637:             // Groups have changed quite a lot from 1.3:
 638:             // unverified:    0 -> 0
 639:             // admin:        1 -> 1
 640:             // mod:            ? -> 2
 641:             // guest:        2 -> 3
 642:             // member:        ? -> 4
 643: 
 644:             $result = $db->query('SELECT MAX(g_id) + 1 FROM '.$db->prefix.'groups') or error('Unable to select temp group ID', __FILE__, __LINE__, $db->error());
 645:             $temp_id = $db->result($result);
 646: 
 647:             $result = $db->query('SELECT g_id FROM '.$db->prefix.'groups WHERE g_moderator = 1 AND g_id > 1 LIMIT 1') or error('Unable to select moderator group', __FILE__, __LINE__, $db->error());
 648:             if ($db->num_rows($result))
 649:                 $mod_gid = $db->result($result);
 650:             else
 651:             {
 652:                 $db->query('INSERT INTO '.$db->prefix.'groups (g_title, g_user_title, g_moderator, g_mod_edit_users, g_mod_rename_users, g_mod_change_passwords, g_mod_ban_users, g_read_board, g_view_users, g_post_replies, g_post_topics, g_edit_posts, g_delete_posts, g_delete_topics, g_set_title, g_search, g_search_users, g_send_email, g_post_flood, g_search_flood, g_email_flood) VALUES('."'Moderators', 'Moderator', 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0)") or error('Unable to add group', __FILE__, __LINE__, $db->error());
 653:                 $mod_gid = $db->insert_id();
 654:             }
 655: 
 656:             $member_gid = $pun_config['o_default_user_group'];
 657: 
 658:             // move the mod group to a temp place
 659:             $db->query('UPDATE '.$db->prefix.'groups SET g_id = '.$temp_id.' WHERE g_id = '.$mod_gid) or error('Unable to update group ID', __FILE__, __LINE__, $db->error());
 660:             $db->query('UPDATE '.$db->prefix.'users SET group_id = '.$temp_id.' WHERE group_id = '.$mod_gid) or error('Unable to update users group ID', __FILE__, __LINE__, $db->error());
 661:             $db->query('UPDATE '.$db->prefix.'forum_perms SET group_id = '.$temp_id.' WHERE group_id = '.$mod_gid) or error('Unable to forum_perms group ID', __FILE__, __LINE__, $db->error());
 662:             if ($member_gid == $mod_gid) $member_gid = $temp_id;
 663: 
 664:             // move whoever is in 3 to a spare slot
 665:             $db->query('UPDATE '.$db->prefix.'groups SET g_id = '.$mod_gid.' WHERE g_id = 3') or error('Unable to update group ID', __FILE__, __LINE__, $db->error());
 666:             $db->query('UPDATE '.$db->prefix.'users SET group_id = '.$mod_gid.' WHERE group_id = 3') or error('Unable to update users group ID', __FILE__, __LINE__, $db->error());
 667:             $db->query('UPDATE '.$db->prefix.'forum_perms SET group_id = '.$mod_gid.' WHERE group_id = 3') or error('Unable to forum_perms group ID', __FILE__, __LINE__, $db->error());
 668:             if ($member_gid == 3) $member_gid = $mod_gid;
 669: 
 670:             // move guest to 3
 671:             $db->query('UPDATE '.$db->prefix.'groups SET g_id = 3 WHERE g_id = 2') or error('Unable to update group ID', __FILE__, __LINE__, $db->error());
 672:             $db->query('UPDATE '.$db->prefix.'users SET group_id = 3 WHERE group_id = 2') or error('Unable to update users group ID', __FILE__, __LINE__, $db->error());
 673:             $db->query('UPDATE '.$db->prefix.'forum_perms SET group_id = 3 WHERE group_id = 2') or error('Unable to forum_perms group ID', __FILE__, __LINE__, $db->error());
 674:             if ($member_gid == 2) $member_gid = 3;
 675: 
 676:             // move mod group in temp place to 2
 677:             $db->query('UPDATE '.$db->prefix.'groups SET g_id = 2 WHERE g_id = '.$temp_id) or error('Unable to update group ID', __FILE__, __LINE__, $db->error());
 678:             $db->query('UPDATE '.$db->prefix.'users SET group_id = 2 WHERE group_id = '.$temp_id) or error('Unable to update users group ID', __FILE__, __LINE__, $db->error());
 679:             $db->query('UPDATE '.$db->prefix.'forum_perms SET group_id = 2 WHERE group_id = '.$temp_id) or error('Unable to forum_perms group ID', __FILE__, __LINE__, $db->error());
 680:             if ($member_gid == $temp_id) $member_gid = 2;
 681: 
 682:             // Only move stuff around if it isn't already in the right place
 683:             if ($member_gid != $mod_gid || $member_gid != 4)
 684:             {
 685:                 // move members to temp place
 686:                 $db->query('UPDATE '.$db->prefix.'groups SET g_id = '.$temp_id.' WHERE g_id = '.$member_gid) or error('Unable to update group ID', __FILE__, __LINE__, $db->error());
 687:                 $db->query('UPDATE '.$db->prefix.'users SET group_id = '.$temp_id.' WHERE group_id = '.$member_gid) or error('Unable to update users group ID', __FILE__, __LINE__, $db->error());
 688:                 $db->query('UPDATE '.$db->prefix.'forum_perms SET group_id = '.$temp_id.' WHERE group_id = '.$member_gid) or error('Unable to forum_perms group ID', __FILE__, __LINE__, $db->error());
 689: 
 690:                 // move whoever is in 4 to members place
 691:                 $db->query('UPDATE '.$db->prefix.'groups SET g_id = '.$member_gid.' WHERE g_id = 4') or error('Unable to update group ID', __FILE__, __LINE__, $db->error());
 692:                 $db->query('UPDATE '.$db->prefix.'users SET group_id = '.$member_gid.' WHERE group_id = 4') or error('Unable to update users group ID', __FILE__, __LINE__, $db->error());
 693:                 $db->query('UPDATE '.$db->prefix.'forum_perms SET group_id = '.$member_gid.' WHERE group_id = 4') or error('Unable to forum_perms group ID', __FILE__, __LINE__, $db->error());
 694: 
 695:                 // move members in temp place to 4
 696:                 $db->query('UPDATE '.$db->prefix.'groups SET g_id = 4 WHERE g_id = '.$temp_id) or error('Unable to update group ID', __FILE__, __LINE__, $db->error());
 697:                 $db->query('UPDATE '.$db->prefix.'users SET group_id = 4 WHERE group_id = '.$temp_id) or error('Unable to update users group ID', __FILE__, __LINE__, $db->error());
 698:                 $db->query('UPDATE '.$db->prefix.'forum_perms SET group_id = 4 WHERE group_id = '.$temp_id) or error('Unable to forum_perms group ID', __FILE__, __LINE__, $db->error());
 699:             }
 700: 
 701:             $db->query('UPDATE '.$db->prefix.'config SET conf_value=\''.$member_gid.'\' WHERE conf_name=\'o_default_user_group\'') or error('Unable to update default user group ID', __FILE__, __LINE__, $db->error());
 702:         }
 703: 
 704:         // Server time zone is now simply the default time zone
 705:         if (!array_key_exists('o_default_timezone', $pun_config))
 706:             $db->query('UPDATE '.$db->prefix.'config SET conf_name = \'o_default_timezone\' WHERE conf_name = \'o_server_timezone\'') or error('Unable to update time zone config', __FILE__, __LINE__, $db->error());
 707: 
 708:         // Increase visit timeout to 30 minutes (only if it hasn't been changed from the default)
 709:         if (!array_key_exists('o_database_revision', $pun_config) && $pun_config['o_timeout_visit'] == '600')
 710:             $db->query('UPDATE '.$db->prefix.'config SET conf_value = \'1800\' WHERE conf_name = \'o_timeout_visit\'') or error('Unable to update visit timeout config', __FILE__, __LINE__, $db->error());
 711: 
 712:         // Remove obsolete g_post_polls permission from groups table
 713:         $db->drop_field('groups', 'g_post_polls');
 714: 
 715:         // Make room for multiple moderator groups
 716:         if (!$db->field_exists('groups', 'g_moderator'))
 717:         {
 718:             // Add g_moderator column to groups table
 719:             $db->add_field('groups', 'g_moderator', 'TINYINT(1)', false, 0, 'g_user_title') or error('Unable to add g_moderator field', __FILE__, __LINE__, $db->error());
 720: 
 721:             // Give the moderator group moderator privileges
 722:             $db->query('UPDATE '.$db->prefix.'groups SET g_moderator = 1 WHERE g_id = 2') or error('Unable to update moderator powers', __FILE__, __LINE__, $db->error());
 723:         }
 724: 
 725:         // Replace obsolete p_mod_edit_users config setting with new per-group permission
 726:         if (array_key_exists('p_mod_edit_users', $pun_config))
 727:         {
 728:             $db->query('DELETE FROM '.$db->prefix.'config WHERE conf_name = \'p_mod_edit_users\'') or error('Unable to update moderator powers', __FILE__, __LINE__, $db->error());
 729: 
 730:             $db->add_field('groups', 'g_mod_edit_users', 'TINYINT(1)', false, 0, 'g_moderator') or error('Unable to add g_mod_edit_users field', __FILE__, __LINE__, $db->error());
 731: 
 732:             $db->query('UPDATE '.$db->prefix.'groups SET g_mod_edit_users = '.$pun_config['p_mod_edit_users'].' WHERE g_moderator = 1') or error('Unable to update moderator powers', __FILE__, __LINE__, $db->error());
 733:         }
 734: 
 735:         // Replace obsolete p_mod_rename_users config setting with new per-group permission
 736:         if (array_key_exists('p_mod_rename_users', $pun_config))
 737:         {
 738:             $db->query('DELETE FROM '.$db->prefix.'config WHERE conf_name = \'p_mod_rename_users\'') or error('Unable to update moderator powers', __FILE__, __LINE__, $db->error());
 739: 
 740:             $db->add_field('groups', 'g_mod_rename_users', 'TINYINT(1)', false, 0, 'g_mod_edit_users') or error('Unable to add g_mod_rename_users field', __FILE__, __LINE__, $db->error());
 741: 
 742:             $db->query('UPDATE '.$db->prefix.'groups SET g_mod_rename_users = '.$pun_config['p_mod_rename_users'].' WHERE g_moderator = 1') or error('Unable to update moderator powers', __FILE__, __LINE__, $db->error());
 743:         }
 744: 
 745:         // Replace obsolete p_mod_change_passwords config setting with new per-group permission
 746:         if (array_key_exists('p_mod_change_passwords', $pun_config))
 747:         {
 748:             $db->query('DELETE FROM '.$db->prefix.'config WHERE conf_name = \'p_mod_change_passwords\'') or error('Unable to update moderator powers', __FILE__, __LINE__, $db->error());
 749: 
 750:             $db->add_field('groups', 'g_mod_change_passwords', 'TINYINT(1)', false, 0, 'g_mod_rename_users') or error('Unable to add g_mod_change_passwords field', __FILE__, __LINE__, $db->error());
 751: 
 752:             $db->query('UPDATE '.$db->prefix.'groups SET g_mod_change_passwords = '.$pun_config['p_mod_change_passwords'].' WHERE g_moderator = 1') or error('Unable to update moderator powers', __FILE__, __LINE__, $db->error());
 753:         }
 754: 
 755:         // Replace obsolete p_mod_ban_users config setting with new per-group permission
 756:         if (array_key_exists('p_mod_ban_users', $pun_config))
 757:         {
 758:             $db->query('DELETE FROM '.$db->prefix.'config WHERE conf_name = \'p_mod_ban_users\'') or error('Unable to update moderator powers', __FILE__, __LINE__, $db->error());
 759: 
 760:             $db->add_field('groups', 'g_mod_ban_users', 'TINYINT(1)', false, 0, 'g_mod_change_passwords') or error('Unable to add g_mod_ban_users field', __FILE__, __LINE__, $db->error());
 761: 
 762:             $db->query('UPDATE '.$db->prefix.'groups SET g_mod_ban_users = '.$pun_config['p_mod_ban_users'].' WHERE g_moderator = 1') or error('Unable to update moderator powers', __FILE__, __LINE__, $db->error());
 763:         }
 764: 
 765:         // We need to add a unique index to avoid users having multiple rows in the online table
 766:         if (!$db->index_exists('online', 'user_id_ident_idx'))
 767:         {
 768:             $db->truncate_table('online') or error('Unable to clear online table', __FILE__, __LINE__, $db->error());
 769: 
 770:             if ($mysql)
 771:                 $db->add_index('online', 'user_id_ident_idx', array('user_id', 'ident(25)'), true) or error('Unable to add user_id_ident_idx index', __FILE__, __LINE__, $db->error());
 772:             else
 773:                 $db->add_index('online', 'user_id_ident_idx', array('user_id', 'ident'), true) or error('Unable to add user_id_ident_idx index', __FILE__, __LINE__, $db->error());
 774:         }
 775: 
 776:         // Remove the redundant user_id_idx on the online table
 777:         $db->drop_index('online', 'user_id_idx') or error('Unable to drop user_id_idx index', __FILE__, __LINE__, $db->error());
 778: 
 779:         // Add an index to ident on the online table
 780:         if ($mysql)
 781:             $db->add_index('online', 'ident_idx', array('ident(25)')) or error('Unable to add ident_idx index', __FILE__, __LINE__, $db->error());
 782:         else
 783:             $db->add_index('online', 'ident_idx', array('ident')) or error('Unable to add ident_idx index', __FILE__, __LINE__, $db->error());
 784: 
 785:         // Add an index to logged in the online table
 786:         $db->add_index('online', 'logged_idx', array('logged')) or error('Unable to add logged_idx index', __FILE__, __LINE__, $db->error());
 787: 
 788:         // Add an index to last_post in the topics table
 789:         $db->add_index('topics', 'last_post_idx', array('last_post')) or error('Unable to add last_post_idx index', __FILE__, __LINE__, $db->error());
 790: 
 791:         // Add an index to username on the bans table
 792:         if ($mysql)
 793:             $db->add_index('bans', 'username_idx', array('username(25)')) or error('Unable to add username_idx index', __FILE__, __LINE__, $db->error());
 794:         else
 795:             $db->add_index('bans', 'username_idx', array('username')) or error('Unable to add username_idx index', __FILE__, __LINE__, $db->error());
 796: 
 797:         // Change the username_idx on users to a unique index of max size 25
 798:         $db->drop_index('users', 'username_idx') or error('Unable to drop old username_idx index', __FILE__, __LINE__, $db->error());
 799:         $field = $mysql ? 'username(25)' : 'username';
 800: 
 801:         // Attempt to add a unique index. If the user doesn't use a transactional database this can fail due to multiple matching usernames in the
 802:         // users table. This is bad, but just giving up if it happens is even worse! If it fails just add a regular non-unique index.
 803:         if (!$db->add_index('users', 'username_idx', array($field), true))
 804:             $db->add_index('users', 'username_idx', array($field)) or error('Unable to add username_idx field', __FILE__, __LINE__, $db->error());
 805: 
 806:         // Add g_view_users field to groups table
 807:         $db->add_field('groups', 'g_view_users', 'TINYINT(1)', false, 1, 'g_read_board') or error('Unable to add g_view_users field', __FILE__, __LINE__, $db->error());
 808: 
 809:         // Add the last_email_sent column to the users table and the g_send_email and
 810:         // g_email_flood columns to the groups table
 811:         $db->add_field('users', 'last_email_sent', 'INT(10) UNSIGNED', true, null, 'last_search') or error('Unable to add last_email_sent field', __FILE__, __LINE__, $db->error());
 812:         $db->add_field('groups', 'g_send_email', 'TINYINT(1)', false, 1, 'g_search_users') or error('Unable to add g_send_email field', __FILE__, __LINE__, $db->error());
 813:         $db->add_field('groups', 'g_email_flood', 'SMALLINT(6)', false, 60, 'g_search_flood') or error('Unable to add g_email_flood field', __FILE__, __LINE__, $db->error());
 814: 
 815:         // Set non-default g_send_email and g_flood_email values properly
 816:         $db->query('UPDATE '.$db->prefix.'groups SET g_send_email = 0 WHERE g_id = 3') or error('Unable to update group email permissions', __FILE__, __LINE__, $db->error());
 817:         $db->query('UPDATE '.$db->prefix.'groups SET g_email_flood = 0 WHERE g_id IN (1,2,3)') or error('Unable to update group email permissions', __FILE__, __LINE__, $db->error());
 818: 
 819:         // Add the auto notify/subscription option to the users table
 820:         $db->add_field('users', 'auto_notify', 'TINYINT(1)', false, 0, 'notify_with_post') or error('Unable to add auto_notify field', __FILE__, __LINE__, $db->error());
 821: 
 822:         // Add the first_post_id column to the topics table
 823:         if (!$db->field_exists('topics', 'first_post_id'))
 824:         {
 825:             $db->add_field('topics', 'first_post_id', 'INT(10) UNSIGNED', false, 0, 'posted') or error('Unable to add first_post_id field', __FILE__, __LINE__, $db->error());
 826:             $db->add_index('topics', 'first_post_id_idx', array('first_post_id')) or error('Unable to add first_post_id_idx index', __FILE__, __LINE__, $db->error());
 827: 
 828:             // Now that we've added the column and indexed it, we need to give it correct data
 829:             $result = $db->query('SELECT MIN(id) AS first_post, topic_id FROM '.$db->prefix.'posts GROUP BY topic_id') or error('Unable to fetch first_post_id', __FILE__, __LINE__, $db->error());
 830: 
 831:             while ($cur_post = $db->fetch_assoc($result))
 832:                 $db->query('UPDATE '.$db->prefix.'topics SET first_post_id = '.$cur_post['first_post'].' WHERE id = '.$cur_post['topic_id']) or error('Unable to update first_post_id', __FILE__, __LINE__, $db->error());
 833:         }
 834: 
 835:         // Move any users with the old unverified status to their new group
 836:         $db->query('UPDATE '.$db->prefix.'users SET group_id=0 WHERE group_id=32000') or error('Unable to move unverified users', __FILE__, __LINE__, $db->error());
 837: 
 838:         // Add the ban_creator column to the bans table
 839:         $db->add_field('bans', 'ban_creator', 'INT(10) UNSIGNED', false, 0) or error('Unable to add ban_creator field', __FILE__, __LINE__, $db->error());
 840: 
 841:         // Add the time/date format settings to the user table
 842:         $db->add_field('users', 'time_format', 'TINYINT(1)', false, 0, 'dst') or error('Unable to add time_format field', __FILE__, __LINE__, $db->error());
 843:         $db->add_field('users', 'date_format', 'TINYINT(1)', false, 0, 'dst') or error('Unable to add date_format field', __FILE__, __LINE__, $db->error());
 844: 
 845:         // Change the search_data field to mediumtext
 846:         $db->alter_field('search_cache', 'search_data', 'MEDIUMTEXT', true) or error('Unable to alter search_data field', __FILE__, __LINE__, $db->error());
 847: 
 848:         // Incase we had the fulltext search extension installed (1.3-legacy), remove it
 849:         $db->drop_index('topics', 'subject_idx') or error('Unable to drop subject_idx index', __FILE__, __LINE__, $db->error());
 850:         $db->drop_index('posts', 'message_idx') or error('Unable to drop message_idx index', __FILE__, __LINE__, $db->error());
 851: 
 852:         // If the search_cache table has been dropped by the fulltext search extension, recreate it
 853:         if (!$db->table_exists('search_cache'))
 854:         {
 855:             $schema = array(
 856:                 'FIELDS'        => array(
 857:                     'id'            => array(
 858:                         'datatype'        => 'INT(10) UNSIGNED',
 859:                         'allow_null'    => false,
 860:                         'default'        => '0'
 861:                     ),
 862:                     'ident'            => array(
 863:                         'datatype'        => 'VARCHAR(200)',
 864:                         'allow_null'    => false,
 865:                         'default'        => '\'\''
 866:                     ),
 867:                     'search_data'    => array(
 868:                         'datatype'        => 'MEDIUMTEXT',
 869:                         'allow_null'    => true
 870:                     )
 871:                 ),
 872:                 'PRIMARY KEY'    => array('id'),
 873:                 'INDEXES'        => array(
 874:                     'ident_idx'    => array('ident')
 875:                 )
 876:             );
 877: 
 878:             if ($db_type == 'mysql' || $db_type == 'mysqli' || $db_type == 'mysql_innodb' || $db_type == 'mysqli_innodb')
 879:                 $schema['INDEXES']['ident_idx'] = array('ident(8)');
 880: 
 881:             $db->create_table('search_cache', $schema);
 882:         }
 883: 
 884:         // If the search_matches table has been dropped by the fulltext search extension, recreate it
 885:         if (!$db->table_exists('search_matches'))
 886:         {
 887:             $schema = array(
 888:                 'FIELDS'        => array(
 889:                     'post_id'        => array(
 890:                         'datatype'        => 'INT(10) UNSIGNED',
 891:                         'allow_null'    => false,
 892:                         'default'        => '0'
 893:                     ),
 894:                     'word_id'        => array(
 895:                         'datatype'        => 'INT(10) UNSIGNED',
 896:                         'allow_null'    => false,
 897:                         'default'        => '0'
 898:                     ),
 899:                     'subject_match'    => array(
 900:                         'datatype'        => 'TINYINT(1)',
 901:                         'allow_null'    => false,
 902:                         'default'        => '0'
 903:                     )
 904:                 ),
 905:                 'INDEXES'        => array(
 906:                     'word_id_idx'    => array('word_id'),
 907:                     'post_id_idx'    => array('post_id')
 908:                 )
 909:             );
 910: 
 911:             $db->create_table('search_matches', $schema);
 912:         }
 913: 
 914:         // If the search_words table has been dropped by the fulltext search extension, recreate it
 915:         if (!$db->table_exists('search_words'))
 916:         {
 917:             $schema = array(
 918:                 'FIELDS'        => array(
 919:                     'id'            => array(
 920:                         'datatype'        => 'SERIAL',
 921:                         'allow_null'    => false
 922:                     ),
 923:                     'word'            => array(
 924:                         'datatype'        => 'VARCHAR(20)',
 925:                         'allow_null'    => false,
 926:                         'default'        => '\'\'',
 927:                         'collation'        => 'bin'
 928:                     )
 929:                 ),
 930:                 'PRIMARY KEY'    => array('word'),
 931:                 'INDEXES'        => array(
 932:                     'id_idx'    => array('id')
 933:                 )
 934:             );
 935: 
 936:             if ($db_type == 'sqlite')
 937:             {
 938:                 $schema['PRIMARY KEY'] = array('id');
 939:                 $schema['UNIQUE KEYS'] = array('word_idx'    => array('word'));
 940:             }
 941: 
 942:             $db->create_table('search_words', $schema);
 943:         }
 944: 
 945:         // Change the default style if the old doesn't exist anymore
 946:         if ($pun_config['o_default_style'] != $default_style)
 947:             $db->query('UPDATE '.$db->prefix.'config SET conf_value = \''.$db->escape($default_style).'\' WHERE conf_name = \'o_default_style\'') or error('Unable to update default style config', __FILE__, __LINE__, $db->error());
 948: 
 949:         // Should we do charset conversion or not?
 950:         if (strpos($cur_version, '1.2') === 0 && isset($_GET['convert_charset']))
 951:             $query_str = '?stage=conv_bans&req_old_charset='.$old_charset;
 952: 
 953:         break;
 954: 
 955: 
 956:     // Convert bans
 957:     case 'conv_bans':
 958:         $query_str = '?stage=conv_categories&req_old_charset='.$old_charset;
 959: 
 960:         function _conv_bans($cur_item, $old_charset)
 961:         {
 962:             echo 'Converting ban '.$cur_item['id'].' â€¦<br />'."\n";
 963: 
 964:             convert_to_utf8($cur_item['username'], $old_charset);
 965:             convert_to_utf8($cur_item['message'], $old_charset);
 966: 
 967:             return $cur_item;
 968:         }
 969: 
 970:         $end_at = convert_table_utf8($db->prefix.'bans', '_conv_bans', $old_charset, 'id', $start_at);
 971: 
 972:         if ($end_at !== true)
 973:             $query_str = '?stage=conv_bans&req_old_charset='.$old_charset.'&start_at='.$end_at;
 974: 
 975:         break;
 976: 
 977: 
 978:     // Convert categories
 979:     case 'conv_categories':
 980:         $query_str = '?stage=conv_censors&req_old_charset='.$old_charset;
 981: 
 982:         echo 'Converting categories â€¦'."<br />\n";
 983: 
 984:         function _conv_categories($cur_item, $old_charset)
 985:         {
 986:             convert_to_utf8($cur_item['cat_name'], $old_charset);
 987: 
 988:             return $cur_item;
 989:         }
 990: 
 991:         convert_table_utf8($db->prefix.'categories', '_conv_categories', $old_charset, 'id');
 992: 
 993:         break;
 994: 
 995: 
 996:     // Convert censor words
 997:     case 'conv_censors':
 998:         $query_str = '?stage=conv_config&req_old_charset='.$old_charset;
 999: 
 1000:         echo 'Converting censor words â€¦'."<br />\n";
 1001: 
 1002:         function _conv_censoring($cur_item, $old_charset)
 1003:         {
 1004:             convert_to_utf8($cur_item['search_for'], $old_charset);
 1005:             convert_to_utf8($cur_item['replace_with'], $old_charset);
 1006: 
 1007:             return $cur_item;
 1008:         }
 1009: 
 1010:         convert_table_utf8($db->prefix.'censoring', '_conv_censoring', $old_charset, 'id');
 1011: 
 1012:         break;
 1013: 
 1014: 
 1015:     // Convert config
 1016:     case 'conv_config':
 1017:         $query_str = '?stage=conv_forums&req_old_charset='.$old_charset;
 1018: 
 1019:         echo 'Converting configuration â€¦'."<br />\n";
 1020: 
 1021:         function _conv_config($cur_item, $old_charset)
 1022:         {
 1023:             convert_to_utf8($cur_item['conf_value'], $old_charset);
 1024: 
 1025:             return $cur_item;
 1026:         }
 1027: 
 1028:         convert_table_utf8($db->prefix.'config', '_conv_config', $old_charset, 'conf_name');
 1029: 
 1030:         break;
 1031: 
 1032: 
 1033:     // Convert forums
 1034:     case 'conv_forums':
 1035:         $query_str = '?stage=conv_perms&req_old_charset='.$old_charset;
 1036: 
 1037:         echo 'Converting forums â€¦'."<br />\n";
 1038: 
 1039:         function _conv_forums($cur_item, $old_charset)
 1040:         {
 1041:             $moderators = ($cur_item['moderators'] != '') ? unserialize($cur_item['moderators']) : array();
 1042:             $moderators_utf8 = array();
 1043:             foreach ($moderators as $mod_username => $mod_user_id)
 1044:             {
 1045:                 convert_to_utf8($mod_username, $old_charset);
 1046:                 $moderators_utf8[$mod_username] = $mod_user_id;
 1047:             }
 1048: 
 1049:             convert_to_utf8($cur_item['forum_name'], $old_charset);
 1050:             convert_to_utf8($cur_item['forum_desc'], $old_charset);
 1051: 
 1052:             if (!empty($moderators_utf8))
 1053:                 $cur_item['moderators'] = serialize($moderators_utf8);
 1054: 
 1055:             return $cur_item;
 1056:         }
 1057: 
 1058:         convert_table_utf8($db->prefix.'forums', '_conv_forums', $old_charset, 'id');
 1059: 
 1060:         break;
 1061: 
 1062: 
 1063:     // Convert forum permissions
 1064:     case 'conv_perms':
 1065:         $query_str = '?stage=conv_groups&req_old_charset='.$old_charset;
 1066: 
 1067:         alter_table_utf8($db->prefix.'forum_perms');
 1068: 
 1069:         break;
 1070: 
 1071: 
 1072:     // Convert groups
 1073:     case 'conv_groups':
 1074:         $query_str = '?stage=conv_online&req_old_charset='.$old_charset;
 1075: 
 1076:         echo 'Converting groups â€¦'."<br />\n";
 1077: 
 1078:         function _conv_groups($cur_item, $old_charset)
 1079:         {
 1080:             convert_to_utf8($cur_item['g_title'], $old_charset);
 1081:             convert_to_utf8($cur_item['g_user_title'], $old_charset);
 1082: 
 1083:             return $cur_item;
 1084:         }
 1085: 
 1086:         convert_table_utf8($db->prefix.'groups', '_conv_groups', $old_charset, 'g_id');
 1087: 
 1088:         break;
 1089: 
 1090: 
 1091:     // Convert online
 1092:     case 'conv_online':
 1093:         $query_str = '?stage=conv_posts&req_old_charset='.$old_charset;
 1094: 
 1095:         // Truncate the table
 1096:         $db->truncate_table('online') or error('Unable to empty online table', __FILE__, __LINE__, $db->error());
 1097: 
 1098:         alter_table_utf8($db->prefix.'online');
 1099: 
 1100:         break;
 1101: 
 1102: 
 1103:     // Convert posts
 1104:     case 'conv_posts':
 1105:         $query_str = '?stage=conv_ranks&req_old_charset='.$old_charset;
 1106: 
 1107:         function _conv_posts($cur_item, $old_charset)
 1108:         {
 1109:             echo 'Converting post '.$cur_item['id'].' â€¦<br />'."\n";
 1110: 
 1111:             convert_to_utf8($cur_item['poster'], $old_charset);
 1112:             convert_to_utf8($cur_item['message'], $old_charset);
 1113:             convert_to_utf8($cur_item['edited_by'], $old_charset);
 1114: 
 1115:             return $cur_item;
 1116:         }
 1117: 
 1118:         $end_at = convert_table_utf8($db->prefix.'posts', '_conv_posts', $old_charset, 'id', $start_at);
 1119: 
 1120:         if ($end_at !== true)
 1121:             $query_str = '?stage=conv_posts&req_old_charset='.$old_charset.'&start_at='.$end_at;
 1122: 
 1123:         break;
 1124: 
 1125: 
 1126:     // Convert ranks
 1127:     case 'conv_ranks':
 1128:         $query_str = '?stage=conv_reports&req_old_charset='.$old_charset;
 1129: 
 1130:         echo 'Converting ranks â€¦'."<br />\n";
 1131: 
 1132:         function _conv_ranks($cur_item, $old_charset)
 1133:         {
 1134:             convert_to_utf8($cur_item['rank'], $old_charset);
 1135: 
 1136:             return $cur_item;
 1137:         }
 1138: 
 1139:         convert_table_utf8($db->prefix.'ranks', '_conv_ranks', $old_charset, 'id');
 1140: 
 1141:         break;
 1142: 
 1143: 
 1144:     // Convert reports
 1145:     case 'conv_reports':
 1146:         $query_str = '?stage=conv_search_cache&req_old_charset='.$old_charset;
 1147: 
 1148:         function _conv_reports($cur_item, $old_charset)
 1149:         {
 1150:             echo 'Converting report '.$cur_item['id'].' â€¦<br />'."\n";
 1151: 
 1152:             convert_to_utf8($cur_item['message'], $old_charset);
 1153: 
 1154:             return $cur_item;
 1155:         }
 1156: 
 1157:         $end_at = convert_table_utf8($db->prefix.'reports', '_conv_reports', $old_charset, 'id', $start_at);
 1158: 
 1159:         if ($end_at !== true)
 1160:             $query_str = '?stage=conv_reports&req_old_charset='.$old_charset.'&start_at='.$end_at;
 1161: 
 1162:         break;
 1163: 
 1164: 
 1165:     // Convert search cache
 1166:     case 'conv_search_cache':
 1167:         $query_str = '?stage=conv_search_matches&req_old_charset='.$old_charset;
 1168: 
 1169:         // Truncate the table
 1170:         $db->truncate_table('search_cache') or error('Unable to empty search cache table', __FILE__, __LINE__, $db->error());
 1171: 
 1172:         alter_table_utf8($db->prefix.'search_cache');
 1173: 
 1174:         break;
 1175: 
 1176: 
 1177:     // Convert search matches
 1178:     case 'conv_search_matches':
 1179:         $query_str = '?stage=conv_search_words&req_old_charset='.$old_charset;
 1180: 
 1181:         // Truncate the table
 1182:         $db->truncate_table('search_matches') or error('Unable to empty search index match table', __FILE__, __LINE__, $db->error());
 1183: 
 1184:         alter_table_utf8($db->prefix.'search_matches');
 1185: 
 1186:         break;
 1187: 
 1188: 
 1189:     // Convert search words
 1190:     case 'conv_search_words':
 1191:         $query_str = '?stage=conv_subscriptions&req_old_charset='.$old_charset;
 1192: 
 1193:         // Truncate the table
 1194:         $db->truncate_table('search_words') or error('Unable to empty search index words table', __FILE__, __LINE__, $db->error());
 1195: 
 1196:         // Reset the sequence for the search words (not needed for SQLite)
 1197:         switch ($db_type)
 1198:         {
 1199:             case 'mysql':
 1200:             case 'mysqli':
 1201:             case 'mysql_innodb':
 1202:             case 'mysqli_innodb':
 1203:                 $db->query('ALTER TABLE '.$db->prefix.'search_words auto_increment=1') or error('Unable to update table auto_increment', __FILE__, __LINE__, $db->error());
 1204:                 break;
 1205: 
 1206:             case 'pgsql';
 1207:                 $db->query('SELECT setval(\''.$db->prefix.'search_words_id_seq\', 1, false)') or error('Unable to update sequence', __FILE__, __LINE__, $db->error());
 1208:                 break;
 1209:         }
 1210: 
 1211:         alter_table_utf8($db->prefix.'search_words');
 1212: 
 1213:         break;
 1214: 
 1215: 
 1216:     // Convert subscriptions
 1217:     case 'conv_subscriptions':
 1218:         $query_str = '?stage=conv_topics&req_old_charset='.$old_charset;
 1219: 
 1220:         alter_table_utf8($db->prefix.'subscriptions');
 1221: 
 1222:         break;
 1223: 
 1224: 
 1225:     // Convert topics
 1226:     case 'conv_topics':
 1227:         $query_str = '?stage=conv_users&req_old_charset='.$old_charset;
 1228: 
 1229:         function _conv_topics($cur_item, $old_charset)
 1230:         {
 1231:             echo 'Converting topic '.$cur_item['id'].' â€¦<br />'."\n";
 1232: 
 1233:             convert_to_utf8($cur_item['poster'], $old_charset);
 1234:             convert_to_utf8($cur_item['subject'], $old_charset);
 1235:             convert_to_utf8($cur_item['last_poster'], $old_charset);
 1236: 
 1237:             return $cur_item;
 1238:         }
 1239: 
 1240:         $end_at = convert_table_utf8($db->prefix.'topics', '_conv_topics', $old_charset, 'id', $start_at);
 1241: 
 1242:         if ($end_at !== true)
 1243:             $query_str = '?stage=conv_topics&req_old_charset='.$old_charset.'&start_at='.$end_at;
 1244: 
 1245:         break;
 1246: 
 1247: 
 1248:     // Convert users
 1249:     case 'conv_users':
 1250:         $query_str = '?stage=preparse_posts';
 1251: 
 1252:         function _conv_users($cur_item, $old_charset)
 1253:         {
 1254:             echo 'Converting user '.$cur_item['id'].' â€¦<br />'."\n";
 1255: 
 1256:             convert_to_utf8($cur_item['username'], $old_charset);
 1257:             convert_to_utf8($cur_item['title'], $old_charset);
 1258:             convert_to_utf8($cur_item['realname'], $old_charset);
 1259:             convert_to_utf8($cur_item['location'], $old_charset);
 1260:             convert_to_utf8($cur_item['signature'], $old_charset);
 1261:             convert_to_utf8($cur_item['admin_note'], $old_charset);
 1262: 
 1263:             return $cur_item;
 1264:         }
 1265: 
 1266:         $end_at = convert_table_utf8($db->prefix.'users', '_conv_users', $old_charset, 'id', $start_at);
 1267: 
 1268:         if ($end_at !== true)
 1269:             $query_str = '?stage=conv_users&req_old_charset='.$old_charset.'&start_at='.$end_at;
 1270: 
 1271:         break;
 1272: 
 1273: 
 1274:     // Preparse posts
 1275:     case 'preparse_posts':
 1276:         $query_str = '?stage=preparse_sigs';
 1277: 
 1278:         // If we don't need to parse the posts, skip this stage
 1279:         if (isset($pun_config['o_parser_revision']) && $pun_config['o_parser_revision'] >= UPDATE_TO_PARSER_REVISION)
 1280:             break;
 1281: 
 1282:         require PUN_ROOT.'include/parser.php';
 1283: 
 1284:         // Fetch posts to process this cycle
 1285:         $result = $db->query('SELECT id, message FROM '.$db->prefix.'posts WHERE id > '.$start_at.' ORDER BY id ASC LIMIT '.PER_PAGE) or error('Unable to fetch posts', __FILE__, __LINE__, $db->error());
 1286: 
 1287:         $temp = array();
 1288:         $end_at = 0;
 1289:         while ($cur_item = $db->fetch_assoc($result))
 1290:         {
 1291:             echo 'Preparsing post '.$cur_item['id'].' â€¦<br />'."\n";
 1292:             $db->query('UPDATE '.$db->prefix.'posts SET message = \''.$db->escape(preparse_bbcode($cur_item['message'], $temp)).'\' WHERE id = '.$cur_item['id']) or error('Unable to update post', __FILE__, __LINE__, $db->error());
 1293: 
 1294:             $end_at = $cur_item['id'];
 1295:         }
 1296: 
 1297:         // Check if there is more work to do
 1298:         if ($end_at > 0)
 1299:         {
 1300:             $result = $db->query('SELECT 1 FROM '.$db->prefix.'posts WHERE id > '.$end_at.' ORDER BY id ASC LIMIT 1') or error('Unable to fetch next ID', __FILE__, __LINE__, $db->error());
 1301: 
 1302:             if ($db->num_rows($result) > 0)
 1303:                 $query_str = '?stage=preparse_posts&start_at='.$end_at;
 1304:         }
 1305: 
 1306:         break;
 1307: 
 1308: 
 1309:     // Preparse signatures
 1310:     case 'preparse_sigs':
 1311:         $query_str = '?stage=rebuild_idx';
 1312: 
 1313:         // If we don't need to parse the sigs, skip this stage
 1314:         if (isset($pun_config['o_parser_revision']) && $pun_config['o_parser_revision'] >= UPDATE_TO_PARSER_REVISION)
 1315:             break;
 1316: 
 1317:         require PUN_ROOT.'include/parser.php';
 1318: 
 1319:         // Fetch users to process this cycle
 1320:         $result = $db->query('SELECT id, signature FROM '.$db->prefix.'users WHERE id > '.$start_at.' ORDER BY id ASC LIMIT '.PER_PAGE) or error('Unable to fetch users', __FILE__, __LINE__, $db->error());
 1321: 
 1322:         $temp = array();
 1323:         $end_at = 0;
 1324:         while ($cur_item = $db->fetch_assoc($result))
 1325:         {
 1326:             echo 'Preparsing signature '.$cur_item['id'].' â€¦<br />'."\n";
 1327:             $db->query('UPDATE '.$db->prefix.'users SET signature = \''.$db->escape(preparse_bbcode($cur_item['signature'], $temp, true)).'\' WHERE id = '.$cur_item['id']) or error('Unable to update user', __FILE__, __LINE__, $db->error());
 1328: 
 1329:             $end_at = $cur_item['id'];
 1330:         }
 1331: 
 1332:         // Check if there is more work to do
 1333:         if ($end_at > 0)
 1334:         {
 1335:             $result = $db->query('SELECT 1 FROM '.$db->prefix.'users WHERE id > '.$end_at.' ORDER BY id ASC LIMIT 1') or error('Unable to fetch next ID', __FILE__, __LINE__, $db->error());
 1336:             if ($db->num_rows($result) > 0)
 1337:                 $query_str = '?stage=preparse_sigs&start_at='.$end_at;
 1338:         }
 1339: 
 1340:         break;
 1341: 
 1342: 
 1343:     // Rebuild the search index
 1344:     case 'rebuild_idx':
 1345:         $query_str = '?stage=finish';
 1346: 
 1347:         // If we don't need to update the search index, skip this stage
 1348:         if (isset($pun_config['o_searchindex_revision']) && $pun_config['o_searchindex_revision'] >= UPDATE_TO_SI_REVISION)
 1349:             break;
 1350: 
 1351:         if ($start_at == 0)
 1352:         {
 1353:             // Truncate the tables just in-case we didn't already (if we are coming directly here without converting the tables)
 1354:             $db->truncate_table('search_cache') or error('Unable to empty search cache table', __FILE__, __LINE__, $db->error());
 1355:             $db->truncate_table('search_matches') or error('Unable to empty search index match table', __FILE__, __LINE__, $db->error());
 1356:             $db->truncate_table('search_words') or error('Unable to empty search index words table', __FILE__, __LINE__, $db->error());
 1357: 
 1358:             // Reset the sequence for the search words (not needed for SQLite)
 1359:             switch ($db_type)
 1360:             {
 1361:                 case 'mysql':
 1362:                 case 'mysqli':
 1363:                 case 'mysql_innodb':
 1364:                 case 'mysqli_innodb':
 1365:                     $db->query('ALTER TABLE '.$db->prefix.'search_words auto_increment=1') or error('Unable to update table auto_increment', __FILE__, __LINE__, $db->error());
 1366:                     break;
 1367: 
 1368:                 case 'pgsql';
 1369:                     $db->query('SELECT setval(\''.$db->prefix.'search_words_id_seq\', 1, false)') or error('Unable to update sequence', __FILE__, __LINE__, $db->error());
 1370:                     break;
 1371:             }
 1372:         }
 1373: 
 1374:         require PUN_ROOT.'include/search_idx.php';
 1375: 
 1376:         // Fetch posts to process this cycle
 1377:         $result = $db->query('SELECT p.id, p.message, t.subject, t.first_post_id FROM '.$db->prefix.'posts AS p INNER JOIN '.$db->prefix.'topics AS t ON t.id=p.topic_id WHERE p.id > '.$start_at.' ORDER BY p.id ASC LIMIT '.PER_PAGE) or error('Unable to fetch posts', __FILE__, __LINE__, $db->error());
 1378: 
 1379:         $end_at = 0;
 1380:         while ($cur_item = $db->fetch_assoc($result))
 1381:         {
 1382:             echo 'Rebuilding index for post '.$cur_item['id'].' â€¦<br />'."\n";
 1383: 
 1384:             if ($cur_item['id'] == $cur_item['first_post_id'])
 1385:                 update_search_index('post', $cur_item['id'], $cur_item['message'], $cur_item['subject']);
 1386:             else
 1387:                 update_search_index('post', $cur_item['id'], $cur_item['message']);
 1388: 
 1389:             $end_at = $cur_item['id'];
 1390:         }
 1391: 
 1392:         // Check if there is more work to do
 1393:         if ($end_at > 0)
 1394:         {
 1395:             $result = $db->query('SELECT 1 FROM '.$db->prefix.'posts WHERE id > '.$end_at.' ORDER BY id ASC LIMIT 1') or error('Unable to fetch next ID', __FILE__, __LINE__, $db->error());
 1396: 
 1397:             if ($db->num_rows($result) > 0)
 1398:                 $query_str = '?stage=rebuild_idx&start_at='.$end_at;
 1399:         }
 1400: 
 1401:         break;
 1402: 
 1403: 
 1404:     // Show results page
 1405:     case 'finish':
 1406:         // We update the version number
 1407:         $db->query('UPDATE '.$db->prefix.'config SET conf_value = \''.UPDATE_TO.'\' WHERE conf_name = \'o_cur_version\'') or error('Unable to update version', __FILE__, __LINE__, $db->error());
 1408: 
 1409:         // And the database revision number
 1410:         $db->query('UPDATE '.$db->prefix.'config SET conf_value = \''.UPDATE_TO_DB_REVISION.'\' WHERE conf_name = \'o_database_revision\'') or error('Unable to update database revision number', __FILE__, __LINE__, $db->error());
 1411: 
 1412:         // And the search index revision number
 1413:         $db->query('UPDATE '.$db->prefix.'config SET conf_value = \''.UPDATE_TO_SI_REVISION.'\' WHERE conf_name = \'o_searchindex_revision\'') or error('Unable to update search index revision number', __FILE__, __LINE__, $db->error());
 1414: 
 1415:         // And the parser revision number
 1416:         $db->query('UPDATE '.$db->prefix.'config SET conf_value = \''.UPDATE_TO_PARSER_REVISION.'\' WHERE conf_name = \'o_parser_revision\'') or error('Unable to update parser revision number', __FILE__, __LINE__, $db->error());
 1417: 
 1418:         // Check the default language still exists!
 1419:         if (!file_exists(PUN_ROOT.'lang/'.$pun_config['o_default_lang'].'/common.php'))
 1420:             $db->query('UPDATE '.$db->prefix.'config SET conf_value = \'English\' WHERE conf_name = \'o_default_lang\'') or error('Unable to update default language', __FILE__, __LINE__, $db->error());
 1421: 
 1422:         // Check the default style still exists!
 1423:         if (!file_exists(PUN_ROOT.'style/'.$pun_config['o_default_style'].'.css'))
 1424:             $db->query('UPDATE '.$db->prefix.'config SET conf_value = \'Air\' WHERE conf_name = \'o_default_style\'') or error('Unable to update default style', __FILE__, __LINE__, $db->error());
 1425: 
 1426:         // This feels like a good time to synchronize the forums
 1427:         $result = $db->query('SELECT id FROM '.$db->prefix.'forums') or error('Unable to fetch forum IDs', __FILE__, __LINE__, $db->error());
 1428: 
 1429:         while ($row = $db->fetch_row($result))
 1430:             update_forum($row[0]);
 1431: 
 1432:         // Empty the PHP cache
 1433:         forum_clear_cache();
 1434: 
 1435: ?>
 1436: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 1437: 
 1438: <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
 1439: <head>
 1440: <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 1441: <title>FluxBB Database Update</title>
 1442: <link rel="stylesheet" type="text/css" href="style/<?php echo $default_style ?>.css" />
 1443: </head>
 1444: <body>
 1445: 
 1446: <div id="pundb_update" class="pun">
 1447: <div class="top-box"><div><!-- Top Corners --></div></div>
 1448: <div class="punwrap">
 1449: 
 1450: <div class="blockform">
 1451:     <h2><span>FluxBB Update</span></h2>
 1452:     <div class="box">
 1453:         <div class="fakeform">
 1454:             <div class="inform">
 1455:                 <div class="forminfo">
 1456:                     <p style="font-size: 1.1em">Your forum database was successfully updated. You may now <a href="<?php echo PUN_ROOT ?>index.php">go to the forum index</a>.</p>
 1457:                 </div>
 1458:             </div>
 1459:         </div>
 1460:     </div>
 1461: </div>
 1462: 
 1463: </div>
 1464: <div class="end-box"><div><!-- Bottom Corners --></div></div>
 1465: </div>
 1466: 
 1467: </body>
 1468: </html>
 1469: <?php
 1470: 
 1471:         break;
 1472: }
 1473: 
 1474: $db->end_transaction();
 1475: $db->close();
 1476: 
 1477: if ($query_str != '')
 1478:     exit('<script type="text/javascript">window.location="db_update.php'.$query_str.'"</script><noscript>JavaScript seems to be disabled. <a href="db_update.php'.$query_str.'">Click here to continue</a>.</noscript>');


/dev/null b/delete.php
   1: <?php
   2: 
   3: /**
   4:  * Copyright (C) 2008-2010 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:  */
   8: 
   9: define('PUN_ROOT', './');
  10: require PUN_ROOT.'include/common.php';
  11: 
  12: 
  13: if ($pun_user['g_read_board'] == '0')
  14:     message($lang_common['No view']);
  15: 
  16: 
  17: $id = isset($_GET['id']) ? intval($_GET['id']) : 0;
  18: if ($id < 1)
  19:     message($lang_common['Bad request']);
  20: 
  21: // Fetch some info about the post, the topic and the forum
  22: $result = $db->query('SELECT f.id AS fid, f.forum_name, f.moderators, f.redirect_url, fp.post_replies, fp.post_topics, t.id AS tid, t.subject, t.first_post_id, t.closed, p.posted, p.poster, p.poster_id, p.message, p.hide_smilies 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='.$id) or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
  23: if (!$db->num_rows($result))
  24:     message($lang_common['Bad request']);
  25: 
  26: $cur_post = $db->fetch_assoc($result);
  27: 
  28: if ($pun_config['o_censoring'] == '1')
  29:     $cur_post['subject'] = censor_words($cur_post['subject']);
  30: 
  31: // Sort out who the moderators are and if we are currently a moderator (or an admin)
  32: $mods_array = ($cur_post['moderators'] != '') ? unserialize($cur_post['moderators']) : array();
  33: $is_admmod = ($pun_user['g_id'] == PUN_ADMIN || ($pun_user['g_moderator'] == '1' && array_key_exists($pun_user['username'], $mods_array))) ? true : false;
  34: 
  35: $is_topic_post = ($id == $cur_post['first_post_id']) ? true : false;
  36: 
  37: // Do we have permission to edit this post?
  38: if (($pun_user['g_delete_posts'] == '0' ||
  39:     ($pun_user['g_delete_topics'] == '0' && $is_topic_post) ||
  40:     $cur_post['poster_id'] != $pun_user['id'] ||
  41:     $cur_post['closed'] == '1') &&
  42:     !$is_admmod)
  43:     message($lang_common['No permission']);
  44: 
  45: // Load the delete.php language file
  46: require PUN_ROOT.'lang/'.$pun_user['language'].'/delete.php';
  47: 
  48: 
  49: if (isset($_POST['delete']))
  50: {
  51:     if ($is_admmod)
  52:         confirm_referrer('delete.php');
  53: 
  54:     require PUN_ROOT.'include/search_idx.php';
  55: 
  56:     if ($is_topic_post)
  57:     {
  58:         // Delete the topic and all of it's posts
  59:         delete_topic($cur_post['tid']);
  60:         update_forum($cur_post['fid']);
  61: 
  62:         redirect('viewforum.php?id='.$cur_post['fid'], $lang_delete['Topic del redirect']);
  63:     }
  64:     else
  65:     {
  66:         // Delete just this one post
  67:         delete_post($id, $cur_post['tid']);
  68:         update_forum($cur_post['fid']);
  69: 
  70:         redirect('viewtopic.php?id='.$cur_post['tid'], $lang_delete['Post del redirect']);
  71:     }
  72: }
  73: 
  74: 
  75: $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_delete['Delete post']);
  76: define ('PUN_ACTIVE_PAGE', 'index');
  77: require PUN_ROOT.'header.php';
  78: 
  79: require PUN_ROOT.'include/parser.php';
  80: $cur_post['message'] = parse_message($cur_post['message'], $cur_post['hide_smilies']);
  81: 
  82: ?>
  83: <div class="linkst">
  84:     <div class="inbox">
  85:         <ul class="crumbs">
  86:             <li><a href="index.php"><?php echo $lang_common['Index'] ?></a></li>
  87:             <li><span>»&#160;</span><a href="viewforum.php?id=<?php echo $cur_post['fid'] ?>"><?php echo pun_htmlspecialchars($cur_post['forum_name']) ?></a></li>
  88:             <li><span>»&#160;</span><a href="viewtopic.php?pid=<?php echo $id ?>#p<?php echo $id ?>"><?php echo pun_htmlspecialchars($cur_post['subject']) ?></a></li>
  89:             <li><span>»&#160;</span><strong><?php echo $lang_delete['Delete post'] ?></strong></li>
  90:         </ul>
  91:     </div>
  92: </div>
  93: 
  94: <div class="blockform">
  95:     <h2><span><?php echo $lang_delete['Delete post'] ?></span></h2>
  96:     <div class="box">
  97:         <form method="post" action="delete.php?id=<?php echo $id ?>">
  98:             <div class="inform">
  99:                 <div class="forminfo">
 100:                     <h3><span><?php printf($is_topic_post ? $lang_delete['Topic by'] : $lang_delete['Reply by'], '<strong>'.pun_htmlspecialchars($cur_post['poster']).'</strong>', format_time($cur_post['posted'])) ?></span></h3>
 101:                     <p><?php echo ($is_topic_post) ? '<strong>'.$lang_delete['Topic warning'].'</strong>' : '<strong>'.$lang_delete['Warning'].'</strong>' ?><br /><?php echo $lang_delete['Delete info'] ?></p>
 102:                 </div>
 103:             </div>
 104:             <p class="buttons"><input type="submit" name="delete" value="<?php echo $lang_delete['Delete'] ?>" /> <a href="javascript:history.go(-1)"><?php echo $lang_common['Go back'] ?></a></p>
 105:         </form>
 106:     </div>
 107: </div>
 108: 
 109: <div id="postreview">
 110:     <div class="blockpost">
 111:         <div class="box<?php echo ($post_count % 2 == 0) ? ' roweven' : ' rowodd' ?>">
 112:             <div class="inbox">
 113:                 <div class="postbody">
 114:                     <div class="postleft">
 115:                         <dl>
 116:                             <dt><strong><?php echo pun_htmlspecialchars($cur_post['poster']) ?></strong></dt>
 117:                             <dd><span><?php echo format_time($cur_post['posted']) ?></span></dd>
 118:                         </dl>
 119:                     </div>
 120:                     <div class="postright">
 121:                         <div class="postmsg">
 122:                             <?php echo $cur_post['message']."\n" ?>
 123:                         </div>
 124:                     </div>
 125:                 </div>
 126:                 <div class="clearer"></div>
 127:             </div>
 128:         </div>
 129:     </div>
 130: </div>
 131: <?php
 132: 
 133: require PUN_ROOT.'footer.php';


/dev/null b/edit.php
   1: <?php
   2: 
   3: /**
   4:  * Copyright (C) 2008-2010 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:  */
   8: 
   9: define('PUN_ROOT', './');
  10: require PUN_ROOT.'include/common.php';
  11: 
  12: 
  13: if ($pun_user['g_read_board'] == '0')
  14:     message($lang_common['No view']);
  15: 
  16: 
  17: $id = isset($_GET['id']) ? intval($_GET['id']) : 0;
  18: if ($id < 1)
  19:     message($lang_common['Bad request']);
  20: 
  21: // Fetch some info about the post, the topic and the forum
  22: $result = $db->query('SELECT f.id AS fid, f.forum_name, f.moderators, f.redirect_url, fp.post_replies, fp.post_topics, t.id AS tid, t.subject, t.posted, t.first_post_id, t.closed, p.poster, p.poster_id, p.message, p.hide_smilies 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='.$id) or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
  23: if (!$db->num_rows($result))
  24:     message($lang_common['Bad request']);
  25: 
  26: $cur_post = $db->fetch_assoc($result);
  27: 
  28: // Sort out who the moderators are and if we are currently a moderator (or an admin)
  29: $mods_array = ($cur_post['moderators'] != '') ? unserialize($cur_post['moderators']) : array();
  30: $is_admmod = ($pun_user['g_id'] == PUN_ADMIN || ($pun_user['g_moderator'] == '1' && array_key_exists($pun_user['username'], $mods_array))) ? true : false;
  31: 
  32: $can_edit_subject = $id == $cur_post['first_post_id'];
  33: 
  34: if ($pun_config['o_censoring'] == '1')
  35: {
  36:     $cur_post['subject'] = censor_words($cur_post['subject']);
  37:     $cur_post['message'] = censor_words($cur_post['message']);
  38: }
  39: 
  40: // Do we have permission to edit this post?
  41: if (($pun_user['g_edit_posts'] == '0' ||
  42:     $cur_post['poster_id'] != $pun_user['id'] ||
  43:     $cur_post['closed'] == '1') &&
  44:     !$is_admmod)
  45:     message($lang_common['No permission']);
  46: 
  47: // Load the post.php/edit.php language file
  48: require PUN_ROOT.'lang/'.$pun_user['language'].'/post.php';
  49: 
  50: // Start with a clean slate
  51: $errors = array();
  52: 
  53: 
  54: if (isset($_POST['form_sent']))
  55: {
  56:     if ($is_admmod)
  57:         confirm_referrer('edit.php');
  58: 
  59:     // If it's a topic it must contain a subject
  60:     if ($can_edit_subject)
  61:     {
  62:         $subject = pun_trim($_POST['req_subject']);
  63: 
  64:         if ($subject == '')
  65:             $errors[] = $lang_post['No subject'];
  66:         else if (pun_strlen($subject) > 70)
  67:             $errors[] = $lang_post['Too long subject'];
  68:         else if ($pun_config['p_subject_all_caps'] == '0' && is_all_uppercase($subject) && !$pun_user['is_admmod'])
  69:             $errors[] = $lang_post['All caps subject'];
  70:     }
  71: 
  72:     // Clean up message from POST
  73:     $message = pun_linebreaks(pun_trim($_POST['req_message']));
  74: 
  75:     if (pun_strlen($message) > PUN_MAX_POSTSIZE)
  76:         $errors[] = $lang_post['Too long message'];
  77:     else if ($pun_config['p_message_all_caps'] == '0' && is_all_uppercase($message) && !$pun_user['is_admmod'])
  78:         $errors[] = $lang_post['All caps message'];
  79: 
  80:     // Validate BBCode syntax
  81:     if ($pun_config['p_message_bbcode'] == '1')
  82:     {
  83:         require PUN_ROOT.'include/parser.php';
  84:         $message = preparse_bbcode($message, $errors);
  85:     }
  86: 
  87:     if ($message == '')
  88:         $errors[] = $lang_post['No message'];
  89: 
  90:     $hide_smilies = isset($_POST['hide_smilies']) ? '1' : '0';
  91: 
  92:     // Did everything go according to plan?
  93:     if (empty($errors) && !isset($_POST['preview']))
  94:     {
  95:         $edited_sql = (!isset($_POST['silent']) || !$is_admmod) ? $edited_sql = ', edited='.time().', edited_by=\''.$db->escape($pun_user['username']).'\'' : '';
  96: 
  97:         require PUN_ROOT.'include/search_idx.php';
  98: 
  99:         if ($can_edit_subject)
 100:         {
 101:             // Update the topic and any redirect topics
 102:             $db->query('UPDATE '.$db->prefix.'topics SET subject=\''.$db->escape($subject).'\' WHERE id='.$cur_post['tid'].' OR moved_to='.$cur_post['tid']) or error('Unable to update topic', __FILE__, __LINE__, $db->error());
 103: 
 104:             // We changed the subject, so we need to take that into account when we update the search words
 105:             update_search_index('edit', $id, $message, $subject);
 106:         }
 107:         else
 108:             update_search_index('edit', $id, $message);
 109: 
 110:         // Update the post
 111:         $db->query('UPDATE '.$db->prefix.'posts SET message=\''.$db->escape($message).'\', hide_smilies='.$hide_smilies.$edited_sql.' WHERE id='.$id) or error('Unable to update post', __FILE__, __LINE__, $db->error());
 112: 
 113:         redirect('viewtopic.php?pid='.$id.'#p'.$id, $lang_post['Edit redirect']);
 114:     }
 115: }
 116: 
 117: 
 118: 
 119: $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_post['Edit post']);
 120: $required_fields = array('req_subject' => $lang_common['Subject'], 'req_message' => $lang_common['Message']);
 121: $focus_element = array('edit', 'req_message');
 122: define('PUN_ACTIVE_PAGE', 'index');
 123: require PUN_ROOT.'header.php';
 124: 
 125: $cur_index = 1;
 126: 
 127: ?>
 128: <div class="linkst">
 129:     <div class="inbox">
 130:         <ul class="crumbs">
 131:             <li><a href="index.php"><?php echo $lang_common['Index'] ?></a></li>
 132:             <li><span>»&#160;</span><a href="viewforum.php?id=<?php echo $cur_post['fid'] ?>"><?php echo pun_htmlspecialchars($cur_post['forum_name']) ?></a></li>
 133:             <li><span>»&#160;</span><a href="viewtopic.php?id=<?php echo $cur_post['tid'] ?>"><?php echo pun_htmlspecialchars($cur_post['subject']) ?></a></li>
 134:             <li><span>»&#160;</span><strong><?php echo $lang_post['Edit post'] ?></strong></li>
 135:         </ul>
 136:     </div>
 137: </div>
 138: 
 139: <?php
 140: 
 141: // If there are errors, we display them
 142: if (!empty($errors))
 143: {
 144: 
 145: ?>
 146: <div id="posterror" class="block">
 147:     <h2><span><?php echo $lang_post['Post errors'] ?></span></h2>
 148:     <div class="box">
 149:         <div class="inbox error-info">
 150:             <p><?php echo $lang_post['Post errors info'] ?></p>
 151:             <ul class="error-list">
 152: <?php
 153: 
 154:     foreach ($errors as $cur_error)
 155:         echo "\t\t\t\t".'<li><strong>'.$cur_error.'</strong></li>'."\n";
 156: ?>
 157:             </ul>
 158:         </div>
 159:     </div>
 160: </div>
 161: 
 162: <?php
 163: 
 164: }
 165: else if (isset($_POST['preview']))
 166: {
 167:     require_once PUN_ROOT.'include/parser.php';
 168:     $preview_message = parse_message($message, $hide_smilies);
 169: 
 170: ?>
 171: <div id="postpreview" class="blockpost">
 172:     <h2><span><?php echo $lang_post['Post preview'] ?></span></h2>
 173:     <div class="box">
 174:         <div class="inbox">
 175:             <div class="postbody">
 176:                 <div class="postright">
 177:                     <div class="postmsg">
 178:                         <?php echo $preview_message."\n" ?>
 179:                     </div>
 180:                 </div>
 181:             </div>
 182:         </div>
 183:     </div>
 184: </div>
 185: 
 186: <?php
 187: 
 188: }
 189: 
 190: ?>
 191: <div class="blockform">
 192:     <h2><span><?php echo $lang_post['Edit post'] ?></span></h2>
 193:     <div class="box">
 194:         <form id="edit" method="post" action="edit.php?id=<?php echo $id ?>&amp;action=edit" onsubmit="return process_form(this)">
 195:             <div class="inform">
 196:                 <fieldset>
 197:                     <legend><?php echo $lang_post['Edit post legend'] ?></legend>
 198:                     <input type="hidden" name="form_sent" value="1" />
 199:                     <div class="infldset txtarea">
 200: <?php if ($can_edit_subject): ?>                        <label class="required"><strong><?php echo $lang_common['Subject'] ?> <span><?php echo $lang_common['Required'] ?></span></strong><br />
 201:                         <input class="longinput" type="text" name="req_subject" size="80" maxlength="70" tabindex="<?php echo $cur_index++ ?>" value="<?php echo pun_htmlspecialchars(isset($_POST['req_subject']) ? $_POST['req_subject'] : $cur_post['subject']) ?>" /><br /></label>
 202: <?php endif; ?>                        <label class="required"><strong><?php echo $lang_common['Message'] ?> <span><?php echo $lang_common['Required'] ?></span></strong><br />
 203:                         <textarea name="req_message" rows="20" cols="95" tabindex="<?php echo $cur_index++ ?>"><?php echo pun_htmlspecialchars(isset($_POST['req_message']) ? $message : $cur_post['message']) ?></textarea><br /></label>
 204:                         <ul class="bblinks">
 205:                             <li><span><a href="help.php#bbcode" onclick="window.open(this.href); return false;"><?php echo $lang_common['BBCode'] ?></a> <?php echo ($pun_config['p_message_bbcode'] == '1') ? $lang_common['on'] : $lang_common['off']; ?></span></li>
 206:                             <li><span><a href="help.php#img" onclick="window.open(this.href); return false;"><?php echo $lang_common['img tag'] ?></a> <?php echo ($pun_config['p_message_img_tag'] == '1') ? $lang_common['on'] : $lang_common['off']; ?></span></li>
 207:                             <li><span><a href="help.php#smilies" onclick="window.open(this.href); return false;"><?php echo $lang_common['Smilies'] ?></a> <?php echo ($pun_config['o_smilies'] == '1') ? $lang_common['on'] : $lang_common['off']; ?></span></li>
 208:                         </ul>
 209:                     </div>
 210:                 </fieldset>
 211: <?php
 212: 
 213: $checkboxes = array();
 214: if ($pun_config['o_smilies'] == '1')
 215: {
 216:     if (isset($_POST['hide_smilies']) || $cur_post['hide_smilies'] == '1')
 217:         $checkboxes[] = '<label><input type="checkbox" name="hide_smilies" value="1" checked="checked" tabindex="'.($cur_index++).'" />'.$lang_post['Hide smilies'].'<br /></label>';
 218:     else
 219:         $checkboxes[] = '<label><input type="checkbox" name="hide_smilies" value="1" tabindex="'.($cur_index++).'" />'.$lang_post['Hide smilies'].'<br /></label>';
 220: }
 221: 
 222: if ($is_admmod)
 223: {
 224:     if ((isset($_POST['form_sent']) && isset($_POST['silent'])) || !isset($_POST['form_sent']))
 225:         $checkboxes[] = '<label><input type="checkbox" name="silent" value="1" tabindex="'.($cur_index++).'" checked="checked" />'.$lang_post['Silent edit'].'<br /></label>';
 226:     else
 227:         $checkboxes[] = '<label><input type="checkbox" name="silent" value="1" tabindex="'.($cur_index++).'" />'.$lang_post['Silent edit'].'<br /></label>';
 228: }
 229: 
 230: if (!empty($checkboxes))
 231: {
 232: 
 233: ?>
 234:             </div>
 235:             <div class="inform">
 236:                 <fieldset>
 237:                     <legend><?php echo $lang_common['Options'] ?></legend>
 238:                     <div class="infldset">
 239:                         <div class="rbox">
 240:                             <?php echo implode("\n\t\t\t\t\t\t\t", $checkboxes)."\n" ?>
 241:                         </div>
 242:                     </div>
 243:                 </fieldset>
 244: <?php
 245: 
 246:     }
 247: 
 248: ?>
 249:             </div>
 250:             <p class="buttons"><input type="submit" name="submit" value="<?php echo $lang_common['Submit'] ?>" tabindex="<?php echo $cur_index++ ?>" accesskey="s" /> <input type="submit" name="preview" value="<?php echo $lang_post['Preview'] ?>" tabindex="<?php echo $cur_index++ ?>" accesskey="p" /> <a href="javascript:history.go(-1)"><?php echo $lang_common['Go back'] ?></a></p>
 251:         </form>
 252:     </div>
 253: </div>
 254: <?php
 255: 
 256: require PUN_ROOT.'footer.php';


/dev/null b/extern.php
   1: <?php
   2: 
   3: /**
   4:  * Copyright (C) 2008-2010 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:  */
   8: 
   9: /*-----------------------------------------------------------------------------
  10: 
  11:   INSTRUCTIONS
  12: 
  13:   This script is used to include information about your board from
  14:   pages outside the forums and to syndicate news about recent
  15:   discussions via RSS/Atom/XML. The script can display a list of
  16:   recent discussions, a list of active users or a collection of
  17:   general board statistics. The script can be called directly via
  18:   an URL, from a PHP include command or through the use of Server
  19:   Side Includes (SSI).
  20: 
  21:   The scripts behaviour is controlled via variables supplied in the
  22:   URL to the script. The different variables are: action (what to
  23:   do), show (how many items to display), fid (the ID or IDs of
  24:   the forum(s) to poll for topics), nfid (the ID or IDs of forums
  25:   that should be excluded), tid (the ID of the topic from which to
  26:   display posts) and type (output as HTML or RSS). The only
  27:   mandatory variable is action. Possible/default values are:
  28: 
  29:     action: feed - show most recent topics/posts (HTML or RSS)
  30:             online - show users online (HTML)
  31:             online_full - as above, but includes a full list (HTML)
  32:             stats - show board statistics (HTML)
  33: 
  34:     type:   rss - output as RSS 2.0
  35:             atom - output as Atom 1.0
  36:             xml - output as XML
  37:             html - output as HTML (<li>'s)
  38: 
  39:     fid:    One or more forum IDs (comma-separated). If ignored,
  40:             topics from all readable forums will be pulled.
  41: 
  42:     nfid:   One or more forum IDs (comma-separated) that are to be
  43:             excluded. E.g. the ID of a a test forum.
  44: 
  45:     tid:    A topic ID from which to show posts. If a tid is supplied,
  46:             fid and nfid are ignored.
  47: 
  48:     show:   Any integer value between 1 and 50. The default is 15.
  49: 
  50:     order:  last_post - show topics ordered by when they were last
  51:                         posted in, giving information about the reply.
  52:             posted - show topics ordered by when they were first
  53:                      posted, giving information about the original post.
  54: 
  55: -----------------------------------------------------------------------------*/
  56: 
  57: define('PUN_QUIET_VISIT', 1);
  58: 
  59: if (!defined('PUN_ROOT'))
  60:     define('PUN_ROOT', './');
  61: require PUN_ROOT.'include/common.php';
  62: 
  63: // The length at which topic subjects will be truncated (for HTML output)
  64: if (!defined('FORUM_EXTERN_MAX_SUBJECT_LENGTH'))
  65:     define('FORUM_EXTERN_MAX_SUBJECT_LENGTH', 30);
  66: 
  67: // If we're a guest and we've sent a username/pass, we can try to authenticate using those details
  68: if ($pun_user['is_guest'] && isset($_SERVER['PHP_AUTH_USER']))
  69:     authenticate_user($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
  70: 
  71: if ($pun_user['g_read_board'] == '0')
  72: {
  73:     http_authenticate_user();
  74:     exit($lang_common['No view']);
  75: }
  76: 
  77: $action = isset($_GET['action']) ? $_GET['action'] : 'feed';
  78: 
  79: 
  80: //
  81: // Sends the proper headers for Basic HTTP Authentication
  82: //
  83: function http_authenticate_user()
  84: {
  85:     global $pun_config, $pun_user;
  86: 
  87:     if (!$pun_user['is_guest'])
  88:         return;
  89: 
  90:     header('WWW-Authenticate: Basic realm="'.$pun_config['o_board_title'].' External Syndication"');
  91:     header('HTTP/1.0 401 Unauthorized');
  92: }
  93: 
  94: 
  95: //
  96: // Output $feed as RSS 2.0
  97: //
  98: function output_rss($feed)
  99: {
 100:     global $lang_common, $pun_config;
 101: 
 102:     // Send XML/no cache headers
 103:     header('Content-Type: application/xml; charset=utf-8');
 104:     header('Expires: '.gmdate('D, d M Y H:i:s').' GMT');
 105:     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
 106:     header('Pragma: public');
 107: 
 108:     echo '<?xml version="1.0" encoding="utf-8"?>'."\n";
 109:     echo '<rss version="2.0">'."\n";
 110:     echo "\t".'<channel>'."\n";
 111:     echo "\t\t".'<title><![CDATA['.escape_cdata($feed['title']).']]></title>'."\n";
 112:     echo "\t\t".'<link>'.$feed['link'].'</link>'."\n";
 113:     echo "\t\t".'<description><![CDATA['.escape_cdata($feed['description']).']]></description>'."\n";
 114:     echo "\t\t".'<lastBuildDate>'.gmdate('r', count($feed['items']) ? $feed['items'][0]['pubdate'] : time()).'</lastBuildDate>'."\n";
 115: 
 116:     if ($pun_config['o_show_version'] == '1')
 117:         echo "\t\t".'<generator>FluxBB '.$pun_config['o_cur_version'].'</generator>'."\n";
 118:     else
 119:         echo "\t\t".'<generator>FluxBB</generator>'."\n";
 120: 
 121:     foreach ($feed['items'] as $item)
 122:     {
 123:         echo "\t\t".'<item>'."\n";
 124:         echo "\t\t\t".'<title><![CDATA['.escape_cdata($item['title']).']]></title>'."\n";
 125:         echo "\t\t\t".'<link>'.$item['link'].'</link>'."\n";
 126:         echo "\t\t\t".'<description><![CDATA['.escape_cdata($item['description']).']]></description>'."\n";
 127:         echo "\t\t\t".'<author><![CDATA['.(isset($item['author']['email']) ? escape_cdata($item['author']['email']) : 'dummy@example.com').' ('.escape_cdata($item['author']['name']).')]]></author>'."\n";
 128:         echo "\t\t\t".'<pubDate>'.gmdate('r', $item['pubdate']).'</pubDate>'."\n";
 129:         echo "\t\t\t".'<guid>'.$item['link'].'</guid>'."\n";
 130: 
 131:         echo "\t\t".'</item>'."\n";
 132:     }
 133: 
 134:     echo "\t".'</channel>'."\n";
 135:     echo '</rss>'."\n";
 136: }
 137: 
 138: 
 139: //
 140: // Output $feed as Atom 1.0
 141: //
 142: function output_atom($feed)
 143: {
 144:     global $lang_common, $pun_config;
 145: 
 146:     // Send XML/no cache headers
 147:     header('Content-Type: application/atom+xml; charset=utf-8');
 148:     header('Expires: '.gmdate('D, d M Y H:i:s').' GMT');
 149:     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
 150:     header('Pragma: public');
 151: 
 152:     echo '<?xml version="1.0" encoding="utf-8"?>'."\n";
 153:     echo '<feed xmlns="http://www.w3.org/2005/Atom">'."\n";
 154: 
 155:     echo "\t".'<title type="html"><![CDATA['.escape_cdata($feed['title']).']]></title>'."\n";
 156:     echo "\t".'<link rel="self" href="'.pun_htmlspecialchars(get_current_url()).'"/>'."\n";
 157:     echo "\t".'<link href="'.$feed['link'].'"/>'."\n";
 158:     echo "\t".'<updated>'.gmdate('Y-m-d\TH:i:s\Z', count($feed['items']) ? $feed['items'][0]['pubdate'] : time()).'</updated>'."\n";
 159: 
 160:     if ($pun_config['o_show_version'] == '1')
 161:         echo "\t".'<generator version="'.$pun_config['o_cur_version'].'">FluxBB</generator>'."\n";
 162:     else
 163:         echo "\t".'<generator>FluxBB</generator>'."\n";
 164: 
 165:     echo "\t".'<id>'.$feed['link'].'</id>'."\n";
 166: 
 167:     $content_tag = ($feed['type'] == 'posts') ? 'content' : 'summary';
 168: 
 169:     foreach ($feed['items'] as $item)
 170:     {
 171:         echo "\t".'<entry>'."\n";
 172:         echo "\t\t".'<title type="html"><![CDATA['.escape_cdata($item['title']).']]></title>'."\n";
 173:         echo "\t\t".'<link rel="alternate" href="'.$item['link'].'"/>'."\n";
 174:         echo "\t\t".'<'.$content_tag.' type="html"><![CDATA['.escape_cdata($item['description']).']]></'.$content_tag.'>'."\n";
 175:         echo "\t\t".'<author>'."\n";
 176:         echo "\t\t\t".'<name><![CDATA['.escape_cdata($item['author']['name']).']]></name>'."\n";
 177: 
 178:         if (isset($item['author']['email']))
 179:             echo "\t\t\t".'<email><![CDATA['.escape_cdata($item['author']['email']).']]></email>'."\n";
 180: 
 181:         if (isset($item['author']['uri']))
 182:             echo "\t\t\t".'<uri>'.$item['author']['uri'].'</uri>'."\n";
 183: 
 184:         echo "\t\t".'</author>'."\n";
 185:         echo "\t\t".'<updated>'.gmdate('Y-m-d\TH:i:s\Z', $item['pubdate']).'</updated>'."\n";
 186: 
 187:         echo "\t\t".'<id>'.$item['link'].'</id>'."\n";
 188:         echo "\t".'</entry>'."\n";
 189:     }
 190: 
 191:     echo '</feed>'."\n";
 192: }
 193: 
 194: 
 195: //
 196: // Output $feed as XML
 197: //
 198: function output_xml($feed)
 199: {
 200:     global $lang_common, $pun_config;
 201: 
 202:     // Send XML/no cache headers
 203:     header('Content-Type: application/xml; charset=utf-8');
 204:     header('Expires: '.gmdate('D, d M Y H:i:s').' GMT');
 205:     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
 206:     header('Pragma: public');
 207: 
 208:     echo '<?xml version="1.0" encoding="utf-8"?>'."\n";
 209:     echo '<source>'."\n";
 210:     echo "\t".'<url>'.$feed['link'].'</url>'."\n";
 211: 
 212:     $forum_tag = ($feed['type'] == 'posts') ? 'post' : 'topic';
 213: 
 214:     foreach ($feed['items'] as $item)
 215:     {
 216:         echo "\t".'<'.$forum_tag.' id="'.$item['id'].'">'."\n";
 217: 
 218:         echo "\t\t".'<title><![CDATA['.escape_cdata($item['title']).']]></title>'."\n";
 219:         echo "\t\t".'<link>'.$item['link'].'</link>'."\n";
 220:         echo "\t\t".'<content><![CDATA['.escape_cdata($item['description']).']]></content>'."\n";
 221:         echo "\t\t".'<author>'."\n";
 222:         echo "\t\t\t".'<name><![CDATA['.escape_cdata($item['author']['name']).']]></name>'."\n";
 223: 
 224:         if (isset($item['author']['email']))
 225:             echo "\t\t\t".'<email><![CDATA['.escape_cdata($item['author']['email']).']]></email>'."\n";
 226: 
 227:         if (isset($item['author']['uri']))
 228:             echo "\t\t\t".'<uri>'.$item['author']['uri'].'</uri>'."\n";
 229: 
 230:         echo "\t\t".'</author>'."\n";
 231:         echo "\t\t".'<posted>'.gmdate('r', $item['pubdate']).'</posted>'."\n";
 232: 
 233:         echo "\t".'</'.$forum_tag.'>'."\n";
 234:     }
 235: 
 236:     echo '</source>'."\n";
 237: }
 238: 
 239: 
 240: //
 241: // Output $feed as HTML (using <li> tags)
 242: //
 243: function output_html($feed)
 244: {
 245: 
 246:     // Send the Content-type header in case the web server is setup to send something else
 247:     header('Content-type: text/html; charset=utf-8');
 248:     header('Expires: '.gmdate('D, d M Y H:i:s').' GMT');
 249:     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
 250:     header('Pragma: public');
 251: 
 252:     foreach ($feed['items'] as $item)
 253:     {
 254:         if (utf8_strlen($item['title']) > FORUM_EXTERN_MAX_SUBJECT_LENGTH)
 255:             $subject_truncated = pun_htmlspecialchars(pun_trim(utf8_substr($item['title'], 0, (FORUM_EXTERN_MAX_SUBJECT_LENGTH - 5)))).' â€¦';
 256:         else
 257:             $subject_truncated = pun_htmlspecialchars($item['title']);
 258: 
 259:         echo '<li><a href="'.$item['link'].'" title="'.pun_htmlspecialchars($item['title']).'">'.$subject_truncated.'</a></li>'."\n";
 260:     }
 261: }
 262: 
 263: // Show recent discussions
 264: if ($action == 'feed')
 265: {
 266:     require PUN_ROOT.'include/parser.php';
 267: 
 268:     // Determine what type of feed to output
 269:     $type = isset($_GET['type']) && in_array($_GET['type'], array('html', 'rss', 'atom', 'xml')) ? $_GET['type'] : 'html';
 270: 
 271:     $show = isset($_GET['show']) ? intval($_GET['show']) : 15;
 272:     if ($show < 1 || $show > 50)
 273:         $show = 15;
 274: 
 275:     // Was a topic ID supplied?
 276:     if (isset($_GET['tid']))
 277:     {
 278:         $tid = intval($_GET['tid']);
 279: 
 280:         // Fetch topic subject
 281:         $result = $db->query('SELECT t.subject, t.first_post_id 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.moved_to IS NULL AND t.id='.$tid) or error('Unable to fetch topic info', __FILE__, __LINE__, $db->error());
 282:         if (!$db->num_rows($result))
 283:         {
 284:             http_authenticate_user();
 285:             exit($lang_common['Bad request']);
 286:         }
 287: 
 288:         $cur_topic = $db->fetch_assoc($result);
 289: 
 290:         if ($pun_config['o_censoring'] == '1')
 291:             $cur_topic['subject'] = censor_words($cur_topic['subject']);
 292: 
 293:         // Setup the feed
 294:         $feed = array(
 295:             'title'         =>    $pun_config['o_board_title'].$lang_common['Title separator'].$cur_topic['subject'],
 296:             'link'            =>    $pun_config['o_base_url'].'/viewtopic.php?id='.$tid,
 297:             'description'        =>    sprintf($lang_common['RSS description topic'], $cur_topic['subject']),
 298:             'items'            =>    array(),
 299:             'type'            =>    'posts'
 300:         );
 301: 
 302:         // Fetch $show posts
 303:         $result = $db->query('SELECT p.id, p.poster, p.message, p.hide_smilies, p.posted, p.poster_id, u.email_setting, u.email, p.poster_email FROM '.$db->prefix.'posts AS p INNER JOIN '.$db->prefix.'users AS u ON u.id=p.poster_id WHERE p.topic_id='.$tid.' ORDER BY p.posted DESC LIMIT '.$show) or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
 304:         while ($cur_post = $db->fetch_assoc($result))
 305:         {
 306:             $cur_post['message'] = parse_message($cur_post['message'], $cur_post['hide_smilies']);
 307: 
 308:             $item = array(
 309:                 'id'            =>    $cur_post['id'],
 310:                 'title'            =>    $cur_topic['first_post_id'] == $cur_post['id'] ? $cur_topic['subject'] : $lang_common['RSS reply'].$cur_topic['subject'],
 311:                 'link'            =>    $pun_config['o_base_url'].'/viewtopic.php?pid='.$cur_post['id'].'#p'.$cur_post['id'],
 312:                 'description'        =>    $cur_post['message'],
 313:                 'author'        =>    array(
 314:                     'name'    => $cur_post['poster'],
 315:                 ),
 316:                 'pubdate'        =>    $cur_post['posted']
 317:             );
 318: 
 319:             if ($cur_post['poster_id'] > 1)
 320:             {
 321:                 if ($cur_post['email_setting'] == '0' && !$pun_user['is_guest'])
 322:                     $item['author']['email'] = $cur_post['email'];
 323: 
 324:                 $item['author']['uri'] = $pun_config['o_base_url'].'/profile.php?id='.$cur_post['poster_id'];
 325:             }
 326:             else if ($cur_post['poster_email'] != '' && !$pun_user['is_guest'])
 327:                 $item['author']['email'] = $cur_post['poster_email'];
 328: 
 329:             $feed['items'][] = $item;
 330:         }
 331: 
 332:         $output_func = 'output_'.$type;
 333:         $output_func($feed);
 334:     }
 335:     else
 336:     {
 337:         $order_posted = isset($_GET['order']) && $_GET['order'] == 'posted';
 338:         $forum_name = '';
 339:         $forum_sql = '';
 340: 
 341:         // Were any forum IDs supplied?
 342:         if (isset($_GET['fid']) && is_scalar($_GET['fid']) && $_GET['fid'] != '')
 343:         {
 344:             $fids = explode(',', pun_trim($_GET['fid']));
 345:             $fids = array_map('intval', $fids);
 346: 
 347:             if (!empty($fids))
 348:                 $forum_sql .= ' AND t.forum_id IN('.implode(',', $fids).')';
 349: 
 350:             if (count($fids) == 1)
 351:             {
 352:                 // Fetch forum name
 353:                 $result = $db->query('SELECT f.forum_name 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='.$fids[0]) or error('Unable to fetch forum name', __FILE__, __LINE__, $db->error());
 354:                 if ($db->num_rows($result))
 355:                     $forum_name = $lang_common['Title separator'].$db->result($result);
 356:             }
 357:         }
 358: 
 359:         // Any forum IDs to exclude?
 360:         if (isset($_GET['nfid']) && is_scalar($_GET['nfid']) && $_GET['nfid'] != '')
 361:         {
 362:             $nfids = explode(',', pun_trim($_GET['nfid']));
 363:             $nfids = array_map('intval', $nfids);
 364: 
 365:             if (!empty($nfids))
 366:                 $forum_sql .= ' AND t.forum_id NOT IN('.implode(',', $nfids).')';
 367:         }
 368: 
 369:         // Setup the feed
 370:         $feed = array(
 371:             'title'         =>    $pun_config['o_board_title'].$forum_name,
 372:             'link'            =>    $pun_config['o_base_url'].'/index.php',
 373:             'description'    =>    sprintf($lang_common['RSS description'], $pun_config['o_board_title']),
 374:             'items'            =>    array(),
 375:             'type'            =>    'topics'
 376:         );
 377: 
 378:         // Fetch $show topics
 379:         $result = $db->query('SELECT t.id, t.poster, t.subject, t.posted, t.last_post, t.last_poster, p.message, p.hide_smilies, u.email_setting, u.email, p.poster_id, p.poster_email FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'posts AS p ON p.id='.($order_posted ? 't.first_post_id' : 't.last_post_id').' INNER JOIN '.$db->prefix.'users AS u ON u.id=p.poster_id 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.moved_to IS NULL'.$forum_sql.' ORDER BY '.($order_posted ? 't.posted' : 't.last_post').' DESC LIMIT '.$show) or error('Unable to fetch topic info', __FILE__, __LINE__, $db->error());
 380:         while ($cur_topic = $db->fetch_assoc($result))
 381:         {
 382:             if ($pun_config['o_censoring'] == '1')
 383:                 $cur_topic['subject'] = censor_words($cur_topic['subject']);
 384: 
 385:             $cur_topic['message'] = parse_message($cur_topic['message'], $cur_topic['hide_smilies']);
 386: 
 387:             $item = array(
 388:                 'id'            =>    $cur_topic['id'],
 389:                 'title'            =>    $cur_topic['subject'],
 390:                 'link'            =>    $pun_config['o_base_url'].($order_posted ? '/viewtopic.php?id='.$cur_topic['id'] : '/viewtopic.php?id='.$cur_topic['id'].'&amp;action=new'),
 391:                 'description'    =>    $cur_topic['message'],
 392:                 'author'        =>    array(
 393:                     'name'    => $order_posted ? $cur_topic['poster'] : $cur_topic['last_poster']
 394:                 ),
 395:                 'pubdate'        =>    $order_posted ? $cur_topic['posted'] : $cur_topic['last_post']
 396:             );
 397: 
 398:             if ($cur_topic['poster_id'] > 1)
 399:             {
 400:                 if ($cur_topic['email_setting'] == '0' && !$pun_user['is_guest'])
 401:                     $item['author']['email'] = $cur_topic['email'];
 402: 
 403:                 $item['author']['uri'] = $pun_config['o_base_url'].'/profile.php?id='.$cur_topic['poster_id'];
 404:             }
 405:             else if ($cur_topic['poster_email'] != '' && !$pun_user['is_guest'])
 406:                 $item['author']['email'] = $cur_topic['poster_email'];
 407: 
 408:             $feed['items'][] = $item;
 409:         }
 410: 
 411:         $output_func = 'output_'.$type;
 412:         $output_func($feed);
 413:     }
 414: 
 415:     exit;
 416: }
 417: 
 418: // Show users online
 419: else if ($action == 'online' || $action == 'online_full')
 420: {
 421:     // Load the index.php language file
 422:     require PUN_ROOT.'lang/'.$pun_config['o_default_lang'].'/index.php';
 423: 
 424:     // Fetch users online info and generate strings for output
 425:     $num_guests = $num_users = 0;
 426:     $users = array();
 427: 
 428:     $result = $db->query('SELECT user_id, ident FROM '.$db->prefix.'online WHERE idle=0 ORDER BY ident', true) or error('Unable to fetch online list', __FILE__, __LINE__, $db->error());
 429: 
 430:     while ($pun_user_online = $db->fetch_assoc($result))
 431:     {
 432:         if ($pun_user_online['user_id'] > 1)
 433:         {
 434:             $users[] = ($pun_user['g_view_users'] == '1') ? '<a href="'.$pun_config['o_base_url'].'/profile.php?id='.$pun_user_online['user_id'].'">'.pun_htmlspecialchars($pun_user_online['ident']).'</a>' : pun_htmlspecialchars($pun_user_online['ident']);
 435:             ++$num_users;
 436:         }
 437:         else
 438:             ++$num_guests;
 439:     }
 440: 
 441:     // Send the Content-type header in case the web server is setup to send something else
 442:     header('Content-type: text/html; charset=utf-8');
 443:     header('Expires: '.gmdate('D, d M Y H:i:s').' GMT');
 444:     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
 445:     header('Pragma: public');
 446: 
 447:     echo sprintf($lang_index['Guests online'], forum_number_format($num_guests)).'<br />'."\n";
 448: 
 449:     if ($action == 'online_full' && !empty($users))
 450:         echo sprintf($lang_index['Users online'], implode(', ', $users)).'<br />'."\n";
 451:     else
 452:         echo sprintf($lang_index['Users online'], forum_number_format($num_users)).'<br />'."\n";
 453: 
 454:     exit;
 455: }
 456: 
 457: // Show board statistics
 458: else if ($action == 'stats')
 459: {
 460:     // Load the index.php language file
 461:     require PUN_ROOT.'lang/'.$pun_config['o_default_lang'].'/index.php';
 462: 
 463:     // Collect some statistics from the database
 464:     $result = $db->query('SELECT COUNT(id)-1 FROM '.$db->prefix.'users WHERE group_id!='.PUN_UNVERIFIED) or error('Unable to fetch total user count', __FILE__, __LINE__, $db->error());
 465:     $stats['total_users'] = $db->result($result);
 466: 
 467:     $result = $db->query('SELECT id, username FROM '.$db->prefix.'users WHERE group_id!='.PUN_UNVERIFIED.' ORDER BY registered DESC LIMIT 1') or error('Unable to fetch newest registered user', __FILE__, __LINE__, $db->error());
 468:     $stats['last_user'] = $db->fetch_assoc($result);
 469: 
 470:     $result = $db->query('SELECT SUM(num_topics), SUM(num_posts) FROM '.$db->prefix.'forums') or error('Unable to fetch topic/post count', __FILE__, __LINE__, $db->error());
 471:     list($stats['total_topics'], $stats['total_posts']) = $db->fetch_row($result);
 472: 
 473:     // Send the Content-type header in case the web server is setup to send something else
 474:     header('Content-type: text/html; charset=utf-8');
 475:     header('Expires: '.gmdate('D, d M Y H:i:s').' GMT');
 476:     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
 477:     header('Pragma: public');
 478: 
 479:     echo sprintf($lang_index['No of users'], forum_number_format($stats['total_users'])).'<br />'."\n";
 480:     echo sprintf($lang_index['Newest user'], (($pun_user['g_view_users'] == '1') ? '<a href="'.$pun_config['o_base_url'].'/profile.php?id='.$stats['last_user']['id'].'">'.pun_htmlspecialchars($stats['last_user']['username']).'</a>' : pun_htmlspecialchars($stats['last_user']['username']))).'<br />'."\n";
 481:     echo sprintf($lang_index['No of topics'], forum_number_format($stats['total_topics'])).'<br />'."\n";
 482:     echo sprintf($lang_index['No of posts'], forum_number_format($stats['total_posts'])).'<br />'."\n";
 483: 
 484:     exit;
 485: }
 486: 
 487: // If we end up here, the script was called with some wacky parameters
 488: exit($lang_common['Bad request']);


/dev/null b/footer.php
   1: <?php
   2: 
   3: /**
   4:  * Copyright (C) 2008-2010 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:  */
   8: 
   9: // Make sure no one attempts to run this script "directly"
  10: if (!defined('PUN'))
  11:     exit;
  12: 
  13: $tpl_temp = trim(ob_get_contents());
  14: $tpl_main = str_replace('<pun_main>', $tpl_temp, $tpl_main);
  15: ob_end_clean();
  16: // END SUBST - <pun_main>
  17: 
  18: 
  19: // START SUBST - <pun_footer>
  20: ob_start();
  21: 
  22: ?>
  23: <div id="brdfooter" class="block">
  24:     <h2><span><?php echo $lang_common['Board footer'] ?></span></h2>
  25:     <div class="box">
  26: <?php
  27: 
  28: if (isset($footer_style) && ($footer_style == 'viewforum' || $footer_style == 'viewtopic') && $is_admmod)
  29: {
  30:     echo "\t\t".'<div id="modcontrols" class="inbox">'."\n";
  31: 
  32:     if ($footer_style == 'viewforum')
  33:     {
  34:         echo "\t\t\t".'<dl>'."\n";
  35:         echo "\t\t\t\t".'<dt><strong>'.$lang_forum['Mod controls'].'</strong></dt>'."\n";
  36:         echo "\t\t\t\t".'<dd><span><a href="moderate.php?fid='.$forum_id.'&amp;p='.$p.'">'.$lang_common['Moderate forum'].'</a></span></dd>'."\n";
  37:         echo "\t\t\t".'</dl>'."\n";
  38:     }
  39:     else if ($footer_style == 'viewtopic')
  40:     {
  41:         echo "\t\t\t".'<dl>'."\n";
  42:         echo "\t\t\t\t".'<dt><strong>'.$lang_topic['Mod controls'].'</strong></dt>'."\n";
  43:         echo "\t\t\t\t".'<dd><span><a href="moderate.php?fid='.$forum_id.'&amp;tid='.$id.'&amp;p='.$p.'">'.$lang_common['Moderate topic'].'</a></span></dd>'."\n";
  44:         echo "\t\t\t\t".'<dd><span><a href="moderate.php?fid='.$forum_id.'&amp;move_topics='.$id.'">'.$lang_common['Move topic'].'</a></span></dd>'."\n";
  45: 
  46:         if ($cur_topic['closed'] == '1')
  47:             echo "\t\t\t\t".'<dd><span><a href="moderate.php?fid='.$forum_id.'&amp;open='.$id.'">'.$lang_common['Open topic'].'</a></span></dd>'."\n";
  48:         else
  49:             echo "\t\t\t\t".'<dd><span><a href="moderate.php?fid='.$forum_id.'&amp;close='.$id.'">'.$lang_common['Close topic'].'</a></span></dd>'."\n";
  50: 
  51:         if ($cur_topic['sticky'] == '1')
  52:             echo "\t\t\t\t".'<dd><span><a href="moderate.php?fid='.$forum_id.'&amp;unstick='.$id.'">'.$lang_common['Unstick topic'].'</a></span></dd>'."\n";
  53:         else
  54:             echo "\t\t\t\t".'<dd><span><a href="moderate.php?fid='.$forum_id.'&amp;stick='.$id.'">'.$lang_common['Stick topic'].'</a></span></dd>'."\n";
  55: 
  56:         echo "\t\t\t".'</dl>'."\n";
  57:     }
  58: 
  59:     echo "\t\t\t".'<div class="clearer"></div>'."\n\t\t".'</div>'."\n";
  60: }
  61: 
  62: ?>
  63:         <div id="brdfooternav" class="inbox">
  64: <?php
  65: 
  66: // If no footer style has been specified, we use the default (only copyright/debug info)
  67: $footer_style = isset($footer_style) ? $footer_style : NULL;
  68: 
  69: if ($footer_style == 'index' || $footer_style == 'search')
  70: {
  71:     echo "\t\t\t".'<div class="conl">'."\n";
  72: 
  73:     if (!$pun_user['is_guest'] && $pun_user['g_search'] == '1')
  74:     {
  75:         echo "\t\t\t\t".'<dl id="searchlinks">'."\n";
  76:         echo "\t\t\t\t\t".'<dt><strong>'.$lang_common['Search links'].'</strong></dt>'."\n";
  77: 
  78:         echo "\t\t\t\t\t".'<dd><span><a href="search.php?action=show_24h">'.$lang_common['Show recent posts'].'</a></span></dd>'."\n";
  79:         echo "\t\t\t\t\t".'<dd><span><a href="search.php?action=show_unanswered">'.$lang_common['Show unanswered posts'].'</a></span></dd>'."\n";
  80: 
  81:         if ($pun_config['o_subscriptions'] == '1')
  82:             echo "\t\t\t\t\t".'<dd><span><a href="search.php?action=show_subscriptions">'.$lang_common['Show subscriptions'].'</a></span></dd>'."\n";
  83: 
  84:         echo "\t\t\t\t\t".'<dd><span><a href="search.php?action=show_user&amp;user_id='.$pun_user['id'].'">'.$lang_common['Show your posts'].'</a></span></dd>'."\n";
  85: 
  86:         echo "\t\t\t\t".'</dl>'."\n";
  87:     }
  88:     else
  89:     {
  90:         if ($pun_user['g_search'] == '1')
  91:         {
  92:             echo "\t\t\t\t".'<dl id="searchlinks">'."\n";
  93:             echo "\t\t\t\t\t".'<dt><strong>'.$lang_common['Search links'].'</strong></dt>'."\n";
  94: 
  95:             echo "\t\t\t\t\t".'<dd><span><a href="search.php?action=show_24h">'.$lang_common['Show recent posts'].'</a></span></dd>'."\n";
  96:             echo "\t\t\t\t\t".'<dd><span><a href="search.php?action=show_unanswered">'.$lang_common['Show unanswered posts'].'</a></span></dd>'."\n";
  97: 
  98:             echo "\t\t\t\t".'</dl>'."\n";
  99:         }
 100:     }
 101: 
 102:     echo "\t\t\t".'</div>'."\n";
 103: }
 104: else if ($footer_style == 'viewforum' || $footer_style == 'viewtopic')
 105: {
 106:     echo "\t\t\t".'<div class="conl">'."\n";
 107: 
 108:     // Display the "Jump to" drop list
 109:     if ($pun_config['o_quickjump'] == '1')
 110:     {
 111:         // Load cached quick jump
 112:         if (file_exists(FORUM_CACHE_DIR.'cache_quickjump_'.$pun_user['g_id'].'.php'))
 113:             include FORUM_CACHE_DIR.'cache_quickjump_'.$pun_user['g_id'].'.php';
 114: 
 115:         if (!defined('PUN_QJ_LOADED'))
 116:         {
 117:             if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
 118:                 require PUN_ROOT.'include/cache.php';
 119: 
 120:             generate_quickjump_cache($pun_user['g_id']);
 121:             require FORUM_CACHE_DIR.'cache_quickjump_'.$pun_user['g_id'].'.php';
 122:         }
 123:     }
 124: 
 125:     echo "\t\t\t".'</div>'."\n";
 126: }
 127: 
 128: ?>
 129:             <div class="conr">
 130: <?php
 131: 
 132: if ($footer_style == 'index')
 133: {
 134:     if ($pun_config['o_feed_type'] == '1')
 135:         echo "\t\t\t\t".'<p id="feedlinks"><span class="rss"><a href="extern.php?action=feed&amp;type=rss">'.$lang_common['RSS active topics feed'].'</a></span></p>'."\n";
 136:     else if ($pun_config['o_feed_type'] == '2')
 137:         echo "\t\t\t\t".'<p id="feedlinks"><span class="atom"><a href="extern.php?action=feed&amp;type=atom">'.$lang_common['Atom active topics feed'].'</a></span></p>'."\n";
 138: }
 139: else if ($footer_style == 'viewforum')
 140: {
 141:     if ($pun_config['o_feed_type'] == '1')
 142:         echo "\t\t\t\t".'<p id="feedlinks"><span class="rss"><a href="extern.php?action=feed&amp;fid='.$forum_id.'&amp;type=rss">'.$lang_common['RSS forum feed'].'</a></span></p>'."\n";
 143:     else if ($pun_config['o_feed_type'] == '2')
 144:         echo "\t\t\t\t".'<p id="feedlinks" class="actions"><span class="atom"><a href="extern.php?action=feed&amp;fid='.$forum_id.'&amp;type=atom">'.$lang_common['Atom forum feed'].'</a></span></p>'."\n";
 145: }
 146: else if ($footer_style == 'viewtopic')
 147: {
 148:     if ($pun_config['o_feed_type'] == '1')
 149:         echo "\t\t\t\t".'<p id="feedlinks"><span class="rss"><a href="extern.php?action=feed&amp;tid='.$id.'&amp;type=rss">'.$lang_common['RSS topic feed'].'</a></span></p>'."\n";
 150:     else if ($pun_config['o_feed_type'] == '2')
 151:         echo "\t\t\t\t".'<p id="feedlinks"><span class="atom"><a href="extern.php?action=feed&amp;tid='.$id.'&amp;type=atom">'.$lang_common['Atom topic feed'].'</a></span></p>'."\n";
 152: }
 153: 
 154: ?>
 155:                 <p id="poweredby"><?php printf($lang_common['Powered by'], '<a href="http://fluxbb.org/">FluxBB</a>'.(($pun_config['o_show_version'] == '1') ? ' '.$pun_config['o_cur_version'] : '')) ?></p>
 156:             </div>
 157:             <div class="clearer"></div>
 158:         </div>
 159:     </div>
 160: </div>
 161: <?php
 162: 
 163: // Display debug info (if enabled/defined)
 164: if (defined('PUN_DEBUG'))
 165: {
 166:     echo '<p id="debugtime">[ ';
 167: 
 168:     // Calculate script generation time
 169:     $time_diff = sprintf('%.3f', get_microtime() - $pun_start);
 170:     echo sprintf($lang_common['Querytime'], $time_diff, $db->get_num_queries());
 171: 
 172:     if (function_exists('memory_get_usage'))
 173:     {
 174:         echo ' - '.sprintf($lang_common['Memory usage'], file_size(memory_get_usage()));
 175: 
 176:         if (function_exists('memory_get_peak_usage'))
 177:             echo ' '.sprintf($lang_common['Peak usage'], file_size(memory_get_peak_usage()));
 178:     }
 179: 
 180:     echo ' ]</p>'."\n";
 181: }
 182: 
 183: 
 184: // End the transaction
 185: $db->end_transaction();
 186: 
 187: // Display executed queries (if enabled)
 188: if (defined('PUN_SHOW_QUERIES'))
 189:     display_saved_queries();
 190: 
 191: $tpl_temp = trim(ob_get_contents());
 192: $tpl_main = str_replace('<pun_footer>', $tpl_temp, $tpl_main);
 193: ob_end_clean();
 194: // END SUBST - <pun_footer>
 195: 
 196: 
 197: // Close the db connection (and free up any result data)
 198: $db->close();
 199: 
 200: // Spit out the page
 201: exit($tpl_main);


/dev/null b/header.php
   1: <?php
   2: 
   3: /**
   4:  * Copyright (C) 2008-2010 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:  */
   8: 
   9: // Make sure no one attempts to run this script "directly"
  10: if (!defined('PUN'))
  11:     exit;
  12: 
  13: // Send no-cache headers
  14: header('Expires: Thu, 21 Jul 1977 07:30:00 GMT'); // When yours truly first set eyes on this world! :)
  15: header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  16: header('Cache-Control: post-check=0, pre-check=0', false);
  17: header('Pragma: no-cache'); // For HTTP/1.0 compatibility
  18: 
  19: // Send the Content-type header in case the web server is setup to send something else
  20: header('Content-type: text/html; charset=utf-8');
  21: 
  22: // Load the template
  23: if (defined('PUN_ADMIN_CONSOLE'))
  24:     $tpl_file = 'admin.tpl';
  25: else if (defined('PUN_HELP'))
  26:     $tpl_file = 'help.tpl';
  27: else
  28:     $tpl_file = 'main.tpl';
  29: 
  30: if (file_exists(PUN_ROOT.'style/'.$pun_user['style'].'/'.$tpl_file))
  31: {
  32:     $tpl_file = PUN_ROOT.'style/'.$pun_user['style'].'/'.$tpl_file;
  33:     $tpl_inc_dir = PUN_ROOT.'style/'.$pun_user['style'].'/';
  34: }
  35: else
  36: {
  37:     $tpl_file = PUN_ROOT.'include/template/'.$tpl_file;
  38:     $tpl_inc_dir = PUN_ROOT.'include/user/';
  39: }
  40: 
  41: $tpl_main = file_get_contents($tpl_file);
  42: 
  43: // START SUBST - <pun_include "*">
  44: preg_match_all('#<pun_include "([^/\\\\]*?)\.(php[45]?|inc|html?|txt)">#', $tpl_main, $pun_includes, PREG_SET_ORDER);
  45: 
  46: foreach ($pun_includes as $cur_include)
  47: {
  48:     ob_start();
  49: 
  50:     // Allow for overriding user includes, too.
  51:     if (file_exists($tpl_inc_dir.$cur_include[1].'.'.$cur_include[2]))
  52:         require $tpl_inc_dir.$cur_include[1].'.'.$cur_include[2];
  53:     else if (file_exists(PUN_ROOT.'include/user/'.$cur_include[1].'.'.$cur_include[2]))
  54:         require PUN_ROOT.'include/user/'.$cur_include[1].'.'.$cur_include[2];
  55:     else
  56:         error(sprintf($lang_common['Pun include error'], htmlspecialchars($cur_include[0]), basename($tpl_file)));
  57: 
  58:     $tpl_temp = ob_get_contents();
  59:     $tpl_main = str_replace($cur_include[0], $tpl_temp, $tpl_main);
  60:     ob_end_clean();
  61: }
  62: // END SUBST - <pun_include "*">
  63: 
  64: 
  65: // START SUBST - <pun_language>
  66: $tpl_main = str_replace('<pun_language>', $lang_common['lang_identifier'], $tpl_main);
  67: // END SUBST - <pun_language>
  68: 
  69: 
  70: // START SUBST - <pun_content_direction>
  71: $tpl_main = str_replace('<pun_content_direction>', $lang_common['lang_direction'], $tpl_main);
  72: // END SUBST - <pun_content_direction>
  73: 
  74: 
  75: // START SUBST - <pun_head>
  76: ob_start();
  77: 
  78: // Define $p if its not set to avoid a PHP notice
  79: $p = isset($p) ? $p : null;
  80: 
  81: // Is this a page that we want search index spiders to index?
  82: if (!defined('PUN_ALLOW_INDEX'))
  83:     echo '<meta name="ROBOTS" content="NOINDEX, FOLLOW" />'."\n";
  84: 
  85: ?>
  86: <title><?php echo generate_page_title($page_title, $p) ?></title>
  87: <link rel="stylesheet" type="text/css" href="style/<?php echo $pun_user['style'].'.css' ?>" />
  88: <?php
  89: 
  90: if (defined('PUN_ADMIN_CONSOLE'))
  91: {
  92:     if (file_exists(PUN_ROOT.'style/'.$pun_user['style'].'/base_admin.css'))
  93:         echo '<link rel="stylesheet" type="text/css" href="style/'.$pun_user['style'].'/base_admin.css" />'."\n";
  94:     else
  95:         echo '<link rel="stylesheet" type="text/css" href="style/imports/base_admin.css" />'."\n";
  96: }
  97: 
  98: if (isset($required_fields))
  99: {
 100:     // Output JavaScript to validate form (make sure required fields are filled out)
 101: 
 102: ?>
 103: <script type="text/javascript">
 104: /* <![CDATA[ */
 105: function process_form(the_form)
 106: {
 107:     var element_names = new Object()
 108: <?php
 109: 
 110:     // Output a JavaScript array with localised field names
 111:     foreach ($required_fields as $elem_orig => $elem_trans)
 112:         echo "\t".'element_names["'.$elem_orig.'"] = "'.addslashes(str_replace('&#160;', ' ', $elem_trans)).'"'."\n";
 113: 
 114: ?>
 115: 
 116:     if (document.all || document.getElementById)
 117:     {
 118:         for (var i = 0; i < the_form.length; ++i)
 119:         {
 120:             var elem = the_form.elements[i]
 121:             if (elem.name && elem.name.substring(0, 4) == "req_")
 122:             {
 123:                 if (elem.type && (elem.type=="text" || elem.type=="textarea" || elem.type=="password" || elem.type=="file") && elem.value=='')
 124:                 {
 125:                     alert("\"" + element_names[elem.name] + "\" <?php echo $lang_common['required field'] ?>")
 126:                     elem.focus()
 127:                     return false
 128:                 }
 129:             }
 130:         }
 131:     }
 132: 
 133:     return true
 134: }
 135: /* ]]> */
 136: </script>
 137: <?php
 138: 
 139: }
 140: 
 141: // JavaScript tricks for IE6 and older
 142: echo '<!--[if lte IE 6]><script type="text/javascript" src="style/imports/minmax.js"></script><![endif]-->'."\n";
 143: 
 144: if (isset($page_head))
 145:     echo implode("\n", $page_head)."\n";
 146: 
 147: $tpl_temp = trim(ob_get_contents());
 148: $tpl_main = str_replace('<pun_head>', $tpl_temp, $tpl_main);
 149: ob_end_clean();
 150: // END SUBST - <pun_head>
 151: 
 152: 
 153: // START SUBST - <body>
 154: if (isset($focus_element))
 155: {
 156:     $tpl_main = str_replace('<body onload="', '<body onload="document.getElementById(\''.$focus_element[0].'\').'.$focus_element[1].'.focus();', $tpl_main);
 157:     $tpl_main = str_replace('<body>', '<body onload="document.getElementById(\''.$focus_element[0].'\').'.$focus_element[1].'.focus()">', $tpl_main);
 158: }
 159: // END SUBST - <body>
 160: 
 161: 
 162: // START SUBST - <pun_page>
 163: $tpl_main = str_replace('<pun_page>', htmlspecialchars(basename($_SERVER['PHP_SELF'], '.php')), $tpl_main);
 164: // END SUBST - <pun_page>
 165: 
 166: 
 167: // START SUBST - <pun_title>
 168: $tpl_main = str_replace('<pun_title>', '<h1><span>'.pun_htmlspecialchars($pun_config['o_board_title']).'</span></h1>', $tpl_main);
 169: // END SUBST - <pun_title>
 170: 
 171: 
 172: // START SUBST - <pun_desc>
 173: $tpl_main = str_replace('<pun_desc>', '<div id="brddesc">'.$pun_config['o_board_desc'].'</div>', $tpl_main);
 174: // END SUBST - <pun_desc>
 175: 
 176: 
 177: // START SUBST - <pun_navlinks>
 178: $tpl_main = str_replace('<pun_navlinks>','<div id="brdmenu" class="inbox">'."\n\t\t\t". generate_navlinks()."\n\t\t".'</div>', $tpl_main);
 179: // END SUBST - <pun_navlinks>
 180: 
 181: 
 182: // START SUBST - <pun_status>
 183: if ($pun_user['is_guest'])
 184:     $tpl_temp = '<div id="brdwelcome" class="inbox">'."\n\t\t\t".'<p>'.$lang_common['Not logged in'].'</p>'."\n\t\t".'</div>';
 185: else
 186: {
 187:     $tpl_temp = '<div id="brdwelcome" class="inbox">'."\n\t\t\t".'<ul class="conl">'."\n\t\t\t\t".'<li><span>'.$lang_common['Logged in as'].' <strong>'.pun_htmlspecialchars($pun_user['username']).'</strong></span></li>'."\n\t\t\t\t".'<li><span>'.sprintf($lang_common['Last visit'], format_time($pun_user['last_visit'])).'</span></li>';
 188: 
 189:     if ($pun_user['is_admmod'])
 190:     {
 191:         if ($pun_config['o_report_method'] == '0' || $pun_config['o_report_method'] == '2')
 192:         {
 193:             $result_header = $db->query('SELECT 1 FROM '.$db->prefix.'reports WHERE zapped IS NULL') or error('Unable to fetch reports info', __FILE__, __LINE__, $db->error());
 194: 
 195:             if ($db->result($result_header))
 196:                 $tpl_temp .= "\n\t\t\t\t".'<li class="reportlink"><span><strong><a href="admin_reports.php">'.$lang_common['New reports'].'</a></strong></span></li>';
 197:         }
 198: 
 199:         if ($pun_config['o_maintenance'] == '1')
 200:             $tpl_temp .= "\n\t\t\t\t".'<li class="maintenancelink"><span><strong><a href="admin_options.php#maintenance">'.$lang_common['Maintenance mode enabled'].'</a></strong></span></li>';
 201:     }
 202: 
 203:     if (in_array(basename($_SERVER['PHP_SELF']), array('index.php', 'search.php')))
 204:         $tpl_temp .= "\n\t\t\t".'</ul>'."\n\t\t\t".'<ul class="conr">'.($pun_user['g_search'] == '1' ? "\n\t\t\t\t".'<li><span><a href="search.php?action=show_new">'.$lang_common['Show new posts'].'</a></span></li>' : '')."\n\t\t\t\t".'<li><span><a href="misc.php?action=markread">'.$lang_common['Mark all as read'].'</a></span></li>'."\n\t\t\t".'</ul>'."\n\t\t\t".'<div class="clearer"></div>'."\n\t\t".'</div>';
 205:     else if (basename($_SERVER['PHP_SELF']) == 'viewforum.php')
 206:         $tpl_temp .= "\n\t\t\t".'</ul>'."\n\t\t\t".'<ul class="conr">'."\n\t\t\t\t".'<li><span><a href="misc.php?action=markforumread&amp;fid='.$id.'">'.$lang_common['Mark forum read'].'</a></span></li>'."\n\t\t\t".'</ul>'."\n\t\t\t".'<div class="clearer"></div>'."\n\t\t".'</div>';
 207:     else
 208:         $tpl_temp .= "\n\t\t\t".'</ul>'."\n\t\t\t".'<div class="clearer"></div>'."\n\t\t".'</div>';
 209: }
 210: 
 211: $tpl_main = str_replace('<pun_status>', $tpl_temp, $tpl_main);
 212: // END SUBST - <pun_status>
 213: 
 214: 
 215: // START SUBST - <pun_announcement>
 216: if ($pun_config['o_announcement'] == '1')
 217: {
 218:     ob_start();
 219: 
 220: ?>
 221: <div id="announce" class="block">
 222:     <div class="hd"><h2><span><?php echo $lang_common['Announcement'] ?></span></h2></div>
 223:     <div class="box">
 224:         <div id="announce-block" class="inbox">
 225:             <div class="usercontent"><?php echo $pun_config['o_announcement_message'] ?></div>
 226:         </div>
 227:     </div>
 228: </div>
 229: <?php
 230: 
 231:     $tpl_temp = trim(ob_get_contents());
 232:     $tpl_main = str_replace('<pun_announcement>', $tpl_temp, $tpl_main);
 233:     ob_end_clean();
 234: }
 235: else
 236:     $tpl_main = str_replace('<pun_announcement>', '', $tpl_main);
 237: // END SUBST - <pun_announcement>
 238: 
 239: 
 240: // START SUBST - <pun_main>
 241: ob_start();
 242: 
 243: 
 244: define('PUN_HEADER', 1);


/dev/null b/help.php
   1: <?php
   2: 
   3: /**
   4:  * Copyright (C) 2008-2010 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:  */
   8: 
   9: // Tell header.php to use the help template
  10: define('PUN_HELP', 1);
  11: 
  12: define('PUN_ROOT', './');
  13: require PUN_ROOT.'include/common.php';
  14: 
  15: 
  16: if ($pun_user['g_read_board'] == '0')
  17:     message($lang_common['No view']);
  18: 
  19: 
  20: // Load the help.php language file
  21: require PUN_ROOT.'lang/'.$pun_user['language'].'/help.php';
  22: 
  23: 
  24: $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_help['Help']);
  25: define('PUN_ACTIVE_PAGE', 'help');
  26: require PUN_ROOT.'header.php';
  27: 
  28: ?>
  29: <h2><span><?php echo $lang_help['BBCode'] ?></span></h2>
  30: <div class="box">
  31:     <div class="inbox">
  32:         <p><a name="bbcode"></a><?php echo $lang_help['BBCode info 1'] ?></p>
  33:         <p><?php echo $lang_help['BBCode info 2'] ?></p>
  34:     </div>
  35: </div>
  36: <h2><span><?php echo $lang_help['Text style'] ?></span></h2>
  37: <div class="box">
  38:     <div class="inbox">
  39:         <p><?php echo $lang_help['Text style info'] ?></p>
  40:         <p><code>[b]<?php echo $lang_help['Bold text'] ?>[/b]</code> <?php echo $lang_help['produces'] ?> <samp><strong><?php echo $lang_help['Bold text'] ?></strong></samp></p>
  41:         <p><code>[u]<?php echo $lang_help['Underlined text'] ?>[/u]</code> <?php echo $lang_help['produces'] ?> <samp><span class="bbu"><?php echo $lang_help['Underlined text'] ?></span></samp></p>
  42:         <p><code>[i]<?php echo $lang_help['Italic text'] ?>[/i]</code> <?php echo $lang_help['produces'] ?> <samp><i><?php echo $lang_help['Italic text'] ?></i></samp></p>
  43:         <p><code>[s]<?php echo $lang_help['Strike-through text'] ?>[/s]</code> <?php echo $lang_help['produces'] ?> <samp><span class="bbs"><?php echo $lang_help['Strike-through text'] ?></span></samp></p>
  44:         <p><code>[del]<?php echo $lang_help['Deleted text'] ?>[/del]</code> <?php echo $lang_help['produces'] ?> <samp><del><?php echo $lang_help['Deleted text'] ?></del></samp></p>
  45:         <p><code>[ins]<?php echo $lang_help['Inserted text'] ?>[/ins]</code> <?php echo $lang_help['produces'] ?> <samp><ins><?php echo $lang_help['Inserted text'] ?></ins></samp></p>
  46:         <p><code>[em]<?php echo $lang_help['Emphasised text'] ?>[/em]</code> <?php echo $lang_help['produces'] ?> <samp><em><?php echo $lang_help['Emphasised text'] ?></em></samp></p>
  47:         <p><code>[color=#FF0000]<?php echo $lang_help['Red text'] ?>[/color]</code> <?php echo $lang_help['produces'] ?> <samp><span style="color: #ff0000"><?php echo $lang_help['Red text'] ?></span></samp></p>
  48:         <p><code>[color=blue]<?php echo $lang_help['Blue text'] ?>[/color]</code> <?php echo $lang_help['produces'] ?> <samp><span style="color: blue"><?php echo $lang_help['Blue text'] ?></span></samp></p>
  49:         <p><code>[h]<?php echo $lang_help['Heading text'] ?>[/h]</code> <?php echo $lang_help['produces'] ?></p> <div class="postmsg"><h5><?php echo $lang_help['Heading text'] ?></h5></div>
  50:     </div>
  51: </div>
  52: <h2><span><?php echo $lang_help['Links and images'] ?></span></h2>
  53: <div class="box">
  54:     <div class="inbox">
  55:         <p><?php echo $lang_help['Links info'] ?></p>
  56:         <p><code>[url=<?php echo $pun_config['o_base_url'].'/' ?>]<?php echo pun_htmlspecialchars($pun_config['o_board_title']) ?>[/url]</code> <?php echo $lang_help['produces'] ?> <samp><a href="<?php echo $pun_config['o_base_url'].'/' ?>"><?php echo pun_htmlspecialchars($pun_config['o_board_title']) ?></a></samp></p>
  57:         <p><code>[url]<?php echo $pun_config['o_base_url'].'/' ?>[/url]</code> <?php echo $lang_help['produces'] ?> <samp><a href="<?php echo $pun_config['o_base_url'] ?>"><?php echo $pun_config['o_base_url'].'/' ?></a></samp></p>
  58:         <p><code>[email]myname@mydomain.com[/email]</code> <?php echo $lang_help['produces'] ?> <samp><a href="mailto:myname@mydomain.com">myname@mydomain.com</a></samp></p>
  59:         <p><code>[email=myname@mydomain.com]<?php echo $lang_help['My email address'] ?>[/email]</code> <?php echo $lang_help['produces'] ?> <samp><a href="mailto:myname@mydomain.com"><?php echo $lang_help['My email address'] ?></a></samp></p>
  60:     </div>
  61:     <div class="inbox">
  62:         <p><a name="img"></a><?php echo $lang_help['Images info'] ?></p>
  63:         <p><code>[img=FluxBB bbcode test]<?php echo $pun_config['o_base_url'].'/' ?>img/test.png[/img]</code> <?php echo $lang_help['produces'] ?> <samp><img src="<?php echo $pun_config['o_base_url'].'/' ?>img/test.png" alt="FluxBB bbcode test" /></samp></p>
  64:     </div>
  65: </div>
  66: <h2><span><?php echo $lang_help['Quotes'] ?></span></h2>
  67: <div class="box">
  68:     <div class="inbox">
  69:         <p><?php echo $lang_help['Quotes info'] ?></p>
  70:         <p><code>[quote=James]<?php echo $lang_help['Quote text'] ?>[/quote]</code></p>
  71:         <p><?php echo $lang_help['produces quote box'] ?></p>
  72:         <div class="postmsg">
  73:             <div class="quotebox"><cite>James <?php echo $lang_common['wrote'] ?></cite><blockquote><div><p><?php echo $lang_help['Quote text'] ?></p></div></blockquote></div>
  74:         </div>
  75:         <p><?php echo $lang_help['Quotes info 2'] ?></p>
  76:         <p><code>[quote]<?php echo $lang_help['Quote text'] ?>[/quote]</code></p>
  77:         <p><?php echo $lang_help['produces quote box'] ?></p>
  78:         <div class="postmsg">
  79:             <div class="quotebox"><blockquote><div><p><?php echo $lang_help['Quote text'] ?></p></div></blockquote></div>
  80:         </div>
  81:         <p><?php echo $lang_help['quote note'] ?></p>
  82:     </div>
  83: </div>
  84: <h2><span><?php echo $lang_help['Code'] ?></span></h2>
  85: <div class="box">
  86:     <div class="inbox">
  87:         <p><?php echo $lang_help['Code info'] ?></p>
  88:         <p><code>[code]<?php echo $lang_help['Code text'] ?>[/code]</code></p>
  89:         <p><?php echo $lang_help['produces code box'] ?></p>
  90:         <div class="postmsg">
  91:             <div class="codebox"><pre><code><?php echo $lang_help['Code text'] ?></code></pre></div>
  92:         </div>
  93:     </div>
  94: </div>
  95: <h2><span><?php echo $lang_help['Lists'] ?></span></h2>
  96: <div class="box">
  97:     <div class="inbox">
  98:         <p><a name="lists"></a><?php echo $lang_help['List info'] ?></p>
  99:         <p><code>[list][*]<?php echo $lang_help['List text 1'] ?>[/*][*]<?php echo $lang_help['List text 2'] ?>[/*][*]<?php echo $lang_help['List text 3'] ?>[/*][/list]</code>
 100:         <br /><span><?php echo $lang_help['produces list'] ?></span></p>
 101:         <div class="postmsg">
 102:             <ul><li><?php echo $lang_help['List text 1'] ?></li><li><?php echo $lang_help['List text 2'] ?></li><li><?php echo $lang_help['List text 3'] ?></li></ul>
 103:         </div>
 104:         <p><code>[list=1][*]<?php echo $lang_help['List text 1'] ?>[/*][*]<?php echo $lang_help['List text 2'] ?>[/*][*]<?php echo $lang_help['List text 3'] ?>[/*][/list]</code>
 105:         <br /><span><?php echo $lang_help['produces decimal list'] ?></span></p>
 106:         <div class="postmsg">
 107:             <ol class="decimal"><li><?php echo $lang_help['List text 1'] ?></li><li><?php echo $lang_help['List text 2'] ?></li><li><?php echo $lang_help['List text 3'] ?></li></ol>
 108:         </div>
 109:         <p><code>[list=a][*]<?php echo $lang_help['List text 1'] ?>[/*][*]<?php echo $lang_help['List text 2'] ?>[/*][*]<?php echo $lang_help['List text 3'] ?>[/*][/list]</code>
 110:         <br /><span><?php echo $lang_help['produces alpha list'] ?></span></p>
 111:         <div class="postmsg">
 112:             <ol class="alpha"><li><?php echo $lang_help['List text 1'] ?></li><li><?php echo $lang_help['List text 2'] ?></li><li><?php echo $lang_help['List text 3'] ?></li></ol>
 113:         </div>
 114:     </div>
 115: </div>
 116: <h2><span><?php echo $lang_help['Nested tags'] ?></span></h2>
 117: <div class="box">
 118:     <div class="inbox">
 119:         <p><?php echo $lang_help['Nested tags info'] ?></p>
 120:         <p><code>[b][u]<?php echo $lang_help['Bold, underlined text'] ?>[/u][/b]</code> <?php echo $lang_help['produces'] ?> <samp><strong><span class="bbu"><?php echo $lang_help['Bold, underlined text'] ?></span></strong></samp></p>
 121:     </div>
 122: </div>
 123: <h2><span><?php echo $lang_help['Smilies'] ?></span></h2>
 124: <div class="box">
 125:     <div class="inbox">
 126:         <p><a name="smilies"></a><?php echo $lang_help['Smilies info'] ?></p>
 127: <?php
 128: 
 129: // Display the smiley set
 130: require PUN_ROOT.'include/parser.php';
 131: 
 132: $smiley_groups = array();
 133: 
 134: foreach ($smilies as $smiley_text => $smiley_img)
 135:     $smiley_groups[$smiley_img][] = $smiley_text;
 136: 
 137: foreach ($smiley_groups as $smiley_img => $smiley_texts)
 138:     echo "\t\t".'<p><code>'.implode('</code> '.$lang_common['and'].' <code>', $smiley_texts).'</code> <span>'.$lang_help['produces'].'</span> <samp><img src="'.$pun_config['o_base_url'].'/img/smilies/'.$smiley_img.'" width="15" height="15" alt="'.$smiley_texts[0].'" /></samp></p>'."\n";
 139: ?>
 140:     </div>
 141: </div>
 142: <?php
 143: 
 144: require PUN_ROOT.'footer.php';


/dev/null b/img/avatars/index.html
   1: <html><head><title>.</title></head><body>.</body></html>


/dev/null b/img/index.html
   1: <html><head><title>.</title></head><body>.</body></html>


- No viewable Change -

- No viewable Change -

- No viewable Change -

/dev/null b/img/smilies/index.html
   1: <html><head><title>.</title></head><body>.</body></html>


- No viewable Change -

- No viewable Change -

- No viewable Change -

- No viewable Change -

- No viewable Change -

- No viewable Change -

- No viewable Change -

- No viewable Change -

- No viewable Change -

- No viewable Change -

/dev/null b/include/cache.php
   1: <?php
   2: 
   3: /**
   4:  * Copyright (C) 2008-2010 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:  */
   8: 
   9: // Make sure no one attempts to run this script "directly"
  10: if (!defined('PUN'))
  11:     exit;
  12: 
  13: 
  14: //
  15: // Generate the config cache PHP script
  16: //
  17: function generate_config_cache()
  18: {
  19:     global $db;
  20: 
  21:     // Get the forum config from the DB
  22:     $result = $db->query('SELECT * FROM '.$db->prefix.'config', true) or error('Unable to fetch forum config', __FILE__, __LINE__, $db->error());
  23:     while ($cur_config_item = $db->fetch_row($result))
  24:         $output[$cur_config_item[0]] = $cur_config_item[1];
  25: 
  26:     // Output config as PHP code
  27:     $fh = @fopen(FORUM_CACHE_DIR.'cache_config.php', 'wb');
  28:     if (!$fh)
  29:         error('Unable to write configuration cache file to cache directory. Please make sure PHP has write access to the directory \'cache\'', __FILE__, __LINE__);
  30: 
  31:     fwrite($fh, '<?php'."\n\n".'define(\'PUN_CONFIG_LOADED\', 1);'."\n\n".'$pun_config = '.var_export($output, true).';'."\n\n".'?>');
  32: 
  33:     fclose($fh);
  34: }
  35: 
  36: 
  37: //
  38: // Generate the bans cache PHP script
  39: //
  40: function generate_bans_cache()
  41: {
  42:     global $db;
  43: 
  44:     // Get the ban list from the DB
  45:     $result = $db->query('SELECT * FROM '.$db->prefix.'bans', true) or error('Unable to fetch ban list', __FILE__, __LINE__, $db->error());
  46: 
  47:     $output = array();
  48:     while ($cur_ban = $db->fetch_assoc($result))
  49:         $output[] = $cur_ban;
  50: 
  51:     // Output ban list as PHP code
  52:     $fh = @fopen(FORUM_CACHE_DIR.'cache_bans.php', 'wb');
  53:     if (!$fh)
  54:         error('Unable to write bans cache file to cache directory. Please make sure PHP has write access to the directory \'cache\'', __FILE__, __LINE__);
  55: 
  56:     fwrite($fh, '<?php'."\n\n".'define(\'PUN_BANS_LOADED\', 1);'."\n\n".'$pun_bans = '.var_export($output, true).';'."\n\n".'?>');
  57: 
  58:     fclose($fh);
  59: }
  60: 
  61: 
  62: //
  63: // Generate the ranks cache PHP script
  64: //
  65: function generate_ranks_cache()
  66: {
  67:     global $db;
  68: 
  69:     // Get the rank list from the DB
  70:     $result = $db->query('SELECT * FROM '.$db->prefix.'ranks ORDER BY min_posts', true) or error('Unable to fetch rank list', __FILE__, __LINE__, $db->error());
  71: 
  72:     $output = array();
  73:     while ($cur_rank = $db->fetch_assoc($result))
  74:         $output[] = $cur_rank;
  75: 
  76:     // Output ranks list as PHP code
  77:     $fh = @fopen(FORUM_CACHE_DIR.'cache_ranks.php', 'wb');
  78:     if (!$fh)
  79:         error('Unable to write ranks cache file to cache directory. Please make sure PHP has write access to the directory \'cache\'', __FILE__, __LINE__);
  80: 
  81:     fwrite($fh, '<?php'."\n\n".'define(\'PUN_RANKS_LOADED\', 1);'."\n\n".'$pun_ranks = '.var_export($output, true).';'."\n\n".'?>');
  82: 
  83:     fclose($fh);
  84: }
  85: 
  86: 
  87: //
  88: // Generate quick jump cache PHP scripts
  89: //
  90: function generate_quickjump_cache($group_id = false)
  91: {
  92:     global $db, $lang_common, $pun_user;
  93: 
  94:     // If a group_id was supplied, we generate the quick jump cache for that group only
  95:     if ($group_id !== false)
  96:         $groups[0] = $group_id;
  97:     else
  98:     {
  99:         // A group_id was now supplied, so we generate the quick jump cache for all groups
 100:         $result = $db->query('SELECT g_id FROM '.$db->prefix.'groups') or error('Unable to fetch user group list', __FILE__, __LINE__, $db->error());
 101:         $num_groups = $db->num_rows($result);
 102: 
 103:         for ($i = 0; $i < $num_groups; ++$i)
 104:             $groups[] = $db->result($result, $i);
 105:     }
 106: 
 107:     // Loop through the groups in $groups and output the cache for each of them
 108:     foreach ($groups as $group_id)
 109:     {
 110:         // Output quick jump as PHP code
 111:         $fh = @fopen(FORUM_CACHE_DIR.'cache_quickjump_'.$group_id.'.php', 'wb');
 112:         if (!$fh)
 113:             error('Unable to write quick jump cache file to cache directory. Please make sure PHP has write access to the directory \'cache\'', __FILE__, __LINE__);
 114: 
 115:         $output = '<?php'."\n\n".'if (!defined(\'PUN\')) exit;'."\n".'define(\'PUN_QJ_LOADED\', 1);'."\n\n".'?>';
 116:         $output .= "\t\t\t\t".'<form id="qjump" method="get" action="viewforum.php">'."\n\t\t\t\t\t".'<div><label><span><?php echo $lang_common[\'Jump to\'] ?>'.'<br /></span>'."\n\t\t\t\t\t".'<select name="id" onchange="window.location=(\'viewforum.php?id=\'+this.options[this.selectedIndex].value)">'."\n";
 117: 
 118: 
 119:         $result = $db->query('SELECT c.id AS cid, c.cat_name, f.id AS fid, f.forum_name, f.redirect_url FROM '.$db->prefix.'categories AS c INNER JOIN '.$db->prefix.'forums AS f ON c.id=f.cat_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$group_id.') WHERE fp.read_forum IS NULL OR fp.read_forum=1 ORDER BY c.disp_position, c.id, f.disp_position', true) or error('Unable to fetch category/forum list', __FILE__, __LINE__, $db->error());
 120: 
 121:         $cur_category = 0;
 122:         while ($cur_forum = $db->fetch_assoc($result))
 123:         {
 124:             if ($cur_forum['cid'] != $cur_category) // A new category since last iteration?
 125:             {
 126:                 if ($cur_category)
 127:                     $output .= "\t\t\t\t\t\t".'</optgroup>'."\n";
 128: 
 129:                 $output .= "\t\t\t\t\t\t".'<optgroup label="'.pun_htmlspecialchars($cur_forum['cat_name']).'">'."\n";
 130:                 $cur_category = $cur_forum['cid'];
 131:             }
 132: 
 133:             $redirect_tag = ($cur_forum['redirect_url'] != '') ? ' &gt;&gt;&gt;' : '';
 134:             $output .= "\t\t\t\t\t\t\t".'<option value="'.$cur_forum['fid'].'"<?php echo ($forum_id == '.$cur_forum['fid'].') ? \' selected="selected"\' : \'\' ?>>'.pun_htmlspecialchars($cur_forum['forum_name']).$redirect_tag.'</option>'."\n";
 135:         }
 136: 
 137:         $output .= "\t\t\t\t\t\t".'</optgroup>'."\n\t\t\t\t\t".'</select>'."\n\t\t\t\t\t".'<input type="submit" value="<?php echo $lang_common[\'Go\'] ?>" accesskey="g" />'."\n\t\t\t\t\t".'</label></div>'."\n\t\t\t\t".'</form>'."\n";
 138: 
 139:         fwrite($fh, $output);
 140: 
 141:         fclose($fh);
 142:     }
 143: }
 144: 
 145: define('FORUM_CACHE_FUNCTIONS_LOADED', true);


/dev/null b/include/common.php
   1: <?php
   2: 
   3: /**
   4:  * Copyright (C) 2008-2010 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:  */
   8: 
   9: if (!defined('PUN_ROOT'))
  10:     exit('The constant PUN_ROOT must be defined and point to a valid FluxBB installation root directory.');
  11: 
  12: // Define the version and database revision that this code was written for
  13: define('FORUM_VERSION', '1.4.1');
  14: 
  15: define('FORUM_DB_REVISION', 7);
  16: define('FORUM_SI_REVISION', 1);
  17: define('FORUM_PARSER_REVISION', 1);
  18: 
  19: // Block prefetch requests
  20: if (isset($_SERVER['HTTP_X_MOZ']) && $_SERVER['HTTP_X_MOZ'] == 'prefetch')
  21: {
  22:     header('HTTP/1.1 403 Prefetching Forbidden');
  23: 
  24:     // Send no-cache headers
  25:     header('Expires: Thu, 21 Jul 1977 07:30:00 GMT'); // When yours truly first set eyes on this world! :)
  26:     header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
  27:     header('Cache-Control: post-check=0, pre-check=0', false);
  28:     header('Pragma: no-cache'); // For HTTP/1.0 compatibility
  29: 
  30:     exit;
  31: }
  32: 
  33: // Attempt to load the configuration file config.php
  34: if (file_exists(PUN_ROOT.'config.php'))
  35:     require PUN_ROOT.'config.php';
  36: 
  37: // If we have the 1.3-legacy constant defined, define the proper 1.4 constant so we don't get an incorrect "need to install" message
  38: if (defined('FORUM'))
  39:     define('PUN', FORUM);
  40: 
  41: // If PUN isn't defined, config.php is missing or corrupt
  42: if (!defined('PUN'))
  43:     exit('The file \'config.php\' doesn\'t exist or is corrupt. Please run <a href="install.php">install.php</a> to install FluxBB first.');
  44: 
  45: // Load the functions script
  46: require PUN_ROOT.'include/functions.php';
  47: 
  48: // Load UTF-8 functions
  49: require PUN_ROOT.'include/utf8/utf8.php';
  50: 
  51: // Strip out "bad" UTF-8 characters
  52: forum_remove_bad_characters();
  53: 
  54: // Reverse the effect of register_globals
  55: forum_unregister_globals();
  56: 
  57: // Record the start time (will be used to calculate the generation time for the page)
  58: $pun_start = get_microtime();
  59: 
  60: // Make sure PHP reports all errors except E_NOTICE. FluxBB supports E_ALL, but a lot of scripts it may interact with, do not
  61: error_reporting(E_ALL ^ E_NOTICE);
  62: 
  63: // Force POSIX locale (to prevent functions such as strtolower() from messing up UTF-8 strings)
  64: setlocale(LC_CTYPE, 'C');
  65: 
  66: // Turn off magic_quotes_runtime
  67: if (get_magic_quotes_runtime())
  68:     set_magic_quotes_runtime(0);
  69: 
  70: // Strip slashes from GET/POST/COOKIE (if magic_quotes_gpc is enabled)
  71: if (get_magic_quotes_gpc())
  72: {
  73:     function stripslashes_array($array)
  74:     {
  75:         return is_array($array) ? array_map('stripslashes_array', $array) : stripslashes($array);
  76:     }
  77: 
  78:     $_GET = stripslashes_array($_GET);
  79:     $_POST = stripslashes_array($_POST);
  80:     $_COOKIE = stripslashes_array($_COOKIE);
  81:     $_REQUEST = stripslashes_array($_REQUEST);
  82: }
  83: 
  84: // If a cookie name is not specified in config.php, we use the default (pun_cookie)
  85: if (empty($cookie_name))
  86:     $cookie_name = 'pun_cookie';
  87: 
  88: // If the cache directory is not specified, we use the default setting
  89: if (!defined('FORUM_CACHE_DIR'))
  90:     define('FORUM_CACHE_DIR', PUN_ROOT.'cache/');
  91: 
  92: // Define a few commonly used constants
  93: define('PUN_UNVERIFIED', 0);
  94: define('PUN_ADMIN', 1);
  95: define('PUN_MOD', 2);
  96: define('PUN_GUEST', 3);
  97: define('PUN_MEMBER', 4);
  98: 
  99: // Load DB abstraction layer and connect
 100: require PUN_ROOT.'include/dblayer/common_db.php';
 101: 
 102: // Start a transaction
 103: $db->start_transaction();
 104: 
 105: // Load cached config
 106: if (file_exists(FORUM_CACHE_DIR.'cache_config.php'))
 107:     include FORUM_CACHE_DIR.'cache_config.php';
 108: 
 109: if (!defined('PUN_CONFIG_LOADED'))
 110: {
 111:     if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
 112:         require PUN_ROOT.'include/cache.php';
 113: 
 114:     generate_config_cache();
 115:     require FORUM_CACHE_DIR.'cache_config.php';
 116: }
 117: 
 118: // Verify that we are running the proper database schema revision
 119: if (!isset($pun_config['o_database_revision']) || $pun_config['o_database_revision'] < FORUM_DB_REVISION ||
 120:         !isset($pun_config['o_searchindex_revision']) || $pun_config['o_searchindex_revision'] < FORUM_SI_REVISION ||
 121:         !isset($pun_config['o_parser_revision']) || $pun_config['o_parser_revision'] < FORUM_PARSER_REVISION ||
 122:         version_compare($pun_config['o_cur_version'], FORUM_VERSION, '<'))
 123:     exit('Your FluxBB database is out-of-date and must be upgraded in order to continue. Please run <a href="'.PUN_ROOT.'db_update.php">db_update.php</a> in order to complete the upgrade process.');
 124: 
 125: // Enable output buffering
 126: if (!defined('PUN_DISABLE_BUFFERING'))
 127: {
 128:     // Should we use gzip output compression?
 129:     if ($pun_config['o_gzip'] && extension_loaded('zlib'))
 130:         ob_start('ob_gzhandler');
 131:     else
 132:         ob_start();
 133: }
 134: 
 135: // Define standard date/time formats
 136: $forum_time_formats = array($pun_config['o_time_format'], 'H:i:s', 'H:i', 'g:i:s a', 'g:i a');
 137: $forum_date_formats = array($pun_config['o_date_format'], 'Y-m-d', 'Y-d-m', 'd-m-Y', 'm-d-Y', 'M j Y', 'jS M Y');
 138: 
 139: // Check/update/set cookie and fetch user info
 140: $pun_user = array();
 141: check_cookie($pun_user);
 142: 
 143: // Attempt to load the common language file
 144: if (file_exists(PUN_ROOT.'lang/'.$pun_user['language'].'/common.php'))
 145:     include PUN_ROOT.'lang/'.$pun_user['language'].'/common.php';
 146: else
 147:     error('There is no valid language pack \''.pun_htmlspecialchars($pun_user['language']).'\' installed. Please reinstall a language of that name');
 148: 
 149: // Check if we are to display a maintenance message
 150: if ($pun_config['o_maintenance'] && $pun_user['g_id'] > PUN_ADMIN && !defined('PUN_TURN_OFF_MAINT'))
 151:     maintenance_message();
 152: 
 153: // Load cached bans
 154: if (file_exists(FORUM_CACHE_DIR.'cache_bans.php'))
 155:     include FORUM_CACHE_DIR.'cache_bans.php';
 156: 
 157: if (!defined('PUN_BANS_LOADED'))
 158: {
 159:     if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
 160:         require PUN_ROOT.'include/cache.php';
 161: 
 162:     generate_bans_cache();
 163:     require FORUM_CACHE_DIR.'cache_bans.php';
 164: }
 165: 
 166: // Check if current user is banned
 167: check_bans();
 168: 
 169: // Update online list
 170: update_users_online();
 171: 
 172: // Check to see if we logged in without a cookie being set
 173: if ($pun_user['is_guest'] && isset($_GET['login']))
 174:     message($lang_common['No cookie']);
 175: 
 176: if (!defined('PUN_MAX_POSTSIZE'))
 177:     define('PUN_MAX_POSTSIZE', 65535);
 178: 
 179: if (!defined('PUN_SEARCH_MIN_WORD'))
 180:     define('PUN_SEARCH_MIN_WORD', 3);
 181: if (!defined('PUN_SEARCH_MAX_WORD'))
 182:     define('PUN_SEARCH_MAX_WORD', 20);


/dev/null b/include/common_admin.php
   1: <?php
   2: 
   3: /**
   4:  * Copyright (C) 2008-2010 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:  */
   8: 
   9: // Make sure no one attempts to run this script "directly"
  10: if (!defined('PUN'))
  11:     exit;
  12: 
  13: // Make sure we have a usable language pack for admin.
  14: if (file_exists(PUN_ROOT.'lang/'.$pun_user['language'].'/admin_common.php'))
  15:     $admin_language = $pun_user['language'];
  16: else if (file_exists(PUN_ROOT.'lang/'.$pun_config['o_default_lang'].'/admin_common.php'))
  17:     $admin_language = $pun_config['language'];
  18: else
  19:     $admin_language = 'English';
  20: 
  21: // Attempt to load the admin_common language file
  22: require PUN_ROOT.'lang/'.$admin_language.'/admin_common.php';
  23: 
  24: //
  25: // Display the admin navigation menu
  26: //
  27: function generate_admin_menu($page = '')
  28: {
  29:     global $pun_config, $pun_user, $lang_admin_common;
  30: 
  31:     $is_admin = $pun_user['g_id'] == PUN_ADMIN ? true : false;
  32: 
  33: ?>
  34: <div id="adminconsole" class="block2col">
  35:     <div id="adminmenu" class="blockmenu">
  36:         <h2><span><?php echo ($is_admin) ? $lang_admin_common['Admin menu'] : $lang_admin_common['Moderator menu'] ?></span></h2>
  37:         <div class="box">
  38:             <div class="inbox">
  39:                 <ul>
  40:                     <li<?php if ($page == 'index') echo ' class="isactive"'; ?>><a href="admin_index.php"><?php echo $lang_admin_common['Index'] ?></a></li>
  41: <?php if ($is_admin): ?>                    <li<?php if ($page == 'categories') echo ' class="isactive"'; ?>><a href="admin_categories.php"><?php echo $lang_admin_common['Categories'] ?></a></li>
  42: <?php endif; ?><?php if ($is_admin): ?>                    <li<?php if ($page == 'forums') echo ' class="isactive"'; ?>><a href="admin_forums.php"><?php echo $lang_admin_common['Forums'] ?></a></li>
  43: <?php endif; ?>                    <li<?php if ($page == 'users') echo ' class="isactive"'; ?>><a href="admin_users.php"><?php echo $lang_admin_common['Users'] ?></a></li>
  44: <?php if ($is_admin): ?>                    <li<?php if ($page == 'groups') echo ' class="isactive"'; ?>><a href="admin_groups.php"><?php echo $lang_admin_common['User groups'] ?></a></li>
  45: <?php endif; ?><?php if ($is_admin): ?>                    <li<?php if ($page == 'options') echo ' class="isactive"'; ?>><a href="admin_options.php"><?php echo $lang_admin_common['Options'] ?></a></li>
  46: <?php endif; ?><?php if ($is_admin): ?>                    <li<?php if ($page == 'permissions') echo ' class="isactive"'; ?>><a href="admin_permissions.php"><?php echo $lang_admin_common['Permissions'] ?></a></li>
  47: <?php endif; ?><?php if ($is_admin || $pun_config['o_censoring'] == '1'): ?>                    <li<?php if ($page == 'censoring') echo ' class="isactive"'; ?>><a href="admin_censoring.php"><?php echo $lang_admin_common['Censoring'] ?></a></li>
  48: <?php endif; ?><?php if ($is_admin): ?>                    <li<?php if ($page == 'ranks') echo ' class="isactive"'; ?>><a href="admin_ranks.php"><?php echo $lang_admin_common['Ranks'] ?></a></li>
  49: <?php endif; ?><?php if ($is_admin || $pun_user['g_mod_ban_users'] == '1'): ?>                    <li<?php if ($page == 'bans') echo ' class="isactive"'; ?>><a href="admin_bans.php"><?php echo $lang_admin_common['Bans'] ?></a></li>
  50: <?php endif; ?><?php if ($is_admin): ?>                    <li<?php if ($page == 'prune') echo ' class="isactive"'; ?>><a href="admin_prune.php"><?php echo $lang_admin_common['Prune'] ?></a></li>
  51: <?php endif; ?><?php if ($is_admin): ?>                    <li<?php if ($page == 'maintenance') echo ' class="isactive"'; ?>><a href="admin_maintenance.php"><?php echo $lang_admin_common['Maintenance'] ?></a></li>
  52: <?php endif; ?>                    <li<?php if ($page == 'reports') echo ' class="isactive"'; ?>><a href="admin_reports.php"><?php echo $lang_admin_common['Reports'] ?></a></li>
  53:                 </ul>
  54:             </div>
  55:         </div>
  56: <?php
  57: 
  58:     // See if there are any plugins
  59:     $plugins = forum_list_plugins($is_admin);
  60: 
  61:     // Did we find any plugins?
  62:     if (!empty($plugins))
  63:     {
  64: 
  65: ?>
  66:         <h2 class="block2"><span><?php echo $lang_admin_common['Plugins menu'] ?></span></h2>
  67:         <div class="box">
  68:             <div class="inbox">
  69:                 <ul>
  70: <?php
  71: 
  72:         foreach ($plugins as $cur_plugin)
  73:             echo "\t\t\t\t\t".'<li'.(($page == $cur_plugin[1]) ? ' class="isactive"' : '').'><a href="admin_loader.php?plugin='.$cur_plugin[1].'">'.str_replace('_', ' ', $cur_plugin[0]).'</a></li>'."\n";
  74: 
  75: ?>
  76:                 </ul>
  77:             </div>
  78:         </div>
  79: <?php
  80: 
  81:     }
  82: 
  83: ?>
  84:     </div>
  85: 
  86: <?php
  87: 
  88: }
  89: 
  90: 
  91: //
  92: // Delete topics from $forum_id that are "older than" $prune_date (if $prune_sticky is 1, sticky topics will also be deleted)
  93: //
  94: function prune($forum_id, $prune_sticky, $prune_date)
  95: {
  96:     global $db;
  97: 
  98:     $extra_sql = ($prune_date != -1) ? ' AND last_post<'.$prune_date : '';
  99: 
 100:     if (!$prune_sticky)
 101:         $extra_sql .= ' AND sticky=\'0\'';
 102: 
 103:     // Fetch topics to prune
 104:     $result = $db->query('SELECT id FROM '.$db->prefix.'topics WHERE forum_id='.$forum_id.$extra_sql, true) or error('Unable to fetch topics', __FILE__, __LINE__, $db->error());
 105: 
 106:     $topic_ids = '';
 107:     while ($row = $db->fetch_row($result))
 108:         $topic_ids .= (($topic_ids != '') ? ',' : '').$row[0];
 109: 
 110:     if ($topic_ids != '')
 111:     {
 112:         // Fetch posts to prune
 113:         $result = $db->query('SELECT id FROM '.$db->prefix.'posts WHERE topic_id IN('.$topic_ids.')', true) or error('Unable to fetch posts', __FILE__, __LINE__, $db->error());
 114: 
 115:         $post_ids = '';
 116:         while ($row = $db->fetch_row($result))
 117:             $post_ids .= (($post_ids != '') ? ',' : '').$row[0];
 118: 
 119:         if ($post_ids != '')
 120:         {
 121:             // Delete topics
 122:             $db->query('DELETE FROM '.$db->prefix.'topics WHERE id IN('.$topic_ids.')') or error('Unable to prune topics', __FILE__, __LINE__, $db->error());
 123:             // Delete subscriptions
 124:             $db->query('DELETE FROM '.$db->prefix.'subscriptions WHERE topic_id IN('.$topic_ids.')') or error('Unable to prune subscriptions', __FILE__, __LINE__, $db->error());
 125:             // Delete posts
 126:             $db->query('DELETE FROM '.$db->prefix.'posts WHERE id IN('.$post_ids.')') or error('Unable to prune posts', __FILE__, __LINE__, $db->error());
 127: 
 128:             // We removed a bunch of posts, so now we have to update the search index
 129:             require_once PUN_ROOT.'include/search_idx.php';
 130:             strip_search_index($post_ids);
 131:         }
 132:     }
 133: }


/dev/null b/include/dblayer/common_db.php
   1: <?php
   2: 
   3: /**
   4:  * Copyright (C) 2008-2010 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:  */
   8: 
   9: // Make sure no one attempts to run this script "directly"
  10: if (!defined('PUN'))
  11:     exit;
  12: 
  13: 
  14: // Load the appropriate DB layer class
  15: switch ($db_type)
  16: {
  17:     case 'mysql':
  18:         require PUN_ROOT.'include/dblayer/mysql.php';
  19:         break;
  20: 
  21:     case 'mysql_innodb':
  22:         require PUN_ROOT.'include/dblayer/mysql_innodb.php';
  23:         break;
  24: 
  25:     case 'mysqli':
  26:         require PUN_ROOT.'include/dblayer/mysqli.php';
  27:         break;
  28: 
  29:     case 'mysqli_innodb':
  30:         require PUN_ROOT.'include/dblayer/mysqli_innodb.php';
  31:         break;
  32: 
  33:     case 'pgsql':
  34:         require PUN_ROOT.'include/dblayer/pgsql.php';
  35:         break;
  36: 
  37:     case 'sqlite':
  38:         require PUN_ROOT.'include/dblayer/sqlite.php';
  39:         break;
  40: 
  41:     default:
  42:         error('\''.$db_type.'\' is not a valid database type. Please check settings in config.php.', __FILE__, __LINE__);
  43:         break;
  44: }
  45: 
  46: 
  47: // Create the database adapter object (and open/connect to/select db)
  48: $db = new DBLayer($db_host, $db_username, $db_password, $db_name, $db_prefix, $p_connect);


/dev/null b/include/dblayer/index.html
   1: <html><head><title>.</title></head><body>.</body></html>


/dev/null b/include/dblayer/mysql.php
   1: <?php
   2: 
   3: /**
   4:  * Copyright (C) 2008-2010 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:  */
   8: 
   9: // Make sure we have built in support for MySQL
  10: if (!function_exists('mysql_connect'))
  11:     exit('This PHP environment doesn\'t have MySQL support built in. MySQL support is required if you want to use a MySQL database to run this forum. Consult the PHP documentation for further assistance.');
  12: 
  13: 
  14: class DBLayer
  15: {
  16:     var $prefix;
  17:     var $link_id;
  18:     var $query_result;
  19: 
  20:     var $saved_queries = array();
  21:     var $num_queries = 0;
  22: 
  23:     var $datatype_transformations = array(
  24:         '/^SERIAL$/'    =>    'INT(10) UNSIGNED AUTO_INCREMENT'
  25:     );
  26: 
  27: 
  28:     function DBLayer($db_host, $db_username, $db_password, $db_name, $db_prefix, $p_connect)
  29:     {
  30:         $this->prefix = $db_prefix;
  31: 
  32:         if ($p_connect)
  33:             $this->link_id = @mysql_pconnect($db_host, $db_username, $db_password);
  34:         else
  35:             $this->link_id = @mysql_connect($db_host, $db_username, $db_password);
  36: 
  37:         if ($this->link_id)
  38:         {
  39:             if (!@mysql_select_db($db_name, $this->link_id))
  40:                 error('Unable to select database. MySQL reported: '.mysql_error(), __FILE__, __LINE__);
  41:         }
  42:         else
  43:             error('Unable to connect to MySQL server. MySQL reported: '.mysql_error(), __FILE__, __LINE__);
  44: 
  45:         // Setup the client-server character set (UTF-8)
  46:         if (!defined('FORUM_NO_SET_NAMES'))
  47:             $this->set_names('utf8');
  48: 
  49:         return $this->link_id;
  50:     }
  51: 
  52: 
  53:     function start_transaction()
  54:     {
  55:         return;
  56:     }
  57: 
  58: 
  59:     function end_transaction()
  60:     {
  61:         return;
  62:     }
  63: 
  64: 
  65:     function query($sql, $unbuffered = false)
  66:     {
  67:         if (defined('PUN_SHOW_QUERIES'))
  68:             $q_start = get_microtime();
  69: 
  70:         if ($unbuffered)
  71:             $this->query_result = @mysql_unbuffered_query($sql, $this->link_id);
  72:         else
  73:             $this->query_result = @mysql_query($sql, $this->link_id);
  74: 
  75:         if ($this->query_result)
  76:         {
  77:             if (defined('PUN_SHOW_QUERIES'))
  78:                 $this->saved_queries[] = array($sql, sprintf('%.5f', get_microtime() - $q_start));
  79: 
  80:             ++$this->num_queries;
  81: 
  82:             return $this->query_result;
  83:         }
  84:         else
  85:         {
  86:             if (defined('PUN_SHOW_QUERIES'))
  87:                 $this->saved_queries[] = array($sql, 0);
  88: 
  89:             return false;
  90:         }
  91:     }
  92: 
  93: 
  94:     function result($query_id = 0, $row = 0, $col = 0)
  95:     {
  96:         return ($query_id) ? @mysql_result($query_id, $row, $col) : false;
  97:     }
  98: 
  99: 
 100:     function fetch_assoc($query_id = 0)
 101:     {
 102:         return ($query_id) ? @mysql_fetch_assoc($query_id) : false;
 103:     }
 104: 
 105: 
 106:     function fetch_row($query_id = 0)
 107:     {
 108:         return ($query_id) ? @mysql_fetch_row($query_id) : false;
 109:     }
 110: 
 111: 
 112:     function num_rows($query_id = 0)
 113:     {
 114:         return ($query_id) ? @mysql_num_rows($query_id) : false;
 115:     }
 116: 
 117: 
 118:     function affected_rows()
 119:     {
 120:         return ($this->link_id) ? @mysql_affected_rows($this->link_id) : false;
 121:     }
 122: 
 123: 
 124:     function insert_id()
 125:     {
 126:         return ($this->link_id) ? @mysql_insert_id($this->link_id) : false;
 127:     }
 128: 
 129: 
 130:     function get_num_queries()
 131:     {
 132:         return $this->num_queries;
 133:     }
 134: 
 135: 
 136:     function get_saved_queries()
 137:     {
 138:         return $this->saved_queries;
 139:     }
 140: 
 141: 
 142:     function free_result($query_id = false)
 143:     {
 144:         return ($query_id) ? @mysql_free_result($query_id) : false;
 145:     }
 146: 
 147: 
 148:     function escape($str)
 149:     {
 150:         if (is_array($str))
 151:             return '';
 152:         else if (function_exists('mysql_real_escape_string'))
 153:             return mysql_real_escape_string($str, $this->link_id);
 154:         else
 155:             return mysql_escape_string($str);
 156:     }
 157: 
 158: 
 159:     function error()
 160:     {
 161:         $result['error_sql'] = @current(@end($this->saved_queries));
 162:         $result['error_no'] = @mysql_errno($this->link_id);
 163:         $result['error_msg'] = @mysql_error($this->link_id);
 164: 
 165:         return $result;
 166:     }
 167: 
 168: 
 169:     function close()
 170:     {
 171:         if ($this->link_id)
 172:         {
 173:             if ($this->query_result)
 174:                 @mysql_free_result($this->query_result);
 175: 
 176:             return @mysql_close($this->link_id);
 177:         }
 178:         else
 179:             return false;
 180:     }
 181: 
 182:     function get_names()
 183:     {
 184:         $result = $this->query('SHOW VARIABLES LIKE \'character_set_connection\'');
 185:         return $this->result($result, 0, 1);
 186:     }
 187: 
 188: 
 189:     function set_names($names)
 190:     {
 191:         return $this->query('SET NAMES \''.$this->escape($names).'\'');
 192:     }
 193: 
 194: 
 195:     function get_version()
 196:     {
 197:         $result = $this->query('SELECT VERSION()');
 198: 
 199:         return array(
 200:             'name'        => 'MySQL Standard',
 201:             'version'    => preg_replace('/^([^-]+).*$/', '\\1', $this->result($result))
 202:         );
 203:     }
 204: 
 205: 
 206:     function table_exists($table_name, $no_prefix = false)
 207:     {
 208:         $result = $this->query('SHOW TABLES LIKE \''.($no_prefix ? '' : $this->prefix).$this->escape($table_name).'\'');
 209:         return $this->num_rows($result) > 0;
 210:     }
 211: 
 212: 
 213:     function field_exists($table_name, $field_name, $no_prefix = false)
 214:     {
 215:         $result = $this->query('SHOW COLUMNS FROM '.($no_prefix ? '' : $this->prefix).$table_name.' LIKE \''.$this->escape($field_name).'\'');
 216:         return $this->num_rows($result) > 0;
 217:     }
 218: 
 219: 
 220:     function index_exists($table_name, $index_name, $no_prefix = false)
 221:     {
 222:         $exists = false;
 223: 
 224:         $result = $this->query('SHOW INDEX FROM '.($no_prefix ? '' : $this->prefix).$table_name);
 225:         while ($cur_index = $this->fetch_assoc($result))
 226:         {
 227:             if ($cur_index['Key_name'] == ($no_prefix ? '' : $this->prefix).$table_name.'_'.$index_name)
 228:             {
 229:                 $exists = true;
 230:                 break;
 231:             }
 232:         }
 233: 
 234:         return $exists;
 235:     }
 236: 
 237: 
 238:     function create_table($table_name, $schema, $no_prefix = false)
 239:     {
 240:         if ($this->table_exists($table_name, $no_prefix))
 241:             return true;
 242: 
 243:         $query = 'CREATE TABLE '.($no_prefix ? '' : $this->prefix).$table_name." (\n";
 244: 
 245:         // Go through every schema element and add it to the query
 246:         foreach ($schema['FIELDS'] as $field_name => $field_data)
 247:         {
 248:             $field_data['datatype'] = preg_replace(array_keys($this->datatype_transformations), array_values($this->datatype_transformations), $field_data['datatype']);
 249: 
 250:             $query .= $field_name.' '.$field_data['datatype'];
 251: 
 252:             if (isset($field_data['collation']))
 253:                 $query .= 'CHARACTER SET utf8 COLLATE utf8_'.$field_data['collation'];
 254: 
 255:             if (!$field_data['allow_null'])
 256:                 $query .= ' NOT NULL';
 257: 
 258:             if (isset($field_data['default']))
 259:                 $query .= ' DEFAULT '.$field_data['default'];
 260: 
 261:             $query .= ",\n";
 262:         }
 263: 
 264:         // If we have a primary key, add it
 265:         if (isset($schema['PRIMARY KEY']))
 266:             $query .= 'PRIMARY KEY ('.implode(',', $schema['PRIMARY KEY']).'),'."\n";
 267: 
 268:         // Add unique keys
 269:         if (isset($schema['UNIQUE KEYS']))
 270:         {
 271:             foreach ($schema['UNIQUE KEYS'] as $key_name => $key_fields)
 272:                 $query .= 'UNIQUE KEY '.($no_prefix ? '' : $this->prefix).$table_name.'_'.$key_name.'('.implode(',', $key_fields).'),'."\n";
 273:         }
 274: 
 275:         // Add indexes
 276:         if (isset($schema['INDEXES']))
 277:         {
 278:             foreach ($schema['INDEXES'] as $index_name => $index_fields)
 279:                 $query .= 'KEY '.($no_prefix ? '' : $this->prefix).$table_name.'_'.$index_name.'('.implode(',', $index_fields).'),'."\n";
 280:         }
 281: 
 282:         // We remove the last two characters (a newline and a comma) and add on the ending
 283:         $query = substr($query, 0, strlen($query) - 2)."\n".') ENGINE = '.(isset($schema['ENGINE']) ? $schema['ENGINE'] : 'MyISAM').' CHARACTER SET utf8';
 284: 
 285:         return $this->query($query) ? true : false;
 286:     }
 287: 
 288: 
 289:     function drop_table($table_name, $no_prefix = false)
 290:     {
 291:         if (!$this->table_exists($table_name, $no_prefix))
 292:             return true;
 293: 
 294:         return $this->query('DROP TABLE '.($no_prefix ? '' : $this->prefix).$table_name) ? true : false;
 295:     }
 296: 
 297: 
 298:     function add_field($table_name, $field_name, $field_type, $allow_null, $default_value = null, $after_field = null, $no_prefix = false)
 299:     {
 300:         if ($this->field_exists($table_name, $field_name, $no_prefix))
 301:             return true;
 302: 
 303:         $field_type = preg_replace(array_keys($this->datatype_transformations), array_values($this->datatype_transformations), $field_type);
 304: 
 305:         if ($default_value !== null && !is_int($default_value) && !is_float($default_value))
 306:             $default_value = '\''.$this->escape($default_value).'\'';
 307: 
 308:         return $this->query('ALTER TABLE '.($no_prefix ? '' : $this->prefix).$table_name.' ADD '.$field_name.' '.$field_type.($allow_null ? ' ' : ' NOT NULL').($default_value !== null ? ' DEFAULT '.$default_value : ' ').($after_field != null ? ' AFTER '.$after_field : '')) ? true : false;
 309:     }
 310: 
 311: 
 312:     function alter_field($table_name, $field_name, $field_type, $allow_null, $default_value = null, $after_field = null, $no_prefix = false)
 313:     {
 314:         if (!$this->field_exists($table_name, $field_name, $no_prefix))
 315:             return true;
 316: 
 317:         $field_type = preg_replace(array_keys($this->datatype_transformations), array_values($this->datatype_transformations), $field_type);
 318: 
 319:         if ($default_value !== null && !is_int($default_value) && !is_float($default_value))
 320:             $default_value = '\''.$this->escape($default_value).'\'';
 321: 
 322:         return $this->query('ALTER TABLE '.($no_prefix ? '' : $this->prefix).$table_name.' MODIFY '.$field_name.' '.$field_type.($allow_null ? ' ' : ' NOT NULL').($default_value !== null ? ' DEFAULT '.$default_value : ' ').($after_field != null ? ' AFTER '.$after_field : '')) ? true : false;
 323:     }
 324: 
 325: 
 326:     function drop_field($table_name, $field_name, $no_prefix = false)
 327:     {
 328:         if (!$this->field_exists($table_name, $field_name, $no_prefix))
 329:             return true;
 330: 
 331:         return $this->query('ALTER TABLE '.($no_prefix ? '' : $this->prefix).$table_name.' DROP '.$field_name) ? true : false;
 332:     }
 333: 
 334: 
 335:     function add_index($table_name, $index_name, $index_fields, $unique = false, $no_prefix = false)
 336:     {
 337:         if ($this->index_exists($table_name, $index_name, $no_prefix))
 338:             return true;
 339: 
 340:         return $this->query('ALTER TABLE '.($no_prefix ? '' : $this->prefix).$table_name.' ADD '.($unique ? 'UNIQUE ' : '').'INDEX '.($no_prefix ? '' : $this->prefix).$table_name.'_'.$index_name.' ('.implode(',', $index_fields).')') ? true : false;
 341:     }
 342: 
 343: 
 344:     function drop_index($table_name, $index_name, $no_prefix = false)
 345:     {
 346:         if (!$this->index_exists($table_name, $index_name, $no_prefix))
 347:             return true;
 348: 
 349:         return $this->query('ALTER TABLE '.($no_prefix ? '' : $this->prefix).$table_name.' DROP INDEX '.($no_prefix ? '' : $this->prefix).$table_name.'_'.$index_name) ? true : false;
 350:     }
 351: 
 352:     function truncate_table($table_name, $no_prefix = false)
 353:     {
 354:         return $this->query('TRUNCATE TABLE '.($no_prefix ? '' : $this->prefix).$table_name) ? true : false;
 355:     }
 356: }


/dev/null b/include/dblayer/mysql_innodb.php
   1: <?php
   2: 
   3: /**
   4:  * Copyright (C) 2008-2010 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:  */
   8: 
   9: // Make sure we have built in support for MySQL
  10: if (!function_exists('mysql_connect'))
  11:     exit('This PHP environment doesn\'t have MySQL support built in. MySQL support is required if you want to use a MySQL database to run this forum. Consult the PHP documentation for further assistance.');
  12: 
  13: 
  14: class DBLayer
  15: {
  16:     var $prefix;
  17:     var $link_id;
  18:     var $query_result;
  19:     var $in_transaction = 0;
  20: 
  21:     var $saved_queries = array();
  22:     var $num_queries = 0;
  23: 
  24:     var $datatype_transformations = array(
  25:         '/^SERIAL$/'    =>    'INT(10) UNSIGNED AUTO_INCREMENT'
  26:     );
  27: 
  28: 
  29:     function DBLayer($db_host, $db_username, $db_password, $db_name, $db_prefix, $p_connect)
  30:     {
  31:         $this->prefix = $db_prefix;
  32: 
  33:         if ($p_connect)
  34:             $this->link_id = @mysql_pconnect($db_host, $db_username, $db_password);
  35:         else
  36:             $this->link_id = @mysql_connect($db_host, $db_username, $db_password);
  37: 
  38:         if ($this->link_id)
  39:         {
  40:             if (!@mysql_select_db($db_name, $this->link_id))
  41:                 error('Unable to select database. MySQL reported: '.mysql_error(), __FILE__, __LINE__);
  42:         }
  43:         else
  44:             error('Unable to connect to MySQL server. MySQL reported: '.mysql_error(), __FILE__, __LINE__);
  45: 
  46:         // Setup the client-server character set (UTF-8)
  47:         if (!defined('FORUM_NO_SET_NAMES'))
  48:             $this->set_names('utf8');
  49: 
  50:         return $this->link_id;
  51:     }
  52: 
  53: 
  54:     function start_transaction()
  55:     {
  56:         ++$this->in_transaction;
  57: 
  58:         mysql_query('START TRANSACTION', $this->link_id);
  59:         return;
  60:     }
  61: 
  62: 
  63:     function end_transaction()
  64:     {
  65:         --$this->in_transaction;
  66: 
  67:         mysql_query('COMMIT', $this->link_id);
  68:         return;
  69:     }
  70: 
  71: 
  72:     function query($sql, $unbuffered = false)
  73:     {
  74:         if (defined('PUN_SHOW_QUERIES'))
  75:             $q_start = get_microtime();
  76: 
  77:         if ($unbuffered)
  78:             $this->query_result = @mysql_unbuffered_query($sql, $this->link_id);
  79:         else
  80:             $this->query_result = @mysql_query($sql, $this->link_id);
  81: 
  82:         if ($this->query_result)
  83:         {
  84:             if (defined('PUN_SHOW_QUERIES'))
  85:                 $this->saved_queries[] = array($sql, sprintf('%.5f', get_microtime() - $q_start));
  86: 
  87:             ++$this->num_queries;
  88: 
  89:             return $this->query_result;
  90:         }
  91:         else
  92:         {
  93:             if (defined('PUN_SHOW_QUERIES'))
  94:                 $this->saved_queries[] = array($sql, 0);
  95: 
  96:             // Rollback transaction
  97:             if ($this->in_transaction)
  98:                 mysql_query('ROLLBACK', $this->link_id);
  99: 
 100:             --$this->in_transaction;
 101: 
 102:             return false;
 103:         }
 104:     }
 105: 
 106: 
 107:     function result($query_id = 0, $row = 0, $col = 0)
 108:     {
 109:         return ($query_id) ? @mysql_result($query_id, $row, $col) : false;
 110:     }
 111: 
 112: 
 113:     function fetch_assoc($query_id = 0)
 114:     {
 115:         return ($query_id) ? @mysql_fetch_assoc($query_id) : false;
 116:     }
 117: 
 118: 
 119:     function fetch_row($query_id = 0)
 120:     {
 121:         return ($query_id) ? @mysql_fetch_row($query_id) : false;
 122:     }
 123: 
 124: 
 125:     function num_rows($query_id = 0)
 126:     {
 127:         return ($query_id) ? @mysql_num_rows($query_id) : false;
 128:     }
 129: 
 130: 
 131:     function affected_rows()
 132:     {
 133:         return ($this->link_id) ? @mysql_affected_rows($this->link_id) : false;
 134:     }
 135: 
 136: 
 137:     function insert_id()
 138:     {
 139:         return ($this->link_id) ? @mysql_insert_id($this->link_id) : false;
 140:     }
 141: 
 142: 
 143:     function get_num_queries()
 144:     {
 145:         return $this->num_queries;
 146:     }
 147: 
 148: 
 149:     function get_saved_queries()
 150:     {
 151:         return $this->saved_queries;
 152:     }
 153: 
 154: 
 155:     function free_result($query_id = false)
 156:     {
 157:         return ($query_id) ? @mysql_free_result($query_id) : false;
 158:     }
 159: 
 160: 
 161:     function escape($str)
 162:     {
 163:         if (is_array($str))
 164:             return '';
 165:         else if (function_exists('mysql_real_escape_string'))
 166:             return mysql_real_escape_string($str, $this->link_id);
 167:         else
 168:             return mysql_escape_string($str);
 169:     }
 170: 
 171: 
 172:     function error()
 173:     {
 174:         $result['error_sql'] = @current(@end($this->saved_queries));
 175:         $result['error_no'] = @mysql_errno($this->link_id);
 176:         $result['error_msg'] = @mysql_error($this->link_id);
 177: 
 178:         return $result;
 179:     }
 180: 
 181: 
 182:     function close()
 183:     {
 184:         if ($this->link_id)
 185:         {
 186:             if ($this->query_result)
 187:                 @mysql_free_result($this->query_result);
 188: 
 189:             return @mysql_close($this->link_id);
 190:         }
 191:         else
 192:             return false;
 193:     }
 194: 
 195: 
 196:     function get_names()
 197:     {
 198:         $result = $this->query('SHOW VARIABLES LIKE \'character_set_connection\'');
 199:         return $this->result($result, 0, 1);
 200:     }
 201: 
 202: 
 203:     function set_names($names)
 204:     {
 205:         return $this->query('SET NAMES \''.$this->escape($names).'\'');
 206:     }
 207: 
 208: 
 209:     function get_version()
 210:     {
 211:         $result = $this->query('SELECT VERSION()');
 212: 
 213:         return array(
 214:             'name'        => 'MySQL Standard (InnoDB)',
 215:             'version'    => preg_replace('/^([^-]+).*$/', '\\1', $this->result($result))
 216:         );
 217:     }
 218: 
 219: 
 220:     function table_exists($table_name, $no_prefix = false)
 221:     {
 222:         $result = $this->query('SHOW TABLES LIKE \''.($no_prefix ? '' : $this->prefix).$this->escape($table_name).'\'');
 223:         return $this->num_rows($result) > 0;
 224:     }
 225: 
 226: 
 227:     function field_exists($table_name, $field_name, $no_prefix = false)
 228:     {
 229:         $result = $this->query('SHOW COLUMNS FROM '.($no_prefix ? '' : $this->prefix).$table_name.' LIKE \''.$this->escape($field_name).'\'');
 230:         return $this->num_rows($result) > 0;
 231:     }
 232: 
 233: 
 234:     function index_exists($table_name, $index_name, $no_prefix = false)
 235:     {
 236:         $exists = false;
 237: 
 238:         $result = $this->query('SHOW INDEX FROM '.($no_prefix ? '' : $this->prefix).$table_name);
 239:         while ($cur_index = $this->fetch_assoc($result))
 240:         {
 241:             if ($cur_index['Key_name'] == ($no_prefix ? '' : $this->prefix).$table_name.'_'.$index_name)
 242:             {
 243:                 $exists = true;
 244:                 break;
 245:             }
 246:         }
 247: 
 248:         return $exists;
 249:     }
 250: 
 251: 
 252:     function create_table($table_name, $schema, $no_prefix = false)
 253:     {
 254:         if ($this->table_exists($table_name, $no_prefix))
 255:             return true;
 256: 
 257:         $query = 'CREATE TABLE '.($no_prefix ? '' : $this->prefix).$table_name." (\n";
 258: 
 259:         // Go through every schema element and add it to the query
 260:         foreach ($schema['FIELDS'] as $field_name => $field_data)
 261:         {
 262:             $field_data['datatype'] = preg_replace(array_keys($this->datatype_transformations), array_values($this->datatype_transformations), $field_data['datatype']);
 263: 
 264:             $query .= $field_name.' '.$field_data['datatype'];
 265: 
 266:             if (isset($field_data['collation']))
 267:                 $query .= 'CHARACTER SET utf8 COLLATE utf8_'.$field_data['collation'];
 268: 
 269:             if (!$field_data['allow_null'])
 270:                 $query .= ' NOT NULL';
 271: 
 272:             if (isset($field_data['default']))
 273:                 $query .= ' DEFAULT '.$field_data['default'];
 274: 
 275:             $query .= ",\n";
 276:         }
 277: 
 278:         // If we have a primary key, add it
 279:         if (isset($schema['PRIMARY KEY']))
 280:             $query .= 'PRIMARY KEY ('.implode(',', $schema['PRIMARY KEY']).'),'."\n";
 281: 
 282:         // Add unique keys
 283:         if (isset($schema['UNIQUE KEYS']))
 284:         {
 285:             foreach ($schema['UNIQUE KEYS'] as $key_name => $key_fields)
 286:                 $query .= 'UNIQUE KEY '.($no_prefix ? '' : $this->prefix).$table_name.'_'.$key_name.'('.implode(',', $key_fields).'),'."\n";
 287:         }
 288: 
 289:         // Add indexes
 290:         if (isset($schema['INDEXES']))
 291:         {
 292:             foreach ($schema['INDEXES'] as $index_name => $index_fields)
 293:                 $query .= 'KEY '.($no_prefix ? '' : $this->prefix).$table_name.'_'.$index_name.'('.implode(',', $index_fields).'),'."\n";
 294:         }
 295: 
 296:         // We remove the last two characters (a newline and a comma) and add on the ending
 297:         $query = substr($query, 0, strlen($query) - 2)."\n".') ENGINE = '.(isset($schema['ENGINE']) ? $schema['ENGINE'] : 'InnoDB').' CHARACTER SET utf8';
 298: 
 299:         return $this->query($query) ? true : false;
 300:     }
 301: 
 302: 
 303:     function drop_table($table_name, $no_prefix = false)
 304:     {
 305:         if (!$this->table_exists($table_name, $no_prefix))
 306:             return true;
 307: 
 308:         return $this->query('DROP TABLE '.($no_prefix ? '' : $this->prefix).$table_name) ? true : false;
 309:     }
 310: 
 311: 
 312:     function add_field($table_name, $field_name, $field_type, $allow_null, $default_value = null, $after_field = null, $no_prefix = false)
 313:     {
 314:         if ($this->field_exists($table_name, $field_name, $no_prefix))
 315:             return true;
 316: 
 317:         $field_type = preg_replace(array_keys($this->datatype_transformations), array_values($this->datatype_transformations), $field_type);
 318: 
 319:         if ($default_value !== null && !is_int($default_value) && !is_float($default_value))
 320:             $default_value = '\''.$this->escape($default_value).'\'';
 321: 
 322:         return $this->query('ALTER TABLE '.($no_prefix ? '' : $this->prefix).$table_name.' ADD '.$field_name.' '.$field_type.($allow_null ? ' ' : ' NOT NULL').($default_value !== null ? ' DEFAULT '.$default_value : ' ').($after_field != null ? ' AFTER '.$after_field : '')) ? true : false;
 323:     }
 324: 
 325: 
 326:     function alter_field($table_name, $field_name, $field_type, $allow_null, $default_value = null, $after_field = null, $no_prefix = false)
 327:     {
 328:         if (!$this->field_exists($table_name, $field_name, $no_prefix))
 329:             return true;
 330: 
 331:         $field_type = preg_replace(array_keys($this->datatype_transformations), array_values($this->datatype_transformations), $field_type);
 332: 
 333:         if ($default_value !== null && !is_int($default_value) && !is_float($default_value))
 334:             $default_value = '\''.$this->escape($default_value).'\'';
 335: 
 336:         return $this->query('ALTER TABLE '.($no_prefix ? '' : $this->prefix).$table_name.' MODIFY '.$field_name.' '.$field_type.($allow_null ? ' ' : ' NOT NULL').($default_value !== null ? ' DEFAULT '.$default_value : ' ').($after_field != null ? ' AFTER '.$after_field : '')) ? true : false;
 337:     }
 338: 
 339: 
 340:     function drop_field($table_name, $field_name, $no_prefix = false)
 341:     {
 342:         if (!$this->field_exists($table_name, $field_name, $no_prefix))
 343:             return true;
 344: 
 345:         return $this->query('ALTER TABLE '.($no_prefix ? '' : $this->prefix).$table_name.' DROP '.$field_name) ? true : false;
 346:     }
 347: 
 348: 
 349:     function add_index($table_name, $index_name, $index_fields, $unique = false, $no_prefix = false)
 350:     {
 351:         if ($this->index_exists($table_name, $index_name, $no_prefix))
 352:             return true;
 353: 
 354:         return $this->query('ALTER TABLE '.($no_prefix ? '' : $this->prefix).$table_name.' ADD '.($unique ? 'UNIQUE ' : '').'INDEX '.($no_prefix ? '' : $this->prefix).$table_name.'_'.$index_name.' ('.implode(',', $index_fields).')') ? true : false;
 355:     }
 356: 
 357: 
 358:     function drop_index($table_name, $index_name, $no_prefix = false)
 359:     {
 360:         if (!$this->index_exists($table_name, $index_name, $no_prefix))
 361:             return true;
 362: 
 363:         return $this->query('ALTER TABLE '.($no_prefix ? '' : $this->prefix).$table_name.' DROP INDEX '.($no_prefix ? '' : $this->prefix).$table_name.'_'.$index_name) ? true : false;
 364:     }
 365: 
 366:     function truncate_table($table_name, $no_prefix = false)
 367:     {
 368:         return $this->query('TRUNCATE TABLE '.($no_prefix ? '' : $this->prefix).$table_name) ? true : false;
 369:     }
 370: }


/dev/null b/include/dblayer/mysqli.php
   1: <?php
   2: 
   3: /**
   4:  * Copyright (C) 2008-2010 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:  */
   8: 
   9: // Make sure we have built in support for MySQL
  10: if (!function_exists('mysqli_connect'))
  11:     exit('This PHP environment doesn\'t have Improved MySQL (mysqli) support built in. Improved MySQL support is required if you want to use a MySQL 4.1 (or later) database to run this forum. Consult the PHP documentation for further assistance.');
  12: 
  13: 
  14: class DBLayer
  15: {
  16:     var $prefix;
  17:     var $link_id;
  18:     var $query_result;
  19: 
  20:     var $saved_queries = array();
  21:     var $num_queries = 0;
  22: 
  23:     var $datatype_transformations = array(
  24:         '/^SERIAL$/'    =>    'INT(10) UNSIGNED AUTO_INCREMENT'
  25:     );
  26: 
  27: 
  28:     function DBLayer($db_host, $db_username, $db_password, $db_name, $db_prefix, $p_connect)
  29:     {
  30:         $this->prefix = $db_prefix;
  31: 
  32:         // Was a custom port supplied with $db_host?
  33:         if (strpos($db_host, ':') !== false)
  34:             list($db_host, $db_port) = explode(':', $db_host);
  35: 
  36:         // Persistent connection in MySQLi are only available in PHP 5.3 and later releases
  37:         $p_connect = $p_connect && version_compare(PHP_VERSION, '5.3.0', '>=') ? 'p:' : '';
  38: 
  39:         if (isset($db_port))
  40:             $this->link_id = @mysqli_connect($p_connect.$db_host, $db_username, $db_password, $db_name, $db_port);
  41:         else
  42:             $this->link_id = @mysqli_connect($p_connect.$db_host, $db_username, $db_password, $db_name);
  43: 
  44:         if (!$this->link_id)
  45:             error('Unable to connect to MySQL and select database. MySQL reported: '.mysqli_connect_error(), __FILE__, __LINE__);
  46: 
  47:         // Setup the client-server character set (UTF-8)
  48:         if (!defined('FORUM_NO_SET_NAMES'))
  49:             $this->set_names('utf8');
  50: 
  51:         return $this->link_id;
  52:     }
  53: 
  54: 
  55:     function start_transaction()
  56:     {
  57:         return;
  58:     }
  59: 
  60: 
  61:     function end_transaction()
  62:     {
  63:         return;
  64:     }
  65: 
  66: 
  67:     function query($sql, $unbuffered = false)
  68:     {
  69:         if (defined('PUN_SHOW_QUERIES'))
  70:             $q_start = get_microtime();
  71: 
  72:         $this->query_result = @mysqli_query($this->link_id, $sql);
  73: 
  74:         if ($this->query_result)
  75:         {
  76:             if (defined('PUN_SHOW_QUERIES'))
  77:                 $this->saved_queries[] = array($sql, sprintf('%.5f', get_microtime() - $q_start));
  78: 
  79:             ++$this->num_queries;
  80: 
  81:             return $this->query_result;
  82:         }
  83:         else
  84:         {
  85:             if (defined('PUN_SHOW_QUERIES'))
  86:                 $this->saved_queries[] = array($sql, 0);
  87: 
  88:             return false;
  89:         }
  90:     }
  91: 
  92: 
  93:     function result($query_id = 0, $row = 0, $col = 0)
  94:     {
  95:         if ($query_id)
  96:         {
  97:             if ($row !== 0 && @mysqli_data_seek($query_id, $row) === false)
  98:                 return false;
  99: 
 100:             $cur_row = @mysqli_fetch_row($query_id);
 101:             if ($cur_row === false)
 102:                 return false;
 103: 
 104:             return $cur_row[$col];
 105:         }
 106:         else
 107:             return false;
 108:     }
 109: 
 110: 
 111:     function fetch_assoc($query_id = 0)
 112:     {
 113:         return ($query_id) ? @mysqli_fetch_assoc($query_id) : false;
 114:     }
 115: 
 116: 
 117:     function fetch_row($query_id = 0)
 118:     {
 119:         return ($query_id) ? @mysqli_fetch_row($query_id) : false;
 120:     }
 121: 
 122: 
 123:     function num_rows($query_id = 0)
 124:     {
 125:         return ($query_id) ? @mysqli_num_rows($query_id) : false;
 126:     }
 127: 
 128: 
 129:     function affected_rows()
 130:     {
 131:         return ($this->link_id) ? @mysqli_affected_rows($this->link_id) : false;
 132:     }
 133: 
 134: 
 135:     function insert_id()
 136:     {
 137:         return ($this->link_id) ? @mysqli_insert_id($this->link_id) : false;
 138:     }
 139: 
 140: 
 141:     function get_num_queries()
 142:     {
 143:         return $this->num_queries;
 144:     }
 145: 
 146: 
 147:     function get_saved_queries()
 148:     {
 149:         return $this->saved_queries;
 150:     }
 151: 
 152: 
 153:     function free_result($query_id = false)
 154:     {
 155:         return ($query_id) ? @mysqli_free_result($query_id) : false;
 156:     }
 157: 
 158: 
 159:     function escape($str)
 160:     {
 161:         return is_array($str) ? '' : mysqli_real_escape_string($this->link_id, $str);
 162:     }
 163: 
 164: 
 165:     function error()
 166:     {
 167:         $result['error_sql'] = @current(@end($this->saved_queries));
 168:         $result['error_no'] = @mysqli_errno($this->link_id);
 169:         $result['error_msg'] = @mysqli_error($this->link_id);
 170: 
 171:         return $result;
 172:     }
 173: 
 174: 
 175:     function close()
 176:     {
 177:         if ($this->link_id)
 178:         {
 179:             if ($this->query_result)
 180:                 @mysqli_free_result($this->query_result);
 181: 
 182:             return @mysqli_close($this->link_id);
 183:         }
 184:         else
 185:             return false;
 186:     }
 187: 
 188: 
 189:     function get_names()
 190:     {
 191:         $result = $this->query('SHOW VARIABLES LIKE \'character_set_connection\'');
 192:         return $this->result($result, 0, 1);
 193:     }
 194: 
 195: 
 196:     function set_names($names)
 197:     {
 198:         return $this->query('SET NAMES \''.$this->escape($names).'\'');
 199:     }
 200: 
 201: 
 202:     function get_version()
 203:     {
 204:         $result = $this->query('SELECT VERSION()');
 205: 
 206:         return array(
 207:             'name'        => 'MySQL Improved',
 208:             'version'    => preg_replace('/^([^-]+).*$/', '\\1', $this->result($result))
 209:         );
 210:     }
 211: 
 212: 
 213:     function table_exists($table_name, $no_prefix = false)
 214:     {
 215:         $result = $this->query('SHOW TABLES LIKE \''.($no_prefix ? '' : $this->prefix).$this->escape($table_name).'\'');
 216:         return $this->num_rows($result) > 0;
 217:     }
 218: 
 219: 
 220:     function field_exists($table_name, $field_name, $no_prefix = false)
 221:     {
 222:         $result = $this->query('SHOW COLUMNS FROM '.($no_prefix ? '' : $this->prefix).$table_name.' LIKE \''.$this->escape($field_name).'\'');
 223:         return $this->num_rows($result) > 0;
 224:     }
 225: 
 226: 
 227:     function index_exists($table_name, $index_name, $no_prefix = false)
 228:     {
 229:         $exists = false;
 230: 
 231:         $result = $this->query('SHOW INDEX FROM '.($no_prefix ? '' : $this->prefix).$table_name);
 232:         while ($cur_index = $this->fetch_assoc($result))
 233:         {
 234:             if ($cur_index['Key_name'] == ($no_prefix ? '' : $this->prefix).$table_name.'_'.$index_name)
 235:             {
 236:                 $exists = true;
 237:                 break;
 238:             }
 239:         }
 240: 
 241:         return $exists;
 242:     }
 243: 
 244: 
 245:     function create_table($table_name, $schema, $no_prefix = false)
 246:     {
 247:         if ($this->table_exists($table_name, $no_prefix))
 248:             return true;
 249: 
 250:         $query = 'CREATE TABLE '.($no_prefix ? '' : $this->prefix).$table_name." (\n";
 251: 
 252:         // Go through every schema element and add it to the query
 253:         foreach ($schema['FIELDS'] as $field_name => $field_data)
 254:         {
 255:             $field_data['datatype'] = preg_replace(array_keys($this->datatype_transformations), array_values($this->datatype_transformations), $field_data['datatype']);
 256: 
 257:             $query .= $field_name.' '.$field_data['datatype'];
 258: 
 259:             if (isset($field_data['collation']))
 260:                 $query .= 'CHARACTER SET utf8 COLLATE utf8_'.$field_data['collation'];
 261: 
 262:             if (!$field_data['allow_null'])
 263:                 $query .= ' NOT NULL';
 264: 
 265:             if (isset($field_data['default']))
 266:                 $query .= ' DEFAULT '.$field_data['default'];
 267: 
 268:             $query .= ",\n";
 269:         }
 270: 
 271:         // If we have a primary key, add it
 272:         if (isset($schema['PRIMARY KEY']))
 273:             $query .= 'PRIMARY KEY ('.implode(',', $schema['PRIMARY KEY']).'),'."\n";
 274: 
 275:         // Add unique keys
 276:         if (isset($schema['UNIQUE KEYS']))
 277:         {
 278:             foreach ($schema['UNIQUE KEYS'] as $key_name => $key_fields)
 279:                 $query .= 'UNIQUE KEY '.($no_prefix ? '' : $this->prefix).$table_name.'_'.$key_name.'('.implode(',', $key_fields).'),'."\n";
 280:         }
 281: 
 282:         // Add indexes
 283:         if (isset($schema['INDEXES']))
 284:         {
 285:             foreach ($schema['INDEXES'] as $index_name => $index_fields)
 286:                 $query .= 'KEY '.($no_prefix ? '' : $this->prefix).$table_name.'_'.$index_name.'('.implode(',', $index_fields).'),'."\n";
 287:         }
 288: 
 289:         // We remove the last two characters (a newline and a comma) and add on the ending
 290:         $query = substr($query, 0, strlen($query) - 2)."\n".') ENGINE = '.(isset($schema['ENGINE']) ? $schema['ENGINE'] : 'MyISAM').' CHARACTER SET utf8';
 291: 
 292:         return $this->query($query) ? true : false;
 293:     }
 294: 
 295: 
 296:     function drop_table($table_name, $no_prefix = false)
 297:     {
 298:         if (!$this->table_exists($table_name, $no_prefix))
 299:             return true;
 300: 
 301:         return $this->query('DROP TABLE '.($no_prefix ? '' : $this->prefix).$table_name) ? true : false;
 302:     }
 303: 
 304: 
 305:     function add_field($table_name, $field_name, $field_type, $allow_null, $default_value = null, $after_field = null, $no_prefix = false)
 306:     {
 307:         if ($this->field_exists($table_name, $field_name, $no_prefix))
 308:             return true;
 309: 
 310:         $field_type = preg_replace(array_keys($this->datatype_transformations), array_values($this->datatype_transformations), $field_type);
 311: 
 312:         if ($default_value !== null && !is_int($default_value) && !is_float($default_value))
 313:             $default_value = '\''.$this->escape($default_value).'\'';
 314: 
 315:         return $this->query('ALTER TABLE '.($no_prefix ? '' : $this->prefix).$table_name.' ADD '.$field_name.' '.$field_type.($allow_null ? ' ' : ' NOT NULL').($default_value !== null ? ' DEFAULT '.$default_value : ' ').($after_field != null ? ' AFTER '.$after_field : '')) ? true : false;
 316:     }
 317: 
 318: 
 319:     function alter_field($table_name, $field_name, $field_type, $allow_null, $default_value = null, $after_field = null, $no_prefix = false)
 320:     {
 321:         if (!$this->field_exists($table_name, $field_name, $no_prefix))
 322:             return true;
 323: 
 324:         $field_type = preg_replace(array_keys($this->datatype_transformations), array_values($this->datatype_transformations), $field_type);
 325: 
 326:         if ($default_value !== null && !is_int($default_value) && !is_float($default_value))
 327:             $default_value = '\''.$this->escape($default_value).'\'';
 328: 
 329:         return $this->query('ALTER TABLE '.($no_prefix ? '' : $this->prefix).$table_name.' MODIFY '.$field_name.' '.$field_type.($allow_null ? ' ' : ' NOT NULL').($default_value !== null ? ' DEFAULT '.$default_value : ' ').($after_field != null ? ' AFTER '.$after_field : '')) ? true : false;
 330:     }
 331: 
 332: 
 333:     function drop_field($table_name, $field_name, $no_prefix = false)
 334:     {
 335:         if (!$this->field_exists($table_name, $field_name, $no_prefix))
 336:             return true;
 337: 
 338:         return $this->query('ALTER TABLE '.($no_prefix ? '' : $this->prefix).$table_name.' DROP '.$field_name) ? true : false;
 339:     }
 340: 
 341: 
 342:     function add_index($table_name, $index_name, $index_fields, $unique = false, $no_prefix = false)
 343:     {
 344:         if ($this->index_exists($table_name, $index_name, $no_prefix))
 345:             return true;
 346: 
 347:         return $this->query('ALTER TABLE '.($no_prefix ? '' : $this->prefix).$table_name.' ADD '.($unique ? 'UNIQUE ' : '').'INDEX '.($no_prefix ? '' : $this->prefix).$table_name.'_'.$index_name.' ('.implode(',', $index_fields).')') ? true : false;
 348:     }
 349: 
 350: 
 351:     function drop_index($table_name, $index_name, $no_prefix = false)
 352:     {
 353:         if (!$this->index_exists($table_name, $index_name, $no_prefix))
 354:             return true;
 355: 
 356:         return $this->query('ALTER TABLE '.($no_prefix ? '' : $this->prefix).$table_name.' DROP INDEX '.($no_prefix ? '' : $this->prefix).$table_name.'_'.$index_name) ? true : false;
 357:     }
 358: 
 359:     function truncate_table($table_name, $no_prefix = false)
 360:     {
 361:         return $this->query('TRUNCATE TABLE '.($no_prefix ? '' : $this->prefix).$table_name) ? true : false;
 362:     }
 363: }


/dev/null b/include/dblayer/mysqli_innodb.php
   1: <?php
   2: 
   3: /**
   4:  * Copyright (C) 2008-2010 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:  */
   8: 
   9: // Make sure we have built in support for MySQL
  10: if (!function_exists('mysqli_connect'))
  11:     exit('This PHP environment doesn\'t have Improved MySQL (mysqli) support built in. Improved MySQL support is required if you want to use a MySQL 4.1 (or later) database to run this forum. Consult the PHP documentation for further assistance.');
  12: 
  13: 
  14: class DBLayer
  15: {
  16:     var $prefix;
  17:     var $link_id;
  18:     var $query_result;
  19: 
  20:     var $saved_queries = array();
  21:     var $num_queries = 0;
  22:     var $in_transaction = 0;
  23: 
  24:     var $datatype_transformations = array(
  25:         '/^SERIAL$/'    =>    'INT(10) UNSIGNED AUTO_INCREMENT'
  26:     );
  27: 
  28: 
  29:     function DBLayer($db_host, $db_username, $db_password, $db_name, $db_prefix, $p_connect)
  30:     {
  31:         $this->prefix = $db_prefix;
  32: 
  33:         // Was a custom port supplied with $db_host?
  34:         if (strpos($db_host, ':') !== false)
  35:             list($db_host, $db_port) = explode(':', $db_host);
  36: 
  37:         // Persistent connection in MySQLi are only available in PHP 5.3 and later releases
  38:         $p_connect = $p_connect && version_compare(PHP_VERSION, '5.3.0', '>=') ? 'p:' : '';
  39: 
  40:         if (isset($db_port))
  41:             $this->link_id = @mysqli_connect($p_connect.$db_host, $db_username, $db_password, $db_name, $db_port);
  42:         else
  43:             $this->link_id = @mysqli_connect($p_connect.$db_host, $db_username, $db_password, $db_name);
  44: 
  45:         if (!$this->link_id)
  46:             error('Unable to connect to MySQL and select database. MySQL reported: '.mysqli_connect_error(), __FILE__, __LINE__);
  47: 
  48:         // Setup the client-server character set (UTF-8)
  49:         if (!defined('FORUM_NO_SET_NAMES'))
  50:             $this->set_names('utf8');
  51: 
  52:         return $this->link_id;
  53:     }
  54: 
  55: 
  56:     function start_transaction()
  57:     {
  58:         ++$this->in_transaction;
  59: 
  60:         mysqli_query($this->link_id, 'START TRANSACTION');
  61:         return;
  62:     }
  63: 
  64: 
  65:     function end_transaction()
  66:     {
  67:         --$this->in_transaction;
  68: 
  69:         mysqli_query($this->link_id, 'COMMIT');
  70:         return;
  71:     }
  72: 
  73: 
  74:     function query($sql, $unbuffered = false)
  75:     {
  76:         if (defined('PUN_SHOW_QUERIES'))
  77:             $q_start = get_microtime();
  78: 
  79:         $this->query_result = @mysqli_query($this->link_id, $sql);
  80: 
  81:         if ($this->query_result)
  82:         {
  83:             if (defined('PUN_SHOW_QUERIES'))
  84:                 $this->saved_queries[] = array($sql, sprintf('%.5f', get_microtime() - $q_start));
  85: 
  86:             ++$this->num_queries;
  87: 
  88:             return $this->query_result;
  89:         }
  90:         else
  91:         {
  92:             if (defined('PUN_SHOW_QUERIES'))
  93:                 $this->saved_queries[] = array($sql, 0);
  94: 
  95:             // Rollback transaction
  96:             if ($this->in_transaction)
  97:                 mysqli_query($this->link_id, 'ROLLBACK');
  98: 
  99:             --$this->in_transaction;
 100: 
 101:             return false;
 102:         }
 103:     }
 104: 
 105: 
 106:     function result($query_id = 0, $row = 0, $col = 0)
 107:     {
 108:         if ($query_id)
 109:         {
 110:             if ($row !== 0 && @mysqli_data_seek($query_id, $row) === false)
 111:                 return false;
 112: 
 113:             $cur_row = @mysqli_fetch_row($query_id);
 114:             if ($cur_row === false)
 115:                 return false;
 116: 
 117:             return $cur_row[$col];
 118:         }
 119:         else
 120:             return false;
 121:     }
 122: 
 123: 
 124:     function fetch_assoc($query_id = 0)
 125:     {
 126:         return ($query_id) ? @mysqli_fetch_assoc($query_id) : false;
 127:     }
 128: 
 129: 
 130:     function fetch_row($query_id = 0)
 131:     {
 132:         return ($query_id) ? @mysqli_fetch_row($query_id) : false;
 133:     }
 134: 
 135: 
 136:     function num_rows($query_id = 0)
 137:     {
 138:         return ($query_id) ? @mysqli_num_rows($query_id) : false;
 139:     }
 140: 
 141: 
 142:     function affected_rows()
 143:     {
 144:         return ($this->link_id) ? @mysqli_affected_rows($this->link_id) : false;
 145:     }
 146: 
 147: 
 148:     function insert_id()
 149:     {
 150:         return ($this->link_id) ? @mysqli_insert_id($this->link_id) : false;
 151:     }
 152: 
 153: 
 154:     function get_num_queries()
 155:     {
 156:         return $this->num_queries;
 157:     }
 158: 
 159: 
 160:     function get_saved_queries()
 161:     {
 162:         return $this->saved_queries;
 163:     }
 164: 
 165: 
 166:     function free_result($query_id = false)
 167:     {
 168:         return ($query_id) ? @mysqli_free_result($query_id) : false;
 169:     }
 170: 
 171: 
 172:     function escape($str)
 173:     {
 174:         return is_array($str) ? '' : mysqli_real_escape_string($this->link_id, $str);
 175:     }
 176: 
 177: 
 178:     function error()
 179:     {
 180:         $result['error_sql'] = @current(@end($this->saved_queries));
 181:         $result['error_no'] = @mysqli_errno($this->link_id);
 182:         $result['error_msg'] = @mysqli_error($this->link_id);
 183: 
 184:         return $result;
 185:     }
 186: 
 187: 
 188:     function close()
 189:     {
 190:         if ($this->link_id)
 191:         {
 192:             if ($this->query_result)
 193:                 @mysqli_free_result($this->query_result);
 194: 
 195:             return @mysqli_close($this->link_id);
 196:         }
 197:         else
 198:             return false;
 199:     }
 200: 
 201: 
 202:     function get_names()
 203:     {
 204:         $result = $this->query('SHOW VARIABLES LIKE \'character_set_connection\'');
 205:         return $this->result($result, 0, 1);
 206:     }
 207: 
 208: 
 209:     function set_names($names)
 210:     {
 211:         return $this->query('SET NAMES \''.$this->escape($names).'\'');
 212:     }
 213: 
 214: 
 215:     function get_version()
 216:     {
 217:         $result = $this->query('SELECT VERSION()');
 218: 
 219:         return array(
 220:             'name'        => 'MySQL Improved (InnoDB)',
 221:             'version'    => preg_replace('/^([^-]+).*$/', '\\1', $this->result($result))
 222:         );
 223:     }
 224: 
 225: 
 226:     function table_exists($table_name, $no_prefix = false)
 227:     {
 228:         $result = $this->query('SHOW TABLES LIKE \''.($no_prefix ? '' : $this->prefix).$this->escape($table_name).'\'');
 229:         return $this->num_rows($result) > 0;
 230:     }
 231: 
 232: 
 233:     function field_exists($table_name, $field_name, $no_prefix = false)
 234:     {
 235:         $result = $this->query('SHOW COLUMNS FROM '.($no_prefix ? '' : $this->prefix).$table_name.' LIKE \''.$this->escape($field_name).'\'');
 236:         return $this->num_rows($result) > 0;
 237:     }
 238: 
 239: 
 240:     function index_exists($table_name, $index_name, $no_prefix = false)
 241:     {
 242:         $exists = false;
 243: 
 244:         $result = $this->query('SHOW INDEX FROM '.($no_prefix ? '' : $this->prefix).$table_name);
 245:         while ($cur_index = $this->fetch_assoc($result))
 246:         {
 247:             if ($cur_index['Key_name'] == ($no_prefix ? '' : $this->prefix).$table_name.'_'.$index_name)
 248:             {
 249:                 $exists = true;
 250:                 break;
 251:             }
 252:         }
 253: 
 254:         return $exists;
 255:     }
 256: 
 257: 
 258:     function create_table($table_name, $schema, $no_prefix = false)
 259:     {
 260:         if ($this->table_exists($table_name, $no_prefix))
 261:             return true;
 262: 
 263:         $query = 'CREATE TABLE '.($no_prefix ? '' : $this->prefix).$table_name." (\n";
 264: 
 265:         // Go through every schema element and add it to the query
 266:         foreach ($schema['FIELDS'] as $field_name => $field_data)
 267:         {
 268:             $field_data['datatype'] = preg_replace(array_keys($this->datatype_transformations), array_values($this->datatype_transformations), $field_data['datatype']);
 269: 
 270:             $query .= $field_name.' '.$field_data['datatype'];
 271: 
 272:             if (isset($field_data['collation']))
 273:                 $query .= 'CHARACTER SET utf8 COLLATE utf8_'.$field_data['collation'];
 274: 
 275:             if (!$field_data['allow_null'])
 276:                 $query .= ' NOT NULL';
 277: 
 278:             if (isset($field_data['default']))
 279:                 $query .= ' DEFAULT '.$field_data['default'];
 280: 
 281:             $query .= ",\n";
 282:         }
 283: 
 284:         // If we have a primary key, add it
 285:         if (isset($schema['PRIMARY KEY']))
 286:             $query .= 'PRIMARY KEY ('.implode(',', $schema['PRIMARY KEY']).'),'."\n";
 287: 
 288:         // Add unique keys
 289:         if (isset($schema['UNIQUE KEYS']))
 290:         {
 291:             foreach ($schema['UNIQUE KEYS'] as $key_name => $key_fields)
 292:                 $query .= 'UNIQUE KEY '.($no_prefix ? '' : $this->prefix).$table_name.'_'.$key_name.'('.implode(',', $key_fields).'),'."\n";
 293:         }
 294: 
 295:         // Add indexes
 296:         if (isset($schema['INDEXES']))
 297:         {
 298:             foreach ($schema['INDEXES'] as $index_name => $index_fields)
 299:                 $query .= 'KEY '.($no_prefix ? '' : $this->prefix).$table_name.'_'.$index_name.'('.implode(',', $index_fields).'),'."\n";
 300:         }
 301: 
 302:         // We remove the last two characters (a newline and a comma) and add on the ending
 303:         $query = substr($query, 0, strlen($query) - 2)."\n".') ENGINE = '.(isset($schema['ENGINE']) ? $schema['ENGINE'] : 'InnoDB').' CHARACTER SET utf8';
 304: 
 305:         return $this->query($query) ? true : false;
 306:     }
 307: 
 308: 
 309:     function drop_table($table_name, $no_prefix = false)
 310:     {
 311:         if (!$this->table_exists($table_name, $no_prefix))
 312:             return true;
 313: 
 314:         return $this->query('DROP TABLE '.($no_prefix ? '' : $this->prefix).$table_name) ? true : false;
 315:     }
 316: 
 317: 
 318:     function add_field($table_name, $field_name, $field_type, $allow_null, $default_value = null, $after_field = null, $no_prefix = false)
 319:     {
 320:         if ($this->field_exists($table_name, $field_name, $no_prefix))
 321:             return true;
 322: 
 323:         $field_type = preg_replace(array_keys($this->datatype_transformations), array_values($this->datatype_transformations), $field_type);
 324: 
 325:         if ($default_value !== null && !is_int($default_value) && !is_float($default_value))
 326:             $default_value = '\''.$this->escape($default_value).'\'';
 327: 
 328:         return $this->query('ALTER TABLE '.($no_prefix ? '' : $this->prefix).$table_name.' ADD '.$field_name.' '.$field_type.($allow_null ? ' ' : ' NOT NULL').($default_value !== null ? ' DEFAULT '.$default_value : ' ').($after_field != null ? ' AFTER '.$after_field : '')) ? true : false;
 329:     }
 330: 
 331: 
 332:     function alter_field($table_name, $field_name, $field_type, $allow_null, $default_value = null, $after_field = null, $no_prefix = false)
 333:     {
 334:         if (!$this->field_exists($table_name, $field_name, $no_prefix))
 335:             return true;
 336: 
 337:         $field_type = preg_replace(array_keys($this->datatype_transformations), array_values($this->datatype_transformations), $field_type);
 338: 
 339:         if ($default_value !== null && !is_int($default_value) && !is_float($default_value))
 340:             $default_value = '\''.$this->escape($default_value).'\'';
 341: 
 342:         return $this->query('ALTER TABLE '.($no_prefix ? '' : $this->prefix).$table_name.' MODIFY '.$field_name.' '.$field_type.($allow_null ? ' ' : ' NOT NULL').($default_value !== null ? ' DEFAULT '.$default_value : ' ').($after_field != null ? ' AFTER '.$after_field : '')) ? true : false;
 343:     }
 344: 
 345: 
 346:     function drop_field($table_name, $field_name, $no_prefix = false)
 347:     {
 348:         if (!$this->field_exists($table_name, $field_name, $no_prefix))
 349:             return true;
 350: 
 351:         return $this->query('ALTER TABLE '.($no_prefix ? '' : $this->prefix).$table_name.' DROP '.$field_name) ? true : false;
 352:     }
 353: 
 354: 
 355:     function add_index($table_name, $index_name, $index_fields, $unique = false, $no_prefix = false)
 356:     {
 357:         if ($this->index_exists($table_name, $index_name, $no_prefix))
 358:             return true;
 359: 
 360:         return $this->query('ALTER TABLE '.($no_prefix ? '' : $this->prefix).$table_name.' ADD '.($unique ? 'UNIQUE ' : '').'INDEX '.($no_prefix ? '' : $this->prefix).$table_name.'_'.$index_name.' ('.implode(',', $index_fields).')') ? true : false;
 361:     }
 362: 
 363: 
 364:     function drop_index($table_name, $index_name, $no_prefix = false)
 365:     {
 366:         if (!$this->index_exists($table_name, $index_name, $no_prefix))
 367:             return true;
 368: 
 369:         return $this->query('ALTER TABLE '.($no_prefix ? '' : $this->prefix).$table_name.' DROP INDEX '.($no_prefix ? '' : $this->prefix).$table_name.'_'.$index_name) ? true : false;
 370:     }
 371: 
 372:     function truncate_table($table_name, $no_prefix = false)
 373:     {
 374:         return $this->query('TRUNCATE TABLE '.($no_prefix ? '' : $this->prefix).$table_name) ? true : false;
 375:     }
 376: }


/dev/null b/include/dblayer/pgsql.php
   1: <?php
   2: 
   3: /**
   4:  * Copyright (C) 2008-2010 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:  */
   8: 
   9: // Make sure we have built in support for PostgreSQL
  10: if (!function_exists('pg_connect'))
  11:     exit('This PHP environment doesn\'t have PostgreSQL support built in. PostgreSQL support is required if you want to use a PostgreSQL database to run this forum. Consult the PHP documentation for further assistance.');
  12: 
  13: 
  14: class DBLayer
  15: {
  16:     var $prefix;
  17:     var $link_id;
  18:     var $query_result;
  19:     var $last_query_text = array();
  20:     var $in_transaction = 0;
  21: 
  22:     var $saved_queries = array();
  23:     var $num_queries = 0;
  24: 
  25:     var $error_no = false;
  26:     var $error_msg = 'Unknown';
  27: 
  28:     var $datatype_transformations = array(
  29:         '/^(TINY|SMALL)INT( )?(\\([0-9]+\\))?( )?(UNSIGNED)?$/i'            =>    'SMALLINT',
  30:         '/^(MEDIUM)?INT( )?(\\([0-9]+\\))?( )?(UNSIGNED)?$/i'                =>    'INTEGER',
  31:         '/^BIGINT( )?(\\([0-9]+\\))?( )?(UNSIGNED)?$/i'                        =>    'BIGINT',
  32:         '/^(TINY|MEDIUM|LONG)?TEXT$/i'                                        =>    'TEXT',
  33:         '/^DOUBLE( )?(\\([0-9,]+\\))?( )?(UNSIGNED)?$/i'                    =>    'DOUBLE PRECISION',
  34:         '/^FLOAT( )?(\\([0-9]+\\))?( )?(UNSIGNED)?$/i'                        =>    'REAL'
  35:     );
  36: 
  37: 
  38:     function DBLayer($db_host, $db_username, $db_password, $db_name, $db_prefix, $p_connect)
  39:     {
  40:         $this->prefix = $db_prefix;
  41: 
  42:         if ($db_host)
  43:         {
  44:             if (strpos($db_host, ':') !== false)
  45:             {
  46:                 list($db_host, $dbport) = explode(':', $db_host);
  47:                 $connect_str[] = 'host='.$db_host.' port='.$dbport;
  48:             }
  49:             else
  50:                 $connect_str[] = 'host='.$db_host;
  51:         }
  52: 
  53:         if ($db_name)
  54:             $connect_str[] = 'dbname='.$db_name;
  55: 
  56:         if ($db_username)
  57:             $connect_str[] = 'user='.$db_username;
  58: 
  59:         if ($db_password)
  60:             $connect_str[] = 'password='.$db_password;
  61: 
  62:         if ($p_connect)
  63:             $this->link_id = @pg_pconnect(implode(' ', $connect_str));
  64:         else
  65:             $this->link_id = @pg_connect(implode(' ', $connect_str));
  66: 
  67:         if (!$this->link_id)
  68:             error('Unable to connect to PostgreSQL server', __FILE__, __LINE__);
  69: 
  70:         // Setup the client-server character set (UTF-8)
  71:         if (!defined('FORUM_NO_SET_NAMES'))
  72:             $this->set_names('utf8');
  73: 
  74:         return $this->link_id;
  75:     }
  76: 
  77: 
  78:     function start_transaction()
  79:     {
  80:         ++$this->in_transaction;
  81: 
  82:         return (@pg_query($this->link_id, 'BEGIN')) ? true : false;
  83:     }
  84: 
  85: 
  86:     function end_transaction()
  87:     {
  88:         --$this->in_transaction;
  89: 
  90:         if (@pg_query($this->link_id, 'COMMIT'))
  91:             return true;
  92:         else
  93:         {
  94:             @pg_query($this->link_id, 'ROLLBACK');
  95:             return false;
  96:         }
  97:     }
  98: 
  99: 
 100:     function query($sql, $unbuffered = false) // $unbuffered is ignored since there is no pgsql_unbuffered_query()
 101:     {
 102:         if (strrpos($sql, 'LIMIT') !== false)
 103:             $sql = preg_replace('#LIMIT ([0-9]+),([ 0-9]+)#', 'LIMIT \\2 OFFSET \\1', $sql);
 104: 
 105:         if (defined('PUN_SHOW_QUERIES'))
 106:             $q_start = get_microtime();
 107: 
 108:         @pg_send_query($this->link_id, $sql);
 109:         $this->query_result = @pg_get_result($this->link_id);
 110: 
 111:         if (pg_result_status($this->query_result) != PGSQL_FATAL_ERROR)
 112:         {
 113:             if (defined('PUN_SHOW_QUERIES'))
 114:                 $this->saved_queries[] = array($sql, sprintf('%.5f', get_microtime() - $q_start));
 115: 
 116:             ++$this->num_queries;
 117: 
 118:             $this->last_query_text[$this->query_result] = $sql;
 119: 
 120:             return $this->query_result;
 121:         }
 122:         else
 123:         {
 124:             if (defined('PUN_SHOW_QUERIES'))
 125:                 $this->saved_queries[] = array($sql, 0);
 126: 
 127:             $this->error_msg = @pg_result_error($this->query_result);
 128: 
 129:             if ($this->in_transaction)
 130:                 @pg_query($this->link_id, 'ROLLBACK');
 131: 
 132:             --$this->in_transaction;
 133: 
 134:             return false;
 135:         }
 136:     }
 137: 
 138: 
 139:     function result($query_id = 0, $row = 0, $col = 0)
 140:     {
 141:         return ($query_id) ? @pg_fetch_result($query_id, $row, $col) : false;
 142:     }
 143: 
 144: 
 145:     function fetch_assoc($query_id = 0)
 146:     {
 147:         return ($query_id) ? @pg_fetch_assoc($query_id) : false;
 148:     }
 149: 
 150: 
 151:     function fetch_row($query_id = 0)
 152:     {
 153:         return ($query_id) ? @pg_fetch_row($query_id) : false;
 154:     }
 155: 
 156: 
 157:     function num_rows($query_id = 0)
 158:     {
 159:         return ($query_id) ? @pg_num_rows($query_id) : false;
 160:     }
 161: 
 162: 
 163:     function affected_rows()
 164:     {
 165:         return ($this->query_result) ? @pg_affected_rows($this->query_result) : false;
 166:     }
 167: 
 168: 
 169:     function insert_id()
 170:     {
 171:         $query_id = $this->query_result;
 172: 
 173:         if ($query_id && $this->last_query_text[$query_id] != '')
 174:         {
 175:             if (preg_match('/^INSERT INTO ([a-z0-9\_\-]+)/is', $this->last_query_text[$query_id], $table_name))
 176:             {
 177:                 // Hack (don't ask)
 178:                 if (substr($table_name[1], -6) == 'groups')
 179:                     $table_name[1] .= '_g';
 180: 
 181:                 $temp_q_id = @pg_query($this->link_id, 'SELECT currval(\''.$table_name[1].'_id_seq\')');
 182:                 return ($temp_q_id) ? intval(@pg_fetch_result($temp_q_id, 0)) : false;
 183:             }
 184:         }
 185: 
 186:         return false;
 187:     }
 188: 
 189: 
 190:     function get_num_queries()
 191:     {
 192:         return $this->num_queries;
 193:     }
 194: 
 195: 
 196:     function get_saved_queries()
 197:     {
 198:         return $this->saved_queries;
 199:     }
 200: 
 201: 
 202:     function free_result($query_id = false)
 203:     {
 204:         if (!$query_id)
 205:             $query_id = $this->query_result;
 206: 
 207:         return ($query_id) ? @pg_free_result($query_id) : false;
 208:     }
 209: 
 210: 
 211:     function escape($str)
 212:     {
 213:         return is_array($str) ? '' : pg_escape_string($str);
 214:     }
 215: 
 216: 
 217:     function error()
 218:     {
 219:         $result['error_sql'] = @current(@end($this->saved_queries));
 220:         $result['error_no'] = false;
 221: /*
 222:         if (!empty($this->query_result))
 223:         {
 224:             $result['error_msg'] = trim(@pg_result_error($this->query_result));
 225:             if ($result['error_msg'] != '')
 226:                 return $result;
 227:         }
 228: 
 229:         $result['error_msg'] = (!empty($this->link_id)) ? trim(@pg_last_error($this->link_id)) : trim(@pg_last_error());
 230: */
 231:         $result['error_msg'] = $this->error_msg;
 232: 
 233:         return $result;
 234:     }
 235: 
 236: 
 237:     function close()
 238:     {
 239:         if ($this->link_id)
 240:         {
 241:             if ($this->in_transaction)
 242:             {
 243:                 if (defined('PUN_SHOW_QUERIES'))
 244:                     $this->saved_queries[] = array('COMMIT', 0);
 245: 
 246:                 @pg_query($this->link_id, 'COMMIT');
 247:             }
 248: 
 249:             if ($this->query_result)
 250:                 @pg_free_result($this->query_result);
 251: 
 252:             return @pg_close($this->link_id);
 253:         }
 254:         else
 255:             return false;
 256:     }
 257: 
 258: 
 259:     function get_names()
 260:     {
 261:         $result = $this->query('SHOW client_encoding');
 262:         return strtolower($this->result($result)); // MySQL returns lowercase so lets be consistent
 263:     }
 264: 
 265: 
 266:     function set_names($names)
 267:     {
 268:         return $this->query('SET NAMES \''.$this->escape($names).'\'');
 269:     }
 270: 
 271: 
 272:     function get_version()
 273:     {
 274:         $result = $this->query('SELECT VERSION()');
 275: 
 276:         return array(
 277:             'name'        => 'PostgreSQL',
 278:             'version'    => preg_replace('/^[^0-9]+([^\s,-]+).*$/', '\\1', $this->result($result))
 279:         );
 280:     }
 281: 
 282: 
 283:     function table_exists($table_name, $no_prefix = false)
 284:     {
 285:         $result = $this->query('SELECT 1 FROM pg_class WHERE relname = \''.($no_prefix ? '' : $this->prefix).$this->escape($table_name).'\'');
 286:         return $this->num_rows($result) > 0;
 287:     }
 288: 
 289: 
 290:     function field_exists($table_name, $field_name, $no_prefix = false)
 291:     {
 292:         $result = $this->query('SELECT 1 FROM pg_class c INNER JOIN pg_attribute a ON a.attrelid = c.oid WHERE c.relname = \''.($no_prefix ? '' : $this->prefix).$this->escape($table_name).'\' AND a.attname = \''.$this->escape($field_name).'\'');
 293:         return $this->num_rows($result) > 0;
 294:     }
 295: 
 296: 
 297:     function index_exists($table_name, $index_name, $no_prefix = false)
 298:     {
 299:         $result = $this->query('SELECT 1 FROM pg_index i INNER JOIN pg_class c1 ON c1.oid = i.indrelid INNER JOIN pg_class c2 ON c2.oid = i.indexrelid WHERE c1.relname = \''.($no_prefix ? '' : $this->prefix).$this->escape($table_name).'\' AND c2.relname = \''.($no_prefix ? '' : $this->prefix).$this->escape($table_name).'_'.$this->escape($index_name).'\'');
 300:         return $this->num_rows($result) > 0;
 301:     }
 302: 
 303: 
 304:     function create_table($table_name, $schema, $no_prefix = false)
 305:     {
 306:         if ($this->table_exists($table_name, $no_prefix))
 307:             return true;
 308: 
 309:         $query = 'CREATE TABLE '.($no_prefix ? '' : $this->prefix).$table_name." (\n";
 310: 
 311:         // Go through every schema element and add it to the query
 312:         foreach ($schema['FIELDS'] as $field_name => $field_data)
 313:         {
 314:             $field_data['datatype'] = preg_replace(array_keys($this->datatype_transformations), array_values($this->datatype_transformations), $field_data['datatype']);
 315: 
 316:             $query .= $field_name.' '.$field_data['datatype'];
 317: 
 318:             // The SERIAL datatype is a special case where we don't need to say not null
 319:             if (!$field_data['allow_null'] && $field_data['datatype'] != 'SERIAL')
 320:                 $query .= ' NOT NULL';
 321: 
 322:             if (isset($field_data['default']))
 323:                 $query .= ' DEFAULT '.$field_data['default'];
 324: 
 325:             $query .= ",\n";
 326:         }
 327: 
 328:         // If we have a primary key, add it
 329:         if (isset($schema['PRIMARY KEY']))
 330:             $query .= 'PRIMARY KEY ('.implode(',', $schema['PRIMARY KEY']).'),'."\n";
 331: 
 332:         // Add unique keys
 333:         if (isset($schema['UNIQUE KEYS']))
 334:         {
 335:             foreach ($schema['UNIQUE KEYS'] as $key_name => $key_fields)
 336:                 $query .= 'UNIQUE ('.implode(',', $key_fields).'),'."\n";
 337:         }
 338: 
 339:         // We remove the last two characters (a newline and a comma) and add on the ending
 340:         $query = substr($query, 0, strlen($query) - 2)."\n".')';
 341: 
 342:         $result = $this->query($query) ? true : false;
 343: 
 344:         // Add indexes
 345:         if (isset($schema['INDEXES']))
 346:         {
 347:             foreach ($schema['INDEXES'] as $index_name => $index_fields)
 348:                 $result &= $this->add_index($table_name, $index_name, $index_fields, false, $no_prefix);
 349:         }
 350: 
 351:         return $result;
 352:     }
 353: 
 354: 
 355:     function drop_table($table_name, $no_prefix = false)
 356:     {
 357:         if (!$this->table_exists($table_name, $no_prefix))
 358:             return true;
 359: 
 360:         return $this->query('DROP TABLE '.($no_prefix ? '' : $this->prefix).$table_name) ? true : false;
 361:     }
 362: 
 363: 
 364:     function add_field($table_name, $field_name, $field_type, $allow_null, $default_value = null, $after_field = null, $no_prefix = false)
 365:     {
 366:         if ($this->field_exists($table_name, $field_name, $no_prefix))
 367:             return true;
 368: 
 369:         $field_type = preg_replace(array_keys($this->datatype_transformations), array_values($this->datatype_transformations), $field_type);
 370: 
 371:         $result = $this->query('ALTER TABLE '.($no_prefix ? '' : $this->prefix).$table_name.' ADD '.$field_name.' '.$field_type) ? true : false;
 372: 
 373:         if ($default_value !== null)
 374:         {
 375:             if (!is_int($default_value) && !is_float($default_value))
 376:                 $default_value = '\''.$this->escape($default_value).'\'';
 377: 
 378:             $result &= $this->query('ALTER TABLE '.($no_prefix ? '' : $this->prefix).$table_name.' ALTER '.$field_name.' SET DEFAULT '.$default_value) ? true : false;
 379:             $result &= $this->query('UPDATE '.($no_prefix ? '' : $this->prefix).$table_name.' SET '.$field_name.'='.$default_value) ? true : false;
 380:         }
 381: 
 382:         if (!$allow_null)
 383:             $result &= $this->query('ALTER TABLE '.($no_prefix ? '' : $this->prefix).$table_name.' ALTER '.$field_name.' SET NOT NULL') ? true : false;
 384: 
 385:         return $result;
 386:     }
 387: 
 388: 
 389:     function alter_field($table_name, $field_name, $field_type, $allow_null, $default_value = null, $after_field = null, $no_prefix = false)
 390:     {
 391:         if (!$this->field_exists($table_name, $field_name, $no_prefix))
 392:             return true;
 393: 
 394:         $field_type = preg_replace(array_keys($this->datatype_transformations), array_values($this->datatype_transformations), $field_type);
 395: 
 396:         $result = $this->add_field($table_name, 'tmp_'.$field_name, $field_type, $allow_null, $default_value, $after_field, $no_prefix);
 397:         $result &= $this->query('UPDATE '.($no_prefix ? '' : $this->prefix).$table_name.' SET tmp_'.$field_name.' = '.$field_name) ? true : false;
 398:         $result &= $this->drop_field($table_name, $field_name, $no_prefix);
 399:         $result &= $this->query('ALTER TABLE '.($no_prefix ? '' : $this->prefix).$table_name.' RENAME COLUMN tmp_'.$field_name.' TO '.$field_name) ? true : false;
 400: 
 401:         return $result;
 402:     }
 403: 
 404: 
 405:     function drop_field($table_name, $field_name, $no_prefix = false)
 406:     {
 407:         if (!$this->field_exists($table_name, $field_name, $no_prefix))
 408:             return true;
 409: 
 410:         return $this->query('ALTER TABLE '.($no_prefix ? '' : $this->prefix).$table_name.' DROP '.$field_name) ? true : false;
 411:     }
 412: 
 413: 
 414:     function add_index($table_name, $index_name, $index_fields, $unique = false, $no_prefix = false)
 415:     {
 416:         if ($this->index_exists($table_name, $index_name, $no_prefix))
 417:             return true;
 418: 
 419:         return $this->query('CREATE '.($unique ? 'UNIQUE ' : '').'INDEX '.($no_prefix ? '' : $this->prefix).$table_name.'_'.$index_name.' ON '.($no_prefix ? '' : $this->prefix).$table_name.'('.implode(',', $index_fields).')') ? true : false;
 420:     }
 421: 
 422: 
 423:     function drop_index($table_name, $index_name, $no_prefix = false)
 424:     {
 425:         if (!$this->index_exists($table_name, $index_name, $no_prefix))
 426:             return true;
 427: 
 428:         return $this->query('DROP INDEX '.($no_prefix ? '' : $this->prefix).$table_name.'_'.$index_name) ? true : false;
 429:     }
 430: 
 431:     function truncate_table($table_name, $no_prefix = false)
 432:     {
 433:         return $this->query('DELETE FROM '.($no_prefix ? '' : $this->prefix).$table_name) ? true : false;
 434:     }
 435: }


/dev/null b/include/dblayer/sqlite.php
   1: <?php
   2: 
   3: /**
   4:  * Copyright (C) 2008-2010 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:  */
   8: 
   9: // Make sure we have built in support for SQLite
  10: if (!function_exists('sqlite_open'))
  11:     exit('This PHP environment doesn\'t have SQLite support built in. SQLite support is required if you want to use a SQLite database to run this forum. Consult the PHP documentation for further assistance.');
  12: 
  13: 
  14: class DBLayer
  15: {
  16:     var $prefix;
  17:     var $link_id;
  18:     var $query_result;
  19:     var $in_transaction = 0;
  20: 
  21:     var $saved_queries = array();
  22:     var $num_queries = 0;
  23: 
  24:     var $error_no = false;
  25:     var $error_msg = 'Unknown';
  26: 
  27:     var $datatype_transformations = array(
  28:         '/^SERIAL$/'                                                            =>    'INTEGER',
  29:         '/^(TINY|SMALL|MEDIUM|BIG)?INT( )?(\\([0-9]+\\))?( )?(UNSIGNED)?$/i'    =>    'INTEGER',
  30:         '/^(TINY|MEDIUM|LONG)?TEXT$/i'                                            =>    'TEXT'
  31:     );
  32: 
  33: 
  34:     function DBLayer($db_host, $db_username, $db_password, $db_name, $db_prefix, $p_connect)
  35:     {
  36:         // Prepend $db_name with the path to the forum root directory
  37:         $db_name = PUN_ROOT.$db_name;
  38: 
  39:         $this->prefix = $db_prefix;
  40: 
  41:         if (!file_exists($db_name))
  42:         {
  43:             @touch($db_name);
  44:             @chmod($db_name, 0666);
  45:             if (!file_exists($db_name))
  46:                 error('Unable to create new database \''.$db_name.'\'. Permission denied', __FILE__, __LINE__);
  47:         }
  48: 
  49:         if (!is_readable($db_name))
  50:             error('Unable to open database \''.$db_name.'\' for reading. Permission denied', __FILE__, __LINE__);
  51: 
  52:         if (!is_writable($db_name))
  53:             error('Unable to open database \''.$db_name.'\' for writing. Permission denied', __FILE__, __LINE__);
  54: 
  55:         if ($p_connect)
  56:             $this->link_id = @sqlite_popen($db_name, 0666, $sqlite_error);
  57:         else
  58:             $this->link_id = @sqlite_open($db_name, 0666, $sqlite_error);
  59: 
  60:         if (!$this->link_id)
  61:             error('Unable to open database \''.$db_name.'\'. SQLite reported: '.$sqlite_error, __FILE__, __LINE__);
  62:         else
  63:             return $this->link_id;
  64:     }
  65: 
  66: 
  67:     function start_transaction()
  68:     {
  69:         ++$this->in_transaction;
  70: 
  71:         return (@sqlite_query($this->link_id, 'BEGIN')) ? true : false;
  72:     }
  73: 
  74: 
  75:     function end_transaction()
  76:     {
  77:         --$this->in_transaction;
  78: 
  79:         if (@sqlite_query($this->link_id, 'COMMIT'))
  80:             return true;
  81:         else
  82:         {
  83:             @sqlite_query($this->link_id, 'ROLLBACK');
  84:             return false;
  85:         }
  86:     }
  87: 
  88: 
  89:     function query($sql, $unbuffered = false)
  90:     {
  91:         if (defined('PUN_SHOW_QUERIES'))
  92:             $q_start = get_microtime();
  93: 
  94:         if ($unbuffered)
  95:             $this->query_result = @sqlite_unbuffered_query($this->link_id, $sql);
  96:         else
  97:             $this->query_result = @sqlite_query($this->link_id, $sql);
  98: 
  99:         if ($this->query_result)
 100:         {
 101:             if (defined('PUN_SHOW_QUERIES'))
 102:                 $this->saved_queries[] = array($sql, sprintf('%.5f', get_microtime() - $q_start));
 103: 
 104:             ++$this->num_queries;
 105: 
 106:             return $this->query_result;
 107:         }
 108:         else
 109:         {
 110:             if (defined('PUN_SHOW_QUERIES'))
 111:                 $this->saved_queries[] = array($sql, 0);
 112: 
 113:             $this->error_no = @sqlite_last_error($this->link_id);
 114:             $this->error_msg = @sqlite_error_string($this->error_no);
 115: 
 116:             if ($this->in_transaction)
 117:                 @sqlite_query($this->link_id, 'ROLLBACK');
 118: 
 119:             --$this->in_transaction;
 120: 
 121:             return false;
 122:         }
 123:     }
 124: 
 125: 
 126:     function result($query_id = 0, $row = 0, $col = 0)
 127:     {
 128:         if ($query_id)
 129:         {
 130:             if ($row !== 0 && @sqlite_seek($query_id, $row) === false)
 131:                 return false;
 132: 
 133:             $cur_row = @sqlite_current($query_id);
 134:             if ($cur_row === false)
 135:                 return false;
 136: 
 137:             return $cur_row[$col];
 138:         }
 139:         else
 140:             return false;
 141:     }
 142: 
 143: 
 144:     function fetch_assoc($query_id = 0)
 145:     {
 146:         if ($query_id)
 147:         {
 148:             $cur_row = @sqlite_fetch_array($query_id, SQLITE_ASSOC);
 149:             if ($cur_row)
 150:             {
 151:                 // Horrible hack to get rid of table names and table aliases from the array keys
 152:                 foreach ($cur_row as $key => $value)
 153:                 {
 154:                     $dot_spot = strpos($key, '.');
 155:                     if ($dot_spot !== false)
 156:                     {
 157:                         unset($cur_row[$key]);
 158:                         $key = substr($key, $dot_spot+1);
 159:                         $cur_row[$key] = $value;
 160:                     }
 161:                 }
 162:             }
 163: 
 164:             return $cur_row;
 165:         }
 166:         else
 167:             return false;
 168:     }
 169: 
 170: 
 171:     function fetch_row($query_id = 0)
 172:     {
 173:         return ($query_id) ? @sqlite_fetch_array($query_id, SQLITE_NUM) : false;
 174:     }
 175: 
 176: 
 177:     function num_rows($query_id = 0)
 178:     {
 179:         return ($query_id) ? @sqlite_num_rows($query_id) : false;
 180:     }
 181: 
 182: 
 183:     function affected_rows()
 184:     {
 185:         return ($this->query_result) ? @sqlite_changes($this->query_result) : false;
 186:     }
 187: 
 188: 
 189:     function insert_id()
 190:     {
 191:         return ($this->link_id) ? @sqlite_last_insert_rowid($this->link_id) : false;
 192:     }
 193: 
 194: 
 195:     function get_num_queries()
 196:     {
 197:         return $this->num_queries;
 198:     }
 199: 
 200: 
 201:     function get_saved_queries()
 202:     {
 203:         return $this->saved_queries;
 204:     }
 205: 
 206: 
 207:     function free_result($query_id = false)
 208:     {
 209:         return true;
 210:     }
 211: 
 212: 
 213:     function escape($str)
 214:     {
 215:         return is_array($str) ? '' : sqlite_escape_string($str);
 216:     }
 217: 
 218: 
 219:     function error()
 220:     {
 221:         $result['error_sql'] = @current(@end($this->saved_queries));
 222:         $result['error_no'] = $this->error_no;
 223:         $result['error_msg'] = $this->error_msg;
 224: 
 225:         return $result;
 226:     }
 227: 
 228: 
 229:     function close()
 230:     {
 231:         if ($this->link_id)
 232:         {
 233:             if ($this->in_transaction)
 234:             {
 235:                 if (defined('PUN_SHOW_QUERIES'))
 236:                     $this->saved_queries[] = array('COMMIT', 0);
 237: 
 238:                 @sqlite_query($this->link_id, 'COMMIT');
 239:             }
 240: 
 241:             return @sqlite_close($this->link_id);
 242:         }
 243:         else
 244:             return false;
 245:     }
 246: 
 247: 
 248:     function get_names()
 249:     {
 250:         return '';
 251:     }
 252: 
 253: 
 254:     function set_names($names)
 255:     {
 256:         return true;
 257:     }
 258: 
 259: 
 260:     function get_version()
 261:     {
 262:         return array(
 263:             'name'        => 'SQLite',
 264:             'version'    => sqlite_libversion()
 265:         );
 266:     }
 267: 
 268: 
 269:     function table_exists($table_name, $no_prefix = false)
 270:     {
 271:         $result = $this->query('SELECT 1 FROM sqlite_master WHERE name = \''.($no_prefix ? '' : $this->prefix).$this->escape($table_name).'\' AND type=\'table\'');
 272:         return $this->num_rows($result) > 0;
 273:     }
 274: 
 275: 
 276:     function field_exists($table_name, $field_name, $no_prefix = false)
 277:     {
 278:         $result = $this->query('SELECT sql FROM sqlite_master WHERE name = \''.($no_prefix ? '' : $this->prefix).$this->escape($table_name).'\' AND type=\'table\'');
 279:         if (!$this->num_rows($result))
 280:             return false;
 281: 
 282:         return preg_match('/[\r\n]'.preg_quote($field_name).' /', $this->result($result));
 283:     }
 284: 
 285: 
 286:     function index_exists($table_name, $index_name, $no_prefix = false)
 287:     {
 288:         $result = $this->query('SELECT 1 FROM sqlite_master WHERE tbl_name = \''.($no_prefix ? '' : $this->prefix).$this->escape($table_name).'\' AND name = \''.($no_prefix ? '' : $this->prefix).$this->escape($table_name).'_'.$this->escape($index_name).'\' AND type=\'index\'');
 289:         return $this->num_rows($result) > 0;
 290:     }
 291: 
 292: 
 293:     function create_table($table_name, $schema, $no_prefix = false)
 294:     {
 295:         if ($this->table_exists($table_name, $no_prefix))
 296:             return true;
 297: 
 298:         $query = 'CREATE TABLE '.($no_prefix ? '' : $this->prefix).$table_name." (\n";
 299: 
 300:         // Go through every schema element and add it to the query
 301:         foreach ($schema['FIELDS'] as $field_name => $field_data)
 302:         {
 303:             $field_data['datatype'] = preg_replace(array_keys($this->datatype_transformations), array_values($this->datatype_transformations), $field_data['datatype']);
 304: 
 305:             $query .= $field_name.' '.$field_data['datatype'];
 306: 
 307:             if (!$field_data['allow_null'])
 308:                 $query .= ' NOT NULL';
 309: 
 310:             if (isset($field_data['default']))
 311:                 $query .= ' DEFAULT '.$field_data['default'];
 312: 
 313:             $query .= ",\n";
 314:         }
 315: 
 316:         // If we have a primary key, add it
 317:         if (isset($schema['PRIMARY KEY']))
 318:             $query .= 'PRIMARY KEY ('.implode(',', $schema['PRIMARY KEY']).'),'."\n";
 319: 
 320:         // Add unique keys
 321:         if (isset($schema['UNIQUE KEYS']))
 322:         {
 323:             foreach ($schema['UNIQUE KEYS'] as $key_name => $key_fields)
 324:                 $query .= 'UNIQUE ('.implode(',', $key_fields).'),'."\n";
 325:         }
 326: 
 327:         // We remove the last two characters (a newline and a comma) and add on the ending
 328:         $query = substr($query, 0, strlen($query) - 2)."\n".')';
 329: 
 330:         $result = $this->query($query) ? true : false;
 331: 
 332:         // Add indexes
 333:         if (isset($schema['INDEXES']))
 334:         {
 335:             foreach ($schema['INDEXES'] as $index_name => $index_fields)
 336:                 $result &= $this->add_index($table_name, $index_name, $index_fields, false, $no_prefix);
 337:         }
 338: 
 339:         return $result;
 340:     }
 341: 
 342: 
 343:     function drop_table($table_name, $no_prefix = false)
 344:     {
 345:         if (!$this->table_exists($table_name, $no_prefix))
 346:             return true;
 347: 
 348:         return $this->query('DROP TABLE '.($no_prefix ? '' : $this->prefix).$table_name) ? true : false;
 349:     }
 350: 
 351: 
 352:     function get_table_info($table_name, $no_prefix = false)
 353:     {
 354:         // Grab table info
 355:         $result = $this->query('SELECT sql FROM sqlite_master WHERE tbl_name = \''.($no_prefix ? '' : $this->prefix).$this->escape($table_name).'\' ORDER BY type DESC') or error('Unable to fetch table information', __FILE__, __LINE__, $this->error());
 356:         $num_rows = $this->num_rows($result);
 357: 
 358:         if ($num_rows == 0)
 359:             return;
 360: 
 361:         $table = array();
 362:         $table['indices'] = array();
 363:         while ($cur_index = $this->fetch_assoc($result))
 364:         {
 365:             if (empty($cur_index['sql']))
 366:                 continue;
 367: 
 368:             if (!isset($table['sql']))
 369:                 $table['sql'] = $cur_index['sql'];
 370:             else
 371:                 $table['indices'][] = $cur_index['sql'];
 372:         }
 373: 
 374:         // Work out the columns in the table currently
 375:         $table_lines = explode("\n", $table['sql']);
 376:         $table['columns'] = array();
 377:         foreach ($table_lines as $table_line)
 378:         {
 379:             $table_line = pun_trim($table_line);
 380:             if (substr($table_line, 0, 12) == 'CREATE TABLE')
 381:                 continue;
 382:             else if (substr($table_line, 0, 11) == 'PRIMARY KEY')
 383:                 $table['primary_key'] = $table_line;
 384:             else if (substr($table_line, 0, 6) == 'UNIQUE')
 385:                 $table['unique'] = $table_line;
 386:             else if (substr($table_line, 0, strpos($table_line, ' ')) != '')
 387:                 $table['columns'][substr($table_line, 0, strpos($table_line, ' '))] = pun_trim(substr($table_line, strpos($table_line, ' ')));
 388:         }
 389: 
 390:         return $table;
 391:     }
 392: 
 393: 
 394:     function add_field($table_name, $field_name, $field_type, $allow_null, $default_value = null, $after_field = 0, $no_prefix = false)
 395:     {
 396:         if ($this->field_exists($table_name, $field_name, $no_prefix))
 397:             return true;
 398: 
 399:         $table = $this->get_table_info($table_name, $no_prefix);
 400: 
 401:         // Create temp table
 402:         $now = time();
 403:         $tmptable = str_replace('CREATE TABLE '.($no_prefix ? '' : $this->prefix).$this->escape($table_name).' (', 'CREATE TABLE '.($no_prefix ? '' : $this->prefix).$this->escape($table_name).'_t'.$now.' (', $table['sql']);
 404:         $result = $this->query($tmptable) ? true : false;
 405:         $result &= $this->query('INSERT INTO '.($no_prefix ? '' : $this->prefix).$this->escape($table_name).'_t'.$now.' SELECT * FROM '.($no_prefix ? '' : $this->prefix).$this->escape($table_name)) ? true : false;
 406: 
 407:         // Create new table sql
 408:         $field_type = preg_replace(array_keys($this->datatype_transformations), array_values($this->datatype_transformations), $field_type);
 409:         $query = $field_type;
 410:         if (!$allow_null)
 411:             $query .= ' NOT NULL';
 412:         if ($default_value === null || $default_value === '')
 413:             $default_value = '\'\'';
 414: 
 415:         $query .= ' DEFAULT '.$default_value;
 416: 
 417:         $old_columns = array_keys($table['columns']);
 418:         array_insert($table['columns'], $after_field, $query.',', $field_name);
 419: 
 420:         $new_table = 'CREATE TABLE '.($no_prefix ? '' : $this->prefix).$this->escape($table_name).' (';
 421: 
 422:         foreach ($table['columns'] as $cur_column => $column_details)
 423:             $new_table .= "\n".$cur_column.' '.$column_details;
 424: 
 425:         if (isset($table['unique']))
 426:             $new_table .= "\n".$table['unique'].',';
 427: 
 428:         if (isset($table['primary_key']))
 429:             $new_table .= "\n".$table['primary_key'];
 430: 
 431:         $new_table = trim($new_table, ',')."\n".');';
 432: 
 433:         // Drop old table
 434:         $result &= $this->drop_table(($no_prefix ? '' : $this->prefix).$this->escape($table_name));
 435: 
 436:         // Create new table
 437:         $result &= $this->query($new_table) ? true : false;
 438: 
 439:         // Recreate indexes
 440:         if (!empty($table['indices']))
 441:         {
 442:             foreach ($table['indices'] as $cur_index)
 443:                 $result &= $this->query($cur_index) ? true : false;
 444:         }
 445: 
 446:         // Copy content back
 447:         $result &= $this->query('INSERT INTO '.($no_prefix ? '' : $this->prefix).$this->escape($table_name).' ('.implode(', ', $old_columns).') SELECT * FROM '.($no_prefix ? '' : $this->prefix).$this->escape($table_name).'_t'.$now) ? true : false;
 448: 
 449:         // Drop temp table
 450:         $result &= $this->drop_table(($no_prefix ? '' : $this->prefix).$this->escape($table_name).'_t'.$now);
 451: 
 452:         return $result;
 453:     }
 454: 
 455: 
 456:     function alter_field($table_name, $field_name, $field_type, $allow_null, $default_value = null, $after_field = 0, $no_prefix = false)
 457:     {
 458:         // Unneeded for SQLite
 459:         return true;
 460:     }
 461: 
 462: 
 463:     function drop_field($table_name, $field_name, $no_prefix = false)
 464:     {
 465:         if (!$this->field_exists($table_name, $field_name, $no_prefix))
 466:             return true;
 467: 
 468:         $table = $this->get_table_info($table_name, $no_prefix);
 469: 
 470:         // Create temp table
 471:         $now = time();
 472:         $tmptable = str_replace('CREATE TABLE '.($no_prefix ? '' : $this->prefix).$this->escape($table_name).' (', 'CREATE TABLE '.($no_prefix ? '' : $this->prefix).$this->escape($table_name).'_t'.$now.' (', $table['sql']);
 473:         $result = $this->query($tmptable) ? true : false;
 474:         $result &= $this->query('INSERT INTO '.($no_prefix ? '' : $this->prefix).$this->escape($table_name).'_t'.$now.' SELECT * FROM '.($no_prefix ? '' : $this->prefix).$this->escape($table_name)) ? true : false;
 475: 
 476:         // Work out the columns we need to keep and the sql for the new table
 477:         unset($table['columns'][$field_name]);
 478:         $new_columns = array_keys($table['columns']);
 479: 
 480:         $new_table = 'CREATE TABLE '.($no_prefix ? '' : $this->prefix).$this->escape($table_name).' (';
 481: 
 482:         foreach ($table['columns'] as $cur_column => $column_details)
 483:             $new_table .= "\n".$cur_column.' '.$column_details;
 484: 
 485:         if (isset($table['unique']))
 486:             $new_table .= "\n".$table['unique'].',';
 487: 
 488:         if (isset($table['primary_key']))
 489:             $new_table .= "\n".$table['primary_key'];
 490: 
 491:         $new_table = trim($new_table, ',')."\n".');';
 492: 
 493:         // Drop old table
 494:         $result &= $this->drop_table(($no_prefix ? '' : $this->prefix).$this->escape($table_name));
 495: 
 496:         // Create new table
 497:         $result &= $this->query($new_table) ? true : false;
 498: 
 499:         // Recreate indexes
 500:         if (!empty($table['indices']))
 501:         {
 502:             foreach ($table['indices'] as $cur_index)
 503:                 if (!preg_match('%\('.preg_quote($field_name, '%').'\)%', $cur_index))
 504:                     $result &= $this->query($cur_index) ? true : false;
 505:         }
 506: 
 507:         // Copy content back
 508:         $result &= $this->query('INSERT INTO '.($no_prefix ? '' : $this->prefix).$this->escape($table_name).' SELECT '.implode(', ', $new_columns).' FROM '.($no_prefix ? '' : $this->prefix).$this->escape($table_name).'_t'.$now) ? true : false;
 509: 
 510:         // Drop temp table
 511:         $result &= $this->drop_table(($no_prefix ? '' : $this->prefix).$this->escape($table_name).'_t'.$now);
 512: 
 513:         return $result;
 514:     }
 515: 
 516: 
 517:     function add_index($table_name, $index_name, $index_fields, $unique = false, $no_prefix = false)
 518:     {
 519:         if ($this->index_exists($table_name, $index_name, $no_prefix))
 520:             return true;
 521: 
 522:         return $this->query('CREATE '.($unique ? 'UNIQUE ' : '').'INDEX '.($no_prefix ? '' : $this->prefix).$table_name.'_'.$index_name.' ON '.($no_prefix ? '' : $this->prefix).$table_name.'('.implode(',', $index_fields).')') ? true : false;
 523:     }
 524: 
 525: 
 526:     function drop_index($table_name, $index_name, $no_prefix = false)
 527:     {
 528:         if (!$this->index_exists($table_name, $index_name, $no_prefix))
 529:             return true;
 530: 
 531:         return $this->query('DROP INDEX '.($no_prefix ? '' : $this->prefix).$table_name.'_'.$index_name) ? true : false;
 532:     }
 533: 
 534:     function truncate_table($table_name, $no_prefix = false)
 535:     {
 536:         return $this->query('DELETE FROM '.($no_prefix ? '' : $this->prefix).$table_name) ? true : false;
 537:     }
 538: }


/dev/null b/include/email.php
   1: <?php
   2: 
   3: /**
   4:  * Copyright (C) 2008-2010 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:  */
   8: 
   9: // Make sure no one attempts to run this script "directly"
  10: if (!defined('PUN'))
  11:     exit;
  12: 
  13: 
  14: //
  15: // Validate an email address
  16: //
  17: function is_valid_email($email)
  18: {
  19:     if (strlen($email) > 80)
  20:         return false;
  21: 
  22:     return preg_match('/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|("[^"]+"))@((\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\])|(([a-zA-Z\d\-]+\.)+[a-zA-Z]{2,}))$/', $email);
  23: }
  24: 
  25: 
  26: //
  27: // Check if $email is banned
  28: //
  29: function is_banned_email($email)
  30: {
  31:     global $pun_bans;
  32: 
  33:     foreach ($pun_bans as $cur_ban)
  34:     {
  35:         if ($cur_ban['email'] != '' &&
  36:             ($email == $cur_ban['email'] ||
  37:             (strpos($cur_ban['email'], '@') === false && stristr($email, '@'.$cur_ban['email']))))
  38:             return true;
  39:     }
  40: 
  41:     return false;
  42: }
  43: 
  44: 
  45: //
  46: // Wrapper for PHP's mail()
  47: //
  48: function pun_mail($to, $subject, $message, $reply_to_email = '', $reply_to_name = '')
  49: {
  50:     global $pun_config, $lang_common;
  51: 
  52:     // Default sender/return address
  53:     $from_name = str_replace('"', '', $pun_config['o_board_title'].' '.$lang_common['Mailer']);
  54:     $from_email = $pun_config['o_webmaster_email'];
  55: 
  56:     // Do a little spring cleaning
  57:     $to = pun_trim(preg_replace('#[\n\r]+#s', '', $to));
  58:     $subject = pun_trim(preg_replace('#[\n\r]+#s', '', $subject));
  59:     $from_email = pun_trim(preg_replace('#[\n\r:]+#s', '', $from_email));
  60:     $from_name = pun_trim(preg_replace('#[\n\r:]+#s', '', str_replace('"', '', $from_name)));
  61:     $reply_to_email = pun_trim(preg_replace('#[\n\r:]+#s', '', $reply_to_email));
  62:     $reply_to_name = pun_trim(preg_replace('#[\n\r:]+#s', '', str_replace('"', '', $reply_to_name)));
  63: 
  64:     // Set up some headers to take advantage of UTF-8
  65:     $from = "=?UTF-8?B?".base64_encode($from_name)."?=".' <'.$from_email.'>';
  66:     $subject = "=?UTF-8?B?".base64_encode($subject)."?=";
  67: 
  68:     $headers = 'From: '.$from."\r\n".'Date: '.gmdate('r')."\r\n".'MIME-Version: 1.0'."\r\n".'Content-transfer-encoding: 8bit'."\r\n".'Content-type: text/plain; charset=utf-8'."\r\n".'X-Mailer: FluxBB Mailer';
  69: 
  70:     // If we specified a reply-to email, we deal with it here
  71:     if (!empty($reply_to_email))
  72:     {
  73:         $reply_to = "=?UTF-8?B?".base64_encode($reply_to_name)."?=".' <'.$reply_to_email.'>';
  74: 
  75:         $headers .= "\r\n".'Reply-To: '.$reply_to;
  76:     }
  77: 
  78:     // Make sure all linebreaks are CRLF in message (and strip out any NULL bytes)
  79:     $message = str_replace(array("\n", "\0"), array("\r\n", ''), pun_linebreaks($message));
  80: 
  81:     if ($pun_config['o_smtp_host'] != '')
  82:         smtp_mail($to, $subject, $message, $headers);
  83:     else
  84:     {
  85:         // Change the linebreaks used in the headers according to OS
  86:         if (strtoupper(substr(PHP_OS, 0, 3)) == 'MAC')
  87:             $headers = str_replace("\r\n", "\r", $headers);
  88:         else if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN')
  89:             $headers = str_replace("\r\n", "\n", $headers);
  90: 
  91:         mail($to, $subject, $message, $headers);
  92:     }
  93: }
  94: 
  95: 
  96: //
  97: // This function was originally a part of the phpBB Group forum software phpBB2 (http://www.phpbb.com)
  98: // They deserve all the credit for writing it. I made small modifications for it to suit PunBB and it's coding standards
  99: //
 100: function server_parse($socket, $expected_response)
 101: {
 102:     $server_response = '';
 103:     while (substr($server_response, 3, 1) != ' ')
 104:     {
 105:         if (!($server_response = fgets($socket, 256)))
 106:             error('Couldn\'t get mail server response codes. Please contact the forum administrator.', __FILE__, __LINE__);
 107:     }
 108: 
 109:     if (!(substr($server_response, 0, 3) == $expected_response))
 110:         error('Unable to send email. Please contact the forum administrator with the following error message reported by the SMTP server: "'.$server_response.'"', __FILE__, __LINE__);
 111: }
 112: 
 113: 
 114: //
 115: // This function was originally a part of the phpBB Group forum software phpBB2 (http://www.phpbb.com)
 116: // They deserve all the credit for writing it. I made small modifications for it to suit PunBB and it's coding standards.
 117: //
 118: function smtp_mail($to, $subject, $message, $headers = '')
 119: {
 120:     global $pun_config;
 121: 
 122:     $recipients = explode(',', $to);
 123: 
 124:     // Sanitize the message
 125:     $message = str_replace("\r\n.", "\r\n..", $message);
 126:     $message = (substr($message, 0, 1) == '.' ? '.'.$message : $message);
 127: 
 128:     // Are we using port 25 or a custom port?
 129:     if (strpos($pun_config['o_smtp_host'], ':') !== false)
 130:         list($smtp_host, $smtp_port) = explode(':', $pun_config['o_smtp_host']);
 131:     else
 132:     {
 133:         $smtp_host = $pun_config['o_smtp_host'];
 134:         $smtp_port = 25;
 135:     }
 136: 
 137:     if ($pun_config['o_smtp_ssl'] == '1')
 138:         $smtp_host = 'ssl://'.$smtp_host;
 139: 
 140:     if (!($socket = fsockopen($smtp_host, $smtp_port, $errno, $errstr, 15)))
 141:         error('Could not connect to smtp host "'.$pun_config['o_smtp_host'].'" ('.$errno.') ('.$errstr.')', __FILE__, __LINE__);
 142: 
 143:     server_parse($socket, '220');
 144: 
 145:     if ($pun_config['o_smtp_user'] != '' && $pun_config['o_smtp_pass'] != '')
 146:     {
 147:         fwrite($socket, 'EHLO '.$smtp_host."\r\n");
 148:         server_parse($socket, '250');
 149: 
 150:         fwrite($socket, 'AUTH LOGIN'."\r\n");
 151:         server_parse($socket, '334');
 152: 
 153:         fwrite($socket, base64_encode($pun_config['o_smtp_user'])."\r\n");
 154:         server_parse($socket, '334');
 155: 
 156:         fwrite($socket, base64_encode($pun_config['o_smtp_pass'])."\r\n");
 157:         server_parse($socket, '235');
 158:     }
 159:     else
 160:     {
 161:         fwrite($socket, 'HELO '.$smtp_host."\r\n");
 162:         server_parse($socket, '250');
 163:     }
 164: 
 165:     fwrite($socket, 'MAIL FROM: <'.$pun_config['o_webmaster_email'].'>'."\r\n");
 166:     server_parse($socket, '250');
 167: 
 168:     foreach ($recipients as $email)
 169:     {
 170:         fwrite($socket, 'RCPT TO: <'.$email.'>'."\r\n");
 171:         server_parse($socket, '250');
 172:     }
 173: 
 174:     fwrite($socket, 'DATA'."\r\n");
 175:     server_parse($socket, '354');
 176: 
 177:     fwrite($socket, 'Subject: '.$subject."\r\n".'To: <'.implode('>, <', $recipients).'>'."\r\n".$headers."\r\n\r\n".$message."\r\n");
 178: 
 179:     fwrite($socket, '.'."\r\n");
 180:     server_parse($socket, '250');
 181: 
 182:     fwrite($socket, 'QUIT'."\r\n");
 183:     fclose($socket);
 184: 
 185:     return true;
 186: }


/dev/null b/include/functions.php
   1: <?php
   2: 
   3: /**
   4:  * Copyright (C) 2008-2010 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:  */
   8: 
   9: 
  10: //
  11: // Return current timestamp (with microseconds) as a float
  12: //
  13: function get_microtime()
  14: {
  15:     list($usec, $sec) = explode(' ', microtime());
  16:     return ((float)$usec + (float)$sec);
  17: }
  18: 
  19: //
  20: // Cookie stuff!
  21: //
  22: function check_cookie(&$pun_user)
  23: {
  24:     global $db, $db_type, $pun_config, $cookie_name, $cookie_seed;
  25: 
  26:     $now = time();
  27: 
  28:     // We assume it's a guest
  29:     $cookie = array('user_id' => 1, 'password_hash' => 'Guest');
  30: 
  31:     // If a cookie is set, we get the user_id and password hash from it
  32:     if (isset($_COOKIE[$cookie_name]))
  33:         list($cookie['user_id'], $cookie['password_hash'], $cookie['expiration_time']) = @unserialize($_COOKIE[$cookie_name]);
  34: 
  35:     if ($cookie['user_id'] > 1)
  36:     {
  37:         // Check if there's a user with the user ID and password hash from the cookie
  38:         $result = $db->query('SELECT u.*, g.*, o.logged, o.idle FROM '.$db->prefix.'users AS u INNER JOIN '.$db->prefix.'groups AS g ON u.group_id=g.g_id LEFT JOIN '.$db->prefix.'online AS o ON o.user_id=u.id WHERE u.id='.intval($cookie['user_id'])) or error('Unable to fetch user information', __FILE__, __LINE__, $db->error());
  39:         $pun_user = $db->fetch_assoc($result);
  40: 
  41:         // If user authorisation failed
  42:         if (!isset($pun_user['id']) || md5($cookie_seed.$pun_user['password']) !== $cookie['password_hash'])
  43:         {
  44:             $expire = $now + 31536000; // The cookie expires after a year
  45:             pun_setcookie(1, md5(uniqid(rand(), true)), $expire);
  46:             set_default_user();
  47: 
  48:             return;
  49:         }
  50: 
  51:         // Send a new, updated cookie with a new expiration timestamp
  52:         $expire = (intval($cookie['expiration_time']) > $now + $pun_config['o_timeout_visit']) ? $now + 1209600 : $now + $pun_config['o_timeout_visit'];
  53:         pun_setcookie($pun_user['id'], $pun_user['password'], $expire);
  54: 
  55:         // Set a default language if the user selected language no longer exists
  56:         if (!file_exists(PUN_ROOT.'lang/'.$pun_user['language']))
  57:             $pun_user['language'] = $pun_config['o_default_lang'];
  58: 
  59:         // Set a default style if the user selected style no longer exists
  60:         if (!file_exists(PUN_ROOT.'style/'.$pun_user['style'].'.css'))
  61:             $pun_user['style'] = $pun_config['o_default_style'];
  62: 
  63:         if (!$pun_user['disp_topics'])
  64:             $pun_user['disp_topics'] = $pun_config['o_disp_topics_default'];
  65:         if (!$pun_user['disp_posts'])
  66:             $pun_user['disp_posts'] = $pun_config['o_disp_posts_default'];
  67: 
  68:         // Define this if you want this visit to affect the online list and the users last visit data
  69:         if (!defined('PUN_QUIET_VISIT'))
  70:         {
  71:             // Update the online list
  72:             if (!$pun_user['logged'])
  73:             {
  74:                 $pun_user['logged'] = $now;
  75: 
  76:                 // With MySQL/MySQLi/SQLite, REPLACE INTO avoids a user having two rows in the online table
  77:                 switch ($db_type)
  78:                 {
  79:                     case 'mysql':
  80:                     case 'mysqli':
  81:                     case 'mysql_innodb':
  82:                     case 'mysqli_innodb':
  83:                     case 'sqlite':
  84:                         $db->query('REPLACE INTO '.$db->prefix.'online (user_id, ident, logged) VALUES('.$pun_user['id'].', \''.$db->escape($pun_user['username']).'\', '.$pun_user['logged'].')') or error('Unable to insert into online list', __FILE__, __LINE__, $db->error());
  85:                         break;
  86: 
  87:                     default:
  88:                         $db->query('INSERT INTO '.$db->prefix.'online (user_id, ident, logged) SELECT '.$pun_user['id'].', \''.$db->escape($pun_user['username']).'\', '.$pun_user['logged'].' WHERE NOT EXISTS (SELECT 1 FROM '.$db->prefix.'online WHERE user_id='.$pun_user['id'].')') or error('Unable to insert into online list', __FILE__, __LINE__, $db->error());
  89:                         break;
  90:                 }
  91: 
  92:                 // Reset tracked topics
  93:                 set_tracked_topics(null);
  94:             }
  95:             else
  96:             {
  97:                 // Special case: We've timed out, but no other user has browsed the forums since we timed out
  98:                 if ($pun_user['logged'] < ($now-$pun_config['o_timeout_visit']))
  99:                 {
 100:                     $db->query('UPDATE '.$db->prefix.'users SET last_visit='.$pun_user['logged'].' WHERE id='.$pun_user['id']) or error('Unable to update user visit data',&