ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjBlogGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 require_once "./Services/Object/classes/class.ilObject2GUI.php";
6 include_once("./Modules/Blog/classes/class.ilBlogPosting.php");
7 
20 {
21  protected $month; // [string]
22  protected $items; // [array]
23 
24  function __construct($a_id = 0, $a_id_type = self::REPOSITORY_NODE_ID, $a_parent_node_id = 0)
25  {
26  global $lng, $ilCtrl;
27 
28  parent::__construct($a_id, $a_id_type, $a_parent_node_id);
29 
30  if($this->object)
31  {
32  $this->month = $_REQUEST["bmn"];
33 
34  // gather postings by month
35  $this->items = $this->buildPostingList($this->object->getId());
36  if($this->items)
37  {
38  // current month (if none given or empty)
39  if(!$this->month || !$this->items[$this->month])
40  {
41  $this->month = array_keys($this->items);
42  $this->month = array_shift($this->month);
43  }
44  }
45 
46  $ilCtrl->setParameter($this, "bmn", $this->month);
47  }
48 
49  $lng->loadLanguageModule("blog");
50  $ilCtrl->saveParameter($this, "prvm");
51  }
52 
53  function getType()
54  {
55  return "blog";
56  }
57 
58  protected function initCreationForms($a_new_type)
59  {
60  $forms = parent::initCreationForms($a_new_type);
61 
62  unset($forms[self::CFORM_IMPORT]);
63  unset($forms[self::CFORM_CLONE]);
64 
65  return $forms;
66  }
67 
68  protected function afterSave(ilObject $a_new_object)
69  {
70  global $ilCtrl;
71 
72  ilUtil::sendSuccess($this->lng->txt("object_added"), true);
73  $ilCtrl->redirect($this, "");
74  }
75 
76  protected function initEditCustomForm(ilPropertyFormGUI $a_form)
77  {
78  global $lng;
79 
80  $notes = new ilCheckboxInputGUI($lng->txt("blog_enable_notes"), "notes");
81  $a_form->addItem($notes);
82 
83  $ppic = new ilCheckboxInputGUI($lng->txt("blog_profile_picture"), "ppic");
84  $a_form->addItem($ppic);
85 
86  $blga_set = new ilSetting("blga");
87  if($blga_set->get("banner"))
88  {
89  $dimensions = " (".$blga_set->get("banner_width")."x".
90  $blga_set->get("banner_height").")";
91 
92  $img = new ilImageFileInputGUI($lng->txt("blog_banner").$dimensions, "banner");
93  $a_form->addItem($img);
94 
95  // show existing file
96  $file = $this->object->getImageFullPath(true);
97  if($file)
98  {
99  $img->setImage($file);
100  }
101  }
102 
103  $bg_color = new ilColorPickerInputGUI($lng->txt("blog_background_color"), "bg_color");
104  $a_form->addItem($bg_color);
105 
106  $font_color = new ilColorPickerInputGUI($lng->txt("blog_font_color"), "font_color");
107  $a_form->addItem($font_color);
108  }
109 
110  protected function getEditFormCustomValues(array &$a_values)
111  {
112  $a_values["notes"] = $this->object->getNotesStatus();
113  $a_values["ppic"] = $this->object->hasProfilePicture();
114  $a_values["bg_color"] = $this->object->getBackgroundColor();
115  $a_values["font_color"] = $this->object->getFontColor();
116  $a_values["banner"] = $this->object->getImage();
117  }
118 
119  protected function updateCustom(ilPropertyFormGUI $a_form)
120  {
121  $this->object->setNotesStatus($a_form->getInput("notes"));
122  $this->object->setProfilePicture($a_form->getInput("ppic"));
123  $this->object->setBackgroundColor($a_form->getInput("bg_color"));
124  $this->object->setFontColor($a_form->getInput("font_color"));
125 
126  // banner field is optional
127  $banner = $a_form->getItemByPostVar("banner");
128  if($banner)
129  {
130  if($_FILES["banner"]["tmp_name"])
131  {
132  $this->object->uploadImage($_FILES["banner"]);
133  }
134  else if($banner->getDeletionFlag())
135  {
136  $this->object->deleteImage();
137  }
138  }
139  }
140 
141  function setTabs()
142  {
143  global $lng;
144 
145  $this->ctrl->setParameter($this,"wsp_id",$this->node_id);
146 
147  if ($this->checkPermissionBool("read"))
148  {
149  $this->tabs_gui->addTab("content",
150  $lng->txt("content"),
151  $this->ctrl->getLinkTarget($this, ""));
152  }
153 
154  if ($this->checkPermissionBool("read"))
155  {
156  $this->tabs_gui->addTab("id_info",
157  $lng->txt("info_short"),
158  $this->ctrl->getLinkTargetByClass(array("ilobjbloggui", "ilinfoscreengui"), "showSummary"));
159  }
160 
161  if ($this->checkPermissionBool("write"))
162  {
163  $this->tabs_gui->addTab("settings",
164  $lng->txt("settings"),
165  $this->ctrl->getLinkTarget($this, "edit"));
166 
167  $this->tabs_gui->addNonTabbedLink("preview", $lng->txt("blog_preview"),
168  $this->ctrl->getLinkTarget($this, "preview"));
169  }
170 
171  // will add permissions if needed
172  parent::setTabs();
173  }
174 
175  function executeCommand()
176  {
177  global $ilCtrl, $tpl, $ilTabs, $lng, $ilUser;
178 
179  // goto link to blog posting
180  if($_GET["gtp"])
181  {
182  $ilCtrl->setCmdClass("ilblogpostinggui");
183  $_GET["blpg"] = $_GET["gtp"];
184  $ilCtrl->setCmd("previewFullscreen");
185  }
186 
187  $next_class = $ilCtrl->getNextClass($this);
188  $cmd = $ilCtrl->getCmd();
189 
190  switch($next_class)
191  {
192  case 'ilblogpostinggui':
193  $ilTabs->setBackTarget($lng->txt("back"),
194  $ilCtrl->getLinkTarget($this, ""));
195 
196  include_once("./Modules/Blog/classes/class.ilBlogPostingGUI.php");
197  $bpost_gui = new ilBlogPostingGUI($this->node_id, $this->getAccessHandler(),
198  $_GET["blpg"], $_GET["old_nr"], $this->object->getNotesStatus() && !$this->disable_notes);
199 
200  // needed for editor
202 
203  if (!$this->checkPermissionBool("write"))
204  {
205  $bpost_gui->setEnableEditing(false);
206  }
207 
208  // keep preview mode through notes gui (has its own commands)
209  switch($cmd)
210  {
211  // blog preview
212  case "previewFullscreen":
213  $ilCtrl->setParameter($this, "prvm", "fsc");
214  break;
215 
216  // blog in portfolio
217  case "previewEmbedded":
218  $ilCtrl->setParameter($this, "prvm", "emb");
219  break;
220 
221  // edit
222  default:
223  $this->ctrl->setParameterByClass("ilblogpostinggui", "blpg", $_GET["blpg"]);
224  $this->tabs_gui->addNonTabbedLink("preview", $lng->txt("blog_preview"),
225  $this->ctrl->getLinkTargetByClass("ilblogpostinggui", "previewFullscreen"));
226  $this->ctrl->setParameterByClass("ilblogpostinggui", "blpg", "");
227  break;
228  }
229 
230  $ret = $ilCtrl->forwardCommand($bpost_gui);
231  if ($ret != "")
232  {
233  // keep preview mode through notes gui
234  if($_REQUEST["prvm"])
235  {
236  $cmd = "preview".(($_REQUEST["prvm"] == "fsc") ? "Fullscreen" : "Embedded");
237  }
238 
239  $is_owner = $this->object->getOwner() == $ilUser->getId();
240  $is_active = $bpost_gui->getBlogPosting()->getActive();
241 
242  // do not show inactive postings
243  if(($cmd == "previewFullscreen" || $cmd == "previewEmbedded")
244  && !$is_owner && !$is_active)
245  {
246  $this->ctrl->redirect($this, "preview");
247  }
248 
249  switch($cmd)
250  {
251  // blog preview
252  case "previewFullscreen":
253  $this->filterInactivePostings();
254  $nav = $this->renderNavigation($this->items, "preview", $cmd);
255  $this->renderFullScreen($ret, $nav);
256  break;
257 
258  // blog in portfolio
259  case "previewEmbedded":
260  $this->filterInactivePostings();
261  $nav = $this->renderNavigation($this->items, "gethtml", $cmd);
262  return $this->buildEmbedded($ret, $nav);
263 
264  // ilias/editor
265  default:
266  // infos about draft status / snippet
267  $info = array();
268  if(!$is_active)
269  {
270  $info[] = $lng->txt("blog_draft_info");
271  }
272  if($cmd != "history" && !$bpost_gui->getBlogPosting()->getFirstParagraphText())
273  {
274  $info[] = $lng->txt("blog_new_posting_info");
275  }
276  if(sizeof($info))
277  {
278  ilUtil::sendInfo(implode("<br />", $info));
279  }
280  $this->addHeaderAction($cmd);
281  $tpl->setContent($ret);
282  $nav = $this->renderNavigation($this->items, "render", $cmd, null, $is_owner);
283  $tpl->setRightContent($nav);
284  break;
285  }
286  }
287  break;
288 
289  case "ilinfoscreengui":
290  $this->prepareOutput();
291  $this->infoScreenForward();
292  break;
293 
294  case "ilnotegui":
295  $this->preview();
296  break;
297 
298  case "ilcommonactiondispatchergui":
299  include_once("Services/Object/classes/class.ilCommonActionDispatcherGUI.php");
301  $this->ctrl->forwardCommand($gui);
302  break;
303 
304  default:
305  if($cmd != "gethtml")
306  {
307  $this->addHeaderAction($cmd);
308  }
309  return parent::executeCommand();
310  }
311 
312  return true;
313  }
314 
320  function infoScreen()
321  {
322  $this->ctrl->setCmd("showSummary");
323  $this->ctrl->setCmdClass("ilinfoscreengui");
324  $this->infoScreenForward();
325  }
326 
330  function infoScreenForward()
331  {
332  global $ilTabs, $ilErr;
333 
334  $ilTabs->activateTab("id_info");
335 
336  if (!$this->checkPermissionBool("visible"))
337  {
338  $ilErr->raiseError($this->lng->txt("msg_no_perm_read"));
339  }
340 
341  include_once("./Services/InfoScreen/classes/class.ilInfoScreenGUI.php");
342  $info = new ilInfoScreenGUI($this);
343 
344  $info->enablePrivateNotes();
345 
346  if ($this->checkPermissionBool("read"))
347  {
348  $info->enableNews();
349  }
350 
351  // no news editing for files, just notifications
352  $info->enableNewsEditing(false);
353  if ($this->checkPermissionBool("write"))
354  {
355  $news_set = new ilSetting("news");
356  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
357 
358  if ($enable_internal_rss)
359  {
360  $info->setBlockProperty("news", "settings", true);
361  $info->setBlockProperty("news", "public_notifications_option", true);
362  }
363  }
364 
365  // standard meta data
366  $info->addMetaDataSections($this->object->getId(), 0, $this->object->getType());
367 
368  $info->addProperty($this->lng->txt("perma_link"), $this->getPermanentLinkWidget());
369 
370  $this->ctrl->forwardCommand($info);
371  }
372 
376  function createPosting()
377  {
378  global $ilCtrl, $lng;
379 
380  $title = trim(ilUtil::stripSlashes($_POST["title"]));
381  if($title)
382  {
383  // create new posting
384  include_once("./Modules/Blog/classes/class.ilBlogPosting.php");
385  $posting = new ilBlogPosting();
386  $posting->setTitle($title);
387  $posting->setBlogId($this->object->getId());
388  $posting->setActive(false);
389  $posting->create();
390 
391  // switch month list to current month (will include new posting)
392  $ilCtrl->setParameter($this, "bmn", date("Y-m"));
393 
394  $ilCtrl->setParameterByClass("ilblogpostinggui", "blpg", $posting->getId());
395  $ilCtrl->redirectByClass("ilblogpostinggui", "edit");
396  }
397  else
398  {
399  $ilCtrl->redirect($this, "render");
400  }
401  }
402 
403  // --- ObjectGUI End
404 
405 
409  function render()
410  {
411  global $tpl, $ilTabs, $ilCtrl, $lng, $ilToolbar, $ilUser, $tree;
412 
413  if(!$this->checkPermissionBool("read"))
414  {
415  ilUtil::sendInfo($lng->txt("no_permission"));
416  return;
417  }
418 
419  $ilTabs->activateTab("content");
420 
421  // toolbar
422  if($this->checkPermissionBool("write"))
423  {
424  $ilToolbar->setFormAction($ilCtrl->getFormAction($this, "createPosting"));
425 
426  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
427  $title = new ilTextInputGUI($lng->txt("title"), "title");
428  $ilToolbar->addInputItem($title, $lng->txt("title"));
429 
430  $ilToolbar->addFormButton($lng->txt("blog_add_posting"), "createPosting");
431 
432  // exercise blog?
433  include_once "Modules/Exercise/classes/class.ilObjExercise.php";
434  $exercises = ilObjExercise::findUserFiles($ilUser->getId(), $this->node_id);
435  if($exercises)
436  {
437  $info = array();
438  foreach($exercises as $exercise)
439  {
440  // #9988
441  $active_ref = false;
442  foreach(ilObject::_getAllReferences($exercise["obj_id"]) as $ref_id)
443  {
444  if(!$tree->isSaved($ref_id))
445  {
446  $active_ref = true;
447  break;
448  }
449  }
450  if($active_ref)
451  {
452  $part = $this->getExerciseInfo($exercise["ass_id"]);
453  if($part)
454  {
455  $info[] = $part;
456  }
457  }
458  }
459  if(sizeof($info))
460  {
461  ilUtil::sendInfo(implode("<br />", $info));
462  }
463  }
464  }
465 
466  $list = $nav = "";
467  if($this->items[$this->month])
468  {
469  $is_owner = ($this->object->getOwner() == $ilUser->getId());
470  $list = $this->renderList($this->items[$this->month], $this->month, "preview", null, $is_owner);
471  $nav = $this->renderNavigation($this->items, "render", "preview", null, $is_owner);
472  }
473 
474  $tpl->setContent($list);
475  $tpl->setRightContent($nav);
476  }
477 
478  function getExerciseInfo($a_assignment_id)
479  {
480  global $lng, $ilCtrl, $ilUser;
481 
482  include_once "Modules/Exercise/classes/class.ilExAssignment.php";
483  $ass = new ilExAssignment($a_assignment_id);
484  $exercise_id = $ass->getExerciseId();
485  if(!$exercise_id)
486  {
487  return;
488  }
489 
490  // is the assignment still open?
491  $times_up = false;
492  if($ass->getDeadline() && $ass->getDeadline() - time() <= 0)
493  {
494  $times_up = true;
495  }
496 
497  // exercise goto
498  include_once "classes/class.ilLink.php";
499  $exc_ref_id = array_shift(ilObject::_getAllReferences($exercise_id));
500  $exc_link = ilLink::_getStaticLink($exc_ref_id, "exc");
501 
502  $info = sprintf($lng->txt("blog_exercise_info"),
503  $ass->getTitle(),
504  "<a href=\"".$exc_link."\">".
505  ilObject::_lookupTitle($exercise_id)."</a>");
506 
507  // submit button
508  if(!$times_up)
509  {
510  $ilCtrl->setParameter($this, "exc", $exercise_id);
511  $ilCtrl->setParameter($this, "ass", $a_assignment_id);
512  $submit_link = $ilCtrl->getLinkTarget($this, "finalize");
513  $ilCtrl->setParameter($this, "ass", "");
514  $ilCtrl->setParameter($this, "exc", "");
515  $info .= " <a class=\"submit\" href=\"".$submit_link."\">".$lng->txt("blog_finalize_blog")."</a>";
516  }
517 
518  // submitted files
519  $submitted = ilExAssignment::getDeliveredFiles($exercise_id, $a_assignment_id, $ilUser->getId(), true);
520  if($submitted)
521  {
522  $submitted = array_pop($submitted);
523 
524  $ilCtrl->setParameter($this, "ass", $a_assignment_id);
525  $dl_link = $ilCtrl->getLinkTarget($this, "downloadExcSubFile");
526  $ilCtrl->setParameter($this, "ass", "");
527 
530 
531  $info .= "<br />".sprintf($lng->txt("blog_exercise_submitted_info"),
533  "<a href=\"".$dl_link."\">".$lng->txt("download")."</a>");
534 
536  }
537 
538 
539  // work instructions incl. files
540 
541  $tooltip = "";
542 
543  $ass = $ass->getInstruction();
544  if($ass)
545  {
546  $tooltip .= nl2br($ass);
547  }
548 
549  $ass_files = ilExAssignment::getFiles($exercise_id, $a_assignment_id);
550  if (count($ass_files) > 0)
551  {
552  $tooltip .= "<br /><br />";
553 
554  foreach($ass_files as $file)
555  {
556  $ilCtrl->setParameter($this, "ass", $a_assignment_id);
557  $ilCtrl->setParameter($this, "file", urlencode($file["name"]));
558  $dl_link = $ilCtrl->getLinkTarget($this, "downloadExcAssFile");
559  $ilCtrl->setParameter($this, "file", "");
560  $ilCtrl->setParameter($this, "ass", "");
561 
562  $tooltip .= $file["name"].": <a href=\"".$dl_link."\">".
563  $lng->txt("download")."</a>";
564  }
565  }
566 
567  if($tooltip)
568  {
569  $ol_id = "exc_ass_".$a_assignment_id;
570 
571  include_once "Services/UIComponent/Overlay/classes/class.ilOverlayGUI.php";
572  $overlay = new ilOverlayGUI($ol_id);
573 
574  // overlay
575  $overlay->setAnchor($ol_id."_tr");
576  $overlay->setTrigger($ol_id."_tr", "click", $ol_id."_tr");
577  $overlay->setAutoHide(false);
578  // $overlay->setCloseElementId($cl_id);
579  $overlay->add();
580 
581  // trigger
582  $overlay->addTrigger($ol_id."_tr", "click", $ol_id."_tr");
583 
584  $info .= "<div id=\"".$ol_id."_tr\"><a href=\"#\">".$lng->txt("exc_instruction")."</a></div>".
585  "<div id=\"".$ol_id."\" style=\"display:none; background-color:white; border: 1px solid #bbb; padding: 10px;\">".$tooltip."</div>";
586  }
587 
588  return "<div>".$info."</div>";
589  }
590 
592  {
593  if($_GET["ass"] && $_GET["file"])
594  {
595  include_once "Modules/Exercise/classes/class.ilExAssignment.php";
596  $ass = new ilExAssignment((int)$_GET["ass"]);
597 
598  $ass_files = ilExAssignment::getFiles($ass->getExerciseId(), $ass->getId());
599  if (count($ass_files) > 0)
600  {
601  foreach($ass_files as $file)
602  {
603  if($file["name"] == $_GET["file"])
604  {
605  ilUtil::deliverFile($file["fullpath"], $file["name"]);
606  }
607  }
608  }
609  }
610  }
611 
613  {
614  global $ilUser;
615 
616  if($_GET["ass"])
617  {
618  include_once "Modules/Exercise/classes/class.ilExAssignment.php";
619  $ass = new ilExAssignment((int)$_GET["ass"]);
620 
621  $submitted = ilExAssignment::getDeliveredFiles($ass->getExerciseId(), $ass->getId(), $ilUser->getId());
622  if (count($submitted) > 0)
623  {
624  $submitted = array_pop($submitted);
625 
626  $user_data = ilObjUser::_lookupName($submitted["user_id"]);
627  $title = ilObject::_lookupTitle($submitted["obj_id"])." - ".
628  $ass->getTitle()." - ".
629  $user_data["firstname"]." ".
630  $user_data["lastname"]." (".
631  $user_data["login"].").zip";
632 
633  ilUtil::deliverFile($submitted["filename"], $title);
634  }
635  }
636  }
637 
643  function getHTML()
644  {
645  // there is no way to do a permissions check here, we have no wsp
646 
647  $this->filterInactivePostings();
648 
649  $list = $nav = "";
650  if($this->items[$this->month])
651  {
652  $list = $this->renderList($this->items[$this->month], $this->month, "previewEmbedded");
653  $nav = $this->renderNavigation($this->items, "gethtml", "previewEmbedded");
654  }
655 
656  return $this->buildEmbedded($list, $nav);
657  }
658 
662  function preview()
663  {
664  global $lng, $ilCtrl;
665 
666  if(!$this->checkPermissionBool("read"))
667  {
668  ilUtil::sendInfo($lng->txt("no_permission"));
669  return;
670  }
671 
672  $this->filterInactivePostings();
673 
674  $list = $nav = "";
675  if($this->items[$this->month])
676  {
677  $list = $this->renderList($this->items[$this->month], $this->month, "previewFullscreen");
678  $nav = $this->renderNavigation($this->items, "preview", "previewFullscreen");
679  }
680 
681  $this->renderFullScreen($list, $nav);
682  }
683 
687  function export()
688  {
689  $zip = $this->buildExportFile();
690 
691  ilUtil::deliverFile($zip, $this->object->getTitle().".zip", '', false, true);
692  }
693 
694 
695  // --- helper functions
696 
704  protected function buildEmbedded($a_content, $a_nav)
705  {
706  $wtpl = new ilTemplate("tpl.blog_embedded.html", true, true, "Modules/Blog");
707  $wtpl->setVariable("VAL_LIST", $a_content);
708  $wtpl->setVariable("VAL_NAVIGATION", $a_nav);
709  return $wtpl->get();
710  }
711 
718  function renderFullScreen($a_content, $a_navigation)
719  {
720  global $tpl, $ilUser, $ilTabs, $ilLocator;
721 
722  $owner = $this->object->getOwner();
723 
724  $ilTabs->clearTargets();
725  $ilLocator->clearItems();
726  $tpl->setLocator();
727 
728  // back (edit)
729  if($owner == $ilUser->getId())
730  {
731  // from editor
732  if($_GET["baseClass"] == "ilPersonalDesktopGUI")
733  {
734  $prvm = $_GET["prvm"];
735  $this->ctrl->setParameter($this, "prvm", "");
736  if(!$_GET["blpg"])
737  {
738  $back = $this->ctrl->getLinkTarget($this, "");
739  }
740  else
741  {
742  $this->ctrl->setParameterByClass("ilblogpostinggui", "bmn", $this->month);
743  $this->ctrl->setParameterByClass("ilblogpostinggui", "blpg", $_GET["blpg"]);
744  $back = $this->ctrl->getLinkTargetByClass("ilblogpostinggui", "preview");
745  }
746  $this->ctrl->setParameter($this, "prvm", $prvm);
747  }
748  // from shared/deeplink
749  else
750  {
751  $back = "ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToWorkspace&wsp_id=".$this->node_id;
752  }
753 
754  }
755  // back (shared resources)
756  else if($ilUser->getId() && $ilUser->getId() != ANONYMOUS_USER_ID)
757  {
758  $back = "ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToWorkspace&dsh=".$owner;
759  }
760  $tpl->setTopBar($back);
761 
762  $this->renderFullscreenHeader($tpl, $owner);
763 
764  // content
765  $tpl->setContent($a_content);
766  $tpl->setRightContent($a_navigation);
767  $tpl->setFrameFixedWidth(true);
768 
769  echo $tpl->show("DEFAULT", true, true);
770  exit();
771  }
772 
780  protected function renderFullscreenHeader($a_tpl, $a_user_id, $a_export = false)
781  {
782  $name = ilObjUser::_lookupName($a_user_id);
783  $name = $name["lastname"].", ".($t = $name["title"] ? $t . " " : "").$name["firstname"];
784 
785  // show banner?
786  $banner = false;
787  $blga_set = new ilSetting("blga");
788  if($blga_set->get("banner"))
789  {
790  $banner = $this->object->getImageFullPath();
791  $banner_width = $blga_set->get("banner_width");
792  $banner_height = $blga_set->get("banner_height");
793  if($a_export)
794  {
795  $banner = basename($banner);
796  }
797  }
798 
799  $ppic = null;
800  if($this->object->hasProfilePicture())
801  {
802  $ppic = ilObjUser::_getPersonalPicturePath($a_user_id, "big");
803  if($a_export)
804  {
805  $ppic = basename($ppic);
806  }
807  }
808 
809  include_once("./Services/User/classes/class.ilUserUtil.php");
810  $a_tpl->setFullscreenHeader($this->object->getTitle(),
811  $name,
812  $ppic,
813  $banner,
814  $this->object->getBackgroundColor(),
815  $this->object->getFontColor(),
816  $banner_width,
817  $banner_height,
818  $a_export);
819  }
820 
827  protected function buildPostingList($a_obj_id)
828  {
829  $items = array();
830  foreach(ilBlogPosting::getAllPostings($a_obj_id) as $posting)
831  {
832  $month = substr($posting["created"]->get(IL_CAL_DATE), 0, 7);
833  $items[$month][$posting["id"]] = $posting;
834  }
835  return $items;
836  }
837 
848  function renderList(array $items, $a_month, $a_cmd = "preview", $a_link_template = null, $a_show_inactive = false)
849  {
850  global $lng, $ilCtrl;
851 
852  include_once "Services/Calendar/classes/class.ilCalendarUtil.php";
853  $wtpl = new ilTemplate("tpl.blog_list.html", true, true, "Modules/Blog");
854 
855  include_once "Services/Calendar/classes/class.ilCalendarUtil.php";
856  $title = ilCalendarUtil::_numericMonthToString((int)substr($a_month, 5)).
857  " ".substr($a_month, 0, 4);
858  $wtpl->setVariable("TXT_CURRENT_MONTH", $title);
859 
860  foreach($items as $item)
861  {
862  $is_active = ilBlogPosting::_lookupActive($item["id"], "blp");
863  if(!$is_active && !$a_show_inactive)
864  {
865  continue;
866  }
867 
868  if(!$a_link_template)
869  {
870  $ilCtrl->setParameterByClass("ilblogpostinggui", "bmn", $this->month);
871  $ilCtrl->setParameterByClass("ilblogpostinggui", "blpg", $item["id"]);
872  $preview = $ilCtrl->getLinkTargetByClass("ilblogpostinggui", $a_cmd);
873  }
874  else
875  {
876  $preview = $this->buildExportLink($a_link_template, "posting", $item["id"]);
877  }
878 
879  // actions
880  if($this->checkPermissionBool("write") && !$a_link_template && $a_cmd == "preview")
881  {
882  include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
883  $alist = new ilAdvancedSelectionListGUI();
884  $alist->setId($item["id"]);
885  $alist->setListTitle($lng->txt("actions"));
886  $alist->addItem($lng->txt("edit_content"), "edit",
887  $ilCtrl->getLinkTargetByClass("ilblogpostinggui", "edit"));
888  $alist->addItem($lng->txt("rename"), "rename",
889  $ilCtrl->getLinkTargetByClass("ilblogpostinggui", "edittitle"));
890  $alist->addItem($lng->txt("delete"), "delete",
891  $ilCtrl->getLinkTargetByClass("ilblogpostinggui", "deleteBlogPostingConfirmationScreen"));
892 
893  $wtpl->setCurrentBlock("actions");
894  $wtpl->setVariable("ACTION_SELECTOR", $alist->getHTML());
895  $wtpl->parseCurrentBlock();
896  }
897 
898  // comments
899  if($this->object->getNotesStatus() && !$a_link_template && !$this->disable_notes)
900  {
901  // count (public) notes
902  include_once("Services/Notes/classes/class.ilNote.php");
903  $count = sizeof(ilNote::_getNotesOfObject($this->obj_id,
904  $item["id"], "blp", IL_NOTE_PUBLIC));
905 
906  if($a_cmd != "preview")
907  {
908  $wtpl->setCurrentBlock("comments");
909  $wtpl->setVariable("TEXT_COMMENTS", $lng->txt("blog_comments"));
910  $wtpl->setVariable("URL_COMMENTS", $preview);
911  $wtpl->setVariable("COUNT_COMMENTS", $count);
912  $wtpl->parseCurrentBlock();
913  }
914  /* we disabled comments in edit mode (should always be done via pagegui)
915  else
916  {
917  $hash = ilCommonActionDispatcherGUI::buildAjaxHash(ilCommonActionDispatcherGUI::TYPE_WORKSPACE,
918  $this->node_id, "blog", $this->obj_id, "blp", $item["id"]);
919  $notes_link = "#\" onclick=\"".ilNoteGUI::getListCommentsJSCall($hash);
920  }
921  */
922  }
923 
924  // permanent link
925  if($a_cmd != "preview" && $a_cmd != "previewEmbedded")
926  {
927  $goto = $this->getAccessHandler()->getGotoLink($this->node_id, $this->obj_id, "_".$item["id"]);
928  $wtpl->setCurrentBlock("permalink");
929  $wtpl->setVariable("URL_PERMALINK", $goto);
930  $wtpl->setVariable("TEXT_PERMALINK", $lng->txt("blog_permanent_link"));
931  $wtpl->parseCurrentBlock();
932  }
933 
934  include_once("./Modules/Blog/classes/class.ilBlogPostingGUI.php");
935  $bpgui = new ilBlogPostingGUI($this->node_id, $this->getAccessHandler(), $item["id"]);
936  $bpgui->setRawPageContent(true);
937  $bpgui->setAbstractOnly(true);
938 
939  // #8627: export won't work - should we set offline mode?
940  $bpgui->setFileDownloadLink(".");
941  $bpgui->setFullscreenLink(".");
942  $bpgui->setSourcecodeDownloadScript(".");
943 
944  $snippet = $bpgui->showPage();
945 
946  if($snippet)
947  {
948  $wtpl->setCurrentBlock("more");
949  $wtpl->setVariable("URL_MORE", $preview);
950  $wtpl->setVariable("TEXT_MORE", $lng->txt("blog_list_more"));
951  $wtpl->parseCurrentBlock();
952  }
953 
954 
955  $wtpl->setCurrentBlock("posting");
956 
957  if(!$is_active)
958  {
959  $wtpl->setVariable("DRAFT_CLASS", " ilBlogListItemDraft");
960  }
961 
962  // title
963  $wtpl->setVariable("URL_TITLE", $preview);
964  $wtpl->setVariable("TITLE", $item["title"]);
965  $wtpl->setVariable("DATETIME",
966  ilDatePresentation::formatDate($item["created"], IL_CAL_DATE));
967 
968  // content
969  $wtpl->setVariable("CONTENT", $snippet);
970 
971  $wtpl->parseCurrentBlock();
972  }
973 
974  // notes
975  /*
976  if($a_cmd == "previewFullscreen" && $this->object->getNotesStatus())
977  {
978  $wtpl->setVariable("NOTES", $this->getNotesHTML());
979  }
980  */
981 
982  // permalink
983  if($a_cmd == "previewFullscreen")
984  {
985  $wtpl->setVariable("PERMALINK", $this->getPermanentLinkWidget(null, true));
986  }
987 
988  return $wtpl->get();
989  }
990 
991  /*
992  function getNotesHTML()
993  {
994  global $ilCtrl, $ilUser;
995 
996  include_once("Services/Notes/classes/class.ilNoteGUI.php");
997  $notes_gui = new ilNoteGUI($this->object->getId(), 0, "blog");
998  // $notes_gui->enablePrivateNotes();
999  $notes_gui->enablePublicNotes();
1000 
1001  if($this->checkPermissionBool("write"))
1002  {
1003  $notes_gui->enablePublicNotesDeletion(true);
1004  }
1005 
1006  $html = $notes_gui->getNotesHTML();
1007  $next_class = $ilCtrl->getNextClass($this);
1008  if ($next_class == "ilnotegui")
1009  {
1010  $html = $ilCtrl->forwardCommand($notes_gui);
1011  }
1012  else
1013  {
1014  $html = $notes_gui->getNotesHTML();
1015  }
1016  return $html;
1017  }
1018  */
1019 
1030  function renderNavigation(array $items, $a_list_cmd = "render", $a_posting_cmd = "preview", $a_link_template = null, $a_show_inactive = false)
1031  {
1032  global $ilCtrl;
1033 
1034  $max_detail_postings = 10;
1035 
1036  $wtpl = new ilTemplate("tpl.blog_list_navigation.html", true, true,
1037  "Modules/Blog");
1038 
1039  $wtpl->setVariable("NAVIGATION_TITLE", $this->lng->txt("blog_navigation"));
1040 
1041  $ilCtrl->setParameter($this, "blpg", "");
1042 
1043  include_once "Services/Calendar/classes/class.ilCalendarUtil.php";
1044  $counter = 0;
1045  foreach($items as $month => $postings)
1046  {
1047  $month_name = ilCalendarUtil::_numericMonthToString((int)substr($month, 5)).
1048  " ".substr($month, 0, 4);
1049 
1050  if(!$a_link_template)
1051  {
1052  $ilCtrl->setParameter($this, "bmn", $month);
1053  $month_url = $ilCtrl->getLinkTarget($this, $a_list_cmd);
1054  }
1055  else
1056  {
1057  $month_url = $this->buildExportLink($a_link_template, "list", $month);
1058  }
1059 
1060  // list postings for month
1061  if($counter < $max_detail_postings)
1062  {
1063 
1064  foreach($postings as $id => $posting)
1065  {
1066  $is_active = ilBlogPosting::_lookupActive($id, "blp");
1067  if(!$is_active && !$a_show_inactive)
1068  {
1069  continue;
1070  }
1071 
1072  $counter++;
1073 
1074  $caption = /* ilDatePresentation::formatDate($posting["created"], IL_CAL_DATETIME).
1075  ", ".*/ $posting["title"];
1076 
1077  if(!$a_link_template)
1078  {
1079  $ilCtrl->setParameterByClass("ilblogpostinggui", "bmn", $month);
1080  $ilCtrl->setParameterByClass("ilblogpostinggui", "blpg", $id);
1081  $url = $ilCtrl->getLinkTargetByClass("ilblogpostinggui", $a_posting_cmd);
1082  }
1083  else
1084  {
1085  $url = $this->buildExportLink($a_link_template, "posting", $id);
1086  }
1087 
1088  if(!$is_active)
1089  {
1090  $wtpl->setCurrentBlock("navigation_item_draft");
1091  $wtpl->setVariable("NAV_ITEM_DRAFT", $this->lng->txt("blog_draft"));
1092  $wtpl->parseCurrentBlock();
1093  }
1094 
1095  $wtpl->setCurrentBlock("navigation_item");
1096  $wtpl->setVariable("NAV_ITEM_URL", $url);
1097  $wtpl->setVariable("NAV_ITEM_CAPTION", $caption);
1098  $wtpl->parseCurrentBlock();
1099  }
1100 
1101  $wtpl->setCurrentBlock("navigation_month_details");
1102  $wtpl->setVariable("NAV_MONTH", $month_name);
1103  $wtpl->setVariable("URL_MONTH", $month_url);
1104  $wtpl->parseCurrentBlock();
1105  }
1106  // summarized month
1107  else
1108  {
1109  $wtpl->setCurrentBlock("navigation_month");
1110  $wtpl->setVariable("MONTH_NAME", $month_name);
1111  $wtpl->setVariable("URL_MONTH", $month_url);
1112  $wtpl->setVariable("MONTH_COUNT", sizeof($postings));
1113  $wtpl->parseCurrentBlock();
1114  }
1115  }
1116 
1117  $ilCtrl->setParameter($this, "bmn", $this->month);
1118  $ilCtrl->setParameterByClass("ilblogpostinggui", "bmn", "");
1119 
1120  return $wtpl->get();
1121  }
1122 
1128  function buildExportFile()
1129  {
1130  // create export file
1131  include_once("./Services/Export/classes/class.ilExport.php");
1132  ilExport::_createExportDirectory($this->object->getId(), "html", "blog");
1133  $exp_dir = ilExport::_getExportDirectory($this->object->getId(), "html", "blog");
1134 
1135  $subdir = $this->object->getType()."_".$this->object->getId();
1136  $export_dir = $exp_dir."/".$subdir;
1137 
1138  // initialize temporary target directory
1139  ilUtil::delDir($export_dir);
1140  ilUtil::makeDir($export_dir);
1141 
1142  // system style html exporter
1143  include_once("./Services/Style/classes/class.ilSystemStyleHTMLExport.php");
1144  $this->sys_style_html_export = new ilSystemStyleHTMLExport($export_dir);
1145  $this->sys_style_html_export->addImage("icon_blog_b.gif");
1146  $this->sys_style_html_export->export();
1147 
1148  // init co page html exporter
1149  include_once("./Services/COPage/classes/class.ilCOPageHTMLExport.php");
1150  $this->co_page_html_export = new ilCOPageHTMLExport($export_dir);
1151  $this->co_page_html_export->createDirectories();
1152  $this->co_page_html_export->exportStyles();
1153  $this->co_page_html_export->exportSupportScripts();
1154 
1155  // banner / profile picture
1156  $blga_set = new ilSetting("blga");
1157  if($blga_set->get("banner"))
1158  {
1159  $banner = $this->object->getImageFullPath();
1160  copy($banner, $export_dir."/".basename($banner));
1161  }
1162  $ppic = ilObjUser::_getPersonalPicturePath($this->object->getOwner(), "big");
1163  if($ppic)
1164  {
1165  $ppic = array_shift(explode("?", $ppic));
1166  copy($ppic, $export_dir."/".basename($ppic));
1167  }
1168 
1169  // export pages
1170  $this->exportHTMLPages($export_dir);
1171 
1172  // zip everything
1173  if (true)
1174  {
1175  // zip it all
1176  $date = time();
1177  $zip_file = ilExport::_getExportDirectory($this->object->getId(), "html", "blog").
1178  "/".$date."__".IL_INST_ID."__".
1179  $this->object->getType()."_".$this->object->getId().".zip";
1180  ilUtil::zip($export_dir, $zip_file);
1181  ilUtil::delDir($export_dir);
1182  }
1183 
1184  return $zip_file;
1185  }
1186 
1196  function exportHTMLPages($a_target_directory, $a_link_template = null, $a_tpl_callback = null, $a_co_page_html_export = null, $a_index_name = "index.html")
1197  {
1198  if(!$a_link_template)
1199  {
1200  $a_link_template = "bl{TYPE}_{ID}.html";
1201  }
1202 
1203  if($a_co_page_html_export)
1204  {
1205  $this->co_page_html_export = $a_co_page_html_export;
1206  }
1207 
1208  $nav = $this->renderNavigation($this->items, "", "", $a_link_template);
1209 
1210  // month list
1211  $has_index = false;
1212  foreach(array_keys($this->items) as $month)
1213  {
1214  $file = $this->buildExportLink($a_link_template, "list", $month);
1215  $list = $this->renderList($this->items[$month], $month, "render", $a_link_template);
1216 
1217  if(!$a_tpl_callback)
1218  {
1219  $tpl = $this->buildExportTemplate();
1220  }
1221  else
1222  {
1223  $tpl = call_user_func($a_tpl_callback);
1224  }
1225 
1226  $file = $this->writeExportFile($a_target_directory, $file,
1227  $tpl, $list, $nav);
1228 
1229  if(!$has_index)
1230  {
1231  copy($file, $a_target_directory."/".$a_index_name);
1232  $has_index = true;
1233  }
1234  }
1235 
1236  // single postings
1237  include_once("./Services/COPage/classes/class.ilPageContentUsage.php");
1238  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
1239  $pages = ilBlogPosting::getAllPostings($this->object->getId(), 0);
1240  foreach ($pages as $page)
1241  {
1242  if (ilPageObject::_exists("blp", $page["id"]))
1243  {
1244  include_once("./Modules/Blog/classes/class.ilBlogPostingGUI.php");
1245  $blp_gui = new ilBlogPostingGUI(0, null, $page["id"]);
1246  $blp_gui->setOutputMode("offline");
1247  $blp_gui->add_date = true;
1248  $page_content = $blp_gui->showPage();
1249 
1250  $back = $this->buildExportLink($a_link_template, "list",
1251  substr($page["created"]->get(IL_CAL_DATE), 0, 7));
1252 
1253  $file = $this->buildExportLink($a_link_template, "posting", $page["id"]);
1254 
1255  if(!$a_tpl_callback)
1256  {
1257  $tpl = $this->buildExportTemplate();
1258  }
1259  else
1260  {
1261  $tpl = call_user_func($a_tpl_callback);
1262  }
1263 
1264  $this->writeExportFile($a_target_directory, $file, $tpl,
1265  $page_content, $nav, $back);
1266 
1267  $this->co_page_html_export->collectPageElements("blp:pg", $page["id"]);
1268  }
1269  }
1270  $this->co_page_html_export->exportPageElements();
1271  }
1272 
1281  protected function buildExportLink($a_template, $a_type, $a_id)
1282  {
1283  if($a_type == "list")
1284  {
1285  $a_type = "m";
1286  }
1287  else
1288  {
1289  $a_type = "p";
1290  }
1291  $link = str_replace("{TYPE}", $a_type, $a_template);
1292  return str_replace("{ID}", $a_id, $link);
1293  }
1294 
1301  protected function buildExportTemplate($a_back_url = "")
1302  {
1303  global $ilTabs, $lng;
1304 
1305  $tpl = $this->co_page_html_export->getPreparedMainTemplate();
1306 
1307  $tpl->getStandardTemplate();
1308 
1309  // workaround
1310  /* $tpl->setVariable("MAINMENU", "<div style='min-height:40px;'></div>");
1311  $tpl->setTitle($this->object->getTitle());
1312  $tpl->setTitleIcon("./images/icon_blog_b.gif",
1313  $lng->txt("obj_blog"));
1314  */
1315 
1316  $ilTabs->clearTargets();
1317  if($a_back_url)
1318  {
1319  $ilTabs->setBackTarget($lng->txt("back"), $a_back_url);
1320  }
1321 
1322  $this->renderFullscreenHeader($tpl, $this->object->getOwner(), true);
1323  $tpl->setFrameFixedWidth(true);
1324 
1325  return $tpl;
1326  }
1327 
1338  protected function writeExportFile($a_target_directory, $a_file, $a_tpl, $a_content, $a_right_content = null)
1339  {
1340  $file = $a_target_directory."/".$a_file;
1341  // return if file is already existing
1342  if (@is_file($file))
1343  {
1344  return;
1345  }
1346 
1347  // export template: page content
1348  $ep_tpl = new ilTemplate("tpl.export_page.html", true, true,
1349  "Modules/Blog");
1350  $ep_tpl->setVariable("PAGE_CONTENT", $a_content);
1351 
1352  // export template: right content
1353  if($a_right_content)
1354  {
1355  $ep_tpl->setVariable("RIGHT_CONTENT", $a_right_content);
1356  }
1357 
1358  $a_tpl->setContent($ep_tpl->get());
1359 
1360  $content = $a_tpl->get("DEFAULT", false, false, false,
1361  true, true, true);
1362 
1363  // open file
1364  if (!file_put_contents($file, $content))
1365  {
1366  die ("<b>Error</b>: Could not open \"".$file."\" for writing".
1367  " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
1368  }
1369 
1370  // set file permissions
1371  chmod($file, 0770);
1372 
1373  return $file;
1374  }
1375 
1379  protected function finalize()
1380  {
1381  global $ilCtrl, $lng;
1382 
1383  // to make exercise gui load assignment
1384  $_GET["ass_id"] = $_REQUEST["ass"];
1385 
1386  include_once "Modules/Exercise/classes/class.ilObjExerciseGUI.php";
1387  $exc_gui = new ilObjExerciseGUI(null, $_REQUEST["exc"], false);
1388  $exc_gui->submitBlog($this->node_id);
1389 
1390  ilUtil::sendSuccess($lng->txt("blog_finalized"), true);
1391  $ilCtrl->redirect($this, "render");
1392  }
1393 
1394  function getNotesSubId()
1395  {
1396  if($_REQUEST["blpg"])
1397  {
1398  return $_REQUEST["blpg"];
1399  }
1400  return 0;
1401  }
1402 
1403  function disableNotes($a_value = false)
1404  {
1405  $this->disable_notes = (bool)$a_value;
1406  }
1407 
1408  protected function addHeaderAction($a_cmd)
1409  {
1410  global $ilUser;
1411 
1412  // preview?
1413  if($a_cmd == "preview" || $_GET["prvm"])
1414  {
1415  // notification
1416  if($ilUser->getId() != ANONYMOUS_USER_ID)
1417  {
1418  return $this->insertHeaderAction($this->initHeaderAction(null, null, true));
1419  }
1420  }
1421  else
1422  {
1423  return parent::addHeaderAction();
1424  }
1425  }
1426 
1427  protected function initHeaderAction($sub_type = null, $sub_id = null, $a_is_preview = false)
1428  {
1429  global $ilUser, $ilCtrl;
1430 
1431  if(!$this->node_id)
1432  {
1433  return false;
1434  }
1435 
1436  $sub_type = $sub_id = null;
1437  if($_GET["blpg"])
1438  {
1439  $sub_type = "blp";
1440  $sub_id = $_GET["blpg"];
1441  }
1442 
1443  $lg = parent::initHeaderAction($a_sub_type, $a_sub_id);
1444 
1445  if($a_is_preview)
1446  {
1447  $lg->enableComments(false);
1448  $lg->enableNotes(false);
1449  $lg->enableTags(false);
1450 
1451  include_once "./Services/Notification/classes/class.ilNotification.php";
1453  {
1454  $ilCtrl->setParameter($this, "ntf", 1);
1455  $link = $ilCtrl->getLinkTarget($this, "setNotification");
1456  $lg->addCustomCommand($link, "blog_notification_toggle_off");
1457 
1458  $lg->addHeaderIcon("not_icon",
1459  ilUtil::getImagePath("notification_on.png"),
1460  $this->lng->txt("blog_notification_activated"));
1461  }
1462  else
1463  {
1464  $ilCtrl->setParameter($this, "ntf", 2);
1465  $link = $ilCtrl->getLinkTarget($this, "setNotification");
1466  $lg->addCustomCommand($link, "blog_notification_toggle_on");
1467 
1468  $lg->addHeaderIcon("not_icon",
1469  ilUtil::getImagePath("notification_off.png"),
1470  $this->lng->txt("blog_notification_deactivated"));
1471  }
1472  }
1473 
1474  return $lg;
1475  }
1476 
1477  protected function setNotification()
1478  {
1479  global $ilUser, $ilCtrl;
1480 
1481  include_once "./Services/Notification/classes/class.ilNotification.php";
1482  switch($_GET["ntf"])
1483  {
1484  case 1:
1486  break;
1487 
1488  case 2:
1490  break;
1491  }
1492 
1493  $ilCtrl->redirect($this, "preview");
1494  }
1495 
1503  static function lookupSubObjectTitle($a_blog_id, $a_posting_id)
1504  {
1505  // page might be deleted, so setting halt on errors to false
1506  include_once "Modules/Blog/classes/class.ilBlogPosting.php";
1507  $post = new ilBlogPosting($a_posting_id, 0, false);
1508  if($post->getBlogId() == $a_blog_id)
1509  {
1510  return $post->getTitle();
1511  }
1512  }
1513 
1519  protected function filterInactivePostings()
1520  {
1521  foreach($this->items as $month => $postings)
1522  {
1523  foreach(array_keys($postings) as $id)
1524  {
1525  if(!ilBlogPosting::_lookupActive($id, "blp"))
1526  {
1527  unset($this->items[$month][$id]);
1528  }
1529  }
1530  if(!sizeof($this->items[$month]))
1531  {
1532  unset($this->items[$month]);
1533  }
1534  }
1535 
1536  if($this->items && !isset($this->items[$this->month]))
1537  {
1538  $this->month = array_shift(array_keys($this->items));
1539  }
1540  }
1541 
1547  function _goto($a_target)
1548  {
1549  global $ilUser;
1550 
1551  $id = explode("_", $a_target);
1552 
1553  $_GET["baseClass"] = "ilsharedresourceGUI";
1554  $_GET["wsp_id"] = $id[0];
1555  if(sizeof($id) == 3)
1556  {
1557  $_GET["gtp"] = $id[1];
1558  }
1559  include("ilias.php");
1560  exit;
1561  }
1562 }
1563 
1564 ?>