You are here

function print_pdf_requirements in Printer, email and PDF versions 5.4

Same name and namespace in other branches
  1. 5.3 print_pdf/print_pdf.module \print_pdf_requirements()
  2. 6 print_pdf/print_pdf.module \print_pdf_requirements()
  3. 7.2 print_pdf/print_pdf.install \print_pdf_requirements()
  4. 7 print_pdf/print_pdf.module \print_pdf_requirements()
  5. 5.x print_pdf/print_pdf.module \print_pdf_requirements()

Implementation of hook_requirements().

File

print_pdf/print_pdf.module, line 126

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('PDF generation library'),
          'value' => $t('No PDF tool selected'),
          'description' => $t('Please configure it in the <a href="@url">PDF settings page</a>.', array(
            '@url' => url('admin/settings/print/pdf'),
          )),
          'severity' => REQUIREMENT_ERROR,
        );
      }
      else {
        if (!is_file($print_pdf_pdf_tool) || !is_readable($print_pdf_pdf_tool)) {
          $requirements['print_pdf_tool'] = array(
            'title' => $t('PDF generation tool'),
            'value' => $t('File not found'),
            'description' => $t('The currently selected PDF generation library (%file) is no longer accessible.', array(
              '%file' => $print_pdf_pdf_tool,
            )),
            'severity' => REQUIREMENT_ERROR,
          );
        }
        elseif (basename($print_pdf_pdf_tool) == 'dompdf_config.inc.php') {
          $directory = dirname($print_pdf_pdf_tool) . '/lib/fonts';
          if (!is_dir($directory) || !is_writable($directory)) {
            $requirements['print_pdf_tool'] = array(
              'title' => $t('DOMPDF font cache directory'),
              'value' => $t('Non-writable permissions'),
              'description' => $t('You must change the %fontdir permissions to be writable, as dompdf requires write-access to that directory.', array(
                '%fontdir' => $directory,
              )),
              'severity' => REQUIREMENT_ERROR,
            );
          }
        }
        elseif (substr(basename($print_pdf_pdf_tool, '.exe'), 0, 11) == 'wkhtmltopdf') {
          if (function_exists('is_executable') && !is_executable($print_pdf_pdf_tool)) {
            $requirements['print_pdf_tool'] = array(
              'title' => $t('wkhtmltopdf library'),
              'value' => $t('Non-executable permissions'),
              'description' => $t('You must modify the permissions of the wkhtmltopdf file (%file) to make it executable.', array(
                '%file' => $print_pdf_pdf_tool,
              )),
              'severity' => REQUIREMENT_ERROR,
            );
          }
          else {
            $version = _print_pdf_wkhtmltopdf_version();
            if (version_compare($version, '0.9.6', '<')) {
              $requirements['print_pdf_tool'] = array(
                'title' => $t('wkhtmltopdf library'),
                'value' => $t('Unsupported version'),
                'description' => $t('The currently selected version of wkhtmltopdf (@version) is not supported. Please update to a <a href="@url">newer version</a>.', array(
                  '@version' => $version,
                  '@url' => url('http://code.google.com/p/wkhtmltopdf/'),
                )),
                'severity' => REQUIREMENT_ERROR,
              );
            }
          }
        }
      }
      break;
  }
  return $requirements;
}