Exemplo n.º 1
0
 public function submit()
 {
     if ($this->validateAction()) {
         $nvc = $this->page->getVersionToModify();
         if ($this->asl->allowEditPaths()) {
             $data = array('cHandle' => $_POST['cHandle']);
             $nvc->update($data);
         }
         if ($this->asl->allowEditName()) {
             $data = array('cName' => $_POST['cName']);
             $nvc->update($data);
         }
         $as = AttributeSet::getByHandle('seo');
         $attributes = $as->getAttributeKeys();
         foreach ($attributes as $ak) {
             $ak->saveAttributeForm($nvc);
         }
         if ($this->request->request->get('sitemap') && $this->permissions->canApprovePageVersions() && \Config::get('concrete.misc.sitemap_approve_immediately')) {
             $pkr = new ApprovePageRequest();
             $u = new User();
             $pkr->setRequestedPage($this->page);
             $v = Version::get($this->page, "RECENT");
             $pkr->setRequestedVersionID($v->getVersionID());
             $pkr->setRequesterUserID($u->getUserID());
             $response = $pkr->trigger();
             $u->unloadCollectionEdit();
         }
         $r = new PageEditResponse($e);
         $r->setPage($this->page);
         $r->setTitle(t('Page Updated'));
         $r->setMessage(t('The SEO information has been saved.'));
         $r->outputJSON();
     }
 }
Exemplo n.º 2
0
 public function submit()
 {
     if ($this->validateAction()) {
         $comments = $this->request->request('comments');
         $comments = is_string($comments) ? trim($comments) : '';
         if ($comments === '' && $this->app->make('config')->get('concrete.misc.require_version_comments')) {
             return Response::create(t('Please specify the version comments'), 400);
         }
         $c = $this->page;
         $u = new User();
         $v = CollectionVersion::get($c, "RECENT");
         $v->setComment($_REQUEST['comments']);
         $pr = new PageEditResponse();
         if (($this->request->request->get('action') == 'publish' || $this->request->request->get('action') == 'schedule') && $this->permissions->canApprovePageVersions()) {
             $e = $this->checkForPublishing();
             $pr->setError($e);
             if (!$e->has()) {
                 $pkr = new ApprovePagePageWorkflowRequest();
                 $pkr->setRequestedPage($c);
                 $pkr->setRequestedVersionID($v->getVersionID());
                 $pkr->setRequesterUserID($u->getUserID());
                 $u->unloadCollectionEdit($c);
                 if ($this->request->request->get('action') == 'schedule') {
                     $dateTime = new DateTime();
                     $publishDateTime = $dateTime->translate('check-in-scheduler');
                     $pkr->scheduleVersion($publishDateTime);
                 }
                 if ($c->isPageDraft()) {
                     $pagetype = $c->getPageTypeObject();
                     $pagetype->publish($c, $pkr);
                 } else {
                     $pkr->trigger();
                 }
             }
         } else {
             if ($this->request->request->get('action') == 'discard') {
                 if ($c->isPageDraft() && $this->permissions->canDeletePage()) {
                     $u = new User();
                     $cID = $u->getPreviousFrontendPageID();
                     $this->page->delete();
                     $pr->setRedirectURL(DIR_REL . '/' . DISPATCHER_FILENAME . '?cID=' . $cID);
                     $pr->outputJSON();
                 } else {
                     if ($v->canDiscard()) {
                         $v->discard();
                     }
                 }
             } else {
                 $v->removeNewStatus();
             }
         }
         $nc = Page::getByID($c->getCollectionID(), $v->getVersionID());
         $u->unloadCollectionEdit();
         $pr->setRedirectURL(Loader::helper('navigation')->getLinkToCollection($nc, true));
         $pr->outputJSON();
     }
 }
