Beispiel #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;
 }
Beispiel #2
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));
 }
Beispiel #3
0
 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);
 }
Beispiel #4
0
 /**
  * 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));
 }
Beispiel #5
0
 /**
  * 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);
     });
 }