ILIAS  release_8 Revision v8.24
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

 filepath ()
 Create the relative file path of the image. More...
 

Protected Attributes

ILIAS Filesystem 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 28 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 64 of file class.ilMathJaxImage.php.

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

References $DIC, TYPE_PNG, and TYPE_SVG.

Member Function Documentation

◆ absolutePath()

ilMathJaxImage::absolutePath ( )

Get the absolute path of the image.

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

100 : string
101 {
102 return CLIENT_WEB_DIR . $this->filepath();
103 }
filepath()
Create the relative file path of the image.
const CLIENT_WEB_DIR
Definition: constants.php:47

References CLIENT_WEB_DIR, and filepath().

+ Here is the call graph for this function:

◆ clearCache()

ilMathJaxImage::clearCache ( )

Delete all files from the cache.

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

156 : void
157 {
158 $this->fs->deleteDir($this->basepath);
159 }

◆ exists()

ilMathJaxImage::exists ( )

Check if an image is cached.

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

108 : bool
109 {
110 return $this->fs->has($this->filepath());
111 }

References filepath().

+ Here is the call graph for this function:

◆ filepath()

ilMathJaxImage::filepath ( )
protected

Create the relative file path of the image.

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

88 : string
89 {
90 $hash = md5($this->tex . $this->salt);
91 return $this->basepath
92 . '/' . substr($hash, 0, 4)
93 . '/' . substr($hash, 4, 4)
94 . '/' . $hash . $this->suffix;
95 }

References $suffix.

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

+ 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 133 of file class.ilMathJaxImage.php.

133 : string
134 {
135 $size = 0;
136 if ($this->fs->hasDir($this->basepath)) {
137 foreach ($this->fs->finder()->in([$this->basepath])->files() as $meta) {
138 $size += $this->fs->getSize($meta->getPath(), 1)->inBytes();
139 }
140 }
141
142 $type = array("K", "M", "G", "T", "P", "E", "Z", "Y");
143 $size /= 1000;
144 $counter = 0;
145 while ($size >= 1000) {
146 $size /= 1000;
147 $counter++;
148 }
149
150 return (round($size, 1) . " " . $type[$counter] . "B");
151 }
$type

References $type.

◆ read()

ilMathJaxImage::read ( )

Read the content of a cached image.

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

116 : string
117 {
118 return $this->fs->read($this->filepath());
119 }

References filepath().

+ 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 125 of file class.ilMathJaxImage.php.

125 : void
126 {
127 $this->fs->put($this->filepath(), $a_content);
128 }

References filepath().

+ Here is the call graph for this function:

Field Documentation

◆ $basepath

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

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

◆ $fs

ILIAS Filesystem Filesystem ilMathJaxImage::$fs
protected

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

◆ $salt

string ilMathJaxImage::$salt
protected

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

◆ $suffix

string ilMathJaxImage::$suffix
protected

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

Referenced by filepath().

◆ $tex

string ilMathJaxImage::$tex
protected

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

◆ TYPE_PNG

const ilMathJaxImage::TYPE_PNG = 'png'
private

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

Referenced by __construct().

◆ TYPE_SVG

const ilMathJaxImage::TYPE_SVG = 'svg'
private

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

Referenced by __construct().


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