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

Revision 948, 11.5 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']) {
35    exit();
36}
37
38foreach (array('forum', 'topic_id', 'post_id', 'order', 'pid') as $getint) {
39    ${$getint} = isset($_POST[$getint]) ? intval($_POST[$getint]) : 0;
40}
41$viewmode = (isset($_POST['viewmode']) && $_POST['viewmode'] != 'flat') ? 'thread' : 'flat';
42if ( empty($forum) ) {
43    redirect_header("index.php", 2, _MD_ERRORFORUM);
44    exit();
45} else {
46    if (!XoopsMultiTokenHandler::quickValidate('newbb_post')) {
47        redirect_header('index.php', 2, _MD_ERROROCCURED);
48        exit();
49    }
50    $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;
51    if ( !$result = $xoopsDB->query($sql) ) {
52        redirect_header('index.php',2,_MD_ERROROCCURED);
53        exit();
54    }
55    $forumdata = $xoopsDB->fetchArray($result);
56    if (empty($forumdata['allow_html'])) {
57         $_POST['nohtml'] = 1;
58    }
59    if ( $forumdata['forum_type'] == 1 ) {
60    // To get here, we have a logged-in user. So, check whether that user is allowed to view
61    // this private forum.
62        $accesserror = 0;
63        if ( $xoopsUser ) {
64            if ( !$xoopsUser->isAdmin($xoopsModule->mid()) ) {
65                if ( !check_priv_forum_auth($xoopsUser->uid(), $_POST['forum'], true) ) {
66                    $accesserror = 1;
67                }
68            }
69        } else {
70            $accesserror = 1;
71        }
72
73        if ( $accesserror == 1 ) {
74            redirect_header("viewforum.php?order=".$order."&amp;viewmode=".$viewmode."&amp;forum=".$forum,2,_MD_NORIGHTTOPOST);
75            exit();
76        }
77    } else {
78        $accesserror = 0;
79        if ( $forumdata['forum_access'] == 3 ) {
80            if ( $xoopsUser ) {
81                if ( !$xoopsUser->isAdmin($xoopsModule->mid()) ) {
82                    if ( !is_moderator($forum, $xoopsUser->uid()) ) {
83                        $accesserror = 1;
84                    }
85                }
86            } else {
87                $accesserror = 1;
88            }
89        } elseif ( $forumdata['forum_access'] == 1 && !$xoopsUser ) {
90            $accesserror = 1;
91        }
92        if ( $accesserror == 1 ) {
93            redirect_header("viewforum.php?order=".$order."&amp;viewmode=".$viewmode."&amp;forum=".$forum,2,_MD_NORIGHTTOPOST);
94            exit();
95        }
96    }
97    if ( !empty($_POST['contents_preview']) ) {
98        include XOOPS_ROOT_PATH."/header.php";
99        echo"<table width='100%' border='0' cellspacing='1' class='outer'><tr><td>";
100        $myts =& MyTextSanitizer::getInstance();
101        $p_subject = $myts->makeTboxData4Preview($_POST['subject']);
102        $dosmiley = empty($_POST['nosmiley']) ? 1 : 0;
103        $dohtml = empty($_POST['nohtml']) ? 1 : 0;
104        $p_message = $myts->makeTareaData4Preview($_POST['message'], $dohtml, $dosmiley, 1);
105
106        themecenterposts($p_subject,$p_message);
107        echo "<br />";
108        $subject = $myts->makeTboxData4PreviewInForm($_POST['subject']);
109        $message = $myts->makeTareaData4PreviewInForm($_POST['message']);
110        $hidden = $myts->makeTboxData4PreviewInForm($_POST['hidden']);
111        $notify = !empty($_POST['notify']) ? 1 : 0;
112        $attachsig = !empty($_POST['attachsig']) ? 1 : 0;
113        include 'include/forumform.inc.php';
114        echo"</td></tr></table>";
115    } else {
116        include_once 'class/class.forumposts.php';
117        if ( !empty($post_id) ) {
118            $editerror = 0;
119            $forumpost = new ForumPosts($post_id);
120            if ( $xoopsUser ) {
121                if ( !$xoopsUser->isAdmin($xoopsModule->mid()) ) {
122                    if ($forumpost->islocked() || ($forumpost->uid() != $xoopsUser->getVar("uid") && !is_moderator($forum, $xoopsUser->getVar("uid")))) {
123                        $editerror = 1;
124                    }
125                }
126            } else {
127                $editerror = 1;
128            }
129            if ( $editerror == 1 ) {
130                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);
131                exit();
132            }
133            $editor = $xoopsUser->getVar("uname");
134            $on_date .= _MD_ON." ".formatTimestamp(time());
135            //$message .= "\n\n<small>[ "._MD_EDITEDBY." ".$editor." ".$on_date." ]</small>";
136        } else {
137            $isreply = 0;
138            $isnew = 1;
139            if ( $xoopsUser && empty($_POST['noname']) ) {
140                $uid = $xoopsUser->getVar("uid");
141            } else {
142                if ( $forumdata['forum_access'] == 2 ) {
143                    $uid = 0;
144                } else {
145                    if ( !empty($topic_id) ) {
146                        redirect_header("viewtopic.php?topic_id=".$topic_id."&amp;order=".$order."&amp;viewmode=".$viewmode."&amp;pid=".$pid."&amp;forum=".$forum,2,_MD_ANONNOTALLOWED);
147                    } else {
148                        redirect_header("viewforum.php?forum=".$forum,2,_MD_ANONNOTALLOWED);
149                    }
150                    exit();
151                }
152            }
153            $forumpost = new ForumPosts();
154            $forumpost->setForum($forum);
155            if (isset($pid) && $pid != "") {
156                $forumpost->setParent($pid);
157            }
158            if (!empty($topic_id)) {
159                $forumpost->setTopicId($topic_id);
160                $isreply = 1;
161            }
162            $forumpost->setIp($_SERVER['REMOTE_ADDR']);
163            $forumpost->setUid($uid);
164        }
165        $subject = xoops_trim($_POST['subject']);
166        $subject = ($subject == '') ? _NOTITLE : $subject;
167        $forumpost->setSubject($subject);
168        $forumpost->setText($_POST['message']);
169        $forumpost->setNohtml($_POST['nohtml']);
170        $forumpost->setNosmiley($_POST['nosmiley']);
171        $forumpost->setIcon($_POST['icon']);
172        $forumpost->setAttachsig($_POST['attachsig']);
173        $forumpost->setResponse($_POST['response']);
174
175        if (!$postid = $forumpost->store()) {
176            include_once(XOOPS_ROOT_PATH.'/header.php');
177            xoops_error('Could not insert forum post');
178            include_once(XOOPS_ROOT_PATH.'/footer.php');
179            exit();
180        }
181        if (is_object($xoopsUser) && !empty($isnew)) {
182            $xoopsUser->incrementPost();
183        }
184        // RMV-NOTIFY
185        // Define tags for notification message
186        $tags = array();
187        $tags['THREAD_NAME'] = $_POST['subject'];
188        $tags['THREAD_URL'] = XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/viewtopic.php?forum=' . $forum . '&amp;post_id='.$postid.'&amp;topic_id=' . $forumpost->topic();
189        $tags['POST_URL'] = $tags['THREAD_URL'] . '#forumpost' . $postid;
190        include_once 'include/notification.inc.php';
191        $forum_info = newbb_notify_iteminfo ('forum', $forum);
192        $tags['FORUM_NAME'] = $forum_info['name'];
193        $tags['FORUM_URL'] = $forum_info['url'];
194       
195        $sql_tmp = "SELECT u.uname FROM xoops_bb_posts p, xoops_users u WHERE p.uid = u.uid AND p.post_id = ".$postid ;
196        if ( $result_tmp = $xoopsDB->query($sql_tmp) ) {
197            $data = $xoopsDB->fetchArray($result_tmp);
198            if($data['uname'] == "") {
199                $tags['USER_NAME'] = "¥²¥¹¥ÈÍÍ";
200            } else {
201                $tags['USER_NAME'] = $data['uname']."ÍÍ";
202            }
203        }
204        $notification_handler =& xoops_gethandler('notification');
205        if (!empty($isnew)) {
206            if (empty($isreply)) {
207                // Notify of new thread
208                $notification_handler->triggerEvent('forum', $forum, 'new_thread', $tags);
209            } else {
210                // Notify of new post
211                $notification_handler->triggerEvent('thread', $topic_id, 'new_post', $tags);
212            }
213            $notification_handler->triggerEvent('global', 0, 'new_post', $tags);
214            $notification_handler->triggerEvent('forum', $forum, 'new_post', $tags);
215            $myts =& MyTextSanitizer::getInstance();
216            $tags['POST_CONTENT'] = $myts->stripSlashesGPC($_POST['message']);
217            $tags['POST_NAME'] = $myts->stripSlashesGPC($_POST['subject']);
218            $notification_handler->triggerEvent('global', 0, 'new_fullpost', $tags);
219        }
220
221        // If user checked notification box, subscribe them to the
222        // appropriate event; if unchecked, then unsubscribe
223
224        if (!empty($xoopsUser) && !empty($xoopsModuleConfig['notification_enabled'])) {
225            if (!empty($_POST['notify'])) {
226                $notification_handler->subscribe('thread', $forumpost->getTopicId(), 'new_post');
227            } else {
228                $notification_handler->unsubscribe('thread', $forumpost->getTopicId(), 'new_post');
229            }
230        }
231
232        if ( $_POST['viewmode'] == "flat" ) {
233            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);
234            exit();
235        } else {
236            $post_id = $forumpost->postid();
237            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);
238            exit();
239        }
240    }
241    include XOOPS_ROOT_PATH.'/footer.php';
242}
243?>
Note: See TracBrowser for help on using the repository browser.