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