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