ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 
4 require_once("./Services/COPage/classes/class.ilPageContent.php");
5 
17 {
21  protected $user;
22 
23  protected $mob_node;
24 
28  protected $ui;
29 
33  protected $lng;
34 
38  public function init()
39  {
40  global $DIC;
41 
42  $this->user = $DIC->user();
43  $this->setType("media");
44  $this->ui = $DIC->ui();
45  $this->lng = $DIC->language();
46  }
47 
53  public function readMediaObject($a_mob_id = 0)
54  {
55  if ($a_mob_id > 0) {
56  $mob = new ilObjMediaObject($a_mob_id);
57  $this->setMediaObject($mob);
58  }
59  }
60 
61  public function setNode($a_node)
62  {
63  parent::setNode($a_node); // this is the PageContent node
64  $this->mob_node = $a_node->first_child();
65  }
66 
70  public function setDom(&$a_dom)
71  {
72  $this->dom = $a_dom;
73  }
74 
78  public function setHierId($a_hier_id)
79  {
80  $this->hier_id = $a_hier_id;
81  }
82 
88  public function setMediaObject($a_mediaobject)
89  {
90  $this->mediaobject = $a_mediaobject;
91  }
92 
98  public function getMediaObject()
99  {
100  return $this->mediaobject;
101  }
102 
103  public function createMediaObject()
104  {
105  $this->setMediaObject(new ilObjMediaObject());
106  }
107 
111  public function create(&$a_pg_obj, $a_hier_id)
112  {
113  $this->node = $this->createPageContentNode();
114  }
115 
122  public function createAlias(&$a_pg_obj, $a_hier_id, $a_pc_id = "")
123  {
124  $this->node = $this->dom->create_element("PageContent");
125  $a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);
126  $this->mob_node = $this->dom->create_element("MediaObject");
127  $this->mob_node = $this->node->append_child($this->mob_node);
128  $this->mal_node = $this->dom->create_element("MediaAlias");
129  $this->mal_node = $this->mob_node->append_child($this->mal_node);
130  $this->mal_node->set_attribute("OriginId", "il__mob_" . $this->getMediaObject()->getId());
131 
132  // standard view
133  $item_node = $this->dom->create_element("MediaAliasItem");
134  $item_node = $this->mob_node->append_child($item_node);
135  $item_node->set_attribute("Purpose", "Standard");
136  $media_item = $this->getMediaObject()->getMediaItem("Standard");
137 
138  $layout_node = $this->dom->create_element("Layout");
139  $layout_node = $item_node->append_child($layout_node);
140  if ($media_item->getWidth() > 0) {
141  //$layout_node->set_attribute("Width", $media_item->getWidth());
142  }
143  if ($media_item->getHeight() > 0) {
144  //$layout_node->set_attribute("Height", $media_item->getHeight());
145  }
146  $layout_node->set_attribute("HorizontalAlign", "Left");
147 
148  // caption
149  if ($media_item->getCaption() != "") {
150  $cap_node = $this->dom->create_element("Caption");
151  $cap_node = $item_node->append_child($cap_node);
152  $cap_node->set_attribute("Align", "bottom");
153  $cap_node->set_content($media_item->getCaption());
154  }
155 
156  // text representation
157  if ($media_item->getTextRepresentation() != "") {
158  $tr_node = $this->dom->create_element("TextRepresentation");
159  $tr_node = $item_node->append_child($tr_node);
160  $tr_node->set_content($media_item->getTextRepresentation());
161  }
162 
163  $pars = $media_item->getParameters();
164  foreach ($pars as $par => $val) {
165  $par_node = $this->dom->create_element("Parameter");
166  $par_node = $item_node->append_child($par_node);
167  $par_node->set_attribute("Name", $par);
168  $par_node->set_attribute("Value", $val);
169  }
170 
171  // fullscreen view
172  $fullscreen_item = $this->getMediaObject()->getMediaItem("Fullscreen");
173  if (is_object($fullscreen_item)) {
174  $item_node = $this->dom->create_element("MediaAliasItem");
175  $item_node = $this->mob_node->append_child($item_node);
176  $item_node->set_attribute("Purpose", "Fullscreen");
177 
178  // width and height
179  $layout_node = $this->dom->create_element("Layout");
180  $layout_node = $item_node->append_child($layout_node);
181  if ($fullscreen_item->getWidth() > 0) {
182  $layout_node->set_attribute("Width", $fullscreen_item->getWidth());
183  }
184  if ($fullscreen_item->getHeight() > 0) {
185  $layout_node->set_attribute("Height", $fullscreen_item->getHeight());
186  }
187 
188  // caption
189  if ($fullscreen_item->getCaption() != "") {
190  $cap_node = $this->dom->create_element("Caption");
191  $cap_node = $item_node->append_child($cap_node);
192  $cap_node->set_attribute("Align", "bottom");
193  $cap_node->set_content($fullscreen_item->getCaption());
194  }
195 
196  // text representation
197  if ($fullscreen_item->getTextRepresentation() != "") {
198  $tr_node = $this->dom->create_element("TextRepresentation");
199  $tr_node = $item_node->append_child($tr_node);
200  $tr_node->set_content($fullscreen_item->getTextRepresentation());
201  }
202 
203  $pars = $fullscreen_item->getParameters();
204  foreach ($pars as $par => $val) {
205  $par_node = $this->dom->create_element("Parameter");
206  $par_node = $item_node->append_child($par_node);
207  $par_node->set_attribute("Name", $par);
208  $par_node->set_attribute("Value", $val);
209  }
210  }
211  }
212 
218  public function updateObjectReference()
219  {
220  if (is_object($this->mob_node)) {
221  $this->mal_node = $this->mob_node->first_child();
222  if (is_object($this->mal_node) && $this->mal_node->node_name() == "MediaAlias") {
223  $this->mal_node->set_attribute("OriginId", "il__mob_" . $this->getMediaObject()->getId());
224  }
225  }
226  }
227 
231  public function dumpXML()
232  {
233  $xml = $this->dom->dump_node($this->node);
234  return $xml;
235  }
236 
242  public function setClass($a_class)
243  {
244  if (is_object($this->mob_node)) {
245  $mal_node = $this->mob_node->first_child();
246  if (is_object($mal_node)) {
247  if (!empty($a_class)) {
248  $mal_node->set_attribute("Class", $a_class);
249  } else {
250  if ($mal_node->has_attribute("Class")) {
251  $mal_node->remove_attribute("Class");
252  }
253  }
254  }
255  }
256  }
257 
263  public function getClass()
264  {
265  if (is_object($this->mob_node)) {
266  $mal_node = $this->mob_node->first_child();
267  if (is_object($mal_node)) {
268  $class = $mal_node->get_attribute("Class");
269  return $class;
270  }
271  }
272  }
273 
278  public static function getLangVars()
279  {
280  return array("pc_mob");
281  }
282 
291  public static function afterPageUpdate($a_page, DOMDocument $a_domdoc, $a_xml, $a_creation)
292  {
293  if (!$a_page->getImportMode()) {
294  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
296  $a_page->getParentType() . ":pg",
297  $a_page->getId(),
298  0,
299  $a_page->getLanguage()
300  );
301  self::saveMobUsage($a_page, $a_domdoc);
302  foreach ($mob_ids as $mob) { // check, whether media object can be deleted
303  if (ilObject::_exists($mob) && ilObject::_lookupType($mob) == "mob") {
304  $mob_obj = new ilObjMediaObject($mob);
305  $usages = $mob_obj->getUsages(false);
306  if (count($usages) == 0) { // delete, if no usage exists
307  $mob_obj->delete();
308  }
309  }
310  }
311  }
312  }
313 
319  public static function beforePageDelete($a_page)
320  {
321  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
323  $a_page->getParentType() . ":pg",
324  $a_page->getId(),
325  0,
326  $a_page->getLanguage()
327  );
328 
330  $a_page->getParentType() . ":pg",
331  $a_page->getId(),
332  false,
333  $a_page->getLanguage()
334  );
335 
336  foreach ($mob_ids as $mob) { // check, whether media object can be deleted
337  if (ilObject::_exists($mob) && ilObject::_lookupType($mob) == "mob") {
338  $mob_obj = new ilObjMediaObject($mob);
339  $usages = $mob_obj->getUsages(false);
340  if (count($usages) == 0) { // delete, if no usage exists
341  $mob_obj->delete();
342  }
343  }
344  }
345  }
346 
355  public static function afterPageHistoryEntry($a_page, DOMDocument $a_old_domdoc, $a_old_xml, $a_old_nr)
356  {
357  self::saveMobUsage($a_page, $a_old_domdoc, $a_old_nr);
358  }
359 
365  public static function saveMobUsage($a_page, $a_domdoc, $a_old_nr = 0)
366  {
367  $usages = array();
368 
369  // media aliases
370  $xpath = new DOMXPath($a_domdoc);
371  $nodes = $xpath->query('//MediaAlias');
372  foreach ($nodes as $node) {
373  $id_arr = explode("_", $node->getAttribute("OriginId"));
374  $mob_id = $id_arr[count($id_arr) - 1];
375  if ($mob_id > 0 && $id_arr[1] == "") {
376  $usages[$mob_id] = true;
377  }
378  }
379 
380  // media objects
381  $xpath = new DOMXPath($a_domdoc);
382  $nodes = $xpath->query('//MediaObject/MetaData/General/Identifier');
383  foreach ($nodes as $node) {
384  $mob_entry = $node->getAttribute("Entry");
385  $mob_arr = explode("_", $mob_entry);
386  $mob_id = $mob_arr[count($mob_arr) - 1];
387  if ($mob_id > 0 && $mob_arr[1] == "") {
388  $usages[$mob_id] = true;
389  }
390  }
391 
392  // internal links
393  $xpath = new DOMXPath($a_domdoc);
394  $nodes = $xpath->query("//IntLink[@Type='MediaObject']");
395  foreach ($nodes as $node) {
396  $mob_target = $node->getAttribute("Target");
397  $mob_arr = explode("_", $mob_target);
398  //echo "<br>3<br>";
399  //echo $mob_target."<br>";
400  //var_dump($mob_arr);
401  $mob_id = $mob_arr[count($mob_arr) - 1];
402  if ($mob_id > 0 && $mob_arr[1] == "") {
403  $usages[$mob_id] = true;
404  }
405  }
406 
407  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
409  $a_page->getParentType() . ":pg",
410  $a_page->getId(),
411  $a_old_nr,
412  $a_page->getLanguage()
413  );
414  foreach ($usages as $mob_id => $val) {
415  // save usage, if object exists...
416  if (ilObject::_lookupType($mob_id) == "mob") {
418  $mob_id,
419  $a_page->getParentType() . ":pg",
420  $a_page->getId(),
421  $a_old_nr,
422  $a_page->getLanguage()
423  );
424  }
425  }
426 
427  return $usages;
428  }
429 
433  public function modifyPageContentPostXsl($a_html, $a_mode, $a_abstract_only = false)
434  {
436 
437  if ($a_mode == "offline") {
438  $page = $this->getPage();
439 
441  $page->getParentType() . ":pg",
442  $page->getId(),
443  0,
444  $page->getLanguage()
445  );
446  foreach ($mob_ids as $mob_id) {
447  $mob = new ilObjMediaObject($mob_id);
448  $srts = $mob->getSrtFiles();
449  foreach ($srts as $srt) {
450  if ($ilUser->getLanguage() == $srt["language"]) {
451  $srt_content = file_get_contents(ilObjMediaObject::_getDirectory($mob->getId()) . "/" . $srt["full_path"]);
452  $a_html = str_replace("[[[[[mobsubtitle;il__mob_" . $mob->getId() . "_Standard]]]]]", $srt_content, $a_html);
453  }
454  }
455  }
456  }
457 
458  if ($a_abstract_only) {
459  return $a_html;
460  }
461 
462  // add fullscreen modals
463  $page = $this->getPage();
464  $suffix = "-".$page->getParentType()."-".$page->getId();
465  $modal = $this->ui->factory()->modal()->roundtrip(
466  $this->lng->txt("cont_fullscreen"),
467  $this->ui->factory()->legacy("<iframe class='il-copg-mob-fullscreen' id='il-copg-mob-fullscreen".$suffix."'></iframe>")
468  );
469  $show_signal = $modal->getShowSignal();
470 
471  return $a_html . "<div class='il-copg-mob-fullscreen-modal'>" . $this->ui->renderer()->render($modal) . "</div><script>$(function () { il.COPagePres.setFullscreenModalShowSignal('" .
472  $show_signal . "', '".$suffix."'); });</script>";
473  }
474 
478  public function getJavascriptFiles($a_mode)
479  {
480  $js_files = ilPlayerUtil::getJsFilePaths();
481  $js_files[] = iljQueryUtil::getLocalMaphilightPath();
482  return $js_files;
483  }
484 
488  public function getCssFiles($a_mode)
489  {
490  $js_files = ilPlayerUtil::getCssFilePaths();
491 
492  return $js_files;
493  }
494 }
static getCssFilePaths()
Get css file paths.
getMediaObject()
Get Media Object.
static _getMobsOfObject($a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
get mobs of object
static _deleteAllUsages($a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
static
static getLangVars()
Get lang vars needed for editing.
static _exists($a_id, $a_reference=false, $a_type=null)
checks if an object exists in object_data
setType($a_type)
Set Type.
setHierId($a_hier_id)
set hierarchical edit id
user()
Definition: user.php:4
Class ilPageContent.
static _getDirectory($a_mob_id)
Get absolute directory.
createAlias(&$a_pg_obj, $a_hier_id, $a_pc_id="")
Create an media alias in page.
static beforePageDelete($a_page)
Before page is being deleted.
static getJsFilePaths()
Get js file paths.
init()
Init page content component.
static afterPageHistoryEntry($a_page, DOMDocument $a_old_domdoc, $a_old_xml, $a_old_nr)
After page history entry has been created.
create(&$a_pg_obj, $a_hier_id)
Create pc media object.
setClass($a_class)
Set Style Class of table.
$ilUser
Definition: imgupload.php:18
ui()
Definition: ui.php:5
modifyPageContentPostXsl($a_html, $a_mode, $a_abstract_only=false)
$xml
Definition: metadata.php:332
Class ilObjMediaObject.
getClass()
Get characteristic of section.
const IL_INSERT_AFTER
static _lookupType($a_id, $a_reference=false)
lookup object type
readMediaObject($a_mob_id=0)
Read/get Media Object.
createPageContentNode($a_set_this_node=true)
Create page content node (always use this method first when adding a new element) ...
$DIC
Definition: xapitoken.php:46
static afterPageUpdate($a_page, DOMDocument $a_domdoc, $a_xml, $a_creation)
After page has been updated (or created)
static saveMobUsage($a_page, $a_domdoc, $a_old_nr=0)
Save all usages of media objects (media aliases, media objects, internal links)
static getLocalMaphilightPath()
Get local path of maphilight file.
setDom(&$a_dom)
set dom object
Class ilPCMediaObject.
setMediaObject($a_mediaobject)
Set Media Object.
updateObjectReference()
Updates the media object referenced by the media alias.
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.
dumpXML()
Dump node xml.