You are here

function print_pdf_requirements in Printer, email and PDF versions 6

Same name and namespace in other branches
  1. 5.4 print_pdf/print_pdf.module \print_pdf_requirements()
  2. 5.3 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 197
Displays Printer-friendly versions of Drupal pages.

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/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('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' => $print_pdf_pdf_tool,
            )),
            'severity' => REQUIREMENT_ERROR,
          );
        }
        elseif (basename($print_pdf_pdf_tool) == 'dompdf_config.inc.php') {
          if (variable_get('print_pdf_autoconfig', PRINT_PDF_AUTOCONFIG_DEFAULT)) {
            $directory = file_directory_path() . '/' . PRINT_PDF_DOMPDF_CACHE_DIR_DEFAULT . '/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 (basename($print_pdf_pdf_tool) == 'tcpdf.php') {
          $version = _print_pdf_tcpdf_version();
          if (version_compare($version, '5.9.001', '<')) {
            $requirements['print_pdf_tool'] = array(
              'title' => $t('Printer, email and PDF versions - PDF generation library'),
              'value' => $t('Unsupported TCPDF version'),
              'description' => $t('The currently selected version of TCPDF (@version) is not supported. Please update to a !url.', array(
                '@version' => $version,
                '!url' => l($t('newer version'), 'http://sourceforge.net/projects/tcpdf/files/latest'),
              )),
              'severity' => REQUIREMENT_ERROR,
            );
          }
          else {
            $requirements['print_pdf_tool'] = array(
              'title' => $t('Printer, email and PDF versions - PDF generation library'),
              'value' => $t('TCPDF') . ' ' . $version,
            );
          }
          if (variable_get('print_pdf_autoconfig', PRINT_PDF_AUTOCONFIG_DEFAULT)) {
            foreach (array(
              'cache',
              'images',
            ) as $dir) {
              $directory = file_directory_path() . '/' . PRINT_PDF_TCPDF_CACHE_DIR_DEFAULT . '/' . $dir;
              if (!is_dir($directory) || !is_writable($directory)) {
                $requirements['print_pdf_tool_' . $dir] = array(
                  'title' => $t('TCPDF directory'),
                  'value' => $t('Non-writable permissions'),
                  'description' => $t('You must change the %fontdir permissions to be writable, as TCPDF requires write-access to that directory.', array(
                    '%fontdir' => $directory,
                  )),
                  'severity' => REQUIREMENT_ERROR,
                );
              }
            }
          }
        }
        elseif (drupal_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('Printer, email and PDF versions - PDF generation library'),
                'value' => $t('Unsupported wkhtmltopdf version'),
                'description' => $t('The currently selected version of wkhtmltopdf (@version) is not supported. Please update to a !url.', array(
                  '@version' => $version,
                  '!url' => l($t('newer version'), 'http://code.google.com/p/wkhtmltopdf/'),
                )),
                'severity' => REQUIREMENT_ERROR,
              );
            }
            else {
              $requirements['print_pdf_tool'] = array(
                'title' => $t('Printer, email and PDF versions - PDF generation library'),
                'value' => $t('wkhtmltopdf') . ' ' . $version,
              );
            }
          }
        }
      }
      break;
  }
  return $requirements;
}