PageRenderTime 61ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/web/concrete/core/libraries/content/importer.php

https://github.com/myconcretelab/concrete5
PHP | 761 lines | 681 code | 61 blank | 19 comment | 132 complexity | 4e6004c2441a635f39900fc3ee064a9d MD5 | raw file
Possible License(s): MIT, BSD-3-Clause
  1. <?
  2. /**
  3. * @package Core
  4. * @author Andrew Embler <andrew@concrete5.org>
  5. * @copyright Copyright (c) 2003-2011 Concrete5. (http://www.concrete5.org)
  6. * @license http://www.concrete5.org/license/ MIT License
  7. *
  8. */
  9. /**
  10. * A way to import concrete5 content.
  11. * @package Core
  12. * @author Andrew Embler <andrew@concrete5.org>
  13. * @copyright Copyright (c) 2003-2011 Concrete5. (http://www.concrete5.org)
  14. * @license http://www.concrete5.org/license/ MIT License
  15. *
  16. */
  17. defined('C5_EXECUTE') or die("Access Denied.");
  18. class Concrete5_Library_Content_Importer {
  19. protected static $mcBlockIDs = array();
  20. protected static $cmpOutputControlIDs = array();
  21. public function importContentFile($file) {
  22. $sx = simplexml_load_file($file);
  23. $this->importSinglePageStructure($sx);
  24. $this->importStacksStructure($sx);
  25. $this->importBlockTypes($sx);
  26. $this->importBlockTypeSets($sx);
  27. $this->importConversationEditors($sx);
  28. $this->importConversationRatingTypes($sx);
  29. $this->importConversationFlagTypes($sx);
  30. $this->importComposerTargetTypes($sx);
  31. $this->importComposerControlTypes($sx);
  32. $this->importBannedWords($sx);
  33. $this->importFeatures($sx);
  34. $this->importFeatureCategories($sx);
  35. $this->importGatheringDataSources($sx);
  36. $this->importGatheringItemTemplateTypes($sx);
  37. $this->importGatheringItemTemplates($sx);
  38. $this->importAttributeCategories($sx);
  39. $this->importAttributeTypes($sx);
  40. $this->importWorkflowTypes($sx);
  41. $this->importWorkflowProgressCategories($sx);
  42. $this->importAttributes($sx);
  43. $this->importAttributeSets($sx);
  44. $this->importThemes($sx);
  45. $this->importPermissionCategories($sx);
  46. $this->importPermissionAccessEntityTypes($sx);
  47. $this->importTaskPermissions($sx);
  48. $this->importPermissions($sx);
  49. $this->importJobs($sx);
  50. $this->importJobSets($sx);
  51. // import bare page types first, then import structure, then page types blocks, attributes and composer settings, then page content, because we need the structure for certain attributes and stuff set in master collections (like composer)
  52. $this->importPageTypesBase($sx);
  53. $this->importPageStructure($sx);
  54. $this->importPageTypeDefaults($sx);
  55. $this->importSinglePageContent($sx);
  56. $this->importStacksContent($sx);
  57. $this->importPageContent($sx);
  58. $this->importPackages($sx);
  59. $this->importConfigValues($sx);
  60. $this->importSystemCaptchaLibraries($sx);
  61. $this->importSystemContentEditorSnippets($sx);
  62. $this->importComposers($sx);
  63. }
  64. protected static function getPackageObject($pkgHandle) {
  65. $pkg = false;
  66. if ($pkgHandle) {
  67. $pkg = Package::getByHandle($pkgHandle);
  68. }
  69. return $pkg;
  70. }
  71. protected function importStacksStructure(SimpleXMLElement $sx) {
  72. if (isset($sx->stacks)) {
  73. foreach($sx->stacks->stack as $p) {
  74. if (isset($p['type'])) {
  75. $type = Stack::mapImportTextToType($p['type']);
  76. Stack::addStack($p['name'], $type);
  77. } else {
  78. Stack::addStack($p['name']);
  79. }
  80. }
  81. }
  82. }
  83. protected function importStacksContent(SimpleXMLElement $sx) {
  84. if (isset($sx->stacks)) {
  85. foreach($sx->stacks->stack as $p) {
  86. $stack = Stack::getByName($p['name']);
  87. if (isset($p->area)) {
  88. $this->importPageAreas($stack, $p);
  89. }
  90. }
  91. }
  92. }
  93. protected function importSinglePageStructure(SimpleXMLElement $sx) {
  94. if (isset($sx->singlepages)) {
  95. foreach($sx->singlepages->page as $p) {
  96. $pkg = ContentImporter::getPackageObject($p['package']);
  97. $spl = SinglePage::add($p['path'], $pkg);
  98. if (is_object($spl)) {
  99. if (isset($p['root']) && $p['root'] == true) {
  100. $spl->moveToRoot();
  101. }
  102. if ($p['name']) {
  103. $spl->update(array('cName' => $p['name'], 'cDescription' => $p['description']));
  104. }
  105. }
  106. }
  107. }
  108. }
  109. protected function importSinglePageContent(SimpleXMLElement $sx) {
  110. if (isset($sx->singlepages)) {
  111. foreach($sx->singlepages->page as $px) {
  112. $page = Page::getByPath($px['path'], 'RECENT');
  113. if (isset($px->area)) {
  114. $this->importPageAreas($page, $px);
  115. }
  116. if (isset($px->attributes)) {
  117. foreach($px->attributes->children() as $attr) {
  118. $ak = CollectionAttributeKey::getByHandle($attr['handle']);
  119. if (is_object($ak)) {
  120. $page->setAttribute((string) $attr['handle'], $ak->getController()->importValue($attr));
  121. }
  122. }
  123. }
  124. }
  125. }
  126. }
  127. protected function setupPageNodeOrder($pageNodeA, $pageNodeB) {
  128. $pathA = (string) $pageNodeA['path'];
  129. $pathB = (string) $pageNodeB['path'];
  130. $numA = count(explode('/', $pathA));
  131. $numB = count(explode('/', $pathB));
  132. if ($numA == $numB) {
  133. if (intval($pageNodeA->originalPos) < intval($pageNodeB->originalPos)) {
  134. return -1;
  135. } else if (intval($pageNodeA->originalPos) > intval($pageNodeB->originalPos)) {
  136. return 1;
  137. } else {
  138. return 0;
  139. }
  140. } else {
  141. return ($numA < $numB) ? -1 : 1;
  142. }
  143. }
  144. protected function importPageContent(SimpleXMLElement $sx) {
  145. if (isset($sx->pages)) {
  146. foreach($sx->pages->page as $px) {
  147. if ($px['path'] != '') {
  148. $page = Page::getByPath($px['path'], 'RECENT');
  149. } else {
  150. $page = Page::getByID(HOME_CID, 'RECENT');
  151. }
  152. if (isset($px->area)) {
  153. $this->importPageAreas($page, $px);
  154. }
  155. if (isset($px->attributes)) {
  156. foreach($px->attributes->children() as $attr) {
  157. $ak = CollectionAttributeKey::getByHandle($attr['handle']);
  158. if (is_object($ak)) {
  159. $page->setAttribute((string) $attr['handle'], $ak->getController()->importValue($attr));
  160. }
  161. }
  162. }
  163. $page->reindex();
  164. }
  165. }
  166. }
  167. protected function importPageStructure(SimpleXMLElement $sx) {
  168. if (isset($sx->pages)) {
  169. $nodes = array();
  170. $i = 0;
  171. foreach($sx->pages->page as $p) {
  172. $p->originalPos = $i;
  173. $nodes[] = $p;
  174. $i++;
  175. }
  176. usort($nodes, array('ContentImporter', 'setupPageNodeOrder'));
  177. $home = Page::getByID(HOME_CID, 'RECENT');
  178. foreach($nodes as $px) {
  179. $pkg = ContentImporter::getPackageObject($px['package']);
  180. $data = array();
  181. $user = (string) $px['user'];
  182. if ($user != '') {
  183. $ui = UserInfo::getByUserName($user);
  184. if (is_object($ui)) {
  185. $data['uID'] = $ui->getUserID();
  186. } else {
  187. $data['uID'] = USER_SUPER_ID;
  188. }
  189. }
  190. $cDatePublic = (string) $px['public-date'];
  191. if ($cDatePublic) {
  192. $data['cDatePublic'] = $cDatePublic;
  193. }
  194. $data['pkgID'] = 0;
  195. if (is_object($pkg)) {
  196. $data['pkgID'] = $pkg->getPackageID();
  197. }
  198. $args = array();
  199. $ct = CollectionType::getByHandle($px['pagetype']);
  200. if ($px['path'] == '') {
  201. // home page
  202. $page = $home;
  203. $args['ctID'] = $ct->getCollectionTypeID();
  204. } else {
  205. $page = Page::getByPath($px['path']);
  206. if (!is_object($page) || ($page->isError())) {
  207. $lastSlash = strrpos((string) $px['path'], '/');
  208. $parentPath = substr((string) $px['path'], 0, $lastSlash);
  209. $data['cHandle'] = substr((string) $px['path'], $lastSlash + 1);
  210. if (!$parentPath) {
  211. $parent = $home;
  212. } else {
  213. $parent = Page::getByPath($parentPath);
  214. }
  215. $page = $parent->add($ct, $data);
  216. }
  217. }
  218. $args['cName'] = $px['name'];
  219. $args['cDescription'] = $px['description'];
  220. $args['ctID'] = $ct->getCollectionTypeID();
  221. $page->update($args);
  222. }
  223. }
  224. }
  225. protected function importPageAreas(Page $page, SimpleXMLElement $px) {
  226. foreach($px->area as $ax) {
  227. if (isset($ax->block)) {
  228. foreach($ax->block as $bx) {
  229. if ($bx['type'] != '') {
  230. // we check this because you might just get a block node with only an mc-block-id, if it's an alias
  231. $bt = BlockType::getByHandle($bx['type']);
  232. $btc = $bt->getController();
  233. $btc->import($page, (string) $ax['name'], $bx);
  234. } else if ($bx['mc-block-id'] != '') {
  235. // we find that block in the master collection block pool and alias it out
  236. $bID = array_search((string) $bx['mc-block-id'], self::$mcBlockIDs);
  237. if ($bID) {
  238. $mc = Page::getByID($page->getMasterCollectionID(), 'RECENT');
  239. $block = Block::getByID($bID, $mc, (string) $ax['name']);
  240. $block->alias($page);
  241. }
  242. }
  243. }
  244. }
  245. }
  246. }
  247. public static function addMasterCollectionBlockID($b, $id) {
  248. self::$mcBlockIDs[$b->getBlockID()] = $id;
  249. }
  250. public static function getMasterCollectionTemporaryBlockID($b) {
  251. if (isset(self::$mcBlockIDs[$b->getBlockID()])) {
  252. return self::$mcBlockIDs[$b->getBlockID()];
  253. }
  254. }
  255. public static function addComposerOutputControlID(ComposerFormLayoutSetControl $control, $id) {
  256. self::$cmpOutputControlIDs[$id] = $control->getComposerFormLayoutSetControlID();
  257. }
  258. public static function getComposerFormLayoutSetControlFromTemporaryID($id) {
  259. if (isset(self::$cmpOutputControlIDs[$id])) {
  260. return self::$cmpOutputControlIDs[$id];
  261. }
  262. }
  263. protected function importPageTypesBase(SimpleXMLElement $sx) {
  264. if (isset($sx->pagetypes)) {
  265. foreach($sx->pagetypes->pagetype as $ct) {
  266. $pkg = ContentImporter::getPackageObject($ct['package']);
  267. $ctt = CollectionType::getByHandle($ct['handle']);
  268. if (!is_object($ctt)) {
  269. $ctr = CollectionType::add(array(
  270. 'ctHandle' => $ct['handle'],
  271. 'ctName' => $ct['name'],
  272. 'ctIcon' => $ct['icon'],
  273. 'ctIsInternal' => (string) $ct['internal']
  274. ), $pkg);
  275. }
  276. }
  277. }
  278. }
  279. protected function importPageTypeDefaults(SimpleXMLElement $sx) {
  280. $db = Loader::db();
  281. if (isset($sx->pagetypes)) {
  282. foreach($sx->pagetypes->pagetype as $ct) {
  283. $ctr = CollectionType::getByHandle((string) $ct['handle']);
  284. $mc = Page::getByID($ctr->getMasterCollectionID(), 'RECENT');
  285. if (isset($ct->page)) {
  286. $this->importPageAreas($mc, $ct->page);
  287. }
  288. }
  289. }
  290. }
  291. protected function importBlockTypes(SimpleXMLElement $sx) {
  292. if (isset($sx->blocktypes)) {
  293. foreach($sx->blocktypes->blocktype as $bt) {
  294. $pkg = ContentImporter::getPackageObject($bt['package']);
  295. if (is_object($pkg)) {
  296. BlockType::installBlockTypeFromPackage($bt['handle'], $pkg);
  297. } else {
  298. BlockType::installBlockType($bt['handle']);
  299. }
  300. }
  301. }
  302. }
  303. protected function importWorkflowTypes(SimpleXMLElement $sx) {
  304. if (isset($sx->workflowtypes)) {
  305. foreach($sx->workflowtypes->workflowtype as $wt) {
  306. $pkg = ContentImporter::getPackageObject($wt['package']);
  307. $name = $wt['name'];
  308. if (!$name) {
  309. $name = Loader::helper('text')->unhandle($wt['handle']);
  310. }
  311. $type = WorkflowType::add($wt['handle'], $name, $pkg);
  312. }
  313. }
  314. }
  315. protected function importAttributeTypes(SimpleXMLElement $sx) {
  316. if (isset($sx->attributetypes)) {
  317. foreach($sx->attributetypes->attributetype as $at) {
  318. $pkg = ContentImporter::getPackageObject($at['package']);
  319. $name = $at['name'];
  320. if (!$name) {
  321. $name = Loader::helper('text')->unhandle($at['handle']);
  322. }
  323. $type = AttributeType::add($at['handle'], $name, $pkg);
  324. if (isset($at->categories)) {
  325. foreach($at->categories->children() as $cat) {
  326. $catobj = AttributeKeyCategory::getByHandle((string) $cat['handle']);
  327. $catobj->associateAttributeKeyType($type);
  328. }
  329. }
  330. }
  331. }
  332. }
  333. protected function importPermissionAccessEntityTypes(SimpleXMLElement $sx) {
  334. if (isset($sx->permissionaccessentitytypes)) {
  335. foreach($sx->permissionaccessentitytypes->permissionaccessentitytype as $pt) {
  336. $pkg = ContentImporter::getPackageObject($pt['package']);
  337. $name = $pt['name'];
  338. if (!$name) {
  339. $name = Loader::helper('text')->unhandle($pt['handle']);
  340. }
  341. $type = PermissionAccessEntityType::add($pt['handle'], $name, $pkg);
  342. if (isset($pt->categories)) {
  343. foreach($pt->categories->children() as $cat) {
  344. $catobj = PermissionKeyCategory::getByHandle((string) $cat['handle']);
  345. $catobj->associateAccessEntityType($type);
  346. }
  347. }
  348. }
  349. }
  350. }
  351. protected function importPackages(SimpleXMLElement $sx) {
  352. if (isset($sx->packages)) {
  353. foreach($sx->packages->package as $p) {
  354. $pkg = Loader::package((string) $p['handle']);
  355. $pkg->install();
  356. }
  357. }
  358. }
  359. protected function importThemes(SimpleXMLElement $sx) {
  360. if (isset($sx->themes)) {
  361. foreach($sx->themes->theme as $th) {
  362. $pkg = ContentImporter::getPackageObject($th['package']);
  363. $ptHandle = (string) $th['handle'];
  364. $pt = PageTheme::getByHandle($ptHandle);
  365. if (!is_object($pt)) {
  366. $pt = PageTheme::add($ptHandle, $pkg);
  367. }
  368. if ($th['activated'] == '1') {
  369. $pt->applyToSite();
  370. }
  371. }
  372. }
  373. }
  374. protected function importComposerTargetTypes(SimpleXMLElement $sx) {
  375. if (isset($sx->composertargettypes)) {
  376. foreach($sx->composertargettypes->type as $th) {
  377. $pkg = ContentImporter::getPackageObject($th['package']);
  378. $ce = ComposerTargetType::add((string) $th['handle'], (string) $th['name'], $pkg);
  379. }
  380. }
  381. }
  382. protected function importComposerControlTypes(SimpleXMLElement $sx) {
  383. if (isset($sx->composercontroltypes)) {
  384. foreach($sx->composercontroltypes->type as $th) {
  385. $pkg = ContentImporter::getPackageObject($th['package']);
  386. $ce = ComposerControlType::add((string) $th['handle'], (string) $th['name'], $pkg);
  387. }
  388. }
  389. }
  390. protected function importComposers(SimpleXMLElement $sx) {
  391. if (isset($sx->composers)) {
  392. foreach($sx->composers->composer as $cm) {
  393. Composer::import($cm);
  394. }
  395. }
  396. }
  397. protected function importConversationEditors(SimpleXMLElement $sx) {
  398. if (isset($sx->conversationeditors)) {
  399. foreach($sx->conversationeditors->editor as $th) {
  400. $pkg = ContentImporter::getPackageObject($th['package']);
  401. $ce = ConversationEditor::add((string) $th['handle'], (string) $th['name'], $pkg);
  402. if ($th['activated'] == '1') {
  403. $ce->activate();
  404. }
  405. }
  406. }
  407. }
  408. protected function importConversationRatingTypes(SimpleXMLElement $sx) {
  409. if (isset($sx->conversationratingtypes)) {
  410. foreach($sx->conversationratingtypes->conversationratingtype as $th) {
  411. $pkg = ContentImporter::getPackageObject($th['package']);
  412. $ce = ConversationRatingType::add((string) $th['handle'], (string) $th['name'], $th['points'], $pkg);
  413. }
  414. }
  415. }
  416. protected function importBannedWords(SimpleXMLElement $sx) {
  417. if (isset($sx->banned_words)) {
  418. foreach($sx->banned_words->banned_word as $p) {
  419. $bw = BannedWord::add(str_rot13($p));
  420. }
  421. }
  422. }
  423. protected function importConversationFlagTypes(SimpleXMLElement $sx) {
  424. if (isset($sx->flag_types)) {
  425. foreach($sx->flag_types->flag_type as $p) {
  426. $bw = ConversationFlagType::add($p);
  427. }
  428. }
  429. }
  430. protected function importSystemCaptchaLibraries(SimpleXMLElement $sx) {
  431. if (isset($sx->systemcaptcha)) {
  432. Loader::model('system/captcha/library');
  433. foreach($sx->systemcaptcha->library as $th) {
  434. $pkg = ContentImporter::getPackageObject($th['package']);
  435. $scl = SystemCaptchaLibrary::add($th['handle'], $th['name'], $pkg);
  436. if ($th['activated'] == '1') {
  437. $scl->activate();
  438. }
  439. }
  440. }
  441. }
  442. protected function importSystemContentEditorSnippets(SimpleXMLElement $sx) {
  443. if (isset($sx->systemcontenteditorsnippets)) {
  444. foreach($sx->systemcontenteditorsnippets->snippet as $th) {
  445. $pkg = ContentImporter::getPackageObject($th['package']);
  446. $scs = SystemContentEditorSnippet::add($th['handle'], $th['name'], $pkg);
  447. if ($th['activated'] == '1') {
  448. $scs->activate();
  449. }
  450. }
  451. }
  452. }
  453. protected function importJobs(SimpleXMLElement $sx) {
  454. Loader::model('job');
  455. if (isset($sx->jobs)) {
  456. foreach($sx->jobs->job as $jx) {
  457. $pkg = ContentImporter::getPackageObject($jx['package']);
  458. if (is_object($pkg)) {
  459. Job::installByPackage($jx['handle'], $pkg);
  460. } else {
  461. Job::installByHandle($jx['handle']);
  462. }
  463. }
  464. }
  465. }
  466. protected function importJobSets(SimpleXMLElement $sx) {
  467. if (isset($sx->jobsets)) {
  468. foreach($sx->jobsets->jobset as $js) {
  469. $pkg = ContentImporter::getPackageObject($js['package']);
  470. $jso = JobSet::getByName((string) $js['name']);
  471. if (!is_object($jso)) {
  472. $jso = JobSet::add((string) $js['name']);
  473. }
  474. foreach($js->children() as $jsk) {
  475. $j = Job::getByHandle((string) $jsk['handle']);
  476. if (is_object($j)) {
  477. $jso->addJob($j);
  478. }
  479. }
  480. }
  481. }
  482. }
  483. protected function importConfigValues(SimpleXMLElement $sx) {
  484. if (isset($sx->config)) {
  485. $db = Loader::db();
  486. $configstore = new ConfigStore($db);
  487. foreach($sx->config->children() as $key) {
  488. $pkg = ContentImporter::getPackageObject($key['package']);
  489. if (is_object($pkg)) {
  490. $configstore->set($key->getName(), (string) $key, $pkg->getPackageID());
  491. } else {
  492. $configstore->set($key->getName(), (string) $key);
  493. }
  494. }
  495. }
  496. }
  497. protected function importTaskPermissions(SimpleXMLElement $sx) {
  498. if (isset($sx->taskpermissions)) {
  499. foreach($sx->taskpermissions->taskpermission as $tp) {
  500. $pkg = ContentImporter::getPackageObject($tp['package']);
  501. $tpa = TaskPermission::addTask($tp['handle'], $tp['name'], $tp['description'], $pkg);
  502. if (isset($tp->access)) {
  503. foreach($tp->access->children() as $ch) {
  504. if ($ch->getName() == 'group') {
  505. $g = Group::getByName($ch['name']);
  506. if (!is_object($g)) {
  507. $g = Group::add($ch['name'], $ch['description']);
  508. }
  509. $tpa->addAccess($g);
  510. }
  511. }
  512. }
  513. }
  514. }
  515. }
  516. protected function importPermissionCategories(SimpleXMLElement $sx) {
  517. if (isset($sx->permissioncategories)) {
  518. foreach($sx->permissioncategories->category as $pkc) {
  519. $pkg = ContentImporter::getPackageObject($akc['package']);
  520. $pkx = PermissionKeyCategory::add((string) $pkc['handle'], $pkg);
  521. }
  522. }
  523. }
  524. protected function importWorkflowProgressCategories(SimpleXMLElement $sx) {
  525. if (isset($sx->workflowprogresscategories)) {
  526. foreach($sx->workflowprogresscategories->category as $wpc) {
  527. $pkg = ContentImporter::getPackageObject($wpc['package']);
  528. $wkx = WorkflowProgressCategory::add((string) $wpc['handle'], $pkg);
  529. }
  530. }
  531. }
  532. protected function importPermissions(SimpleXMLElement $sx) {
  533. if (isset($sx->permissionkeys)) {
  534. foreach($sx->permissionkeys->permissionkey as $pk) {
  535. $pkc = PermissionKeyCategory::getByHandle((string) $pk['category']);
  536. $pkg = ContentImporter::getPackageObject($pk['package']);
  537. $txt = Loader::helper('text');
  538. $className = $txt->camelcase($pkc->getPermissionKeyCategoryHandle());
  539. $c1 = $className . 'PermissionKey';
  540. $pkx = call_user_func(array($c1, 'import'), $pk);
  541. if (isset($pk->access)) {
  542. foreach($pk->access->children() as $ch) {
  543. if ($ch->getName() == 'group') {
  544. $g = Group::getByName($ch['name']);
  545. if (!is_object($g)) {
  546. $g = Group::add($g['name'], $g['description']);
  547. }
  548. $pae = GroupPermissionAccessEntity::getOrCreate($g);
  549. $pa = PermissionAccess::create($pkx);
  550. $pa->addListItem($pae);
  551. $pt = $pkx->getPermissionAssignmentObject();
  552. $pt->assignPermissionAccess($pa);
  553. }
  554. }
  555. }
  556. }
  557. }
  558. }
  559. protected function importFeatures(SimpleXMLElement $sx) {
  560. if (isset($sx->features)) {
  561. foreach($sx->features->feature as $fea) {
  562. $feHasCustomClass = false;
  563. if ($fea['has-custom-class']) {
  564. $feHasCustomClass = true;
  565. }
  566. $pkg = ContentImporter::getPackageObject($fea['package']);
  567. $fx = Feature::add((string) $fea['handle'], (string) $fea['score'], $feHasCustomClass, $pkg);
  568. }
  569. }
  570. }
  571. protected function importFeatureCategories(SimpleXMLElement $sx) {
  572. if (isset($sx->featurecategories)) {
  573. foreach($sx->featurecategories->featurecategory as $fea) {
  574. $pkg = ContentImporter::getPackageObject($fea['package']);
  575. $fx = FeatureCategory::add($fea['handle'], $pkg);
  576. }
  577. }
  578. }
  579. protected function importAttributeCategories(SimpleXMLElement $sx) {
  580. if (isset($sx->attributecategories)) {
  581. foreach($sx->attributecategories->category as $akc) {
  582. $pkg = ContentImporter::getPackageObject($akc['package']);
  583. $akx = AttributeKeyCategory::add($akc['handle'], $akc['allow-sets'], $pkg);
  584. }
  585. }
  586. }
  587. protected function importAttributes(SimpleXMLElement $sx) {
  588. if (isset($sx->attributekeys)) {
  589. foreach($sx->attributekeys->attributekey as $ak) {
  590. $akc = AttributeKeyCategory::getByHandle($ak['category']);
  591. $pkg = ContentImporter::getPackageObject($ak['package']);
  592. $type = AttributeType::getByHandle($ak['type']);
  593. $txt = Loader::helper('text');
  594. $className = $txt->camelcase($akc->getAttributeKeyCategoryHandle());
  595. $c1 = $className . 'AttributeKey';
  596. $ak = call_user_func(array($c1, 'import'), $ak);
  597. }
  598. }
  599. }
  600. protected function importAttributeSets(SimpleXMLElement $sx) {
  601. if (isset($sx->attributesets)) {
  602. foreach($sx->attributesets->attributeset as $as) {
  603. $akc = AttributeKeyCategory::getByHandle($as['category']);
  604. $pkg = ContentImporter::getPackageObject($as['package']);
  605. $set = $akc->addSet((string) $as['handle'], (string) $as['name'], $pkg, $as['locked']);
  606. foreach($as->children() as $ask) {
  607. $ak = $akc->getAttributeKeyByHandle((string) $ask['handle']);
  608. if (is_object($ak)) {
  609. $set->addKey($ak);
  610. }
  611. }
  612. }
  613. }
  614. }
  615. protected function importGatheringDataSources(SimpleXMLElement $sx) {
  616. if (isset($sx->gatheringsources)) {
  617. foreach($sx->gatheringsources->gatheringsource as $ags) {
  618. $pkg = ContentImporter::getPackageObject($ags['package']);
  619. $source = GatheringDataSource::add((string) $ags['handle'], (string) $ags['name'], $pkg);
  620. }
  621. }
  622. }
  623. protected function importGatheringItemTemplateTypes(SimpleXMLElement $sx) {
  624. if (isset($sx->gatheringitemtemplatetypes)) {
  625. foreach($sx->gatheringitemtemplatetypes->gatheringitemtemplatetype as $at) {
  626. $pkg = ContentImporter::getPackageObject($wt['package']);
  627. $type = GatheringItemTemplateType::add((string) $at['handle'], $pkg);
  628. }
  629. }
  630. }
  631. protected function importGatheringItemTemplates(SimpleXMLElement $sx) {
  632. if (isset($sx->gatheringitemtemplates)) {
  633. foreach($sx->gatheringitemtemplates->gatheringitemtemplate as $at) {
  634. $pkg = ContentImporter::getPackageObject($at['package']);
  635. $type = GatheringItemTemplateType::getByHandle((string) $at['type']);
  636. $gatHasCustomClass = false;
  637. $gatForceDefault = false;
  638. $gatFixedSlotWidth = 0;
  639. $gatFixedSlotHeight = 0;
  640. if ($at['has-custom-class']) {
  641. $gatHasCustomClass = true;
  642. }
  643. if ($at['force-default']) {
  644. $gatForceDefault = true;
  645. }
  646. if ($at['fixed-slot-width']) {
  647. $gatFixedSlotWidth = (string) $at['fixed-slot-width'];
  648. }
  649. if ($at['fixed-slot-height']) {
  650. $gatFixedSlotHeight = (string) $at['fixed-slot-height'];
  651. }
  652. $template = GatheringItemTemplate::add($type, (string) $at['handle'], (string) $at['name'], $gatFixedSlotWidth, $gatFixedSlotHeight, $gatHasCustomClass, $gatForceDefault, $pkg);
  653. foreach($at->children() as $fe) {
  654. $feo = Feature::getByHandle((string) $fe['handle']);
  655. if (is_object($feo)) {
  656. $template->addGatheringItemTemplateFeature($feo);
  657. }
  658. }
  659. }
  660. }
  661. }
  662. protected function importBlockTypeSets(SimpleXMLElement $sx) {
  663. if (isset($sx->blocktypesets)) {
  664. foreach($sx->blocktypesets->blocktypeset as $bts) {
  665. $pkg = ContentImporter::getPackageObject($bts['package']);
  666. $set = BlockTypeSet::add((string) $bts['handle'], (string) $bts['name'], $pkg);
  667. foreach($bts->children() as $btk) {
  668. $bt = BlockType::getByHandle((string) $btk['handle']);
  669. if (is_object($bt)) {
  670. $set->addBlockType($bt);
  671. }
  672. }
  673. }
  674. }
  675. }
  676. public static function getValue($value) {
  677. if (preg_match('/\{ccm:export:page:(.*)\}|\{ccm:export:file:(.*)\}|\{ccm:export:image:(.*)\}|\{ccm:export:pagetype:(.*)\}/i', $value, $matches)) {
  678. if ($matches[1]) {
  679. $c = Page::getByPath($matches[1]);
  680. return $c->getCollectionID();
  681. }
  682. if ($matches[2]) {
  683. $db = Loader::db();
  684. $fID = $db->GetOne('select fID from FileVersions where fvFilename = ?', array($matches[2]));
  685. return $fID;
  686. }
  687. if ($matches[3]) {
  688. $db = Loader::db();
  689. $fID = $db->GetOne('select fID from FileVersions where fvFilename = ?', array($matches[3]));
  690. return $fID;
  691. }
  692. if ($matches[4]) {
  693. $ct = CollectionType::getByHandle($matches[4]);
  694. return $ct->getCollectionTypeID();
  695. }
  696. } else {
  697. return $value;
  698. }
  699. }
  700. }