Beehive PHP Cross Reference Discussion Forums

Source: /pm_edit.php - 378 lines - 14477 bytes - Summary - Text - Print

   1  <?php
   2  
   3  /*======================================================================
   4  Copyright Project Beehive Forum 2002
   5  
   6  This file is part of Beehive Forum.
   7  
   8  Beehive Forum is free software; you can redistribute it and/or modify
   9  it under the terms of the GNU General Public License as published by
  10  the Free Software Foundation; either version 3 of the License, or
  11  (at your option) any later version.
  12  
  13  Beehive Forum is distributed in the hope that it will be useful,
  14  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16  GNU General Public License for more details.
  17  
  18  You should have received a copy of the GNU General Public License
  19  along with Beehive; if not, write to the Free Software
  20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  21  USA
  22  ======================================================================*/
  23  
  24  // Bootstrap
  25  require_once  'boot.php';
  26  
  27  // Required includes
  28  require_once  BH_INCLUDE_PATH . 'attachments.inc.php';
  29  require_once  BH_INCLUDE_PATH . 'constants.inc.php';
  30  require_once  BH_INCLUDE_PATH . 'emoticons.inc.php';
  31  require_once  BH_INCLUDE_PATH . 'fixhtml.inc.php';
  32  require_once  BH_INCLUDE_PATH . 'form.inc.php';
  33  require_once  BH_INCLUDE_PATH . 'format.inc.php';
  34  require_once  BH_INCLUDE_PATH . 'forum.inc.php';
  35  require_once  BH_INCLUDE_PATH . 'header.inc.php';
  36  require_once  BH_INCLUDE_PATH . 'html.inc.php';
  37  require_once  BH_INCLUDE_PATH . 'pm.inc.php';
  38  require_once  BH_INCLUDE_PATH . 'post.inc.php';
  39  require_once  BH_INCLUDE_PATH . 'session.inc.php';
  40  require_once  BH_INCLUDE_PATH . 'user.inc.php';
  41  require_once  BH_INCLUDE_PATH . 'word_filter.inc.php';
  42  // End Required includes
  43  
  44  // Check we're logged in correctly
  45  if (!session::logged_in()) {
  46      html_guest_error();
  47  }
  48  
  49  // Check that PM system is enabled
  50  pm_enabled();
  51  
  52  // Get the user's post page preferences.
  53  $page_prefs = session::get_post_page_prefs();
  54  
  55  // Prune old messages for the current user
  56  pm_user_prune_folders($_SESSION['UID']);
  57  
  58  $t_subject = null;
  59  $t_content = null;
  60  
  61  // Get the Message ID (MID)
  62  if (isset($_GET['mid']) && is_numeric($_GET['mid'])) {
  63  
  64      $mid = $_GET['mid'];
  65  
  66  } else if (isset($_POST['mid']) && is_numeric($_POST['mid'])) {
  67  
  68      $mid = $_POST['mid'];
  69  
  70  } else {
  71  
  72      html_draw_error(gettext("No message specified for editing"));
  73  }
  74  
  75  // Get the message.
  76  if (!($message_data = pm_message_get($mid))) {
  77      pm_edit_refuse();
  78  }
  79  
  80  if (isset($message_data['ATTACHMENTS'])) {
  81      $attachments = $message_data['ATTACHMENTS'];
  82  } else {
  83      $attachments = array();
  84  }
  85  
  86  $valid = true;
  87  
  88  // For future's sake, if we ever add an admin option for allowing/disallowing HTML PMs.
  89  // Then just do something like $allow_html = forum_allow_html_pms() ? true : false
  90  $allow_html = true;
  91  
  92  if (isset($_POST['apply']) || isset($_POST['preview'])) {
  93  
  94      if (isset($_POST['t_subject']) && strlen(trim($_POST['t_subject'])) > 0) {
  95  
  96          $t_subject = trim($_POST['t_subject']);
  97  
  98      } else {
  99  
 100          $error_msg_array[] = gettext("Enter a subject for the message");
 101          $valid = false;
 102      }
 103  
 104      if (isset($_POST['t_content']) && strlen(trim($_POST['t_content'])) > 0) {
 105  
 106          $t_content = fix_html(emoticons_strip($_POST['t_content']));
 107  
 108          if (mb_strlen($t_content) >= 65535) {
 109  
 110              $error_msg_array[] = sprintf(
 111                  gettext("Message length must be under 65,535 characters (currently: %s)"),
 112                  number_format(mb_strlen($t_content))
 113              );
 114  
 115              $valid = false;
 116          }
 117  
 118      } else {
 119  
 120          $error_msg_array[] = gettext("Enter some content for the message");
 121          $valid = false;
 122      }
 123  
 124      if (isset($_POST['attachment']) && is_array($_POST['attachment'])) {
 125          $attachments = array_filter($_POST['attachment'], 'is_md5');
 126      } else {
 127          $attachments = array();
 128      }
 129  }
 130  
 131  if ($valid && isset($_POST['preview'])) {
 132  
 133      $message_data['CONTENT'] = $t_content;
 134  
 135      $message_data['SUBJECT'] = $t_subject;
 136  
 137      $message_data['FOLDER'] = PM_FOLDER_OUTBOX;
 138  
 139      $message_data['ATTACHMENTS'] = $attachments;
 140  
 141  } else if ($valid && isset($_POST['apply'])) {
 142  
 143      if (pm_edit_message($mid, $t_subject, $t_content)) {
 144  
 145          if (sizeof($attachments) > 0 && ($attachments_array = attachments_get($_SESSION['UID'], $attachments))) {
 146  
 147              foreach ($attachments_array as $attachment) {
 148  
 149                  pm_add_attachment($mid, $attachment['aid']);
 150              }
 151          }
 152  
 153          header_redirect("pm.php?webtag=$webtag&mid=$mid");
 154          exit;
 155  
 156      } else {
 157  
 158          $error_msg_array[] = gettext("Error creating PM! Please try again in a few minutes");
 159          $valid = false;
 160      }
 161  
 162  } else if (isset($_POST['emots_toggle'])) {
 163  
 164      if (isset($_POST['t_subject']) && strlen(trim($_POST['t_subject'])) > 0) {
 165          $t_subject = trim($_POST['t_subject']);
 166      }
 167  
 168      if (isset($_POST['t_content']) && strlen(trim($_POST['t_content'])) > 0) {
 169          $t_content = fix_html(emoticons_strip($_POST['t_content']));
 170      }
 171  
 172      if (isset($_POST['to_radio']) && is_numeric($_POST['to_radio'])) {
 173          $to_radio = $_POST['to_radio'];
 174      } else {
 175          $to_radio = 1;
 176      }
 177  
 178      if (isset($_POST['t_to_uid']) && is_numeric($_POST['t_to_uid'])) {
 179          $t_to_uid = $_POST['t_to_uid'];
 180      } else {
 181          $t_to_uid = 0;
 182      }
 183  
 184      $page_prefs = (double)$page_prefs ^ POST_EMOTICONS_DISPLAY;
 185  
 186      $user_prefs = array(
 187          'POST_PAGE' => $page_prefs
 188      );
 189  
 190      if (!user_update_prefs($_SESSION['UID'], $user_prefs)) {
 191  
 192          $error_msg_array[] = gettext("Some or all of your user account details could not be updated. Please try again later.");
 193          $valid = false;
 194      }
 195  
 196  } else {
 197  
 198      if (!isset($message_data['EDITABLE']) || ($message_data['EDITABLE'] == 0)) {
 199          pm_edit_refuse();
 200      }
 201  
 202      $parsed_message = new MessageTextParse(pm_get_content($mid));
 203  
 204      $t_content = $parsed_message->getMessage();
 205  
 206      $t_subject = $message_data['SUBJECT'];
 207  }
 208  
 209  html_draw_top(sprintf("title=%s", gettext("Private Messages")), "resize_width=960", "js/attachments.js", "js/edit.js", "js/pm.js", "js/emoticons.js", 'ckeditor/ckeditor.js', 'js/fineuploader.min.js', "basetarget=_blank", 'pm_popup_disabled', 'class=window_title');
 210  
 211  echo "<h1>", gettext("Private Messages"), "<img src=\"", html_style_image('separator.png'), "\" alt=\"\" border=\"0\" />", gettext("Edit Message"), "</h1>\n";
 212  
 213  if (isset($error_msg_array) && sizeof($error_msg_array) > 0) {
 214      html_display_error_array($error_msg_array, '960', 'left');
 215  }
 216  
 217  echo "<br />\n";
 218  echo "<form accept-charset=\"utf-8\" name=\"f_post\" action=\"pm_edit.php\" method=\"post\" target=\"_self\">\n";
 219  echo "  ", form_input_hidden('webtag', htmlentities_array($webtag)), "\n";
 220  echo "  ", form_input_hidden('mid', htmlentities_array($mid)), "\n";
 221  echo "  <table cellpadding=\"0\" cellspacing=\"0\" width=\"960\">\n";
 222  echo "    <tr>\n";
 223  echo "      <td align=\"left\">\n";
 224  echo "        <table class=\"box\" width=\"100%\">\n";
 225  echo "          <tr>\n";
 226  echo "            <td align=\"left\" class=\"posthead\">\n";
 227  
 228  if ($valid && isset($_POST['preview'])) {
 229  
 230      echo "              <table class=\"posthead\" width=\"100%\">\n";
 231      echo "                <tr>\n";
 232      echo "                  <td align=\"left\" class=\"subhead\">", gettext("Message Preview"), "</td>\n";
 233      echo "                </tr>";
 234      echo "                <tr>\n";
 235      echo "                  <td align=\"left\"><br />";
 236  
 237      pm_display($message_data, true);
 238  
 239      echo "                  </td>\n";
 240      echo "                </tr>\n";
 241      echo "                <tr>\n";
 242      echo "                  <td align=\"left\" colspan=\"2\">&nbsp;</td>\n";
 243      echo "                </tr>\n";
 244      echo "              </table>\n";
 245  }
 246  
 247  echo "              <table width=\"100%\" class=\"posthead\">\n";
 248  echo "                <tr>\n";
 249  echo "                  <td align=\"left\" class=\"subhead\" colspan=\"2\">", gettext("Edit Message"), "</td>\n";
 250  echo "                </tr>\n";
 251  echo "                <tr>\n";
 252  echo "                  <td align=\"left\" valign=\"top\" width=\"210\">\n";
 253  echo "                    <table class=\"posthead\" width=\"210\">\n";
 254  echo "                      <tr>\n";
 255  echo "                        <td align=\"left\"><h2>", gettext("Subject"), "</h2></td>\n";
 256  echo "                      </tr>\n";
 257  echo "                      <tr>\n";
 258  echo "                        <td align=\"left\">", form_input_text("t_subject", isset($t_subject) ? htmlentities_array($t_subject) : "", 42, null, null, "thread_title"), "</td>\n";
 259  echo "                      </tr>\n";
 260  echo "                      <tr>\n";
 261  echo "                        <td align=\"left\"><h2>", gettext("To"), "</h2></td>\n";
 262  echo "                      </tr>\n";
 263  
 264  foreach ($message_data['RECIPIENTS'] as $recipient) {
 265  
 266      echo "                      <tr>\n";
 267      echo "                        <td align=\"left\"><a href=\"user_profile.php?webtag=$webtag&amp;uid={$recipient['UID']}\" target=\"_blank\" class=\"popup 650x500\">", word_filter_add_ob_tags(format_user_name($recipient['LOGON'], $recipient['NICKNAME']), true), "</a></td>\n";
 268      echo "                      </tr>\n";
 269  }
 270  
 271  if (isset($_SESSION['EMOTICONS']) && strlen(trim($_SESSION['EMOTICONS'])) > 0) {
 272      $user_emoticon_pack = $_SESSION['EMOTICONS'];
 273  } else {
 274      $user_emoticon_pack = forum_get_setting('default_emoticons', 'strlen', 'default');
 275  }
 276  
 277  if (($emoticon_preview_html = emoticons_preview($user_emoticon_pack)) !== false) {
 278  
 279      echo "                      <tr>\n";
 280      echo "                        <td align=\"left\">&nbsp;</td>\n";
 281      echo "                      </tr>\n";
 282      echo "                      <tr>\n";
 283      echo "                        <td align=\"left\">\n";
 284      echo "                          <table width=\"196\" class=\"messagefoot\" cellspacing=\"0\">\n";
 285      echo "                            <tr>\n";
 286      echo "                              <td align=\"left\" class=\"subhead\">", gettext("Emoticons"), "</td>\n";
 287  
 288      if (($page_prefs & POST_EMOTICONS_DISPLAY) > 0) {
 289          echo "                              <td class=\"subhead\" align=\"right\">", form_submit_image('hide.png', 'emots_toggle', 'hide', null, 'button_image toggle_button'), "&nbsp;</td>\n";
 290      } else {
 291          echo "                              <td class=\"subhead\" align=\"right\">", form_submit_image('show.png', 'emots_toggle', 'show', null, 'button_image toggle_button'), "&nbsp;</td>\n";
 292      }
 293  
 294      echo "                            </tr>\n";
 295      echo "                            <tr>\n";
 296      echo "                              <td align=\"left\" colspan=\"2\">\n";
 297  
 298      if (($page_prefs & POST_EMOTICONS_DISPLAY) > 0) {
 299          echo "                                <div class=\"emots_toggle\">{$emoticon_preview_html}</div>\n";
 300      } else {
 301          echo "                                <div class=\"emots_toggle\" style=\"display: none\">{$emoticon_preview_html}</div>\n";
 302      }
 303  
 304      echo "                              </td>\n";
 305      echo "                            </tr>\n";
 306      echo "                          </table>\n";
 307      echo "                        </td>\n";
 308      echo "                      </tr>\n";
 309  }
 310  
 311  echo "                    </table>\n";
 312  echo "                  </td>\n";
 313  echo "                  <td align=\"left\" width=\"740\" valign=\"top\">\n";
 314  echo "                    <table border=\"0\" class=\"posthead\" width=\"100%\">\n";
 315  echo "                      <tr>\n";
 316  echo "                        <td align=\"left\">";
 317  echo "                         <h2>", gettext("Message"), "</h2>\n";
 318  echo "                         ", form_textarea("t_content", htmlentities_array(emoticons_apply($t_content)), 22, 100, 'tabindex="1"', 'post_content editor focus'), "\n";
 319  echo "                        </td>\n";
 320  echo "                      </tr>\n";
 321  echo "                      <tr>\n";
 322  echo "                        <td align=\"left\">\n";
 323  
 324  echo form_submit('apply', gettext("Apply"), "tabindex=\"2\""), "\n";
 325  
 326  echo form_submit('preview', gettext("Preview"), "tabindex=\"3\""), "\n";
 327  
 328  echo "<a href=\"pm.php?webtag=$webtag&mid=$mid\" class=\"button\" target=\"_self\"><span>", gettext("Cancel"), "</span></a>\n";
 329  
 330  if (attachments_check_dir()) {
 331  
 332      echo "                        </td>\n";
 333      echo "                      </tr>\n";
 334      echo "                      <tr>\n";
 335      echo "                        <td align=\"left\">&nbsp;</td>\n";
 336      echo "                      </tr>\n";
 337      echo "                      <tr>\n";
 338      echo "                        <td align=\"left\">\n";
 339      echo "                          <table class=\"messagefoot\" width=\"722\" cellspacing=\"0\">\n";
 340      echo "                            <tr>\n";
 341      echo "                              <td align=\"left\" class=\"subhead\">", gettext("Attachments"), "</td>\n";
 342  
 343      if (($page_prefs & POST_ATTACHMENT_DISPLAY) > 0) {
 344          echo "                              <td class=\"subhead\" align=\"right\">", form_submit_image('hide.png', 'attachment_toggle', 'hide', null, 'button_image toggle_button'), "&nbsp;</td>\n";
 345      } else {
 346          echo "                              <td class=\"subhead\" align=\"right\">", form_submit_image('show.png', 'attachment_toggle', 'show', null, 'button_image toggle_button'), "&nbsp;</td>\n";
 347      }
 348  
 349      echo "                            </tr>\n";
 350      echo "                            <tr>\n";
 351      echo "                              <td align=\"left\" colspan=\"2\">\n";
 352      echo "                                <div class=\"attachments attachment_toggle\" style=\"display: ", (($page_prefs & POST_ATTACHMENT_DISPLAY) > 0) ? "block" : "none", "\">\n";
 353      echo "                                  <ul>\n";
 354      echo "                                  ", attachments_form($_SESSION['UID'], $attachments), "\n";
 355      echo "                                </div>\n";
 356      echo "                              </td>\n";
 357      echo "                            </tr>\n";
 358      echo "                          </table>\n";
 359  }
 360  
 361  echo "                        </td>\n";
 362  echo "                      </tr>\n";
 363  echo "                    </table>\n";
 364  echo "                  </td>\n";
 365  echo "                </tr>\n";
 366  echo "                <tr>\n";
 367  echo "                  <td align=\"left\" colspan=\"2\">&nbsp;</td>\n";
 368  echo "                </tr>\n";
 369  echo "              </table>\n";
 370  echo "            </td>\n";
 371  echo "          </tr>\n";
 372  echo "        </table>\n";
 373  echo "      </td>\n";
 374  echo "    </tr>\n";
 375  echo "  </table>\n";
 376  echo "</form>\n";
 377  
 378  html_draw_bottom();

title

Description

title

Description

title

Description

title

title

Body