<?php if ( !defined( 'ABSPATH' ) ) exit;//PHPの宣言と直接アクセスの拒否
/* セクションID haumenu_define_section_id_01_media() */
/* タブのスラグ haumenu_define_tab_slug_01_media() */
/* $option_name 設定名 haumenu_define_option_name_01_media() */
/* get_option GetOP01_media() */

/***** 親設定の有効／無効に合わせて子設定の表示方法を変更する *****/
/* 関数名・設定名は画面ごとに変えること（関数重複を防ぐ） */
/* add_action('admin_notices', 'current_pagehook');を追加してページ名を取得し、$page_fooksuffixの値を変える */
/* 連動マップ（ID => セレクター）の項目を編集する */

function haup_child_setting_view_control_01_media( $hook_suffix ) {
	//ページフックにより出力を判断
	$page_fooksuffix = 'ha-utilitiy_page_haumenu_page_media';

	if ( $page_fooksuffix !== $hook_suffix ) {
		return;
	}

	//メインスクリプトのハンドル
	$handle = 'haup-child-setting-control-js';

	// メインスクリプトが登録されていなければ終了(スクリプトの読み込みはmain-menu.phpで記述)
	if ( ! wp_script_is( $handle, 'registered' ) ) {
		return;
	}

	//設定名
	$set_name = haumenu_define_option_name_01_media();

	// 連動マップ（ID => セレクター）
	// 1つのIDに対して複数のCSSクラスを指定する（1つなら1行）
	$dependency_map = array(
		//$set_name . 'enable-set-revisions' => array(
			//'.set-revisions-num-wrapper', // リビジョン数
			//'.set-revisions-posttype-wrapper', // 指定する投稿タイプ
		//),

	);

	$inner_js = "";
	foreach ( $dependency_map as $id => $selectors ) {
		foreach ( (array) $selectors as $selector ) {
			// translators: %s stands for the CSS Class & ID.
			$inner_js .= sprintf(
				"haup_apply_dependency('%s', '%s');\n",
				esc_js( $id ),
				esc_js( $selector )
			);
		}
	}

	if ( $inner_js ) {
		$js_code = "if (window.haup_apply_dependency) {\n" . $inner_js . "}";
		// 第3引数を 'after' にすることで、本体JSの直後に出力
		wp_add_inline_script( $handle, $js_code, 'after' );
	}
}
add_action( 'admin_enqueue_scripts', 'haup_child_setting_view_control_01_media', 20 );

/*** 自身のメディアのみ表示 ***/
/* 項目の追加とデータの更新 */
function haumenu_init_field_show_own_media(){
//項目の追加
	add_settings_field(
		'show-own-media', // 設定名
		__('Show only your own media','hima-art-utility'), // 設定タイトル
		'haumenu_show_own_media', // 設定項目のHTMLを出力する関数名
		haumenu_define_tab_slug_01_media(), //表示させるタブのスラグ
		haumenu_define_section_id_01_media(),// $section 表示させるセクションのID
		array( 'class' => 'ha-settings-separate' )
	);

}
add_action( 'admin_init', 'haumenu_init_field_show_own_media' );

/* 入力フォーム */
function haumenu_show_own_media() {
	$set_name = haumenu_define_option_name_01_media(); //  $option_name 設定名
	$options = get_option($set_name);
	$option_name = 'show-own-media'; //個別配列名

	//テーブルに値がなかった場合の措置（PHP8.x以降への対応）
	if(isset($options[$option_name])){
		$checked = $options[$option_name];
	}else{
		$checked = '';
	}
?>
<label>
	<input type="checkbox" id="<?php echo esc_html($set_name . $option_name ); ?>" name="<?php echo esc_html($set_name . '[' .$option_name. ']'); ?>" class="wppd-ui-toggle" <?php checked( $checked , 1 ); ?> value="1">
	<p><?php esc_html_e('In the media list on the management screen, users with contributor privileges will only see their own media','hima-art-utility'); ?></p>
</label>
<?php
}

/*** メディア一覧へサイズを表示 ***/
/* 項目の追加とデータの更新 */
function haumenu_init_field_show_media_size_column(){
//項目の追加
	add_settings_field(
		'show-media-size-column', // 設定名
		__('Display size information in media list','hima-art-utility'), // 設定タイトル
		'haumenu_show_media_size_column', // 設定項目のHTMLを出力する関数名
		haumenu_define_tab_slug_01_media(), //表示させるタブのスラグ
		haumenu_define_section_id_01_media(),// $section 表示させるセクションのID
		array( 'class' => 'ha-settings-separate' )
	);

}
add_action( 'admin_init', 'haumenu_init_field_show_media_size_column' );

/* 入力フォーム */
function haumenu_show_media_size_column() {
	$set_name = haumenu_define_option_name_01_media(); //  $option_name 設定名
	$options = get_option($set_name);
	$option_name = 'show-media-size-column'; //個別配列名

	//テーブルに値がなかった場合の措置（PHP8.x以降への対応）
	if(isset($options[$option_name])){
		$checked = $options[$option_name];
	}else{
		$checked = '';
	}
?>
<label>
	<input type="checkbox" id="<?php echo esc_html($set_name . $option_name ); ?>" name="<?php echo esc_html($set_name . '[' .$option_name. ']'); ?>" class="wppd-ui-toggle" <?php checked( $checked , 1 ); ?> value="1">
	<p><?php esc_html_e('The vertical and horizontal size of the image and the file capacity are displayed in the media list.','hima-art-utility'); ?></p>
</label>
<p class="haup-admin-bk"><?php esc_html_e('Even if the function is enabled, you can always hide it from "Display option" at the top right of each list','hima-art-utility'); ?></p>
<?php
}

/*** メディア一覧へalt、キャプション、説明を表示する ***/
/* 項目の追加とデータの更新 */
function haumenu_init_field_show_media_other_attribute_column(){
//項目の追加
	add_settings_field(
		'show-media-other-attribute-column', // 設定名
		__('Displaying other information on the media list','hima-art-utility'), // 設定タイトル
		'haumenu_show_media_other_attribute_column', // 設定項目のHTMLを出力する関数名
		haumenu_define_tab_slug_01_media(), //表示させるタブのスラグ
		haumenu_define_section_id_01_media(),// $section 表示させるセクションのID
		array( 'class' => 'ha-settings-separate' )
	);

}

add_action( 'admin_init', 'haumenu_init_field_show_media_other_attribute_column' );

/* 入力フォーム */
function haumenu_show_media_other_attribute_column() {
	$set_name = haumenu_define_option_name_01_media(); //  $option_name 設定名
	$options = get_option($set_name);
	$option_name = 'show-media-other-attribute-column'; //個別配列名

	//テーブルに値がなかった場合の措置（PHP8.x以降への対応）
	if(isset($options[$option_name])){
		$checked = $options[$option_name];
	}else{
		$checked = '';
	}
?>
<label>
	<input type="checkbox" id="<?php echo esc_html($set_name . $option_name ); ?>" name="<?php echo esc_html($set_name . '[' .$option_name. ']'); ?>" class="wppd-ui-toggle" <?php checked( $checked , 1 ); ?> value="1">
	<p><?php esc_html_e('Display alt (alternative string), caption, and description in the media list','hima-art-utility'); ?></p>
</label>
<p class="haup-admin-bk"><?php esc_html_e('Even if the function is enabled, you can always hide it from "Display option" at the top right of each list','hima-art-utility'); ?></p>
<?php
}

/*** メディア一覧へEXIF情報を表示する ***/
/* 項目の追加とデータの更新 */
function haumenu_init_field_show_media_exif_column(){
//項目の追加
	add_settings_field(
		'show-media-exif-column', // 設定名
		__('Display EXIF information on media list','hima-art-utility'), // 設定タイトル
		'haumenu_show_media_exif_column', // 設定項目のHTMLを出力する関数名
		haumenu_define_tab_slug_01_media(), //表示させるタブのスラグ
		haumenu_define_section_id_01_media(),// $section 表示させるセクションのID
		array( 'class' => 'ha-settings-separate' )
	);

}
add_action( 'admin_init', 'haumenu_init_field_show_media_exif_column' );

