ILIAS  Release_4_0_x_branch Revision 61816
 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  if ($_SESSION["il_feed_js"] != "n" &&
222  ($ilUser->getPref("il_feed_js") != "n" || $_SESSION["il_feed_js"] == "y"))
223  {
224  // do not get feed dynamically, if cache hit is given.
225  if (!$this->feed->checkCacheHit())
226  {
227  return true;
228  }
229  }
230  }
231 
232  return false;
233  }
234 
235  function getDynamicReload()
236  {
237  global $ilCtrl, $lng;
238 
239  $ilCtrl->setParameterByClass("ilcolumngui", "block_id",
240  "block_pdfeed_".$this->getBlockId());
241 
242  $rel_tpl = new ilTemplate("tpl.dynamic_reload.html", true, true, "Services/Feeds");
243  $rel_tpl->setVariable("TXT_LOADING", $lng->txt("feed_loading_feed"));
244  $rel_tpl->setVariable("BLOCK_ID", "block_pdfeed_".$this->getBlockId());
245  $rel_tpl->setVariable("TARGET",
246  $ilCtrl->getLinkTargetByClass("ilcolumngui", "updateBlock", "", true));
247 
248  // no JS
249  $rel_tpl->setVariable("TXT_FEED_CLICK_HERE", $lng->txt("feed_no_js_click_here"));
250  $rel_tpl->setVariable("TARGET_NO_JS",
251  $ilCtrl->getLinkTargetByClass("ilpdexternalfeedblockgui", "disableJS"));
252 
253  return $rel_tpl->get();
254  }
255 
256  function getJSEnabler()
257  {
258  global $ilCtrl, $lng;
259 
260  $ilCtrl->setParameterByClass("ilcolumngui", "block_id",
261  "block_pdfeed_".$this->getBlockId());
262 
263  $rel_tpl = new ilTemplate("tpl.js_enabler.html", true, true, "Services/Feeds");
264  $rel_tpl->setVariable("BLOCK_ID", "block_pdfeed_".$this->getBlockId());
265  $rel_tpl->setVariable("TARGET",
266  $ilCtrl->getLinkTargetByClass("ilpdexternalfeedblockgui", "enableJS", true));
267 
268  return $rel_tpl->get();
269  }
270 
271 
272  function disableJS()
273  {
274  global $ilCtrl, $ilUser;
275 
276  $_SESSION["il_feed_js"] = "n";
277  $ilUser->writePref("il_feed_js", "n");
278  $ilCtrl->redirectByClass("ilpersonaldesktopgui", "show");
279  }
280 
281  function enableJS()
282  {
283  global $ilUser;
284 
285  $_SESSION["il_feed_js"] = "y";
286  $ilUser->writePref("il_feed_js", "y");
287  echo $this->getHTML();
288  exit;
289  }
290 
294  function fillRow($item)
295  {
296  global $ilUser, $ilCtrl, $lng;
297 
298  $ilCtrl->setParameter($this, "feed_item_id", $item->getId());
299  $this->tpl->setVariable("VAL_TITLE", $item->getTitle());
300  $this->tpl->setVariable("HREF_SHOW",
301  $ilCtrl->getLinkTarget($this, "showFeedItem"));
302  $ilCtrl->setParameter($this, "feed_item_id", "");
303  }
304 
308  function getOverview()
309  {
310  global $ilUser, $lng, $ilCtrl;
311 
312  $this->setEnableNumInfo(false);
313  return '<div class="small">'.((int) count($this->getData()))." ".$lng->txt("feed_feed_items")."</div>";
314  }
315 
319  function showFeedItem()
320  {
321  global $lng, $ilCtrl;
322 
323  include_once("./Services/News/classes/class.ilNewsItem.php");
324 
325  $this->feed->fetch();
326  foreach($this->feed->getItems() as $item)
327  {
328  if ($item->getId() == $_GET["feed_item_id"])
329  {
330  $c_item = $item;
331  break;
332  }
333  }
334 
335  $tpl = new ilTemplate("tpl.show_feed_item.html", true, true, "Services/Feeds");
336 
337  if (is_object($c_item))
338  {
339  if (trim($c_item->getSummary()) != "") // summary
340  {
341  $tpl->setCurrentBlock("content");
342  $tpl->setVariable("VAL_CONTENT", $c_item->getSummary());
343  $tpl->parseCurrentBlock();
344  }
345  if (trim($c_item->getDate()) != "" || trim($c_item->getAuthor()) != "") // date
346  {
347  $tpl->setCurrentBlock("date_author");
348  if (trim($c_item->getAuthor()) != "")
349  {
350  $tpl->setVariable("VAL_AUTHOR", $c_item->getAuthor()." - ");
351  }
352  $tpl->setVariable("VAL_DATE", $c_item->getDate());
353  $tpl->parseCurrentBlock();
354  }
355 
356  if (trim($c_item->getLink()) != "") // link
357  {
358  $tpl->setCurrentBlock("plink");
359  $tpl->setVariable("HREF_LINK", $c_item->getLink());
360  $tpl->setVariable("TXT_LINK", $lng->txt("feed_open_source_page"));
361  $tpl->parseCurrentBlock();
362  }
363  $tpl->setVariable("VAL_TITLE", $c_item->getTitle()); // title
364  }
365 
366  include_once("./Services/PersonalDesktop/classes/class.ilPDContentBlockGUI.php");
367  $content_block = new ilPDContentBlockGUI();
368  $content_block->setContent($tpl->get());
369  $content_block->setTitle($this->getTitle());
370  $content_block->setImage(ilUtil::getImagePath("icon_feed.gif"));
371  $content_block->addHeaderCommand($ilCtrl->getParentReturn($this),
372  $lng->txt("selected_items_back"));
373 
374  return $content_block->getHTML();
375  }
376 
380  function create()
381  {
382  return $this->createFeedBlock();
383  }
384 
391  public function initFormFeedBlock($a_mode)
392  {
393  global $lng;
394 
395  $lng->loadLanguageModule("block");
396 
397  include("Services/Form/classes/class.ilPropertyFormGUI.php");
398 
399  $this->form_gui = new ilPropertyFormGUI();
400 
401  // Property Title
402  $text_input = new ilTextInputGUI($lng->txt("block_feed_block_title"), "block_title");
403  $text_input->setInfo("");
404  $text_input->setRequired(true);
405  $text_input->setMaxLength(200);
406  $this->form_gui->addItem($text_input);
407 
408  // Property FeedUrl
409  $text_input = new ilFeedUrlInputGUI($lng->txt("block_feed_block_feed_url"), "block_feed_url");
410  $text_input->setInfo($lng->txt("block_feed_block_feed_url_info"));
411  $text_input->setRequired(true);
412  $text_input->setMaxLength(250);
413  $this->form_gui->addItem($text_input);
414 
415 
416  // save and cancel commands
417  if (in_array($a_mode, array(IL_FORM_CREATE,IL_FORM_RE_CREATE)))
418  {
419  $this->form_gui->addCommandButton("saveFeedBlock", $lng->txt("save"));
420  $this->form_gui->addCommandButton("cancelSaveFeedBlock", $lng->txt("cancel"));
421  }
422  else
423  {
424  $this->form_gui->addCommandButton("updateFeedBlock", $lng->txt("save"));
425  $this->form_gui->addCommandButton("cancelUpdateFeedBlock", $lng->txt("cancel"));
426  }
427 
428  $this->form_gui->setTitle($lng->txt("block_feed_block_head"));
429  $this->form_gui->setFormAction($this->ctrl->getFormAction($this));
430 
431  $this->prepareFormFeedBlock($this->form_gui);
432 
433  }
434 
440  public function prepareSaveFeedBlock(&$a_feed_block)
441  {
442  global $ilCtrl;
443 
444  $a_feed_block->setContextObjId($ilCtrl->getContextObjId());
445  $a_feed_block->setContextObjType($ilCtrl->getContextObjType());
446  $a_feed_block->setType("pdfeed");
447  }
448 
453  {
454  global $ilCtrl, $lng;
455 
456  include_once("Services/Utilities/classes/class.ilConfirmationGUI.php");
457  $c_gui = new ilConfirmationGUI();
458 
459  // set confirm/cancel commands
460  $c_gui->setFormAction($ilCtrl->getFormAction($this, "deleteFeedBlock"));
461  $c_gui->setHeaderText($lng->txt("info_delete_sure"));
462  $c_gui->setCancel($lng->txt("cancel"), "exitDeleteFeedBlock");
463  $c_gui->setConfirm($lng->txt("confirm"), "deleteFeedBlock");
464 
465  // add items to delete
466  $c_gui->addItem("external_feed_block_id",
467  $this->feed_block->getId(), $this->feed_block->getTitle(),
468  ilUtil::getImagePath("icon_feed.gif"));
469 
470  return $c_gui->getHTML();
471  }
472 
477  {
478  global $ilCtrl;
479 
480  $ilCtrl->returnToParent($this);
481  }
482 
486  function deleteFeedBlock()
487  {
488  global $ilCtrl;
489 
490  $this->feed_block->delete();
491  $ilCtrl->returnToParent($this);
492  }
493 }
494 
495 ?>