Example #1
0
 public static function get_original_datetime($exif)
 {
     if (empty($exif['DateTimeOriginal'])) {
         return null;
     }
     if (!($exif_time = \Util_Date::check_is_past($exif['DateTimeOriginal'], null, '-30 years', true))) {
         return null;
     }
     return $exif_time;
 }
Example #2
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);
 }
Example #3
0
 /**
  * @dataProvider update_public_flag_with_relations_provider
  */
 public function test_update_public_flag_with_relations($public_flag, $is_update_children_public_flag)
 {
     $album = $this->get_album();
     $before = array('public_flag' => $album->public_flag, 'created_at' => $album->created_at, 'updated_at' => $album->updated_at);
     $album->update_public_flag_with_relations($public_flag, $is_update_children_public_flag);
     self::$album = $album;
     // 件数
     $this->assertEquals(self::$album_count, \Util_Orm::get_count_all('\\Album\\Model_Album'));
     // 値
     $this->assertEquals($public_flag, $album->public_flag);
     // date
     // 変更なし
     if ($album->public_flag == $before['public_flag']) {
         $this->assertEquals($before['updated_at'], $album->updated_at);
     } else {
         $this->assertTrue(\Util_Date::check_is_future($album->updated_at, $album->created_at));
         $this->assertTrue(\Util_Date::check_is_future($album->updated_at, $before['updated_at']));
     }
     // timeline
     if (is_enabled('timeline')) {
         $timelines = \Timeline\Model_Timeline::get4foreign_table_and_foreign_ids('album', $album->id, \Config::get('timeline.types.album'));
         $this->assertCount(1, $timelines);
         $timeline = array_shift($timelines);
         $this->assertEquals($album->public_flag, $timeline->public_flag);
         // 変更なし
         if ($album->public_flag == $before['public_flag']) {
             $this->assertEquals($before['updated_at'], $timeline->sort_datetime);
         } else {
             $this->assertEquals($album->updated_at, $timeline->sort_datetime);
         }
     }
 }
Example #4
0
 /**
  * Account locked check
  *
  * @return  bool
  */
 public function check_is_account_locked($email)
 {
     if (!\Config::get('uzuraauth.accountLock.isEnabled')) {
         return false;
     }
     $login_failed_info = \Session::get('login_failed', array());
     if (!($login_failed_info = \Session::get('login_failed', array()))) {
         return false;
     }
     if (!isset($login_failed_info[$email]['last_execute_time'])) {
         return false;
     }
     if (\Util_Date::check_is_passed($login_failed_info[$email]['last_execute_time'], \Config::get('uzuraauth.accountLock.recoveryTime'))) {
         $this->reset_account_lock_count($email);
         return false;
     }
     if (!isset($login_failed_info[$email]['count'])) {
         return false;
     }
     if ($login_failed_info[$email]['count'] < \Config::get('uzuraauth.accountLock.loginFailAcceptCount')) {
         return false;
     }
     return true;
 }
Example #5
0
 public function _validation_date_string($val, $year_field = null, $delimiter = '-')
 {
     if (empty($val)) {
         return true;
     }
     // if $val is empty, uncheck;
     $date_items = Util_Date::sprit_date_str($val, true, $delimiter);
     $month = $date_items['month'];
     $date = $date_items['date'];
     $year = 2000;
     // 閏年の年を初期値としてセット
     if (!empty($date_items['year'])) {
         $year = $date_items['year'];
     } elseif ($year_field && $this->input($year_field)) {
         $year = $this->input($year_field);
     }
     if ($month < 1 || $month > 12) {
         return false;
     }
     if ($date < 1) {
         return false;
     }
     if ($date > Date::days_in_month($month, $year)) {
         return false;
     }
     return checkdate($month, $date, $year);
 }
Example #6
0
 protected static function get_shot_at_for_update($default_shot_at, $update_shot_at_time = null, $update_shot_at = null)
 {
     if ($update_shot_at && $update_shot_at != $default_shot_at) {
         return $update_shot_at;
     } elseif ($update_shot_at_time && !\Util_Date::check_is_same_minute($update_shot_at_time, $default_shot_at)) {
         return $update_shot_at_time . ':00';
     }
     return $default_shot_at;
 }
Example #7
0
 /**
  * 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('/^\\&gt;/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));
 }
Example #8
0
 /**
  * @dataProvider update_public_flag_with_relations_provider
  */
 public function test_update_public_flag_with_relations($public_flag)
 {
     $note = $this->get_last_row();
     $before = array('public_flag' => $note->public_flag, 'updated_at' => $note->updated_at, 'sort_datetime' => $note->sort_datetime);
     $note->update_public_flag_with_relations($public_flag);
     // 件数
     $this->assertEquals(self::$note_count, \Util_Orm::get_count_all('\\Note\\Model_Note'));
     // 値
     $this->assertEquals($public_flag, $note->public_flag);
     // date
     // 変更なし
     if ($note->public_flag == $before['public_flag']) {
         $this->assertEquals($before['updated_at'], $note->updated_at);
         $this->assertEquals($before['sort_datetime'], $note->sort_datetime);
     } else {
         $this->assertTrue(\Util_Date::check_is_future($note->updated_at, $note->created_at));
         $this->assertEquals($note->updated_at, $note->sort_datetime);
     }
     // timeline
     if (is_enabled('timeline')) {
         $timelines = \Timeline\Model_Timeline::get4foreign_table_and_foreign_ids('note', $note->id, \Config::get('timeline.types.note'));
         if ($note->is_published) {
             $this->assertCount(1, $timelines);
             $timeline = array_shift($timelines);
             $this->assertEquals($note->public_flag, $timeline->public_flag);
             $this->assertEquals($note->sort_datetime, $timeline->sort_datetime);
         } else {
             $this->assertCount(0, $timelines);
         }
     }
 }
