ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilExternalFeedBlockGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5include_once("./Services/Block/classes/class.ilBlockGUI.php");
6include_once("./Services/Block/classes/class.ilExternalFeedBlockGUIGen.php");
7include_once("./Services/Feeds/classes/class.ilExternalFeed.php");
8
21{
22 static $block_type = "feed";
23
28 {
29 global $ilCtrl, $lng;
30
31 parent::__construct();
32 parent::ilBlockGUI();
33
34 $lng->loadLanguageModule("feed");
35 $this->setLimit(5);
36 $this->setRowTemplate("tpl.block_external_feed_row.html", "Services/Feeds");
37 }
38
44 static function getBlockType()
45 {
46 return self::$block_type;
47 }
48
54 static function isRepositoryObject()
55 {
56 return true;
57 }
58
62 static function getScreenMode()
63 {
64 global $ilCtrl;
65
66 switch($ilCtrl->getCmd())
67 {
68 case "create":
69 case "edit":
70 case "saveFeedBlock":
71 case "updateFeedBlock":
72 case "editFeedBlock":
73 case "showFeedItem":
74 case "confirmDeleteFeedBlock":
75 return IL_SCREEN_CENTER;
76 break;
77
78 default:
79 return IL_SCREEN_SIDE;
80 break;
81 }
82 }
83
87 function setBlock($a_block)
88 {
89 global $ilCtrl;
90
91 // init block
92 $this->feed_block = $a_block;
93 $this->setTitle($this->feed_block->getTitle());
94 $this->setBlockId($this->feed_block->getId());
95
96 // get feed object
97 include_once("./Services/Feeds/classes/class.ilExternalFeed.php");
98 $this->feed = new ilExternalFeed();
99 $this->feed->setUrl($this->feed_block->getFeedUrl());
100
101 // init details
102 $this->setAvailableDetailLevels(2);
103
104 $ilCtrl->setParameter($this, "block_id", $this->feed_block->getId());
105 }
106
110 function &executeCommand()
111 {
112 global $ilCtrl;
113
114 $next_class = $ilCtrl->getNextClass();
115 $cmd = $ilCtrl->getCmd("getHTML");
116
117 switch ($next_class)
118 {
119 default:
120 return $this->$cmd();
121 }
122 }
123
128 {
129 if ($this->getDynamic())
130 {
131 $this->setDataSection($this->getDynamicReload());
132 }
133 else if ($this->getCurrentDetailLevel() > 1 && count($this->getData()) > 0)
134 {
135 parent::fillDataSection();
136 }
137 else
138 {
139 $this->setDataSection($this->getOverview());
140 }
141 }
142
146 function getHTML()
147 {
148 global $ilCtrl, $lng, $ilUser, $ilAccess, $ilSetting;
149
150 if ($this->getCurrentDetailLevel() == 0)
151 {
152 return "";
153 }
154
155 $feed_set = new ilSetting("feed");
156
157 if ($feed_set->get("disable_rep_feeds"))
158 {
159 return "";
160 }
161
162 // if no dynamic reload
163 if (!$this->getDynamic())
164 {
165 $this->feed->fetch();
166 $this->setData($this->feed->getItems());
167 }
168
169 //$this->setTitle($this->feed->getChannelTitle());
170 $this->setData($this->feed->getItems());
171
172 if ($ilAccess->checkAccess("write", "", $this->getRefId()))
173 {
174 $ilCtrl->setParameterByClass("ilobjexternalfeedgui",
175 "ref_id", $this->getRefId());
176 $ilCtrl->setParameter($this, "external_feed_block_id", $this->getBlockId());
177 $this->addBlockCommand(
178 $ilCtrl->getLinkTargetByClass(array("ilrepositorygui", "ilobjexternalfeedgui",
179 "ilexternalfeedblockgui"),
180 "editFeedBlock"),
181 $lng->txt("settings"));
182 $ilCtrl->clearParametersByClass("ilobjexternalfeedgui");
183 }
184
185 // JS enabler
186 $add = "";
187 if ($_SESSION["il_feed_js"] == "n" ||
188 ($ilUser->getPref("il_feed_js") == "n" && $_SESSION["il_feed_js"] != "y"))
189 {
190 $add = $this->getJSEnabler();
191 }
192
193 return parent::getHTML().$add;
194 }
195
196 function getDynamic()
197 {
198 global $ilCtrl, $ilUser;
199
200 if ($ilCtrl->getCmdClass() != "ilcolumngui" && $ilCtrl->getCmd() != "enableJS")
201 {
202 if ($_SESSION["il_feed_js"] != "n" &&
203 ($ilUser->getPref("il_feed_js") != "n" || $_SESSION["il_feed_js"] == "y"))
204 {
205 // do not get feed dynamically, if cache hit is given.
206 if (!$this->feed->checkCacheHit())
207 {
208 return true;
209 }
210 }
211 }
212
213 return false;
214 }
215
217 {
218 global $ilCtrl, $lng;
219
220 $ilCtrl->setParameterByClass("ilcolumngui", "block_id",
221 "block_feed_".$this->getBlockId());
222
223 $rel_tpl = new ilTemplate("tpl.dynamic_reload.html", true, true, "Services/Feeds");
224 $rel_tpl->setVariable("TXT_LOADING", $lng->txt("feed_loading_feed"));
225 $rel_tpl->setVariable("BLOCK_ID", "block_feed_".$this->getBlockId());
226 $rel_tpl->setVariable("TARGET",
227 $ilCtrl->getLinkTargetByClass("ilcolumngui", "updateBlock", "", true));
228
229 // no JS
230 $rel_tpl->setVariable("TXT_FEED_CLICK_HERE", $lng->txt("feed_no_js_click_here"));
231 $rel_tpl->setVariable("TARGET_NO_JS",
232 $ilCtrl->getLinkTargetByClass("ilexternalfeedblockgui", "disableJS"));
233
234 return $rel_tpl->get();
235 }
236
237 function getJSEnabler()
238 {
239 global $ilCtrl, $lng;
240
241 $ilCtrl->setParameterByClass("ilcolumngui", "block_id",
242 "block_feed_".$this->getBlockId());
243
244 $rel_tpl = new ilTemplate("tpl.js_enabler.html", true, true, "Services/Feeds");
245 $rel_tpl->setVariable("BLOCK_ID", "block_feed_".$this->getBlockId());
246 $rel_tpl->setVariable("TARGET",
247 $ilCtrl->getLinkTargetByClass("ilexternalfeedblockgui", "enableJS", true, "", false));
248
249 return $rel_tpl->get();
250 }
251
252
253 function disableJS()
254 {
255 global $ilCtrl, $ilUser;
256
257 $_SESSION["il_feed_js"] = "n";
258 $ilUser->writePref("il_feed_js", "n");
259 $ilCtrl->returnToParent($this);
260 }
261
262 function enableJS()
263 {
264 global $ilUser;
265
266 $_SESSION["il_feed_js"] = "y";
267 $ilUser->writePref("il_feed_js", "y");
268 echo $this->getHTML();
269 exit;
270 }
271
275 function fillRow($item)
276 {
277 global $ilUser, $ilCtrl, $lng, $ilAccess;
278
279 if ($this->isRepositoryObject() && !$ilAccess->checkAccess("read", "", $this->getRefId()))
280 {
281 $this->tpl->setVariable("TXT_TITLE", $item->getTitle());
282 }
283 else
284 {
285 $ilCtrl->setParameter($this, "feed_item_id", $item->getId());
286 $this->tpl->setCurrentBlock("feed_link");
287 $this->tpl->setVariable("VAL_TITLE", $item->getTitle());
288 $this->tpl->setVariable("HREF_SHOW",
289 $ilCtrl->getLinkTarget($this, "showFeedItem"));
290 $ilCtrl->setParameter($this, "feed_item_id", "");
291 $this->tpl->parseCurrentBlock();
292 }
293 }
294
298 function getOverview()
299 {
300 global $ilUser, $lng, $ilCtrl;
301
302 $this->setEnableNumInfo(false);
303 return '<div class="small">'.((int) count($this->getData()))." ".$lng->txt("feed_feed_items")."</div>";
304 }
305
309 function showFeedItem()
310 {
311 global $lng, $ilCtrl;
312
313 include_once("./Services/News/classes/class.ilNewsItem.php");
314
315 $this->feed->fetch();
316 foreach($this->feed->getItems() as $item)
317 {
318 if ($item->getId() == $_GET["feed_item_id"])
319 {
320 $c_item = $item;
321 break;
322 }
323 }
324
325 $tpl = new ilTemplate("tpl.show_feed_item.html", true, true, "Services/Feeds");
326
327 if (is_object($c_item))
328 {
329 if (trim($c_item->getSummary()) != "") // summary
330 {
331 $tpl->setCurrentBlock("content");
332 $tpl->setVariable("VAL_CONTENT", $c_item->getSummary());
333 $tpl->parseCurrentBlock();
334 }
335 if (trim($c_item->getDate()) != "" || trim($c_item->getAuthor()) != "") // date
336 {
337 $tpl->setCurrentBlock("date_author");
338 if (trim($c_item->getAuthor()) != "")
339 {
340 $tpl->setVariable("VAL_AUTHOR", $c_item->getAuthor()." - ");
341 }
342 $tpl->setVariable("VAL_DATE", $c_item->getDate());
343 $tpl->parseCurrentBlock();
344 }
345
346 if (trim($c_item->getLink()) != "") // link
347 {
348 $tpl->setCurrentBlock("plink");
349 $tpl->setVariable("HREF_LINK", $c_item->getLink());
350 $tpl->setVariable("TXT_LINK", $lng->txt("feed_open_source_page"));
351 $tpl->parseCurrentBlock();
352 }
353 $tpl->setVariable("VAL_TITLE", $c_item->getTitle()); // title
354 }
355
356 include_once("./Services/PersonalDesktop/classes/class.ilPDContentBlockGUI.php");
357 $content_block = new ilPDContentBlockGUI();
358 $content_block->setContent($tpl->get());
359 $content_block->setTitle($this->getTitle());
360 $content_block->setImage(ilUtil::getImagePath("icon_feed.svg"));
361 $content_block->addHeaderCommand($ilCtrl->getParentReturn($this),
362 $lng->txt("close"), true);
363
364 return $content_block->getHTML();
365 }
366
370 function create()
371 {
372 $html1 = $this->createFeedBlock();
373
374 $html2 = "";
375 if (DEVMODE == 1)
376 {
377 $this->initImportForm("feed");
378 $html2 = "<br/>".$this->form->getHTML();
379 }
380
381 return $html1.$html2;
382 }
383
389 public function initImportForm($a_new_type = "")
390 {
391 global $lng, $ilCtrl;
392
393 $lng->loadLanguageModule("feed");
394
395 include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
396 $this->form = new ilPropertyFormGUI();
397 $this->form->setTarget("_top");
398
399 // Import file
400 include_once("./Services/Form/classes/class.ilFileInputGUI.php");
401 $fi = new ilFileInputGUI($lng->txt("import_file"), "importfile");
402 $fi->setSuffixes(array("zip"));
403 $fi->setRequired(true);
404 $this->form->addItem($fi);
405
406 $this->form->addCommandButton("importFile", $lng->txt("import"));
407 $this->form->addCommandButton("cancelSaveFeedBlock", $lng->txt("cancel"));
408 $this->form->setTitle($lng->txt($a_new_type."_import"));
409
410 $ilCtrl->setParameter($this, "new_type", $a_new_type);
411 $this->form->setFormAction($ilCtrl->getFormAction($this));
412 }
413
419 function importFile()
420 {
421 global $rbacsystem, $objDefinition, $tpl, $lng;
422
423 $new_type = $_POST["new_type"] ? $_POST["new_type"] : $_GET["new_type"];
424
425 // create permission is already checked in createObject. This check here is done to prevent hacking attempts
426 if (!$rbacsystem->checkAccess("create", $_GET["ref_id"], $new_type))
427 {
428 $this->ilias->raiseError($this->lng->txt("no_create_permission"), $this->ilias->error_obj->MESSAGE);
429 }
430 $this->ctrl->setParameter($this, "new_type", $new_type);
431 $this->initImportForm($new_type);
432 if ($this->form->checkInput())
433 {
434 // todo: make some check on manifest file
435 include_once("./Services/Export/classes/class.ilImport.php");
436 $imp = new ilImport((int) $_GET['ref_id']);
437 $new_id = $imp->importObject($newObj, $_FILES["importfile"]["tmp_name"],
438 $_FILES["importfile"]["name"], $new_type);
439
440 // put new object id into tree
441 if ($new_id > 0)
442 {
443 $newObj = ilObjectFactory::getInstanceByObjId($new_id);
444 $newObj->createReference();
445 $newObj->putInTree($_GET["ref_id"]);
446 $newObj->setPermissions($_GET["ref_id"]);
447 ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
448 $this->exitSaveFeedBlock();
449 }
450 return;
451 }
452
453 $this->form->setValuesByPost();
454 $tpl->setContent($this->form->getHtml());
455 }
456
457
464 public function initFormFeedBlock($a_mode)
465 {
466 global $lng;
467
468 $lng->loadLanguageModule("block");
469
470 include("Services/Form/classes/class.ilPropertyFormGUI.php");
471
472 $this->form_gui = new ilPropertyFormGUI();
473
474 // Property Title
475 $text_input = new ilTextInputGUI($lng->txt("block_feed_block_title"), "block_title");
476 $text_input->setInfo("");
477 $text_input->setRequired(true);
478 $text_input->setMaxLength(200);
479 $this->form_gui->addItem($text_input);
480
481 // Property FeedUrl
482 $text_input = new ilFeedUrlInputGUI($lng->txt("block_feed_block_feed_url"), "block_feed_url");
483 $text_input->setInfo($lng->txt("block_feed_block_feed_url_info"));
484 $text_input->setRequired(true);
485 $text_input->setMaxLength(250);
486 $this->form_gui->addItem($text_input);
487
488
489 // save and cancel commands
490 if (in_array($a_mode, array(IL_FORM_CREATE,IL_FORM_RE_CREATE)))
491 {
492 $this->form_gui->addCommandButton("saveFeedBlock", $lng->txt("save"));
493 $this->form_gui->addCommandButton("cancelSaveFeedBlock", $lng->txt("cancel"));
494 }
495 else
496 {
497 $this->form_gui->addCommandButton("updateFeedBlock", $lng->txt("save"));
498 $this->form_gui->addCommandButton("cancelUpdateFeedBlock", $lng->txt("cancel"));
499 }
500
501 $this->form_gui->setTitle($lng->txt("block_feed_block_head"));
502 $this->form_gui->setFormAction($this->ctrl->getFormAction($this));
503
504 $this->prepareFormFeedBlock($this->form_gui);
505
506 }
507
513 public function prepareSaveFeedBlock(&$a_feed_block)
514 {
515 global $ilCtrl;
516
517 $ref_id = $this->getGuiObject()->save($a_feed_block);
518 $a_feed_block->setType($this->getBlockType());
519 //$a_feed_block->setContextObjId($ilCtrl->getContextObjId());
520 //$a_feed_block->setContextObjType($ilCtrl->getContextObjType());
521 }
522
527 public function exitSaveFeedBlock()
528 {
529 global $ilCtrl;
530
531 $this->getGuiObject()->exitSave();
532 }
533
538 public function cancelUpdateFeedBlock()
539 {
540 global $ilCtrl;
541
542 $this->getGuiObject()->cancelUpdate();
543 }
544
549 public function exitUpdateFeedBlock()
550 {
551 global $ilCtrl;
552
553 $this->getGuiObject()->update($this->external_feed_block);
554 }
555
559/*
560 function confirmDeleteFeedBlock()
561 {
562 global $ilCtrl, $lng;
563
564 include_once("Services/Utilities/classes/class.ilConfirmationGUI.php");
565 $c_gui = new ilConfirmationGUI();
566
567 // set confirm/cancel commands
568 $c_gui->setFormAction($ilCtrl->getFormAction($this, "deleteFeedBlock"));
569 $c_gui->setHeaderText($lng->txt("info_delete_sure"));
570 $c_gui->setCancel($lng->txt("cancel"), "exitDeleteFeedBlock");
571 $c_gui->setConfirm($lng->txt("confirm"), "deleteFeedBlock");
572
573 // add items to delete
574 $c_gui->addItem("external_feed_block_id",
575 $this->feed_block->getId(), $this->feed_block->getTitle(),
576 ilUtil::getImagePath("icon_feed.svg"));
577
578 return $c_gui->getHTML();
579 }
580*/
581
585/*
586 function exitDeleteFeedBlock()
587 {
588 global $ilCtrl;
589
590 $ilCtrl->returnToParent($this);
591 }
592*/
593
597/*
598 function deleteFeedBlock()
599 {
600 global $ilCtrl;
601
602 $this->feed_block->delete();
603 $ilCtrl->returnToParent($this);
604 }
605*/
606
607}
608
609?>
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.
getRefId()
Get Ref Id (only used if isRepositoryObject() is true).
getData()
Get Data.
GUI class for external news feed custom block.
createFeedBlock()
FORM FeedBlock: Create ExternalFeedBlock.
prepareFormFeedBlock(&$a_form_gui)
FORM FeedBlock: Prepare form.
BlockGUI class for external feed block.
initImportForm($a_new_type="")
Init object import form.
cancelUpdateFeedBlock()
FORM FeedBlock: Exit save.
static getScreenMode()
Get Screen Mode for current command.
fillRow($item)
Fill feed item row.
setBlock($a_block)
Do most of the initialisation.
exitUpdateFeedBlock()
FORM FeedBlock: Exit save.
initFormFeedBlock($a_mode)
FORM FeedBlock: Init form.
static isRepositoryObject()
Get block type.
static getBlockType()
Get block type.
exitSaveFeedBlock()
FORM FeedBlock: Exit save.
prepareSaveFeedBlock(&$a_feed_block)
FORM FeedBlock: Prepare Saving of FeedBlock.
Handles external Feeds via Magpie libaray.
This class represents a feed url property in a property form.
This class represents a file property in a property form.
Import class.
getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
BlockGUI class for (centered) Content on Personal Desktop.
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 sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
$_POST['username']
Definition: cron.php:12
$html1
$html2
global $ilCtrl
Definition: ilias.php:18
exit
Definition: login.php:54
redirection script todo: (a better solution should control the processing via a xml file)
global $lng
Definition: privfeed.php:40
global $ilSetting
Definition: privfeed.php:40
$feed_set
Definition: privfeed.php:42
$cmd
Definition: sahs_server.php:35
$ref_id
Definition: sahs_server.php:39
global $ilUser
Definition: imgupload.php:15