Ejemplo n.º 1
0
 protected static function createPage($name, $parent = false, $type = false, $template = false)
 {
     if ($parent === false) {
         $parent = Page::getByID(HOME_CID);
     } else {
         if (is_string($parent)) {
             $parent = Page::getByPath($parent);
         }
     }
     if ($type === false) {
         $type = 1;
     }
     if (is_string($type)) {
         $pt = PageType::getByHandle($type);
     } else {
         $pt = PageType::getByID($type);
     }
     if ($template === false) {
         $template = 1;
     }
     if (is_string($template)) {
         $template = PageTemplate::getByHandle($template);
     } else {
         $template = PageTemplate::getByID($template);
     }
     $page = $parent->add($pt, array('cName' => $name, 'pTemplateID' => $template->getPageTemplateID()));
     return $page;
 }
Ejemplo n.º 2
0
 /**
  * @param FileList $list
  * @param $request
  */
 public function filterList(ItemList $list)
 {
     $template = \PageTemplate::getByID($this->data['pTemplateID']);
     if (is_object($template)) {
         $list->filterByPageTemplate($template);
     }
 }
Ejemplo n.º 3
0
 protected function addPage2()
 {
     $home = Page::getByID(HOME_CID);
     PageType::add(array('handle' => 'alternate', 'name' => 'Alternate'));
     $pt = PageType::getByID(2);
     $template = PageTemplate::getByID(1);
     $page = $home->add($pt, array('uID' => 1, 'cName' => 'Test page', 'pTemplateID' => $template->getPageTemplateID()));
     return $page;
 }
Ejemplo n.º 4
0
<?php

defined('C5_EXECUTE') or die("Access Denied.");
use Concrete\Core\Page\Type\Composer\OutputControl as PageTypeComposerOutputControl;
use Concrete\Core\Page\Type\Composer\FormLayoutSetControl as PageTypeComposerFormLayoutSetControl;
$c = Page::getCurrentPage();
// retrieve all block controls attached to this page template.
$pt = PageTemplate::getByID($c->getPageTemplateID());
$ptt = PageType::getByDefaultsPage($c);
$controls = PageTypeComposerOutputControl::getList($ptt, $pt);
$values = array();
foreach ($controls as $control) {
    $fls = PageTypeComposerFormLayoutSetControl::getByID($control->getPageTypeComposerFormLayoutSetControlID());
    $cc = $fls->getPageTypeComposerControlObject();
    $values[$control->getPageTypeComposerOutputControlID()] = $cc->getPageTypeComposerControlName();
}
$form = Loader::helper('form');
?>
<div class="form-group">
	<label for="ptComposerOutputControlID" class="control-label"><?php 
echo t('Control');
?>
</label>
	<?php 
echo $form->select('ptComposerOutputControlID', $values, $ptComposerOutputControlID);
?>
</div>
Ejemplo n.º 5
0
 public function testDelete()
 {
     $db = Database::get();
     $page1 = self::createPage('Awesome Page');
     $page2 = self::createPage('Awesome Page 2');
     $this->assertEquals(3, $page2->getCollectionID());
     $page2->delete();
     $np = Page::getByID(3);
     $this->assertEquals($np->getCollectionID(), null);
     $pt = PageType::getByID(1);
     $template = PageTemplate::getByID(1);
     $newpage = $page1->add($pt, array('uID' => 1, 'cName' => 'Test Sub-page', 'pTemplateID' => $template->getPageTemplateID()));
     $page1->delete();
     $this->assertEquals(1, $db->GetOne('select count(cID) from Pages'));
     $np1 = Page::getByID(2);
     $np2 = Page::getByID(4);
     $this->assertEquals($np1->getCollectionID(), null);
     $this->assertEquals($np2->getCollectionID(), null);
 }
