예제 #1
0
 /**
  * Adds a new page of a certain type, using a passed associate array to setup value. $data may contain any or all of the following:
  * "uID": User ID of the page's owner
  * "pkgID": Package ID the page belongs to
  * "cName": The name of the page
  * "cHandle": The handle of the page as used in the path
  * "cDatePublic": The date assigned to the page.
  *
  * @param \Concrete\Core\Page\Type\Type $pt
  * @param array $data
  *
  * @return page
  **/
 public function add($pt, $data, $template = false)
 {
     $data += array('cHandle' => null);
     $db = Database::get();
     $txt = Core::make('helper/text');
     // the passed collection is the parent collection
     $cParentID = $this->getCollectionID();
     $u = new User();
     if (isset($data['uID'])) {
         $uID = $data['uID'];
     } else {
         $uID = $u->getUserID();
         $data['uID'] = $uID;
     }
     if (isset($data['pkgID'])) {
         $pkgID = $data['pkgID'];
     } else {
         $pkgID = 0;
     }
     if (isset($data['cName'])) {
         $data['name'] = $data['cName'];
     }
     if (!$data['cHandle']) {
         // make the handle out of the title
         $handle = $txt->urlify($data['name']);
     } else {
         $handle = $txt->slugSafeString($data['cHandle']);
         // we take it as it comes.
     }
     $handle = str_replace('-', Config::get('concrete.seo.page_path_separator'), $handle);
     $data['handle'] = $handle;
     $ptID = 0;
     $masterCIDBlocks = null;
     $masterCID = null;
     if ($pt instanceof \Concrete\Core\Page\Type\Type) {
         if ($pt->getPageTypeHandle() == STACKS_PAGE_TYPE) {
             $data['cvIsNew'] = 0;
         }
         if ($pt->getPackageID() > 0) {
             $pkgID = $pt->getPackageID();
         }
         // if we have a page type and we don't have a template,
         // then we use the page type's default template
         if ($pt->getPageTypeDefaultPageTemplateID() > 0 && !$template) {
             $template = $pt->getPageTypeDefaultPageTemplateObject();
         }
         $ptID = $pt->getPageTypeID();
         if ($template) {
             $mc1 = $pt->getPageTypePageTemplateDefaultPageObject($template);
             $mc2 = $pt->getPageTypePageTemplateDefaultPageObject();
             $masterCIDBlocks = $mc1->getCollectionID();
             $masterCID = $mc2->getCollectionID();
         }
     }
     if ($template instanceof PageTemplate) {
         $data['pTemplateID'] = $template->getPageTemplateID();
     }
     $cobj = parent::addCollection($data);
     $cID = $cobj->getCollectionID();
     //$this->rescanChildrenDisplayOrder();
     $cDisplayOrder = $this->getNextSubPageDisplayOrder();
     $cInheritPermissionsFromCID = $this->overrideTemplatePermissions() ? $this->getPermissionsCollectionID() : $masterCID;
     $cInheritPermissionsFrom = $this->overrideTemplatePermissions() ? 'PARENT' : 'TEMPLATE';
     $v = array($cID, $ptID, $cParentID, $uID, $cInheritPermissionsFrom, $this->overrideTemplatePermissions(), $cInheritPermissionsFromCID, $cDisplayOrder, $pkgID);
     $q = 'insert into Pages (cID, ptID, cParentID, uID, cInheritPermissionsFrom, cOverrideTemplatePermissions, cInheritPermissionsFromCID, cDisplayOrder, pkgID) values (?, ?, ?, ?, ?, ?, ?, ?, ?)';
     $r = $db->prepare($q);
     $res = $db->execute($r, $v);
     $newCID = $cID;
     if ($res) {
         // Collection added with no problem -- update cChildren on parrent
         PageStatistics::incrementParents($newCID);
         if ($r) {
             // now that we know the insert operation was a success, we need to see if the collection type we're adding has a master collection associated with it
             if ($masterCIDBlocks) {
                 $this->_associateMasterCollectionBlocks($newCID, $masterCIDBlocks);
             }
             if ($masterCID) {
                 $this->_associateMasterCollectionAttributes($newCID, $masterCID);
             }
         }
         $pc = Page::getByID($newCID, 'RECENT');
         // if we are in the drafts area of the site, then we don't check multilingual status. Otherwise
         // we do
         if ($this->getCollectionPath() != Config::get('concrete.paths.drafts')) {
             Section::registerPage($pc);
         }
         if ($template) {
             $pc->acquireAreaStylesFromDefaults($template);
         }
         // run any internal event we have for page addition
         $pe = new Event($pc);
         Events::dispatch('on_page_add', $pe);
         $pc->rescanCollectionPath();
     }
     return $pc;
 }
예제 #2
0
 public function getPageTypeHandle()
 {
     return parent::getPageTypeHandle();
 }