You are here

biblio_rtf.module in Bibliography Module 7

Same filename and directory in other branches
  1. 6.2 modules/rtf/biblio_rtf.module
  2. 7.2 modules/rtf/biblio_rtf.module

File

modules/rtf/biblio_rtf.module
View source
<?php

/**
 * @file
 */

/**
 *
 */
function biblio_rtf_views_api() {
  return array(
    'api' => 2,
    'path' => drupal_get_path('module', 'biblio_rtf') . '/views',
  );
}

/**
 *
 */
function biblio_rtf_biblio_export_options() {
  return array(
    'rtf' => t('RTF'),
  );
}

/**
 *
 */
function biblio_rtf_node_view($node, $view_mode) {
  if ($node->type == 'biblio') {
    switch ($view_mode) {
      case 'full':
      case 'teaser':
        $links = biblio_rtf_biblio_export_link($node->nid);
        $node->content['links']['biblio_rtf'] = array(
          '#links' => $links,
          '#attributes' => array(
            'class' => array(
              'links',
              'inline',
            ),
          ),
        );
    }
  }
}

/**
 *
 */
function biblio_rtf_link($type, $node = NULL, $teaser = FALSE) {
  if ($type != 'node' && $node->type != 'biblio') {
    return;
  }
  return biblio_rtf_biblio_export_link($node->nid);
}

/**
 * Creates a link to export a node (or view) in rtf format.
 *
 * @param $base
 *   this is the base url (defaults to /biblio)
 * @param $nid
 *   the node id, if NULL then the current view is exported
 *
 * @return a link (<a href=...>rtf</a>)
 */
function biblio_rtf_biblio_export_link($nid = NULL, $filter = array()) {
  $show_link = variable_get('biblio_export_links', array(
    'rtf' => TRUE,
  ));
  if (!isset($show_link['rtf']) || empty($show_link['rtf']) || !biblio_access('export')) {
    return array();
  }
  $base = variable_get('biblio_base', 'biblio');
  $link = array(
    'attributes' => array(
      'title' => t("Click to download the RTF formatted file"),
      'rel' => 'nofollow',
    ),
  );
  $link['href'] = !empty($nid) ? "{$base}/export/rtf/{$nid}" : "{$base}/export/rtf";
  $link['title'] = t('RTF');

  // Add any filters which may be on the current page.
  if (empty($nid) && !empty($filter)) {
    $link['query'] = $filter;
  }
  return array(
    'biblio_rtf' => $link,
  );
}

/**
 *
 */
function biblio_rtf_biblio_export($nids) {
  $count = 0;
  $variables = array(
    'style_name' => biblio_get_style(),
  );
  $nodes = node_load_multiple($nids, array(), TRUE);
  foreach ($nodes as $node) {
    if (variable_get('biblio_hide_bibtex_braces', 0)) {
      $node->title = biblio_remove_brace($node->title);
    }
    $count++;
    $variables['node'] = $node;
    if ($count == 1) {
      $rtf = new rtf();
      $rtf
        ->setPaperSize(5);
      $rtf
        ->setPaperOrientation(1);
      $rtf
        ->setDefaultFontFace(1);
      $rtf
        ->setDefaultFontSize(24);
      $rtf
        ->setAuthor("Biblio 7.x");
      $rtf
        ->setOperator("");
      $rtf
        ->setTitle("Biblio RTF Export");
      $rtf
        ->addColour("#000000");
    }
    $rtf
      ->addText(filter_xss(theme('biblio_style', $variables) . '<br><br>', array(
      'i',
      'b',
      'br',
      'u',
      'p',
      'strong',
      'em',
      'sub',
      'sup',
      'ul',
      'li',
    )));
  }
  if ($count > 0) {
    $rtf
      ->getDocument();
  }
}