| 1 |
<?php |
<?php |
| 2 |
// $Id: drutex_pdf.inc,v 1.17 2006/09/06 04:58:51 dfg Exp $ |
// $Id: drutex_pdf.inc,v 1.18 2007/04/25 14:46:28 darthsteven Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 15 |
return (object) array( |
return (object) array( |
| 16 |
'title' => t('PDF Generator'), |
'title' => t('PDF Generator'), |
| 17 |
'description' => t('Allows to generate pdf-versions of a node (with decent html2latex features).'), |
'description' => t('Allows to generate pdf-versions of a node (with decent html2latex features).'), |
| 18 |
'toggle' => true, |
'toggle' => TRUE, |
| 19 |
'weight' => 6 |
'weight' => 6 |
| 20 |
); |
); |
| 21 |
} |
} |
| 22 |
|
|
| 23 |
/** |
/** |
| 24 |
|
* Implementation of subhook_filter_tips(). |
| 25 |
|
*/ |
| 26 |
|
function drutex_pdf_filter_tips($delta, $format, $long = FALSE) { |
| 27 |
|
if (user_access('access pdf files')) { |
| 28 |
|
return t('Visit drutex/pdf/nid to generate pdf-versions of this node.'); |
| 29 |
|
} |
| 30 |
|
} |
| 31 |
|
|
| 32 |
|
/** |
| 33 |
|
* Implementation of subhook_link(). |
| 34 |
|
*/ |
| 35 |
|
function drutex_pdf_link($type, $node = NULL, $teaser = FALSE) { |
| 36 |
|
if (user_access('access pdf files')) { |
| 37 |
|
$pdf_link = 'drutex/pdf/'. $node->nid; |
| 38 |
|
$text = t('Generate PDF file'); |
| 39 |
|
$links['drutex_pdf_link'] = array( |
| 40 |
|
'title' => $text, |
| 41 |
|
'href' => $pdf_link, |
| 42 |
|
); |
| 43 |
|
return $links; |
| 44 |
|
} |
| 45 |
|
} |
| 46 |
|
|
| 47 |
|
/** |
| 48 |
* Implementation of subhook_defaults(). |
* Implementation of subhook_defaults(). |
| 49 |
*/ |
*/ |
| 50 |
function drutex_pdf_defaults() { |
function drutex_pdf_defaults() { |
| 51 |
$D['drutex_pdf_active'] = true; |
$D['drutex_pdf_active'] = TRUE; |
| 52 |
|
|
| 53 |
/* relative to drutex/templates/pdf */ |
/* relative to drutex/templates/pdf */ |
| 54 |
$D['drutex_template_pdf'] = 'plain.tex'; |
$D['drutex_template_pdf'] = 'plain.tex'; |
| 108 |
function drutex_node2pdf_wrapper($nid) { |
function drutex_node2pdf_wrapper($nid) { |
| 109 |
$node = node_load($nid); |
$node = node_load($nid); |
| 110 |
$pdf_dir = drutex_var_get("drutex_dir_images_{$node->format}"); |
$pdf_dir = drutex_var_get("drutex_dir_images_{$node->format}"); |
| 111 |
|
$pdf_file = $pdf_dir .'/'. $node->nid .'.pdf'; |
| 112 |
if (!is_file("$pdf_dir/{$node->nid}.pdf")) { |
if (!is_file($pdf_file)) { |
| 113 |
drutex_node2pdf($nid); |
drutex_node2pdf($nid); |
| 114 |
} |
} |
| 115 |
|
drupal_goto($pdf_file); |
|
drupal_goto("$pdf_dir/{$node->nid}.pdf"); |
|
| 116 |
} |
} |
| 117 |
|
|
| 118 |
/** |
/** |
| 128 |
$node = node_load($nid); |
$node = node_load($nid); |
| 129 |
|
|
| 130 |
drutex_node2latex($nid); |
drutex_node2latex($nid); |
|
|
|
| 131 |
$image_dir = drutex_var_get("drutex_dir_images_{$node->format}"); |
$image_dir = drutex_var_get("drutex_dir_images_{$node->format}"); |
| 132 |
|
|
| 133 |
/* create temporary dir */ |
/* create temporary dir */ |
| 134 |
$temporary_dir = _drutex_create_temporary_dir(); |
$temporary_dir = _drutex_create_temporary_dir(); |
| 135 |
|
$file = $node->nid .'.tex'; |
| 136 |
copy("$image_dir/{$node->nid}.tex", "$temporary_dir/{$node->nid}.tex"); |
$temporary_file = $temporary_dir .'/'. $file; |
| 137 |
_drutex_copy_dir("modules/drutex/templates/pdf", $temporary_dir); |
$source_file = $image_dir .'/'. $file; |
| 138 |
|
file_copy($source_file, $temporary_file); |
| 139 |
|
$pdf_template_path = drupal_get_path('module', 'drutex') .'/templates/pdf'; |
| 140 |
|
_drutex_copy_dir($pdf_template_path, $temporary_dir); |
| 141 |
|
|
| 142 |
/* |
/* |
| 143 |
* Prepare and execute the conversion commands |
* Prepare and execute the conversion commands |
| 144 |
*/ |
*/ |
|
|
|
| 145 |
$pattern_convert = drutex_var_get("drutex_pattern_pdflatex_{$node->format}"); |
$pattern_convert = drutex_var_get("drutex_pattern_pdflatex_{$node->format}"); |
| 146 |
|
|
| 147 |
/* replacement array */ |
/* replacement array */ |
| 164 |
|
|
| 165 |
if (drutex_var_get("drutex_debug_$format")) { |
if (drutex_var_get("drutex_debug_$format")) { |
| 166 |
$level = ($cmd_retval == 0) ? WATCHDOG_NOTICE : WATCHDOG_WARNING; |
$level = ($cmd_retval == 0) ? WATCHDOG_NOTICE : WATCHDOG_WARNING; |
| 167 |
watchdog('DruTeX', "Command: $cmd<br />Return value: $cmd_retval", $level); |
watchdog('DruTeX', "Command: %cmd<br />Return value: %cmdret", array('%cmd' => $cmd, '%cmdret' => $cmd_retval), $level); |
| 168 |
} |
} |
| 169 |
} |
} |
| 170 |
} |
} |
| 174 |
_drutex_delete_dir($temporary_dir); |
_drutex_delete_dir($temporary_dir); |
| 175 |
} |
} |
| 176 |
else { |
else { |
| 177 |
watchdog('DruTeX', "Temporary directory for pdf-generation was $temporary_dir.", WATCHDOG_NOTICE); |
watchdog('DruTeX', "Temporary directory for pdf-generation was %tdir.", array('%tdir' => $temporary_dir), WATCHDOG_NOTICE); |
| 178 |
} |
} |
| 179 |
} |
} |
| 180 |
|
|
| 189 |
function drutex_node2latex_wrapper($nid) { |
function drutex_node2latex_wrapper($nid) { |
| 190 |
$node = node_load($nid); |
$node = node_load($nid); |
| 191 |
$pdf_dir = drutex_var_get("drutex_dir_images_{$node->format}"); |
$pdf_dir = drutex_var_get("drutex_dir_images_{$node->format}"); |
| 192 |
|
$tex_file = $pdf_dir .'/'. $node->nid .'.tex'; |
| 193 |
if (!is_file("$pdf_dir/{$node->nid}.tex")) { |
if (!is_file($tex_file)) { |
| 194 |
drutex_node2latex($nid); |
drutex_node2latex($nid); |
| 195 |
} |
} |
| 196 |
|
|
| 197 |
drupal_goto("$pdf_dir/{$node->nid}.tex"); |
drupal_goto($tex_file); |
| 198 |
} |
} |
| 199 |
|
|
| 200 |
/** |
/** |
| 221 |
|
|
| 222 |
/* convert html elements in the node's content to latex */ |
/* convert html elements in the node's content to latex */ |
| 223 |
$content = drutex_html2latex($node); |
$content = drutex_html2latex($node); |
| 224 |
|
// print $content; |
| 225 |
/* replace the template keys by the actual values */ |
/* replace the template keys by the actual values */ |
| 226 |
$map = array( |
$map = array( |
| 227 |
'DRUTEX_NODE_TITLE' => $node->title, |
'DRUTEX_NODE_TITLE' => $node->title, |
| 228 |
'DRUTEX_NODE_URL' => url('node/'. $node->nid, null, null, true), |
'DRUTEX_NODE_URL' => url("node/$node->nid", array('absolute' => TRUE)), |
| 229 |
'DRUTEX_DIR' => drutex_var_get('drutex_dir'), |
'DRUTEX_DIR' => drutex_var_get('drutex_dir'), |
| 230 |
'DRUTEX_NODE_BODY' => $content |
'DRUTEX_NODE_BODY' => $content |
| 231 |
); |
); |
| 247 |
*/ |
*/ |
| 248 |
function drutex_html2latex(&$node) { |
function drutex_html2latex(&$node) { |
| 249 |
if (drutex_submodule_is_active('security', $node->format)) { |
if (drutex_submodule_is_active('security', $node->format)) { |
| 250 |
if (drutex_security($node->body, $format) == false) { |
if (drutex_security($node->body, $format) == FALSE) { |
| 251 |
return 'Unallowed command detected!'; |
return 'Unallowed command detected!'; |
| 252 |
} |
} |
| 253 |
} |
} |
| 256 |
|
|
| 257 |
/* include the rules file */ |
/* include the rules file */ |
| 258 |
$drutex_path = drupal_get_path('module', 'drutex'); |
$drutex_path = drupal_get_path('module', 'drutex'); |
| 259 |
include_once("$drutex_path/drutex_pdf.rules"); |
require_once("$drutex_path/drutex_pdf.rules"); |
| 260 |
|
|
| 261 |
/* get entities */ |
/* get entities */ |
| 262 |
$A = drutex_submodule_invoke_all('drutex2latex', $node, "format=$format"); |
$A = drutex_submodule_invoke_all('drutex2latex', $node, "format=$format"); |
| 273 |
return $text; |
return $text; |
| 274 |
} |
} |
| 275 |
|
|
| 276 |
|
|
| 277 |
/** |
/** |
| 278 |
* Implementation of hook_nodeapi(). |
* Implementation of hook_nodeapi(). |
| 279 |
*/ |
*/ |
| 280 |
function drutex_pdf_nodeapi(&$node, $op, $arg) { |
function drutex_pdf_nodeapi(&$node, $op, $teaser = FALSE, $page = FALSE) { |
| 281 |
if (true) { |
if (TRUE) { |
| 282 |
switch ($op) { |
switch ($op) { |
|
case 'validate': |
|
|
break; |
|
|
|
|
| 283 |
case 'load': |
case 'load': |
| 284 |
break; |
break; |
| 285 |
|
case 'view': |
| 286 |
|
break; |
| 287 |
|
case 'validate': |
| 288 |
|
break; |
| 289 |
case 'insert': |
case 'insert': |
| 290 |
break; |
break; |
|
|
|
| 291 |
case 'update': |
case 'update': |
| 292 |
case 'delete': |
case 'delete': |
| 293 |
$pdf_dir = drutex_var_get("drutex_dir_images_{$node->format}"); |
$pdf_dir = drutex_var_get("drutex_dir_images_{$node->format}"); |
| 294 |
|
$pdf_file = $pdf_dir .'/'. $node->nid .'.pdf'; |
| 295 |
if (is_file("$pdf_dir/{$node->nid}.pdf")) { |
$tex_file = $pdf_dir .'/'. $node->nid .'.tex'; |
| 296 |
unlink("$pdf_dir/{$node->nid}.pdf"); |
file_delete($pdf_file); |
| 297 |
} |
file_delete($tex_file); |
|
|
|
|
if (is_file("$pdf_dir/{$node->nid}.tex")) { |
|
|
unlink("$pdf_dir/{$node->nid}.tex"); |
|
|
} |
|
|
|
|
| 298 |
break; |
break; |
| 299 |
} |
} |
| 300 |
} |
} |