示例#1
0
 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;
 }
示例#2
0
 public function before_delete(\Orm\Model $obj)
 {
     // カバー写真の確認 & 削除
     if (!($album = \Album\Model_Album::find($obj->album_id))) {
         throw new \FuelException('Invalid album id.');
     }
     if ($album->cover_album_image_id == $obj->id) {
         $album->cover_album_image_id = null;
         $album->save();
     }
     // プロフィール写真の確認 & 削除
     if ($album->foreign_table == 'member') {
         if ($album->member->file_name == $obj->file_name) {
             $album->member->file_name = null;
             $album->member->save();
         }
         // timeline 投稿の削除
         if (is_enabled('timeline')) {
             \Timeline\Model_Timeline::delete4foreign_table_and_foreign_ids('album_image', $obj->id);
         }
     }
     if (is_enabled('timeline')) {
         // timeline_child_data の削除
         \Timeline\Model_TimelineChildData::delete4foreign_table_and_foreign_ids('album_image', $obj->id);
         // timeline view cache の削除
         if (is_enabled('note') && \Config::get('timeline.articles.cache.is_use') && $obj->album->foreign_table == 'note') {
             \Timeline\Site_Model::delete_note_view_cache4album_image_id($obj->id);
         }
     }
     // file 削除
     if ($file = \Model_File::get4name($obj->file_name)) {
         $file->delete();
     }
 }
示例#3
0
 /**
  * Mmeber_Profile_Image index
  * 
  * @access  public
  * @return  Response
  */
 public function action_index($member_id = null)
 {
     list($is_mypage, $member, $access_from) = $this->check_auth_and_is_mypage($member_id);
     $member_profiles = Model_MemberProfile::get4member_id($member->id, true);
     $title = term('profile', 'site.picture', $is_mypage ? 'site.setting' : '');
     $this->set_title_and_breadcrumbs($title, array('/member/' . $member_id => sprintf('%sさんの%s', $member->name, term('site.page.kana'))), $member);
     $images = array();
     if (is_enabled('album') && conf('upload.types.img.types.m.save_as_album_image')) {
         $album_id = \Album\Model_Album::get_id_for_foreign_table($member->id, 'member');
         $images = \Album\Model_AlbumImage::query()->related('album')->where('album_id', $album_id)->order_by('id', 'desc')->get();
         $this->template->post_footer = \View::forge('_parts/load_masonry');
     }
     $this->template->content = View::forge('member/profile/image/index', array('is_mypage' => $is_mypage, 'member' => $member, 'access_from' => $access_from, 'images' => $images, 'member_profiles' => $member_profiles));
 }
示例#4
0
文件: note.php 项目: uzura8/flockbird
 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);
 }
示例#5
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));
 }
示例#6
0
文件: api.php 项目: uzura8/flockbird
 /**
  * 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);
     });
 }
示例#7
0
 public static function get_foreign_table_obj($type, $foreign_id)
 {
     switch ($type) {
         case \Config::get('timeline.types.note'):
             return \Note\Model_Note::find($foreign_id);
         case \Config::get('timeline.types.thread'):
             return \thread\Model_thread::find($foreign_id);
         case \Config::get('timeline.types.album'):
         case \Config::get('timeline.types.album_image'):
         case \Config::get('timeline.types.album_image_timeline'):
             return \Album\Model_Album::find($foreign_id);
     }
     return null;
 }
示例#8
0
 public function test_check_type_album_image_timeline()
 {
     if (!($list = Model_Timeline::get4type_key('album_image_timeline'))) {
         $this->markTestSkipped('No record for test.');
     }
     \Util_Develop::output_test_info(__FILE__, __LINE__);
     foreach ($list as $obj) {
         // check for reference data.
         $this->assertEquals('album', $obj->foreign_table);
         $album = \Album\Model_Album::check_authority($obj->foreign_id);
         $this->assertNotEmpty($album);
         // check for member
         $member = \Model_Member::check_authority($obj->member_id);
         $this->assertNotEmpty($member);
         // check for member_id
         $this->assertEquals($album->member_id, $obj->member_id);
         // check for timeline_child_data
         $timeline_child_datas = Model_TimelineChildData::get4timeline_id($obj->id);
         $this->assertNotEmpty($timeline_child_datas);
         $public_flag_max_range = null;
         if ($timeline_child_datas) {
             foreach ($timeline_child_datas as $timeline_child_data) {
                 // check for reference data.
                 $this->assertEquals('album_image', $timeline_child_data->foreign_table);
                 // check for album_image
                 $album_image = \Album\Model_AlbumImage::check_authority($timeline_child_data->foreign_id);
                 $this->assertNotEmpty($album_image);
                 // check for album_id
                 $this->assertEquals($album->id, $album_image->album_id);
                 // check for public_flag.
                 $this->assertEquals($album_image->public_flag, $obj->public_flag);
             }
         }
     }
 }
示例#9
0
 public function delete_with_album_image($member_id)
 {
     $album_image_ids = array();
     $deleted_files = null;
     if (Site_Util::check_type($this->type, 'album_image_timeline')) {
         try {
             $album = \Album\Model_Album::check_authority($this->foreign_id, $member_id);
         } catch (\FuelException $e) {
             $album = null;
         }
         $album_image_ids = $album ? Model_TimelineChildData::get_foreign_ids4timeline_id($this->id) : null;
     }
     if ($album_image_ids) {
         \Album\Model_AlbumImage::delete_multiple($album_image_ids);
     }
     $this->delete();
 }