<?php
$template = <<<END
<!-- haken1_list: haken1一覧 -->
<section class="haken1_list {val item/class}">
<!--{def item/title}-->
<h2>{val item/title}</h2>
<!--{/def}-->
<!--{each item/list}-->
<div class="list2">
<!--{def item/list/image}-->
<figure><img src="user_data/{val item/list/image}" alt=""></figure>
<!--{/def}-->
    <div>
	<h4>
<!--{def item/list/link}-->
	<a href="{val item/list/link}">{val item/list/title}</a>
<!--{/def}-->
<!--{ndef item/list/link}-->
{val item/list/title}
<!--{/ndef}-->
<!--{def item/list/badge}-->
	<span class="icon {val item/list/badge_class}">{val item/list/badge}</span>
<!--{/def}-->
	</h4>
		<dl class="line">
<!--{each item/list/table}-->
		<dt>{val item/list/table/item1}</dt>
		<dd>{val item/list/table/item2}</dd>
<!--{/each}-->
		</dl>
<!--{def item/list/link}-->
<!--p class="c"><a href="{val item/list/link}" class="btn1 block">詳しくみる</a></p-->
<!--{/def}-->
	</div>
</div>
<!--{/each}-->
</section>
END;

$haken1_list = array(
	"title" => "haken1一覧",
	"name" => "haken1_list",			// 名称、重複すると正しく動作しません
	"template" => $template,		// ブロックのテンプレート
	"input" => array(
		"help" => array(
			"title" => "使い方",
			"type" => "comment",
			"link" => DOCUMENT1 . "/?act=haken1_list",
			"class" => "notice",
		),
		"title" => array(
			"title" => "タイトル",
			"type" => "text",
		),
		"class" => array(
			"title" => "背景",
			"type" => "select",
			"list" => array(
				"" => "なし",
				"bg1" => "色1",
				"bg2" => "色2",
				"bg3" => "色3",
			),
		),
		"dummy1" => array(
			"title" => " ",
			"type" => "comment",
		),
		"title1" => array(
			"title" => "タイトル1",
			"type" => "text",
		),
		"image1" => array(
			"title" => "画像1",
			"type" => "image",
		),
		"badge1" => array(
			"title" => "バッジ",
			"type" => "text",
		),
		"badge_class1" => array(
			"title" => "バッジ背景",
			"type" => "select",
            "list" => array(
                "" => "",
                "newicon" => "赤",
                "upicon" => "青",
            ),
		),
		"text1" => array(
			"title" => "内容1",
			"type" => "textarea",
		),
		"link1" => array(
			"title" => "リンク1",
			"type" => "text",
		),
		"dummy2" => array(
			"title" => " ",
			"type" => "comment",
		),
		"title2" => array(
			"title" => "タイトル2",
			"type" => "text",
		),
		"image2" => array(
			"title" => "画像2",
			"type" => "image",
		),
		"badge2" => array(
			"title" => "バッジ",
			"type" => "text",
		),
		"badge_class2" => array(
			"title" => "バッジ背景",
			"type" => "select",
            "list" => array(
                "" => "",
                "newicon" => "赤",
                "upicon" => "青",
            ),
		),
		"text2" => array(
			"title" => "内容2",
			"type" => "textarea",
		),
		"link2" => array(
			"title" => "リンク2",
			"type" => "text",
		),
		"dummy3" => array(
			"title" => " ",
			"type" => "comment",
		),
		"title3" => array(
			"title" => "タイトル3",
			"type" => "text",
		),
		"image3" => array(
			"title" => "画像3",
			"type" => "image",
		),
		"badge3" => array(
			"title" => "バッジ",
			"type" => "text",
		),
		"badge_class3" => array(
			"title" => "バッジ背景",
			"type" => "select",
            "list" => array(
                "" => "",
                "newicon" => "赤",
                "upicon" => "青",
            ),
		),
		"text3" => array(
			"title" => "内容3",
			"type" => "textarea",
		),
		"link3" => array(
			"title" => "リンク3",
			"type" => "text",
		),
		"dummy4" => array(
			"title" => " ",
			"type" => "comment",
		),
		"title4" => array(
			"title" => "タイトル4",
			"type" => "text",
		),
		"image4" => array(
			"title" => "画像4",
			"type" => "image",
		),
		"badge4" => array(
			"title" => "バッジ",
			"type" => "text",
		),
		"badge_class4" => array(
			"title" => "バッジ背景",
			"type" => "select",
            "list" => array(
                "" => "",
                "newicon" => "赤",
                "upicon" => "青",
            ),
		),
		"text4" => array(
			"title" => "内容4",
			"type" => "textarea",
		),
		"link4" => array(
			"title" => "リンク4",
			"type" => "text",
		),
		"dummy5" => array(
			"title" => " ",
			"type" => "comment",
		),
		"title5" => array(
			"title" => "タイトル5",
			"type" => "text",
		),
		"image5" => array(
			"title" => "画像5",
			"type" => "image",
		),
		"badge5" => array(
			"title" => "バッジ",
			"type" => "text",
		),
		"badge_class5" => array(
			"title" => "バッジ背景",
			"type" => "select",
            "list" => array(
                "" => "",
                "newicon" => "赤",
                "upicon" => "青",
            ),
		),
		"text5" => array(
			"title" => "内容5",
			"type" => "textarea",
		),
		"link5" => array(
			"title" => "リンク5",
			"type" => "text",
		),
		"dummy6" => array(
			"title" => " ",
			"type" => "comment",
		),
		"title6" => array(
			"title" => "タイトル6",
			"type" => "text",
		),
		"image6" => array(
			"title" => "画像6",
			"type" => "image",
		),
		"badge6" => array(
			"title" => "バッジ",
			"type" => "text",
		),
		"badge_class6" => array(
			"title" => "バッジ背景",
			"type" => "select",
            "list" => array(
                "" => "",
                "newicon" => "赤",
                "upicon" => "青",
            ),
		),
		"text6" => array(
			"title" => "内容6",
			"type" => "textarea",
		),
		"link6" => array(
			"title" => "リンク6",
			"type" => "text",
		),
		"dummy7" => array(
			"title" => " ",
			"type" => "comment",
		),
		"title7" => array(
			"title" => "タイトル7",
			"type" => "text",
		),
		"image7" => array(
			"title" => "画像7",
			"type" => "image",
		),
		"badge7" => array(
			"title" => "バッジ",
			"type" => "text",
		),
		"badge_class7" => array(
			"title" => "バッジ背景",
			"type" => "select",
            "list" => array(
                "" => "",
                "newicon" => "赤",
                "upicon" => "青",
            ),
		),
		"text7" => array(
			"title" => "内容7",
			"type" => "textarea",
		),
		"link7" => array(
			"title" => "リンク7",
			"type" => "text",
		),
		"dummy8" => array(
			"title" => " ",
			"type" => "comment",
		),
		"title8" => array(
			"title" => "タイトル8",
			"type" => "text",
		),
		"image8" => array(
			"title" => "画像8",
			"type" => "image",
		),
		"badge8" => array(
			"title" => "バッジ",
			"type" => "text",
		),
		"badge_class8" => array(
			"title" => "バッジ背景",
			"type" => "select",
            "list" => array(
                "" => "",
                "newicon" => "赤",
                "upicon" => "青",
            ),
		),
		"text8" => array(
			"title" => "内容8",
			"type" => "textarea",
		),
		"link8" => array(
			"title" => "リンク8",
			"type" => "text",
		),
		"dummy9" => array(
			"title" => " ",
			"type" => "comment",
		),
		"title9" => array(
			"title" => "タイトル9",
			"type" => "text",
		),
		"image9" => array(
			"title" => "画像9",
			"type" => "image",
		),
		"badge9" => array(
			"title" => "バッジ",
			"type" => "text",
		),
		"badge_class9" => array(
			"title" => "バッジ背景",
			"type" => "select",
            "list" => array(
                "" => "",
                "newicon" => "赤",
                "upicon" => "青",
            ),
		),
		"text9" => array(
			"title" => "内容9",
			"type" => "textarea",
		),
		"link9" => array(
			"title" => "リンク9",
			"type" => "text",
		),
		"dummy10" => array(
			"title" => " ",
			"type" => "comment",
		),
		"title10" => array(
			"title" => "タイトル10",
			"type" => "text",
		),
		"image10" => array(
			"title" => "画像10",
			"type" => "image",
		),
		"badge10" => array(
			"title" => "バッジ",
			"type" => "text",
		),
		"badge_class10" => array(
			"title" => "バッジ背景",
			"type" => "select",
            "list" => array(
                "" => "",
                "newicon" => "赤",
                "upicon" => "青",
            ),
		),
		"text10" => array(
			"title" => "内容10",
			"type" => "textarea",
		),
		"link10" => array(
			"title" => "リンク10",
			"type" => "text",
		),
	),
//    "repeat" => array("title", "image", "badge", "badge_class", "text", "link"),
	"func" => "func_haken1_list",
);

block_add($haken1_list);

function func_haken1_list($def, $info)
{
	$list = array();
	for ($i = 1; $i <= 10; $i++) {
		unset($item);
		foreach (array("title", "image", "badge", "badge_class", "text", "link") as $key) {
			if ($info[$key . $i]) {		// 値がある
				if ($def["input"][$key . $i]["type"] == "image") {
					$f = Image::getData($info[$key . $i]);
					$item[$key] =  $f["save_name"];
				} else if ($key == "text") {
					$ary = explode("\n", trim($info[$key . $i]));
					$vals = array();
					foreach ($ary as $val) {
						if (trim($val)) {
							unset($v);
							$ary2 = explode("|", trim($val));
							$v["item1"] = trim($ary2[0]);
							$v["item2"] = trim($ary2[1]);
							$vals[] = $v;
						}
					}
				} else {
					$item[$key] = $info[$key . $i];
				}
				if ($vals) {
					$item["table"] = $vals;
				}
			}
		}
		if ($item) {
			$list[] = $item;
		}
	}
	if ($list) {
		$info["list"] = $list;
	}
	return $info;
}