/[drupal]/contributions/modules/drutex/drutex_render.inc
ViewVC logotype

Diff of /contributions/modules/drutex/drutex_render.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.22, Wed Apr 25 23:23:49 2007 UTC revision 1.22.4.1, Mon Nov 17 09:05:37 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: drutex_render.inc,v 1.21 2007/04/25 14:46:28 darthsteven Exp $  // $Id: drutex_render.inc,v 1.21.2.3 2008/03/31 08:34:17 darthsteven Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 13  function drutex_render_info($format = -1 Line 13  function drutex_render_info($format = -1
13    return (object) array(    return (object) array(
14      'title' => t('LaTeX Renderer'),      'title' => t('LaTeX Renderer'),
15      'description' => t('Provides different environments to create rendered images (especially maths).'),      'description' => t('Provides different environments to create rendered images (especially maths).'),
16      'toggle' => true,      'toggle' => TRUE,
17      'weight' => 0      'weight' => 0
18    );    );
19  }  }
20    
21  /**  /**
22     * Implementation of subhook_filter_tips().
23     */
24    
25    function drutex_render_filter_tips($delta, $format, $long = FALSE) {
26      return t('Provides different environments to create rendered images (especially maths).');
27    }
28    
29    /**
30   * Implementation of subhook_defaults().   * Implementation of subhook_defaults().
31   */   */
32  function drutex_render_defaults() {  function drutex_render_defaults() {
33    $D['drutex_render_active'] = true;    $D['drutex_render_active'] = TRUE;
34    
35    /* relative to drutex/templates/render */    /* relative to drutex/templates/render */
36    $D['drutex_template_render'] = 'default.tex';    $D['drutex_template_render'] = 'default.tex';
37    
38    $D['drutex_pattern_render_dvipng']       = 'cd [TMP_DIR]; TEXINPUTS="[DRUTEX_DIR]//:" latex -interaction=batchmode [HASH].tex'."\n".    $D['drutex_pattern_render_dvipng']           = 'cd [TMP_DIR]; TEXINPUTS="[DRUTEX_DIR]//:" latex -interaction=batchmode [HASH].tex'."\n".
39                                        'dvipng -o [IMG_FILE] -D [DPI] -T tight [TMP_DIR]/[HASH].dvi';                                        'dvipng -o [IMG_FILE] -D [DPI] -T tight [TMP_DIR]/[HASH].dvi';
40    
41    $D['drutex_pattern_render_imagemagick']  = 'cd [TMP_DIR]; TEXINPUTS="[DRUTEX_DIR]//:" latex -interaction=batchmode [HASH].tex'."\n".    $D['drutex_pattern_render_imagemagick']      = 'cd [TMP_DIR]; TEXINPUTS="[DRUTEX_DIR]//:" latex -interaction=batchmode [HASH].tex'."\n".
42                                          'convert -density [DPI] -trim [TMP_DIR]/[HASH].dvi [IMG_FILE]';
43    
44      $D['drutex_pattern_render_dvipng_trans']      = 'cd [TMP_DIR]; TEXINPUTS="[DRUTEX_DIR]//:" latex -interaction=batchmode [HASH].tex'."\n".
45                                          'dvipng -o [IMG_FILE] -D [DPI] -T tight -bg Transparent [TMP_DIR]/[HASH].dvi';
46    
47      $D['drutex_pattern_render_imagemagick_trans'] = 'cd [TMP_DIR]; TEXINPUTS="[DRUTEX_DIR]//:" latex -interaction=batchmode [HASH].tex'."\n".
48                                          'convert -density [DPI] -trim -transparent "#FFFFFF" -antialias +repage [TMP_DIR]/[HASH].dvi [IMG_FILE]';
49    
50      $D['drutex_pattern_render_dvipng_win32']      = 'cd [TMP_DIR] & latex -interaction=batchmode [HASH].tex'."\n".
51                                          'dvipng -o [IMG_FILE] -D [DPI] -T tight [TMP_DIR]/[HASH].dvi';
52    
53      $D['drutex_pattern_render_imagemagick_win32'] = 'cd [TMP_DIR] & latex -interaction=batchmode [HASH].tex'."\n".
54                                        'convert -density [DPI] -trim [TMP_DIR]/[HASH].dvi [IMG_FILE]';                                        'convert -density [DPI] -trim [TMP_DIR]/[HASH].dvi [IMG_FILE]';
55    
56    return $D;    return $D;
# Line 106  function drutex_render_node2html() { Line 126  function drutex_render_node2html() {
126   */   */
127  function drutex_render_filter_settings($format = -1) {  function drutex_render_filter_settings($format = -1) {
128    /* conversion methods */    /* conversion methods */
129    $conversions = array('dvipng'        => 'dvipng',    $conversions = array('dvipng'            => 'dvipng',
130                         'imagemagick'   => 'ImageMagick (convert)',                         'imagemagick'       => 'ImageMagick (convert)',
131                         'custom'        => 'custom');                         'dvipng_trans'      => 'dvipng - Transparent',
132                           'imagemagick_trans' => 'ImageMagick (convert) - Transparent',
133                           'dvipng_win32'      => 'dvipng - Windows',
134                           'imagemagick_win32' => 'ImageMagick (convert) - Windows',
135                           'custom'            => 'custom');
136    
137    $form["drutex_template_render_$format"] = array(    $form["drutex_template_render_$format"] = array(
138        '#type' => 'select',        '#type' => 'select',
# Line 145  function drutex_render_filter_settings($ Line 169  function drutex_render_filter_settings($
169    }    }
170    
171    /* description for <custom conversion method> */    /* description for <custom conversion method> */
172    $description = t('* Leave blank and select dvipng or ImageMagick, to display a template for one of these commands in this box.') . '<br />'    $description = t('* Leave blank and select dvipng or ImageMagick, to display a template for one of these commands in this box.') .'<br />'. t('* Every line is executed in sequence, but in its own shell (so path changes aren\'t inherited).') .'<br />'. t('Placeholders available:<br />
     . t('* Every line is executed in sequence, but in its own shell (so path changes aren\'t inherited).') . '<br />'  
     . t('Placeholders available:<br />  
173          [HASH] - hash (name) for the image<br />          [HASH] - hash (name) for the image<br />
174          [TMP_DIR] - temporary dir (automatically cleaned)<br />          [TMP_DIR] - temporary dir (automatically cleaned)<br />
175          [IMG_DIR] - directory where the images are saved<br />          [IMG_DIR] - directory where the images are saved<br />
# Line 177  function drutex_render($text, $format = Line 199  function drutex_render($text, $format =
199    $text = _drutex_unescape($text);    $text = _drutex_unescape($text);
200    
201    if (drutex_submodule_is_active('security', $format)) {    if (drutex_submodule_is_active('security', $format)) {
202      if (drutex_security($text, $format) == false) {      if (drutex_security($text, $format) == FALSE) {
203        return '<em class="error">Unallowed command detected!</em>';        return '<em class="error">Unallowed command detected!</em>';
204      }      }
205    }    }
# Line 188  function drutex_render($text, $format = Line 210  function drutex_render($text, $format =
210    
211    $image_dir = drutex_var_get("drutex_dir_images_$format");    $image_dir = drutex_var_get("drutex_dir_images_$format");
212    
213    $template_dir = drutex_var_get('drutex_dir') . '/templates/render';    $template_dir = drutex_var_get('drutex_dir') .'/templates/render';
214    $template_file = drutex_var_get("drutex_template_render_$format");    $template_file = drutex_var_get("drutex_template_render_$format");
215    $template = $template_dir . '/' . $template_file;    $template = $template_dir .'/'. $template_file;
216    
217    $dpi = drutex_var_get("drutex_dpi_render_$format");    $dpi = drutex_var_get("drutex_dpi_render_$format");
218    
# Line 246  function drutex_render($text, $format = Line 268  function drutex_render($text, $format =
268    
269          if (drutex_var_get("drutex_debug_$format")) {          if (drutex_var_get("drutex_debug_$format")) {
270            $level = ($cmd_retval == 0) ? WATCHDOG_NOTICE : WATCHDOG_WARNING;            $level = ($cmd_retval == 0) ? WATCHDOG_NOTICE : WATCHDOG_WARNING;
271            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);
272          }          }
273        }        }
274      }      }
# Line 259  function drutex_render($text, $format = Line 281  function drutex_render($text, $format =
281      }      }
282      else {      else {
283        if ($success) {        if ($success) {
284          watchdog('DruTeX', "$image_file was created. Temporary directory was $temporary_dir.", WATCHDOG_NOTICE);          watchdog('DruTeX', "%imgfile was created. Temporary directory was %tdir.", array('%imgfile' => $image_file, '%tdir' => $temporary_dir), WATCHDOG_NOTICE);
285        }        }
286        else {        else {
287          watchdog('DruTeX', "$image_file couldn't be created. Temporary directory was $temporary_dir.", WATCHDOG_WARNING);          watchdog('DruTeX', "%imgfile couldn\'t be created. Temporary directory was %tdir.",  array('%imgfile' => $image_file, '%tdir' => $temporary_dir), WATCHDOG_WARNING);
288        }        }
289      }      }
290    }    }
291    
292    $img_url = drutex_get_image_url($format) . "/$hash.$image_type";    $img_url = drutex_get_image_url($format) ."/$hash.$image_type";
293    
294    if ($success) {    if ($success) {
295      $img_alt = _drutex_hide('set', check_plain($text));      $img_alt = _drutex_hide('set', check_plain($text));
296      $res = "<img class=\"teximage\" src=\"$img_url\" alt=\"$img_alt\" />";      $res = '<img class="teximage" src="'. $img_url .'" alt="'. $img_alt .'" />';
297    }    }
298    else {    else {
299      $res = '<em class="error">TeX Embedding failed!</em>';      $res = '<em class="error">TeX Embedding failed!</em>';
300    }    }
   
301    if (!empty($attributes['tag'])) {    if (!empty($attributes['tag'])) {
302      $class_attr = empty($attributes['class']) ? '' : " class=\"{$attributes['class']}\"";      $class_attr = empty($attributes['class']) ? '' : " class=\"{$attributes['class']}\"";
303    
# Line 299  function drutex_render($text, $format = Line 320  function drutex_render($text, $format =
320      }      }
321    }    }
322    
   
323    return $res;    return $res;
324  }  }
325    
# Line 307  function drutex_render($text, $format = Line 327  function drutex_render($text, $format =
327   * Get a list with templates for drutex_render.   * Get a list with templates for drutex_render.
328   */   */
329  function _drutex_get_templates() {  function _drutex_get_templates() {
330    $dir = drupal_get_path('module', 'drutex') . '/templates/render';    $dir = drupal_get_path('module', 'drutex') .'/templates/render';
331    
332    $A = file_scan_directory($dir, '.*\.tex');    $A = file_scan_directory($dir, '.*\.tex');
333    $B = array();    $B = array();

Legend:
Removed from v.1.22  
changed lines
  Added in v.1.22.4.1

  ViewVC Help
Powered by ViewVC 1.1.2