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 = "
"; //Add publish button to pages that are unpublished and admin has publish rights if((isset($_GET["preview"]) || $page['approval_status'] == "unapproved") && $api->checkPermission($_SESSION["cms_user_id"], "Approve Updates", "Workflow")) { $admin_bar .= "Preview"; } $admin_bar .= "Edit
View Date:
Versions
Logged in as ".htmlentities($_SESSION["cms_user_name"], ENT_QUOTES)." | Log out

UPDATE CONTENT

"; //Add admin bar code to page $template = str_replace("",$admin_bar."", $template); } /** Populate Dynamic Content on the page **/ if(isset($_GET["date"]) && strtotime($_GET["date"]) && $valid_admin) { //get date range from page items by getting last 2 versions before date specified $page_versions = mysql_query("SELECT * FROM (SELECT V.*, U.name as modified_user FROM cms_item_instance_version V, cms_item_instance I, cms_user U WHERE I.id='".$pageID."' AND V.item_instance_id=I.id AND V.modified_by=U.id AND STR_TO_DATE(V.date_modified,'%a, %e %b %Y %H:%i:%s') < '".date('Y-m-d H:i:s', strtotime(urldecode($_GET["date"])))."' UNION SELECT V.*, U.name as modified_user FROM cms_item_instance_version_archive V, cms_item_instance I, cms_user U WHERE I.id='".$pageID."' AND V.item_instance_id=I.id AND V.modified_by=U.id AND STR_TO_DATE(V.date_modified,'%a, %e %b %Y %H:%i:%s') < '".date('Y-m-d H:i:s', strtotime(urldecode($_GET["date"])))."') A ORDER BY version DESC"); if($page_versions && mysql_num_rows($page_versions) > 0) { $late_date = mysql_result($page_versions,0,'date_modified'); //get newest versions before late date $qry = "SELECT * FROM (SELECT MAX(id) as version_id, item_order FROM (SELECT V.id, V.item_order FROM cms_page_item_instance I, cms_page_item P, cms_page_item_instance_version V WHERE I.item_id=P.id AND I.page_id='".$pageID."' AND V.item_instance_id=I.id AND STR_TO_DATE(SUBSTRING(V.date_modified,1, CHAR_LENGTH(V.date_modified)-6),'%a, %d %b %Y %H:%i:%S') <= STR_TO_DATE('".$late_date."','%a, %d %b %Y %H:%i:%S') AND V.archived='no' UNION SELECT V.id, V.item_order FROM cms_page_item_instance I, cms_page_item P, cms_page_item_instance_version_archive V WHERE I.item_id=P.id AND I.page_id='".$pageID."' AND V.item_instance_id=I.id AND STR_TO_DATE(SUBSTRING(V.date_modified,1, CHAR_LENGTH(V.date_modified)-6),'%a, %d %b %Y %H:%i:%S') <= STR_TO_DATE('".$late_date."','%a, %d %b %Y %H:%i:%S') AND V.archived='no' ) C GROUP BY item_order) A LEFT JOIN (SELECT I.*, P.item_class, V.id as version_id, V.item_order, V.template_hotspot FROM cms_page_item_instance I, cms_page_item P, cms_page_item_instance_version V WHERE I.item_id=P.id AND I.page_id='".$pageID."' AND V.item_instance_id=I.id AND STR_TO_DATE(SUBSTRING(V.date_modified,1, CHAR_LENGTH(V.date_modified)-6),'%a, %d %b %Y %H:%i:%S') <= STR_TO_DATE('".$late_date."','%a, %d %b %Y %H:%i:%S') AND V.archived='no' UNION SELECT I.*, P.item_class, V.id as version_id, V.item_order, V.template_hotspot FROM cms_page_item_instance I, cms_page_item P, cms_page_item_instance_version_archive V WHERE I.item_id=P.id AND I.page_id='".$pageID."' AND V.item_instance_id=I.id AND STR_TO_DATE(SUBSTRING(V.date_modified,1, CHAR_LENGTH(V.date_modified)-6),'%a, %d %b %Y %H:%i:%S') <= STR_TO_DATE('".$late_date."','%a, %d %b %Y %H:%i:%S') AND V.archived='no') B ON A.version_id=B.version_id"; } } else { if($valid_admin) { //load content data for the page $page_content = mysql_query("SELECT I.*, P.item_class, V.item_order, V.template_hotspot FROM cms_page_item_instance I, cms_page_item P, cms_page_item_instance_version V WHERE I.item_id=P.id AND I.page_id='".$pageID."' AND V.item_instance_id=I.id AND I.current_version=V.version AND V.archived='no' ORDER BY item_order"); } else { $page_content = mysql_query("SELECT I.*, P.item_class, V.item_order, V.template_hotspot FROM cms_page_item_instance I, cms_page_item P, cms_page_item_instance_version V WHERE I.item_id=P.id AND I.page_id='".$pageID."' AND V.item_instance_id=I.id AND I.approved_version=V.version AND V.archived='no' ORDER BY item_order"); } } if(!$page_content) { echo mysql_error(); } //include classes that will be used on this page if(mysql_num_rows($page_content) > 0) { mysql_data_seek($page_content,0); } while($item = mysql_fetch_array($page_content)) { include_once($_SERVER['DOCUMENT_ROOT']."/".$config["admin_root"]."/content/class.".$item["item_class"].".php"); } //reset to first row for later iterations /* Find template hotspots */ $file_area = array(); $file_splits = split(" 1) { for($z=0;$z")+1; $stype = "content"; if(strpos($myText,"") !== false) { $stype = "cond"; } else if(strpos($myText,"") !== false) { $stype = "file"; } if($stype == "content") { $fname = substr($myText,$ind,strpos($myText,"")-$ind); } else if($stype == "file") { $fname = substr($myText,$ind,strpos($myText,"")-$ind); } else if($stype == "cond") { $fname = substr($myText,$ind,strpos($myText,"")-($ind-10)); } $page_specific = false; $mobile_match = true; //Test if page specific file if($myText{0} != ">") { if(strstr($myText,"page=") || strstr($myText,"page!=")) $page_specific = true; if(strstr($myText,"device=")) { if((strstr($myText,"phone") && $mobile == "phone") || (strstr($myText,"tablet") && $mobile == "tablet") || (strstr($myText,"desktop") && $mobile == "desktop") || (strstr($myText,"mobile") && ($mobile == "phone" || $mobile == "tablet"))) { $mobile_match = true; } else { $mobile_match = false; } } $page_match = ""; $not_equal_page = false; $pageTest = substr($myText,0,$ind); //test if content should show when not the specified page if(strstr($pageTest,"!=")) { $not_equal_page = true; } $pageSplit = explode('"', $pageTest); //Page specific if(count($pageSplit) > 1) { $page_match = $pageSplit[1]; $myText = substr($myText, strpos($myText,">")); } } if($mobile_match && (!$page_specific || (!$not_equal_page && ($page_match == $link || strstr($page_match,$link."|") || strstr($page_match,"|".$link))) || ($not_equal_page && ($page_match != $link && !strstr($page_match,$link."|") && !strstr($page_match,"|".$link))))) { if($z!=0) { if($stype == "content") { if(mysql_num_rows($page_content) > 0) mysql_data_seek($page_content,0); while($item = mysql_fetch_array($page_content)) { if($item['template_hotspot'] == $fname) { $class = $item['item_class']; $content_item = new $class(); //new body(); if(isset($_GET["preview"]) || $valid_admin) { $content_item->preview = true; } $content_item->setPage($page['id']); $content_item->instance = $item["id"]; if(isset($_GET["date"]) && strtotime($_GET["date"])) { $content_item->setDate($_GET["date"]); } //if content allows inline edit show edit link next to content if($valid_admin && $content_item->allow_inline_edit) { //Hide edit button until it's tested further //echo "Edit this content"; //If they can publish then highlight what change when content allows it if((isset($_GET["preview"]) || $page['approval_status'] == "unapproved") && $api->checkPermission($_SESSION["cms_user_id"], "Approve Updates", "Workflow")) { //$content_item->highlight_updates = true; } } //display content echo $content_item->display(); } } //reset row to 0 for later iterations if(mysql_num_rows($page_content) > 0) mysql_data_seek($page_content,0); } else if($stype == "cond") //just display conditional code { echo substr($myText,1); } else //file { if(strstr($fname,".php")) { include($_SERVER['DOCUMENT_ROOT']."/content/".str_replace("content/","",$fname)); } else { //$api->get_item_instance_by_field("page","permalink",$link,$valid_admin); $item = $api->get_item_instance_by_field("template", "template_name", $fname, $valid_admin); if($item["template_type"] == "piece") { echo html_entity_decode($item["template_content"], ENT_QUOTES); } } } } } //Remove template hotspot tags so they don't show in the generated html if($z != 0) { $myText = substr($myText,1); } if($stype == "content") { echo str_replace($fname."","",$myText); } else if($stype == "cond") { echo str_replace($fname."","",$myText); } else if($stype == "file") { echo str_replace($fname."","",$myText); } } } else { //if no template hotspots just print template and move on to template tags echo $template; } function selfURL() { $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : ""; $protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s; $port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]); return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI']; } function strleft($s1, $s2) { return substr($s1, 0, strpos($s1, $s2)); } /*** Social Sharing ***/ $link = htmlentities(selfURL(), ENT_QUOTES); $soc_facebook = ''; $soc_twitter = ' '; $soc_google = ' '; $soc_linkedin = ' '; $soc_pinterest = ' '; $section = ""; $sec_split = explode("/", $link); if(count($sec_split) > 1) { $section = $api->get_item_instance_by_field("page","permalink",htmlentities($sec_split[3], ENT_QUOTES),$valid_admin); } //Get printed html up to this point in variable so we can do template tag replacement $content=ob_get_contents(); ob_end_clean(); //Create array of template tags $sfind = array( "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "::page_title::", "::page_description::", "::page_keywords::", "::page_name::", "::page_path::", "::section_permalink::", "::section_title::", "::year::", "::page_permalink::", "::breadcrumb::", "::social_facebook::", "::social_twitter::", "::social_google::", "::social_linkedin::", "::social_pinterest::", ""); //Create array of replacements for the template tags $srep = array( $GLOBALS["page_title"], $page['page_description'], $page['keywords'], $GLOBALS["page_name"], $page['page_path'], $section["permalink"], $section["page_name"], date("Y"), $page['permalink'], $GLOBALS["breadcrumb"], $soc_facebook, $soc_twitter, $soc_google, $soc_linkedin, $soc_pinterest, $GLOBALS["page_title"], $page['page_description'], $page['keywords'], $GLOBALS["page_name"], $page['page_path'], $section["permalink"], $section["page_name"], date("Y"), $page['permalink'], $GLOBALS["breadcrumb"], $soc_facebook, $soc_twitter, $soc_google, $soc_linkedin, $soc_pinterest, ""); /*adaptive images replace $doc = new DOMDocument(); $doc->loadHTML($content); $xpath = new DOMXPath($doc); if($mobile == "desktop") { $nodes = $xpath->query('//img[(contains(@src, "desktop="))]'); if(count($nodes) > 0) { foreach($nodes as $node) { $its = explode("desktop=",$node->getAttribute('src')); if(count($its) > 0) { $item = explode("&",$its[1]); array_push($sfind,$node->getAttribute('src')); array_push($srep,$item[0]); } } } } if($mobile == "tablet") { $nodes = $xpath->query('//img[(contains(@src, "tablet="))]'); if(count($nodes) > 0) { foreach($nodes as $node) { $its = explode("tablet=",$node->getAttribute('src')); if(count($its) > 0) { $item = explode("&",$its[1]); array_push($sfind,$node->getAttribute('src')); array_push($srep,$item[0]); } } } } if($mobile == "phone") { $nodes = $xpath->query('//img[(contains(@src, "phone="))]'); if(count($nodes) > 0) { foreach($nodes as $node) { $its = explode("phone=",$node->getAttribute('src')); if(count($its) > 0) { $item = explode("&",$its[1]); array_push($sfind,$node->getAttribute('src')); array_push($srep,$item[0]); } } } } */ //Replace core template tags $content = str_replace($sfind,$srep,$content); //Replace custom template tags (generated by content types through api) $content = str_replace($GLOBALS["template_tags"],$GLOBALS["template_tags_replace"],$content); //Finaly display the html code to the page echo $content; //write to cache if no query string so we don't have to process this page every time if($cacheme) { $fp = fopen($cachefile, 'w'); fwrite($fp, $content); fclose($fp); } } ?>