ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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
24include_once("./Services/Block/classes/class.ilBlockGUI.php");
25include_once("./Services/Block/classes/class.ilExternalFeedBlockGUIGen.php");
26include_once("./Services/Feeds/classes/class.ilExternalFeed.php");
27
40{
41 const FORM_EDIT = 0;
42 const FORM_CREATE = 1;
43 const FORM_RE_EDIT = 2;
44 const FORM_RE_CREATE = 2;
45
49 protected $settings;
50
51 public static $block_type = "pdfeed";
52
56 public function __construct()
57 {
58 global $DIC;
59
60 $this->ctrl = $DIC->ctrl();
61 $this->lng = $DIC->language();
62 $this->user = $DIC->user();
63 $this->access = $DIC->access();
64 $this->settings = $DIC->settings();
65 $lng = $DIC->language();
66
68
69 $lng->loadLanguageModule("feed");
70
71 $this->setLimit(5);
72 $this->setRowTemplate("tpl.block_external_feed_row.html", "Services/Feeds");
73 }
74
78 public function getBlockType() : string
79 {
80 return self::$block_type;
81 }
82
86 protected function isRepositoryObject() : bool
87 {
88 return false;
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 {
122 $ilCtrl = $this->ctrl;
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
142 public function executeCommand()
143 {
144 $ilCtrl = $this->ctrl;
145
146 $next_class = $ilCtrl->getNextClass();
147 $cmd = $ilCtrl->getCmd("getHTML");
148
149 switch ($next_class) {
150 default:
151 return $this->$cmd();
152 }
153 }
154
158 public function fillDataSection()
159 {
160 if ($this->getDynamic()) {
161 $this->setDataSection($this->getDynamicReload());
162 } elseif (count($this->getData()) > 0) {
163 parent::fillDataSection();
164 } else {
165 $this->setDataSection($this->getOverview());
166 }
167 }
168
172 public function getHTML()
173 {
174 $ilCtrl = $this->ctrl;
176 $ilUser = $this->user;
178
179
180 if ($ilSetting->get("block_limit_pdfeed") == 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 {
224 $ilCtrl = $this->ctrl;
225 $ilUser = $this->user;
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 {
246 $ilCtrl = $this->ctrl;
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 {
275 $ilCtrl = $this->ctrl;
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 {
296 $ilCtrl = $this->ctrl;
297 $ilUser = $this->user;
298
299 $_SESSION["il_feed_js"] = "n";
300 $ilUser->writePref("il_feed_js", "n");
301 $ilCtrl->redirectByClass("ildashboardgui", "show");
302 }
303
304 public function enableJS()
305 {
306 $ilUser = $this->user;
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 {
319 $ilCtrl = $this->ctrl;
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 {
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 {
347 $ilCtrl = $this->ctrl;
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 $content_block = new ilDashboardContentBlockGUI();
386 $content_block->setContent($tpl->get());
387 $content_block->setTitle($this->getTitle());
388
389 return $content_block->getHTML();
390 }
391
395 public function create()
396 {
397 return $this->createFeedBlock();
398 }
399
406 public function initFormFeedBlock($a_mode)
407 {
409
410 $lng->loadLanguageModule("block");
411
412 require_once("Services/Form/classes/class.ilPropertyFormGUI.php");
413
414 $this->form_gui = new ilPropertyFormGUI();
415
416 // Property Title
417 $text_input = new ilTextInputGUI($lng->txt("block_feed_block_title"), "block_title");
418 $text_input->setInfo("");
419 $text_input->setRequired(true);
420 $text_input->setMaxLength(200);
421 $this->form_gui->addItem($text_input);
422
423 // Property FeedUrl
424 $text_input = new ilFeedUrlInputGUI($lng->txt("block_feed_block_feed_url"), "block_feed_url");
425 $text_input->setInfo($lng->txt("block_feed_block_feed_url_info"));
426 $text_input->setRequired(true);
427 $text_input->setMaxLength(250);
428 $this->form_gui->addItem($text_input);
429
430
431 // save and cancel commands
432 if (in_array($a_mode, array(self::FORM_CREATE, self::FORM_RE_CREATE))) {
433 $this->form_gui->addCommandButton("saveFeedBlock", $lng->txt("save"));
434 $this->form_gui->addCommandButton("cancelSaveFeedBlock", $lng->txt("cancel"));
435 } else {
436 $this->form_gui->addCommandButton("updateFeedBlock", $lng->txt("save"));
437 $this->form_gui->addCommandButton("cancelUpdateFeedBlock", $lng->txt("cancel"));
438 }
439
440 $this->form_gui->setTitle($lng->txt("block_feed_block_head"));
441 $this->form_gui->setFormAction($this->ctrl->getFormAction($this));
442
443 $this->prepareFormFeedBlock($this->form_gui);
444 }
445
451 public function prepareSaveFeedBlock(&$a_feed_block)
452 {
453 $ilCtrl = $this->ctrl;
454
455 $a_feed_block->setContextObjId($ilCtrl->getContextObjId());
456 $a_feed_block->setContextObjType($ilCtrl->getContextObjType());
457 $a_feed_block->setType("pdfeed");
458 }
459
463 public function confirmDeleteFeedBlock()
464 {
465 $ilCtrl = $this->ctrl;
467
468 include_once("Services/Utilities/classes/class.ilConfirmationGUI.php");
469 $c_gui = new ilConfirmationGUI();
470
471 // set confirm/cancel commands
472 $c_gui->setFormAction($ilCtrl->getFormAction($this, "deleteFeedBlock"));
473 $c_gui->setHeaderText($lng->txt("info_delete_sure"));
474 $c_gui->setCancel($lng->txt("cancel"), "exitDeleteFeedBlock");
475 $c_gui->setConfirm($lng->txt("confirm"), "deleteFeedBlock");
476
477 // add items to delete
478 $c_gui->addItem(
479 "external_feed_block_id",
480 $this->feed_block->getId(),
481 $this->feed_block->getTitle(),
482 ilUtil::getImagePath("icon_feed.svg")
483 );
484
485 return $c_gui->getHTML();
486 }
487
491 public function exitDeleteFeedBlock()
492 {
493 $ilCtrl = $this->ctrl;
494
495 $ilCtrl->returnToParent($this);
496 }
497
501 public function deleteFeedBlock()
502 {
503 $ilCtrl = $this->ctrl;
504
505 $this->feed_block->delete();
506 $ilCtrl->returnToParent($this);
507 }
508}
user()
Definition: user.php:4
$_GET["client_id"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
const IL_SCREEN_SIDE
const IL_SCREEN_CENTER
Confirmation screen class.
BlockGUI class for (centered) Content on Personal Desktop.
Handles external Feeds via Magpie library.
This class represents a feed url property in a property form.
BlockGUI class for external feed block on the personal desktop.
setBlock($a_block)
Do most of the initialisation.
static getScreenMode()
Get Screen Mode for current command.
initFormFeedBlock($a_mode)
FORM FeedBlock: Init form.
exitDeleteFeedBlock()
Cancel deletion of feed block.
confirmDeleteFeedBlock()
Confirmation of feed block deletion.
prepareSaveFeedBlock(&$a_feed_block)
FORM FeedBlock: Prepare Saving of FeedBlock.
This class represents a property form user interface.
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)
global $ilCtrl
Definition: ilias.php:18
exit
Definition: login.php:29
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $ilSetting
Definition: privfeed.php:17
$lng
settings()
Definition: settings.php:2
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
$ilUser
Definition: imgupload.php:18
$DIC
Definition: xapitoken.php:46