Example #1
0
 /**
  * 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();
         $r = array();
         $db = Loader::db();
         $cID = false;
         while (!$cID && $path) {
             $cID = $db->GetOne('select cID from PagePaths where cPath = ?', array($path));
             if ($cID) {
                 $cPath = $path;
                 break;
             }
             $path = substr($path, 0, strrpos($path, '/'));
         }
         if ($cID && $cPath) {
             $c = Page::getByID($cID, 'ACTIVE');
         } else {
             $c = new Page();
             $c->loadError(COLLECTION_NOT_FOUND);
         }
         return $c;
     } else {
         $cID = $request->query->get('cID');
         if (!$cID) {
             $cID = $request->request->get('cID');
         }
         $cID = Loader::helper('security')->sanitizeInt($cID);
         if (!$cID) {
             $cID = 1;
         }
         $c = Page::getByID($cID, 'ACTIVE');
     }
     return $c;
 }
Example #2
0
 /**
  * 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::get();
         $cID = false;
         $ppIsCanonical = false;
         while (!$cID && $path) {
             $row = $db->GetRow('select cID, ppIsCanonical from PagePaths where cPath = ?', array($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 = Page::getByID($cID, 'ACTIVE');
             $c->cPathFetchIsCanonical = $ppIsCanonical;
         } else {
             $c = new Page();
             $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) {
             $cID = 1;
         }
         $c = Page::getByID($cID, 'ACTIVE');
         $c->cPathFetchIsCanonical = true;
     }
     return $c;
 }
Example #3
0
 public function loadError($error)
 {
     return parent::loadError($error);
 }