Exemple #1
0
 /**
  * Action: comment
  */
 public function action_comment()
 {
     $this->history = false;
     $comment_id = (int) $this->request->param('id');
     $action = $this->request->param('commentaction');
     // Load image comment
     $comment = new Model_Image_Comment($comment_id);
     if (($action == 'delete' || $action == 'private') && Security::csrf_valid() && $comment->loaded()) {
         $image = $comment->image();
         $gallery = $image->gallery();
         switch ($action) {
             // Delete comment
             case 'delete':
                 if (Permission::has($comment, Model_Image_Comment::PERMISSION_DELETE)) {
                     $comment->delete();
                     $image->comment_count--;
                     $image->save();
                     $gallery->comment_count--;
                     $gallery->save();
                 }
                 break;
                 // Set comment as private
             // Set comment as private
             case 'private':
                 if (Permission::has($comment, Model_Image_Comment::PERMISSION_UPDATE)) {
                     $comment->private = true;
                     $comment->save();
                 }
                 break;
         }
         if (!$this->ajax) {
             $this->request->redirect(Route::get('gallery_image')->uri(array('gallery_id' => Route::model_id($gallery), 'id' => $image->id, 'action' => '')));
         }
     }
     if (!$this->ajax) {
         Request::back('galleries');
     }
 }