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

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

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

	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_02_addcontent();

	// 連動マップ（ID => セレクター）
	// 1つのIDに対して複数のCSSクラスを指定する（1つなら1行）
	$dependency_map = array(
		//$set_name . 'use-top-home-scroll' => array(
			//'.home-top-button-align-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_02_addcontent', 20 );

/*** 独自ショートコードを使う ***/
/* 項目の追加とデータの更新 */
function haumenu_init_field_is_use_shortcode(){
//項目の追加
	add_settings_field(
		'use-shortcode', // 設定名
		__('Use HA Utility Shortcodes','hima-art-utility'), // 設定タイトル
		'haumenu_is_use_shortcode', // 設定項目のHTMLを出力する関数名
		haumenu_define_tab_slug_02_addcontent(), //表示させるタブのスラグ
		haumenu_define_section_id_02_addcontent(),// $section 表示させるセクションのID
		array( 'class' => 'ha-settings-separate' )
	);

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

/* 入力フォーム */
function haumenu_is_use_shortcode() {
	$set_name = haumenu_define_option_name_02_addcontent(); //  $option_name 設定名
	$options = get_option($set_name);
	$option_name = 'use-shortcode'; //個別配列名

	//テーブルに値がなかった場合の措置（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('Activate HimaArt Utilitiy plugin own shortcode','hima-art-utility'); ?></p>
</label>
<?php echo wp_kses_post(haup_usage_info_haup_is_single_filter()); ?>
<?php echo wp_kses_post(haup_usage_info_next_prev_shortcode_filter()); ?>
<?php echo wp_kses_post(haup_usage_info_pass_content_filter()); ?>
<div style="text-align:right;margin-top:1rem;"><a href="<?php echo esc_url(HAUP_MANUAL_DIR); ?>/howto-use-shortcode" target="_blank"><?php echo esc_html(haup_manual_text()); ?></a></div>
<?php
}

/*** 投稿スライダーショートコードを使う ***/
/* 項目の追加とデータの更新 */
function haumenu_init_field_is_use_post_slider_shortcode(){
//項目の追加
	add_settings_field(
		'use-post-slider-shortcode', // 設定名
		__('Enable Post Slider shortcode','hima-art-utility'), // 設定タイトル
		'haumenu_is_use_post_slider_shortcode', // 設定項目のHTMLを出力する関数名
		haumenu_define_tab_slug_02_addcontent(), //表示させるタブのスラグ
		haumenu_define_section_id_02_addcontent(),// $section 表示させるセクションのID
		array( 'class' => 'ha-settings-separate' )
	);

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

/* 入力フォーム */
function haumenu_is_use_post_slider_shortcode() {
	$set_name = haumenu_define_option_name_02_addcontent(); //  $option_name 設定名
	$options = get_option($set_name);
	$option_name = 'use-post-slider-shortcode'; //個別配列名

	//テーブルに値がなかった場合の措置（PHP8.x以降への対応）
	if(isset($options[$option_name])){
		$checked = $options[$option_name];
	}else{
		$checked = '';
	}

	$wp_page_url = 'https://developer.wordpress.org/reference/classes/wp_query/#order-orderby-parameters';
?>
<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 enabled, you can use a shortcode to slide posts.','hima-art-utility'); ?></p>
	<p class="haup-admin-font-red"><?php esc_html_e('This feature requires the loading of external scripts (swiper.js/swiper.css), which may affect page display performance. Therefore, this switch has been added. Please note that if you disable the switch while a shortcode is inserted, the shortcode will be displayed as is.','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('The underlying shortcode is [ha-post-slider post_type="" category="" speed="" delay="" per_page="" slides_768="" slides_1024="" slides_1200="" slides_1900="" orderby="" order=""]','hima-art-utility'); ?></p>
<p>
	<span><?php esc_html_e('Below is a summary of each parameter:','hima-art-utility'); ?></span>
	<br>
	<span class="haup-admin-font-red"><?php esc_html_e('* If the parameter is omitted, the default value will be applied.','hima-art-utility'); ?></span>
	<br>
	<span class="haup-admin-font-red"><?php esc_html_e('*If the parameter value is empty, the default value will be applied.','hima-art-utility'); ?></span>
</p>
<ul>
<li><?php esc_html_e('post_type Specifies post types (multiple types separated by commas). Default is post.','hima-art-utility'); ?></li>
<li><?php esc_html_e('category Specifies the category to include in the slide. If not specified, all content will be included in the slide.','hima-art-utility'); ?></li>
<li><?php esc_html_e('speed Specifies the time to stop after sliding. If not specified, 3000 milliseconds is applied.','hima-art-utility'); ?></li>
<li><?php esc_html_e('delay Specifies the slide movement speed. If not specified, 500 milliseconds is applied.','hima-art-utility'); ?></li>
<li><?php esc_html_e('per_page Specifies the number of contents to extract. If not specified, all contents will be extracted.','hima-art-utility'); ?></li>
<li><?php esc_html_e('slides_768 Specifies the number of slides to display on devices with a width of 768px or more (typical tablet portrait orientation). If not specified, two slides will be displayed.','hima-art-utility'); ?></li>
<li><?php esc_html_e('slides_1024 Specifies the number of slides to display on devices with a width of 1024px or more (typical tablet landscape orientation). If not specified, 3 slides will be displayed.','hima-art-utility'); ?></li>
<li><?php esc_html_e('slides_1200 Specifies the number of slides to display on devices with a width of 1200px or more (HD). If not specified, 6 slides will be displayed.','hima-art-utility'); ?></li>
<li><?php esc_html_e('slides_1900 Specifies the number of slides to display on devices with a width of 1900px or more (full HD). If not specified, 8 slides will be displayed.','hima-art-utility'); ?></li>
<li><?php esc_html_e('orderby Specifies the order of the items. If not specified, the items will be displayed randomly.','hima-art-utility'); ?></li>
<li><?php esc_html_e('order Specifies the display order. If not specified, it will be displayed randomly.','hima-art-utility'); ?></li>
</ul>
<p><?php esc_html_e('For the values ​​that can be specified for the orderby and order parameters, please refer to the official WordPress reference page below.','hima-art-utility'); ?></p>
<p><a href="<?php echo esc_url( $wp_page_url); ?>" target="_blank"><?php echo esc_html('See the official WordPress reference page','hima-art-utility'); ?></a></p>
</div>
</details>
<div style="text-align:right;margin-top:1rem;"><a href="<?php echo esc_url(HAUP_MANUAL_DIR); ?>/howtouse-post-slider" target="_blank"><?php echo esc_html(haup_manual_text()); ?></a></div>
<?php
}


/*** シェアボタンをショートコードで出力 ***/
/* 項目の追加とデータの更新 */
function haumenu_init_field_share_button_shortcode(){
//項目の追加
	add_settings_field(
		'share-button-shortcode', // 設定名
		__('Enable share button shortcode','hima-art-utility'), // 設定タイトル
		'haumenu_share_button_shortcode', // 設定項目のHTMLを出力する関数名
		haumenu_define_tab_slug_02_addcontent(), //表示させるタブのスラグ
		haumenu_define_section_id_02_addcontent(),// $section 表示させるセクションのID
		array( 'class' => 'ha-settings-separate' )
	);

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

/* 入力フォーム */
function haumenu_share_button_shortcode() {
	$set_name = haumenu_define_option_name_02_addcontent(); //  $option_name 設定名
	$options = get_option($set_name);
	$option_name = 'share-button-shortcode'; //個別配列名

	//テーブルに値がなかった場合の措置（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('Using the [ha-share] shortcode, you can display share buttons for various SNS etc. anywhere','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('The underlying shortcode is [ha-share type="" width="" margin=""]','hima-art-utility'); ?></p>
<p><?php esc_html_e('You can display the following buttons by specifying the type parameter','hima-art-utility'); ?></p>
<ul>
<li><?php esc_html_e('type="facebook" Show Facebook share button','hima-art-utility'); ?></li>
<li><?php esc_html_e('type="twitter" Display Twitter share button','hima-art-utility'); ?></li>
<li><?php esc_html_e('type="linkedin" Show LinkedIn share button','hima-art-utility'); ?></li>
<li><?php esc_html_e('type="hatena" Displays share button for Hatena Bookmark','hima-art-utility'); ?></li>
<li><?php esc_html_e('type="feed" Display URL of RSS Feed','hima-art-utility'); ?></li>
<li><?php esc_html_e('type="mail" Opens the mail creation screen of the mailer and automatically inserts a link to the page in the address, subject, and text','hima-art-utility'); ?></li>
</ul>
<p><?php esc_html_e('The width="" parameter specifies the width of the button (default is 17.5% of parent element)','hima-art-utility'); ?></p>
<p><?php esc_html_e('The margin="" parameter allows you to adjust the margin of the button (default is 0px 4px of the parent element)','hima-art-utility'); ?></p>
</div>
</details>
<div style="text-align:right;margin-top:1rem;"><a href="<?php echo esc_url(HAUP_MANUAL_DIR); ?>/share-button-shortcode" target="_blank"><?php echo esc_html(haup_manual_text()); ?></a></div>
<?php
}

