taxonomy_csv.module 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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-2012 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 or structure of terms from or into a
  28. * vocabulary with a simple csv file. General infos can be found in README.txt.
  29. * Technical infos can be found in TECHINFO.txt.
  30. *
  31. * taxonomy_csv.module manage general hooks of module.
  32. */
  33. /**
  34. * Implements hook_help().
  35. */
  36. function taxonomy_csv_help($path, $arg) {
  37. global $language;
  38. switch ($path) {
  39. case 'admin/structure/taxonomy/csv_import':
  40. $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(
  41. '!link' => url('http://en.wikipedia.org/wiki/Comma-separated_values'),
  42. )) . '</p>'
  43. . '<ul>'
  44. . '<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>'
  45. . '<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>'
  46. . '<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>'
  47. . '</ul>'
  48. . theme('more_help_link', array('url' => 'admin/help/taxonomy_csv')) . '<br />';
  49. return $output;
  50. case 'admin/structure/taxonomy/csv_export':
  51. $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(
  52. '!link' => url('http://en.wikipedia.org/wiki/Comma-separated_values'),
  53. )) . '</p>'
  54. . '<p>' . t('Set vocabulary to export in first tab, format to use in second tab and order of terms in third tab.') . '</p>'
  55. . theme('more_help_link', array('url' => 'admin/help/taxonomy_csv')) . '<br />';
  56. return $output;
  57. case 'admin/help#taxonomy_csv':
  58. $check = drupal_realpath(drupal_get_path('module', 'taxonomy_csv') . '/taxonomy_csv.help.' . $language->prefix . '.html');
  59. $output = file_get_contents($check ? $check : drupal_realpath(drupal_get_path('module', 'taxonomy_csv') . '/taxonomy_csv.help.html'));
  60. return $output;
  61. }
  62. }
  63. /**
  64. * Implements hook_permission().
  65. */
  66. function taxonomy_csv_permission() {
  67. return array(
  68. 'import taxonomy by csv' => array(
  69. 'title' => t('Import taxonomy by CSV'),
  70. ),
  71. 'export taxonomy by csv' => array(
  72. 'title' => t('Export taxonomy by CSV'),
  73. ),
  74. );
  75. }
  76. /**
  77. * Implements hook_menu().
  78. */
  79. function taxonomy_csv_menu() {
  80. $items = array();
  81. $items['admin/structure/taxonomy/csv_import'] = array(
  82. 'title' => 'CSV import',
  83. 'description' => 'Import taxonomies, hierarchical structure or simple lists of terms and properties with CSV file or text.',
  84. 'page callback' => 'drupal_get_form',
  85. 'page arguments' => array('taxonomy_csv_import_form'),
  86. 'access arguments' => array('import taxonomy by csv'),
  87. 'weight' => 12,
  88. 'type' => MENU_LOCAL_TASK,
  89. 'file' => 'import/taxonomy_csv.import.admin.inc',
  90. );
  91. $items['admin/structure/taxonomy/csv_export'] = array(
  92. 'title' => 'CSV export',
  93. 'description' => 'Export terms and properties to a CSV file.',
  94. 'page callback' => 'drupal_get_form',
  95. 'page arguments' => array('taxonomy_csv_export_form'),
  96. 'access arguments' => array('export taxonomy by csv'),
  97. 'weight' => 13,
  98. 'type' => MENU_LOCAL_TASK,
  99. 'file' => 'export/taxonomy_csv.export.admin.inc',
  100. );
  101. return $items;
  102. }