PageRenderTime 43ms CodeModel.GetById 14ms app.highlight 21ms RepoModel.GetById 2ms app.codeStats 0ms

/post.php

https://gitlab.com/VoyaTrax/vtforum
PHP | 278 lines | 191 code | 29 blank | 58 comment | 62 complexity | 72733811ac833186de4e2531fd9fb846 MD5 | raw file
  1<?php
  2// $Id: post.php,v 1.5 2005/02/10 19:04:21 gij 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';
 33include_once XOOPS_ROOT_PATH.'/modules/vtforum/class/class.forumposts.php';
 34
 35// get real topic_id, forum and CHECK THE PRIVILEGES
 36if( ! empty( $_POST['post_id'] ) ) {
 37
 38	// EDIT
 39	$forumpost = new ForumPosts( intval( $_POST['post_id'] ) ) ;
 40	$post_id = $forumpost->postid() ;
 41	if( empty( $post_id ) ) {
 42		die(_MD_VTFORUM_ERRORPOST);
 43	}
 44	if( $forumpost->islocked() ) {
 45		die(_MD_VTFORUM_TOPICLOCKED);
 46	}
 47	$topic_id = $forumpost->topic() ;
 48	$forum = $forumpost->forum() ;
 49	$pid = 0 ;
 50	$isedit = 1 ;
 51
 52	if( ! is_object( $xoopsUser ) || ! ( $xoopsUser->isAdmin() || $forumpost->uid() == $xoopsUser->getVar("uid") || vtforum_is_moderator($forum, $xoopsUser->getVar("uid")) ) ) {
 53		die(_MD_VTFORUM_EDITNOTALLOWED);
 54	}
 55
 56} else if( ! empty( $_POST['pid'] ) ) {
 57	// REPLY
 58	$parent_post = new ForumPosts( intval( $_POST['pid'] ) ) ;
 59	$pid = $parent_post->postid() ;
 60	if( empty( $pid ) ) {
 61		die(_MD_VTFORUM_ERRORPOST);
 62	}
 63	if( $parent_post->islocked() ) {
 64		die(_MD_VTFORUM_TOPICLOCKED);
 65	}
 66	$topic_id = $parent_post->topic() ;
 67	$forum = $parent_post->forum() ;
 68	$post_id = 0 ;
 69} else {
 70	// NEW
 71	$topic_id = 0 ;
 72	$forum = intval( @$_POST['forum'] ) ;
 73	$post_id = 0 ;
 74	$pid = 0 ;
 75}
 76
 77
 78if( empty( $forum ) ) {
 79	die(_MD_VTFORUM_ERRORFORUM);
 80}
 81
 82
 83$sql = "SELECT forum_type, forum_name, forum_access, allow_html, allow_sig, posts_per_page, hot_threshold, topics_per_page FROM ".$xoopsDB->prefix("vtforum_forums")." WHERE forum_id = ".$forum;
 84if ( !$result = $xoopsDB->query($sql) ) {
 85	die(_MD_VTFORUM_ERROROCCURED);
 86}
 87$forumdata = $xoopsDB->fetchArray($result);
 88
 89// GIJ Patch
 90if( empty( $forumdata['allow_html'] ) ) $_POST['nohtml'] = 1 ;
 91
 92// CHECK ACCESS RIGHTS BY FORUM TYPE 
 93if ( $forumdata['forum_type'] == 1 ) {
 94// To get here, we have a logged-in user. So, check whether that user is allowed to view
 95// this private forum.
 96	$accesserror = 0;
 97	if ( $xoopsUser ) {
 98		if ( !$xoopsUser->isAdmin($xoopsModule->mid()) ) {
 99			if ( !vtforum_check_priv_forum_post($xoopsUser->uid(), $_POST['forum']) ) {
100				$accesserror = 1;
101			}
102		}
103	} else {
104		$accesserror = 1;
105	}
106
107	if ( $accesserror == 1 ) {
108		die(_MD_VTFORUM_NORIGHTTOPOST);
109	}
110
111	require_once dirname(__FILE__).'/include/perm_functions.php' ;
112	$users2notify = get_users_can_read_forum( $forum ) ;
113	if( empty( $users2notify ) ) $users2notify = array( 0 ) ;
114
115} else {
116	$accesserror = 0;
117	if ( $forumdata['forum_access'] == 3 ) {
118		if ( $xoopsUser ) {
119			if ( !$xoopsUser->isAdmin($xoopsModule->mid()) ) {
120				if ( !vtforum_is_moderator($forum, $xoopsUser->uid()) ) {
121					$accesserror = 1;
122				}
123			}
124		} else {
125			$accesserror = 1;
126		}
127	} elseif ( $forumdata['forum_access'] == 1 && !$xoopsUser ) {
128		$accesserror = 1;
129	}
130	if ( $accesserror == 1 ) {
131		die(_MD_VTFORUM_NORIGHTTOPOST);
132	}
133
134	$users2notify = array() ;
135}
136
137
138
139if ( !empty($_POST['contents_preview']) ) {
140	include XOOPS_ROOT_PATH."/header.php";
141	echo"<table width='100%' border='0' cellspacing='1' class='outer'><tr><td>";
142	$myts =& MyTextSanitizer::getInstance();
143	$p_subject = $myts->makeTboxData4Preview($_POST['subject']);
144	$p_message = $myts->previewTarea( $_POST['message'] , intval( ! @$_POST['nohtml'] ) , intval( ! @$_POST['nosmiley'] ) , 1 , @$GLOBALS['xoopsModuleConfig']['vtforum_allow_textimg'] ) ; // GIJ
145	/*
146	$nosmiley = !empty($_POST['nosmiley']) ? 1 : 0;
147	$nohtml = !empty($_POST['nohtml']) ? 1 : 0;
148	if ( $nosmiley && $nohtml ) {
149		$p_message = $myts->makeTareaData4Preview($_POST['message'],0,0,1);
150	} elseif ( $nohtml ) {
151		$p_message = $myts->makeTareaData4Preview($_POST['message'],0,1,1);
152	} elseif ( $nosmiley ) {
153		$p_message = $myts->makeTareaData4Preview($_POST['message'],1,0,1);
154	} else {
155		$p_message = $myts->makeTareaData4Preview($_POST['message'],1,1,1);
156	}
157	*/
158	themecenterposts($p_subject,$p_message);
159	echo "<br />";
160	$subject = $myts->makeTboxData4PreviewInForm(@$_POST['subject']);
161	$message = $myts->makeTareaData4PreviewInForm(@$_POST['message']);
162	$hidden = $myts->makeTboxData4PreviewInForm(@$_POST['hidden']);
163	$notify = !empty($_POST['notify']) ? 1 : 0;
164
165	$guestName = $myts->makeTboxData4PreviewInForm(@$_POST['guestName']); // Ryuji_edit(2003-05-06)
166
167	$attachsig = !empty($_POST['attachsig']) ? 1 : 0;
168	$icon = preg_match( '/^icon[1-7]\.gif$/' , @$_POST['icon'] ) ? $_POST['icon'] : '' ;
169	$solved = empty( $_POST['solved'] ) ? 0 : 1 ;
170	$formTitle = _MD_VTFORUM_FORMTITLEINPREVIEW ;
171	include XOOPS_ROOT_PATH.'/modules/vtforum/include/forumform.inc.php';
172	echo"</td></tr></table>";
173
174} else {
175
176	//Ryuji_edit(2003-05-06)
177	if((isset($_POST['message']))&&(!empty ($_POST['guestName']))){
178		$_POST['message'] = sprintf(_MD_VTFORUM_FMT_GUESTSPOSTHEADER,$_POST['guestName']).$_POST['message'];
179	}
180	
181	if( ! is_object( @$forumpost ) ) {
182		$isreply = 0;
183		$isnew = 1;
184		if ( $xoopsUser && empty($_POST['noname']) ) {
185			$uid = $xoopsUser->getVar("uid");
186		} else {
187			if ( $forumdata['forum_access'] == 2 ) {
188				$uid = 0;
189			} else {
190				die(_MD_VTFORUM_ANONNOTALLOWED);
191			}
192		}
193		$forumpost = new ForumPosts();
194		$forumpost->setForum($forum);
195		if ( $pid > 0 ) {
196			$forumpost->setParent($pid);
197			$isreply = 1;
198		}
199		if ( $topic_id > 0 ) {
200			$forumpost->setTopicId($topic_id);
201		}
202		$forumpost->setIp($_SERVER['REMOTE_ADDR']);
203		$forumpost->setUid($uid);
204	}
205	$subject = xoops_trim(@$_POST['subject']);
206	$subject = ($subject == '') ? _NOTITLE : $subject;
207	$icon = preg_match( '/^icon[1-7]\.gif$/' , @$_POST['icon'] ) ? $_POST['icon'] : '' ;
208	$solved = empty( $_POST['solved'] ) ? 0 : 1 ;
209	$forumpost->setSubject($subject);
210	$forumpost->setText(@$_POST['message']);
211	$forumpost->setNohtml(@$_POST['nohtml']);
212	$forumpost->setNosmiley(@$_POST['nosmiley']);
213	$forumpost->setIcon($icon);
214	$forumpost->setSolved(@$_POST['solved']);
215	$forumpost->setAttachsig(@$_POST['attachsig']);
216	if (!$postid = $forumpost->store()) {
217		include_once(XOOPS_ROOT_PATH.'/header.php');
218		xoops_error('Could not insert forum post');
219		include_once(XOOPS_ROOT_PATH.'/footer.php');
220		exit();
221	}
222	if (is_object($xoopsUser) && !empty($isnew)) {
223		$xoopsUser->incrementPost();
224	}
225
226	// set u2t_marked
227	$uid = is_object( @$xoopsUser ) ? $xoopsUser->getVar('uid') : 0 ;
228	$topic_id = $forumpost->topic() ;
229	if( ! empty( $xoopsModuleConfig['vtforum_use_solved'] ) && $uid > 0 ) {
230		$xoopsDB->query( "UPDATE ".$xoopsDB->prefix("vtforum_users2topics")." SET u2t_marked=1 , u2t_time=".time()." WHERE uid='$uid' AND topic_id='$topic_id'" ) ;
231		if( ! $xoopsDB->getAffectedRows() ) $xoopsDB->query( 'INSERT INTO '.$xoopsDB->prefix('vtforum_users2topics')." SET uid='$uid',topic_id='$topic_id',u2t_marked=1 , u2t_time=".time() ) ;
232	}
233
234	// RMV-NOTIFY
235	// Define tags for notification message
236	$tags = array();
237	$tags['THREAD_NAME'] = $_POST['subject'];
238	$tags['THREAD_URL'] = XOOPS_URL . "/modules/" . $xoopsModule->dirname() . "/viewtopic.php?post_id=$postid&topic_id=" . $forumpost->topic();
239	$tags['POST_URL'] = $tags['THREAD_URL'] . '#forumpost' . $postid;
240	include_once XOOPS_ROOT_PATH.'/modules/vtforum/include/notification.inc.php';
241	$forum_info = vtforum_notify_iteminfo ('forum', $forum);
242	$tags['FORUM_NAME'] = $forum_info['name'];
243	$tags['FORUM_URL'] = $forum_info['url'];
244	$notification_handler =& xoops_gethandler('notification');
245	if (!empty($isnew)) {
246		if (empty($isreply)) {
247			// Notify of new thread
248			$notification_handler->triggerEvent('forum', $forum, 'new_thread', $tags , $users2notify );
249		} else {
250			// Notify of new post
251			$notification_handler->triggerEvent('thread', $topic_id, 'new_post', $tags , $users2notify );
252		}
253		$notification_handler->triggerEvent('global', 0, 'new_post', $tags , $users2notify );
254		$notification_handler->triggerEvent('forum', $forum, 'new_post', $tags , $users2notify );
255		$myts =& MyTextSanitizer::getInstance();
256		$tags['POST_CONTENT'] = $myts->stripSlashesGPC($_POST['message']);
257		$tags['POST_NAME'] = $myts->stripSlashesGPC($_POST['subject']);
258		$notification_handler->triggerEvent('global', 0, 'new_fullpost', $tags , $users2notify );
259	}
260
261	// If user checked notification box, subscribe them to the
262	// appropriate event; if unchecked, then unsubscribe
263
264	if (!empty($xoopsUser) && !empty($xoopsModuleConfig['notification_enabled'])) {
265		if (!empty($_POST['notify'])) {
266			$notification_handler->subscribe('thread', $forumpost->getTopicId(), 'new_post');
267		} else {
268			$notification_handler->unsubscribe('thread', $forumpost->getTopicId(), 'new_post');
269		}
270	}
271
272	$post_id = $forumpost->postid();
273	redirect_header( XOOPS_URL."/modules/vtforum/viewtopic.php?topic_id=".$forumpost->topic()."&amp;post_id=".$forumpost->postid()."&amp;viewmode=$viewmode&amp;order=$order#forumpost".$forumpost->postid() , 2 , empty( $isedit ) ? _MD_VTFORUM_THANKSSUBMIT : _MD_VTFORUM_THANKSEDIT ) ;
274	exit ;
275}
276include XOOPS_ROOT_PATH.'/footer.php';
277
278?>