/** * View topic * * @param mixed $topic_id * @param string $action * @param mixed $extra */ public function topic($topic_id, $action = false, $extra = false) { // Hide tabs $this->tabs = null; if ($action) { switch ($action) { // Delete topic case 'delete': $this->_topic_delete($topic_id); return; // Edit topic // Edit topic case 'edit': $this->_topic_edit($topic_id); return; // Post to topic // Post to topic case 'post': $this->_post_add($topic_id); return; // Go to post // Go to post default: if (is_numeric($action)) { $post_id = (int) $action; } } } $forum_topic = new Forum_Topic_Model((int) $topic_id); $errors = $forum_topic->id ? array() : __('Topic not found'); if (empty($errors)) { $forum_area = $forum_topic->forum_area; $this->breadcrumb[] = html::anchor(url::model($forum_area), $forum_area->name); // Admin actions if ($forum_topic->has_access(Forum_Topic_Model::ACCESS_EDIT)) { $this->page_actions[] = array('link' => url::model($forum_topic) . '/edit', 'text' => __('Edit topic'), 'class' => 'topic-edit'); } // Logged user actions if ($forum_topic->has_access(Forum_Topic_Model::ACCESS_WRITE)) { $this->page_actions[] = array('link' => '#reply', 'text' => __('Reply to topic'), 'class' => 'topic-post'); } // Check access and proceed if ($forum_area->has_access(Forum_Area_Model::ACCESS_READ)) { $this->breadcrumb[] = html::anchor(url::model($forum_topic), $forum_topic->name); $this->page_title = ($forum_topic->read_only ? '<span class="locked">' . __('[Locked]') . '</span> ' : '') . text::title($forum_topic->name); $this->page_subtitle = __('Area :area. ', array(':area' => html::anchor(url::model($forum_area), text::title($forum_area->name), array('title' => strip_tags($forum_area->description))))); $this->page_subtitle .= html::icon_value(array(':views' => $forum_topic->reads), ':views view', ':views views', 'views'); $this->page_subtitle .= html::icon_value(array(':posts' => $forum_topic->posts), ':posts post', ':posts posts', 'posts'); // Handle pagination $per_page = $this->config['posts_per_page']; $pagination = new Pagination(array('items_per_page' => $per_page, 'total_items' => $forum_topic->posts)); if ($action == 'page' && $extra == 'last') { $pagination->to_last_page(); } $posts = $forum_topic->forum_posts->find_all($per_page, $pagination->sql_offset); // Update read counter if not owner if (!$forum_topic->is_author($this->user)) { $forum_topic->reads++; $forum_topic->save(); } if (count($posts)) { // Posts widget::add('main', View_Mod::factory('forum/topic', array('mod_class' => 'topic articles topic-' . $forum_topic->id, 'user' => $this->user, 'topic' => $forum_topic, 'posts' => $posts, 'pagination' => $pagination))); // Reply if ($forum_topic->has_access(Forum_Topic_Model::ACCESS_WRITE)) { widget::add('main', View_Mod::factory('forum/post_edit', array('mod_id' => 'reply', 'mod_title' => __('Reply'), 'form_post' => url::model($forum_topic) . '/post', 'post' => array('post_id' => 0), 'errors' => array(), 'parent_id' => 0))); } } else { $errors[] = __('No posts found.'); } } else { // No access $this->page_title = text::title($forum_area->name); $this->page_subtitle = html::specialchars($forum_area->description) . ' '; $errors[] = __('Access denied.'); } } if (count($errors)) { $this->_error(Kohana::lang('generic.error'), $errors); } $this->_side_views(); }