ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilQtiMatImageSecurity Class Reference
+ Collaboration diagram for ilQtiMatImageSecurity:

Public Member Functions

 __construct (ilQTIMatimage $imageMaterial, \ILIAS\TestQuestionPool\QuestionFilesService $questionFilesService)
 
 getImageMaterial ()
 
 setImageMaterial (ilQTIMatimage $imageMaterial)
 
 validate ()
 
 sanitizeLabel ()
 

Protected Member Functions

 getDetectedMimeType ()
 
 setDetectedMimeType (string $detectedMimeType)
 
 validateContent ()
 
 validateLabel ()
 
 determineMimeType (?string $content)
 
 determineFileExtension (string $label)
 
 hasFileExtension (string $label)
 

Protected Attributes

ilQTIMatimage $imageMaterial
 
string $detectedMimeType = ""
 

Private Attributes

ILIAS TestQuestionPool QuestionFilesService $questionFilesService
 

Detailed Description

Definition at line 28 of file class.ilQtiMatImageSecurity.php.

Constructor & Destructor Documentation

◆ __construct()

ilQtiMatImageSecurity::__construct ( ilQTIMatimage  $imageMaterial,
\ILIAS\TestQuestionPool\QuestionFilesService  $questionFilesService 
)

Definition at line 34 of file class.ilQtiMatImageSecurity.php.

References $questionFilesService, determineMimeType(), getImageMaterial(), setDetectedMimeType(), and setImageMaterial().

35  {
36  $this->questionFilesService = $questionFilesService;
37 
38  $this->setImageMaterial($imageMaterial);
39 
40  if (!strlen($this->getImageMaterial()->getRawContent())) {
41  throw new ilQtiException('cannot import image without content');
42  }
43 
44  $this->setDetectedMimeType(
45  $this->determineMimeType($this->getImageMaterial()->getRawContent())
46  );
47  }
ILIAS TestQuestionPool QuestionFilesService $questionFilesService
setImageMaterial(ilQTIMatimage $imageMaterial)
setDetectedMimeType(string $detectedMimeType)
+ Here is the call graph for this function:

Member Function Documentation

◆ determineFileExtension()

ilQtiMatImageSecurity::determineFileExtension ( string  $label)
protected

Definition at line 145 of file class.ilQtiMatImageSecurity.php.

Referenced by validateLabel().

145  : ?string
146  {
147  $pathInfo = pathinfo($label);
148 
149  if (isset($pathInfo['extension'])) {
150  return $pathInfo['extension'];
151  }
152 
153  return null;
154  }
+ Here is the caller graph for this function:

◆ determineMimeType()

ilQtiMatImageSecurity::determineMimeType ( ?string  $content)
protected

Definition at line 138 of file class.ilQtiMatImageSecurity.php.

Referenced by __construct().

138  : string
139  {
140  $finfo = new finfo(FILEINFO_MIME);
141 
142  return $finfo->buffer($content);
143  }
+ Here is the caller graph for this function:

◆ getDetectedMimeType()

ilQtiMatImageSecurity::getDetectedMimeType ( )
protected

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

References $detectedMimeType.

Referenced by validateContent(), and validateLabel().

59  : string
60  {
62  }
+ Here is the caller graph for this function:

◆ getImageMaterial()

ilQtiMatImageSecurity::getImageMaterial ( )

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

References $imageMaterial.

Referenced by __construct(), sanitizeLabel(), validateContent(), and validateLabel().

+ Here is the caller graph for this function:

◆ hasFileExtension()

ilQtiMatImageSecurity::hasFileExtension ( string  $label)
protected

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

Referenced by validateLabel().

156  : bool
157  {
158  $pathInfo = pathinfo($label);
159 
160  return array_key_exists('extension', $pathInfo);
161  }
+ Here is the caller graph for this function:

◆ sanitizeLabel()

ilQtiMatImageSecurity::sanitizeLabel ( )

Definition at line 127 of file class.ilQtiMatImageSecurity.php.

References ilFileUtils\getASCIIFilename(), getImageMaterial(), and ilUtil\stripSlashes().

