'AKIASDEM5WNICS4KN4UQ', 'secret' => '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', ]; public $dbc; public $templatePageTitle; public $templatePageDescription; public $curPage; public $s3bucket; public $s3bucketOptimized; public $s3ClientDirectory; public $s3BucketUrl; public $s3OptimizedBucketUrl; public $cdnOptimizedUrl; public $cdnOptimizedClientUrl; private $svgIcons = []; public $cdnUrl; public $cdnClientUrl; public $googleAPIkey; public $uspsUserId; public $rawPage; public $generatedId; public $parentPage; public $templatePage; public $category; public $slugOverride; public $clearanceProduct; public $outletProduct; public $customInventoryTypeProduct; public $isMyAccount; public $isCategory; public $isCategoryShop; public $isSubCategory; public $isProductGroup; public $isBrand; public $isBrandPage; public $isClearance; public $isOutlet; public $isCustomInventoryType; public $shopAll; public $isProductPage; public $isLocation; public $isCart; public $isCollection; public $isBlogIndex; public $isBlog; public $isBlogArchive; public $isBlogTags; public $isEvent; public $isShopAllLanding; public $isSearch; public $isCurated; public $mattressCategories; public $isMattresses; public $isMattressCatalogPage; public $page; public $setSiteDebugging; public $dropShipMaxQty; public $userIP; public $userLocation; public $userStoreId; public $userStoreInfo; public $pickupStoreId; public $knorrIp; public $debug; public $showVariant; public $brand; public $brandTitle; public $brandId; public $brandPage; public function __construct() { // Database connection $this->dbc = ClientDatabase::getClientDatabase(); $config = Config::getConfig(); echo $this->dbc->connect_error ? "Site is currently down for maintenance. Please refresh your browser to try again." : ""; //Get current page $protocol = isset($_SERVER["HTTPS"]) ? "https" : "http"; $this->curPage = isset($_SERVER["HTTP_HOST"]) && isset($_SERVER["REQUEST_URI"]) ? "$protocol://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] : null; //Set settings -- DEPRECATED: this functionality has been moved to the Config class // $settingsQuery = $this->dbc->query("SELECT title, setting FROM config"); // while($setting = $settingsQuery->fetch_object()) { // $var = $setting->title; // $this->$var = $setting->setting; // } //Set S3 Settings $this->s3bucket = 'knorrcatalog'; $this->s3bucketOptimized = 'knorrcatalog-optimized'; $this->s3ClientDirectory = 'sites/'.$config->clientCode.'/'; $this->s3BucketUrl = 'https://'.$this->s3bucket.'.s3-accelerate.amazonaws.com/'.$this->s3ClientDirectory; $this->s3OptimizedBucketUrl = 'https://'.$this->s3bucketOptimized.'.s3.amazonaws.com/'.$this->s3ClientDirectory; //Set cloudFront/CDN //$this->cdnUrl = 'https://d2yb88fn1bt7t.cloudfront.net/'; //Original cloudfront url $this->cdnUrl = strpos($config->url, '.knorrweb.com') !== false || strpos($config->url, 'local') !== false || strpos($config->url, 'test') !== false ? 'https://'.$this->s3bucket.'.s3.amazonaws.com/' : 'https://cdn.knorrweb.com/'; //The pretty one $this->cdnOptimizedUrl = strpos($config->url, '.knorrweb.com') !== false || strpos($config->url, 'local') !== false || strpos($config->url, 'test') !== false ? 'https://'.$this->s3bucketOptimized.'.s3.amazonaws.com/' : 'https://cdn.knorrweb.com/'; $this->cdnClientUrl = strpos($config->url, '.knorrweb.com') !== false ? $this->s3BucketUrl : $this->cdnUrl.$this->s3ClientDirectory; $this->cdnOptimizedClientUrl = strpos($config->url, '.knorrweb.com') !== false ? $this->s3OptimizedBucketUrl : $this->cdnOptimizedUrl.$this->s3ClientDirectory; //Set timezone date_default_timezone_set($config->defaultTimezone); //Page settings $this->rawPage = isset($_GET['page']) && !empty($_GET['page']) ? htmlspecialchars($_GET['page'], ENT_QUOTES) : 'index'; $this->generatedId = isset($_GET['v']) && !empty($_GET['v']) ? htmlspecialchars($_GET['v'], ENT_QUOTES) : null; $this->parentPage = isset($_GET['parentPage']) && !empty($_GET['parentPage']) ? htmlspecialchars($_GET['parentPage'], ENT_QUOTES) : ''; $this->templatePage = isset($_GET['templatepage']) && !empty($_GET['templatepage']) ? htmlspecialchars($_GET['templatepage'], ENT_QUOTES) : ''; $this->category = isset($_GET['category']) && !empty($_GET['category']) ? htmlspecialchars($_GET['category'], ENT_QUOTES) : ''; $this->slugOverride = !empty($config->slugOverride) ? $config->slugOverride : ''; //Inventory type $inventoryType = isset($_GET['inventoryType']) && !empty($_GET['inventoryType']) ? htmlspecialchars($_GET['inventoryType'], ENT_QUOTES) : ''; if (empty($inventoryType) && !is_null($this->generatedId)) { $productData = $this->getProductByGeneratedId($this->generatedId); if ($productData && !is_null($productData->inventoryType)) { $inventoryTypeData = $this->getInventoryTypeData($productData->inventoryType); $inventoryType = !is_null($inventoryTypeData) && $inventoryTypeData->folder ? $inventoryTypeData->folder : ''; } } $clearanceTypeData = $this->getInventoryTypeData(1); $outletTypeData = $this->getInventoryTypeData(2); $this->clearanceProduct = $clearanceTypeData && $clearanceTypeData->folder == $inventoryType ? $clearanceTypeData : null; $this->outletProduct = $outletTypeData && $outletTypeData->folder == $inventoryType ? $outletTypeData : null; $customInventoryTypes = array_column($this->dbc->query("SELECT folder FROM inventoryTypes WHERE active='1' AND type='custom'")->fetch_all(MYSQLI_ASSOC), 'folder'); $this->customInventoryTypeProduct = in_array($inventoryType, $customInventoryTypes) ? $this->getInventoryTypeData($inventoryType) : null; //Check for page type $this->isMyAccount = $this->myAccountSearch(); $this->isCategory = $this->categorySearch(); $this->isCategoryShop = $this->categoryShopSearch(); $this->isSubCategory = $this->subCategorySearch(); $this->isProductGroup = $this->productGroupSearch(); $this->isBrand = $this->brandSearch(); $this->isBrandPage = $this->brandPageSearch(); $this->isClearance = $this->clearanceSearch(); $this->isOutlet = $this->outletSearch(); $this->isCustomInventoryType = $this->customInventoryTypeSearch(); $this->shopAll = $this->shopAllSearch(); $this->isProductPage = $this->productPageSearch(); $this->isLocation = $this->locationSearch(); $this->isCart = $this->cartSearch(); $this->isCollection = $this->collectionSearch(); $this->isBlogIndex = $this->blogIndexSearch(); $this->isBlog = $this->blogSearch(); $this->isBlogArchive = $this->blogArchiveSearch(); $this->isBlogTags = $this->blogTagsSearch(); $this->isEvent = $this->eventSearch(); $this->isShopAllLanding = $this->shopAllLandingSearch(); $this->isSearch = $this->searchSearch(); $this->isCurated = $this->curatedSearch(); $this->mattressCategories = ['mattresses','foundations-bases','mattress-protectors']; $this->isMattresses = in_array($this->category, $this->mattressCategories); $this->isMattressCatalogPage = $this->rawPage == 'mattresses' && strpos($this->curPage, 'shop-mattresses/mattresses') !== false; //Set page settings $this->page = $this->getPage(); // var_dump($this->page); //Debugging $this->setSiteDebugging(); //Get user location information $this->userIP = Geolocation::getUserIP(); //Get user store info $userStoreInfo = $this->getUserStoreInfo(); $this->userStoreId = !empty($userStoreInfo) ? $userStoreInfo->id : 0; $this->userStoreInfo = $userStoreInfo; //Get user pickup location $this->pickupStoreId = $this->getUserPickupStoreId(); //Check for Knorr IP Address $this->knorrIp = preg_match('/71\.89\.153|10\.0\.0\.254|10\.0\.1\.125/i', $this->userIP); } private function getPage() { // Don't look for content pages if we're in a catalog context if (!empty($this->category)) { // We're in catalog context - only check for 404 if nothing else matches if (!$this->templatePage && !$this->isMyAccount && !$this->isCategory && !$this->isCategoryShop && !$this->isSubCategory && !$this->isProductGroup && !$this->isBrand && !$this->isBrandPage && !$this->isClearance && !$this->isOutlet && !$this->isCustomInventoryType && !$this->shopAll && !$this->isProductPage && !$this->isLocation && !$this->isCart && !$this->isBlogIndex && !$this->isBlog && !$this->isBlogArchive && !$this->isBlogTags && !$this->isShopAllLanding && !$this->isEvent && !$this->isSearch) { // Check for 404 page $page = $this->dbc->query(" SELECT *, IF(metaTitle!='', metaTitle, title) metaTitle FROM pages WHERE page = '404-page-not-found' AND active = '1' "); if ($page->num_rows > 0) { $thisPage = $page->fetch_object(); header("HTTP/1.0 404 Not Found"); } else { $thisPage = false; } } else { $thisPage = false; } return $thisPage; } // Original content page lookup for non-catalog contexts $page = $this->dbc->query(" SELECT *, IF(metaTitle != '', metaTitle, title) metaTitle FROM pages WHERE page = '$this->rawPage' AND active = '1' "); if ($page->num_rows > 0) $thisPage = $page->fetch_object(); else if (!$this->templatePage && !$this->isMyAccount && !$this->isCategory && !$this->isCategoryShop && !$this->isSubCategory && !$this->isProductGroup && !$this->isBrand && !$this->isBrandPage && !$this->isClearance && !$this->isOutlet && !$this->isCustomInventoryType && !$this->shopAll && !$this->isProductPage && !$this->isLocation && !$this->isCart && !$this->isBlogIndex && !$this->isBlog && !$this->isBlogArchive && !$this->isBlogTags && !$this->isShopAllLanding && !$this->isEvent && !$this->isSearch) { // Check for 404 page $page = $this->dbc->query(" SELECT *, IF(metaTitle!='', metaTitle, title) metaTitle FROM pages WHERE page = '404-page-not-found' AND active = '1' "); if ($page->num_rows > 0) { $thisPage = $page->fetch_object(); header("HTTP/1.0 404 Not Found"); } else $thisPage = false; } else $thisPage = false; return $thisPage; } public function loadTemplate() { $tpl = __DIR__ . "/../tpl"; if ($this->page !== false) include "$tpl/{$this->page->template}.php"; else if ($this->isMyAccount) include "$tpl/my-account.php"; else if ($this->isCategory) include "$tpl/category.php"; else if ($this->isSubCategory || $this->isBrand || $this->isClearance || $this->isOutlet || $this->isCustomInventoryType || $this->isProductGroup || $this->shopAll || $this->isCategoryShop) include "$tpl/subCategory.php"; else if ($this->isProductPage) include "$tpl/product.php"; else if ($this->isBrandPage) include "$tpl/brands.php"; else if ($this->isLocation) include "$tpl/location.php"; else if ($this->isShopAllLanding) include "$tpl/shop-all-landing.php"; else include "$tpl/page.php"; } /** * Writes (to stdout) the relevant code to add Google Tag Manager to the * page. * * @param $part string Either 'head' or 'body', depending on which * @return void */ public function loadTagManager(string $part): void { $tagManager = Config::getConfig()->tagManager; if (empty($tagManager)) return; if ($part === "head") { ?> pushToDataLayer() ?> userStoreInfo)) { //Display selected store's # if location is already set ?>