/** * 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); }); }
/** * Api delete common controller * * @access protected * @param string $table Delete target table * @param int $id Delete target record's id * @param string $method Excecuting method name * @param string $content_name Delete target content name for message * @return Response(json) */ protected function api_delete_common($table, $id = null, $method = null, $content_name = '') { $this->controller_common_api(function () use($table, $id, $method, $content_name) { if (!$method) { $method = 'delete'; } $id = intval(\Input::post('id') ?: $id); $model = Site_Model::get_model_name($table); $obj = $model::check_authority($id, IS_ADMIN ? 0 : $this->u->id); if (is_enabled('album') && $table == 'album') { if ($result = \Album\Site_Util::check_album_disabled_to_update($obj->foreign_table)) { throw new \DisableToUpdateException($result['message']); } } \DB::start_transaction(); if ($table == 'timeline') { $result = \Timeline\Site_Model::delete_timeline($obj, $this->u->id); } else { $result = $obj->{$method}(); } \DB::commit_transaction(); $target_conntent_name = $content_name ?: Site_Model::get_content_name($table); $data = array('result' => (bool) $result, 'message' => sprintf('%s%sしました。', $target_conntent_name ? $target_conntent_name . 'を' : '', term('form.delete'))); $this->set_response_body_api($data); }); }
if (empty($is_simple_view)) { if (!empty($is_member_page)) { ?> <div class="date_box"> <small><?php echo site_get_time($album_image->created_at); ?> </small> <?php $is_mycontents = Auth::check() && $u->id == $album_image->album->member_id; echo render('_parts/public_flag_selecter', array('model' => 'album_image', 'id' => $album_image->id, 'public_flag' => $album_image->public_flag, 'is_mycontents' => $is_mycontents, 'view_icon_only' => true, 'disabled_to_update' => \Album\Site_Util::check_album_disabled_to_update($album_image->album->foreign_table))); ?> </div> <?php } else { echo render('_parts/member_contents_box', array('member' => $album_image->album->member, 'id' => $album_image->id, 'public_flag' => $album_image->public_flag, 'public_flag_view_icon_only' => true, 'public_flag_disabled_to_update' => \Album\Site_Util::check_album_disabled_to_update($album_image->album->foreign_table), 'model' => 'album_image', 'date' => array('datetime' => $album_image->created_at))); } } ?> <?php if (empty($is_simple_view)) { ?> <div class="article"> <?php if (empty($album)) { ?> <div class="subinfo"> <small><?php echo term('album'); ?>
?> "> <div class="imgBox" id="imgBox_<?php echo $album->id; ?> "> <div class="content"><?php echo img(\Album\Model_AlbumImage::get_album_cover_filename($album->cover_album_image_id, $album->id, $access_from), 'M', 'album/' . $album->id); ?> </div> <h5><?php echo Html::anchor('album/' . $album->id, strim($album->name, \Config::get('album.articles.trim_width.name'))); ?> </h5> <?php $disable_to_update = \Album\Site_Util::check_album_disabled_to_update($album->foreign_table); if (!empty($is_member_page)) { ?> <div class="date_box"> <small><?php echo site_get_time($album->created_at); ?> </small> <?php $is_mycontents = Auth::check() && $u->id == $album->member_id; echo render('_parts/public_flag_selecter', array('model' => 'album', 'id' => $album->id, 'public_flag' => $album->public_flag, 'is_mycontents' => $is_mycontents, 'view_icon_only' => true, 'disabled_to_update' => $disable_to_update, 'have_children_public_flag' => true, 'child_model' => 'album_image')); ?> </div><!-- date_box --> <?php } else { echo render('_parts/member_contents_box', array('member' => $album->member, 'id' => $album->id, 'public_flag' => $album->public_flag, 'public_flag_view_icon_only' => true, 'public_flag_disabled_to_update' => $disable_to_update, 'have_children_public_flag' => true, 'model' => 'album', 'date' => array('datetime' => $album->created_at), 'child_model' => 'album_image'));
/** * Album slide * * @access public * @params integer * @return Response */ public function action_slide($id = null) { $album = Model_Album::check_authority($id, null, 'member'); $disabled_to_update = \Album\Site_Util::check_album_disabled_to_update($album->foreign_table); $data = array('content_id' => $id, 'body' => $album->body); $this->set_title_and_breadcrumbs(sprintf('%sの%s', $album->name, term('album_image')), array('/album/' . $id => $album->name), $album->member, 'album'); $this->template->subtitle = \View::forge('_parts/detail_subtitle', array('album' => $album, 'disabled_to_update' => $disabled_to_update)); $this->template->post_footer = \View::forge('_parts/slide_footer', array('is_desc' => true)); $this->template->content = \View::forge('_parts/slide', $data); }
/** * Get edit menu common api controller * * @access protected * @param string $table target table * @param int $id target record id * @param bool $is_watch_target if true,add menu to watch * @param string $parent_selector_prefix use to define delete target * @param string $member_related related table for get member_id * @return Response (html) * @throws Exception in Controller_Base::controller_common_api * @see Controller_Base::controller_common_api */ protected function api_get_menu_common($table, $id, $is_watch_target = false, $parent_selector_prefix = null, $member_related = null) { $this->api_accept_formats = 'html'; $this->controller_common_api(function () use($id, $table, $is_watch_target, $parent_selector_prefix, $member_related) { $id = (int) $id; $is_detail = (bool) \Input::get('is_detail', 0); $model = Site_Model::get_model_name($table); $obj = $model::check_authority($id); $member_id = $member_related ? $obj->{$member_related}->member_id : $obj->member_id; $this->check_browse_authority($obj->public_flag, $member_id); $is_enabled_to_edit = true; if (is_enabled('album') && $table == 'album' && \Album\Site_Util::check_album_disabled_to_update($obj->foreign_table, true)) { $is_enabled_to_edit = false; } $menus = array(); if ($member_id == $this->u->id) { if (is_enabled('album') && $table == 'album_image') { if ($add_menu = \Album\Site_Util::get_album_image_edit_menu($obj, $this->u->file_name)) { $menus += $add_menu; } } if (is_enabled('note') && $table == 'note' && !$obj->is_published) { $menus[] = array('icon_term' => 'form.do_publish', 'attr' => array('class' => 'js-simplePost', 'data-uri' => Site_Util::get_action_uri($table, $id, 'publish'), 'data-msg' => term('form.publish') . 'しますか?')); } if ($is_enabled_to_edit) { $edit_uri = $table == 'timeline' ? \Timeline\Site_Util::get_edit_action_uri($obj) : Site_Util::get_action_uri($table, $id, 'edit'); if ($edit_uri) { $menus[] = array('href' => $edit_uri, 'icon_term' => 'form.do_edit'); } $delete_api_uri = $table == 'timeline' ? \Timeline\Site_Util::get_delete_api_uri($obj) : Site_Util::get_action_uri($table, $id, 'delete', 'json'); $menus[] = array('icon_term' => 'form.do_delete', 'attr' => array('class' => $is_detail ? 'js-simplePost' : 'js-ajax-delete', 'data-uri' => $is_detail ? Site_Util::get_action_uri($table, $id, 'delete') : $delete_api_uri, 'data-msg' => term('form.delete') . 'します。よろしいですか。', 'data-parent' => sprintf('#%s%d', $parent_selector_prefix ?: 'article_', $id))); } // add divider. if (!$is_detail && $menus) { array_unshift($menus, array('tag' => 'divider')); } } else { if (is_enabled('notice') && $is_watch_target) { if ($table == 'timeline') { list($foreign_table, $foreign_id_prop) = \Timeline\Site_Util::get_member_watch_content_info4timeline_type($obj->type); $is_watched = \Notice\Model_MemberWatchContent::get_one4foreign_data_and_member_id($foreign_table, $obj->{$foreign_id_prop}, $this->u->id); $api_uri = \Timeline\Site_Util::get_member_watch_content_api_uri($obj); } else { $is_watched = \Notice\Model_MemberWatchContent::get_one4foreign_data_and_member_id($table, $id, $this->u->id); $api_uri = sprintf('member/notice/api/update_watch_status/%s/%d', $table, $id); } $menus[] = array('icon_term' => $is_watched ? 'form.do_unwatch' : 'form.do_watch', 'attr' => array('class' => 'js-update_toggle', 'data-uri' => $api_uri)); } if ($table == 'timeline' && conf('articleUnfollow.isEnabled', 'timeline')) { $is_followed = (bool) \Timeline\Model_MemberFollowTimeline::get4timeline_id_and_member_id($obj->id, $this->u->id); $menus[] = array('icon_term' => $is_followed ? 'followed' : 'do_follow', 'attr' => array('class' => 'js-update_toggle', 'data-uri' => sprintf('timeline/api/update_follow_status/%d.json', $obj->id))); } } $this->set_response_body_api(array('menus' => $menus, 'is_ajax_loaded' => true), '_parts/dropdown_menu'); }); }
<?php $date = isset($album_image->shot_at) ? $album_image->shot_at : $album_image->created_at; echo render('_parts/member_contents_box', array('member' => $album_image->album->member, 'id' => $album_image->id, 'public_flag' => $album_image->public_flag, 'public_flag_disabled_to_update' => \Album\Site_Util::check_album_disabled_to_update($album_image->album->foreign_table), 'model' => 'album_image', 'date' => array('datetime' => $date, 'label' => term('site.shot')))); ?> <?php $dropdown_btn_group_attr = array('id' => 'btn_dropdown_' . $album_image->id, 'class' => array('dropdown', 'boxBtn', 'edit')); $get_uri = sprintf('album/image/api/menu/%d.html', $album_image->id); $dropdown_btn_attr = array('class' => 'js-dropdown_content_menu', 'data-uri' => sprintf('album/image/api/menu/%d.html?is_detail=1', $album_image->id), 'data-member_id' => $album_image->album->member_id, 'data-menu' => '#menu_' . $album_image->id, 'data-loaded' => 0); $menus = array(); echo btn_dropdown('noterm.dropdown', $menus, false, 'xs', null, true, $dropdown_btn_group_attr, $dropdown_btn_attr, false);
<?php $label_col_size = 3; ?> <div class="well"> <?php echo form_open(true); ?> <?php echo form_input($val, 'name', isset($album_image) ? $album_image->name : '', 12, $label_col_size); if (!\Album\Site_Util::check_album_disabled_to_update($album_image->album->foreign_table, true)) { ?> <?php echo form_public_flag($val, isset($album_image) ? $album_image->public_flag : null, false, $label_col_size); ?> <?php echo Form::hidden('original_public_flag', isset($album_image) ? $album_image->public_flag : null); } ?> <?php echo form_input_datetime($val, 'shot_at_time', isset($album_image) ? check_and_get_datatime($album_image->shot_at, 'datetime_minutes') : '', null, 6, $label_col_size); if (is_enabled_map('image/edit', 'album')) { ?> <?php echo form_map($val, null, $location, $label_col_size); } ?> <?php echo form_button('form.do_edit', 'submit', null, null, $label_col_size); ?> </div><!-- well -->