<?php if(!defined('master_script')) die();

/**
 * Settings
 *
 * @category   Backend (actions)
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   2009-03-24
 */

	header('content-type: application/x-javascript');

	$hidden_dirs = array('storage', 'cache');

/**
 * Create JavaScript file list for TinyMCE
 *
 * @category   Backend (actions)
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   2009-04-24
 */

	if($_GET['action'] == 'filelist' && is_dir($_GET['path'])) {
		switch($_GET['type']) {
			case 'images' :
				$function_name = 'tinyMCEImageList';
				$file_type = 'image';
				break;
			case 'multimedia' :
				$function_name = 'tinyMCEMediaList';
				$file_type = 'image';
				break;
			default :
				$function_name = 'tinyMCELinkList';
				$file_type = 'all';
		}

		$files = filelist($_GET['path'], $file_type, $hidden_dirs, $system_data['backend']['hidden files']);
		
		// Create JavaScript array
		$filelist = '';
		
		for($i = 0; $i < count($files); $i++)
			$filelist .= '["' . $files[$i] . '","' . $files[$i] . '"]' . ($i + 1 < count($files) ? ',' : '');
		
		echo 'var ' . $function_name . ' = new Array(' . $filelist . ');';
	}
?>