ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilBlogPostingGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once("./Services/COPage/classes/class.ilPageObjectGUI.php");
5 include_once("./Modules/Blog/classes/class.ilBlogPosting.php");
6 
19 {
20  protected $node_id; // [int]
21  protected $access_handler; // [object]
22  protected $enable_public_notes; // [bool]
23  protected $may_contribute; // [bool]
24 
36  function __construct($a_node_id, $a_access_handler = null, $a_id = 0, $a_old_nr = 0, $a_enable_public_notes = true, $a_may_contribute = true)
37  {
38  global $tpl, $lng;
39 
40  $lng->loadLanguageModule("blog");
41 
42  $this->node_id = $a_node_id;
43  $this->access_handler = $a_access_handler;
44  $this->enable_public_notes = (bool)$a_enable_public_notes;
45 
46  parent::__construct("blp", $a_id, $a_old_nr);
47 
48  // #11151
49  $this->may_contribute = (bool)$a_may_contribute;
50  $this->setEnableEditing($a_may_contribute);
51 
52  // content style
53  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
54 
55  $tpl->setCurrentBlock("SyntaxStyle");
56  $tpl->setVariable("LOCATION_SYNTAX_STYLESHEET",
58  $tpl->parseCurrentBlock();
59 
60  $tpl->setCurrentBlock("ContentStyle");
61  $tpl->setVariable("LOCATION_CONTENT_STYLESHEET",
63  $tpl->parseCurrentBlock();
64 
65  // #11190
66  $blga_set = new ilSetting("blga");
67  $this->setPreventHTMLUnmasking(!(bool)$blga_set->get("mask", false));
68 
69  $this->setEnabledMaps(true);
70  $this->setEnabledInternalLinks(false);
71  $this->setEnabledWikiLinks(false);
72  $this->setEnabledPCTabs(true);
73 
74  $this->setEnabledActivation(true);
75  }
76 
84  function initPageObject($a_parent_type, $a_id, $a_old_nr)
85  {
86  $this->setPageObject(new ilBlogPosting($a_id, $a_old_nr));
87 
88  // needed for notification
89  $this->getBlogPosting()->setBlogNodeId($this->node_id, $this->isInWorkspace());
90  }
91 
95  function executeCommand()
96  {
97  global $ilCtrl, $ilTabs, $ilLocator, $tpl;
98 
99  $next_class = $ilCtrl->getNextClass($this);
100  $cmd = $ilCtrl->getCmd();
101 
102  $posting = $this->getBlogPosting();
103  $ilCtrl->setParameter($this, "blpg", $posting->getId());
104 
105  switch($next_class)
106  {
107  case "ilnotegui":
108  // $this->getTabs();
109  // $ilTabs->setTabActive("pg");
110  return $this->previewFullscreen();
111 
112  /*
113  case "ilratinggui":
114  include_once("./Services/Rating/classes/class.ilRatingGUI.php");
115  $rating_gui = new ilRatingGUI();
116  $rating_gui->setObject($this->getBlogPosting()->getParentId(), "blog",
117  $this->getBlogPosting()->getId(), "blp");
118  $this->ctrl->forwardCommand($rating_gui);
119  $ilCtrl->redirect($this, "preview");
120  break;
121  */
122 
123  case "ilpageobjectgui":
124  $page_gui = new ilPageObjectGUI("blp",
125  $this->getPageObject()->getId(),
126  $this->getPageObject()->old_nr);
127  if($posting)
128  {
129  $this->setPresentationTitle($posting->getTitle());
130  }
131  return $ilCtrl->forwardCommand($page_gui);
132 
133  default:
134  if($posting)
135  {
136  $this->setPresentationTitle($posting->getTitle());
137 
138  $tpl->setTitle(ilObject::_lookupTitle($this->getBlogPosting()->getBlogId())." - ".
139  $posting->getTitle());
140  $tpl->setTitleIcon(ilUtil::getImagePath("icon_blog_b.png"),
141  $this->lng->txt("obj_blog")); // #12879
142 
143  $ilLocator->addItem($posting->getTitle(),
144  $ilCtrl->getLinkTarget($this, "preview"));
145  }
146  return parent::executeCommand();
147  }
148  }
149 
155  function setBlogPosting(ilBlogPosting $a_posting)
156  {
157  $this->setPageObject($a_posting);
158  }
159 
165  function getBlogPosting()
166  {
167  return $this->getPageObject();
168  }
169 
176  protected function checkAccess($a_cmd)
177  {
178  if($a_cmd == "contribute")
179  {
180  return $this->may_contribute;
181  }
182  return $this->access_handler->checkAccess($a_cmd, "", $this->node_id);
183  }
184 
188  function preview($a_mode = null)
189  {
190  global $ilCtrl, $lng, $tpl, $ilUser, $ilToolbar;
191 
192  $this->getBlogPosting()->increaseViewCnt();
193 
194  $wtpl = new ilTemplate("tpl.blog_page_view_main_column.html",
195  true, true, "Modules/Blog");
196 
197  // page commands
198  if(!$a_mode)
199  {
200  /*
201  // delete
202  $page_commands = false;
203  if ($this->checkAccess("write"))
204  {
205  $wtpl->setCurrentBlock("page_command");
206  $wtpl->setVariable("HREF_PAGE_CMD",
207  $ilCtrl->getLinkTarget($this, "deleteBlogPostingConfirmationScreen"));
208  $wtpl->setVariable("TXT_PAGE_CMD", $lng->txt("delete"));
209  $wtpl->parseCurrentBlock();
210  }
211  if ($page_commands)
212  {
213  $wtpl->setCurrentBlock("page_commands");
214  $wtpl->parseCurrentBlock();
215  }
216  */
217  }
218  else
219  {
220  $callback = array($this, "observeNoteAction");
221 
222  // notes
223  $wtpl->setVariable("NOTES", $this->getNotesHTML($this->getBlogPosting(),
224  false, $this->enable_public_notes, $this->checkAccess("contribute"), $callback));
225  }
226 
227  // permanent link
228  if($a_mode != "embedded")
229  {
230  $append = ($_GET["blpg"] != "")
231  ? "_".$_GET["blpg"]
232  : "";
233  if($this->isInWorkspace())
234  {
235  $append .= "_wsp";
236  }
237  include_once("./Services/PermanentLink/classes/class.ilPermanentLinkGUI.php");
238  $perma_link = new ilPermanentLinkGUI("blog", $this->node_id, $append);
239  $wtpl->setVariable("PERMA_LINK", $perma_link->getHTML());
240  }
241 
242  $wtpl->setVariable("PAGE", parent::preview());
243 
244  $tpl->setLoginTargetPar("blog_".$this->node_id.$append);
245 
246  $ilCtrl->setParameter($this, "blpg", $this->getBlogPosting()->getId());
247 
248  return $wtpl->get();
249  }
250 
256  function previewEmbedded()
257  {
258  return $this->preview("embedded");
259  }
260 
266  function previewFullscreen()
267  {
268  $this->add_date = true;
269  return $this->preview("fullscreen");
270  }
271 
277  function showPage()
278  {
279  $this->setTemplateOutput(false);
280 
281  if (!$this->getAbstractOnly())
282  {
283  $this->setPresentationTitle($this->getBlogPosting()->getTitle());
284  }
285  $this->getBlogPosting()->increaseViewCnt();
286 
287  return parent::showPage();
288  }
289 
295  protected function isInWorkspace()
296  {
297  return stristr(get_class($this->access_handler), "workspace");
298  }
299 
306  function postOutputProcessing($a_output)
307  {
308  // #8626/#9370
309  if(($this->getOutputMode() == "preview" || $this->getOutputMode() == "offline")
310  && !$this->getAbstractOnly() && $this->add_date)
311  {
312  if(!$this->isInWorkspace())
313  {
314  $author = "";
315  $author_id = $this->getBlogPosting()->getAuthor();
316  if($author_id)
317  {
318  include_once "Services/User/classes/class.ilUserUtil.php";
319  $author = ilUserUtil::getNamePresentation($author_id)." - ";
320  }
321  }
322 
323  // prepend creation date
326  $prefix = "<div class=\"il_BlockInfo\" style=\"text-align:right\">".
327  $author.ilDatePresentation::formatDate($this->getBlogPosting()->getCreated()).
328  "</div>";
330 
331  $a_output = $prefix.$a_output;
332  }
333 
334  return $a_output;
335  }
336 
342  function getTabs($a_activate = "")
343  {
344  global $ilCtrl;
345 
346  $ilCtrl->setParameterByClass("ilobjbloggui", "blpg", $this->getBlogPosting()->getId());
347 
348  parent::getTabs($a_activate);
349  }
350 
355  {
356  global $tpl, $ilCtrl, $lng;
357 
358  if ($this->checkAccess("write") || $this->checkAccess("contribute"))
359  {
360  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
361  $confirmation_gui = new ilConfirmationGUI();
362  $confirmation_gui->setFormAction($ilCtrl->getFormAction($this));
363  $confirmation_gui->setHeaderText($lng->txt("blog_posting_deletion_confirmation"));
364  $confirmation_gui->setCancel($lng->txt("cancel"), "cancelBlogPostingDeletion");
365  $confirmation_gui->setConfirm($lng->txt("delete"), "confirmBlogPostingDeletion");
366 
367  $dtpl = new ilTemplate("tpl.blog_posting_deletion_confirmation.html", true,
368  true, "Modules/Blog");
369 
370  $dtpl->setVariable("PAGE_TITLE", $this->getBlogPosting()->getTitle());
371 
372  // notes/comments
373  include_once("./Services/Notes/classes/class.ilNote.php");
374  $cnt_note_users = ilNote::getUserCount($this->getBlogPosting()->getParentId(),
375  $this->getBlogPosting()->getId(), "wpg");
376  $dtpl->setVariable("TXT_NUMBER_USERS_NOTES_OR_COMMENTS",
377  $lng->txt("blog_number_users_notes_or_comments"));
378  $dtpl->setVariable("TXT_NR_NOTES_COMMENTS", $cnt_note_users);
379 
380  $confirmation_gui->addItem("", "", $dtpl->get());
381 
382  $tpl->setContent($confirmation_gui->getHTML());
383  }
384  }
385 
390  {
391  global $ilCtrl;
392 
393  $ilCtrl->redirect($this, "preview");
394  }
395 
400  {
401  global $ilCtrl, $lng;
402 
403  if ($this->checkAccess("write") || $this->checkAccess("contribute"))
404  {
405  // delete all md keywords
406  $md_section = $this->getMDSection();
407  foreach($md_section->getKeywordIds() as $id)
408  {
409  $md_key = $md_section->getKeyword($id);
410  $md_key->delete();
411  }
412 
413  $this->getBlogPosting()->delete();
414  ilUtil::sendSuccess($lng->txt("blog_posting_deleted"), true);
415  }
416 
417  $ilCtrl->setParameterByClass("ilobjbloggui", "blpg", ""); // #14363
418  $ilCtrl->redirectByClass("ilobjbloggui", "render");
419  }
420 
421  function editTitle($a_form = null)
422  {
423  global $tpl, $ilTabs;
424 
425  $ilTabs->activateTab("edit");
426 
427  if(!$a_form)
428  {
429  $a_form = $this->initTitleForm();
430  }
431 
432  $tpl->setContent($a_form->getHTML());
433  }
434 
435  function updateTitle()
436  {
437  global $ilCtrl, $lng;
438 
439  $form = $this->initTitleForm();
440  if($form->checkInput())
441  {
442  $page = $this->getPageObject();
443  $page->setTitle($form->getInput("title"));
444  $page->update();
445 
446  ilUtil::sendSuccess($lng->txt("settings_saved"), true);
447  $ilCtrl->redirect($this, "preview");
448  }
449 
450  $form->setValuesByPost();
451  $this->editTitle($form);
452  }
453 
454  function initTitleForm()
455  {
456  global $lng, $ilCtrl;
457 
458  include_once('Services/Form/classes/class.ilPropertyFormGUI.php');
459  $form = new ilPropertyFormGUI();
460  $form->setFormAction($ilCtrl->getFormAction($this));
461  $form->setTitle($lng->txt('blog_rename_posting'));
462 
463  $title = new ilTextInputGUI($lng->txt("title"), "title");
464  $title->setRequired(true);
465  $form->addItem($title);
466 
467  $title->setValue($this->getPageObject()->getTitle());
468 
469  $form->addCommandButton('updateTitle', $lng->txt('save'));
470  $form->addCommandButton('preview', $lng->txt('cancel'));
471 
472  return $form;
473  }
474 
475  function editDate($a_form = null)
476  {
477  global $tpl, $ilTabs;
478 
479  $ilTabs->activateTab("edit");
480 
481  if(!$a_form)
482  {
483  $a_form = $this->initDateForm();
484  }
485 
486  $tpl->setContent($a_form->getHTML());
487  }
488 
489  function updateDate()
490  {
491  global $ilCtrl, $lng;
492 
493  $form = $this->initDateForm();
494  if($form->checkInput())
495  {
496  $dt = $form->getInput("date");
497  $dt = new ilDateTime($dt["date"]." ".$dt["time"], IL_CAL_DATETIME);
498 
499  $page = $this->getPageObject();
500  $page->setCreated($dt);
501  $page->update();
502 
503  ilUtil::sendSuccess($lng->txt("settings_saved"), true);
504  $ilCtrl->redirect($this, "preview");
505  }
506 
507  $form->setValuesByPost();
508  $this->editTitle($form);
509  }
510 
511  function initDateForm()
512  {
513  global $lng, $ilCtrl;
514 
515  include_once('Services/Form/classes/class.ilPropertyFormGUI.php');
516  $form = new ilPropertyFormGUI();
517  $form->setFormAction($ilCtrl->getFormAction($this));
518  $form->setTitle($lng->txt('blog_edit_date'));
519 
520  $date = new ilDateTimeInputGUI($lng->txt("date"), "date");
521  $date->setRequired(true);
522  $date->setShowTime(true);
523  $date->setInfo($lng->txt('blog_edit_date_info'));
524  $form->addItem($date);
525 
526  $date->setDate($this->getPageObject()->getCreated());
527 
528  $form->addCommandButton('updateDate', $lng->txt('save'));
529  $form->addCommandButton('preview', $lng->txt('cancel'));
530 
531  return $form;
532  }
533 
534  function observeNoteAction($a_blog_id, $a_posting_id, $a_type, $a_action, $a_note_id)
535  {
536  // #10040 - get note text
537  include_once "Services/Notes/classes/class.ilNote.php";
538  $note = new ilNote($a_note_id);
539  $note = $note->getText();
540 
541  include_once "Modules/Blog/classes/class.ilObjBlog.php";
542  ilObjBlog::sendNotification("comment", $this->isInWorkspace(), $this->node_id, $a_posting_id, $note);
543  }
544 
545  protected function getActivationCaptions()
546  {
547  global $lng;
548 
549  return array("deactivatePage" => $lng->txt("blog_toggle_draft"),
550  "activatePage" => $lng->txt("blog_toggle_final"));
551  }
552 
553  function deactivatePage()
554  {
555  $this->getBlogPosting()->setApproved(false);
556  $this->getBlogPosting()->setActive(false);
557  $this->getBlogPosting()->update(true, false, false);
558  $this->ctrl->redirect($this, "edit");
559  }
560 
561  function activatePage()
562  {
563  // send notifications
564  include_once "Modules/Blog/classes/class.ilObjBlog.php";
565  ilObjBlog::sendNotification("new", $this->isInWorkspace(), $this->node_id, $this->getBlogPosting()->getId());
566 
567  $this->getBlogPosting()->setActive(true);
568  $this->getBlogPosting()->update(true, false, false);
569  $this->ctrl->redirect($this, "edit");
570  }
571 
572  function editKeywords(ilPropertyFormGUI $a_form = null)
573  {
574  global $ilTabs, $tpl;
575 
576  if (!$this->checkAccess("contribute"))
577  {
578  return;
579  }
580 
581  $ilTabs->activateTab("pg");
582 
583  if(!$a_form)
584  {
585  $a_form = $this->initKeywordsForm();
586  }
587 
588  $tpl->setContent($a_form->getHTML());
589  }
590 
591  protected function initKeywordsForm()
592  {
593  global $ilUser;
594 
595  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
596  $form = new ilPropertyFormGUI();
597  $form->setFormAction($this->ctrl->getFormAction($this, "saveKeywordsForm"));
598  $form->setTitle($this->lng->txt("blog_edit_keywords"));
599 
600  $txt = new ilTextInputGUI($this->lng->txt("blog_keywords"), "keywords");
601  // $txt->setRequired(true); #10504
602  $txt->setMulti(true);
603  $txt->setDataSource($this->ctrl->getLinkTarget($this, "keywordAutocomplete", "", true));
604  $txt->setMaxLength(200);
605  $txt->setSize(50);
606  $txt->setInfo($this->lng->txt("blog_keywords_info"));
607  $form->addItem($txt);
608 
609  $md_section = $this->getMDSection();
610 
611  $keywords = array();
612  foreach($ids = $md_section->getKeywordIds() as $id)
613  {
614  $md_key = $md_section->getKeyword($id);
615  if (trim($md_key->getKeyword()) != "")
616  {
617  $keywords[$md_key->getKeywordLanguageCode()][]
618  = $md_key->getKeyword();
619  }
620  }
621 
622  // language is not "used" anywhere
623  $ulang = $ilUser->getLanguage();
624  if($keywords[$ulang])
625  {
626  asort($keywords[$ulang]);
627  $txt->setValue($keywords[$ulang]);
628  }
629 
630  $form->addCommandButton("saveKeywordsForm", $this->lng->txt("save"));
631  $form->addCommandButton("preview", $this->lng->txt("cancel"));
632 
633  return $form;
634  }
635 
636  protected function getParentObjId()
637  {
638  if($this->node_id)
639  {
640  if($this->isInWorkspace())
641  {
642  return $this->access_handler->getTree()->lookupObjectId($this->node_id);
643  }
644  else
645  {
646  return ilObject::_lookupObjId($this->node_id);
647  }
648  }
649  }
650 
651  protected function getMDSection()
652  {
653  // general section available?
654  include_once 'Services/MetaData/classes/class.ilMD.php';
655  $md_obj = new ilMD($this->getParentObjId(),
656  $this->getBlogPosting()->getId(), "blp");
657  if(!is_object($md_section = $md_obj->getGeneral()))
658  {
659  $md_section = $md_obj->addGeneral();
660  $md_section->save();
661  }
662 
663  return $md_section;
664  }
665 
666  function saveKeywordsForm()
667  {
668  global $ilUser;
669 
670  $form = $this->initKeywordsForm();
671  if($form->checkInput())
672  {
673  $keywords = $form->getInput("keywords");
674  if(is_array($keywords))
675  {
676  // language is not "used" anywhere
677  $ulang = $ilUser->getLanguage();
678  $keywords = array($ulang=>$keywords);
679 
680  include_once("./Services/MetaData/classes/class.ilMDKeyword.php");
681  ilMDKeyword::updateKeywords($this->getMDSection(), $keywords);
682  }
683 
684  $this->ctrl->redirect($this, "preview");
685  }
686 
687  $form->setValuesByPost();
688  $this->editKeywords($form);
689  }
690 
691  public static function getKeywords($a_obj_id, $a_posting_id)
692  {
693  include_once("./Services/MetaData/classes/class.ilMDKeyword.php");
694  return ilMDKeyword::lookupKeywords($a_obj_id, $a_posting_id);
695  }
696 
698  {
699  include_once("./Services/MetaData/classes/class.ilMDKeyword.php");
701  "blp", $this->getParentObjId());
702 
703  $result = array();
704  $cnt = 0;
705  foreach ($res as $r)
706  {
707  if ($cnt++ > 19)
708  {
709  continue;
710  }
711  $entry = new stdClass();
712  $entry->value = $r;
713  $entry->label = $r;
714  $result[] = $entry;
715  }
716 
717  include_once './Services/JSON/classes/class.ilJsonUtil.php';
719  exit;
720  }
721 
728  static function getSnippet($a_id)
729  {
730  $bpgui = new self(0, null, $a_id);
731  $bpgui->setRawPageContent(true);
732  $bpgui->setAbstractOnly(true);
733 
734  // #8627: export won't work - should we set offline mode?
735  $bpgui->setFileDownloadLink(".");
736  $bpgui->setFullscreenLink(".");
737  $bpgui->setSourcecodeDownloadScript(".");
738 
739  return $bpgui->showPage();
740  }
741 }
742 
743 ?>