public static function save_profile_image(Model_Member $member, $file_path = null) { if (conf('upload.types.img.types.m.save_as_album_image')) { $album_id = \Album\Model_Album::get_id_for_foreign_table($member->id, 'member'); list($album_image, $file) = \Album\Model_AlbumImage::save_with_relations($album_id, $member, conf('public_flag.maxRange'), $file_path, 'album_image_profile'); $member->file_name = $album_image->file_name; $member->save(); } else { if ($member->file_name) { Model_File::delete_with_timeline($member->file_name); } $options = Site_Upload::get_uploader_options($member->id); $uploadhandler = new Site_Uploader($options); $file = $uploadhandler->save($file_path); if (!empty($file->error)) { throw new FuelException($file->error); } $member->file_name = $file->name; $member->save(); // timeline 投稿 if (is_enabled('timeline')) { \Timeline\Site_Model::save_timeline($member->id, conf('public_flag.maxRange'), 'profile_image', $file->id, $member->updated_at); } } return $file; }
public static function move_from_file_tmp(Model_FileTmp $file_tmp, $new_filename_prefix = '', $upload_type = 'img') { $file = static::forge(); $file->name = $file_tmp->name; if ($new_filename_prefix) { $file->name = Site_Upload::change_filename_prefix($file_tmp->name, $new_filename_prefix); } $file->filesize = $file_tmp->filesize; $file->original_filename = $file_tmp->original_filename; $file->type = $file_tmp->type; $file->member_id = $file_tmp->member_id; $file->user_type = $file_tmp->user_type; if (!is_null($file_tmp->exif)) { $file->exif = $file_tmp->exif; } if (!empty($file_tmp->shot_at)) { $file->shot_at = $file_tmp->shot_at; } $file->save(); if (conf('upload.storageType') == 'db') { $file_bin = Model_FileBin::get4name($file_tmp->name); $file_bin->name = $file->name; $file_bin->save(); } elseif (conf('upload.storageType') == 'S3') { Site_S3::move($file_tmp->name, $file->name, $upload_type); } $file_tmp->delete(); return $file; }
/** * Upload images * * @access public * @return Response (json|html) * @throws Exception in Controller_Base::controller_common_api * @see Controller_Base::controller_common_api */ public function post_upload($parent_id = null) { $this->api_accept_formats = array('html', 'json'); $this->api_not_check_csrf = true; $this->controller_common_api(function () use($parent_id) { $upload_type = 'img'; $news = \News\Model_News::check_authority($parent_id); if (!in_array($this->format, array('html', 'json'))) { throw new HttpNotFoundException(); } $thumbnail_size = \Input::post('thumbnail_size'); if (!\Validation::_validation_in_array($thumbnail_size, array('M', 'S'))) { throw new \HttpInvalidInputException('Invalid input data'); } $insert_target = \Input::post('insert_target'); $is_insert_body_image = conf('image.isInsertBody', 'news'); $options = \Site_Upload::get_upload_handler_options($this->u->id, true, false, 'nw', $parent_id, true, 'img', $is_insert_body_image); $uploadhandler = new \MyUploadHandler($options, false); \DB::start_transaction(); $files = $uploadhandler->post(false); $files['files'] = \News\Model_NewsImage::save_images($parent_id, $files['files']); \DB::commit_transaction(); $files['upload_type'] = $upload_type; $files['thumbnail_size'] = $thumbnail_size; $files['insert_target'] = $insert_target; $files['model'] = 'news'; $this->set_response_body_api($files, $this->format == 'html' ? 'filetmp/_parts/upload_images' : null); }); }
public static function save($file_path, $file_name = null, $upload_type = 'img', $is_private_acl = false) { if (!file_exists($file_path)) { throw new FuelException('File not exists.'); } static::set_s3_instanse(); return self::$s3_instantse->putObject(array('Bucket' => FBD_AWS_S3_BUCKET, 'Key' => static::get_key($file_name ?: \Site_Upload::get_file_name_from_file_path($file_path), $upload_type), 'Body' => EntityBody::factory(fopen($file_path, 'r')), 'ACL' => $is_private_acl ? CannedAcl::PRIVATE_ACCESS : CannedAcl::PUBLIC_READ)); }
public static function save_from_file_path($file_path, $save_name = '', $is_image = true) { if (!($bin = Util_file::get_encoded_bin_data($file_path, $is_image))) { throw new FuelException('Binary data is invalid.'); } $obj = self::forge(); $filepath = Util_File::get_filepath_from_path($file_path); if (!$save_name) { $save_name = Site_Upload::convert_filepath2filename($filepath); } $obj->name = $save_name; $obj->bin = $bin; return $obj->save(); }
public function before_insert(\Orm\Model $obj) { if ($obj->user_type) { return false; } if (!$obj->{$this->_key_from}) { return false; } $member = \Model_Member::find('first', array('where' => array($this->_key_to => $obj->{$this->_key_from}))); $member->filesize_total += $obj->{$this->_property_from}; // check filesize_total if ($member->filesize_total > \Site_Upload::get_accepted_filesize($obj->{$this->_key_from})) { throw new LimitUploadFileSizeException('File size is over the limit of the member.'); } $member->save(); }
public static function save_images($news_id, $files) { $file_cate = static::$image_prefix; $new_filepath_prefix = \Site_Upload::get_filepath_prefix($file_cate, $news_id); $new_filename_prefix = \Site_Upload::convert_filepath2filename($new_filepath_prefix); $returns = array(); foreach ($files as $file) { $obj = self::forge(); $obj->news_id = $news_id; $obj->file_name = $new_filename_prefix . $file->name; //$obj->name = $file->description; $obj->shot_at = !empty($file->shot_at) ? $file->shot_at : date('Y-m-d H:i:s'); $obj->save(); $file->id = $obj->id; $returns[] = $file; } return $returns; }
public function test_check_real_file_info() { $raw_file_dir_path = conf('upload.types.img.raw_file_path'); if (!file_exists($raw_file_dir_path) || !($file_paths = Util_file::get_file_recursive($raw_file_dir_path))) { \Util_Develop::output_test_info(__FILE__, __LINE__); $this->markTestSkipped('No data.'); } foreach ($file_paths as $file_path) { $file_info = File::file_info($file_path); $file_name = \Site_Upload::get_filename_from_file_path($file_path); $file = Model_File::get4name($file_name); // file に対応する Model_File が存在する $this->assertNotEmpty($file); // path の確認 $this->assertEquals(trim(\Site_Upload::get_filepath_prefix_from_filename($file_name), '/'), Util_file::get_path_partial($file_info['dirname'], 2)); // type の確認 $this->assertEquals($file->type, $file_info['mimetype']); // size の確認 $this->assertEquals($file->filesize, $file_info['size']); } }
private static function add_file_options($files, $type) { if (!$files) { return array(); } if (!in_array($type, array('img', 'file'))) { throw new \InvalidArgumentException('Second parameter is invalid.'); } $confs = conf('upload.types.' . $type); foreach ($files as $key => $file) { $upload_uri = \Site_Upload::get_uploaded_file_path($file['file_name'], 'raw', $type, false, true); $files[$key]['file_url_raw'] = \Uri::create($upload_uri); if ($type == 'img') { $upload_uri = \Site_Upload::get_uploaded_file_path($file['file_name'], 'thumbnail', $type, false, true); $files[$key]['file_url_thumbnail'] = \Uri::create($upload_uri); } if ($type == 'file') { $files[$key]['file_type_view'] = self::get_file_type_view($file['file_type']); } } return $files; }
public static function save_with_relations($album_id, \Model_Member $member = null, $public_flag = null, $file_path = null, $timeline_type_key = 'album_image', $optional_values = array()) { if (!\Util_Array::array_in_array(array_keys($optional_values), array('name', 'shot_at', 'shot_at_time', 'public_flag'))) { throw new \InvalidArgumentException('Parameter optional_values is invalid.'); } if (is_null($public_flag)) { $public_flag = isset($optional_values['public_flag']) ? $optional_values['public_flag'] : conf('public_flag.default'); } $album = null; if (empty($member)) { $album = Model_Album::find($album_id, array('related' => 'member')); $member = $album->member; } $options = \Site_Upload::get_uploader_options($member->id, 'ai', $album_id); $uploadhandler = new \Site_Uploader($options); $file = $uploadhandler->save($file_path); if (!empty($file->error)) { throw new \FuelException($file->error); } $self = new self(); $self->album_id = $album_id; $self->file_name = $file->name; $self->public_flag = $public_flag; $self->shot_at = self::get_shot_at_for_insert($file->shot_at, isset($optional_values['shot_at_time']) ? $optional_values['shot_at_time'] : null, isset($optional_values['shot_at']) ? $optional_values['shot_at'] : null); $self->save(); // カバー写真の更新 if ($timeline_type_key == 'album_image_profile') { if (!$album) { $album = Model_Album::find($album_id); } $album->cover_album_image_id = $self->id; $album->save(); } // timeline 投稿 if (\Module::loaded('timeline')) { switch ($timeline_type_key) { case 'album_image_profile': $timeline_foreign_id = $self->id; $timeline_child_foreign_ids = array(); break; case 'album': case 'album_image': default: $timeline_foreign_id = $self->album->id; $timeline_child_foreign_ids = array($self->id); break; } \Timeline\Site_Model::save_timeline($member->id, $public_flag, $timeline_type_key, $timeline_foreign_id, $self->updated_at, null, null, $timeline_child_foreign_ids); } return array($self, $file); }
public static function get_file_objects($file_tmps, $member_id, $is_admin = false, $type = 'img') { $options = Site_Upload::get_upload_handler_options($member_id, $is_admin, true, null, 0, true, $type); $uploadhandler = new MyUploadHandler($options, false); return $uploadhandler->get_file_objects_from_file_tmps($file_tmps, $type); }
/** * 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)); }
function img($filename = '', $size_key = '', $link_uri = '', $is_link2raw_file = false, $alt = '', $is_profile = false, $is_responsive = false, $anchor_attr = array(), $img_attr = array()) { list($uri_path, $filename, $file_cate, $size) = img_uri($filename, $size_key, $is_profile, true); if (!isset($img_attr['class'])) { $img_attr['class'] = ''; } if ($is_responsive) { if (!empty($img_attr['class'])) { $img_attr['class'] .= ' '; } $img_attr['class'] .= 'img-responsive'; } if ($is_profile) { if (!empty($img_attr['class'])) { $img_attr['class'] .= ' '; } $img_attr['class'] .= 'profile_image'; } if (empty($filename)) { $noimage_tag = Site_Util::get_noimage_tag($size, $file_cate, $img_attr); if ($link_uri) { return Html::anchor($link_uri, $noimage_tag, $anchor_attr); } return $noimage_tag; } if ($alt) { $img_attr['alt'] = $alt; } $image_tag = Html::img($uri_path, $img_attr); if ($link_uri) { return Html::anchor($link_uri, $image_tag, $anchor_attr); } if ($is_link2raw_file) { $anchor_attr['target'] = '_blank'; $uri_path = Site_Upload::get_uploaded_file_path($filename, 'raw', 'img', false, true); return Html::anchor(Site_Util::get_media_uri($uri_path), $image_tag, $anchor_attr); } return $image_tag; }
private function make_image($original_file_path, $target_file_dir, $target_filename) { $target_file_path = $target_file_dir . $target_filename; Site_Upload::check_and_make_uploaded_dir($target_file_dir); Util_file::resize($original_file_path, $target_file_path, $this->width, $this->height, $this->resize_type); }
protected function common_FileTmp_delete_upload($upload_type = 'img') { $this->controller_common_api(function () use($upload_type) { $id = (int) Input::post('id'); $file_tmp = Model_FileTmp::check_authority($id, $this->u->id, null, 'member_id', IS_ADMIN ? 1 : 0); $options = Site_Upload::get_upload_handler_options($this->u->id, IS_ADMIN, true, null, 0, true, $upload_type); $uploadhandler = new MyUploadHandler($options, false); \DB::start_transaction(); $this->response_body = $uploadhandler->delete(false, $file_tmp); \DB::commit_transaction(); return $this->response_body; }); }
$data['after_uri'] = 'admin/content/image/' . $after_id; } echo render('_parts/image/detail', $data); ?> <?php $sizes = conf('upload.types.img.types.si.sizes'); ?> <ul class="media-list mt20"> <?php foreach ($sizes as $key => $size) { ?> <li class="media"> <?php echo img($site_image->file_name, $key, '#', false, $site_image->name ?: '', false, false, array('class' => 'pull-left'), array('class' => 'media-object')); ?> <div class="media-body"> <h4 class="media-heading"><?php echo $size; ?> </h4> <?php echo Site_Util::get_media_uri(Site_Upload::get_uploaded_file_path($site_image->file_name, $size, 'img', false, true), true); ?> </div> </li> <?php } ?> </ul>
/** * 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)); }
public static function get_image_uri4file_name($file_name, $size = 'L', $additional_table = '') { if (!$file_name) { return ''; } if (strlen($file_name) < 4) { return ''; } $file_cate = Site_Upload::get_file_cate_from_filename($file_name); $file_size = img_size($file_cate, $size, $additional_table); return Site_Upload::get_uploaded_file_path($file_name, $file_size, 'img', false, true); }
/** * 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)); }
protected static function check_album_imgage4top_page_slide(Model_AlbumImage $album_image, $limit_width = null) { if (!empty($album_image->album->foreign_table) && $album_image->album->foreign_table == 'member') { return false; } if ($limit_width) { if (!($file_path = \Site_Upload::get_file_path4file_name($album_image->file_name))) { return false; } $raw_size_obj = \Image::sizes($file_path); if ($raw_size_obj->width < $limit_width) { return false; } } return true; }
protected function is_valid_file_object($filename_excluded_prefix) { $file_path = $this->get_upload_path($filename_excluded_prefix); if (is_file($file_path) && $filename_excluded_prefix[0] !== '.') { return true; } if ($this->options['storage_type'] != 'normal' && !file_exists($file_path)) { $file_name = $this->options['filename_prefix'] . $filename_excluded_prefix; if (Site_Upload::make_raw_file_from_storage($file_name, $file_path, $this->options['storage_type'], $this->options['upload_type'])) { return true; } } return false; }
public function test_delete() { if (!self::$album_image) { self::$album_image = $this->get_album_image(array('public_flag' => FBD_PUBLIC_FLAG_MEMBER)); } $album_image_id = self::$album_image->id; $file_name = self::$album_image->file_name; $file = \Model_File::get4name($file_name); $file_size = $file->filesize; $file_path = \Site_Upload::get_uploaded_file_path(self::$album_image->file_name); $member_filesize_before = self::get_member_filesize_total(self::$member_id); // set cover_album_image_id self::$album->cover_album_image_id = $album_image_id; // timeline view cache 作成 if (self::$is_check_timeline_view_cache) { $timeline_view_cache_before = \Timeline\Site_Util::make_view_cache4foreign_table_and_foreign_id('album', $album->id, \Config::get('timeline.types.album_image')); } // file if (conf('upload.storageType') == 'db') { $this->assertNotNull(\Model_FileBin::get4name(self::$album_image->file_name)); } elseif (conf('upload.storageType') == 'normal') { $this->assertTrue(file_exists($file_path)); } // album_image delete. self::$album_image->delete(); // 件数 $this->assertEquals(self::$total_count - 1, Model_AlbumImage::get_count()); // file $this->assertEmpty(\Model_File::get4name($file_name)); $this->assertFalse(file_exists($file_path)); // meber_filesize $this->assertEquals($member_filesize_before - $file_size, self::get_member_filesize_total(self::$member_id)); // check cover_album_image_id $this->assertEmpty(self::$album->cover_album_image_id); // timeline if (is_enabled('timeline')) { $timeline_child_datas = \Timeline\Model_TimelineChildData::get4foreign_table_and_foreign_ids('album_image', $album_image_id); $this->assertEmpty($timeline_child_datas); // timeline view cache check if (self::$is_check_timeline_view_cache) { $this->assertEmpty(\Timeline\Site_Util::get_view_cache($timeline->id)); } } }
<?php if (empty($is_modal)) { echo render('_parts/comment/load_template'); } ?> <script> function getConfigSlide(key) { var config = { uploadUriBasePath: '<?php echo FBD_URI_PATH . Site_Upload::get_uploaded_file_path('', img_size('ai', 'L'), 'img', false, true); ?> ', slideLimit: <?php echo conf('display_setting.slide.limit', 'album'); ?> , sort: '<?php echo !empty($is_desc) ? 'desc' : 'asc'; ?> ' }; return config[key]; } </script> <?php echo Asset::js('site/modules/album/common/slide.js'); ?>
<?php if ($list) { $file_cate = !empty($file_cate) ? $file_cate : 'nw'; $file_uri_base = conf('upload.types.file.tmp.root_path.raw_dir'); if (!empty($title)) { ?> <h4><?php echo $title; ?> </h4> <?php } ?> <ul> <?php foreach ($list as $file) { $file_obj = \Model_File::get4name($file->file_name); $file_uri = Site_Upload::get_uploaded_file_path($file_obj->name, 'raw', 'file', false, true); ?> <li><?php echo anchor($file_uri, $file->name ?: $file_obj->original_filename); ?> </li> <?php } ?> </ul> <?php }
public static function check_file_type($file_path, $arrow_extentions = array(), $format = '', $upload_type = 'img') { if (empty($arrow_extentions)) { $arrow_extentions = Site_Upload::get_accept_format($upload_type); } if ($format) { if (!($extension = Site_Upload::check_file_format_is_accepted($format, $upload_type))) { return false; } } else { if (!($extension = self::check_extension($file_path, $arrow_extentions))) { return false; } } if ($upload_type == 'file') { return $extension; } $imginfo = getimagesize($file_path); $type = $imginfo[2]; switch ($type) { case IMAGETYPE_JPEG: if ($extension == 'jpg' || $extension == 'jpeg') { return 'jpg'; } break; case IMAGETYPE_GIF: if ($extension == 'gif') { return 'gif'; } break; case IMAGETYPE_PNG: if ($extension == 'png') { return 'png'; } break; } return false; }
<?php $img_max_sizes = Site_Upload::conv_size_str_to_array(conf('upload.types.img.accepted_max_size.default')); ?> <script> var GL = {}; GL.execute_flg = false; function get_uid() {return <?php echo !IS_ADMIN && Auth::check() ? $u->id : 0; ?> ;} function check_is_admin() {return <?php echo IS_ADMIN ? 'true' : 'false'; ?> ;} function getBasePath() {return '<?php echo Uri::base_path(); ?> ';} function getCurrentPath() {return '<?php echo Uri::string(); ?> ';} function getBaseUrl() { var is_current_protocol = (arguments.length > 0) ? arguments[0] : false; if (is_current_protocol) return '<?php echo Uri::base(true); ?> '; return '<?php echo Uri::base();
protected function save_profile_image($provider, $image_url, $member_obj) { $image_url = $this->get_profile_image_url($provider, $image_url); $save_file_path_tmp = sprintf('%stmp/%s_%s_%s', APPPATH, $member_obj->id, Util_string::get_unique_id(), time()); Site_Upload::save_image_from_url($image_url, $save_file_path_tmp, conf('upload.types.img.types.m.max_size', null, 0)); \DB::start_transaction(); Site_Member::save_profile_image($member_obj, $save_file_path_tmp, false); \DB::commit_transaction(); }
private static function execute_clean_file($file_type, $is_tmp = false) { if (!self::$absolute_execute && !\Site_Util::check_is_dev_env()) { throw new \FuelException('This task is not work at prod env.'); } $raw_file_dir_path = \Site_Upload::get_uploaded_path('raw', $file_type, $is_tmp); $cache_file_dir_path_key = 'upload.types.' . $file_type; if ($is_tmp) { $cache_file_dir_path_key .= '.tmp'; } $cache_file_dir_path_key .= '.root_path.cache_dir'; $cache_file_dir_path = DOCROOT . conf($cache_file_dir_path_key); if (!file_exists($raw_file_dir_path) && ($cache_file_dir_path && !file_exists($cache_file_dir_path))) { return "File directry '" . $raw_file_dir_path . "' not exists."; } $file_paths = \Util_file::get_file_recursive($raw_file_dir_path); if ($cache_file_dir_path) { $file_paths = array_merge($file_paths, \Util_file::get_file_recursive($cache_file_dir_path)); } if (!$file_paths) { return sprintf("No files at '%s'", $raw_file_dir_path); } $i = 0; foreach ($file_paths as $file_path) { if (self::check_file_exists_record($file_path, $is_tmp)) { continue; } \Util_file::remove($file_path); $i++; } $subject = $file_type; if ($is_tmp) { $subject .= '_tmp'; } return sprintf('%d %s removed.', $i, $subject); }
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); }
public static function save_image_from_url($image_url, $save_file_path, $max_size = 0, $old_file_path = null) { if (!($data = file_get_contents($image_url))) { throw new FuelException('Get image from url failed.'); } if (!file_put_contents($save_file_path, $data)) { throw new FuelException('Failed to save image.'); } unset($data); if ($max_size) { Site_Upload::check_max_size_and_resize($save_file_path, $max_size); } // if exists old_file_path, compare data. if data is same, delete new file and return false; if ($old_file_path) { $new_data = file_get_contents($save_file_path); $old_data = file_get_contents($old_file_path); if ($new_data == $old_data) { return false; } } unset($new_data, $old_data); return true; }