public function InstapageCmsPluginPageModel::display in Instapage plugin 7.3
Same name and namespace in other branches
- 8.3 core/models/InstapageCmsPluginPageModel.php \InstapageCmsPluginPageModel::display()
Displays the landing page.
Parameters
object $page Landing page to display.:
int $forcedStatus Status to be set as a header. Default: null.:
File
- core/
models/ InstapageCmsPluginPageModel.php, line 418
Class
- InstapageCmsPluginPageModel
- Class responsible for managing the landing pages.
Code
public function display($page, $forcedStatus = null) {
require_once __DIR__ . '/../modules/lpAjaxLoader/InstapageCmsPluginLPAjaxLoaderController.php';
$lpAjaxLoaderController = new InstapageCmsPluginLPAjaxLoaderController();
$instapageId = $page->instapage_id;
$slug = $page->slug;
$host = parse_url($page->enterprise_url, PHP_URL_HOST);
InstapageCmsPluginHelper::writeDiagnostics($slug . ' : ' . $instapageId, 'slug : instapage_id');
$api = InstapageCmsPluginAPIModel::getInstance();
$querySufix = '';
$cookies = $_COOKIE;
if (!empty($_GET)) {
if ($lpAjaxLoaderController
->shouldDecodeQuery()) {
$querySufix = '?' . base64_decode($_GET['b64']);
}
else {
$querySufix = '?' . http_build_query($_GET);
}
}
elseif (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) {
$querySufix = '?' . $_SERVER['QUERY_STRING'];
}
if (is_array($cookies) && count($cookies)) {
$cookiesWeNeed = array(
"instapage-variant-{$instapageId}",
);
foreach ($cookies as $key => $value) {
if (!in_array($key, $cookiesWeNeed)) {
unset($cookies[$key]);
}
}
}
$url = preg_replace('/https?:\\/\\/' . $host . '/', INSTAPAGE_ENTERPRISE_ENDPOINT, $page->enterprise_url);
$url .= $querySufix;
$url = InstapageCmsPluginConnector::getURLWithSelectedProtocol($url);
$enterpriseCallResult = $api
->enterpriseCall($url, $host, $cookies);
$html = $this
->getLandingPageHTMLFromTheApp($enterpriseCallResult);
$this
->setVariantCookie($enterpriseCallResult, $instapageId);
if ($lpAjaxLoaderController
->shouldBeUsed($url)) {
$html = $lpAjaxLoaderController
->injectScript($html);
$html = $lpAjaxLoaderController
->addDisplayNoneOnBody($html);
}
if ($forcedStatus) {
$status = $forcedStatus;
}
else {
$status = isset($enterpriseCallResult['code']) ? $enterpriseCallResult['code'] : 200;
}
if ($html) {
ob_start();
InstapageCmsPluginHelper::disableCaching();
InstapageCmsPluginHelper::httpResponseCode($status);
print $html;
ob_end_flush();
die;
}
else {
return false;
}
}