ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
class.ilQtiMatImageSecurity.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Modules/TestQuestionPool/classes/class.assQuestion.php';
5require_once 'Services/Utilities/classes/class.ilFileUtils.php';
6require_once 'Services/QTI/exceptions/class.ilQtiException.php';
7
15{
19 protected $imageMaterial;
20
25
27 {
28 $this->setImageMaterial($imageMaterial);
29
30 if( !strlen($this->getImageMaterial()->getRawContent()) )
31 {
32 throw new ilQtiException('cannot import image without content');
33 }
34
36 $this->determineMimeType($this->getImageMaterial()->getRawContent())
37 );
38 }
39
43 public function getImageMaterial()
44 {
46 }
47
52 {
53 $this->imageMaterial = $imageMaterial;
54 }
55
59 protected function getDetectedMimeType()
60 {
62 }
63
68 {
69 $this->detectedMimeType = $detectedMimeType;
70 }
71
72 public function validate()
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 }
86
87 protected function validateContent()
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 }
112
113 protected function validateLabel()
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 }
126
127 public function sanitizeLabel()
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 }
137
138 protected function determineMimeType($content)
139 {
140 return ilFileUtils::lookupContentMimeType($content);
141 }
142
143 protected function determineFileExtension($label)
144 {
145 list($dirname, $basename, $extension, $filename) = array_values( pathinfo($label) );
146 return $extension;
147 }
148}
$filename
Definition: buildRTE.php:89
static isAllowedImageFileExtension($mimeType, $fileExtension)
static fetchMimeTypeIdentifier($contentTypeString)
static isAllowedImageMimeType($mimeType)
static lookupContentMimeType($content)
__construct(ilQTIMatimage $imageMaterial)
setDetectedMimeType($detectedMimeType)
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