Exemplo n.º 3
0
 public function submit()
 {
     if ($this->validateAction()) {
         $c = $this->page;
         $u = new User();
         $v = CollectionVersion::get($c, "RECENT");
         $v->setComment($_REQUEST['comments']);
         $pr = new PageEditResponse();
         if ($this->request->request->get('action') == 'publish' && $this->permissions->canApprovePageVersions()) {
             $e = $this->checkForPublishing();
             $pr->setError($e);
             if (!$e->has()) {
                 $pkr = new ApprovePagePageWorkflowRequest();
                 $pkr->setRequestedPage($c);
                 $pkr->setRequestedVersionID($v->getVersionID());
                 $pkr->setRequesterUserID($u->getUserID());
                 $u->unloadCollectionEdit($c);
                 $response = $pkr->trigger();
                 if ($c->isPageDraft()) {
                     $pagetype = $c->getPageTypeObject();
                     $pagetype->publish($c);
                 }
             }
         } else {
             if ($this->request->request->get('action') == 'discard') {
                 if ($c->isPageDraft() && $this->permissions->canDeletePage()) {
                     $this->page->delete();
                     $u = new User();
                     $cID = $u->getPreviousFrontendPageID();
                     $pr->setRedirectURL(DIR_REL . '/' . DISPATCHER_FILENAME . '?cID=' . $cID);
                 } else {
                     if ($v->canDiscard()) {
                         $v->discard();
                     }
                 }
             } else {
                 $v->removeNewStatus();
             }
         }
         $nc = Page::getByID($c->getCollectionID(), $v->getVersionID());
         $u->unloadCollectionEdit();
         $pr->setRedirectURL(Loader::helper('navigation')->getLinkToCollection($nc, true));
         $pr->outputJSON();
     }
 }
Exemplo n.º 4
0
 public function create_new()
 {
     $pr = new PageEditResponse();
     $ms = Section::getByID($this->request->request->get('section'));
     // we get the related parent id
     $cParentID = $this->page->getCollectionParentID();
     $cParent = \Page::getByID($cParentID);
     $cParentRelatedID = $ms->getTranslatedPageID($cParent);
     if ($cParentRelatedID > 0) {
         // we copy the page underneath it and store it
         $newParent = \Page::getByID($cParentRelatedID);
         $ct = \PageType::getByID($this->page->getPageTypeID());
         $cp = new \Permissions($newParent);
         if ($cp->canAddSubCollection($ct) && $this->page->canMoveCopyTo($newParent)) {
             $newPage = $this->page->duplicate($newParent);
             if (is_object($newPage)) {
                 // grab the approved version and unapprove it
                 $v = Version::get($newPage, 'ACTIVE');
                 if (is_object($v)) {
                     $v->deny();
                     $pkr = new ApprovePageRequest();
                     $pkr->setRequestedPage($newPage);
                     $u = new \User();
                     $pkr->setRequestedVersionID($v->getVersionID());
                     $pkr->setRequesterUserID($u->getUserID());
                     $response = $pkr->trigger();
                     if (!$response instanceof Response) {
                         // we are deferred
                         $pr->setMessage(t('<strong>Request Saved.</strong> You must complete the workflow before this change is active.'));
                     } else {
                         $ih = Core::make('multilingual/interface/flag');
                         $icon = $ih->getSectionFlagIcon($ms);
                         $pr->setAdditionalDataAttribute('name', $newPage->getCollectionName());
                         $pr->setAdditionalDataAttribute('link', $newPage->getCollectionLink());
                         $pr->setAdditionalDataAttribute('icon', $icon);
                         $pr->setMessage(t('Page created.'));
                     }
                 }
             }
         } else {
             throw new \Exception(t('You do not have permission to add this page to this section of the tree.'));
         }
     }
     $pr->outputJSON();
 }
