<?php
if (!defined("ROOT_PATH"))
{
	define("ROOT_PATH", dirname(__FILE__) . '/');
}
require ROOT_PATH . 'app/config/options.inc.php';

require_once PJ_FRAMEWORK_PATH . 'pjAutoloader.class.php';
pjAutoloader::register();

if (!isset($_GET['controller']) || empty($_GET['controller']))
{
	header("HTTP/1.1 301 Moved Permanently");
	if(PJ_IS_WEBSITE == true)
	{
		pjUtil::redirect(PJ_INSTALL_URL . "index.php?controller=pjWebsite&action=pjActionIndex");
	}
}
ob_start();
?>
<!DOCTYPE html>
<html>
	<head>
		<title>Yacht Listing Script - Preview</title>
		<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=8" />
		<meta name="viewport" content="width=device-width, initial-scale=1">
		{YL_META}
	<head>
	<body>
		{YL_LISTINGS}
	</body>
</html>
<?php
if (!isset($_GET['iframe']))
{
	$content = ob_get_contents();
	ob_end_clean();
	ob_start();
}

if (!isset($_GET['controller']) || empty($_GET['controller']))
{
	$_GET["controller"] = "pjListings";
}
if (!isset($_GET['action']) || empty($_GET['action']))
{
	$_GET["action"] = "pjActionIndex";
}
if(isset($pjLang))
{
	$_GET["pjLang"] = $pjLang;
}

$dirname = str_replace("\\", "/", dirname(__FILE__));
include str_replace("app/views/pjLayouts", "", $dirname) . '/ind'.'ex.php';

$meta = '';
$meta_arr = $pjObserver->getController()->get('meta_arr');
if ($meta_arr !== FALSE)
{
	$meta = sprintf('<title>%s</title>
<meta name="keywords" content="%s" />
<meta name="description" content="%s" />',
	    !empty($meta_arr['title']) ? stripslashes($meta_arr['title']) : '',
	    !empty($meta_arr['keywords']) ? htmlspecialchars(stripslashes($meta_arr['keywords'])) : '',
	    !empty($meta_arr['description']) ? htmlspecialchars(stripslashes($meta_arr['description'])) : ''
	);
}
$content = str_replace('{YL_META}', $meta, $content);

if (!isset($_GET['iframe']))
{
	$app = ob_get_contents();
	ob_end_clean();
	ob_start();
	$app = str_replace('$','&#36;',$app);
	echo preg_replace('/\{YL_LISTINGS\}/', $app, $content);
}
?>