Beispiel #1
0
 /**
  * Upload slider
  *
  * @author Nguyen Van Hiep
  * @access public
  *
  * @version 1.0
  * @since 1.0
  */
 public function action_add($current_cat_view = '', $current_lang_view = '')
 {
     $view = View::forge('admin/article/add');
     $view->err = array();
     $view->langs = $this->langs;
     $view->cats = Model_Categories::get_cat_list();
     if ($current_cat_view != 'cat' and $current_lang_view != 'lang') {
         $view->current_cat_view = "cat={$current_cat_view}&lang={$current_lang_view}";
     } elseif ($current_cat_view != 'cat') {
         $view->current_cat_view = "cat={$current_cat_view}&lang=";
     } elseif ($current_lang_view != 'lang') {
         $view->current_cat_view = "cat=&lang={$current_lang_view}";
     } else {
         $view->current_cat_view = "cat=&lang=";
     }
     if (Input::method() == 'POST') {
         if (count(Input::file()) == 0) {
             Session::set_flash('error', __('message.upload_files_error'));
             Response::redirect('admin/article/add');
         }
         $a = Model_Article::forge();
         $a->title = Input::post('title');
         $a->title_search = str_replace('-', ' ', Input::post('slug'));
         $a->slug = Input::post('slug');
         $val = Model_Article::validate('add', $a);
         // Custom configuration for this upload
         Upload::process($this->config);
         if ($val->run() and count(Upload::get_errors()) == 0) {
             $a->desc = Input::post('desc');
             $a->content = Input::post('content');
             $a->content_search = preg_replace('/[\\s]+/mu', ' ', strip_tags(Input::post('content')));
             $content = Input::vn_str_filter(strip_tags(Input::post('content')));
             $a->content_search_no_mark = preg_replace('/[\\s]+/mu', ' ', $content);
             $a->thumb = '';
             $a->views = 0;
             $a->lang = Input::post('lang');
             $a->created_at = date('Y-m-d h:i:s', time());
             $a->updated_at = date('Y-m-d h:i:s', time());
             //save article
             if ($a->save()) {
                 // Save Product-Slug
                 Model_Article::save_slug($a->id);
                 // Save Article-Category
                 Model_ArtCat::save_art_cat($a->id, Input::post('cat') ? Input::post('cat') : array(), false);
                 //Save images
                 $this->save_thumb($a->id, true);
                 //redirect to index page
                 Session::set_flash('success', __('message.art_added'));
                 Response::redirect("admin/article?{$view->current_cat_view}");
             } else {
                 //fail in transaction
                 Session::set_flash('error', __('message.registration_failed'));
             }
         } else {
             $view->err = $val->error_message();
             $err = $this->upload_errors(Upload::get_errors());
             $view->err = array_merge($view->err, $err);
             Session::set_flash('error', __('message.validation_error'));
         }
     }
     $this->template->title = __('art.add_new');
     $this->template->content = $view;
 }