ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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
5include_once("./Services/Block/classes/class.ilBlockGUI.php");
6include_once("./Services/Block/classes/class.ilExternalFeedBlockGUIGen.php");
7include_once("./Services/Feeds/classes/class.ilExternalFeed.php");
8
21{
25 protected $settings;
26
30 protected $rbacsystem;
31
35 protected $obj_definition;
36
37 public static $block_type = "feed";
38
42 public function __construct()
43 {
44 global $DIC;
45
46 $this->ctrl = $DIC->ctrl();
47 $this->lng = $DIC->language();
48 $this->user = $DIC->user();
49 $this->access = $DIC->access();
50 $this->settings = $DIC->settings();
51 $this->rbacsystem = $DIC->rbac()->system();
52 $this->obj_definition = $DIC["objDefinition"];
53 $lng = $DIC->language();
54
55 parent::__construct();
56
57 $lng->loadLanguageModule("feed");
58 $this->setLimit(5);
59 $this->setRowTemplate("tpl.block_external_feed_row.html", "Services/Feeds");
60 }
61
65 public function getBlockType() : string
66 {
67 return self::$block_type;
68 }
69
73 protected function isRepositoryObject() : bool
74 {
75 return true;
76 }
77
81 public static function getScreenMode()
82 {
83 global $DIC;
84
85 $ilCtrl = $DIC->ctrl();
86
87 switch ($ilCtrl->getCmd()) {
88 case "create":
89 case "edit":
90 case "saveFeedBlock":
91 case "updateFeedBlock":
92 case "editFeedBlock":
93 case "showFeedItem":
94 case "confirmDeleteFeedBlock":
95 return IL_SCREEN_CENTER;
96 break;
97
98 default:
99 return IL_SCREEN_SIDE;
100 break;
101 }
102 }
103
107 public function setBlock($a_block)
108 {
110
111 // init block
112 $this->feed_block = $a_block;
113 $this->setTitle($this->feed_block->getTitle());
114 $this->setBlockId($this->feed_block->getId());
115
116 // get feed object
117 include_once("./Services/Feeds/classes/class.ilExternalFeed.php");
118 $this->feed = new ilExternalFeed();
119 $this->feed->setUrl($this->feed_block->getFeedUrl());
120
121 // init details
122 $this->setAvailableDetailLevels(2);
123
124 $ilCtrl->setParameter($this, "block_id", $this->feed_block->getId());
125 }
126
130 public function executeCommand()
131 {
133
134 $next_class = $ilCtrl->getNextClass();
135 $cmd = $ilCtrl->getCmd("getHTML");
136 switch ($next_class) {
137 default:
138 return $this->$cmd();
139 }
140 }
141
145 public function fillDataSection()
146 {
147 if ($this->getDynamic()) {
148 $this->setDataSection($this->getDynamicReload());
149 } elseif ($this->getCurrentDetailLevel() > 1 && count($this->getData()) > 0) {
150 parent::fillDataSection();
151 } else {
152 $this->setDataSection($this->getOverview());
153 }
154 }
155
159 public function getHTML()
160 {
164 $ilAccess = $this->access;
166
167 if ($this->getCurrentDetailLevel() == 0) {
168 return "";
169 }
170
171 $feed_set = new ilSetting("feed");
172
173 if ($feed_set->get("disable_rep_feeds")) {
174 return "";
175 }
176
177 // if no dynamic reload
178 if (!$this->getDynamic()) {
179 $this->feed->fetch();
180 $this->setData($this->feed->getItems());
181 }
182
183 //$this->setTitle($this->feed->getChannelTitle());
184 $this->setData($this->feed->getItems());
185
186 if ($ilAccess->checkAccess("write", "", $this->getRefId())) {
187 $ilCtrl->setParameterByClass(
188 "ilobjexternalfeedgui",
189 "ref_id",
190 $this->getRefId()
191 );
192 $ilCtrl->setParameter($this, "external_feed_block_id", $this->getBlockId());
193 $this->addBlockCommand(
194 $ilCtrl->getLinkTargetByClass(
195 array("ilrepositorygui", "ilobjexternalfeedgui",
196 "ilexternalfeedblockgui"),
197 "editFeedBlock"
198 ),
199 $lng->txt("settings")
200 );
201 $ilCtrl->clearParametersByClass("ilobjexternalfeedgui");
202 }
203
204 // JS enabler
205 $add = "";
206 if ($_SESSION["il_feed_js"] == "n" ||
207 ($ilUser->getPref("il_feed_js") == "n" && $_SESSION["il_feed_js"] != "y")) {
208 $add = $this->getJSEnabler();
209 }
210
211 return parent::getHTML() . $add;
212 }
213
214 public function getDynamic()
215 {
218
219 if ($ilCtrl->getCmdClass() != "ilcolumngui" && $ilCtrl->getCmd() != "enableJS") {
220 if ($_SESSION["il_feed_js"] != "n" &&
221 ($ilUser->getPref("il_feed_js") != "n" || $_SESSION["il_feed_js"] == "y")) {
222 // do not get feed dynamically, if cache hit is given.
223 if (!$this->feed->checkCacheHit()) {
224 return true;
225 }
226 }
227 }
228
229 return false;
230 }
231
232 public function getDynamicReload()
233 {
236
237 $ilCtrl->setParameterByClass(
238 "ilcolumngui",
239 "block_id",
240 "block_feed_" . $this->getBlockId()
241 );
242
243 $rel_tpl = new ilTemplate("tpl.dynamic_reload.html", true, true, "Services/Feeds");
244 $rel_tpl->setVariable("TXT_LOADING", $lng->txt("feed_loading_feed"));
245 $rel_tpl->setVariable("BLOCK_ID", "block_feed_" . $this->getBlockId());
246 $rel_tpl->setVariable(
247 "TARGET",
248 $ilCtrl->getLinkTargetByClass("ilcolumngui", "updateBlock", "", true)
249 );
250
251 // no JS
252 $rel_tpl->setVariable("TXT_FEED_CLICK_HERE", $lng->txt("feed_no_js_click_here"));
253 $rel_tpl->setVariable(
254 "TARGET_NO_JS",
255 $ilCtrl->getLinkTargetByClass("ilexternalfeedblockgui", "disableJS")
256 );
257
258 return $rel_tpl->get();
259 }
260
261 public function getJSEnabler()
262 {
265
266 $ilCtrl->setParameterByClass(
267 "ilcolumngui",
268 "block_id",
269 "block_feed_" . $this->getBlockId()
270 );
271
272 $rel_tpl = new ilTemplate("tpl.js_enabler.html", true, true, "Services/Feeds");
273 $rel_tpl->setVariable("BLOCK_ID", "block_feed_" . $this->getBlockId());
274 $rel_tpl->setVariable(
275 "TARGET",
276 $ilCtrl->getLinkTargetByClass("ilexternalfeedblockgui", "enableJS", true, "", false)
277 );
278
279 return $rel_tpl->get();
280 }
281
282
283 public function disableJS()
284 {
287
288 $_SESSION["il_feed_js"] = "n";
289 $ilUser->writePref("il_feed_js", "n");
290 $ilCtrl->returnToParent($this);
291 }
292
293 public function enableJS()
294 {
296
297 $_SESSION["il_feed_js"] = "y";
298 $ilUser->writePref("il_feed_js", "y");
299 echo $this->getHTML();
300 exit;
301 }
302
306 public function fillRow($item)
307 {
309 $ilAccess = $this->access;
310
311 if ($this->isRepositoryObject() && !$ilAccess->checkAccess("read", "", $this->getRefId())) {
312 $this->tpl->setVariable("TXT_TITLE", $item->getTitle());
313 } else {
314 $ilCtrl->setParameter($this, "feed_item_id", $item->getId());
315 $this->tpl->setCurrentBlock("feed_link");
316 $this->tpl->setVariable("VAL_TITLE", $item->getTitle());
317 $this->tpl->setVariable(
318 "HREF_SHOW",
319 $ilCtrl->getLinkTarget($this, "showFeedItem")
320 );
321 $ilCtrl->setParameter($this, "feed_item_id", "");
322 $this->tpl->parseCurrentBlock();
323 }
324 }
325
329 public function getOverview()
330 {
334
335 $this->setEnableNumInfo(false);
336 return '<div class="small">' . ((int) count($this->getData())) . " " . $lng->txt("feed_feed_items") . "</div>";
337 }
338
342 public function showFeedItem()
343 {
346
347 include_once("./Services/News/classes/class.ilNewsItem.php");
348
349 $this->feed->fetch();
350 foreach ($this->feed->getItems() as $item) {
351 if ($item->getId() == $_GET["feed_item_id"]) {
352 $c_item = $item;
353 break;
354 }
355 }
356
357 $tpl = new ilTemplate("tpl.show_feed_item.html", true, true, "Services/Feeds");
358
359 if (is_object($c_item)) {
360 if (trim($c_item->getSummary()) != "") { // summary
361 $tpl->setCurrentBlock("content");
362 $tpl->setVariable("VAL_CONTENT", $c_item->getSummary());
363 $tpl->parseCurrentBlock();
364 }
365 if (trim($c_item->getDate()) != "" || trim($c_item->getAuthor()) != "") { // date
366 $tpl->setCurrentBlock("date_author");
367 if (trim($c_item->getAuthor()) != "") {
368 $tpl->setVariable("VAL_AUTHOR", $c_item->getAuthor() . " - ");
369 }
370 $tpl->setVariable("VAL_DATE", $c_item->getDate());
371 $tpl->parseCurrentBlock();
372 }
373
374 if (trim($c_item->getLink()) != "") { // link
375 $tpl->setCurrentBlock("plink");
376 $tpl->setVariable("HREF_LINK", $c_item->getLink());
377 $tpl->setVariable("TXT_LINK", $lng->txt("feed_open_source_page"));
378 $tpl->parseCurrentBlock();
379 }
380 $tpl->setVariable("VAL_TITLE", $c_item->getTitle()); // title
381 }
382
383 include_once("./Services/PersonalDesktop/classes/class.ilPDContentBlockGUI.php");
384 $content_block = new ilPDContentBlockGUI();
385 $content_block->setContent($tpl->get());
386 $content_block->setTitle($this->getTitle());
387 $content_block->setImage(ilUtil::getImagePath("icon_feed.svg"));
388 $content_block->addHeaderCommand(
389 $ilCtrl->getParentReturn($this),
390 $lng->txt("close"),
391 true
392 );
393
394 return $content_block->getHTML();
395 }
396
400 public function create()
401 {
402 $html1 = $this->createFeedBlock();
403
404 $html2 = "";
405 if (DEVMODE == 1) {
406 $this->initImportForm("feed");
407 $html2 = "<br/>" . $this->form->getHTML();
408 }
409
410 return $html1 . $html2;
411 }
412
418 public function initImportForm($a_new_type = "")
419 {
422
423 $lng->loadLanguageModule("feed");
424
425 include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
426 $this->form = new ilPropertyFormGUI();
427 $this->form->setTarget("_top");
428
429 // Import file
430 include_once("./Services/Form/classes/class.ilFileInputGUI.php");
431 $fi = new ilFileInputGUI($lng->txt("import_file"), "importfile");
432 $fi->setSuffixes(array("zip"));
433 $fi->setRequired(true);
434 $this->form->addItem($fi);
435
436 $this->form->addCommandButton("importFile", $lng->txt("import"));
437 $this->form->addCommandButton("cancelSaveFeedBlock", $lng->txt("cancel"));
438 $this->form->setTitle($lng->txt($a_new_type . "_import"));
439
440 $ilCtrl->setParameter($this, "new_type", $a_new_type);
441 $this->form->setFormAction($ilCtrl->getFormAction($this));
442 }
443
449 public function importFile()
450 {
454
455 $new_type = $_POST["new_type"] ? $_POST["new_type"] : $_GET["new_type"];
456
457 // create permission is already checked in createObject. This check here is done to prevent hacking attempts
458 if (!$rbacsystem->checkAccess("create", $_GET["ref_id"], $new_type)) {
459 $this->ilias->raiseError($this->lng->txt("no_create_permission"), $this->ilias->error_obj->MESSAGE);
460 }
461 $this->ctrl->setParameter($this, "new_type", $new_type);
462 $this->initImportForm($new_type);
463 if ($this->form->checkInput()) {
464 // todo: make some check on manifest file
465 include_once("./Services/Export/classes/class.ilImport.php");
466 $imp = new ilImport((int) $_GET['ref_id']);
467 $new_id = $imp->importObject(
468 $newObj,
469 $_FILES["importfile"]["tmp_name"],
470 $_FILES["importfile"]["name"],
471 $new_type
472 );
473
474 // put new object id into tree
475 if ($new_id > 0) {
476 $newObj = ilObjectFactory::getInstanceByObjId($new_id);
477 $newObj->createReference();
478 $newObj->putInTree($_GET["ref_id"]);
479 $newObj->setPermissions($_GET["ref_id"]);
480 ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
481 $this->exitSaveFeedBlock();
482 }
483 return;
484 }
485
486 $this->form->setValuesByPost();
487 $tpl->setContent($this->form->getHtml());
488 }
489
490
497 public function initFormFeedBlock($a_mode)
498 {
500
501 $lng->loadLanguageModule("block");
502
503 require_once("Services/Form/classes/class.ilPropertyFormGUI.php");
504
505 $this->form_gui = new ilPropertyFormGUI();
506
507 // Property Title
508 $text_input = new ilTextInputGUI($lng->txt("block_feed_block_title"), "block_title");
509 $text_input->setInfo("");
510 $text_input->setRequired(true);
511 $text_input->setMaxLength(200);
512 $this->form_gui->addItem($text_input);
513
514 // Property FeedUrl
515 $text_input = new ilFeedUrlInputGUI($lng->txt("block_feed_block_feed_url"), "block_feed_url");
516 $text_input->setInfo($lng->txt("block_feed_block_feed_url_info"));
517 $text_input->setRequired(true);
518 $text_input->setMaxLength(250);
519 $this->form_gui->addItem($text_input);
520
521
522 // save and cancel commands
523 if (in_array($a_mode, array(IL_FORM_CREATE,IL_FORM_RE_CREATE))) {
524 $this->form_gui->addCommandButton("saveFeedBlock", $lng->txt("save"));
525 $this->form_gui->addCommandButton("cancelSaveFeedBlock", $lng->txt("cancel"));
526 } else {
527 $this->form_gui->addCommandButton("updateFeedBlock", $lng->txt("save"));
528 $this->form_gui->addCommandButton("cancelUpdateFeedBlock", $lng->txt("cancel"));
529 }
530
531 $this->form_gui->setTitle($lng->txt("block_feed_block_head"));
532 $this->form_gui->setFormAction($this->ctrl->getFormAction($this));
533
534 $this->prepareFormFeedBlock($this->form_gui);
535 }
536
542 public function prepareSaveFeedBlock(&$a_feed_block)
543 {
544 $this->getGuiObject()->save($a_feed_block);
545 $a_feed_block->setType($this->getBlockType());
546 }
547
552 public function exitSaveFeedBlock()
553 {
554 $this->getGuiObject()->exitSave();
555 }
556
561 public function cancelUpdateFeedBlock()
562 {
563 $this->getGuiObject()->cancelUpdate();
564 }
565
570 public function exitUpdateFeedBlock()
571 {
572 $this->getGuiObject()->update($this->external_feed_block);
573 }
574}
user()
Definition: user.php:4
exit
Definition: backend.php:16
$_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
setRowTemplate($a_rowtemplatename, $a_rowtemplatedir="")
Set Row Template Name.
setLimit($a_limit)
Set Limit.
getCurrentDetailLevel()
Get Current Detail Level.
getBlockId()
Get Block Id.
setAvailableDetailLevels($a_max, $a_min=0)
Set Available Detail Levels.
setData($a_data)
Set Data.
setDataSection($a_content)
Call this from overwritten fillDataSection(), if standard row based data is not used.
getTitle()
Get Title.
setTitle($a_title)
Set Title.
setBlockId($a_block_id=0)
Set Block Id.
setEnableNumInfo($a_enablenuminfo)
Set Enable Item Number Info.
addBlockCommand( $a_href, $a_text, $a_target="", $a_img="", $a_right_aligned=false, $a_checked=false, $a_html="")
Add Block Command.
getRefId()
Get Ref Id (only used if isRepositoryObject() is true).
getData()
Get Data.
GUI class for external news feed custom block.
createFeedBlock()
FORM FeedBlock: Create ExternalFeedBlock.
prepareFormFeedBlock(&$a_form_gui)
FORM FeedBlock: Prepare form.
BlockGUI class for external feed block.
initImportForm($a_new_type="")
Init object import form.
cancelUpdateFeedBlock()
FORM FeedBlock: Exit save.
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.
isRepositoryObject()
Returns whether block has a corresponding repository object.bool
exitSaveFeedBlock()
FORM FeedBlock: Exit save.
prepareSaveFeedBlock(&$a_feed_block)
FORM FeedBlock: Prepare Saving of FeedBlock.
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
BlockGUI class for (centered) Content on Personal Desktop.
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 getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
$html1
$html2
global $ilCtrl
Definition: ilias.php:18
redirection script todo: (a better solution should control the processing via a xml file)
$feed_set
Definition: privfeed.php:19
global $ilSetting
Definition: privfeed.php:17
global $DIC
Definition: saml.php:7
settings()
Definition: settings.php:2
$ilUser
Definition: imgupload.php:18