예제 #1
0
파일: note.php 프로젝트: uzura8/flockbird
 /**
  * Note edit
  * 
  * @access  public
  * @params  integer
  * @return  Response
  */
 public function action_edit($id = null)
 {
     $note = Model_Note::check_authority($id, $this->u->id);
     $val = self::get_validation_object($note, true);
     $album_images = array();
     if (is_enabled('album')) {
         $album_id = \Album\Model_Album::get_id_for_foreign_table($this->u->id, 'note');
         $album_images = Model_NoteAlbumImage::get_album_image4note_id($note->id);
     }
     $files = is_enabled('album') ? \Site_Upload::get_file_objects($album_images, $album_id, false, $this->u->id) : array();
     $file_tmps = array();
     if (\Input::method() == 'POST') {
         \Util_security::check_csrf();
         $moved_files = array();
         try {
             if (is_enabled('album')) {
                 $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, $album_images, $files);
             \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.publish') : term('form.edit'));
             \Session::set_flash('message', $message);
             \Response::redirect('note/detail/' . $note->id);
         } catch (\FuelException $e) {
             if (\DB::in_transaction()) {
                 \DB::rollback_transaction();
             }
             if ($moved_files) {
                 \Site_FileTmp::move_files_to_tmp_dir($moved_files);
             }
             $file_tmps = \Site_FileTmp::get_file_objects($file_tmps, $this->u->id);
             \Session::set_flash('error', $e->getMessage());
         }
     }
     $files = array_merge($files, $file_tmps);
     $this->set_title_and_breadcrumbs(sprintf('%sを%s', term('note'), term('form.do_edit')), array('/note/' . $id => $note->title), $note->member, '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, 'note' => $note, 'is_edit' => true, 'files' => $files));
 }
예제 #2
0
파일: image.php 프로젝트: uzura8/flockbird
 /**
  * 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));
 }
예제 #3
0
파일: album.php 프로젝트: uzura8/flockbird
 /**
  * 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));
 }
예제 #4
0
파일: news.php 프로젝트: uzura8/flockbird
 /**
  * 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));
 }
예제 #5
0
파일: thread.php 프로젝트: uzura8/flockbird
 /**
  * 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));
 }