1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- /**
- * @file
- * Install, update and uninstall functions for the Plupload module.
- */
- /**
- * Implements hook_requirements().
- */
- function plupload_requirements($phase) {
- $requirements = array();
- if ($phase == 'runtime') {
- $requirements['plupload'] = array(
- 'title' => t('Plupload library'),
- 'value' => t('Unknown'),
- );
- $requirements['plupload']['severity'] = REQUIREMENT_OK;
- $libraries = plupload_library();
- $library = $libraries['plupload'];
- // Check if Plupload library exists. Try to determine it's version
- // if it does.
- if (!_plupload_requirements_installed()) {
- $message = 'The <a href="@url">@title</a> library (version @version or higher) is not installed.';
- $args = array(
- '@title' => $library['title'],
- '@url' => url($library['website']),
- '@version' => $library['version']
- );
- $requirements['plupload']['description'] = t($message, $args);
- $requirements['plupload']['severity'] = REQUIREMENT_ERROR;
- }
- elseif (($installed_version = _plupload_requirements_version()) === NULL) {
- $requirements['plupload']['description'] = t('Plupload version could not be determined.');
- $requirements['plupload']['severity'] = REQUIREMENT_INFO;
- }
- elseif (!version_compare($library['version'], $installed_version, '<=')) {
- $requirements['plupload']['description'] = t('Plupload @version or higher is required.', array('@version' => $library['version']));
- $requirements['plupload']['severity'] = REQUIREMENT_INFO;
- }
- $requirements['plupload']['value'] = empty($installed_version) ? t('Not found') : $installed_version;
- }
- return $requirements;
- }
- /**
- * Checks wether Plupload library exists or not.
- *
- * @return TRUE if plupload library installed, FALSE otherwise.
- */
- function _plupload_requirements_installed() {
- $libraries = plupload_library();
- $library = $libraries['plupload'];
- // We grab the first file and check if it exists.
- $testfile = key($library['js']);
- if (!file_exists($testfile)) {
- return FALSE;
- }
- return TRUE;
- }
- /**
- * Returns the version of the installed plupload library.
- *
- * @return The version of installed Plupload or NULL if unable to detect
- * version.
- */
- function _plupload_requirements_version() {
- $library_path = _plupload_library_path();
- $jspath = $library_path . '/js/plupload.js';
- // Read contents of Plupload's javascript file.
- $configcontents = @file_get_contents($jspath);
- if (!$configcontents) {
- return NULL;
- }
- // Search for version string using a regular expression.
- $matches = array();
- if (preg_match('#VERSION:\"(\d+[\.\d+]*)\"#', $configcontents, $matches)) {
- return $matches[1];
- }
- return NULL;
- }
|