/** * 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)); }
public static function save_with_relations($values, $member_id, Model_Album $album = null, $file_tmps = array()) { if (!$album) { $album = self::forge(); } $is_new = $album->is_new(); $album->name = $values['name']; $album->body = $values['body']; $album->public_flag = $values['public_flag']; $album->member_id = $member_id; $is_changed = $album->is_changed(); $is_changed_public_flag = !$is_new && $album->is_changed('public_flag'); $album->save(); $moved_files = array(); $album_image_ids = array(); if ($file_tmps) { list($moved_files, $album_image_ids) = \Site_FileTmp::save_images($file_tmps, $album->id, 'album_id', 'album_image', $values['public_flag']); } if (\Module::loaded('timeline')) { \Timeline\Site_Model::save_timeline($member_id, $values['public_flag'], 'album', $album->id, $album->updated_at, null, null, $album_image_ids); } if ($is_changed_public_flag && \Module::loaded('timeline')) { // timeline の public_flag の更新 \Timeline\Model_Timeline::update_public_flag4foreign_table_and_foreign_id($values['public_flag'], 'album', $album->id, \Config::get('timeline.types.album')); } if (!empty($values['is_update_children_public_flag'])) { // update album_image public_flag Model_AlbumImage::update_public_flag4album_id($album->id, $values['public_flag']); } return array($album, $moved_files, $is_changed); }
public function save_with_relations($member_id, $values, $file_tmps = null, $album_images = array(), $files = array()) { if (!empty($this->member_id) && $this->member_id != $member_id) { throw new \InvalidArgumentException('Parameter member_id is invalid.'); } $is_new = $this->_is_new; $this->member_id = $member_id; if (isset($values['title'])) { $this->title = $values['title']; } if (isset($values['body'])) { $this->body = $values['body']; } if (isset($values['public_flag'])) { $this->public_flag = $values['public_flag']; } $is_changed_public_flag = $this->is_changed('public_flag'); if (!$this->is_published) { if (!empty($values['is_published'])) { $this->is_published = 1; } elseif (empty($values['is_draft'])) { $this->is_published = 1; } } $is_published = $this->is_changed('is_published') && $this->is_published; if (!empty($values['published_at_time'])) { if (!\Util_Date::check_is_same_minute($values['published_at_time'], $this->published_at)) { $this->published_at = $values['published_at_time'] . ':00'; } } elseif (!$this->published_at && $is_published) { $this->published_at = \Date::time()->format('mysql'); } $is_changed = $this->is_changed(); if ($is_changed) { $this->save(); } $moved_files = array(); if (is_enabled('album')) { $image_public_flag = $this->is_published ? $this->public_flag : FBD_PUBLIC_FLAG_PRIVATE; if ($file_tmps) { $album_id = \Album\Model_Album::get_id_for_foreign_table($member_id, 'note'); list($moved_files, $album_image_ids) = \Site_FileTmp::save_images($file_tmps, $album_id, 'album_id', 'album_image', $image_public_flag); \Note\Model_NoteAlbumImage::save_multiple($this->id, $album_image_ids); } // フォーム編集時 if ($album_images && $files) { \Site_Upload::update_image_objs4file_objects($album_images, $files, $image_public_flag); } elseif ($is_published && ($saved_album_images = Model_NoteAlbumImage::get_album_image4note_id($this->id))) { foreach ($saved_album_images as $saved_album_image) { $saved_album_image->update_public_flag($this->public_flag, true); } } } if (is_enabled('timeline')) { if ($is_published) { // timeline 投稿 \Timeline\Site_Model::save_timeline($member_id, $this->public_flag, 'note', $this->id, $this->updated_at); } elseif (!$is_new && $is_changed_public_flag) { // timeline の public_flag の更新 \Timeline\Model_Timeline::update_public_flag4foreign_table_and_foreign_id($this->public_flag, 'note', $this->id, \Config::get('timeline.types.note')); } } return array($is_changed, $is_published, $moved_files); }
/** * Create timeline * * @access public * @param int $parent_id target parent id * @return Response(json) * @throws Exception in Controller_Base::controller_common_api * @see Controller_Base::controller_common_api */ public function post_create() { $this->controller_common_api(function () { $this->response_body['errors']['message_default'] = term('timeline') . 'の' . term('form.post') . 'に失敗しました。'; $moved_files = array(); $album_image_ids = array(); $timeline = Model_Timeline::forge(); $val = \Validation::forge(); $val->add_model($timeline); if (!$val->run()) { throw new \ValidationFailedException($val->show_errors()); } $post = $val->validated(); $file_tmps = \Site_FileTmp::get_file_tmps_and_check_filesize($this->u->id, $this->u->filesize_total); if (!strlen($post['body']) && !$file_tmps) { throw new \ValidationFailedException('Data is empty.'); } $type_key = 'normal'; $album_id = (int) \Input::post('album_id', 0); if ($file_tmps && $album_id) { $album = \Album\Model_Album::check_authority($album_id, $this->u->id); if (\Album\Site_Util::check_album_disabled_to_update($album->foreign_table, true)) { throw new \ValidationFailedException('Album id is invalid.'); } $type_key = 'album_image'; } try { \DB::start_transaction(); if ($file_tmps) { if (!$album_id) { $type_key = 'album_image_timeline'; $album_id = \Album\Model_Album::get_id_for_foreign_table($this->u->id, 'timeline'); } list($moved_files, $album_image_ids) = \Site_FileTmp::save_images($file_tmps, $album_id, 'album_id', 'album_image', $post['public_flag']); } else { $album_id = null; } $timeline = \Timeline\Site_Model::save_timeline($this->u->id, $post['public_flag'], $type_key, $album_id, null, $post['body'], $timeline, $album_image_ids); \DB::commit_transaction(); // thumbnail 作成 & tmp_file thumbnail 削除 \Site_FileTmp::make_and_remove_thumbnails($moved_files); } catch (\Exception $e) { if (\DB::in_transaction()) { \DB::rollback_transaction(); } if ($moved_files) { \Site_FileTmp::move_files_to_tmp_dir($moved_files); } throw $e; } $data = array('id' => $timeline->id, 'message' => term('timeline') . 'を' . term('form.post') . 'しました。'); if (conf('service.facebook.shareDialog.myhome.autoPopupAfterCreated')) { $link = \Uri::create(Site_Util::get_detail_uri($timeline->id, $timeline->type)); $data['shareFacebook'] = array('obj' => array('link' => $link)); if ($album_image_ids && ($album_image = \Album\Model_AlbumImage::find($album_image_ids[0]))) { $data['shareFacebook']['obj']['picture'] = \Site_Util::get_media_uri(img_uri($album_image->file_name, 'thumbnail'), true); } } $this->set_response_body_api($data); }); }
/** * News edit * * @access public * @params integer * @return Response */ public function action_edit($id = null) { $news = \News\Model_News::check_authority($id); $val = self::get_validation_object($news); $news_images = array(); $news_files = array(); $images = array(); $files = array(); $is_enabled_image = conf('image.isEnabled', 'news'); $is_insert_body_image = conf('image.isInsertBody', 'news'); $is_modal_upload_image = conf('image.isModalUpload', 'news'); if ($is_enabled_image && !$is_modal_upload_image) { $news_images = \News\Model_NewsImage::get4news_id($news->id); $images = \Site_Upload::get_file_objects($news_images, $news->id, true, null, 'img', $is_insert_body_image); } if ($is_enabled_file = \Config::get('news.file.isEnabled')) { $news_files = \News\Model_NewsFile::get4news_id($news->id); $files = \Site_Upload::get_file_objects($news_files, $news->id, true, null, 'file'); } $posted_links = array(); $saved_links = array(); if ($is_enabled_link = \Config::get('news.link.isEnabled')) { $saved_links = $this->get_saved_links($news->id); } $tags = \Config::get('news.tags.isEnabled') ? \News\Model_NewsTag::get_names4news_id($news->id) : array(); $image_tmps = array(); $file_tmps = array(); if (\Input::method() == 'POST') { \Util_security::check_csrf(); if ($is_enabled_link) { $posted_links = $this->get_posted_links(); $val = $this->add_validation_object_posted_links($val, $saved_links, true); $val = $this->add_validation_object_posted_links($val, $posted_links); } $moved_images = array(); $moved_files = array(); $news_image_ids = array(); $news_file_ids = array(); $error_message = ''; try { if ($is_enabled_image) { $image_tmps = \Site_FileTmp::get_file_tmps_and_check_filesize(); } if ($is_enabled_file) { $file_tmps = \Site_FileTmp::get_file_tmps_and_check_filesize(null, null, 'file'); } // 識別名の変更がない場合は unique を確認しない if (trim(\Input::post('slug')) == $news->slug) { $val->fieldset()->field('slug')->delete_rule('unique'); } if (!$val->run()) { throw new \FuelException($val->show_errors()); } $post = $val->validated(); if ($post['format'] == 2) { $post['body'] = preg_replace('/^\\>/um', '>', $post['body']); } $news->set_values($post); $message = sprintf('%sを%sしました。', term('news.view'), term('form.edit')); if ($is_published = !$news->is_published && empty($post['is_draft'])) { $news->is_published = 1; $message = sprintf('%sを%sしました。', term('news.view'), term('form.publish')); } if ($post['published_at_time'] && !\Util_Date::check_is_same_minute($post['published_at_time'], $news->published_at)) { $news->published_at = $post['published_at_time'] . ':00'; } elseif ($is_published) { $news->published_at = date('Y-m-d H:i:s'); } \DB::start_transaction(); $news->save(); if ($is_enabled_image) { list($moved_images, $news_image_ids) = \Site_FileTmp::save_images($image_tmps, $news->id, 'news_id', 'news_image'); \Site_Upload::update_image_objs4file_objects($news_images, $images); } if ($is_enabled_file) { list($moved_files, $news_file_ids) = \Site_FileTmp::save_images($file_tmps, $news->id, 'news_id', 'news_file', null, 'file'); \Site_Upload::update_image_objs4file_objects($news_files, $files); } if ($is_enabled_link) { $this->save_posted_links($saved_links, $news->id, true); $this->save_posted_links($posted_links, $news->id); } if (\Config::get('news.tags.isEnabled')) { \News\Model_NewsTag::save_tags($post['tags'], $news->id); } //// timeline 投稿 //if (is_enabled('timeline')) //{ // if ($is_published) // { // \Timeline\Site_Model::save_timeline($this->u->id, $note->public_flag, 'note', $note->id); // } // elseif ($is_update_public_flag) // { // // timeline の public_flag の更新 // \Timeline\Model_Timeline::update_public_flag4foreign_table_and_foreign_id($note->public_flag, 'note', $note->id, \Config::get('timeline.types.note')); // } //} \DB::commit_transaction(); // thumbnail 作成 & tmp_file thumbnail 削除 \Site_FileTmp::make_and_remove_thumbnails($moved_images); \Session::set_flash('message', $message); \Response::redirect('admin/news/detail/' . $news->id); } catch (\Database_Exception $e) { $error_message = \Site_Controller::get_error_message($e, true); } catch (\FuelException $e) { $error_message = $e->getMessage(); } if ($error_message) { if (\DB::in_transaction()) { \DB::rollback_transaction(); } if ($moved_images) { \Site_FileTmp::move_files_to_tmp_dir($moved_images); } if ($moved_files) { \Site_FileTmp::move_files_to_tmp_dir($moved_files); } $image_tmps = \Site_FileTmp::get_file_objects($image_tmps, $this->u->id, true, 'img'); $file_tmps = \Site_FileTmp::get_file_objects($file_tmps, $this->u->id, true, 'file'); \Session::set_flash('error', $error_message); } } $images = array_merge($images, $image_tmps); $files = array_merge($files, $file_tmps); $this->set_title_and_breadcrumbs(term('form.edit'), array('admin/news' => term('news.view', 'admin.view'), 'admin/news/' . $news->id => $news->title)); $this->template->post_header = \View::forge('news/_parts/form_header'); $this->template->post_footer = \View::forge('news/_parts/form_footer', array('news' => $news)); $this->template->content = \View::forge('news/_parts/form', array('val' => $val, 'saved_links' => $saved_links, 'posted_links' => $posted_links, 'news' => $news, 'is_edit' => true, 'images' => $images, 'files' => $files, 'tags' => $tags)); }
/** * Album upload * @access public * @params integer * @return Response */ public function action_upload($id = null) { $id = (int) $id; $album = Model_Album::check_authority($id, $this->u->id, 'member'); if (Site_Util::check_album_disabled_to_update($album->foreign_table, true)) { throw new \HttpForbiddenException(); } $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, $album_image_ids) = \Site_FileTmp::save_images($file_tmps, $album->id, 'album_id', 'album_image', $album->public_flag); if (\Module::loaded('timeline')) { \Timeline\Site_Model::save_timeline($this->u->id, $album->public_flag, 'album_image', $album->id, null, null, null, $album_image_ids); } \DB::commit_transaction(); // thumbnail 作成 & tmp_file thumbnail 削除 \Site_FileTmp::make_and_remove_thumbnails($moved_files); $message = sprintf('%sをアップロードしました。', term('album_image')); \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.autoPopupAfterUploaded')) { $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->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('album_image', 'form.upload'), array('/album/' . $id => $album->name), $album->member, 'album'); $this->template->content = \View::forge('_parts/form/upload', array('id' => $id, 'album' => $album, 'files' => $files)); }
/** * Thread edit * * @access public * @params integer * @return Response */ public function action_edit($id = null) { $thread = Model_Thread::check_authority($id, $this->u->id); $val = self::get_validation_object($thread, true); $thread_images = \Thread\Model_ThreadImage::get4thread_id($thread->id); $images = \Site_Upload::get_file_objects($thread_images, $thread->id); $image_tmps = array(); if (\Input::method() == 'POST') { \Util_security::check_csrf(); $moved_images = array(); $news_image_ids = array(); $error_message = ''; try { $image_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(); $thread->save_with_relations($this->u->id, $post); list($moved_images, $thread_image_ids) = \Site_FileTmp::save_images($image_tmps, $thread->id, 'thread_id', 'thread_image'); \Site_Upload::update_image_objs4file_objects($thread_images, $images); \DB::commit_transaction(); // thumbnail 作成 & tmp_file thumbnail 削除 \Site_FileTmp::make_and_remove_thumbnails($moved_images); $message = sprintf('%sを%sしました。', term('thread'), term('form.edit')); \Session::set_flash('message', $message); \Response::redirect('thread/detail/' . $thread->id); } catch (\Database_Exception $e) { $error_message = \Site_Controller::get_error_message($e, true); } catch (\FuelException $e) { $error_message = $e->getMessage(); } if ($error_message) { if (\DB::in_transaction()) { \DB::rollback_transaction(); } if ($moved_images) { \Site_FileTmp::move_files_to_tmp_dir($moved_images); } $image_tmps = \Site_FileTmp::get_file_objects($image_tmps, $this->u->id); \Session::set_flash('error', $error_message); } } $images = array_merge($images, $image_tmps); $this->set_title_and_breadcrumbs(sprintf('%sを%s', term('thread'), term('form.do_edit')), array('/thread/' . $id => $thread->title), null, 'thread'); $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, 'thread' => $thread, 'is_edit' => true, 'images' => $images)); }