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