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.

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