Ejemplo n.º 1
0
 public static function createPageInTree($cPath, TreeInterface $tree, $moveToRoot = false, $pkg = null)
 {
     $txt = Loader::helper('text');
     // trim off a leading / if there is one
     $cPath = trim($cPath, '/');
     // now we grab the parent collection, if there is a static one.
     $pages = explode('/', $cPath);
     $parent = $tree->getSiteTreeObject()->getSiteHomePageObject();
     // now we iterate through the pages  to ensure that they exist in the system before adding the new guy
     $pathPrefix = '';
     $checkGlobally = false;
     for ($i = 0; $i < count($pages); ++$i) {
         $currentPath = $pathPrefix . $pages[$i];
         if ($i == 0) {
             // First, we check the first path to see if it falls outside of the root already. If it does,
             // we're not going to check within the site for them
             $rootPage = CorePage::getByPath("/" . $currentPath);
             if (!$rootPage->isError() && $rootPage->getSiteTreeID() == 0) {
                 // That means we've already added this as a system page, like Dashboard, etc... Which means
                 // that we add the subsequent pages globally
                 $checkGlobally = true;
             }
         }
         $pathToFile = static::getPathToNode($currentPath, $pkg);
         // check to see if a page at this point in the tree exists
         if (!$checkGlobally) {
             $c = CorePage::getByPath("/" . $currentPath, 'RECENT', $tree);
         } else {
             $c = CorePage::getByPath("/" . $currentPath);
         }
         if ($c->isError() && $c->getError() == COLLECTION_NOT_FOUND) {
             // create the page at that point in the tree
             $data = array();
             $data['handle'] = $pages[$i];
             $data['name'] = $txt->unhandle($data['handle']);
             $data['filename'] = $pathToFile;
             $data['uID'] = USER_SUPER_ID;
             if ($pkg != null) {
                 $data['pkgID'] = $pkg->getPackageID();
             }
             if ($moveToRoot) {
                 $newC = Page::addStatic($data, $tree);
                 $newC->moveToRoot();
                 // change cparent ID back to 0
             } else {
                 $newC = Page::addStatic($data, $parent);
             }
             $parent = $newC;
         } else {
             $parent = $c;
         }
         $pathPrefix = $currentPath . '/';
     }
     return $parent;
 }
Ejemplo n.º 2
0
 public static function addStatic($data, TreeInterface $parent = null)
 {
     $db = Database::connection();
     $cParentID = 1;
     $cDisplayOrder = 0;
     $cInheritPermissionsFromCID = 1;
     $cOverrideTemplatePermissions = 1;
     if ($parent instanceof Page) {
         $cParentID = $parent->getCollectionID();
         $parent->rescanChildrenDisplayOrder();
         $cDisplayOrder = $parent->getNextSubPageDisplayOrder();
         $cInheritPermissionsFromCID = $parent->getPermissionsCollectionID();
         $cOverrideTemplatePermissions = $parent->overrideTemplatePermissions();
     }
     if (isset($data['pkgID'])) {
         $pkgID = $data['pkgID'];
     } else {
         $pkgID = 0;
     }
     $cFilename = $data['filename'];
     $uID = USER_SUPER_ID;
     $data['uID'] = $uID;
     $cobj = parent::addCollection($data);
     $cID = $cobj->getCollectionID();
     // These get set to parent by default here, but they can be overridden later
     $cInheritPermissionsFrom = 'PARENT';
     $siteTreeID = 0;
     if (is_object($parent)) {
         $siteTreeID = $parent->getSiteTreeID();
     }
     $v = [$cID, $siteTreeID, $cFilename, $cParentID, $cInheritPermissionsFrom, $cOverrideTemplatePermissions, $cInheritPermissionsFromCID, $cDisplayOrder, $uID, $pkgID];
     $q = 'insert into Pages (cID, siteTreeID, cFilename, cParentID, cInheritPermissionsFrom, cOverrideTemplatePermissions, cInheritPermissionsFromCID, cDisplayOrder, uID, pkgID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
     $r = $db->prepare($q);
     $res = $r->execute($v);
     if ($res) {
         // Collection added with no problem -- update cChildren on parrent
         PageStatistics::incrementParents($cID);
     }
     $pc = self::getByID($cID);
     $pc->rescanCollectionPath();
     return $pc;
 }