Example #1
0
 /**
  * Get a single line of text representing the exception:
  *
  * Error [ Code ]: Message ~ File [ Line ] (#id: username, ip: IP, uri: URI)
  *
  * @param   Exception   $e
  * @return  string
  */
 public static function text(Exception $e)
 {
     if ($user = Visitor::instance()->get_user()) {
         $user_id = $user->id;
         $username = Text::clean($user->username);
     } else {
         $user_id = 0;
         $username = '';
     }
     return sprintf('%s [ %s ]: %s ~ %s [ %d ] (#%d: %s, ip: %s, uri: %s)', get_class($e), $e->getCode(), strip_tags($e->getMessage()), Debug::path($e->getFile()), $e->getLine(), $user_id, $username, Request::$client_ip, Text::clean(Request::current_uri()));
 }
Example #2
0
File: topic.php Project: anqh/forum
 /**
  * Action: index
  */
 public function action_index()
 {
     // Go to post?
     $topic_id = (int) $this->request->param('topic_id');
     if ($topic_id) {
         $post_id = (int) $this->request->param('id');
     } else {
         $topic_id = (int) $this->request->param('id');
     }
     // Load topic
     /** @var  Model_Forum_Private_Topic|Model_Forum_Topic  $topic */
     $topic = $this->private ? Model_Forum_Private_Topic::factory($topic_id) : Model_Forum_Topic::factory($topic_id);
     if (!$topic->loaded()) {
         throw new Model_Exception($topic, $topic_id);
     }
     Permission::required($topic, Model_Forum_Topic::PERMISSION_READ, self::$user);
     // Did we request single post with ajax?
     if (($this->ajax || $this->internal) && isset($post_id)) {
         $this->history = false;
         $post = $this->private ? Model_Forum_Private_Post::factory($post_id) : Model_Forum_Post::factory($post_id);
         if (!$post->loaded()) {
             throw new Model_Exception($topic, $topic_id);
         }
         // Permission is already checked by the topic, no need to check for post
         $this->response->body($this->section_post($topic, $post));
         return;
     }
     // Update counts
     if ($this->private) {
         $topic->mark_as_read(self::$user);
     }
     if (!self::$user || $topic->author_id != self::$user->id) {
         $topic->read_count++;
         $topic->save();
     }
     // Build page
     $this->view = new View_Page();
     $this->view->title_html = Forum::topic($topic);
     $this->view->subtitle = __($topic->post_count == 1 ? ':posts post' : ':posts posts', array(':posts' => Num::format($topic->post_count, 0)));
     $this->view->tab = 'topic';
     $this->page_actions['topic'] = array('link' => Route::model($topic), 'text' => '<i class="icon-comment icon-white"></i> ' . __('Topic'));
     // Public topic extras
     if (!$this->private) {
         // Quotes are supported only in public forum as we get notifications anyway in private
         if (self::$user) {
             $quotes = Model_Forum_Quote::factory()->find_by_user(self::$user);
             if (count($quotes)) {
                 foreach ($quotes as $quote) {
                     if ($topic->id == $quote->forum_topic_id) {
                         $quote->delete();
                         break;
                     }
                 }
             }
         }
         // Facebook
         if (Kohana::$config->load('site.facebook')) {
             Anqh::open_graph('title', $topic->name);
             Anqh::open_graph('url', URL::site(Route::url('forum_topic', array('id' => $topic->id, 'action' => '')), true));
         }
         Anqh::share(true);
         // Model binding
         $area = $topic->area();
         if ($area->type == Model_Forum_Area::TYPE_BIND && $topic->bind_id) {
             if ($bind = Model_Forum_Area::get_binds($area->bind)) {
                 $model = AutoModeler::factory($bind['model'], $topic->bind_id);
                 if ($model->loaded()) {
                     // Set actions
                     $this->page_actions[] = array('link' => Route::model($model), 'text' => $bind['link']);
                     // Set views
                     foreach ((array) $bind['view'] as $view) {
                         $this->view->add(View_Page::COLUMN_SIDE, View_Module::factory($view, array($bind['model'] => $model)), Widget::TOP);
                     }
                 }
             }
         }
     }
     // Public topic extras
     // Set actions
     if (Permission::has($topic, Model_Forum_Topic::PERMISSION_POST, self::$user)) {
         $this->view->actions[] = array('link' => Request::current_uri() . '#reply', 'text' => '<i class="icon-comment icon-white"></i> ' . __('Reply to topic'), 'class' => 'btn btn-primary topic-post');
     }
     if (Permission::has($topic, Model_Forum_Topic::PERMISSION_UPDATE, self::$user)) {
         $this->view->actions[] = array('link' => Route::model($topic, 'edit'), 'text' => '<i class="icon-edit icon-white"></i> ' . __('Edit topic'));
     }
     // Breadcrumbs
     $this->page_breadcrumbs[] = HTML::anchor(Route::url('forum_group'), __('Forum'));
     $this->page_breadcrumbs[] = HTML::anchor(Route::model($topic->area()), $topic->area()->name);
     // Pagination
     $this->view->add(View_Page::COLUMN_MAIN, $pagination = $this->section_pagination($topic));
     $this->view->subtitle .= ', ' . __($pagination->total_pages == 1 ? ':pages page' : ':pages pages', array(':pages' => Num::format($pagination->total_pages, 0)));
     $this->view->subtitle .= ', ' . __($topic->read_count == 1 ? ':views view' : ':views views', array(':views' => Num::format($topic->read_count, 0)));
     // Go to post?
     if (isset($post_id)) {
         $pagination->item($topic->get_post_number($post_id) + 1);
         // We need to set pagination urls manually if jumped to a post
         $pagination->base_url = Route::model($topic);
     }
     // Recipients
     if ($this->private) {
         $this->view->add(View_Page::COLUMN_MAIN, $this->section_recipients($topic));
         $this->view->add(View_Page::COLUMN_MAIN, '<hr />');
     }
     // Posts
     $this->view->add(View_Page::COLUMN_MAIN, $this->section_topic($topic, $pagination));
     // Reply
     if (Permission::has($topic, Model_Forum_Topic::PERMISSION_POST, self::$user)) {
         $section = $this->section_post_edit(View_Forum_PostEdit::REPLY, $this->private ? Model_Forum_Private_Post::factory() : Model_Forum_Post::factory());
         $section->forum_topic = $topic;
         $this->view->add(View_Page::COLUMN_MAIN, $section);
     }
     // Pagination
     $this->view->add(View_Page::COLUMN_MAIN, $pagination);
     $this->_side_views();
 }
