XMB PHP Cross Reference Discussion Forums

Source: /forumdisplay.php - 417 lines - 12944 bytes - Summary - Text - Print

Description: eXtreme Message Board XMB 1.9.11

   1  <?php
   2  /**
   3   * eXtreme Message Board
   4   * XMB 1.9.11
   5   *
   6   * Developed And Maintained By The XMB Group
   7   * Copyright (c) 2001-2012, The XMB Group
   8   * http://www.xmbforum2.com/
   9   *
  10   * This program is free software; you can redistribute it and/or
  11   * modify it under the terms of the GNU General Public License
  12   * as published by the Free Software Foundation; either version 2
  13   * of the License, or (at your option) any later version.
  14   *
  15   * This program is distributed in the hope that it will be useful,
  16   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18   * GNU General Public License for more details.
  19   *
  20   * You should have received a copy of the GNU General Public License
  21   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  22   *
  23   **/
  24  
  25  define('X_SCRIPT', 'forumdisplay.php');
  26  
  27  require  'header.php';
  28  
  29  loadtemplates(
  30  'forumdisplay',
  31  'forumdisplay_admin',
  32  'forumdisplay_sortby',
  33  'forumdisplay_multipage',
  34  'forumdisplay_multipage_admin',
  35  'forumdisplay_newpoll',
  36  'forumdisplay_newtopic',
  37  'forumdisplay_nothreads',
  38  'forumdisplay_password',
  39  'forumdisplay_subforum',
  40  'forumdisplay_subforum_lastpost',
  41  'forumdisplay_subforum_nolastpost',
  42  'forumdisplay_subforums',
  43  'forumdisplay_thread',
  44  'forumdisplay_thread_admin',
  45  'forumdisplay_thread_lastpost'
  46  );
  47  
  48  smcwcache();
  49  
  50  eval('$css = "'.template('css').'";');
  51  eval($lang['hottopiceval']);
  52  
  53  $fid = getInt('fid');
  54  
  55  $forum = getForum($fid);
  56  
  57  if (($forum['type'] != 'forum' && $forum['type'] != 'sub') || $forum['status'] != 'on') {
  58      header('HTTP/1.0 404 Not Found');
  59      error($lang['textnoforum']);
  60  }
  61  
  62  $perms = checkForumPermissions($forum);
  63  if (!$perms[X_PERMS_VIEW]) {
  64      if (X_GUEST) {
  65          redirect("{$full_url}misc.php?action=login", 0);
  66          exit;
  67      } else {
  68          error($lang['privforummsg']);
  69      }
  70  } else if (!$perms[X_PERMS_PASSWORD]) {
  71      handlePasswordDialog($fid);
  72  }
  73  
  74  $fup = array();
  75  if ($forum['type'] == 'sub') {
  76      $fup = getForum($forum['fup']);
  77      // prevent access to subforum when upper forum can't be viewed.
  78      $fupPerms = checkForumPermissions($fup);
  79      if (!$fupPerms[X_PERMS_VIEW]) {
  80          if (X_GUEST) {
  81              redirect("{$full_url}misc.php?action=login", 0);
  82              exit;
  83          } else {
  84              error($lang['privforummsg']);
  85          }
  86      } else if (!$fupPerms[X_PERMS_PASSWORD]) {
  87          handlePasswordDialog($fup['fid']);
  88      } else if ($fup['fup'] > 0) {
  89          $fupup = getForum($fup['fup']);
  90          nav('<a href="index.php?gid='.$fup['fup'].'">'.fnameOut($fupup['name']).'</a>');
  91          unset($fupup);
  92      }
  93      nav('<a href="forumdisplay.php?fid='.$fup['fid'].'">'.fnameOut($fup['name']).'</a>');
  94      unset($fup);
  95  } else if ($forum['fup'] > 0) { // 'forum' in a 'group'
  96      $fup = getForum($forum['fup']);
  97      nav('<a href="index.php?gid='.$fup['fid'].'">'.fnameOut($fup['name']).'</a>');
  98      unset($fup);
  99  }
 100  nav(fnameOut($forum['name']));
 101  
 102  if ($SETTINGS['subject_in_title'] == 'on') {
 103      $threadSubject = '- '.fnameOut($forum['name']);
 104  }
 105  
 106  // Search-link
 107  $searchlink = makeSearchLink($forum['fid']);
 108  
 109  validateTpp();
 110  validatePpp();
 111  
 112  $threadcount = $db->result($db->query("SELECT COUNT(tid) FROM ".X_PREFIX."threads WHERE fid=$fid"), 0);
 113  
 114  // Perform automatic maintenance
 115  if ($forum['type'] == 'sub' And $forum['threads'] != $threadcount) {
 116      updateforumcount($fid);
 117  }
 118  
 119  $mpage = multipage($threadcount, $tpp, 'forumdisplay.php?fid='.$fid);
 120  
 121  eval('$header = "'.template('header').'";');
 122  
 123  if ($perms[X_PERMS_POLL]) {
 124      eval('$newpolllink = "'.template('forumdisplay_newpoll').'";');
 125  } else {
 126      $newpolllink = '';
 127  }
 128  
 129  if ($perms[X_PERMS_THREAD]) {
 130      eval('$newtopiclink = "'.template('forumdisplay_newtopic').'";');
 131  } else {
 132      $newtopiclink = '';
 133  }
 134  
 135  $index_subforums = array();
 136  $subforums = '';
 137  if ($forum['type'] == 'forum') {
 138      $forumlist = '';
 139      $permitted = permittedForums(forumCache(), 'forum');
 140      foreach($permitted as $sub) {
 141          if ($sub['type'] == 'sub' And $sub['fup'] == $fid) {
 142              $forumlist .= forum($sub, "forumdisplay_subforum", $index_subforums);
 143          }
 144      }
 145      if ($forumlist != '') {
 146          eval('$subforums .= "'.template('forumdisplay_subforums').'";');
 147      }
 148  }
 149  
 150  $t_extension = get_extension($lang['toppedprefix']);
 151  switch($t_extension) {
 152      case 'gif':
 153      case 'jpg':
 154      case 'jpeg':
 155      case 'png':
 156          $lang['toppedprefix'] = '<img src="'.$imgdir.'/'.$lang['toppedprefix'].'" alt="'.$lang['toppedpost'].'" border="0" />';
 157          break;
 158  }
 159  
 160  $p_extension = get_extension($lang['pollprefix']);
 161  switch($p_extension) {
 162      case 'gif':
 163      case 'jpg':
 164      case 'jpeg':
 165      case 'png':
 166          $lang['pollprefix'] = '<img src="'.$imgdir.'/'.$lang['pollprefix'].'" alt="'.$lang['postpoll'].'" border="0" />';
 167          break;
 168  }
 169  
 170  $cusdate = formInt('cusdate');
 171  if ($cusdate) {
 172      $cusdate = $onlinetime - $cusdate;
 173      $cusdate = "AND (substring_index(lastpost, '|',1)+1) >= '$cusdate'";
 174  } else {
 175      $cusdate = '';
 176  }
 177  
 178  $ascdesc = postedVar('ascdesc', '', FALSE, FALSE);
 179  if (strtolower($ascdesc) != 'asc') {
 180      $ascdesc = "desc";
 181  }
 182  
 183  $forumdisplay_thread = 'forumdisplay_thread';
 184  
 185  $status1 = modcheck($self['username'], $forum['moderator']);
 186  
 187  if ($status1 == 'Moderator') {
 188      $forumdisplay_thread = 'forumdisplay_thread_admin';
 189  }
 190  
 191  // This first query does not access any table data if the new forum_optimize index is available.  :)
 192  $criteria = '';
 193  $offset = '';
 194  if ($mpage['start'] <= 30) {
 195      // However, we need to be beyond page 1 to get any boost.
 196      $offset = "{$mpage['start']},";
 197  } else {
 198      $query1 = $db->query(
 199          "SELECT topped, lastpost
 200           FROM ".X_PREFIX."threads
 201           WHERE fid=$fid
 202           ORDER BY topped DESC, lastpost DESC
 203           LIMIT {$mpage['start']}, $tpp"
 204      );
 205      if ($row = $db->fetch_array($query1)) {
 206          $db->escape_fast($row['lastpost']);
 207  
 208          $rowcount = $db->num_rows($query1);
 209          $db->data_seek($query1, $rowcount - 1);
 210          $lastrow = $db->fetch_array($query1);
 211  
 212          if (intval($row['topped']) == 0) {
 213              $criteria = " AND topped = 0 AND lastpost <= '{$row['lastpost']}' ";
 214          } elseif (intval($lastrow['topped']) == 1) {
 215              $criteria = " AND topped = 1 AND lastpost <= '{$row['lastpost']}' ";
 216          } else {
 217              $criteria = " AND (lastpost <= '{$row['lastpost']}' OR topped = 0) ";
 218          }
 219      } else {
 220          $criteria = " AND 1=0 ";
 221      }
 222      $db->free_result($query1);
 223  }
 224  
 225  $threadlist = '';
 226  $threadsInFid = array();
 227  
 228  $querytop = $db->query(
 229      "SELECT t.*, m.uid, r.uid AS lastauthor
 230       FROM ".X_PREFIX."threads AS t
 231       LEFT JOIN ".X_PREFIX."members AS m ON t.author = m.username
 232       LEFT JOIN ".X_PREFIX."members AS r ON SUBSTRING_INDEX(SUBSTRING_INDEX(t.lastpost, '|', 2), '|', -1) = r.username
 233       WHERE t.fid=$fid $criteria $cusdate
 234       ORDER BY topped $ascdesc, lastpost $ascdesc
 235       LIMIT $offset $tpp"
 236  );
 237  
 238  if ($db->num_rows($querytop) == 0) {
 239      eval('$threadlist = "'.template('forumdisplay_nothreads').'";');
 240  } elseif ($SETTINGS['dotfolders'] == 'on' && X_MEMBER && $self['postnum'] > 0) {
 241      while($thread = $db->fetch_array($querytop)) {
 242          $threadsInFid[] = $thread['tid'];
 243      }
 244      $db->data_seek($querytop, 0);
 245  
 246      $threadsInFid = implode(',', $threadsInFid);
 247      $query = $db->query("SELECT tid FROM ".X_PREFIX."posts WHERE tid IN ($threadsInFid) AND author='$xmbuser' GROUP BY tid");
 248  
 249      $threadsInFid = array();
 250      while($row = $db->fetch_array($query)) {
 251          $threadsInFid[] = $row['tid'];
 252      }
 253      $db->free_result($query);
 254  }
 255  
 256  while($thread = $db->fetch_array($querytop)) {
 257      if ($thread['icon'] != '' && file_exists($smdir.'/'.$thread['icon'])) {
 258          $thread['icon'] = '<img src="'.$smdir.'/'.$thread['icon'].'" alt="'.$thread['icon'].'" border="0" />';
 259      } else {
 260          $thread['icon'] = '';
 261      }
 262  
 263      if ($thread['topped'] == 1) {
 264          $topimage = '<img src="'.$admdir.'/untop.gif" alt="'.$lang['textuntopthread'].'" border="0" />';
 265      } else {
 266          $topimage = '<img src="'.$admdir.'/top.gif" alt="'.$lang['alttopthread'].'" border="0" />';
 267      }
 268  
 269      $thread['subject'] = shortenString(rawHTMLsubject(stripslashes($thread['subject'])), 125, X_SHORTEN_SOFT|X_SHORTEN_HARD, '...');
 270  
 271      if ($thread['author'] == 'Anonymous') {
 272          $authorlink = $lang['textanonymous'];
 273      } elseif (is_null($thread['uid'])) {
 274          $authorlink = $thread['author'];
 275      } else {
 276          $authorlink = '<a href="member.php?action=viewpro&amp;member='.recodeOut($thread['author']).'">'.$thread['author'].'</a>';
 277      }
 278  
 279      $prefix = '';
 280  
 281      $lastpost = explode('|', $thread['lastpost']);
 282      $dalast = trim($lastpost[0]);
 283  
 284      if ($lastpost[1] == 'Anonymous') {
 285          $lastpost[1] = $lang['textanonymous'];
 286      } elseif (!is_null($thread['lastauthor'])) {
 287          $lastpost[1] = '<a href="member.php?action=viewpro&amp;member='.recodeOut(trim($lastpost[1])).'">'.trim($lastpost[1]).'</a>';
 288      } // else leave value unchanged
 289  
 290      $lastPid = isset($lastpost[2]) ? $lastpost[2] : 0;
 291  
 292      if ($thread['replies'] >= $SETTINGS['hottopic']) {
 293          $folder = 'hot_folder.gif';
 294      } else {
 295          $folder = 'folder.gif';
 296      }
 297  
 298      $oldtopics = isset($oldtopics) ? $oldtopics : '';
 299  
 300      if (($oT = strpos($oldtopics, '|'.$lastPid.'|')) === false && $thread['replies'] >= $SETTINGS['hottopic'] && $lastvisit < $dalast) {
 301          $folder = "hot_red_folder.gif";
 302      } else if ($lastvisit < $dalast && $oT === false) {
 303          $folder = "red_folder.gif";
 304      }
 305  
 306      if ($SETTINGS['dotfolders'] == 'on' && X_MEMBER && (count($threadsInFid) > 0) && in_array($thread['tid'], $threadsInFid)) {
 307          $folder = 'dot_'.$folder;
 308      }
 309  
 310      $folder = '<img src="'.$imgdir.'/'.$folder.'" alt="'.$lang['altfolder'].'" border="0" />';
 311  
 312      if ($thread['closed'] == 'yes') {
 313          $folder = '<img src="'.$imgdir.'/lock_folder.gif" alt="'.$lang['altclosedtopic'].'" border="0" />';
 314      }
 315  
 316      $lastreplydate = gmdate($dateformat, $lastpost[0] + ($timeoffset * 3600) + ($addtime * 3600));
 317      $lastreplytime = gmdate($timecode, $lastpost[0] + ($timeoffset * 3600) + ($addtime * 3600));
 318  
 319      $lastpost = $lastreplydate.' '.$lang['textat'].' '.$lastreplytime.'<br />'.$lang['textby'].' '.$lastpost[1];
 320  
 321      $moved = explode('|', $thread['closed']);
 322      if ($moved[0] == 'moved') {
 323          $prefix = $lang['moved'].' ';
 324          $thread['realtid'] = $thread['tid'];
 325          $thread['tid'] = $moved[1];
 326          $thread['replies'] = "-";
 327          $thread['views'] = "-";
 328          $folder = '<img src="'.$imgdir.'/lock_folder.gif" alt="'.$lang['altclosedtopic'].'" border="0" />';
 329          $query = $db->query("SELECT COUNT(pid) FROM ".X_PREFIX."posts WHERE tid='$thread[tid]'");
 330          $postnum = 0;
 331          if ($query !== false) {
 332              $postnum = $db->result($query, 0);
 333          }
 334      } else {
 335          $thread['realtid'] = $thread['tid'];
 336      }
 337  
 338      eval('$lastpostrow = "'.template('forumdisplay_thread_lastpost').'";');
 339  
 340      if ($thread['pollopts'] == 1) {
 341          $prefix = $lang['pollprefix'].' ';
 342      }
 343  
 344      if ($thread['topped'] == 1) {
 345          $prefix = $lang['toppedprefix'].' '.$prefix;
 346      }
 347  
 348      $mpurl = 'viewthread.php?tid='.$thread['tid'];
 349      $multipage2 = multi(1, quickpage($thread['replies']+1, $ppp), $mpurl, FALSE);
 350      if (strlen($multipage2) != 0) {
 351          $multipage2 = "(<small>$multipage2</small>)";
 352      }
 353      unset($mpurl);
 354  
 355      eval('$threadlist .= "'.template($forumdisplay_thread).'";');
 356  
 357      $prefix = '';
 358  }
 359  $db->free_result($querytop);
 360  
 361  $check1 = $check5 = '';
 362  $check15 = $check30 = '';
 363  $check60 = $check100 = '';
 364  $checkyear = $checkall = '';
 365  switch($cusdate) {
 366      case 86400:
 367          $check1 = $selHTML;
 368          break;
 369      case 432000:
 370          $check5 = $selHTML;
 371          break;
 372      case 1296000:
 373          $check15 = $selHTML;
 374          break;
 375      case 2592000:
 376          $check30 = $selHTML;
 377          break;
 378      case 5184000:
 379          $check60 = $selHTML;
 380          break;
 381      case 8640000:
 382          $check100 = $selHTML;
 383          break;
 384      case 31536000:
 385          $checkyear = $selHTML;
 386          break;
 387      default:
 388          $checkall = $selHTML;
 389          break;
 390  }
 391  
 392  eval('$sortby = "'.template('forumdisplay_sortby').'";');
 393  
 394  $multipage =& $mpage['html'];
 395  if (strlen($mpage['html']) != 0) {
 396      if ($status1 == 'Moderator') {
 397          eval('$multipage = "'.template('forumdisplay_multipage_admin').'";');
 398      } else {
 399          eval('$multipage = "'.template('forumdisplay_multipage').'";');
 400      }
 401  }
 402  
 403  if ($status1 == 'Moderator') {
 404      if (X_ADMIN) {
 405          $fadminlink = '<a href="cp.php?action=forum&amp;fdetails='.$forum['fid'].'" title="'.$lang['alteditsettings'].'"><img src="'.$admdir.'/editforumsets.gif" border="0" alt="" /></a>';
 406      } else {
 407          $fadminlink = '';
 408      }
 409      eval('$forumdisplay = "'.template('forumdisplay_admin').'";');
 410  } else {
 411      eval('$forumdisplay = "'.template('forumdisplay').'";');
 412  }
 413  
 414  end_time();
 415  eval('$footer = "'.template('footer').'";');
 416  echo $header, $forumdisplay, $footer;
 417  ?>

title

Description

title

Description

title

Description

title

title

Body