Skip to content

Commit

Permalink
adding ctools object caching to drutexml
Browse files Browse the repository at this point in the history
  • Loading branch information
jukowski committed Jul 4, 2011
1 parent 09fbf9e commit 032755e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sites/all/modules/drutexml/drutexml.info
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ name = DruTeXML
description = A module that allows a new formatting method for Drupal
core = 7.x
package = Planetary Modules

dependencies[] = ctools
8 changes: 8 additions & 0 deletions sites/all/modules/drutexml/drutexml.module
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ function _drutexml_filter_latex_settings($form, $form_state, $filter, $format, $
* @param unknown_type $format
*/
function _drutexml_filter_latex_process($text, $filter, $format, $langcode, $cache, $cache_id) {
$key = md5($text);
ctools_include("object-cache");
$cached = ctools_object_cache_get("drutexml_cache", $key);
if (isset($cached)) {
return $cached;
}

$host = isset($filter->settings['latexml_url']) ? $filter->settings['latexml_url'] : 'http://tex2xml.kwarc.info/test/ajax/convert_fragment.php';
$data = 'formula=' . urlencode($text);
$content = do_post($host,$data);
Expand All @@ -128,6 +135,7 @@ function _drutexml_filter_latex_process($text, $filter, $format, $langcode, $cac
$res = str_replace('xml:','',$res); //also remove xml:id
//$res = "<span xmlns:m=\"http://www.w3.org/1998/Math/MathML\">".$res."</span>";

ctools_object_cache_set("drutexml_cache", $key, $res);
return $res;
}

Expand Down

0 comments on commit 032755e

Please sign in to comment.