ob_start(); session_start(); error_reporting(0); include_once("includes/site.config.php"); require_once $_SERVER['DOCUMENT_ROOT'].'/includes/Mobile_Detect.php'; $detect = new Mobile_Detect; $mobile = ($detect->isMobile() ? ($detect->isTablet() ? 'tablet' : 'phone') : 'desktop'); //cache time in hours comes from config file $cachetime = $config["cache_time"] * 60 * 60; $cacheme = true; $fname = ""; $page_perm = htmlentities($_GET["page"], ENT_QUOTES); //If there is a query param don't cache if(!strstr($_SERVER['REQUEST_URI'],"?") && !isset($_SESSION["cms_user_id"]) && $config["cache_site"] && !strstr($page_perm,".")) { //create cache file name from url $fname = "ch_".htmlentities(str_replace(array("/".$page_perm."/","/".$page_perm,"/"),array("_[".$page_perm."]","_[".$page_perm."]","_"),$_SERVER['REQUEST_URI']), ENT_QUOTES)."_".$mobile; $cachefile = "cache/".$fname.".html"; // Serve from the cache if it is younger than $cachetime if (file_exists($cachefile) && (time() - $cachetime < filemtime($cachefile))) { echo file_get_contents($cachefile); //include($cachefile); echo ""; ob_end_flush(); exit; } } else { $cacheme = false; } /*************************************************** * Create a fresh copy of the page ***************************************************/ include_once($config["admin_root"]."/includes/class.content.php"); include_once($config["admin_root"]."/includes/db_connection.php"); include_once($config["admin_root"]."/includes/class.API.php"); //Setup api variable for all classes $api = new API(); //Setup global variables $GLOBALS["template_tags"] = array(); $GLOBALS["template_tags_replace"] = array(); $GLOBALS["template_scripts"] = ""; $GLOBALS["permalink"] = ""; $valid_admin = false; //test for shortened url if(isset($_GET["arg1"]) && $_GET["arg1"] == "!") { $redirect = mysql_query("SELECT * FROM mod_short_urls WHERE short_url='".$page_perm."'"); if($redirect && mysql_num_rows($redirect) > 0) { $row = mysql_fetch_array($redirect); header("Location: ".$row["full_url"]); exit(); } } else { //Get current page from permalink $link = "home"; if(isset($_GET["page"])) { $link = str_replace("/","",htmlentities($_GET["page"], ENT_QUOTES)); } $date = ""; //Get site settings from database to test for under construction $site = $api->get_item("site_settings"); if($site['published'] == "no") { if($site['unpublished_page'] != "") { $uc = $api->get_item_instance($site["unpublished_page"]); if($link != $uc["permalink"]) header("Location: ".$uc['page_path']); } } //Get information about the current page $page = $api->get_item_instance_by_field("page","permalink",$link,$valid_admin); //redirect to 404 page if page not found or home if no 404 is set if(!$page || count($page) == 0 || $page["published"] == "no") { if($site['404_page'] != "") { $np = $api->get_item_instance($site["404_page"]); header("Location: ".$np['page_path']."?e=".$page_perm); } else { header("Location: /"); } $cacheme = false; //header("Location: /"); } if($page["cache_page"] == "no") { $cacheme = false; } if(isset($_GET["date"]) && strtotime($_GET["date"]) && $valid_admin) { $date = urldecode($_GET["date"]); } /** Check if admin is logged in and if so check if they have access to edit this page **/ if(isset($_SESSION["cms_user_id"]) && is_numeric($_SESSION["cms_user_id"]) && isset($_SESSION["cms_user_token"])) { $loginCheck = mysql_query("SELECT id FROM cms_user WHERE login_token='".htmlentities($_SESSION["cms_user_token"], ENT_QUOTES)."' and id='".htmlentities($_SESSION["cms_user_id"], ENT_QUOTES)."'"); if($loginCheck && mysql_num_rows($loginCheck) == 1) { if($page['group_access'] == "" || strstr($page['group_access'],'::all::') || strstr($page['group_access'],"::".htmlentities($_SESSION["cms_user_group"], ENT_QUOTES)."::")) { $valid_admin = true; } } } $template_info = $api->get_item_instance($page["template"], $valid_admin, $date); $template = html_entity_decode($template_info["template_content"], ENT_QUOTES); //Get information about parent page if($page['parent_page'] != "" && $page['parent_page'] != "-1") { $parent = $api->get_item_instance($page['parent_page'], $valid_admin, $date); if($parent) { $parent_page = $parent['permalink']; $parent_id = $parent['id']; } } $pageID = $page["id"]; /* Set Page Information for template tags */ $GLOBALS["permalink"] = $page["permalink"]; $GLOBALS["page_title"] = $page['page_title']; $GLOBALS["page_name"] = html_entity_decode($page['page_name'], ENT_QUOTES); // Create Breadcrumb $bread_levels = 12; $bread_spot = 0; $bread_build = ""; $GLOBALS["breadcrumb"] = $bread_build; //If they are an admin and have access to the page create admin bar and inline update options if($valid_admin) { //Include admin bar stylesheet $template = str_replace("","", $template); $admin_bar = "