Exemplo n.º 5
0
 public function submit()
 {
     if ($this->validateAction()) {
         $cp = $this->permissions;
         $c = $this->page;
         $nvc = $c->getVersionToModify();
         if ($this->permissions->canEditPageTheme()) {
             $pl = false;
             if ($_POST['pThemeID']) {
                 $pl = PageTheme::getByID($_POST['pThemeID']);
             }
             $data = array();
             if (is_object($pl)) {
                 $nvc->setTheme($pl);
             }
         }
         if (!$c->isGeneratedCollection()) {
             if ($_POST['pTemplateID'] && $cp->canEditPageTemplate()) {
                 // now we have to check to see if you're allowed to update this page to this page type.
                 // We do this by checking to see whether the PARENT page allows you to add this page type here.
                 // if this is the home page then we assume you are good
                 $template = PageTemplate::getByID($_POST['pTemplateID']);
                 $proceed = true;
                 $pagetype = $c->getPageTypeObject();
                 if (is_object($pagetype)) {
                     $templates = $pagetype->getPageTypePageTemplateObjects();
                     if (!in_array($template, $templates)) {
                         $proceed = false;
                     }
                 }
                 if ($proceed) {
                     $data['pTemplateID'] = $_POST['pTemplateID'];
                     $nvc->update($data);
                 }
             }
             if ($cp->canEditPageType()) {
                 $ptID = $c->getPageTypeID();
                 if ($ptID != $_POST['ptID']) {
                     // the page type has changed.
                     if ($_POST['ptID']) {
                         $type = Type::getByID($_POST['ptID']);
                         if (is_object($type)) {
                             $nvc->setPageType($type);
                         }
                     } else {
                         $nvc->setPageType(null);
                     }
                 }
             }
         }
         $r = new PageEditResponse();
         $r->setPage($c);
         if ($this->request->request->get('sitemap')) {
             $r->setMessage(t('Page updated successfully.'));
             if ($this->permissions->canApprovePageVersions() && Config::get('concrete.misc.sitemap_approve_immediately')) {
                 $pkr = new ApprovePageRequest();
                 $u = new User();
                 $pkr->setRequestedPage($this->page);
                 $v = Version::get($this->page, "RECENT");
                 $pkr->setRequestedVersionID($v->getVersionID());
                 $pkr->setRequesterUserID($u->getUserID());
                 $response = $pkr->trigger();
                 $u->unloadCollectionEdit();
             }
         } else {
             $r->setRedirectURL(\URL::to($c));
         }
         $r->outputJSON();
     }
 }
Exemplo n.º 6
0
 public function submit()
 {
     if ($this->validateAction()) {
         $c = $this->page;
         $cp = $this->permissions;
         $asl = $this->assignment;
         $nvc = $c->getVersionToModify();
         $data = array();
         if ($asl->allowEditName()) {
             $data['cName'] = $_POST['cName'];
         }
         if ($asl->allowEditDescription()) {
             $data['cDescription'] = $_POST['cDescription'];
         }
         if ($asl->allowEditDateTime()) {
             $dt = Loader::helper('form/date_time');
             $dh = Loader::helper('date');
             $data['cDatePublic'] = $dt->translate('cDatePublic');
         }
         if ($asl->allowEditUserID()) {
             $data['uID'] = $_POST['uID'];
         }
         $nvc->update($data);
         // First, we check out the attributes we need to clear.
         $setAttribs = $nvc->getSetCollectionAttributes();
         $processedAttributes = array();
         $selectedAKIDs = $_POST['selectedAKIDs'];
         if (!is_array($selectedAKIDs)) {
             $selectedAKIDs = array();
         }
         $selected = is_array($_POST['selectedAKIDs']) ? $_POST['selectedAKIDs'] : array();
         foreach ($setAttribs as $ak) {
             // do I have the ability to edit this attribute?
             if (in_array($ak->getAttributeKeyID(), $asl->getAttributesAllowedArray())) {
                 // Is this item in the selectedAKIDs array? If so then it is being saved
                 if (in_array($ak->getAttributeKeyID(), $selected)) {
                     $controller = $ak->getController();
                     $value = $controller->createAttributeValueFromRequest();
                     $nvc->setAttribute($ak, $value);
                 } else {
                     // it is being removed
                     $nvc->clearAttribute($ak);
                 }
                 $processedAttributes[] = $ak->getAttributeKeyID();
             }
         }
         $newAttributes = array_diff($selectedAKIDs, $processedAttributes);
         foreach ($newAttributes as $akID) {
             if ($akID > 0 && in_array($akID, $asl->getAttributesAllowedArray())) {
                 $ak = CollectionAttributeKey::getByID($akID);
                 $controller = $ak->getController();
                 $value = $controller->createAttributeValueFromRequest();
                 $nvc->setAttribute($ak, $value);
             }
         }
         if ($this->request->request->get('sitemap') && $this->permissions->canApprovePageVersions() && \Config::get('concrete.misc.sitemap_approve_immediately')) {
             $pkr = new ApprovePageRequest();
             $u = new User();
             $pkr->setRequestedPage($this->page);
             $v = Version::get($this->page, "RECENT");
             $pkr->setRequestedVersionID($v->getVersionID());
             $pkr->setRequesterUserID($u->getUserID());
             $response = $pkr->trigger();
             $u->unloadCollectionEdit();
         }
         $r = new PageEditResponse();
         $r->setPage($c);
         $r->setTitle(t('Page Updated'));
         $r->setMessage(t('Page Attributes have been saved.'));
         $r->outputJSON();
     }
 }
