taxonomy_csv.module

Tracking 6.x-5.x branch
  1. drupal
    1. 6 contributions/taxonomy_csv/taxonomy_csv.module

Quick export and import of taxonomies, structure or lists of terms to or from a csv local or distant file or a text area.

Automatically exports or imports a list of terms, structure, children, related, synonyms, descriptions and/or weights from or into a vocabulary with a simple csv file. General infos can be found in README.txt. Technical infos can be found in TECHINFO.txt.

taxonomy_csv.module manage general hooks of module.

Functions & methods

NameDescription
taxonomy_csv_form_export_prepareMenu callback of the main export form.
taxonomy_csv_form_import_prepareMenu callback of the main import form.
taxonomy_csv_helpImplements hook_help().
taxonomy_csv_menuImplements hook_menu().
taxonomy_csv_permImplements hook_perm().

File

View source
  1. <?php
  2. /**
  3. * taxonomy_csv module for Drupal
  4. *
  5. * Copyright (c) 2007-2008 Dennis Stevense, see LICENSE.txt for more information
  6. * Copyright (c) 2009-2010 Daniel Berthereau <daniel.drupal@berthereau.net>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it under
  9. * the terms of the GNU General Public License as published by the Free Software
  10. * Foundation; either version 2 of the License, or (at your option) any later
  11. * version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  15. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU General Public License along with
  19. * this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. */
  22. /**
  23. * @file
  24. * Quick export and import of taxonomies, structure or lists of terms to or from
  25. * a csv local or distant file or a text area.
  26. *
  27. * Automatically exports or imports a list of terms, structure, children,
  28. * related, synonyms, descriptions and/or weights from or into a vocabulary with
  29. * a simple csv file. General infos can be found in README.txt. Technical
  30. * infos can be found in TECHINFO.txt.
  31. *
  32. * taxonomy_csv.module manage general hooks of module.
  33. */
  34. /**
  35. * Implements hook_help().
  36. */
  37. function taxonomy_csv_help($path, $arg) {
  38. global $language;
  39. switch ($path) {
  40. case 'admin/content/taxonomy/csv_import':
  41. $output = '<p>' . t('Use this form to import a taxonomy, a structure or a list of terms into a vocabulary from a simple <a href="!link" title="Wikipedia definition">CSV</a> file, a url or a copy-and-paste text.', array(
  42. '!link' => url('http://en.wikipedia.org/wiki/Comma-separated_values'),
  43. )) . '</p>'
  44. . '<ul>'
  45. . '<li>' . t('For performance reasons, it is recommended to disable some other taxonomy related modules before import of big taxonomies and to reactivate them after process.') . '</li>'
  46. . '<li>' . t('For a better user experience, it is recommended to avoid duplicate terms. This module can manage them efficiently, but hidden errors can occur when a complex vocabulary with duplicates is updated by the administrator or by the module.') . '</li>'
  47. . '<li>' . '<strong>' . t('Warning') . '</strong>' . ': ' . t('If you want to update an existing vocabulary, make sure you have a backup before you proceed so you can roll back, if necessary.') . '</li>'
  48. . '</ul>'
  49. . theme('more_help_link', url('admin/help/taxonomy_csv')) . '<br />';
  50. return $output;
  51. case 'admin/content/taxonomy/csv_export':
  52. $output = '<p>' . t('Use this form to export a taxonomy, a structure or a list of terms to a simple <a href="!link" title="Wikipedia definition">CSV</a> file.', array(
  53. '!link' => url('http://en.wikipedia.org/wiki/Comma-separated_values'),
  54. )) . '</p>'
  55. . '<p>' . t('Set vocabulary to export in first tab, format to use in second tab and order of terms in third tab.') . '</p>'
  56. . theme('more_help_link', url('admin/help/taxonomy_csv')) . '<br />';
  57. return $output;
  58. case 'admin/help#taxonomy_csv':
  59. $check = realpath(drupal_get_path('module', 'taxonomy_csv') . '/taxonomy_csv.help.' . $language->prefix . '.html');
  60. $output = file_get_contents(file_exists($check) ? $check : realpath(drupal_get_path('module', 'taxonomy_csv') . '/taxonomy_csv.help.html'));
  61. return $output;
  62. }
  63. }
  64. /**
  65. * Implements hook_perm().
  66. */
  67. function taxonomy_csv_perm() {
  68. return array(
  69. 'import taxonomy by csv',
  70. 'export taxonomy by csv',
  71. );
  72. }
  73. /**
  74. * Implements hook_menu().
  75. *
  76. * @note See hook_menu for a description of return values.
  77. */
  78. function taxonomy_csv_menu() {
  79. $items = array();
  80. $items['admin/content/taxonomy/csv_import'] = array(
  81. 'title' => 'CSV import',
  82. 'description' => 'Import taxonomies, hierarchical structure or simple lists of terms and properties with CSV file or text.',
  83. 'page callback' => 'taxonomy_csv_form_import_prepare',
  84. 'access arguments' => array('import taxonomy by csv'),
  85. 'weight' => 12,
  86. 'type' => MENU_LOCAL_TASK,
  87. );
  88. $items['admin/content/taxonomy/csv_export'] = array(
  89. 'title' => 'CSV export',
  90. 'description' => 'Export terms and properties to a CSV file.',
  91. 'page callback' => 'taxonomy_csv_form_export_prepare',
  92. 'access arguments' => array('export taxonomy by csv'),
  93. 'weight' => 13,
  94. 'type' => MENU_LOCAL_TASK,
  95. );
  96. return $items;
  97. }
  98. /**
  99. * Menu callback of the main import form.
  100. */
  101. function taxonomy_csv_form_import_prepare() {
  102. // Invoke taxonomy_csv api (defines and functions).
  103. $module_dir = drupal_get_path('module', 'taxonomy_csv');
  104. require_once("$module_dir/import/taxonomy_csv.import.admin.inc");
  105. // Javascript and css allow to show only available options depending choices.
  106. drupal_add_js("$module_dir/taxonomy_csv.js");
  107. drupal_add_css("$module_dir/taxonomy_csv.css");
  108. return drupal_get_form('taxonomy_csv_form_import');
  109. }
  110. /**
  111. * Menu callback of the main export form.
  112. */
  113. function taxonomy_csv_form_export_prepare() {
  114. // Invoke taxonomy_csv api (defines and functions).
  115. $module_dir = drupal_get_path('module', 'taxonomy_csv');
  116. require_once("$module_dir/export/taxonomy_csv.export.admin.inc");
  117. // Javascript and css allow to show only available options depending choices.
  118. drupal_add_js("$module_dir/taxonomy_csv.js");
  119. drupal_add_css("$module_dir/taxonomy_csv.css");
  120. return drupal_get_form('taxonomy_csv_form_export');
  121. }