ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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{
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
75 public static function getBlockType()
76 {
77 return self::$block_type;
78 }
79
85 public static function isRepositoryObject()
86 {
87 return false;
88 }
89
93 public static function getScreenMode()
94 {
95 global $DIC;
96
97 $ilCtrl = $DIC->ctrl();
98
99 switch ($ilCtrl->getCmd()) {
100 case "create":
101 case "edit":
102 case "saveFeedBlock":
103 case "updateFeedBlock":
104 case "editFeedBlock":
105 case "showFeedItem":
106 case "confirmDeleteFeedBlock":
107 return IL_SCREEN_CENTER;
108 break;
109
110 default:
111 return IL_SCREEN_SIDE;
112 break;
113 }
114 }
115
119 public function setBlock($a_block)
120 {
122
123 // init block
124 $this->feed_block = $a_block;
125 $this->setTitle($this->feed_block->getTitle());
126 $this->setBlockId($this->feed_block->getId());
127
128 // get feed object
129 include_once("./Services/Feeds/classes/class.ilExternalFeed.php");
130 $this->feed = new ilExternalFeed();
131 $this->feed->setUrl($this->feed_block->getFeedUrl());
132
133 // init details
134 $this->setAvailableDetailLevels(2);
135
136 $ilCtrl->setParameter($this, "block_id", $this->feed_block->getId());
137 }
138
142 public function executeCommand()
143 {
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 ($this->getCurrentDetailLevel() > 1 && count($this->getData()) > 0) {
163 parent::fillDataSection();
164 } else {
165 $this->setDataSection($this->getOverview());
166 }
167 }
168
172 public function getHTML()
173 {
178
179
180 if ($ilSetting->get("block_limit_pdfeed") == 0) {
181 return "";
182 }
183
184 if ($this->getCurrentDetailLevel() == 0) {
185 return "";
186 }
187
188
189 // if no dynamic reload
190 if (!$this->getDynamic()) {
191 $this->feed->fetch();
192 $this->setData($this->feed->getItems());
193 }
194
195 $ilCtrl->setParameter(
196 $this,
197 "external_feed_block_id",
198 $this->getBlockId()
199 );
200 $this->addBlockCommand(
201 $ilCtrl->getLinkTarget(
202 $this,
203 "editFeedBlock"
204 ),
205 $lng->txt("edit")
206 );
207 $this->addBlockCommand(
208 $ilCtrl->getLinkTarget(
209 $this,
210 "confirmDeleteFeedBlock"
211 ),
212 $lng->txt("delete")
213 );
214 $ilCtrl->setParameter($this, "external_feed_block_id", "");
215
216 // JS enabler
217 $add = "";
218 if ($_SESSION["il_feed_js"] == "n" ||
219 ($ilUser->getPref("il_feed_js") == "n" && $_SESSION["il_feed_js"] != "y")) {
220 $add = $this->getJSEnabler();
221 }
222
223 return parent::getHTML() . $add;
224 }
225
226 public function getDynamic()
227 {
230
231 if ($ilCtrl->getCmdClass() != "ilcolumngui" && $ilCtrl->getCmd() != "enableJS") {
232 $sess_feed_js = "";
233 if (isset($_SESSION["il_feed_js"])) {
234 $sess_feed_js = $_SESSION["il_feed_js"];
235 }
236 if ($sess_feed_js != "n" &&
237 ($ilUser->getPref("il_feed_js") != "n" || $sess_feed_js == "y")) {
238 // do not get feed dynamically, if cache hit is given.
239 if (!$this->feed->checkCacheHit()) {
240 return true;
241 }
242 }
243 }
244
245 return false;
246 }
247
248 public function getDynamicReload()
249 {
252
253 $ilCtrl->setParameterByClass(
254 "ilcolumngui",
255 "block_id",
256 "block_pdfeed_" . $this->getBlockId()
257 );
258
259 $rel_tpl = new ilTemplate("tpl.dynamic_reload.html", true, true, "Services/Feeds");
260 $rel_tpl->setVariable("TXT_LOADING", $lng->txt("feed_loading_feed"));
261 $rel_tpl->setVariable("BLOCK_ID", "block_pdfeed_" . $this->getBlockId());
262 $rel_tpl->setVariable(
263 "TARGET",
264 $ilCtrl->getLinkTargetByClass("ilcolumngui", "updateBlock", "", true)
265 );
266
267 // no JS
268 $rel_tpl->setVariable("TXT_FEED_CLICK_HERE", $lng->txt("feed_no_js_click_here"));
269 $rel_tpl->setVariable(
270 "TARGET_NO_JS",
271 $ilCtrl->getLinkTargetByClass("ilpdexternalfeedblockgui", "disableJS")
272 );
273
274 return $rel_tpl->get();
275 }
276
277 public function getJSEnabler()
278 {
280
281 $ilCtrl->setParameterByClass(
282 "ilcolumngui",
283 "block_id",
284 "block_pdfeed_" . $this->getBlockId()
285 );
286
287 $rel_tpl = new ilTemplate("tpl.js_enabler.html", true, true, "Services/Feeds");
288 $rel_tpl->setVariable("BLOCK_ID", "block_pdfeed_" . $this->getBlockId());
289 $rel_tpl->setVariable(
290 "TARGET",
291 $ilCtrl->getLinkTargetByClass("ilpdexternalfeedblockgui", "enableJS", true)
292 );
293
294 return $rel_tpl->get();
295 }
296
297
298 public function disableJS()
299 {
302
303 $_SESSION["il_feed_js"] = "n";
304 $ilUser->writePref("il_feed_js", "n");
305 $ilCtrl->redirectByClass("ilpersonaldesktopgui", "show");
306 }
307
308 public function enableJS()
309 {
311
312 $_SESSION["il_feed_js"] = "y";
313 $ilUser->writePref("il_feed_js", "y");
314 echo $this->getHTML();
315 exit;
316 }
317
321 public function fillRow($item)
322 {
324
325 $ilCtrl->setParameter($this, "feed_item_id", $item->getId());
326 $this->tpl->setVariable("VAL_TITLE", $item->getTitle());
327 $this->tpl->setVariable(
328 "HREF_SHOW",
329 $ilCtrl->getLinkTarget($this, "showFeedItem")
330 );
331 $ilCtrl->setParameter($this, "feed_item_id", "");
332 }
333
337 public function getOverview()
338 {
340
341 $this->setEnableNumInfo(false);
342 return '<div class="small">' . ((int) count($this->getData())) . " " . $lng->txt("feed_feed_items") . "</div>";
343 }
344
348 public function showFeedItem()
349 {
352
353 include_once("./Services/News/classes/class.ilNewsItem.php");
354
355 $this->feed->fetch();
356 foreach ($this->feed->getItems() as $item) {
357 if ($item->getId() == $_GET["feed_item_id"]) {
358 $c_item = $item;
359 break;
360 }
361 }
362
363 $tpl = new ilTemplate("tpl.show_feed_item.html", true, true, "Services/Feeds");
364
365 if (is_object($c_item)) {
366 if (trim($c_item->getSummary()) != "") { // summary
367 $tpl->setCurrentBlock("content");
368 $tpl->setVariable("VAL_CONTENT", $c_item->getSummary());
369 $tpl->parseCurrentBlock();
370 }
371 if (trim($c_item->getDate()) != "" || trim($c_item->getAuthor()) != "") { // date
372 $tpl->setCurrentBlock("date_author");
373 if (trim($c_item->getAuthor()) != "") {
374 $tpl->setVariable("VAL_AUTHOR", $c_item->getAuthor() . " - ");
375 }
376 $tpl->setVariable("VAL_DATE", $c_item->getDate());
377 $tpl->parseCurrentBlock();
378 }
379
380 if (trim($c_item->getLink()) != "") { // link
381 $tpl->setCurrentBlock("plink");
382 $tpl->setVariable("HREF_LINK", $c_item->getLink());
383 $tpl->setVariable("TXT_LINK", $lng->txt("feed_open_source_page"));
384 $tpl->parseCurrentBlock();
385 }
386 $tpl->setVariable("VAL_TITLE", $c_item->getTitle()); // title
387 }
388
389 include_once("./Services/PersonalDesktop/classes/class.ilPDContentBlockGUI.php");
390 $content_block = new ilPDContentBlockGUI();
391 $content_block->setContent($tpl->get());
392 $content_block->setTitle($this->getTitle());
393 $content_block->setImage(ilUtil::getImagePath("icon_feed.svg"));
394 $content_block->addHeaderCommand(
395 $ilCtrl->getParentReturn($this),
396 $lng->txt("selected_items_back")
397 );
398
399 return $content_block->getHTML();
400 }
401
405 public function create()
406 {
407 return $this->createFeedBlock();
408 }
409
416 public function initFormFeedBlock($a_mode)
417 {
419
420 $lng->loadLanguageModule("block");
421
422 require_once("Services/Form/classes/class.ilPropertyFormGUI.php");
423
424 $this->form_gui = new ilPropertyFormGUI();
425
426 // Property Title
427 $text_input = new ilTextInputGUI($lng->txt("block_feed_block_title"), "block_title");
428 $text_input->setInfo("");
429 $text_input->setRequired(true);
430 $text_input->setMaxLength(200);
431 $this->form_gui->addItem($text_input);
432
433 // Property FeedUrl
434 $text_input = new ilFeedUrlInputGUI($lng->txt("block_feed_block_feed_url"), "block_feed_url");
435 $text_input->setInfo($lng->txt("block_feed_block_feed_url_info"));
436 $text_input->setRequired(true);
437 $text_input->setMaxLength(250);
438 $this->form_gui->addItem($text_input);
439
440
441 // save and cancel commands
442 if (in_array($a_mode, array(IL_FORM_CREATE,IL_FORM_RE_CREATE))) {
443 $this->form_gui->addCommandButton("saveFeedBlock", $lng->txt("save"));
444 $this->form_gui->addCommandButton("cancelSaveFeedBlock", $lng->txt("cancel"));
445 } else {
446 $this->form_gui->addCommandButton("updateFeedBlock", $lng->txt("save"));
447 $this->form_gui->addCommandButton("cancelUpdateFeedBlock", $lng->txt("cancel"));
448 }
449
450 $this->form_gui->setTitle($lng->txt("block_feed_block_head"));
451 $this->form_gui->setFormAction($this->ctrl->getFormAction($this));
452
453 $this->prepareFormFeedBlock($this->form_gui);
454 }
455
461 public function prepareSaveFeedBlock(&$a_feed_block)
462 {
464
465 $a_feed_block->setContextObjId($ilCtrl->getContextObjId());
466 $a_feed_block->setContextObjType($ilCtrl->getContextObjType());
467 $a_feed_block->setType("pdfeed");
468 }
469
473 public function confirmDeleteFeedBlock()
474 {
477
478 include_once("Services/Utilities/classes/class.ilConfirmationGUI.php");
479 $c_gui = new ilConfirmationGUI();
480
481 // set confirm/cancel commands
482 $c_gui->setFormAction($ilCtrl->getFormAction($this, "deleteFeedBlock"));
483 $c_gui->setHeaderText($lng->txt("info_delete_sure"));
484 $c_gui->setCancel($lng->txt("cancel"), "exitDeleteFeedBlock");
485 $c_gui->setConfirm($lng->txt("confirm"), "deleteFeedBlock");
486
487 // add items to delete
488 $c_gui->addItem(
489 "external_feed_block_id",
490 $this->feed_block->getId(),
491 $this->feed_block->getTitle(),
492 ilUtil::getImagePath("icon_feed.svg")
493 );
494
495 return $c_gui->getHTML();
496 }
497
501 public function exitDeleteFeedBlock()
502 {
504
505 $ilCtrl->returnToParent($this);
506 }
507
511 public function deleteFeedBlock()
512 {
514
515 $this->feed_block->delete();
516 $ilCtrl->returnToParent($this);
517 }
518}
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
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.
getData()
Get Data.
Confirmation screen class.
GUI class for external news feed custom block.
createFeedBlock()
FORM FeedBlock: Create ExternalFeedBlock.
prepareFormFeedBlock(&$a_form_gui)
FORM FeedBlock: Prepare form.
Handles external Feeds via Magpie library.
This class represents a feed url property in a property form.
BlockGUI class for (centered) Content on Personal Desktop.
BlockGUI class for external feed block on the personal desktop.
static isRepositoryObject()
Get block type.
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
global $ilSetting
Definition: privfeed.php:17
global $DIC
Definition: saml.php:7
settings()
Definition: settings.php:2
$ilUser
Definition: imgupload.php:18