<?php
$template = <<<END
<!--block_imagetext:画像＋記事-->
<section class="block_imagetext">
<!--{def item/title}-->
<h2>{val item/title}</h2>
<!--{/def}-->
<div class="list-normal">
<!--{each item/items}-->
<div class="list">
<!--{def item/items/image_file}-->
<figure><img src="user_data/{val item/items/image_file}" alt="{val item/items/image_name}"></figure>
<!--{/def}-->
<div class="text">
<!--{def item/items/title}-->
<h4>{val item/items/title}</h4>
<!--{/def}-->
<!--{def item/items/text}-->
<p class="markdown-body">{rval item/items/text}</p>
<!--{/def}-->
</div>
</div>
<!--{/each}-->
</div>
</section>
END;

$block_imagetext = array(
		"title" => "画像＋記事",
		"name" => "block_imagetext",
		"template" => $template,		// ブロックのテンプレート
		"input" => array(
		"help" => array(
			"title" => "使い方",
			"type" => "comment",
			"link" => DOCUMENT1 . "/?act=block_imagetext",
			"class" => "notice",
		),
			"title" => array(
				"title" => "見出し",
				"type" => "text",
			),
			"dummy1-1" => array(
				"title" => " ",
				"type" => "comment",
			),
			"item1_title" => array(
				"title" => "タイトル1",
				"type" => "text",
			),
			"item1_image" => array(
				"title" => "画像1",
				"type" => "image",
			),
			"item1_text" => array(
				"title" => "説明1",
				"type" => "textarea",
			),
			"dummy1-2" => array(
				"title" => " ",
				"type" => "comment",
			),
			"item2_title" => array(
				"title" => "タイトル2",
				"type" => "text",
			),
			"item2_image" => array(
				"title" => "画像2",
				"type" => "image",
			),
			"item2_text" => array(
				"title" => "説明2",
				"type" => "textarea",
			),
			"dummy1-3" => array(
				"title" => " ",
				"type" => "comment",
			),
			"item3_title" => array(
				"title" => "タイトル3",
				"type" => "text",
			),
			"item3_image" => array(
				"title" => "画像3",
				"type" => "image",
			),
			"item3_text" => array(
				"title" => "説明3",
				"type" => "textarea",
			),
			"dummy1-4" => array(
				"title" => " ",
				"type" => "comment",
			),
			"item4_title" => array(
				"title" => "タイトル4",
				"type" => "text",
			),
			"item4_image" => array(
				"title" => "画像4",
				"type" => "image",
			),
			"item4_text" => array(
				"title" => "説明4",
				"type" => "textarea",
			),
			"dummy1-5" => array(
				"title" => " ",
				"type" => "comment",
			),
			"item5_title" => array(
				"title" => "タイトル5",
				"type" => "text",
			),
			"item5_image" => array(
				"title" => "画像5",
				"type" => "image",
			),
			"item5_text" => array(
				"title" => "説明5",
				"type" => "textarea",
			),
			"dummy1-6" => array(
				"title" => " ",
				"type" => "comment",
			),
			"item6_title" => array(
				"title" => "タイトル6",
				"type" => "text",
			),
			"item6_image" => array(
				"title" => "画像6",
				"type" => "image",
			),
			"item6_text" => array(
				"title" => "説明6",
				"type" => "textarea",
			),
			"dummy1-7" => array(
				"title" => " ",
				"type" => "comment",
			),
			"item7_title" => array(
				"title" => "タイトル7",
				"type" => "text",
			),
			"item7_image" => array(
				"title" => "画像7",
				"type" => "image",
			),
			"item7_text" => array(
				"title" => "説明7",
				"type" => "textarea",
			),
			"dummy1-8" => array(
				"title" => " ",
				"type" => "comment",
			),
			"item8_title" => array(
				"title" => "タイトル8",
				"type" => "text",
			),
			"item8_image" => array(
				"title" => "画像8",
				"type" => "image",
			),
			"item8_text" => array(
				"title" => "説明8",
				"type" => "textarea",
			),
			"dummy1-9" => array(
				"title" => " ",
				"type" => "comment",
			),
			"item9_title" => array(
				"title" => "タイトル9",
				"type" => "text",
			),
			"item9_image" => array(
				"title" => "画像9",
				"type" => "image",
			),
			"item9_text" => array(
				"title" => "説明9",
				"type" => "textarea",
			),
			"dummy1-10" => array(
				"title" => " ",
				"type" => "comment",
			),
			"item10_title" => array(
				"title" => "タイトル10",
				"type" => "text",
			),
			"item10_image" => array(
				"title" => "画像10",
				"type" => "image",
			),
			"item10_text" => array(
				"title" => "説明10",
				"type" => "textarea",
			),
		),
		"func" => "func_block_imagetext",
	);

block_add($block_imagetext);

// 画像＋文章
function func_block_imagetext($def, $info)
{
	$ary = array();
	for ($i = 1; $i <= 10; $i++) {
		unset($item);
		$item["title"] = $info["item" . $i . "_title"];
		$item["text"] = $info["item" . $i . "_text"];
		if ($item["title"] || $item["text"] || $info["item" . $i . "_image"]) {
			$item["image_file"] = $info["item" . $i . "_image_file"];
			$item["image_name"] = $info["item" . $i . "_image_name"];
			$ary[] = $item;
		}
	}
	if ($ary) {
		$info["items"] = $ary;
	}
	return $info;
}
