/** * @method POST */ function get() { parse_str($this->request->data, $request); // parse request $siteUniqId = SITE_UNIQ_ID; $pageUniqId = $request['pageUniqId']; $prefix = $request['prefix']; // handle reverse lookup if (strpos($pageUniqId, 'lookup:') !== FALSE) { $url = str_replace('lookup:', '', $pageUniqId); $page = Page::GetByUrl($url, SITE_ID); if ($page != NULL) { $pageUniqId = $page['PageUniqId']; } } // get language $language = 'en'; if (isset($request['language'])) { $language = $request['language']; } $site = Site::GetBySiteUniqId($siteUniqId); // get fragment $fragment = '../fragments/render/' . $pageUniqId . '.php'; if (file_exists($fragment)) { // set language to the domain for the site $domain = '../locale'; Utilities::SetLanguage($language, $domain); ob_start(); // start output buffer textdomain($domain); include $fragment; $content = ob_get_contents(); // get contents of buffer ob_end_clean(); // fix nested, relative URLs if displayed in the root if ($prefix == '') { $content = str_replace('src="../', 'src="', $content); $content = str_replace('href="../', 'href="', $content); } // update images with sites/[name] to a relative URL $content = str_replace('src="sites/' . $site['FriendlyId'] . '/', 'src="' . $prefix, $content); // return html response $response = new Tonic\Response(Tonic\Response::OK); $response->contentType = 'text/html'; $response->body = $content; return $response; } else { return new Tonic\Response(Tonic\Response::NOTFOUND); } }
public static function ParseHTML($site, $page, $content, $preview, $root = '../') { $html = str_get_html($content, true, true, DEFAULT_TARGET_CHARSET, false, DEFAULT_BR_TEXT); $mapcount = 0; $pageId = $page['PageId']; $rootloc = ''; $commonloc = '../common/'; // set page url $pageurl = 'http://' . $site['Domain']; if ($page['PageTypeId'] != -1) { $pageType = PageType::GetByPageTypeId($page['PageTypeId']); $pageurl .= '/' . $pageType['FriendlyId'] . '/' . $page['FriendlyId']; } else { $pageurl .= '/' . $page['FriendlyId']; } // set root and common locations if ($page['PageTypeId'] != -1 || $preview == true) { $rootloc = '../'; $commonloc = '../../common/'; } $css = $rootloc . 'css/' . $page['Stylesheet'] . '.css'; if ($html == null) { return ''; } // setup gettext blockquote, h1, h2, h3, p, td, th, li, meta tags for multi-lingual support foreach ($html->find('#content blockquote') as $el) { $el->innertext = Utilities::GenerateGettext($el->innertext); } foreach ($html->find('#content h1') as $el) { $el->innertext = Utilities::GenerateGettext($el->innertext); } foreach ($html->find('#content h2') as $el) { $el->innertext = Utilities::GenerateGettext($el->innertext); } foreach ($html->find('#content h3') as $el) { $el->innertext = Utilities::GenerateGettext($el->innertext); } foreach ($html->find('#content p') as $el) { $el->innertext = Utilities::GenerateGettext($el->innertext); } foreach ($html->find('#content td') as $el) { $el->innertext = Utilities::GenerateGettext($el->innertext); } foreach ($html->find('#content th') as $el) { $el->innertext = Utilities::GenerateGettext($el->innertext); } foreach ($html->find('#content li') as $el) { $el->innertext = Utilities::GenerateGettext($el->innertext); } foreach ($html->find('meta[name=description]') as $el) { $content = $el->content; $el->content = Utilities::GenerateGettext($content); } foreach ($html->find('meta[name=keywords]') as $el) { $content = $el->content; $el->content = Utilities::GenerateGettext($content); } foreach ($html->find('meta[name=callout]') as $el) { $content = $el->content; $el->content = Utilities::GenerateGettext($content); } // parse module foreach ($html->find('module') as $el) { if (isset($el->name)) { $name = $el->name; if ($name == 'styles') { $el->outertext = '<link href="' . $css . '" type="text/css" rel="stylesheet" media="screen">' . '<link href="' . BOOTSTRAP_CSS . '" rel="stylesheet">' . '<link href="' . FONTAWESOME_CSS . '" rel="stylesheet">' . '<link href="' . $rootloc . 'css/prettify.css" type="text/css" rel="stylesheet" media="screen">'; } else { if ($name == 'header') { ob_start(); include $root . 'sites/common/modules/header.php'; // loads the module $content = ob_get_contents(); // holds the content ob_end_clean(); $el->outertext = $content; } else { if ($name == 'scripts') { ob_start(); include $root . 'sites/common/modules/scripts.php'; // loads the module $content = ob_get_contents(); // holds the content ob_end_clean(); $el->outertext = $content; } else { if ($name == 'analytics') { ob_start(); $webpropertyid = $site['AnalyticsId']; include $root . 'sites/common/modules/analytics.php'; // loads the module $content = ob_get_contents(); // holds the content ob_end_clean(); $el->outertext = $content; } else { if ($name == 'rss') { ob_start(); include $root . 'sites/common/modules/rss.php'; // loads the module $content = ob_get_contents(); // holds the content ob_end_clean(); $el->outertext = $content; } else { if ($name == 'list') { $pageTypeUniqId = ''; if (isset($el->type)) { $pageTypeUniqId = $el->type; } // translate a friendlyId to a pageTypeUniqId if (isset($el->pagetype)) { $friendlyId = $el->pagetype; $pageType = PageType::GetByFriendlyId($friendlyId, $site['SiteId']); $pageTypeUniqId = $pageType['PageTypeUniqId']; } if ($pageTypeUniqId != '') { $label = $el->label; $isAjax = false; $pageNo = 1; $curr = 0; $listid = $el->id; $display = $el->display; $desclength = $el->desclength; $length = $el->length; $orderby = $el->orderby; $category = $el->category; $pageresults = $el->pageresults; if ($el->display == 'blog') { $list = ''; ob_start(); include $root . 'sites/common/modules/list-blog.php'; // loads the module $list = ob_get_contents(); // get content from module ob_end_clean(); } else { if ($el->display == 'list') { $list = ''; ob_start(); include $root . 'sites/common/modules/list.php'; // loads the module $list = ob_get_contents(); // get content from module ob_end_clean(); } else { if ($el->display == 'thumbnails') { $list = ''; ob_start(); include $root . 'sites/common/modules/list-thumbnails.php'; // loads the module $list = ob_get_contents(); // get content from module ob_end_clean(); } else { if ($el->display == 'calendar') { $list = ''; ob_start(); include $root . 'sites/common/modules/list-calendar.php'; // loads the module $list = ob_get_contents(); // get content from module ob_end_clean(); } else { if ($el->display == 'map') { $list = ''; $id = 'map-' + $mapcount; $cssClass = ''; $zoom = 'auto'; ob_start(); include $root . 'sites/common/modules/list-map.php'; // loads the module $list = ob_get_contents(); // get content from module ob_end_clean(); $mapcount++; } } } } } $el->outertext = $list; } } else { if ($name == 'featured') { $id = $el->id; $pageName = $el->pagename; $pageUniqId = ''; if (isset($el->pageuniqid)) { $pageUniqId = $el->pageuniqid; } // translate a friendlyId to a pageTypeUniqId if (isset($el->url)) { $url = $el->url; $page = Page::GetByUrl($url, $site['SiteId']); $pageUniqId = $page['PageUniqId']; } $featured = '<div id="' . $id . '" data-pageuniqid="' . $pageUniqId . '" data-pagename="' . $pageName . '" class="featured-content">' . '<p class="featured-loading"><i class="fa fa-spinner fa-spin"></i> <?php print _("Loading..."); ?></p>' . '</div>'; $el->outertext = $featured; } else { if ($name == 'secure') { if (isset($el->type)) { $type = $el->type; } else { $type = 'login'; } $el->outertext = '<?php include "' . $commonloc . 'modules/' . $type . '.php"; ?>'; } else { if ($name == 'menu') { if (isset($el->type)) { $type = $el->type; } else { $type = 'primary'; } $el->outertext = '<?php $type="' . $type . '"; include "' . $commonloc . 'modules/menu.php"; ?>'; } else { if ($name == 'footer') { ob_start(); $copy = $el->innertext; include $root . 'sites/common/modules/footer.php'; // loads the module $content = ob_get_contents(); // holds the content ob_end_clean(); $el->outertext = $content; } else { if ($name == 'slideshow') { $id = $el->id; $display = 'slideshow'; if (isset($el->display)) { $display = $el->display; } $imgList = $el->innertext; ob_start(); if ($display == 'gallery') { include $root . 'sites/common/modules/gallery.php'; // loads the module } else { include $root . 'sites/common/modules/slideshow.php'; // loads the module } $content = ob_get_contents(); // holds the content ob_end_clean(); $el->outertext = $content; } else { if ($name == 'html') { $h = $el->innertext; $el->outertext = $h; } else { if ($name == 'youtube' || $name == 'vimeo') { $el->outertext = $el->innertext; } else { if ($name == 'file') { $file = $el->file; $description = $el->description; ob_start(); include $root . 'sites/common/modules/file.php'; // loads the module $content = ob_get_contents(); // holds the content ob_end_clean(); $el->outertext = $content; } else { if ($name == 'form') { $formId = 'form-0'; if (isset($el->id)) { $formId = $el->id; } $type = 'default'; if (isset($el->type)) { $type = $el->type; } $action = ''; if (isset($el->action)) { $action = $el->action; } $successMessage = ''; if (isset($el->success)) { $successMessage = $el->success; } $errorMessage = ''; if (isset($el->error)) { $errorMessage = $el->error; } $submitText = ''; if (isset($el->submit)) { $submitText = $el->submit; } // place gettext around labels foreach ($el->find('label') as $el_label) { if (count($el_label->find('input')) > 0) { // generate gettext for radios, checkboxes $input_arr = $el_label->find('input'); $input_txt = $input_arr[0]->outertext; $text = str_replace($input_txt, '', $el_label->innertext); // replace input text $el_label->innertext = $input_txt . Utilities::GenerateGettext($text); } else { $el_label->innertext = Utilities::GenerateGettext($el_label->innertext); } } // place gettext around spans foreach ($el->find('.help-block') as $el_block) { $el_block->innertext = Utilities::GenerateGettext($el_block->innertext); } if (strpos($el->innertext, '{{reCaptcha}}') > 0) { $replace = '<?php require_once(\'' . $root . 'libs/recaptchalib.php\'); echo recaptcha_get_html("' . $site['FormPublicId'] . '");?>'; $el->innertext = str_replace('{{reCaptcha}}', $replace, $el->innertext); } $form = $el->innertext; ob_start(); include $root . 'sites/common/modules/form.php'; // loads the module $content = ob_get_contents(); // holds the content ob_end_clean(); $el->outertext = $content; } else { if ($name == 'map') { $address = $el->address; if (isset($el->zoom)) { $zoom = $el->zoom; } else { $zoom = 'auto'; } if (isset($el->id)) { $id = $el->id; } else { $id = 'map-' + $mapcount; } if (isset($el->class)) { $cssClass = $el->class; } else { $cssClass = ''; } ob_start(); include $root . 'sites/common/modules/map.php'; // loads the module $content = ob_get_contents(); // holds the content ob_end_clean(); $el->outertext = $content; $mapcount++; } else { if ($name == 'like') { $username = $el->username; ob_start(); include $root . 'sites/common/modules/like.php'; // loads the module $content = ob_get_contents(); // holds the content ob_end_clean(); $el->outertext = $content; } else { if ($name == 'comments') { ob_start(); include $root . 'sites/common/modules/comments.php'; // loads the module $content = ob_get_contents(); // holds the content ob_end_clean(); $el->outertext = $content; } else { if ($name == 'byline') { ob_start(); include $root . 'sites/common/modules/byline.php'; // loads the module $content = ob_get_contents(); // holds the content ob_end_clean(); $el->outertext = $content; } else { if ($name == 'shelf') { // place gettext around descripton foreach ($el->find('.shelf-description') as $el_label) { $el_label->innertext = Utilities::GenerateGettext($el_label->innertext); } // place gettext around shipping foreach ($el->find('.shelf-shipping') as $el_label) { $el_label->innertext = Utilities::GenerateGettext($el_label->innertext); } // place gettext around add to cart button foreach ($el->find('.btn span') as $el_label) { $el_label->innertext = Utilities::GenerateGettext($el_label->innertext); } $shelfId = $el->id; $shelf = $el->innertext; ob_start(); include $root . 'sites/common/modules/shelf.php'; // loads the module $content = ob_get_contents(); // holds the content ob_end_clean(); $el->outertext = $content; } else { // do nothing } } } } } } } } } } } } } } } } } } } } } } foreach ($html->find('plugin') as $el) { $attrs = $el->attr; $p_vars = ''; foreach ($attrs as $key => &$val) { ${$key} = $val; // set variable $p_vars .= '$' . $key . '="' . $val . '";'; } $id = $el->id; $name = $el->name; if ($render == 'publish') { ob_start(); include $root . 'plugins/' . $type . '/render.php'; // loads the module $content = ob_get_contents(); // holds the content ob_end_clean(); $el->outertext = $content; } else { if ($render == 'runtime') { $list = '<?php ' . $p_vars . 'include "' . $rootloc . 'plugins/' . $type . '/render.php"; ?>'; $el->outertext = $list; } } } return $html; }