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