<?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
 */

$callback = preg_replace('#[^a-z0-9.]#i', '', $callback);
$filename = json_encode($file->getFilename());
$title    = json_encode($file->getTitle());

?>
<script type="text/javascript">
var filename = <?php echo $filename ?>;
var title    = <?php echo $title ?>;
var link     = 'data/mediapool/' + filename;
var callback = '<?php echo $callback ?>' in window.opener ? window.opener['<?php echo $callback ?>'] : null;
var fullName = '';

if (title.length === 0) {
	fullName = filename;
}
else {
	fullName = title;
}

// execute callback (media widget, WYMeditor, ...)
if (callback !== null) {
	callback(filename, fullName, title, link, window);
}

window.close();
</script>
