Exemplo n.º 1
0
 public function edit($id = NULL)
 {
     $id = (int) $id;
     if (!$id) {
         $this->redirect('comments');
     }
     $this->view->conf = $this->conf;
     $Comment = new comment();
     $comment = $Comment->find($id);
     $comment['content'] = utils::convert2HTML($comment['content']);
     $Post = new post();
     $post = $Post->findBy('ID', $comment['ID_post']);
     $comment['post'] = array('urlfriendly' => $post['urlfriendly'], 'title' => $post['title']);
     $this->view->comment = $comment;
     $this->view->id = $id;
     $statuses = array("publish", "waiting");
     $this->view->statuses = $statuses;
     if ($_SERVER["REQUEST_METHOD"] == "POST") {
         if (isset($_POST['cancelar'])) {
             $this->redirect("comments");
         } else {
             ###########
             # Las siguientes dos lineas no deberian estar pero algo anda mal con el ActiveRecord que no deja las variables
             # de las consultas que se realizan directamente desde dentro de algun metodo en el model con $this->db->query e interfiere
             # con el actualizar por que podria haber campos que no se requieren en la actualizacion.
             ###########
             $comment = new comment();
             #######
             $comment->find($id);
             #######
             $comment->prepareFromArray($_POST);
             $comment->save();
             $this->redirect("comments/edit/{$id}");
         }
     } else {
         $this->view->setLayout("admin");
         $this->title_for_layout($this->l10n->__("Editar comentario - Codice CMS"));
         $this->render();
     }
 }
Exemplo n.º 2
0
 public function addComment($urlfriendly = null)
 {
     $C = new configuration();
     $codice = $C->getBlogConfiguration();
     if ($this->data) {
         if (is_null($urlfriendly) === true) {
             $this->redirect($codice['blog_siteurl'], true);
         }
         $P = new post();
         $post = $P->findBy('urlfriendly', $urlfriendly);
         if ($P->isNew() === true) {
             $this->redirect($codice['blog_siteurl'], true);
         }
         if (isset($this->data["resultado"]) === true) {
             $captcha = $this->data['resultado'];
             if ($captcha != '5') {
                 $this->session->flash('Tu comentario no puede ser agregado. Necesitas contestar la pregunta correctamente.');
                 $this->redirect("{$post['urlfriendly']}#comments");
             }
             unset($this->data['resultado']);
         } else {
             $this->session->flash('Tu comentario no puede ser agregado. Necesitas contestar la pregunta.');
             $this->redirect("{$post['urlfriendly']}#comments");
         }
         if ($this->cookie->check('id_user')) {
             $this->data['user_id'] = $this->cookie->id_user;
             $this->data['status'] = 'publish';
         } else {
             $this->data['user_id'] = 0;
             $this->data['status'] = 'waiting';
         }
         $this->data['type'] = '';
         //'pingback', 'trackback', ''
         $this->data['IP'] = utils::getIP();
         $this->data['ID_post'] = $post["ID"];
         $this->cookie->author = $this->data['author'];
         $this->cookie->email = $this->data['email'];
         $this->cookie->url = $this->data['url'];
         $C = new comment();
         $C->prepareFromArray($this->data);
         $valid = $C->save();
         if ($valid) {
             $this->registry->lastCommentID = $valid;
             $this->registry->postID = $post["ID"];
             $this->plugin->call("index_comment_added");
         }
         if ($valid and $this->isAjax()) {
             echo $valid;
         } else {
             if ($valid) {
                 $this->redirect("{$post['urlfriendly']}#comment-{$valid}");
             } else {
                 $this->redirect("{$post['urlfriendly']}");
             }
         }
     }
 }