ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilBlogPostingGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
24 
32 {
33  protected \ILIAS\Blog\InternalGUIService $blog_gui;
35  protected \ILIAS\Notes\Service $notes;
36  protected \ILIAS\Blog\ReadingTime\ReadingTimeManager $reading_time_manager;
38  protected ilTabsGUI $tabs;
40  protected ilSetting $settings;
42  protected int $node_id;
43  protected ?object $access_handler = null;
44  protected bool $enable_public_notes = false;
45  protected bool $may_contribute = false;
46  protected bool $fetchall = false;
47  protected int $blpg = 0;
48  protected string $term = "";
49  public bool $add_date = false;
50 
51  public function __construct(
52  int $a_node_id,
53  object $a_access_handler = null,
54  int $a_id = 0,
55  int $a_old_nr = 0,
56  bool $a_enable_public_notes = true,
57  bool $a_may_contribute = true,
58  int $a_style_sheet_id = 0
59  ) {
60  global $DIC;
61 
62  $this->tabs = $DIC->tabs();
63  $this->locator = $DIC["ilLocator"];
64  $this->settings = $DIC->settings();
65  $this->user = $DIC->user();
66  $tpl = $DIC["tpl"];
67  $lng = $DIC->language();
68  $this->blog_request = $DIC->blog()
69  ->internal()
70  ->gui()
71  ->standardRequest();
72  $this->lom_services = $DIC->learningObjectMetadata();
73 
74  $lng->loadLanguageModule("blog");
75 
76  $this->node_id = $a_node_id;
77  $this->access_handler = $a_access_handler;
78  $this->enable_public_notes = $a_enable_public_notes;
79 
80  parent::__construct("blp", $a_id, $a_old_nr);
81 
82  // needed for notification
83  $this->getBlogPosting()->setBlogNodeId($this->node_id, $this->isInWorkspace());
84  $this->getBlogPosting()->getPageConfig()->setEditLockSupport(!$this->isInWorkspace());
85 
86  // #11151
87  $this->may_contribute = $a_may_contribute;
88  $this->setEnableEditing($a_may_contribute);
89 
90  // content style
91 
92  $tpl->setCurrentBlock("SyntaxStyle");
94  "LOCATION_SYNTAX_STYLESHEET",
96  );
98 
99  // #17814
100  /*
101  $tpl->setCurrentBlock("ContentStyle");
102  $tpl->setVariable(
103  "LOCATION_CONTENT_STYLESHEET",
104  ilObjStyleSheet::getContentStylePath($a_style_sheet_id)
105  );
106  $tpl->parseCurrentBlock();*/
107 
108  // needed for editor
109  $this->setStyleId($a_style_sheet_id);
110 
111  $this->blpg = $this->blog_request->getBlogPage();
112  $this->fetchall = $this->blog_request->getFetchAll();
113  $this->term = $this->blog_request->getTerm();
114 
115  $this->reading_time_manager = new \ILIAS\Blog\ReadingTime\ReadingTimeManager();
116  $this->notes = $DIC->notes();
117  $this->profile_gui = $DIC->blog()->internal()->gui()->profile();
118  $this->blog_gui = $DIC->blog()->internal()->gui();
119  }
120 
121  public function executeCommand(): string
122  {
123  $ilCtrl = $this->ctrl;
124  $ilLocator = $this->locator;
125  $tpl = $this->tpl;
126 
127  $next_class = $ilCtrl->getNextClass($this);
128 
129  $posting = $this->getBlogPosting();
130  $ilCtrl->setParameter($this, "blpg", $posting->getId());
131 
132  switch ($next_class) {
133  case "ilcommentgui":
134  // $this->getTabs();
135  // $ilTabs->setTabActive("pg");
136  return $this->previewFullscreen();
137 
138  default:
139  if ($ilCtrl->getCmd() === "deactivatePageToList") {
140  $this->tpl->setOnScreenMessage('success', $this->lng->txt("blog_draft_info"), true);
141  } elseif ($ilCtrl->getCmd() === "activatePageToList") {
142  $this->tpl->setOnScreenMessage('success', $this->lng->txt("blog_new_posting_info"), true);
143  }
144  $this->setPresentationTitle($posting->getTitle());
145 
146  $tpl->setTitle(ilObject::_lookupTitle($this->getBlogPosting()->getBlogId()) . ": " . // #15017
147  $posting->getTitle());
149  ilUtil::getImagePath("standard/icon_blog.svg"),
150  $this->lng->txt("obj_blog")
151  ); // #12879
152 
153  $ilLocator->addItem(
154  $posting->getTitle(),
155  $ilCtrl->getLinkTarget($this, "preview")
156  );
157  return parent::executeCommand();
158  }
159  }
160 
161  public function setBlogPosting(ilBlogPosting $a_posting): void
162  {
163  $this->setPageObject($a_posting);
164  }
165 
166  public function getBlogPosting(): ilBlogPosting
167  {
169  $bp = $this->getPageObject();
170  return $bp;
171  }
172 
173  protected function checkAccess(string $a_cmd): bool
174  {
175  if ($a_cmd === "contribute") {
176  return $this->may_contribute;
177  }
178  return $this->access_handler->checkAccess($a_cmd, "", $this->node_id);
179  }
180 
181  public function preview(
182  string $a_mode = null
183  ): string {
184  global $DIC;
185  $ilCtrl = $this->ctrl;
186  $tpl = $this->tpl;
188 
189  $toolbar = $DIC->toolbar();
190  $append = "";
191 
192  $this->getBlogPosting()->increaseViewCnt();
193 
194  $wtpl = new ilTemplate(
195  "tpl.blog_page_view_main_column.html",
196  true,
197  true,
198  "components/ILIAS/Blog"
199  );
200 
201  // page commands
202  if (!$a_mode) {
203  if (!$this->getEnableEditing()) {
204  $this->ctrl->redirect($this, "previewFullscreen");
205  }
206  } else {
207  $callback = array($this, "observeNoteAction");
208 
209  // notes
210 
211  $may_delete_comments = ($this->checkAccess("contribute") &&
212  $ilSetting->get("comments_del_tutor", '1'));
213 
214  //$wtpl->setVariable("TOOLBAR", $toolbar->getHTML());
215 
216  $wtpl->setVariable("NOTES", $this->getNotesHTML(
217  $this->getBlogPosting(),
218  false,
219  $this->enable_public_notes,
220  $may_delete_comments,
221  $callback
222  ));
223  }
224  // permanent link
225  $ref_id = $this->isInWorkspace()
226  ? 0
227  : $this->node_id;
228  $wsp_id = $this->isInWorkspace()
229  ? $this->node_id
230  : 0;
231  $this->blog_gui->permanentLink($ref_id, $wsp_id)->setPermanentLink($this->blpg);
232 
233  $wtpl->setVariable("PAGE", parent::preview());
234 
235  $tpl->setLoginTargetPar("blog_" . $this->node_id . $append);
236 
237  $ilCtrl->setParameter($this, "blpg", $this->getBlogPosting()->getId());
238 
239  return $wtpl->get();
240  }
241 
242 
246  public function previewFullscreen(): string
247  {
248  $this->add_date = true;
249  return $this->preview("fullscreen");
250  }
251 
252  public function showPage(
253  string $a_title = ""
254  ): string {
255  $this->setTemplateOutput(false);
256 
257  $this->setPresentationTitle("");
258  if (!$this->getAbstractOnly() && !$this->showPageHeading()) {
259  if ($a_title !== "") {
260  $this->setPresentationTitle($a_title);
261  } else {
262  $this->setPresentationTitle($this->getBlogPosting()->getTitle());
263  }
264  }
265  $this->getBlogPosting()->increaseViewCnt();
266  return parent::showPage();
267  }
268 
272  protected function isInWorkspace(): bool
273  {
274  $class = '';
275  if (is_object($this->access_handler)) {
276  $class = get_class($this->access_handler);
277  }
278 
279  return (bool) stristr($class, "workspace");
280  }
281 
285  public function postOutputProcessing(
286  string $a_output
287  ): string {
288  // #8626/#9370
289  if ($this->showPageHeading()) {
290  $a_output = $this->getPageHeading() . $a_output;
291  }
292 
293  return $a_output;
294  }
295 
296  protected function showPageHeading(): bool
297  {
298  if (!$this->getAbstractOnly() && $this->add_date) {
299  return true;
300  }
301 
302  return false;
303  }
304 
310  protected function getPageHeading(): string
311  {
312  $author = "";
313  if (!$this->isInWorkspace()) {
314  $authors = array();
315  $author_id = $this->getBlogPosting()->getAuthor();
316  if ($author_id) {
317  $authors[] = $this->profile_gui->getNamePresentation($author_id);
318  }
319 
320  foreach (ilBlogPosting::getPageContributors("blp", $this->getBlogPosting()->getId()) as $editor) {
321  if ($editor["user_id"] != $author_id) {
322  $authors[] = $this->profile_gui->getNamePresentation($editor["user_id"]);
323  }
324  }
325 
326  if ($authors) {
327  $author = implode(", ", $authors) . " - ";
328  }
329  }
332  $tpl = new ilTemplate("tpl.posting_head.html", true, true, "components/ILIAS/Blog");
333 
334  // reading time
335  $reading_time = $this->reading_time_manager->getReadingTime(
336  $this->getBlogPosting()->getParentId(),
337  $this->getBlogPosting()->getId()
338  );
339  if (!is_null($reading_time)) {
340  $this->lng->loadLanguageModule("copg");
341  $tpl->setCurrentBlock("reading_time");
342  $tpl->setVariable(
343  "READING_TIME",
344  $this->lng->txt("copg_est_reading_time") . ": " .
345  sprintf($this->lng->txt("copg_x_minutes"), $reading_time)
346  );
348  }
349 
350  $tpl->setVariable("TITLE", $this->getBlogPosting()->getTitle());
351  $tpl->setVariable(
352  "DATETIME",
353  $author . ilDatePresentation::formatDate($this->getBlogPosting()->getCreated())
354  );
356  return $tpl->get();
357  }
358 
359  public function getTabs(string $a_activate = ""): void
360  {
361  $ilCtrl = $this->ctrl;
362 
363  $ilCtrl->setParameterByClass("ilobjbloggui", "blpg", $this->getBlogPosting()->getId());
364 
365  parent::getTabs($a_activate);
366  }
367 
368  public function deleteBlogPostingConfirmationScreen(): void
369  {
370  $tpl = $this->tpl;
371  $ilCtrl = $this->ctrl;
372  $lng = $this->lng;
373 
374  if ($this->checkAccess("write") || $this->checkAccess("contribute")) {
375  $confirmation_gui = new ilConfirmationGUI();
376  $confirmation_gui->setFormAction($ilCtrl->getFormAction($this));
377  $confirmation_gui->setHeaderText($lng->txt("blog_posting_deletion_confirmation"));
378  $confirmation_gui->setCancel($lng->txt("cancel"), "cancelBlogPostingDeletion");
379  $confirmation_gui->setConfirm($lng->txt("delete"), "confirmBlogPostingDeletion");
380 
381  $dtpl = new ilTemplate(
382  "tpl.blog_posting_deletion_confirmation.html",
383  true,
384  true,
385  "components/ILIAS/Blog"
386  );
387 
388  $dtpl->setVariable("PAGE_TITLE", $this->getBlogPosting()->getTitle());
389 
390  // notes/comments
391  $cnt_note_users = $this->notes->domain()->getUserCount(
392  $this->getBlogPosting()->getParentId(),
393  $this->getBlogPosting()->getId(),
394  "wpg"
395  );
396  $dtpl->setVariable(
397  "TXT_NUMBER_USERS_NOTES_OR_COMMENTS",
398  $lng->txt("blog_number_users_notes_or_comments")
399  );
400  $dtpl->setVariable("TXT_NR_NOTES_COMMENTS", $cnt_note_users);
401 
402  $confirmation_gui->addItem("", "", $dtpl->get());
403 
404  $tpl->setContent($confirmation_gui->getHTML());
405  }
406  }
407 
408  public function cancelBlogPostingDeletion(): void
409  {
410  $ilCtrl = $this->ctrl;
411 
412  $ilCtrl->setParameterByClass("ilobjbloggui", "blpg", ""); // #14363
413  $ilCtrl->redirectByClass("ilobjbloggui", "render");
414  }
415 
416  public function confirmBlogPostingDeletion(): void
417  {
418  $ilCtrl = $this->ctrl;
419  $lng = $this->lng;
420 
421  if ($this->checkAccess("write") || $this->checkAccess("contribute")) {
422  // delete all md keywords
423  $this->lom_services->deleteAll(
424  $this->getBlogPosting()->getBlogId(),
425  $this->getBlogPosting()->getId(),
426  "blp"
427  );
428 
429  $this->getBlogPosting()->delete();
430  $this->tpl->setOnScreenMessage('success', $lng->txt("blog_posting_deleted"), true);
431  }
432 
433  $ilCtrl->setParameterByClass("ilobjbloggui", "blpg", ""); // #14363
434  $ilCtrl->redirectByClass("ilobjbloggui", "render");
435  }
436 
437  public function editTitle(ilPropertyFormGUI $a_form = null): void
438  {
439  $tpl = $this->tpl;
440  $ilTabs = $this->tabs;
441 
442  $ilTabs->clearTargets();
443  $ilTabs->setBackTarget($this->lng->txt("back"), $this->ctrl->getLinkTargetByClass("ilobjblogGUI"));
444 
445  $ilTabs->activateTab("edit");
446 
447  if (!$a_form) {
448  $a_form = $this->initTitleForm();
449  }
450 
451  $tpl->setContent($a_form->getHTML());
452  }
453 
454  public function updateTitle(): void
455  {
456  $lng = $this->lng;
457 
458  $form = $this->initTitleForm();
459  if ($form->checkInput()) {
460  if ($this->checkAccess("write") || $this->checkAccess("contribute")) {
461  $page = $this->getPageObject();
462  $page->setTitle($form->getInput("title"));
463  $page->update();
464 
465  $page->handleNews(true);
466 
467  $this->tpl->setOnScreenMessage('success', $lng->txt("settings_saved"), true);
468  //$ilCtrl->redirect($this, "preview");
469  $this->ctrl->redirectByClass("ilObjBlogGUI", "");
470  }
471  }
472 
474  $this->editTitle($form);
475  }
476 
477  public function initTitleForm(): ilPropertyFormGUI
478  {
479  $lng = $this->lng;
480  $ilCtrl = $this->ctrl;
481 
482  $form = new ilPropertyFormGUI();
483  $form->setFormAction($ilCtrl->getFormAction($this));
484  $form->setTitle($lng->txt('blog_rename_posting'));
485 
486  $title = new ilTextInputGUI($lng->txt("title"), "title");
487  $title->setRequired(true);
488  $form->addItem($title);
489 
490  $title->setValue($this->getPageObject()->getTitle());
491 
492  $form->addCommandButton('updateTitle', $lng->txt('save'));
493  $form->addCommandButton('cancelEdit', $lng->txt('cancel'));
494 
495  return $form;
496  }
497 
498  public function editDate(ilPropertyFormGUI $a_form = null): void
499  {
500  $tpl = $this->tpl;
501  $ilTabs = $this->tabs;
502 
503  $ilTabs->clearTargets();
504  $ilTabs->setBackTarget($this->lng->txt("back"), $this->ctrl->getLinkTargetByClass("ilobjblogGUI"));
505 
506  $ilTabs->activateTab("edit");
507 
508  if (!$a_form) {
509  $a_form = $this->initDateForm();
510  }
511 
512  $tpl->setContent($a_form->getHTML());
513  }
514 
515  public function updateDate(): void
516  {
517  $lng = $this->lng;
518 
519  $form = $this->initDateForm();
520  if ($form->checkInput()) {
521  if ($this->checkAccess("write") || $this->checkAccess("contribute")) {
522  $dt = $form->getItemByPostVar("date");
523  $dt = $dt->getDate();
524 
525  $page = $this->getPageObject();
526  $page->setCreated($dt);
527  $page->update();
528 
529  $this->tpl->setOnScreenMessage('success', $lng->txt("settings_saved"), true);
530  //$ilCtrl->redirect($this, "preview");
531  $this->ctrl->redirectByClass("ilObjBlogGUI", "");
532  }
533  }
534 
536  $this->editTitle($form);
537  }
538 
539  public function initDateForm(): ilPropertyFormGUI
540  {
541  $lng = $this->lng;
542  $ilCtrl = $this->ctrl;
543 
544  $form = new ilPropertyFormGUI();
545  $form->setFormAction($ilCtrl->getFormAction($this));
546  $form->setTitle($lng->txt('blog_edit_date'));
547 
548  $date = new ilDateTimeInputGUI($lng->txt("date"), "date");
549  $date->setRequired(true);
550  $date->setShowTime(true);
551  $date->setInfo($lng->txt('blog_edit_date_info'));
552  $form->addItem($date);
553 
554  $date->setDate($this->getPageObject()->getCreated());
555 
556  $form->addCommandButton('updateDate', $lng->txt('save'));
557  $form->addCommandButton('cancelEdit', $lng->txt('cancel'));
558 
559  return $form;
560  }
561 
562  protected function cancelEdit(): void
563  {
564  $this->ctrl->redirectByClass("ilObjBlogGUI", "");
565  }
566 
567  public function observeNoteAction(
568  int $a_blog_id,
569  int $a_posting_id,
570  string $a_type,
571  string $a_action,
572  int $a_note_id
573  ): void {
574  // #10040 - get note text
575  $note = $this->notes->domain()->getById($a_note_id);
576  $text = $note->getText();
577  ilObjBlog::sendNotification("comment", $this->isInWorkspace(), $this->node_id, $a_posting_id, $text);
578  }
579 
580  public function getActivationCaptions(): array
581  {
582  $lng = $this->lng;
583 
584  return array("deactivatePage" => $lng->txt("blog_toggle_draft"),
585  "activatePage" => $lng->txt("blog_toggle_final"));
586  }
587 
588  public function deactivatePageToList(): void
589  {
590  $this->deactivatePage(true);
591  }
592 
593  public function deactivatePage(bool $a_to_list = false): void
594  {
595  if ($this->checkAccess("write") || $this->checkAccess("contribute")) {
596  $this->getBlogPosting()->unpublish();
597  }
598 
599  if (!$a_to_list) {
600  $this->ctrl->redirect($this, "edit");
601  } else {
602  $this->ctrl->setParameterByClass("ilobjbloggui", "blpg", "");
603  $this->ctrl->redirectByClass("ilobjbloggui", "");
604  }
605  }
606 
607  public function activatePageToList(): void
608  {
609  $this->activatePage(true);
610  }
611 
612  public function activatePage(bool $a_to_list = false): void
613  {
614  // send notifications
615  ilObjBlog::sendNotification("new", $this->isInWorkspace(), $this->node_id, $this->getBlogPosting()->getId());
616 
617  if ($this->checkAccess("write") || $this->checkAccess("contribute")) {
618  $this->getBlogPosting()->setActive(true);
619  $this->getBlogPosting()->update(true, false);
620  }
621  if (!$a_to_list) {
622  $this->ctrl->redirect($this, "edit");
623  } else {
624  $this->ctrl->setParameterByClass("ilobjbloggui", "blpg", "");
625  $this->ctrl->redirectByClass("ilobjbloggui", "");
626  }
627  }
628 
632  public function editKeywords(): void
633  {
634  global $DIC;
635 
636  $renderer = $DIC->ui()->renderer();
637 
638  $ilTabs = $this->tabs;
639  $tpl = $this->tpl;
640 
641  $ilTabs->clearTargets();
642  $ilTabs->setBackTarget($this->lng->txt("back"), $this->ctrl->getLinkTargetByClass("ilobjblogGUI"));
643 
644  if (!$this->checkAccess("contribute")) {
645  return;
646  }
647 
648  $ilTabs->activateTab("pg");
649 
650  $tpl->setContent($renderer->render($this->initKeywordsForm()));
651  }
652 
656  protected function initKeywordsForm(): \ILIAS\UI\Component\Input\Container\Form\Standard
657  {
658  global $DIC;
659 
660  $ui_factory = $DIC->ui()->factory();
661 
662  $keywords = ilBlogPosting::getKeywords(
663  $this->getBlogPosting()->getBlogId(),
664  $this->getBlogPosting()->getId()
665  );
666 
667  // other keywords in blog
668  $other = array();
669  foreach (array_keys(ilBlogPosting::getAllPostings($this->getBlogPosting()->getBlogId())) as $posting_id) {
670  if ($posting_id != $this->getBlogPosting()->getId()) {
671  $other = array_merge($other, ilBlogPosting::getKeywords($this->getBlogPosting()->getBlogId(), $posting_id));
672  }
673  }
674  // #17414
675  $other = array_unique($other);
676  sort($other, SORT_LOCALE_STRING);
677 
678  $input_tag = $ui_factory->input()->field()->tag($this->lng->txt("blog_keywords"), $other, $this->lng->txt("blog_keyword_enter"))->withUserCreatedTagsAllowed(true);
679  if (count($keywords) > 0) {
680  $input_tag = $input_tag->withValue($keywords);
681  }
682 
683  $DIC->ctrl()->setParameter(
684  $this,
685  'tags',
686  'tags_processing'
687  );
688 
689  $section = $ui_factory->input()->field()->section([$input_tag], $this->lng->txt("blog_edit_keywords"), "");
690 
691  $form_action = $DIC->ctrl()->getFormAction($this, "saveKeywordsForm");
692  return $ui_factory->input()->container()->form()->standard($form_action, ["tags" => $section]);
693  }
694 
695  protected function getParentObjId(): int
696  {
697  if ($this->node_id) {
698  if ($this->isInWorkspace()) {
699  return $this->access_handler->getTree()->lookupObjectId($this->node_id);
700  }
701 
702  return ilObject::_lookupObjId($this->node_id);
703  }
704  return 0;
705  }
706 
707  public function saveKeywordsForm(): void
708  {
709  global $DIC;
710 
711  $request = $DIC->http()->request();
712  $form = $this->initKeywordsForm();
713 
714  if ($request->getMethod() === "POST"
715  && $request->getQueryParams()['tags'] == 'tags_processing') {
716  $form = $form->withRequest($request);
717  $result = $form->getData();
718  //TODO identify the input instead of use 0
719  $keywords = $result["tags"][0];
720 
721  if ($this->checkAccess("write") || $this->checkAccess("contribute")) {
722  if (is_array($keywords)) {
723  $this->getBlogPosting()->updateKeywords($keywords);
724  } else {
725  $this->getBlogPosting()->updateKeywords([]);
726  }
727  }
728 
729  $this->ctrl->setParameterByClass(ilObjBlogGUI::class, "blpg", "");
730  $this->ctrl->redirectByClass("ilObjBlogGUI", "");
731  }
732  }
733 
737  public static function getSnippet(
738  int $a_id,
739  bool $a_truncate = false,
740  int $a_truncate_length = 500,
741  string $a_truncate_sign = "...",
742  bool $a_include_picture = false,
743  int $a_picture_width = 144,
744  int $a_picture_height = 144,
745  string $a_export_directory = null
746  ): string {
747  $bpgui = new self(0, null, $a_id);
748 
749  // scan the full page for media objects
750  $img = "";
751  if ($a_include_picture) {
752  $img = $bpgui->getFirstMediaObjectAsTag($a_picture_width, $a_picture_height, $a_export_directory);
753  }
754 
755  $bpgui->setRawPageContent(true);
756  $bpgui->setAbstractOnly(true);
757 
758  // #8627: export won't work - should we set offline mode?
759  $bpgui->setFileDownloadLink(".");
760  $bpgui->setFullscreenLink(".");
761  $bpgui->setSourcecodeDownloadScript(".");
762  $bpgui->setProfileBackUrl(".");
763 
764  // render without title
765  $page = $bpgui->showPage();
766 
767  if ($a_truncate) {
768  $page = ilPageObject::truncateHTML($page, $a_truncate_length, $a_truncate_sign);
769  }
770 
771  if ($img) {
772  $page = '<div>' . $img . $page . '</div><div style="clear:both;"></div>';
773  }
774 
775  return $page;
776  }
777 
778  protected function getFirstMediaObjectAsTag(
779  int $a_width = 144,
780  int $a_height = 144,
781  string $a_export_directory = null
782  ): string {
783  $this->obj->buildDom();
784  $mob_ids = $this->obj->collectMediaObjects();
785  if ($mob_ids) {
786  foreach ($mob_ids as $mob_id) {
787  $mob_obj = new ilObjMediaObject((int) $mob_id);
788  $mob_item = $mob_obj->getMediaItem("Standard");
789  if (stripos($mob_item->getFormat(), "image") !== false) {
790  $mob_size = $mob_item->getOriginalSize();
791  if (is_null($mob_size)) {
792  continue;
793  }
794  if ($mob_size["width"] >= $a_width ||
795  $mob_size["height"] >= $a_height) {
796  if (!$a_export_directory) {
797  $mob_dir = ilObjMediaObject::_getDirectory($mob_obj->getId());
798  } else {
799  // see ilCOPageHTMLExport::exportHTMLMOB()
800  $mob_dir = "./mobs/mm_" . $mob_obj->getId();
801  }
802  $mob_res = self::parseImage(
803  $mob_size["width"],
804  $mob_size["height"],
805  $a_width,
806  $a_height
807  );
808 
809 
810  $location = $mob_obj->getStandardSrc();
811 
812  return '<img' .
813  ' src="' . $location . '"' .
814  ' width="' . $mob_res[0] . '"' .
815  ' height="' . $mob_res[1] . '"' .
816  ' class="ilBlogListItemSnippetPreviewImage ilFloatLeft noMirror"' .
817  ' />';
818  }
819  }
820  }
821  }
822  return "";
823  }
824 
825  protected static function parseImage(
826  int $src_width,
827  int $src_height,
828  int $tgt_width,
829  int $tgt_height
830  ): array {
831  $ratio_width = $ratio_height = 1;
832  if ($src_width > $tgt_width) {
833  $ratio_width = $tgt_width / $src_width;
834  }
835  if ($src_height > $tgt_height) {
836  $ratio_height = $tgt_height / $src_height;
837  }
838  $shrink_ratio = min($ratio_width, $ratio_height);
839 
840  return array(
841  (int) round($src_width * $shrink_ratio),
842  (int) round($src_height * $shrink_ratio)
843  );
844  }
845 
846  public function getDisabledText(): string
847  {
848  return $this->lng->txt("blog_draft_text");
849  }
850 
851  public function getCommentsHTMLExport(): string
852  {
853  return $this->getNotesHTML(
854  $this->getBlogPosting(),
855  false,
856  $this->enable_public_notes,
857  false,
858  null,
859  true
860  );
861  }
862 
863  protected function showEditToolbar(): void
864  {
865  }
866 
867  public function finishEditing(): void
868  {
869  $this->ctrl->setParameterByClass("ilobjbloggui", "bmn", "");
870  $this->ctrl->redirectByClass("ilobjbloggui", "render");
871  }
872 }
static array static setUseRelativeDates(bool $a_status)
set use relative dates
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ilObjUser $user=null,)
editTitle(ilPropertyFormGUI $a_form=null)
$renderer
Class ilBlogPosting.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
static getAllPostings(int $a_blog_id, int $a_limit=1000, int $a_offset=0)
Get all postings of blog.
getItemByPostVar(string $a_post_var)
$location
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: buildRTE.php:22
Interface Observer Contains several chained tasks and infos about them.
Class ilBlogPosting GUI class.
Class ilPageObjectGUI.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
preview(string $a_mode=null)
get(string $part=self::DEFAULT_BLOCK)
Renders the given block and returns the html string.
setParameterByClass(string $a_class, string $a_parameter, $a_value)
editKeywords()
Diplay the keywords form.
static getPageContributors(string $a_parent_type, int $a_page_id, string $a_lang="-")
Get all contributors for parent object.
loadLanguageModule(string $a_module)
Load language module.
setVariable(string $variable, $value='')
Sets the given variable to the given value.
deactivatePage(bool $a_to_list=false)
setLoginTargetPar(string $a_val)
Set target parameter for login (public sector).
setTitleIcon(string $a_icon_path, string $a_icon_desc="")
set title icon
setStyleId(int $a_styleid)
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
sort()
description: > Example for rendering a Sort Glyph.
Definition: sort.php:25
setTemplateOutput(bool $a_output=true)
This class represents a date/time property in a property form.
static _lookupObjId(int $ref_id)
static parseImage(int $src_width, int $src_height, int $tgt_width, int $tgt_height)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ILIAS Blog ReadingTime ReadingTimeManager $reading_time_manager
preview()
description: > Example for rendering a Preview Glyph.
Definition: preview.php:25
getFirstMediaObjectAsTag(int $a_width=144, int $a_height=144, string $a_export_directory=null)
StandardGUIRequest $blog_request
previewFullscreen()
Needed for portfolio/blog handling.
static truncateHTML(string $a_text, int $a_length=100, string $a_ending='...', bool $a_exact=false, bool $a_consider_html=true)
Truncate (html) string.
__construct(int $a_node_id, object $a_access_handler=null, int $a_id=0, int $a_old_nr=0, bool $a_enable_public_notes=true, bool $a_may_contribute=true, int $a_style_sheet_id=0)
static _getDirectory(int $a_mob_id)
Get absolute directory.
$ref_id
Definition: ltiauth.php:66
static sendNotification(string $a_action, bool $a_in_wsp, int $a_blog_node_id, int $a_posting_id, ?string $a_comment=null)
static _lookupTitle(int $obj_id)
setContent(string $a_html)
Sets content for standard template.
setBlogPosting(ilBlogPosting $a_posting)
setFormAction(string $a_formaction)
ilGlobalTemplateInterface $tpl
$text
Definition: xapiexit.php:21
setPageObject(ilPageObject $a_pg_obj)
ILIAS Blog InternalGUIService $blog_gui
editDate(ilPropertyFormGUI $a_form=null)
global $DIC
Definition: shib_login.php:25
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
clearTargets()
clear all targets
observeNoteAction(int $a_blog_id, int $a_posting_id, string $a_type, string $a_action, int $a_note_id)
setPresentationTitle(string $a_title="")
setTitle(string $a_title, bool $hidden=false)
Sets title in standard template.
setRequired(bool $a_required)
addCommandButton(string $a_cmd, string $a_text, string $a_id="")
activatePage(bool $a_to_list=false)
setCurrentBlock(string $part=self::DEFAULT_BLOCK)
Sets the template to the given block.
postOutputProcessing(string $a_output)
Finalizing output processing.
global $ilSetting
Definition: privfeed.php:32
EditGUIRequest $request
__construct(Container $dic, ilPlugin $plugin)
getPageHeading()
Get page heading see also https://docu.ilias.de/goto_docu_wiki_wpage_5793_1357.html the presentation ...
isInWorkspace()
Is current page part of personal workspace blog?
static getSnippet(int $a_id, bool $a_truncate=false, int $a_truncate_length=500, string $a_truncate_sign="...", bool $a_include_picture=false, int $a_picture_width=144, int $a_picture_height=144, string $a_export_directory=null)
Get first text paragraph of page.
showPage(string $a_title="")
getNotesHTML(object $a_content_object=null, bool $a_enable_private_notes=true, bool $a_enable_public_notes=false, bool $a_enable_notes_deletion=false, callable $a_callback=null, bool $export=false)
Get html for public and/or private notes.
static getKeywords(int $a_obj_id, int $a_posting_id)
parseCurrentBlock(string $block_name=self::DEFAULT_BLOCK)
Parses the given block.
ilPropertyFormGUI $form
getTabs(string $a_activate="")
ILIAS Notes Service $notes
setEnableEditing(bool $a_enableediting)