/** * @method GET */ function get($type) { $list = MenuItem::GetMenuItemsForType(SITE_ID, $type); $menu = array(); foreach ($list as $row) { $scope = 'external'; $pageUniqId = ''; // set the scope of the link if ($row['PageId'] != '-1') { $scope = 'internal'; $page = Page::GetByPageId($row['PageId']); if ($page != NULL) { $pageUniqId = $page['PageUniqId']; } } // set the item $item = array('MenuItemUniqId' => $row['MenuItemUniqId'], 'Name' => $row['Name'], 'Url' => $row['Url'], 'PageUniqId' => $pageUniqId, 'Scope' => $scope); // push the item to the array array_push($menu, $item); } // return a json response $response = new Tonic\Response(Tonic\Response::OK); $response->contentType = 'application/json'; $response->body = json_encode($menu); return $response; }
/** * @method GET */ function get($type) { // get an authuser $authUser = new AuthUser(); if (isset($authUser->UserUniqId)) { // check if authorized $list = MenuItem::GetMenuItemsForType($authUser->SiteId, $type); // return a json response $response = new Tonic\Response(Tonic\Response::OK); $response->contentType = 'application/json'; $response->body = json_encode($list); return $response; } else { return new Tonic\Response(Tonic\Response::UNAUTHORIZED); } }
/** * @method GET */ function get() { // get an authuser $token = Utilities::ValidateJWTToken(apache_request_headers()); // check if token is not null if ($token != NULL) { parse_str($this->request->data, $request); // parse request $type = $request['type']; $list = MenuItem::GetMenuItemsForType($authUser->SiteId, $type); // return a json response $response = new Tonic\Response(Tonic\Response::OK); $response->contentType = 'application/json'; $response->body = json_encode($list); return $response; } else { return new Tonic\Response(Tonic\Response::UNAUTHORIZED); } }
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; // 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; }
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 GeneratePage($site, $page, $siteurl, $imageurl, $preview, $root = '../') { $pageTypeId = $page['PageTypeId']; $path = '/'; $pageType = null; $type = 'preview'; $isSecure = false; $pageurl = 'http://' . $site['Domain']; if ($page['PageTypeId'] != -1) { $pageType = PageType::GetByPageTypeId($page['PageTypeId']); $pageurl .= '/' . $pageType['FriendlyId'] . '/' . $page['FriendlyId']; // set whether a page is secured based on page type if ($pageType['IsSecure'] == 1) { $isSecure = true; } } else { $pageurl .= '/' . $page['FriendlyId']; } if ($page['PageTypeId'] != -1) { $pageType = PageType::GetByPageTypeId($pageTypeId); $type = $pageType['FriendlyId']; } $rootloc = ''; $commonloc = '../common/'; $default_url = ''; if ($page['PageTypeId'] != -1 || $preview == true) { $rootloc = '../'; $commonloc = '../../common/'; $path = '/' . strtolower($type) . '/' . strtolower($page['FriendlyId']); $default_url = $path; } else { $path = '/' . strtolower($page['FriendlyId']); } $siteId = $site['SiteId']; $timezone = $site['TimeZone']; $siteUniqId = $site['SiteUniqId']; $siteName = $site['Name']; $theme = $site['Theme']; $analyticsId = $site['AnalyticsId']; $htmlDir = $root . 'sites/' . $site['FriendlyId'] . '/themes/' . $site['Theme'] . '/layouts/'; $htmlFile = $htmlDir . $page['Layout'] . '.html'; $content = '{{content}}'; if (file_exists($htmlFile)) { $content = file_get_contents($htmlFile); if ($content == '') { $content = '{{content}}'; } } // translations $content = str_replace('{{t}}', '<?php print _("', $content); $content = str_replace('{{/t}}', '"); ?>', $content); // global constants $content = str_replace('{{root}}', $rootloc, $content); $content = str_replace('{{site}}', $site['Name'], $content); $content = str_replace('{{site-url}}', '//' . $site['Domain'], $content); $content = str_replace('{{page-url}}', $pageurl, $content); $content = str_replace('{{logo}}', $rootloc . 'files/' . $site['LogoUrl'], $content); $content = str_replace('{{resources}}', $rootloc . 'themes/' . $site['Theme'] . '/resources/', $content); // icons $relative_icon_url = $rootloc . 'files/' . $site['IconUrl']; $abs_icon_url = 'http://' . $site['Domain'] . '/files/' . $site['IconUrl']; // icon urls $content = str_replace('{{icon}}', $relative_icon_url, $content); $content = str_replace('{{icon-abs}}', $abs_icon_url, $content); // favicon $content = str_replace('{{favicon}}', '<link rel="icon" href="' . $relative_icon_url . '">', $content); // tile $tile_html = '<meta name="msapplication-TileColor" content="' . $site['IconBg'] . '">' . PHP_EOL . '<meta name="msapplication-TileImage" content="' . $relative_icon_url . '">'; $content = str_replace('{{tileicon}}', $tile_html, $content); // touch icon $content = str_replace('{{touchicon}}', '<link rel="apple-touch-icon" href="' . $relative_icon_url . '">', $content); // replace with constants $content = str_replace('{{id}}', $page['FriendlyId'], $content); $content = str_replace('{{type}}', $type, $content); $content = str_replace('{{name}}', $page['Name'], $content); $content = str_replace('{{description}}', $page['Description'], $content); $content = str_replace('{{synopsis}}', substr(strip_tags(html_entity_decode($page['Description'])), 0, 200), $content); $content = str_replace('{{keywords}}', $page['Keywords'], $content); $content = str_replace('{{callout}}', $page['Callout'], $content); // facebook $content = str_replace('{{facebook-appid}}', $site['FacebookAppId'], $content); $content = str_replace('{{facebook-meta-appid}}', '<meta property="fb:app_id" content="' . $site['FacebookAppId'] . '">', $content); // replace with php $content = str_replace('{{language}}', '<?php print $language; ?>', $content); $local = new DateTimeZone($site['TimeZone']); // create a friendly date $date = DateTime::createFromFormat('Y-m-d H:i:s', $page['LastModifiedDate']); $date->setTimezone($local); $readable = $date->format('D, M d y h:i a'); $content = str_replace('{{date}}', $readable, $content); // create a friendly event date $eventBeginDate = DateTime::createFromFormat('Y-m-d H:i:s', $page['BeginDate']); if ($eventBeginDate != null) { $eventBeginDate->setTimezone($local); $readable = $eventBeginDate->format('D, M d y h:i a'); $content = str_replace('{{event-begin-date}}', $readable, $content); } // get the author $user = User::GetByUserId($page['LastModifiedBy']); $author = ''; $photo = ''; if ($user != null) { $author = $user['FirstName'] . ' ' . $user['LastName']; if ($user['PhotoUrl'] != NULL && $user['PhotoUrl'] != '') { $photo = '<span class="photo" style="background-image: url(' . $rootloc . 'files/' . $user['PhotoUrl'] . ')"></span>'; } } $content = str_replace('{{author}}', $author, $content); $content = str_replace('{{photo}}', $photo, $content); // menus $delimiter = '#'; $startTag = '{{menu-'; $endTag = '}}'; $regex = $delimiter . preg_quote($startTag, $delimiter) . '(.*?)' . preg_quote($endTag, $delimiter) . $delimiter . 's'; preg_match_all($regex, $content, $matches); foreach ($matches[1] as &$value) { $menuItems = MenuItem::GetMenuItemsForType($site['SiteId'], $value); $menu = ''; $i = 0; $parent_flag = false; $new_parent = true; 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 = $rootloc; // 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="' . $menu_root . $url . '" class="dropdown-toggle" data-toggle="dropdown">' . $menuItem['Name'] . ' <b class="caret"></b></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; } $content = str_replace('{{menu-' . $value . '}}', $menu, $content); } // welcome $welcomeFile = $root . 'sites/common/modules/welcome.php'; if (file_exists($welcomeFile)) { $welcome = file_get_contents($welcomeFile); $content = str_replace('{{welcome}}', $welcome, $content); } // snippets $delimiter = '#'; $startTag = '{{snippet-'; $endTag = '}}'; $regex = $delimiter . preg_quote($startTag, $delimiter) . '(.*?)' . preg_quote($endTag, $delimiter) . $delimiter . 's'; preg_match_all($regex, $content, $matches); foreach ($matches[1] as &$value) { if (substr($value, -3) === '-rt') { $value = substr($value, 0, -3); $snippet_content = '<?php include "' . $rootloc . 'fragments/snippets/' . $value . '.php"; ?>'; $content = str_replace('{{snippet-' . $value . '-rt}}', $snippet_content, $content); } else { // get snippet $snippet = $root . 'sites/' . $site['FriendlyId'] . '/fragments/snippets/' . $value . '.php'; $snippet_content = ''; if (file_exists($snippet)) { $snippet_content = file_get_contents($snippet); } $content = str_replace('{{snippet-' . $value . '}}', $snippet_content, $content); } } // custom scripts $delimiter = '#'; $startTag = '{{script-'; $endTag = '}}'; $regex = $delimiter . preg_quote($startTag, $delimiter) . '(.*?)' . preg_quote($endTag, $delimiter) . $delimiter . 's'; preg_match_all($regex, $content, $matches); foreach ($matches[1] as &$value) { // get snippet $script_url = $rootloc . 'js/custom/' . $value . '.js'; $script_content = '<script type="text/javascript" src="' . $script_url . '"></script>'; $content = str_replace('{{script-' . $value . '}}', $script_content, $content); } // cart $cartFile = $root . 'sites/common/modules/cart.php'; $cart = ''; if (file_exists($cartFile)) { $cart = file_get_contents($cartFile); $payPalLogoUrl = ''; if ($site['PayPalLogoUrl'] != NULL && $site['PayPalLogoUrl'] != '') { $payPalLogoUrl = 'http://' . $site['Domain'] . '/files/' . $site['PayPalLogoUrl']; } // fill in the blanks $cart = str_replace('{{payPalId}}', $site['PayPalId'], $cart); $cart = str_replace('{{payPalLogoUrl}}', $payPalLogoUrl, $cart); $cart = str_replace('{{payPalUseSandbox}}', $site['PayPalUseSandbox'], $cart); $cart = str_replace('{{currency}}', $site['Currency'], $cart); $cart = str_replace('{{weightUnit}}', $site['WeightUnit'], $cart); $cart = str_replace('{{taxRate}}', $site['TaxRate'], $cart); $cart = str_replace('{{shippingCalculation}}', $site['ShippingCalculation'], $cart); $cart = str_replace('{{shippingRate}}', $site['ShippingRate'], $cart); $cart = str_replace('{{shippingTiers}}', htmlentities($site['ShippingTiers']), $cart); } $content = str_replace('{{cart}}', $cart, $content); $content = str_replace('{{email}}', $site['PrimaryEmail'], $content); // search $searchFile = $root . 'sites/common/modules/search.php'; $search = ''; if (file_exists($searchFile)) { $search = file_get_contents($searchFile); } // custom scripts $delimiter = '#'; $startTag = '{{search-'; $endTag = '}}'; $regex = $delimiter . preg_quote($startTag, $delimiter) . '(.*?)' . preg_quote($endTag, $delimiter) . $delimiter . 's'; preg_match_all($regex, $content, $matches); foreach ($matches[1] as &$value) { $search = str_replace('{{id}}', $value, $search); $content = str_replace('{{search-' . $value . '}}', $search, $content); } // css $css = ''; $stylesheet = $rootloc . 'css/' . $page['Stylesheet'] . '.css'; ob_start(); include $root . 'sites/common/modules/css.php'; // loads the module $css = ob_get_contents(); // get content from module ob_end_clean(); $content = str_replace('{{css}}', $css, $content); // css-bootstrap $css = '<link href="' . BOOTSTRAP_CSS . '" rel="stylesheet">' . PHP_EOL; $content = str_replace('{{css-bootstrap}}', $css, $content); // css-bootstrap-amelia $css = '<link href="' . BOOTSTRAP_AMELIA_CSS . '" rel="stylesheet">' . PHP_EOL; $content = str_replace('{{css-bootstrap-amelia}}', $css, $content); // css-bootstrap-cerulean $css = '<link href="' . BOOTSTRAP_CERULEAN_CSS . '" rel="stylesheet">' . PHP_EOL; $content = str_replace('{{css-bootstrap-cerulean}}', $css, $content); // css-bootstrap-cosmo $css = '<link href="' . BOOTSTRAP_COSMO_CSS . '" rel="stylesheet">' . PHP_EOL; $content = str_replace('{{css-bootstrap-cosmo}}', $css, $content); // css-bootstrap-cyborg $css = '<link href="' . BOOTSTRAP_CYBORG_CSS . '" rel="stylesheet">' . PHP_EOL; $content = str_replace('{{css-bootstrap-cyborg}}', $css, $content); // css-bootstrap-flatly $css = '<link href="' . BOOTSTRAP_FLATLY_CSS . '" rel="stylesheet">' . PHP_EOL; $content = str_replace('{{css-bootstrap-flatly}}', $css, $content); // css-bootstrap-journal $css = '<link href="' . BOOTSTRAP_JOURNAL_CSS . '" rel="stylesheet">' . PHP_EOL; $content = str_replace('{{css-bootstrap-journal}}', $css, $content); // css-bootstrap-lumen $css = '<link href="' . BOOTSTRAP_LUMEN_CSS . '" rel="stylesheet">' . PHP_EOL; $content = str_replace('{{css-bootstrap-lumen}}', $css, $content); // css-bootstrap-readable $css = '<link href="' . BOOTSTRAP_READABLE_CSS . '" rel="stylesheet">' . PHP_EOL; $content = str_replace('{{css-bootstrap-readable}}', $css, $content); // css-bootstrap-simplex $css = '<link href="' . BOOTSTRAP_SIMPLEX_CSS . '" rel="stylesheet">' . PHP_EOL; $content = str_replace('{{css-bootstrap-simplex}}', $css, $content); // css-bootstrap-slate $css = '<link href="' . BOOTSTRAP_SLATE_CSS . '" rel="stylesheet">' . PHP_EOL; $content = str_replace('{{css-bootstrap-slate}}', $css, $content); // css-bootstrap-spacelab $css = '<link href="' . BOOTSTRAP_SPACELAB_CSS . '" rel="stylesheet">' . PHP_EOL; $content = str_replace('{{css-bootstrap-spacelab}}', $css, $content); // css-bootstrap-superhero $css = '<link href="' . BOOTSTRAP_SUPERHERO_CSS . '" rel="stylesheet">' . PHP_EOL; $content = str_replace('{{css-bootstrap-superhero}}', $css, $content); // css-bootstrap-united $css = '<link href="' . BOOTSTRAP_UNITED_CSS . '" rel="stylesheet">' . PHP_EOL; $content = str_replace('{{css-bootstrap-united}}', $css, $content); // css-bootstrap-yeti $css = '<link href="' . BOOTSTRAP_YETI_CSS . '" rel="stylesheet">' . PHP_EOL; $content = str_replace('{{css-bootstrap-yeti}}', $css, $content); // css-bootstrap-yeti $css = '<link href="' . BOOTSTRAP_DARKLY_CSS . '" rel="stylesheet">' . PHP_EOL; $content = str_replace('{{css-bootstrap-darkly}}', $css, $content); // css-fontawesome $css = '<link href="' . FONTAWESOME_CSS . '" rel="stylesheet">' . PHP_EOL; $content = str_replace('{{css-fontawesome}}', $css, $content); // css-prettify $css = '<link href="' . $rootloc . 'css/prettify.css" type="text/css" rel="stylesheet" media="screen">'; $content = str_replace('{{css-prettify}}', $css, $content); // js $js = ''; ob_start(); include $root . 'sites/common/modules/js.php'; // loads the module $js = ob_get_contents(); // get content from module ob_end_clean(); $content = str_replace('{{js}}', $js, $content); $js_cart = '<script type="text/javascript" src="' . $rootloc . 'js/cartModel.js"></script>' . PHP_EOL; $content = str_replace('{{js-cart}}', $js_cart, $content); // analytics $analytics = ''; if ($site['AnalyticsId'] != '') { $analytics = '<script type="text/javascript">' . PHP_EOL . 'var _gaq = _gaq || [];' . PHP_EOL . '_gaq.push([\'_setAccount\', \'' . $site['AnalyticsId'] . '\']);' . PHP_EOL . (empty($site['AnalyticsSubdomain']) ? '' : "_gaq.push(['_setDomainName', '" . $site['AnalyticsDomain'] . "']);" . PHP_EOL) . (empty($site['AnalyticsMultidomain']) ? '' : "_gaq.push(['_setAllowLinker', true]);" . PHP_EOL) . '_gaq.push([\'_trackPageview\']);' . PHP_EOL . '(function() {' . PHP_EOL . 'var ga = document.createElement(\'script\'); ga.type = \'text/javascript\'; ga.async = true;' . PHP_EOL . 'ga.src = (\'https:\' == document.location.protocol ? \'https://ssl\' : \'http://www\') + \'.google-analytics.com/ga.js\';' . PHP_EOL . 'var s = document.getElementsByTagName(\'script\')[0]; s.parentNode.insertBefore(ga, s);' . PHP_EOL . '})();' . PHP_EOL . '</script>'; } $content = str_replace('{{analytics}}', $analytics, $content); // rss $rss = ''; if ($page['Rss'] != '') { $rss_arr = explode(',', $page['Rss']); $count = count($rss_arr); for ($x = 0; $x < $count; $x++) { $rss_pageType = PageType::GetByFriendlyId($rss_arr[$x], $site['SiteId']); if ($rss_pageType != null) { $rss .= '<link rel="alternate" type="application/rss+xml" title="' . $site['Name'] . ' - ' . $rss_pageType['TypeP'] . ' RSS Feed" href="' . $rootloc . 'data/' . strtolower($rss_pageType['TypeP']) . '.xml">' . PHP_EOL; } } } $content = str_replace('{{rss}}', $rss, $content); // preview content $p_content = ''; $status = 'publish'; if ($preview == true) { $status = 'draft'; } $fragment = $root . 'sites/' . $site['FriendlyId'] . '/fragments/' . $status . '/' . $page['PageUniqId'] . '.html'; if (file_exists($fragment)) { $p_content = file_get_contents($fragment); } // update images with sites/[name] to a relative URL $p_content = str_replace('src="sites/' . $site['FriendlyId'] . '/', 'src="' . $rootloc, $p_content); //content and synopsis $content = str_replace('{{content}}', $p_content, $content); // parses the template to get the html $html = Utilities::ParseHTML($site, $page, $content, $preview, $root); $pageTypeUniqId = '-1'; if ($pageType) { $pageTypeUniqId = $pageType['PageTypeUniqId']; } if ($preview == true) { $pageTypeUniqId = 'preview'; } $pageUrl = ltrim($path, '/'); // setup php header $header = '<?php ' . PHP_EOL . '$rootPrefix="' . $rootloc . '";' . PHP_EOL . '$formPublicId="' . $site['FormPublicId'] . '";' . PHP_EOL . '$pageUrl="' . $pageUrl . '";' . PHP_EOL . '$isSecure=' . ($isSecure ? 'true' : 'false') . ';' . PHP_EOL . '$siteUniqId="' . $site['SiteUniqId'] . '";' . PHP_EOL . '$siteFriendlyId="' . $site['FriendlyId'] . '";' . PHP_EOL . '$pageUniqId="' . $page['PageUniqId'] . '";' . PHP_EOL . '$pageFriendlyId="' . $page['FriendlyId'] . '";' . PHP_EOL . '$pageTypeUniqId="' . $pageTypeUniqId . '";' . PHP_EOL . '$language="' . $site['Language'] . '";' . PHP_EOL . 'include \'../../' . $rootloc . 'libs/Utilities.php\';' . PHP_EOL . 'include \'' . $rootloc . 'libs/SiteAuthUser.php\';' . PHP_EOL . 'include \'' . $rootloc . 'site.php\';' . PHP_EOL; $header .= '?>'; $api = APP_URL; $inject = '<body data-siteuniqid="' . $site['SiteUniqId'] . '" data-sitefriendlyid="' . $site['FriendlyId'] . '" data-domain="' . $site['Domain'] . '" data-pageuniqid="' . $page['PageUniqId'] . '" data-pagefriendlyid="' . $page['FriendlyId'] . '" data-pagetypeuniqid="' . $pageTypeUniqId . '" data-api="' . $api . '"'; $html = str_replace('<body', $inject, $html); $html = str_replace('{root}', $rootloc, $html); return $header . $html; }
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; }