-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdruplastex.module~
74 lines (52 loc) · 1.71 KB
/
druplastex.module~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
function druplastex_perm() {
return array('access druplastex', 'create druplastex', 'administer druplastex');
}
function druplastex_filter($op, $delta = 0, $format = -1, $text = '') {
switch ($op) {
case 'list':
return array(0 => t('Maths rendering filter module'));
case 'description':
return t('Allows users to insert Maths easily');
case 'prepare':
return $text;
case "process":
$text=_druplastex_process_text($text);
return $text;
default:
return $text;
}
}
function _druplastex_process_text($text) {
$dir="/www/plus/html/MI/";
$imgbaseurl="/MI/";
if (preg_match_all('/\[maths\](.*)\[\/maths\]/sU', $text, $match)) {
$hits=count($match[0]);
for ($i=0;$i<$hits;$i++) {
$tex=$match[1][$i];
$tex=str_replace('\$','$',$tex);
$tex=str_replace('<','<',$tex);//fix broken imports
$tex=str_replace('>','>',$tex);//fix broken imports
$tex=str_replace('&','&',$tex);//fix broken imports
$tex ='\documentclass[10pt]{article}\textwidth 6.5in\begin{document}' . $tex . '\end{document}';
$md5=md5($tex);
$cachecheck=$dir.$md5.".md5";
if (!file_exists($cachecheck)) {
$tmpfname = tempnam("/tmp", "Plus");
$handle = fopen($tmpfname, "w");
fwrite($handle, $tex);
fclose($handle);
chmod($tmpfname, 0644);
$cmd = "export PATH=$PATH:/usr/local/bin/; /usr/local/bin/plastex --dir=".$dir.$md5."/ --image-base-url=".$imgbaseurl.$md5."/ --theme=minimal --no-theme-extras ".$tmpfname." ";
exec($cmd);
unlink($tmpfname);
if (!touch($cachecheck)) {
echo "error";
}
}
$replace=file_get_contents($dir.$md5."/index.html");
$text=str_replace($match[0][$i],$replace,$text);
}
}
return $text;
}