node_export_feeds.module 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. /**
  3. * @file
  4. * Node export feeds importer.
  5. */
  6. /**
  7. * Implementation of hook_ctools_plugin_api().
  8. */
  9. function node_export_feeds_ctools_plugin_api($module = '', $api = '') {
  10. if ($module == 'feeds' && in_array($api, array(
  11. 'feeds_importer_default',
  12. 'plugins'
  13. ))
  14. ) {
  15. return array('version' => 1);
  16. }
  17. }
  18. /**
  19. * Implementation of hook_feeds_plugins().
  20. */
  21. function node_export_feeds_feeds_plugins() {
  22. $info = array();
  23. $info['FeedsNodeExportParser'] = array(
  24. 'name' => 'Node export parser',
  25. 'description' => 'Parse a node export.',
  26. 'help' => 'Parses the output from the node export module.',
  27. 'handler' => array(
  28. 'parent' => 'FeedsParser',
  29. 'class' => 'FeedsNodeExportParser',
  30. 'file' => 'FeedsNodeExportParser.inc',
  31. 'path' => drupal_get_path('module', 'node_export_feeds'),
  32. ),
  33. );
  34. $info['FeedsNodeExportProcessor'] = array(
  35. 'name' => 'Node Export Processor',
  36. 'description' => 'Process a node export.',
  37. 'help' => 'Processes the output from the node export module.',
  38. 'handler' => array(
  39. 'parent' => 'FeedsNodeProcessor',
  40. 'class' => 'FeedsNodeExportProcessor',
  41. 'file' => 'FeedsNodeExportProcessor.inc',
  42. 'path' => drupal_get_path('module', 'node_export_feeds'),
  43. ),
  44. );
  45. return $info;
  46. }
  47. /**
  48. * Implementation of hook_feeds_importer_default().
  49. */
  50. function node_export_feeds_feeds_importer_default() {
  51. $export = array();
  52. // Commented out properties seem to be unsupported targets in feeds?
  53. $mappings_keys = array(
  54. //'vid',
  55. 'uid',
  56. 'title',
  57. //'log',
  58. 'status',
  59. 'comment',
  60. 'promote',
  61. 'sticky',
  62. //'vuuid',
  63. 'nid',
  64. //'type',
  65. 'language',
  66. 'created',
  67. //'changed',
  68. //'tnid',
  69. //'translate',
  70. //'uuid',
  71. //'revision_timestamp',
  72. //'revision_uid',
  73. 'body',
  74. //'rdf_mapping',
  75. //'cid',
  76. //'last_comment_timestamp',
  77. //'last_comment_name',
  78. //'last_comment_uid',
  79. //'comment_count',
  80. //'name',
  81. //'picture',
  82. //'data',
  83. //'path',
  84. //'menu',
  85. //'node_export_drupal_version',
  86. );
  87. $mappings = array();
  88. foreach ($mappings_keys as $mappings_key) {
  89. $mappings[] = array(
  90. 'source' => $mappings_key,
  91. 'target' => $mappings_key,
  92. 'unique' => FALSE,
  93. );
  94. }
  95. $mappings[] = array(
  96. 'source' => 'uuid',
  97. 'target' => 'guid',
  98. 'unique' => 1,
  99. );
  100. $feeds_importer = new stdClass;
  101. $feeds_importer->disabled = FALSE;
  102. $feeds_importer->api_version = 1;
  103. $feeds_importer->id = 'node_export';
  104. $feeds_importer->config = array(
  105. 'name' => 'Node export import',
  106. 'description' => 'Import nodes from node export.',
  107. 'fetcher' => array(
  108. 'plugin_key' => 'FeedsFileFetcher',
  109. 'config' => array(
  110. 'allowed_extensions' => 'export txt csv tsv xml opml',
  111. 'direct' => FALSE,
  112. ),
  113. ),
  114. 'parser' => array(
  115. 'plugin_key' => 'FeedsNodeExportParser',
  116. 'config' => array(),
  117. ),
  118. 'processor' => array(
  119. 'plugin_key' => 'FeedsNodeExportProcessor',
  120. 'config' => array(
  121. 'content_type' => 'article',
  122. 'update_existing' => 1,
  123. 'expire' => '-1',
  124. 'mappings' => $mappings,
  125. 'input_format' => 'plain_text',
  126. 'author' => 0,
  127. ),
  128. ),
  129. 'content_type' => '',
  130. 'update' => 0,
  131. 'import_period' => '-1',
  132. 'expire_period' => 3600,
  133. 'import_on_create' => 1,
  134. );
  135. $export['node_export'] = $feeds_importer;
  136. return $export;
  137. }
  138. /**
  139. * Implementation of hook_feeds_after_import().
  140. */
  141. function node_export_feeds_feeds_after_import($source) {
  142. if ($source->importer->processor instanceOf FeedsNodeExportProcessor && !empty($source->importer->processor->new_nodes)) {
  143. // This code is similar to some code in node_export_import()
  144. // which gets executed for all nodes when the $save param is TRUE.
  145. $save = TRUE;
  146. drupal_alter('node_export_after_import', $source->importer->processor->new_nodes, $source->importer->parser->format, $save);
  147. // @todo: Is this what we should do with output messages?
  148. drupal_set_message(("Some values may have been reset depending on Node export's configuration."));
  149. // Clear the page and block caches.
  150. cache_clear_all();
  151. }
  152. }