You are here

function theme_pdf_reader in PDF Reader 7

Same name and namespace in other branches
  1. 7.2 pdf_reader.module \theme_pdf_reader()

Theme the field with pdf reader

2 theme calls to theme_pdf_reader()
PdfReaderTest::testIframeRendering in tests/pdf_reader.test
pdf_reader_field_formatter_view in ./pdf_reader.module
Implements hook_field_formatter_view().

File

./pdf_reader.module, line 158
pdf reader module file.

Code

function theme_pdf_reader($variables) {
  $file_url = isset($variables['file']['uri']) ? file_create_url($variables['file']['uri']) : $variables['file']['value'];
  switch ($variables['settings']['renderer']) {
    case 'google':
      $output = '<iframe id="pdf_reader" src="//docs.google.com/viewer?embedded=true&url=' . urlencode($file_url) . '" width="' . $variables['settings']['pdf_width'] . '" height="' . $variables['settings']['pdf_height'] . '" scrolling="no' . '" style="border: none;"></iframe>';
      break;
    case 'direct':
      $download_link = '';
      if (user_access('download pdf files')) {
        $download_link = t('or') . ' ' . l(t('click here to download the PDF file.'), $file_url);
      }
      $output = '<object id="pdf_reader" data="' . $file_url . '#view=Fit' . '" ' . 'type="application/pdf' . '" ' . 'width="' . $variables['settings']['pdf_width'] . '" ' . 'height="' . $variables['settings']['pdf_height'] . '">' . '<embed src="' . $file_url . '#view=Fit' . '"' . 'width="' . $variables['settings']['pdf_width'] . '" ' . 'height="' . $variables['settings']['pdf_height'] . '" ' . 'type="application/pdf">' . '<p>' . t('It appears your Web browser is not configured to display PDF files. ') . l(t('Download adobe Acrobat '), 'http://www.adobe.com/products/reader.html') . ' ' . $download_link . '</p>' . '</embed></object>';
      break;
    case 'pdf-js':
      _pdf_reader_load_pdf_js($file_url);
      $output = theme('pdf_js');
      break;
  }
  if ($variables['settings']['download'] == TRUE && user_access('download pdf files')) {
    $output .= l(t('Click here to download the PDF file.'), $file_url, array(
      'attributes' => array(
        'class' => 'pdf-reader-download-link',
      ),
    ));
  }
  if ($variables['settings']['colorbox'] == TRUE) {
    $html = $output;
    $options = array(
      'attributes' => array(
        'class' => array(
          'colorbox-inline',
          'show',
        ),
      ),
      'query' => array(
        'width' => $variables['settings']['pdf_width'],
        'height' => $variables['settings']['pdf_height'],
        'inline' => 'true',
      ),
      'fragment' => 'pdf_reader',
    );
    $output = l(t($variables['settings']['colorbox_link_text']), $file_url, $options);
    $output .= '<div style="display:none">' . $html . '</div>';
  }
  return $output;
}