[ Index ]

PHP Cross Reference of phpBB 3.0 Beta 3

title

Body

[close]

/includes/mcp/ -> mcp_topic.php (source)

   1  <?php
   2  /** 
   3  *
   4  * @package mcp
   5  * @version $Id: mcp_topic.php,v 1.32 2006/11/12 14:29:32 naderman Exp $
   6  * @copyright (c) 2005 phpBB Group 
   7  * @license http://opensource.org/licenses/gpl-license.php GNU Public License 
   8  *
   9  */
  10  
  11  /**
  12  * View topic in MCP
  13  */
  14  function mcp_topic_view($id, $mode, $action)
  15  {
  16      global $phpEx, $phpbb_root_path, $config;
  17      global $template, $db, $user, $auth;
  18  
  19      $url = append_sid("{$phpbb_root_path}mcp.$phpEx?" . extra_url());
  20  
  21      $user->add_lang('viewtopic');
  22  
  23      $topic_id = request_var('t', 0);
  24      $topic_info = get_topic_data(array($topic_id));
  25  
  26      if (!sizeof($topic_info))
  27      {
  28          trigger_error($user->lang['TOPIC_NOT_EXIST']);
  29      }
  30  
  31      $topic_info = $topic_info[$topic_id];
  32  
  33      // Set up some vars
  34      $icon_id        = request_var('icon', 0);
  35      $subject        = request_var('subject', '', true);
  36      $start            = request_var('start', 0);
  37      $to_topic_id    = request_var('to_topic_id', 0);
  38      $to_forum_id    = request_var('to_forum_id', 0);
  39      $post_id_list    = request_var('post_id_list', array(0));
  40      
  41      utf8_normalize_nfc(&$subject);
  42  
  43      // Split Topic?
  44      if ($action == 'split_all' || $action == 'split_beyond')
  45      {
  46          split_topic($action, $topic_id, $to_forum_id, $subject);
  47          $action = 'split';
  48      }
  49  
  50      // Merge Posts?
  51      if ($action == 'merge_posts')
  52      {
  53          merge_posts($topic_id, $to_topic_id);
  54          $action = 'merge';
  55      }
  56  
  57      if ($action == 'split' && !$subject)
  58      {
  59          $subject = $topic_info['topic_title'];
  60      }
  61  
  62      // Jumpbox, sort selects and that kind of things
  63      make_jumpbox($url . "&amp;i=$id&amp;mode=forum_view", $topic_info['forum_id'], false, 'm_');
  64      $where_sql = ($action == 'reports') ? 'WHERE post_reported = 1 AND ' : 'WHERE';
  65  
  66      $sort_days = $total = 0;
  67      $sort_key = $sort_dir = '';
  68      $sort_by_sql = $sort_order_sql = array();
  69      mcp_sorting('viewtopic', $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $topic_info['forum_id'], $topic_id, $where_sql);
  70  
  71      $limit_time_sql = ($sort_days) ? 'AND t.topic_last_post_time >= ' . (time() - ($sort_days * 86400)) : '';
  72  
  73      if ($total == -1)
  74      {
  75          $total = $topic_info['topic_replies'] + 1;
  76      }
  77  
  78      $posts_per_page = max(0, request_var('posts_per_page', intval($config['posts_per_page'])));
  79      if ($posts_per_page == 0)
  80      {
  81          $posts_per_page = $total;
  82      }
  83  
  84      $sql = 'SELECT u.username, u.user_colour, p.*
  85          FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u
  86          WHERE ' . (($action == 'reports') ? 'p.post_reported = 1 AND ' : '') . "
  87              p.topic_id = {$topic_id}
  88              AND p.poster_id = u.user_id
  89          ORDER BY $sort_order_sql";
  90      $result = $db->sql_query_limit($sql, $posts_per_page, $start);
  91  
  92      $rowset = array();
  93      $bbcode_bitfield = '';
  94      while ($row = $db->sql_fetchrow($result))
  95      {
  96          $rowset[] = $row;
  97          $bbcode_bitfield = $bbcode_bitfield | base64_decode($row['bbcode_bitfield']);
  98      }
  99      $db->sql_freeresult($result);
 100  
 101      if ($bbcode_bitfield !== '')
 102      {
 103          include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
 104          $bbcode = new bbcode(base64_encode($bbcode_bitfield));
 105      }
 106  
 107      foreach ($rowset as $i => $row)
 108      {
 109          $has_unapproved_posts = false;
 110          $poster = ($row['poster_id'] != ANONYMOUS) ? $row['username'] : ((!$row['post_username']) ? $user->lang['GUEST'] : $row['post_username']);
 111          $poster = ($row['user_colour']) ? '<span style="color:#' . $row['user_colour'] . '">' . $poster . '</span>' : $poster;
 112  
 113          $message = $row['post_text'];
 114          $post_subject = ($row['post_subject'] != '') ? $row['post_subject'] : $topic_info['topic_title'];
 115          $message = str_replace("\n", '<br />', $message);
 116  
 117          if ($row['bbcode_bitfield'])
 118          {
 119              $bbcode->bbcode_second_pass($message, $row['bbcode_uid'], $row['bbcode_bitfield']);
 120          }
 121  
 122          $message = smiley_text($message);
 123  
 124          if (!$row['post_approved'])
 125          {
 126              $has_unapproved_posts = true;
 127          }
 128  
 129          $template->assign_block_vars('postrow', array(
 130              'POSTER_NAME'    => $poster,
 131              'POST_DATE'        => $user->format_date($row['post_time']),
 132              'POST_SUBJECT'    => $post_subject,
 133              'MESSAGE'        => $message,
 134              'POST_ID'        => $row['post_id'],
 135              'RETURN_TOPIC'    => sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $topic_id) . '">', '</a>'),
 136  
 137              'MINI_POST_IMG'        => ($row['post_time'] > $user->data['user_lastvisit'] && $user->data['is_registered']) ? $user->img('icon_post_target_unread', $user->lang['NEW_POST']) : $user->img('icon_post_target', $user->lang['POST']),
 138  
 139              'S_POST_REPORTED'    => ($row['post_reported']) ? true : false,
 140              'S_POST_UNAPPROVED'    => ($row['post_approved']) ? false : true,
 141              'S_CHECKED'            => ($post_id_list && in_array(intval($row['post_id']), $post_id_list)) ? true : false,
 142  
 143              'U_POST_DETAILS'    => "$url&amp;i=$id&amp;p={$row['post_id']}&amp;mode=post_details",
 144              'U_MCP_APPROVE'        => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&amp;mode=approve_details&amp;f=' . $topic_info['forum_id'] . '&amp;p=' . $row['post_id']),
 145              'U_MCP_REPORT'        => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&amp;mode=report_details&amp;f=' . $topic_info['forum_id'] . '&amp;p=' . $row['post_id']))
 146          );
 147  
 148          unset($rowset[$i]);
 149      }
 150  
 151      // Display topic icons for split topic
 152      $s_topic_icons = false;
 153  
 154      if ($auth->acl_get('m_split', $topic_info['forum_id']))
 155      {
 156          include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
 157          $s_topic_icons = posting_gen_topic_icons('', $icon_id);
 158  
 159          // Has the user selected a topic for merge?
 160          if ($to_topic_id)
 161          {
 162              $to_topic_info = get_topic_data(array($to_topic_id), 'm_merge');
 163  
 164              if (!sizeof($to_topic_info))
 165              {
 166                  $to_topic_id = 0;
 167              }
 168              else
 169              {
 170                  $to_topic_info = $to_topic_info[$to_topic_id];
 171              }
 172  
 173              if (!$to_topic_info['enable_icons'])
 174              {
 175                  $s_topic_icons = false;
 176              }
 177          }
 178      }
 179  
 180      $template->assign_vars(array(
 181          'TOPIC_TITLE'        => $topic_info['topic_title'],
 182          'U_VIEWTOPIC'        => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $topic_info['forum_id'] . '&amp;t=' . $topic_info['topic_id']),
 183  
 184          'TO_TOPIC_ID'        => $to_topic_id,
 185          'TO_TOPIC_INFO'        => ($to_topic_id) ? sprintf($user->lang['YOU_SELECTED_TOPIC'], $to_topic_id, '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $to_topic_info['forum_id'] . '&amp;t=' . $to_topic_id) . '">' . $to_topic_info['topic_title'] . '</a>') : '',
 186  
 187          'SPLIT_SUBJECT'        => $subject,
 188          'POSTS_PER_PAGE'    => $posts_per_page,
 189          'ACTION'            => $action,
 190  
 191          'REPORTED_IMG'        => $user->img('icon_topic_reported', 'POST_REPORTED', false, true),
 192          'UNAPPROVED_IMG'    => $user->img('icon_topic_unapproved', 'POST_UNAPPROVED', false, true),
 193  
 194          'S_MCP_ACTION'        => "$url&amp;i=$id&amp;mode=$mode&amp;action=$action&amp;start=$start",
 195          'S_FORUM_SELECT'    => ($to_forum_id) ? make_forum_select($to_forum_id, false, false, true, true, true) : make_forum_select($topic_info['forum_id'], false, false, true, true, true),
 196          'S_CAN_SPLIT'        => ($auth->acl_get('m_split', $topic_info['forum_id'])) ? true : false,
 197          'S_CAN_MERGE'        => ($auth->acl_get('m_merge', $topic_info['forum_id'])) ? true : false,
 198          'S_CAN_DELETE'        => ($auth->acl_get('m_delete', $topic_info['forum_id'])) ? true : false,
 199          'S_CAN_APPROVE'        => ($has_unapproved_posts && $auth->acl_get('m_approve', $topic_info['forum_id'])) ? true : false,
 200          'S_CAN_LOCK'        => ($auth->acl_get('m_lock', $topic_info['forum_id'])) ? true : false,
 201          'S_REPORT_VIEW'        => ($action == 'reports') ? true : false,
 202          'S_MERGE_VIEW'        => ($action == 'merge') ? true : false,
 203  
 204          'S_SHOW_TOPIC_ICONS'    => $s_topic_icons,
 205          'S_TOPIC_ICON'            => $icon_id,
 206  
 207          'U_SELECT_TOPIC'    => "$url&amp;i=$id&amp;mode=forum_view&amp;action=merge_select",
 208  
 209          'RETURN_TOPIC'        => sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f={$topic_info['forum_id']}&amp;t={$topic_info['topic_id']}&amp;start=$start") . '">', '</a>'),
 210          'RETURN_FORUM'        => sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", "f={$topic_info['forum_id']}&amp;start=$start") . '">', '</a>'),
 211  
 212          'PAGE_NUMBER'        => on_page($total, $posts_per_page, $start),
 213          'PAGINATION'        => (!$posts_per_page) ? '' : generate_pagination(append_sid("{$phpbb_root_path}mcp.$phpEx", "i=$id&amp;t={$topic_info['topic_id']}&amp;mode=$mode&amp;action=$action&amp;to_topic_id=$to_topic_id&amp;posts_per_page=$posts_per_page&amp;st=$sort_days&amp;sk=$sort_key&amp;sd=$sort_dir"), $total, $posts_per_page, $start),
 214          'TOTAL'                => $total)
 215      );
 216  }
 217  
 218  /**
 219  * Split topic
 220  */
 221  function split_topic($action, $topic_id, $to_forum_id, $subject)
 222  {
 223      global $db, $template, $user, $phpEx, $phpbb_root_path, $auth;
 224  
 225      $post_id_list    = request_var('post_id_list', array(0));
 226      $start            = request_var('start', 0);
 227  
 228      if (!sizeof($post_id_list))
 229      {
 230          $template->assign_var('MESSAGE', $user->lang['NO_POST_SELECTED']);
 231          return;
 232      }
 233  
 234      if (!($forum_id = check_ids($post_id_list, POSTS_TABLE, 'post_id', 'm_split')))
 235      {
 236          return;
 237      }
 238  
 239      $post_id = $post_id_list[0];
 240      $post_info = get_post_data(array($post_id));
 241  
 242      if (!sizeof($post_info))
 243      {
 244          $template->assign_var('MESSAGE', $user->lang['NO_POST_SELECTED']);
 245          return;
 246      }
 247  
 248      $post_info = $post_info[$post_id];
 249      $subject = trim($subject);
 250  
 251      // Make some tests
 252      if (!$subject)
 253      {
 254          $template->assign_var('MESSAGE', $user->lang['EMPTY_SUBJECT']);
 255          return;
 256      }
 257  
 258      if ($to_forum_id <= 0)
 259      {
 260          $template->assign_var('MESSAGE', $user->lang['NO_DESTINATION_FORUM']);
 261          return;
 262      }
 263  
 264      $forum_info = get_forum_data(array($to_forum_id), 'm_split');
 265  
 266      if (!sizeof($forum_info))
 267      {
 268          $template->assign_var('MESSAGE', $user->lang['NOT_MODERATOR']);
 269          return;
 270      }
 271  
 272      $forum_info = $forum_info[$to_forum_id];
 273  
 274      if ($forum_info['forum_type'] != FORUM_POST)
 275      {
 276          $template->assign_var('MESSAGE', $user->lang['FORUM_NOT_POSTABLE']);
 277          return;
 278      }
 279  
 280      $redirect = request_var('redirect', $user->data['session_page']);
 281  
 282      $s_hidden_fields = build_hidden_fields(array(
 283          'i'                => 'main',
 284          'post_id_list'    => $post_id_list,
 285          'f'                => $forum_id,
 286          'mode'            => 'topic_view',
 287          'start'            => $start,
 288          'action'        => $action,
 289          't'                => $topic_id,
 290          'redirect'        => $redirect,
 291          'subject'        => $subject,
 292          'to_forum_id'    => $to_forum_id,
 293          'icon'            => request_var('icon', 0))
 294      );
 295      $success_msg = $return_link = '';
 296  
 297      if (confirm_box(true))
 298      {
 299          if ($action == 'split_beyond')
 300          {
 301              $sort_days = $total = 0;
 302              $sort_key = $sort_dir = '';
 303              $sort_by_sql = $sort_order_sql = array();
 304              mcp_sorting('viewtopic', $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $forum_id, $topic_id);
 305  
 306              $limit_time_sql = ($sort_days) ? 'AND t.topic_last_post_time >= ' . (time() - ($sort_days * 86400)) : '';
 307  
 308              if ($sort_order_sql[0] == 'u')
 309              {
 310                  $sql = 'SELECT p.post_id, p.forum_id, p.post_approved
 311                      FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . " u
 312                      WHERE p.topic_id = $topic_id
 313                          AND p.poster_id = u.user_id
 314                          $limit_time_sql
 315                      ORDER BY $sort_order_sql";
 316              }
 317              else
 318              {
 319                  $sql = 'SELECT p.post_id, p.forum_id, p.post_approved
 320                      FROM ' . POSTS_TABLE . " p
 321                      WHERE p.topic_id = $topic_id
 322                          $limit_time_sql
 323                      ORDER BY $sort_order_sql";
 324              }
 325              $result = $db->sql_query_limit($sql, 0, $start);
 326  
 327              $store = false;
 328              $post_id_list = array();
 329              while ($row = $db->sql_fetchrow($result))
 330              {
 331                  // If splitted from selected post (split_beyond), we split the unapproved items too.
 332                  if (!$row['post_approved'] && !$auth->acl_get('m_approve', $row['forum_id']))
 333                  {
 334  //                    continue;
 335                  }
 336  
 337                  // Start to store post_ids as soon as we see the first post that was selected
 338                  if ($row['post_id'] == $post_id)
 339                  {
 340                      $store = true;
 341                  }
 342  
 343                  if ($store)
 344                  {
 345                      $post_id_list[] = $row['post_id'];
 346                  }
 347              }
 348              $db->sql_freeresult($result);
 349          }
 350  
 351          if (!sizeof($post_id_list))
 352          {
 353              trigger_error($user->lang['NO_POST_SELECTED']);
 354          }
 355  
 356          $icon_id = request_var('icon', 0);
 357  
 358          $sql_ary = array(
 359              'forum_id'        => $to_forum_id,
 360              'topic_title'    => $subject,
 361              'icon_id'        => $icon_id,
 362              'topic_approved'=> 1
 363          );
 364  
 365          $sql = 'INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
 366          $db->sql_query($sql);
 367  
 368          $to_topic_id = $db->sql_nextid();
 369          move_posts($post_id_list, $to_topic_id);
 370  
 371          // Change topic title of first post
 372          $sql = 'UPDATE ' . POSTS_TABLE . "
 373              SET post_subject = '" . $db->sql_escape($subject) . "'
 374              WHERE post_id = {$post_id_list[0]}";
 375          $db->sql_query($sql);
 376  
 377          $success_msg = 'TOPIC_SPLIT_SUCCESS';
 378  
 379          // Link back to both topics
 380          $return_link = sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $post_info['forum_id'] . '&amp;t=' . $post_info['topic_id']) . '">', '</a>') . '<br /><br />' . sprintf($user->lang['RETURN_NEW_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $to_forum_id . '&amp;t=' . $to_topic_id) . '">', '</a>');
 381      }
 382      else
 383      {
 384          confirm_box(false, ($action == 'split_all') ? 'SPLIT_TOPIC_ALL' : 'SPLIT_TOPIC_BEYOND', $s_hidden_fields);
 385      }
 386  
 387      $redirect = request_var('redirect', "index.$phpEx");
 388      $redirect = reapply_sid($redirect);
 389  
 390      if (!$success_msg)
 391      {
 392          return;
 393      }
 394      else
 395      {
 396          meta_refresh(3, append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$to_forum_id&amp;t=$to_topic_id"));
 397          trigger_error($user->lang[$success_msg] . '<br /><br />' . $return_link);
 398      }
 399  }
 400  
 401  /**
 402  * Merge selected posts into selected topic
 403  */
 404  function merge_posts($topic_id, $to_topic_id)
 405  {
 406      global $db, $template, $user, $phpEx, $phpbb_root_path, $auth;
 407  
 408      if (!$to_topic_id)
 409      {
 410          $template->assign_var('MESSAGE', $user->lang['NO_FINAL_TOPIC_SELECTED']);
 411          return;
 412      }
 413  
 414      $topic_data = get_topic_data(array($to_topic_id), 'm_merge');
 415  
 416      if (!sizeof($topic_data))
 417      {
 418          $template->assign_var('MESSAGE', $user->lang['NO_FINAL_TOPIC_SELECTED']);
 419          return;
 420      }
 421  
 422      $topic_data = $topic_data[$to_topic_id];
 423  
 424      $post_id_list    = request_var('post_id_list', array(0));
 425      $start            = request_var('start', 0);
 426  
 427      if (!sizeof($post_id_list))
 428      {
 429          $template->assign_var('MESSAGE', $user->lang['NO_POST_SELECTED']);
 430          return;
 431      }
 432  
 433      if (!($forum_id = check_ids($post_id_list, POSTS_TABLE, 'post_id', 'm_merge')))
 434      {
 435          return;
 436      }
 437  
 438      $redirect = request_var('redirect', $user->data['session_page']);
 439  
 440      $s_hidden_fields = build_hidden_fields(array(
 441          'i'                => 'main',
 442          'post_id_list'    => $post_id_list,
 443          'to_topic_id'    => $to_topic_id,
 444          'mode'            => 'topic_view',
 445          'action'        => 'merge_posts',
 446          'start'            => $start,
 447          'redirect'        => $redirect,
 448          'f'                => $forum_id,
 449          't'                => $topic_id)
 450      );
 451      $success_msg = $return_link = '';
 452  
 453      if (confirm_box(true))
 454      {
 455          $to_forum_id = $topic_data['forum_id'];
 456  
 457          move_posts($post_id_list, $to_topic_id);
 458          add_log('mod', $to_forum_id, $to_topic_id, 'LOG_MERGE', $topic_data['topic_title']);
 459  
 460          // Message and return links
 461          $success_msg = 'POSTS_MERGED_SUCCESS';
 462  
 463          // Does the original topic still exist? If yes, link back to it
 464          $topic_data = get_topic_data(array($topic_id));
 465  
 466          if (sizeof($topic_data))
 467          {
 468              $return_link .= sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $forum_id . '&amp;t=' . $topic_id) . '">', '</a>');
 469          }
 470  
 471          // Link to the new topic
 472          $return_link .= (($return_link) ? '<br /><br />' : '') . sprintf($user->lang['RETURN_NEW_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $to_forum_id . '&amp;t=' . $to_topic_id) . '">', '</a>');
 473      }
 474      else
 475      {
 476          confirm_box(false, 'MERGE_POSTS', $s_hidden_fields);
 477      }
 478  
 479      $redirect = request_var('redirect', "index.$phpEx");
 480      $redirect = reapply_sid($redirect);
 481  
 482      if (!$success_msg)
 483      {
 484          return;
 485      }
 486      else
 487      {
 488          meta_refresh(3, append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$to_forum_id&amp;t=$to_topic_id"));
 489          trigger_error($user->lang[$success_msg] . '<br /><br />' . $return_link);
 490      }
 491  }
 492  
 493  ?>


Generated: Wed Nov 22 00:35:05 2006 Cross-referenced by PHPXref 0.6