public function action_delete()
 {
     $result = array('status' => false, 'error' => array());
     try {
         $input = Input::post();
         if (empty($input) || empty($input['id'])) {
             throw new Exception('You must specify a blog to delete.');
         }
         $blog = Model_Blog::find($input['id']);
         if (!$blog) {
             throw new Exception('Blog not found.');
         }
         if (!\Access::can('delete_any_blog', $this->user) && (!\Access::can('delete_own_blog', $this->user) || !Model_Agency_Contact::is_confirmed($blog->user_id, $this->user))) {
             throw new Exception('You are not authorized to delete this blog');
         }
         try {
             $blog->delete();
             $result['status'] = true;
         } catch (\Orm\ValidationFailed $ex) {
             $result['error'] = $ex->getMessage();
         } catch (Exception $ex) {
             $msg = $ex->getMessage();
             $result['error'] = $msg ? $msg : 'Oops, something went wrong.';
         }
     } catch (Exception $ex) {
         $result['error'] = $ex->getMessage();
     }
     return $this->response($result);
 }
Exemple #2
0
 public function post_add()
 {
     $model = Model_Blog::forge();
     $model->set(Input::post());
     $model->set(BLOG_CREATED_DATE, DB::expr('now()'));
     $model->set(DELETE_FLG, '0');
     $model->save();
     Response::redirect(Config::get('base_url'));
 }
Exemple #3
0
 public function action_detail()
 {
     $this->setJavascript('responesive_tabs.js');
     $this->setJavascript('fb_comment.js');
     $aryDataTemplate['data'] = array();
     $id = Input::param('id');
     if ($id) {
         $data = Model_Blog::find($id);
         $aryDataTemplate['data'] = $data;
         $this->setPageTitle($data[BLOG_TITLE]);
     }
     $this->template->content = View_Smarty::forge('blog/detail.tpl', $aryDataTemplate);
 }
Exemple #4
0
 public function action_delete($id = null)
 {
     is_null($id) and Response::redirect('blog');
     if ($blog = Model_Blog::find($id)) {
         $blog->delete();
         Session::set_flash('success', 'Deleted blog #' . $id);
     } else {
         Session::set_flash('error', 'Could not delete blog #' . $id);
     }
     Response::redirect('blog');
 }
 protected function load_blog_view($user_id, $blog_id = null)
 {
     $blogView = \View::forge('pages/blog');
     $results = Model_Blog::load($blog_id, $user_id);
     $blogView->is_confirmed = $this->user && $this->user->id == $user_id;
     $blogView->user_id = $this->user ? $this->user->id : $user_id;
     $blogView->blog_id = $blog_id;
     $blogView->blogs = $results['data'];
     $blogView->count = $results['count'];
     $blogView->is_public = empty($user_id) ? true : false;
     $blogView->can_edit_own = $this->user && \Access::can('edit_own_blog', $this->user);
     $blogView->can_edit_any = $this->user && \Access::can('edit_any_blog', $this->user);
     $blogView->can_delete_own = $this->user && \Access::can('delete_own_blog', $this->user);
     $blogView->can_delete_any = $this->user && \Access::can('delete_any_blog', $this->user);
     $blogView->can_make_own_public = $this->user && \Access::can('publicize_own_blog', $this->user);
     $blogView->can_make_any_public = $this->user && \Access::can('publicize_any_blog', $this->user);
     $blogView->addable = empty($blog_id) && $this->user && $blogView->can_edit_own && ($blogView->is_public && $blogView->can_make_own_public || $blogView->is_confirmed);
     //user can add their own blog
     $blogView->include_edit_form = $blogView->addable || $blogView->can_edit_any && $blogView->count;
     $blogView->force_public = $blogView->is_public && $blogView->can_make_any_public;
     $blogView->title = null;
     if ($blogView->include_edit_form) {
         $this->include_client_scripts(array('jquery_forms'));
     }
     return $blogView;
 }
Exemple #6
0
 public function action_undoFeatured($id = null)
 {
     is_null($id) and Response::redirect('blog');
     $blog = Model_Blog::find($id);
     if ($blog) {
         $blog->blog_featured = 0;
         if ($blog->save()) {
             Session::set_flash('success', 'Blog #' . $id . ' is now featured.');
         } else {
             Session::set_flash('error', 'Could not make blog #' . $id . ' featured.');
         }
     }
     Response::redirect('blog');
 }