127  : void
128  {
129  $label = $this->getImageMaterial()->getLabel();
130 
131  $label = basename($label);
132  $label = ilUtil::stripSlashes($label);
133  $label = ilFileUtils::getASCIIFilename($label);
134 
135  $this->getImageMaterial()->setLabel($label);
136  }
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
static getASCIIFilename(string $a_filename)
+ Here is the call graph for this function:

◆ setDetectedMimeType()

ilQtiMatImageSecurity::setDetectedMimeType ( string  $detectedMimeType)
protected

Definition at line 64 of file class.ilQtiMatImageSecurity.php.

References $detectedMimeType.

Referenced by __construct().

64  : void
65  {
66  $this->detectedMimeType = $detectedMimeType;
67  }
+ Here is the caller graph for this function:

◆ setImageMaterial()

ilQtiMatImageSecurity::setImageMaterial ( ilQTIMatimage  $imageMaterial)

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

References $imageMaterial.

Referenced by __construct().

54  : void
55  {
56  $this->imageMaterial = $imageMaterial;
57  }
+ Here is the caller graph for this function:

◆ validate()

ilQtiMatImageSecurity::validate ( )

Definition at line 69 of file class.ilQtiMatImageSecurity.php.

References validateContent(), and validateLabel().

69  : bool
70  {
71  if (!$this->validateLabel()) {
72  return false;
73  }
74 
75  if (!$this->validateContent()) {
76  return false;
77  }
78 
79  return true;
80  }
+ Here is the call graph for this function:

◆ validateContent()

ilQtiMatImageSecurity::validateContent ( )
protected

Definition at line 82 of file class.ilQtiMatImageSecurity.php.

References $GLOBALS, $log, getDetectedMimeType(), and getImageMaterial().

Referenced by validate().

82  : bool
83  {
84  if ($this->getImageMaterial()->getImagetype() && !$this->questionFilesService->isAllowedImageMimeType($this->getImageMaterial()->getImagetype())) {
85  return false;
86  }
87 
88  if (!$this->questionFilesService->isAllowedImageMimeType($this->getDetectedMimeType())) {
89  return false;
90  }
91 
92  if ($this->getImageMaterial()->getImagetype()) {
93  $declaredMimeType = current(explode(';', $this->getImageMaterial()->getImagetype()));
94  $detectedMimeType = current(explode(';', $this->getDetectedMimeType()));
95 
96  if ($declaredMimeType != $detectedMimeType) {
97  // since ilias exports jpeg declared pngs itself, we skip this validation ^^
98  // return false;
99 
100  /* @var ilComponentLogger $log */
101  $log = $GLOBALS['DIC'] ? $GLOBALS['DIC']['ilLog'] : $GLOBALS['ilLog'];
102  $log->log(
103  'QPL: imported image with declared mime (' . $declaredMimeType . ') '
104  . 'and detected mime (' . $detectedMimeType . ')'
105  );
106  }
107  }
108 
109  return true;
110  }
$GLOBALS["DIC"]
Definition: wac.php:31
$log
Definition: result.php:33
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ validateLabel()

ilQtiMatImageSecurity::validateLabel ( )
protected

Definition at line 112 of file class.ilQtiMatImageSecurity.php.

References determineFileExtension(), getDetectedMimeType(), getImageMaterial(), and hasFileExtension().

Referenced by validate().

112  : bool
113  {
114  if ($this->getImageMaterial()->getUri()) {
115  if (!$this->hasFileExtension($this->getImageMaterial()->getUri())) {
116  return true;
117  }
118 
119  $extension = $this->determineFileExtension($this->getImageMaterial()->getUri());
120  } else {
121  $extension = $this->determineFileExtension($this->getImageMaterial()->getLabel());
122  }
123 
124  return $this->questionFilesService->isAllowedImageFileExtension($this->getDetectedMimeType(), $extension);
125  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $detectedMimeType

string ilQtiMatImageSecurity::$detectedMimeType = ""
protected

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

Referenced by getDetectedMimeType(), and setDetectedMimeType().

◆ $imageMaterial

ilQTIMatimage ilQtiMatImageSecurity::$imageMaterial
protected

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

Referenced by getImageMaterial(), and setImageMaterial().

◆ $questionFilesService

ILIAS TestQuestionPool QuestionFilesService ilQtiMatImageSecurity::$questionFilesService
private

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

Referenced by __construct().


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