public function getPost()
 {
     if ($_REQUEST['action'] == 'new') {
         return View::make('post.new');
     }
     if ($_REQUEST['action'] == 'edit') {
         $post = Post::getPostById($_REQUEST['post_id']);
         $tags = Post::getTagsByPostId($_REQUEST['post_id']);
         $tags = array_pluck($tags, 'tag_name');
         return View::make('post.edit', array('post' => $post, 'tags' => $tags));
     }
 }
 public static function updatePost(array $post)
 {
     $postId = $post['postId'];
     $headline = $post['headline'];
     $body = $post['body'];
     $updated = Post::updatePost(new Post($postId, $headline, $body, null, null, null));
     if (is_a($updated, 'ErrorObject')) {
         return $updated;
     }
     $postData = Post::getPostById($postId);
     return $postData;
 }
Example #3
0
 public static function getCommentsOfPost($post_id)
 {
     $comments = Comment::where('post_id', $post_id)->get();
     foreach ($comments as $comment) {
         $user_id = $comment['user_id'];
         $user = User::getUserById($user_id);
         $comment['username'] = $user['username'];
         $comment['avatar_link'] = $user['avatar_link'];
         $comment['email'] = $user['email'];
         $post = Post::getPostById($comment["post_id"]);
         $comment['title'] = $post['title'];
         $format = "F j, Y, g:i a";
         $date = new DateTime($post['updated_at']);
         $formatDate = $date->format($format);
         $comment['update_time'] = $formatDate;
     }
     return $comments;
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store($post_id)
 {
     //
     try {
         if (Auth::check()) {
         }
     } catch (Exception $ex) {
         return Response::json(array("message" => "Đăng nhập để comment", "isHide" => true), 404);
     }
     $content = Input::get('content');
     $id = Auth::id();
     if ($id == null) {
         return Response::json(array("message" => "Đăng nhập để comment", "isHide" => true), 404);
     }
     if ($content != null) {
         $comment = new Comment();
         $comment->content = $content;
         $comment->user_id = Auth::id();
         $comment->post_id = $post_id;
         $comment->avatar_link = Auth::user()->avatar_link;
         $comment->save();
         $user_id = $comment['user_id'];
         $user = User::getUserById($user_id);
         $comment['username'] = $user['username'];
         $comment['email'] = $user['email'];
         $post = Post::getPostById($comment["post_id"]);
         $comment['title'] = $post['title'];
         $format = "F j, Y, g:i a";
         $date = new DateTime($post['updated_at']);
         $formatDate = $date->format($format);
         $comment['update_time'] = $formatDate;
         if (isset($user['fb_img'])) {
             $comment['fb_img'] = $user['fb_img'];
         }
         if ($comment["user_id"] == $id) {
             $comment["owner"] = true;
         } else {
             $comment["owner"] = false;
         }
         return Response::json($comment);
     } else {
         return Response::json(array('success' => false));
     }
 }
Example #5
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     //Auth::check()
     //        if(true) {
     $content = Input::get('content');
     $id = Auth::id();
     if ($content != null) {
         $comment = new Comment();
         $comment->content = $content;
         $comment->user_id = Auth::id();
         $comment->save();
         $user_id = $comment['user_id'];
         $user = User::getUserById($user_id);
         $comment['username'] = $user['username'];
         $comment['email'] = $user['email'];
         $post = Post::getPostById($comment["post_id"]);
         $comment['title'] = $post['title'];
         $format = "F j, Y, g:i a";
         $date = new DateTime($post['updated_at']);
         $formatDate = $date->format($format);
         $comment['update_time'] = $formatDate;
         if (isset($user['fb_img'])) {
             $comment['fb_img'] = $user['fb_img'];
         }
         if ($comment["user_id"] == $id) {
             $comment["owner"] = true;
         } else {
             $comment["owner"] = false;
         }
         return Response::json($comment);
     } else {
         return Response::json(array('success' => false));
     }
     //        else
     //        {
     //           return Redirect::to('/login');
     //        }
 }
Example #6
0
<?php

require_once '../classes/domains/Categories.php';
require_once '../classes/domains/Post.php';
$postId = isset($_GET["pid"]) ? $_GET['pid'] : null;
if (!is_null($postId)) {
    $postArray = Post::getPostById($postId);
    $post = $postArray[0];
} else {
    $post = new Post(0, '', '');
    //redirect back to where they came from.
}
$currentCategory = Categories::getCategoryById($post->categoryId);
$currentActiveString = $currentCategory[0]->category;
$showBottomLink = false;
?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <?php 
require_once 'views/header.php';
?>
    <link href="../assets/css/styles/tomorrow-night-eighties.css" rel="stylesheet">
    <style>
      fieldset.fieldset-override {
        padding: 20px 20px 20px 20px;
        background-color: #FFFFFF;
        border: 1px solid #DDDDDD;
        border-radius: 4px 4px 4px 4px;
        margin: 15px 0;
Example #7
0
<?php

require_once 'includes/config.inc.php';
if (isset($_GET['id']) && intval($_GET['id']) > 0) {
    $id = $_GET['id'];
    $post = Post::getPostById($id);
} else {
    redirect_to('.');
}
require_once VIEW_PATH . 'read.view.php';
Example #8
0
});
$app->post('/uploadCover', function () use($user, $app, $login) {
    echo json_encode($user->uploadCover($_SESSION['auth']['user_id'], $_FILES['cover'], $login));
});
$app->put('/changePassword', function () use($user, $app) {
    $passwords = json_decode($app->request->getBody(), true);
    echo json_encode($user->changePassword($_SESSION['auth']['user_id'], $passwords));
});
/**
 * Posts
 */
$app->get('/posts/:type/:user_id/:offset/:limit', function ($type, $user_id, $offset, $limit) use($post, $app) {
    echo json_encode($post->getPosts($type, $user_id, null, $offset, $limit));
});
$app->get('/post/:id', function ($id) use($post) {
    echo json_encode($post->getPostById($id));
});
$app->post('/post', function () use($post, $app) {
    $data = json_decode($app->request->getBody());
    echo json_encode($post->publishPost($_SESSION['auth']['user_id'], $data->friend_id, $data->content));
});
$app->delete('/post', function () use($post, $app) {
    $post_id = json_decode($app->request->getBody());
    echo json_encode($post->deletePost($_SESSION['auth']['user_id'], $post_id));
});
/**
 * Posts - Like
 */
$app->put('/post/like', function () use($post, $app) {
    $post_id = json_decode($app->request->getBody());
    echo json_encode($post->likePost($_SESSION['auth']['user_id'], $post_id));
Example #9
0
 public function getUpdate($id)
 {
     $post = Post::getPostById($id);
     return View::make('post.update', array('post' => $post));
 }