/** * Action: blog entry */ public function action_entry() { $entry_id = (int) $this->request->param('id'); // Load blog entry $entry = Model_Blog_Entry::factory($entry_id); if (!$entry->loaded()) { throw new Model_Exception($entry, $entry_id); } Permission::required($entry, Model_Blog_Entry::PERMISSION_READ); // Comments section if (Permission::has($entry, Model_Blog_Entry::PERMISSION_COMMENTS)) { $errors = array(); $values = array(); if ($_POST && Permission::has($entry, Model_Blog_Entry::PERMISSION_COMMENT)) { // Handle comment try { $comment = Model_Blog_Comment::factory()->add(Visitor::$user->id, null, Arr::get($_POST, 'comment'), Arr::get($_POST, 'private'), $entry); $entry->comment_count++; $entry->new_comment_count++; $entry->save(); // Newsfeed if (!$comment->private) { NewsfeedItem_Blog::comment(Visitor::$user, $entry); } if ($this->_request_type !== Controller::REQUEST_AJAX) { $this->request->redirect(Route::model($entry)); } } catch (Validation_Exception $e) { $errors = $e->array->errors('validation'); $values = $comment; } } // Get view $section_comments = $this->section_comments($entry); $section_comments->errors = $errors; $section_comments->values = $values; } else { if (!Visitor::$user) { // Guest user $section_comments = $this->section_comments_teaser($entry->comment_count); } } if (isset($section_comments) && $this->_request_type === Controller::REQUEST_AJAX) { $this->response->body($section_comments); return; } // Build page // Set actions if (Permission::has($entry, Model_Blog_Entry::PERMISSION_UPDATE)) { $this->view->actions[] = array('link' => Route::model($entry, 'edit'), 'text' => '<i class="fa fa-edit"></i> ' . __('Edit blog entry')); } // Content $this->view->add(View_Page::COLUMN_CENTER, $this->section_entry($entry, true)); // Comments if (isset($section_comments)) { $this->view->add(View_Page::COLUMN_CENTER, $section_comments); } // Update counts if (Visitor::$user && Visitor::$user->id == $entry->author_id) { // Clear new comment counts for owner if ($entry->new_comment_count) { $entry->new_comment_count = 0; $entry->save(); } } else { $entry->view_count++; $entry->save(); } // Month browser $author = Model_User::find_user($entry->author_id); if ($months = $this->_build_months(Model_Blog_Entry::factory()->find_by_user($author))) { $params = array('username' => urlencode($author->username)); $this->view->add(View_Page::COLUMN_RIGHT, $this->section_month_browser($months, 'blog_user', $params, date('Y', $entry->created), date('n', $entry->created))); } }
/** * Action: blog entry */ public function action_entry() { $entry_id = (int) $this->request->param('id'); // Load blog entry $entry = Model_Blog_Entry::factory($entry_id); if (!$entry->loaded()) { throw new Model_Exception($entry, $entry_id); } Permission::required($entry, Model_Blog_Entry::PERMISSION_READ, self::$user); // Comments section if (Permission::has($entry, Model_Blog_Entry::PERMISSION_COMMENTS, self::$user)) { $errors = array(); $values = array(); if ($_POST && Permission::has($entry, Model_Blog_Entry::PERMISSION_COMMENT, self::$user)) { // Handle comment try { $comment = Model_Blog_Comment::factory()->add(self::$user->id, $entry, Arr::get($_POST, 'comment'), Arr::get($_POST, 'private')); $entry->comment_count++; $entry->new_comment_count++; $entry->save(); // Newsfeed if (!$comment->private) { NewsfeedItem_Blog::comment(self::$user, $entry); } if ($this->_request_type !== Controller::REQUEST_AJAX) { $this->request->redirect(Route::model($entry)); } } catch (Validation_Exception $e) { $errors = $e->array->errors('validation'); $values = $comment; } } // Get view $section_comments = $this->section_comments($entry); $section_comments->errors = $errors; $section_comments->values = $values; } else { if (!self::$user) { // Guest user $section_comments = $this->section_comments_teaser($entry->comment_count); } } if (isset($section_comments) && $this->_request_type === Controller::REQUEST_AJAX) { $this->response->body($section_comments); return; } // Build page $this->view = new View_Page($entry->name); $this->view->subtitle = __('By :user :ago', array(':user' => HTML::user($entry->author()), ':ago' => HTML::time(Date::fuzzy_span($entry->created), $entry->created))); // Set actions if (Permission::has($entry, Model_Blog_Entry::PERMISSION_UPDATE, self::$user)) { $this->view->actions[] = array('link' => Route::model($entry, 'edit'), 'text' => '<i class="icon-edit icon-white"></i> ' . __('Edit blog entry')); } // Content $this->view->add(View_Page::COLUMN_MAIN, $this->section_entry($entry)); // Comments if (isset($section_comments)) { $this->view->add(View_Page::COLUMN_MAIN, $section_comments); } // Update counts if (self::$user && self::$user->id == $entry->author_id) { // Clear new comment counts for owner if ($entry->new_comment_count) { $entry->new_comment_count = 0; $entry->save(); } } else { $entry->view_count++; $entry->save(); } }