Example #9
0
 private function set_validation_member_field_birthday()
 {
     if (!$this->check_is_enabled_member_field('birthday')) {
         return false;
     }
     $properties = Form_Util::get_model_field('member', 'birthyear');
     $attrs = $properties['attributes'];
     $attrs['value'] = isset($this->member_obj->birthyear) ? $this->member_obj->birthyear : date('Y');
     if (self::conf('birthday', 'birthyear.isRequired')) {
         $properties['rules'][] = 'required';
     }
     $this->validation->add('member_birthyear', $properties['label'], $attrs, $properties['rules']);
     list($month, $day) = !empty($this->member_obj->birthday) ? Util_Date::sprit_date_str($this->member_obj->birthday) : array(1, 1);
     if (self::conf('birthday', 'birthday.isRequired')) {
         $rules[] = 'required';
     }
     $options = Form_Util::get_int_options(1, 12);
     $rules = array(array('valid_string', 'numeric'), array('in_array', array_keys($options)));
     $this->validation->add('member_birthday_month', '誕生日(月)', array('type' => 'select', 'options' => $options, 'value' => $month), $rules);
     $options = Form_Util::get_int_options(1, 31);
     $rules = array(array('valid_string', 'numeric'), array('in_array', array_keys($options)));
     $this->validation->add('member_birthday_day', '誕生日(日)', array('type' => 'select', 'options' => $options, 'value' => $month), $rules);
 }
Example #10
0
 /**
  * @dataProvider update_public_flag_provider
  */
 public function test_update_public_flag($default_public_flag, $public_flag, $timeline_public_flag_expected)
 {
     if (!self::$album_image || !is_null($default_public_flag)) {
         self::$album_image = $this->get_album_image(array('public_flag' => $default_public_flag), 2);
     }
     $timelines = \Timeline\Model_Timeline::get4foreign_table_and_foreign_ids('album', self::$album_image->album_id, \Config::get('timeline.types.album_image'));
     $timeline_before = array_shift($timelines);
     // 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'));
     }
     $before = array('public_flag' => self::$album_image->public_flag, 'created_at' => self::$album_image->created_at, 'updated_at' => self::$album_image->updated_at);
     // update public_flag
     \Util_Develop::sleep();
     self::$album_image->update_public_flag($public_flag);
     $is_updated = $public_flag != $before['public_flag'];
     // 値
     $this->assertEquals($public_flag, self::$album_image->public_flag);
     // date
     // 変更あり
     if ($is_updated) {
         $this->assertTrue(\Util_Date::check_is_future(self::$album_image->updated_at, $before['updated_at']));
     } else {
         $this->assertEquals($before['updated_at'], self::$album_image->updated_at);
     }
     // timeline
     if (is_enabled('timeline')) {
         // 件数
         $this->assertEquals(self::$timeline_count, \Util_Orm::get_count_all('\\Timeline\\Model_Timeline'));
         $this->assertEquals(self::$timeline_cache_count, \Util_Orm::get_count_all('\\Timeline\\Model_TimelineCache'));
         $timelines = \Timeline\Model_Timeline::get4foreign_table_and_foreign_ids('album', self::$album_image->album_id, \Config::get('timeline.types.album_image'));
         $timeline = array_shift($timelines);
         $this->assertEquals($timeline_public_flag_expected, $timeline->public_flag);
         // 変更あり
         if ($is_updated) {
             if (\Site_Util::check_is_expanded_public_flag_range($before['public_flag'], $public_flag)) {
                 $this->assertTrue(\Util_Date::check_is_future($timeline->sort_datetime, self::$album_image->created_at));
             }
         } else {
             $this->assertEquals($timeline_before->updated_at, $timeline->updated_at);
         }
         // timeline view cache check
         if (self::$is_check_timeline_view_cache) {
             $this->assertEmpty(\Timeline\Site_Util::get_view_cache($timeline->id));
         }
     }
 }
Example #11
0
年<?php 
    }
    ?>
				</div>
			</div>
<?php 
}
if (!$is_simple_list && !empty($member_profiles) && $member->birthday && check_display_type(conf('profile.birthday.birthday.displayType'), $display_type) && check_public_flag($member->birthday_public_flag, $access_from)) {
    ?>
			<div class="row">
				<div class="col-xs-4 u-alr"><label><?php 
    echo term('member.birthday');
    ?>
</label></div>
				<div class="col-xs-8"><?php 
    echo Util_Date::conv_date_format($member->birthday, '%d月%d日');
    ?>
</div>
			</div>
<?php 
}
if (!empty($member_profiles)) {
    ?>
			<?php 
    echo render('member/profile/_parts/values', array('member' => $member, 'member_profiles' => $member_profiles, 'access_from' => $access_from, 'display_type' => $display_type));
}
if (!$is_simple_list) {
    ?>
			<ul class="list-inline mt10">
				<li><small><label><?php 
    echo term('site.registration');