/** * Uses a Request object to determine which page to load. queries by path and then * by cID. */ public static function getFromRequest(Request $request) { // if something has already set a page object, we return it $c = $request->getCurrentPage(); if (is_object($c)) { return $c; } if ($request->getPath() != '') { $path = $request->getPath(); $db = Database::connection(); $cID = false; $ppIsCanonical = false; $site = \Core::make('site')->getSite(); $treeIDs = [0]; foreach ($site->getLocales() as $locale) { $treeIDs[] = $locale->getSiteLocaleID(); } $treeIDs = implode(',', $treeIDs); while (!$cID && $path) { $row = $db->fetchAssoc('select pp.cID, ppIsCanonical from PagePaths pp inner join Pages p on pp.cID = p.cID where cPath = ? and siteTreeID in (' . $treeIDs . ')', [$path]); if (!empty($row)) { $cID = $row['cID']; if ($cID) { $cPath = $path; $ppIsCanonical = (bool) $row['ppIsCanonical']; break; } } $path = substr($path, 0, strrpos($path, '/')); } if ($cID && $cPath) { $c = self::getByID($cID, 'ACTIVE'); $c->cPathFetchIsCanonical = $ppIsCanonical; } else { $c = new self(); $c->loadError(COLLECTION_NOT_FOUND); } return $c; } else { $cID = $request->query->get('cID'); if (!$cID) { $cID = $request->request->get('cID'); } $cID = Core::make('helper/security')->sanitizeInt($cID); if ($cID) { $c = self::getByID($cID, 'ACTIVE'); } else { $site = \Core::make('site')->getSite(); $c = $site->getSiteHomePageObject('ACTIVE'); } $c->cPathFetchIsCanonical = true; } return $c; }