ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjMediaCastGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 require_once "./Services/Object/classes/class.ilObjectGUI.php";
6 
18 {
19 
20  private $additionalPurposes = array ("VideoPortable", "AudioPortable");
21  private $purposeSuffixes = array ();
22  private $mimeTypes = array();
23 
28  function ilObjMediaCastGUI($a_data, $a_id, $a_call_by_reference, $a_prepare_output = true)
29  {
30  global $ilCtrl, $lng;
31 
32  $this->type = "mcst";
33  $this->ilObjectGUI($a_data,$a_id,$a_call_by_reference,$a_prepare_output);
34  $lng->loadLanguageModule("mcst");
35  $lng->loadLanguageModule("news");
36  $lng->loadLanguageModule("rep");
37 
38  $ilCtrl->saveParameter($this, "item_id");
39 
40  include_once ("./Modules/MediaCast/classes/class.ilMediaCastSettings.php");
42  $this->purposeSuffixes = $settings->getPurposeSuffixes();
43  $this->mimeTypes = array();
44  $mime_types = $settings->getMimeTypes();
45  foreach ($mime_types as $mt)
46  {
47  $this->mimeTypes[$mt] = $mt;
48  }
49 
50  include_once("./Services/Utilities/classes/class.ilMimeTypeUtil.php");
51  foreach (ilMimeTypeUtil::getExt2MimeMap() as $mt)
52  {
53  $this->mimeTypes[$mt] = $mt;
54  }
55  asort($this->mimeTypes);
56  }
57 
58  function executeCommand()
59  {
60  global $ilUser, $ilTabs;
61 
62  $next_class = $this->ctrl->getNextClass($this);
63  $cmd = $this->ctrl->getCmd();
64  $this->prepareOutput();
65 
66  switch($next_class)
67  {
68  case "ilinfoscreengui":
69  $this->checkPermission("visible");
70  $this->infoScreen(); // forwards command
71  break;
72 
73  case "ilexportgui":
74 // $this->prepareOutput();
75  $ilTabs->activateTab("export");
76  include_once("./Services/Export/classes/class.ilExportGUI.php");
77  $exp_gui = new ilExportGUI($this);
78  $exp_gui->addFormat("xml");
79  $ret = $this->ctrl->forwardCommand($exp_gui);
80 // $this->tpl->show();
81  break;
82 
83  case 'ilpermissiongui':
84  $ilTabs->activateTab("id_permissions");
85  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
86  $perm_gui =& new ilPermissionGUI($this);
87  $ret =& $this->ctrl->forwardCommand($perm_gui);
88  break;
89 
90  case "ilcommonactiondispatchergui":
91  include_once("Services/Object/classes/class.ilCommonActionDispatcherGUI.php");
93  $this->ctrl->forwardCommand($gui);
94  break;
95 
96  default:
97  if(!$cmd)
98  {
99  $cmd = "infoScreen";
100  }
101  $cmd .= "Object";
102  if ($cmd != "infoScreenObject")
103  {
104  $this->checkPermission("read");
105  }
106  else
107  {
108  $this->checkPermission("visible");
109  }
110  $this->$cmd();
111 
112  break;
113  }
114 
115  $this->addHeaderAction();
116 
117  return true;
118  }
119 
120  protected function initCreationForms($a_new_type)
121  {
122  $forms = array(self::CFORM_NEW => $this->initCreateForm($a_new_type),
123  self::CFORM_IMPORT => $this->initImportForm($a_new_type));
124 
125  return $forms;
126  }
127 
132  function afterSave($newObj)
133  {
134  // always send a message
135  ilUtil::sendSuccess($this->lng->txt("object_added"),true);
136  ilUtil::redirect("ilias.php?baseClass=ilMediaCastHandlerGUI&ref_id=".$newObj->getRefId()."&cmd=editSettings");
137  }
138 
142  function listItemsObject($a_presentation_mode = false)
143  {
144  global $tpl, $lng, $ilAccess, $ilTabs, $ilToolbar;
145 
146  $this->checkPermission("read");
147 
148  if ($a_presentation_mode)
149  {
150  $this->addContentSubTabs("content");
151  }
152  else
153  {
154  $this->addContentSubTabs("manage");
155  }
156 
157  $med_items = $this->object->getSortedItemsArray();
158 
159  include_once("./Modules/MediaCast/classes/class.ilMediaCastTableGUI.php");
160  if ($a_presentation_mode)
161  {
162  $table_gui = new ilMediaCastTableGUI($this, "showContent", false, true);
163  }
164  else
165  {
166  $table_gui = new ilMediaCastTableGUI($this, "listItems");
167  }
168 
169  $table_gui->setData($med_items);
170 
171  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"]) && !$a_presentation_mode)
172  {
173  $ilToolbar->addButton($lng->txt("add"), $this->ctrl->getLinkTarget($this, "addCastItem"));
174 
175  $table_gui->addMultiCommand("confirmDeletionItems", $lng->txt("delete"));
176  $table_gui->setSelectAllCheckbox("item_id");
177  }
178 
179  $feed_icon_html = $this->getFeedIconsHTML();
180  if ($feed_icon_html != "")
181  {
182  $table_gui->setHeaderHTML($feed_icon_html);
183  }
184 
185  $tpl->setContent($table_gui->getHTML());
186 
187  $tpl->setPermanentLink($this->object->getType(), $this->object->getRefId());
188  }
189 
196  function getFeedIconsHTML()
197  {
198  global $lng;
199 
200  $html = "";
201 
202  include_once("./Services/Block/classes/class.ilBlockSetting.php");
203  $public_feed = ilBlockSetting::_lookup("news", "public_feed",
204  0, $this->object->getId());
205 
206  // rss icon/link
207  if ($public_feed)
208  {
209  $news_set = new ilSetting("news");
210  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
211 
212  if ($enable_internal_rss)
213  {
214  // create dummy object in db (we need an id)
215  $items = $this->object->getItemsArray();
216  include_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
217  $html = "";
218  foreach (ilObjMediaCast::$purposes as $purpose)
219  {
220  foreach ($items as $id => $item)
221  {
222  $mob = new ilObjMediaObject($item["mob_id"]);
223  $mob->read();
224  if ($mob->hasPurposeItem($purpose))
225  {
226  if ($html == "")
227  {
228  $html = " ";
229  }
230  $url = ILIAS_HTTP_PATH."/feed.php?client_id=".rawurlencode(CLIENT_ID)."&"."ref_id=".$_GET["ref_id"]."&purpose=$purpose";
231  $title = $lng->txt("news_feed_url");
232 
233  include_once("./Services/News/classes/class.ilRSSButtonGUI.php");
234  switch (strtolower($purpose))
235  {
236  case "audioportable":
239  break;
240 
241  case "videoportable":
244  break;
245 
246  default:
247  $type1 = ilRSSButtonGUI::ICON_RSS;
249  break;
250  }
251  $row1 .= "&nbsp;".ilRSSButtonGUI::get($type1, $url);
252  if ($this->object->getPublicFiles())
253  {
254  $url = preg_replace("/https?/i","itpc",$url);
255  $title = $lng->txt("news_feed_url");
256 
257  include_once("./Services/News/classes/class.ilRSSButtonGUI.php");
258  $row2 .= "&nbsp;".ilRSSButtonGUI::get($type2, $url);
259  }
260  break;
261  }
262  }
263  }
264  if ($html != "")
265  {
266  $html .= $row1;
267  if ($row2 != "")
268  {
269  $html .= $row2;
270  }
271  }
272  }
273  }
274  return $html;
275  }
276 
277 
281  function addCastItemObject()
282  {
283  global $tpl;
284 
285  $this->checkPermission("write");
286 
287  $this->initAddCastItemForm();
288  $tpl->setContent($this->form_gui->getHTML());
289  }
290 
295  {
296  global $tpl, $ilToolbar, $ilCtrl;
297 
298  $this->checkPermission("write");
299 
300  // conversion toolbar
301  include_once("./Services/MediaObjects/classes/class.ilFFmpeg.php");
302  if (ilFFmpeg::enabled())
303  {
304  $this->mcst_item = new ilNewsItem($_GET["item_id"]);
305  include_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
306  $mob = new ilObjMediaObject($this->mcst_item->getMobId());
307 
308  $conv_cnt = 0;
309  // we had other purposes as source as well, but
310  // currently only "Standard" is implemented in the convertFile method
311  foreach (array("Standard") as $p)
312  {
313  /*
314  $med = $mob->getMediaItem($p);
315  if (is_object($med))
316  {
317  $options = ilFFmpeg::getPossibleTargetMimeTypes($med->getFormat());
318  if (count($options) > 0)
319  {
320  if ($conv_cnt > 0)
321  {
322  $ilToolbar->addSeparator();
323  }
324 
325  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
326  $si = new ilSelectInputGUI($this->lng->txt("mcst_conv_".
327  strtolower($p)."_to"), "target_format");
328  $si->setOptions($options);
329  $ilToolbar->addInputItem($si, true);
330 
331  $si = new ilSelectInputGUI(", ".$this->lng->txt("mcst_target").": ",
332  "target_purpose");
333  $si->setOptions(array("Standard" => $this->lng->txt("mcst_purpose_standard"),
334  "VideoAlternative" => $this->lng->txt("mcst_purpose_videoalternative")
335  ));
336  $si->setValue($p);
337  $ilToolbar->addInputItem($si, true);
338 
339  $ilToolbar->addFormButton($this->lng->txt("mcst_convert"), "convertFile");
340 
341  $conv_cnt++;
342  }
343  }
344  */
345 
346  $med = $mob->getMediaItem($p);
347  if (is_object($med))
348  {
349  if (ilFFmpeg::supportsImageExtraction($med->getFormat()))
350  {
351  // second
352  include_once("./Services/Form/classes/class.ilTextInputGUI.php");
353  $ni = new ilTextInputGUI($this->lng->txt("mcst_second"), "sec");
354  $ni->setMaxLength(4);
355  $ni->setSize(4);
356  $ni->setValue(1);
357  $ilToolbar->addInputItem($ni, true);
358 
359  $ilToolbar->addFormButton($this->lng->txt("mcst_extract_preview_image"), "extractPreviewImage");
360  $ilToolbar->setFormAction($ilCtrl->getFormAction($this));
361  }
362  }
363 
364  /*if ($conv_cnt > 0)
365  {
366  $ilToolbar->setFormAction($ilCtrl->getFormAction($this));
367  }*/
368  }
369  }
370 
371  $this->initAddCastItemForm("edit");
372  $this->getCastItemValues();
373  $tpl->setContent($this->form_gui->getHTML());
374  }
375 
379  function initAddCastItemForm($a_mode = "create")
380  {
381  global $lng, $ilCtrl, $ilTabs;
382 
383  $this->checkPermission("write");
384  $ilTabs->activateTab("edit_content");
385 
386  $lng->loadLanguageModule("mcst");
387 
388  $news_set = new ilSetting("news");
389  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
390 
391  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
392  $this->form_gui = new ilPropertyFormGUI();
393  $this->form_gui->setMultipart(true);
394 
395  // Property Title
396  $text_input = new ilTextInputGUI($lng->txt("title"), "title");
397  $text_input->setMaxLength(200);
398  $this->form_gui->addItem($text_input);
399 
400  // Property Content
401  $text_area = new ilTextAreaInputGUI($lng->txt("description"), "description");
402  $text_area->setRequired(false);
403  $this->form_gui->addItem($text_area);
404 
405  // Property Visibility
406  if ($enable_internal_rss)
407  {
408  $radio_group = new ilRadioGroupInputGUI($lng->txt("access_scope"), "visibility");
409  $radio_option = new ilRadioOption($lng->txt("access_users"), "users");
410  $radio_group->addOption($radio_option);
411  $radio_option = new ilRadioOption($lng->txt("access_public"), "public");
412  $radio_group->addOption($radio_option);
413  $radio_group->setInfo($lng->txt("mcst_visibility_info"));
414  $radio_group->setRequired(true);
415  $radio_group->setValue($this->object->getDefaultAccess() == 0 ? "users" : "public");
416  $this->form_gui->addItem($radio_group);
417  }
418 
419  // Duration
420  $dur = new ilDurationInputGUI($lng->txt("mcst_duration"), "duration");
421  $dur->setInfo($lng->txt("mcst_duration_info"));
422  $dur->setShowDays(false);
423  $dur->setShowHours(true);
424  $dur->setShowSeconds(true);
425  $this->form_gui->addItem($dur);
426 
427  foreach (ilObjMediaCast::$purposes as $purpose)
428  {
429  if ($purpose == "VideoAlternative" &&
430  $a_mode == "create")
431  {
432  continue;
433  }
434 
436  $section->setTitle($lng->txt("mcst_".strtolower($purpose)."_title"));
437  $this->form_gui->addItem($section);
438  if ($a_mode != "create")
439  {
440  $value = new ilHiddenInputGUI("value_".$purpose);
441  $label = new ilNonEditableValueGUI($lng->txt("value"));
442  $label->setPostVar("label_value_".$purpose);
443  $label->setInfo($lng->txt("mcst_current_value_info"));
444  $this->form_gui->addItem($label);
445  $this->form_gui->addItem($value);
446 
447  }
448  $file = new ilFileInputGUI($lng->txt("file"), "file_".$purpose);
449  $file->setSuffixes($this->purposeSuffixes[$purpose]);
450  $this->form_gui->addItem($file);
451  $text_input = new ilRegExpInputGUI($lng->txt("url"), "url_".$purpose);
452  $text_input->setPattern("/https?\:\/\/.+/i");
453  $text_input->setInfo($lng->txt("mcst_reference_info"));
454  $this->form_gui->addItem($text_input);
455  if ($purpose != "Standard")
456  {
457  $clearCheckBox = new ilCheckboxInputGUI();
458  $clearCheckBox->setPostVar("delete_".$purpose);
459  $clearCheckBox->setTitle($lng->txt("mcst_clear_purpose_title"));
460  $this->form_gui->addItem($clearCheckBox);
461  } else {
462 
463  // mime type selection
464  $mimeTypeSelection = new ilSelectInputGUI();
465  $mimeTypeSelection->setPostVar("mimetype_".$purpose);
466  $mimeTypeSelection->setTitle($lng->txt("mcst_mimetype"));
467  $mimeTypeSelection->setInfo($lng->txt("mcst_mimetype_info"));
468  $options = array("" => $lng->txt("mcst_automatic_detection"));
469  $options = array_merge($options, $this->mimeTypes);
470  $mimeTypeSelection->setOptions($options);
471  $this->form_gui->addItem($mimeTypeSelection);
472 
473  // preview picure
474  $pp = new ilImageFileInputGUI($lng->txt("mcst_preview_picture"), "preview_pic");
475  $pp->setSuffixes(array("png", "jpeg", "jpg"));
476  $pp->setInfo($lng->txt("mcst_preview_picture_info")." mp4, mp3, png, jp(e)g, gif");
477  $this->form_gui->addItem($pp);
478 
479  }
480 
481  }
482 
483  // save/cancel button
484  if ($a_mode == "create")
485  {
486  $this->form_gui->setTitle($lng->txt("mcst_add_new_item"));
487  $this->form_gui->addCommandButton("saveCastItem", $lng->txt("save"));
488  }
489  else
490  {
491  $this->form_gui->setTitle($lng->txt("mcst_edit_item"));
492  $this->form_gui->addCommandButton("updateCastItem", $lng->txt("save"));
493  }
494  $this->form_gui->addCommandButton("listItems", $lng->txt("cancel"));
495  $this->form_gui->setFormAction($ilCtrl->getFormAction($this, "saveCastItem"));
496 
497  }
498 
502  public function getCastItemValues()
503  {
504  global $lng;
505 
506  // get mob
507  $this->mcst_item = new ilNewsItem($_GET["item_id"]);
508  include_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
509  $mob = new ilObjMediaObject($this->mcst_item->getMobId());
510 
511  // preview
512  $ppic = $mob->getVideoPreviewPic();
513  if ($ppic != "")
514  {
515  $i = $this->form_gui->getItemByPostVar("preview_pic");
516  $i->setImage($ppic);
517  }
518 
519 
520  $values = array();
521  $mediaItems = $this->getMediaItems($_GET["item_id"]);
522  if (count ($mediaItems) > 0)
523  {
524  foreach ($mediaItems as $med)
525  {
526  if (!isset ($values["title"]))
527  {
528  // first item, so set title, description, ...
529  $values["title"] = $this->mcst_item->getTitle();
530  $values["description"] = $this->mcst_item->getContent();
531  $values["visibility"] = $this->mcst_item->getVisibility();
532  $length = explode(":", $this->mcst_item->getPlaytime());
533  $values["duration"] = array("hh" => $length[0], "mm" => $length[1], "ss" => $length[2]);
534  }
535 
536  $values["value_".$med->getPurpose()] = (strlen($med->getLocation())> 100) ? "...".substr($med->getLocation(), strlen($med->getLocation()) - 100) : $med->getLocation();
537  $values["label_value_".$med->getPurpose()] = (strlen($med->getLocation())> 100) ? "...".substr($med->getLocation(), strlen($med->getLocation()) - 100) : $med->getLocation();
538  $values["mimetype_".$med->getPurpose()] = $med->getFormat();
539  }
540  }
541  foreach (ilObjMediaCast::$purposes as $purpose) {
542  if (!isset ($values["value_".$purpose]))
543  {
544  $values["label_value_".$purpose] = $lng->txt("none");
545  $values["value_".$purpose] = $lng->txt("none");
546  }
547  }
548  $this->form_gui->setValuesByArray($values);
549  }
550 
555  {
556  global $tpl, $ilCtrl, $ilUser, $lng, $ilTabs;
557 
558  $this->checkPermission("write");
559  $ilTabs->activateTab("edit_content");
560 
561  $this->initAddCastItemForm();
562 
563  if ($_POST["url_Standard"] == "" && !$_FILES['file_Standard']['tmp_name']) {
564  ilUtil::sendFailure($lng->txt("msg_input_either_file_or_url"));
565  $this->populateFormFromPost();
566  }
567  else if ($this->form_gui->checkInput())
568  {
569  // create dummy object in db (we need an id)
570  include_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
571  $mob = new ilObjMediaObject();
572  $mob->create();
573 
574  //handle standard purpose
575  $file = $this->createMediaItemForPurpose($mob, "Standard");
576 
577  // set title and description
578  // set title to basename of file if left empty
579  $title = $this->form_gui->getInput("title") != "" ? $this->form_gui->getInput("title") : basename($file);
580  $description = $this->form_gui->getInput("description");
581  $mob->setTitle($title);
582  $mob->setDescription($description);
583 
584  // save preview pic
585  $prevpic = $this->form_gui->getInput("preview_pic");
586  if ($prevpic["size"] > 0)
587  {
588  $mob->uploadVideoPreviewPic($prevpic);
589  }
590 
591  // determine duration for standard purpose
592  $duration = $this->getDuration($file);
593 
594  // handle other purposes
595  foreach ($this->additionalPurposes as $purpose)
596  {
597  // check if some purpose has been uploaded
598  $file_gui = $this->form_gui->getInput("file_".$purpose);
599  $url_gui = $this->form_gui->getInput("url_".$purpose);
600  if ($url_gui || $file_gui["size"] > 0)
601  {
602  $this->createMediaItemForPurpose ($mob, $purpose);
603  }
604  }
605 
606  $mob->update();
607 
608  if ($prevpic["size"] == 0)
609  {
610  // re-read media object
611  $mob = new ilObjMediaObject($mob->getId());
612  $mob->generatePreviewPic(320, 240);
613  }
614 
615  //
616  // @todo: save usage
617  //
618 
619  $news_set = new ilSetting("news");
620  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
621 
622  // create new media cast item
623  include_once("./Services/News/classes/class.ilNewsItem.php");
624  $mc_item = new ilNewsItem();
625  $mc_item->setMobId($mob->getId());
626  $mc_item->setContentType(NEWS_AUDIO);
627  $mc_item->setContextObjId($this->object->getId());
628  $mc_item->setContextObjType($this->object->getType());
629  $mc_item->setUserId($ilUser->getId());
630  $mc_item->setPlaytime($duration);
631  $mc_item->setTitle($title);
632  $mc_item->setContent($description);
633  $mc_item->setLimitation(false);
634  if ($enable_internal_rss)
635  {
636  $mc_item->setVisibility($this->form_gui->getInput("visibility"));
637  }
638  else
639  {
640  $mc_item->setVisibility("users");
641  }
642  $mc_item->create();
643 
644  $ilCtrl->redirect($this, "listItems");
645  }
646  else
647  {
648  $this->populateFormFromPost();
649  }
650  }
651 
658  private function getDuration($file)
659  {
660  $duration = isset($this->form_gui)
661  ? $this->form_gui->getInput("duration")
662  : array("hh"=>0, "mm"=>0, "ss"=>0);
663  if ($duration["hh"] == 0 && $duration["mm"] == 0 && $duration["ss"] == 0 && is_file($file))
664  {
665  include_once("./Services/MediaObjects/classes/class.ilMediaAnalyzer.php");
666  $ana = new ilMediaAnalyzer();
667  $ana->setFile($file);
668  $ana->analyzeFile();
669  $dur = $ana->getPlaytimeString();
670  $dur = explode(":", $dur);
671  $duration["mm"] = $dur[0];
672  $duration["ss"] = $dur[1];
673  }
674  $duration = str_pad($duration["hh"], 2 , "0", STR_PAD_LEFT).":".
675  str_pad($duration["mm"], 2 , "0", STR_PAD_LEFT).":".
676  str_pad($duration["ss"], 2 , "0", STR_PAD_LEFT);
677  return $duration;
678  }
679 
686  private function createMediaItemForPurpose ($mob, $purpose)
687  {
688  $mediaItem = new ilMediaItem();
689  $mob->addMediaItem($mediaItem);
690  $mediaItem->setPurpose($purpose);
691  return $this->updateMediaItem($mob, $mediaItem);
692  }
693 
701  private function updateMediaItem ($mob, & $mediaItem)
702  {
703  $purpose = $mediaItem->getPurpose();
704  $url_gui = $this->form_gui->getInput ("url_".$purpose);
705  $file_gui = $this->form_gui->getInput ("file_".$purpose);
706  if ($url_gui)
707  {
708  // http
709  $file = $this->form_gui->getInput ("url_".$purpose);
710  $title = basename ($file);
711  $location = $this->form_gui->getInput ("url_".$purpose);
712  $locationType = "Reference";
713  } elseif ($file_gui["size"] > 0){
714  // lokal
715  // determine and create mob directory, move uploaded file to directory
716  $mob_dir = ilObjMediaObject::_getDirectory($mob->getId());
717  if (!is_dir($mob_dir))
718  $mob->createDirectory();
719 
720  $file_name = ilUtil::getASCIIFilename($_FILES['file_'.$purpose]['name']);
721  $file_name = str_replace(" ", "_", $file_name);
722 
723  $file = $mob_dir."/".$file_name;
724  $title = $file_name;
725  $locationType = "LocalFile";
726  $location = $title;
727  ilUtil::moveUploadedFile($_FILES['file_'.$purpose]['tmp_name'], $file_name, $file);
728  ilUtil::renameExecutables($mob_dir);
729 
730  }
731 
732  // check if not automatic mimetype detection
733  if ($_POST["mimetype_".$purpose] != "")
734  {
735  $mediaItem->setFormat($_POST["mimetype_".$purpose]);
736  }
737  elseif ($mediaItem->getLocation () != "")
738  {
739  $format = ilObjMediaObject::getMimeType($mediaItem->getLocation());
740  $mediaItem->setFormat($format);
741  }
742 
743  if (isset($file))
744  {
745  // get mime type, if not already set!
746  if (!isset($format))
747  {
749  }
750 
751  // set real meta and object data
752  $mediaItem->setFormat($format);
753  $mediaItem->setLocation($location);
754  $mediaItem->setLocationType($locationType);
755  $mediaItem->setHAlign("Left");
756  $mediaItem->setHeight(self::isAudio($format)?0:180);
757  }
758 
759  if ($purpose == "Standard")
760  {
761  if (isset($title))
762  $mob->setTitle ($title);
763  if (isset($format))
764  $mob->setDescription($format);
765  }
766 
767  return $file;
768  }
769 
774  {
775  global $tpl, $lng, $ilCtrl, $ilUser, $log;
776 
777  $this->checkPermission("write");
778 
779  $this->initAddCastItemForm("edit");
780 
781  if ($this->form_gui->checkInput())
782  {
783  // create new media cast item
784  include_once("./Services/News/classes/class.ilNewsItem.php");
785  $mc_item = new ilNewsItem($_GET["item_id"]);
786  $mob_id = $mc_item->getMobId();
787 
788  // create dummy object in db (we need an id)
789  include_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
790  $mob = new ilObjMediaObject($mob_id);
791 
792 
793  foreach (ilObjMediaCast::$purposes as $purpose)
794  {
795  if ($this->form_gui->getInput("delete_".$purpose))
796  {
797  $mob->removeMediaItem($purpose);
798  $log->write ("Mcst: deleting purpose $purpose");
799  continue;
800  }
801  $media_item = $mob->getMediaItem($purpose);
802  $url_gui = $this->form_gui->getInput("url_".$purpose);
803  $file_gui = $this->form_gui->getInput("file_".$purpose);
804 
805  if ($media_item == null)
806  {
807  if ($purpose != "Standard" &&
808  ($url_gui || $file_gui["size"]>0))
809  {
810  // check if we added an additional purpose when updating
811  // either by url or by file
812  $file = $this->createMediaItemForPurpose($mob, $purpose);
813  }
814  } else
815  {
816  $file = $this->updateMediaItem($mob, $media_item);
817  }
818 
819  if ($purpose == "Standard")
820  {
821  $duration = $this->getDuration($file);
822  $title = $this->form_gui->getInput("title") != "" ? $this->form_gui->getInput("title") : basename($file);
823  $description = $this->form_gui->getInput("description");
824 
825  $mob->setTitle($title);
826  $mob->setDescription($description);
827 
828  $prevpic = $this->form_gui->getInput("preview_pic");
829  if ($prevpic["size"] > 0)
830  {
831  $mob->uploadVideoPreviewPic($prevpic);
832  }
833  else
834  {
835  $prevpici = $this->form_gui->getItemByPostVar("preview_pic");
836  if ($prevpici->getDeletionFlag())
837  {
838  $mob->removeAdditionalFile($mob->getVideoPreviewPic(true));
839  }
840  }
841  }
842  }
843 
844  // set real meta and object data
845  $mob->update();
846 
847  //
848  // @todo: save usage
849  //
850 
851  $news_set = new ilSetting("news");
852  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
853 
854  $mc_item->setUserId($ilUser->getId());
855  if (isset($duration))
856  {
857  $mc_item->setPlaytime($duration);
858  }
859  $mc_item->setTitle($title);
860  $mc_item->setContent($description);
861  if ($enable_internal_rss)
862  {
863  $mc_item->setVisibility($this->form_gui->getInput("visibility"));
864  }
865  $mc_item->update();
866 
867  $ilCtrl->redirect($this, "listItems");
868  }
869  else
870  {
871  $this->populateFormFromPost();
872  }
873  }
874 
879  {
880  global $ilCtrl, $lng, $tpl, $ilTabs;
881 
882  $this->checkPermission("write");
883  $ilTabs->activateTab("edit_content");
884 
885  if (!is_array($_POST["item_id"]))
886  {
887  $this->listItemsObject();
888  return;
889  }
890 
891  include_once("Services/Utilities/classes/class.ilConfirmationGUI.php");
892  $c_gui = new ilConfirmationGUI();
893 
894  // set confirm/cancel commands
895  $c_gui->setFormAction($ilCtrl->getFormAction($this, "deleteItems"));
896  $c_gui->setHeaderText($lng->txt("info_delete_sure"));
897  $c_gui->setCancel($lng->txt("cancel"), "listItems");
898  $c_gui->setConfirm($lng->txt("confirm"), "deleteItems");
899 
900  // add items to delete
901  include_once("./Services/News/classes/class.ilNewsItem.php");
902  foreach($_POST["item_id"] as $item_id)
903  {
904  $item = new ilNewsItem($item_id);
905  $c_gui->addItem("item_id[]", $item_id, $item->getTitle(),
906  ilUtil::getImagePath("icon_mcst.svg"));
907  }
908 
909  $tpl->setContent($c_gui->getHTML());
910  }
911 
915  function deleteItemsObject()
916  {
917  global $ilCtrl;
918 
919  $this->checkPermission("write");
920 
921  // delete all selected news items
922  foreach($_POST["item_id"] as $item_id)
923  {
924  $mc_item = new ilNewsItem($item_id);
925  $mc_item->delete();
926  }
927 
928  $ilCtrl->redirect($this, "listItems");
929  }
930 
935  {
936  global $ilCtrl;
937  $this->checkPermission("read");
938 
939  $news_item = new ilNewsItem($_GET["item_id"]);
940  if (!$news_item->deliverMobFile($_GET["purpose"], (int) $_GET["presentation"]))
941  {
942  $ilCtrl->redirect($this, "listItems");
943  }
944  exit;
945  }
946 
951  {
952  global $ilCtrl, $lng;
953 
954  $mc_item = new ilNewsItem($_GET["item_id"]);
955  $mob = $mc_item->getMobId();
956  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
957  $mob = new ilObjMediaObject($mob);
958  $mob_dir = ilObjMediaObject::_getDirectory($mob->getId());
959  $m_item = $mob->getMediaItem("Standard");
960  $file = $mob_dir."/".$m_item->getLocation();
961  $duration = $this->getDuration($file);
962  if ($duration != "00:00:00")
963  {
964  $mc_item->setPlaytime($duration);
965  $mc_item->update();
966  ilUtil::sendSuccess($lng->txt("mcst_set_playtime"), true);
967  }
968  else
969  {
970  ilUtil::sendFailure($lng->txt("mcst_unable_to_determin_playtime"), true);
971  }
972 
973  $ilCtrl->redirect($this, "listItems");
974  }
975 
981  function infoScreenObject()
982  {
983  $this->checkPermission("visible");
984  $this->ctrl->setCmd("showSummary");
985  $this->ctrl->setCmdClass("ilinfoscreengui");
986  $this->infoScreen();
987  }
988 
992  function infoScreen()
993  {
994  global $ilAccess, $ilUser, $ilTabs;
995 
996  $ilTabs->activateTab("id_info");
997 
998  if (!$ilAccess->checkAccess("visible", "", $this->object->getRefId()))
999  {
1000  $this->ilias->raiseError($this->lng->txt("msg_no_perm_read"),$this->ilias->error_obj->MESSAGE);
1001  }
1002 
1003  include_once("./Services/InfoScreen/classes/class.ilInfoScreenGUI.php");
1004  $info = new ilInfoScreenGUI($this);
1005 
1006  $info->enablePrivateNotes();
1007 
1008  /*
1009  $info->enableNews();
1010  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"]))
1011  {
1012  //$info->enableNewsEditing();
1013  $info->setBlockProperty("news", "settings", true);
1014  }*/
1015 
1016  // general information
1017  $this->lng->loadLanguageModule("meta");
1018  $this->lng->loadLanguageModule("mcst");
1019  $med_items = $this->object->getItemsArray();
1020  $info->addSection($this->lng->txt("meta_general"));
1021  $info->addProperty($this->lng->txt("mcst_nr_items"),
1022  (int) count($med_items));
1023 
1024  if (count($med_items) > 0)
1025  {
1026  $cur = current($med_items);
1027  $last = ilDatePresentation::formatDate(new ilDateTime($cur["creation_date"], IL_CAL_DATETIME));
1028  }
1029  else
1030  {
1031  $last = "-";
1032  }
1033 
1034  $info->addProperty($this->lng->txt("mcst_last_submission"), $last);
1035 
1036  // forward the command
1037  $this->ctrl->forwardCommand($info);
1038  }
1039 
1044  function setTabs()
1045  {
1046  global $ilAccess, $ilTabs, $lng, $ilHelp;
1047 
1048  $ilHelp->setScreenIdComponent("mcst");
1049 
1050  // list items
1051  if ($ilAccess->checkAccess('read', "", $this->object->getRefId()))
1052  {
1053  $ilTabs->addTab("content",
1054  $lng->txt("content"),
1055  $this->ctrl->getLinkTarget($this, "showContent"));
1056  }
1057 
1058  // info screen
1059  if ($ilAccess->checkAccess('visible', "", $this->object->getRefId()))
1060  {
1061  $ilTabs->addTab("id_info",
1062  $lng->txt("info_short"),
1063  $this->ctrl->getLinkTargetByClass("ilinfoscreengui", "showSummary"));
1064  }
1065 
1066  // settings
1067  if ($ilAccess->checkAccess('write', "", $this->object->getRefId()))
1068  {
1069  $ilTabs->addTab("id_settings",
1070  $lng->txt("settings"),
1071  $this->ctrl->getLinkTarget($this, "editSettings"));
1072  }
1073 
1074  // export
1075  if ($ilAccess->checkAccess("write", "", $this->object->getRefId()))
1076  {
1077  $ilTabs->addTab("export",
1078  $lng->txt("export"),
1079  $this->ctrl->getLinkTargetByClass("ilexportgui", ""));
1080  }
1081 
1082  // edit permissions
1083  if ($ilAccess->checkAccess('edit_permission', "", $this->object->getRefId()))
1084  {
1085  $ilTabs->addTab("id_permissions",
1086  $lng->txt("perm_settings"),
1087  $this->ctrl->getLinkTargetByClass("ilpermissiongui", "perm"));
1088  }
1089  }
1090 
1097  function addContentSubTabs($a_active = "content")
1098  {
1099  global $ilTabs, $ilAccess, $lng;
1100 
1101  $ilTabs->addSubTab("content",
1102  $lng->txt("view"),
1103  $this->ctrl->getLinkTarget($this, "showContent"));
1104 
1105  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"]))
1106  {
1107  $ilTabs->addSubTab("manage",
1108  $lng->txt("mcst_manage"),
1109  $this->ctrl->getLinkTarget($this, "listItems"));
1110 
1111  if ($this->object->getOrder() == ilObjMediaCast::ORDER_MANUAL)
1112  {
1113  $ilTabs->addSubTab("sorting",
1114  $lng->txt("mcst_ordering"),
1115  $this->ctrl->getLinkTarget($this, "editOrder"));
1116  }
1117  }
1118 
1119  $ilTabs->activateSubTab($a_active);
1120  $ilTabs->activateTab("content");
1121  }
1122 
1123 
1128  {
1129  global $tpl, $ilTabs;
1130 
1131  $this->checkPermission("write");
1132  $ilTabs->activateTab("id_settings");
1133 
1134  $this->initSettingsForm();
1135  $tpl->setContent($this->form_gui->getHtml());
1136  }
1137 
1141  function initSettingsForm()
1142  {
1143  global $tpl, $lng, $ilCtrl;
1144 
1145  $lng->loadLanguageModule("mcst");
1146 
1147  include("Services/Form/classes/class.ilPropertyFormGUI.php");
1148  $this->form_gui = new ilPropertyFormGUI();
1149  $this->form_gui->setTitle($lng->txt("mcst_settings"));
1150 
1151  // Title
1152  $tit = new ilTextInputGUI($lng->txt("title"), "title");
1153  $tit->setValue($this->object->getTitle());
1154  $tit->setRequired(true);
1155  $this->form_gui->addItem($tit);
1156 
1157  // description
1158  $des = new ilTextAreaInputGUI($lng->txt("description"), "description");
1159  $des->setValue($this->object->getLongDescription());
1160  $this->form_gui->addItem($des);
1161 
1162  $sh = new ilFormSectionHeaderGUI();
1163  $sh->setTitle($lng->txt("rep_activation_availability"));
1164  $this->form_gui->addItem($sh);
1165 
1166  // Online
1167  $online = new ilCheckboxInputGUI($lng->txt("online"), "online");
1168  $online->setChecked($this->object->getOnline());
1169  $this->form_gui->addItem($online);
1170 
1171  // presentation
1172  $sh = new ilFormSectionHeaderGUI();
1173  $sh->setTitle($lng->txt("obj_presentation"));
1174  $this->form_gui->addItem($sh);
1175 
1176  // Sorting
1177  $sort = new ilRadioGroupInputGUI($lng->txt("mcst_ordering"), "order");
1178  $sort->addOption(new ilRadioOption($lng->txt("mcst_ordering_title"),
1180  $sort->addOption(new ilRadioOption($lng->txt("mcst_ordering_creation_date_asc"),
1182  $sort->addOption(new ilRadioOption($lng->txt("mcst_ordering_creation_date_desc"),
1184  $sort->addOption(new ilRadioOption($lng->txt("mcst_ordering_manual"),
1186  $sort->setValue($this->object->getOrder());
1187  $this->form_gui->addItem($sort);
1188 
1189  // view mode
1190  $options = array(
1191  ilObjMediaCast::VIEW_LIST => $lng->txt("mcst_list"),
1192  ilObjMediaCast::VIEW_GALLERY => $lng->txt("mcst_gallery")
1193  );
1194  $si = new ilRadioGroupInputGUI($this->lng->txt("mcst_viewmode"), "viewmode");
1195  $si->addOption(new ilRadioOption($lng->txt("mcst_list"),
1197  $si->addOption(new ilRadioOption($lng->txt("mcst_gallery"),
1199 
1200 // $si->setOptions($options);
1201  $si->setValue($this->object->getViewMode());
1202  $this->form_gui->addItem($si);
1203 
1204 
1205  // Downloadable
1206  $downloadable = new ilCheckboxInputGUI($lng->txt("mcst_downloadable"), "downloadable");
1207  $downloadable->setChecked($this->object->getDownloadable());
1208  $downloadable->setInfo($lng->txt("mcst_downloadable_info"));
1209  $this->form_gui->addItem($downloadable);
1210 
1211  $news_set = new ilSetting("news");
1212  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
1213 
1214  //Default Visibility
1215  if ($enable_internal_rss)
1216  {
1217  // webfeed
1218  $sh = new ilFormSectionHeaderGUI();
1219  $sh->setTitle($lng->txt("mcst_webfeed"));
1220  $this->form_gui->addItem($sh);
1221 
1222  $radio_group = new ilRadioGroupInputGUI($lng->txt("news_default_visibility"), "defaultaccess");
1223  $radio_option = new ilRadioOption($lng->txt("news_visibility_users"), "0");
1224  $radio_option->setInfo($lng->txt("news_news_item_def_visibility_users_info"));
1225  $radio_group->addOption($radio_option);
1226  $radio_option = new ilRadioOption($lng->txt("news_visibility_public"), "1");
1227  $radio_option->setInfo($lng->txt("news_news_item_def_visibility_public_info"));
1228  $radio_group->addOption($radio_option);
1229  $radio_group->setRequired(false);
1230  $radio_group->setValue($this->object->getDefaultAccess());
1231  #$ch->addSubItem($radio_group);
1232  $this->form_gui->addItem($radio_group);
1233 
1234  //Extra Feed
1235  include_once("./Services/Block/classes/class.ilBlockSetting.php");
1236  $public_feed = ilBlockSetting::_lookup("news", "public_feed", 0, $this->object->getId());
1237  $ch = new ilCheckboxInputGUI($lng->txt("news_public_feed"), "extra_feed");
1238  $ch->setInfo($lng->txt("news_public_feed_info"));
1239  $ch->setChecked($public_feed);
1240  $this->form_gui->addItem($ch);
1241 
1242  // keep minimal x number of items
1243  $ni = new ilNumberInputGUI($this->lng->txt("news_keep_minimal_x_items"), "keep_rss_min");
1244  $ni->setMaxValue(100);
1245  $ni->setMinValue(0);
1246  $ni->setMaxLength(3);
1247  $ni->setSize(3);
1248  $ni->setInfo($this->lng->txt("news_keep_minimal_x_items_info")." (".
1249  ilNewsItem::_lookupRSSPeriod()." ".(ilNewsItem::_lookupRSSPeriod() == 1 ? $lng->txt("day") : $lng->txt("days")).")");
1250  $ni->setValue((int) ilBlockSetting::_lookup("news", "keep_rss_min", 0, $this->object->getId()));
1251  $ch->addSubItem($ni);
1252 
1253  // Include Files in Pubic Items
1254  $incl_files = new ilCheckboxInputGUI($lng->txt("mcst_incl_files_in_rss"), "public_files");
1255  $incl_files->setChecked($this->object->getPublicFiles());
1256  $incl_files->setInfo($lng->txt("mcst_incl_files_in_rss_info"));
1257  #$ch->addSubItem($incl_files);
1258  $this->form_gui->addItem($incl_files);
1259  }
1260 
1261  // Form action and save button
1262  $this->form_gui->addCommandButton("saveSettings", $lng->txt("save"));
1263  $this->form_gui->setFormAction($ilCtrl->getFormAction($this, "saveSettings"));
1264  }
1265 
1270  {
1271  global $ilCtrl, $ilTabs;
1272 
1273  $this->checkPermission("write");
1274  $ilTabs->activateTab("id_settings");
1275 
1276  $this->initSettingsForm();
1277  if ($this->form_gui->checkInput())
1278  {
1279  $news_set = new ilSetting("news");
1280  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
1281 
1282  $this->object->setTitle($this->form_gui->getInput("title"));
1283  $this->object->setDescription($this->form_gui->getInput("description"));
1284  $this->object->setOnline($this->form_gui->getInput("online"));
1285  $this->object->setDownloadable($this->form_gui->getInput("downloadable"));
1286  $this->object->setOrder($this->form_gui->getInput("order"));
1287  $this->object->setViewMode($this->form_gui->getInput("viewmode"));
1288 
1289  if ($enable_internal_rss)
1290  {
1291  $this->object->setPublicFiles($this->form_gui->getInput("public_files"));
1292  $this->object->setDefaultAccess($this->form_gui->getInput("defaultaccess"));
1293  }
1294  $this->object->update();
1295 
1296  if ($enable_internal_rss)
1297  {
1298  include_once("./Services/Block/classes/class.ilBlockSetting.php");
1299  ilBlockSetting::_write("news", "public_feed",
1300  $this->form_gui->getInput("extra_feed"),
1301  0, $this->object->getId());
1302 
1303  ilBlockSetting::_write("news", "keep_rss_min",
1304  $this->form_gui->getInput("keep_rss_min"),
1305  0, $this->object->getId());
1306  }
1307 
1308  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"),true);
1309  $ilCtrl->redirect($this, "editSettings");
1310  }
1311  else
1312  {
1313  $this->form_gui->setValuesByPost();
1314  $this->tpl->setContent($this->form_gui->getHTML());
1315  }
1316  }
1317 
1318  // add media cast to locator
1319  function addLocatorItems()
1320  {
1321  global $ilLocator;
1322 
1323  if (is_object($this->object))
1324  {
1325  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, "listItems"), "", $_GET["ref_id"]);
1326  }
1327  }
1328 
1329  public static function _goto($a_target)
1330  {
1331  global $ilAccess, $ilErr, $lng;
1332 
1333  if ($ilAccess->checkAccess("read", "", $a_target))
1334  {
1335  $_GET["cmd"] = "listItems";
1336  $_GET["ref_id"] = $a_target;
1337  $_GET["baseClass"] = "ilmediacasthandlergui";
1338  $_GET["cmdClass"] = "ilobjmediacastgui";
1339  include("ilias.php");
1340  exit;
1341  }
1342  else if ($ilAccess->checkAccess("visible", "", $a_target))
1343  {
1344  ilObjectGUI::_gotoRepositoryNode($a_target, "infoScreen");
1345  }
1346  else if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID))
1347  {
1348  ilUtil::sendFailure(sprintf($lng->txt("msg_no_perm_read_item"),
1351  }
1352 
1353  $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL);
1354 
1355  }
1356 
1363  protected static function isAudio($extension) {
1364  return strpos($extension,"audio") !== false;
1365  }
1366 
1373  protected function getMediaItem ($id) {
1374  include_once("./Services/News/classes/class.ilNewsItem.php");
1375  $this->mcst_item = new ilNewsItem($id);
1376  // create dummy object in db (we need an id)
1377  include_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
1378  $mob = new ilObjMediaObject($this->mcst_item->getMobId());
1379  return $mob->getMediaItem("Standard");
1380  }
1381 
1388  protected function getMediaItems ($id) {
1389  include_once("./Services/News/classes/class.ilNewsItem.php");
1390  $this->mcst_item = new ilNewsItem($id);
1391  // create dummy object in db (we need an id)
1392  include_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
1393  $mob = new ilObjMediaObject($this->mcst_item->getMobId());
1394  return $mob->getMediaItems();
1395  }
1396 
1397  private function populateFormFromPost()
1398  {
1399  global $tpl;
1400  //issue: we have to display the current settings
1401  // problem: POST does not contain values of disabled textfields
1402  // solution: use hidden field and label to display-> here we need to synchronize the labels
1403  // with the values from the hidden fields.
1404  foreach (ilObjMediaCast::$purposes as $purpose)
1405  {
1406  if ($_POST["value_".$purpose])
1407  {
1408  $_POST["label_value_".$purpose] = $_POST["value_".$purpose];
1409  }
1410  }
1411 
1412  $this->form_gui->setValuesByPost();
1413  $tpl->setContent($this->form_gui->getHTML());
1414  }
1415 
1416  protected function editOrderObject()
1417  {
1418  global $ilTabs, $lng, $tpl;
1419 
1420  $this->checkPermission("write");
1421  $ilTabs->activateTab("edit_content");
1422 
1423  $this->addContentSubTabs("sorting");
1424 
1425  // sort by order setting
1426  switch($this->object->getOrder())
1427  {
1431  return $this->listItemsObject();
1432 
1434  // sub-tabs
1435  break;
1436  }
1437 
1438  include_once("./Modules/MediaCast/classes/class.ilMediaCastTableGUI.php");
1439  $table_gui = new ilMediaCastTableGUI($this, "editOrder", true);
1440 
1441  $table_gui->setTitle($lng->txt("mcst_media_cast"));
1442  $table_gui->setData($this->object->getSortedItemsArray());
1443 
1444  $table_gui->addCommandButton("saveOrder", $lng->txt("mcst_save_order"));
1445 
1446  $tpl->setContent($table_gui->getHTML());
1447  }
1448 
1449  function saveOrderObject()
1450  {
1451  global $lng;
1452 
1453  asort($_POST["item_id"]);
1454 
1455  $items = array();
1456  foreach(array_keys($_POST["item_id"]) as $id)
1457  {
1458  $items[] = $id;
1459  }
1460  $this->object->saveOrder($items);
1461 
1462  ilUtil::sendSuccess($lng->txt("settings_saved"), true);
1463  $this->ctrl->redirect($this, "editOrder");
1464  }
1465 
1469 
1477  {
1478  if ($this->object->getViewMode() == ilObjMediaCast::VIEW_GALLERY)
1479  {
1480  $this->showGallery();
1481  }
1482  else
1483  {
1484  $this->listItemsObject(true);
1485  }
1486  }
1487 
1488  function showGallery()
1489  {
1490  global $tpl, $ilTabs, $ilCtrl;
1491 
1492  $tpl->addJavascript("./Modules/MediaCast/js/MediaCast.js");
1493 
1494  $ilTabs->activateTab("content");
1495 
1496  $this->addContentSubTabs("content");
1497 
1498  $ctpl = new ilTemplate("tpl.mcst_content.html", true, true, "Modules/MediaCast");
1499 
1500  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
1501  foreach ($this->object->getSortedItemsArray() as $item)
1502  {
1503  $mob = new ilObjMediaObject($item["mob_id"]);
1504  $med = $mob->getMediaItem("Standard");
1505 
1506  $ctpl->setCurrentBlock("item");
1507  $ctpl->setVariable("TITLE", $item["title"]);
1508  $ctpl->setVariable("TIME", $item["playtime"]);
1509  $ctpl->setVariable("ID", $item["id"]);
1510 
1511  if ($mob->getVideoPreviewPic() != "")
1512  {
1513  $ctpl->setVariable("PREVIEW_PIC",
1514  ilUtil::img($mob->getVideoPreviewPic(), $item["title"], 320, 240));
1515  }
1516  else
1517  {
1518  $ctpl->setVariable("PREVIEW_PIC",
1519  ilUtil::img(ilUtil::getImagePath("mcst_preview.svg"), $item["title"], 320, 240));
1520  }
1521 
1522  // player
1523  if (is_object($med))
1524  {
1525  include_once("./Services/MediaObjects/classes/class.ilMediaPlayerGUI.php");
1526 
1527  // the news id will be used as player id, see also ilMediaCastTableGUI
1528  $mpl = new ilMediaPlayerGUI($item["id"],
1529  $ilCtrl->getLinkTarget($this, "handlePlayerEvent", "", true, false));
1530 
1531  if (strcasecmp("Reference", $med->getLocationType()) == 0)
1532  {
1533  $mpl->setFile($med->getLocation());
1534  }
1535  else
1536  {
1537  $mpl->setFile(ilObjMediaObject::_getURL($mob->getId())."/".$med->getLocation());
1538  }
1539  $mpl->setMimeType ($med->getFormat());
1540  //$mpl->setDisplayHeight($med->getHeight());
1541  $mpl->setDisplayHeight("480");
1542  $mpl->setDisplayWidth("640");
1543  $mpl->setVideoPreviewPic($mob->getVideoPreviewPic());
1544  $mpl->setTitle($item["title"]);
1545  $mpl->setDescription($item["content"]);
1546  $mpl->setForceAudioPreview(true);
1547  if ($this->object->getDownloadable())
1548  {
1549  $ilCtrl->setParameterByClass("ilobjmediacastgui", "item_id", $item["id"]);
1550  $ilCtrl->setParameterByClass("ilobjmediacastgui", "purpose", "Standard");
1551  $mpl->setDownloadLink($ilCtrl->getLinkTargetByClass("ilobjmediacastgui", "downloadItem"));
1552  }
1553  $med_alt = $mob->getMediaItem("VideoAlternative");
1554  if (is_object($med_alt))
1555  {
1556  $mpl->setAlternativeVideoFile(ilObjMediaObject::_getURL($mob->getId())."/".
1557  $med_alt->getLocation());
1558  $mpl->setAlternativeVideoMimeType($med_alt->getFormat());
1559  }
1560 
1561  $ctpl->setVariable("PLAYER", $mpl->getPreviewHtml());
1562  }
1563 
1564 
1565  $ctpl->parseCurrentBlock();
1566  }
1567 
1568  $feed_icon_html = $this->getFeedIconsHTML();
1569 
1570  if ($feed_icon_html != "")
1571  {
1572  $feed_icon_html = '<p>'.$feed_icon_html.'</p>';
1573  }
1574 
1575  $tpl->setContent($feed_icon_html.$ctpl->get());
1576  }
1577 
1585  {
1586  global $ilCtrl;
1587 
1588  $this->checkPermission("write");
1589 
1590  $this->mcst_item = new ilNewsItem($_GET["item_id"]);
1591  include_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
1592  $mob = new ilObjMediaObject($this->mcst_item->getMobId());
1593 
1594  $target_purpose = ilUtil::stripSlashes($_POST["target_purpose"]);
1595  $target_format = ilUtil::stripSlashes($_POST["target_format"]);
1596 
1597  try
1598  {
1599  include_once("./Services/MediaObjects/classes/class.ilFFmpeg.php");
1600  $med = $mob->getMediaItem("Standard");
1601  $mob_file = ilObjMediaObject::_getDirectory($mob->getId())."/".$med->getLocation();
1602  $new_file = ilFFmpeg::convert($mob_file, $target_format);
1604  $pi = pathinfo($new_file);
1605  $med = $mob->getMediaItem($target_purpose);
1606  if (!is_object($med))
1607  {
1608  $med = new ilMediaItem();
1609  $med->setMobId($mob->getId());
1610  $mob->addMediaItem($med);
1611  $mob->update();
1612  $med->setPurpose($target_purpose);
1613  }
1614  $med->setFormat($target_format);
1615  $med->setLocation($pi["basename"]);
1616  $med->setLocationType("LocalFile");
1617  $med->update();
1618 
1619  $add = (is_array($ret) && count($ret) > 0)
1620  ? "<br />".implode($ret, "<br />")
1621  : "";
1622 
1623  ilUtil::sendInfo($this->lng->txt("mcst_converted_file").$add, true);
1624  }
1625  catch (ilException $e)
1626  {
1628  $add = (is_array($ret) && count($ret) > 0)
1629  ? "<br />".implode($ret, "<br />")
1630  : "";
1631  ilUtil::sendFailure($e->getMessage().$add, true);
1632  }
1633 
1634 
1635  $ilCtrl->redirect($this, "editCastItem");
1636  }
1637 
1645  {
1646  global $ilCtrl;
1647 
1648  $this->checkPermission("write");
1649 
1650  $this->mcst_item = new ilNewsItem($_GET["item_id"]);
1651  include_once("./Services/MediaObjects/classes/class.ilObjMediaObjectGUI.php");
1652  $mob = new ilObjMediaObject($this->mcst_item->getMobId());
1653 
1654  try
1655  {
1656  $sec = (int) $_POST["sec"];
1657  if ($sec < 0)
1658  {
1659  $sec = 0;
1660  }
1661  if ($mob->getVideoPreviewPic() != "")
1662  {
1663  $mob->removeAdditionalFile($mob->getVideoPreviewPic(true));
1664  }
1665  include_once("./Services/MediaObjects/classes/class.ilFFmpeg.php");
1666  $med = $mob->getMediaItem("Standard");
1667  $mob_file = ilObjMediaObject::_getDirectory($mob->getId())."/".$med->getLocation();
1668  $new_file = ilFFmpeg::extractImage($mob_file, "mob_vpreview.png",
1669  ilObjMediaObject::_getDirectory($mob->getId()), $sec);
1670 
1671  if ($new_file != "")
1672  {
1673  ilUtil::sendInfo($this->lng->txt("mcst_image_extracted"), true);
1674  }
1675  else
1676  {
1677  ilUtil::sendFailure($this->lng->txt("mcst_no_extraction_possible"), true);
1678  }
1679  }
1680  catch (ilException $e)
1681  {
1682  if (DEVMODE == 1)
1683  {
1685  $add = (is_array($ret) && count($ret) > 0)
1686  ? "<br />".implode($ret, "<br />")
1687  : "";
1688  }
1689  ilUtil::sendFailure($e->getMessage().$add, true);
1690  }
1691 
1692 
1693  $ilCtrl->redirect($this, "editCastItem");
1694  }
1695 
1703  {
1704  if ($_GET["event"] == "play")
1705  {
1706  $player = explode("_", $_GET["player"]);
1707  $news_id = (int) $player[1];
1708  include_once("./Services/News/classes/class.ilNewsItem.php");
1709  $item = new ilNewsItem($news_id);
1710  $item->increasePlayCounter();
1711  }
1712  exit;
1713  }
1714 
1715 
1716 }
1717 ?>