<?php if ( !defined( 'ABSPATH' ) ) exit;//PHPの宣言と直接アクセスの拒否
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
function hima_art_share_button_sc_init($atts){
	$atts = shortcode_atts(
	array(
	'type' => '',
	'width' => '',
	'margin' => '',
	'lm' => '',
	'rm' => '',
	),$atts);
	
	
	$url_encode=get_permalink();
	$title_encode=get_the_title().'｜'.get_bloginfo('name');
	//$url_encode=urlencode(home_url('/'));
	//$title_encode=urlencode(get_bloginfo('name'));	

	$open_content = "javascript:window.open(this.href,'','menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600');return false;";


//パソコン用の規定値
if(!haup_is_mobile()){
//幅指定がなかったら17.5%にする
if(empty($atts['width'])){
	$atts['width'] = '17.5';
}

//マージン指定がなかったら4pxにする
if(empty($atts['margin'])){
	$atts['margin'] = '0px 4px';
}

//個別の左右マージン
//左
if(empty($atts['lm'])){
	$atts['lm'] = '0px';
}
//右
if(empty($atts['rm'])){
	$atts['rm'] = '0px';
}
}

//モバイル用の規定値
if(haup_is_mobile()){
//幅指定がなかったら100%にする
if(empty($atts['width'])){
	$atts['width'] = '100';
}

//マージン指定がなかったら4pxにする
if(empty($atts['margin'])){
	$atts['margin'] = '4px 4px';
}

//個別の左右マージン
//左
if(empty($atts['lm'])){
	$atts['lm'] = '0px';
}
//右
if(empty($atts['rm'])){
	$atts['rm'] = '0px';
}
}

//Facebookの場合
if($atts['type'] == 'facebook'){
	$url = '//www.facebook.com/sharer.php?src=bm&u='.$url_encode.'&t='.$title_encode.'';
	return '<div class="ha-share-button share-facebook" style="width:'.$atts['width'].'%;margin:'.$atts['margin'].';margin-left:'.$atts['lm'].'!important;margin-right:'.$atts['rm'].'!important;"><a href="'.$url.'" onclick="'.$open_content.'"><span class="icon-hauicon-share13 ha-share-icon"></span><span> facebook</span></a></div>';
}

//Xの場合
//2024.5.xx以降完全にx.comへ切り替わったので対応
//if($atts['type'] == 'twitter'){
//	$url = '//twitter.com/intent/tweet?url='.$url_encode.'&text='.$title_encode.'&tw_p=tweetbutton';
if($atts['type'] == 'x'){
	$url = '//x.com/intent/post?url='.$url_encode.'&text='.$title_encode.'&tw_p=tweetbutton';

	return '<div class="ha-share-button share-twitter" style="width:'.$atts['width'].'%;margin:'.$atts['margin'].';margin-left:'.$atts['lm'].'!important;margin-right:'.$atts['rm'].'!important;"><a href="'.$url.'" onclick="'.$open_content.'"><span class="icon-hauicon-share04 ha-share-icon"></span><span>&nbsp; &nbsp; &nbsp; &nbsp; X</span></a></div>';
}

//はてブの場合
if($atts['type'] == 'hatena'){
	$url = '//b.hatena.ne.jp/entry/'.$url_encode.'&text='.$title_encode.'';
	return '<div class="ha-share-button share-hatena" style="width:'.$atts['width'].'%;margin:'.$atts['margin'].';margin-left:'.$atts['lm'].'!important;margin-right:'.$atts['rm'].'!important;"><a href="'.$url.'" onclick="'.$open_content.'"><span class="icon-hauicon-share09 ha-share-icon"></span><span> Hatena</span></a></div>';
}

//Linkedinの場合
if($atts['type'] == 'linkedin'){
	$url = '//www.linkedin.com/sharing/share-offsite/?url='.$url_encode.'&text='.$title_encode.'';
	return '<div class="ha-share-button share-linkedin" style="width:'.$atts['width'].'%;margin:'.$atts['margin'].';margin-left:'.$atts['lm'].'!important;margin-right:'.$atts['rm'].'!important;"><a href="'.$url.'" onclick="'.$open_content.'"><span class="icon-hauicon-share33 ha-share-icon"></span><span> LinkedIn</span></a></div>';
}

//RSSフィードの場合
if($atts['type'] == 'feed'){
	$url = get_bloginfo('rss2_url');
	return '<div class="ha-share-button share-rss" style="width:'.$atts['width'].'%;margin:'.$atts['margin'].';margin-left:'.$atts['lm'].'!important;margin-right:'.$atts['rm'].'!important;"><a href="'.$url.'" target="_blank"><span class="icon-hauicon-share20 ha-share-icon"></span><span> RSS</span></a></div>';
}

//メールの場合
if($atts['type'] == 'mail'){
	$mail = antispambot(get_bloginfo('admin_email'));
	$url = get_permalink();
	$sub = '「'.get_the_title(url_to_postid($url)).'（'.$url.'）」について';
	$body = '%0d%0a-------- ここから上にメッセージ本文ををお書きください ----------%0d%0a';
	return '<div class="ha-share-button share-email" style="width:'.$atts['width'].'%;margin:'.$atts['margin'].';margin-left:'.$atts['lm'].'!important;margin-right:'.$atts['rm'].'!important;"><a href="mailto:'.$mail.'?subject='.$sub.'&amp;body='.$body.$url.'"><span class="icon-hauicon-share03 ha-share-icon"></span><span> Mail</span></a></div>';
}

//メール（サンプル）の場合
if($atts['type'] == 'blank-mail'){
	$mail = '';
	$url = get_permalink();
	$sub = '「'.get_the_title(url_to_postid($url)).'（'.$url.'）」について';
	$body = '%0d%0a-------- ここから上にメッセージ本文ををお書きください ----------%0d%0a';
	return '<div class="ha-share-button share-email" style="width:'.$atts['width'].'%;margin:'.$atts['margin'].';"><a href="mailto:'.$mail.'?subject='.$sub.'&amp;body='.$body.$url.'"><span class="icon-hauicon-share03 ha-share-icon"></span><span> Mail</span></a></div>';
}
}
add_shortcode('ha-share','hima_art_share_button_sc_init');