-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdruplastex.module
121 lines (91 loc) · 3.09 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
function druplastex_perm() {
return array('access druplastex', 'create druplastex', 'administer druplastex');
}
function druplastex_filter_info() {
$filters['druplastex_filter'] = array(
'title' => t('Drupal Plastex filter'),
'description' => t('Turns maths in to html maths'),
'cache' => TRUE,
'process callback' => 'druplastex_substitute',
'tips callback' => 'druplastex_filter_tips'
);
return $filters;
}
function druplastex_filter_tips($filter, $format, $long) {
if ($long) {
return t('You may link to uploaded images within the current node using the wysiwyg editor toolbar icons.
The Custom Inline Filter is to replace added image placeholders with uploaded inline images.'
);
}
else {
return t('Use the wysiwyg editor toolbar icons to display uploaded images inline.');
}
}
function druplastex_substitute($text, $filter, $format, $langcode, $cache, $cache_id) {
$text=_druplastex_process_text($text);
return $text;
}
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}';
$tex ='\documentclass[10pt]{article}\usepackage{amsfonts}\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);
//watchdog(WATCHDOG_ERROR, $tex);
$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." ";
//watchdog(WATCHDOG_ERROR, $cmd);
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;
}
function druplastex_install() {
db_update('system')
->fields(array('weight' => 999))
->condition('name', 'druplastex', '=')
->execute();
}
function druplastex_update_7100() {
db_update('system')
->fields(array('weight' => 999))
->condition('name', 'druplastex', '=')
->execute();
}