Exemplo n.º 1
0
 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;
     }
 }
Exemplo n.º 2
0
 /**
  * @method POST
  */
 function generate()
 {
     // get an authuser
     $authUser = new AuthUser();
     if (isset($authUser->UserUniqId)) {
         // check if authorized
         parse_str($this->request->data, $request);
         // parse request
         $name = $request['name'];
         $content = $request['content'];
         $site = Site::GetBySiteId($authUser->SiteId);
         $dir = '../sites/' . $site['FriendlyId'] . '/';
         Utilities::SaveContent($dir, $name, $content);
         return new Tonic\Response(Tonic\Response::OK);
     } else {
         // unauthorized access
         return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
     }
     return new Tonic\Response(Tonic\Response::NOTIMPLEMENTED);
 }
Exemplo n.º 3
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;
 }
Exemplo n.º 4
0
 /**
  * @method POST
  */
 function post()
 {
     // get token
     $token = Utilities::ValidateJWTToken();
     // check if token is not null
     if ($token != NULL) {
         // get a reference to the site, user
         $site = Site::GetBySiteId($token->SiteId);
         parse_str($this->request->data, $request);
         // parse request
         // get content
         $content = $request['content'];
         // set locale as default language
         $locale = $site['Language'];
         // override if in request
         if (isset($request['locale'])) {
             $locale = $request['locale'];
         }
         // decode JSON
         $json = json_decode($content);
         // encode it to make it look pretty
         if (defined('JSON_PRETTY_PRINT')) {
             $content = json_encode($json, JSON_PRETTY_PRINT);
         } else {
             $content = json_encode($json);
         }
         // make the locales directory if it does not exist
         $locales_dir = SITES_LOCATION . '/' . $site['FriendlyId'] . '/locales';
         // create locales directory if it does not exist
         if (!file_exists($locales_dir)) {
             mkdir($locales_dir, 0755, true);
         }
         // set directory an filename
         $locale_dir = $locales_dir . '/' . $locale . '/';
         // make the locale dir if it does not exist
         if (!file_exists($locale_dir)) {
             mkdir($locale_dir, 0755, true);
         }
         // set filename
         $filename = 'translation.json';
         // save content
         Utilities::SaveContent($locale_dir, $filename, $content);
         // return a json response
         return new Tonic\Response(Tonic\Response::OK);
     } else {
         // return an unauthorized exception (401)
         return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
     }
 }
Exemplo n.º 5
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);
         }
         // 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;
 }
