<?php
chdir(dirname(dirname(__FILE__)));
if (isset($_GET['cpanel'])) {
	$files = array(
		'js/ext/ux/ScriptLoader.js',
		'js/cpanel/ext.overrides.js',
		'js/cpanel/app.js',
		'js/cpanel/tree.js',
		'js/cpanel/grid.js',
		'js/cpanel/layout.js',
		'js/fileman/user_chooser.js',
		'js/cpanel/userslist.comp.js',
		'js/cpanel/editform.comp.js',
		'js/genpass.js'
	);
} else if (isset($_GET['extjs'])) {
	if (isset($_GET['debug'])) {
		$files = array(
			'js/ext/adapter/ext/_ext-base-debug.js',
			'js/ext/_ext-all-debug-w-comments.js',
			'js/ext/ux/overrides.js',
			'js/ext/ux/LocalStorage.js',
			'js/ext/ux/FileRunPrompt.js'
		);
	} else {
		$files = array(
			'js/ext/adapter/ext/ext-base.js',
			'js/ext/ext-all.js',
			'js/ext/ux/overrides.js',
			'js/ext/ux/LocalStorage.js',
			'js/ext/ux/FileRunPrompt.js'
		);
	}
} else if (isset($_GET['weblink_gallery'])) {
		$files = array(
			'js/jquery/jquery.min.js',
			'js/jquery/fancybox/jquery.fancybox.pack.js',
			'js/jquery/fancybox/helpers/jquery.fancybox-buttons.js',
			'js/jquery/fancybox/helpers/jquery.fancybox-thumbs.js',
			'js/jquery/collagePlus/jquery.collagePlus.min.js',
			'js/jquery/collagePlus/extras/jquery.removeWhitespace.min.js',
			'js/weblink.js',
			'js/imagesloaded.pkgd.min.js'
		);
} else if (isset($_GET['plupload'])) {
	$files = array(
		'js/plupload/plupload.full.min.js',
		'js/ext/ux/pluploadpanel/PluploadPanel.js',
		'js/fileman/plupload.js'
	);
} else if (isset($_GET['mobile'])) {
	$files = array(
		'js/stouch/sencha-touch-all.js',
		'js/stouch/ux/overrides.js',
		'js/mobile/app.js',
		'js/mobile/models/File.js',
		'js/mobile/stores/FileList.js',
		'js/mobile/views/Main.js',
		'js/mobile/views/LoginForm.js',
		'js/mobile/views/FileList.js',
		'js/mobile/views/UploadForm.js',
		'js/mobile/views/FilePanel.js',
		'js/mobile/controllers/app.js',
		'js/mobile/controllers/FileList.js',
		'js/mobile/controllers/FilePanel.js'
	);
} else if (isset($_GET['flow'])) {
	if (isset($_GET['debug'])) {
		$files[] = 'js/flow/_flow.js';
		$files[] = 'js/flow/_flowfile.js';
		$files[] = 'js/flow/_flowchunk.js';
		$files[] = 'js/flow/_flowext.js';
	} else {
		$files[] = 'js/flow/all.min.js';
	}
} else if (isset($_GET['flow-standalone'])) {
	if (isset($_GET['debug'])) {
		$files[] = 'js/flow/_flow.js';
		$files[] = 'js/flow/_flowfile.js';
		$files[] = 'js/flow/_flowchunk.js';
	} else {
		$files[] = 'js/flow/all-standalone.min.js';
	}
} else {
	$files = array(
		'js/ext/ux/ProgressColumn/ProgressColumn.js',
		'js/ext/ux/GridDragSelector.js',
		'js/fileman/filerun.js',
		'js/fileman/toolbars_and_menus.js',
		'js/fileman/grid.js',
		'js/fileman/tree.js',
		'js/fileman/info_panel.js',
		'js/fileman/details_panel.js',
		'js/fileman/download_cart.js',
		'js/fileman/activity_panel.js',
		'js/fileman/comments_panel.js',
		'js/fileman/layout.js',
		'js/fileman/ui_utils.js',
		'js/fileman/actions.js',
		'js/fileman/image_viewer.js'
	);
	if (isset($_GET['debug'])) {
		$files[] = 'js/flow/_flow.js';
		$files[] = 'js/flow/_flowfile.js';
		$files[] = 'js/flow/_flowchunk.js';
		$files[] = 'js/flow/_flowext.js';
	} else {
		$files[] = 'js/flow/all.min.js';
	}
}

if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], "gzip") && extension_loaded('zlib')) {
	ob_start("ob_gzhandler");
} else {
	ob_start();
}

header("Content-Type: application/javascript; charset=UTF-8");
header("Cache-control: public");
header("Pragma: cache");
header("Expires: " . gmdate ("D, d M Y H:i:s", time() + 31356000) . " GMT");

foreach ($files as $key => $file) {
	readfile($file);
	echo "\r\n";
}

ob_end_flush();