module_install.api.inc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. /**
  3. * @file
  4. * Internal API methods for the module_install module.
  5. */
  6. /**
  7. * Helper to return a list of directories which will be searched.
  8. *
  9. * @param string $directory
  10. * The subdirectory to include.
  11. *
  12. * @return array
  13. * An array of directories which will be searched for possible destination
  14. * candidate folders.
  15. */
  16. function module_install_get_search_directories($directory) {
  17. $searchdir = array();
  18. // Always search sites/all/* as well as the global directories.
  19. $dir = 'sites/all/' . $directory;
  20. $searchdir[$dir] = $dir;
  21. // The 'profiles' directory contains pristine collections of modules and
  22. // themes as organized by a distribution. It is pristine in the same way
  23. // that /modules is pristine for core; users should avoid changing anything
  24. // there in favor of sites/all or sites/<domain> directories.
  25. $profiles = array();
  26. $profile = drupal_get_profile();
  27. // In case both profile directories contain the same extension, the actual
  28. // profile always has precedence.
  29. $profiles[] = $profile;
  30. foreach ($profiles as $profile) {
  31. $dir = 'profiles/' . $profile . '/' . $directory;
  32. if (file_exists($dir)) {
  33. $searchdir[$dir] = $dir;
  34. }
  35. }
  36. $config = conf_path();
  37. $dir = $config . '/' . $directory;
  38. if (file_exists($dir)) {
  39. $searchdir[$dir] = $dir;
  40. }
  41. return $searchdir;
  42. }
  43. /**
  44. * Helper to scan a directory and look for candidate destination folders.
  45. *
  46. * @param string $dir
  47. * The directory to scan
  48. *
  49. * @param unknown $found
  50. * An array containing candidate destination folders
  51. */
  52. function module_install_get_destination_directories($dir, &$found, $type) {
  53. $exceptions = module_invoke_all('module_install_exceptions');
  54. // Get directories automatically.
  55. if ($handle = opendir($dir)) {
  56. while (false !== ($file = readdir($handle))) {
  57. if (is_dir($dir . '/' . $file) && $file != '.' && $file != '..') {
  58. $directory = $dir . '/' . $file;
  59. $files = file_scan_directory($directory, '/.*\.module$/', array(
  60. 'recurse' => false
  61. ));
  62. if (count($files) == 0) {
  63. if (!in_array($directory, $found) && !in_array($directory, $exceptions)) {
  64. $found[$directory] = $directory;
  65. }
  66. }
  67. }
  68. }
  69. closedir($handle);
  70. }
  71. // Get specific listed directories.
  72. $includes = module_invoke_all('module_install_includes');
  73. foreach ($includes as $directory) {
  74. if (is_string($directory) && file_exists($directory) && !in_array($directory, $found)) {
  75. $found[$directory] = trim($directory, '/');
  76. }
  77. }
  78. }
  79. /**
  80. * Helper function to get the destination choice variable format.
  81. *
  82. * @return string
  83. * The variable name.
  84. */
  85. function module_install_get_destination_variable() {
  86. global $user;
  87. return 'module_install_destination_' . $user->uid;
  88. }
  89. /**
  90. * Helper function to get the destination choice variable.
  91. *
  92. * @return string
  93. * The destination folder path.
  94. */
  95. function module_install_get_destination_choice($default) {
  96. global $user;
  97. $variable = module_install_get_destination_variable();
  98. return variable_get($variable, $default);
  99. }
  100. /**
  101. * Helper function to set the destination choice variable.
  102. *
  103. * @param string $choice
  104. * The destination folder path.
  105. */
  106. function module_install_set_destination_choice($choice) {
  107. global $user;
  108. $variable = module_install_get_destination_variable();
  109. variable_set($variable, $choice);
  110. }
  111. /**
  112. * Helper function to delete the destination choice variable.
  113. */
  114. function module_install_del_destination_choice() {
  115. global $user;
  116. $variable = module_install_get_destination_variable();
  117. variable_del($variable);
  118. }