ILIAS  Release_4_2_x_branch Revision 61807
 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 
34  function __construct($a_node_id, $a_access_handler = null, $a_id = 0, $a_old_nr = 0, $a_enable_public_notes = true)
35  {
36  global $tpl, $lng;
37 
38  $lng->loadLanguageModule("blog");
39 
40  $this->node_id = $a_node_id;
41  $this->access_handler = $a_access_handler;
42  $this->enable_public_notes = (bool)$a_enable_public_notes;
43 
44  parent::__construct("blp", $a_id, $a_old_nr);
45 
46  // content style
47  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
48 
49  $tpl->setCurrentBlock("SyntaxStyle");
50  $tpl->setVariable("LOCATION_SYNTAX_STYLESHEET",
52  $tpl->parseCurrentBlock();
53 
54  $tpl->setCurrentBlock("ContentStyle");
55  $tpl->setVariable("LOCATION_CONTENT_STYLESHEET",
57  $tpl->parseCurrentBlock();
58 
59  $this->setEnabledMaps(true);
60  $this->setPreventHTMLUnmasking(true);
61  $this->setEnabledInternalLinks(false);
62  $this->setEnabledWikiLinks(false);
63  $this->setEnabledPCTabs(true);
64 
65  $this->setEnabledActivation(true);
66  }
67 
75  function initPageObject($a_parent_type, $a_id, $a_old_nr)
76  {
77  $this->setPageObject(new ilBlogPosting($a_id, $a_old_nr));
78 
79  // needed for notification
80  $this->getBlogPosting()->setBlogWspId($this->node_id);
81  }
82 
86  function executeCommand()
87  {
88  global $ilCtrl, $ilTabs, $ilLocator, $tpl;
89 
90  $next_class = $ilCtrl->getNextClass($this);
91  $cmd = $ilCtrl->getCmd();
92 
93  $posting = $this->getBlogPosting();
94  $ilCtrl->setParameter($this, "blpg", $posting->getId());
95 
96  switch($next_class)
97  {
98  case "ilnotegui":
99  // $this->getTabs();
100  // $ilTabs->setTabActive("pg");
101  return $this->previewFullscreen();
102 
103  /*
104  case "ilratinggui":
105  include_once("./Services/Rating/classes/class.ilRatingGUI.php");
106  $rating_gui = new ilRatingGUI();
107  $rating_gui->setObject($this->getBlogPosting()->getParentId(), "blog",
108  $this->getBlogPosting()->getId(), "blp");
109  $this->ctrl->forwardCommand($rating_gui);
110  $ilCtrl->redirect($this, "preview");
111  break;
112  */
113 
114  case "ilpageobjectgui":
115  $page_gui = new ilPageObjectGUI("blp",
116  $this->getPageObject()->getId(),
117  $this->getPageObject()->old_nr);
118  if($posting)
119  {
120  $this->setPresentationTitle($posting->getTitle());
121  }
122  return $ilCtrl->forwardCommand($page_gui);
123 
124  default:
125  if($posting)
126  {
127  $this->setPresentationTitle($posting->getTitle());
128 
129  $tpl->setTitle(ilObject::_lookupTitle($this->getBlogPosting()->getBlogId())." - ".
130  $posting->getTitle());
131 
132  $ilLocator->addItem($posting->getTitle(),
133  $ilCtrl->getLinkTarget($this, "preview"));
134  }
135  return parent::executeCommand();
136  }
137  }
138 
144  function setBlogPosting(ilBlogPosting $a_posting)
145  {
146  $this->setPageObject($a_posting);
147  }
148 
154  function getBlogPosting()
155  {
156  return $this->getPageObject();
157  }
158 
165  protected function checkAccess($a_cmd)
166  {
167  return $this->access_handler->checkAccess($a_cmd, "", $this->node_id);
168  }
169 
173  function preview($a_mode = null)
174  {
175  global $ilCtrl, $lng, $tpl, $ilUser, $ilToolbar;
176 
177  $this->getBlogPosting()->increaseViewCnt();
178 
179  $wtpl = new ilTemplate("tpl.blog_page_view_main_column.html",
180  true, true, "Modules/Blog");
181 
182  // page commands
183  if(!$a_mode)
184  {
185  // delete
186  $page_commands = false;
187  if ($this->checkAccess("write"))
188  {
189  $wtpl->setCurrentBlock("page_command");
190  $wtpl->setVariable("HREF_PAGE_CMD",
191  $ilCtrl->getLinkTarget($this, "deleteBlogPostingConfirmationScreen"));
192  $wtpl->setVariable("TXT_PAGE_CMD", $lng->txt("delete"));
193  $wtpl->parseCurrentBlock();
194  }
195  if ($page_commands)
196  {
197  $wtpl->setCurrentBlock("page_commands");
198  $wtpl->parseCurrentBlock();
199  }
200  }
201  else
202  {
203  $callback = array($this, "observeNoteAction");
204 
205  // notes
206  $wtpl->setVariable("NOTES", $this->getNotesHTML($this->getBlogPosting(),
207  false, $this->enable_public_notes, $this->checkAccess("write"), $callback));
208  }
209 
210  // permanent link
211  if($a_mode != "embedded")
212  {
213  $append = ($_GET["blpg"] != "")
214  ? "_".$_GET["blpg"]
215  : "";
216  include_once("./Services/PermanentLink/classes/class.ilPermanentLinkGUI.php");
217  $perma_link = new ilPermanentLinkGUI("blog", $this->node_id, $append."_wsp");
218  $wtpl->setVariable("PERMA_LINK", $perma_link->getHTML());
219  }
220 
221  $wtpl->setVariable("PAGE", parent::preview());
222 
223  $tpl->setLoginTargetPar("blog_".$this->node_id.$append);
224 
225  $ilCtrl->setParameter($this, "blpg", $this->getBlogPosting()->getId());
226 
227  return $wtpl->get();
228  }
229 
235  function previewEmbedded()
236  {
237  return $this->preview("embedded");
238  }
239 
245  function previewFullscreen()
246  {
247  $this->add_date = true;
248  return $this->preview("fullscreen");
249  }
250 
256  function showPage()
257  {
258  $this->setTemplateOutput(false);
259 
260  if (!$this->getAbstractOnly())
261  {
262  $this->setPresentationTitle($this->getBlogPosting()->getTitle());
263  }
264  $this->getBlogPosting()->increaseViewCnt();
265 
266  return parent::showPage();
267  }
268 
275  function postOutputProcessing($a_output)
276  {
277  // #8626/#9370
278  if(($this->getOutputMode() == "preview" || $this->getOutputMode() == "offline")
279  && !$this->getAbstractOnly() && $this->add_date)
280  {
281  // prepend creation date
284  $prefix = "<div class=\"il_BlockInfo\" style=\"text-align:right\">".
285  ilDatePresentation::formatDate($this->getBlogPosting()->getCreated()).
286  "</div>";
288 
289  $a_output = $prefix.$a_output;
290  }
291 
292  return $a_output;
293  }
294 
300  function getTabs($a_activate = "")
301  {
302  global $ilTabs, $ilCtrl;
303 
304  // $ilCtrl->setParameterByClass("ilobjbloggui", "wsp_id", $this->getBlogPosting()->getParentId());
305  $ilCtrl->setParameterByClass("ilobjbloggui", "blpg", $this->getBlogPosting()->getId());
306 
307  parent::getTabs($a_activate);
308  }
309 
314  {
315  global $tpl, $ilCtrl, $lng;
316 
317  if ($this->checkAccess("write"))
318  {
319  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
320  $confirmation_gui = new ilConfirmationGUI();
321  $confirmation_gui->setFormAction($ilCtrl->getFormAction($this));
322  $confirmation_gui->setHeaderText($lng->txt("blog_posting_deletion_confirmation"));
323  $confirmation_gui->setCancel($lng->txt("cancel"), "cancelBlogPostingDeletion");
324  $confirmation_gui->setConfirm($lng->txt("delete"), "confirmBlogPostingDeletion");
325 
326  $dtpl = new ilTemplate("tpl.blog_posting_deletion_confirmation.html", true,
327  true, "Modules/Blog");
328 
329  $dtpl->setVariable("PAGE_TITLE", $this->getBlogPosting()->getTitle());
330 
331  // notes/comments
332  include_once("./Services/Notes/classes/class.ilNote.php");
333  $cnt_note_users = ilNote::getUserCount($this->getBlogPosting()->getParentId(),
334  $this->getBlogPosting()->getId(), "wpg");
335  $dtpl->setVariable("TXT_NUMBER_USERS_NOTES_OR_COMMENTS",
336  $lng->txt("blog_number_users_notes_or_comments"));
337  $dtpl->setVariable("TXT_NR_NOTES_COMMENTS", $cnt_note_users);
338 
339  $confirmation_gui->addItem("", "", $dtpl->get());
340 
341  $tpl->setContent($confirmation_gui->getHTML());
342  }
343  }
344 
349  {
350  global $ilCtrl;
351 
352  $ilCtrl->redirect($this, "preview");
353  }
354 
359  {
360  global $ilCtrl, $lng;
361 
362  if ($this->checkAccess("write"))
363  {
364  $this->getBlogPosting()->delete();
365  ilUtil::sendSuccess($lng->txt("blog_posting_deleted"), true);
366  }
367 
368  $ilCtrl->redirectByClass("ilobjbloggui", "render");
369  }
370 
371  function editTitle($a_form = null)
372  {
373  global $tpl, $ilTabs;
374 
375  $ilTabs->activateTab("edit");
376 
377  if(!$a_form)
378  {
379  $a_form = $this->initTitleForm();
380  }
381 
382  $tpl->setContent($a_form->getHTML());
383  }
384 
385  function updateTitle()
386  {
387  global $ilCtrl, $lng;
388 
389  $form = $this->initTitleForm();
390  if($form->checkInput())
391  {
392  $page = $this->getPageObject();
393  $page->setTitle($form->getInput("title"));
394  $page->update();
395 
396  ilUtil::sendSuccess($lng->txt("settings_saved"), true);
397  $ilCtrl->redirect($this, "preview");
398  }
399 
400  $form->setValuesByPost();
401  $this->editTitle($form);
402  }
403 
404  function initTitleForm()
405  {
406  global $lng, $ilCtrl;
407 
408  include_once('Services/Form/classes/class.ilPropertyFormGUI.php');
409  $form = new ilPropertyFormGUI();
410  $form->setFormAction($ilCtrl->getFormAction($this));
411  $form->setTitle($lng->txt('blog_rename_posting'));
412 
413  $title = new ilTextInputGUI($lng->txt("title"), "title");
414  $title->setRequired(true);
415  $form->addItem($title);
416 
417  $title->setValue($this->getPageObject()->getTitle());
418 
419  $form->addCommandButton('updateTitle', $lng->txt('save'));
420  $form->addCommandButton('preview', $lng->txt('cancel'));
421 
422  return $form;
423  }
424 
425  function observeNoteAction($a_blog_id, $a_posting_id, $a_type, $a_action)
426  {
427  include_once "Modules/Blog/classes/class.ilObjBlog.php";
428  ilObjBlog::sendNotification("comment", $this->node_id, $a_posting_id);
429  }
430 
431  protected function getActivationCaptions()
432  {
433  global $lng;
434 
435  return array("deactivatePage" => $lng->txt("blog_toggle_draft"),
436  "activatePage" => $lng->txt("blog_toggle_final"));
437  }
438 
439  function activatePage()
440  {
441  // send notifications
442  include_once "Modules/Blog/classes/class.ilObjBlog.php";
443  ilObjBlog::sendNotification("new", $this->node_id, $this->getBlogPosting()->getId());
444 
445  $this->getBlogPosting()->setActive(true);
446  $this->getBlogPosting()->update(true, false, false);
447  $this->ctrl->redirect($this, "edit");
448  }
449 }
450 
451 ?>