ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilPDExternalFeedBlockGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 include_once("./Services/Block/classes/class.ilBlockGUI.php");
25 include_once("./Services/Block/classes/class.ilExternalFeedBlockGUIGen.php");
26 include_once("./Services/Feeds/classes/class.ilExternalFeed.php");
27 
40 {
44  protected $settings;
45 
46  public static $block_type = "pdfeed";
47 
51  public function __construct()
52  {
53  global $DIC;
54 
55  $this->ctrl = $DIC->ctrl();
56  $this->lng = $DIC->language();
57  $this->user = $DIC->user();
58  $this->access = $DIC->access();
59  $this->settings = $DIC->settings();
60  $lng = $DIC->language();
61 
62  parent::__construct();
63 
64  $lng->loadLanguageModule("feed");
65 
66  $this->setLimit(5);
67  $this->setRowTemplate("tpl.block_external_feed_row.html", "Services/Feeds");
68  }
69 
73  public function getBlockType() : string
74  {
75  return self::$block_type;
76  }
77 
81  protected function isRepositoryObject() : bool
82  {
83  return false;
84  }
85 
89  public static function getScreenMode()
90  {
91  global $DIC;
92 
93  $ilCtrl = $DIC->ctrl();
94 
95  switch ($ilCtrl->getCmd()) {
96  case "create":
97  case "edit":
98  case "saveFeedBlock":
99  case "updateFeedBlock":
100  case "editFeedBlock":
101  case "showFeedItem":
102  case "confirmDeleteFeedBlock":
103  return IL_SCREEN_CENTER;
104  break;
105 
106  default:
107  return IL_SCREEN_SIDE;
108  break;
109  }
110  }
111 
115  public function setBlock($a_block)
116  {
118 
119  // init block
120  $this->feed_block = $a_block;
121  $this->setTitle($this->feed_block->getTitle());
122  $this->setBlockId($this->feed_block->getId());
123 
124  // get feed object
125  include_once("./Services/Feeds/classes/class.ilExternalFeed.php");
126  $this->feed = new ilExternalFeed();
127  $this->feed->setUrl($this->feed_block->getFeedUrl());
128 
129  // init details
130  $this->setAvailableDetailLevels(2);
131 
132  $ilCtrl->setParameter($this, "block_id", $this->feed_block->getId());
133  }
134 
138  public function executeCommand()
139  {
141 
142  $next_class = $ilCtrl->getNextClass();
143  $cmd = $ilCtrl->getCmd("getHTML");
144 
145  switch ($next_class) {
146  default:
147  return $this->$cmd();
148  }
149  }
150 
154  public function fillDataSection()
155  {
156  if ($this->getDynamic()) {
157  $this->setDataSection($this->getDynamicReload());
158  } elseif ($this->getCurrentDetailLevel() > 1 && count($this->getData()) > 0) {
159  parent::fillDataSection();
160  } else {
161  $this->setDataSection($this->getOverview());
162  }
163  }
164 
168  public function getHTML()
169  {
171  $lng = $this->lng;
174 
175 
176  if ($ilSetting->get("block_limit_pdfeed") == 0) {
177  return "";
178  }
179 
180  if ($this->getCurrentDetailLevel() == 0) {
181  return "";
182  }
183 
184 
185  // if no dynamic reload
186  if (!$this->getDynamic()) {
187  $this->feed->fetch();
188  $this->setData($this->feed->getItems());
189  }
190 
191  $ilCtrl->setParameter(
192  $this,
193  "external_feed_block_id",
194  $this->getBlockId()
195  );
196  $this->addBlockCommand(
197  $ilCtrl->getLinkTarget(
198  $this,
199  "editFeedBlock"
200  ),
201  $lng->txt("edit")
202  );
203  $this->addBlockCommand(
204  $ilCtrl->getLinkTarget(
205  $this,
206  "confirmDeleteFeedBlock"
207  ),
208  $lng->txt("delete")
209  );
210  $ilCtrl->setParameter($this, "external_feed_block_id", "");
211 
212  // JS enabler
213  $add = "";
214  if ($_SESSION["il_feed_js"] == "n" ||
215  ($ilUser->getPref("il_feed_js") == "n" && $_SESSION["il_feed_js"] != "y")) {
216  $add = $this->getJSEnabler();
217  }
218 
219  return parent::getHTML() . $add;
220  }
221 
222  public function getDynamic()
223  {
226 
227  if ($ilCtrl->getCmdClass() != "ilcolumngui" && $ilCtrl->getCmd() != "enableJS") {
228  $sess_feed_js = "";
229  if (isset($_SESSION["il_feed_js"])) {
230  $sess_feed_js = $_SESSION["il_feed_js"];
231  }
232  if ($sess_feed_js != "n" &&
233  ($ilUser->getPref("il_feed_js") != "n" || $sess_feed_js == "y")) {
234  // do not get feed dynamically, if cache hit is given.
235  if (!$this->feed->checkCacheHit()) {
236  return true;
237  }
238  }
239  }
240 
241  return false;
242  }
243 
244  public function getDynamicReload()
245  {
247  $lng = $this->lng;
248 
249  $ilCtrl->setParameterByClass(
250  "ilcolumngui",
251  "block_id",
252  "block_pdfeed_" . $this->getBlockId()
253  );
254 
255  $rel_tpl = new ilTemplate("tpl.dynamic_reload.html", true, true, "Services/Feeds");
256  $rel_tpl->setVariable("TXT_LOADING", $lng->txt("feed_loading_feed"));
257  $rel_tpl->setVariable("BLOCK_ID", "block_pdfeed_" . $this->getBlockId());
258  $rel_tpl->setVariable(
259  "TARGET",
260  $ilCtrl->getLinkTargetByClass("ilcolumngui", "updateBlock", "", true)
261  );
262 
263  // no JS
264  $rel_tpl->setVariable("TXT_FEED_CLICK_HERE", $lng->txt("feed_no_js_click_here"));
265  $rel_tpl->setVariable(
266  "TARGET_NO_JS",
267  $ilCtrl->getLinkTargetByClass("ilpdexternalfeedblockgui", "disableJS")
268  );
269 
270  return $rel_tpl->get();
271  }
272 
273  public function getJSEnabler()
274  {
276 
277  $ilCtrl->setParameterByClass(
278  "ilcolumngui",
279  "block_id",
280  "block_pdfeed_" . $this->getBlockId()
281  );
282 
283  $rel_tpl = new ilTemplate("tpl.js_enabler.html", true, true, "Services/Feeds");
284  $rel_tpl->setVariable("BLOCK_ID", "block_pdfeed_" . $this->getBlockId());
285  $rel_tpl->setVariable(
286  "TARGET",
287  $ilCtrl->getLinkTargetByClass("ilpdexternalfeedblockgui", "enableJS", true)
288  );
289 
290  return $rel_tpl->get();
291  }
292 
293 
294  public function disableJS()
295  {
298 
299  $_SESSION["il_feed_js"] = "n";
300  $ilUser->writePref("il_feed_js", "n");
301  $ilCtrl->redirectByClass("ilpersonaldesktopgui", "show");
302  }
303 
304  public function enableJS()
305  {
307 
308  $_SESSION["il_feed_js"] = "y";
309  $ilUser->writePref("il_feed_js", "y");
310  echo $this->getHTML();
311  exit;
312  }
313 
317  public function fillRow($item)
318  {
320 
321  $ilCtrl->setParameter($this, "feed_item_id", $item->getId());
322  $this->tpl->setVariable("VAL_TITLE", $item->getTitle());
323  $this->tpl->setVariable(
324  "HREF_SHOW",
325  $ilCtrl->getLinkTarget($this, "showFeedItem")
326  );
327  $ilCtrl->setParameter($this, "feed_item_id", "");
328  }
329 
333  public function getOverview()
334  {
335  $lng = $this->lng;
336 
337  $this->setEnableNumInfo(false);
338  return '<div class="small">' . ((int) count($this->getData())) . " " . $lng->txt("feed_feed_items") . "</div>";
339  }
340 
344  public function showFeedItem()
345  {
346  $lng = $this->lng;
348 
349  include_once("./Services/News/classes/class.ilNewsItem.php");
350 
351  $this->feed->fetch();
352  foreach ($this->feed->getItems() as $item) {
353  if ($item->getId() == $_GET["feed_item_id"]) {
354  $c_item = $item;
355  break;
356  }
357  }
358 
359  $tpl = new ilTemplate("tpl.show_feed_item.html", true, true, "Services/Feeds");
360 
361  if (is_object($c_item)) {
362  if (trim($c_item->getSummary()) != "") { // summary
363  $tpl->setCurrentBlock("content");
364  $tpl->setVariable("VAL_CONTENT", $c_item->getSummary());
365  $tpl->parseCurrentBlock();
366  }
367  if (trim($c_item->getDate()) != "" || trim($c_item->getAuthor()) != "") { // date
368  $tpl->setCurrentBlock("date_author");
369  if (trim($c_item->getAuthor()) != "") {
370  $tpl->setVariable("VAL_AUTHOR", $c_item->getAuthor() . " - ");
371  }
372  $tpl->setVariable("VAL_DATE", $c_item->getDate());
373  $tpl->parseCurrentBlock();
374  }
375 
376  if (trim($c_item->getLink()) != "") { // link
377  $tpl->setCurrentBlock("plink");
378  $tpl->setVariable("HREF_LINK", $c_item->getLink());
379  $tpl->setVariable("TXT_LINK", $lng->txt("feed_open_source_page"));
380  $tpl->parseCurrentBlock();
381  }
382  $tpl->setVariable("VAL_TITLE", $c_item->getTitle()); // title
383  }
384 
385  include_once("./Services/PersonalDesktop/classes/class.ilPDContentBlockGUI.php");
386  $content_block = new ilPDContentBlockGUI();
387  $content_block->setContent($tpl->get());
388  $content_block->setTitle($this->getTitle());
389  $content_block->setImage(ilUtil::getImagePath("icon_feed.svg"));
390  $content_block->addHeaderCommand(
391  $ilCtrl->getParentReturn($this),
392  $lng->txt("selected_items_back")
393  );
394 
395  return $content_block->getHTML();
396  }
397 
401  public function create()
402  {
403  return $this->createFeedBlock();
404  }
405 
412  public function initFormFeedBlock($a_mode)
413  {
414  $lng = $this->lng;
415 
416  $lng->loadLanguageModule("block");
417 
418  require_once("Services/Form/classes/class.ilPropertyFormGUI.php");
419 
420  $this->form_gui = new ilPropertyFormGUI();
421 
422  // Property Title
423  $text_input = new ilTextInputGUI($lng->txt("block_feed_block_title"), "block_title");
424  $text_input->setInfo("");
425  $text_input->setRequired(true);
426  $text_input->setMaxLength(200);
427  $this->form_gui->addItem($text_input);
428 
429  // Property FeedUrl
430  $text_input = new ilFeedUrlInputGUI($lng->txt("block_feed_block_feed_url"), "block_feed_url");
431  $text_input->setInfo($lng->txt("block_feed_block_feed_url_info"));
432  $text_input->setRequired(true);
433  $text_input->setMaxLength(250);
434  $this->form_gui->addItem($text_input);
435 
436 
437  // save and cancel commands
438  if (in_array($a_mode, array(IL_FORM_CREATE,IL_FORM_RE_CREATE))) {
439  $this->form_gui->addCommandButton("saveFeedBlock", $lng->txt("save"));
440  $this->form_gui->addCommandButton("cancelSaveFeedBlock", $lng->txt("cancel"));
441  } else {
442  $this->form_gui->addCommandButton("updateFeedBlock", $lng->txt("save"));
443  $this->form_gui->addCommandButton("cancelUpdateFeedBlock", $lng->txt("cancel"));
444  }
445 
446  $this->form_gui->setTitle($lng->txt("block_feed_block_head"));
447  $this->form_gui->setFormAction($this->ctrl->getFormAction($this));
448 
449  $this->prepareFormFeedBlock($this->form_gui);
450  }
451 
457  public function prepareSaveFeedBlock(&$a_feed_block)
458  {
460 
461  $a_feed_block->setContextObjId($ilCtrl->getContextObjId());
462  $a_feed_block->setContextObjType($ilCtrl->getContextObjType());
463  $a_feed_block->setType("pdfeed");
464  }
465 
469  public function confirmDeleteFeedBlock()
470  {
472  $lng = $this->lng;
473 
474  include_once("Services/Utilities/classes/class.ilConfirmationGUI.php");
475  $c_gui = new ilConfirmationGUI();
476 
477  // set confirm/cancel commands
478  $c_gui->setFormAction($ilCtrl->getFormAction($this, "deleteFeedBlock"));
479  $c_gui->setHeaderText($lng->txt("info_delete_sure"));
480  $c_gui->setCancel($lng->txt("cancel"), "exitDeleteFeedBlock");
481  $c_gui->setConfirm($lng->txt("confirm"), "deleteFeedBlock");
482 
483  // add items to delete
484  $c_gui->addItem(
485  "external_feed_block_id",
486  $this->feed_block->getId(),
487  $this->feed_block->getTitle(),
488  ilUtil::getImagePath("icon_feed.svg")
489  );
490 
491  return $c_gui->getHTML();
492  }
493 
497  public function exitDeleteFeedBlock()
498  {
500 
501  $ilCtrl->returnToParent($this);
502  }
503 
507  public function deleteFeedBlock()
508  {
510 
511  $this->feed_block->delete();
512  $ilCtrl->returnToParent($this);
513  }
514 }
This class represents a feed url property in a property form.
createFeedBlock()
FORM FeedBlock: Create ExternalFeedBlock.
settings()
Definition: settings.php:2
$_SESSION["AccountId"]
prepareFormFeedBlock(&$a_form_gui)
FORM FeedBlock: Prepare form.
This class represents a property form user interface.
global $DIC
Definition: saml.php:7
setDataSection($a_content)
Call this from overwritten fillDataSection(), if standard row based data is not used.
$_GET["client_id"]
setBlock($a_block)
Do most of the initialisation.
BlockGUI class for external feed block on the personal desktop.
setEnableNumInfo($a_enablenuminfo)
Set Enable Item Number Info.
confirmDeleteFeedBlock()
Confirmation of feed block deletion.
user()
Definition: user.php:4
Handles external Feeds via Magpie library.
GUI class for external news feed custom block.
global $ilCtrl
Definition: ilias.php:18
setInfo($a_info)
Set Information Text.
setTitle($a_title)
Set Title.
setBlockId($a_block_id=0)
Set Block Id.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
static getScreenMode()
Get Screen Mode for current command.
setData($a_data)
Set Data.
prepareSaveFeedBlock(&$a_feed_block)
FORM FeedBlock: Prepare Saving of FeedBlock.
special template class to simplify handling of ITX/PEAR
setAvailableDetailLevels($a_max, $a_min=0)
Set Available Detail Levels.
This class represents a text property in a property form.
$ilUser
Definition: imgupload.php:18
const IL_SCREEN_CENTER
getBlockId()
Get Block Id.
addBlockCommand( $a_href, $a_text, $a_target="", $a_img="", $a_right_aligned=false, $a_checked=false, $a_html="")
Add Block Command.
getData()
Get Data.
exit
Definition: backend.php:16
initFormFeedBlock($a_mode)
FORM FeedBlock: Init form.
setLimit($a_limit)
Set Limit.
global $ilSetting
Definition: privfeed.php:17
exitDeleteFeedBlock()
Cancel deletion of feed block.
BlockGUI class for (centered) Content on Personal Desktop.
const IL_SCREEN_SIDE
setRowTemplate($a_rowtemplatename, $a_rowtemplatedir="")
Set Row Template Name.
getTitle()
Get Title.
getCurrentDetailLevel()
Get Current Detail Level.
Confirmation screen class.