[ 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_edit.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  // Create a message which can be used by the database library.
  26  $dbmessage = array(
  27      "message_id"    => $message["message_id"],
  28      "thread"        => $message["thread"],
  29      "parent_id"     => $message["parent_id"],
  30      "forum_id"      => $message["forum_id"],
  31      "author"        => $message["author"],
  32      "subject"       => $message["subject"],
  33      "email"         => $message["email"],
  34      "status"        => $message["status"],
  35      "closed"        => ($message["allow_reply"])?0:1,
  36      "body"          => $message["body"],
  37      "meta"          => $message["meta"],
  38  );
  39  
  40  // Update sort setting, if allowed. This can only be done
  41  // when editing the thread starter message.
  42  if ( $message["parent_id"]==0 ) {
  43  
  44      if ($PHORUM["DATA"]["OPTION_ALLOWED"]["sticky"] && $message["special"]=="sticky") {
  45          $dbmessage["sort"] = PHORUM_SORT_STICKY;
  46      } elseif ($PHORUM["DATA"]["OPTION_ALLOWED"]["announcement"] && $message["special"] == "announcement") {
  47          $dbmessage["forum_id"] = $PHORUM["vroot"] ? $PHORUM["vroot"] : 0;
  48          $dbmessage["sort"] = PHORUM_SORT_ANNOUNCEMENT;
  49      } else {
  50          // Not allowed to edit. Keep existing sort value.
  51          switch ($message["special"]) {
  52              case "sticky": $sort = PHORUM_SORT_STICKY; break;
  53              case "announcement": $sort = PHORUM_SORT_ANNOUNCEMENT; break;
  54              default: $sort = PHORUM_SORT_DEFAULT; break;
  55          }
  56          $dbmessage["sort"] = $sort;
  57      }
  58  
  59  } else {
  60  
  61      // set some key fields to the same values as the first message in the thread
  62      $dbmessage["forum_id"] = $top_parent["forum_id"];
  63      $dbmessage["sort"] = $top_parent["sort"];
  64  
  65  }
  66  
  67  // Update the editing info in the meta data.
  68  $dbmessage["meta"]["show_signature"] = $message["show_signature"];
  69  $dbmessage["meta"]["edit_count"] =
  70      isset($message["meta"]["edit_count"])
  71      ? $message["meta"]["edit_count"]+1 : 1;
  72  $dbmessage["meta"]["edit_date"] = time();
  73  $dbmessage["meta"]["edit_username"] = $PHORUM["user"]["username"];
  74  
  75  // Update attachments in the meta data, link active attachments
  76  // to the message and delete stale attachments.
  77  $dbmessage["meta"]["attachments"] = array();
  78  foreach ($message["attachments"] as $info)
  79  {
  80      if ($info["keep"])
  81      {
  82          // Because there might be inconsistencies in the list due to going
  83          // backward in the browser after deleting attachments, a check is
  84          // needed to see if the attachments are really in the database.
  85          if (! phorum_db_file_get($info["file_id"])) continue;
  86  
  87          $dbmessage["meta"]["attachments"][] = array(
  88              "file_id" => $info["file_id"],
  89              "name"    => $info["name"],
  90              "size"    => $info["size"],
  91          );
  92  
  93          phorum_db_file_link(
  94              $info["file_id"],
  95              $message["message_id"],
  96              PHORUM_LINK_MESSAGE
  97          );
  98      } else {
  99          phorum_db_file_delete($info["file_id"]);
 100      }
 101  }
 102  if (!count($dbmessage["meta"]["attachments"])) {
 103      unset($dbmessage["meta"]["attachments"]);
 104  }
 105  
 106  // Update the data in the database and run pre and post editing hooks.
 107  $dbmessage = phorum_hook("pre_edit", $dbmessage);
 108  phorum_db_update_message($message["message_id"], $dbmessage);
 109  phorum_hook("post_edit", $dbmessage);
 110  
 111  // Update children to the same sort setting and forum_id.
 112  // The forum_id update is needed for switching between
 113  // announcements and other types of messages.
 114  if (! $message["parent_id"] &&
 115      $origmessage["sort"] != $dbmessage["sort"])
 116  {
 117      $messages = phorum_db_get_messages($message["thread"], 0);
 118      unset($messages["users"]);
 119      foreach($messages as $message_id => $msg){
 120          if($msg["sort"]!=$dbmessage["sort"] ||
 121             $msg["forum_id"] != $dbmessage["forum_id"]) {
 122              $msg["sort"]=$dbmessage["sort"];
 123              $msg["forum_id"]=$dbmessage["forum_id"];
 124              phorum_db_update_message($message_id, $msg);
 125          }
 126      }
 127  
 128      if($dbmessage["sort"] == PHORUM_SORT_ANNOUNCEMENT || $origmessage["sort"] == PHORUM_SORT_ANNOUNCEMENT) {
 129  
 130          // recalculating the newflags
 131          $thread_message_ids = array_keys($messages);
 132  
 133          phorum_db_newflag_update_forum($thread_message_ids);
 134  
 135      }
 136  
 137      // The forum stats have to be updated. Announcements aren't
 138      // counted in the thread_count, so if switching to or
 139      // from announcement, the thread_count will change.
 140      phorum_db_update_forum_stats(true);
 141  }
 142  
 143  // Update all thread messages to the same closed setting.
 144  if (! $message["parent_id"] &&
 145      $origmessage["closed"] != $dbmessage["closed"]) {
 146      if ($dbmessage["closed"]) {
 147          phorum_db_close_thread($message["thread"]);
 148      } else {
 149          phorum_db_reopen_thread($message["thread"]);
 150      }
 151  }
 152  
 153  // Update thread info.
 154  phorum_update_thread_info($message['thread']);
 155  
 156  // Update thread subscription or unsubscription.
 157  if ($message["user_id"])
 158  {
 159      if ($message["email_notify"])
 160      {
 161          phorum_user_subscribe(
 162              $message["user_id"], $PHORUM["forum_id"],
 163              $message["thread"], PHORUM_SUBSCRIPTION_MESSAGE
 164          );
 165      } else {
 166          phorum_user_unsubscribe(
 167              $message["user_id"],
 168              $message["thread"],
 169              $message["forum_id"]
 170          );
 171      }
 172  }
 173  
 174  $PHORUM["posting_template"] = "message";
 175  $PHORUM["DATA"]["MESSAGE"] = $PHORUM["DATA"]["LANG"]["MsgModEdited"];
 176  $PHORUM['DATA']["BACKMSG"] = $PHORUM['DATA']["LANG"]["BackToThread"];
 177  $PHORUM["DATA"]["URL"]["REDIRECT"] = phorum_get_url(
 178      PHORUM_READ_URL,
 179      $message["thread"],
 180      $message["message_id"]
 181  );
 182  
 183  ?>


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