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

/**
 * @ingroup controller
 */
class sly_Controller_Wymiframe implements sly_Controller_Interface {
	protected $request   = null; ///< sly_Request    the current request
	protected $container = null; ///< sly_Container  the DI container

	public function indexAction() {
		$styles = sly_getArray('stylesheets', 'string');
		$base   = sly_Util_AddOn::assetBaseUri('webvariants/wymeditor');

		$content  = '<html><head>';
		$content .= '<meta charset="utf-8" />';
		$content .= '<title>WYMeditor iframe</title>';
		$content .= '<base href="'.sly_Util_HTTP::getBaseUrl(true).'/" />';
		$content .= '<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />';

		foreach ($styles as $stylesheet) {
			$content .= '<link rel="stylesheet" type="text/css" media="screen" href="'.$stylesheet.'" />';
		}

		if (substr($base, 0, 3) === '../') {
			$base = substr($base, 3);
		}

		$content .= '<link rel="stylesheet" type="text/css" media="screen" href="'.$base.'wymeditor/iframe/default/wymiframe.less" />';
		$content .= '</head>';
		$content .= '<body class="wym_iframe"></body>';
		$content .= '</html>';

		return new sly_Response($content);
	}

	public function checkPermission($action) {
		return true;
	}

	public function setContainer(sly_Container $container) {
		$this->container = $container;
	}

	public function setRequest(sly_Request $request) {
		$this->request = $request;
	}
}
