Esempio n. 1
0
 public function createAction()
 {
     $request = $this->getRequest();
     $ad_id = $this->_request->getParam('ad_id');
     //first we check if user is logged, if not redir to login
     $auth = Zend_Auth::getInstance();
     if (!$auth->hasIdentity()) {
         //keep this url in zend session to redir after login
         $aNamespace = new Zend_Session_Namespace('Nolotiro');
         $aNamespace->redir = $this->lang . '/ad/' . $ad_id;
         $this->_redirect($this->lang . '/auth/login');
     } else {
         $form = $this->_getCommentForm();
         // check to see if this action has been POST'ed to
         if ($this->getRequest()->isPost()) {
             if ($form->isValid($request->getPost())) {
                 $formulario = $form->getValues();
                 //if comment its empty dont do nothing as redir to same ad
                 if (empty($formulario['body'])) {
                     $this->_helper->_flashMessenger->addMessage($this->view->translate('Write something!'));
                     $this->_redirect('/' . $this->lang . '/ad/' . $ad_id);
                 }
                 //strip html tags to body
                 $formulario['body'] = strip_tags($formulario['body']);
                 //anti hoygan to body
                 $split = explode(". ", $formulario['body']);
                 foreach ($split as $sentence) {
                     $sentencegood = ucfirst(mb_convert_case($sentence, MB_CASE_LOWER, "UTF-8"));
                     $formulario['body'] = str_replace($sentence, $sentencegood, $formulario['body']);
                 }
                 //get the ip of the ad publisher
                 if (getenv(HTTP_X_FORWARDED_FOR)) {
                     $ip = getenv(HTTP_X_FORWARDED_FOR);
                 } else {
                     $ip = getenv(REMOTE_ADDR);
                 }
                 $formulario['ip'] = $ip;
                 $formulario['ads_id'] = $ad_id;
                 //get this ad user owner
                 $formulario['user_owner'] = $auth->getIdentity()->id;
                 //get date created
                 //TODO to use the Zend Date object to apapt the time to the locale user zone
                 $datenow = date("Y-m-d H:i:s", time());
                 $formulario['date_created'] = $datenow;
                 $modelC = new Model_Comment();
                 $modelC->save($formulario);
                 $this->_helper->_flashMessenger->addMessage($this->view->translate('Comment published succesfully!'));
                 $this->_redirect('/' . $this->lang . '/ad/' . $ad_id);
             }
         }
     }
 }
Esempio n. 2
0
 private function saveComment(Model_Comment $comment, View_Html $view)
 {
     if (isset($_REQUEST['save'])) {
         $comment->setData($_POST);
         if (!($errors = $comment->validate())) {
             $comment->save();
             $view->redir('Admin_Article', 'edit', array('id' => $comment->article));
             return true;
         }
         $view->errors = $errors;
     }
     return false;
 }
Esempio n. 3
0
 private function saveComment(View_Html $view)
 {
     if (in_array("comments", $view->article->flags) && $_POST['comment'] === 'save' && !$_POST['comment_url']) {
         $comment = new Model_Comment($this->getStorage());
         $comment->username = nl2br(htmlspecialchars(strip_tags($_POST['comment_username'])));
         $comment->email = $_POST['comment_email'];
         $comment->title = nl2br(htmlspecialchars(strip_tags($_POST['comment_title'])));
         $comment->content = nl2br(htmlspecialchars(strip_tags($_POST['comment_content'])));
         $comment->article = $view->article->getId();
         //$comment->owner    = $view->article->owner;
         //$comment->group    = $view->article->group;
         if (empty($comment->title)) {
             $comment->title = "Без темы";
         }
         if (!($errors = $comment->validate())) {
             $comment->save();
             $view->redir("Default", "article", array('path' => $view->topic->getPath(), 'article' => $view->article->getId()));
             return true;
         }
         $view->errors = $errors;
         $view->newComment = $comment;
     }
     return false;
 }