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.

291 lines
7.3 KiB

  1. <?php
  2. /**
  3. * @package uForum
  4. * @file posting.php
  5. * @version $Id$
  6. * @copyright 2007-2010 (c) PioDer <pioder@wp.pl>
  7. * @link http://www.pioder.pl/
  8. * @license see LICENSE.txt
  9. **/
  10. define('IN_uF', true);
  11. //include files
  12. require('./config.php');
  13. require('./includes/constants.php');
  14. require('./includes/db.php');
  15. require('./includes/errors.php');
  16. //connect to database
  17. DataBase::db_connect();
  18. require('./includes/sessions.php');
  19. require('./includes/classes/class_user.php');
  20. require('./common.php');
  21. require('./includes/misc_functions.php');
  22. require('./includes/classes/class_forum.php');
  23. require('./includes/classes/class_posting.php');
  24. require('./includes/classes/class_topic.php');
  25. require('./includes/classes/secure.php');
  26. require('./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']>$_SERVER['REQUEST_TIME'])
  64. {
  65. message_forum($lng['antiflood_enabled'],$_SERVER['REQUEST_URI']);
  66. }
  67. }
  68. else
  69. {
  70. setcookie('antiflood_time',($_SERVER['REQUEST_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. $window_title = $lng['writetopic'];
  214. $navigator_title = '<a href="forum.php?f='.$_GET['f'].'" class="navigator">'.$forum['name'].' &raquo; <a href="posting.php?mode=ntopic&amp;f='.$_GET['f'].'" class="navigator">'.$lng['writetopic'];
  215. break;
  216. }
  217. case 'edit':
  218. {
  219. $window_title = $lng['editpost'];
  220. $navigator_title = '<a href="posting.php?mode=edit&amp;id='.intval($_GET['id']).'" class="navigator">'.$lng['editpost'];
  221. break;
  222. }
  223. case 'rpost':
  224. {
  225. $window_title = $lng['answer'].': '.Topic::TopicInformation(intval($_GET['id']),'name');
  226. $navigator_title = '<a href="posting.php?mode=rpost&amp;id='.intval($_GET['id']).'" class="navigator">'.$lng['answer'].': </a><a href="topic.php?t='.$_GET['id'].'"
  227. class="navigator">'.Topic::TopicInformation(intval($_GET['id']),'name');
  228. break;
  229. }
  230. case 'qpost':
  231. {
  232. $window_title = $lng['quote'];
  233. $navigator_title = '<a href="posting.php?mode=qpost&amp;id='.$_GET['id'].'&amp;t='.$_GET['t'].'" class="navigator">'.$lng['quote'];
  234. break;
  235. }
  236. // if no mode... :D
  237. default:
  238. {
  239. $stop = TimeGeneration();
  240. message_forum($lng['invalidmode'],'index.php');
  241. break;
  242. }
  243. }
  244. $skin = array_push_assoc($skin, GenerateHeader($window_title, $navigator_title));
  245. $skin = array_push_assoc($skin, array(
  246. 'smiles'=>Post::SmilesShow(),
  247. //labels
  248. 'lsmiles'=>$lng['smiles'],
  249. 'ltopicname'=>$lng['ltopicname'],
  250. 'lsave'=>$lng['save'],
  251. 'lreset'=>$lng['reset'],
  252. 'lmsg'=>$lng['message'],
  253. 'lsticky_topic'=>$lng['sticky_topic'],
  254. 'lwritetopic'=>$lng['writetopic'],
  255. ));
  256. if ($msg=='')
  257. {
  258. $msg='./skins/'.$default_skin.'/blank.tpl';
  259. }
  260. //do it!
  261. require('./skins/'.$default_skin.'/overall_header.tpl');
  262. require('./skins/'.$default_skin.'/posting_body.tpl');
  263. require('./skins/'.$default_skin.'/overall_footer.tpl');
  264. ?>