elfinder.install 4.9 KB

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