public static function PublishPage($pageUniqId, $preview = false, $remove_draft = false, $root = '../') { $page = Page::GetByPageUniqId($pageUniqId); if ($page != null) { $site = Site::GetBySiteId($page['SiteId']); // test for now $dest = $root . 'sites/' . $site['FriendlyId'] . '/'; $imageurl = $dest . 'files/'; $siteurl = 'http://' . $site['Domain'] . '/'; $friendlyId = $page['FriendlyId']; $url = ''; $file = ''; if ($preview == true) { $previewId = uniqid(); $file = $page['FriendlyId'] . '-' . $previewId . '-preview.php'; } else { $file = $page['FriendlyId'] . '.php'; } // create a nice path to store the file if ($page['PageTypeId'] == -1) { $url = $page['FriendlyId'] . '.php'; $path = ''; } else { $pageType = PageType::GetByPageTypeId($page['PageTypeId']); $path = 'uncategorized/'; if ($pageType != null) { $path = strtolower($pageType['FriendlyId']) . '/'; } } // generate default $html = Utilities::GeneratePage($site, $page, $siteurl, $imageurl, $preview, $root); // remove any drafts associated with the page if ($remove_draft == true) { $draft = $root . 'sites/' . $site['FriendlyId'] . '/fragments/draft/' . $page['PageUniqId'] . '.html'; if (file_exists($draft)) { unlink($draft); } } if ($preview == true) { $s_dest = $dest . 'preview/'; } else { $s_dest = $dest . $path; } // save the content to the published file Utilities::SaveContent($s_dest, $file, $html); // publish a rendered fragment Publish::PublishRender($site, $page, $root); // build the search index for the page Publish::BuildSearchIndex($site, $page, $root); return $s_dest . $file; } }
public static function GenerateSiteMap($site) { $list = Page::GetPagesForSite($site['SiteId']); // get offset for time zone $timeZone = new DateTimeZone($site['TimeZone']); $now = new DateTime("now", $timeZone); $offset = $timeZone->getOffset($now); $xml = '<?xml version="1.0" encoding="UTF-8"?>' . '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'; date_default_timezone_set('America/Los_Angeles'); foreach ($list as $row) { $u = strtotime($row['LastModifiedDate']) + $offset; $pageType = PageType::GetByPageTypeId($row['PageTypeId']); if ($pageType['IsSecure'] == 1) { continue; } if ($row['IncludeOnly'] == 1) { continue; } // set URL divider based on URL mode $divider = '/'; // build url if ($row['PageTypeId'] == -1) { $xml = $xml . '<url>' . '<loc>' . $site['Domain'] . $divider . strtolower($row['FriendlyId']) . '</loc>' . '<lastmod>' . date('Y-m-d', $u) . '</lastmod>' . '<priority>1.0</priority>' . '</url>'; } else { $xml = $xml . '<url>' . '<loc>' . $site['Domain'] . $divider . strtolower($pageType['FriendlyId']) . '/' . strtolower($row['FriendlyId']) . '</loc>' . '<lastmod>' . date('Y-m-d', $u) . '</lastmod>' . '<priority>0.5</priority>' . '</url>'; } } $xml = $xml . '</urlset>'; return $xml; }
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); } // set $base to the root of the director $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); $html = str_replace('<body ui-view></body>', '<body ng-controller="PageCtrl" page="' . $page['PageId'] . '" class="' . $page['Stylesheet'] . '">' . $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']); } // replace common Angular calls for SEO, e.g. {{page.Name}} {{page.Description}} {{site.Name}} $html = str_replace('{{page.Name}}', $page['Name'], $html); $html = str_replace('{{page.Description}}', $page['Description'], $html); $html = str_replace('{{page.Keywords}}', $page['Keywords'], $html); $html = str_replace('{{page.Callout}}', $page['Callout'], $html); $html = str_replace('{{site.Name}}', $site['Name'], $html); $html = str_replace('{{site.Language}}', $site['Language'], $html); $html = str_replace('{{site.Direction}}', $site['Direction'], $html); $html = str_replace('{{page.FullStylesheetUrl}}', 'css/' . $page['Stylesheet'] . '.css', $html); // update base $html = str_replace('<base href="/">', '<base href="' . $base . '">', $html); // add menu links for SEO (<respond-menu type="primary"></respond-menu>) $delimiter = '#'; $startTag = '<respond-menu type="'; $endTag = '"></respond-menu>'; $regex = $delimiter . preg_quote($startTag, $delimiter) . '(.*?)' . preg_quote($endTag, $delimiter) . $delimiter . 's'; // match against html preg_match_all($regex, $html, $matches); // crawl matches foreach ($matches[1] as &$value) { // init menu $menu = ''; // get items for type $menuItems = MenuItem::GetMenuItemsForType($site['SiteId'], $value); $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>'; $menu .= '<a href="' . $menu_root . $url . '">' . $menuItem['Name'] . '</a>'; $menu .= '<ul class="dropdown-menu">'; $new_parent = false; } else { $menu .= '<li' . $cssClass . '>'; $menu .= '<a href="' . $menu_root . $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; // fill menu with string $html = str_replace('<respond-menu type="' . $value . '"></respond-menu>', '<respond-menu type="' . $value . '">' . $menu . '</respond-menu>', $html); } // save the content to the published file Utilities::SaveContent($dest, $file, $html); return $dest . $file; }
public static function ApplyMustacheSyntax($html, $site, $page) { // meta data $photo = ''; $firstName = ''; $lastName = ''; $lastModifiedDate = $page['LastModifiedDate']; // replace last modified if ($page['LastModifiedBy'] != NULL) { // get user $user = User::GetByUserId($page['LastModifiedBy']); // set user infomration if ($user != NULL) { $photo = $user['PhotoUrl']; $firstName = $user['FirstName']; $lastName = $user['LastName']; } } // set page information $html = str_replace('{{page.PhotoUrl}}', $photo, $html); $html = str_replace('{{page.FirstName}}', $firstName, $html); $html = str_replace('{{page.LastName}}', $lastName, $html); $html = str_replace('{{page.LastModifiedDate}}', $lastModifiedDate, $html); // replace timestamp $html = str_replace('{{timestamp}}', time(), $html); // replace year $html = str_replace('{{year}}', date('Y'), $html); // set images URL $imagesURL = $site['Domain'] . '/'; // set iconURL $iconURL = ''; if ($site['IconUrl'] != '') { $iconURL = $imagesURL . 'files/' . $site['IconUrl']; } // replace $html = str_replace('ng-src', 'src', $html); $html = str_replace('{{site.ImagesUrl}}', $imagesURL, $html); $html = str_replace('{{site.ImagesURL}}', $imagesURL, $html); $html = str_replace('{{site.IconUrl}}', $iconURL, $html); // set fullLogo $html = str_replace('{{fullLogoUrl}}', $imagesURL . 'files/' . $site['LogoUrl'], $html); // set altLogo (defaults to full logo if not available) if ($site['AltLogoUrl'] != '' && $site['AltLogoUrl'] != NULL) { $html = str_replace('{{fullAltLogoUrl}}', $imagesURL . 'files/' . $site['AltLogoUrl'], $html); } else { $html = str_replace('{{fullAltLogoUrl}}', $imagesURL . 'files/' . $site['LogoUrl'], $html); } // set urls $relativeURL = $page['FriendlyId']; if ($page['PageTypeId'] != -1) { $pageType = PageType::GetByPageTypeId($page['PageTypeId']); $relativeURL = strtolower($pageType['FriendlyId']) . '/' . $page['FriendlyId']; } $fullURL = $site['Domain'] . '/' . $relativeURL; // replace mustaches syntax {{page.Description}} {{site.Name}} $html = str_replace('{{page.Name}}', $page['Name'], $html); $html = str_replace('{{page.Description}}', $page['Description'], $html); $html = str_replace('{{page.Keywords}}', $page['Keywords'], $html); $html = str_replace('{{page.Callout}}', $page['Callout'], $html); $html = str_replace('{{site.Name}}', $site['Name'], $html); $html = str_replace('{{site.Language}}', $site['Language'], $html); $html = str_replace('{{site.Direction}}', $site['Direction'], $html); $html = str_replace('{{site.IconBg}}', $site['IconBg'], $html); $html = str_replace('{{site.EmbeddedCodeHead}}', $site['EmbeddedCodeHead'], $html); $html = str_replace('{{site.EmbeddedCodeBottom}}', $site['EmbeddedCodeBottom'], $html); $html = str_replace('{{page.FullStylesheetUrl}}', 'css/' . $page['Stylesheet'] . '.css', $html); // urls $html = str_replace('{{page.Url}}', $relativeURL, $html); $html = str_replace('{{page.FullUrl}}', $fullURL, $html); return $html; }
/** * @method GET */ function get($friendlyId) { // get token $token = Utilities::ValidateJWTToken(apache_request_headers()); // check if token is not null if ($token != NULL) { // get a reference to the site $site = Site::GetBySiteId($token->SiteId); $siteId = $token->SiteId; $pageSize = 100; $orderBy = 'Created DESC'; $page = 0; $pageTypeId = -1; $dir = '/'; if ($friendlyId != 'root') { // get pagetype $pageType = PageType::GetByFriendlyId($friendlyId, $siteId); $pageTypeId = $pageType['PageTypeId']; $dir = strtolower($pageType['FriendlyId']) . '/'; } // get pages $list = Page::GetPages($siteId, $pageTypeId, $pageSize, $page, $orderBy); $pages = array(); foreach ($list as $row) { $page = Page::GetByPageId($row['PageId']); $fullName = $row['FirstName'] . ' ' . $row['LastName']; $page['LastModifiedFullName'] = $fullName; $thumbUrl = ''; if ($page['Image'] != '') { $thumbUrl = '/files/thumbs/' . $page['Image']; } // set thumb $page['Thumb'] = $thumbUrl; $url = $page['FriendlyId']; if ($page['PageTypeId'] != -1) { $pageType = PageType::GetByPageTypeId($page['PageTypeId']); $url = strtolower($pageType['FriendlyId']) . '/' . $page['FriendlyId']; } // set url $page['Url'] = $url; // permissions are not applicable to this API call $page['CanEdit'] = ''; $page['CanPublish'] = ''; $page['CanRemove'] = ''; $pages[$row['PageId']] = $page; } // return a json response $response = new Tonic\Response(Tonic\Response::OK); $response->contentType = 'application/json'; $response->body = json_encode($pages); return $response; } else { // unauthorized access return new Tonic\Response(Tonic\Response::UNAUTHORIZED); } }
/** * @method GET */ function get($friendlyId) { // get an authuser $authUser = new AuthUser(); if (isset($authUser->UserUniqId)) { // check if authorized $siteId = $authUser->SiteId; $pageSize = 100; $orderBy = 'Created DESC'; $page = 0; $pageTypeId = -1; $dir = '/'; if ($friendlyId != 'root') { // get pagetype $pageType = PageType::GetByFriendlyId($friendlyId, $siteId); $pageTypeId = $pageType['PageTypeId']; $dir = strtolower($pageType['TypeS']) . '/'; } // get site url $site = Site::GetBySiteId($authUser->SiteId); $dir = 'sites/' . $site['FriendlyId'] . '/files/'; // get pages $list = Page::GetPages($siteId, $pageTypeId, $pageSize, $page, $orderBy); $pages = array(); foreach ($list as $row) { $page = Page::GetByPageId($row['PageId']); $fullName = $row['FirstName'] . ' ' . $row['LastName']; $page['LastModifiedFullName'] = $fullName; $thumbUrl = ''; if ($page['Image'] != '') { if (strpos($page['Image'], 't-') !== false) { $thumbUrl = $dir . $page['Image']; } else { $thumbUrl = $dir . 't-' . $page['Image']; } } // set thumb $page['Thumb'] = $thumbUrl; $url = $page['FriendlyId']; if ($page['PageTypeId'] != -1) { $pageType = PageType::GetByPageTypeId($page['PageTypeId']); $url = strtolower($pageType['TypeS']) . '/' . $page['FriendlyId']; } // set url $page['Url'] = $url; // permissions are not applicable to this API call $page['CanEdit'] = ''; $page['CanPublish'] = ''; $page['CanRemove'] = ''; $pages[$row['PageUniqId']] = $page; } // return a json response $response = new Tonic\Response(Tonic\Response::OK); $response->contentType = 'application/json'; $response->body = json_encode($pages); return $response; } else { // unauthorized access return new Tonic\Response(Tonic\Response::UNAUTHORIZED); } }
public static function BuildSearchIndex($site, $page, $language, $isDefaultLanguage, $content, $root = '../') { $html = str_get_html($content, true, true, DEFAULT_TARGET_CHARSET, false, DEFAULT_BR_TEXT); $url = $page['FriendlyId']; $isSecure = 0; $image = $page['Image']; if ($page['PageTypeId'] != -1) { $pageType = PageType::GetByPageTypeId($page['PageTypeId']); $url = $pageType['FriendlyId'] . '/' . $page['FriendlyId']; if ($pageType['IsSecure'] == 1) { $isSecure = 1; } } if ($isDefaultLanguage == false) { // set language to the domain for the site $domain = $root . 'sites/' . $site['FriendlyId'] . '/locale'; // set the language Utilities::SetLanguage($language, $domain); } $name = $page['Name']; $text = ''; $h1s = ''; $h2s = ''; $h3s = ''; $description = $page['Description']; if ($isDefaultLanguage == false) { $name = _($name); // get translated version $description = _($description); } if ($html == null) { return ''; } // setup gettext blockquote, h1, h2, h3, p, td, th, li, meta tags for multi-lingual support foreach ($html->find('blockquote') as $el) { if ($isDefaultLanguage == false) { $text .= _($el->innertext) . ' '; // get translated version } else { $text .= $el->innertext . ' '; } } foreach ($html->find('h1') as $el) { if ($isDefaultLanguage == false) { $h1s .= _($el->innertext) . ' '; // get translated version } else { $h1s .= $el->innertext . ' '; } } foreach ($html->find('h2') as $el) { if ($isDefaultLanguage == false) { $h2s .= _($el->innertext) . ' '; // get translated version } else { $h2s .= $el->innertext . ' '; } } foreach ($html->find('h3') as $el) { if ($isDefaultLanguage == false) { $h3s .= _($el->innertext) . ' '; // get translated version } else { $h3s .= $el->innertext . ' '; } } foreach ($html->find('p') as $el) { if ($isDefaultLanguage == false) { $text .= _($el->innertext) . ' '; // get translated version } else { $text .= $el->innertext . ' '; } } foreach ($html->find('td') as $el) { if ($isDefaultLanguage == false) { $text .= _($el->innertext) . ' '; // get translated version } else { $text .= $el->innertext . ' '; } } foreach ($html->find('th') as $el) { if ($isDefaultLanguage == false) { $text .= _($el->innertext) . ' '; // get translated version } else { $text .= $el->innertext . ' '; } } foreach ($html->find('li') as $el) { if ($isDefaultLanguage == false) { $text .= _($el->innertext) . ' '; // get translated version } else { $text .= $el->innertext . ' '; } } foreach ($html->find('meta[name=description]') as $el) { if ($isDefaultLanguage == false) { $description = _($el->innertext); // get translated version } else { $description = $el->innertext; } } // strip any html $h1s = strip_tags($h1s); $h2s = strip_tags($h2s); $h3s = strip_tags($h3s); $description = strip_tags($description); $text = strip_tags($text); // add to search index SearchIndex::Add($page['PageUniqId'], $site['SiteUniqId'], $language, $url, $name, $image, $isSecure, $h1s, $h2s, $h3s, $description, $text); }
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); } // set $base to the root of the director $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']); } // replace mustaches syntax {{page.Description}} {{site.Name}} $html = str_replace('{{page.Name}}', $page['Name'], $html); $html = str_replace('{{page.Description}}', $page['Description'], $html); $html = str_replace('{{page.Keywords}}', $page['Keywords'], $html); $html = str_replace('{{page.Callout}}', $page['Callout'], $html); $html = str_replace('{{site.Name}}', $site['Name'], $html); $html = str_replace('{{site.Language}}', $site['Language'], $html); $html = str_replace('{{site.Direction}}', $site['Direction'], $html); $html = str_replace('{{site.IconBg}}', $site['IconBg'], $html); $html = str_replace('{{page.FullStylesheetUrl}}', 'css/' . $page['Stylesheet'] . '.css', $html); // meta data $photo = ''; $firstName = ''; $lastName = ''; $lastModifiedDate = $page['LastModifiedDate']; // replace last modified if ($page['LastModifiedBy'] != NULL) { // get user $user = User::GetByUserId($page['LastModifiedBy']); // set user infomration if ($user != NULL) { $photo = $user['PhotoUrl']; $firstName = $user['FirstName']; $lastName = $user['LastName']; } } // set page information $html = str_replace('{{page.PhotoUrl}}', $photo, $html); $html = str_replace('{{page.FirstName}}', $firstName, $html); $html = str_replace('{{page.LastName}}', $lastName, $html); $html = str_replace('{{page.LastModifiedDate}}', $lastModifiedDate, $html); // add a timestamp $html = str_replace('{{timestamp}}', time(), $html); // set imaages URL $imagesURL = $site['Domain'] . '/'; // if files are stored on S3 if (FILES_ON_S3 == true) { $bucket = $site['Bucket']; $imagesURL = str_replace('{{bucket}}', $bucket, S3_URL) . '/'; $imagesURL = str_replace('{{site}}', $site['FriendlyId'], $imagesURL); } // set iconURL $iconURL = ''; if ($site['IconUrl'] != '') { $iconURL = $imagesURL . 'files/' . $site['IconUrl']; } // replace $html = str_replace('ng-src', 'src', $html); $html = str_replace('{{site.ImagesUrl}}', $imagesURL, $html); $html = str_replace('{{site.ImagesURL}}', $imagesURL, $html); $html = str_replace('{{site.IconUrl}}', $iconURL, $html); // set fullLogo $html = str_replace('{{fullLogoUrl}}', $imagesURL . 'files/' . $site['LogoUrl'], $html); // set altLogo (defaults to full logo if not available) if ($site['AltLogoUrl'] != '' && $site['AltLogoUrl'] != NULL) { $html = str_replace('{{fullAltLogoUrl}}', $imagesURL . 'files/' . $site['AltLogoUrl'], $html); } else { $html = str_replace('{{fullAltLogoUrl}}', $imagesURL . 'files/' . $site['LogoUrl'], $html); } // update base $html = str_replace('<base href="/">', '<base href="' . $base . '">', $html); // parse the html for menus $html = str_get_html($html, true, true, DEFAULT_TARGET_CHARSET, false, DEFAULT_BR_TEXT); // 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; // 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 */ // replace background color foreach ($html->find('[backgroundcolor]') as $el) { // set existing style $style = ''; if (isset($el->style)) { $style = $el->style . ' '; } // if it is nested, break if (isset($el->{'data-nested'})) { if ($el->{'data-nested'} != 'nested') { $el->style = $style . 'background-color: ' . $el->backgroundcolor . ';'; } } else { $el->style = $style . 'background-color: ' . $el->backgroundcolor . ';'; } } /* foreach */ // replace background image foreach ($html->find('[backgroundimage]') as $el) { // set existing style $style = ''; if (isset($el->style)) { $style = $el->style . ' '; } $backgroundimage = $el->backgroundimage; $backgroundstyle = 'cover'; // add site url for files that start with files if (substr($backgroundimage, 0, 5) === "files") { $backgroundimage = $imagesURL . $el->backgroundimage; } // set background style if (isset($el->backgroundstyle)) { $backgroundstyle = $el->backgroundstyle; } // if it is nested, break if (isset($el->{'data-nested'})) { if ($el->{'data-nested'} != 'nested') { if ($backgroundstyle == 'parallax') { $el->{'data-parallax'} = 'scroll'; $el->{'data-image-src'} = $backgroundimage; } else { if ($backgroundstyle == 'repeat') { $el->style = $style . 'background-image: url(' . $backgroundimage . '); background-repeat: repeat;'; } else { $el->style = $style . 'background-image: url(' . $backgroundimage . '); background-size: cover; background-position: center center;'; } } } } else { if ($backgroundstyle == 'parallax') { $el->{'data-parallax'} = 'scroll'; $el->{'data-image-src'} = $backgroundimage; } else { if ($backgroundstyle == 'repeat') { $el->style = $style . 'background-image: url(' . $backgroundimage . '); background-repeat: repeat;'; } else { $el->style = $style . 'background-image: url(' . $backgroundimage . '); background-size: cover; background-position: center center;'; } } } } /* foreach */ // replace textcolor foreach ($html->find('[textcolor]') as $el) { // if it is nested, break if (isset($el->style)) { $el->style = $el->style . ' color: ' . $el->textcolor . ';'; } else { $el->style = 'color: ' . $el->textcolor . ';'; } } /* foreach */ // replace paddingtop foreach ($html->find('[paddingtop]') as $el) { // if it is nested, break if (isset($el->style)) { $el->style = $el->style . ' padding-top: ' . $el->paddingtop . 'px;'; } else { $el->style = 'padding-top: ' . $el->paddingtop . 'px;'; } } /* foreach */ // replace paddingright foreach ($html->find('[paddingright]') as $el) { // if it is nested, break if (isset($el->style)) { $el->style = $el->style . ' padding-right: ' . $el->paddingright . 'px;'; } else { $el->style = 'padding-right: ' . $el->paddingright . 'px;'; } } /* foreach */ // replace paddingbottom foreach ($html->find('[paddingbottom]') as $el) { // if it is nested, break if (isset($el->style)) { $el->style = $el->style . ' padding-bottom: ' . $el->paddingbottom . 'px;'; } else { $el->style = 'padding-bottom: ' . $el->paddingbottom . 'px;'; } } /* foreach */ // replace paddingleft foreach ($html->find('[paddingleft]') as $el) { // if it is nested, break if (isset($el->style)) { $el->style = $el->style . ' padding-left: ' . $el->paddingleft . 'px;'; } else { $el->style = 'padding-left: ' . $el->paddingleft . 'px;'; } } /* foreach */ // replace textshadowcolor foreach ($html->find('[textshadowcolor]') as $el) { $color = $el->textshadowcolor; $horizontal = '1px'; $vertical = '1px'; $blur = '1px'; if (isset($el->textshadowhorizontal)) { $horizontal = $el->textshadowhorizontal; } if (isset($el->textshadowvertical)) { $vertical = $el->textshadowblur; } if (isset($el->textshadowvertical)) { $blur = $el->textshadowblur; } // build shadow $textshadow = $horizontal . ' ' . $vertical . ' ' . $blur . ' ' . $color . ';'; // if it is nested, break if (isset($el->style)) { $el->style = $el->style . ' text-shadow: ' . $textshadow; } else { $el->style = 'text-shadow: ' . $textshadow; } } /* foreach */ // replace textsize foreach ($html->find('[textsize]') as $el) { $textsize = $el->textsize; $el->innertext = '<span style="font-size:' . $textsize . '">' . $el->innertext . '</span>'; } /* foreach */ // save the content to the published file Utilities::SaveContent($dest, $file, $html); return $dest . $file; }
/** * @method POST */ function post() { // get token $token = Utilities::ValidateJWTToken(apache_request_headers()); // check if token is not null if ($token != NULL) { parse_str($this->request->data, $request); // parse request $pageTypeId = $request['pageTypeId']; $pageType = PageType::GetByPageTypeId($pageTypeId); $site = Site::GetBySiteId($pageType['SiteId']); // remove page type and pages from DB PageType::Remove($pageType['PageTypeId'], $token->SiteId); return new Tonic\Response(Tonic\Response::OK); } else { return new Tonic\Response(Tonic\Response::UNAUTHORIZED); } }