예제 #1
0
 /**
  * Guarda el comentario del artículo
  * @param $tag
  * @return unknown_type
  */
 public function nuevo_comentario($articulo_slug = null)
 {
     $articulo = new Articulo();
     $recaptcha = new Recaptcha();
     $articulo = $articulo->getEntryBySlug($articulo_slug);
     $this->articulo_id = $articulo->id;
     $this->articulo_slug = $articulo_slug;
     $this->comentarios = Load::model('comentario')->getCommentByPost($this->articulo_id);
     $this->countComment = count($this->comentarios);
     $this->captcha = $recaptcha->generar();
     if (Input::hasPost('comentario')) {
         try {
             //Comprueba el reCAPTCHA
             if ($recaptcha->comprobar($_SERVER["REMOTE_ADDR"], $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field'])) {
                 if (Load::model('comentario')->save(Input::post('comentario'))) {
                     Flash::success('Comentario enviado');
                     Router::redirect("articulo/{$articulo_slug}/");
                 } else {
                     Flash::error('Ha ocurrido un error');
                     $this->comentario = Input::post('comentario');
                 }
             }
         } catch (KumbiaException $kex) {
             Flash::error('Ingresa correctamente las palabras del captcha');
             $this->captcha = $recaptcha->generar($kex->getMessage());
             $this->comentario = Input::post('comentario');
         }
     }
 }