Example #1
0
 /**
  * Get user's new comment counts
  *
  * @return  array
  */
 public function find_new_comments()
 {
     $new = array();
     // Profile comments
     if ($this->new_comment_count) {
         $new['new-comments'] = HTML::anchor(URL::user($this), __(':comments', array(':comments' => '<div></div><var>' . $this->new_comment_count . '</var>')), array('title' => __('New comments')));
     }
     // Blog comments
     $blog_comments = Model_Blog_Entry::find_new_comments($this);
     if (count($blog_comments)) {
         $new_comments = 0;
         foreach ($blog_comments as $blog_entry) {
             $new_comments += $blog_entry->new_comment_count;
         }
         $new['new-blog-comments'] = HTML::anchor(Route::model($blog_entry), __(':comments', array(':comments' => '<div></div><var>' . $new_comments . '</var>')), array('title' => __('New blog comments')));
     }
     unset($blog_comments);
     // Forum quotes
     $forum_quotes = Model_Forum_Quote::find_by_user($this);
     if (count($forum_quotes)) {
         $new_quotes = count($forum_quotes);
         $quote = $forum_quotes->current();
         $new['new-forum-quotes'] = HTML::anchor(Route::get('forum_post')->uri(array('topic_id' => Route::model_id($quote->topic), 'id' => $quote->post->id)) . '#post-' . $quote->post->id, __(':quotes', array(':quotes' => '<div></div><var>' . $new_quotes . '</var>')), array('title' => __('Forum quotes')));
     }
     // Images waiting for approval
     if (Permission::has(new Model_Gallery(), Model_Gallery::PERMISSION_APPROVE_WAITING, $this)) {
         $gallery_approvals = Model_Gallery::find_pending(Permission::has(new Model_Gallery(), Model_Gallery::PERMISSION_APPROVE, $this) ? null : $this);
         if (count($gallery_approvals)) {
             $new_approvals = count($gallery_approvals);
             $new['new-gallery-approvals'] = HTML::anchor(Route::get('galleries')->uri(array('action' => 'approval')), __(':galleries', array(':galleries' => '<div></div><var>' . $new_approvals . '</var>')), array('title' => __('Galleries waiting for approval')));
         }
     }
     // Image comments
     $image_comments = Model_Image::find_new_comments($this);
     if (count($image_comments)) {
         $new_comments = 0;
         foreach ($image_comments as $image) {
             $new_comments += $image->new_comment_count;
         }
         $new['new-image-comments'] = HTML::anchor(Route::get('gallery_image')->uri(array('gallery_id' => Route::model_id(Model_Gallery::find_by_image($image->id)), 'id' => $image->id, 'action' => '')), __(':comments', array(':comments' => '<div></div><var>' . $new_comments . '</var>')), array('title' => __('New image comments')));
     }
     unset($image_comments);
     // Private messages
     return $new;
 }
Example #2
0
File: topic.php Project: anqh/forum
 /**
  * Edit forum post
  *
  * @param  integer  $topic_id  When replying to a topic
  * @param  integer  $post_id   When editing a post
  * @param  integer  $quote_id  When quoting a post
  *
  * @throws  Model_Exception  missing topic, missing post
  */
 protected function _edit_post($topic_id, $post_id = null, $quote_id = null)
 {
     $this->history = false;
     // Topic is always loaded, avoid haxing attempts to edit posts from wrong topics
     $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_POST, self::$user);
     if ($post_id) {
         // Editing a post
         $post = $this->private ? Model_Forum_Private_Post::factory($post_id) : Model_Forum_Post::factory($post_id);
         if (!$post->loaded() || $post->forum_topic_id != $topic->id) {
             throw new Model_Exception($post, $post_id);
         }
         Permission::required($post, Model_Forum_Post::PERMISSION_UPDATE, self::$user);
     } else {
         // New reply
         $post = $this->private ? Model_Forum_Private_Post::factory() : Model_Forum_Post::factory();
     }
     // Quoting a post
     if ($quote_id) {
         $quote = $this->private ? Model_Forum_Private_Post::factory() : Model_Forum_Post::factory($quote_id);
         if (!$quote->loaded() || $quote->forum_topic_id != $topic->id) {
             throw new Model_Exception($quote, $quote_id);
         }
         Permission::required($quote, Model_Forum_Post::PERMISSION_READ, self::$user);
         if (!$post->loaded()) {
             $post->post = '[quote author="' . $quote->author_name . '" post="' . $quote->id . '"]' . $quote->post . "[/quote]\n\n";
         }
         $post->parent_id = $quote_id;
     }
     // Handle post
     $errors = array();
     if ($_POST && Security::csrf_valid()) {
         $post->post = Arr::get($_POST, 'post');
         $post->author_ip = Request::$client_ip;
         $post->author_host = Request::host_name();
         if (!$post->loaded()) {
             // New post
             $post->forum_topic_id = $topic->id;
             $post->forum_area_id = $topic->forum_area_id;
             $post->author_id = self::$user->id;
             $post->author_name = self::$user->username;
             $post->created = time();
             $increase = true;
             // Notify recipients
             if ($this->private) {
                 $topic->notify_recipients(self::$user);
             }
         } else {
             // Old post
             $post->modify_count++;
             $post->modified = time();
             $increase = false;
         }
         try {
             $post->save();
             if ($increase) {
                 // Quote, only for public topics
                 if (!$this->private && $quote_id && $quote->author_id) {
                     $quoted = $quote->author_id;
                     $quote = new Model_Forum_Quote();
                     $quote->user_id = $quoted;
                     $quote->author_id = self::$user->id;
                     $quote->forum_topic_id = $topic->id;
                     $quote->forum_post_id = $post->id;
                     $quote->created = time();
                     $quote->save();
                 }
                 // Topic
                 $topic->post_count++;
                 $topic->last_post_id = $post->id;
                 $topic->last_poster = $post->author_name;
                 // If current topic is set to sink, don't update last posted date
                 if ($topic->status != Model_Forum_Topic::STATUS_SINK) {
                     $topic->last_posted = $post->created;
                 }
                 $topic->save();
                 // Area, only for public topics
                 if (!$this->private) {
                     $area = $topic->area();
                     $area->post_count++;
                     $area->last_topic_id = $topic->id;
                     $area->save();
                 }
                 // User
                 self::$user->post_count++;
                 self::$user->save();
                 // News feed
                 if (!$this->private) {
                     NewsfeedItem_Forum::reply(self::$user, $post);
                 }
             }
             if ($this->ajax) {
                 $post_route = Route::url($this->private ? 'forum_private_post' : 'forum_post', array('topic_id' => Route::model_id($topic), 'id' => $post->id));
                 $post_response = Request::factory($post_route)->execute();
                 $this->response->body($post_response->body());
                 return;
             }
             $this->request->redirect(Route::model($topic, '?page=last#last'));
         } catch (Validation_Exception $e) {
             $errors = $e->array->errors('validate');
         }
     }
     // Common attributes
     if ($quote_id) {
         $mode = View_Forum_PostEdit::QUOTE;
     } else {
         if ($post_id) {
             $mode = View_Forum_PostEdit::EDIT_POST;
         } else {
             $mode = View_Forum_PostEdit::REPLY;
         }
     }
     $section = $this->section_post_edit($mode, $post);
     $section->forum_topic = $topic;
     $section->errors = $errors;
     $section->cancel = $this->ajax ? Route::url($this->private ? 'forum_private_post' : 'forum_post', array('topic_id' => Route::model_id($topic), 'id' => $quote_id ? $quote_id : $post->id)) : Request::back(Route::model($topic), true);
     /*		$form = array(
     			'errors'  => $errors,
     			'ajax'    => $this->ajax ? true : null,
     			'topic'   => $topic,
     			'post'    => $post,
     			'user'    => self::$user,
     			'private' => $this->private,
     			'cancel'  => $this->ajax
     				? Route::get($this->private ? 'forum_private_post' : 'forum_post')
     						->uri(array(
     							'topic_id' => Route::model_id($topic),
     							'id'       => $quote_id ? $quote_id : $post->id,
     						))
     				: Request::back(Route::model($topic), true),
     		);*/
     if ($this->ajax) {
         $this->response->body($mode == View_Forum_PostEdit::EDIT_POST ? $section->content() : $section);
         return;
     }
     // Build page
     $this->view = new View_Page();
     $this->view->title_html = Forum::topic($topic);
     $this->view->add(View_Page::COLUMN_MAIN, $section);
     /*
     		Widget::add('main', View_Module::factory('forum/reply', array(
     			'mod_id'  => 'reply',
     		) + $form));*/
 }
Example #3
0
File: core.php Project: anqh/core
 /**
  * Get user's new comment counts.
  *
  * @param   Model_User  $user
  * @return  array
  */
 public static function notifications(Model_User $user)
 {
     $new = array();
     // Profile comments
     if ($user->new_comment_count) {
         $new['new-comments'] = HTML::anchor(URL::user($user), '<i class="icon-comment icon-white"></i> ' . $user->new_comment_count, array('class' => 'badge badge-info', 'title' => __('New comments')));
     }
     // Forum private messages
     $private_messages = Forum::find_new_private_messages($user);
     if (count($private_messages)) {
         $new_messages = 0;
         foreach ($private_messages as $private_message) {
             $new_messages += $private_message->unread;
         }
         $new['new-private-messages'] = HTML::anchor(Route::model($private_message->topic()) . '?page=last#last', '<i class="icon-comment icon-white"></i> ' . $new_messages, array('class' => 'badge badge-info', 'title' => __('New private messages')));
     }
     unset($private_messages);
     // Blog comments
     $blog_comments = Model_Blog_Entry::factory()->find_new_comments($user);
     if (count($blog_comments)) {
         $new_comments = 0;
         foreach ($blog_comments as $blog_entry) {
             $new_comments += $blog_entry->new_comment_count;
         }
         $new['new-blog-comments'] = HTML::anchor(Route::model($blog_entry), '<i class="icon-comment icon-white"></i> ' . $new_comments, array('class' => 'badge badge-info', 'title' => __('New blog comments')));
     }
     unset($blog_comments);
     // Forum quotes
     $forum_quotes = Model_Forum_Quote::factory()->find_by_user($user);
     if (count($forum_quotes)) {
         $new_quotes = count($forum_quotes);
         $quote = $forum_quotes->current();
         $new['new-forum-quotes'] = HTML::anchor(Route::get('forum_post')->uri(array('topic_id' => $quote->forum_topic_id, 'id' => $quote->forum_post_id)) . '#post-' . $quote->forum_post_id, '<i class="icon-comment icon-white"></i> ' . $new_quotes, array('class' => 'badge badge-info', 'title' => __('Forum quotes')));
     }
     // Images waiting for approval
     if (Permission::has(new Model_Gallery(), Model_Gallery::PERMISSION_APPROVE_WAITING, $user)) {
         $gallery_approvals = Model_Gallery::factory()->find_pending(Permission::has(new Model_Gallery(), Model_Gallery::PERMISSION_APPROVE, $user) ? null : $user);
         if (count($gallery_approvals)) {
             $new_approvals = count($gallery_approvals);
             $new['new-gallery-approvals'] = HTML::anchor(Route::get('galleries')->uri(array('action' => 'approval')), '<i class="icon-exclamation-sign icon-white"></i> ' . $new_approvals, array('class' => 'badge badge-warning', 'title' => __('Galleries waiting for approval')));
         }
     }
     // Flyer comments
     $flyer_comments = Model_Flyer::factory()->find_new_comments($user);
     $flyers = array();
     if (count($flyer_comments)) {
         $new_comments = 0;
         foreach ($flyer_comments as $flyer) {
             $flyers[$flyer->image_id] = true;
             $new_comments += $flyer->image()->new_comment_count;
         }
         $new['new-flyer-comments'] = HTML::anchor(Route::get('flyer')->uri(array('id' => $flyer->id, 'action' => '')), '<i class="icon-picture icon-white"></i> ' . $new_comments, array('class' => 'badge badge-info', 'title' => __('New flyer comments')));
     }
     unset($flyer_comments);
     // Image comments
     $image_comments = Model_Image::factory()->find_new_comments($user);
     $note_comments = Model_Image_Note::factory()->find_new_comments($user);
     if (count($image_comments) || count($note_comments)) {
         $new_comments = 0;
         $new_image = null;
         foreach ($image_comments as $image) {
             // @TODO: Until flyer comments are fixed..
             if (!isset($flyers[$image->id])) {
                 $new_comments += $image->new_comment_count;
                 $new_image_id = $image->id;
             }
         }
         foreach ($note_comments as $note) {
             $new_comments += $note->new_comment_count;
             $new_image_id = $note->image_id;
         }
         if ($new_comments) {
             $new['new-image-comments'] = HTML::anchor(Route::get('gallery_image')->uri(array('gallery_id' => Route::model_id(Model_Gallery::find_by_image($new_image_id)), 'id' => $new_image_id, 'action' => '')), '<i class="icon-camera icon-white"></i> ' . $new_comments, array('class' => 'badge badge-info', 'title' => __('New image comments')));
         }
     }
     unset($image_comments, $note_comments, $new_image);
     // Image tags
     $notes = Model_Image_Note::factory()->find_new_notes($user);
     if (count($notes)) {
         $new_notes = 0;
         $new_note_image_id = null;
         /** @var  Model_Image_Note  $note */
         foreach ($notes as $note) {
             $new_notes++;
             $new_note_image_id = $note->image_id;
         }
         if ($new_notes) {
             $new['new-image-notes'] = HTML::anchor(Route::get('gallery_image')->uri(array('gallery_id' => Route::model_id(Model_Gallery::find_by_image($new_note_image_id)), 'id' => $new_note_image_id, 'action' => '')), '<i class="icon-tag icon-white"></i> ' . $new_notes, array('class' => 'badge badge-info', 'title' => __('New image tags')));
         }
     }
     unset($note_comments, $new_note_image_id);
     return $new;
 }