A new, object-oriented, better vesion of μForum
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.

535 lines
20 KiB

  1. <?php
  2. require_once('./inc/view.class.php');
  3. class MainView extends View
  4. {
  5. private function setDefaults($admin = false)
  6. {
  7. //logged user information
  8. $this->assign('is_logged', $this->getModel('SessionModel')->isLogged());
  9. $this->assign('my_nick', $this->getModel('SessionModel')->getNick());
  10. $this->assign('my_id', $this->getModel('SessionModel')->getID());
  11. $this->assign('my_rank', $this->getModel('SessionModel')->getRank());
  12. $this->assign('actual_time', date('Y-m-d G:i', $_SERVER['REQUEST_TIME']));
  13. //forum prefs
  14. $this->assign('forum_name', $this->getModel('ConfigModel')->getConf('forum_name'));
  15. $this->assign('forum_desc', $this->getModel('ConfigModel')->getConf('forum_desc'));
  16. //navigation
  17. $this->loadModel('NavigationModel');
  18. $this->getModel('NavigationModel')->setForumName($this->getModel('ConfigModel')->getConf('forum_name'));
  19. if ($admin)
  20. $this->getModel('NavigationModel')->addLink('ACP Admin', 'index.php?mode=admin');
  21. }
  22. //widok strony głównej
  23. public function main()
  24. {
  25. $this->setDefaults();
  26. // get categories, forums, forums statistics
  27. $this->loadModel('ForumsModel');
  28. $this->assign('forums_list', $this->getModel('ForumsModel')->getForums());
  29. //get data for bottom statistics
  30. $this->loadModel('StatisticsModel');
  31. $this->assign('posts_count', $this->getModel('StatisticsModel')->getPostsCount());
  32. $this->assign('users_count', $this->getModel('StatisticsModel')->getUsersCount());
  33. $this->assign('last_user', $this->getModel('StatisticsModel')->getLastRegisteredUser());
  34. $this->assign('logged_users_count', $this->getModel('StatisticsModel')->getLoggedUsersCount());
  35. $this->assign('logged_users', $this->getModel('StatisticsModel')->getLoggedUsers());
  36. //nawigacja po witrynie
  37. $this->getModel('NavigationModel')->setSubTitle('Main Page');
  38. $this->getModel('NavigationModel')->addLink('Main Page', 'index.php');
  39. // końcowe rzeczy
  40. $this->assign('nav', $this->getModel('NavigationModel')->getNav());
  41. $this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
  42. $this->show('main');
  43. }
  44. public function viewforum()
  45. {
  46. $this->setDefaults();
  47. // get forum info
  48. $f_info = $this->getModel('ForumsModel')->getForum($_GET['id']);
  49. $this->assign('f_name', $f_info['name']);
  50. $this->assign('forum_info', $f_info);
  51. $this->assign('topics_list', $this->getModel('ForumsModel')->getTopics($_GET['id']));
  52. //nawigacja po witrynie
  53. $this->getModel('NavigationModel')->setSubTitle('View forum: '.$f_info['name']);
  54. $this->getModel('NavigationModel')->addLink($f_info['name'], 'index.php?mode=viewforum&amp;id='.$_GET['id']);
  55. // końcowe rzeczy
  56. $this->assign('nav', $this->getModel('NavigationModel')->getNav());
  57. $this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
  58. $this->show('viewforum');
  59. }
  60. public function userlist()
  61. {
  62. $this->setDefaults();
  63. $this->loadModel('UsersModel');
  64. $this->assign('users_list', $this->getModel('UsersModel')->getUsers($_POST['sort_type'], $_POST['sort_desc'], $_GET['rank']));
  65. $this->assign('regdate_selected', ($_POST['sort_type'] == 'regdate') ? 'selected="selected"' : '');
  66. $this->assign('lastvisit_selected', ($_POST['sort_type'] == 'lastvisit') ? 'selected="selected"' : '');
  67. $this->assign('username_selected', ($_POST['sort_type'] == 'nick') ? 'selected="selected"' : '');
  68. $this->assign('posts_selected', ($_POST['sort_type'] == 'post_count') ? 'selected="selected"' : '');
  69. $this->assign('desc_checked', ($_POST['sort_desc'] == 'DESC') ? 'checked="checked"' : '');
  70. //nawigacja po witrynie
  71. $this->getModel('NavigationModel')->setSubTitle('Users list');
  72. $this->getModel('NavigationModel')->addLink('Users list', 'index.php?mode=userlist');
  73. // końcowe rzeczy
  74. $this->assign('nav', $this->getModel('NavigationModel')->getNav());
  75. $this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
  76. $this->show('userlist');
  77. }
  78. public function viewtopic()
  79. {
  80. $this->setDefaults();
  81. // get forum info
  82. $t_info = $this->getModel('PostsModel')->getTopic($_GET['id']);
  83. $this->assign('topic_info', $t_info);
  84. $this->assign('posts_list', $this->getModel('PostsModel')->getPosts($_GET['id']));
  85. //nawigacja po witrynie
  86. $this->getModel('NavigationModel')->setSubTitle('View topic: '.$t_info['topic_title']);
  87. $this->getModel('NavigationModel')->addLink($t_info['forum_name'], 'index.php?mode=viewforum&amp;id='.$t_info['forum_id']);
  88. $this->getModel('NavigationModel')->addLink($t_info['topic_title'], 'index.php?mode=viewtopic&amp;id='.$_GET['id']);
  89. // końcowe rzeczy
  90. $this->assign('nav', $this->getModel('NavigationModel')->getNav());
  91. $this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
  92. $this->show('viewtopic');
  93. }
  94. public function login_form($msg)
  95. {
  96. $this->setDefaults();
  97. $this->assign('nick', $_POST['nick']);
  98. $this->assign('error_msg', $msg);
  99. //nawigacja po witrynie
  100. $this->getModel('NavigationModel')->setSubTitle('Log in');
  101. $this->getModel('NavigationModel')->addLink('Log in', 'index.php?mode=login');
  102. // końcowe rzeczy
  103. $this->assign('nav', $this->getModel('NavigationModel')->getNav());
  104. $this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
  105. $this->show('login_form');
  106. }
  107. public function register_form($msg)
  108. {
  109. $this->setDefaults();
  110. $this->assign('nick', $_POST['nick']);
  111. $this->assign('email', $_POST['email']);
  112. $this->assign('error_msg', $msg);
  113. //nawigacja po witrynie
  114. $this->getModel('NavigationModel')->setSubTitle('Register');
  115. $this->getModel('NavigationModel')->addLink('Register', 'index.php?mode=register');
  116. // końcowe rzeczy
  117. $this->assign('nav', $this->getModel('NavigationModel')->getNav());
  118. $this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
  119. $this->show('register_form');
  120. }
  121. public function viewprofile()
  122. {
  123. $this->setDefaults();
  124. $this->loadModel('StatisticsModel');
  125. $user_info = $this->getModel('UsersModel')->getUserInformation($_GET['id']);
  126. $this->assign('user_info', $user_info);
  127. $total_posts = $this->getModel('StatisticsModel')->getPostsCount();
  128. $posts_ration = ($total_posts > 0) ? round(100*$user_info['post_count']/$total_posts, 2) : 0;
  129. $this->assign('post_ratio', $total_posts);
  130. $this->assign('logged_id', $this->getModel('SessionModel')->getID());
  131. //nawigacja po witrynie
  132. $this->getModel('NavigationModel')->addLink('Users list', 'index.php?mode=userlist');
  133. $this->getModel('NavigationModel')->setSubTitle('View profile: '.$user_info['nick']);
  134. $this->getModel('NavigationModel')->addLink('Profile: '.$user_info['nick'], 'index.php?mode=viewprofile&amp;id='.$_GET['id']);
  135. // końcowe rzeczy
  136. $this->assign('nav', $this->getModel('NavigationModel')->getNav());
  137. $this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
  138. $this->show('viewprofile');
  139. }
  140. public function edprofile_form($msg, $admin = false)
  141. {
  142. $this->setDefaults($admin);
  143. if ($admin)
  144. $user_info = $this->getModel('UsersModel')->getUserInformation($_GET['id']);
  145. else
  146. $user_info = $this->getModel('UsersModel')->getUserInformation($this->getModel('SessionModel')->getID());
  147. $this->assign('nick', $_POST['nick']);
  148. $this->assign('is_admin', $admin);
  149. $this->assign('email', $_POST['email']);
  150. $this->assign('location', $_POST['location']);
  151. $this->assign('signature', $_POST['signature']);
  152. $this->assign('avatar', $user_info['avatar']);
  153. $this->assign('error_msg', $msg);
  154. if ($admin)
  155. {
  156. $this->assign('user_selected', ($_POST['user_rank'] == RANK_USER) ? 'checked="checked"' : '');
  157. $this->assign('mod_selected', ($_POST['user_rank'] == RANK_MOD) ? 'checked="checked"' : '');
  158. $this->assign('admin_selected', ($_POST['user_rank'] == RANK_ADMIN) ? 'checked="checked"' : '');
  159. }
  160. //nawigacja po witrynie
  161. if ($admin)
  162. {
  163. $this->getModel('NavigationModel')->setSubTitle('ACP &bull; Edit profile');
  164. $this->getModel('NavigationModel')->addLink('Users list', 'index.php?mode=admin&amp;submode=users');
  165. $this->getModel('NavigationModel')->addLink('Edit user: '.$user_info['nick']);
  166. }
  167. else
  168. {
  169. $this->getModel('NavigationModel')->setSubTitle('Edit profile');
  170. $this->getModel('NavigationModel')->addLink('Edit profile', 'index.php?mode=editprofile');
  171. }
  172. // końcowe rzeczy
  173. $this->assign('nav', $this->getModel('NavigationModel')->getNav());
  174. $this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
  175. $this->show('edprofile');
  176. }
  177. public function posting_form($type, $msg='')
  178. {
  179. $this->setDefaults();
  180. $this->assign('error_msg', $msg);
  181. //nawigacja po witrynie
  182. switch ($type)
  183. {
  184. case POSTING_NEWTOPIC:
  185. $forum_info = $this->getModel('ForumsModel')->getForum($_GET['id']);
  186. $this->getModel('NavigationModel')->setSubTitle('New topic');
  187. $this->getModel('NavigationModel')->addLink($forum_info['name'], 'index.php?mode=viewforum&amp;id='.$forum_info['forum_id']);
  188. $this->getModel('NavigationModel')->addLink('New topic', $_SERVER['REQUEST_URI']);
  189. break;
  190. case POSTING_REPLY:
  191. case POSTING_QUOTE:
  192. $topic_info = $this->getModel('PostsModel')->getTopic($_GET['id']);
  193. $this->getModel('NavigationModel')->setSubTitle('Reply');
  194. $this->getModel('NavigationModel')->addLink($topic_info['forum_name'], 'index.php?mode=viewforum&amp;id='.$topic_info['forum_id']);
  195. $this->getModel('NavigationModel')->addLink($topic_info['topic_title'], 'index.php?mode=viewtopic&amp;id='.$topic_info['topic_id']);
  196. $this->getModel('NavigationModel')->addLink('Write a reply', $_SERVER['REQUEST_URI']);
  197. break;
  198. case POSTING_EDIT:
  199. $topic_info = $this->getModel('PostsModel')->getTopic($_GET['id']);
  200. $this->getModel('NavigationModel')->setSubTitle('Edit post');
  201. $this->getModel('NavigationModel')->addLink($topic_info['forum_name'], 'index.php?mode=viewforum&amp;id='.$topic_info['forum_id']);
  202. $this->getModel('NavigationModel')->addLink($topic_info['topic_title'], 'index.php?mode=viewtopic&amp;id='.$topic_info['topic_id']);
  203. $this->getModel('NavigationModel')->addLink('Edit post', $_SERVER['REQUEST_URI']);
  204. break;
  205. case POSTING_EDITTOPIC:
  206. $topic_info = $this->getModel('PostsModel')->getTopic($_GET['id']);
  207. $this->getModel('NavigationModel')->setSubTitle('Edit topic');
  208. $this->getModel('NavigationModel')->addLink($topic_info['forum_name'], 'index.php?mode=viewforum&amp;id='.$topic_info['forum_id']);
  209. $this->getModel('NavigationModel')->addLink($topic_info['topic_title'], 'index.php?mode=viewtopic&amp;id='.$topic_info['topic_id']);
  210. $this->getModel('NavigationModel')->addLink('Edit topic', $_SERVER['REQUEST_URI']);
  211. break;
  212. }
  213. $this->assign('post', $_POST['post']);
  214. if (isset($_POST['preview']))
  215. $this->assign('preview', addslashes(htmlspecialchars($_POST['post'])));
  216. if ($type == POSTING_NEWTOPIC || $type == POSTING_EDITTOPIC)
  217. $this->assign('topic', $_POST['topic']);
  218. // końcowe rzeczy
  219. $this->assign('nav', $this->getModel('NavigationModel')->getNav());
  220. $this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
  221. $this->show('posting');
  222. }
  223. public function move_topic()
  224. {
  225. $this->setDefaults();
  226. $this->loadModel('ForumsModel');
  227. //nawigacja po witrynie
  228. $this->getModel('NavigationModel')->setSubTitle('Move topic');
  229. $this->getModel('NavigationModel')->addLink('Move topic', $_SERVER['REQUEST_URI']);
  230. $this->assign('topic_info', $this->getModel('PostsModel')->getTopic($_GET['id']));
  231. $this->assign('forums_list', $this->getModel('ForumsModel')->getForumsNames());
  232. // końcowe rzeczy
  233. $this->assign('nav', $this->getModel('NavigationModel')->getNav());
  234. $this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
  235. $this->show('move_topic');
  236. }
  237. public function forum_message($msg, $url = '', $timeout = 2)
  238. {
  239. $this->setDefaults();
  240. $this->assign('message', $msg);
  241. $this->assign('url', $url);
  242. $this->assign('timeout', $timeout);
  243. //nawigacja po witrynie
  244. $this->getModel('NavigationModel')->setSubTitle('Forum message');
  245. $this->getModel('NavigationModel')->addLink('Forum message', 'index.php');
  246. // końcowe rzeczy
  247. $this->assign('nav', $this->getModel('NavigationModel')->getNav());
  248. $this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
  249. $this->show('forum_message');
  250. }
  251. public function confirm_action($msg)
  252. {
  253. $this->setDefaults();
  254. $this->assign('message', $msg);
  255. //nawigacja po witrynie
  256. $this->getModel('NavigationModel')->setSubTitle('Confirm action');
  257. $this->getModel('NavigationModel')->addLink('Confirm action', $_SERVER['REQUEST_URI']);
  258. // końcowe rzeczy
  259. $this->assign('nav', $this->getModel('NavigationModel')->getNav());
  260. $this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
  261. $this->show('confirm_action');
  262. }
  263. public function colorRank($username, $rank)
  264. {
  265. if ($rank == RANK_ADMIN)
  266. return '<span class="fadmin">'.$username.'</span>';
  267. if ($rank == RANK_MOD)
  268. return '<span class="fmod">'.$username.'</span>';
  269. return $username;
  270. }
  271. public function getRankLevel($rank)
  272. {
  273. if ($rank == RANK_ADMIN)
  274. return $this->colorRank('Admin', $rank);
  275. if ($rank == RANK_MOD)
  276. return $this->colorRank('Mod', $rank);
  277. return 'User';
  278. }
  279. // ADMIN PANEL -----------------------------------------------------------------
  280. public function admin_main()
  281. {
  282. $this->setDefaults(true);
  283. $this->loadModel('StatisticsModel');
  284. //nawigacja po witrynie
  285. $this->getModel('NavigationModel')->setSubTitle('Main Page');
  286. $this->assign('installation_date', $this->getModel('ConfigModel')->getConf('installation_date'));
  287. $this->assign('topics_total', $this->getModel('StatisticsModel')->getTopicsCount());
  288. $this->assign('posts_total', $this->getModel('StatisticsModel')->getPostsCount());
  289. $this->assign('users_total', $this->getModel('StatisticsModel')->getUsersCount());
  290. $this->assign('script_version', VERSION);
  291. $this->assign('logged_users', $this->getModel('StatisticsModel')->getLoggedUsers());
  292. $this->assign('logged_users_total', $this->getModel('StatisticsModel')->getLoggedUsersCount());
  293. // końcowe rzeczy
  294. $this->assign('nav', $this->getModel('NavigationModel')->getNav());
  295. $this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
  296. $this->show('admin/main');
  297. }
  298. public function admin_userlist()
  299. {
  300. $this->setDefaults(true);
  301. $this->loadModel('UsersModel');
  302. $this->assign('users_list', $this->getModel('UsersModel')->getUsers($_POST['sort_type'], $_POST['sort_desc'], $_GET['rank']));
  303. $this->assign('regdate_selected', ($_POST['sort_type'] == 'regdate') ? 'selected="selected"' : '');
  304. $this->assign('lastvisit_selected', ($_POST['sort_type'] == 'lastvisit') ? 'selected="selected"' : '');
  305. $this->assign('username_selected', ($_POST['sort_type'] == 'nick') ? 'selected="selected"' : '');
  306. $this->assign('posts_selected', ($_POST['sort_type'] == 'post_count') ? 'selected="selected"' : '');
  307. $this->assign('desc_checked', ($_POST['sort_desc'] == 'DESC') ? 'checked="checked"' : '');
  308. //nawigacja po witrynie
  309. $this->getModel('NavigationModel')->setSubTitle('ACP &bull; Users list');
  310. $this->getModel('NavigationModel')->addLink('Users list');
  311. // końcowe rzeczy
  312. $this->assign('nav', $this->getModel('NavigationModel')->getNav());
  313. $this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
  314. $this->show('admin/userlist');
  315. }
  316. public function admin_config($msg)
  317. {
  318. $this->setDefaults(true);
  319. $this->loadModel('UsersModel');
  320. $this->assign('forum_name', $_POST['forum_name']);
  321. $this->assign('forum_desc', $_POST['forum_desc']);
  322. $this->assign('error_msg', $msg);
  323. //nawigacja po witrynie
  324. $this->getModel('NavigationModel')->setSubTitle('ACP &bull; Admin config');
  325. $this->getModel('NavigationModel')->addLink('Forum configuration');
  326. // końcowe rzeczy
  327. $this->assign('nav', $this->getModel('NavigationModel')->getNav());
  328. $this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
  329. $this->show('admin/config');
  330. }
  331. //widok strony głównej
  332. public function admin_forums()
  333. {
  334. $this->setDefaults(true);
  335. // get categories, forums, forums statistics
  336. $this->loadModel('ForumsModel');
  337. $this->assign('forums_list', $this->getModel('ForumsModel')->getForums());
  338. //nawigacja po witrynie
  339. $this->getModel('NavigationModel')->setSubTitle('ACP &bull; Forums list');
  340. $this->getModel('NavigationModel')->addLink('Forums list');
  341. // końcowe rzeczy
  342. $this->assign('nav', $this->getModel('NavigationModel')->getNav());
  343. $this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
  344. $this->show('admin/forums');
  345. }
  346. public function admin_cat_form($msg, $m)
  347. {
  348. $this->setDefaults(true);
  349. $this->assign('name', $_POST['name']);
  350. $this->assign('error_msg', $msg);
  351. //nawigacja po witrynie
  352. $this->getModel('NavigationModel')->addLink('Forums list', 'index.php?mode=admin&amp;submode=forums');
  353. if ($m == 'add')
  354. {
  355. $this->getModel('NavigationModel')->setSubTitle('ACP &bull; Add category');
  356. $this->getModel('NavigationModel')->addLink('Add category');
  357. $this->assign('cat_form_name', 'Add new category');
  358. }
  359. else
  360. {
  361. $cat_info = $this->getModel('ForumsModel')->getCat($_GET['id']);
  362. $this->getModel('NavigationModel')->setSubTitle('ACP &bull; Edit category');
  363. $this->getModel('NavigationModel')->addLink('Edit category: '.$cat_info['name']);
  364. $this->assign('cat_form_name', 'Edit category');
  365. }
  366. // końcowe rzeczy
  367. $this->assign('nav', $this->getModel('NavigationModel')->getNav());
  368. $this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
  369. $this->show('admin/cat_form');
  370. }
  371. public function admin_forum_form($msg, $m)
  372. {
  373. $this->setDefaults(true);
  374. $this->assign('name', $_POST['name']);
  375. $this->assign('desc', $_POST['desc']);
  376. $this->assign('category_id', $_POST['category_id']);
  377. $this->assign('lock_selected', ($_POST['locked']) ? 'checked="checked"' : '');
  378. $this->assign('unlock_selected', (!$_POST['locked']) ? 'checked="checked"' : '');
  379. $this->assign('error_msg', $msg);
  380. $this->assign('cats_list', $this->getModel('ForumsModel')->getCats());
  381. //nawigacja po witrynie
  382. $this->getModel('NavigationModel')->addLink('Forums list', 'index.php?mode=admin&amp;submode=forums');
  383. if ($m == 'add')
  384. {
  385. $this->getModel('NavigationModel')->setSubTitle('ACP &bull; Add forum');
  386. $this->getModel('NavigationModel')->addLink('Add forum');
  387. $this->assign('forum_form_name', 'Add new forum');
  388. }
  389. else
  390. {
  391. $forum_info = $this->getModel('ForumsModel')->getForum($_GET['id']);
  392. $this->getModel('NavigationModel')->setSubTitle('ACP &bull; Edit forum');
  393. $this->getModel('NavigationModel')->addLink('Edit forum'.$forum_info['name']);
  394. $this->assign('forum_form_name', 'Edit forum');
  395. }
  396. // końcowe rzeczy
  397. $this->assign('nav', $this->getModel('NavigationModel')->getNav());
  398. $this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
  399. $this->show('admin/forum_form');
  400. }
  401. public function admin_banlist()
  402. {
  403. $this->setDefaults(true);
  404. $this->loadModel('BansModel');
  405. $this->assign('bans_list', $this->getModel('BansModel')->getBans());
  406. //nawigacja po witrynie
  407. $this->getModel('NavigationModel')->setSubTitle('ACP &bull; Banlist');
  408. $this->getModel('NavigationModel')->addLink('Banlist');
  409. // końcowe rzeczy
  410. $this->assign('nav', $this->getModel('NavigationModel')->getNav());
  411. $this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
  412. $this->show('admin/banlist');
  413. }
  414. public function admin_ban_form($msg)
  415. {
  416. $this->setDefaults(true);
  417. $this->assign('user_id', $_POST['user_id']);
  418. $this->assign('reason', $_POST['reason']);
  419. $this->loadModel('UsersModel');
  420. $this->assign('error_msg', $msg);
  421. $this->assign('users_list', $this->getModel('UsersModel')->getUsersNicks());
  422. //nawigacja po witrynie
  423. $this->getModel('NavigationModel')->addLink('Banlist', 'index.php?mode=admin&amp;submode=banlist');
  424. $this->getModel('NavigationModel')->setSubTitle('ACP &bull; Add ban');
  425. $this->getModel('NavigationModel')->addLink('Add ban');
  426. $this->assign('forum_form_name', 'Add ban');
  427. // końcowe rzeczy
  428. $this->assign('nav', $this->getModel('NavigationModel')->getNav());
  429. $this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
  430. $this->show('admin/ban_form');
  431. }
  432. }
  433. ?>