summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKai Stevenson <kai@kaistevenson.com>2023-08-01 15:48:14 -0700
committerKai Stevenson <kai@kaistevenson.com>2023-08-01 15:48:14 -0700
commitf385016a307bc5451f504f17676fde8172934d32 (patch)
treeb1e561b30efa6f787de139d85e833cf9c42004b7 /src
parent7175a9c8e1bfb2a19cb77d8ce5b8c9609a7b3e4d (diff)
centralized latex image storage, other improvements
Diffstat (limited to 'src')
-rw-r--r--src/lateximages/.gitignore (renamed from src/writing/images/.gitignore)0
-rw-r--r--src/phplatex.php12
-rw-r--r--src/tmp/.gitignore (renamed from src/writing/tmp/.gitignore)0
3 files changed, 6 insertions, 6 deletions
diff --git a/src/writing/images/.gitignore b/src/lateximages/.gitignore
index f935021..f935021 100644
--- a/src/writing/images/.gitignore
+++ b/src/lateximages/.gitignore
diff --git a/src/phplatex.php b/src/phplatex.php
index ce6a2fe..996dd88 100644
--- a/src/phplatex.php
+++ b/src/phplatex.php
@@ -55,7 +55,7 @@ function texify($string,$dpi='90',$fore="",$back="",$extraprelude="",$trans=FALS
$hashfn = sha1($totex).".".$dpi.".".$fore.".".$back.".".intval($trans); #file cache entry string: 40-char hash string plus size
$stralt = str_replace("&","&amp;", preg_replace("/[\"\n]/","",$string)); # stuck in the alt and title attributes
# May need some extra safety.
- $heredir = getcwd();
+ $heredir = $_SERVER["DOCUMENT_ROOT"];
# Experiment: Tries to adjust vertical positioning, so that rendered TeX text looks natural enough inline with HTML text
# Only descenders are really a problem since HTML's leeway is upwards.
@@ -81,14 +81,14 @@ function texify($string,$dpi='90',$fore="",$back="",$extraprelude="",$trans=FALS
# check if image for that TeX in the cache, return img HTML if it exists
- if (file_exists($heredir.'/images/'.$hashfn.'.'.$imgfmt))
- return '<img style="'.$verticalalign.'" title="'.$stralt.'" alt="'.$stralt.'" src="images/'.$hashfn.'.'.$imgfmt.'">';
+ if (file_exists($heredir.'/lateximages/'.$hashfn.'.'.$imgfmt))
+ return '<img style="'.$verticalalign.'" title="'.$stralt.'" alt="'.$stralt.'" src="lateximages/'.$hashfn.'.'.$imgfmt.'">';
# otherwise try to make and store:
# chdir to have superfluous files be created in just one place, tmp/ (you probably want to occasionally clean this yourself)
error_reporting(0); # TODO: fetch current value so we can restore it
- if (chdir("tmp")===FALSE) { return '[tmp directory access error, please fix permissions]'; } #I should think about some more specific errors, e.g. check whether file creation is allowed
+ if (chdir($_SERVER["DOCUMENT_ROOT"] . "/tmp")===FALSE) { return '[tmp directory access error, please fix permissions]'; } #I should think about some more specific errors, e.g. check whether file creation is allowed
error_reporting(E_ERROR | E_PARSE | E_WARNING | E_NOTICE);
$tfn = tempnam(getcwd(), 'PTX'); # unique base path in tmp dir
@@ -131,9 +131,9 @@ function texify($string,$dpi='90',$fore="",$back="",$extraprelude="",$trans=FALS
}
# Copy result image to chache.
- copy($tfn.'.'.$imgfmt, $heredir.'/images/'.$hashfn.'.'.$imgfmt);
+ copy($tfn.'.'.$imgfmt, $heredir.'/lateximages/'.$hashfn.'.'.$imgfmt);
# Clean up temporary files, and return link to just-created image
- return phplatex_cleantmp($tfn,$heredir).'<img style="'.$verticalalign.'" title="'.$stralt.'" alt="LaTeX formula: '.$stralt.'" src="images/'.$hashfn.'.'.$imgfmt.'">';
+ return phplatex_cleantmp($tfn,$heredir).'<img style="'.$verticalalign.'" title="'.$stralt.'" alt="LaTeX formula: '.$stralt.'" src="/lateximages/'.$hashfn.'.'.$imgfmt.'">';
}
?>
diff --git a/src/writing/tmp/.gitignore b/src/tmp/.gitignore
index f935021..f935021 100644
--- a/src/writing/tmp/.gitignore
+++ b/src/tmp/.gitignore