<?php

define('WP_PATH', '../../../../../../');

require_once( WP_PATH . 'wp-load.php');

define('WP_URL', site_url());

if (!is_user_logged_in() || !current_user_can('edit_posts'))
	die();

function load_script($handle) {
	global $wp_scripts;

	if (!$wp_scripts)
		die('No $wp_scripts!');

	$src = site_url() . $wp_scripts->registered[$handle]->src;
	echo '<script type="text/javascript" src="', $src, '?ver=', uniqid() , '"></script>';
}

?>
<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="content-type" content="text/html; charset=utf-8">

	<script type="text/javascript">
		function convertThisEntities(b){var d,a;d=function(c){if(/&[^;]+;/.test(c)){var f=document.createElement("div");f.innerHTML=c;return !f.firstChild?c:f.firstChild.nodeValue}return c};if(typeof b==="string"){return d(b)}else{if(typeof b==="object"){for(a in b){if(typeof b[a]==="string"){b[a]=d(b[a])}}}}return b};
		var thickboxL10n = {
			next: "Next >",
			prev: "< Prev",
			image: "Image",
			of: "of",
			close: "Close",
			closeImage: "<?php echo WP_URL; ?>" + "/wp-includes/js/thickbox/tb-close.png",
			loadingAnimation: "<?php echo WP_URL; ?>" + "/wp-includes/js/thickbox/loadingAnimation.gif"
		};
		try {
			convertThisEntities(thickboxL10n);
		} catch(e) {};
	</script>

	<link rel="stylesheet" type="text/css" href="<?php echo CORE_URI; ?>/slider/slider-builder.css" media="screen">
	<link rel="stylesheet" type="text/css" href="<?php echo THEME_URI; ?>/tdframework/css/font-awesome.min.css" media="screen">
	<link rel="stylesheet" type="text/css" href="<?php echo WP_URL; ?>/wp-includes/js/thickbox/thickbox.css" media="screen">

	<?php

		// Some plugins (BuddyPress!) unset $wp_scripts
		global $wp_scripts;
		if (!isset($wp_scripts)) {
			$wp_scripts = new WP_Scripts();
		}

		// Load local scripts manually
		load_script('jquery');
		load_script('jquery-core'); // will be used in WP3.6
		load_script('json2');
		load_script('jquery-ui-core');
		load_script('jquery-ui-widget');
		load_script('jquery-ui-mouse');
		load_script('jquery-ui-sortable');
		load_script('thickbox');
		load_script('media-upload');

		// Slider settings
		$slider_name = $_GET['name'];
		$slider_slug = $_GET['slug'];
		$slider_type = $_GET['slider'];
		$slider_settings = get_option('core_slider_' .$slider_slug, '{}');

		// Write script
		echo '<script type="text/javascript">';
			echo 'window.sliderSlug = "', $slider_slug, '";';
			echo 'window.sliderName = "', $slider_name, '";';
			echo 'window.sliderType = "', $slider_type, '";';
			echo 'window.sliderSettings = "', $slider_settings, '";';
			echo 'window.nonce = "' . wp_create_nonce('core-slider-save'). '";';
			echo 'window.ajaxurl = "' . admin_url('admin-ajax.php'). '";';
			echo 'window.blogurl = "' . esc_url( home_url() ) . '";';
		echo '</script>';
	?>

	<script type="text/javascript" src="<?php echo CORE_URI; ?>/slider/slider-builder.js"></script>
</head>

<body>

<div id="header"><?php echo $slider_name; ?></div>

<!-- Slider settings -->
<ul id="core-slider-settings">
</ul>

<!-- Slides -->
<div id="core-slider-slides">
</div>

<!-- Add new slide -->
<a href="#" class="core-slide-add"><i class="icon-plus-sign fa fa-plus-sign"></i> Add slide</a>

<!-- Save slider -->
<br>
<p id="save-result"></p>

<!-- Slide template -->
<div class="core-slider-slide core-slide-template">
</div>

<!-- Layer template -->
<table>
	<tr class="core-slidertable-row core-layer-template">
	</tr>
</table>

</body>
</html>