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

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