tripal_core_files.api.inc 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * @file
  4. * The Tripal Files API
  5. *
  6. * This file provides the API to help Tripal modules to storing files
  7. * in a consistent directory strcuture.
  8. *
  9. * @defgroup tripal_files_api Files API
  10. * @ingroup tripal_core_api
  11. * @{
  12. * Provides an application programming interface (API) for managing files within
  13. * the Tripal data directory structure.
  14. *
  15. * @}
  16. *
  17. */
  18. /**
  19. * This function is a substitute for Drupal 6's file_directory_path()
  20. * function which no longer exists in Drupal 7. However, the function
  21. * call is useful because it's more intitutive. So this wrapper was created
  22. * to mimic the behavior of the old function.
  23. *
  24. * @return
  25. * the public directory where tripal files are housed: sites/default/files/tripal
  26. */
  27. function tripal_file_directory_path() {
  28. return variable_get('file_public_path', conf_path() . '/files/tripal');
  29. }
  30. /**
  31. * This function is typically used in the '.install' file for a Tripal module
  32. * Each module should call this function during installation to create
  33. * the module data directory which is sites/default/files/tripal/[module_name]
  34. * for default Drupal settings. This directory can then be used by the module
  35. * for storing files.
  36. *
  37. * @param $module_name
  38. * the name of the module being installed.
  39. *
  40. * @returns
  41. * nothing
  42. *
  43. * @ingroup tripal_files_api
  44. */
  45. function tripal_create_moddir($module_name) {
  46. // make the data directory for this module
  47. $data_dir = tripal_file_directory_path() . "$module_name";
  48. if (!file_check_directory($data_dir, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
  49. $message = "Cannot create directory $data_dir. This module may not " .
  50. "behave correctly without this directory. Please create " .
  51. "the directory manually or fix the problem and reinstall.";
  52. drupal_set_message(check_plain(t($message)), 'error');
  53. watchdog('tripal_core', $message, array(), WATCHDOG_ERROR);
  54. }
  55. }
  56. /**
  57. * Each Tripal module has a unique data directory which was creatd using the
  58. * tripal_create_moddir function during installation. This function
  59. * retrieves the directory path.
  60. *
  61. * @param $module_name
  62. * The name of the module
  63. *
  64. * @returns
  65. * The path within the Drupal installation where the data directory resides
  66. *
  67. * @ingroup tripal_files_api
  68. */
  69. function tripal_get_moddir($module_name) {
  70. $data_dir = tripal_file_directory_path() . "$module_name";
  71. return $data_dir;
  72. }