ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilExternalFeedBlockGUI.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 
24 include_once("./Services/Block/classes/class.ilBlockGUI.php");
25 include_once("./Services/Block/classes/class.ilExternalFeedBlockGUIGen.php");
26 include_once("./Services/Feeds/classes/class.ilExternalFeed.php");
27 
40 {
41  static $block_type = "feed";
42 
47  {
48  global $ilCtrl, $lng;
49 
52 
53  $this->setImage(ilUtil::getImagePath("icon_feed_s.gif"));
54 
55  $lng->loadLanguageModule("feed");
56  $this->setLimit(5);
57  $this->setRowTemplate("tpl.block_external_feed_row.html", "Services/Feeds");
58  }
59 
65  static function getBlockType()
66  {
67  return self::$block_type;
68  }
69 
75  static function isRepositoryObject()
76  {
77  return true;
78  }
79 
83  static function getScreenMode()
84  {
85  global $ilCtrl;
86 
87  switch($ilCtrl->getCmd())
88  {
89  case "create":
90  case "edit":
91  case "saveFeedBlock":
92  case "updateFeedBlock":
93  case "editFeedBlock":
94  case "showFeedItem":
95  case "confirmDeleteFeedBlock":
96  return IL_SCREEN_CENTER;
97  break;
98 
99  default:
100  return IL_SCREEN_SIDE;
101  break;
102  }
103  }
104 
108  function setBlock($a_block)
109  {
110  global $ilCtrl;
111 
112  // init block
113  $this->feed_block = $a_block;
114  $this->setTitle($this->feed_block->getTitle());
115  $this->setBlockId($this->feed_block->getId());
116 
117  // get feed object
118  include_once("./Services/Feeds/classes/class.ilExternalFeed.php");
119  $this->feed = new ilExternalFeed();
120  $this->feed->setUrl($this->feed_block->getFeedUrl());
121 
122  // init details
123  $this->setAvailableDetailLevels(2);
124 
125  $ilCtrl->setParameter($this, "block_id", $this->feed_block->getId());
126  }
127 
131  function &executeCommand()
132  {
133  global $ilCtrl;
134 
135  $next_class = $ilCtrl->getNextClass();
136  $cmd = $ilCtrl->getCmd("getHTML");
137 
138  switch ($next_class)
139  {
140  default:
141  return $this->$cmd();
142  }
143  }
144 
148  function fillDataSection()
149  {
150  if ($this->getDynamic())
151  {
152  $this->setDataSection($this->getDynamicReload());
153  }
154  else if ($this->getCurrentDetailLevel() > 1 && count($this->getData()) > 0)
155  {
157  }
158  else
159  {
160  $this->setDataSection($this->getOverview());
161  }
162  }
163 
167  function getHTML()
168  {
169  global $ilCtrl, $lng, $ilUser, $ilAccess, $ilSetting;
170 
171  if ($this->getCurrentDetailLevel() == 0)
172  {
173  return "";
174  }
175 
176  $feed_set = new ilSetting("feed");
177 
178  if ($feed_set->get("disable_rep_feeds"))
179  {
180  return "";
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  //$this->setTitle($this->feed->getChannelTitle());
191  $this->setData($this->feed->getItems());
192 
193  if ($ilAccess->checkAccess("write", "", $this->getRefId()))
194  {
195  $ilCtrl->setParameterByClass("ilobjexternalfeedgui",
196  "ref_id", $this->getRefId());
197  $ilCtrl->setParameter($this, "external_feed_block_id", $this->getBlockId());
198  $this->addBlockCommand(
199  $ilCtrl->getLinkTargetByClass(array("ilrepositorygui", "ilobjexternalfeedgui",
200  "ilexternalfeedblockgui"),
201  "editFeedBlock"),
202  $lng->txt("edit"));
203  $ilCtrl->clearParametersByClass("ilobjexternalfeedgui");
204  }
205 
206  // JS enabler
207  $add = "";
208  if ($_SESSION["il_feed_js"] == "n" ||
209  ($ilUser->getPref("il_feed_js") == "n" && $_SESSION["il_feed_js"] != "y"))
210  {
211  $add = $this->getJSEnabler();
212  }
213 
214  return parent::getHTML().$add;
215  }
216 
217  function getDynamic()
218  {
219  global $ilCtrl, $ilUser;
220 
221  if ($ilCtrl->getCmdClass() != "ilcolumngui" && $ilCtrl->getCmd() != "enableJS")
222  {
223  if ($_SESSION["il_feed_js"] != "n" &&
224  ($ilUser->getPref("il_feed_js") != "n" || $_SESSION["il_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 
237  function getDynamicReload()
238  {
239  global $ilCtrl, $lng;
240 
241  $ilCtrl->setParameterByClass("ilcolumngui", "block_id",
242  "block_feed_".$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_feed_".$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("ilexternalfeedblockgui", "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_feed_".$this->getBlockId());
264 
265  $rel_tpl = new ilTemplate("tpl.js_enabler.html", true, true, "Services/Feeds");
266  $rel_tpl->setVariable("BLOCK_ID", "block_feed_".$this->getBlockId());
267  $rel_tpl->setVariable("TARGET",
268  $ilCtrl->getLinkTargetByClass("ilexternalfeedblockgui", "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->returnToParent($this);
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, $ilAccess;
299 
300  if ($this->isRepositoryObject() && !$ilAccess->checkAccess("read", "", $this->getRefId()))
301  {
302  $this->tpl->setVariable("TXT_TITLE", $item->getTitle());
303  }
304  else
305  {
306  $ilCtrl->setParameter($this, "feed_item_id", $item->getId());
307  $this->tpl->setCurrentBlock("feed_link");
308  $this->tpl->setVariable("VAL_TITLE", $item->getTitle());
309  $this->tpl->setVariable("HREF_SHOW",
310  $ilCtrl->getLinkTarget($this, "showFeedItem"));
311  $ilCtrl->setParameter($this, "feed_item_id", "");
312  $this->tpl->parseCurrentBlock();
313  }
314  }
315 
319  function getOverview()
320  {
321  global $ilUser, $lng, $ilCtrl;
322 
323  $this->setEnableNumInfo(false);
324  return '<div class="small">'.((int) count($this->getData()))." ".$lng->txt("feed_feed_items")."</div>";
325  }
326 
330  function showFeedItem()
331  {
332  global $lng, $ilCtrl;
333 
334  include_once("./Services/News/classes/class.ilNewsItem.php");
335 
336  $this->feed->fetch();
337  foreach($this->feed->getItems() as $item)
338  {
339  if ($item->getId() == $_GET["feed_item_id"])
340  {
341  $c_item = $item;
342  break;
343  }
344  }
345 
346  $tpl = new ilTemplate("tpl.show_feed_item.html", true, true, "Services/Feeds");
347 
348  if (is_object($c_item))
349  {
350  if (trim($c_item->getSummary()) != "") // summary
351  {
352  $tpl->setCurrentBlock("content");
353  $tpl->setVariable("VAL_CONTENT", $c_item->getSummary());
354  $tpl->parseCurrentBlock();
355  }
356  if (trim($c_item->getDate()) != "" || trim($c_item->getAuthor()) != "") // date
357  {
358  $tpl->setCurrentBlock("date_author");
359  if (trim($c_item->getAuthor()) != "")
360  {
361  $tpl->setVariable("VAL_AUTHOR", $c_item->getAuthor()." - ");
362  }
363  $tpl->setVariable("VAL_DATE", $c_item->getDate());
364  $tpl->parseCurrentBlock();
365  }
366 
367  if (trim($c_item->getLink()) != "") // link
368  {
369  $tpl->setCurrentBlock("plink");
370  $tpl->setVariable("HREF_LINK", $c_item->getLink());
371  $tpl->setVariable("TXT_LINK", $lng->txt("feed_open_source_page"));
372  $tpl->parseCurrentBlock();
373  }
374  $tpl->setVariable("VAL_TITLE", $c_item->getTitle()); // title
375  }
376 
377  include_once("./Services/PersonalDesktop/classes/class.ilPDContentBlockGUI.php");
378  $content_block = new ilPDContentBlockGUI();
379  $content_block->setContent($tpl->get());
380  $content_block->setTitle($this->getTitle());
381  $content_block->setImage(ilUtil::getImagePath("icon_feed.gif"));
382  $content_block->addHeaderCommand($ilCtrl->getParentReturn($this),
383  $lng->txt("close"), true);
384 
385  return $content_block->getHTML();
386  }
387 
391  function create()
392  {
393  return $this->createFeedBlock();
394  }
395 
402  public function initFormFeedBlock($a_mode)
403  {
404  global $lng;
405 
406  $lng->loadLanguageModule("block");
407 
408  include("Services/Form/classes/class.ilPropertyFormGUI.php");
409 
410  $this->form_gui = new ilPropertyFormGUI();
411 
412  // Property Title
413  $text_input = new ilTextInputGUI($lng->txt("block_feed_block_title"), "block_title");
414  $text_input->setInfo("");
415  $text_input->setRequired(true);
416  $text_input->setMaxLength(200);
417  $this->form_gui->addItem($text_input);
418 
419  // Property FeedUrl
420  $text_input = new ilFeedUrlInputGUI($lng->txt("block_feed_block_feed_url"), "block_feed_url");
421  $text_input->setInfo($lng->txt("block_feed_block_feed_url_info"));
422  $text_input->setRequired(true);
423  $text_input->setMaxLength(250);
424  $this->form_gui->addItem($text_input);
425 
426 
427  // save and cancel commands
428  if (in_array($a_mode, array(IL_FORM_CREATE,IL_FORM_RE_CREATE)))
429  {
430  $this->form_gui->addCommandButton("saveFeedBlock", $lng->txt("save"));
431  $this->form_gui->addCommandButton("cancelSaveFeedBlock", $lng->txt("cancel"));
432  }
433  else
434  {
435  $this->form_gui->addCommandButton("updateFeedBlock", $lng->txt("save"));
436  $this->form_gui->addCommandButton("cancelUpdateFeedBlock", $lng->txt("cancel"));
437  }
438 
439  $this->form_gui->setTitle($lng->txt("block_feed_block_head"));
440  $this->form_gui->setFormAction($this->ctrl->getFormAction($this));
441 
442  $this->prepareFormFeedBlock($this->form_gui);
443 
444  }
445 
451  public function prepareSaveFeedBlock(&$a_feed_block)
452  {
453  global $ilCtrl;
454 
455  $ref_id = $this->getGuiObject()->save($a_feed_block);
456  $a_feed_block->setType($this->getBlockType());
457  //$a_feed_block->setContextObjId($ilCtrl->getContextObjId());
458  //$a_feed_block->setContextObjType($ilCtrl->getContextObjType());
459  }
460 
465  public function exitSaveFeedBlock()
466  {
467  global $ilCtrl;
468 
469  $this->getGuiObject()->exitSave();
470  }
471 
476  public function cancelUpdateFeedBlock()
477  {
478  global $ilCtrl;
479 
480  $this->getGuiObject()->cancelUpdate();
481  }
482 
487  public function exitUpdateFeedBlock()
488  {
489  global $ilCtrl;
490 
491  $this->getGuiObject()->update($this->external_feed_block);
492  }
493 
497 /*
498  function confirmDeleteFeedBlock()
499  {
500  global $ilCtrl, $lng;
501 
502  include_once("Services/Utilities/classes/class.ilConfirmationGUI.php");
503  $c_gui = new ilConfirmationGUI();
504 
505  // set confirm/cancel commands
506  $c_gui->setFormAction($ilCtrl->getFormAction($this, "deleteFeedBlock"));
507  $c_gui->setHeaderText($lng->txt("info_delete_sure"));
508  $c_gui->setCancel($lng->txt("cancel"), "exitDeleteFeedBlock");
509  $c_gui->setConfirm($lng->txt("confirm"), "deleteFeedBlock");
510 
511  // add items to delete
512  $c_gui->addItem("external_feed_block_id",
513  $this->feed_block->getId(), $this->feed_block->getTitle(),
514  ilUtil::getImagePath("icon_feed.gif"));
515 
516  return $c_gui->getHTML();
517  }
518 */
519 
523 /*
524  function exitDeleteFeedBlock()
525  {
526  global $ilCtrl;
527 
528  $ilCtrl->returnToParent($this);
529  }
530 */
531 
535 /*
536  function deleteFeedBlock()
537  {
538  global $ilCtrl;
539 
540  $this->feed_block->delete();
541  $ilCtrl->returnToParent($this);
542  }
543 */
544 
545 }
546 
547 ?>