|
|
- <?php
- /**
- * @package uForum2
- * @file inc/views/MainView.class.php
- * @copyright 2007-2015 (c) PioDer <piotrek@pioder.pl>
- * @link http://www.pioder.pl/
- * @license see LICENSE.txt
- **/
-
- class MainView extends View
- {
- private function setDefaults($admin = false)
- {
- //logged user information
- $this->assign('is_logged', $this->getModel('SessionModel')->isLogged());
- $this->assign('my_nick', $this->getModel('SessionModel')->getNick());
- $this->assign('my_id', $this->getModel('SessionModel')->getID());
- $this->assign('my_rank', $this->getModel('SessionModel')->getRank());
- $this->assign('actual_time', date('Y-m-d G:i', $_SERVER['REQUEST_TIME']));
-
- //forum prefs
- $this->assign('forum_name', $this->getModel('ConfigModel')->getConf('forum_name'));
- $this->assign('forum_desc', $this->getModel('ConfigModel')->getConf('forum_desc'));
-
- //navigation
- $this->loadModel('NavigationModel');
- $this->getModel('NavigationModel')->setForumName($this->getModel('ConfigModel')->getConf('forum_name'));
- if ($admin)
- $this->getModel('NavigationModel')->addLink('ACP Admin', 'index.php?mode=admin');
- }
-
- //widok strony głównej
- public function main()
- {
- $this->setDefaults();
-
- // get categories, forums, forums statistics
- $this->loadModel('ForumsModel');
- $this->assign('forums_list', $this->getModel('ForumsModel')->getForums());
-
- //get data for bottom statistics
- $this->loadModel('StatisticsModel');
- $this->assign('posts_count', $this->getModel('StatisticsModel')->getPostsCount());
- $this->assign('users_count', $this->getModel('StatisticsModel')->getUsersCount());
- $this->assign('last_user', $this->getModel('StatisticsModel')->getLastRegisteredUser());
- $this->assign('logged_users_count', $this->getModel('StatisticsModel')->getLoggedUsersCount());
- $this->assign('logged_users', $this->getModel('StatisticsModel')->getLoggedUsers());
-
- //nawigacja po witrynie
- $this->getModel('NavigationModel')->setSubTitle('Main Page');
- $this->getModel('NavigationModel')->addLink('Main Page', 'index.php');
-
- // końcowe rzeczy
- $this->assign('nav', $this->getModel('NavigationModel')->getNav());
- $this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
- $this->show('main');
- }
-
- public function viewforum()
- {
- $this->setDefaults();
-
- // get forum info
- $f_info = $this->getModel('ForumsModel')->getForum($_GET['id']);
-
- $this->assign('f_name', $f_info['name']);
- $this->assign('forum_info', $f_info);
- $this->assign('topics_list', $this->getModel('ForumsModel')->getTopics($_GET['id']));
- //nawigacja po witrynie
- $this->getModel('NavigationModel')->setSubTitle('View forum: '.$f_info['name']);
- $this->getModel('NavigationModel')->addLink($f_info['name'], 'index.php?mode=viewforum&id='.$_GET['id']);
-
- // końcowe rzeczy
- $this->assign('nav', $this->getModel('NavigationModel')->getNav());
- $this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
- $this->show('viewforum');
- }
-
- public function userlist()
- {
- $this->setDefaults();
-
- $this->loadModel('UsersModel');
- $this->assign('users_list', $this->getModel('UsersModel')->getUsers($_POST['sort_type'], $_POST['sort_desc'], $_GET['rank']));
-
- $this->assign('regdate_selected', ($_POST['sort_type'] == 'regdate') ? 'selected="selected"' : '');
- $this->assign('lastvisit_selected', ($_POST['sort_type'] == 'lastvisit') ? 'selected="selected"' : '');
- $this->assign('username_selected', ($_POST['sort_type'] == 'nick') ? 'selected="selected"' : '');
- $this->assign('posts_selected', ($_POST['sort_type'] == 'post_count') ? 'selected="selected"' : '');
- $this->assign('desc_checked', ($_POST['sort_desc'] == 'DESC') ? 'checked="checked"' : '');
-
- //nawigacja po witrynie
- $this->getModel('NavigationModel')->setSubTitle('Users list');
- $this->getModel('NavigationModel')->addLink('Users list', 'index.php?mode=userlist');
-
- // końcowe rzeczy
- $this->assign('nav', $this->getModel('NavigationModel')->getNav());
- $this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
- $this->show('userlist');
- }
-
- public function viewtopic()
- {
- $this->setDefaults();
-
- // get forum info
- $t_info = $this->getModel('PostsModel')->getTopic($_GET['id']);
-
- $this->assign('topic_info', $t_info);
- $this->assign('posts_list', $this->getModel('PostsModel')->getPosts($_GET['id']));
- //nawigacja po witrynie
- $this->getModel('NavigationModel')->setSubTitle('View topic: '.$t_info['topic_title']);
- $this->getModel('NavigationModel')->addLink($t_info['forum_name'], 'index.php?mode=viewforum&id='.$t_info['forum_id']);
- $this->getModel('NavigationModel')->addLink($t_info['topic_title'], 'index.php?mode=viewtopic&id='.$_GET['id']);
-
- // końcowe rzeczy
- $this->assign('nav', $this->getModel('NavigationModel')->getNav());
- $this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
- $this->show('viewtopic');
- }
-
- public function login_form($msg)
- {
- $this->setDefaults();
-
- $this->assign('nick', $_POST['nick']);
- $this->assign('error_msg', $msg);
-
- //nawigacja po witrynie
- $this->getModel('NavigationModel')->setSubTitle('Log in');
- $this->getModel('NavigationModel')->addLink('Log in', 'index.php?mode=login');
-
- // końcowe rzeczy
- $this->assign('nav', $this->getModel('NavigationModel')->getNav());
- $this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
- $this->show('login_form');
- }
-
- public function register_form($msg)
- {
- $this->setDefaults();
-
- $this->assign('nick', $_POST['nick']);
- $this->assign('email', $_POST['email']);
- $this->assign('error_msg', $msg);
-
- //nawigacja po witrynie
- $this->getModel('NavigationModel')->setSubTitle('Register');
- $this->getModel('NavigationModel')->addLink('Register', 'index.php?mode=register');
-
- // końcowe rzeczy
- $this->assign('nav', $this->getModel('NavigationModel')->getNav());
- $this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
- $this->show('register_form');
- }
-
- public function viewprofile()
- {
- $this->setDefaults();
- $this->loadModel('StatisticsModel');
-
- $user_info = $this->getModel('UsersModel')->getUserInformation($_GET['id']);
-
- $this->assign('user_info', $user_info);
- $total_posts = $this->getModel('StatisticsModel')->getPostsCount();
- $posts_ration = ($total_posts > 0) ? round(100*$user_info['post_count']/$total_posts, 2) : 0;
- $this->assign('post_ratio', $total_posts);
- $this->assign('logged_id', $this->getModel('SessionModel')->getID());
-
- //nawigacja po witrynie
- $this->getModel('NavigationModel')->addLink('Users list', 'index.php?mode=userlist');
- $this->getModel('NavigationModel')->setSubTitle('View profile: '.$user_info['nick']);
- $this->getModel('NavigationModel')->addLink('Profile: '.$user_info['nick'], 'index.php?mode=viewprofile&id='.$_GET['id']);
-
- // końcowe rzeczy
- $this->assign('nav', $this->getModel('NavigationModel')->getNav());
- $this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
- $this->show('viewprofile');
- }
-
- public function edprofile_form($msg, $admin = false)
- {
- $this->setDefaults($admin);
-
- if ($admin)
- $user_info = $this->getModel('UsersModel')->getUserInformation($_GET['id']);
- else
- $user_info = $this->getModel('UsersModel')->getUserInformation($this->getModel('SessionModel')->getID());
- $this->assign('nick', $_POST['nick']);
- $this->assign('is_admin', $admin);
- $this->assign('email', $_POST['email']);
- $this->assign('location', $_POST['location']);
- $this->assign('signature', $_POST['signature']);
- $this->assign('avatar', $user_info['avatar']);
- $this->assign('error_msg', $msg);
-
- if ($admin)
- {
- $this->assign('user_selected', ($_POST['user_rank'] == RANK_USER) ? 'checked="checked"' : '');
- $this->assign('mod_selected', ($_POST['user_rank'] == RANK_MOD) ? 'checked="checked"' : '');
- $this->assign('admin_selected', ($_POST['user_rank'] == RANK_ADMIN) ? 'checked="checked"' : '');
- }
-
- //nawigacja po witrynie
- if ($admin)
- {
- $this->getModel('NavigationModel')->setSubTitle('ACP • Edit profile');
- $this->getModel('NavigationModel')->addLink('Users list', 'index.php?mode=admin&submode=users');
- $this->getModel('NavigationModel')->addLink('Edit user: '.$user_info['nick']);
- }
- else
- {
- $this->getModel('NavigationModel')->setSubTitle('Edit profile');
- $this->getModel('NavigationModel')->addLink('Edit profile', 'index.php?mode=editprofile');
- }
-
- // końcowe rzeczy
- $this->assign('nav', $this->getModel('NavigationModel')->getNav());
- $this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
- $this->show('edprofile');
- }
-
- public function posting_form($type, $msg='')
- {
- $this->setDefaults();
- $this->assign('error_msg', $msg);
-
- //nawigacja po witrynie
- switch ($type)
- {
- case POSTING_NEWTOPIC:
- $forum_info = $this->getModel('ForumsModel')->getForum($_GET['id']);
- $this->getModel('NavigationModel')->setSubTitle('New topic');
- $this->getModel('NavigationModel')->addLink($forum_info['name'], 'index.php?mode=viewforum&id='.$forum_info['forum_id']);
- $this->getModel('NavigationModel')->addLink('New topic', $_SERVER['REQUEST_URI']);
- break;
- case POSTING_REPLY:
- case POSTING_QUOTE:
- $topic_info = $this->getModel('PostsModel')->getTopic($_GET['id']);
-
- $this->getModel('NavigationModel')->setSubTitle('Reply');
- $this->getModel('NavigationModel')->addLink($topic_info['forum_name'], 'index.php?mode=viewforum&id='.$topic_info['forum_id']);
- $this->getModel('NavigationModel')->addLink($topic_info['topic_title'], 'index.php?mode=viewtopic&id='.$topic_info['topic_id']);
- $this->getModel('NavigationModel')->addLink('Write a reply', $_SERVER['REQUEST_URI']);
- break;
-
- case POSTING_EDIT:
- $topic_info = $this->getModel('PostsModel')->getTopic($_GET['id']);
-
- $this->getModel('NavigationModel')->setSubTitle('Edit post');
- $this->getModel('NavigationModel')->addLink($topic_info['forum_name'], 'index.php?mode=viewforum&id='.$topic_info['forum_id']);
- $this->getModel('NavigationModel')->addLink($topic_info['topic_title'], 'index.php?mode=viewtopic&id='.$topic_info['topic_id']);
- $this->getModel('NavigationModel')->addLink('Edit post', $_SERVER['REQUEST_URI']);
- break;
-
- case POSTING_EDITTOPIC:
- $topic_info = $this->getModel('PostsModel')->getTopic($_GET['id']);
-
- $this->getModel('NavigationModel')->setSubTitle('Edit topic');
- $this->getModel('NavigationModel')->addLink($topic_info['forum_name'], 'index.php?mode=viewforum&id='.$topic_info['forum_id']);
- $this->getModel('NavigationModel')->addLink($topic_info['topic_title'], 'index.php?mode=viewtopic&id='.$topic_info['topic_id']);
- $this->getModel('NavigationModel')->addLink('Edit topic', $_SERVER['REQUEST_URI']);
- break;
- }
-
- $this->assign('post', $_POST['post']);
- if (isset($_POST['preview']))
- $this->assign('preview', true);
-
- if ($type == POSTING_NEWTOPIC || $type == POSTING_EDITTOPIC)
- $this->assign('topic', $_POST['topic']);
-
- // końcowe rzeczy
- $this->assign('nav', $this->getModel('NavigationModel')->getNav());
- $this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
- $this->show('posting');
- }
-
- public function move_topic()
- {
- $this->setDefaults();
- $this->loadModel('ForumsModel');
-
- //nawigacja po witrynie
- $this->getModel('NavigationModel')->setSubTitle('Move topic');
- $this->getModel('NavigationModel')->addLink('Move topic', $_SERVER['REQUEST_URI']);
-
- $this->assign('topic_info', $this->getModel('PostsModel')->getTopic($_GET['id']));
- $this->assign('forums_list', $this->getModel('ForumsModel')->getForumsNames());
-
- // końcowe rzeczy
- $this->assign('nav', $this->getModel('NavigationModel')->getNav());
- $this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
- $this->show('move_topic');
- }
-
- public function forum_message($msg, $url = '', $timeout = 2)
- {
- $this->setDefaults();
-
- $this->assign('message', $msg);
- $this->assign('url', $url);
- $this->assign('timeout', $timeout);
-
- //nawigacja po witrynie
- $this->getModel('NavigationModel')->setSubTitle('Forum message');
- $this->getModel('NavigationModel')->addLink('Forum message', 'index.php');
-
- // końcowe rzeczy
- $this->assign('nav', $this->getModel('NavigationModel')->getNav());
- $this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
- $this->show('forum_message');
- }
-
- public function confirm_action($msg)
- {
- $this->setDefaults();
-
- $this->assign('message', $msg);
-
- //nawigacja po witrynie
- $this->getModel('NavigationModel')->setSubTitle('Confirm action');
- $this->getModel('NavigationModel')->addLink('Confirm action', $_SERVER['REQUEST_URI']);
-
- // końcowe rzeczy
- $this->assign('nav', $this->getModel('NavigationModel')->getNav());
- $this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
- $this->show('confirm_action');
- }
-
- public function colorRank($username, $rank)
- {
- if ($rank == RANK_ADMIN)
- return '<span class="fadmin">'.$username.'</span>';
-
- if ($rank == RANK_MOD)
- return '<span class="fmod">'.$username.'</span>';
-
- return $username;
- }
-
- public function getRankLevel($rank)
- {
- if ($rank == RANK_ADMIN)
- return $this->colorRank('Admin', $rank);
- if ($rank == RANK_MOD)
- return $this->colorRank('Mod', $rank);
-
- return 'User';
- }
-
- // ADMIN PANEL -----------------------------------------------------------------
- public function admin_main()
- {
- $this->setDefaults(true);
- $this->loadModel('StatisticsModel');
-
- //nawigacja po witrynie
- $this->getModel('NavigationModel')->setSubTitle('Main Page');
- $this->assign('installation_date', $this->getModel('ConfigModel')->getConf('installation_date'));
- $this->assign('topics_total', $this->getModel('StatisticsModel')->getTopicsCount());
- $this->assign('posts_total', $this->getModel('StatisticsModel')->getPostsCount());
- $this->assign('users_total', $this->getModel('StatisticsModel')->getUsersCount());
- $this->assign('script_version', VERSION);
- $this->assign('logged_users', $this->getModel('StatisticsModel')->getLoggedUsers());
- $this->assign('logged_users_total', $this->getModel('StatisticsModel')->getLoggedUsersCount());
-
- // końcowe rzeczy
- $this->assign('nav', $this->getModel('NavigationModel')->getNav());
- $this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
- $this->show('admin/main');
- }
-
- public function admin_userlist()
- {
- $this->setDefaults(true);
-
- $this->loadModel('UsersModel');
- $this->assign('users_list', $this->getModel('UsersModel')->getUsers($_POST['sort_type'], $_POST['sort_desc'], $_GET['rank']));
-
- $this->assign('regdate_selected', ($_POST['sort_type'] == 'regdate') ? 'selected="selected"' : '');
- $this->assign('lastvisit_selected', ($_POST['sort_type'] == 'lastvisit') ? 'selected="selected"' : '');
- $this->assign('username_selected', ($_POST['sort_type'] == 'nick') ? 'selected="selected"' : '');
- $this->assign('posts_selected', ($_POST['sort_type'] == 'post_count') ? 'selected="selected"' : '');
- $this->assign('desc_checked', ($_POST['sort_desc'] == 'DESC') ? 'checked="checked"' : '');
-
- //nawigacja po witrynie
- $this->getModel('NavigationModel')->setSubTitle('ACP • Users list');
- $this->getModel('NavigationModel')->addLink('Users list');
-
- // końcowe rzeczy
- $this->assign('nav', $this->getModel('NavigationModel')->getNav());
- $this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
- $this->show('admin/userlist');
- }
-
- public function admin_config($msg)
- {
- $this->setDefaults(true);
-
- $this->loadModel('UsersModel');
-
-
- $this->assign('forum_name', $_POST['forum_name']);
- $this->assign('forum_desc', $_POST['forum_desc']);
- $this->assign('error_msg', $msg);
-
- //nawigacja po witrynie
- $this->getModel('NavigationModel')->setSubTitle('ACP • Admin config');
- $this->getModel('NavigationModel')->addLink('Forum configuration');
-
- // końcowe rzeczy
- $this->assign('nav', $this->getModel('NavigationModel')->getNav());
- $this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
- $this->show('admin/config');
- }
-
- //widok strony głównej
- public function admin_forums()
- {
- $this->setDefaults(true);
-
- // get categories, forums, forums statistics
- $this->loadModel('ForumsModel');
- $this->assign('forums_list', $this->getModel('ForumsModel')->getForums());
-
- //nawigacja po witrynie
- $this->getModel('NavigationModel')->setSubTitle('ACP • Forums list');
- $this->getModel('NavigationModel')->addLink('Forums list');
-
- // końcowe rzeczy
- $this->assign('nav', $this->getModel('NavigationModel')->getNav());
- $this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
- $this->show('admin/forums');
- }
-
- public function admin_cat_form($msg, $m)
- {
- $this->setDefaults(true);
-
- $this->assign('name', $_POST['name']);
- $this->assign('error_msg', $msg);
-
- //nawigacja po witrynie
- $this->getModel('NavigationModel')->addLink('Forums list', 'index.php?mode=admin&submode=forums');
- if ($m == 'add')
- {
- $this->getModel('NavigationModel')->setSubTitle('ACP • Add category');
- $this->getModel('NavigationModel')->addLink('Add category');
- $this->assign('cat_form_name', 'Add new category');
- }
- else
- {
- $cat_info = $this->getModel('ForumsModel')->getCat($_GET['id']);
- $this->getModel('NavigationModel')->setSubTitle('ACP • Edit category');
- $this->getModel('NavigationModel')->addLink('Edit category: '.$cat_info['name']);
- $this->assign('cat_form_name', 'Edit category');
- }
-
- // końcowe rzeczy
- $this->assign('nav', $this->getModel('NavigationModel')->getNav());
- $this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
- $this->show('admin/cat_form');
- }
-
- public function admin_forum_form($msg, $m)
- {
- $this->setDefaults(true);
-
- $this->assign('name', $_POST['name']);
- $this->assign('desc', $_POST['desc']);
- $this->assign('category_id', $_POST['category_id']);
- $this->assign('lock_selected', ($_POST['locked']) ? 'checked="checked"' : '');
- $this->assign('unlock_selected', (!$_POST['locked']) ? 'checked="checked"' : '');
- $this->assign('error_msg', $msg);
- $this->assign('cats_list', $this->getModel('ForumsModel')->getCats());
-
- //nawigacja po witrynie
- $this->getModel('NavigationModel')->addLink('Forums list', 'index.php?mode=admin&submode=forums');
- if ($m == 'add')
- {
- $this->getModel('NavigationModel')->setSubTitle('ACP • Add forum');
- $this->getModel('NavigationModel')->addLink('Add forum');
- $this->assign('forum_form_name', 'Add new forum');
- }
- else
- {
- $forum_info = $this->getModel('ForumsModel')->getForum($_GET['id']);
- $this->getModel('NavigationModel')->setSubTitle('ACP • Edit forum');
- $this->getModel('NavigationModel')->addLink('Edit forum'.$forum_info['name']);
- $this->assign('forum_form_name', 'Edit forum');
- }
-
- // końcowe rzeczy
- $this->assign('nav', $this->getModel('NavigationModel')->getNav());
- $this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
- $this->show('admin/forum_form');
- }
-
- public function admin_banlist()
- {
- $this->setDefaults(true);
-
- $this->loadModel('BansModel');
- $this->assign('bans_list', $this->getModel('BansModel')->getBans());
-
- //nawigacja po witrynie
- $this->getModel('NavigationModel')->setSubTitle('ACP • Banlist');
- $this->getModel('NavigationModel')->addLink('Banlist');
-
- // końcowe rzeczy
- $this->assign('nav', $this->getModel('NavigationModel')->getNav());
- $this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
- $this->show('admin/banlist');
- }
-
- public function admin_ban_form($msg)
- {
- $this->setDefaults(true);
-
- $this->assign('user_id', $_POST['user_id']);
- $this->assign('reason', $_POST['reason']);
-
- $this->loadModel('UsersModel');
- $this->assign('error_msg', $msg);
- $this->assign('users_list', $this->getModel('UsersModel')->getUsersNicks());
-
- //nawigacja po witrynie
- $this->getModel('NavigationModel')->addLink('Banlist', 'index.php?mode=admin&submode=banlist');
-
- $this->getModel('NavigationModel')->setSubTitle('ACP • Add ban');
- $this->getModel('NavigationModel')->addLink('Add ban');
- $this->assign('forum_form_name', 'Add ban');
-
- // końcowe rzeczy
- $this->assign('nav', $this->getModel('NavigationModel')->getNav());
- $this->assign('meta_title', $this->getModel('NavigationModel')->getTitle());
- $this->show('admin/ban_form');
- }
- }
- ?>
|