ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilExternalFeedBlockGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5
18{
19 const FORM_EDIT = 0;
20 const FORM_CREATE = 1;
21 const FORM_RE_EDIT = 2;
22 const FORM_RE_CREATE = 2;
23
24 protected $gui_object;
25 protected $form_edit_mode;
26
30 protected $settings;
31
35 protected $rbacsystem;
36
40 protected $obj_definition;
41
42 public static $block_type = "feed";
43
47 public function __construct()
48 {
49 global $DIC;
50
51 $this->ctrl = $DIC->ctrl();
52 $this->lng = $DIC->language();
53 $this->user = $DIC->user();
54 $this->access = $DIC->access();
55 $this->settings = $DIC->settings();
56 $this->rbacsystem = $DIC->rbac()->system();
57 $this->obj_definition = $DIC["objDefinition"];
58 $lng = $DIC->language();
59
61
62 $lng->loadLanguageModule("feed");
63 $this->setLimit(5);
64 $this->setRowTemplate("tpl.block_external_feed_row.html", "Services/Feeds");
65
66 if (isset($_GET["external_feed_block_id"]) && $_GET["external_feed_block_id"] > 0) {
67 $this->external_feed_block = new ilExternalFeedBlock($_GET["external_feed_block_id"]);
68 }
69
70 $this->ctrl->saveParameter($this, array("external_feed_block_id"));
71
72 $this->setPresentation(self::PRES_SEC_LIST);
73 }
74
78 public function getBlockType() : string
79 {
80 return self::$block_type;
81 }
82
86 protected function isRepositoryObject() : bool
87 {
88 return true;
89 }
90
94 public static function getScreenMode()
95 {
96 global $DIC;
97
98 $ilCtrl = $DIC->ctrl();
99
100 switch ($ilCtrl->getCmd()) {
101 case "create":
102 case "edit":
103 case "saveFeedBlock":
104 case "updateFeedBlock":
105 case "editFeedBlock":
106 case "showFeedItem":
107 case "confirmDeleteFeedBlock":
108 return IL_SCREEN_CENTER;
109 break;
110
111 default:
112 return IL_SCREEN_SIDE;
113 break;
114 }
115 }
116
120 public function setBlock($a_block)
121 {
123
124 // init block
125 $this->feed_block = $a_block;
126 $this->setTitle($this->feed_block->getTitle());
127 $this->setBlockId($this->feed_block->getId());
128
129 // get feed object
130 include_once("./Services/Feeds/classes/class.ilExternalFeed.php");
131 $this->feed = new ilExternalFeed();
132 $this->feed->setUrl($this->feed_block->getFeedUrl());
133
134 // init details
135
136 $ilCtrl->setParameter($this, "block_id", $this->feed_block->getId());
137 }
138
139
140
146 public function setGuiObject(&$a_gui_object)
147 {
148 $this->gui_object = $a_gui_object;
149 }
150
156 public function getGuiObject()
157 {
158 return $this->gui_object;
159 }
160
166 public function setFormEditMode($a_form_edit_mode)
167 {
168 $this->form_edit_mode = $a_form_edit_mode;
169 }
170
176 public function getFormEditMode()
177 {
179 }
180
185 public function createFeedBlock()
186 {
187 $this->initFormFeedBlock(self::FORM_CREATE);
188 return $this->form_gui->getHtml();
189 }
190
195 public function editFeedBlock()
196 {
197 $this->initFormFeedBlock(self::FORM_EDIT);
198 $this->getValuesFeedBlock();
199 return $this->form_gui->getHtml();
200 }
201
206 public function saveFeedBlock()
207 {
208 $this->initFormFeedBlock(self::FORM_CREATE);
209
210 $this->external_feed_block = new ilExternalFeedBlock();
211
212 if ($this->form_gui->checkInput() &&
213 !$this->external_feed_block->isFeedUrlLocal($this->form_gui->getInput("block_feed_url"))) {
214 $this->external_feed_block->setTitle($this->form_gui->getInput("block_title"));
215 $this->external_feed_block->setFeedUrl($this->form_gui->getInput("block_feed_url"));
216 $this->prepareSaveFeedBlock($this->external_feed_block);
217 $this->external_feed_block->create();
218 $this->exitSaveFeedBlock();
219 } else {
220 if ($this->external_feed_block->isFeedUrlLocal($this->form_gui->getInput("block_feed_url"))) {
221 ilUtil::sendFailure($this->lng->txt("feed_no_local_url"), true);
222 }
223 $this->form_gui->setValuesByPost();
224 return $this->form_gui->getHtml();
225 }
226 }
227
232 public function updateFeedBlock()
233 {
234 $this->initFormFeedBlock(self::FORM_EDIT);
235 if ($this->form_gui->checkInput() &&
236 !$this->external_feed_block->isFeedUrlLocal($this->form_gui->getInput("block_feed_url"))) {
237 $this->external_feed_block->setTitle($this->form_gui->getInput("block_title"));
238 $this->external_feed_block->setFeedUrl($this->form_gui->getInput("block_feed_url"));
239 $this->external_feed_block->update();
240 $this->exitUpdateFeedBlock();
241 } else {
242 if ($this->external_feed_block->isFeedUrlLocal($this->form_gui->getInput("block_feed_url"))) {
243 ilUtil::sendFailure($this->lng->txt("feed_no_local_url"));
244 }
245 $this->form_gui->setValuesByPost();
246 return $this->form_gui->getHtml();
247 }
248 }
249
250
255 public function getValuesFeedBlock()
256 {
257 $values = array();
258
259 $values["block_title"] = $this->external_feed_block->getTitle();
260 $values["block_feed_url"] = $this->external_feed_block->getFeedUrl();
261
262 $this->form_gui->setValuesByArray($values);
263 }
264
269 public function cancelSaveFeedBlock()
270 {
272
273 $ilCtrl->returnToParent($this);
274 }
275
276
280 public function executeCommand()
281 {
283
284 $next_class = $ilCtrl->getNextClass();
285 $cmd = $ilCtrl->getCmd("getHTML");
286 switch ($next_class) {
287 default:
288 return $this->$cmd();
289 }
290 }
291
295 public function fillDataSection()
296 {
297 if ($this->getDynamic()) {
298 $this->setDataSection($this->getDynamicReload());
299 } elseif (count($this->getData()) > 0) {
300 parent::fillDataSection();
301 } else {
302 $this->setDataSection($this->getOverview());
303 }
304 }
305
309 public function getHTML()
310 {
314 $ilAccess = $this->access;
315
316
317 $feed_set = new ilSetting("feed");
318
319 if ($feed_set->get("disable_rep_feeds")) {
320 return "";
321 }
322
323 // if no dynamic reload
324 if (!$this->getDynamic()) {
325 $this->feed->fetch();
326 $this->setData(array_map(function ($i) {
327 return ["item" => $i];
328 }, $this->feed->getItems()));
329 }
330
331 //$this->setTitle($this->feed->getChannelTitle());
332 //$this->setData($this->feed->getItems());
333
334 if ($ilAccess->checkAccess("write", "", $this->getRefId())) {
335 $ilCtrl->setParameterByClass(
336 "ilobjexternalfeedgui",
337 "ref_id",
338 $this->getRefId()
339 );
340 $ilCtrl->setParameter($this, "external_feed_block_id", $this->getBlockId());
341 $this->addBlockCommand(
342 $ilCtrl->getLinkTargetByClass(
343 array("ilrepositorygui", "ilobjexternalfeedgui",
344 "ilexternalfeedblockgui"),
345 "editFeedBlock"
346 ),
347 $lng->txt("settings")
348 );
349 $ilCtrl->clearParametersByClass("ilobjexternalfeedgui");
350 }
351
352 // JS enabler
353 $add = "";
354 if ($_SESSION["il_feed_js"] == "n" ||
355 ($ilUser->getPref("il_feed_js") == "n" && $_SESSION["il_feed_js"] != "y")) {
356 $add = $this->getJSEnabler();
357 }
358
359 return parent::getHTML() . $add;
360 }
361
362 public function getDynamic()
363 {
366
367 // @todo
368 return false;
369
370 if ($ilCtrl->getCmdClass() != "ilcolumngui" && $ilCtrl->getCmd() != "enableJS") {
371 if ($_SESSION["il_feed_js"] != "n" &&
372 ($ilUser->getPref("il_feed_js") != "n" || $_SESSION["il_feed_js"] == "y")) {
373 // do not get feed dynamically, if cache hit is given.
374 if (!$this->feed->checkCacheHit()) {
375 return true;
376 }
377 }
378 }
379
380 return false;
381 }
382
383 public function getDynamicReload()
384 {
387
388 $ilCtrl->setParameterByClass(
389 "ilcolumngui",
390 "block_id",
391 "block_feed_" . $this->getBlockId()
392 );
393
394 $rel_tpl = new ilTemplate("tpl.dynamic_reload.html", true, true, "Services/Feeds");
395 $rel_tpl->setVariable("TXT_LOADING", $lng->txt("feed_loading_feed"));
396 $rel_tpl->setVariable("BLOCK_ID", "block_feed_" . $this->getBlockId());
397 $rel_tpl->setVariable(
398 "TARGET",
399 $ilCtrl->getLinkTargetByClass("ilcolumngui", "updateBlock", "", true)
400 );
401
402 // no JS
403 $rel_tpl->setVariable("TXT_FEED_CLICK_HERE", $lng->txt("feed_no_js_click_here"));
404 $rel_tpl->setVariable(
405 "TARGET_NO_JS",
406 $ilCtrl->getLinkTargetByClass("ilexternalfeedblockgui", "disableJS")
407 );
408
409 return $rel_tpl->get();
410 }
411
412 public function getJSEnabler()
413 {
416
417 $ilCtrl->setParameterByClass(
418 "ilcolumngui",
419 "block_id",
420 "block_feed_" . $this->getBlockId()
421 );
422
423 $rel_tpl = new ilTemplate("tpl.js_enabler.html", true, true, "Services/Feeds");
424 $rel_tpl->setVariable("BLOCK_ID", "block_feed_" . $this->getBlockId());
425 $rel_tpl->setVariable(
426 "TARGET",
427 $ilCtrl->getLinkTargetByClass("ilexternalfeedblockgui", "enableJS", true, "", false)
428 );
429
430 return $rel_tpl->get();
431 }
432
433
434 public function disableJS()
435 {
438
439 $_SESSION["il_feed_js"] = "n";
440 $ilUser->writePref("il_feed_js", "n");
441 $ilCtrl->returnToParent($this);
442 }
443
444 public function enableJS()
445 {
447
448 $_SESSION["il_feed_js"] = "y";
449 $ilUser->writePref("il_feed_js", "y");
450 echo $this->getHTML();
451 exit;
452 }
453
457 public function fillRow($item)
458 {
460 $ilAccess = $this->access;
461
462 if ($this->isRepositoryObject() && !$ilAccess->checkAccess("read", "", $this->getRefId())) {
463 $this->tpl->setVariable("TXT_TITLE", $item->getTitle());
464 } else {
465 $ilCtrl->setParameter($this, "feed_item_id", $item->getId());
466 $this->tpl->setCurrentBlock("feed_link");
467 $this->tpl->setVariable("VAL_TITLE", $item->getTitle());
468 $this->tpl->setVariable(
469 "HREF_SHOW",
470 $ilCtrl->getLinkTarget($this, "showFeedItem")
471 );
472 $ilCtrl->setParameter($this, "feed_item_id", "");
473 $this->tpl->parseCurrentBlock();
474 }
475 }
476
480 public function getOverview()
481 {
485
486 $this->setEnableNumInfo(false);
487 return '<div class="small">' . ((int) count($this->getData())) . " " . $lng->txt("feed_feed_items") . "</div>";
488 }
489
493 public function showFeedItem()
494 {
497
498 include_once("./Services/News/classes/class.ilNewsItem.php");
499
500 $this->feed->fetch();
501 foreach ($this->feed->getItems() as $item) {
502 if ($item->getId() == $_GET["feed_item_id"]) {
503 $c_item = $item;
504 break;
505 }
506 }
507
508 $tpl = new ilTemplate("tpl.show_feed_item.html", true, true, "Services/Feeds");
509
510 if (is_object($c_item)) {
511 if (trim($c_item->getSummary()) != "") { // summary
512 $tpl->setCurrentBlock("content");
513 $tpl->setVariable("VAL_CONTENT", $c_item->getSummary());
514 $tpl->parseCurrentBlock();
515 }
516 if (trim($c_item->getDate()) != "" || trim($c_item->getAuthor()) != "") { // date
517 $tpl->setCurrentBlock("date_author");
518 if (trim($c_item->getAuthor()) != "") {
519 $tpl->setVariable("VAL_AUTHOR", $c_item->getAuthor() . " - ");
520 }
521 $tpl->setVariable("VAL_DATE", $c_item->getDate());
522 $tpl->parseCurrentBlock();
523 }
524
525 if (trim($c_item->getLink()) != "") { // link
526 $tpl->setCurrentBlock("plink");
527 $tpl->setVariable("HREF_LINK", $c_item->getLink());
528 $tpl->setVariable("TXT_LINK", $lng->txt("feed_open_source_page"));
529 $tpl->parseCurrentBlock();
530 }
531 $tpl->setVariable("VAL_TITLE", $c_item->getTitle()); // title
532 }
533
534 $content_block = new ilDashboardContentBlockGUI();
535 $content_block->setContent($tpl->get());
536 $content_block->setTitle($this->getTitle());
537
538 return $content_block->getHTML();
539 }
540
544 public function create()
545 {
546 $html1 = $this->createFeedBlock();
547
548 $html2 = "";
549 if (DEVMODE == 1) {
550 $this->initImportForm("feed");
551 $html2 = "<br/>" . $this->form->getHTML();
552 }
553
554 return $html1 . $html2;
555 }
556
562 public function initImportForm($a_new_type = "")
563 {
566
567 $lng->loadLanguageModule("feed");
568
569 include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
570 $this->form = new ilPropertyFormGUI();
571 $this->form->setTarget("_top");
572
573 // Import file
574 include_once("./Services/Form/classes/class.ilFileInputGUI.php");
575 $fi = new ilFileInputGUI($lng->txt("import_file"), "importfile");
576 $fi->setSuffixes(array("zip"));
577 $fi->setRequired(true);
578 $this->form->addItem($fi);
579
580 $this->form->addCommandButton("importFile", $lng->txt("import"));
581 $this->form->addCommandButton("cancelSaveFeedBlock", $lng->txt("cancel"));
582 $this->form->setTitle($lng->txt($a_new_type . "_import"));
583
584 $ilCtrl->setParameter($this, "new_type", $a_new_type);
585 $this->form->setFormAction($ilCtrl->getFormAction($this));
586 }
587
593 public function importFile()
594 {
598
599 $new_type = $_POST["new_type"] ? $_POST["new_type"] : $_GET["new_type"];
600
601 // create permission is already checked in createObject. This check here is done to prevent hacking attempts
602 if (!$rbacsystem->checkAccess("create", $_GET["ref_id"], $new_type)) {
603 $this->ilias->raiseError($this->lng->txt("no_create_permission"), $this->ilias->error_obj->MESSAGE);
604 }
605 $this->ctrl->setParameter($this, "new_type", $new_type);
606 $this->initImportForm($new_type);
607 if ($this->form->checkInput()) {
608 // todo: make some check on manifest file
609 include_once("./Services/Export/classes/class.ilImport.php");
610 $imp = new ilImport((int) $_GET['ref_id']);
611 $new_id = $imp->importObject(
612 $newObj,
613 $_FILES["importfile"]["tmp_name"],
614 $_FILES["importfile"]["name"],
615 $new_type
616 );
617
618 // put new object id into tree
619 if ($new_id > 0) {
620 $newObj = ilObjectFactory::getInstanceByObjId($new_id);
621 $newObj->createReference();
622 $newObj->putInTree($_GET["ref_id"]);
623 $newObj->setPermissions($_GET["ref_id"]);
624 ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
625 $this->exitSaveFeedBlock();
626 }
627 return;
628 }
629
630 $this->form->setValuesByPost();
631 $tpl->setContent($this->form->getHtml());
632 }
633
634
641 public function initFormFeedBlock($a_mode)
642 {
644
645 $lng->loadLanguageModule("block");
646
647 require_once("Services/Form/classes/class.ilPropertyFormGUI.php");
648
649 $this->form_gui = new ilPropertyFormGUI();
650
651 // Property Title
652 $text_input = new ilTextInputGUI($lng->txt("block_feed_block_title"), "block_title");
653 $text_input->setInfo("");
654 $text_input->setRequired(true);
655 $text_input->setMaxLength(200);
656 $this->form_gui->addItem($text_input);
657
658 // Property FeedUrl
659 $text_input = new ilFeedUrlInputGUI($lng->txt("block_feed_block_feed_url"), "block_feed_url");
660 $text_input->setInfo($lng->txt("block_feed_block_feed_url_info"));
661 $text_input->setRequired(true);
662 $text_input->setMaxLength(250);
663 $this->form_gui->addItem($text_input);
664
665
666 // save and cancel commands
667 if (in_array($a_mode, array(self::FORM_CREATE,self::FORM_RE_CREATE))) {
668 $this->form_gui->addCommandButton("saveFeedBlock", $lng->txt("save"));
669 $this->form_gui->addCommandButton("cancelSaveFeedBlock", $lng->txt("cancel"));
670 } else {
671 $this->form_gui->addCommandButton("updateFeedBlock", $lng->txt("save"));
672 $this->form_gui->addCommandButton("cancelUpdateFeedBlock", $lng->txt("cancel"));
673 }
674
675 $this->form_gui->setTitle($lng->txt("block_feed_block_head"));
676 $this->form_gui->setFormAction($this->ctrl->getFormAction($this));
677 }
678
684 public function prepareSaveFeedBlock(&$a_feed_block)
685 {
686 $this->getGuiObject()->save($a_feed_block);
687 $a_feed_block->setType($this->getBlockType());
688 }
689
694 public function exitSaveFeedBlock()
695 {
696 $this->getGuiObject()->exitSave();
697 }
698
703 public function cancelUpdateFeedBlock()
704 {
705 $this->getGuiObject()->cancelUpdate();
706 }
707
712 public function exitUpdateFeedBlock()
713 {
714 $this->getGuiObject()->update($this->external_feed_block);
715 }
716
717 //
718 // New rendering
719 //
720
721 protected $new_rendering = true;
722
723
727 /*
728 protected function getViewControls(): array
729 {
730 return [$this->getViewControl()];
731 }*/
732
733
737 protected function getListItemForData(array $data) : \ILIAS\UI\Component\Item\Item
738 {
740 $f = $this->ui->factory();
741
742 $item = $data["item"];
743
744 //if ($this->isRepositoryObject() && !$ilAccess->checkAccess("read", "", $this->getRefId()))
745 $ctrl->setParameter($this, "feed_item_id", $item->getId());
746 $button = $f->button()->shy(
747 $item->getTitle(),
748 $ctrl->getLinkTarget($this, "showFeedItem", "", false, false)
749 );
750 $ctrl->setParameter($this, "feed_item_id", "");
751
752 return $f->item()->standard($button);
753 }
754}
user()
Definition: user.php:4
$_GET["client_id"]
$_POST["username"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
const IL_SCREEN_SIDE
const IL_SCREEN_CENTER
This class represents a block method of a block.
setRowTemplate($a_rowtemplatename, $a_rowtemplatedir="")
Set Row Template Name.
setLimit($a_limit)
Set Limit.
getBlockId()
Get Block Id.
setData($a_data)
Set Data.
setPresentation(int $type)
Set presentation.
setDataSection($a_content)
Call this from overwritten fillDataSection(), if standard row based data is not used.
getTitle()
Get Title.
addBlockCommand(string $a_href, string $a_text, string $a_onclick="")
Add Block Command.
setTitle($a_title)
Set Title.
setBlockId($a_block_id=0)
Set Block Id.
setEnableNumInfo($a_enablenuminfo)
Set Enable Item Number Info.
getRefId()
Get Ref Id (only used if isRepositoryObject() is true).
getData()
Get Data.
BlockGUI class for (centered) Content on Personal Desktop.
BlockGUI class for external feed block.
initImportForm($a_new_type="")
Init object import form.
cancelUpdateFeedBlock()
FORM FeedBlock: Exit save.
setGuiObject(&$a_gui_object)
Set GuiObject.
static getScreenMode()
Get Screen Mode for current command.
fillRow($item)
Fill feed item row.
setBlock($a_block)
Do most of the initialisation.
exitUpdateFeedBlock()
FORM FeedBlock: Exit save.
initFormFeedBlock($a_mode)
FORM FeedBlock: Init form.
getListItemForData(array $data)
Get list item for data array.null|\ILIAS\UI\Component\Item\Item
setFormEditMode($a_form_edit_mode)
Set FormEditMode.
isRepositoryObject()
Returns whether block has a corresponding repository object.bool
updateFeedBlock()
FORM FeedBlock: Update ExternalFeedBlock.
editFeedBlock()
FORM FeedBlock: Edit form.
cancelSaveFeedBlock()
FORM FeedBlock: Cancel save.
createFeedBlock()
FORM FeedBlock: Create ExternalFeedBlock.
exitSaveFeedBlock()
FORM FeedBlock: Exit save.
getValuesFeedBlock()
FORM FeedBlock: Get current values for ExternalFeedBlock form.
prepareSaveFeedBlock(&$a_feed_block)
FORM FeedBlock: Prepare Saving of FeedBlock.
saveFeedBlock()
FORM FeedBlock: Save ExternalFeedBlock.
Custom block for external feeds.
Handles external Feeds via Magpie library.
This class represents a feed url property in a property form.
This class represents a file property in a property form.
Import class.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
This class represents a property form user interface.
ILIAS Setting Class.
special template class to simplify handling of ITX/PEAR
This class represents a text property in a property form.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
global $ilCtrl
Definition: ilias.php:18
exit
Definition: login.php:29
$i
Definition: metadata.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.
redirection script todo: (a better solution should control the processing via a xml file)
$feed_set
Definition: privfeed.php:19
settings()
Definition: settings.php:2
$ilUser
Definition: imgupload.php:18
ui()
Definition: ui.php:5
$DIC
Definition: xapitoken.php:46