<?php
/*
 * Copyright (c) 2013, webvariants GbR, http://www.webvariants.de
 *
 * This file is released under the terms of the MIT license. You can find the
 * complete text in the attached LICENSE file or online at:
 *
 * http://www.opensource.org/licenses/mit-license.php
 */

$name     = sly_html($this->getName());
$id       = sly_html($this->getID());
$filename = $this->getDisplayValue();
$value    = sly_Form_Widget_Media::getFullName($filename);

if ($value === '') {
	$filename = '';
}

$filetypeFilter = '';
$categoryFilter = '';

if (!empty($this->filetypes)) {
	$filetypeFilter = ' data-filetypes="'.implode('|', $this->filetypes).'"';
}

if (!empty($this->categories)) {
	$categoryFilter = ' data-categories="'.implode('|', $this->categories).'"';
}

$cls = 'sly-widget sly-media'.(isset($this->attributes['class']) ? ' '.sly_html($this->attributes['class']) : '');

if ($this->getAttribute('required') === 'required') {
	$cls .= ' required';
}

?>

<span class="<?php echo $cls ?>"<?php echo $filetypeFilter.$categoryFilter ?>>
	<input class="value" type="hidden" name="<?php echo $name ?>" value="<?php echo sly_html($filename) ?>" />
	<input class="name sly-form-text" type="text" value="<?php echo sly_html($value) ?>" readonly="readonly" id="<?php echo $id ?>" />

	<span class="sly-icons"><a href="#" class="fct-open" title="<?php echo t('select_medium') ?>"></a></span>
	<span class="sly-icons"><a href="#" class="fct-add" title="<?php echo t('upload_medium') ?>"></a></span>
	<span class="sly-icons"><a href="#" class="fct-delete" title="<?php echo t('remove_medium') ?>"></a></span>
</span>