Ejemplo n.º 6
0
 public function testPagePathUpdate()
 {
     $home = Page::getByID(HOME_CID);
     $pt = PageType::getByID(1);
     $template = PageTemplate::getByID(1);
     $page = $home->add($pt, array('uID' => 1, 'cName' => 'Here\'s a twist', 'pTemplateID' => $template->getPageTemplateID()));
     $nc = $page->getVersionToModify();
     $nc->addAdditionalPagePath('/something/cool', false);
     $nc->addAdditionalPagePath('/something/rad', true);
     $nc->update(array('cName' => 'My new name', 'cHandle' => false));
     $nv = $nc->getVersionObject();
     $nv->approve();
     $nc2 = Page::getByID(2);
     $this->assertEquals('/my-new-name', $nc2->getCollectionPath());
     $this->assertEquals('my-new-name', $nc2->getCollectionHandle());
     $this->assertEquals(2, $nc2->getVersionID());
     $path = $nc2->getCollectionPathObject();
     $this->assertInstanceOf('\\Concrete\\Core\\Page\\PagePath', $path);
     $this->assertEquals('/my-new-name', $path->getPagePath());
     $this->assertEquals(true, $path->isPagePathAutoGenerated());
     $this->assertEquals(true, $path->isPagePathCanonical());
     $additionalPaths = $nc2->getAdditionalPagePaths();
     $this->assertEquals(2, count($additionalPaths));
     $this->assertEquals('/something/rad', $additionalPaths[1]->getPagePath());
     $this->assertEquals(false, $additionalPaths[1]->isPagePathAutoGenerated());
     $this->assertEquals(false, $additionalPaths[1]->isPagePathCanonical());
 }
 public function view($pagetypehandle = '', $success = 0)
 {
     $homepage = Page::getByID(HOME_CID);
     $emptysite = $homepage->getFirstChild('cDisplayOrder asc', true) === false;
     $this->set('emptysite', $emptysite);
     $typeList = PageType::getList();
     $pageTypesSelect = array();
     foreach ($typeList as $_pagetype) {
         $pageTypesSelect[$_pagetype->getPageTypeHandle()] = $_pagetype;
     }
     $this->set('pageTypes', $pageTypesSelect);
     $onepagetype = count($pageTypesSelect) == 1;
     $this->set('onepagetype', $onepagetype);
     if ($pagetypehandle) {
         $pageType = \PageType::getByHandle($pagetypehandle);
         if ($pageType) {
             $pageTemplates = $pageType->getPageTypePageTemplateObjects();
             $pageTemplatesSelect = array();
             foreach ($pageTemplates as $pt) {
                 $pageTemplatesSelect[$pt->getPageTemplateID()] = $pt->getPageTemplateDisplayName();
             }
             $this->set('pageTemplates', $pageTemplatesSelect);
             $this->set('pageType', $pageType);
         } else {
             $this->redirect('/dashboard/sitemap/add_multiple_pages/');
         }
         if ($success > 0) {
             $this->set('success', $success . ' ' . ($success > 1 ? t('pages created') : t('page created')));
         }
     } else {
         if ($onepagetype) {
             $this->redirect('/dashboard/sitemap/add_multiple_pages/' . array_pop($pageTypesSelect)->getPageTypeHandle());
         }
     }
     if ($this->post()) {
         $error = false;
         if ($this->post('parent_page') <= 0) {
             $this->error->add(t('A parent page must be selected'));
             $error = true;
         }
         if ($this->post('page_template') <= 0) {
             $this->error->add(t('A page template must be selected'));
             $error = true;
         }
         $pagenames = trim($this->post('pagenames'));
         if (!$pagenames) {
             $this->error->add(t('At least one page name must be entered'));
             $error = true;
         }
         if (substr($pagenames, 0, 1) == '-') {
             $this->error->add(t('The first page must not start with a dash'));
             $error = true;
         }
         if (!$error && $pagetypehandle) {
             $numpages = 0;
             $pagenames = explode("\n", trim($this->post('pagenames')));
             $parentPage = \Page::getByID($this->post('parent_page'));
             $parentList = array($parentPage);
             $currentLevel = 0;
             $pageTemplate = \PageTemplate::getByID($this->post('page_template'));
             if (is_object($parentPage) && is_object($pageType) && is_object($pageTemplate)) {
                 foreach ($pagenames as $pagename) {
                     $pagename = trim($pagename);
                     preg_match('/^(-\\s*)*/', $pagename, $matches);
                     if (!empty($matches)) {
                         $depth = strlen(str_replace(' ', '', $matches[0]));
                         $pagename = ltrim($pagename, '- ');
                         $pagename = trim($pagename);
                         if ($depth > $currentLevel && isset($parentList[1])) {
                             $currentLevel++;
                         }
                         if ($depth < $currentLevel) {
                             $currentLevel = $depth;
                         }
                     } else {
                         $currentLevel = 0;
                     }
                     $entry = $parentList[$currentLevel]->add($pageType, array('cName' => $pagename), $pageTemplate);
                     $parentList[$currentLevel + 1] = $entry;
                     $pageType->savePageTypeComposerForm($entry);
                     $entry->updateCollectionName($pagename);
                     $numpages++;
                 }
             }
             $this->redirect('/dashboard/sitemap/add_multiple_pages/' . $pagetypehandle . '/' . $numpages);
         }
     }
 }
