/** * Note create * * @access public * @return Response */ public function action_create() { $note = Model_Note::forge(); $val = self::get_validation_object($note); $files = array(); if (\Input::method() == 'POST') { \Util_security::check_csrf(); $file_tmps = array(); $moved_files = array(); try { $file_tmps = \Site_FileTmp::get_file_tmps_and_check_filesize($this->u->id, $this->u->filesize_total); if (!$val->run()) { throw new \FuelException($val->show_errors()); } $post = $val->validated(); \DB::start_transaction(); list($is_changed, $is_published, $moved_files) = $note->save_with_relations($this->u->id, $post, $file_tmps); \DB::commit_transaction(); // thumbnail 作成 & tmp_file thumbnail 削除 \Site_FileTmp::make_and_remove_thumbnails($moved_files, 'note'); $message = sprintf('%sを%sしました。', term('note'), $is_published ? term('form.create_simple') : term('form.draft')); \Session::set_flash('message', $message); $redirect_uri = 'note/detail/' . $note->id; if ($is_published && FBD_FACEBOOK_APP_ID && conf('service.facebook.shareDialog.note.isEnabled') && conf('service.facebook.shareDialog.note.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(term('note') . 'を書く', null, $this->u, 'note'); $this->template->post_header = \View::forge('_parts/form_header'); $this->template->post_footer = \View::forge('_parts/form_footer'); $this->template->content = \View::forge('_parts/form', array('val' => $val, 'files' => $files)); }