ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilPCMediaObject.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once("./Services/COPage/classes/class.ilPageContent.php");
5
17{
21 protected $user;
22
23 protected $mob_node;
24
28 protected $ui;
29
33 protected $mediaobject;
34
38 protected $lng;
39
43 public function init()
44 {
45 global $DIC;
46
47 $this->user = $DIC->user();
48 $this->setType("media");
49 $this->ui = $DIC->ui();
50 $this->lng = $DIC->language();
51 }
52
58 public function readMediaObject($a_mob_id = 0)
59 {
60 if ($a_mob_id > 0) {
61 $mob = new ilObjMediaObject($a_mob_id);
62 $this->setMediaObject($mob);
63 }
64 }
65
66 public function setNode($a_node)
67 {
68 parent::setNode($a_node); // this is the PageContent node
69 $this->mob_node = $a_node->first_child();
70 }
71
75 public function setDom(&$a_dom)
76 {
77 $this->dom = $a_dom;
78 }
79
83 public function setHierId($a_hier_id)
84 {
85 $this->hier_id = $a_hier_id;
86 }
87
93 public function setMediaObject($a_mediaobject)
94 {
95 $this->mediaobject = $a_mediaobject;
96 }
97
104 {
105 return $this->mediaobject;
106 }
107
108 public function createMediaObject()
109 {
110 $this->setMediaObject(new ilObjMediaObject());
111 }
112
116 public function create(&$a_pg_obj, $a_hier_id)
117 {
118 $this->node = $this->createPageContentNode();
119 }
120
127 public function createAlias(&$a_pg_obj, $a_hier_id, $a_pc_id = "")
128 {
129 $this->node = $this->dom->create_element("PageContent");
130 $a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);
131 $this->mob_node = $this->dom->create_element("MediaObject");
132 $this->mob_node = $this->node->append_child($this->mob_node);
133 $this->mal_node = $this->dom->create_element("MediaAlias");
134 $this->mal_node = $this->mob_node->append_child($this->mal_node);
135 $this->mal_node->set_attribute("OriginId", "il__mob_" . $this->getMediaObject()->getId());
136
137 // standard view
138 $item_node = $this->dom->create_element("MediaAliasItem");
139 $item_node = $this->mob_node->append_child($item_node);
140 $item_node->set_attribute("Purpose", "Standard");
141 $media_item = $this->getMediaObject()->getMediaItem("Standard");
142
143 $layout_node = $this->dom->create_element("Layout");
144 $layout_node = $item_node->append_child($layout_node);
145 if ($media_item->getWidth() > 0) {
146 //$layout_node->set_attribute("Width", $media_item->getWidth());
147 }
148 if ($media_item->getHeight() > 0) {
149 //$layout_node->set_attribute("Height", $media_item->getHeight());
150 }
151 $layout_node->set_attribute("HorizontalAlign", "Left");
152
153 // caption
154 if ($media_item->getCaption() != "") {
155 $cap_node = $this->dom->create_element("Caption");
156 $cap_node = $item_node->append_child($cap_node);
157 $cap_node->set_attribute("Align", "bottom");
158 $cap_node->set_content($media_item->getCaption());
159 }
160
161 // text representation
162 if ($media_item->getTextRepresentation() != "") {
163 $tr_node = $this->dom->create_element("TextRepresentation");
164 $tr_node = $item_node->append_child($tr_node);
165 $tr_node->set_content($media_item->getTextRepresentation());
166 }
167
168 $pars = $media_item->getParameters();
169 foreach ($pars as $par => $val) {
170 $par_node = $this->dom->create_element("Parameter");
171 $par_node = $item_node->append_child($par_node);
172 $par_node->set_attribute("Name", $par);
173 $par_node->set_attribute("Value", $val);
174 }
175
176 // fullscreen view
177 $fullscreen_item = $this->getMediaObject()->getMediaItem("Fullscreen");
178 if (is_object($fullscreen_item)) {
179 $item_node = $this->dom->create_element("MediaAliasItem");
180 $item_node = $this->mob_node->append_child($item_node);
181 $item_node->set_attribute("Purpose", "Fullscreen");
182
183 // width and height
184 $layout_node = $this->dom->create_element("Layout");
185 $layout_node = $item_node->append_child($layout_node);
186 if ($fullscreen_item->getWidth() > 0) {
187 $layout_node->set_attribute("Width", $fullscreen_item->getWidth());
188 }
189 if ($fullscreen_item->getHeight() > 0) {
190 $layout_node->set_attribute("Height", $fullscreen_item->getHeight());
191 }
192
193 // caption
194 if ($fullscreen_item->getCaption() != "") {
195 $cap_node = $this->dom->create_element("Caption");
196 $cap_node = $item_node->append_child($cap_node);
197 $cap_node->set_attribute("Align", "bottom");
198 $cap_node->set_content($fullscreen_item->getCaption());
199 }
200
201 // text representation
202 if ($fullscreen_item->getTextRepresentation() != "") {
203 $tr_node = $this->dom->create_element("TextRepresentation");
204 $tr_node = $item_node->append_child($tr_node);
205 $tr_node->set_content($fullscreen_item->getTextRepresentation());
206 }
207
208 $pars = $fullscreen_item->getParameters();
209 foreach ($pars as $par => $val) {
210 $par_node = $this->dom->create_element("Parameter");
211 $par_node = $item_node->append_child($par_node);
212 $par_node->set_attribute("Name", $par);
213 $par_node->set_attribute("Value", $val);
214 }
215 }
216 }
217
223 public function updateObjectReference()
224 {
225 if (is_object($this->mob_node)) {
226 $this->mal_node = $this->mob_node->first_child();
227 if (is_object($this->mal_node) && $this->mal_node->node_name() == "MediaAlias") {
228 $this->mal_node->set_attribute("OriginId", "il__mob_" . $this->getMediaObject()->getId());
229 }
230 }
231 }
232
236 public function dumpXML()
237 {
238 $xml = $this->dom->dump_node($this->node);
239 return $xml;
240 }
241
247 public function setClass($a_class)
248 {
249 if (is_object($this->mob_node)) {
250 $mal_node = $this->mob_node->first_child();
251 if (is_object($mal_node)) {
252 if (!empty($a_class)) {
253 $mal_node->set_attribute("Class", $a_class);
254 } else {
255 if ($mal_node->has_attribute("Class")) {
256 $mal_node->remove_attribute("Class");
257 }
258 }
259 }
260 }
261 }
262
268 public function getClass()
269 {
270 if (is_object($this->mob_node)) {
271 $mal_node = $this->mob_node->first_child();
272 if (is_object($mal_node)) {
273 $class = $mal_node->get_attribute("Class");
274 return $class;
275 }
276 }
277 }
278
283 public static function getLangVars()
284 {
285 return array("pc_mob");
286 }
287
296 public static function afterPageUpdate($a_page, DOMDocument $a_domdoc, $a_xml, $a_creation)
297 {
298 if (!$a_page->getImportMode()) {
299 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
301 $a_page->getParentType() . ":pg",
302 $a_page->getId(),
303 0,
304 $a_page->getLanguage()
305 );
306 self::saveMobUsage($a_page, $a_domdoc);
307 foreach ($mob_ids as $mob) { // check, whether media object can be deleted
308 if (ilObject::_exists($mob) && ilObject::_lookupType($mob) == "mob") {
309 $mob_obj = new ilObjMediaObject($mob);
310 $usages = $mob_obj->getUsages(false);
311 if (count($usages) == 0) { // delete, if no usage exists
312 $mob_obj->delete();
313 }
314 }
315 }
316 }
317 }
318
324 public static function beforePageDelete($a_page)
325 {
326 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
328 $a_page->getParentType() . ":pg",
329 $a_page->getId(),
330 0,
331 $a_page->getLanguage()
332 );
333
335 $a_page->getParentType() . ":pg",
336 $a_page->getId(),
337 false,
338 $a_page->getLanguage()
339 );
340
341 foreach ($mob_ids as $mob) { // check, whether media object can be deleted
342 if (ilObject::_exists($mob) && ilObject::_lookupType($mob) == "mob") {
343 $mob_obj = new ilObjMediaObject($mob);
344 $usages = $mob_obj->getUsages(false);
345 if (count($usages) == 0) { // delete, if no usage exists
346 $mob_obj->delete();
347 }
348 }
349 }
350 }
351
360 public static function afterPageHistoryEntry($a_page, DOMDocument $a_old_domdoc, $a_old_xml, $a_old_nr)
361 {
362 self::saveMobUsage($a_page, $a_old_domdoc, $a_old_nr);
363 }
364
370 public static function saveMobUsage($a_page, $a_domdoc, $a_old_nr = 0)
371 {
372 $usages = array();
373
374 // media aliases
375 $xpath = new DOMXPath($a_domdoc);
376 $nodes = $xpath->query('//MediaAlias');
377 foreach ($nodes as $node) {
378 $id_arr = explode("_", $node->getAttribute("OriginId"));
379 $mob_id = $id_arr[count($id_arr) - 1];
380 if ($mob_id > 0 && $id_arr[1] == "") {
381 $usages[$mob_id] = true;
382 }
383 }
384
385 // media objects
386 $xpath = new DOMXPath($a_domdoc);
387 $nodes = $xpath->query('//MediaObject/MetaData/General/Identifier');
388 foreach ($nodes as $node) {
389 $mob_entry = $node->getAttribute("Entry");
390 $mob_arr = explode("_", $mob_entry);
391 $mob_id = $mob_arr[count($mob_arr) - 1];
392 if ($mob_id > 0 && $mob_arr[1] == "") {
393 $usages[$mob_id] = true;
394 }
395 }
396
397 // internal links
398 $xpath = new DOMXPath($a_domdoc);
399 $nodes = $xpath->query("//IntLink[@Type='MediaObject']");
400 foreach ($nodes as $node) {
401 $mob_target = $node->getAttribute("Target");
402 $mob_arr = explode("_", $mob_target);
403 //echo "<br>3<br>";
404 //echo $mob_target."<br>";
405 //var_dump($mob_arr);
406 $mob_id = $mob_arr[count($mob_arr) - 1];
407 if ($mob_id > 0 && $mob_arr[1] == "") {
408 $usages[$mob_id] = true;
409 }
410 }
411
412 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
414 $a_page->getParentType() . ":pg",
415 $a_page->getId(),
416 $a_old_nr,
417 $a_page->getLanguage()
418 );
419 foreach ($usages as $mob_id => $val) {
420 // save usage, if object exists...
421 if (ilObject::_lookupType($mob_id) == "mob") {
423 $mob_id,
424 $a_page->getParentType() . ":pg",
425 $a_page->getId(),
426 $a_old_nr,
427 $a_page->getLanguage()
428 );
429 }
430 }
431
432 return $usages;
433 }
434
438 public function modifyPageContentPostXsl($a_html, $a_mode, $a_abstract_only = false)
439 {
441
442 if ($a_mode == "offline") {
443 $page = $this->getPage();
444
446 $page->getParentType() . ":pg",
447 $page->getId(),
448 0,
449 $page->getLanguage()
450 );
451 foreach ($mob_ids as $mob_id) {
452 $mob = new ilObjMediaObject($mob_id);
453 $srts = $mob->getSrtFiles();
454 foreach ($srts as $srt) {
455 if ($ilUser->getLanguage() == $srt["language"]) {
456 $srt_content = file_get_contents(ilObjMediaObject::_getDirectory($mob->getId()) . "/" . $srt["full_path"]);
457 $a_html = str_replace("[[[[[mobsubtitle;il__mob_" . $mob->getId() . "_Standard]]]]]", $srt_content, $a_html);
458 }
459 }
460 }
461 }
462
463 if ($a_abstract_only) {
464 return $a_html;
465 }
466
467 // add fullscreen modals
468 $page = $this->getPage();
469 $suffix = "-" . $page->getParentType() . "-" . $page->getId();
470 $modal = $this->ui->factory()->modal()->roundtrip(
471 $this->lng->txt("cont_fullscreen"),
472 $this->ui->factory()->legacy("<iframe class='il-copg-mob-fullscreen' id='il-copg-mob-fullscreen" . $suffix . "'></iframe>")
473 );
474 $show_signal = $modal->getShowSignal();
475
476 return $a_html . "<div class='il-copg-mob-fullscreen-modal'>" . $this->ui->renderer()->render($modal) . "</div><script>$(function () { il.COPagePres.setFullscreenModalShowSignal('" .
477 $show_signal . "', '" . $suffix . "'); });</script>";
478 }
479
483 public function getJavascriptFiles($a_mode)
484 {
485 $js_files = ilPlayerUtil::getJsFilePaths();
487 return $js_files;
488 }
489
493 public function getCssFiles($a_mode)
494 {
495 $js_files = ilPlayerUtil::getCssFilePaths();
496
497 return $js_files;
498 }
499
504 {
505 $std_alias_item = new ilMediaAliasItem(
506 $this->dom,
507 $this->getHierId(),
508 "Standard",
509 $this->getPcId()
510 );
511 return $std_alias_item;
512 }
513
518 {
519 $std_alias_item = new ilMediaAliasItem(
520 $this->dom,
521 $this->getHierId(),
522 "Fullscreen",
523 $this->getPcId()
524 );
525 return $std_alias_item;
526 }
527
531 public function checkInstanceEditing() : bool
532 {
533 // if any properties are set on the instance,
534 // that are not accessible through the quick editing screen
535 // -> offer instance editing
536 $std_alias_item = $this->getStandardMediaAliasItem();
537 if ($std_alias_item->hasAnyPropertiesSet()) {
538 return true;
539 }
540 if ($this->getMediaObject()->hasFullScreenItem()) {
541 $full_alias_item = $this->getFullscreenMediaAliasItem();
542 if ($full_alias_item->hasAnyPropertiesSet()) {
543 return true;
544 }
545 }
546
547 // if the media object has any other use outside of the current page
548 // -> offer instance editing
550 $mob = $this->getMediaObject();
551 $page = $this->getPage();
552 if (is_object($mob)) {
553 $usages = $mob->getUsages();
554 $other_usages = array_filter($usages, function ($usage) use ($page) {
555 return ($usage["type"] != $page->getParentType() . ":pg" || $usage["id"] != $page->getId());
556 });
557 if (count($other_usages) > 0) {
558 return true;
559 }
560 }
561
562 // see https://mantis.ilias.de/view.php?id=38582
563 // we allow instance editing regardless of number of usages
564 return true;
565 }
566}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
const IL_INSERT_AFTER
Class ilMediaAliasItem.
Class ilObjMediaObject.
static _deleteAllUsages($a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
static
static _saveUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
Save usage of mob within another container (e.g.
static _getMobsOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
get mobs of object
static _getDirectory($a_mob_id)
Get absolute directory.
static _exists($a_id, $a_reference=false, $a_type=null)
checks if an object exists in object_data@access public
static _lookupType($a_id, $a_reference=false)
lookup object type
Class ilPCMediaObject.
static beforePageDelete($a_page)
Before page is being deleted.
getJavascriptFiles($a_mode)
@inheritDoc
static saveMobUsage($a_page, $a_domdoc, $a_old_nr=0)
Save all usages of media objects (media aliases, media objects, internal links)
modifyPageContentPostXsl($a_html, $a_mode, $a_abstract_only=false)
@inheritDoc
readMediaObject($a_mob_id=0)
Read/get Media Object.
setClass($a_class)
Set Style Class of table.
updateObjectReference()
Updates the media object referenced by the media alias.
setNode($a_node)
Set xml node of page content.
createAlias(&$a_pg_obj, $a_hier_id, $a_pc_id="")
Create an media alias in page.
getClass()
Get characteristic of section.
setMediaObject($a_mediaobject)
Set Media Object.
static afterPageUpdate($a_page, DOMDocument $a_domdoc, $a_xml, $a_creation)
After page has been updated (or created)
dumpXML()
Dump node xml.
init()
Init page content component.
static getLangVars()
Get lang vars needed for editing.
create(&$a_pg_obj, $a_hier_id)
Create pc media object.
setHierId($a_hier_id)
set hierarchical edit id
getCssFiles($a_mode)
@inheritDoc
getMediaObject()
Get Media Object.
setDom(&$a_dom)
set dom object
static afterPageHistoryEntry($a_page, DOMDocument $a_old_domdoc, $a_old_xml, $a_old_nr)
After page history entry has been created.
Class ilPageContent.
createPageContentNode($a_set_this_node=true)
Create page content node (always use this method first when adding a new element)
getHierId()
Get hierarchical id.
setType($a_type)
Set Type.
static getJsFilePaths()
Get js file paths.
static getCssFilePaths()
Get css file paths.
static getLocalMaphilightPath()
Get local path of maphilight file.
global $DIC
Definition: goto.php:24
$ilUser
Definition: imgupload.php:18
$xml
Definition: metadata.php:332
ui()
Definition: ui.php:5