function print_pdf_requirements in Printer, email and PDF versions 7.2
Same name and namespace in other branches
- 5.4 print_pdf/print_pdf.module \print_pdf_requirements()
- 5.3 print_pdf/print_pdf.module \print_pdf_requirements()
- 6 print_pdf/print_pdf.module \print_pdf_requirements()
- 7 print_pdf/print_pdf.module \print_pdf_requirements()
- 5.x print_pdf/print_pdf.module \print_pdf_requirements()
Implements hook_requirements().
File
- print_pdf/
print_pdf.install, line 142 - Install, update and uninstall functions for the print_pdf module.
Code
function print_pdf_requirements($phase) {
$requirements = array();
$t = get_t();
switch ($phase) {
// At runtime, make sure that a PDF generation tool is selected.
case 'runtime':
$print_pdf_pdf_tool = variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT);
if (empty($print_pdf_pdf_tool)) {
$requirements['print_pdf_tool'] = array(
'title' => $t('Printer, email and PDF versions - PDF generation library'),
'value' => $t('No PDF tool selected'),
'description' => $t('Please configure it in the !url.', array(
'!url' => l($t('PDF settings page'), 'admin/config/user-interface/print/pdf'),
)),
'severity' => REQUIREMENT_ERROR,
);
}
else {
// Tool is defined, get some data from it's handler module.
$tool = explode('|', $print_pdf_pdf_tool);
$function = $tool[0] . '_pdf_tool_info';
$info = function_exists($function) ? $function() : array();
// Is the file there?
if (!is_file($tool[1]) || !is_readable($tool[1])) {
$requirements['print_pdf_tool'] = array(
'title' => $t('Printer, email and PDF versions - PDF generation library'),
'value' => $t('File not found'),
'description' => $t('The currently selected PDF generation library (%file) is no longer accessible.', array(
'%file' => $tool[1],
)),
'severity' => REQUIREMENT_ERROR,
);
}
else {
// Get the version number.
$function = $tool[0] . '_pdf_tool_version';
if (function_exists($function)) {
$version = $function($tool[1]);
if (isset($info['min_version']) && version_compare($version, $info['min_version'], '<')) {
$requirements['print_pdf_tool_version'] = array(
'title' => $t('Printer, email and PDF versions - PDF generation library'),
'value' => $t('Unsupported %lib version', array(
'%lib' => $info['name'],
)),
'description' => $t('The currently selected version of %lib (@version) is not supported. Please update to !url.', array(
'%lib' => $info['name'],
'@version' => $version,
'!url' => l($t('version @min or newer', array(
'@min' => $info['min_version'],
)), $info['url']),
)),
'severity' => REQUIREMENT_ERROR,
);
}
else {
$requirements['print_pdf_tool_version'] = array(
'title' => $t('Printer, email and PDF versions - PDF generation library'),
'value' => $info['name'] . ' ' . $version,
);
}
}
}
// If auto-config is on, check for write access to the appropriate dirs.
if (variable_get('print_pdf_autoconfig', PRINT_PDF_AUTOCONFIG_DEFAULT)) {
$directories = array();
if (isset($info['public_dirs'])) {
foreach ($info['public_dirs'] as $dir) {
$directories[] = 'public://print_pdf/' . $tool[0] . '/' . $dir;
}
}
if (isset($info['tool_dirs'])) {
foreach ($info['tool_dirs'] as $dir) {
$directories[] = dirname($tool[1]) . '/' . $dir;
}
}
foreach ($directories as $dir) {
if (!is_dir($dir) || !is_writable($dir)) {
$requirements['print_pdf_tool_' . $dir] = array(
'title' => $t('%lib directory', array(
'%lib' => $info['name'],
)),
'value' => $t('Non-writable permissions'),
'description' => $t('You must change the %libdir permissions to be writable, as %lib requires write-access to that directory.', array(
'%lib' => $info['name'],
'%libdir' => $dir,
)),
'severity' => REQUIREMENT_ERROR,
);
}
}
}
}
break;
}
return $requirements;
}