/** * displays the form new topic * @return [type] [description] */ public function action_new() { if (!Auth::instance()->logged_in()) { Alert::set(Alert::ALERT, __('Please login before posting')); $this->redirect(Route::url('oc-panel', array('controller' => 'auth', 'action' => 'login'))); } $forums = Model_Forum::get_forum_count(); if (count($forums) == 0) { if (Auth::instance()->logged_in() and Auth::instance()->get_user()->id_role == Model_Role::ROLE_ADMIN) { Alert::set(Alert::INFO, __('Please, first create some Forums.')); $this->redirect(Route::url('oc-panel', array('controller' => 'forum', 'action' => 'index'))); } else { Alert::set(Alert::INFO, __('New Topic is not available as a feature.')); $this->redirect('default'); } } $errors = NULL; if ($this->request->post()) { //captcha check if (captcha::check('new-forum')) { $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', 'min_length', array(':value', 5))->rule('description', 'max_length', array(':value', 1000))->rule('title', 'not_empty')->rule('title', 'min_length', array(':value', 5))->rule('id_forum', 'numeric'); // Optional banned words validation if (core::config('advertisement.validate_banned_words')) { $validation = $validation->rule('title', 'no_banned_words'); } if ($validation->check()) { $topic = new Model_Post(); $topic->id_user = $user->id_user; $topic->id_forum = core::post('id_forum'); $topic->title = Text::banned_words(core::post('title')); $topic->seotitle = $topic->gen_seotitle($topic->title); $topic->description = Text::banned_words(core::post('description')); $topic->status = Model_Post::STATUS_ACTIVE; $topic->ip_address = ip2long(Request::$client_ip); $topic->save(); $this->redirect(Route::url('forum-topic', array('forum' => $topic->forum->seoname, 'seotitle' => $topic->seotitle))); } else { $errors = $validation->errors('ad'); } } else { Alert::set(Alert::WARNING, __('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')); } } //template header $this->template->title = __('New Forum Topic'); $this->template->meta_description = $this->template->title; Breadcrumbs::add(Breadcrumb::factory()->set_title($this->template->title)); $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'); $this->template->bind('content', $content); $this->template->content = View::factory('pages/forum/new', array('forums' => $forums)); $content->errors = $errors; }