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