<?php
$template = <<<END
<!-- recipe1_newspopup:お知らせ(ポップアップ) -->
<section class="recipe1_newspopup">
<div class="list-free">
<!--{def item/title}-->
<h2>{val item/title}<span>{val item/subtitle}</span></h2>
<!--{/def}-->
<dl class="new1-maru">
<!--{each item/newinfo}-->
<dt>{val item/newinfo/news_date}<!--{def item/newinfo/kind}--><span<!--{def item/newinfo/color}--> class="{val item/newinfo/color}"<!--{/def}-->>{val item/newinfo/kind}</span><!--{/def}--></dt>
<dd><a href="javascript:void(null)" onClick="popup('{val item/newinfo/news_date}', '{val item/newinfo/title}', '{rval item/newinfo/contents}', '{val item/newinfo/url}', '{val item/newinfo/image}')">{val item/newinfo/title}</a></dd>
<!--{/each}-->
</dl>
</div>
<!--/.list-free-->
<!-- ポップアップ要素 -->
<div class="popup-maru overlay" id="popup_{val id}" style="display: none;">
<div>
<h3 id="{val id}_title">タイトル</h3>
<p id="{val id}_contents">ポップアップの外側をクリックした場合も閉じるようにしました。</p>
<p><img src="" alt="" id="{val id}_image"></p>
<p class="c btn1-maru" id="{val id}_link"><a href="" id="{val id}_url">詳しくはこちら</a></p>
<i class="fa-solid fa-xmark close-maru"></i>
</div>
</div>
</section>
<script>
function popup(date, title, contents, url, image)
{
//	$('#{val id}_date').html(date);
	$('#{val id}_title').html(date + "<br>" + title);
	$('#{val id}_contents').html(contents);
	if (url != '') {
		$('#{val id}_url').attr('href', url);
	} else {
		$('#{val id}_link').hide();
	}
	$('#{val id}_image').attr('src', image);
    $('#popup_{val id}').fadeIn(); // ポップアップを表示
}
</script>
END;

$recipe1_newspopup = array(
		"title" => "お知らせ(ポップアップ)",
		"name" => "recipe1_newspopup",			// 名称、重複すると正しく動作しません
		"template" => $template,		// ブロックのテンプレート
		"input" => array(
		"help" => array(
			"title" => "使い方",
			"type" => "comment",
			"link" => DOCUMENT1 . "/?act=recipe1_newspopup",
			"class" => "notice",
		),
		"notice1" => array(
			"title" => "このブロックは1ページに1つしか使えません",
			"type" => "comment",
			"class"=> "notice",
		),
		"title" => array(
			"title" => "タイトル",
			"type" => "text",
		),
		"subtitle" => array(
			"title" => "サブタイトル",
			"type" => "text",
		),
		"info_num" => array(
			"title" => "表示数",
			"type" => "text",
		),
	),
	"func" => "func_recipe1_newspopup",		// 処理プログラム（指定がない物は標準処理）
);

block_add($recipe1_newspopup);

// お知らせの取得
function func_recipe1_newspopup($def, $info)
{
	$login = get_setup();
	$kiji_list = array("" => "");
	$kiji_color = array("" => "");
	for ($i = 1; $i <= 10; $i++) {
		if (trim($login["news" . $i])) {
			$ary = explode("|", trim($login["news" . $i]));
			$kiji_list[$i] = $ary[0];
			$kiji_color[$i] = $ary[1];
		}
	}
	//
	$num = intval($info["info_num"]);
	if ($num) {
		$info["newinfo"] = get_newinfo(($setup["info_max"] == "")?$num:$setup["info_max"]);
	}
	if (is_array($info["newinfo"])) {
		foreach ($info["newinfo"] as $key => $val) {
			if ($info["newinfo"][$key]["image"]) {
				$f = Image::getData($info["newinfo"][$key]["image"]);
				if ($f) {
					$info["newinfo"][$key]["image"] = "user_data/" . $f["save_name"];
				}
			}
			$info["newinfo"][$key]["contents"] = str_replace("\r", "", str_replace("\n", "<br>", trim($val["contents"])));
			$info["newinfo"][$key]["kind"] = $kiji_list[$val["kind"]];
			$info["newinfo"][$key]["color"] = "bgcolor-" . $kiji_color[$val["kind"]] . "-maru";
		}
	}
	return $info;
}
