Example #1
0
 /**
  * Upload action
  * @access  public
  * @return  Response
  */
 public function action_upload()
 {
     $files = array();
     if (\Input::method() == 'POST') {
         \Util_security::check_csrf();
         $file_tmps = array();
         $moved_files = array();
         try {
             //if (!$val->run()) throw new \FuelException($val->show_errors());
             $file_tmps = \Site_FileTmp::get_file_tmps_uploaded($this->u->id, true);
             //\Site_FileTmp::check_uploaded_under_accepted_filesize($file_tmps, $this->u->filesize_total, \Site_Upload::get_accepted_filesize());
             \DB::start_transaction();
             list($moved_files, $site_image_ids) = \Site_FileTmp::save_images($file_tmps, $this->u->id, 'admin_user_id', 'site_image');
             \DB::commit_transaction();
             // thumbnail 作成 & tmp_file thumbnail 削除
             \Site_FileTmp::make_and_remove_thumbnails($moved_files);
             $message = sprintf('%sをアップロードしました。', term('site.image'));
             \Session::set_flash('message', $message);
             \Response::redirect('admin/content/image');
         } catch (\FuelException $e) {
             if (\DB::in_transaction()) {
                 \DB::rollback_transaction();
             }
             if ($moved_files) {
                 \Site_FileTmp::move_files_to_tmp_dir($moved_files);
             }
             $files = \Site_FileTmp::get_file_objects($file_tmps, $this->u->id);
             \Session::set_flash('error', $e->getMessage());
         }
     }
     $this->template->post_header = \View::forge('filetmp/_parts/upload_header');
     $this->template->post_footer = \View::forge('_parts/form/upload_footer');
     $this->set_title_and_breadcrumbs(term('site.image', 'form.upload'), array('admin/content' => term('site.content', 'site.management'), 'admin/content/image' => term('site.image', 'site.management')));
     $this->template->content = \View::forge('_parts/form/upload', array('files' => $files));
 }
Example #2
0
 /**
  * Album create
  * 
  * @access  public
  * @return  Response
  */
 public function action_create()
 {
     $album = Model_Album::forge();
     $val = \Validation::forge();
     $val->add_model($album);
     $files = array();
     if (\Input::method() == 'POST') {
         \Util_security::check_csrf();
         $file_tmps = array();
         $moved_files = array();
         try {
             $file_tmps = \Site_FileTmp::get_file_tmps_uploaded($this->u->id, true);
             \Site_FileTmp::check_uploaded_under_accepted_filesize($file_tmps, $this->u->filesize_total, \Site_Upload::get_accepted_filesize());
             if (!$val->run()) {
                 throw new \FuelException($val->show_errors());
             }
             $post = $val->validated();
             \DB::start_transaction();
             list($album, $moved_files) = Model_Album::save_with_relations($post, $this->u->id, $album, $file_tmps);
             \DB::commit_transaction();
             // thumbnail 作成 & tmp_file thumbnail 削除
             \Site_FileTmp::make_and_remove_thumbnails($moved_files);
             $message = sprintf('%sを作成しました。', term('album'));
             \Session::set_flash('message', $message);
             $redirect_uri = 'album/detail/' . $album->id;
             if (FBD_FACEBOOK_APP_ID && conf('service.facebook.shareDialog.album.isEnabled') && conf('service.facebook.shareDialog.album.autoPopupAfterCreated')) {
                 $redirect_uri .= '?created=1';
             }
             \Response::redirect($redirect_uri);
         } catch (\FuelException $e) {
             if (\DB::in_transaction()) {
                 \DB::rollback_transaction();
             }
             if ($moved_files) {
                 \Site_FileTmp::move_files_to_tmp_dir($moved_files);
             }
             $files = \Site_FileTmp::get_file_objects($file_tmps, $this->u->id);
             \Session::set_flash('error', $e->getMessage());
         }
     }
     $this->set_title_and_breadcrumbs(sprintf('%sを%s', term('album'), term('form.do_create')), null, $this->u, 'album');
     $this->template->post_header = \View::forge('filetmp/_parts/upload_header');
     $this->template->post_footer = \View::forge('_parts/create_footer');
     $this->template->content = \View::forge('_parts/form', array('val' => $val, 'files' => $files));
 }