ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
All Data Structures Namespaces Files Functions Variables Modules Pages
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)
 

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  {
32  throw new ilQtiException('cannot import image without content');
33  }
34 
35  $this->setDetectedMimeType(
36  $this->determineMimeType($this->getImageMaterial()->getRawContent())
37  );
38  }
setDetectedMimeType($detectedMimeType)
+ Here is the call graph for this function:

Member Function Documentation

◆ determineFileExtension()

ilQtiMatImageSecurity::determineFileExtension (   $label)
protected

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

References $filename.

Referenced by validateLabel().

144  {
145  list($dirname, $basename, $extension, $filename) = array_values( pathinfo($label) );
146  return $extension;
147  }
$filename
Definition: buildRTE.php:89
+ Here is the caller graph for this function:

◆ determineMimeType()

ilQtiMatImageSecurity::determineMimeType (   $content)
protected

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

References ilFileUtils\lookupContentMimeType().

Referenced by __construct().

139  {
140  return ilFileUtils::lookupContentMimeType($content);
141  }
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 59 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 43 of file class.ilQtiMatImageSecurity.php.

References $imageMaterial.

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

+ Here is the caller graph for this function:

◆ sanitizeLabel()

ilQtiMatImageSecurity::sanitizeLabel ( )

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

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

128  {
129  $label = $this->getImageMaterial()->getLabel();
130 
131  $label = basename($label);
132  $label = ilUtil::stripSlashes($label);
133  $label = ilUtil::getASCIIFilename($label);
134 
135  $this->getImageMaterial()->setLabel($label);
136  }
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 67 of file class.ilQtiMatImageSecurity.php.

References $detectedMimeType.

Referenced by __construct().

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

◆ setImageMaterial()

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

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

References $imageMaterial.

Referenced by __construct().

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

◆ validate()

ilQtiMatImageSecurity::validate ( )

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

References validateContent(), and validateLabel().

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

◆ validateContent()

ilQtiMatImageSecurity::validateContent ( )
protected

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

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

Referenced by validate().

88  {
89  if($this->getImageMaterial()->getImagetype() && !assQuestion::isAllowedImageMimeType($this->getImageMaterial()->getImagetype()) )
90  {
91  return false;
92  }
93 
95  {
96  return false;
97  }
98 
99  if ($this->getImageMaterial()->getImagetype())
100  {
101  $declaredMimeType = assQuestion::fetchMimeTypeIdentifier($this->getImageMaterial()->getImagetype());
103 
104  if( $declaredMimeType != $detectedMimeType )
105  {
106  return false;
107  }
108  }
109 
110  return true;
111  }
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 113 of file class.ilQtiMatImageSecurity.php.

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

Referenced by validate().

114  {
115  if ($this->getImageMaterial()->getUri())
116  {
117  $extension = $this->determineFileExtension($this->getImageMaterial()->getUri());
118  }
119  else
120  {
121  $extension = $this->determineFileExtension($this->getImageMaterial()->getLabel());
122  }
123 
125  }
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: