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.

302 lines
7.4 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. $start = TimeGeneration();
  38. //add skin variables
  39. $skin = array();
  40. $skin = array_push_assoc($skin, GenerateHeader('',''));
  41. $stop = TimeGeneration();
  42. $skin['queries'] = ShowQueries($start, $stop);
  43. if (isset($_POST['textedit']))
  44. {
  45. $errors = false;
  46. //check post form
  47. if (($_POST['textedit'] =='' ) or (strlen(trim($_POST['textedit']))<10))
  48. {
  49. $errors = true;
  50. $message = $lng['perror_1'];
  51. }
  52. if ($_GET['mode'] == 'ntopic')
  53. {
  54. if (($_POST['ntopic']!='') or (strlen(trim($_POST['ntopic']))>5))
  55. {
  56. $errors = true;
  57. $message = $lng['perror_3'];
  58. }
  59. }
  60. //antiflood lock
  61. if (isset($_COOKIE['antiflood_time']))
  62. {
  63. if ($_COOKIE['antiflood_time']>time())
  64. {
  65. message_forum($lng['antiflood_enabled'],$_SERVER['REQUEST_URI']);
  66. }
  67. }
  68. else
  69. {
  70. setcookie('antiflood_time',(time() + $forum_config['time_antiflood']));
  71. }
  72. //prepare post...
  73. if (!$errors)
  74. {
  75. $_POST['textedit'] = Secure::TagsReplace($_POST['textedit']);
  76. if ($_GET['mode']=='ntopic')
  77. {
  78. $_POST['ntopic'] = Secure::UseCensorlist(strip_tags(trim($_POST['ntopic'])));
  79. if (isset($_POST['topic_sticky']))
  80. {
  81. $_POST['topic_sticky']='1';
  82. }
  83. else
  84. {
  85. $_POST['topic_sticky']='0';
  86. }
  87. }
  88. //do it!
  89. switch ($_GET['mode'])
  90. {
  91. case 'rpost':
  92. {
  93. $id = Post::NewPost(intval($_GET['id']),$_POST['textedit'], $_SESSION['uid']);
  94. $count =ceil(($id / 15 ));
  95. if ($count >1)
  96. {
  97. $page= '&amp;page='.$count;
  98. }
  99. else
  100. {
  101. $page='';
  102. }
  103. $redirect_url = 'topic.php?t='.$_GET['id'].$page.'#p'.$id;
  104. break;
  105. }
  106. case 'qpost':
  107. {
  108. $id = Post::NewPost(intval($_GET['id']),$_POST['textedit'], $_SESSION['uid']);
  109. $count =ceil(($id / 15 ));
  110. if ($count >1)
  111. {
  112. $page= '&amp;page='.$count;
  113. }
  114. else
  115. {
  116. $page='';
  117. }
  118. $redirect_url = 'topic.php?t='.$_GET['id'].$page.'#p'.$id;
  119. break;
  120. }
  121. case 'edit':
  122. {
  123. Post::EditPost(intval($_GET['id']),$_POST['textedit']);
  124. $count = ceil((Topic::PostInformation(intval($_GET['id']),'tp_id') / 15 ));
  125. if ($count >1)
  126. {
  127. $page= '&amp;page='.$count;
  128. }
  129. else
  130. {
  131. $page='';
  132. }
  133. $redirect_url = 'topic.php?t='.Topic::PostInformation(intval($_GET['id']),'t_id').$page.'#p'.$_GET['id'];
  134. break;
  135. }
  136. case 'ntopic':
  137. {
  138. $last = Post::NewTopic($_POST['textedit'],$_POST['ntopic'], intval($_GET['f']), $_SESSION['uid'], $_POST['topic_sticky']);
  139. $redirect_url = 'topic.php?t='.$last;
  140. break;
  141. }
  142. }
  143. //redirecting to topic page...
  144. $stop = TimeGeneration();
  145. message_forum($lng['post_is_saved'], $redirect_url);
  146. }
  147. else
  148. {
  149. $msg = './skins/'.$default_skin.'/post_error_body.tpl';
  150. }
  151. }
  152. else
  153. {
  154. switch($_GET['mode'])
  155. {
  156. case 'qpost':
  157. {
  158. $_POST['textedit'] = (empty($_POST['textedit'])) ? '[quote]'.stripslashes(Topic::PostInformation($_GET['id'],'text')).'[/quote]' : $_POST['textedit'];
  159. break;
  160. }
  161. case 'edit':
  162. {
  163. $_POST['textedit'] = (empty($_POST['textedit'])) ? stripslashes(Topic::PostInformation($_GET['id'],'text')) : $_POST['textedit'];
  164. break;
  165. }
  166. case 'rpost':
  167. {
  168. $_POST['textedit'] = (empty($_POST['textedit'])) ? '' : $_POST['textedit'];
  169. break;
  170. }
  171. case 'ntopic':
  172. {
  173. $_POST['textedit'] = (empty($_POST['textedit'])) ? '' : $_POST['textedit'];
  174. $_POST['ntopic'] = (empty($_POST['ntopic'])) ? '' : $_POST['ntopic'];
  175. break;
  176. }
  177. }
  178. }
  179. //generating output page
  180. if ($_GET['mode'] == 'rpost' || $_GET['mode'] == 'qpost')
  181. {
  182. Secure::topic_exists(intval($_GET['id']));
  183. Secure::TopicLocked(intval($_GET['id']));
  184. }
  185. if ($_GET['mode'] == 'ntopic')
  186. {
  187. $sql = "SELECT `lock`, `name`, `f_id` FROM ".FORUMS_TABLE." WHERE `f_id`='".intval($_GET['f'])."'";
  188. $forum = DataBase::fetch(DataBase::sql_query($sql, GENERAL, 'Could not obtain forum information'));
  189. if($forum['name']=='')
  190. {
  191. message_forum($lng['no_forum'], 'index.php');
  192. }
  193. if($forum['lock']=='1')
  194. {
  195. message_forum($lng['no_posting_forum_locked'],'index.php', 5);
  196. }
  197. }
  198. if ($_GET['mode']=='edit')
  199. {
  200. if (Topic::PostInformation(trim(strip_tags($_GET['id'])), 'p_id')== '')
  201. {
  202. message_forum($lng['no_message'], 'index.php');
  203. }
  204. if ((!User::RankAdminMod($_SESSION['uid'])) or ($_SESSION['uid']!=Topic::PostInformation($_GET['id'],'u_id')))
  205. {
  206. message_forum($lng['perror_2'], 'index.php');
  207. }
  208. }
  209. switch ($_GET['mode'])
  210. {
  211. case 'ntopic':
  212. {
  213. $skin = array_push_assoc($skin, array(
  214. 'mainpage' => $lng['writetopic'],
  215. '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']
  216. ));
  217. break;
  218. }
  219. case 'edit':
  220. {
  221. $skin = array_push_assoc($skin, array(
  222. 'mainpage' => $lng['editpost'],
  223. 'lmainpage' => '</a>&gt; <a href="posting.php?mode=edit&amp;id='.intval($_GET['id']).'"
  224. class="navigator">'.$lng['editpost']
  225. ));
  226. break;
  227. }
  228. case 'rpost':
  229. {
  230. $skin = array_push_assoc($skin, array(
  231. 'mainpage' => $lng['answer'].': '.Topic::TopicInformation(intval($_GET['id']),'name'),
  232. 'lmainpage' => '</a>&gt; <a href="posting.php?mode=rpost&amp;id='.intval($_GET['id']).'"
  233. class="navigator">'.$lng['answer'].': </a><a href="topic.php?t='.$_GET['id'].'"
  234. class="navigator">'.Topic::TopicInformation(intval($_GET['id']),'name')
  235. ));
  236. break;
  237. }
  238. case 'qpost':
  239. {
  240. $skin = array_push_assoc($skin, array(
  241. 'mainpage' => $lng['quote'],
  242. 'lmainpage' => '</a>&gt; <a href="posting.php?mode=qpost&amp;id='.$_GET['id'].'&amp;t='.$_GET['t'].'"
  243. class="navigator">'.$lng['quote']
  244. ));
  245. break;
  246. }
  247. // if no mode... :D
  248. default:
  249. {
  250. $stop = TimeGeneration();
  251. message_forum($lng['invalidmode'],'index.php');
  252. break;
  253. }
  254. }
  255. $skin = array_push_assoc($skin, array(
  256. 'smiles'=>Post::SmilesShow(),
  257. //labels
  258. 'lsmiles'=>$lng['smiles'],
  259. 'ltopicname'=>$lng['ltopicname'],
  260. 'lsave'=>$lng['save'],
  261. 'lreset'=>$lng['reset'],
  262. 'lmsg'=>$lng['message'],
  263. 'lsticky_topic'=>$lng['sticky_topic'],
  264. 'lwritetopic'=>$lng['writetopic'],
  265. ));
  266. if ($msg=='')
  267. {
  268. $msg='./skins/'.$default_skin.'/blank.tpl';
  269. }
  270. //do it!
  271. include('./skins/'.$default_skin.'/overall_header.tpl');
  272. include('./skins/'.$default_skin.'/posting_body.tpl');
  273. include('./skins/'.$default_skin.'/overall_footer.tpl');
  274. ?>