plupload.install 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. if ($phase == 'runtime') {
  12. $requirements['plupload'] = array(
  13. 'title' => t('Plupload library'),
  14. 'value' => t('Unknown'),
  15. );
  16. $requirements['plupload']['severity'] = REQUIREMENT_OK;
  17. $libraries = plupload_library();
  18. $library = $libraries['plupload'];
  19. // Check if Plupload library exists. Try to determine it's version
  20. // if it does.
  21. if (!_plupload_requirements_installed()) {
  22. $message = 'The <a href="@url">@title</a> library (version @version or higher) is not installed.';
  23. $args = array(
  24. '@title' => $library['title'],
  25. '@url' => url($library['website']),
  26. '@version' => $library['version']
  27. );
  28. $requirements['plupload']['description'] = t($message, $args);
  29. $requirements['plupload']['severity'] = REQUIREMENT_ERROR;
  30. }
  31. elseif (($installed_version = _plupload_requirements_version()) === NULL) {
  32. $requirements['plupload']['description'] = t('Plupload version could not be determined.');
  33. $requirements['plupload']['severity'] = REQUIREMENT_INFO;
  34. }
  35. elseif (!version_compare($library['version'], $installed_version, '<=')) {
  36. $requirements['plupload']['description'] = t('Plupload @version or higher is required.', array('@version' => $library['version']));
  37. $requirements['plupload']['severity'] = REQUIREMENT_INFO;
  38. }
  39. $requirements['plupload']['value'] = empty($installed_version) ? t('Not found') : $installed_version;
  40. }
  41. return $requirements;
  42. }
  43. /**
  44. * Checks wether Plupload library exists or not.
  45. *
  46. * @return TRUE if plupload library installed, FALSE otherwise.
  47. */
  48. function _plupload_requirements_installed() {
  49. $libraries = plupload_library();
  50. $library = $libraries['plupload'];
  51. // We grab the first file and check if it exists.
  52. $testfile = key($library['js']);
  53. if (!file_exists($testfile)) {
  54. return FALSE;
  55. }
  56. return TRUE;
  57. }
  58. /**
  59. * Returns the version of the installed plupload library.
  60. *
  61. * @return The version of installed Plupload or NULL if unable to detect
  62. * version.
  63. */
  64. function _plupload_requirements_version() {
  65. $library_path = _plupload_library_path();
  66. $jspath = $library_path . '/js/plupload.js';
  67. // Read contents of Plupload's javascript file.
  68. $configcontents = @file_get_contents($jspath);
  69. if (!$configcontents) {
  70. return NULL;
  71. }
  72. // Search for version string using a regular expression.
  73. $matches = array();
  74. if (preg_match('#VERSION:\"(\d+[\.\d+]*)\"#', $configcontents, $matches)) {
  75. return $matches[1];
  76. }
  77. return NULL;
  78. }