59 $this->db =
$DIC->database();
60 $this->
lng = $DIC->language();
61 $this->parameters = array();
62 $this->mapareas = array();
74 public function setId(
int $a_id): void
89 $this->mob_id = $a_mob_id;
100 public function setNr(
int $a_nr): void
119 $a_desired_type = strtolower($a_desired_type);
121 $im_types = ImageTypes();
123 switch ($a_desired_type) {
126 if ($im_types & IMG_JPG) {
129 if ($im_types & IMG_GIF) {
132 if ($im_types & IMG_PNG) {
138 if ($im_types & IMG_GIF) {
141 if ($im_types & IMG_JPG) {
144 if ($im_types & IMG_PNG) {
151 if ($im_types & IMG_PNG) {
154 if ($im_types & IMG_JPG) {
157 if ($im_types & IMG_GIF) {
168 $this->duration = $a_val;
178 $this->text_representation = $a_val;
188 $this->upload_hash = $a_val;
200 $item_id =
$ilDB->nextId(
"media_item");
201 $query =
"INSERT INTO media_item (id,mob_id, purpose, location, " .
202 "location_type, format, width, " .
203 "height, halign, caption, nr, text_representation, upload_hash, duration) VALUES " .
205 $ilDB->quote($item_id,
"integer") .
"," .
215 $ilDB->quote($this->
getNr(),
"integer") .
"," .
222 $this->
setId($item_id);
227 $query =
"INSERT INTO mob_parameter (med_item_id, name, value) VALUES " .
228 "(" .
$ilDB->quote($item_id,
"integer") .
"," .
230 $ilDB->quote($value,
"text") .
")";
235 for (
$i = 0;
$i < count($this->mapareas);
$i++) {
236 if (is_object($this->mapareas[
$i])) {
237 $this->mapareas[
$i]->setItemId($this->
getId());
238 $this->mapareas[
$i]->setNr(
$i + 1);
239 $this->mapareas[
$i]->create();
248 $query =
"UPDATE media_item SET " .
249 " mob_id = " .
$ilDB->quote($this->
getMobId(),
"integer") .
"," .
254 " width = " .
$ilDB->quote($this->
getWidth(),
"text") .
"," .
258 " nr = " .
$ilDB->quote($this->
getNr(),
"integer") .
"," .
262 " WHERE id = " .
$ilDB->quote($this->
getId(),
"integer");
266 $query =
"DELETE FROM mob_parameter WHERE med_item_id = " .
273 $query =
"INSERT INTO mob_parameter (med_item_id, name, value) VALUES " .
274 "(" .
$ilDB->quote($this->
getId(),
"integer") .
"," .
276 $ilDB->quote($value,
"text") .
")";
287 $query =
"INSERT INTO mob_parameter (med_item_id, name, value) VALUES " .
288 "(" .
$ilDB->quote($this->
getId(),
"integer") .
"," .
289 $ilDB->quote($a_name,
"text") .
"," .
290 $ilDB->quote($a_value,
"text") .
")";
301 $item_id = $this->
getId();
302 $mob_id = $this->getMobId();
303 $nr = $this->getNr();
306 $query =
"SELECT * FROM media_item WHERE id = " .
308 } elseif ($mob_id > 0 && $nr > 0) {
309 $query =
"SELECT * FROM media_item WHERE mob_id = " .
310 $ilDB->quote($this->getMobId(),
"integer") .
" " .
311 "AND nr=" .
$ilDB->quote($this->getNr(),
"integer");
315 $item_rec =
$ilDB->fetchAssoc($item_set);
317 $this->setLocation((
string) $item_rec[
"location"]);
318 $this->setLocationType((
string) $item_rec[
"location_type"]);
319 $this->setFormat((
string) $item_rec[
"format"]);
320 $this->setWidth((
string) $item_rec[
"width"]);
321 $this->setHeight((
string) $item_rec[
"height"]);
322 $this->setHAlign((
string) $item_rec[
"halign"]);
323 $this->setCaption((
string) $item_rec[
"caption"]);
324 $this->setPurpose((
string) $item_rec[
"purpose"]);
325 $this->setNr((
int) $item_rec[
"nr"]);
326 $this->setMobId((
int) $item_rec[
"mob_id"]);
327 $this->setId((
int) $item_rec[
"id"]);
328 $this->setThumbTried((
string) $item_rec[
"tried_thumb"]);
329 $this->setTextRepresentation((
string) $item_rec[
"text_representation"]);
330 $this->setUploadHash((
string) $item_rec[
"upload_hash"]);
331 $this->setDuration((
int) $item_rec[
"duration"]);
334 $query =
"SELECT * FROM mob_parameter WHERE med_item_id = " .
337 while ($par_rec =
$ilDB->fetchAssoc($par_set)) {
338 $this->setParameter($par_rec[
"name"], $par_rec[
"value"]);
343 for (
$i = 1;
$i <= $max;
$i++) {
345 $this->addMapArea($area);
357 $q =
"UPDATE media_item SET tried_thumb = " .
358 $ilDB->quote($a_tried,
"text") .
359 " WHERE id = " .
$ilDB->quote($this->
getId(),
"integer");
361 $ilDB->manipulate($q);
373 $query =
"SELECT * FROM media_item WHERE mob_id = " .
374 $ilDB->quote($a_mob_id,
"integer") .
" " .
375 "AND purpose = " .
$ilDB->quote($a_purpose,
"text");
377 if ($rec =
$ilDB->fetchAssoc($set)) {
378 return $rec[
"location"];
392 $query =
"SELECT * FROM media_item WHERE id = " .
393 $ilDB->quote($a_med_id,
"integer");
395 if ($rec =
$ilDB->fetchAssoc($set)) {
396 return (
int) $rec[
"mob_id"];
417 $query =
"SELECT * FROM media_item WHERE mob_id = " .
418 $ilDB->quote($a_mobId,
"integer") .
" " .
419 "AND purpose=" .
$ilDB->quote($a_purpose,
"text") .
" ORDER BY nr";
422 while ($item_rec =
$ilDB->fetchAssoc($item_set)) {
439 $query =
"SELECT * FROM media_item WHERE mob_id = " .
440 $ilDB->quote($a_mob->
getId(),
"integer") .
" " .
443 while ($item_rec =
$ilDB->fetchAssoc($item_set)) {
445 $media_item->setNr((
int) $item_rec[
"nr"]);
446 $media_item->setId((
int) $item_rec[
"id"]);
447 $media_item->setLocation((
string) $item_rec[
"location"]);
448 $media_item->setLocationType((
string) $item_rec[
"location_type"]);
449 $media_item->setFormat((
string) $item_rec[
"format"]);
450 $media_item->setWidth((
string) $item_rec[
"width"]);
451 $media_item->setHeight((
string) $item_rec[
"height"]);
452 $media_item->setHAlign((
string) $item_rec[
"halign"]);
453 $media_item->setCaption((
string) $item_rec[
"caption"]);
454 $media_item->setPurpose((
string) $item_rec[
"purpose"]);
455 $media_item->setMobId((
int) $item_rec[
"mob_id"]);
456 $media_item->setThumbTried((
string) $item_rec[
"tried_thumb"]);
457 $media_item->setTextRepresentation((
string) $item_rec[
"text_representation"]);
458 $media_item->setUploadHash((
string) $item_rec[
"upload_hash"]);
459 $media_item->setDuration((
int) $item_rec[
"duration"]);
462 $query =
"SELECT * FROM mob_parameter WHERE med_item_id = " .
463 $ilDB->quote($item_rec[
"id"],
"integer");
465 while ($par_rec =
$ilDB->fetchAssoc($par_set)) {
466 $media_item->setParameter($par_rec[
"name"], $par_rec[
"value"]);
471 for (
$i = 1;
$i <= $max;
$i++) {
473 $media_item->addMapArea($area);
488 $query =
"SELECT * FROM media_item WHERE mob_id = " .
489 $ilDB->quote($a_mob_id,
"integer");
491 while ($item_rec =
$ilDB->fetchAssoc($item_set)) {
493 $query =
"DELETE FROM mob_parameter WHERE med_item_id = " .
494 $ilDB->quote($item_rec[
"id"],
"integer");
498 $query =
"DELETE FROM map_area WHERE item_id = " .
499 $ilDB->quote($item_rec[
"id"],
"integer");
504 $query =
"DELETE FROM media_item WHERE mob_id = " .
505 $ilDB->quote($a_mob_id,
"integer");
511 $this->purpose = $a_purpose;
516 return $this->purpose;
521 $this->location = $a_location;
531 $this->location_type = $a_type;
536 return $this->location_type;
541 $this->format = $a_format;
551 $this->tried_thumb = $a_tried;
556 return $this->tried_thumb;
561 $this->mapareas[$this->map_cnt] = $a_map_area;
567 for (
$i = 1;
$i <= $this->map_cnt;
$i++) {
569 $this->mapareas[
$i - 2] = $this->mapareas[
$i - 1];
570 $this->mapareas[
$i - 2]->setNr(
$i - 1);
573 if ($nr <= $this->map_cnt) {
574 unset($this->mapareas[$this->map_cnt - 1]);
581 return $this->mapareas[$nr - 1] ??
null;
586 return $this->mapareas;
596 $this->width = $a_width;
601 return $this->height;
606 $this->height = $a_height;
614 if ($this->getLocationType() ==
"LocalFile") {
615 $loc = $mob_dir .
"/" . $this->getLocation();
617 $loc = $this->getLocation();
621 if ($size[0] > 0 && $size[1] > 0) {
622 return array(
"width" => $size[0],
"height" => $size[1]);
631 $this->caption = $a_caption;
636 return $this->caption;
644 $this->halign = $a_halign;
649 return $this->halign;
656 if (self::checkParameter($a_name, $a_value)) {
657 $this->parameters[$a_name] = $a_value;
663 $this->parameters = [];
671 $this->resetParameters();
673 if (is_array($par_arr)) {
674 foreach ($par_arr as $par => $val) {
675 $this->setParameter($par, $val);
688 if (substr(strtolower(trim($a_par)), 0, 2) ==
"on") {
692 if (is_int(strpos(strtolower($a_val),
"javascript"))) {
696 if (strtolower(trim($a_par)) ==
"src") {
705 return $this->parameters;
710 if (is_array($this->parameters)) {
712 foreach ($this->parameters as $par => $val) {
722 return (
string) ($this->parameters[$a_name] ??
"");
741 $work_dir = $this->getWorkDirectory();
742 if (!is_dir($work_dir)) {
752 $loc_arr = explode(
".", $this->getLocation());
754 return $loc_arr[count($loc_arr) - 1];
762 return self::getGDSupportedImageType($this->getSuffix());
770 bool $a_reference_copy =
false
772 $file_arr = explode(
"/", $this->getLocation());
773 $o_file = $file_arr[count($file_arr) - 1];
774 $file_arr = explode(
".", $o_file);
775 unset($file_arr[count($file_arr) - 1]);
776 $file = implode(
".", $file_arr);
778 if (!$a_reference_copy) {
779 return $this->getWorkDirectory() .
"/" . $file .
"." . $this->getMapWorkCopyType();
781 return $this->getWorkDirectory() .
"/l_copy_" . $o_file;
797 string $a_mode =
"filesystem"
808 $jpeg_file = $this->getThumbnailDirectory() .
"/" .
809 $this->getPurpose() .
".jpeg";
811 if (is_file($jpeg_file)) {
814 if (is_int(strpos($this->getFormat(),
"image"))) {
815 $thumb_file = $this->getThumbnailDirectory() .
"/" .
816 $this->getPurpose() .
"." .
$format;
817 $thumb_file_small = $this->getThumbnailDirectory() .
"/" .
818 $this->getPurpose() .
"_small." .
$format;
820 if ($this->getThumbTried() ==
"n" && $this->getLocationType() ==
"LocalFile" && $this->getFormat() !==
"image/svg+xml") {
821 if (is_file($thumb_file)) {
824 if (is_file($thumb_file_small)) {
825 unlink($thumb_file_small);
827 $this->writeThumbTried(
"y");
829 $med_file = $this->getDirectory() .
"/" . $this->getLocation();
831 if (is_file($med_file)) {
833 $mob->makeThumbnail($this->getLocation(), $this->getPurpose() .
"." .
$format,
$format,
"80");
834 $mob->makeThumbnail($this->getLocation(), $this->getPurpose() .
"_small." .
$format,
$format,
"40");
837 if ($this->getFormat() ===
"image/svg+xml") {
840 if ($a_size ==
"small") {
841 if (is_file($thumb_file_small)) {
842 $random = new \ilRandom();
843 return $this->getThumbnailDirectory(
"output") .
"/" .
844 $this->getPurpose() .
"_small." .
$format .
"?dummy=" . $random->int(1, 999999);
847 if (is_file($thumb_file)) {
848 $random = new \ilRandom();
849 return $this->getThumbnailDirectory(
"output") .
"/" .
850 $this->getPurpose() .
"." .
$format .
"?dummy=" . $random->int(1, 999999);
866 $this->createWorkDirectory();
868 $geom = ($this->getWidth() !=
"" && $this->getHeight() !=
"")
869 ? $this->getWidth() .
"x" . $this->getHeight()
872 if ($this->getLocationType() !==
"Reference") {
874 $this->getDirectory() .
"/" . $this->getLocation(),
875 $this->getMapWorkCopyName(),
876 $this->getMapWorkCopyType(),
881 if (!is_file($this->getMapWorkCopyName(
true)) || (filesize($this->getMapWorkCopyName(
true)) == 0)) {
882 $handle = fopen($this->getLocation(),
"r");
883 $lcopy = fopen($this->getMapWorkCopyName(
true),
"w");
884 if ($handle && $lcopy) {
885 while (!feof($handle)) {
886 $content = fread($handle, 4096);
887 fwrite($lcopy, $content);
896 $this->getMapWorkCopyName(
true),
897 $this->getMapWorkCopyName(),
898 $this->getMapWorkCopyType(),
902 if (!is_file($this->getMapWorkCopyName())) {
914 bool $a_exclude =
false
918 $this->copyOriginal();
919 $this->buildMapWorkImage();
922 $size = getimagesize($this->getMapWorkCopyName());
924 if ($size[0] > 0 && $this->getWidth() > 0) {
925 $x_ratio = $this->getWidth() / $size[0];
928 if ($size[1] > 0 && $this->getHeight() > 0) {
929 $y_ratio = $this->getHeight() / $size[1];
933 for (
$i = 0;
$i < count($this->mapareas);
$i++) {
934 if ((((
$i + 1) == $a_area_nr) && !$a_exclude) ||
935 (((
$i + 1) != $a_area_nr) && $a_exclude) ||
938 $area = $this->mapareas[
$i];
940 $this->getMapWorkImage(),
950 $this->saveMapWorkImage();
962 $this->buildMapWorkImage();
965 $size = getimagesize($this->getMapWorkCopyName());
967 if ($size[0] > 0 && $this->getWidth() > 0) {
968 $x_ratio = $this->getWidth() / $size[0];
971 if ($size[1] > 0 && $this->getHeight() > 0) {
972 $y_ratio = $this->getHeight() / $size[1];
977 $area->setShape($a_shape);
978 $area->setCoords($a_coords);
980 $this->getMapWorkImage(),
988 $this->saveMapWorkImage();
996 if ($this->getMapWorkCopyType() !=
"") {
997 header(
"Pragma: no-cache");
998 header(
"Expires: 0");
999 header(
"Content-type: image/" . strtolower($this->getMapWorkCopyType()));
1000 readfile($this->getMapWorkCopyName());
1010 $im_type = strtolower($this->getMapWorkCopyType());
1014 $this->map_image = imagecreatefromgif($this->getMapWorkCopyName());
1019 $this->map_image = imagecreatefromjpeg($this->getMapWorkCopyName());
1023 $this->map_image = imagecreatefrompng($this->getMapWorkCopyName());
1028 if (imagecolorstotal($this->map_image) > 250) {
1029 $this->color1 = imagecolorclosest($this->map_image, 0, 0, 0);
1030 $this->color2 = imagecolorclosest($this->map_image, 255, 255, 255);
1032 $this->color1 = imagecolorallocate($this->map_image, 0, 0, 0);
1033 $this->color2 = imagecolorallocate($this->map_image, 255, 255, 255);
1042 $im_type = strtolower($this->getMapWorkCopyType());
1047 imagegif($this->map_image, $this->getMapWorkCopyName());
1052 imagejpeg($this->map_image, $this->getMapWorkCopyName());
1056 imagepng($this->map_image, $this->getMapWorkCopyName());
1060 imagedestroy($this->map_image);
1068 return $this->map_image;
1075 bool $a_insert_inst =
false,
1081 for (
$i = 0;
$i < count($this->mapareas);
$i++) {
1082 $area = $this->mapareas[
$i];
1086 if ($area->getHighlightMode() !=
"") {
1087 $hm =
' HighlightMode="' . $area->getHighlightMode() .
'" ';
1088 $hcl = ($area->getHighlightClass() !=
"")
1089 ? $area->getHighlightClass()
1091 $hm .=
'HighlightClass="' . $hcl .
'" ';
1094 $xml .=
"<MapArea Shape=\"" . $area->getShape() .
"\" Coords=\"" . $area->getCoords() .
"\" " . $hm .
">";
1096 $target_frame = $area->getTargetFrame();
1098 if ($area->getType() ==
"GlossaryItem" && $target_frame ==
"") {
1099 $target_frame =
"Glossary";
1102 $tf_str = ($target_frame ==
"")
1104 :
"TargetFrame=\"" . $target_frame .
"\"";
1106 $xml .=
"<IntLink Target=\"" . $area->getTarget($a_insert_inst, $a_inst) .
"\" Type=\"" .
1107 $area->getType() .
"\" $tf_str>";
1109 $xml .= htmlspecialchars($area->getTitle(), ENT_QUOTES);
1110 $xml .=
"</IntLink>";
1112 $xml .=
"<ExtLink Href=\"" . str_replace(
"&",
"&", $area->getHref()) .
"\" Title=\"" .
1113 str_replace(
"&",
"&", $area->getExtTitle()) .
"\">";
1114 $xml .= str_replace(
"&",
"&", $area->getTitle());
1115 $xml .=
"</ExtLink>";
1117 $xml .=
"</MapArea>";
1135 $query =
"SELECT * FROM media_item WHERE mob_id = " .
1136 $ilDB->quote($a_mob_id,
"integer") .
" " .
1139 while ($item_rec =
$ilDB->fetchAssoc($item_set)) {
1156 $query =
"SELECT * FROM media_item WHERE mob_id = " .
1157 $ilDB->quote($a_mob_id,
"integer") .
" ORDER BY nr";
1161 while ($item_rec =
$ilDB->fetchAssoc($item_set)) {
1163 foreach ($map_links as
$key => $map_link) {
1164 $links[
$key] = $map_link;
1176 $this->getLocation(),
1177 $this->getParameters()
1179 foreach ($par as $k => $v) {
1180 $this->setParameter($k, $v);
1191 if ($meta[
"duration"] > 0) {
1192 $this->setDuration((
int) $meta[
"duration"]);
1195 $file = ($this->getLocationType() ==
"Reference")
1196 ? $this->getLocation()
1202 if (substr($file, 0, 4) ==
"http") {
1203 if ($fp_remote = fopen($file,
'rb')) {
1206 $localtempfilename = tempnam($tmpdir,
'getID3');
1207 if ($fp_local = fopen($localtempfilename,
'wb')) {
1208 while ($buffer = fread($fp_remote, 8192)) {
1209 fwrite($fp_local, $buffer);
1212 $file = $localtempfilename;
1218 $ana->setFile($file);
1219 $ana->analyzeFile();
1220 $this->setDuration((
int) $ana->getPlaytimeSeconds());
1223 unlink($localtempfilename);
1225 }
catch (Exception
$e) {
1240 $db =
$DIC->database();
1243 "SELECT * FROM media_item " .
1244 " WHERE upload_hash = %s ",
1248 $media_items = array();
1250 $media_items[] = $rec;
1252 return $media_items;
$location
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static makeDir(string $a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
static ilTempnam(?string $a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
static getDataDir()
get data directory (outside webspace)
static createDirectory(string $a_dir, int $a_mod=0755)
create directory
static _resolveIntLinks(int $a_item_id)
resolve internal links of an item id
static _getMaxNr(int $a_item_id)
get maximum nr of media item (static)
static _getIntLinks(int $a_item_id)
get all internal links of a media items map areas
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static convertImage(string $a_from, string $a_to, string $a_target_format="", string $a_geometry="", string $a_background_color="")
convert image
static deducibleSize(string $a_mime)
checks if mime type is provided by getimagesize()
static extractParameterString(string $a_parstr)
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
fetchAssoc(ilDBStatement $statement)
queryF(string $query, array $types, array $values)
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params