Ejemplo n.º 8
0
 public function search()
 {
     $dh = Loader::helper('concrete/dashboard/sitemap');
     if (!$dh->canRead()) {
         return false;
     }
     if ($_REQUEST['submitSearch']) {
         $this->searchRequest->resetSearchRequest();
     }
     $req = $this->searchRequest->getSearchRequest();
     $columns = PageSearchColumnSet::getCurrent();
     if (!$this->pageList->getActiveSortColumn()) {
         $col = $columns->getDefaultSortColumn();
         $this->pageList->sanitizedSortBy($col->getColumnKey(), $col->getColumnDefaultSortDirection());
     }
     $cvName = htmlentities($req['cvName'], ENT_QUOTES, APP_CHARSET);
     $this->pageList->setPageVersionToRetrieve(\Concrete\Core\Page\PageList::PAGE_VERSION_RECENT);
     if ($cvName != '') {
         $this->pageList->filterByName($cvName);
     }
     if ($req['numResults'] && Loader::helper('validation/numbers')->integer($req['numResults'])) {
         $this->pageList->setItemsPerPage($req['numResults']);
     }
     if (is_array($req['field'])) {
         foreach ($req['field'] as $i => $item) {
             $this->fields[] = $this->getField($item);
             // due to the way the form is setup, index will always be one more than the arrays
             if ($item != '') {
                 switch ($item) {
                     case 'keywords':
                         $keywords = htmlentities($req['keywords'], ENT_QUOTES, APP_CHARSET);
                         $this->pageList->filterByFulltextKeywords($keywords);
                         break;
                     case 'num_children':
                         $symbol = '=';
                         if ($req['cChildrenSelect'] == 'gt') {
                             $symbol = '>';
                         } elseif ($req['cChildrenSelect'] == 'lt') {
                             $symbol = '<';
                         }
                         $this->pageList->filterByNumberOfChildren($req['cChildren'], $symbol);
                         break;
                     case 'type':
                         $this->pageList->filterByPageTypeID($req['ptID']);
                         break;
                     case 'template':
                         $template = \PageTemplate::getByID($req['pTemplateID']);
                         if (is_object($template)) {
                             $this->pageList->filterByPageTemplate($template);
                         }
                         break;
                     case 'owner':
                         $ui = \UserInfo::getByUserName($req['owner']);
                         if (is_object($ui)) {
                             $this->pageList->filterByUserID($ui->getUserID());
                         } else {
                             $this->pageList->filterByUserID(-1);
                         }
                         break;
                     case 'theme':
                         $this->pageList->filter('pThemeID', $req['pThemeID']);
                         break;
                     case 'parent':
                         if (isset($req['_cParentAll'])) {
                             $req['cParentAll'] = $req['_cParentAll'];
                         }
                         if ($req['cParentIDSearchField'] > 0) {
                             if ($req['cParentAll'] == 1) {
                                 $pc = \Page::getByID($req['cParentIDSearchField']);
                                 $cPath = $pc->getCollectionPath();
                                 $this->pageList->filterByPath($cPath);
                             } else {
                                 $this->pageList->filterByParentID($req['cParentIDSearchField']);
                             }
                         }
                         break;
                     case 'version_status':
                         if (in_array($req['versionToRetrieve'], array(\Concrete\Core\Page\PageList::PAGE_VERSION_RECENT, \Concrete\Core\Page\PageList::PAGE_VERSION_ACTIVE))) {
                             $this->pageList->setPageVersionToRetrieve($req['versionToRetrieve']);
                         }
                         break;
                     case 'permissions_inheritance':
                         $this->pageList->filter('cInheritPermissionsFrom', $req['cInheritPermissionsFrom']);
                         break;
                     case "date_public":
                         $wdt = Loader::helper('form/date_time');
                         /* @var $wdt \Concrete\Core\Form\Service\Widget\DateTime */
                         $dateFrom = $wdt->translate('date_public_from', $req);
                         if ($dateFrom) {
                             $this->pageList->filterByPublicDate($dateFrom, '>=');
                         }
                         $dateTo = $wdt->translate('date_public_to', $req);
                         if ($dateTo != '') {
                             if (preg_match('/^(.+\\d+:\\d+):00$/', $dateTo, $m)) {
                                 $dateTo = $m[1] . ':59';
                             }
                             $this->pageList->filterByPublicDate($dateTo, '<=');
                         }
                         break;
                     case "last_modified":
                         $wdt = Loader::helper('form/date_time');
                         /* @var $wdt \Concrete\Core\Form\Service\Widget\DateTime */
                         $dateFrom = $wdt->translate('last_modified_from', $req);
                         if ($dateFrom) {
                             $this->pageList->filterByDateLastModified($dateFrom, '>=');
                         }
                         $dateTo = $wdt->translate('last_modified_to', $req);
                         if ($dateTo) {
                             if (preg_match('/^(.+\\d+:\\d+):00$/', $dateTo, $m)) {
                                 $dateTo = $m[1] . ':59';
                             }
                             $this->pageList->filterByDateLastModified($dateTo, '<=');
                         }
                         break;
                     case "date_added":
                         $wdt = Loader::helper('form/date_time');
                         /* @var $wdt \Concrete\Core\Form\Service\Widget\DateTime */
                         $dateFrom = $wdt->translate('date_added_from', $req);
                         if ($dateFrom) {
                             $this->pageList->filterByDateAdded($dateFrom, '>=');
                         }
                         $dateTo = $wdt->translate('date_added_to', $req);
                         if ($dateTo) {
                             if (preg_match('/^(.+\\d+:\\d+):00$/', $dateTo, $m)) {
                                 $dateTo = $m[1] . ':59';
                             }
                             $this->pageList->filterByDateAdded($dateTo, '<=');
                         }
                         break;
                     default:
                         $akID = $item;
                         $fak = CollectionAttributeKey::getByID($akID);
                         if (!is_object($fak) || !$fak instanceof CollectionAttributeKey) {
                             break;
                         }
                         $type = $fak->getAttributeType();
                         $cnt = $type->getController();
                         $cnt->setRequestArray($req);
                         $cnt->setAttributeKey($fak);
                         $cnt->searchForm($this->pageList);
                         break;
                 }
             }
         }
     }
     $ilr = new PageSearchResult($columns, $this->pageList, URL::to('/ccm/system/search/pages/submit'), $this->fields);
     $this->result = $ilr;
 }