/* 入力フォーム */
function haumenu_show_media_exif_column() {
	$set_name = haumenu_define_option_name_01_media(); //  $option_name 設定名
	$options = get_option($set_name);
	$option_name = 'show-media-exif-column'; //個別配列名

	//テーブルに値がなかった場合の措置（PHP8.x以降への対応）
	if(isset($options[$option_name])){
		$checked = $options[$option_name];
	}else{
		$checked = '';
	}
?>
<label>
	<input type="checkbox" id="<?php echo esc_html($set_name . $option_name ); ?>" name="<?php echo esc_html($set_name . '[' .$option_name. ']'); ?>" class="wppd-ui-toggle" <?php checked( $checked , 1 ); ?> value="1">
	<p><?php esc_html_e('Displays image information (EXIF information) obtained from the camera when uploading to the media list','hima-art-utility'); ?></p>
</label>
<p class="haup-admin-bk">
	<span>
		<?php esc_html_e('What is displayed are the "shooting date," "camera model," and "ISO" values.','hima-art-utility'); ?>
	</span>
	<br>
	<span>
		<?php esc_html_e('Even if the function is enabled, you can always hide it from "Display option" at the top right of each list','hima-art-utility'); ?>
	</span>
</p>
<?php
}

/*** メディアの無限スクロールを復活する ***/
/* 項目の追加とデータの更新 */
function haumenu_init_field_media_infinite_scroll(){
//項目の追加
	add_settings_field(
		'media-infinite-scroll', // 設定名
		__('Make the media list infinitely scrollable','hima-art-utility'), // 設定タイトル
		'haumenu_media_infinite_scroll', // 設定項目のHTMLを出力する関数名
		haumenu_define_tab_slug_01_media(), //表示させるタブのスラグ
		haumenu_define_section_id_01_media(),// $section 表示させるセクションのID
		array( 'class' => 'ha-settings-separate' )
	);

}
add_action( 'admin_init', 'haumenu_init_field_media_infinite_scroll' );

/* 入力フォーム */
function haumenu_media_infinite_scroll() {
	$set_name = haumenu_define_option_name_01_media(); //  $option_name 設定名
	$options = get_option($set_name);
	$option_name = 'media-infinite-scroll'; //個別配列名

	//テーブルに値がなかった場合の措置（PHP8.x以降への対応）
	if(isset($options[$option_name])){
		$checked = $options[$option_name];
	}else{
		$checked = '';
	}
?>
<label>
	<input type="checkbox" id="<?php echo esc_html($set_name . $option_name ); ?>" name="<?php echo esc_html($set_name . '[' .$option_name. ']'); ?>" class="wppd-ui-toggle" <?php checked( $checked , 1 ); ?> value="1">
	<p><?php esc_html_e('When viewing the media list in grid view, the "Load more" button will be removed and the next image will be loaded as you scroll.','hima-art-utility'); ?></p>
</label>
<p class="haup-admin-bk"><?php esc_html_e('This function will also work when inserting images in the editing screen, in addition to the media library.','hima-art-utility'); ?></p>
<?php
}

/*** メディアライブラリからEXIF情報を削除する ***/
/* 項目の追加とデータの更新 */
function haumenu_init_field_delete_exif_data_by_media_library(){
//項目の追加
	add_settings_field(
		'delete-exif-data-by-media-library', // 設定名
		__('Remove EXIF ​​data','hima-art-utility'), // 設定タイトル
		'haumenu_delete_exif_data_by_media_library', // 設定項目のHTMLを出力する関数名
		haumenu_define_tab_slug_01_media(), //表示させるタブのスラグ
		haumenu_define_section_id_01_media(),// $section 表示させるセクションのID
		array( 'class' => 'ha-settings-separate' )
	);

}
add_action( 'admin_init', 'haumenu_init_field_delete_exif_data_by_media_library' );

