Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
831 florian 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"],
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
        $dbmessage["meta"]["attachments"][] = array(
83
            "file_id" => $info["file_id"],
84
            "name"    => $info["name"],
85
            "size"    => $info["size"],
86
        );
87
 
88
        phorum_db_file_link(
89
            $info["file_id"],
90
            $message["message_id"],
91
            PHORUM_LINK_MESSAGE
92
        );
93
    } else {
94
        phorum_db_file_delete($info["file_id"]);
95
    }
96
}
97
if (!count($dbmessage["meta"]["attachments"])) {
98
    unset($dbmessage["meta"]["attachments"]);
99
}
100
 
101
// Update the data in the database and run pre and post editing hooks.
102
$dbmessage = phorum_hook("pre_edit", $dbmessage);
103
phorum_db_update_message($message["message_id"], $dbmessage);
104
phorum_hook("post_edit", $dbmessage);
105
 
106
// Update children to the same sort setting and forum_id.
107
// The forum_id update is needed for switching between
108
// announcements and other types of messages.
109
if (! $message["parent_id"] &&
110
    $origmessage["sort"] != $dbmessage["sort"])
111
{
112
    $messages = phorum_db_get_messages($message["thread"], 0);
113
    unset($messages["users"]);
114
    foreach($messages as $message_id => $msg){
115
        if($msg["sort"]!=$dbmessage["sort"] ||
116
           $msg["forum_id"] != $dbmessage["forum_id"]) {
117
            $msg["sort"]=$dbmessage["sort"];
118
            $msg["forum_id"]=$dbmessage["forum_id"];
119
            phorum_db_update_message($message_id, $msg);
120
        }
121
    }
122
 
123
    // The forum stats have to be updated. Announcements aren't
124
    // counted in the thread_count, so if switching to or
125
    // from announcement, the thread_count will change.
126
    phorum_db_update_forum_stats(true);
127
}
128
 
129
// Update all thread messages to the same closed setting.
130
if (! $message["parent_id"] &&
131
    $origmessage["closed"] != $dbmessage["closed"]) {
132
    if ($dbmessage["closed"]) {
133
        phorum_db_close_thread($message["thread"]);
134
    } else {
135
        phorum_db_reopen_thread($message["thread"]);
136
    }
137
}
138
 
139
// Update thread info.
140
phorum_update_thread_info($message['thread']);
141
 
142
// Update thread subscription or unsubscription.
143
if ($message["user_id"])
144
{
145
    if ($message["email_notify"])
146
    {
147
        phorum_user_subscribe(
148
            $message["user_id"], $PHORUM["forum_id"],
149
            $message["thread"], PHORUM_SUBSCRIPTION_MESSAGE
150
        );
151
    } else {
152
        phorum_user_unsubscribe(
153
            $message["user_id"],
154
            $message["thread"],
155
            $message["forum_id"]
156
        );
157
    }
158
}
159
 
160
$PHORUM["DATA"]["MESSAGE"] = $PHORUM["DATA"]["LANG"]["MsgModEdited"];
161
$PHORUM['DATA']["BACKMSG"] = $PHORUM['DATA']["LANG"]["BackToThread"];
162
$PHORUM["DATA"]["URL"]["REDIRECT"] = phorum_get_url(
163
    PHORUM_READ_URL,
164
    $message["thread"],
165
    $message["message_id"]
166
);
167
 
168
?>