ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
28  {
29  global $ilCtrl, $lng;
30 
33 
34  $this->setImage(ilUtil::getImagePath("icon_feed_s.png"));
35 
36  $lng->loadLanguageModule("feed");
37  $this->setLimit(5);
38  $this->setRowTemplate("tpl.block_external_feed_row.html", "Services/Feeds");
39  }
40 
46  static function getBlockType()
47  {
48  return self::$block_type;
49  }
50 
56  static function isRepositoryObject()
57  {
58  return true;
59  }
60 
64  static function getScreenMode()
65  {
66  global $ilCtrl;
67 
68  switch($ilCtrl->getCmd())
69  {
70  case "create":
71  case "edit":
72  case "saveFeedBlock":
73  case "updateFeedBlock":
74  case "editFeedBlock":
75  case "showFeedItem":
76  case "confirmDeleteFeedBlock":
77  return IL_SCREEN_CENTER;
78  break;
79 
80  default:
81  return IL_SCREEN_SIDE;
82  break;
83  }
84  }
85 
89  function setBlock($a_block)
90  {
91  global $ilCtrl;
92 
93  // init block
94  $this->feed_block = $a_block;
95  $this->setTitle($this->feed_block->getTitle());
96  $this->setBlockId($this->feed_block->getId());
97 
98  // get feed object
99  include_once("./Services/Feeds/classes/class.ilExternalFeed.php");
100  $this->feed = new ilExternalFeed();
101  $this->feed->setUrl($this->feed_block->getFeedUrl());
102 
103  // init details
104  $this->setAvailableDetailLevels(2);
105 
106  $ilCtrl->setParameter($this, "block_id", $this->feed_block->getId());
107  }
108 
112  function &executeCommand()
113  {
114  global $ilCtrl;
115 
116  $next_class = $ilCtrl->getNextClass();
117  $cmd = $ilCtrl->getCmd("getHTML");
118 
119  switch ($next_class)
120  {
121  default:
122  return $this->$cmd();
123  }
124  }
125 
129  function fillDataSection()
130  {
131  if ($this->getDynamic())
132  {
133  $this->setDataSection($this->getDynamicReload());
134  }
135  else if ($this->getCurrentDetailLevel() > 1 && count($this->getData()) > 0)
136  {
138  }
139  else
140  {
141  $this->setDataSection($this->getOverview());
142  }
143  }
144 
148  function getHTML()
149  {
150  global $ilCtrl, $lng, $ilUser, $ilAccess, $ilSetting;
151 
152  if ($this->getCurrentDetailLevel() == 0)
153  {
154  return "";
155  }
156 
157  $feed_set = new ilSetting("feed");
158 
159  if ($feed_set->get("disable_rep_feeds"))
160  {
161  return "";
162  }
163 
164  // if no dynamic reload
165  if (!$this->getDynamic())
166  {
167  $this->feed->fetch();
168  $this->setData($this->feed->getItems());
169  }
170 
171  //$this->setTitle($this->feed->getChannelTitle());
172  $this->setData($this->feed->getItems());
173 
174  if ($ilAccess->checkAccess("write", "", $this->getRefId()))
175  {
176  $ilCtrl->setParameterByClass("ilobjexternalfeedgui",
177  "ref_id", $this->getRefId());
178  $ilCtrl->setParameter($this, "external_feed_block_id", $this->getBlockId());
179  $this->addBlockCommand(
180  $ilCtrl->getLinkTargetByClass(array("ilrepositorygui", "ilobjexternalfeedgui",
181  "ilexternalfeedblockgui"),
182  "editFeedBlock"),
183  $lng->txt("settings"));
184  $ilCtrl->clearParametersByClass("ilobjexternalfeedgui");
185  }
186 
187  // JS enabler
188  $add = "";
189  if ($_SESSION["il_feed_js"] == "n" ||
190  ($ilUser->getPref("il_feed_js") == "n" && $_SESSION["il_feed_js"] != "y"))
191  {
192  $add = $this->getJSEnabler();
193  }
194 
195  return parent::getHTML().$add;
196  }
197 
198  function getDynamic()
199  {
200  global $ilCtrl, $ilUser;
201 
202  if ($ilCtrl->getCmdClass() != "ilcolumngui" && $ilCtrl->getCmd() != "enableJS")
203  {
204  if ($_SESSION["il_feed_js"] != "n" &&
205  ($ilUser->getPref("il_feed_js") != "n" || $_SESSION["il_feed_js"] == "y"))
206  {
207  // do not get feed dynamically, if cache hit is given.
208  if (!$this->feed->checkCacheHit())
209  {
210  return true;
211  }
212  }
213  }
214 
215  return false;
216  }
217 
218  function getDynamicReload()
219  {
220  global $ilCtrl, $lng;
221 
222  $ilCtrl->setParameterByClass("ilcolumngui", "block_id",
223  "block_feed_".$this->getBlockId());
224 
225  $rel_tpl = new ilTemplate("tpl.dynamic_reload.html", true, true, "Services/Feeds");
226  $rel_tpl->setVariable("TXT_LOADING", $lng->txt("feed_loading_feed"));
227  $rel_tpl->setVariable("BLOCK_ID", "block_feed_".$this->getBlockId());
228  $rel_tpl->setVariable("TARGET",
229  $ilCtrl->getLinkTargetByClass("ilcolumngui", "updateBlock", "", true));
230 
231  // no JS
232  $rel_tpl->setVariable("TXT_FEED_CLICK_HERE", $lng->txt("feed_no_js_click_here"));
233  $rel_tpl->setVariable("TARGET_NO_JS",
234  $ilCtrl->getLinkTargetByClass("ilexternalfeedblockgui", "disableJS"));
235 
236  return $rel_tpl->get();
237  }
238 
239  function getJSEnabler()
240  {
241  global $ilCtrl, $lng;
242 
243  $ilCtrl->setParameterByClass("ilcolumngui", "block_id",
244  "block_feed_".$this->getBlockId());
245 
246  $rel_tpl = new ilTemplate("tpl.js_enabler.html", true, true, "Services/Feeds");
247  $rel_tpl->setVariable("BLOCK_ID", "block_feed_".$this->getBlockId());
248  $rel_tpl->setVariable("TARGET",
249  $ilCtrl->getLinkTargetByClass("ilexternalfeedblockgui", "enableJS", true, "", false));
250 
251  return $rel_tpl->get();
252  }
253 
254 
255  function disableJS()
256  {
257  global $ilCtrl, $ilUser;
258 
259  $_SESSION["il_feed_js"] = "n";
260  $ilUser->writePref("il_feed_js", "n");
261  $ilCtrl->returnToParent($this);
262  }
263 
264  function enableJS()
265  {
266  global $ilUser;
267 
268  $_SESSION["il_feed_js"] = "y";
269  $ilUser->writePref("il_feed_js", "y");
270  echo $this->getHTML();
271  exit;
272  }
273 
277  function fillRow($item)
278  {
279  global $ilUser, $ilCtrl, $lng, $ilAccess;
280 
281  if ($this->isRepositoryObject() && !$ilAccess->checkAccess("read", "", $this->getRefId()))
282  {
283  $this->tpl->setVariable("TXT_TITLE", $item->getTitle());
284  }
285  else
286  {
287  $ilCtrl->setParameter($this, "feed_item_id", $item->getId());
288  $this->tpl->setCurrentBlock("feed_link");
289  $this->tpl->setVariable("VAL_TITLE", $item->getTitle());
290  $this->tpl->setVariable("HREF_SHOW",
291  $ilCtrl->getLinkTarget($this, "showFeedItem"));
292  $ilCtrl->setParameter($this, "feed_item_id", "");
293  $this->tpl->parseCurrentBlock();
294  }
295  }
296 
300  function getOverview()
301  {
302  global $ilUser, $lng, $ilCtrl;
303 
304  $this->setEnableNumInfo(false);
305  return '<div class="small">'.((int) count($this->getData()))." ".$lng->txt("feed_feed_items")."</div>";
306  }
307 
311  function showFeedItem()
312  {
313  global $lng, $ilCtrl;
314 
315  include_once("./Services/News/classes/class.ilNewsItem.php");
316 
317  $this->feed->fetch();
318  foreach($this->feed->getItems() as $item)
319  {
320  if ($item->getId() == $_GET["feed_item_id"])
321  {
322  $c_item = $item;
323  break;
324  }
325  }
326 
327  $tpl = new ilTemplate("tpl.show_feed_item.html", true, true, "Services/Feeds");
328 
329  if (is_object($c_item))
330  {
331  if (trim($c_item->getSummary()) != "") // summary
332  {
333  $tpl->setCurrentBlock("content");
334  $tpl->setVariable("VAL_CONTENT", $c_item->getSummary());
335  $tpl->parseCurrentBlock();
336  }
337  if (trim($c_item->getDate()) != "" || trim($c_item->getAuthor()) != "") // date
338  {
339  $tpl->setCurrentBlock("date_author");
340  if (trim($c_item->getAuthor()) != "")
341  {
342  $tpl->setVariable("VAL_AUTHOR", $c_item->getAuthor()." - ");
343  }
344  $tpl->setVariable("VAL_DATE", $c_item->getDate());
345  $tpl->parseCurrentBlock();
346  }
347 
348  if (trim($c_item->getLink()) != "") // link
349  {
350  $tpl->setCurrentBlock("plink");
351  $tpl->setVariable("HREF_LINK", $c_item->getLink());
352  $tpl->setVariable("TXT_LINK", $lng->txt("feed_open_source_page"));
353  $tpl->parseCurrentBlock();
354  }
355  $tpl->setVariable("VAL_TITLE", $c_item->getTitle()); // title
356  }
357 
358  include_once("./Services/PersonalDesktop/classes/class.ilPDContentBlockGUI.php");
359  $content_block = new ilPDContentBlockGUI();
360  $content_block->setContent($tpl->get());
361  $content_block->setTitle($this->getTitle());
362  $content_block->setImage(ilUtil::getImagePath("icon_feed.png"));
363  $content_block->addHeaderCommand($ilCtrl->getParentReturn($this),
364  $lng->txt("close"), true);
365 
366  return $content_block->getHTML();
367  }
368 
372  function create()
373  {
374  $html1 = $this->createFeedBlock();
375 
376  $html2 = "";
377  if (DEVMODE == 1)
378  {
379  $this->initImportForm("feed");
380  $html2 = "<br/>".$this->form->getHTML();
381  }
382 
383  return $html1.$html2;
384  }
385 
391  public function initImportForm($a_new_type = "")
392  {
393  global $lng, $ilCtrl;
394 
395  $lng->loadLanguageModule("feed");
396 
397  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
398  $this->form = new ilPropertyFormGUI();
399  $this->form->setTarget("_top");
400 
401  // Import file
402  include_once("./Services/Form/classes/class.ilFileInputGUI.php");
403  $fi = new ilFileInputGUI($lng->txt("import_file"), "importfile");
404  $fi->setSuffixes(array("zip"));
405  $fi->setRequired(true);
406  $this->form->addItem($fi);
407 
408  $this->form->addCommandButton("importFile", $lng->txt("import"));
409  $this->form->addCommandButton("cancelSaveFeedBlock", $lng->txt("cancel"));
410  $this->form->setTitle($lng->txt($a_new_type."_import"));
411 
412  $ilCtrl->setParameter($this, "new_type", $a_new_type);
413  $this->form->setFormAction($ilCtrl->getFormAction($this));
414  }
415 
421  function importFile()
422  {
423  global $rbacsystem, $objDefinition, $tpl, $lng;
424 
425  $new_type = $_POST["new_type"] ? $_POST["new_type"] : $_GET["new_type"];
426 
427  // create permission is already checked in createObject. This check here is done to prevent hacking attempts
428  if (!$rbacsystem->checkAccess("create", $_GET["ref_id"], $new_type))
429  {
430  $this->ilias->raiseError($this->lng->txt("no_create_permission"), $this->ilias->error_obj->MESSAGE);
431  }
432  $this->ctrl->setParameter($this, "new_type", $new_type);
433  $this->initImportForm($new_type);
434  if ($this->form->checkInput())
435  {
436  // todo: make some check on manifest file
437  include_once("./Services/Export/classes/class.ilImport.php");
438  $imp = new ilImport((int) $_GET['ref_id']);
439  $new_id = $imp->importObject($newObj, $_FILES["importfile"]["tmp_name"],
440  $_FILES["importfile"]["name"], $new_type);
441 
442  // put new object id into tree
443  if ($new_id > 0)
444  {
445  $newObj = ilObjectFactory::getInstanceByObjId($new_id);
446  $newObj->createReference();
447  $newObj->putInTree($_GET["ref_id"]);
448  $newObj->setPermissions($_GET["ref_id"]);
449  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
450  $this->exitSaveFeedBlock();
451  }
452  return;
453  }
454 
455  $this->form->setValuesByPost();
456  $tpl->setContent($this->form->getHtml());
457  }
458 
459 
466  public function initFormFeedBlock($a_mode)
467  {
468  global $lng;
469 
470  $lng->loadLanguageModule("block");
471 
472  include("Services/Form/classes/class.ilPropertyFormGUI.php");
473 
474  $this->form_gui = new ilPropertyFormGUI();
475 
476  // Property Title
477  $text_input = new ilTextInputGUI($lng->txt("block_feed_block_title"), "block_title");
478  $text_input->setInfo("");
479  $text_input->setRequired(true);
480  $text_input->setMaxLength(200);
481  $this->form_gui->addItem($text_input);
482 
483  // Property FeedUrl
484  $text_input = new ilFeedUrlInputGUI($lng->txt("block_feed_block_feed_url"), "block_feed_url");
485  $text_input->setInfo($lng->txt("block_feed_block_feed_url_info"));
486  $text_input->setRequired(true);
487  $text_input->setMaxLength(250);
488  $this->form_gui->addItem($text_input);
489 
490 
491  // save and cancel commands
492  if (in_array($a_mode, array(IL_FORM_CREATE,IL_FORM_RE_CREATE)))
493  {
494  $this->form_gui->addCommandButton("saveFeedBlock", $lng->txt("save"));
495  $this->form_gui->addCommandButton("cancelSaveFeedBlock", $lng->txt("cancel"));
496  }
497  else
498  {
499  $this->form_gui->addCommandButton("updateFeedBlock", $lng->txt("save"));
500  $this->form_gui->addCommandButton("cancelUpdateFeedBlock", $lng->txt("cancel"));
501  }
502 
503  $this->form_gui->setTitle($lng->txt("block_feed_block_head"));
504  $this->form_gui->setFormAction($this->ctrl->getFormAction($this));
505 
506  $this->prepareFormFeedBlock($this->form_gui);
507 
508  }
509 
515  public function prepareSaveFeedBlock(&$a_feed_block)
516  {
517  global $ilCtrl;
518 
519  $ref_id = $this->getGuiObject()->save($a_feed_block);
520  $a_feed_block->setType($this->getBlockType());
521  //$a_feed_block->setContextObjId($ilCtrl->getContextObjId());
522  //$a_feed_block->setContextObjType($ilCtrl->getContextObjType());
523  }
524 
529  public function exitSaveFeedBlock()
530  {
531  global $ilCtrl;
532 
533  $this->getGuiObject()->exitSave();
534  }
535 
540  public function cancelUpdateFeedBlock()
541  {
542  global $ilCtrl;
543 
544  $this->getGuiObject()->cancelUpdate();
545  }
546 
551  public function exitUpdateFeedBlock()
552  {
553  global $ilCtrl;
554 
555  $this->getGuiObject()->update($this->external_feed_block);
556  }
557 
561 /*
562  function confirmDeleteFeedBlock()
563  {
564  global $ilCtrl, $lng;
565 
566  include_once("Services/Utilities/classes/class.ilConfirmationGUI.php");
567  $c_gui = new ilConfirmationGUI();
568 
569  // set confirm/cancel commands
570  $c_gui->setFormAction($ilCtrl->getFormAction($this, "deleteFeedBlock"));
571  $c_gui->setHeaderText($lng->txt("info_delete_sure"));
572  $c_gui->setCancel($lng->txt("cancel"), "exitDeleteFeedBlock");
573  $c_gui->setConfirm($lng->txt("confirm"), "deleteFeedBlock");
574 
575  // add items to delete
576  $c_gui->addItem("external_feed_block_id",
577  $this->feed_block->getId(), $this->feed_block->getTitle(),
578  ilUtil::getImagePath("icon_feed.png"));
579 
580  return $c_gui->getHTML();
581  }
582 */
583 
587 /*
588  function exitDeleteFeedBlock()
589  {
590  global $ilCtrl;
591 
592  $ilCtrl->returnToParent($this);
593  }
594 */
595 
599 /*
600  function deleteFeedBlock()
601  {
602  global $ilCtrl;
603 
604  $this->feed_block->delete();
605  $ilCtrl->returnToParent($this);
606  }
607 */
608 
609 }
610 
611 ?>