-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathProcess_LaTeX.php
executable file
·85 lines (77 loc) · 3.89 KB
/
Process_LaTeX.php
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
<?php
################################################################################
# Program Name: Process_LaTeX.php
# Description: Process_LaTeX is part of a system that duplicates some of the
# functionality of the Microsoft Word equation editor. A Word
# macro calls this PHP script on a web server that subsequently
# calls a PERL script that converts its argument into a PNG
# image. Refer to the PERL script for further documentation.
# Usage: Process_LaTeX.php?formula=font_size.data[&dont_del=del_value]
# Where font_size is the desired LaTeX font size (10, 11, or
# 12), data is a LaTeX formula that has been percent-encoded,
# and del_value is the boolean value (0 or 1) of dont_del.
# The dont_del option prevents the temporary files from being
# deleted after an error; this option defaults to 0 and would
# normally only be invoked for diagnostic purposes.
#
# Copyright (C) 2007 Tyler A. Davis
# Copyright (C) 2007 Philip Stevenson
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
################################################################################
# Microsoft Word will not make the call to this PHP script if the URL (including
# the 'formula' argument) has already been called since Word was started. This
# means that the correct PNG will not be (re)generated and the wrong image may
# be loaded into Word. This problem can be prevented by disabling caching with
# the following line.
header("Cache-Control: no-cache, must-revalidate");
# Get the formula whether from POST (preferable) or GET (for backward
# compatibility).
if($_POST)
$formula = $_POST['formula'];
else
$formula = $_GET['formula'];
$encodedFormula = $formula;
# PHP versions < 6 have a feature called "magic quotes" inteded to make input
# safe by escaping dangerous characters. If this feature is enabled, strip the
# extra slashed it adds.
if(get_magic_quotes_gpc()) {
$formula = stripslashes($formula);
print("Stripped 'magic quotes' extra slashes $formula<br>\n");
}
# PHP tries to undo the percent encoding, but the following restores the
# encoding because it's also handy for passing a string as an argument.
# "escapeshellarg" is used for added security.
# $LaTeX_String = escapeshellarg(urlencode($formula));
$LaTeX_String = urlencode($formula); # jlh - the above caused trouble on my windows machine setting
#$LaTeX_String_Display = str_replace('%', '%%',$LaTeX_String);
# Call PERL to generate the PNG and display the required baseline offset. If
# necessary, the PERL script will also display any error messages.
if ($_GET['dont_del']) {
print("Calling perl LaTeX_Converter.pl --URL=\"$LaTeX_String\" --Dont_Del<br>\n");
system("perl LaTeX_Converter.pl --URL=\"$LaTeX_String\" --Dont_Del");
} else {
print("Calling perl LaTeX_Converter.pl --URL=\"$LaTeX_String\"<br>\n");
system("perl LaTeX_Converter.pl --URL=\"$LaTeX_String\"");
}
#log the IP address
$dtime = date('r');
$ip = getenv("REMOTE_ADDR");
#$fp = fopen("G:/xampp/htdocs/process_latex/requestLog.txt", "a");
$fp = fopen("./requestLog.txt", "a"); # log ip in local file
fputs($fp, "$dtime: $ip $\n");
fclose($fp);
?>