PageRenderTime 56ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/com_joomlaboard/post.php

http://joomlaboard.googlecode.com/
PHP | 948 lines | 878 code | 33 blank | 37 comment | 78 complexity | e2d950835943a7c8fb27c701c2e717d2 MD5 | raw file
  1. <?php
  2. /**
  3. * post.php handles everything related to posts
  4. * @package com_joomlaboard
  5. * @copyright (C) 2000 - 2007 TSMF / Jan de Graaff / All Rights Reserved
  6. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
  7. * @author TSMF
  8. * Joomla! is Free Software
  9. **/
  10. // Dont allow direct linking
  11. defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
  12. // get variables
  13. $action = mosGetParam($_POST , 'action' , '');
  14. $resubject = mosGetParam($_REQUEST, 'resubject' , '');
  15. $replyto = (int) mosGetParam($_REQUEST, 'replyto' , 0);
  16. $ip = $_SERVER["REMOTE_ADDR"]; //ip for floodprotection, post logging, subscriptions, etcetera
  17. $editmode = 0;
  18. $catName = $thisCat->getName();
  19. if ($my->id > 0) {
  20. $my_name = $sbConfig['username'] ? $my->username : $my->name;
  21. $my_email= $my->email;
  22. }
  23. else {
  24. $my_name = '';
  25. $my_email= '';
  26. }
  27. // permissions check
  28. switch (sb_has_post_permission($database,$catid,$replyto,$my->id,$sbConfig['pubwrite'],$is_moderator)) {
  29. case 0:
  30. echo "<p align=\"center\">";
  31. echo _POST_NO_PUBACCESS1."<br />";
  32. echo _POST_NO_PUBACCESS2."<br /><br />";
  33. if ($sbConfig['cb_profile']) {
  34. echo '<a href="'.sefRelToAbs('index.php?option=com_comprofiler&amp;task=registers').'">'._POST_NO_PUBACCESS3.'</a><br /></p>';
  35. }
  36. else {
  37. echo '<a href="'.sefRelToAbs('index.php?option=com_registration&amp;task=register').'">'._POST_NO_PUBACCESS3.'</a><br /></p>';
  38. }
  39. return;
  40. case -1:
  41. echo '<p align="center">' . _GEN_TOPIC ._POST_LOCKED.'<br />';
  42. echo _POST_NO_NEW.'<br /></p>';
  43. return;
  44. case -2:
  45. echo '<p align="center">' . _GEN_FORUM ._POST_LOCKED.'<br />';
  46. echo _POST_NO_NEW.'<br /></p>';
  47. return;
  48. }
  49. // flood protection
  50. $sbConfig['floodprotection'] = (int) $sbConfig['floodprotection'];
  51. if ($sbConfig['floodprotection'] != 0) {
  52. $database->setQuery("select max(time) from #__sb_messages where ip='$ip'");
  53. $lastPostTime=$database->loadResult();
  54. }
  55. if ( ! $is_moderator && $do!='edit' && $sbConfig['floodprotection'] == 1 && ($lastPostTime+$sbConfig['floodprotection']) >= $systime) {
  56. echo _POST_TOPIC_FLOOD1;
  57. echo $sbConfig['floodprotection']." "._POST_TOPIC_FLOOD2."<br />";
  58. echo _POST_TOPIC_FLOOD3;
  59. return;
  60. }
  61. ?>
  62. <table border="0" cellspacing="0" cellpadding="0" width="100%" align="center">
  63. <tr>
  64. <td>
  65. <?php
  66. if ($action=="post"){
  67. ?>
  68. <table border="0" cellspacing="1" cellpadding="3" width="70%" align="center" class="contentpane"><tr><td>
  69. <?php
  70. $parent=(int)$parentid;
  71. $message = isset($_POST['message']) ? trim($_POST['message']) : '';
  72. if (empty($sb_authorname))
  73. {
  74. echo _POST_FORGOT_NAME;
  75. }
  76. else if (empty($subject))
  77. {
  78. echo _POST_FORGOT_SUBJECT;
  79. }
  80. else if (empty($message))
  81. {
  82. echo _POST_FORGOT_MESSAGE;
  83. }
  84. else
  85. {
  86. if ($parent == 0)
  87. $thread = $parent = 0;
  88. $database->setQuery("SELECT id,thread,parent FROM #__sb_messages WHERE id='$parent'");
  89. $database->query();
  90. if ($database->getNumRows() == 0)
  91. {
  92. // bad parent, create a new post
  93. $parent = 0;
  94. $thread = 0;
  95. }
  96. else
  97. {
  98. $database->loadObject($m);
  99. $thread = $m->parent==0?$m->id:$m->thread;
  100. }
  101. if ($catid == 0 )
  102. {
  103. $catid = 1; //make sure there's a proper category
  104. }
  105. if ($attachfile != '' ) {
  106. $noFileUpload=0;
  107. include JB_ABSPATH.'/file_upload.php';
  108. if ($rc==0){
  109. $noFileUpload=1;
  110. }
  111. }
  112. if ($attachimage != '' ) {
  113. $noImgUpload=0;
  114. include JB_ABSPATH.'/image_upload.php';
  115. if ($rc==0){
  116. $noImgUpload=1;
  117. }
  118. }
  119. $messagesubject=$subject;//before we add slashes and all... used later in mail
  120. $sb_authorname=trim(addslashes($sb_authorname));
  121. $subject=trim(htmlspecialchars(addslashes($subject)));
  122. $message=trim(htmlspecialchars(addslashes($message)));
  123. if ($contentURL != "empty") { $message= $contentURL.'\n\n'.$message;}
  124. //parse the message for some preliminary bbcode and stripping of HTML
  125. $message = smile::bbencode_first_pass($message);
  126. $subject = smile::bbencode_first_pass($subject);
  127. //--
  128. $email=trim(addslashes($email));
  129. $topic_emoticon=(int)$topic_emoticon;
  130. $topic_emoticon=$topic_emoticon>7?0:$topic_emoticon;
  131. $posttime=time()+($sbConfig['board_ofset']*3600);
  132. //check if the post must be reviewed by a Moderator prior to showing
  133. //doesn't apply to admin/moderator posts ;-)
  134. $holdPost=0;
  135. if (!$is_moderator){
  136. $database->setQuery("SELECT review FROM #__sb_categories WHERE id=$catid");
  137. $holdPost=$database->loadResult();
  138. }
  139. $database->setQuery("INSERT INTO #__sb_messages (parent,thread,catid,name,userid,email,subject,time,ip,topic_emoticon,hold) VALUES('$parent','$thread','$catid','$sb_authorname','$my_id','$email','$subject','$posttime','$ip','$topic_emoticon','$holdPost')");
  140. if ($database->query())
  141. {
  142. $pid=$database->insertId();
  143. $database->setQuery("INSERT INTO #__sb_messages_text (mesid,message) VALUES('$pid','$message')");
  144. $database->query();
  145. if ($thread==0){
  146. //if thread was zero, we now know to which id it belongs, so we can determine the thread and update it
  147. $database->setQuery("UPDATE #__sb_messages SET thread='$pid' WHERE id='$pid'");
  148. $database->query();
  149. }
  150. //update the user posts count
  151. if ($my->id != 0){
  152. $database->setQuery("UPDATE #__sb_users SET posts=posts+1 WHERE userid='$my->id'");
  153. $database->query();
  154. }
  155. //Update the attachments table if an image has been attached
  156. if ( $imageLocation != "" && ! $noImgUpload)
  157. {
  158. $database->setQuery("INSERT INTO #__sb_attachments (mesid, filelocation) values ('$pid','$imageLocation')");
  159. if (!$database->query()){
  160. echo "<script> alert('Storing image failed: ".$database->getErrorMsg()."'); </script>\n";
  161. }
  162. }
  163. //Update the attachments table if an file has been attached
  164. if ( $fileLocation != "" && ! $noFileUpload)
  165. {
  166. $database->setQuery("INSERT INTO #__sb_attachments (mesid, filelocation) values ('$pid','$fileLocation')");
  167. if (!$database->query()){
  168. echo "<script> alert('Storing file failed: ".$database->getErrorMsg()."'); </script>\n";
  169. }
  170. }
  171. //Now manage the subscriptions (only if subscriptions are allowed)
  172. if($sbConfig['allowsubscriptions'] == 1) {//they're allowed
  173. //get the proper user credentials for each subscription to this topic
  174. if ($thread==0){
  175. $querythread=$pid;
  176. } else {
  177. $querythread=$thread;
  178. }
  179. //clean up the message
  180. $mailmessage=smile::purify($message);
  181. $database->setQuery("SELECT * FROM #__sb_subscriptions AS a"
  182. . "\n LEFT JOIN #__users as u"
  183. . "\n ON a.userid=u.id "
  184. . "\n WHERE a.thread= '$querythread'");
  185. $subsList=$database->loadObjectList();
  186. //construct a useable URL
  187. $messageUrl=sefRelToAbs($mosConfig_live_site."/index.php?option=com_joomlaboard&Itemid=$Itemid&func=view&catid=$catid&id=$pid")."#$pid";
  188. if(count($subsList)>0){//we got more than 0 subscriptions
  189. foreach($subsList as $subs){
  190. $mailsubject = "$_COM_A_NOTIFICATION $board_title";
  191. $msg = "$subs->name,\n";
  192. $msg .= "$_COM_A_NOTIFICATION1 $board_title forum\n";
  193. $msg .= "Subject: '".stripslashes($messagesubject)."' in Forum: '".stripslashes($catName)."'\n";
  194. $msg .= "Posted by: ". stripslashes($sb_authorname) . "\n\n";
  195. $msg .= "$_COM_A_NOTIFICATION2\n";
  196. $msg .= "URL: $messageUrl\n\n";
  197. $msg .= "Post:\n";
  198. $msg .= stripslashes($mailmessage);
  199. $msg .= "\n\n";
  200. $msg .= "$_COM_A_NOTIFICATION3\n";
  201. $msg .= "\n\n\n\n\n";
  202. $msg .= "** Joomlaboard Forum Component by Jan de Graaff **\n";
  203. $msg .= "** the Two Shoes M-Factory - http://www.tsmf.net **";
  204. if($ip != "127.0.0.1" && $my_id != $subs->id){//don't mail yourself
  205. mosmail($sbConfig['email'],"Forum at ". $_SERVER['SERVER_NAME'],$subs->email,$mailsubject,$msg);
  206. }
  207. }
  208. }
  209. }
  210. //Now manage the mail for moderators (only if configured)
  211. if($sbConfig['mailmod'] == '1') {//they're configured
  212. //get the proper user credentials for each moderator for this forum
  213. $database->setQuery("SELECT * FROM #__sb_moderation AS a"
  214. . "\n LEFT JOIN #__users AS u"
  215. . "\n ON a.userid=u.id"
  216. . "\n WHERE a.catid=$catid");
  217. $modsList=$database->loadObjectList();
  218. if(count($modsList)>0){//we got more than 0 moderators eligible for email
  219. foreach($modsList as $mods){
  220. $mailsubject = "$_COM_A_NOTIFICATION $board_title";
  221. $msg = "$mods->name,\n";
  222. $msg .= "$_COM_A_NOT_MOD1 $board_title forum\n";
  223. $msg .= "Subject: '".stripslashes($messagesubject)."' in Forum: '".stripslashes($catName)."'\n";
  224. $msg .= "Posted by: ". stripslashes($sb_authorname) . "\n\n";
  225. $msg .= "$_COM_A_NOT_MOD2\n";
  226. $msg .= "URL: $messageUrl\n\n";
  227. $msg .= "Post:\n";
  228. $msg .= stripslashes($mailmessage);
  229. $msg .= "\n\n";
  230. $msg .= "$_COM_A_NOTIFICATION3\n";
  231. $msg .= "\n\n\n\n\n";
  232. $msg .= "** Joomlaboard Forum Component by TSMF **\n";
  233. $msg .= "** the Two Shoes M-Factory - http://www.tsmf.net **";
  234. if($ip != "127.0.0.1" && $my_id != $mods->id){//don't mail yourself
  235. //Send away
  236. mosmail($sbConfig['email'],"Forum at ". $_SERVER['SERVER_NAME'],$mods->email,$mailsubject,$msg);
  237. }
  238. }
  239. }
  240. }
  241. //now try adding any new subscriptions if asked for by the poster
  242. if($subscribeMe == 1){
  243. if ($thread==0){$sb_thread=$pid;}else{$sb_thread=$thread;}
  244. $database->setQuery("INSERT INTO #__sb_subscriptions (thread,userid) VALUES ('$sb_thread','$my_id')");
  245. if ($database->query()){
  246. echo _POST_SUBSCRIBED_TOPIC."<br /><br />";
  247. }else{
  248. echo _POST_NO_SUBSCRIBED_TOPIC."<br /><br />";
  249. }
  250. }
  251. if($holdPost==1){
  252. echo _POST_SUCCES_REVIEW.' <a href="'.sefRelToAbs('index.php?option=com_joomlaboard&amp;Itemid='.$Itemid.'&amp;func=showcat&catid='.$catid).'">'._GEN_CONTINUE.'</a>.';
  253. }else{
  254. echo '<div align="center">'._POST_SUCCESS_POSTED.'<br /><br />';
  255. echo '<a href="'.sefRelToAbs('index.php?option=com_joomlaboard&amp;Itemid='.$Itemid.'&amp;func=view&catid='.$catid.'&amp;id='.$pid).'#'.$pid.'">'._POST_SUCCESS_VIEW.'</a><br />';
  256. echo '<a href="'.sefRelToAbs('index.php?option=com_joomlaboard&amp;Itemid='.$Itemid.'&amp;func=showcat&catid='.$catid).'">'._POST_SUCCESS_FORUM.'</a><br />';
  257. echo '</div>';
  258. ?>
  259. <script language="javascript">
  260. setTimeout("location='<?php echo sefRelToAbs('index.php?option=com_joomlaboard&Itemid='.$Itemid.'&func=view&catid='.$catid.'&id='.$pid).'#'.$pid;?>'",3500);
  261. </script>
  262. <?php
  263. }
  264. }
  265. else
  266. {
  267. echo _POST_ERROR_MESSAGE;
  268. }
  269. }?>
  270. </td></tr></table>
  271. <?php
  272. }
  273. else if ($action=="cancel") {
  274. echo '<br /><br /><div align="center">'._SUBMIT_CANCEL."</div><br />";
  275. echo '<div align="center">'._SUBMIT_CANCEL.'<br /><br />';
  276. echo '<a href="'.sefRelToAbs('index.php?option=com_joomlaboard&amp;Itemid='.$Itemid.'&amp;func=view&catid='.$catid.'&amp;id='.$pid).'#'.$pid.'">'._POST_SUCCESS_VIEW.'</a><br />';
  277. echo '<a href="'.sefRelToAbs('index.php?option=com_joomlaboard&amp;Itemid='.$Itemid.'&amp;func=showcat&catid='.$catid).'">'._POST_SUCCESS_FORUM.'</a><br />';
  278. echo '</div>';
  279. }
  280. else {
  281. if ($do=="quote") {//reply do quote
  282. $parentid=0;
  283. if ($replyto > 0)
  284. {
  285. $database->setQuery("SELECT #__sb_messages.*,#__sb_messages_text.message FROM #__sb_messages,#__sb_messages_text WHERE id='$replyto' AND mesid='$replyto'");
  286. $database->query();
  287. if ($database->getNumRows() > 0)
  288. {
  289. $database->loadObject($message);
  290. //$message->message=smile::smileReplace($message->message,0);
  291. $table = array_flip(get_html_translation_table(HTML_ENTITIES));
  292. $quote = strtr($message->message, $table);
  293. $htmlText = "[b]".stripslashes($message->name)." "._POST_WROTE.":[/b]\n";
  294. $htmlText .= '[quote]'.$quote."[/quote]";
  295. $quote=smile::sbStripHtmlTags($quote);
  296. //$quote=RTESafe_sb(nl2br($quote));
  297. $resubject = strtr($message->subject, $table);
  298. $resubject = strtolower(substr($resubject,0,strlen(_POST_RE)))==strtolower(_POST_RE)?stripslashes($resubject):_POST_RE.stripslashes($resubject);
  299. //$resubject = htmlspecialchars($resubject);
  300. $resubject=smile::sbStripHtmlTags($resubject);
  301. $parentid = $message->id;
  302. $authorName=$my_name;
  303. }
  304. }
  305. ?>
  306. <form action="<?php echo sefRelToAbs(JB_LIVEURL.'&amp;func=post'); ?>" method="post" name="postform" enctype="multipart/form-data">
  307. <input type="hidden" name="parentid" value="<?php echo $parentid;?>" />
  308. <input type="hidden" name="catid" value="<?php echo $catid;?>" />
  309. <input type="hidden" name="action" value="post" />
  310. <input type="hidden" name="contentURL" value="empty" />
  311. <?php
  312. //get the writing stuff in:
  313. $no_upload="0";//only edit mode should disallow this
  314. include(JB_ABSPATH.'/write.html.php');
  315. //--
  316. }
  317. else if ($do=="reply") {// reply no quote
  318. $parentid=0;
  319. $setFocus=0;
  320. if ($replyto > 0) {
  321. $database->setQuery('SELECT #__sb_messages.*,#__sb_messages_text.message'.
  322. "\n". 'FROM #__sb_messages,#__sb_messages_text'.
  323. "\n". 'WHERE id='.$replyto.' AND mesid='.$replyto);
  324. $database->query();
  325. if ($database->getNumRows() > 0){
  326. $database->loadObject($message);
  327. $table = array_flip(get_html_translation_table(HTML_ENTITIES));
  328. $resubject = htmlspecialchars(strtr($message->subject, $table));
  329. $resubject = strtolower(substr($resubject,0,strlen(_POST_RE)))==strtolower(_POST_RE)?stripslashes($resubject):_POST_RE.stripslashes($resubject);
  330. $parentid = $message->id;
  331. }
  332. }
  333. $htmlText="";
  334. $authorName=$my_name;
  335. ?>
  336. <form action="<?php echo sefRelToAbs('index.php?option=com_joomlaboard&amp;Itemid='.$Itemid . '&amp;func=post'); ?>" method="post" name="postform" enctype="multipart/form-data">
  337. <input type="hidden" name="parentid" value="<?php echo $parentid;?>" />
  338. <input type="hidden" name="catid" value="<?php echo $catid;?>" />
  339. <input type="hidden" name="action" value="post" />
  340. <input type="hidden" name="contentURL" value="empty" />
  341. <?php
  342. //get the writing stuff in:
  343. $no_upload="0";//only edit mode should disallow this
  344. include(JB_ABSPATH.'/write.html.php');
  345. //--
  346. }
  347. else if ($do=="newFromBot") {// The Mosbot "discuss on forums" has detected an unexisting thread and wants to create one
  348. $parentid=0;
  349. $setFocus=0;
  350. // $resubject = base64_decode($resubject); //per mf#6100 -- jdg 16/07/2005
  351. $resubject = base64_decode(strtr($resubject, "()", "+/"));
  352. $resubject = str_replace("%20"," ",$resubject);
  353. $resubject = preg_replace('/%32/','&',$resubject);
  354. $resubject = preg_replace('/%33/',';',$resubject);
  355. $resubject = preg_replace("/\'/",'&#039;',$resubject);
  356. $resubject = preg_replace("/\"/",'&quot;',$resubject);
  357. //$table = array_flip(get_html_translation_table(HTML_ENTITIES));
  358. //$resubject = strtr($resubject, $table);
  359. $fromBot=1; //this new topic comes from the discuss mambot
  360. $authorName=htmlspecialchars($my_name);
  361. $rowid = (int) mosGetParam( $_GET, 'rowid', 0 );
  362. $rowItemid = (int) mosGetParam( $_GET, 'rowItemid', 0 );
  363. if ( $rowItemid ) {
  364. $contentURL=sefRelToAbs('index.php?option=content&task=view&amp;Itemid='.$rowItemid.'&amp;id='.$rowid);
  365. }
  366. else {
  367. $contentURL=sefRelToAbs('index.php?option=content&task=view&amp;Itemid=1&amp;id='.$rowid);
  368. }
  369. $contentURL= _POST_DISCUSS.': [url='.$contentURL.']'.$resubject.'[/url]';
  370. ?>
  371. <form action="<?php echo sefRelToAbs("index.php?option=com_joomlaboard&amp;Itemid=$Itemid&amp;func=post");?>" method="post" name="postform" enctype="multipart/form-data">
  372. <input type="hidden" name="parentid" value="<?php echo $parentid;?>" />
  373. <input type="hidden" name="catid" value="<?php echo $catid;?>" />
  374. <input type="hidden" name="action" value="post" />
  375. <input type="hidden" name="contentURL" value="<?php echo $contentURL ;?>" />
  376. <?php
  377. //get the writing stuff in:
  378. $no_upload="0";//only edit mode should disallow this
  379. include(JB_ABSPATH.'/write.html.php');
  380. //--
  381. //echo "</form>";
  382. }
  383. else if ($do == "edit") {
  384. $allowEdit=0;
  385. $id=(int)$id;
  386. $mess=null;
  387. $database->setQuery("SELECT * FROM #__sb_messages LEFT JOIN #__sb_messages_text ON #__sb_messages.id=#__sb_messages_text.mesid WHERE #__sb_messages.id='$id'");
  388. $database->loadObject($mes);
  389. // Check permission
  390. $allowEdit=0;
  391. if ($is_moderator) {
  392. $allowEdit=1;
  393. }
  394. elseif ($sbConfig['useredit']==1 && $my->id >0 && $my->id == $mes->userid ) {
  395. $allowEdit=1;
  396. }
  397. if (!$allowEdit) {
  398. echo '<p>Hacking attempt!</p>';
  399. return;
  400. }
  401. //we're now in edit mode
  402. $editmode=1;
  403. $htmlText=smile::sbStripHtmlTags($mes->message);
  404. $table = array_flip(get_html_translation_table(HTML_ENTITIES));
  405. $htmlText = strtr($htmlText, $table);
  406. $htmlText=smile::sbHtmlSafe($htmlText);
  407. $resubject=htmlspecialchars(stripslashes($mes->subject));
  408. $authorName=htmlspecialchars($mes->name);
  409. ?>
  410. <form action="<?php echo sefRelToAbs("index.php?option=com_joomlaboard&Itemid=$Itemid&catid=$catid&func=post"); ?>" method="post" name="postform" enctype="multipart/form-data" />
  411. <input type="hidden" name="id" value="<?php echo $mes->id;?>" />
  412. <input type="hidden" name="do" value="editpostnow" />
  413. <?php
  414. // get the writing stuff in:
  415. // first check if there is an uploaded image or file already for this post (no new ones allowed)
  416. $no_file_upload=0;
  417. $no_image_upload=0;
  418. $database->setQuery("SELECT filelocation FROM #__sb_attachments WHERE mesid='$id'");
  419. $attachments=$database->loadObjectList();
  420. if (count($attachments > 0) ) {
  421. foreach($attachments as $att) {
  422. if (preg_match("&/uploaded/files/&si", $att->filelocation) ){
  423. $no_file_upload="1";
  424. }
  425. if (preg_match("&/uploaded/images/&si", $att->filelocation) ){
  426. $no_image_upload="1";
  427. }
  428. }
  429. }
  430. else {
  431. $no_upload="0";
  432. }
  433. include(JB_ABSPATH.'/write.html.php');
  434. //echo "</form>";
  435. }
  436. else if ($do == "editpostnow") {
  437. $database->setQuery("SELECT userid FROM #__sb_messages WHERE id='$id'");
  438. $userid=$database->loadResult();
  439. // Check permission
  440. $allowEdit=0;
  441. if ($is_moderator) {
  442. $allowEdit=1;
  443. }
  444. elseif ($sbConfig['useredit']==1 && $my->id >0 && $my->id == $userid ) {
  445. $allowEdit=1;
  446. }
  447. if (!$allowEdit) {
  448. echo '<p>Hacking attempt!</p>';
  449. return;
  450. }
  451. if ($attachfile != '' ) {
  452. include JB_ABSPATH.'/file_upload.php';
  453. }
  454. if ($attachimage != '' ) {
  455. include JB_ABSPATH.'/image_upload.php';
  456. }
  457. $message = isset($_POST['message']) ? trim($_POST['message']) : '';
  458. $message=trim(htmlspecialchars(addslashes($message)));
  459. if ($sbConfig['editMarkUp']) {
  460. $posttime=time()+($sbConfig['board_ofset']*3600);
  461. $message = $message."<br /><br />"._EDIT_BY." ".$my_name.", "._EDIT_AT." ".date(_DATETIME, $posttime);
  462. }
  463. //parse the message for some preliminary bbcode and stripping of HTML
  464. $message = smile::bbencode_first_pass($message);
  465. $id=(int)$id;
  466. $database->setQuery("SELECT id FROM #__sb_messages WHERE id='$id'");
  467. $database->query();
  468. if ($database->getNumRows() > 0)
  469. {
  470. $database->setQuery("UPDATE #__sb_messages SET name='$sb_authorname', email='".addslashes($email)."', subject='".addslashes($subject)."', topic_emoticon='".((int)$topic_emoticon)."' WHERE id='$id'");
  471. $dbr_nameset=$database->query();
  472. $database->setQuery("UPDATE #__sb_messages_text SET message='$message' WHERE mesid='$id'");
  473. if ($database->query() && $dbr_nameset)
  474. {
  475. //Update the attachments table if an image has been attached
  476. if ( $imageLocation != "" )
  477. {
  478. $database->setQuery("INSERT INTO #__sb_attachments (mesid, filelocation) values ('$id','$imageLocation')");
  479. if (!$database->query()){
  480. echo "<script> alert('Storing image failed: ".$database->getErrorMsg()."'); </script>\n";
  481. }
  482. }
  483. //Update the attachments table if an file has been attached
  484. if ( $fileLocation != "" )
  485. {
  486. $database->setQuery("INSERT INTO #__sb_attachments (mesid, filelocation) values ('$id','$fileLocation')");
  487. if (!$database->query()){
  488. echo "<script> alert('Storing file failed: ".$database->getErrorMsg()."'); </script>\n";
  489. }
  490. }
  491. echo '<div align="center">'._POST_SUCCESS_EDIT.'<br /><br />';
  492. echo '<a href="'.sefRelToAbs('index.php?option=com_joomlaboard&amp;Itemid='.$Itemid.'&amp;func=view&catid='.$catid.'&amp;id='.$id).'#'.$id.'">'._POST_SUCCESS_VIEW.'</a><br />';
  493. echo '<a href="'.sefRelToAbs('index.php?option=com_joomlaboard&amp;Itemid='.$Itemid.'&amp;func=showcat&catid='.$catid).'">'._POST_SUCCESS_FORUM.'</a><br />';
  494. echo '</div>';
  495. }
  496. else
  497. echo _POST_ERROR_MESSAGE_OCCURED;
  498. }
  499. else
  500. {
  501. echo _POST_INVALID;
  502. }
  503. }
  504. else if ($do == "delete") {
  505. if(!$is_moderator){ die("Hacking Attempt!");}
  506. $id=(int)$id;
  507. $database->setQuery("SELECT * FROM #__sb_messages WHERE id=$id");
  508. $message=$database->loadObjectList();
  509. foreach ($message as $mes) {
  510. ?>
  511. <form action="<?php echo sefRelToAbs("index.php?option=com_joomlaboard&Itemid=$Itemid&catid=$catid&func=post"); ?>" method="post" name="myform">
  512. <input type="hidden" name="do" value="deletepostnow" />
  513. <input type="hidden" name="id" value="<?php echo $mes->id;?>" />
  514. <?php echo _POST_ABOUT_TO_DELETE;?>: <strong><?php echo stripslashes(htmlspecialchars($mes->subject));?></strong>.<br /><br />
  515. <?php echo _POST_ABOUT_DELETE;?><br /><br />
  516. <input type="checkbox" checked name="delAttachments" value="delAtt" /> <?php echo _POST_DELETE_ATT;?>
  517. <br /><br />
  518. <a href="javascript:document.myform.submit();"><?php echo _GEN_CONTINUE;?></a>
  519. | <a href="<?php echo sefRelToAbs("index.php?option=com_joomlaboard&amp;Itemid=$Itemid&amp;func=view&catid=$catid;&amp;id=$id");?>"><?php echo _GEN_CANCEL;?></a>
  520. </form>
  521. <?php
  522. }
  523. }
  524. else if ($do == "deletepostnow") {
  525. if(!$is_moderator)
  526. die("Hacking Attempt!");
  527. $id=(int) mosGetParam($_POST,'id','');
  528. $dellattach=mosGetParam($_POST,'delAttachments','')=='delAtt'?1:0;
  529. $thread=sb_delete_post($database,$id,$dellattach);
  530. switch ($thread) {
  531. case -1:
  532. echo _POST_ERROR_TOPIC.'<br />';
  533. echo 'Could not promote children in post hierarchy. Nothing deleted.';
  534. break;
  535. case -2:
  536. echo _POST_ERROR_TOPIC.'<br />';
  537. echo 'Could not delete the post(s) - nothing else deleted';
  538. break;
  539. case -3:
  540. echo _POST_ERROR_TOPIC.'<br />';
  541. echo 'Could not delete the texts of the post(s). Update the database manually (mesid='.$id.').';
  542. break;
  543. case -4:
  544. echo _POST_ERROR_TOPIC.'<br />';
  545. echo 'Everything deleted, but failed to update user post stats!';
  546. break;
  547. case -5:
  548. echo _POST_ERROR_TOPIC.'<br />';
  549. echo 'Could not delete the poll. Update the database manually.';
  550. break;
  551. default:
  552. echo '<div align="center">'._POST_SUCCESS_DELETE.'<br /><br />';
  553. if ($do=='deletepostnow')
  554. echo '<a href="'.sefRelToAbs(JB_LIVEURL.'&amp;func=view&catid='.$catid.'&amp;id='.$thread).'">'._POST_SUCCESS_VIEW.'</a><br />';
  555. echo '<a href="'.sefRelToAbs(JB_LIVEURL.'&amp;func=showcat&catid='.$catid).'">'._POST_SUCCESS_FORUM.'</a><br />';
  556. echo '</div>';
  557. echo '<script language="javascript">';
  558. if ($do=='deletetopicnow')
  559. echo 'setTimeout("location=\''.sefRelToAbs(JB_LIVEURL.'&func=showcat&catid='.$catid).'\'",3500)';
  560. else
  561. echo 'setTimeout("location=\''.sefRelToAbs(JB_LIVEURL.'&func=view&catid='.$catid.'&id='.$thread).'\'",3500)';
  562. echo '</script>';
  563. break;
  564. }
  565. }//fi $do==deletepostnow
  566. else if ($do == "move") {
  567. if(!$is_moderator){ die("Hacking Attempt!");}
  568. $catid=(int)$catid;
  569. $id=(int)$id;
  570. //get list of available forums
  571. //$database->setQuery("SELECT id,name FROM #__sb_categories WHERE parent != '0'");
  572. $database->setQuery( "SELECT a.*, b.name AS category"
  573. . "\nFROM #__sb_categories AS a"
  574. . "\nLEFT JOIN #__sb_categories AS b ON b.id = a.parent"
  575. . "\nWHERE a.parent != '0'"
  576. . "\nORDER BY parent, ordering");
  577. $catlist=$database->loadObjectList();
  578. // get topic subject:
  579. $database->setQuery("select subject from #__sb_messages where id=$id");
  580. $topicSubject=$database->loadResult();
  581. ?>
  582. <form action="<?php echo sefRelToAbs("index.php?option=com_joomlaboard&Itemid=$Itemid&func=post"); ?>" method="post" name="myform">
  583. <input type="hidden" name="do" value="domovepost" />
  584. <input type="hidden" name="id" value="<?php echo $id;?>" />
  585. <p><?php echo _GEN_TOPIC;?>: <strong><?php echo $topicSubject;?></strong><br /><br />
  586. <?php echo _POST_MOVE_TOPIC;?>:<br />
  587. <select name="catid" size="4">
  588. <?php
  589. foreach ($catlist as $cat)
  590. {
  591. echo "<OPTION value=\"$cat->id\" > $cat->category/$cat->name </OPTION>";
  592. }?>
  593. </select><br />
  594. <input type="checkbox" checked name="leaveGhost" value="1" /> <?php echo _POST_MOVE_GHOST;?>
  595. <br />
  596. <input type="submit" class="button" value="<?php echo _GEN_MOVE;?>" />
  597. </form>
  598. <?php
  599. }
  600. else if ($do == "domovepost")
  601. {
  602. if(!$is_moderator){ die("Hacking Attempt!");}
  603. $catid=(int)$catid;
  604. $id=(int)$id;
  605. $bool_leaveGhost=(int)mosGetParam($_POST,'leaveGhost',0);
  606. //get the some details from the original post for later
  607. $database->setQuery("SELECT `subject`, `catid`, `time` AS timestamp FROM #__sb_messages WHERE `id`='$id'");
  608. $oldRecord=$database->loadObjectList();
  609. $newSubject=_MOVED_TOPIC." ".$oldRecord[0]->subject;
  610. $database->setQuery("SELECT MAX(time) AS timestamp FROM #__sb_messages WHERE `thread`='$id'");
  611. $lastTimestamp=$database->loadResult();
  612. if ($lastTimestamp == "") { $lastTimestamp = $oldRecord[0]->timestamp; }
  613. //perform the actual move
  614. //Move topic post first
  615. $database->setQuery("UPDATE #__sb_messages SET `catid`='$catid' WHERE `id`='$id'");
  616. if ($database->query())
  617. { //succeeded; move the rest of the thread if exists
  618. $database->setQuery("UPDATE #__sb_messages set `catid`='$catid' WHERE `thread`='$id'");
  619. if ($database->query())
  620. {
  621. // insert 'moved topic' notification in old forum if needed
  622. if ($bool_leaveGhost) {
  623. $database->setQuery("INSERT INTO #__sb_messages (`parent`, `subject`, `time`, `catid`, `moved`) VALUES ('0','$newSubject','".$lastTimestamp."','".$oldRecord[0]->catid."','1')");
  624. if ($database->query() ) {
  625. //determine the new location for link composition
  626. $newId=$database->insertid();
  627. $newURL = "catid=".$catid."&id=".$id;
  628. $database->setQuery("INSERT INTO #__sb_messages_text (`mesid`, `message`) VALUES ('$newId', '$newURL')");
  629. if (! $database->query() ) { $database->stderr(true); }
  630. //and update the thread id on the 'moved' post for the right ordering when viewing the forum..
  631. $database->setQuery("UPDATE #__sb_messages SET `thread`='$newId' WHERE `id`='$newId'");
  632. if (! $database->query() ) { $database->stderr(true); }
  633. }
  634. else
  635. echo '<p style="text-align:center">'._POST_GHOST_FAILED.'</p>';
  636. }
  637. //move succeeded
  638. echo '<div align="center">'._POST_SUCCESS_MOVE.'<br /><br />';
  639. echo '<a href="'.sefRelToAbs(JB_LIVEURL.'&amp;func=view&catid='.$catid.'&amp;id='.$id).'#'.$id.'">'._POST_SUCCESS_VIEW.'</a><br />';
  640. echo '<a href="'.sefRelToAbs(JB_LIVEURL.'&amp;func=showcat&catid='.$catid).'">'._POST_SUCCESS_FORUM.'</a><br />';
  641. echo '</div>';
  642. ?>
  643. <script language="javascript">
  644. setTimeout("location='<?php echo sefRelToAbs(JB_LIVEURL.'&amp;func=view&amp;catid='.$catid.'&amp;id='.$id); ?>'",3500);
  645. </script>
  646. <?php
  647. }
  648. else
  649. {
  650. echo "Severe database error. Update your database manually so the replies to the topic are matched to the new forum as well";
  651. //this is severe.. takes a lot of coding to programatically correct it. Won't do that.
  652. //chances of this happening are very slim. Disclaimer: this is software as-is *lol*;
  653. //go read the GPL and the header of this file..
  654. }
  655. }
  656. else
  657. {?>
  658. <?php echo _POST_TOPIC_NOT_MOVED;?> <a href="index.php?option=com_joomlaboard&amp;Itemid=<?php echo $Itemid;?>&amp;func=view&catid=<?php echo $catid;?>&amp;id=<?php echo $id;?>"><?php echo _POST_CLICK;?></a>
  659. <?php
  660. }
  661. }
  662. else if ($do == "subscribe")
  663. {
  664. $catid=(int)$catid;
  665. $id=(int)$id;
  666. $database->setQuery("INSERT INTO #__sb_subscriptions (thread,userid) VALUES ('$sb_thread','$my_id')");
  667. if ($database->query()){
  668. echo _POST_SUBSCRIBED_TOPIC."<br /><br />";
  669. }else{
  670. echo _POST_NO_SUBSCRIBED_TOPIC."<br /><br />";
  671. }
  672. echo '<div align="center">'._POST_SUCCESS_SUBSCRIBE.'<br /><br />';
  673. echo '<a href="'.sefRelToAbs(JB_LIVEURL.'&amp;func=view&amp;catid='.$catid.'&amp;id='.$pid).'#'.$pid.'">'._POST_SUCCESS_VIEW.'</a><br />';
  674. echo '<a href="'.sefRelToAbs(JB_LIVEURL.'&amp;func=showcat&amp;catid='.$catid).'">'._POST_SUCCESS_FORUM.'</a><br />';
  675. echo '</div>'; ?>
  676. <script language="javascript">
  677. setTimeout("location='<?php echo sefRelToAbs(JB_LIVEURL.'&amp;func=userprofile&amp;do=show'); ?>'",3500);
  678. </script>
  679. <?php
  680. }
  681. else if ($do == "sticky")
  682. {
  683. if(!$is_moderator){ die("Hacking Attempt!");}
  684. $database->setQuery("update #__sb_messages set ordering=1 where id=$id");
  685. if ($database->query()){
  686. echo '<p align="center">'._POST_STICKY_SET.'<br /><br />';
  687. }else{
  688. echo '<p align="center">'._POST_STICKY_NOT_SET.'<br /><br />';
  689. }
  690. echo '<div align="center">'._POST_SUCCESS_REQUEST2.'<br /><br />';
  691. echo '<a href="'.sefRelToAbs(JB_LIVEURL.'&amp;func=view&amp;catid='.$catid.'&amp;id='.$id).'#'.$id.'">'._POST_SUCCESS_VIEW.'</a><br />';
  692. echo '<a href="'.sefRelToAbs(JB_LIVEURL.'&amp;func=showcat&amp;catid='.$catid).'">'._POST_SUCCESS_FORUM.'</a><br />';
  693. echo '</div>';
  694. ?>
  695. <script language="javascript">
  696. setTimeout("location='<?php echo sefRelToAbs(JB_LIVEURL.'&amp;func=view&amp;catid='.$catid.'&amp;id='.$id);?>'",3500);
  697. </script>
  698. <?php
  699. }
  700. else if ($do == "unsticky")
  701. {
  702. if(!$is_moderator){ die("Hacking Attempt!");}
  703. $database->setQuery("update #__sb_messages set ordering=0 where id=$id");
  704. if ($database->query()){
  705. echo '<p align="center">'._POST_STICKY_UNSET.'<br /><br />';
  706. }else{
  707. echo '<p align="center">'._POST_STICKY_NOT_UNSET.'<br /><br />';
  708. }
  709. echo '<div align="center">'._POST_SUCCESS_REQUEST2.'<br /><br />';
  710. echo '<a href="'.sefRelToAbs(JB_LIVEURL.'&amp;func=view&amp;catid='.$catid.'&amp;id='.$id).'#'.$id.'">'._POST_SUCCESS_VIEW.'</a><br />';
  711. echo '<a href="'.sefRelToAbs(JB_LIVEURL.'&amp;func=showcat&amp;catid='.$catid).'">'._POST_SUCCESS_FORUM.'</a><br />';
  712. echo '</div>'; ?>
  713. <script language="javascript">
  714. setTimeout("location='<?php echo sefRelToAbs(JB_LIVEURL.'&amp;func=view&amp;catid='.$catid.'&amp;id='.$id) ;?>'",3500);
  715. </script>
  716. <?php
  717. }
  718. else if ($do == "lock")
  719. {
  720. if(!$is_moderator){ die("Hacking Attempt!");}
  721. //lock topic post
  722. $database->setQuery("update #__sb_messages set locked=1 where id=$id");
  723. if ($database->query()){
  724. echo '<p align=/"center/">'._POST_LOCK_SET.'<br /><br />';
  725. }else{
  726. echo '<p align=/"center/">'._POST_LOCK_NOT_SET.'<br /><br />';
  727. }
  728. echo '<div align=/"center/">'._POST_SUCCESS_REQUEST2.'<br /><br />';
  729. echo '<a href="'.sefRelToAbs(JB_LIVEURL.'&amp;func=view&amp;catid='.$catid.'&amp;id='.$id).'#'.$id.'">'._POST_SUCCESS_VIEW.'</a><br />';
  730. echo '<a href="'.sefRelToAbs(JB_LIVEURL.'&amp;func=showcat&amp;catid='.$catid).'">'._POST_SUCCESS_FORUM.'</a><br />';
  731. echo '</div>';
  732. ?>
  733. <script language="javascript">
  734. setTimeout("location='<?php echo sefRelToAbs(JB_LIVEURL.'&amp;func=view&amp;catid='.$catid.'&amp;id='.$id);?>'",3500);
  735. </script>
  736. <?php
  737. }
  738. else if ($do == "unlock")
  739. {
  740. if(!$is_moderator){ die("Hacking Attempt!");}
  741. $database->setQuery("update #__sb_messages set locked=0 where id=$id");
  742. if ($database->query()){
  743. echo '<p align="center">'._POST_LOCK_UNSET.'<br /><br />';
  744. }else{
  745. echo '<p align="center">'._POST_LOCK_NOT_UNSET.'<br /><br />';
  746. }
  747. echo '<div align="center">'._POST_SUCCESS_REQUEST2.'<br /><br />';
  748. echo '<a href="'.sefRelToAbs(JB_LIVEURL.'&amp;func=view&amp;catid='.$catid.'&amp;id='.$id).'#'.$id.'">'._POST_SUCCESS_VIEW.'</a><br />';
  749. echo '<a href="'.sefRelToAbs(JB_LIVEURL.'&amp;func=showcat&amp;catid='.$catid).'">'._POST_SUCCESS_FORUM.'</a><br />';
  750. echo '</div>'; ?>
  751. <script language="javascript">
  752. setTimeout("location='<?php echo sefRelToAbs(JB_LIVEURL.'&amp;func=view&amp;catid='.$catid.'&amp;id='.$id);?>'",3500);
  753. </script>
  754. <?php
  755. }
  756. }
  757. ?>
  758. </td>
  759. </tr>
  760. </table>
  761. <?php
  762. /**
  763. * Function to delete posts
  764. *
  765. * @param database object
  766. * @param int the id if the post to be deleted
  767. * @param boolean determines if we need to delete attachements as well
  768. *
  769. * @return int returns thread id if all went well, -1 to -5 are error numbers
  770. **/
  771. function sb_delete_post(&$database,$id,$dellattach) {
  772. $database->setQuery('SELECT id,catid,parent,thread,subject,userid FROM #__sb_messages WHERE id='.$id);
  773. if (!$database->query())
  774. return -2;
  775. $database->loadObject($mes);
  776. $thread=$mes->thread;
  777. if ($mes->parent==0) {
  778. // this is the forum topic; if removed, all children must be removed as well.
  779. $children=array();
  780. $userids=array();
  781. $database->setQuery('SELECT userid,id FROM #__sb_messages WHERE thread='.$id .' OR id='.$id);
  782. foreach ($database->loadObjectList() as $line) {
  783. $children[]=$line->id;
  784. if ($line->userid > 0)
  785. $userids[]=$line->userid;
  786. }
  787. $children=implode(',',$children);
  788. $userids=implode(',',$userids);
  789. }
  790. else {
  791. //this is not the forum topic, so delete it and promote the direct children one level up in the hierarchy
  792. $database->setQuery('UPDATE #__sb_messages SET parent=\''.$mes->parent.'\' WHERE parent=\''.$id.'\'');
  793. if (!$database->query())
  794. return -1;
  795. $children=$id;
  796. $userids=$mes->userid > 0 ? $mes->userid : '';
  797. }
  798. //Delete the post (and it's children when it's the first post)
  799. $database->setQuery('DELETE FROM #__sb_messages WHERE id='.$id .' OR thread='.$id);
  800. if (!$database->query())
  801. return -2;
  802. //Delete message text(s)
  803. $database->setQuery('DELETE FROM #__sb_messages_text WHERE mesid IN ('.$children.')');
  804. if (!$database->query())
  805. return -3;
  806. //Update user post stats
  807. if (!empty($userids) && count($userids) > 0) {
  808. $database->setQuery('UPDATE #__sb_users SET posts=posts-1 WHERE userid IN ('.$userids.')');
  809. if (!$database->query())
  810. return -4;
  811. }
  812. //Delete (possible) ghost post
  813. $database->setQuery('SELECT mesid FROM #__sb_messages_text WHERE message=\'catid='.$mes->catid.'&id='.$id.'\'');
  814. $int_ghost_id=$database->loadResult();
  815. if ($int_ghost_id>0) {
  816. $database->setQuery('DELETE FROM #__sb_messages WHERE id='.$int_ghost_id);
  817. $database->query();
  818. $database->setQuery('DELETE FROM #__sb_messages_text WHERE mesid='.$int_ghost_id);
  819. $database->query();
  820. }
  821. //Delete attachments
  822. if ($dellattach) {
  823. $database->setQuery('SELECT filelocation FROM #__sb_attachments WHERE mesid IN ('.$children.')');
  824. $fileList=$database->loadObjectList();
  825. if (count($fileList)>0){
  826. foreach ($fileList as $fl)
  827. unlink($fl->filelocation);
  828. $database->setQuery('DELETE FROM #__sb_attachments WHERE mesid IN ('.$children.')');
  829. $database->query();
  830. }
  831. }
  832. return $thread; // all went well :-)
  833. }
  834. function listThreadHistory($id,$sbConfig, $database)
  835. {
  836. if($id != 0)
  837. {
  838. //get the parent# for the post on which 'reply' or 'quote' is chosen
  839. $database->setQuery("SELECT parent FROM #__sb_messages WHERE id='$id'");
  840. $this_message_parent = $database->loadResult();
  841. //Get the thread# for the same post
  842. $database->setQuery("SELECT thread FROM #__sb_messages WHERE id='$id'");
  843. $this_message_thread = $database->loadResult();
  844. //determine the correct thread# for the entire thread
  845. if ($this_message_parent==0)
  846. {$thread=$id;} else {$thread=$this_message_thread;}
  847. //get all the messages for this thread
  848. $database->setQuery("SELECT * FROM #__sb_messages LEFT JOIN #__sb_messages_text ON #__sb_messages.id=#__sb_messages_text.mesid WHERE thread='$thread' OR id='$thread' AND hold = 0 ORDER BY time DESC LIMIT ".$sbConfig['historyLimit']);
  849. $messages=$database->loadObjectList();
  850. //and the subject of the first thread (for reference)
  851. $database->setQuery("SELECT subject FROM #__sb_messages WHERE id='$thread' and parent=0");
  852. $this_message_subject = $database->loadResult();
  853. echo "<b>"._POST_TOPIC_HISTORY.":</b> ".htmlspecialchars($this_message_subject)." <br />"._POST_TOPIC_HISTORY_MAX." $historyLimit "._POST_TOPIC_HISTORY_LAST."<br />";
  854. ?>
  855. <table border="0" cellspacing="1" cellpadding="3" width="100%" class="sb_review_table">
  856. <tr>
  857. <td class="sb_review_header" width="20%" align="center"><strong><?php echo _GEN_AUTHOR;?></strong></td>
  858. <td class="sb_review_header" align="center"><strong><?php echo _GEN_MESSAGE;?></strong></td>
  859. </tr>
  860. <?php
  861. $k=0;
  862. foreach($messages as $mes)
  863. {
  864. $k = 1-$k;
  865. $mes->name = htmlspecialchars($mes->name);
  866. $mes->email = htmlspecialchars($mes->email);
  867. $mes->subject = htmlspecialchars($mes->subject);
  868. $mes->message = smile::smileReplace($mes->message,1, $sbConfig['disemoticons']);
  869. ?>
  870. <tr>
  871. <td class="sb_review_body<?php echo $k;?>" valign="top"><?php echo stripslashes($mes->name);?></td>
  872. <td class="sb_review_body<?php echo $k;?>">
  873. <?php
  874. $sb_message_txt = stripslashes($mes->message);
  875. $sb_message_txt = str_replace("</P><br />","</P>", $sb_message_txt );
  876. //Long Words Wrap:
  877. $sb_message_txt = smile::htmlwrap($sb_message_txt, $sbConfig['wrap']);
  878. echo $sb_message_txt;
  879. ?>
  880. </td>
  881. </tr>
  882. <?php }
  883. ?>
  884. </table><?php
  885. }//else: this is a new topic so there can't be a history
  886. }
  887. ?>