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
// 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.
99
$message["meta"]["attachments"] = array();
100
foreach ($message["attachments"] as $info) {
101
    if ($info["keep"]) {
102
        $message["meta"]["attachments"][] = array(
103
            "file_id"   => $info["file_id"],
104
            "name"      => $info["name"],
105
            "size"      => $info["size"],
106
        );
107
    }
108
}
109
if (!count($message["meta"]["attachments"])) {
110
    unset($message["meta"]["attachments"]);
111
}
112
 
113
// Keep a copy of the message we have got now.
114
$message_copy = $message;
115
 
116
// Store the message in the database.
117
$success = phorum_db_post_message($message);
118
 
119
if ($success)
120
{
121
    // Handle linking and deleting of attachments to synchronize
122
    // the message attachments with the working copy list
123
    // of attachments.
124
    foreach ($message_copy["attachments"] as $info) {
125
        if ($info["keep"]) {
126
            phorum_db_file_link(
127
                $info["file_id"],
128
                $message["message_id"],
129
                PHORUM_LINK_MESSAGE
130
            );
131
        } else {
132
            phorum_db_file_delete($info["file_id"]);
133
        }
134
    }
135
 
136
    // Retrieve the message again to have it in the correct
137
    // format (otherwise it's a bit messed up in the
138
    // post-function). Do merge back data which is not
139
    // stored in the database, but which we might need later on.
140
    $message = phorum_db_get_message($message["message_id"]);
141
    foreach ($message_copy as $key => $val) {
142
        if (! isset($message[$key])) {
143
            $message[$key] = $val;
144
        }
145
    }
146
 
147
    phorum_update_thread_info($message["thread"]);
148
 
149
    // Subscribe user to the thread if requested.
150
    if ($message["email_notify"] && $message["user_id"]) {
151
        phorum_user_subscribe(
152
            $message["user_id"], $PHORUM["forum_id"],
153
            $message["thread"], PHORUM_SUBSCRIPTION_MESSAGE
154
        );
155
    }
156
 
157
    // Mark own message read.
158
    if ($PHORUM["DATA"]["LOGGEDIN"]) {
159
        phorum_db_newflag_add_read(array(0=>array(
160
            "id"    => $message["message_id"],
161
            "forum" => $message["forum_id"],
162
        )));
163
        phorum_user_addpost();
164
    }
165
 
166
    // Actions for messages which are approved.
167
    if ($message["status"] > 0)
168
    {
169
        // Update forum statistics.
170
        phorum_db_update_forum_stats(false, 1, $message["datestamp"]);
171
 
172
        // Mail subscribed users.
173
        phorum_email_notice($message);
174
    }
175
 
176
    // Mail moderators.
177
    if ($PHORUM["email_moderators"] == PHORUM_EMAIL_MODERATOR_ON) {
178
        phorum_email_moderators($message);
179
    }
180
 
181
    // Run after post mods.
182
    $message = phorum_hook("post_post", $message);
183
 
184
    // Posting is completed. Take the user back to the forum.
185
    if ($PHORUM["redirect_after_post"] == "read")
186
    {
187
        // To the end of the thread.
188
        if (isset($top_parent)) { // not set for top parents themselves.
189
            $readlen = $PHORUM["read_length"];
190
            $pages = ceil(($top_parent["thread_count"]+1) / $readlen);
191
 
192
            if ($pages > 1) {
193
                $redir_url = phorum_get_url(
194
                    PHORUM_READ_URL, $message["thread"],
195
                    $message["message_id"], "page=$pages"
196
                );
197
            } else {
198
                $redir_url = phorum_get_url(
199
                    PHORUM_READ_URL, $message["thread"],
200
                    $message["message_id"]
201
                );
202
            }
203
 
204
            // wrap redirect because of IE
205
            $redir_url = phorum_get_url(PHORUM_REDIRECT_URL, 'phorum_redirect_to=' . urlencode($redir_url));
206
 
207
        } else {
208
 
209
            $redir_url = phorum_get_url( PHORUM_READ_URL, $message["thread"] );
210
        }
211
 
212
    }
213
    else
214
    {
215
        $redir_url = phorum_get_url(PHORUM_LIST_URL);
216
    }
217
 
218
    phorum_redirect_by_url($redir_url);
219
 
220
    return;
221
}
222
 
223
// If we get here, the posting was not successful.
224
// Restore message and setup the data for displaying an error to the user.
225
$message = $message_copy;
226
$PHORUM["DATA"]["ERROR"] = $PHORUM["DATA"]["LANG"]["PostErrorOccured"];
227
$error_flag = true;
228
 
229
?>