ob_start(); session_start(); include_once("includes/site.config.php"); //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); $cachefile = "cache/".$fname.".html"; // Serve from the cache if it is younger than $cachetime if (file_exists($cachefile) && (time() - $cachetime < filemtime($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']); } else { header("Location: /"); } //header("Location: /"); } if($page["cache_page"] == "no") { $cacheme = false; } if(isset($_GET["date"]) && strtotime($_GET["date"]) && $valid_admin) { $date = urldecode($_GET["date"]); } //print_r($page); /********* FACEBOOK INFO *************/ if($page["page_type"] == "facebook") { $app = $api->get_item_instance($page["app"]); if(isset($_REQUEST["signed_request"])) { $data = parse_signed_request($_REQUEST["signed_request"], $app['app_key']); $clientID = $data["page"]["id"]; $_SESSION["client_id"] = $clientID; $_SESSION["user_id"] = $data["user_id"]; $like_status = $data["page"]["liked"]; $_SESSION["is_fan"] = $like_status; } else if(isset($_SESSION["client_id"])) { $clientID = htmlentities($_SESSION["client_id"], ENT_QUOTES); $like_status = $_SESSION["is_fan"]; } // $clientID = "115524038161"; //For Testing $client = $api->get_item_instance_by_field("clients","facebook_id",$clientID, true); $client_apps = $api->get_item_instance_list("client_apps",false);//$api->get_item_instance_by_field("client_apps","client_id", $clientID, true); $client_app = ""; foreach($client_apps as $capp) { if($capp["app_id"] == $app["id"] && $capp["client_id"] == $client["id"] && $app["published"] == "yes") { $client_app = $capp; $s_arr = array(); $s_arr["id"] = $capp["id"]; $s_arr["app_name"] = $capp["app_name"]; $s_arr["app_state"] = $capp["app_state"]; $_SESSION["app"] = $s_arr; break; } } //print_r($client_app); } /********** END FACEBOOK ************/ /** 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 = "