ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 static $block_type = "pdfeed";
42
46 function __construct()
47 {
48 global $ilCtrl, $lng;
49
50 parent::__construct();
51
52 $lng->loadLanguageModule("feed");
53
54 $this->setLimit(5);
55 $this->setRowTemplate("tpl.block_external_feed_row.html", "Services/Feeds");
56 }
57
63 static function getBlockType()
64 {
65 return self::$block_type;
66 }
67
73 static function isRepositoryObject()
74 {
75 return false;
76 }
77
81 static function getScreenMode()
82 {
83 global $ilCtrl;
84
85 switch($ilCtrl->getCmd())
86 {
87 case "create":
88 case "edit":
89 case "saveFeedBlock":
90 case "updateFeedBlock":
91 case "editFeedBlock":
92 case "showFeedItem":
93 case "confirmDeleteFeedBlock":
94 return IL_SCREEN_CENTER;
95 break;
96
97 default:
98 return IL_SCREEN_SIDE;
99 break;
100 }
101 }
102
106 function setBlock($a_block)
107 {
108 global $ilCtrl;
109
110 // init block
111 $this->feed_block = $a_block;
112 $this->setTitle($this->feed_block->getTitle());
113 $this->setBlockId($this->feed_block->getId());
114
115 // get feed object
116 include_once("./Services/Feeds/classes/class.ilExternalFeed.php");
117 $this->feed = new ilExternalFeed();
118 $this->feed->setUrl($this->feed_block->getFeedUrl());
119
120 // init details
121 $this->setAvailableDetailLevels(2);
122
123 $ilCtrl->setParameter($this, "block_id", $this->feed_block->getId());
124 }
125
129 function executeCommand()
130 {
131 global $ilCtrl;
132
133 $next_class = $ilCtrl->getNextClass();
134 $cmd = $ilCtrl->getCmd("getHTML");
135
136 switch ($next_class)
137 {
138 default:
139 return $this->$cmd();
140 }
141 }
142
147 {
148 if ($this->getDynamic())
149 {
150 $this->setDataSection($this->getDynamicReload());
151 }
152 else if ($this->getCurrentDetailLevel() > 1 && count($this->getData()) > 0)
153 {
154 parent::fillDataSection();
155 }
156 else
157 {
158 $this->setDataSection($this->getOverview());
159 }
160 }
161
165 function getHTML()
166 {
167 global $ilCtrl, $lng, $ilUser, $ilAccess, $ilSetting;
168
169 $feed_set = new ilSetting("feed");
170
171 if ($ilSetting->get("block_limit_pdfeed") == 0)
172 {
173 return "";
174 }
175
176 if ($this->getCurrentDetailLevel() == 0)
177 {
178 return "";
179 }
180
181
182 // if no dynamic reload
183 if (!$this->getDynamic())
184 {
185 $this->feed->fetch();
186 $this->setData($this->feed->getItems());
187 }
188
189 $ilCtrl->setParameter($this, "external_feed_block_id",
190 $this->getBlockId());
191 $this->addBlockCommand(
192 $ilCtrl->getLinkTarget($this,
193 "editFeedBlock"),
194 $lng->txt("edit"));
195 $this->addBlockCommand(
196 $ilCtrl->getLinkTarget($this,
197 "confirmDeleteFeedBlock"),
198 $lng->txt("delete"));
199 $ilCtrl->setParameter($this, "external_feed_block_id", "");
200
201 // JS enabler
202 $add = "";
203 if ($_SESSION["il_feed_js"] == "n" ||
204 ($ilUser->getPref("il_feed_js") == "n" && $_SESSION["il_feed_js"] != "y"))
205 {
206 $add = $this->getJSEnabler();
207 }
208
209 return parent::getHTML().$add;
210 }
211
212 function getDynamic()
213 {
214 global $ilCtrl, $ilUser;
215
216 if ($ilCtrl->getCmdClass() != "ilcolumngui" && $ilCtrl->getCmd() != "enableJS")
217 {
218 $sess_feed_js = "";
219 if (isset($_SESSION["il_feed_js"]))
220 {
221 $sess_feed_js = $_SESSION["il_feed_js"];
222 }
223 if ($sess_feed_js != "n" &&
224 ($ilUser->getPref("il_feed_js") != "n" || $sess_feed_js == "y"))
225 {
226 // do not get feed dynamically, if cache hit is given.
227 if (!$this->feed->checkCacheHit())
228 {
229 return true;
230 }
231 }
232 }
233
234 return false;
235 }
236
238 {
239 global $ilCtrl, $lng;
240
241 $ilCtrl->setParameterByClass("ilcolumngui", "block_id",
242 "block_pdfeed_".$this->getBlockId());
243
244 $rel_tpl = new ilTemplate("tpl.dynamic_reload.html", true, true, "Services/Feeds");
245 $rel_tpl->setVariable("TXT_LOADING", $lng->txt("feed_loading_feed"));
246 $rel_tpl->setVariable("BLOCK_ID", "block_pdfeed_".$this->getBlockId());
247 $rel_tpl->setVariable("TARGET",
248 $ilCtrl->getLinkTargetByClass("ilcolumngui", "updateBlock", "", true));
249
250 // no JS
251 $rel_tpl->setVariable("TXT_FEED_CLICK_HERE", $lng->txt("feed_no_js_click_here"));
252 $rel_tpl->setVariable("TARGET_NO_JS",
253 $ilCtrl->getLinkTargetByClass("ilpdexternalfeedblockgui", "disableJS"));
254
255 return $rel_tpl->get();
256 }
257
258 function getJSEnabler()
259 {
260 global $ilCtrl, $lng;
261
262 $ilCtrl->setParameterByClass("ilcolumngui", "block_id",
263 "block_pdfeed_".$this->getBlockId());
264
265 $rel_tpl = new ilTemplate("tpl.js_enabler.html", true, true, "Services/Feeds");
266 $rel_tpl->setVariable("BLOCK_ID", "block_pdfeed_".$this->getBlockId());
267 $rel_tpl->setVariable("TARGET",
268 $ilCtrl->getLinkTargetByClass("ilpdexternalfeedblockgui", "enableJS", true));
269
270 return $rel_tpl->get();
271 }
272
273
274 function disableJS()
275 {
276 global $ilCtrl, $ilUser;
277
278 $_SESSION["il_feed_js"] = "n";
279 $ilUser->writePref("il_feed_js", "n");
280 $ilCtrl->redirectByClass("ilpersonaldesktopgui", "show");
281 }
282
283 function enableJS()
284 {
285 global $ilUser;
286
287 $_SESSION["il_feed_js"] = "y";
288 $ilUser->writePref("il_feed_js", "y");
289 echo $this->getHTML();
290 exit;
291 }
292
296 function fillRow($item)
297 {
298 global $ilUser, $ilCtrl, $lng;
299
300 $ilCtrl->setParameter($this, "feed_item_id", $item->getId());
301 $this->tpl->setVariable("VAL_TITLE", $item->getTitle());
302 $this->tpl->setVariable("HREF_SHOW",
303 $ilCtrl->getLinkTarget($this, "showFeedItem"));
304 $ilCtrl->setParameter($this, "feed_item_id", "");
305 }
306
310 function getOverview()
311 {
312 global $ilUser, $lng, $ilCtrl;
313
314 $this->setEnableNumInfo(false);
315 return '<div class="small">'.((int) count($this->getData()))." ".$lng->txt("feed_feed_items")."</div>";
316 }
317
321 function showFeedItem()
322 {
323 global $lng, $ilCtrl;
324
325 include_once("./Services/News/classes/class.ilNewsItem.php");
326
327 $this->feed->fetch();
328 foreach($this->feed->getItems() as $item)
329 {
330 if ($item->getId() == $_GET["feed_item_id"])
331 {
332 $c_item = $item;
333 break;
334 }
335 }
336
337 $tpl = new ilTemplate("tpl.show_feed_item.html", true, true, "Services/Feeds");
338
339 if (is_object($c_item))
340 {
341 if (trim($c_item->getSummary()) != "") // summary
342 {
343 $tpl->setCurrentBlock("content");
344 $tpl->setVariable("VAL_CONTENT", $c_item->getSummary());
345 $tpl->parseCurrentBlock();
346 }
347 if (trim($c_item->getDate()) != "" || trim($c_item->getAuthor()) != "") // date
348 {
349 $tpl->setCurrentBlock("date_author");
350 if (trim($c_item->getAuthor()) != "")
351 {
352 $tpl->setVariable("VAL_AUTHOR", $c_item->getAuthor()." - ");
353 }
354 $tpl->setVariable("VAL_DATE", $c_item->getDate());
355 $tpl->parseCurrentBlock();
356 }
357
358 if (trim($c_item->getLink()) != "") // link
359 {
360 $tpl->setCurrentBlock("plink");
361 $tpl->setVariable("HREF_LINK", $c_item->getLink());
362 $tpl->setVariable("TXT_LINK", $lng->txt("feed_open_source_page"));
363 $tpl->parseCurrentBlock();
364 }
365 $tpl->setVariable("VAL_TITLE", $c_item->getTitle()); // title
366 }
367
368 include_once("./Services/PersonalDesktop/classes/class.ilPDContentBlockGUI.php");
369 $content_block = new ilPDContentBlockGUI();
370 $content_block->setContent($tpl->get());
371 $content_block->setTitle($this->getTitle());
372 $content_block->setImage(ilUtil::getImagePath("icon_feed.svg"));
373 $content_block->addHeaderCommand($ilCtrl->getParentReturn($this),
374 $lng->txt("selected_items_back"));
375
376 return $content_block->getHTML();
377 }
378
382 function create()
383 {
384 return $this->createFeedBlock();
385 }
386
393 public function initFormFeedBlock($a_mode)
394 {
395 global $lng;
396
397 $lng->loadLanguageModule("block");
398
399 require_once("Services/Form/classes/class.ilPropertyFormGUI.php");
400
401 $this->form_gui = new ilPropertyFormGUI();
402
403 // Property Title
404 $text_input = new ilTextInputGUI($lng->txt("block_feed_block_title"), "block_title");
405 $text_input->setInfo("");
406 $text_input->setRequired(true);
407 $text_input->setMaxLength(200);
408 $this->form_gui->addItem($text_input);
409
410 // Property FeedUrl
411 $text_input = new ilFeedUrlInputGUI($lng->txt("block_feed_block_feed_url"), "block_feed_url");
412 $text_input->setInfo($lng->txt("block_feed_block_feed_url_info"));
413 $text_input->setRequired(true);
414 $text_input->setMaxLength(250);
415 $this->form_gui->addItem($text_input);
416
417
418 // save and cancel commands
419 if (in_array($a_mode, array(IL_FORM_CREATE,IL_FORM_RE_CREATE)))
420 {
421 $this->form_gui->addCommandButton("saveFeedBlock", $lng->txt("save"));
422 $this->form_gui->addCommandButton("cancelSaveFeedBlock", $lng->txt("cancel"));
423 }
424 else
425 {
426 $this->form_gui->addCommandButton("updateFeedBlock", $lng->txt("save"));
427 $this->form_gui->addCommandButton("cancelUpdateFeedBlock", $lng->txt("cancel"));
428 }
429
430 $this->form_gui->setTitle($lng->txt("block_feed_block_head"));
431 $this->form_gui->setFormAction($this->ctrl->getFormAction($this));
432
433 $this->prepareFormFeedBlock($this->form_gui);
434
435 }
436
442 public function prepareSaveFeedBlock(&$a_feed_block)
443 {
444 global $ilCtrl;
445
446 $a_feed_block->setContextObjId($ilCtrl->getContextObjId());
447 $a_feed_block->setContextObjType($ilCtrl->getContextObjType());
448 $a_feed_block->setType("pdfeed");
449 }
450
455 {
456 global $ilCtrl, $lng;
457
458 include_once("Services/Utilities/classes/class.ilConfirmationGUI.php");
459 $c_gui = new ilConfirmationGUI();
460
461 // set confirm/cancel commands
462 $c_gui->setFormAction($ilCtrl->getFormAction($this, "deleteFeedBlock"));
463 $c_gui->setHeaderText($lng->txt("info_delete_sure"));
464 $c_gui->setCancel($lng->txt("cancel"), "exitDeleteFeedBlock");
465 $c_gui->setConfirm($lng->txt("confirm"), "deleteFeedBlock");
466
467 // add items to delete
468 $c_gui->addItem("external_feed_block_id",
469 $this->feed_block->getId(), $this->feed_block->getTitle(),
470 ilUtil::getImagePath("icon_feed.svg"));
471
472 return $c_gui->getHTML();
473 }
474
479 {
480 global $ilCtrl;
481
482 $ilCtrl->returnToParent($this);
483 }
484
489 {
490 global $ilCtrl;
491
492 $this->feed_block->delete();
493 $ilCtrl->returnToParent($this);
494 }
495}
496
497?>
global $tpl
Definition: ilias.php:8
$_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.
addBlockCommand($a_href, $a_text, $a_target="", $a_img="", $a_right_aligned=false, $a_checked=false, $a_html="")
Add Block Command.
getTitle()
Get Title.
setTitle($a_title)
Set Title.
setBlockId($a_block_id=0)
Set Block Id.
setEnableNumInfo($a_enablenuminfo)
Set Enable Item Number Info.
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 libaray.
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.
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)
global $ilCtrl
Definition: ilias.php:18
global $lng
Definition: privfeed.php:17
$feed_set
Definition: privfeed.php:19
global $ilSetting
Definition: privfeed.php:17
$cmd
Definition: sahs_server.php:35
$ilUser
Definition: imgupload.php:18