} $fname = $tpl_name; if (!file_exists($fname)) { die('error preview temp file not found: ' . $fname); return false; } // build pageinfo $fh = fopen($fname, 'r'); $_SESSION['cms_preview_data'] = unserialize(fread($fh, filesize($fname))); fclose($fh); unset($_SESSION['cms_preview']); $pageinfo = PageInfoOperations::LoadPageInfoFromSerializedData($_SESSION['cms_preview_data']); $pageinfo->content_id = '__CMS_PREVIEW_PAGE__'; } if (!is_object($pageinfo)) { $pageinfo = PageInfoOperations::LoadPageInfoByContentAlias($page); } // $page cannot be empty here if (isset($pageinfo) && $pageinfo !== FALSE) { $gCms->variables['pageinfo'] =& $pageinfo; if (isset($pageinfo->template_encoding) && $pageinfo->template_encoding != '') { set_encoding($pageinfo->template_encoding); } if ($pageinfo->content_id > 0) { $manager =& $gCms->GetHierarchyManager(); $node =& $manager->sureGetNodeById($pageinfo->content_id); if (is_object($node)) { $contentobj =& $node->GetContent(true, true, false); if (!$contentobj->IsViewable()) { $url = $contentobj->GetURL(); if ($url != '' && $url != '#') {
function LoadPageInfoByContentAlias($alias) { $result = false; global $gCms; $db =& $gCms->GetDb(); $row = ''; if (is_numeric($alias) && strpos($alias, '.') === FALSE && strpos($alias, ',') === FALSE) { $query = "SELECT c.content_id, c.content_name, c.content_alias, c.menu_text, c.titleattribute, c.hierarchy, c.metadata, c.id_hierarchy, c.prop_names, c.create_date AS c_create_date, c.modified_date AS c_date, c.cachable, c.last_modified_by, t.template_id, t.encoding, t.modified_date AS t_date FROM " . cms_db_prefix() . "templates t INNER JOIN " . cms_db_prefix() . "content c ON c.template_id = t.template_id WHERE (c.content_alias = ? OR c.content_id = ?) AND c.active = 1"; $row =& $db->GetRow($query, array($alias, $alias)); } else { $query = "SELECT c.content_id, c.content_name, c.content_alias, c.menu_text, c.titleattribute, c.hierarchy, c.metadata, c.id_hierarchy, c.prop_names, c.create_date AS c_create_date, c.modified_date AS c_date, c.cachable, c.last_modified_by,t.template_id, t.encoding, t.modified_date AS t_date FROM " . cms_db_prefix() . "templates t INNER JOIN " . cms_db_prefix() . "content c ON c.template_id = t.template_id WHERE c.content_alias = ? AND c.active = 1"; $row =& $db->GetRow($query, array($alias)); } if ($row) { $onepageinfo = new PageInfo(); $onepageinfo->content_id = $row['content_id']; $onepageinfo->content_title = $row['content_name']; $onepageinfo->content_alias = $row['content_alias']; $onepageinfo->content_menutext = $row['menu_text']; $onepageinfo->content_titleattribute = $row['titleattribute']; $onepageinfo->content_hierarchy = $row['hierarchy']; $onepageinfo->content_id_hierarchy = $row['id_hierarchy']; $onepageinfo->content_metadata = $row['metadata']; $onepageinfo->content_created_date = $db->UnixTimeStamp($row['c_create_date']); $onepageinfo->content_modified_date = $db->UnixTimeStamp($row['c_date']); $onepageinfo->content_last_modified_by_id = $row['last_modified_by']; $onepageinfo->content_props = explode(',', $row['prop_names']); $onepageinfo->template_id = $row['template_id']; $onepageinfo->template_encoding = $row['encoding']; $onepageinfo->cachable = $row['cachable'] == 1 ? true : false; $onepageinfo->template_modified_date = $db->UnixTimeStamp($row['t_date']); if (!$onepageinfo->cachable) { // calguy1000 - if the page is not cachable, don't cache // the template either. This trick forces smarty to // refresh the template cache. $onepageinfo->template_modified_date = time() + 10; } $result = $onepageinfo; } else { #Page isn't found. Should we setup an alternate page? #if (get_site_preference('custom404template') > 0 && get_site_preference('enablecustom404') == "1") //First check if there is an error page set -- this overrides the enablecustom404 setting if ($alias == 'error404') { return null; } $result = PageInfoOperations::LoadPageInfoByContentAlias('error404'); if ($result != null) { //Change header to 404 header("HTTP/1.0 404 Not Found"); header("Status: 404 Not Found"); } else { if (get_site_preference('enablecustom404') == "1") { $onepageinfo = new PageInfo(); $onepageinfo->cachable = false; if (get_site_preference('custom404template') > 0) { $onepageinfo->template_id = get_site_preference('custom404template'); } else { $onepageinfo->template_id = 'notemplate'; } $onepageinfo->template_modified_date = time(); $result = $onepageinfo; } } } return $result; }