[ Index ]
 

Code source de Phorum 5.1.25

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/include/posting/ -> action_post.php (source)

   1  <?php
   2  
   3  ////////////////////////////////////////////////////////////////////////////////
   4  //                                                                            //
   5  //   Copyright (C) 2006  Phorum Development Team                              //
   6  //   http://www.phorum.org                                                    //
   7  //                                                                            //
   8  //   This program is free software. You can redistribute it and/or modify     //
   9  //   it under the terms of either the current Phorum License (viewable at     //
  10  //   phorum.org) or the Phorum License that was distributed with this file    //
  11  //                                                                            //
  12  //   This program is distributed in the hope that it will be useful,          //
  13  //   but WITHOUT ANY WARRANTY, without even the implied warranty of           //
  14  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     //
  15  //                                                                            //
  16  //   You should have received a copy of the Phorum License                    //
  17  //   along with this program.                                                 //
  18  ////////////////////////////////////////////////////////////////////////////////
  19  
  20  if(!defined("PHORUM")) return;
  21  
  22  // For phorum_update_thread_info().
  23  include_once ("./include/thread_info.php");
  24  
  25  // For phorum_email_moderators() and phorum_email_notice().
  26  include_once ("./include/email_functions.php");
  27  
  28  // Set some values.
  29  $message["moderator_post"] = $PHORUM["DATA"]["MODERATOR"] ? 1 : 0;
  30  $message["sort"] = PHORUM_SORT_DEFAULT;
  31  $message["closed"] = $message["allow_reply"] ? 0 : 1;
  32  
  33  // Determine and set the user's IP address.
  34  $user_ip = $_SERVER["REMOTE_ADDR"];
  35  if ($PHORUM["dns_lookup"]) {
  36      $resolved = @gethostbyaddr($_SERVER["REMOTE_ADDR"]);
  37      if (!empty($resolved)) {
  38          $user_ip = $resolved;
  39      }
  40  }
  41  $message["ip"] = $user_ip;
  42  
  43  // For replies, inherit the closed parameter of our top parent.
  44  // Only for rare race conditions, since you cannot reply to
  45  // closed threads.
  46  if ($mode == "reply") {
  47      $message["closed"] = $top_parent["closed"];
  48      $message["allow_reply"] = ! $top_parent["closed"];
  49  }
  50  
  51  // Check if allow_reply can be set.
  52  if ($mode == "post" && ! $PHORUM["DATA"]["OPTION_ALLOWED"]["allow_reply"]) {
  53      $message["closed"] = 0;
  54      $message["allow_reply"] = 1;
  55  }
  56  
  57  // For sticky and announcement theads set the sort parameter
  58  // for replies to the correct value, so threaded views will work.
  59  if ($mode == "reply")
  60  {
  61      if ($top_parent["sort"] == PHORUM_SORT_STICKY) {
  62          $message["sort"] = PHORUM_SORT_STICKY;
  63      } elseif ($top_parent["sort"] == PHORUM_SORT_ANNOUNCEMENT) {
  64          $message["sort"] = PHORUM_SORT_ANNOUNCEMENT;
  65          $message["forum_id"] = $top_parent["forum_id"];
  66      }
  67  }
  68  
  69  // Do specific actions for new threads with a "special" flag.
  70  if ($mode == "post" && isset($message["special"]))
  71  {
  72      if ($message["special"]=="sticky" && $PHORUM["DATA"]["OPTION_ALLOWED"]["sticky"]) {
  73          $message["sort"] = PHORUM_SORT_STICKY;
  74      } elseif ($message["special"] == "announcement" && $PHORUM["DATA"]["OPTION_ALLOWED"]["announcement"]) {
  75          $message["sort"] = PHORUM_SORT_ANNOUNCEMENT;
  76          $message["forum_id"]= $PHORUM["vroot"] ? $PHORUM["vroot"] : 0;
  77      }
  78  }
  79  
  80  if ($PHORUM["DATA"]["LOGGEDIN"] && $message["show_signature"]) {
  81      $message["meta"]["show_signature"] = 1;
  82  }
  83  
  84  // Put messages on hold in case the forum is moderated.
  85  if ($PHORUM["DATA"]["MODERATED"]) {
  86      $message["status"] = PHORUM_STATUS_HOLD;
  87  } else {
  88      $message["status"] = PHORUM_STATUS_APPROVED;
  89  }
  90  
  91  // Create a unique message id.
  92  $suffix = preg_replace("/[^a-z0-9]/i", "", $PHORUM["name"]);
  93  $message["msgid"] = md5(uniqid(rand())) . ".$suffix";
  94  
  95  // Run pre post mods.
  96  $message = phorum_hook("pre_post", $message);
  97  
  98  // Add attachments to meta data. Because there might be inconsistencies in
  99  // the list due to going backward in the browser after deleting attachments,
 100  // a check is needed to see if the attachments are really in the database.
 101  $message["meta"]["attachments"] = array();
 102  foreach ($message["attachments"] as $info) {
 103      if ($info["keep"] && phorum_db_file_get($info["file_id"])) {
 104          $message["meta"]["attachments"][] = array(
 105              "file_id"   => $info["file_id"],
 106              "name"      => $info["name"],
 107              "size"      => $info["size"],
 108          );
 109      }
 110  }
 111  if (!count($message["meta"]["attachments"])) {
 112      unset($message["meta"]["attachments"]);
 113  }
 114  
 115  // Keep a copy of the message we have got now.
 116  $message_copy = $message;
 117  
 118  // Store the message in the database.
 119  $success = phorum_db_post_message($message);
 120  
 121  if ($success)
 122  {
 123      // Handle linking and deleting of attachments to synchronize
 124      // the message attachments with the working copy list
 125      // of attachments.
 126      foreach ($message_copy["attachments"] as $info) {
 127          if ($info["keep"]) {
 128              phorum_db_file_link(
 129                  $info["file_id"],
 130                  $message["message_id"],
 131                  PHORUM_LINK_MESSAGE
 132              );
 133          } else {
 134              phorum_db_file_delete($info["file_id"]);
 135          }
 136      }
 137  
 138      // Retrieve the message again to have it in the correct
 139      // format (otherwise it's a bit messed up in the
 140      // post-function). Do merge back data which is not
 141      // stored in the database, but which we might need later on.
 142      $message = phorum_db_get_message($message["message_id"]);
 143      foreach ($message_copy as $key => $val) {
 144          if (! isset($message[$key])) {
 145              $message[$key] = $val;
 146          }
 147      }
 148  
 149      phorum_update_thread_info($message["thread"]);
 150  
 151      // Run mods for after db is set but before other actions occur.
 152      if (isset($PHORUM["hooks"]["after_message_save"]))
 153          $message = phorum_hook("after_message_save", $message);
 154  
 155  
 156      // Subscribe user to the thread if requested.
 157      if ($message["email_notify"] && $message["user_id"]) {
 158          phorum_user_subscribe(
 159              $message["user_id"], $PHORUM["forum_id"],
 160              $message["thread"], PHORUM_SUBSCRIPTION_MESSAGE
 161          );
 162      }
 163  
 164      // Mark own message read.
 165      if ($PHORUM["DATA"]["LOGGEDIN"]) {
 166          phorum_db_newflag_add_read(array(0=>array(
 167              "id"    => $message["message_id"],
 168              "forum" => $message["forum_id"],
 169          )));
 170          phorum_user_addpost();
 171      }
 172  
 173      // Actions for messages which are approved.
 174      if ($message["status"] > 0)
 175      {
 176          // Update forum statistics.
 177          phorum_db_update_forum_stats(false, 1, $message["datestamp"]);
 178  
 179          // Mail subscribed users.
 180          phorum_email_notice($message);
 181      }
 182  
 183      // Mail moderators.
 184      if ($PHORUM["email_moderators"] == PHORUM_EMAIL_MODERATOR_ON) {
 185          phorum_email_moderators($message);
 186      }
 187  
 188      // Run after post mods.
 189      $message = phorum_hook("post_post", $message);
 190  
 191      // Posting is completed. Take the user back to the forum.
 192      if ($PHORUM["redirect_after_post"] == "read")
 193      {
 194          $not_viewable =
 195              $message["status"] != PHORUM_STATUS_APPROVED &&
 196              !$PHORUM["DATA"]["MODERATOR"];
 197  
 198          // To the end of the thread for reply messages.
 199          if (isset($top_parent)) {
 200              if ($not_viewable) {
 201                  $redir_url = phorum_get_url(
 202                      PHORUM_READ_URL, $message["thread"]
 203                  );
 204              } else {
 205                  $readlen = $PHORUM["read_length"];
 206                  $pages = ceil(($top_parent["thread_count"]+1) / $readlen);
 207  
 208                  if ($pages > 1) {
 209                      $redir_url = phorum_get_url(
 210                          PHORUM_READ_URL, $message["thread"],
 211                          $message["message_id"], "page=$pages"
 212                      );
 213                  } else {
 214                      $redir_url = phorum_get_url(
 215                          PHORUM_READ_URL, $message["thread"],
 216                          $message["message_id"]
 217                      );
 218                  }
 219  
 220                  // wrap redirect because of an MSIE bug.
 221                  // See the comments in redirect.php why we need this hack.
 222                  $redir_url = phorum_get_url(PHORUM_REDIRECT_URL, 'phorum_redirect_to=' . urlencode($redir_url));
 223              }
 224  
 225          // This is a thread starter message.
 226          } else {
 227              $redir_url = $not_viewable
 228                         ? phorum_get_url(PHORUM_LIST_URL)
 229                         : phorum_get_url(PHORUM_READ_URL, $message["thread"]);
 230          }
 231  
 232      }
 233      else
 234      {
 235          $redir_url = phorum_get_url(PHORUM_LIST_URL);
 236      }
 237  
 238      phorum_redirect_by_url($redir_url);
 239  
 240      return;
 241  }
 242  
 243  // If we get here, the posting was not successful. The return value from
 244  // the post function is 0 in case of duplicate posting and FALSE in case
 245  // a database problem occured.
 246  
 247  // Restore the original message.
 248  $message = $message_copy;
 249  
 250  // Setup the data for displaying an error to the user.
 251  // The fallback code for determining what language string to use is there
 252  // because the duplicate posting error string was added between minor versions.
 253  $PHORUM["DATA"]["ERROR"] = $PHORUM["DATA"]["LANG"]["PostErrorOccured"];
 254  if ($success === 0 && isset($PHORUM["DATA"]["LANG"]["PostErrorDuplicate"])) {
 255      $PHORUM["DATA"]["ERROR"] = $PHORUM["DATA"]["LANG"]["PostErrorDuplicate"];
 256  }
 257  
 258  $error_flag = true;
 259  
 260  ?>


Généré le : Thu Nov 29 12:22:27 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics