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