1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
<?php
/**
* @file
* Install, update and uninstall functions for the Plupload module.
*/
/**
* Implements hook_requirements().
*/
function plupload_requirements($phase) {
$requirements = array();
$t = get_t();
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;
if (file_exists(_plupload_library_path() . '/examples/upload.php')) {
$requirements['plupload_examples'] = array(
'title' => $t('Plupload example folder'),
'value' => $t('Example folder found'),
'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(
'!url' => 'http://drupal.org/node/1189632',
'!path' => _plupload_library_path() . '/examples'
)),
'severity' => REQUIREMENT_ERROR
);
}
}
return $requirements;
}
/**
* Checks wether Plupload library exists or not.
*
* @return boolean
* 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 string
* 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];
}
// After 1.5.8 Plupload stopped adding version string to .js file. Let's check
// first line of changelog.txt.
$library_path = _plupload_library_path();
$clpath = $library_path . '/changelog.txt';
$configcontents = @file_get_contents($clpath);
if (!$configcontents) {
return NULL;
}
$lines = explode("\n", $configcontents);
if (preg_match('#^Version (\d+[\.\d+]*)#', $lines[0], $matches)) {
return $matches[1];
}
return NULL;
}
|