60 $this->db = $DIC->database();
61 $this->
lng = $DIC->language();
62 $this->image_converter = $DIC->fileConverters()->legacyImages();
63 $this->parameters = array();
64 $this->mapareas = array();
76 public function setId(
int $a_id): void
91 $this->mob_id = $a_mob_id;
102 public function setNr(
int $a_nr): void
121 $a_desired_type = strtolower($a_desired_type);
123 $im_types = ImageTypes();
125 switch ($a_desired_type) {
128 if ($im_types & IMG_JPG) {
131 if ($im_types & IMG_GIF) {
134 if ($im_types & IMG_PNG) {
140 if ($im_types & IMG_GIF) {
143 if ($im_types & IMG_JPG) {
146 if ($im_types & IMG_PNG) {
153 if ($im_types & IMG_PNG) {
156 if ($im_types & IMG_JPG) {
159 if ($im_types & IMG_GIF) {
170 $this->duration = $a_val;
180 $this->text_representation = $a_val;
190 $this->upload_hash = $a_val;
202 $item_id =
$ilDB->nextId(
"media_item");
203 $query =
"INSERT INTO media_item (id,mob_id, purpose, location, " .
204 "location_type, format, width, " .
205 "height, halign, caption, nr, text_representation, upload_hash, duration) VALUES " .
207 $ilDB->quote($item_id,
"integer") .
"," .
217 $ilDB->quote($this->
getNr(),
"integer") .
"," .
222 $ilDB->manipulate($query);
224 $this->
setId($item_id);
228 foreach (
$params as $name => $value) {
229 $query =
"INSERT INTO mob_parameter (med_item_id, name, value) VALUES " .
230 "(" .
$ilDB->quote($item_id,
"integer") .
"," .
231 $ilDB->quote($name,
"text") .
"," .
232 $ilDB->quote($value,
"text") .
")";
233 $ilDB->manipulate($query);
237 for ($i = 0; $i < count($this->mapareas); $i++) {
238 if (is_object($this->mapareas[$i])) {
239 $this->mapareas[$i]->setItemId($this->
getId());
240 $this->mapareas[$i]->setNr($i + 1);
241 $this->mapareas[$i]->create();
250 $query =
"UPDATE media_item SET " .
251 " mob_id = " .
$ilDB->quote($this->
getMobId(),
"integer") .
"," .
256 " width = " .
$ilDB->quote($this->
getWidth(),
"text") .
"," .
260 " nr = " .
$ilDB->quote($this->
getNr(),
"integer") .
"," .
264 " WHERE id = " .
$ilDB->quote($this->
getId(),
"integer");
265 $ilDB->manipulate($query);
268 $query =
"DELETE FROM mob_parameter WHERE med_item_id = " .
270 $ilDB->manipulate($query);
274 foreach (
$params as $name => $value) {
275 $query =
"INSERT INTO mob_parameter (med_item_id, name, value) VALUES " .
276 "(" .
$ilDB->quote($this->
getId(),
"integer") .
"," .
277 $ilDB->quote($name,
"text") .
"," .
278 $ilDB->quote($value,
"text") .
")";
279 $ilDB->manipulate($query);
289 $query =
"INSERT INTO mob_parameter (med_item_id, name, value) VALUES " .
290 "(" .
$ilDB->quote($this->
getId(),
"integer") .
"," .
291 $ilDB->quote($a_name,
"text") .
"," .
292 $ilDB->quote($a_value,
"text") .
")";
293 $ilDB->manipulate($query);
303 $item_id = $this->
getId();
305 $nr = $this->
getNr();
308 $query =
"SELECT * FROM media_item WHERE id = " .
310 } elseif ($mob_id > 0 && $nr > 0) {
311 $query =
"SELECT * FROM media_item WHERE mob_id = " .
313 "AND nr=" .
$ilDB->quote($this->
getNr(),
"integer");
316 $item_set =
$ilDB->query($query);
317 $item_rec =
$ilDB->fetchAssoc($item_set);
319 $this->
setLocation((
string) $item_rec[
"location"]);
321 $this->
setFormat((
string) $item_rec[
"format"]);
322 $this->
setWidth((
string) $item_rec[
"width"]);
323 $this->
setHeight((
string) $item_rec[
"height"]);
324 $this->
setHAlign((
string) $item_rec[
"halign"]);
325 $this->
setCaption((
string) $item_rec[
"caption"]);
326 $this->
setPurpose((
string) $item_rec[
"purpose"]);
327 $this->
setNr((
int) $item_rec[
"nr"]);
328 $this->
setMobId((
int) $item_rec[
"mob_id"]);
329 $this->
setId((
int) $item_rec[
"id"]);
336 $query =
"SELECT * FROM mob_parameter WHERE med_item_id = " .
338 $par_set =
$ilDB->query($query);
339 while ($par_rec =
$ilDB->fetchAssoc($par_set)) {
340 $this->
setParameter($par_rec[
"name"], $par_rec[
"value"]);
345 for ($i = 1; $i <= $max; $i++) {
359 $q =
"UPDATE media_item SET tried_thumb = " .
360 $ilDB->quote($a_tried,
"text") .
361 " WHERE id = " .
$ilDB->quote($this->
getId(),
"integer");
372 $ilDB = $DIC->database();
375 $query =
"SELECT * FROM media_item WHERE mob_id = " .
376 $ilDB->quote($a_mob_id,
"integer") .
" " .
377 "AND purpose = " .
$ilDB->quote($a_purpose,
"text");
378 $set =
$ilDB->query($query);
379 if ($rec =
$ilDB->fetchAssoc($set)) {
380 return $rec[
"location"];
391 $ilDB = $DIC->database();
394 $query =
"SELECT * FROM media_item WHERE id = " .
395 $ilDB->quote($a_med_id,
"integer");
396 $set =
$ilDB->query($query);
397 if ($rec =
$ilDB->fetchAssoc($set)) {
398 return (
int) $rec[
"mob_id"];
416 $ilDB = $DIC->database();
419 $query =
"SELECT * FROM media_item WHERE mob_id = " .
420 $ilDB->quote($a_mobId,
"integer") .
" " .
421 "AND purpose=" .
$ilDB->quote($a_purpose,
"text") .
" ORDER BY nr";
422 $item_set =
$ilDB->query($query);
424 while ($item_rec =
$ilDB->fetchAssoc($item_set)) {
438 $ilDB = $DIC->database();
441 $query =
"SELECT * FROM media_item WHERE mob_id = " .
442 $ilDB->quote($a_mob->
getId(),
"integer") .
" " .
444 $item_set =
$ilDB->query($query);
445 while ($item_rec =
$ilDB->fetchAssoc($item_set)) {
447 $media_item->setNr((
int) $item_rec[
"nr"]);
448 $media_item->setId((
int) $item_rec[
"id"]);
449 $media_item->setLocation((
string) $item_rec[
"location"]);
450 $media_item->setLocationType((
string) $item_rec[
"location_type"]);
451 $media_item->setFormat((
string) $item_rec[
"format"]);
452 $media_item->setWidth((
string) $item_rec[
"width"]);
453 $media_item->setHeight((
string) $item_rec[
"height"]);
454 $media_item->setHAlign((
string) $item_rec[
"halign"]);
455 $media_item->setCaption((
string) $item_rec[
"caption"]);
456 $media_item->setPurpose((
string) $item_rec[
"purpose"]);
457 $media_item->setMobId((
int) $item_rec[
"mob_id"]);
458 $media_item->setThumbTried((
string) $item_rec[
"tried_thumb"]);
459 $media_item->setTextRepresentation((
string) $item_rec[
"text_representation"]);
460 $media_item->setUploadHash((
string) $item_rec[
"upload_hash"]);
461 $media_item->setDuration((
int) $item_rec[
"duration"]);
464 $query =
"SELECT * FROM mob_parameter WHERE med_item_id = " .
465 $ilDB->quote($item_rec[
"id"],
"integer");
466 $par_set =
$ilDB->query($query);
467 while ($par_rec =
$ilDB->fetchAssoc($par_set)) {
468 $media_item->setParameter($par_rec[
"name"], $par_rec[
"value"]);
473 for ($i = 1; $i <= $max; $i++) {
474 $area =
new ilMapArea($media_item->getId(), $i);
475 $media_item->addMapArea($area);
487 $ilDB = $DIC->database();
490 $query =
"SELECT * FROM media_item WHERE mob_id = " .
491 $ilDB->quote($a_mob_id,
"integer");
492 $item_set =
$ilDB->query($query);
493 while ($item_rec =
$ilDB->fetchAssoc($item_set)) {
495 $query =
"DELETE FROM mob_parameter WHERE med_item_id = " .
496 $ilDB->quote($item_rec[
"id"],
"integer");
497 $ilDB->manipulate($query);
500 $query =
"DELETE FROM map_area WHERE item_id = " .
501 $ilDB->quote($item_rec[
"id"],
"integer");
502 $ilDB->manipulate($query);
506 $query =
"DELETE FROM media_item WHERE mob_id = " .
507 $ilDB->quote($a_mob_id,
"integer");
508 $ilDB->manipulate($query);
513 $this->purpose = $a_purpose;
523 $this->location = $a_location;
533 $this->location_type = $a_type;
543 $this->format = $a_format;
553 $this->tried_thumb = $a_tried;
571 $this->mapareas[$i - 2] = $this->mapareas[$i - 1];
572 $this->mapareas[$i - 2]->setNr($i - 1);
575 if ($nr <= $this->map_cnt) {
576 unset($this->mapareas[$this->map_cnt - 1]);
583 return $this->mapareas[$nr - 1] ?? null;
598 $this->width = $a_width;
608 $this->height = $a_height;
623 if ($size[0] > 0 && $size[1] > 0) {
624 return array(
"width" => $size[0],
"height" => $size[1]);
633 $this->caption = $a_caption;
646 $this->halign = $a_halign;
658 if (self::checkParameter($a_name, $a_value)) {
659 $this->parameters[$a_name] = $a_value;
665 $this->parameters = [];
675 if (is_array($par_arr)) {
676 foreach ($par_arr as $par => $val) {
690 if (substr(strtolower(trim($a_par)), 0, 2) ==
"on") {
694 if (is_int(strpos(strtolower($a_val),
"javascript"))) {
698 if (strtolower(trim($a_par)) ==
"src") {
712 if (is_array($this->parameters)) {
714 foreach ($this->parameters as $par => $val) {
715 $target_arr[] =
"$par=\"$val\"";
717 return implode(
", ", $target_arr);
724 return (
string) ($this->parameters[$a_name] ??
"");
744 if (!is_dir($work_dir)) {
756 return $loc_arr[count($loc_arr) - 1];
764 return self::getGDSupportedImageType($this->
getSuffix());
772 bool $a_reference_copy =
false 775 $o_file = $file_arr[count($file_arr) - 1];
776 $file_arr = explode(
".", $o_file);
777 unset($file_arr[count($file_arr) - 1]);
778 $file = implode(
".", $file_arr);
780 if (!$a_reference_copy) {
799 string $a_mode =
"filesystem" 813 if (is_file($jpeg_file)) {
816 if (is_int(strpos($this->
getFormat(),
"image"))) {
823 if (is_file($thumb_file)) {
826 if (is_file($thumb_file_small)) {
827 unlink($thumb_file_small);
833 if (is_file($med_file)) {
839 if ($this->
getFormat() ===
"image/svg+xml") {
842 if ($a_size ==
"small") {
843 if (is_file($thumb_file_small)) {
844 $random = new \ilRandom();
846 $this->
getPurpose() .
"_small." . $format .
"?dummy=" . $random->int(1, 999999);
849 if (is_file($thumb_file)) {
850 $random = new \ilRandom();
852 $this->
getPurpose() .
"." . $format .
"?dummy=" . $random->int(1, 999999);
871 $this->image_converter->convertToFormat(
883 if ($handle && $lcopy) {
884 while (!feof($handle)) {
885 $content = fread($handle, 4096);
886 fwrite($lcopy, $content);
894 $this->image_converter->convertToFormat(
914 bool $a_exclude =
false 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];
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);
997 header(
"Pragma: no-cache");
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);
1060 imagedestroy($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>";
1131 $ilDB = $DIC->database();
1135 $query =
"SELECT * FROM media_item WHERE mob_id = " .
1136 $ilDB->quote($a_mob_id,
"integer") .
" " .
1138 $item_set =
$ilDB->query($query);
1139 while ($item_rec =
$ilDB->fetchAssoc($item_set)) {
1153 $ilDB = $DIC->database();
1156 $query =
"SELECT * FROM media_item WHERE mob_id = " .
1157 $ilDB->quote($a_mob_id,
"integer") .
" ORDER BY nr";
1159 $item_set =
$ilDB->query($query);
1161 while ($item_rec =
$ilDB->fetchAssoc($item_set)) {
1163 foreach ($map_links as
$key => $map_link) {
1164 $links[
$key] = $map_link;
1179 foreach ($par as $k => $v) {
1191 if ($meta[
"duration"] > 0) {
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);
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;
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
fetchAssoc(ilDBStatement $statement)
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
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
static _resolveIntLinks(int $a_item_id)
resolve internal links of an item id
static createDirectory(string $a_dir, int $a_mod=0755)
create directory
static getDataDir()
get data directory (outside webspace)
queryF(string $query, array $types, array $values)
static deducibleSize(string $a_mime)
checks if mime type is provided by getimagesize()
static ilTempnam(?string $a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
static extractParameterString(string $a_parstr)
static makeDir(string $a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...