<?php
$template = <<<END
<!--{def item/title}-->
<h3>{val item/title}</h3>
<!--{/def}-->
<!--{def item/image}-->
<!--{def item/image_movie_file}-->
<video src="{val item/image_movie_file}" autoplay loop muted playsinline>
<!--{/def}-->
<!--{def item/image_file}-->
<img src="{val item/image_file}">
<!--{/def}-->
<!--{/def}-->
END;

$block_side_image = array(
	"title" => "サイド画像",
	"name" => "block_side_image",	// 名称、重複すると正しく動作しません
	"template" => $template,		// ブロックのテンプレート
	"type" => "@side",				// この名称のページのみで使用可能
	"output" => "side_contents",	// 出力場所
	"input" => array(
		"help" => array(
			"title" => "使い方",
			"type" => "comment",
			"link" => DOCUMENT1 . "/?act=block_side_image",
			"class" => "notice",
		),
		"title" => array(
			"title" => "タイトル",
			"type" => "text",
		),
		"image" => array(
			"title" => "画像",
			"type" => "file",
			"info" => "画像と動画(MP4)が使えます",
		),
	),
	"func" => "func_block_side_image",
);

block_add($block_side_image);

function func_block_side_image($def, $info)
{
	if ($info["image"]) {
		$f = Image::getData(intval($info["image"]));
		if ($f) {
			if ($f["filetype"] == "video/mp4") {
				$info["image_movie_file"] = "user_data/" . $f["save_name"];
			} else {
				$info["image_file"] = "user_data/" . $f["save_name"];
			}
		}
	}
	return $info;
}