Example #3
0
File: topic.php Project: anqh/anqh
 /**
  * Action: index
  */
 public function action_index()
 {
     // Go to post?
     $topic_id = (int) $this->request->param('topic_id');
     if ($topic_id) {
         $post_id = (int) $this->request->param('id');
     } else {
         $topic_id = (int) $this->request->param('id');
     }
     // Load topic
     /** @var  Model_Forum_Private_Topic|Model_Forum_Topic  $topic */
     $topic = $this->private ? Model_Forum_Private_Topic::factory($topic_id) : Model_Forum_Topic::factory($topic_id);
     if (!$topic->loaded()) {
         throw new Model_Exception($topic, $topic_id);
     }
     Permission::required($topic, Model_Forum_Topic::PERMISSION_READ);
     // Did we request single post with ajax?
     if (($this->ajax || $this->internal) && isset($post_id)) {
         $this->history = false;
         $post = $this->private ? Model_Forum_Private_Post::factory($post_id) : Model_Forum_Post::factory($post_id);
         if (!$post->loaded()) {
             throw new Model_Exception($topic, $topic_id);
         }
         // Permission is already checked by the topic, no need to check for post
         $this->response->body($this->section_post($topic, $post));
         return;
     }
     // Update counts
     if ($this->private) {
         $topic->mark_as_read(Visitor::$user);
     }
     if (!Visitor::$user || $topic->author_id != Visitor::$user->id) {
         $topic->read_count++;
         $topic->save();
     }
     // Build page
     $this->view = new View_Page();
     $this->view->title = $topic->name;
     $this->view->title_html = Forum::topic($topic);
     $this->view->subtitle = __($topic->post_count == 1 ? ':posts post' : ':posts posts', array(':posts' => Num::format($topic->post_count, 0)));
     $this->view->tab = 'topic';
     $this->page_actions['topic'] = array('link' => Route::model($topic), 'text' => __('Topic'));
     // Breadcrumbs
     $this->page_breadcrumbs[] = HTML::anchor(Route::url('forum'), __('Forum'));
     // Public topic extras
     if (!$this->private) {
         $this->page_breadcrumbs[] = HTML::anchor(Route::model($topic->area()), $topic->area()->name);
         // Quotes are supported only in public forum as we get notifications anyway in private
         if (Visitor::$user) {
             $quotes = Model_Forum_Quote::factory()->find_by_user(Visitor::$user);
             if (count($quotes)) {
                 foreach ($quotes as $quote) {
                     if ($topic->id == $quote->forum_topic_id) {
                         $quote->delete();
                         break;
                     }
                 }
             }
         }
         // Facebook
         Anqh::page_meta('title', $topic->name);
         Anqh::page_meta('url', URL::site(Route::url('forum_topic', array('id' => $topic->id, 'action' => '')), true));
         Anqh::share(true);
         // Model binding
         $area = $topic->area();
         if ($topic->bind_id && ($bind_config = $area->bind_config())) {
             if ($bind_model = $topic->bind_model()) {
                 // Set actions
                 $this->page_actions[] = array('link' => Route::model($bind_model), 'text' => $bind_config['link']);
                 /*					// Set views
                 					foreach ((array)$bind['view'] as $view) {
                 						$this->view->add(View_Page::COLUMN_RIGHT, View_Module::factory($view, array(
                 							$bind['model'] => $model,
                 						)), Widget::TOP);
                 					}*/
             }
         }
     } else {
         $this->page_breadcrumbs[] = HTML::anchor(Forum::private_messages_url(), __('Private messages'));
     }
     // Set actions
     if (Permission::has($topic, Model_Forum_Topic::PERMISSION_UPDATE)) {
         $this->view->actions[] = array('link' => Route::model($topic, 'edit'), 'text' => __('Edit topic'));
     }
     if (Permission::has($topic, Model_Forum_Topic::PERMISSION_POST)) {
         $this->view->actions[] = array('link' => Request::current_uri() . '#reply', 'text' => __('Reply to topic'), 'class' => 'btn btn-primary topic-post');
     }
     // Pagination
     $this->view->add(View_Page::COLUMN_CENTER, $pagination = $this->section_pagination($topic));
     $this->view->subtitle .= ', ' . __($pagination->total_pages == 1 ? ':pages page' : ':pages pages', array(':pages' => Num::format($pagination->total_pages, 0)));
     $this->view->subtitle .= ', ' . __($topic->read_count == 1 ? ':views view' : ':views views', array(':views' => Num::format($topic->read_count, 0)));
     // Go to post?
     if (isset($post_id)) {
         $pagination->item($topic->get_post_number($post_id) + 1);
         // We need to set pagination urls manually if jumped to a post
         $pagination->base_url = Route::model($topic);
     }
     // Recipients
     if ($this->private) {
         $this->view->add(View_Page::COLUMN_RIGHT, $this->section_recipients($topic));
     }
     // Posts
     $this->view->add(View_Page::COLUMN_CENTER, $this->section_topic($topic, $pagination));
     // Reply
     if (Permission::has($topic, Model_Forum_Topic::PERMISSION_POST)) {
         // Old post warning
         if ($topic->last_posted && time() - $topic->last_posted > Date::YEAR) {
             $this->view->add(View_Page::COLUMN_CENTER, $this->section_ancient_warning($topic->last_posted));
         }
         $section = $this->section_post_edit(View_Forum_PostEdit::REPLY, $this->private ? Model_Forum_Private_Post::factory() : Model_Forum_Post::factory());
         $section->forum_topic = $topic;
         $this->view->add(View_Page::COLUMN_CENTER, $section);
     }
     // Pagination
     $this->view->add(View_Page::COLUMN_CENTER, $pagination);
     $this->_side_views();
 }