plupload.install 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the Plupload module.
  5. */
  6. /**
  7. * Implements hook_requirements().
  8. */
  9. function plupload_requirements($phase) {
  10. $requirements = array();
  11. $t = get_t();
  12. if ($phase == 'runtime') {
  13. $requirements['plupload'] = array(
  14. 'title' => $t('Plupload library'),
  15. 'value' => $t('Unknown'),
  16. );
  17. $requirements['plupload']['severity'] = REQUIREMENT_OK;
  18. $libraries = plupload_library();
  19. $library = $libraries['plupload'];
  20. // Check if Plupload library exists. Try to determine it's version
  21. // if it does.
  22. if (!_plupload_requirements_installed()) {
  23. $message = 'The <a href="@url">@title</a> library (version @version or higher) is not installed.';
  24. $args = array(
  25. '@title' => $library['title'],
  26. '@url' => url($library['website']),
  27. '@version' => $library['version'],
  28. );
  29. $requirements['plupload']['description'] = $t($message, $args);
  30. $requirements['plupload']['severity'] = REQUIREMENT_ERROR;
  31. }
  32. elseif (($installed_version = _plupload_requirements_version()) === NULL) {
  33. $requirements['plupload']['description'] = $t('Plupload version could not be determined.');
  34. $requirements['plupload']['severity'] = REQUIREMENT_INFO;
  35. }
  36. elseif (!version_compare($library['version'], $installed_version, '<=')) {
  37. $requirements['plupload']['description'] = $t('Plupload @version or higher is required.', array('@version' => $library['version']));
  38. $requirements['plupload']['severity'] = REQUIREMENT_INFO;
  39. }
  40. $requirements['plupload']['value'] = empty($installed_version) ? $t('Not found') : $installed_version;
  41. if (file_exists(_plupload_library_path() . '/examples/upload.php')) {
  42. $requirements['plupload_examples'] = array(
  43. 'title' => $t('Plupload example folder'),
  44. 'value' => $t('Example folder found'),
  45. 'description' => $t('Plupload library contains example files, these could constitute a security risk to your site as per <a href="!url">PSA-2011-02</a>. Please remove the !path folder immediately.', array(
  46. '!url' => 'http://drupal.org/node/1189632',
  47. '!path' => _plupload_library_path() . '/examples'
  48. )),
  49. 'severity' => REQUIREMENT_ERROR
  50. );
  51. }
  52. }
  53. return $requirements;
  54. }
  55. /**
  56. * Checks wether Plupload library exists or not.
  57. *
  58. * @return boolean
  59. * TRUE if plupload library installed, FALSE otherwise.
  60. */
  61. function _plupload_requirements_installed() {
  62. $libraries = plupload_library();
  63. $library = $libraries['plupload'];
  64. // We grab the first file and check if it exists.
  65. $testfile = key($library['js']);
  66. if (!file_exists($testfile)) {
  67. return FALSE;
  68. }
  69. return TRUE;
  70. }
  71. /**
  72. * Returns the version of the installed plupload library.
  73. *
  74. * @return string
  75. * The version of installed Plupload or NULL if unable to detect version.
  76. */
  77. function _plupload_requirements_version() {
  78. $library_path = _plupload_library_path();
  79. $jspath = $library_path . '/js/plupload.js';
  80. // Read contents of Plupload's javascript file.
  81. $configcontents = @file_get_contents($jspath);
  82. if (!$configcontents) {
  83. return NULL;
  84. }
  85. // Search for version string using a regular expression.
  86. $matches = array();
  87. if (preg_match('#VERSION:\"(\d+[\.\d+]*)\"#', $configcontents, $matches)) {
  88. return $matches[1];
  89. }
  90. return NULL;
  91. }