<?php

/**
 *
 * @copyright  2010-2016 izend.org
 * @version    20
 * @link       http://www.izend.org
 */
?>
<?php
foreach ($contents as $c) {
	switch($c['type']) {
		case 'text':
			$s = $c['text'];
			if ($s) {
				echo $s, PHP_EOL;
			}
			break;
		case 'file':
			$file_content = $c['file'];
			if ($file_content) {
				echo '<div class="file">', PHP_EOL, $file_content, PHP_EOL,'</div>', PHP_EOL;
			}
			break;
		case 'download':
			$file = htmlspecialchars($c['file'], ENT_COMPAT, 'UTF-8');
			$download_url = $c['download_url'];
			echo '<div class="download">', PHP_EOL, '<a href="', $download_url, '" rel="nofollow">', $file, '</a>', PHP_EOL, '</div>', PHP_EOL;
			break;
		case 'infile':
			@include $c['infile'];
			break;
		case 'youtube':
			require_once 'ishttps.php';

			extract($c);	/* id width height miniature title autoplay theme controls fs rel */
			$autoplay=$autoplay ? '1' : '0';
			$controls=$controls ? '1' : '0';
			$fs=$fs ? '1' : '0';
			$rel=$rel ? '1' : '0';
			$padding=round($height/$width, 4) * 100;
			$url=(is_https() ? 'https' : 'http') . "://www.youtube.com/embed/$id?wmode=transparent&amp;autoplay=$autoplay&amp;autohide=1&amp;controls=$controls&amp;fs=$fs&amp;modestbranding=0&amp;showinfo=0&amp;rel=$rel&amp;theme=$theme";
			$embed=<<<__MARK__
<div style="padding-bottom:${padding}%;"><iframe frameborder="0" width="$width" height="$height" src="$url"></iframe></div>
__MARK__;
			if ($miniature) {
				$ytid = uniqid('id');
				echo '<div id="', $ytid, '" class="youtube" style="width:', $width, 'px;max-width:100%;" title="', htmlspecialchars($title, ENT_COMPAT, 'UTF-8'), '">', PHP_EOL;
				echo '<a href="https://www.youtube.com/watch?v=', $id, '"><span class="ytplay"></span><img src="', $base_path, $miniature, '" alt="" /></a>', PHP_EOL;
				echo '</div>', PHP_EOL;
				echo '<script type="text/javascript">', PHP_EOL;
				echo '//<![CDATA[', PHP_EOL;
				echo 'var div=$("#', $ytid, '");', PHP_EOL;
				echo 'div.html(div.children().html());', PHP_EOL;
				echo 'div.children().click(function() { div.html(\'', $embed, '\'); })', PHP_EOL;
				echo '//]]>', PHP_EOL;
				echo '</script>', PHP_EOL;
			}
			else {
				echo '<div class="youtube" style="width:', $width, 'px;max-width:100%;">', PHP_EOL;
				echo $embed, PHP_EOL;
				echo '</div>', PHP_EOL;
			}
			break;
		case 'longtail':
			extract($c);	/* file image width height skin icons controlbar duration autostart repeat */
			$id = uniqid('id');
			echo '<div class="longtail">', PHP_EOL;
			echo '<div id="', $id, '"></div>', PHP_EOL;
			echo '<script type="text/javascript">', PHP_EOL;
			echo '//<![CDATA[', PHP_EOL;
			echo 'var w=', $width,', h=', $height, ', maxw=$(window).innerWidth();', PHP_EOL;
			echo 'if (maxw < w) {', PHP_EOL;
			echo '    h=Math.floor(h*maxw/w);', PHP_EOL;
			echo '    w=maxw;', PHP_EOL;
			echo '}', PHP_EOL;
			echo 'jwplayer("', $id, '").setup({', PHP_EOL;
			if (true) {
				echo '    flashplayer: "', $base_path, '/longtail/player.swf",', PHP_EOL;
			}
			echo '    id: "', $id, '",', PHP_EOL;
			echo '    width: w,', PHP_EOL;
			echo '    height: h,', PHP_EOL;
			if ($image) {
				echo '    image: "', $base_path, $image, '",', PHP_EOL;
			}
			if (false) {
				echo '    modes: [', PHP_EOL;
				echo '        { type: "html5" },', PHP_EOL;
				echo '        { type: "flash", src: "', $base_path, '/longtail/player.swf" },', PHP_EOL;
				echo '        { type: "download" },', PHP_EOL;
				echo '    ],', PHP_EOL;
			}
			$levels=preg_split('/[\s]+/', $file);
			switch (count($levels)) {
				case 1:
					echo '    file: "', $base_path, $file, '",', PHP_EOL;
					break;
				default:
					echo '    levels: [', PHP_EOL;
					foreach ($levels as $file) {
						echo '        { file: "', $base_path, $file, '" },', PHP_EOL;
					}
					echo '    ],', PHP_EOL;
					break;
			}
			if ($duration) {
				echo '    duration: "', $duration, '",', PHP_EOL;
			}
			if ($skin) {
				echo '    skin: "', $base_path, $skin, '",', PHP_EOL;
			}
			echo '    controlbar: "', $controlbar, '",', PHP_EOL;
			echo '    icons: "', $icons ? 'true' : 'false', '",', PHP_EOL;
			echo '    repeat: "', $repeat ? 'always' : 'none', '",', PHP_EOL;
			echo '    autostart: "', $autostart ? 'true' : 'false', '",', PHP_EOL;
			echo '    screencolor: "ffffff"', PHP_EOL;
			echo '});', PHP_EOL;
			echo '//]]>', PHP_EOL;
			echo '</script>', PHP_EOL;
			echo '</div>', PHP_EOL;
			break;
		case 'sms':
			$text = $c['text'];
			if ($text) {
				require_once 'filtersms.php';

				list(, $coding, $msglen, $count, $len)=filtersms($text);

				echo '<div class="sms">', PHP_EOL;
				echo '<p id="sms_params">', PHP_EOL;
				echo "$msglen / $len &nbsp;-&nbsp $count SMS $coding", PHP_EOL;
				echo '</p>', PHP_EOL;
				echo '<p>', nl2br(htmlspecialchars($text, ENT_COMPAT, 'UTF-8')), '</p>', PHP_EOL;
				echo '</div>', PHP_EOL;
			}
			break;
		default:
			break;
	}
}
?>
