public function __construct() { parent::__construct(); $this->contentTransforms['page_standard'] = new PageStandardToStandardPageTransformer(); $this->contentTransforms['page_asset_listing'] = new PageAssetListingToListingPageTransformer(); $this->contentTransforms['folder'] = new FolderToPageTransformer(); }
public function import($contentItem, $target, $includeParent = false, $includeChildren = true, $duplicateStrategy = 'Overwrite', $params = array()) { parent::import($contentItem, $target, $includeParent, $includeChildren, $duplicateStrategy, $params); if ($this->has_extension('PostImportStepExtension') && !is_a($target, 'TaxonomyTerm')) { $extension = $this->getExtensionInstance('PostImportStepExtension'); if ($extension) { // Build up a list of link aliases to page IDs. $linkRewrites = array(); foreach ($extension->importResults as $result) { $page = $result->page; $originalData = $result->original->getRemoteProperties(); foreach (array('Path', 'PathAlias') as $key) { if (array_key_exists($key, $originalData)) { $linkRewrites['/' . $originalData[$key]] = $page->ID; } } } // Go through all imported pages and rewrite any necessary links. foreach ($extension->importResults as $result) { $page = $result->page; // Find the href attribute of every a element. $pattern = '/<a [^>]*href="([^"]*)/'; if (!preg_match_all($pattern, $page->Content, $matches)) { continue; } // Loop through all the matches to ([^"]*), which captures the link href. $numReplacements = 0; foreach ($matches[1] as $match) { if (array_key_exists($match, $linkRewrites)) { $replacement = '[sitetree_link,id=' . $linkRewrites[$match] . ']'; $page->Content = str_replace("\"{$match}\"", "\"{$replacement}\"", $page->Content); $numReplacements++; } } if ($numReplacements > 0) { $page->write(); } } } } }
public function __construct() { parent::__construct(); $this->contentTransforms['Tweet'] = new TwitterContentItemImporter(); }