elfinder.install 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. /**
  3. * @file
  4. * Installation file for elfinder.
  5. */
  6. /**
  7. * Implements hook_requirements().
  8. */
  9. function elfinder_requirements($phase) {
  10. require_once drupal_get_path('module', 'elfinder') . "/elfinder.module";
  11. $requirements = array();
  12. $ver_major = 0;
  13. $ver_minor = 0;
  14. $ver_release = 0;
  15. $min_major = 2;
  16. $min_minor = 0;
  17. $min_ver = "$min_major.$min_minor";
  18. $libpath = elfinder_lib_path();
  19. $ver = '';
  20. $install_t = t('Please download it from <a href="@url">@url</a> and install to @libpath.', array('@url' => 'http://elfinder.org', '@libpath' => $libpath));
  21. if ($phase == 'runtime' || $phase == 'install' || $phase == 'update') {
  22. $description = t('elFinder library was not found.') . ' ' . $install_t;
  23. $severity = '';
  24. $value = t('Not found');
  25. if ( (is_readable($libpath . '/connectors/php/elFinder.class.php') || is_readable($libpath . '/php/elFinder.class.php') ) && is_readable($libpath . '/js/elfinder.min.js') ) {
  26. $editor_file_content = file_get_contents($libpath . '/js/elfinder.min.js');
  27. $value = t('Exists');
  28. if (preg_match("/(?:this|elFinder\.prototype|\.prototype)\.version\s*=\s*[\"\']([^\"\']+)[\"\']/", $editor_file_content, $matches)) {
  29. $ver = $matches[1];
  30. $value = t('@ver', array('@ver' => $ver));
  31. }
  32. $description = '';
  33. if (preg_match("/^(\d+)\.(\d+|x)(\.(\d+))?/", $ver, $matches)) {
  34. $ver_major = (int)$matches[1];
  35. $ver_minor = $matches[2];
  36. $ver = "$ver_major.$ver_minor";
  37. if (count($matches) == 5) {
  38. $ver_release = (int)$matches[4];
  39. $ver = "$ver_major.$ver_minor.$ver_release";
  40. }
  41. }
  42. if (($ver_major < $min_major) || ($ver_major == 2 && $ver_minor == '1' && $ver_release < 38)) {
  43. $description = t('Not supported elFinder library. Please upgrade to @minver.', array('@ver' => $ver, '@minver' => $min_ver)) . ' ' . $install_t;
  44. $severity = REQUIREMENT_ERROR;
  45. } else {
  46. $severity = REQUIREMENT_OK;
  47. }
  48. $badpaths_check = elfinder_check_badpaths();
  49. if ($badpaths_check['result'] == FALSE) {
  50. $severity = REQUIREMENT_ERROR;
  51. $description = $badpaths_check['message'];
  52. }
  53. }
  54. else {
  55. $severity = REQUIREMENT_ERROR;
  56. }
  57. $requirements['elfinder'] = array(
  58. 'title' => 'elFinder',
  59. 'description' => $description,
  60. 'value' => $value,
  61. 'severity' => $severity
  62. );
  63. }
  64. return $requirements;
  65. }
  66. function elfinder_uninstall() {
  67. db_delete('variable')
  68. ->condition('name', 'elfinder_%', 'like')
  69. ->execute();
  70. cache_clear_all('variables', 'cache');
  71. }
  72. function elfinder_schema() {
  73. $schema = array();
  74. $schema['elfinder_file_extinfo'] = array(
  75. 'description' => 'Stores additional filesystem attributes',
  76. 'fields' => array(
  77. 'extid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
  78. 'fid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE),
  79. 'description' => array('type' => 'varchar', 'length' => 255, 'not null' => FALSE, 'default' => ''),
  80. ),
  81. 'primary key' => array('extid'),
  82. );
  83. $schema['elfinder_profile'] = array(
  84. 'description' => 'Stores configuration profiles',
  85. 'fields' => array(
  86. 'pid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
  87. 'name' => array('type' => 'varchar', 'length' => 255, 'not null' => FALSE, 'default' => ''),
  88. 'description' => array('type' => 'varchar', 'length' => 255, 'not null' => FALSE, 'default' => ''),
  89. 'settings' => array('type' => 'text', 'not null' => FALSE),
  90. ),
  91. 'primary key' => array('pid'),
  92. );
  93. return $schema;
  94. }
  95. function elfinder_update_7101() {
  96. }
  97. function elfinder_update_7102() {
  98. $ret = array();
  99. if (db_table_exists('elfinder_profile') == FALSE) {
  100. drupal_install_schema('elfinder');
  101. }
  102. if (!db_field_exists('elfinder_profile', 'settings')) {
  103. db_add_field($ret, 'elfinder_profile', 'settings', array('type' => 'text', 'not null' => FALSE));
  104. }
  105. return $ret;
  106. }
  107. function elfinder_update_7103() {
  108. drupal_flush_all_caches();
  109. }
  110. /**
  111. * Reformat the setting profile_role in elfinder_profile table.
  112. */
  113. function elfinder_update_7104() {
  114. $results = db_query("SELECT pid, name, description, settings from {elfinder_profile}");
  115. foreach($results as $row) {
  116. $settings = unserialize($row->settings);
  117. if (!is_array($settings['profile_role'])) {
  118. if (isset($settings['profile_role']) && $settings['profile_role'] > 0) {
  119. $settings['profile_role'] = array($settings['profile_role'] => $settings['profile_role']);
  120. }
  121. else {
  122. $settings['profile_role'] = array();
  123. }
  124. db_update('elfinder_profile')
  125. ->fields(array('settings' => serialize($settings)))
  126. ->condition('pid', $row->pid)
  127. ->execute();
  128. }
  129. }
  130. }