A lightweight forum engine written in PHP. Repository is now obsolete and read-only. http://www.pioder.pl/uforum.html
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

332 lines
9.7 KiB

  1. <?php
  2. /**
  3. * @package uForum
  4. * @file posting.php
  5. * @version $Id$
  6. * @copyright 2009(c) PioDer <pioder@wp.pl>
  7. * @link http://pioder.gim2przemysl.int.pl/
  8. * @license GNU GPL v3
  9. **/
  10. define('IN_uF', true);
  11. //include files
  12. include('./config.php');
  13. include('./includes/constants.php');
  14. include('./includes/db.php');
  15. include('./includes/errors.php');
  16. //connect to database
  17. DataBase::db_connect();
  18. include('./includes/sessions.php');
  19. include('./includes/classes/class_user.php');
  20. include('./common.php');
  21. include('./includes/misc_functions.php');
  22. include('./includes/classes/class_forum.php');
  23. include('./includes/classes/class_posting.php');
  24. include('./includes/classes/class_topic.php');
  25. include('./includes/classes/secure.php');
  26. include('./lngs/'.DefaultLang().'/main.php');
  27. $start = TimeGeneration();
  28. $default_skin = ViewSkinName();
  29. SessDelInvalid();
  30. SessRegister();
  31. SessDeleteOld();
  32. $msg='';
  33. if ($_SESSION['uid']<1)
  34. {
  35. message_forum($lng['youarenotlogd'],'login.php?mode=login');
  36. }
  37. /**foreach ($_POST as $name => $value)
  38. {
  39. if ($forum_config['use_censorlist'])
  40. {
  41. $_POST[$name] = Secure::UseCensorlist($value);
  42. }
  43. }
  44. */
  45. $start = TimeGeneration();
  46. //add skin variables
  47. $skin = array(
  48. 'smiles'=>Post::SmilesShow(),
  49. //labels
  50. 'lsmiles'=>$lng['smiles'],
  51. 'ltopicname'=>$lng['ltopicname'],
  52. 'lsave'=>$lng['save'],
  53. 'lreset'=>$lng['reset'],
  54. 'lmsg'=>$lng['message'],
  55. 'lsticky_topic'=>$lng['sticky_topic'],
  56. 'lwritetopic'=>$lng['writetopic'],
  57. );
  58. $skin = array_push_associative($skin, GenerateHeader('',''));
  59. $stop = TimeGeneration();
  60. $skin['queries'] = ShowQueries($start, $stop);
  61. if(RANK=='2')
  62. {
  63. $skin['pa_link']='<a href="admin/index.php" class="fsmall"><b>'.$lng['pa_link'].'</b></a>';
  64. }
  65. else
  66. {
  67. $skin['pa_link']='';
  68. }
  69. switch(trim($_GET['mode']))
  70. {
  71. /**
  72. *
  73. functions for reply: normal, editing, quoting...
  74. *
  75. **/
  76. case 'qpost': //quote post
  77. {
  78. $msg ='';
  79. if (isset($_POST['textedit']))
  80. {
  81. if (($_POST['textedit'] !='' ) and (strlen(trim($_POST['textedit']))>10))
  82. {
  83. if (isset($_COOKIE['antiflood_time']))
  84. {
  85. if ($_COOKIE['antiflood_time']>time())
  86. {
  87. message_forum($lng['antiflood_enabled'],$_SERVER['REQUEST_URI']);
  88. }
  89. }
  90. else
  91. {
  92. setcookie('antiflood_time',(time() + $forum_config['time_antiflood']));
  93. }
  94. $_POST['textedit'] = Secure::TagsReplace($_POST['textedit']);
  95. $id = Post::NewPost(intval($_GET['t']),$_POST['textedit'], $_SESSION['uid']);
  96. $count = ceil(($id / 15 ));
  97. if ($count >1)
  98. {
  99. $page= '&amp;page='.$count;
  100. }
  101. else
  102. {
  103. $page='';
  104. }
  105. $stop = TimeGeneration();
  106. message_forum($lng['post_is_saved'],'topic.php?t='.$_GET['t'].$page.'#'.$id);
  107. }
  108. else
  109. {
  110. $message = $lng['perror_1'];
  111. $msg = './skins/'.$default_skin.'/post_error_body.tpl';
  112. }
  113. }
  114. else
  115. {
  116. $_POST['textedit']='[quote]'.stripslashes(Topic::PostInformation($_GET['id'],'text')).'[/quote]';
  117. }
  118. Secure::topic_exists(intval($_GET['t']));
  119. Secure::TopicLocked(intval($_GET['t']));
  120. $skin['mainpage'] = $lng['quote'];
  121. $skin['lmainpage'] = '</a>&gt; <a href="posting.php?mode=qpost&amp;id='.$_GET['id'].'&amp;t='.$_GET['t'].'"
  122. class="navigator">'.$lng['quote'];
  123. $skin['f_id'] = $_GET['id'];
  124. $skin['action'] = 'posting.php?mode=qpost&amp;id='.$_GET['id'].'&amp;t='.$_GET['t'];
  125. if ($msg=='')
  126. {
  127. $msg='./skins/'.$default_skin.'/blank.tpl';
  128. }
  129. include('./skins/'.$default_skin.'/overall_header.tpl');
  130. include('./skins/'.$default_skin.'/posting_body.tpl');
  131. include('./skins/'.$default_skin.'/overall_footer.tpl');
  132. break;
  133. }
  134. case 'edit': //edit post
  135. {
  136. if ((User::RankAdminMod($_SESSION['uid'])) or ($_SESSION['uid']==Topic::PostInformation($_GET['id'],'u_id')))
  137. {
  138. $msg ='';
  139. if (isset($_POST['textedit']))
  140. {
  141. if (($_POST['textedit'] !='' ) and (strlen(trim($_POST['textedit']))>10))
  142. {
  143. if (isset($_COOKIE['antiflood_time']))
  144. {
  145. if ($_COOKIE['antiflood_time']>time())
  146. {
  147. message_forum($lng['antiflood_enabled'],$_SERVER['REQUEST_URI']);
  148. }
  149. }
  150. else
  151. {
  152. setcookie('antiflood_time',(time() + $forum_config['time_antiflood']));
  153. }
  154. $_POST['textedit'] = Secure::TagsReplace($_POST['textedit']);
  155. Post::EditPost(intval($_GET['id']),$_POST['textedit']);
  156. $count = ceil((Topic::PostInformation(intval($_GET['id']),'tp_id') / 15 ));
  157. if ($count >1)
  158. {
  159. $page= '&amp;page='.$count;
  160. }
  161. else
  162. {
  163. $page='';
  164. }
  165. $stop = TimeGeneration();
  166. message_forum($lng['post_is_saved'],'topic.php?t='.Topic::PostInformation(intval($_GET['id']),'t_id').$page.'#p'.$_GET['id']);
  167. }
  168. else
  169. {
  170. $message = $lng['perror_1'];
  171. $msg = './skins/'.$default_skin.'/post_error_body.tpl';
  172. }
  173. }
  174. else
  175. {
  176. $_POST['textedit']=stripslashes(Topic::PostInformation($_GET['id'],'text'));
  177. }
  178. }
  179. $skin['mainpage'] = $lng['editpost'];
  180. $skin['lmainpage'] = '</a>&gt; <a href="posting.php?mode=edit&amp;id='.intval($_GET['id']).'"
  181. class="navigator">'.$lng['editpost'];
  182. $skin['f_id'] = intval($_GET['id']);
  183. $skin['action'] = 'posting.php?mode=edit&amp;id='.intval($_GET['id']);
  184. if ($msg=='')
  185. {
  186. $msg='./skins/'.$default_skin.'/blank.tpl';
  187. }
  188. include('./skins/'.$default_skin.'/overall_header.tpl');
  189. include('./skins/'.$default_skin.'/posting_body.tpl');
  190. include('./skins/'.$default_skin.'/overall_footer.tpl');
  191. break;
  192. }
  193. case 'rpost': //reply post
  194. {
  195. $msg ='';
  196. if (isset($_POST['textedit']))
  197. {
  198. if (($_POST['textedit'] !='' ) and (strlen(trim($_POST['textedit']))>10))
  199. {
  200. if (isset($_COOKIE['antiflood']))
  201. {
  202. if ($_COOKIE['antiflood_time']>time())
  203. {
  204. message_forum($lng['antiflood_enabled'],$_SERVER['REQUEST_URI']);
  205. }
  206. }
  207. else
  208. {
  209. setcookie('antiflood_time',(time() + $forum_config['time_antiflood']));
  210. }
  211. $_POST['textedit'] = Secure::TagsReplace($_POST['textedit']);
  212. $id = Post::NewPost(intval($_GET['id']),$_POST['textedit'], $_SESSION['uid']);
  213. $count =ceil(($id / 15 ));
  214. if ($count >1)
  215. {
  216. $page= '&amp;page='.$count;
  217. }
  218. else
  219. {
  220. $page='';
  221. }
  222. $stop = TimeGeneration();
  223. message_forum($lng['post_is_saved'],'topic.php?t='.$_GET['id'].$page.'#p'.$id);
  224. }
  225. else
  226. {
  227. $message = $lng['perror_1'];
  228. $msg = './skins/'.$default_skin.'/post_error_body.tpl';
  229. }
  230. }
  231. else
  232. {
  233. $_POST['textedit']='';
  234. }
  235. Secure::topic_exists(intval($_GET['id']));
  236. Secure::TopicLocked(intval($_GET['id']));
  237. $skin['mainpage'] = $lng['answer'].': '.Topic::TopicInformation(intval($_GET['id']),'name');
  238. $skin['lmainpage'] = '</a>&gt; <a href="posting.php?mode=rpost&amp;id='.intval($_GET['id']).'"
  239. class="navigator">'.$lng['answer'].': </a><a href="topic.php?t='.$_GET['id'].'"
  240. class="navigator">'.Topic::TopicInformation(intval($_GET['id']),'name');
  241. $skin['f_id'] = $_GET['id'];
  242. $skin['action'] = 'posting.php?mode=rpost&amp;id='.$_GET['id'];
  243. if ($msg=='')
  244. {
  245. $msg='./skins/'.$default_skin.'/blank.tpl';
  246. }
  247. include('./skins/'.$default_skin.'/overall_header.tpl');
  248. include('./skins/'.$default_skin.'/posting_body.tpl');
  249. include('./skins/'.$default_skin.'/overall_footer.tpl');
  250. break;
  251. }
  252. /**
  253. *
  254. Select new TOPIC
  255. *
  256. **/
  257. case 'ntopic': //new topic
  258. {
  259. $msg ='';
  260. if ((isset($_POST['textedit'])) and (isset($_POST['ntopic'])))
  261. {
  262. if (($_POST['textedit'] !='' ) and ($_POST['ntopic']!='') and (strlen(trim($_POST['textedit']))>10) and (strlen(trim($_POST['ntopic']))>5))
  263. {
  264. $_POST['textedit'] = Secure::TagsReplace($_POST['textedit']);
  265. if (isset($_COOKIE['antiflood_time']))
  266. {
  267. if ($_COOKIE['antiflood_time']>time())
  268. {
  269. message_forum($lng['antiflood_enabled'],$_SERVER['REQUEST_URI']);
  270. }
  271. }
  272. else
  273. {
  274. setcookie('antiflood_time',(time() + $forum_config['time_antiflood']));
  275. }
  276. $_POST['ntopic'] = strip_tags(addslashes($_POST['ntopic']));
  277. if (isset($_POST['topic_sticky']))
  278. {
  279. $_POST['topic_sticky']='1';
  280. }
  281. else
  282. {
  283. $_POST['topic_sticky']='0';
  284. }
  285. $last = Post::NewTopic($_POST['textedit'],$_POST['ntopic'], intval($_GET['f']), $_SESSION['uid'], $_POST['topic_sticky']);
  286. $stop = TimeGeneration();
  287. message_forum($lng['post_is_saved'],'topic.php?t='.$last);
  288. }
  289. else
  290. {
  291. $message = $lng['perror_1'];
  292. $msg = './skins/'.$default_skin.'/post_error_body.tpl';
  293. }
  294. }
  295. else
  296. {
  297. $_POST['ntopic'] = '';
  298. $_POST['textedit']='';
  299. }
  300. $sql = "SELECT `lock`, `name`, `f_id` FROM ".FORUMS_TABLE." WHERE `f_id`='".intval($_GET['f'])."'";
  301. $forum = DataBase::fetch(DataBase::sql_query($sql, GENERAL, 'Could not obtain forum information'));
  302. if($forum['name']=='')
  303. {
  304. message_forum($lng['no_forum'], 'index.php');
  305. }
  306. if($forum['lock']=='1')
  307. {
  308. message_forum($lng['no_posting_forum_locked'],'index.php');
  309. }
  310. $skin['mainpage'] = $lng['writetopic'];
  311. $skin['action'] = $_SERVER['REQUEST_URI'];
  312. $skin['lmainpage'] = '</a>&gt; <a href="forum.php?f='.$_GET['f'].'" class="navigator">'.$forum['name'].'</a> &gt;<a href="posting.php?mode=ntopic&amp;f='.$_GET['f'].'" class="navigator">'.$lng['writetopic'];
  313. $skin['f_id']=$_GET['f'];
  314. if ($msg=='')
  315. {
  316. $msg='./skins/'.$default_skin.'/blank.tpl';
  317. }
  318. include('./skins/'.$default_skin.'/overall_header.tpl');
  319. include('./skins/'.$default_skin.'/posting_body.tpl');
  320. include('./skins/'.$default_skin.'/overall_footer.tpl');
  321. break;
  322. }
  323. // if no mode... :D
  324. default:
  325. {
  326. $stop = TimeGeneration();
  327. message_forum($lng['invalidmode'],'index.php');
  328. break;
  329. }
  330. }