예제 #1
0
 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;
 }
예제 #2
0
파일: Publish.php 프로젝트: OnekO/respond
 public static function GenerateRenderAtPublish($html, $site, $page)
 {
     // set images URL
     $imagesURL = $site['Domain'] . '/';
     // build out the menus where render is set to publish
     foreach ($html->find('respond-menu[render=publish]') as $el) {
         // get the type
         if ($el->type) {
             $type = $el->type;
             // init menu
             $menu = '<ul';
             // set class if applicable
             if (isset($el->class)) {
                 $menu .= ' class="' . $el->class . '">';
             } else {
                 $menu .= '>';
             }
             // get items for type
             $menuItems = MenuItem::GetMenuItemsForType($site['SiteId'], $type);
             $i = 0;
             $parent_flag = false;
             $new_parent = true;
             // walk through items
             foreach ($menuItems as $menuItem) {
                 $url = $menuItem['Url'];
                 $name = $menuItem['Name'];
                 $css = '';
                 $cssClass = '';
                 $active = '';
                 if ($page['PageId'] == $menuItem['PageId']) {
                     $css = 'active';
                 }
                 $css .= ' ' . $menuItem['CssClass'];
                 if (trim($css) != '') {
                     $cssClass = ' class="' . $css . '"';
                 }
                 // check for new parent
                 if (isset($menuItems[$i + 1])) {
                     if ($menuItems[$i + 1]['IsNested'] == 1 && $new_parent == true) {
                         $parent_flag = true;
                     }
                 }
                 $menu_root = '/';
                 // check for external links
                 if (strpos($url, 'http') !== false) {
                     $menu_root = '';
                 }
                 if ($new_parent == true && $parent_flag == true) {
                     $menu .= '<li class="dropdown">';
                     $menu .= '<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">' . $menuItem['Name'] . ' <span class="caret"></span></a>';
                     $menu .= '<ul class="dropdown-menu">';
                     $new_parent = false;
                 } else {
                     $menu .= '<li' . $cssClass . '>';
                     $menu .= '<a href="' . $url . '">' . $menuItem['Name'] . '</a>';
                     $menu .= '</li>';
                 }
                 // end parent
                 if (isset($menuItems[$i + 1])) {
                     if ($menuItems[$i + 1]['IsNested'] == 0 && $parent_flag == true) {
                         $menu .= '</ul></li>';
                         // end parent if next item is not nested
                         $parent_flag = false;
                         $new_parent = true;
                     }
                 } else {
                     if ($parent_flag == true) {
                         $menu .= '</ul></li>';
                         // end parent if next menu item is null
                         $parent_flag = false;
                         $new_parent = true;
                     }
                 }
                 $i = $i + 1;
             }
             $menu .= '</ul>';
             $el->outertext = $menu;
         }
         /* isset */
     }
     /* foreach */
     // replace content where render is set to publish
     foreach ($html->find('respond-content[render=publish]') as $el) {
         // get the url
         if (isset($el->url)) {
             $url = $el->url;
             $url = Publish::ApplyMustacheSyntax($url, $site, $page);
             // replace the / with a period
             $url = str_replace('/', '.', $url);
             $url .= '.html';
             $content_html = '';
             // get the content from the site
             $content_dest = SITES_LOCATION . '/' . $site['FriendlyId'] . '/templates/page/' . $url;
             if (file_exists($content_dest)) {
                 $content_html = file_get_contents($content_dest);
             }
             // update images url
             $content_html = str_replace('{{site.ImagesUrl}}', $imagesURL, $content_html);
             $content_html = str_replace('{{site.ImagesURL}}', $imagesURL, $content_html);
             // set outer text
             if ($content_html != '') {
                 $el->outertext = $content_html;
             }
         }
     }
     /* foreach */
     return $html;
 }