public function testForErrors()
 {
     if (!$this->object->getVersionID()) {
         $c = Page::getByID($this->object->getCollectionID());
         $cp = new Permissions($c);
         if ($cp->canViewPageVersions()) {
             return COLLECTION_FORBIDDEN;
         } else {
             return COLLECTION_NOT_FOUND;
         }
     } elseif (!$this->object->isMostRecent()) {
         return VERSION_NOT_RECENT;
     }
     return parent::testForErrors();
 }
Beispiel #2
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();
     }
 }
Beispiel #3
0
 public function get($itemsToGet = 0, $offset = 0)
 {
     $r = parent::get($itemsToGet, $offset);
     $items = array();
     foreach ($r as $row) {
         $cv = Version::get($this->c, $row['cvID']);
         $items[] = $cv;
     }
     return $items;
 }
Beispiel #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();
 }
Beispiel #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();
     }
 }
 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();
     }
 }
Beispiel #7
0
 public function approve_stack($stackID = false, $token = false)
 {
     if (Loader::helper('validation/token')->validate('approve_stack', $token)) {
         $s = Stack::getByID($stackID);
         if (is_object($s)) {
             $sps = new Permissions($s);
             if ($sps->canApprovePageVersions()) {
                 $u = new User();
                 $v = Version::get($s, 'RECENT');
                 $pkr = new ApproveStackRequest();
                 $pkr->setRequestedPage($s);
                 $pkr->setRequestedVersionID($v->getVersionID());
                 $pkr->setRequesterUserID($u->getUserID());
                 $response = $pkr->trigger();
                 if ($response instanceof \Concrete\Core\Workflow\Progress\Response) {
                     // we only get this response if we have skipped workflows and jumped straight in to an approve() step.
                     $this->redirect('/dashboard/blocks/stacks', 'view_details', $stackID, 'stack_approved');
                 } else {
                     $this->redirect('/dashboard/blocks/stacks', 'view_details', $stackID, 'approve_saved');
                 }
             } else {
                 $this->error->add(t('You do not have access to approve this stack.'));
             }
         } else {
             $this->error->add(t('Invalid stack'));
         }
     } else {
         $this->error->add(Loader::helper('validation/token')->getErrorMessage());
     }
 }
 /**
  * @inheritdoc
  */
 public function collection(Collection $collection, $code = Response::HTTP_OK, $headers = array())
 {
     if (!$this->app) {
         throw new \RuntimeException('Cannot resolve collections without a reference to the application');
     }
     $request = $this->request;
     if ($collection->isError() && $collection->getError() == COLLECTION_NOT_FOUND) {
         if ($response = $this->collectionNotFound($collection, $request, $headers)) {
             return $response;
         }
     }
     if ($collection->getCollectionPath() != '/page_not_found') {
         if (!isset($collection->cPathFetchIsCanonical) || !$collection->cPathFetchIsCanonical) {
             // Handle redirect URL (additional page paths)
             /** @var Url $url */
             $url = $this->app->make('url/manager')->resolve([$collection]);
             $query = $url->getQuery();
             $query->modify($request->getQueryString());
             $url = $url->setQuery($query);
             return $this->redirect($url, Response::HTTP_MOVED_PERMANENTLY, $headers);
         }
     }
     // maintenance mode
     if ($collection->getCollectionPath() != '/login') {
         $smm = $this->config->get('concrete.maintenance_mode');
         if ($smm == 1 && !Key::getByHandle('view_in_maintenance_mode')->validate() && ($_SERVER['REQUEST_METHOD'] != 'POST' || Loader::helper('validation/token')->validate() == false)) {
             $v = new View('/frontend/maintenance_mode');
             $router = $this->app->make(RouterInterface::class);
             $tmpTheme = $router->getThemeByRoute('/frontend/maintenance_mode');
             $v->setViewTheme($tmpTheme[0]);
             $v->addScopeItems(['c' => $collection]);
             $request->setCurrentPage($collection);
             if (isset($tmpTheme[1])) {
                 $v->setViewTemplate($tmpTheme[1]);
             }
             return $this->view($v, $code, $headers);
         }
     }
     if ($collection->getCollectionPointerExternalLink() != '') {
         return $this->redirect($collection->getCollectionPointerExternalLink());
     }
     $cp = new Checker($collection);
     if ($cp->isError() && $cp->getError() == COLLECTION_FORBIDDEN) {
         return $this->forbidden($request->getUri(), Response::HTTP_FORBIDDEN, $headers);
     }
     if (!$collection->isActive() && !$cp->canViewPageVersions()) {
         return $this->notFound('', Response::HTTP_NOT_FOUND, $headers);
     }
     $scheduledVersion = Version::get($collection, "SCHEDULED");
     if ($publishDate = $scheduledVersion->cvPublishDate) {
         $datetime = $this->app->make('helper/date');
         $now = $datetime->date('Y-m-d G:i:s');
         if (strtotime($now) >= strtotime($publishDate)) {
             $scheduledVersion->approve();
             $collection->loadVersionObject('ACTIVE');
         }
     }
     if ($cp->canEditPageContents() || $cp->canEditPageProperties() || $cp->canViewPageVersions()) {
         $collection->loadVersionObject('RECENT');
     }
     $vp = new Checker($collection->getVersionObject());
     // returns the $vp object, which we then check
     if (is_object($vp) && $vp->isError()) {
         switch ($vp->getError()) {
             case COLLECTION_NOT_FOUND:
                 return $this->notFound('', Response::HTTP_NOT_FOUND, $headers);
                 break;
             case COLLECTION_FORBIDDEN:
                 return $this->forbidden($request->getUri(), Response::HTTP_FORBIDDEN, $headers);
                 break;
         }
     }
     // Now that we've passed all permissions checks, and we have a page, we check to see if we
     // ought to redirect based on base url or trailing slash settings
     $cms = $this->app;
     $site = $this->app['site']->getSite();
     $response = $cms->handleCanonicalURLRedirection($request, $site);
     if (!$response) {
         $response = $cms->handleURLSlashes($request, $site);
     }
     if (isset($response)) {
         return $response;
     }
     $dl = $cms->make('multilingual/detector');
     if ($dl->isEnabled()) {
         $dl->setupSiteInterfaceLocalization($collection);
     }
     if (!$request->getPath() && $request->isMethod('GET') && !$request->query->has('cID')) {
         // This is a request to the home page –http://www.mysite.com/
         // First, we check to see if we need to redirect to a default multilingual section.
         if ($dl->isEnabled() && $site->getConfigRepository()->get('multilingual.redirect_home_to_default_locale')) {
             // Let's retrieve the default language
             $ms = $dl->getPreferredSection();
             if (is_object($ms)) {
                 return $this->redirect(\URL::to($ms));
             }
         }
         // Otherwise, let's check to see if our home page, which we have loaded already, has a path (like /en)
         // If it does, we'll redirect to the path.
         if ($collection->getCollectionPath() != '') {
             return $this->redirect(\URL::to($collection));
         }
     }
     $request->setCurrentPage($collection);
     $c = $collection;
     // process.php needs this
     require DIR_BASE_CORE . '/bootstrap/process.php';
     $u = new User();
     // On page view event.
     $pe = new Event($collection);
     $pe->setUser($u);
     $pe->setRequest($request);
     $this->app['director']->dispatch('on_page_view', $pe);
     // Core menu items
     $item = new RelationListItem();
     $menu = $this->app->make('helper/concrete/ui/menu');
     $menu->addMenuItem($item);
     $controller = $collection->getPageController();
     // we update the current page with the one bound to this controller.
     $collection->setController($controller);
     return $this->controller($controller);
 }
 public function create_new()
 {
     $pr = new PageEditResponse();
     $ms = Section::getByID($this->request->request->get('section'));
     // we get the related parent id
     if ($this->page->isPageDraft()) {
         $cParentID = $this->page->getPageDraftTargetParentPageID();
     } else {
         $cParentID = $this->page->getCollectionParentID();
     }
     $cParent = \Page::getByID($cParentID);
     $cParentRelatedID = $ms->getTranslatedPageID($cParent);
     if ($cParentRelatedID > 0) {
         // we copy the page underneath it and store it
         $ct = \PageType::getByID($this->page->getPageTypeID());
         if ($this->page->isPageDraft()) {
             $ptp = new \Permissions($ct);
             if (!$ptp->canAddPageType()) {
                 throw new \Exception(t('You do not have permission to add a page of this type.'));
             }
         }
         $newParent = \Page::getByID($cParentRelatedID);
         $cp = new \Permissions($newParent);
         if ($cp->canAddSubCollection($ct)) {
             if ($this->page->isPageDraft()) {
                 $targetParent = \Page::getByPath(\Config::get('concrete.paths.drafts'));
             } else {
                 $targetParent = $newParent;
             }
             $newPage = $this->page->duplicate($targetParent);
             if (is_object($newPage)) {
                 if ($this->page->isPageDraft()) {
                     $newPage->setPageDraftTargetParentPageID($newParent->getCollectionID());
                     Section::relatePage($this->page, $newPage, $ms->getLocale());
                     $pr->setMessage(t('New draft created.'));
                 } else {
                     // grab the approved version and unapprove it
                     $v = Version::get($newPage, 'ACTIVE');
                     if (is_object($v)) {
                         $v->deny();
                     }
                     $pr->setMessage(t('Unapproved page created. You must publish this page before it is live.'));
                 }
                 $ih = Core::make('multilingual/interface/flag');
                 $icon = (string) $ih->getSectionFlagIcon($ms);
                 $pr->setAdditionalDataAttribute('name', $newPage->getCollectionName());
                 $pr->setAdditionalDataAttribute('link', $newPage->getCollectionLink());
                 $pr->setAdditionalDataAttribute('icon', $icon);
             }
         } else {
             throw new \Exception(t('You do not have permission to add this page to this section of the tree.'));
         }
     }
     $pr->outputJSON();
 }
Beispiel #10
0
 public function setPropertiesFromArray($arr)
 {
     return parent::setPropertiesFromArray($arr);
 }