ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilQtiMatImageSecurity Class Reference
+ Collaboration diagram for ilQtiMatImageSecurity:

Public Member Functions

 __construct (ilQTIMatimage $imageMaterial)
 
 getImageMaterial ()
 
 setImageMaterial ($imageMaterial)
 
 validate ()
 
 sanitizeLabel ()
 

Protected Member Functions

 getDetectedMimeType ()
 
 setDetectedMimeType ($detectedMimeType)
 
 validateContent ()
 
 validateLabel ()
 
 determineMimeType ($content)
 
 determineFileExtension ($label)
 Returns the determine file extension. More...
 
 hasFileExtension ($label)
 Returns whether or not the passed label contains a file extension. More...
 

Protected Attributes

 $imageMaterial
 
 $detectedMimeType
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

ilQtiMatImageSecurity::__construct ( ilQTIMatimage  $imageMaterial)

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

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

27  {
28  $this->setImageMaterial($imageMaterial);
29 
30  if (!strlen($this->getImageMaterial()->getRawContent())) {
31  throw new ilQtiException('cannot import image without content');
32  }
33 
34  $this->setDetectedMimeType(
35  $this->determineMimeType($this->getImageMaterial()->getRawContent())
36  );
37  }
setDetectedMimeType($detectedMimeType)
+ Here is the call graph for this function:

Member Function Documentation

◆ determineFileExtension()

ilQtiMatImageSecurity::determineFileExtension (   $label)
protected

Returns the determine file extension.

If no extension

Parameters
string$label
Returns
string|null

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

Referenced by validateLabel().

151  {
152  $pathInfo = pathinfo($label);
153 
154  if (isset($pathInfo['extension'])) {
155  return $pathInfo['extension'];
156  }
157 
158  return null;
159  }
+ Here is the caller graph for this function:

◆ determineMimeType()

ilQtiMatImageSecurity::determineMimeType (   $content)
protected

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

References ilFileUtils\lookupContentMimeType().

Referenced by __construct().

141  {
142  return ilFileUtils::lookupContentMimeType($content);
143  }
static lookupContentMimeType($content)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDetectedMimeType()

ilQtiMatImageSecurity::getDetectedMimeType ( )
protected
Returns
string

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

References $detectedMimeType.

Referenced by validateContent(), and validateLabel().

+ Here is the caller graph for this function:

◆ getImageMaterial()

ilQtiMatImageSecurity::getImageMaterial ( )
Returns
ilQTIMatimage

Definition at line 42 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 (   $label)
protected

Returns whether or not the passed label contains a file extension.

Parameters
string$label
Returns
bool

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

Referenced by validateLabel().

167  {
168  $pathInfo = pathinfo($label);
169 
170  return array_key_exists('extension', $pathInfo);
171  }
+ Here is the caller graph for this function:

◆ sanitizeLabel()

ilQtiMatImageSecurity::sanitizeLabel ( )

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

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

130  {
131  $label = $this->getImageMaterial()->getLabel();
132 
133  $label = basename($label);
134  $label = ilUtil::stripSlashes($label);
135  $label = ilUtil::getASCIIFilename($label);
136 
137  $this->getImageMaterial()->setLabel($label);
138  }
static getASCIIFilename($a_filename)
convert utf8 to ascii filename
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
+ Here is the call graph for this function:

◆ setDetectedMimeType()

ilQtiMatImageSecurity::setDetectedMimeType (   $detectedMimeType)
protected
Parameters
string$detectedMimeType

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

References $detectedMimeType.

Referenced by __construct().

67  {
68  $this->detectedMimeType = $detectedMimeType;
69  }
+ Here is the caller graph for this function:

◆ setImageMaterial()

ilQtiMatImageSecurity::setImageMaterial (   $imageMaterial)
Parameters
ilQTIMatimage$imageMaterial

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

References $imageMaterial.

Referenced by __construct().

51  {
52  $this->imageMaterial = $imageMaterial;
53  }
+ Here is the caller graph for this function:

◆ validate()

ilQtiMatImageSecurity::validate ( )

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

References validateContent(), and validateLabel().

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

◆ validateContent()

ilQtiMatImageSecurity::validateContent ( )
protected

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

References $detectedMimeType, $GLOBALS, $log, assQuestion\fetchMimeTypeIdentifier(), getDetectedMimeType(), getImageMaterial(), and assQuestion\isAllowedImageMimeType().

Referenced by validate().

85  {
86  if ($this->getImageMaterial()->getImagetype() && !assQuestion::isAllowedImageMimeType($this->getImageMaterial()->getImagetype())) {
87  return false;
88  }
89 
91  return false;
92  }
93 
94  if ($this->getImageMaterial()->getImagetype()) {
95  $declaredMimeType = assQuestion::fetchMimeTypeIdentifier($this->getImageMaterial()->getImagetype());
97 
98  if ($declaredMimeType != $detectedMimeType) {
99  // since ilias exports jpeg declared pngs itself, we skip this validation ^^
100  // return false;
101 
102  /* @var ilComponentLogger $log */
103  $log = $GLOBALS['DIC'] ? $GLOBALS['DIC']['ilLog'] : $GLOBALS['ilLog'];
104  $log->log(
105  'QPL: imported image with declared mime (' . $declaredMimeType . ') '
106  . 'and detected mime (' . $detectedMimeType . ')'
107  );
108  }
109  }
110 
111  return true;
112  }
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
static isAllowedImageMimeType($mimeType)
static fetchMimeTypeIdentifier($contentTypeString)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ validateLabel()

ilQtiMatImageSecurity::validateLabel ( )
protected

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

References determineFileExtension(), getDetectedMimeType(), getImageMaterial(), hasFileExtension(), and assQuestion\isAllowedImageFileExtension().

Referenced by validate().

115  {
116  if ($this->getImageMaterial()->getUri()) {
117  if (!$this->hasFileExtension($this->getImageMaterial()->getUri())) {
118  return true;
119  }
120 
121  $extension = $this->determineFileExtension($this->getImageMaterial()->getUri());
122  } else {
123  $extension = $this->determineFileExtension($this->getImageMaterial()->getLabel());
124  }
125 
127  }
determineFileExtension($label)
Returns the determine file extension.
hasFileExtension($label)
Returns whether or not the passed label contains a file extension.
static isAllowedImageFileExtension($mimeType, $fileExtension)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $detectedMimeType

ilQtiMatImageSecurity::$detectedMimeType
protected

◆ $imageMaterial

ilQtiMatImageSecurity::$imageMaterial
protected

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

Referenced by getImageMaterial(), and setImageMaterial().


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