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