ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 public function init()
29 {
30 global $DIC;
31
32 $this->user = $DIC->user();
33 $this->setType("media");
34 }
35
41 public function readMediaObject($a_mob_id = 0)
42 {
43 if ($a_mob_id > 0) {
44 $mob = new ilObjMediaObject($a_mob_id);
45 $this->setMediaObject($mob);
46 }
47 }
48
49 public function setNode($a_node)
50 {
51 parent::setNode($a_node); // this is the PageContent node
52 $this->mob_node = $a_node->first_child();
53 }
54
58 public function setDom(&$a_dom)
59 {
60 $this->dom = $a_dom;
61 }
62
66 public function setHierId($a_hier_id)
67 {
68 $this->hier_id = $a_hier_id;
69 }
70
76 public function setMediaObject($a_mediaobject)
77 {
78 $this->mediaobject = $a_mediaobject;
79 }
80
86 public function getMediaObject()
87 {
88 return $this->mediaobject;
89 }
90
91 public function createMediaObject()
92 {
93 $this->setMediaObject(new ilObjMediaObject());
94 }
95
99 public function create(&$a_pg_obj, $a_hier_id)
100 {
101 $this->node = $this->createPageContentNode();
102 }
103
110 public function createAlias(&$a_pg_obj, $a_hier_id, $a_pc_id = "")
111 {
112 $this->node = $this->dom->create_element("PageContent");
113 $a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);
114 $this->mob_node = $this->dom->create_element("MediaObject");
115 $this->mob_node = $this->node->append_child($this->mob_node);
116 $this->mal_node = $this->dom->create_element("MediaAlias");
117 $this->mal_node = $this->mob_node->append_child($this->mal_node);
118 $this->mal_node->set_attribute("OriginId", "il__mob_" . $this->getMediaObject()->getId());
119
120 // standard view
121 $item_node = $this->dom->create_element("MediaAliasItem");
122 $item_node = $this->mob_node->append_child($item_node);
123 $item_node->set_attribute("Purpose", "Standard");
124 $media_item = $this->getMediaObject()->getMediaItem("Standard");
125
126 $layout_node = $this->dom->create_element("Layout");
127 $layout_node = $item_node->append_child($layout_node);
128 if ($media_item->getWidth() > 0) {
129 //$layout_node->set_attribute("Width", $media_item->getWidth());
130 }
131 if ($media_item->getHeight() > 0) {
132 //$layout_node->set_attribute("Height", $media_item->getHeight());
133 }
134 $layout_node->set_attribute("HorizontalAlign", "Left");
135
136 // caption
137 if ($media_item->getCaption() != "") {
138 $cap_node = $this->dom->create_element("Caption");
139 $cap_node = $item_node->append_child($cap_node);
140 $cap_node->set_attribute("Align", "bottom");
141 $cap_node->set_content($media_item->getCaption());
142 }
143
144 // text representation
145 if ($media_item->getTextRepresentation() != "") {
146 $tr_node = $this->dom->create_element("TextRepresentation");
147 $tr_node = $item_node->append_child($tr_node);
148 $tr_node->set_content($media_item->getTextRepresentation());
149 }
150
151 $pars = $media_item->getParameters();
152 foreach ($pars as $par => $val) {
153 $par_node = $this->dom->create_element("Parameter");
154 $par_node = $item_node->append_child($par_node);
155 $par_node->set_attribute("Name", $par);
156 $par_node->set_attribute("Value", $val);
157 }
158
159 // fullscreen view
160 $fullscreen_item = $this->getMediaObject()->getMediaItem("Fullscreen");
161 if (is_object($fullscreen_item)) {
162 $item_node = $this->dom->create_element("MediaAliasItem");
163 $item_node = $this->mob_node->append_child($item_node);
164 $item_node->set_attribute("Purpose", "Fullscreen");
165
166 // width and height
167 $layout_node = $this->dom->create_element("Layout");
168 $layout_node = $item_node->append_child($layout_node);
169 if ($fullscreen_item->getWidth() > 0) {
170 $layout_node->set_attribute("Width", $fullscreen_item->getWidth());
171 }
172 if ($fullscreen_item->getHeight() > 0) {
173 $layout_node->set_attribute("Height", $fullscreen_item->getHeight());
174 }
175
176 // caption
177 if ($fullscreen_item->getCaption() != "") {
178 $cap_node = $this->dom->create_element("Caption");
179 $cap_node = $item_node->append_child($cap_node);
180 $cap_node->set_attribute("Align", "bottom");
181 $cap_node->set_content($fullscreen_item->getCaption());
182 }
183
184 // text representation
185 if ($fullscreen_item->getTextRepresentation() != "") {
186 $tr_node = $this->dom->create_element("TextRepresentation");
187 $tr_node = $item_node->append_child($tr_node);
188 $tr_node->set_content($fullscreen_item->getTextRepresentation());
189 }
190
191 $pars = $fullscreen_item->getParameters();
192 foreach ($pars as $par => $val) {
193 $par_node = $this->dom->create_element("Parameter");
194 $par_node = $item_node->append_child($par_node);
195 $par_node->set_attribute("Name", $par);
196 $par_node->set_attribute("Value", $val);
197 }
198 }
199 }
200
206 public function updateObjectReference()
207 {
208 if (is_object($this->mob_node)) {
209 $this->mal_node = $this->mob_node->first_child();
210 if (is_object($this->mal_node) && $this->mal_node->node_name() == "MediaAlias") {
211 $this->mal_node->set_attribute("OriginId", "il__mob_" . $this->getMediaObject()->getId());
212 }
213 }
214 }
215
219 public function dumpXML()
220 {
221 $xml = $this->dom->dump_node($this->node);
222 return $xml;
223 }
224
230 public function setClass($a_class)
231 {
232 if (is_object($this->mob_node)) {
233 $mal_node = $this->mob_node->first_child();
234 if (is_object($mal_node)) {
235 if (!empty($a_class)) {
236 $mal_node->set_attribute("Class", $a_class);
237 } else {
238 if ($mal_node->has_attribute("Class")) {
239 $mal_node->remove_attribute("Class");
240 }
241 }
242 }
243 }
244 }
245
251 public function getClass()
252 {
253 if (is_object($this->mob_node)) {
254 $mal_node = $this->mob_node->first_child();
255 if (is_object($mal_node)) {
256 $class = $mal_node->get_attribute("Class");
257 return $class;
258 }
259 }
260 }
261
266 public static function getLangVars()
267 {
268 return array("pc_mob");
269 }
270
279 public static function afterPageUpdate($a_page, DOMDocument $a_domdoc, $a_xml, $a_creation)
280 {
281 if (!$a_page->getImportMode()) {
282 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
284 $a_page->getParentType() . ":pg",
285 $a_page->getId(),
286 0,
287 $a_page->getLanguage()
288 );
289 self::saveMobUsage($a_page, $a_domdoc);
290 foreach ($mob_ids as $mob) { // check, whether media object can be deleted
291 if (ilObject::_exists($mob) && ilObject::_lookupType($mob) == "mob") {
292 $mob_obj = new ilObjMediaObject($mob);
293 $usages = $mob_obj->getUsages(false);
294 if (count($usages) == 0) { // delete, if no usage exists
295 $mob_obj->delete();
296 }
297 }
298 }
299 }
300 }
301
307 public static function beforePageDelete($a_page)
308 {
309 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
311 $a_page->getParentType() . ":pg",
312 $a_page->getId(),
313 0,
314 $a_page->getLanguage()
315 );
316
318 $a_page->getParentType() . ":pg",
319 $a_page->getId(),
320 false,
321 $a_page->getLanguage()
322 );
323
324 foreach ($mob_ids as $mob) { // check, whether media object can be deleted
325 if (ilObject::_exists($mob) && ilObject::_lookupType($mob) == "mob") {
326 $mob_obj = new ilObjMediaObject($mob);
327 $usages = $mob_obj->getUsages(false);
328 if (count($usages) == 0) { // delete, if no usage exists
329 $mob_obj->delete();
330 }
331 }
332 }
333 }
334
343 public static function afterPageHistoryEntry($a_page, DOMDocument $a_old_domdoc, $a_old_xml, $a_old_nr)
344 {
345 self::saveMobUsage($a_page, $a_old_domdoc, $a_old_nr);
346 }
347
353 public static function saveMobUsage($a_page, $a_domdoc, $a_old_nr = 0)
354 {
355 $usages = array();
356
357 // media aliases
358 $xpath = new DOMXPath($a_domdoc);
359 $nodes = $xpath->query('//MediaAlias');
360 foreach ($nodes as $node) {
361 $id_arr = explode("_", $node->getAttribute("OriginId"));
362 $mob_id = $id_arr[count($id_arr) - 1];
363 if ($mob_id > 0 && $id_arr[1] == "") {
364 $usages[$mob_id] = true;
365 }
366 }
367
368 // media objects
369 $xpath = new DOMXPath($a_domdoc);
370 $nodes = $xpath->query('//MediaObject/MetaData/General/Identifier');
371 foreach ($nodes as $node) {
372 $mob_entry = $node->getAttribute("Entry");
373 $mob_arr = explode("_", $mob_entry);
374 $mob_id = $mob_arr[count($mob_arr) - 1];
375 if ($mob_id > 0 && $mob_arr[1] == "") {
376 $usages[$mob_id] = true;
377 }
378 }
379
380 // internal links
381 $xpath = new DOMXPath($a_domdoc);
382 $nodes = $xpath->query("//IntLink[@Type='MediaObject']");
383 foreach ($nodes as $node) {
384 $mob_target = $node->getAttribute("Target");
385 $mob_arr = explode("_", $mob_target);
386 //echo "<br>3<br>";
387 //echo $mob_target."<br>";
388 //var_dump($mob_arr);
389 $mob_id = $mob_arr[count($mob_arr) - 1];
390 if ($mob_id > 0 && $mob_arr[1] == "") {
391 $usages[$mob_id] = true;
392 }
393 }
394
395 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
397 $a_page->getParentType() . ":pg",
398 $a_page->getId(),
399 $a_old_nr,
400 $a_page->getLanguage()
401 );
402 foreach ($usages as $mob_id => $val) {
403 // save usage, if object exists...
404 if (ilObject::_lookupType($mob_id) == "mob") {
406 $mob_id,
407 $a_page->getParentType() . ":pg",
408 $a_page->getId(),
409 $a_old_nr,
410 $a_page->getLanguage()
411 );
412 }
413 }
414
415 return $usages;
416 }
417
424 public function modifyPageContentPostXsl($a_html, $a_mode)
425 {
427
428 if ($a_mode == "offline") {
429 $page = $this->getPage();
430
432 $page->getParentType() . ":pg",
433 $page->getId(),
434 0,
435 $page->getLanguage()
436 );
437 foreach ($mob_ids as $mob_id) {
438 $mob = new ilObjMediaObject($mob_id);
439 $srts = $mob->getSrtFiles();
440 foreach ($srts as $srt) {
441 if ($ilUser->getLanguage() == $srt["language"]) {
442 $srt_content = file_get_contents(ilObjMediaObject::_getDirectory($mob->getId()) . "/" . $srt["full_path"]);
443 $a_html = str_replace("[[[[[mobsubtitle;il__mob_" . $mob->getId() . "_Standard]]]]]", $srt_content, $a_html);
444 }
445 }
446 }
447 }
448
449 return $a_html;
450 }
451}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
const IL_INSERT_AFTER
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.
static saveMobUsage($a_page, $a_domdoc, $a_old_nr=0)
Save all usages of media objects (media aliases, media objects, internal links)
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.
modifyPageContentPostXsl($a_html, $a_mode)
Modify page content after xsl.
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
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)
setType($a_type)
Set Type.
global $DIC
Definition: saml.php:7
$ilUser
Definition: imgupload.php:18