function index()
 {
     $params = array('fields' => array('title', 'body', 'hoge'), 'order' => array('_id' => -1), 'limit' => 35, 'page' => 1);
     $results = $this->Post->find('all', $params);
     //$result = $this->Post->find('count', $params);
     $this->set(compact('results'));
 }
Example #2
0
 public function getArticle($id)
 {
     $post = Post::find($id);
     $sidePosts = Post::take(3)->offset(1)->orderby('id', 'desc')->get();
     $comments = Comment::where('post_id', $id)->get();
     return View::make('pages.view')->with(compact('post', 'sidePosts', 'comments'))->with('pageTitle', $post->title);
 }
 public function testCommentsReturnRelatedComments()
 {
     $post1 = Post::find(1);
     $post2 = Post::find(2);
     $this->assertEquals(5, $post1->comments()->count());
     $this->assertEquals(1, $post2->comments()->count());
 }
 public function edit($id)
 {
     $post = Post::find($id);
     $this->authorOrAdminPermissioinRequire($post->user_id);
     $category_selects = Category::lists('name', 'id');
     return View::make('posts.create_edit', compact('category_selects', 'post'));
 }
 public function articleAction()
 {
     $posts = Post::find(['type = "post" AND id_web = "' . $this->auth->id_web . '" order by id desc']);
     $paginator = new PaginatorModel(array("data" => $posts, "limit" => $this->params->limit, "page" => $this->params->page));
     $page = $paginator->getPaginate();
     $this->view->setVar("page", $page);
 }
 public function postContent($type_id, $id = 'add')
 {
     $all = Input::all();
     if (!$all['slug']) {
         $all['slug'] = BaseController::ru2Lat($all['title']);
     }
     $rules = array('name' => 'required|min:2|max:255', 'title' => 'required|min:3|max:255', 'slug' => 'required|min:4|max:255|alpha_dash');
     $validator = Validator::make($all, $rules);
     if ($validator->fails()) {
         return Redirect::to('/admin/content/' . $type_id . '/' . $id)->withErrors($validator)->withInput()->with('error', 'Ошибка');
     }
     if (is_numeric($id)) {
         $post = Post::find($id);
     } else {
         $post = new Post();
     }
     $post->type_id = $all['type_id'];
     $post->name = $all['name'];
     $post->title = $all['title'];
     $post->slug = $all['slug'];
     $post->text = $all['text'];
     $post->parent = $all['parent'];
     $post->status = isset($all['status']) ? true : false;
     $post->order = $all['order'];
     $post->description = $all['description'];
     $post->keywords = $all['keywords'];
     if (isset($all['image'])) {
         $post->image = AdminController::saveImage($all['image'], 'upload/image/', 250);
     }
     $post->save();
     return Redirect::to('/admin/content/' . $all['type_id'] . '/' . $id)->with('success', 'Изменения сохранены');
 }
Example #7
0
 public static function updatePost($input, $id)
 {
     $answer = [];
     $rules = ['title' => 'required', 'body' => 'required', 'user_id' => 'required|integer'];
     $validation = Validator::make($input, $rules);
     if ($validation->fails()) {
         $answer['message'] = $validation->errors()->getMessages();
         $answer['error'] = true;
     } else {
         $post = Post::find($id);
         $post->title = Input::get('title');
         $post->image_url = Input::get('image_url');
         $post->body = Input::get('body');
         $post->user_id = Input::get('user_id');
         if ($post->save()) {
             $answer['message'] = 'Editado con exito!';
             $answer['error'] = false;
             $answer['data'] = $post;
         } else {
             $answer['message'] = 'UPDATE error, team noob!';
             $answer['error'] = false;
         }
     }
     return $answer;
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $post = Post::find($id);
     $post->delete();
     Session::flash('successMessage', 'Your post has been deleted.');
     return Redirect::action('posts.index');
 }
Example #9
0
 public function testTranslatedAttributesCanBeRetrievedInDifferentLocales()
 {
     $this->createTwoPostsWithOneTranslatedInThreeLocales();
     $model = Post::find(1);
     $model->translations()->where('locale', 'en')->update(['title' => 'New Title']);
     $this->assertEquals('New Title', Post::find(1)->title);
 }
Example #10
0
 public function testPostKeywords()
 {
     $post = Post::find(16);
     $this->assertTrue(count($post->keywords) > 0);
     $post = Post::find(2);
     $this->assertTrue(count($post->keywords) == 0);
 }
 public function delete($id)
 {
     $post = $this->blogRepository->find($id);
     // Title
     $title = Lang::get('admin.blogs.title.blog_delete');
     // Show the page
     $this->render('admin.blogs.delete', compact('post', 'title'));
 }
 public function show($id)
 {
     $post = Post::find($id);
     if ($post->is_premium && Auth::user()->stripe_plan != 'gold') {
         return View::make('error', ['message' => 'Only GOLD members can read this post, <a href="/upgrade">upgrade</a> your membership to get access']);
     }
     return View::make('post', ['post' => $post]);
 }
Example #13
0
 public function testModelCanBeMassUpdated()
 {
     Post::forceCreate(['id' => 1, 'title' => 'Lorem ipsum']);
     Post::forceCreate(['id' => 2, 'title' => 'Lorem ipsum']);
     Post::where('title', 'Lorem ipsum')->update(['title' => 'Lorem ipsum 2']);
     $this->assertEquals('Lorem ipsum 2', Post::find(1)->title);
     $this->assertEquals('Lorem ipsum 2', Post::find(2)->title);
 }
