Ejemplo n.º 1
0
 /**
  * add a repply to a topic
  * @param Model_Post  $topic 
  * @param Model_Forum $forum 
  */
 public function add_topic_reply(Model_Post $topic, Model_Forum $forum)
 {
     //if loged in add styles and check for post
     if (Auth::instance()->logged_in()) {
         $this->template->styles = array('css/jquery.sceditor.default.theme.min.css' => 'screen');
         $this->template->scripts['footer'] = array('js/jquery.sceditor.bbcode.min.js', 'js/forum-new.js');
         $errors = NULL;
         if ($this->request->post()) {
             //captcha check
             if (captcha::check('new-reply-topic')) {
                 $user = Auth::instance()->get_user();
                 //akismet spam filter
                 if (!core::akismet($user->name, $user->email, core::post('description'))) {
                     $validation = Validation::factory($this->request->post())->rule('description', 'not_empty')->rule('description', 'max_length', array(':value', 1000))->rule('description', 'min_length', array(':value', 5));
                     if ($validation->check()) {
                         $reply = new Model_Post();
                         $reply->id_user = $user->id_user;
                         $reply->id_forum = $forum->id_forum;
                         $reply->id_post_parent = $topic->id_post;
                         $reply->title = mb_substr(core::post('description'), 0, 145);
                         $reply->seotitle = $reply->gen_seotitle($reply->title);
                         $reply->description = Text::banned_words(core::post('description'));
                         $reply->status = Model_Post::STATUS_ACTIVE;
                         $reply->ip_address = ip2long(Request::$client_ip);
                         $reply->save();
                         //set empty since they already replied
                         Request::current()->post('description', '');
                         Alert::set(Alert::SUCCESS, __('Reply added, thanks!'));
                         //notification to the participants
                         $topic->notify_repliers();
                     } else {
                         $errors = $validation->errors('ad');
                     }
                 } else {
                     Alert::set(Alert::ERROR, __('This email has been considered as spam! We are sorry but we can not send this email.'));
                 }
             } else {
                 Alert::set(Alert::ERROR, __('Check the form for errors'));
             }
         }
         return $errors;
     }
 }