/** * Removes any existing pages, files, stacks, block and page types and installs content from the package. * * @param $options */ public function swapContent(Package $package, $options) { if ($this->validateClearSiteContents($options)) { \Core::make('cache/request')->disable(); $pl = new PageList(); $pages = $pl->getResults(); foreach ($pages as $c) { $c->delete(); } $fl = new FileList(); $files = $fl->getResults(); foreach ($files as $f) { $f->delete(); } // clear stacks $sl = new StackList(); foreach ($sl->get() as $c) { $c->delete(); } $home = \Page::getByID(HOME_CID); $blocks = $home->getBlocks(); foreach ($blocks as $b) { $b->deleteBlock(); } $pageTypes = Type::getList(); foreach ($pageTypes as $ct) { $ct->delete(); } // Set the page type of the home page to 0, because // if it has a type the type will be gone since we just // deleted it $home = Page::getByID(HOME_CID); $home->setPageType(null); // now we add in any files that this package has if (is_dir($package->getPackagePath() . '/content_files')) { $ch = new ContentImporter(); $computeThumbnails = true; if ($package->contentProvidesFileThumbnails()) { $computeThumbnails = false; } $ch->importFiles($package->getPackagePath() . '/content_files', $computeThumbnails); } // now we parse the content.xml if it exists. $ci = new ContentImporter(); $ci->importContentFile($package->getPackagePath() . '/content.xml'); \Core::make('cache/request')->enable(); } }
/** * Apply any customizations to the FileList query * @param \Concrete\Core\File\FileList $fileListObj */ protected function applyFileListFilters(\Concrete\Core\File\FileList $fileListObj) { if ((int) $this->fileSource === self::FILE_SOURCE_CUSTOM) { $fileListObj->getQueryObject()->join('f', $this->btTableSecondary, 'btsecondary', 'f.fID = btsecondary.fileID'); $fileListObj->getQueryObject()->andWhere('btsecondary.bID = :bRecordID'); $fileListObj->getQueryObject()->setParameter(':bRecordID', $this->bID); $fileListObj->getQueryObject()->orderBy('btsecondary.displayOrder', 'asc'); } if ((int) $this->fileSource === self::FILE_SOURCE_SET) { $fileSetObj = FileSet::getByID((int) $this->fileSetID); if (is_object($fileSetObj)) { $fileListObj->filterBySet($fileSetObj); $fileListObj->sortByFileSetDisplayOrder(); } } }
public function testPaginationPagesWithoutPermissions() { $pagination = $this->list->getPagination(); $pagination->setMaxPerPage(2)->setCurrentPage(1); $this->assertEquals(6, $pagination->getTotalPages()); $this->list->filterByType(\Concrete\Core\File\Type\Type::T_IMAGE); $pagination = $this->list->getPagination(); $this->assertEquals(5, $pagination->getTotalResults()); $pagination->setMaxPerPage(2)->setCurrentPage(2); $this->assertEquals(3, $pagination->getTotalPages()); $this->assertTrue($pagination->hasNextPage()); $this->assertTrue($pagination->hasPreviousPage()); $pagination->setCurrentPage(1); $this->assertTrue($pagination->hasNextPage()); $this->assertFalse($pagination->hasPreviousPage()); $pagination->setCurrentPage(3); $this->assertFalse($pagination->hasNextPage()); $this->assertTrue($pagination->hasPreviousPage()); $results = $pagination->getCurrentPageResults(); $this->assertInstanceOf('\\Concrete\\Core\\File\\File', $results[0]); $this->assertEquals(1, count($results[0])); }
public function getFileSet() { $fs = FileSet::getById($this->fsID); $files = array(); // if the file set exists (may have been deleted) if ($fs->fsID) { $this->fileSetName = $fs->getFileSetName(); $fl = new FileList(); $fl->filterBySet($fs); if ($this->fileOrder == 'date_asc') { $fl->sortBy('fDateAdded', 'asc'); } elseif ($this->fileOrder == 'date_desc') { $fl->sortBy('fDateAdded', 'desc'); } elseif ($this->fileOrder == 'alpha_asc') { $fl->sortBy('fvTitle', 'asc'); } elseif ($this->fileOrder == 'alpha_desc') { $fl->sortBy('fvTitle', 'desc'); } elseif ($this->fileOrder == 'set_order') { $fl->sortBy('fsDisplayOrder', 'asc'); } elseif ($this->fileOrder == 'set_order_rev') { $fl->sortBy('fsDisplayOrder', 'desc'); } if ($this->numberFiles > 0) { $fl->setItemsPerPage($this->numberFiles); } else { $fl->setItemsPerPage(10000); } $pagination = $fl->getPagination(); $files = $pagination->getCurrentPageResults(); if ($pagination->getTotalPages() > 1) { if ($this->paginate) { $pagination = $pagination->renderDefaultView(); $this->set('pagination', $pagination); } } } return $files; }
public function search() { $cp = FilePermissions::getGlobal(); if (!$cp->canSearchFiles()) { return false; } if ($_REQUEST['submitSearch']) { $this->searchRequest->resetSearchRequest(); } $req = $this->searchRequest->getSearchRequest(); $columns = FileSearchColumnSet::getCurrent(); if (!$this->fileList->getActiveSortColumn()) { $col = $columns->getDefaultSortColumn(); $this->fileList->sortBy($col->getColumnKey(), $col->getColumnDefaultSortDirection()); } // first thing, we check to see if a saved search is being used if (isset($req['fssID'])) { $fs = FileSet::getByID($req['fssID']); if ($fs->getFileSetType() == FileSet::TYPE_SAVED_SEARCH) { $req = $fs->getSavedSearchRequest(); $columns = $fs->getSavedSearchColumns(); $colsort = $columns->getDefaultSortColumn(); $this->fileList->addToSearchRequest('ccm_order_dir', $colsort->getColumnDefaultSortDirection()); $this->fileList->addToSearchRequest('ccm_order_by', $colsort->getColumnKey()); } } $keywords = htmlentities($req['fKeywords'], ENT_QUOTES, APP_CHARSET); if ($keywords != '') { $this->fileList->filterByKeywords($keywords); } if ($req['numResults']) { $this->fileList->setItemsPerPage(intval($req['numResults'])); } if (isset($req['fsIDNone']) && $req['fsIDNone'] == 1 || is_array($req['fsID']) && in_array(-1, $req['fsID'])) { $this->fileList->filterByNoSet(); } else { if (is_array($req['fsID'])) { foreach ($req['fsID'] as $fsID) { $fs = FileSet::getByID($fsID); $this->fileList->filterBySet($fs); } } else { if (isset($req['fsID']) && $req['fsID'] != '' && $req['fsID'] > 0) { $set = $req['fsID']; $fs = FileSet::getByID($set); $this->fileList->filterBySet($fs); } } } if (isset($req['fType']) && $req['fType'] != '') { $type = $req['fType']; $this->fileList->filterByType($type); } if (isset($req['fExtension']) && $req['fExtension'] != '') { $ext = $_GET['fExtension']; $fileList->filterByExtension($ext); } $selectedSets = array(); 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 "extension": $extension = $req['extension']; $this->fileList->filterByExtension($extension); break; case "type": $type = $req['type']; $this->fileList->filterByType($type); break; case "date_added": $dateFrom = $req['date_from']; $dateTo = $req['date_to']; if ($dateFrom != '') { $dateFrom = date('Y-m-d', strtotime($dateFrom)); $this->fileList->filterByDateAdded($dateFrom, '>='); $dateFrom .= ' 00:00:00'; } if ($dateTo != '') { $dateTo = date('Y-m-d', strtotime($dateTo)); $dateTo .= ' 23:59:59'; $this->fileList->filterByDateAdded($dateTo, '<='); } break; case 'added_to': $ocID = $req['ocIDSearchField']; if ($ocID > 0) { $this->fileList->filterByOriginalPageID($ocID); } break; case "size": $from = $req['size_from']; $to = $req['size_to']; $this->fileList->filterBySize($from, $to); break; default: $akID = $item; $fak = FileAttributeKey::get($akID); $type = $fak->getAttributeType(); $cnt = $type->getController(); $cnt->setRequestArray($req); $cnt->setAttributeKey($fak); $cnt->searchForm($this->fileList); break; } } } } if (isset($req['numResults'])) { $this->fileList->setItemsPerPage(intval($req['numResults'])); } $ilr = new FileSearchResult($columns, $this->fileList, URL::to('/ccm/system/search/files/submit'), $this->fields); $this->result = $ilr; }
public function search() { $cp = FilePermissions::getGlobal(); if (!$cp->canSearchFiles() && !$cp->canAddFile()) { return false; } if ($_REQUEST['submitSearch']) { $this->searchRequest->resetSearchRequest(); } $req = $this->searchRequest->getSearchRequest(); $columns = FileSearchColumnSet::getCurrent(); if (!$this->fileList->getActiveSortColumn()) { $col = $columns->getDefaultSortColumn(); $this->fileList->sanitizedSortBy($col->getColumnKey(), $col->getColumnDefaultSortDirection()); } // first thing, we check to see if a saved search is being used if (isset($req['fssID'])) { $fs = FileSet::getByID($req['fssID']); if ($fs->getFileSetType() == FileSet::TYPE_SAVED_SEARCH) { $req = $fs->getSavedSearchRequest(); $columns = $fs->getSavedSearchColumns(); $colsort = $columns->getDefaultSortColumn(); $this->fileList->addToSearchRequest('ccm_order_dir', $colsort->getColumnDefaultSortDirection()); $this->fileList->addToSearchRequest('ccm_order_by', $colsort->getColumnKey()); } } $keywords = htmlentities($req['fKeywords'], ENT_QUOTES, APP_CHARSET); if ($keywords != '') { $this->fileList->filterByKeywords($keywords); } if ($req['numResults']) { $this->fileList->setItemsPerPage(intval($req['numResults'])); } if (isset($req['fsIDNone']) && $req['fsIDNone'] == 1 || is_array($req['fsID']) && in_array(-1, $req['fsID'])) { $this->fileList->filterByNoSet(); } else { if (is_array($req['fsID'])) { foreach ($req['fsID'] as $fsID) { $fs = FileSet::getByID($fsID); $this->fileList->filterBySet($fs); } } elseif (isset($req['fsID']) && $req['fsID'] != '' && $req['fsID'] > 0) { $set = $req['fsID']; $fs = FileSet::getByID($set); $this->fileList->filterBySet($fs); } } if (isset($req['fType']) && $req['fType'] != '') { $type = $req['fType']; $this->fileList->filterByType($type); } if (isset($req['fExtension']) && $req['fExtension'] != '') { $ext = $_GET['fExtension']; $fileList->filterByExtension($ext); } $selectedSets = array(); 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 "extension": $extension = $req['extension']; $this->fileList->filterByExtension($extension); break; case "type": $type = $req['type']; $this->fileList->filterByType($type); 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->fileList->filterByDateAdded($dateFrom, '>='); } $dateTo = $wdt->translate('date_added_to', $req); if ($dateTo) { if (preg_match('/^(.+\\d+:\\d+):00$/', $dateTo, $m)) { $dateTo = $m[1] . ':59'; } $this->fileList->filterByDateAdded($dateTo, '<='); } break; case 'added_to': $ocID = $req['ocIDSearchField']; if ($ocID > 0) { $this->fileList->filterByOriginalPageID($ocID); } break; case "size": $from = $req['size_from']; $to = $req['size_to']; $this->fileList->filterBySize($from, $to); break; default: $akID = $item; $fak = FileAttributeKey::get($akID); $type = $fak->getAttributeType(); $cnt = $type->getController(); $cnt->setRequestArray($req); $cnt->setAttributeKey($fak); $cnt->searchForm($this->fileList); break; } } } } if (isset($req['numResults'])) { $this->fileList->setItemsPerPage(intval($req['numResults'])); } $this->fileList->setPermissionsChecker(function ($file) { $cp = new \Permissions($file); return $cp->canViewFileInFileManager(); }); $handleName = "filter" . Loader::helper('text')->camelcase($this->attributeHandle); if (method_exists("Application\\Src\\AdvancedAttributeFilters", $handleName)) { \Application\Src\AdvancedAttributeFilters::$handleName($this, $this->fileList); } $ilr = new FileSearchResult($columns, $this->fileList, URL::to($this->getSearchURL()), $this->fields); $this->result = $ilr; }
public function swapContent($options) { // Custom method to allow us to offer multiple starting points if ($this->validateClearSiteContents($options)) { \Core::make('cache/request')->disable(); $pl = new PageList(); $pages = $pl->getResults(); foreach ($pages as $c) { $c->delete(); } $fl = new FileList(); $files = $fl->getResults(); foreach ($files as $f) { $f->delete(); } // clear stacks $sl = new StackList(); foreach ($sl->get() as $c) { $c->delete(); } $home = Page::getByID(HOME_CID); $blocks = $home->getBlocks(); foreach ($blocks as $b) { $b->deleteBlock(); } $pageTypes = PageType::getList(); foreach ($pageTypes as $ct) { $ct->delete(); } // Overidden functionality to let us install selected starting point.... now we add in any files that this package has if (is_dir($this->getPackagePath() . '/starting_points/' . $this->startingPoint . '/content_files')) { $fh = new FileImporter(); $contents = Core::make('helper/file')->getDirectoryContents($this->getPackagePath() . '/starting_points/' . $this->startingPoint . '/content_files'); foreach ($contents as $filename) { $f = $fh->import($this->getPackagePath() . '/starting_points/' . $this->startingPoint . '/content_files/' . $filename, $filename); } } // Install selected starting point. $ci = new ContentImporter(); $ci->importContentFile($this->getPackagePath() . '/starting_points/' . $this->startingPoint . '/content.xml'); // Set the default preset $pt = PageTheme::getByHandle($this->pkgHandle); if (is_object($pt) && $pt->isThemeCustomizable()) { $presets = $pt->getThemeCustomizableStylePresets(); foreach ($presets as $preset) { if ($preset->getPresetHandle() == $this->startingPoint) { $styles = $pt->getThemeCustomizableStyleList(); $lessFile = $this->getPackagePath() . '/themes/' . $this->pkgHandle . '/css/presets/' . $this->startingPoint . '.less'; $vl = \Concrete\Core\StyleCustomizer\Style\ValueList::loadFromLessFile($lessFile); $vl->save(); $pt->setCustomStyleObject($vl, $preset, false); } } } \Core::make('cache/request')->enable(); } }
/** * @deprecated */ public function get() { return parent::get(); }