public function assign() { $pr = new PageEditResponse(); if ($this->request->request->get('destID') == $this->page->getCollectionID()) { throw new \Exception(t("You cannot assign this page to itself.")); } $destPage = \Page::getByID($_POST['destID']); if (Section::isMultilingualSection($destPage)) { $ms = Section::getByID($destPage->getCollectionID()); } else { $ms = Section::getBySectionOfSite($destPage); } if (is_object($ms)) { // we need to assign/relate the source ID too, if it doesn't exist if (!Section::isAssigned($this->page)) { Section::registerPage($this->page); } Section::relatePage($this->page, $destPage, $ms->getLocale()); $ih = Core::make('multilingual/interface/flag'); $icon = (string) $ih->getSectionFlagIcon($ms); $pr->setAdditionalDataAttribute('name', $destPage->getCollectionName()); $pr->setAdditionalDataAttribute('link', $destPage->getCollectionLink()); $pr->setAdditionalDataAttribute('icon', $icon); $pr->setMessage(t('Page assigned.')); $pr->outputJSON(); } else { throw new \Exception(t("The destination page doesn't appear to be in a valid multilingual section.")); } }
/** * 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; }
public function publish(Page $c) { $this->stripEmptyPageTypeComposerControls($c); $parent = Page::getByID($c->getPageDraftTargetParentPageID()); if ($c->isPageDraft()) { // this is still a draft, which means it has never been properly published. // so we need to move it, check its permissions, etc... Section::registerPage($c); $c->move($parent); if (!$parent->overrideTemplatePermissions()) { // that means the permissions of pages added beneath here inherit from page type permissions // this is a very poorly named method. Template actually used to mean Type. // so this means we need to set the permissions of this current page to inherit from page types. $c->inheritPermissionsFromDefaults(); } $c->activate(); } else { $c->rescanCollectionPath(); } $u = new User(); $v = CollectionVersion::get($c, 'RECENT'); $pkr = new ApprovePagePageWorkflowRequest(); $pkr->setRequestedPage($c); $pkr->setRequestedVersionID($v->getVersionID()); $pkr->setRequesterUserID($u->getUserID()); $pkr->trigger(); $u->unloadCollectionEdit($c); CacheLocal::flush(); $ev = new Event($c); $ev->setPageType($this); $ev->setUser($u); \Events::dispatch('on_page_type_publish', $ev); }
public function setPageDraftTargetParentPageID($cParentID) { if ($cParentID != $this->getPageDraftTargetParentPageID()) { Section::unregisterPage($this); } $db = Database::connection(); $cParentID = intval($cParentID); $db->executeQuery('update Pages set cDraftTargetParentPageID = ? where cID = ?', [$cParentID, $this->cID]); $this->cDraftTargetParentPageID = $cParentID; Section::registerPage($this); }