ILIAS  trunk Revision v11.0_alpha-1749-g1a06bdef097
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilMathJaxImage Class Reference

Rendered MathJax image Supports image types SVG or PNG Files are stored in the web file system of ilias. More...

+ Collaboration diagram for ilMathJaxImage:

Public Member Functions

 __construct (string $a_tex, string $a_type, int $a_dpi)
 
 absolutePath ()
 Get the absolute path of the image. More...
 
 exists ()
 Check if an image is cached. More...
 
 read ()
 Read the content of a cached image. More...
 
 write (string $a_content)
 Save the content of a cached image. More...
 
 getCacheSize ()
 Get the total size of the cache with an appropriate unit for display. More...
 
 clearCache ()
 Delete all files from the cache. More...
 

Protected Member Functions

 filedir ()
 Get the relative directory path of the image. More...
 
 filepath ()
 Get the relative file path of the image. More...
 

Protected Attributes

Filesystem $fs
 
string $basepath = '/temp/tex'
 
string $tex
 
string $suffix
 
string $salt
 

Private Attributes

const TYPE_PNG = 'png'
 
const TYPE_SVG = 'svg'
 

Detailed Description

Rendered MathJax image Supports image types SVG or PNG Files are stored in the web file system of ilias.

Definition at line 30 of file class.ilMathJaxImage.php.

Constructor & Destructor Documentation

◆ __construct()

ilMathJaxImage::__construct ( string  $a_tex,
string  $a_type,
int  $a_dpi 
)
Parameters
string$a_texlatex code
string$a_typeimage type ('png' or 'svg')
int$a_dpidpi of rendered image

Definition at line 66 of file class.ilMathJaxImage.php.

References $DIC.

67  {
68  global $DIC;
69 
70  $this->fs = $DIC->filesystem()->web();
71  $this->tex = $a_tex;
72 
73  switch ($a_type) {
74  case self::TYPE_PNG:
75  $this->suffix = '.png';
76  break;
77  case self::TYPE_SVG:
78  $this->suffix = '.svg';
79  break;
80  default:
81  throw new ilMathJaxException('imagetype not supported');
82  }
83 
84  $this->salt = '#' . $a_dpi;
85  }
global $DIC
Definition: shib_login.php:22

Member Function Documentation

◆ absolutePath()

ilMathJaxImage::absolutePath ( )

Get the absolute path of the image.

Definition at line 110 of file class.ilMathJaxImage.php.

References CLIENT_WEB_DIR, and filepath().

110  : string
111  {
112  return CLIENT_WEB_DIR . $this->filepath();
113  }
filepath()
Get the relative file path of the image.
const CLIENT_WEB_DIR
Definition: constants.php:47
+ Here is the call graph for this function:

◆ clearCache()

ilMathJaxImage::clearCache ( )

Delete all files from the cache.

Definition at line 181 of file class.ilMathJaxImage.php.

181  : void
182  {
183  $this->fs->deleteDir($this->basepath);
184  }

◆ exists()

ilMathJaxImage::exists ( )

Check if an image is cached.

Definition at line 118 of file class.ilMathJaxImage.php.

References filepath().

118  : bool
119  {
120  return $this->fs->has($this->filepath());
121  }
filepath()
Get the relative file path of the image.
+ Here is the call graph for this function:

◆ filedir()

ilMathJaxImage::filedir ( )
protected

Get the relative directory path of the image.

Definition at line 90 of file class.ilMathJaxImage.php.

Referenced by filepath(), and write().

90  : string
91  {
92  $hash = md5($this->tex . $this->salt);
93  return $this->basepath
94  . '/' . substr($hash, 0, 4)
95  . '/' . substr($hash, 4, 4);
96  }
+ Here is the caller graph for this function:

◆ filepath()

ilMathJaxImage::filepath ( )
protected

Get the relative file path of the image.

Definition at line 101 of file class.ilMathJaxImage.php.

References $suffix, and filedir().

Referenced by absolutePath(), exists(), read(), and write().

101  : string
102  {
103  $hash = md5($this->tex . $this->salt);
104  return $this->filedir() . '/' . $hash . $this->suffix;
105  }
filedir()
Get the relative directory path of the image.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCacheSize()

ilMathJaxImage::getCacheSize ( )

Get the total size of the cache with an appropriate unit for display.

Definition at line 158 of file class.ilMathJaxImage.php.

158  : string
159  {
160  $size = 0;
161  if ($this->fs->hasDir($this->basepath)) {
162  foreach ($this->fs->finder()->in([$this->basepath])->files() as $meta) {
163  $size += $this->fs->getSize($meta->getPath(), 1)->inBytes();
164  }
165  }
166 
167  $type = array("K", "M", "G", "T", "P", "E", "Z", "Y");
168  $size /= 1000;
169  $counter = 0;
170  while ($size >= 1000) {
171  $size /= 1000;
172  $counter++;
173  }
174 
175  return (round($size, 1) . " " . $type[$counter] . "B");
176  }

◆ read()

ilMathJaxImage::read ( )

Read the content of a cached image.

Definition at line 126 of file class.ilMathJaxImage.php.

References filepath().

126  : string
127  {
128  return $this->fs->read($this->filepath());
129  }
filepath()
Get the relative file path of the image.
+ Here is the call graph for this function:

◆ write()

ilMathJaxImage::write ( string  $a_content)

Save the content of a cached image.

Parameters
string$a_contentimage content

Definition at line 135 of file class.ilMathJaxImage.php.

References filedir(), and filepath().

135  : void
136  {
137  // set the directory access of the whole relative file to visible
138  // this is needed if TeX is used in certificates
139  // the ILIAS java server must have read access to the files for the PDF generation
140  // it may run with a different user account
141  $dir = '';
142  foreach (explode('/', $this->filedir()) as $part) {
143  if (!empty($part)) {
144  $dir = $dir . '/' . $part;
145  }
146  if (!$this->fs->hasDir($dir)) {
147  $this->fs->createDir($dir, Visibility::PUBLIC_ACCESS);
148  } else {
149  $this->fs->setVisibility($dir, Visibility::PUBLIC_ACCESS);
150  }
151  }
152  $this->fs->put($this->filepath(), $a_content);
153  }
filepath()
Get the relative file path of the image.
filedir()
Get the relative directory path of the image.
+ Here is the call graph for this function:

Field Documentation

◆ $basepath

string ilMathJaxImage::$basepath = '/temp/tex'
protected

Definition at line 44 of file class.ilMathJaxImage.php.

◆ $fs

Filesystem ilMathJaxImage::$fs
protected

Definition at line 39 of file class.ilMathJaxImage.php.

◆ $salt

string ilMathJaxImage::$salt
protected

Definition at line 59 of file class.ilMathJaxImage.php.

◆ $suffix

string ilMathJaxImage::$suffix
protected

Definition at line 54 of file class.ilMathJaxImage.php.

Referenced by filepath().

◆ $tex

string ilMathJaxImage::$tex
protected

Definition at line 49 of file class.ilMathJaxImage.php.

◆ TYPE_PNG

const ilMathJaxImage::TYPE_PNG = 'png'
private

Definition at line 32 of file class.ilMathJaxImage.php.

◆ TYPE_SVG

const ilMathJaxImage::TYPE_SVG = 'svg'
private

Definition at line 33 of file class.ilMathJaxImage.php.


The documentation for this class was generated from the following file: