source: temp/test-xoops.ec-cube.net/html/modules/newbb/post.php @ 1319

Revision 1319, 11.6 KB checked in by uehara, 19 years ago (diff)
Line 
1<?php
2// $Id: post.php,v 1.5 2005/09/04 20:46:10 onokazu Exp $
3//  ------------------------------------------------------------------------ //
4//                XOOPS - PHP Content Management System                      //
5//                    Copyright (c) 2000 XOOPS.org                           //
6//                       <http://www.xoops.org/>                             //
7//  ------------------------------------------------------------------------ //
8//  This program is free software; you can redistribute it and/or modify     //
9//  it under the terms of the GNU General Public License as published by     //
10//  the Free Software Foundation; either version 2 of the License, or        //
11//  (at your option) any later version.                                      //
12//                                                                           //
13//  You may not change or alter any portion of this comment or credits       //
14//  of supporting developers from this source code or any supporting         //
15//  source code which is considered copyrighted (c) material of the          //
16//  original comment or credit authors.                                      //
17//                                                                           //
18//  This program is distributed in the hope that it will be useful,          //
19//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
20//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
21//  GNU General Public License for more details.                             //
22//                                                                           //
23//  You should have received a copy of the GNU General Public License        //
24//  along with this program; if not, write to the Free Software              //
25//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
26//  ------------------------------------------------------------------------ //
27// Author: Kazumi Ono (AKA onokazu)                                          //
28// URL: http://www.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ //
29// Project: The XOOPS Project                                                //
30// ------------------------------------------------------------------------- //
31
32include 'header.php';
33
34if(!$_POST['check_spam'] || !mb_ereg("[¤¢-¤ó¥¢-¥ó]", $_POST['message'])) {
35    echo "spam!!";
36    exit();
37}
38
39foreach (array('forum', 'topic_id', 'post_id', 'order', 'pid') as $getint) {
40    ${$getint} = isset($_POST[$getint]) ? intval($_POST[$getint]) : 0;
41}
42$viewmode = (isset($_POST['viewmode']) && $_POST['viewmode'] != 'flat') ? 'thread' : 'flat';
43if ( empty($forum) ) {
44    redirect_header("index.php", 2, _MD_ERRORFORUM);
45    exit();
46} else {
47    if (!XoopsMultiTokenHandler::quickValidate('newbb_post')) {
48        redirect_header('index.php', 2, _MD_ERROROCCURED);
49        exit();
50    }
51    $sql = "SELECT forum_type, forum_name, forum_access, allow_html, allow_sig, posts_per_page, hot_threshold, topics_per_page FROM ".$xoopsDB->prefix("bb_forums")." WHERE forum_id = ".$forum;
52    if ( !$result = $xoopsDB->query($sql) ) {
53        redirect_header('index.php',2,_MD_ERROROCCURED);
54        exit();
55    }
56    $forumdata = $xoopsDB->fetchArray($result);
57    if (empty($forumdata['allow_html'])) {
58         $_POST['nohtml'] = 1;
59    }
60    if ( $forumdata['forum_type'] == 1 ) {
61    // To get here, we have a logged-in user. So, check whether that user is allowed to view
62    // this private forum.
63        $accesserror = 0;
64        if ( $xoopsUser ) {
65            if ( !$xoopsUser->isAdmin($xoopsModule->mid()) ) {
66                if ( !check_priv_forum_auth($xoopsUser->uid(), $_POST['forum'], true) ) {
67                    $accesserror = 1;
68                }
69            }
70        } else {
71            $accesserror = 1;
72        }
73
74        if ( $accesserror == 1 ) {
75            redirect_header("viewforum.php?order=".$order."&amp;viewmode=".$viewmode."&amp;forum=".$forum,2,_MD_NORIGHTTOPOST);
76            exit();
77        }
78    } else {
79        $accesserror = 0;
80        if ( $forumdata['forum_access'] == 3 ) {
81            if ( $xoopsUser ) {
82                if ( !$xoopsUser->isAdmin($xoopsModule->mid()) ) {
83                    if ( !is_moderator($forum, $xoopsUser->uid()) ) {
84                        $accesserror = 1;
85                    }
86                }
87            } else {
88                $accesserror = 1;
89            }
90        } elseif ( $forumdata['forum_access'] == 1 && !$xoopsUser ) {
91            $accesserror = 1;
92        }
93        if ( $accesserror == 1 ) {
94            redirect_header("viewforum.php?order=".$order."&amp;viewmode=".$viewmode."&amp;forum=".$forum,2,_MD_NORIGHTTOPOST);
95            exit();
96        }
97    }
98    if ( !empty($_POST['contents_preview']) ) {
99        include XOOPS_ROOT_PATH."/header.php";
100        echo"<table width='100%' border='0' cellspacing='1' class='outer'><tr><td>";
101        $myts =& MyTextSanitizer::getInstance();
102        $p_subject = $myts->makeTboxData4Preview($_POST['subject']);
103        $dosmiley = empty($_POST['nosmiley']) ? 1 : 0;
104        $dohtml = empty($_POST['nohtml']) ? 1 : 0;
105        $p_message = $myts->makeTareaData4Preview($_POST['message'], $dohtml, $dosmiley, 1);
106
107        themecenterposts($p_subject,$p_message);
108        echo "<br />";
109        $subject = $myts->makeTboxData4PreviewInForm($_POST['subject']);
110        $message = $myts->makeTareaData4PreviewInForm($_POST['message']);
111        $hidden = $myts->makeTboxData4PreviewInForm($_POST['hidden']);
112        $notify = !empty($_POST['notify']) ? 1 : 0;
113        $attachsig = !empty($_POST['attachsig']) ? 1 : 0;
114        include 'include/forumform.inc.php';
115        echo"</td></tr></table>";
116    } else {
117        include_once 'class/class.forumposts.php';
118        if ( !empty($post_id) ) {
119            $editerror = 0;
120            $forumpost = new ForumPosts($post_id);
121            if ( $xoopsUser ) {
122                if ( !$xoopsUser->isAdmin($xoopsModule->mid()) ) {
123                    if ($forumpost->islocked() || ($forumpost->uid() != $xoopsUser->getVar("uid") && !is_moderator($forum, $xoopsUser->getVar("uid")))) {
124                        $editerror = 1;
125                    }
126                }
127            } else {
128                $editerror = 1;
129            }
130            if ( $editerror == 1 ) {
131                redirect_header("viewtopic.php?topic_id=".$topic_id."&amp;post_id=".$post_id."&amp;order=".$order."&amp;viewmode=".$viewmode."&amp;pid=".$pid."&amp;forum=".$forum,2,_MD_EDITNOTALLOWED);
132                exit();
133            }
134            $editor = $xoopsUser->getVar("uname");
135            $on_date .= _MD_ON." ".formatTimestamp(time());
136            //$message .= "\n\n<small>[ "._MD_EDITEDBY." ".$editor." ".$on_date." ]</small>";
137        } else {
138            $isreply = 0;
139            $isnew = 1;
140            if ( $xoopsUser && empty($_POST['noname']) ) {
141                $uid = $xoopsUser->getVar("uid");
142            } else {
143                if ( $forumdata['forum_access'] == 2 ) {
144                    $uid = 0;
145                } else {
146                    if ( !empty($topic_id) ) {
147                        redirect_header("viewtopic.php?topic_id=".$topic_id."&amp;order=".$order."&amp;viewmode=".$viewmode."&amp;pid=".$pid."&amp;forum=".$forum,2,_MD_ANONNOTALLOWED);
148                    } else {
149                        redirect_header("viewforum.php?forum=".$forum,2,_MD_ANONNOTALLOWED);
150                    }
151                    exit();
152                }
153            }
154            $forumpost = new ForumPosts();
155            $forumpost->setForum($forum);
156            if (isset($pid) && $pid != "") {
157                $forumpost->setParent($pid);
158            }
159            if (!empty($topic_id)) {
160                $forumpost->setTopicId($topic_id);
161                $isreply = 1;
162            }
163            $forumpost->setIp($_SERVER['REMOTE_ADDR']);
164            $forumpost->setUid($uid);
165        }
166        //$subject = xoops_trim($_POST['subject']);
167        $subject = ($_POST['subject'] == '') ? _NOTITLE : $subject;
168        $forumpost->setSubject($subject);
169        $forumpost->setText($_POST['message']);
170        $forumpost->setNohtml($_POST['nohtml']);
171        $forumpost->setNosmiley($_POST['nosmiley']);
172        $forumpost->setIcon($_POST['icon']);
173        $forumpost->setAttachsig($_POST['attachsig']);
174        $forumpost->setResponse($_POST['response']);
175
176        if (!$postid = $forumpost->store()) {
177            include_once(XOOPS_ROOT_PATH.'/header.php');
178            xoops_error('Could not insert forum post');
179            include_once(XOOPS_ROOT_PATH.'/footer.php');
180            exit();
181        }
182        if (is_object($xoopsUser) && !empty($isnew)) {
183            $xoopsUser->incrementPost();
184        }
185        // RMV-NOTIFY
186        // Define tags for notification message
187        $tags = array();
188        $tags['THREAD_NAME'] = $_POST['subject'];
189        $tags['THREAD_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/viewtopic.php?forum=' . $forum . '&amp;post_id='.$postid.'&amp;topic_id=' . $forumpost->topic();
190        $tags['POST_URL'] = $tags['THREAD_URL'] . '#forumpost' . $postid;
191        include_once 'include/notification.inc.php';
192        $forum_info = newbb_notify_iteminfo ('forum', $forum);
193        $tags['FORUM_NAME'] = $forum_info['name'];
194        $tags['FORUM_URL'] = $forum_info['url'];
195       
196        $sql_tmp = "SELECT u.uname FROM xoops_bb_posts p, xoops_users u WHERE p.uid = u.uid AND p.post_id = ".$postid ;
197        if ( $result_tmp = $xoopsDB->query($sql_tmp) ) {
198            $data = $xoopsDB->fetchArray($result_tmp);
199            if($data['uname'] == "") {
200                $tags['USER_NAME'] = "¥²¥¹¥ÈÍÍ";
201            } else {
202                $tags['USER_NAME'] = $data['uname']."ÍÍ";
203            }
204        }
205        $notification_handler =& xoops_gethandler('notification');
206        if (!empty($isnew)) {
207            if (empty($isreply)) {
208                // Notify of new thread
209                $notification_handler->triggerEvent('forum', $forum, 'new_thread', $tags);
210            } else {
211                // Notify of new post
212                $notification_handler->triggerEvent('thread', $topic_id, 'new_post', $tags);
213            }
214            $notification_handler->triggerEvent('global', 0, 'new_post', $tags);
215            $notification_handler->triggerEvent('forum', $forum, 'new_post', $tags);
216            $myts =& MyTextSanitizer::getInstance();
217            $tags['POST_CONTENT'] = $myts->stripSlashesGPC($_POST['message']);
218            $tags['POST_NAME'] = $myts->stripSlashesGPC($_POST['subject']);
219            $notification_handler->triggerEvent('global', 0, 'new_fullpost', $tags);
220        }
221
222        // If user checked notification box, subscribe them to the
223        // appropriate event; if unchecked, then unsubscribe
224
225        if (!empty($xoopsUser) && !empty($xoopsModuleConfig['notification_enabled'])) {
226            if (!empty($_POST['notify'])) {
227                $notification_handler->subscribe('thread', $forumpost->getTopicId(), 'new_post');
228            } else {
229                $notification_handler->unsubscribe('thread', $forumpost->getTopicId(), 'new_post');
230            }
231        }
232
233        if ( $_POST['viewmode'] == "flat" ) {
234            redirect_header("viewtopic.php?topic_id=".$forumpost->topic()."&amp;post_id=".$postid."&amp;order=".$order."&amp;viewmode=flat&amp;pid=".$pid."&amp;forum=".$forum."#forumpost".$postid."",2,_MD_THANKSSUBMIT);
235            exit();
236        } else {
237            $post_id = $forumpost->postid();
238            redirect_header("viewtopic.php?topic_id=".$forumpost->topic()."&amp;post_id=".$postid."&amp;order=".$order."&amp;viewmode=thread&amp;pid=".$pid."&amp;forum=".$forum."#forumpost".$postid."",2,_MD_THANKSSUBMIT);
239            exit();
240        }
241    }
242    include XOOPS_ROOT_PATH.'/footer.php';
243}
244?>
Note: See TracBrowser for help on using the repository browser.