/* 入力フォーム */
function haumenu_delete_exif_data_by_media_library() {
	$set_name = haumenu_define_option_name_01_media(); //  $option_name 設定名
	$options = get_option($set_name);
	$option_name = 'delete-exif-data-by-media-library'; //個別配列名

	//テーブルに値がなかった場合の措置（PHP8.x以降への対応）
	if(isset($options[$option_name])){
		$checked = $options[$option_name];
	}else{
		$checked = '';
	}
?>
<label>
	<input type="checkbox" id="<?php echo esc_html($set_name . $option_name ); ?>" name="<?php echo esc_html($set_name . '[' .$option_name. ']'); ?>" class="wppd-ui-toggle" <?php checked( $checked , 1 ); ?> value="1">
	<p><?php esc_html_e('You can now delete the EXIF ​​information stored in images (original images) uploaded to the media library.','hima-art-utility'); ?></p>
	<p><?php esc_html_e('Please be sure to read the detailed explanation before enabling and using the function.','hima-art-utility'); ?></p>
</label>

<details class="accordion"  style="margin: 5px 0px 0px 0px;overflow: hidden;">
<summary class="accordion__title" style="cursor: pointer;"><?php esc_html_e('View detailed description','hima-art-utility'); ?></summary>
<div class="accordion__content">
	<p><?php esc_html_e('This function protects privacy by removing location information (GPS) and metadata that could lead to personal identification from uploaded, unedited images (original images).','hima-art-utility'); ?></p>
<p><?php esc_html_e('When this function is enabled, the Delete button will be displayed only for images displayed in the media library that have EXIF information remaining. You can delete EXIF information for each image, as well as perform bulk processing.','hima-art-utility'); ?></p>
<p class="haup-admin-font-red" style="font-size:0.8rem;"><?php esc_html_e('This function deletes the EXIF data of any image individually, and does not have a function to delete it automatically when uploading. If the EXIF information has been deleted from the original image uploaded in the past, please check the functions of the image optimization plugin (as far as I know, if you are using a plugin such as EWWW or Imsanity that has the function to resize the original image, the EXIF information will be deleted at the same time as uploading due to the WordPress image processing function).','hima-art-utility'); ?></p>
<h3><?php esc_html_e('Data deleted by this function','hima-art-utility'); ?></h3>
<p><?php esc_html_e('The EXIF information that is deleted varies depending on the image processing software that is enabled in your environment.','hima-art-utility'); ?></p>
<ol>
	<li><?php esc_html_e('GD: Completely discards all EXIF information','hima-art-utility'); ?></li>
	<li><?php esc_html_e('ImageMagick: Delete the following data items:','hima-art-utility'); ?></li>
	<ol>
		<li><?php esc_html_e('GPS: All About Location','hima-art-utility'); ?></li>
		<li><?php esc_html_e('SerialNumber: Camera serial number','hima-art-utility'); ?></li>
		<li><?php esc_html_e('Artist: Creator','hima-art-utility'); ?></li>
		<li><?php esc_html_e('Copyright: Copyright information','hima-art-utility'); ?></li>
		<li><?php esc_html_e('UserComment:User comment','hima-art-utility'); ?></li>
		<li><?php esc_html_e('ImageDescription: Image title and description','hima-art-utility'); ?></li>
	</ol>
</ol>
<h3><?php esc_html_e('Precautions when using this function','hima-art-utility'); ?></h3>
<h4><?php esc_html_e('Once deleted, it cannot be undone','hima-art-utility'); ?></h4>
	<p><?php esc_html_e('EXIF information deleted using this function cannot be restored. If you want to keep the original images, please make a backup.','hima-art-utility'); ?></p>
	<p><?php esc_html_e('Unless you specifically want to display shooting data (such as exposure information) on photo sharing sites or portfolio sites, we recommend deleting EXIF information when using original images in the following ways:','hima-art-utility'); ?></p>
	<ol>
		<li><?php esc_html_e('When the original, unprocessed files are directly called using themes or plugin functions','hima-art-utility'); ?></li>
		<li><?php esc_html_e('When using the "Lightbox" function of the image block','hima-art-utility'); ?></li>
		<li><?php esc_html_e('When the image block link destination is set to "Media File"','hima-art-utility'); ?></li>
		<li><?php esc_html_e('When "Full size" is specified for the image block size','hima-art-utility'); ?></li>
	</ol>
<h4><?php esc_html_e('Please make sure it has been deleted','hima-art-utility'); ?></h4>
	<p><?php esc_html_e('Once you click the Delete button and the deletion is complete, please check whether the EXIF ​​information has been successfully deleted using one of the following methods:','hima-art-utility'); ?></p>
	<ol>
		<li><?php esc_html_e('Download deleted images from the media library and view detailed image information','hima-art-utility'); ?></li>
		<li><?php esc_html_e('While the full-size image with the EXIF removed is displayed on the front end, click "Save As" to check the image details.','hima-art-utility'); ?></li>
	</ol>
</div>
</details>
<div style="text-align:right;margin-top:1rem;"><a href="<?php echo esc_url(HAUP_MANUAL_DIR); ?>/howtouse-delete-exif-data-by-medialibrary" target="_blank"><?php echo esc_html(haup_manual_text()); ?></a></div>
<?php
}