Esempio n. 1
0
 public function store()
 {
     $article = Model\Article::findOrFail(set_value('article_id'));
     $this->form_validation->set_rules('name', 'Name', 'required');
     $this->form_validation->set_rules('email', 'Email', 'required|valid_email');
     $this->form_validation->set_rules('content', 'Komentar', 'required');
     $this->form_validation->set_rules('article_id', 'Artikel', 'required');
     if ($this->form_validation->run() == FALSE) {
         if ($this->request->isXmlHttpRequest()) {
             $response = new Response();
             $response->setContent(json_encode(['status' => 'error', 'data' => $this->form_validation->error_array()]));
             $response->headers->set('Content-Type', 'application/json');
         } else {
             keepValidationErrors();
             redirect($article->link . '#comment-title', 'refresh');
         }
     } else {
         $data = array('content' => set_value('content'), 'nama' => set_value('name'), 'email' => set_value('email'), 'artikel_id' => set_value('article_id'), 'parent' => set_value('parent', 0), 'date' => Carbon::now());
         $comment = Model\Comment::create($data);
         if (auth()->loginCheck()) {
             $comment->user()->associate(auth()->user()->id);
             $comment->save();
         }
         if ($this->request->isXmlHttpRequest()) {
             $response = new Response();
             $response->setContent(json_encode(['status' => 'success', 'data' => $comment]));
             $response->headers->set('Content-Type', 'application/json');
         } else {
             redirect($article->link . '#comment-' . $comment->id, 'refresh');
         }
     }
 }
<?php

$app->group('/comment', function () use($app) {
    $user = new \Model\User();
    $comment = new \Model\Comment();
    $app->get('/', function () use($app, $comment) {
        try {
            $result = $comment->getAll();
            jsonSuccess($app, array('comments' => $result));
        } catch (Exception $e) {
            jsonError($app, $e);
        }
    });
    $app->get('/marker/:id', function ($id) use($app, $comment) {
        try {
            $result = $comment->getByMarker($id);
            jsonSuccess($app, array('comments' => $result));
        } catch (Exception $e) {
            jsonError($app, $e);
        }
    });
    $app->get('/id/:id', function ($id) use($app, $comment) {
        try {
            $result = $comment->getByID($id);
            jsonSuccess($app, $result);
        } catch (Exception $e) {
            jsonError($app, $e);
        }
    });
    $app->get('/user/:id', function ($id) use($app, $comment) {
        try {
Esempio n. 3
0
 /**
  * add a comment from POST data to current blog post
  */
 public function addComment(\Base $f3, $params)
 {
     if (isset($params['slug'])) {
         // you may only comment published posts
         $this->resource->load(array('slug = ? and publish_date <= ? and published = ?', $params['slug'], date('Y-m-d'), true));
         if ($this->resource->dry()) {
             // invalid post ID
             $f3->error(404, 'Post not found.');
             return false;
         }
         if (!$this->resource->enable_comments && !$this->resource->enable_comments === NULL) {
             $f3->error(403, 'Comments are not allowed for this Post');
             return false;
         }
         $comment = new \Model\Comment();
         $comment->copyfrom('POST', 'author_name, author_email, message');
         $comment->post = $this->resource->_id;
         $comment->approved = \Config::instance()->get('auto_approve_comments') ? 1 : 0;
         $comment->save();
         if ($f3->get('ERROR')) {
             // if posting failed, return to comment form
             $this->getSingle($f3, $params);
         } else {
             // if posting was successful, reroute to the post view
             if (\Config::instance()->get('auto_approve_comments')) {
                 \Flash::instance()->addMessage('Your comment has been added.', 'success');
             } else {
                 \Flash::instance()->addMessage('Your comment has been added, but must be approved first before it becomes public.', 'success');
             }
             $f3->reroute('/' . $params['slug']);
         }
     } else {
         // invalid URL, no post id given
         \Flash::instance()->addMessage('No Post ID specified.', 'danger');
         $f3->reroute('/');
     }
 }
Esempio n. 4
0
                    <?php 
}
?>
                </div>
            </div>
        </div>
    </div>

    <div class="widget">
        <div class="widget-heading">
            <h3>LATEST KOMENTAR</h3>
        </div>
        <div class="widget-content">
            <div class="row">
                <?php 
foreach (Model\Comment::latest('date')->get() as $comment) {
    ?>
                <div class="box-komentar-widget">
                    <div class="col-sm-3 col-xs-4">
                        <div class="box-komentar-widget-img">
                            <img src="<?php 
    echo $comment->avatar;
    ?>
" alt="">
                        </div>
                    </div>
                    <div class="col-sm-9 col-xs-8">
                        <div class="box-komentar-widget-title">
                            <p><strong><a href="#"><?php 
    echo $comment->nama;
    ?>