| 1 |
<?php |
<?php |
| 2 |
// $Id: drutex.module,v 1.22 2007/09/09 18:57:38 darthsteven Exp $ |
// $Id: drutex.module,v 1.20.2.3 2008/01/16 01:06:00 darthsteven Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 7 |
*/ |
*/ |
| 8 |
|
|
| 9 |
/** |
/** |
| 10 |
|
* Implementation of hook_link(). |
| 11 |
|
*/ |
| 12 |
|
|
| 13 |
|
function drutex_link($type, $node = NULL, $teaser = FALSE) { |
| 14 |
|
$links = array(); |
| 15 |
|
if ($type == 'node') { |
| 16 |
|
$format = $node->format; |
| 17 |
|
foreach (drutex_submodule_list($format) as $submodule) { |
| 18 |
|
if (drutex_submodule_is_active($submodule, $format)) { |
| 19 |
|
$linkfunction = 'drutex_'. $submodule .'_link'; |
| 20 |
|
if (function_exists($linkfunction)) { |
| 21 |
|
$result = $linkfunction($type, $node, $teaser); |
| 22 |
|
if (isset($result) && is_array($result)) { |
| 23 |
|
$links = array_merge($links, $result); |
| 24 |
|
} |
| 25 |
|
elseif (isset($result)) { |
| 26 |
|
$links[] = $result; |
| 27 |
|
} |
| 28 |
|
} |
| 29 |
|
} |
| 30 |
|
} |
| 31 |
|
} |
| 32 |
|
return $links; |
| 33 |
|
} |
| 34 |
|
|
| 35 |
|
/** |
| 36 |
|
* Implementation of hook_help(). |
| 37 |
|
*/ |
| 38 |
|
function drutex_help($path, $arg) { |
| 39 |
|
switch ($path) { |
| 40 |
|
case 'admin/modules#description': |
| 41 |
|
return t('Allows users to render LaTeX/TeX in many different ways.'); |
| 42 |
|
} |
| 43 |
|
} |
| 44 |
|
|
| 45 |
|
/** |
| 46 |
|
* Implementation of hook_filter_tips(). |
| 47 |
|
*/ |
| 48 |
|
function drutex_filter_tips($delta, $format, $long) { |
| 49 |
|
$output = ''; |
| 50 |
|
$output .= t('LaTex commands embedded in text will be interpreted and rendered. Additional information can be found at <a href ="http://groups.drupal.org/node/1263"> DruTex Documentation Pages </a>'); |
| 51 |
|
$output .= '<ul>'; |
| 52 |
|
foreach (drutex_submodule_list($format) as $submodule) { |
| 53 |
|
if (drutex_submodule_is_active($submodule, $format)) { |
| 54 |
|
$helpfunction = 'drutex_'. $submodule .'_filter_tips'; |
| 55 |
|
if (function_exists($helpfunction)) { |
| 56 |
|
$res = $helpfunction($delta, $format, $long); |
| 57 |
|
if ($res != '') { |
| 58 |
|
$output .= '<li>'. $res .'</li>'; |
| 59 |
|
} |
| 60 |
|
} |
| 61 |
|
} |
| 62 |
|
} |
| 63 |
|
$ouptut .= '</ul>'; |
| 64 |
|
return $output; |
| 65 |
|
} |
| 66 |
|
|
| 67 |
|
/** |
| 68 |
* Implementation of hook_filter(). |
* Implementation of hook_filter(). |
| 69 |
*/ |
*/ |
| 70 |
function drutex_filter($op, $delta = 0, $format = -1, $text = '') { |
function drutex_filter($op, $delta = 0, $format = -1, $text = '') { |
| 75 |
case 'description': |
case 'description': |
| 76 |
return t('Allows users to render LaTeX/TeX in many different ways.'); |
return t('Allows users to render LaTeX/TeX in many different ways.'); |
| 77 |
|
|
| 78 |
case "process": |
case 'process': |
| 79 |
return drutex_node2html($text, $format); |
return drutex_node2html($text, $format); |
| 80 |
|
|
| 81 |
case 'settings': |
case 'settings': |
| 89 |
/** |
/** |
| 90 |
* Implementation of hook_menu(). |
* Implementation of hook_menu(). |
| 91 |
*/ |
*/ |
| 92 |
function drutex_menu($may_cache) { |
function drutex_menu() { |
| 93 |
$items = array(); |
$items = array(); |
| 94 |
|
if (drutex_submodule_is_active('remote')) { |
| 95 |
if ($may_cache) { |
$items['drutex/remote'] = array( |
| 96 |
if (drutex_submodule_is_active('remote')) { |
'title' => 'Drutex Remote Rendering', |
| 97 |
$items[] = array( |
'file' => 'drutex_remote.inc', |
| 98 |
'path' => 'drutex/remote', |
'page callback' => 'drutex_remote_do_render', |
| 99 |
'title' => 'Drutex Remote Rendering', |
'access callback' => 'user_access', |
| 100 |
'access'=> TRUE, |
'access arguments' => array('access content'), |
| 101 |
'callback' => 'drutex_remote_do_render', |
'type' => MENU_CALLBACK, |
| 102 |
'type' => MENU_CALLBACK, |
); |
| 103 |
); |
|
| 104 |
|
$items['admin/settings/drutex'] = array( |
| 105 |
$items[] = array( |
'title' => 'DruTeX Settings', |
| 106 |
'path' => 'admin/settings/drutex/remote', |
'description' => 'Adjusts the settings for the remote LaTeX rendering interface', |
| 107 |
'title' => 'DruTeX Settings', |
'file' => 'drutex_remote.inc', |
| 108 |
'description' => 'Adjusts the settings for the remote LaTeX rendering interface', |
'page callback' => 'drupal_get_form', |
| 109 |
'callback' => 'drupal_get_form', |
'page arguments' => array('drutex_remote_admin_settings'), |
| 110 |
'access' => user_access('administer site configuration'), |
'access callback' => 'user_access', |
| 111 |
'callback arguments' => array('drutex_remote_settings'), |
'access arguments' => array('administer site configuration'), |
| 112 |
); |
'type' => MENU_NORMAL_ITEM, |
| 113 |
} |
); |
| 114 |
|
} |
| 115 |
|
if (drutex_submodule_is_active('pdf')) { |
| 116 |
|
$items['drutex/pdf'] = array( |
| 117 |
|
'title' => 'node2pdf', |
| 118 |
|
'file' => 'drutex_pdf.inc', |
| 119 |
|
'page callback' => 'drutex_node2pdf_wrapper', |
| 120 |
|
'page arguments' => array(2), |
| 121 |
|
'access callback' => 'user_access', |
| 122 |
|
'access arguments' => array('access pdf files'), |
| 123 |
|
'type' => MENU_CALLBACK, |
| 124 |
|
); |
| 125 |
|
|
| 126 |
|
$items['drutex/latex'] = array( |
| 127 |
|
'title' => 'node2latex', |
| 128 |
|
'file' => 'drutex_pdf.inc', |
| 129 |
|
'page callback' => 'drutex_node2latex_wrapper', |
| 130 |
|
'page arguments' => array(2), |
| 131 |
|
'access callback' => 'user_access', |
| 132 |
|
'access arguments' => array('access latex source'), |
| 133 |
|
'type' => MENU_CALLBACK, |
| 134 |
|
); |
| 135 |
} |
} |
|
else { |
|
|
if (drutex_submodule_is_active('pdf')) { |
|
|
$items[] = array( |
|
|
'path' => 'drutex/pdf', |
|
|
'title' => t('node2pdf'), |
|
|
'callback' => 'drutex_node2pdf_wrapper', |
|
|
'access' => user_access('access pdf files'), |
|
|
'type' => MENU_CALLBACK); |
|
|
|
|
|
$items[] = array( |
|
|
'path' => 'drutex/latex', |
|
|
'title' => t('node2latex'), |
|
|
'callback' => 'drutex_node2latex_wrapper', |
|
|
'access' => user_access('access latex source'), |
|
|
'type' => MENU_CALLBACK); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
| 136 |
|
|
| 137 |
drutex_set_stylesheet(); |
drutex_set_stylesheet(); |
| 138 |
|
|
| 236 |
*/ |
*/ |
| 237 |
|
|
| 238 |
$image_dir = drutex_var_get("drutex_dir_images_$format"); |
$image_dir = drutex_var_get("drutex_dir_images_$format"); |
| 239 |
|
file_check_directory($image_dir, FILE_CREATE_DIRECTORY); |
|
if (!is_writable($image_dir)) { |
|
|
if (file_exists($image_dir)) { |
|
|
chmod($image_dir, 0777); |
|
|
} |
|
|
else { |
|
|
mkdir($image_dir); |
|
|
} |
|
|
} |
|
| 240 |
|
|
| 241 |
/* global settings |
/* global settings |
| 242 |
that means: settings all submodules can share |
that means: settings all submodules can share |
| 343 |
*/ |
*/ |
| 344 |
function drutex_node2html($text, $format = -1) { |
function drutex_node2html($text, $format = -1) { |
| 345 |
/* preprocess */ |
/* preprocess */ |
| 346 |
|
|
| 347 |
foreach (drutex_submodule_implements('node2html_preprocess', $format) as $submodule) { |
foreach (drutex_submodule_implements('node2html_preprocess', $format) as $submodule) { |
| 348 |
$text = drutex_submodule_invoke($submodule, 'node2html_preprocess', $text, $format); |
$text = drutex_submodule_invoke($submodule, 'node2html_preprocess', $text, $format); |
| 349 |
} |
} |
| 380 |
$b->weight = 1000; |
$b->weight = 1000; |
| 381 |
} |
} |
| 382 |
if ($a->weight == $b->weight) { |
if ($a->weight == $b->weight) { |
| 383 |
return 0; |
return 0; |
| 384 |
} |
} |
| 385 |
return ($a->weight < $b->weight) ? -1 : 1; |
return ($a->weight < $b->weight) ? -1 : 1; |
| 386 |
} |
} |
| 454 |
function drutex_merge_attributes($A) { |
function drutex_merge_attributes($A) { |
| 455 |
$str = ''; |
$str = ''; |
| 456 |
foreach ($A as $key => $val) { |
foreach ($A as $key => $val) { |
| 457 |
$str .= strtolower($key) . "=\"$val\" "; |
$str .= strtolower($key) ."=\"$val\" "; |
| 458 |
} |
} |
| 459 |
return trim($str); |
return trim($str); |
| 460 |
} |
} |
| 491 |
|
|
| 492 |
if ($cmd == 'set') { |
if ($cmd == 'set') { |
| 493 |
$hidden[$count] = _drutex_unescape($subject); |
$hidden[$count] = _drutex_unescape($subject); |
| 494 |
return _drutex_secret() . ':' . $count++ . ':'; |
return _drutex_secret() .':'. $count++ .':'; |
| 495 |
} |
} |
| 496 |
else if ($cmd == 'get') { |
elseif ($cmd == 'get') { |
| 497 |
$subject = (int)$subject; |
$subject = (int)$subject; |
| 498 |
return $hidden[$subject]; |
return $hidden[$subject]; |
| 499 |
} |
} |
| 560 |
*/ |
*/ |
| 561 |
function _drutex_create_temporary_dir($format = -1) { |
function _drutex_create_temporary_dir($format = -1) { |
| 562 |
static $n = 1; |
static $n = 1; |
| 563 |
$dir = drutex_var_get("drutex_dir_temporary_$format") . '/drutex-' . _drutex_secret() . '-' . $n++; |
$dir = drutex_var_get("drutex_dir_temporary_$format") .'/drutex-'. _drutex_secret() .'-'. $n++; |
| 564 |
mkdir($dir); |
file_check_directory($dir, FILE_CREATE_DIRECTORY); |
| 565 |
return $dir; |
return $dir; |
| 566 |
} |
} |
| 567 |
|
|
| 574 |
if ($handle = opendir($dir)) { |
if ($handle = opendir($dir)) { |
| 575 |
while ($item = readdir($handle)) { |
while ($item = readdir($handle)) { |
| 576 |
if ($item != '.' && $item != '..') { |
if ($item != '.' && $item != '..') { |
| 577 |
unlink("$dir/$item"); |
$file = $dir .'/'. $item; |
| 578 |
|
file_delete($file); |
| 579 |
} |
} |
| 580 |
} |
} |
| 581 |
closedir($handle); |
closedir($handle); |
| 590 |
if ($handle = opendir($source)) { |
if ($handle = opendir($source)) { |
| 591 |
while ($item = readdir($handle)) { |
while ($item = readdir($handle)) { |
| 592 |
if ($item != '.' && $item != '..') { |
if ($item != '.' && $item != '..') { |
| 593 |
if(is_file("$source/$item")) { |
$sourcefile = $source .'/'. $item; |
| 594 |
copy("$source/$item", "$dest/$item"); |
$destfile = $dest .'/'. $item; |
| 595 |
} |
file_copy($sourcefile, $destfile); |
| 596 |
} |
} |
| 597 |
} |
} |
| 598 |
closedir($handle); |
closedir($handle); |
| 602 |
/** |
/** |
| 603 |
* Get URL where the images are saved. |
* Get URL where the images are saved. |
| 604 |
*/ |
*/ |
| 605 |
|
|
| 606 |
function drutex_get_image_url($format = -1) { |
function drutex_get_image_url($format = -1) { |
| 607 |
$path = drutex_var_get("drutex_url_images_$format"); |
$path = drutex_var_get("drutex_url_images_$format"); |
| 608 |
|
|
| 615 |
} |
} |
| 616 |
} |
} |
| 617 |
|
|
| 618 |
|
|
| 619 |
/** |
/** |
| 620 |
* Implementation of hook_nodeapi(). |
* Implementation of hook_nodeapi(). |
| 621 |
* |
* |
| 622 |
* Notify all submodules when a node changed. |
* Notify all submodules when a node changed. |
| 623 |
*/ |
*/ |
| 624 |
function drutex_nodeapi(&$node, $op, $arg) { |
function drutex_nodeapi(&$node, $op, $teaser = FALSE, $page = FALSE) { |
| 625 |
drutex_submodule_invoke_all('nodeapi', $node, $op, $arg, "format={$node->format}"); |
drutex_submodule_invoke_all('nodeapi', $node, $op, $teaser, $page, "format={$node->format}"); |
| 626 |
} |
} |
| 627 |
|
|
| 628 |
/** |
/** |
| 646 |
* marked active in the specified input format. |
* marked active in the specified input format. |
| 647 |
*/ |
*/ |
| 648 |
function drutex_submodule_is_active($submodule, $format = -1) { |
function drutex_submodule_is_active($submodule, $format = -1) { |
| 649 |
if (is_file(drupal_get_path('module', 'drutex') . "/drutex_{$submodule}.inc")) { |
if (is_file(drupal_get_path('module', 'drutex') ."/drutex_{$submodule}.inc")) { |
| 650 |
if ($format == -1) { |
if ($format == -1) { |
| 651 |
return true; |
return TRUE; |
| 652 |
} |
} |
| 653 |
else if (_format_uses_drutex($format) && drutex_var_get("drutex_{$submodule}_active_{$format}")) { |
else if (_format_uses_drutex($format) && drutex_var_get("drutex_{$submodule}_active_{$format}")) { |
| 654 |
return true; |
return TRUE; |
| 655 |
} |
} |
| 656 |
} |
} |
| 657 |
|
|
| 658 |
return false; |
return FALSE; |
| 659 |
} |
} |
| 660 |
|
|
| 661 |
/** |
/** |
| 671 |
$result = db_query("SELECT format from {filters} WHERE module = 'drutex'"); |
$result = db_query("SELECT format from {filters} WHERE module = 'drutex'"); |
| 672 |
|
|
| 673 |
while ($obj = db_fetch_object($result)) { |
while ($obj = db_fetch_object($result)) { |
| 674 |
$cache[$obj->format] = true; |
$cache[$obj->format] = TRUE; |
| 675 |
} |
} |
| 676 |
|
|
| 677 |
/* the format -1 always 'uses' DruTeX */ |
/* the format -1 always 'uses' DruTeX */ |
| 678 |
$cache[-1] = true; |
$cache[-1] = TRUE; |
| 679 |
} |
} |
| 680 |
|
|
| 681 |
return isset($cache[$format]); |
return isset($cache[$format]); |
| 820 |
$hook = array_shift($args); |
$hook = array_shift($args); |
| 821 |
$return = array(); |
$return = array(); |
| 822 |
$format = _drutex_rewrite_format_call($args); |
$format = _drutex_rewrite_format_call($args); |
|
|
|
| 823 |
foreach (drutex_submodule_implements($hook, $format) as $submodule) { |
foreach (drutex_submodule_implements($hook, $format) as $submodule) { |
| 824 |
$result = call_user_func_array("drutex_{$submodule}_{$hook}", $args); |
$result = call_user_func_array("drutex_{$submodule}_{$hook}", $args); |
| 825 |
if (isset($result) && is_array($result)) { |
if (isset($result) && is_array($result)) { |
| 849 |
|
|
| 850 |
$path = drupal_get_path('module', 'drutex'); |
$path = drupal_get_path('module', 'drutex'); |
| 851 |
|
|
|
|
|
| 852 |
/* load the submodules */ |
/* load the submodules */ |
| 853 |
foreach (drutex_submodule_list() as $submodule) { |
foreach (drutex_submodule_list() as $submodule) { |
| 854 |
include_once("{$path}/drutex_{$submodule}.inc"); |
include_once("{$path}/drutex_{$submodule}.inc"); |