Source of trunk/reply.php at revision 430 (08/29/2009 9:08:47, 6466 bytes, 200 lines, language: php) [download]:

1
<?php
2
3
/*
4
** Reply Functions
5
** for CodewiseBlog Multi-User
6
**
7
** by William R. Fraser <wrf@codewise.org>
8
** Copyright (c) 2005-2008 Codewise.org
9
*/
10
11
/*
12
** This file is part of CodewiseBlog
13
**
14
** CodewiseBlog is free software; you can redistribute it and/or modify
15
** it under the terms of the GNU General Public License as published by
16
** the Free Software Foundation; either version 2 of the License, or
17
** (at your option) any later version.
18
**
19
** CodewiseBlog is distributed in the hope that it will be useful,
20
** but WITHOUT ANY WARRANTY; without even the implied warranty of
21
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
** GNU General Public License for more details.
23
**
24
** You should have received a copy of the GNU General Public License
25
** along with CodewiseBlog; if not, write to the Free Software
26
** Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
27
*/
28
29
function show_reply_form($tid$preview_data ""$text ""$text_filter_msg "")
30
{
31
    global $db$ALLOWED_TAGS$BLOGINFO$TITLE;
32
33
    $q $db->issue_query("SELECT * FROM topics WHERE tid = '$tid' AND blogid = '" BLOGID "'");
34
35
    if($db->num_rows[$q] == 0)
36
    {
37
        echo "no such topic";
38
        return;
39
    }
40
41
    $topic $db->fetch_row($q0L1SQL_ASSOC);
42
43
    $TITLE $BLOGINFO['title'] . " :: Commenting on '" $topic['title'] . "'";
44
45
    $out display_topic($topic);
46
    //display_main_post($topic, TRUE);
47
48
    $q $db->issue_query("SELECT * FROM replies WHERE tid = '$tid' AND blogid = '" BLOGID "' ORDER BY timestamp DESC LIMIT 5");
49
50
    if($db->num_rows[$q] > 0)
51
    {
52
        $out .= skinvoodoo("topic""last_comments", array("num" => $db->num_rows[$q]));
53
54
        $data $db->fetch_all($q);
55
        $data array_reverse($data);
56
57
        foreach($data as $row)
58
            $out .= display_post($row);
59
    }
60
61
    if($preview_data !== "")
62
    {
63
        $preview_data['pid'] = "0";
64
        $out .= display_post($preview_dataTRUE);
65
    } else {
66
        if(is_numeric($_GET['ref']))
67
            $text "@{$_GET['ref']}: ";
68
        else
69
            $text "";
70
    }
71
72
    $tags "";
73
    foreach($ALLOWED_TAGS as $name => $attribs)
74
    {
75
        $tags .= "&lt;$name";
76
        if(count($attribs))
77
        {
78
            foreach($attribs as $attrib)
79
                $tags .= "&nbsp;$attrib=\"\"";
80
        }
81
        $tags .= "&gt; ";
82
    }
83
84
    if(IMAGEVERIFY)
85
    {
86
        // image verification id
87
        $ivid genivid();
88
    } else {
89
        $ivid NULL;
90
    }
91
92
    return $out skinvoodoo("replyform""", array(
93
        "form_url" => INDEX_URL "?do_reply=$tid#previewcomment",
94
        "name" => $_SESSION['postername'],
95
        "tripcode" => $_SESSION['tripcode'],
96
        "tripcode_help_link" => INDEX_URL "?tid=1#tripcodes"//oo
97
        "link" => ($_SESSION['posterlink'] ? $_SESSION['posterlink'] : "http://"),
98
        "text" => htmlspecialchars($text),
99
        "allowed_tags" => $tags,
100
        "text_filter_msg" => $text_filter_msg === "" "" $text_filter_msg,
101
        "imageverify" => HTTP.BASE_DOMAIN.INSTALLED_PATH."imageverify.php?id=$ivid",
102
        "ivid" => $ivid,
103
        "terms" => (file_exists(FSPATH."/TERMS") ? HTTP.BASE_DOMAIN.INSTALLED_PATH."TERMS" NULL),
104
    ));
105
106
// end of show_reply_form()
107
108
function process_reply_form($tid)
109
{
110
    global $db;
111
112
    $name strip_tags($_POST['name']);
113
    $tripcode $_POST['tripcode'];
114
    $link strip_tags($_POST['link']);
115
    $text_filter in_text_filter($_POST['text']);
116
    $timestamp time();
117
118
    if(is_array($text_filter))
119
    {
120
        $text $text_filter[0];
121
        $text_filter_msg $text_filter[1];
122
    } else {
123
        $text $text_filter;
124
        $text_filter_msg "";
125
    }
126
127
    if($link == "http://")
128
        $link null;
129
    elseif(strpos($link"http://") !== 0)
130
        $link "http://" $link;
131
132
    $_SESSION['postername'] = $name;
133
    $_SESSION['posterlink'] = $link;
134
    $_SESSION['tripcode']   = $tripcode;
135
136
    if(empty($name))
137
        $name ANONYMOUS_NAME;
138
139
    $ip $_SERVER['REMOTE_ADDR'];
140
141
    // make sure we get the client's IP if we're using mod_rewrite to proxy the request
142
    if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
143
        $ip .= "::".$_SERVER['HTTP_X_FORWARDED_FOR'];
144
145
    $data = array
146
    (
147
        "blogid" => BLOGID,
148
        "tid" => $tid,
149
        "name" => $name,
150
        "tripcode" => tripcode($tripcode),
151
        "timestamp" => $timestamp,
152
        "link" => $link,
153
        "text" => $text,
154
        "extra" => "ip: $ip\nuseragent: " $_SERVER['HTTP_USER_AGENT'] . "\n",
155
    );
156
157
    if($_POST['preview'] == "preview" || $text_filter_msg)
158
    {
159
        return show_reply_form($data['tid'], $data$_POST['text'], $text_filter_msg);
160
    }
161
162
    if(IMAGEVERIFY)
163
    {
164
        $q $db->issue_query("SELECT text FROM imageverify WHERE id = ".$db->prepare_value($_POST['ivid']));
165
        if ($db->num_rows[$q] > 0) {
166
            $imagetext $db->fetch_var($q);
167
            $db->issue_query("DELETE FROM imageverify WHERE id = ".$db->prepare_value($_POST['ivid']));
168
        } else {
169
            return show_reply_form($data['tid'], $data$_POST['text'], "Invalid imageverify parameters.");
170
        }
171
172
        if (strtolower($_POST['imageverify']) != strtolower($imagetext)) {
173
            return show_reply_form($data['tid'], $data$_POST['text'], "You didn't correctly type the letters in the image.<br />Try again.");
174
        }
175
    }
176
177
    if(empty($text))
178
    {
179
        return show_reply_form($data['tid'], $data$_POST['text'], "Your comment cannot be empty.<br />Please go back and fix this.");
180
    }
181
182
    $db->insert("replies"$data);
183
    $q $db->issue_query("SELECT pid FROM replies WHERE timestamp = " $db->prepare_value($timestamp) . " AND blogid = '" BLOGID "'");
184
    $pid $db->fetch_var($q);
185
186
    $topic_title $db->fetch_var($db->issue_query("SELECT title FROM topics WHERE tid = " $db->prepare_value($data['tid']) . " AND blogid = '" BLOGID "'"));
187
188
    if(EMAIL)
189
    {
190
        $message $data['name'] . " has posted a comment on \"$topic_title\":\n" INDEX_URL "?tid={$data['tid']}&pid=$pid";
191
        mailADMIN_EMAIL"Blog Comment"$message"From: ".BASE_DOMAIN." <nobody@".BASE_DOMAIN.">");
192
    }
193
194
    return skinvoodoo("error""notify", array("message" => "Your comment has been successfully recorded.<br />"
195
        "<a href=\"" INDEX_URL "?tid=$tid#pid$pid\">Click here</a> to go to your comment."));
196
197
// end of process_reply_form()
198
199
?>
200

powered by Codewise Manager v0.1-DEV :: 57.79ms, 6 ops, 3 queries