Exemplo n.º 6
0
 /**
  * @method POST
  */
 function post()
 {
     parse_str($this->request->data, $request);
     // parse request
     $friendlyId = trim($request['friendlyId']);
     $name = trim($request['name']);
     $s_passcode = $request['passcode'];
     $timeZone = $request['timeZone'];
     $email = '';
     $password = '';
     $language = DEFAULT_LANGUAGE;
     // language for the app
     $direction = DEFAULT_DIRECTION;
     $userId = -1;
     // get first name and lastname
     $firstName = $request['firstName'];
     $lastName = $request['lastName'];
     // validate name and friendlyId
     if ($friendlyId == '' || $name == '') {
         return new Tonic\Response(Tonic\Response::BADREQUEST);
     }
     $theme = DEFAULT_THEME;
     // set theme
     if (isset($request['theme'])) {
         $theme = $request['theme'];
     }
     // set language if set
     if (isset($request['language'])) {
         $language = $request['language'];
     }
     // set direction if set
     if (isset($request['direction'])) {
         $direction = $request['direction'];
     }
     // check for email and password
     if (isset($request['email'])) {
         $userLanguage = 'en-us';
         if (isset($request['userLanguage'])) {
             $userLanguage = $request['userLanguage'];
         }
         $email = $request['email'];
         $password = $request['password'];
         // valide email and password
         if ($email == '' || $password == '') {
             return new Tonic\Response(Tonic\Response::BADREQUEST);
         }
     } else {
         // get an authuser
         $authUser = new AuthUser();
         if ($authUser->UserId && $authUser->IsSuperAdmin == true) {
             // check if authorized
             $userId = $authUser->UserId;
         } else {
             return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
         }
     }
     // defaults
     $domain = SITE_URL;
     $domain = str_replace('{{friendlyId}}', $friendlyId, $domain);
     $logoUrl = 'sample-logo.png';
     $altLogoUrl = '';
     if ($s_passcode == PASSCODE) {
         $isFriendlyIdUnique = Site::IsFriendlyIdUnique($friendlyId);
         // check for reserved names
         if ($friendlyId == 'app' || $friendlyId == 'sites' || $friendlyId == 'api' || $friendlyId == 'triangulate' || $friendlyId == 'developer') {
             $isFriendlyIdUnique = false;
         }
         if ($isFriendlyIdUnique == false) {
             return new Tonic\Response(Tonic\Response::CONFLICT);
         }
         // default is blank
         $welcomeEmail = '';
         $receiptEmail = '';
         // files for emails
         $welcome_file = APP_LOCATION . '/site/emails/welcome.html';
         $receipt_file = APP_LOCATION . '/site/emails/receipt.html';
         // make sure the welcome email exists
         if (file_exists($welcome_file)) {
             // get default email file
             $welcomeEmail = file_get_contents($welcome_file);
         }
         // make sure the receipt email exists
         if (file_exists($receipt_file)) {
             // get default email file
             $receiptEmail = file_get_contents($receipt_file);
         }
         // add the site
         $site = Site::Add($domain, $name, $friendlyId, $logoUrl, $altLogoUrl, $theme, $email, $timeZone, $language, $direction, $welcomeEmail, $receiptEmail);
         // add the admin
         if ($email != '') {
             $isActive = 1;
             // admins by default are active
             $user = User::Add($email, $password, $firstName, $lastName, 'Admin', $userLanguage, $isActive, $site['SiteId']);
             $userId = $user['UserId'];
         }
         // set $siteId
         $siteId = $site['SiteId'];
         // publishes a theme for a site
         Publish::PublishTheme($site, $theme);
         // publish default content for the theme
         Publish::PublishDefaultContent($site, $theme, $user['UserId']);
         // publish the site
         Publish::PublishSite($site['SiteId']);
         // create a locale directory
         $locales_dir = SITES_LOCATION . '/' . $site['FriendlyId'] . '/locales';
         // create locales directory if it does not exist
         if (!file_exists($locales_dir)) {
             mkdir($locales_dir, 0755, true);
         }
         // set directory for locale
         $locale_dir = $locales_dir . '/' . $site['Language'] . '/';
         // make the locale dir if it does not exist
         if (!file_exists($locale_dir)) {
             mkdir($locale_dir, 0755, true);
         }
         // set filename
         $filename = 'translation.json';
         if (!file_exists($locale_dir . $filename)) {
             // create a blank translation file
             Utilities::SaveContent($locale_dir, $filename, '{}');
         }
         // send welcome email
         if (SEND_WELCOME_EMAIL == true && $email != '') {
             $to = $email;
             $from = EMAILS_FROM;
             $fromName = EMAILS_FROM_NAME;
             $subject = WELCOME_EMAIL_SUBJECT;
             $file = WELCOME_EMAIL_FILE;
             // create strings to replace
             $loginUrl = APP_URL . '/login/' . $site['FriendlyId'];
             $newSiteUrl = $domain;
             $replace = array('{{brand-logo}}' => '<img src="' . BRAND_LOGO . '" style="max-height:50px">', '{{brand}}' => BRAND, '{{reply-to}}' => EMAILS_FROM, '{{new-site-url}}' => $newSiteUrl, '{{login-url}}' => $loginUrl);
             // send email from file
             Utilities::SendEmailFromFile($to, $from, $fromName, $subject, $replace, $file);
         }
         // send new site hook
         Webhooks::NewSite($site);
         // send new user hook
         Webhooks::NewUser($user);
         return new Tonic\Response(Tonic\Response::OK);
     } else {
         return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
     }
 }
Exemplo n.º 7
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);
         }
         // 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;
 }