PageRenderTime 53ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/solar27/forum.php

https://bitbucket.org/sebs/mosolar
PHP | 304 lines | 247 code | 49 blank | 8 comment | 30 complexity | 77db0608203cbcbbcf9d57f719f79ef6 MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-3.0, BSD-3-Clause, LGPL-2.0, MIT, GPL-2.0
  1. <?php
  2. // Solar Imperium is licensed under GPL2, Check LICENSE.TXT for mode details //
  3. define("LANGUAGE_DOMAIN","system");
  4. require_once("include/init.php");
  5. // (please do not remove credit)
  6. // author: Louai Munajim
  7. // website: http://elouai.com
  8. // date: 2004/Apr/18
  9. function bbcode2html($text)
  10. {
  11. $bbcode = array("<", ">",
  12. "[list]", "[*]", "[/list]",
  13. "[b]", "[/b]",
  14. "[u]", "[/u]",
  15. "[i]", "[/i]",
  16. "[code]", "[/code]",
  17. "[quote]", "[/quote]",
  18. '"]');
  19. $htmlcode = array("&lt;", "&gt;",
  20. "<ul>", "<li>", "</ul>",
  21. "<b>", "</b>",
  22. "<u>", "</u>",
  23. "<i>", "</i>",
  24. "<code>", "</code>",
  25. "<table width=100% cellpadding=\"5\" cellspacing=\"0\" bgcolor=lightgray style=\"color:#333333;border:1px dashed #333333\"><tr><td bgcolor=\"#eeeeee\">", "</td></tr></table>",
  26. '">');
  27. $newtext = str_replace($bbcode, $htmlcode, $text);
  28. $newtext = nl2br($newtext);//second pass
  29. $newtext = str_replace("javascript:","",$newtext);
  30. $newtext = str_replace("onmouseover=","",$newtext);
  31. $newtext = str_replace("onmouseleave=","",$newtext);
  32. $newtext = str_replace("onclick=","",$newtext);
  33. $newtext = stripslashes($newtext);
  34. return $newtext;
  35. }
  36. if (!isset($_SESSION["forum_page"])) $_SESSION["forum_page"] = 0;
  37. if (isset($_GET["forum_page"])) $_SESSION["forum_page"] = intval($_GET["forum_page"]);
  38. if (isset($_GET["BACK"])) {
  39. unset($_SESSION["current_forum"]);
  40. }
  41. if (isset($_GET["forum"])) {
  42. reset($FORUMS);
  43. $found = false;
  44. while(list($key,$value) = each($FORUMS)) {
  45. if ($key == $_GET["forum"]) { $found = true; break; }
  46. }
  47. if ($found) $_SESSION["current_forum"] = addslashes($_GET["forum"]);
  48. }
  49. // **********************************************************
  50. // Post a new forum topic callback
  51. // **********************************************************
  52. if (isset($_POST["forum_newtopic"]))
  53. {
  54. $subject = $_POST["subject"];
  55. $content = $_POST["content"];
  56. if ($subject == "") {
  57. $DB->CompleteTrans();
  58. die(header("Location: forum.php?WARNING=".T_("Empty subject field!")));
  59. }
  60. if ($content == "") {
  61. $DB->CompleteTrans();
  62. die(header("Location: forum.php?WARNING=".T_("Empty content field!")));
  63. }
  64. if (!isset($_SESSION["player"]))
  65. die(header("Location: forum.php?WARNING=".T_("You need to be logged to post something, there is the content of your post (if you want to copypaste it back later) : <b>").stripslashes($content)."</b>"));
  66. if (!isset($_SESSION["current_forum"])) {
  67. $DB->CompleteTrans();
  68. die(header("Location: forum.php?WARNING=".T_("You can't post until you have choosen a forum!")));
  69. }
  70. if (($FORUMS[$_SESSION["current_forum"]]["admin_post"] ==1) && ($_SESSION["player"]["admin"] != 1)) {
  71. die(header("Location: forum.php?WARNING=".T_("Only administrators can post in this forum!")));
  72. }
  73. $query = "INSERT INTO system_tb_forum (player,date_creation,date_update,title,content,forum_name) VALUES(".$_SESSION["player"]["id"].",".time(NULL).",".time(NULL).",'".addslashes($subject)."','".addslashes($content)."','".$_SESSION["current_forum"]."');";
  74. $DB->Execute($query);
  75. if (!$DB) trigger_error($DB->ErrorMsg());
  76. $DB->CompleteTrans();
  77. die(header("Location: forum.php?"));
  78. }
  79. // **********************************************************
  80. // Delete a forum thread callback (ADMIN ONLY)
  81. // **********************************************************
  82. if (isset($_SESSION["player"]))
  83. if ($_SESSION["player"]["admin"]==1) {
  84. if (isset($_GET["DELETE"])) {
  85. $topic_id = -1;
  86. $page = -1;
  87. if (isset($_GET["topic"])) $topic_id = intval($_GET["topic"]);
  88. if (isset($_GET["page"])) $page = intval($_GET["page"]);
  89. $id = intval($_GET["DELETE"]);
  90. $DB->Execute("DELETE FROM system_tb_forum WHERE id=$id OR parent=$id");
  91. if (!$DB) trigger_error($DB->ErrorMsg());
  92. $DB->CompleteTrans();
  93. if ($topic_id == -1) {
  94. header("Location: forum.php?");
  95. } else {
  96. header("Location: forum_viewtopic.php?topic=$topic_id&page=$page");
  97. }
  98. die();
  99. }
  100. }
  101. // Show the main page (Select a forum)
  102. if (!isset($_SESSION["current_forum"])) {
  103. reset($FORUMS);
  104. $items = array();
  105. $count = 0;
  106. while(list($key,$value) = each($FORUMS))
  107. {
  108. $item = array();
  109. $item["bgcolor"] = ($count++ % 2 == 0?"#cacada":"#dadaea");
  110. $item["fgcolor"] = ($count % 2 == 0?"#000000":"#333333");
  111. $item["url"] = "forum.php?forum=".$key;
  112. $item["description"] = $value["description"];
  113. $rs = $DB->Execute("SELECT COUNT(*) FROM system_tb_forum WHERE parent=-1 AND forum_name='".addslashes($key)."'");
  114. $item["posts"] = $rs->fields[0];
  115. $rs = $DB->Execute("SELECT COUNT(*) FROM system_tb_forum WHERE parent > -1 AND forum_name='".addslashes($key)."'");
  116. $item["replies"] = $rs->fields[0];
  117. if ($item["posts"] == 0) $item["lastpost"] = "---"; else {
  118. $rs = $DB->Execute("SELECT date_creation FROM system_tb_forum WHERE parent=-1 AND forum_name='".addslashes($key)."' ORDER BY date_creation DESC");
  119. if (!$rs) trigger_error($DB->ErrorMsg());
  120. $days = floor((time() - $rs->fields["date_creation"]) / (60*60*24));
  121. if ($days == 0)
  122. $item["lastpost"] = T_("Today");
  123. else
  124. $item["lastpost"] = $days . T_(" days");
  125. }
  126. if ($item["replies"] == 0) $item["lastreply"] = "---"; else {
  127. $rs = $DB->Execute("SELECT date_creation FROM system_tb_forum WHERE parent > -1 AND forum_name='".addslashes($key)."' ORDER BY date_creation DESC");
  128. if (!$rs) trigger_error($DB->ErrorMsg());
  129. $days = floor((time() - $rs->fields["date_creation"]) / (60*60*24));
  130. if ($days == 0)
  131. $item["lastreply"] = T_("Today");
  132. else
  133. $item["lastreply"] = $days . T_(" days");
  134. }
  135. $items[] = $item;
  136. }
  137. $TPL->assign("items",$items);
  138. $DB->CompleteTrans();
  139. $TPL->display("page_forum.html");
  140. die();
  141. }
  142. // Display selected forum
  143. if (!isset($_SESSION["forum_page"])) $_SESSION["forum_page"] = 0;
  144. if (isset($_GET["forum_page"])) $_SESSION["forum_page"] = intval($_GET["forum_page"]);
  145. $total_posts = $DB->Execute("SELECT COUNT(*) FROM system_tb_forum WHERE parent=-1 AND forum_name='".addslashes($_SESSION["current_forum"])."'");
  146. $total_posts = $total_posts->fields[0];
  147. $query = "SELECT * FROM system_tb_forum WHERE parent=-1 AND forum_name='".addslashes($_SESSION["current_forum"])."' ORDER BY date_update DESC";
  148. $rs = $DB->Execute($query);
  149. if (!$rs) trigger_error($DB->ErrorMsg());
  150. $forum_items = array();
  151. $count = 0;
  152. while(!$rs->EOF)
  153. {
  154. $item = array();
  155. $item["bgcolor"] = ($count++ % 2 == 0?"#cacada":"#dadaea");
  156. $item["fgcolor"] = ($count % 2 == 0?"#000000":"#333333");
  157. $item["title"] = str_replace("\\'","'",bbcode2html($rs->fields["title"]));
  158. if (isset($_SESSION["player"]))
  159. if ($_SESSION["player"]["admin"]==1) {
  160. $item["title"].=" <a class=\"link2\" href=?DELETE=".$rs->fields["id"]." onClick=\"return confirm('".T_("Are you sure?")."');\">".T_("Delete")."</a>";
  161. }
  162. $item["views"] = $rs->fields["views"];
  163. $rs2 = $DB->Execute("SELECT COUNT(*) FROM system_tb_forum WHERE forum_name='".$_SESSION["current_forum"]."' AND parent=".$rs->fields["id"]);
  164. $item["replies"] = $rs2->fields[0];
  165. $page = 0;
  166. $page = floor($item["replies"] / CONF_FORUM_REPLIES_PER_PAGE);
  167. if ($page < 0) $page = 0;
  168. $rs2 = $DB->Execute("SELECT * FROM system_tb_forum WHERE forum_name='".$_SESSION["current_forum"]."' AND parent=".$rs->fields["id"]." AND forum_name='".addslashes($_SESSION["current_forum"])."' ORDER BY date_creation DESC LIMIT 1");
  169. if (!$rs2->EOF) {
  170. $rs3 = $DB->Execute("SELECT * FROM system_tb_players WHERE id=".$rs2->fields["player"]);
  171. $item["lastreply"] = $rs3->fields["nickname"];
  172. $item["date"] = (floor((time(NULL) - $rs2->fields["date_update"])/(60*60*24))+1).T_(" days");
  173. } else {
  174. $item["lastreply"] = "---";
  175. }
  176. $rs2 = $DB->Execute("SELECT * FROM system_tb_players WHERE id=".$rs->fields["player"]);
  177. $item["author"] = $rs2->fields["nickname"];
  178. $item["date"] = (floor((time(NULL) - $rs->fields["date_creation"])/(60*60*24))+1).T_(" days");
  179. $item["url"] = "forum_viewtopic.php?topic=".$rs->fields["id"]."&page=0";
  180. $item["lastseen"] = (floor((time(NULL) - $rs->fields["date_seen"])/(60*60*24))+1).T_(" days");
  181. $item["new"] = "";
  182. if ((time(NULL) - $rs->fields["date_update"]) < (60*60*24*2)) $item["new"] = "<img border=\"0\" src=\"images/common/new.png\">";
  183. $forum_items[] = $item;
  184. $rs->MoveNext();
  185. }
  186. $tmp = $forum_items;
  187. $forum_items = array();
  188. $offset = ($_SESSION["forum_page"]*CONF_FORUM_POSTS_PER_PAGE);
  189. $count = 0;
  190. while (list($key,$value) = each($tmp))
  191. {
  192. if (($count >= $offset) && ($count < ($offset+CONF_FORUM_POSTS_PER_PAGE)))
  193. {
  194. $forum_items[] = $value;
  195. }
  196. $count++;
  197. }
  198. unset($tmp);
  199. $TPL->assign("items",$forum_items);
  200. $forum_pages = "";
  201. for ($i=0;$i<($total_posts/CONF_FORUM_POSTS_PER_PAGE);$i++)
  202. {
  203. if ($i == $_SESSION["forum_page"])
  204. $forum_pages .= "<b class=\"text_normal\">".($i+1)."</b>&nbsp;";
  205. else
  206. $forum_pages .= "<a class=\"link\" href=\"?forum_page=$i\"><b>".($i+1)."</b></a>&nbsp;";
  207. }
  208. $TPL->assign("pages",$forum_pages);
  209. $TPL->assign("current_forum",$FORUMS[$_SESSION["current_forum"]]["description"]);
  210. if (isset($_SESSION["player"])) {
  211. if (($FORUMS[$_SESSION["current_forum"]]["admin_post"] ==1) && ($_SESSION["player"]["admin"] != 1)) {
  212. $TPL->assign("player_connected",0);
  213. } else
  214. $TPL->assign("player_connected",1);
  215. } else
  216. $TPL->assign("player_connected",0);
  217. $DB->CompleteTrans();
  218. $TPL->display("page_forum_showpage.html");
  219. ?>