"; 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 = "
"; //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'); if(mysql_num_rows($page_versions) > 1) { $early_date = mysql_result($page_versions,1,'date_modified'); } } $qry = "SELECT * FROM (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 STR_TO_DATE(V.date_modified,'%a, %e %b %Y %H:%i:%s') <= '".date('Y-m-d H:i:s', strtotime("+15 seconds",strtotime($late_date)))."'"; if($early_date != "") { $qry .= " AND STR_TO_DATE(V.date_modified,'%a, %e %b %Y %H:%i:%s') > '".date('Y-m-d H:i:s', strtotime("-15 seconds",strtotime($early_date)))."'"; } $qry .= " AND V.archived='no' UNION 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_archive V WHERE I.item_id=P.id AND I.page_id='".$pageID."' AND V.item_instance_id=I.id AND STR_TO_DATE(V.date_modified,'%a, %e %b %Y %H:%i:%s') <= '".date('Y-m-d H:i:s', strtotime("+15 seconds",strtotime($late_date)))."'"; if($early_date != "") { $qry .= " AND STR_TO_DATE(V.date_modified,'%a, %e %b %Y %H:%i:%s') > '".date('Y-m-d H:i:s', strtotime("-15 seconds",strtotime($early_date)))."'"; } $qry .= " AND V.archived='no') A ORDER BY item_order"; $page_content = mysql_query($qry); } 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); } $page_specific = false; //Test if page specific file if($myText{0} != ">") { $page_specific = true; $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(!$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,$ind,strpos($myText,"")-$ind); } 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; } /*** Social Sharing ***/ $link = $_SERVER["REQUEST_URI"]; $soc_facebook = ''; $soc_twitter = ' '; $soc_google = ' '; $soc_linkedin = ' '; $soc_pinterest = ' '; //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( "", "", "", "", "", "", "", "", "", "", "", "", ""); //Create array of replacements for the template tags $srep = array( $GLOBALS["page_title"], $page['page_description'], $page['keywords'], $GLOBALS["page_name"], date("Y"), $page['permalink'], $GLOBALS["breadcrumb"], $soc_facebook, $soc_twitter, $soc_google, $soc_linkedin, $soc_pinterest, ""); //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); //do facebook replaces if($page["page_type"] == "facebook") { $fb_build = ""; $tag_find = array(); $tag_replace = array(); //Fix for iframe position on page change $api->addTemplateScript(' $(document).ready(function() { window.scrollTop = 0; }); '); $cdata = explode("",$content); if(count($cdata) > 0) { $fb_build = $cdata[0]; for($c=1;$c")); $ad_name = substr(substr($sp_str,strpos($sp_str,"") + 9),0,strpos(substr($sp_str,strpos($sp_str,"") + 9),"")); $ad_state = substr(substr($sp_str,strpos($sp_str,"") + 10),0,strpos(substr($sp_str,strpos($sp_str,"") + 10),"")); $ad_type = substr(substr($sp_str,strpos($sp_str,"") + 9),0,strpos(substr($sp_str,strpos($sp_str,"") + 9),"")); $ad_tag = substr(substr($sp_str,strpos($sp_str,"") + 8),0,strpos(substr($sp_str,strpos($sp_str,"") + 8),"")); $ad_fan = substr(substr($sp_str,strpos($sp_str,"") + 8),0,strpos(substr($sp_str,strpos($sp_str,"") + 8),"")); if(!$ad_fan || ($ad_fan == "yes" && $like_status) || ($ad_fan == "no" && !$like_status)) { if(strtoupper($client_app["app_state"]) == strtoupper($ad_state) || strtoupper($ad_state) == "ALL") { switch($ad_type) { case "Rich_Text": if($ad_tag) { array_push($tag_find, "::".$ad_tag."::"); array_push($tag_replace, html_entity_decode($client_app["ad_".clean($ad_name)], ENT_QUOTES)); } else { $fb_build .= html_entity_decode($client_app["ad_".clean($ad_name)], ENT_QUOTES); } break; case "Date": if($ad_tag) { array_push($tag_find, "::".$ad_tag."::"); array_push($tag_replace, $client_app["ad_".clean($ad_name)]); } else { $fb_build .= $client_app["ad_".clean($ad_name)]; } break; case "HTML": if($ad_tag) { array_push($tag_find, "::".$ad_tag."::"); array_push($tag_replace, html_entity_decode($client_app["ad_".clean($ad_name)], ENT_QUOTES)); } else { $fb_build .= html_entity_decode($client_app["ad_".clean($ad_name)], ENT_QUOTES); } break; case "Media": $phts = explode("::",$client_app["ad_".clean($ad_name)]); if(count($phts) > 0) { $ptsplit = explode("|",$phts[0]); if(count($ptsplit) > 2) { $photo = $api->get_item_instance($ptsplit[0], true); if($ad_tag) { array_push($tag_find, "::".$ad_tag."::"); array_push($tag_replace, $photo["media_path"]); } else { $fb_build .= "".$photo["media_name"].""; } } } //$api->showMediaButton("ad_".clean($data[0])); //$form->createImageBrowser("ad_".clean($data[0]), $item["ad_".clean($data[0])], "ad_".clean($data[0]), false, ""); break; } } } $fb_build .= substr($cdata[$c],strpos($cdata[$c],"") + 11); } } //replace fb tags $fb_build = str_replace($tag_find,$tag_replace,$fb_build); //echo ""; $content = $fb_build; } //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); } } /**** FACEBOOK FUNCTIONS *******/ function clean($str) { $str = str_replace(array(" ",".","'","&",";","!"),array("_","","","","",""),$str); return $str; } function parse_signed_request($signed_request, $secret) { list($encoded_sig, $payload) = explode('.', $signed_request, 2); // decode the data $sig = base64_url_decode($encoded_sig); $data = json_decode(base64_url_decode($payload), true); if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') { error_log('Unknown algorithm. Expected HMAC-SHA256'); return null; } // check sig $expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true); if ($sig !== $expected_sig) { error_log('Bad Signed JSON signature!'); return null; } return $data; } function base64_url_decode($input) { return base64_decode(strtr($input, '-_', '+/')); } ?>