Exemplo n.º 7
0
 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);
 }
Exemplo n.º 8
0
 public function approve()
 {
     $c = $this->page;
     $cp = $this->permissions;
     if ($this->validateAction()) {
         $r = new PageEditVersionResponse();
         if ($cp->canApprovePageVersions()) {
             $ov = CollectionVersion::get($c, 'ACTIVE');
             if (is_object($ov)) {
                 $ovID = $ov->getVersionID();
             }
             $nvID = $_REQUEST['cvID'];
             $r = new PageEditVersionResponse();
             $r->setPage($c);
             $u = new User();
             $pkr = new ApprovePagePageWorkflowRequest();
             $pkr->setRequestedPage($c);
             $v = CollectionVersion::get($c, $_REQUEST['cvID']);
             $pkr->setRequestedVersionID($v->getVersionID());
             $pkr->setRequesterUserID($u->getUserID());
             $response = $pkr->trigger();
             if (!$response instanceof WorkflowProgressResponse) {
                 // we are deferred
                 $r->setMessage(t('<strong>Request Saved.</strong> You must complete the workflow before this change is active.'));
             } else {
                 if ($ovID) {
                     $r->addCollectionVersion(CollectionVersion::get($c, $ovID));
                 }
                 $r->addCollectionVersion(CollectionVersion::get($c, $nvID));
                 $r->setMessage(t('Version %s approved successfully', $v->getVersionID()));
             }
         } else {
             $e = Loader::helper('validation/error');
             $e->add(t('You do not have permission to approve page versions.'));
             $r = new PageEditResponse($e);
         }
         $r->outputJSON();
     }
 }
Exemplo n.º 9
0
 public function publish(Page $c)
 {
     $this->stripEmptyPageTypeComposerControls($c);
     $parent = Page::getByID($c->getPageDraftTargetParentPageID());
     $c->move($parent);
     $u = new User();
     $v = CollectionVersion::get($c, 'RECENT');
     $pkr = new ApprovePagePageWorkflowRequest();
     $pkr->setRequestedPage($c);
     $pkr->setRequestedVersionID($v->getVersionID());
     $pkr->setRequesterUserID($u->getUserID());
     $pkr->trigger();
     $c->activate();
     $u->unloadCollectionEdit($c);
     CacheLocal::flush();
     $ev = new Event($c);
     $ev->setPageType($this);
     $ev->setUser($u);
     \Events::dispatch('on_page_type_publish', $ev);
 }