array( 'name' => t('PDFview: Output PDF-file'), 'theme' => 'pdfview_views_pdf_output', 'needs_table_header' => TRUE, 'needs_fields' => TRUE, 'even_empty' => TRUE, ), ); } /** * While we support the global selector, some might want to allow * ONLY RSS feeds so we support a stingy selector too */ function pdfview_views_views_arguments() { $arguments = array( 'pdf_output' => array( 'name' => t('PDFview: PDF output Selector'), 'handler' => 'views_handler_arg_pdf_output', 'help' => t('This argument specifies a specific PDF output selector.'), ), ); return $arguments; } /** * handler for our own RSS argument; mimics the feed selector */ function views_handler_arg_pdf_output($op, &$query, $argtype, $arg = '') { switch($op) { case 'summary': case 'sort': case 'link': case 'title': break; case 'filter': // This is a clone of the default selector, but it just invokes ours // rather than calling all of them. pdfview_views_pdf_output_argument('argument', $GLOBALS['current_view'], $arg); } } /** * post view for our own op -- mimics the feed selector */ function pdfview_views_views_post_view($view, $items, $output) { foreach ($view->argument as $id => $argument) { if ($argument['type'] == 'pdf_output') { $feed = $id; break; } } if ($feed !== NULL) { return pdfview_views_pdf_output_argument('post_view', $view, 'pdf_output'); } } /** * feed argument hook that will convert us to RSS or display an icon. * the 4th argument isn't part of the hook, but we use it to differentiate * when called as a hook or when called manually from pdfview_views_views_post_view */ function pdfview_views_pdf_output_argument($op, &$view, $arg) { if ($op == 'argument' && $arg == 'pdf') { $view->page_type = 'pdfview_views'; } else if ($op == 'post_view') { $args = views_post_view_make_args($view, $arg, 'pdf'); $url = views_get_url($view, $args); $title = views_get_title($view, 'page', $args); if ($view->used_filters) { $filters = drupal_query_string_encode($view->used_filters); } // drupal_add_feed(url($url, $filters), $title); return theme('pdf_icon', url($url, $filters), $title); } } /** * plugin that actually outputs a pdf file */ function theme_pdfview_views_pdf_output($view, $nodes, $type) { if ($type == 'block') { return; } global $base_url; $path = drupal_get_path('module', 'pdfview'); require_once($path . '/tcpdf/tcpdf.php'); require_once($path . '/tcpdf/config/tcpdf_config.php'); $pdf = theme('pdfview_pdf'); $pdf->SetTitle(check_plain(views_get_title($view, 'page'))); // Except for the original being a while and this being a foreach, this is // completely cut & pasted from node.module. foreach ($nodes as $node) { // Load the specified node: $item = node_load($node->nid); $link = url("node/$node->nid", NULL, NULL, 1); // Filter and prepare node teaser if (node_hook($item, 'view')) { node_invoke($item, 'view', FALSE, FALSE); } else { $item = node_prepare($item, FALSE); } // Allow modules to change $node->teaser before viewing. node_invoke_nodeapi($item, 'view', FALSE, FALSE); $item_text = $item->body; $pdf = theme('pdfview_node', $pdf, $item); } pdfview_generate_file($pdf, check_plain(views_get_title($view, 'page'))); module_invoke_all('exit'); exit; } function theme_pdf_icon ($url, $title = NULL) { if ($title === NULL) { $title = t('Output as PDF'); } $title = check_plain($title); $path = drupal_get_path('module', 'pdfview'); if ($image = theme('image', $path .'/pdf.gif', $title, $title)) { return ''. $image. ''; } }