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