/** * 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(); } }
public function swapContent($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 = PageType::getList(); foreach ($pageTypes as $ct) { $ct->delete(); } $path = $this->getPackagePath(); // Import Files if (is_dir($path . '/files')) { $ch = new ContentImporter(); $computeThumbnails = true; if ($this->contentProvidesFileThumbnails()) { $computeThumbnails = false; } $ch->importFiles($path . '/files', $computeThumbnails); } // Install the starting point. if (is_file($path . '/content.xml')) { $ci = new ContentImporter(); $ci->importContentFile($path . '/content.xml'); } // Restore Cache \Core::make('cache/request')->enable(); } }
public function getImportData($blockNode, $page) { $args = array(); $formLayoutSetControlID = ContentImporter::getPageTypeComposerFormLayoutSetControlFromTemporaryID((string) $blockNode->control['output-control-id']); $formLayoutSetControl = PageTypeComposerFormLayoutSetControl::getByID($formLayoutSetControlID); $pt = PageTemplate::getByID($page->getPageTemplateID()); $outputControl = PageTypeComposerOutputControl::getByPageTypeComposerFormLayoutSetControl($pt, $formLayoutSetControl); $args['ptComposerOutputControlID'] = $outputControl->getPageTypeComposerOutputControlID(); return $args; }
public function importValue(\SimpleXMLElement $akv) { if (isset($akv->value->fID)) { $fIDVal = (string) $akv->value->fID; $fID = ContentImporter::getValue($fIDVal); if ($fID) { return File::getByID($fID); } } }
public function importPageAreas(Page $page, \SimpleXMLElement $px) { foreach ($px->area as $ax) { if (isset($ax->blocks)) { foreach ($ax->blocks->block as $bx) { if ($bx['type'] != '') { // we check this because you might just get a block node with only an mc-block-id, if it's an alias $bt = BlockType::getByHandle((string) $bx['type']); if (!is_object($bt)) { throw new \Exception(t('Invalid block type handle: %s', strval($bx['type']))); } $btc = $bt->getController(); $btc->import($page, (string) $ax['name'], $bx); } else { if ($bx['mc-block-id'] != '') { // we find that block in the master collection block pool and alias it out $bID = array_search((string) $bx['mc-block-id'], ContentImporter::getMasterCollectionTemporaryBlockIDs()); if ($bID) { $mc = Page::getByID($page->getMasterCollectionID(), 'RECENT'); $block = Block::getByID($bID, $mc, (string) $ax['name']); $block->alias($page); if ($block->getBlockTypeHandle() == BLOCK_HANDLE_LAYOUT_PROXY) { // we have to go get the blocks on that page in this layout. $btc = $block->getController(); $arLayout = $btc->getAreaLayoutObject(); $columns = $arLayout->getAreaLayoutColumns(); foreach ($columns as $column) { $area = $column->getAreaObject(); $blocks = $area->getAreaBlocksArray($mc); foreach ($blocks as $_b) { $_b->alias($page); } } } } } } } } if (isset($ax->style)) { $area = \Area::get($page, (string) $ax['name']); $set = StyleSet::import($ax->style); $page->setCustomStyleSet($area, $set); } } }
public function install_permissions() { $ci = new ContentImporter(); $ci->importContentFile(DIR_BASE_CORE . '/config/install/base/permissions.xml'); }
public static function import(\SimpleXMLElement $node) { $o = new self(); $o->setBackgroundColor((string) $node->backgroundColor); $filename = (string) $node['backgroundImage']; if ($filename) { $fID = ContentImporter::getValue($filename); if ($fID) { $o->setBackgroundImageFileID($fID); } } $o->setBackgroundRepeat((string) $node->backgroundRepeat); $o->setBorderWidth((string) $node->borderWidth); $o->setBorderColor((string) $node->borderColor); $o->setBorderStyle((string) $node->borderStyle); $o->setBorderRadius((string) $node->borderRadius); $o->setBaseFontSize((string) $node->baseFontSize); $o->setAlignment((string) $node->alignment); $o->setTextColor((string) $node->textColor); $o->setLinkColor((string) $node->linkColor); $o->setPaddingTop((string) $node->paddingTop); $o->setPaddingBottom((string) $node->paddingBottom); $o->setPaddingLeft((string) $node->paddingLeft); $o->setPaddingRight((string) $node->paddingRight); $o->setMarginTop((string) $node->marginTop); $o->setMarginBottom((string) $node->marginBottom); $o->setMarginLeft((string) $node->marginLeft); $o->setMarginRight((string) $node->marginRight); $o->setRotate((string) $node->rotate); $o->setBoxShadowHorizontal((string) $node->boxShadowHorizontal); $o->setBoxShadowVertical((string) $node->boxShadowVertical); $o->setBoxShadowSpread((string) $node->boxShadowSpread); $o->setBoxShadowBlur((string) $node->boxShadowBlur); $o->setBoxShadowColor((string) $node->boxShadowColor); $o->setCustomClass((string) $node->customClass); $o->save(); return $o; }
protected function addPermissions() { $this->output(t('Adding permissions...')); CacheLocal::delete('permission_keys', false); $ci = new ContentImporter(); $ci->importContentFile(DIR_BASE_CORE . '/config/install/base/permissions.xml'); CacheLocal::delete('permission_keys', false); }
public static function importContent($node) { $db = Loader::db(); $ptHandle = (string) $node['handle']; $ptID = $db->GetOne('select ptID from PageTypes where ptHandle = ?', array($ptHandle)); if ($ptID) { $pt = static::getByID($ptID); if (isset($node->composer->output->pagetemplate)) { $ci = new ContentImporter(); foreach ($node->composer->output->pagetemplate as $pagetemplate) { $ptt = PageTemplate::getByHandle((string) $pagetemplate['handle']); if (is_object($ptt)) { // let's get the defaults page for this $xc = $pt->getPageTypePageTemplateDefaultPageObject($ptt); // now that we have the defaults page, let's import this content into it. if (isset($pagetemplate->page)) { $ci->importPageAreas($xc, $pagetemplate->page); } } } } } }
protected function installXmlContent() { $pkg = Package::getByHandle($this->pkgHandle); $ci = new ContentImporter(); $ci->importContentFile($pkg->getPackagePath() . '/install.xml'); }
public function install() { $pkg = parent::install(); $ci = new ContentImporter(); $ci->importContentFile($pkg->getPackagePath() . '/config/dashboard.xml'); }
public function installContentFile($file) { $ci = new ContentImporter(); $ci->importContentFile($this->getPackagePath() . DIRECTORY_SEPARATOR . $file); }
public function import($page, $arHandle, \SimpleXMLElement $blockNode) { $db = Database::connection(); // handle the adodb stuff $args = $this->getImportData($blockNode, $page); $blockData = array(); $bt = \Concrete\Core\Block\BlockType\BlockType::getByHandle($this->btHandle); $b = $page->addBlock($bt, $arHandle, $args); $bName = (string) $blockNode['name']; $bFilename = (string) $blockNode['custom-template']; if ($bName) { $blockData['bName'] = $bName; } if ($bFilename) { $blockData['bFilename'] = $bFilename; } if (count($blockData)) { $b->updateBlockInformation($blockData); } if ($page->isMasterCollection() && $blockNode['mc-block-id'] != '') { ContentImporter::addMasterCollectionBlockID($b, (string) $blockNode['mc-block-id']); } // now we insert stuff that isn't part of the btTable // we have to do this this way because we need a bID $this->importAdditionalData($b, $blockNode); // now we handle the styles if (isset($blockNode->style)) { $set = StyleSet::import($blockNode->style); $b->setCustomStyleSet($set); } // now we handle block caching $cache = (int) $blockNode['cache-output']; if ($cache) { $b->setCustomCacheSettings(true, $blockNode['cache-output-on-post'], $blockNode['cache-output-for-registered-users'], $blockNode['cache-output-lifetime']); } }
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(); } }
public static function importContent($node) { $db = Loader::db(); $ptHandle = (string) $node['handle']; $ptID = $db->GetOne('select ptID from PageTypes where ptHandle = ?', array($ptHandle)); if ($ptID) { $pt = static::getByID($ptID); $defaultTemplate = $pt->getPageTypeDefaultPageTemplateObject(); if (isset($node->composer->output->pagetemplate)) { $ci = new ContentImporter(); foreach ($node->composer->output->pagetemplate as $pagetemplate) { $handle = (string) $pagetemplate['handle']; $ptt = PageTemplate::getByHandle($handle); if (is_object($ptt)) { // let's get the defaults page for this $xc = $pt->getPageTypePageTemplateDefaultPageObject($ptt); // if the $handle matches the default page template for this page type, then we ALSO check in here // and see if there are any attributes if (is_object($defaultTemplate) && $defaultTemplate->getPageTemplateHandle() == $handle) { if (isset($pagetemplate->page->attributes)) { foreach ($pagetemplate->page->attributes->children() as $attr) { $ak = CollectionKey::getByHandle((string) $attr['handle']); if (is_object($ak)) { $xc->setAttribute((string) $attr['handle'], $ak->getController()->importValue($attr)); } } } } // now that we have the defaults page, let's import this content into it. if (isset($pagetemplate->page)) { $ci->importPageAreas($xc, $pagetemplate->page); } } } } } }
protected function importAdditionalData($b, $blockNode) { if (isset($blockNode->data)) { foreach ($blockNode->data as $data) { if (strtoupper($data['table']) != strtoupper($this->getBlockTypeDatabaseTable())) { $table = (string) $data['table']; if (isset($data->record)) { foreach ($data->record as $record) { $aar = new \Concrete\Core\Legacy\BlockRecord($table); $aar->bID = $b->getBlockID(); foreach ($record->children() as $node) { $nodeName = $node->getName(); $aar->{$nodeName} = ContentImporter::getValue((string) $node); } $aar->Save(); } } } } } }
public static function import($node) { $types = array(); if ((string) $node->pagetemplates['type'] == 'custom' || (string) $node->pagetemplates['type'] == 'except') { if ((string) $node->pagetemplates['type'] == 'custom') { $ptAllowedPageTemplates = 'C'; } else { $ptAllowedPageTemplates = 'X'; } foreach ($node->pagetemplates->pagetemplate as $pagetemplate) { $types[] = PageTemplate::getByHandle((string) $pagetemplate['handle']); } } else { $ptAllowedPageTemplates = 'A'; } $ptName = (string) $node['name']; $ptHandle = (string) $node['handle']; $db = Loader::db(); $defaultPageTemplate = PageTemplate::getByHandle((string) $node->pagetemplates['default']); $ptID = $db->GetOne('select ptID from PageTypes where ptHandle = ?', array($ptHandle)); $data = array('handle' => $ptHandle, 'name' => $ptName); $siteType = (string) $node['site-type']; if ($siteType) { $data['siteType'] = \Core::make('site/type')->getByHandle($siteType); } if ($defaultPageTemplate) { $data['defaultTemplate'] = $defaultPageTemplate; } if ($ptAllowedPageTemplates) { $data['allowedTemplates'] = $ptAllowedPageTemplates; } if ($node['internal']) { $data['internal'] = true; } $data['ptLaunchInComposer'] = 0; if ($node['launch-in-composer'] == '1') { $data['ptLaunchInComposer'] = 1; } $data['ptIsFrequentlyAdded'] = 0; if ($node['is-frequently-added'] == '1') { $data['ptIsFrequentlyAdded'] = 1; } $data['templates'] = $types; $pkg = false; if ($node['package']) { $pkg = Package::getByHandle((string) $node['package']); } if ($ptID) { $cm = static::getByID($ptID); $cm->update($data); } else { $cm = static::add($data, $pkg); } $node = $node->composer; if (isset($node->formlayout->set)) { foreach ($node->formlayout->set as $setnode) { $set = $cm->addPageTypeComposerFormLayoutSet((string) $setnode['name'], (string) $setnode['description']); if (isset($setnode->control)) { foreach ($setnode->control as $controlnode) { $controltype = PageTypeComposerControlType::getByHandle((string) $controlnode['type']); $control = $controltype->configureFromImportHandle((string) $controlnode['handle']); $setcontrol = $control->addToPageTypeComposerFormLayoutSet($set, true); $required = (string) $controlnode['required']; $customTemplate = (string) $controlnode['custom-template']; $label = (string) $controlnode['custom-label']; $description = (string) $controlnode['description']; $outputControlID = (string) $controlnode['output-control-id']; if ($required == '1') { $setcontrol->updateFormLayoutSetControlRequired(true); } else { $setcontrol->updateFormLayoutSetControlRequired(false); } if ($customTemplate) { $setcontrol->updateFormLayoutSetControlCustomTemplate($customTemplate); } if ($label) { $setcontrol->updateFormLayoutSetControlCustomLabel($label); } if ($description) { $setcontrol->updateFormLayoutSetControlDescription($description); } if ($outputControlID) { ContentImporter::addPageTypeComposerOutputControlID($setcontrol, $outputControlID); } } } } } }