Example #14
0
 private function getComments()
 {
     $post = Post::find(Input::get('post'));
     if (is_null($post)) {
         return false;
     }
     return $post->comments()->where('created_at', '>', Input::get('timestamp'))->take($this->count)->get();
 }
Example #15
0
 /**
  * MI: Warning for Windows:
  * The PHP function symlink only works on Windows Vista, Server 2008 or greater.
  */
 public function setPostId($id)
 {
     $post = Post::find($id);
     $file = $post->file_path();
     symlink($file, $this->tempfile_image_path());
     $this->received_file = true;
     $this->md5 = $post->md5;
 }
Example #16
0
 public function indexAction()
 {
     $currentPage = $this->request->getQuery('page', 'int', 1);
     $posts = Post::find(['status > 0', 'order' => 'id DESC']);
     $paginator = new Paginator(['data' => $posts, 'limit' => Post::DEFAULT_POSTS_ON_PAGE, 'page' => $currentPage]);
     $this->view->setVar('title', 'Posts | ');
     $this->view->setVar('page', $paginator->getPaginate());
 }
Example #17
0
 public function actionLikes($postid)
 {
     $model = Post::find()->where(['id' => $postid])->one();
     print_r($model->post_likes);
     if (app()->request->isAjaxRequest) {
         echo \CJSON::encode(array('success' => 'true'));
     }
 }
Example #18
0
 public function showDashboard()
 {
     $page = Post::find(285);
     if ($page) {
         $data['page'] = PostLang::where('post_id', $page->id)->where('lang_id', WebAPL\Language::getId())->first();
     }
     $this->layout->content = View::make('hello', $data);
 }
Example #19
0
 public function tag_changes($prev)
 {
     $new_tags = explode(' ', $this->tags);
     $old_tags = explode(' ', $prev->tags);
     $latest = Post::find($this->post_id)->cached_tags;
     $latest_tags = explode(' ', $latest);
     return ['added_tags' => array_diff($new_tags, $old_tags), 'removed_tags' => array_diff($old_tags, $new_tags), 'unchanged_tags' => array_intersect($array_new_tags, $old_tags), 'obsolete_added_tags' => array_diff(array_diff($new_tags, $old_tags), $latest_tags), 'obsolete_removed_tags' => array_intersect(array_diff($old_tags, $new_tags), $latest_tags)];
 }
Example #20
0
 public function destroy($id)
 {
     $content = Input::all();
     foreach ($content['data'] as $object) {
         $post = Post::find($object['id']);
         $post->delete();
     }
     return Response::json(array('error' => false, 'msg' => 'post deleted'));
 }
Example #21
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $post = Post::find($id);
     $post->entry()->delete();
     $post->delete();
     Session::flash('status', true);
     Session::flash('messages', array('Đã xóa ảnh'));
     return Redirect::route('admin.post.index');
 }
Example #22
0
 static function index()
 {
     if (!isset($_SESSION['user'])) {
         $ids = Post::find('all', array('select' => 'DISTINCT user_id'));
         set('ids', $ids);
         return html('welcome.html.php');
     }
     redirect_to('/blog/' . $_SESSION['user']['id']);
 }
Example #23
0
 public function show()
 {
     if (!isset($_GET['id'])) {
         return call('pages', 'error');
     }
     //use id to get the right post
     $post = Post::find($_GET['id']);
     require_once 'views/posts/show.php';
 }
Example #24
0
 public function delete_destroy()
 {
     $cid = Input::get('cid');
     $pid = Input::get('pid');
     $post = Post::find($pid);
     //$post_id = Comment::find(Input::get('id'))->post->slug;
     Comment::find($cid)->delete();
     return Redirect::to_route('post_view', $post->slug)->with('message', 'Comment has been deleted Successfully!');
 }
 function approve($user_id, $ip_addr)
 {
     DB::update("tag_implications SET is_pending = FALSE WHERE id = {$this->id}");
     $t = Tag::find($this->predicate_id);
     $implied_tags = implode(' ', self::with_implied(array($t->name)));
     foreach (Post::find('all', array('conditions' => array("id IN (SELECT pt.post_id FROM posts_tags pt WHERE pt.tag_id = ?)", $t->id))) as $post) {
         $post->update_attributes(array('tags' => $post->tags . " " . $implied_tags, 'updater_user_id' => $user_id, 'updater_ip_addr' => $ip_addr));
     }
 }
 public function show($id)
 {
     $post = Post::find($id);
     if ($post) {
         return Response::json(['data' => $post]);
     } else {
         return Response::json(['error' => true, 'description' => 'no existe!']);
     }
 }
 public function article($id)
 {
     $article = Post::find($id);
     if (is_null($article)) {
         return App::abort('404');
     }
     View::share('page_title', $article->title);
     View::share('post', $article);
     return View::make('public.post');
 }
Example #28
0
 public function show($id)
 {
     $post = Post::find($id);
     $user = User::find($post->user_id);
     if ($post) {
         return View::make('post.show', ['post' => $post, 'user' => $user]);
     } else {
         return "Publicacion no existe";
     }
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     //
     $post = Post::find($id);
     if (is_null($post)) {
         App::abort(404);
     }
     // throw NofFoundHttpException with $code=404
     return View::make('posts.edit')->with('post', $post);
 }
 public function testShow()
 {
     $post = Factory::create('Post', ['slug' => 'foo']);
     $this->action('GET', 'PostsController@show', 'foo');
     $this->assertResponseOk();
     $this->assertViewIs('posts.show');
     $this->assertViewHas('post');
     $post = Post::find($post->id);
     $this->assertEquals(1, $post->views);
 }