function htmlpurifier_requirements in HTML Purifier 7.2
Same name and namespace in other branches
- 6.2 htmlpurifier.install \htmlpurifier_requirements()
- 7 htmlpurifier.install \htmlpurifier_requirements()
Implements hook_requirements().
Checks the version of HTML Purifier on install and issues an error if there is a problem
File
- ./
htmlpurifier.install, line 35 - Install, update and uninstall functions for the HTML Purifier module.
Code
function htmlpurifier_requirements($phase) {
$requirements = array();
// Ensure translations do not break at install time
$t = get_t();
if ($phase == 'runtime') {
// Default requirement title
$title = $t('HTML Purifier Library');
$library = libraries_detect('htmlpurifier');
// Grab the versions of HTML Purifier
$current_version = variable_get('htmlpurifier_version_current', FALSE);
$our_version = isset($library['version']) ? $library['version'] : '';
// If we aren't at a current version, check again...
// This will happen the first time if we've never checked before
if (!$current_version) {
$current_version = htmlpurifier_check_version();
}
// If we can't check and retrieve the current version for some reason
if (!$current_version) {
$description = $t('Unable to check for the latest version of the HTML Purifier library. You will need to check manually at %url to find out if the version you are using is out of date.', array(
'%url' => $library['download url'],
));
$requirements['htmlpurifer_check']['title'] = $title;
$requirements['htmlpurifer_check']['value'] = $our_version;
$requirements['htmlpurifer_check']['description'] = $description;
$requirements['htmlpurifer_check']['severity'] = REQUIREMENT_WARNING;
}
elseif (version_compare($current_version, $our_version, '>')) {
$description = $t('Your HTML Purifier library is out of date. The latest version is %version, which you can download from %url.', array(
'%version' => $current_version,
'%url' => $library['download url'],
));
$requirements['htmlpurifer_check']['title'] = $title;
$requirements['htmlpurifer_check']['value'] = $our_version;
$requirements['htmlpurifer_check']['description'] = $description;
$requirements['htmlpurifer_check']['severity'] = REQUIREMENT_WARNING;
}
// Success! We found the library
if ($library['installed']) {
$requirements['htmlpurifer']['title'] = $title;
$requirements['htmlpurifer']['value'] = $our_version;
$requirements['htmlpurifer']['description'] = $t('Installed version');
$requirements['htmlpurifer']['severity'] = REQUIREMENT_OK;
}
else {
$supported_versions = array_keys($library['versions']);
$error = $library['error message'] . $t(' Please download a supported version (%versions) from %url.', array(
'%versions' => implode(' or ', $supported_versions),
'%url' => $library['download url'],
));
$requirements['htmlpurifer']['title'] = $title;
$requirements['htmlpurifer']['value'] = $our_version;
$requirements['htmlpurifer']['description'] = $error;
$requirements['htmlpurifer']['severity'] = REQUIREMENT_ERROR;
}
}
return $requirements;
}