public static function PublishStaticPage($page, $site, $preview = false, $remove_draft = false) { $dest = SITES_LOCATION . '/' . $site['FriendlyId'] . '/'; $imageurl = $dest . 'files/'; $siteurl = $site['Domain'] . '/'; $friendlyId = $page['FriendlyId']; $url = ''; $file = ''; // created ctrl $ctrl = ucfirst($page['FriendlyId']); $ctrl = str_replace('-', '', $ctrl); // set base $base = ''; // create a static location for the page if ($page['PageTypeId'] == -1) { $url = $page['FriendlyId'] . '.html'; $dest = SITES_LOCATION . '/' . $site['FriendlyId'] . '/'; } else { $pageType = PageType::GetByPageTypeId($page['PageTypeId']); $dest = SITES_LOCATION . '/' . $site['FriendlyId'] . '/uncategorized/'; if ($pageType != null) { $dest = SITES_LOCATION . '/' . $site['FriendlyId'] . '/' . $pageType['FriendlyId'] . '/'; // created ctrl $ctrl = ucfirst($pageType['FriendlyId']) . $ctrl; $ctrl = str_replace('-', '', $ctrl); } // explode friendlyid by '/' $parts = explode('/', $pageType['FriendlyId']); // set base based on the depth foreach ($parts as $part) { $base .= '../'; } } // create directory if it does not exist if (!file_exists($dest)) { mkdir($dest, 0755, true); } // generate default $html = ''; $content = ''; // get index and layout (file_get_contents) $index = SITES_LOCATION . '/' . $site['FriendlyId'] . '/themes/' . $site['Theme'] . '/layouts/index.html'; $layout = SITES_LOCATION . '/' . $site['FriendlyId'] . '/themes/' . $site['Theme'] . '/layouts/' . $page['Layout'] . '.html'; // get index html if (file_exists($index)) { $html = file_get_contents($index); } // get layout html if (file_exists($layout)) { $layout_html = file_get_contents($layout); // set class $cssClass = $page['Stylesheet']; // set show-cart, show-settings, show-languages, show-login if ($site['ShowCart'] == 1) { $cssClass .= ' show-cart'; } if ($site['ShowSettings'] == 1) { $cssClass .= ' show-settings'; } if ($site['ShowLanguages'] == 1) { $cssClass .= ' show-languages'; } if ($site['ShowLogin'] == 1) { $cssClass .= ' show-login'; } $html = str_replace('<body ui-view></body>', '<body page="' . $page['PageId'] . '" class="' . $cssClass . '">' . $layout_html . '</body>', $html); $html = str_replace('<body></body>', '<body page="' . $page['PageId'] . '" class="' . $cssClass . '">' . $layout_html . '</body>', $html); } // get draft/content if ($preview == true) { $file = $page['FriendlyId'] . '.preview.html'; $content = $page['Draft']; } else { $file = $page['FriendlyId'] . '.html'; $content = $page['Content']; } // replace respond-content for layout with content $html = str_replace('<respond-content id="main-content" url="{{page.Url}}"></respond-content>', $content, $html); // remove any drafts associated with the page if ($remove_draft == true) { // remove a draft from the page Page::RemoveDraft($page['PageId']); } if ($html !== NULL) { // parse the html for menus $html = str_get_html($html, true, true, DEFAULT_TARGET_CHARSET, false, DEFAULT_BR_TEXT); // generate the [render=publish] components $html = Publish::GenerateRenderAtPublish($html, $site, $page); // applies the style attributes to the $html $html = Publish::ApplyStyleAttributes($html); // applies the mustache syntax $html = Publish::ApplyMustacheSyntax($html, $site, $page); } else { $html = ''; } // update base $html = str_replace('<base href="/">', '<base href="' . $base . '">', $html); // save the content to the published file Utilities::SaveContent($dest, $file, $html); return $dest . $file; }