From f385016a307bc5451f504f17676fde8172934d32 Mon Sep 17 00:00:00 2001 From: Kai Stevenson Date: Tue, 1 Aug 2023 15:48:14 -0700 Subject: centralized latex image storage, other improvements --- src/lateximages/.gitignore | 1 + src/phplatex.php | 12 ++++++------ src/tmp/.gitignore | 1 + src/writing/images/.gitignore | 1 - src/writing/tmp/.gitignore | 1 - 5 files changed, 8 insertions(+), 8 deletions(-) create mode 100644 src/lateximages/.gitignore create mode 100644 src/tmp/.gitignore delete mode 100644 src/writing/images/.gitignore delete mode 100644 src/writing/tmp/.gitignore (limited to 'src') diff --git a/src/lateximages/.gitignore b/src/lateximages/.gitignore new file mode 100644 index 0000000..f935021 --- /dev/null +++ b/src/lateximages/.gitignore @@ -0,0 +1 @@ +!.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("&","&", 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 ''.$stralt.''; + if (file_exists($heredir.'/lateximages/'.$hashfn.'.'.$imgfmt)) + return ''.$stralt.''; # 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).'LaTeX formula: '.$stralt.''; + return phplatex_cleantmp($tfn,$heredir).'LaTeX formula: '.$stralt.''; } ?> diff --git a/src/tmp/.gitignore b/src/tmp/.gitignore new file mode 100644 index 0000000..f935021 --- /dev/null +++ b/src/tmp/.gitignore @@ -0,0 +1 @@ +!.gitignore diff --git a/src/writing/images/.gitignore b/src/writing/images/.gitignore deleted file mode 100644 index f935021..0000000 --- a/src/writing/images/.gitignore +++ /dev/null @@ -1 +0,0 @@ -!.gitignore diff --git a/src/writing/tmp/.gitignore b/src/writing/tmp/.gitignore deleted file mode 100644 index f935021..0000000 --- a/src/writing/tmp/.gitignore +++ /dev/null @@ -1 +0,0 @@ -!.gitignore -- cgit v1.2.3-70-g09d2