tripal_core.files.api.inc 2.9 KB

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