ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 {
25  protected $settings;
26 
30  protected $rbacsystem;
31 
35  protected $obj_definition;
36 
37  public static $block_type = "feed";
38 
42  public function __construct()
43  {
44  global $DIC;
45 
46  $this->ctrl = $DIC->ctrl();
47  $this->lng = $DIC->language();
48  $this->user = $DIC->user();
49  $this->access = $DIC->access();
50  $this->settings = $DIC->settings();
51  $this->rbacsystem = $DIC->rbac()->system();
52  $this->obj_definition = $DIC["objDefinition"];
53  $lng = $DIC->language();
54 
55  parent::__construct();
56 
57  $lng->loadLanguageModule("feed");
58  $this->setLimit(5);
59  $this->setRowTemplate("tpl.block_external_feed_row.html", "Services/Feeds");
60  }
61 
67  public static function getBlockType()
68  {
69  return self::$block_type;
70  }
71 
77  public static function isRepositoryObject()
78  {
79  return true;
80  }
81 
85  public static function getScreenMode()
86  {
87  global $DIC;
88 
89  $ilCtrl = $DIC->ctrl();
90 
91  switch ($ilCtrl->getCmd()) {
92  case "create":
93  case "edit":
94  case "saveFeedBlock":
95  case "updateFeedBlock":
96  case "editFeedBlock":
97  case "showFeedItem":
98  case "confirmDeleteFeedBlock":
99  return IL_SCREEN_CENTER;
100  break;
101 
102  default:
103  return IL_SCREEN_SIDE;
104  break;
105  }
106  }
107 
111  public function setBlock($a_block)
112  {
114 
115  // init block
116  $this->feed_block = $a_block;
117  $this->setTitle($this->feed_block->getTitle());
118  $this->setBlockId($this->feed_block->getId());
119 
120  // get feed object
121  include_once("./Services/Feeds/classes/class.ilExternalFeed.php");
122  $this->feed = new ilExternalFeed();
123  $this->feed->setUrl($this->feed_block->getFeedUrl());
124 
125  // init details
126  $this->setAvailableDetailLevels(2);
127 
128  $ilCtrl->setParameter($this, "block_id", $this->feed_block->getId());
129  }
130 
134  public function executeCommand()
135  {
137 
138  $next_class = $ilCtrl->getNextClass();
139  $cmd = $ilCtrl->getCmd("getHTML");
140  switch ($next_class) {
141  default:
142  return $this->$cmd();
143  }
144  }
145 
149  public function fillDataSection()
150  {
151  if ($this->getDynamic()) {
152  $this->setDataSection($this->getDynamicReload());
153  } elseif ($this->getCurrentDetailLevel() > 1 && count($this->getData()) > 0) {
154  parent::fillDataSection();
155  } else {
156  $this->setDataSection($this->getOverview());
157  }
158  }
159 
163  public function getHTML()
164  {
166  $lng = $this->lng;
168  $ilAccess = $this->access;
170 
171  if ($this->getCurrentDetailLevel() == 0) {
172  return "";
173  }
174 
175  $feed_set = new ilSetting("feed");
176 
177  if ($feed_set->get("disable_rep_feeds")) {
178  return "";
179  }
180 
181  // if no dynamic reload
182  if (!$this->getDynamic()) {
183  $this->feed->fetch();
184  $this->setData($this->feed->getItems());
185  }
186 
187  //$this->setTitle($this->feed->getChannelTitle());
188  $this->setData($this->feed->getItems());
189 
190  if ($ilAccess->checkAccess("write", "", $this->getRefId())) {
191  $ilCtrl->setParameterByClass(
192  "ilobjexternalfeedgui",
193  "ref_id",
194  $this->getRefId()
195  );
196  $ilCtrl->setParameter($this, "external_feed_block_id", $this->getBlockId());
197  $this->addBlockCommand(
198  $ilCtrl->getLinkTargetByClass(
199  array("ilrepositorygui", "ilobjexternalfeedgui",
200  "ilexternalfeedblockgui"),
201  "editFeedBlock"
202  ),
203  $lng->txt("settings")
204  );
205  $ilCtrl->clearParametersByClass("ilobjexternalfeedgui");
206  }
207 
208  // JS enabler
209  $add = "";
210  if ($_SESSION["il_feed_js"] == "n" ||
211  ($ilUser->getPref("il_feed_js") == "n" && $_SESSION["il_feed_js"] != "y")) {
212  $add = $this->getJSEnabler();
213  }
214 
215  return parent::getHTML() . $add;
216  }
217 
218  public function getDynamic()
219  {
222 
223  if ($ilCtrl->getCmdClass() != "ilcolumngui" && $ilCtrl->getCmd() != "enableJS") {
224  if ($_SESSION["il_feed_js"] != "n" &&
225  ($ilUser->getPref("il_feed_js") != "n" || $_SESSION["il_feed_js"] == "y")) {
226  // do not get feed dynamically, if cache hit is given.
227  if (!$this->feed->checkCacheHit()) {
228  return true;
229  }
230  }
231  }
232 
233  return false;
234  }
235 
236  public function getDynamicReload()
237  {
239  $lng = $this->lng;
240 
241  $ilCtrl->setParameterByClass(
242  "ilcolumngui",
243  "block_id",
244  "block_feed_" . $this->getBlockId()
245  );
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_feed_" . $this->getBlockId());
250  $rel_tpl->setVariable(
251  "TARGET",
252  $ilCtrl->getLinkTargetByClass("ilcolumngui", "updateBlock", "", true)
253  );
254 
255  // no JS
256  $rel_tpl->setVariable("TXT_FEED_CLICK_HERE", $lng->txt("feed_no_js_click_here"));
257  $rel_tpl->setVariable(
258  "TARGET_NO_JS",
259  $ilCtrl->getLinkTargetByClass("ilexternalfeedblockgui", "disableJS")
260  );
261 
262  return $rel_tpl->get();
263  }
264 
265  public function getJSEnabler()
266  {
268  $lng = $this->lng;
269 
270  $ilCtrl->setParameterByClass(
271  "ilcolumngui",
272  "block_id",
273  "block_feed_" . $this->getBlockId()
274  );
275 
276  $rel_tpl = new ilTemplate("tpl.js_enabler.html", true, true, "Services/Feeds");
277  $rel_tpl->setVariable("BLOCK_ID", "block_feed_" . $this->getBlockId());
278  $rel_tpl->setVariable(
279  "TARGET",
280  $ilCtrl->getLinkTargetByClass("ilexternalfeedblockgui", "enableJS", true, "", false)
281  );
282 
283  return $rel_tpl->get();
284  }
285 
286 
287  public function disableJS()
288  {
291 
292  $_SESSION["il_feed_js"] = "n";
293  $ilUser->writePref("il_feed_js", "n");
294  $ilCtrl->returnToParent($this);
295  }
296 
297  public function enableJS()
298  {
300 
301  $_SESSION["il_feed_js"] = "y";
302  $ilUser->writePref("il_feed_js", "y");
303  echo $this->getHTML();
304  exit;
305  }
306 
310  public function fillRow($item)
311  {
313  $ilAccess = $this->access;
314 
315  if ($this->isRepositoryObject() && !$ilAccess->checkAccess("read", "", $this->getRefId())) {
316  $this->tpl->setVariable("TXT_TITLE", $item->getTitle());
317  } else {
318  $ilCtrl->setParameter($this, "feed_item_id", $item->getId());
319  $this->tpl->setCurrentBlock("feed_link");
320  $this->tpl->setVariable("VAL_TITLE", $item->getTitle());
321  $this->tpl->setVariable(
322  "HREF_SHOW",
323  $ilCtrl->getLinkTarget($this, "showFeedItem")
324  );
325  $ilCtrl->setParameter($this, "feed_item_id", "");
326  $this->tpl->parseCurrentBlock();
327  }
328  }
329 
333  public function getOverview()
334  {
336  $lng = $this->lng;
338 
339  $this->setEnableNumInfo(false);
340  return '<div class="small">' . ((int) count($this->getData())) . " " . $lng->txt("feed_feed_items") . "</div>";
341  }
342 
346  public function showFeedItem()
347  {
348  $lng = $this->lng;
350 
351  include_once("./Services/News/classes/class.ilNewsItem.php");
352 
353  $this->feed->fetch();
354  foreach ($this->feed->getItems() as $item) {
355  if ($item->getId() == $_GET["feed_item_id"]) {
356  $c_item = $item;
357  break;
358  }
359  }
360 
361  $tpl = new ilTemplate("tpl.show_feed_item.html", true, true, "Services/Feeds");
362 
363  if (is_object($c_item)) {
364  if (trim($c_item->getSummary()) != "") { // summary
365  $tpl->setCurrentBlock("content");
366  $tpl->setVariable("VAL_CONTENT", $c_item->getSummary());
367  $tpl->parseCurrentBlock();
368  }
369  if (trim($c_item->getDate()) != "" || trim($c_item->getAuthor()) != "") { // date
370  $tpl->setCurrentBlock("date_author");
371  if (trim($c_item->getAuthor()) != "") {
372  $tpl->setVariable("VAL_AUTHOR", $c_item->getAuthor() . " - ");
373  }
374  $tpl->setVariable("VAL_DATE", $c_item->getDate());
375  $tpl->parseCurrentBlock();
376  }
377 
378  if (trim($c_item->getLink()) != "") { // link
379  $tpl->setCurrentBlock("plink");
380  $tpl->setVariable("HREF_LINK", $c_item->getLink());
381  $tpl->setVariable("TXT_LINK", $lng->txt("feed_open_source_page"));
382  $tpl->parseCurrentBlock();
383  }
384  $tpl->setVariable("VAL_TITLE", $c_item->getTitle()); // title
385  }
386 
387  include_once("./Services/PersonalDesktop/classes/class.ilPDContentBlockGUI.php");
388  $content_block = new ilPDContentBlockGUI();
389  $content_block->setContent($tpl->get());
390  $content_block->setTitle($this->getTitle());
391  $content_block->setImage(ilUtil::getImagePath("icon_feed.svg"));
392  $content_block->addHeaderCommand(
393  $ilCtrl->getParentReturn($this),
394  $lng->txt("close"),
395  true
396  );
397 
398  return $content_block->getHTML();
399  }
400 
404  public function create()
405  {
406  $html1 = $this->createFeedBlock();
407 
408  $html2 = "";
409  if (DEVMODE == 1) {
410  $this->initImportForm("feed");
411  $html2 = "<br/>" . $this->form->getHTML();
412  }
413 
414  return $html1 . $html2;
415  }
416 
422  public function initImportForm($a_new_type = "")
423  {
424  $lng = $this->lng;
426 
427  $lng->loadLanguageModule("feed");
428 
429  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
430  $this->form = new ilPropertyFormGUI();
431  $this->form->setTarget("_top");
432 
433  // Import file
434  include_once("./Services/Form/classes/class.ilFileInputGUI.php");
435  $fi = new ilFileInputGUI($lng->txt("import_file"), "importfile");
436  $fi->setSuffixes(array("zip"));
437  $fi->setRequired(true);
438  $this->form->addItem($fi);
439 
440  $this->form->addCommandButton("importFile", $lng->txt("import"));
441  $this->form->addCommandButton("cancelSaveFeedBlock", $lng->txt("cancel"));
442  $this->form->setTitle($lng->txt($a_new_type . "_import"));
443 
444  $ilCtrl->setParameter($this, "new_type", $a_new_type);
445  $this->form->setFormAction($ilCtrl->getFormAction($this));
446  }
447 
453  public function importFile()
454  {
457  $lng = $this->lng;
458 
459  $new_type = $_POST["new_type"] ? $_POST["new_type"] : $_GET["new_type"];
460 
461  // create permission is already checked in createObject. This check here is done to prevent hacking attempts
462  if (!$rbacsystem->checkAccess("create", $_GET["ref_id"], $new_type)) {
463  $this->ilias->raiseError($this->lng->txt("no_create_permission"), $this->ilias->error_obj->MESSAGE);
464  }
465  $this->ctrl->setParameter($this, "new_type", $new_type);
466  $this->initImportForm($new_type);
467  if ($this->form->checkInput()) {
468  // todo: make some check on manifest file
469  include_once("./Services/Export/classes/class.ilImport.php");
470  $imp = new ilImport((int) $_GET['ref_id']);
471  $new_id = $imp->importObject(
472  $newObj,
473  $_FILES["importfile"]["tmp_name"],
474  $_FILES["importfile"]["name"],
475  $new_type
476  );
477 
478  // put new object id into tree
479  if ($new_id > 0) {
480  $newObj = ilObjectFactory::getInstanceByObjId($new_id);
481  $newObj->createReference();
482  $newObj->putInTree($_GET["ref_id"]);
483  $newObj->setPermissions($_GET["ref_id"]);
484  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
485  $this->exitSaveFeedBlock();
486  }
487  return;
488  }
489 
490  $this->form->setValuesByPost();
491  $tpl->setContent($this->form->getHtml());
492  }
493 
494 
501  public function initFormFeedBlock($a_mode)
502  {
503  $lng = $this->lng;
504 
505  $lng->loadLanguageModule("block");
506 
507  require_once("Services/Form/classes/class.ilPropertyFormGUI.php");
508 
509  $this->form_gui = new ilPropertyFormGUI();
510 
511  // Property Title
512  $text_input = new ilTextInputGUI($lng->txt("block_feed_block_title"), "block_title");
513  $text_input->setInfo("");
514  $text_input->setRequired(true);
515  $text_input->setMaxLength(200);
516  $this->form_gui->addItem($text_input);
517 
518  // Property FeedUrl
519  $text_input = new ilFeedUrlInputGUI($lng->txt("block_feed_block_feed_url"), "block_feed_url");
520  $text_input->setInfo($lng->txt("block_feed_block_feed_url_info"));
521  $text_input->setRequired(true);
522  $text_input->setMaxLength(250);
523  $this->form_gui->addItem($text_input);
524 
525 
526  // save and cancel commands
527  if (in_array($a_mode, array(IL_FORM_CREATE,IL_FORM_RE_CREATE))) {
528  $this->form_gui->addCommandButton("saveFeedBlock", $lng->txt("save"));
529  $this->form_gui->addCommandButton("cancelSaveFeedBlock", $lng->txt("cancel"));
530  } else {
531  $this->form_gui->addCommandButton("updateFeedBlock", $lng->txt("save"));
532  $this->form_gui->addCommandButton("cancelUpdateFeedBlock", $lng->txt("cancel"));
533  }
534 
535  $this->form_gui->setTitle($lng->txt("block_feed_block_head"));
536  $this->form_gui->setFormAction($this->ctrl->getFormAction($this));
537 
538  $this->prepareFormFeedBlock($this->form_gui);
539  }
540 
546  public function prepareSaveFeedBlock(&$a_feed_block)
547  {
548  $this->getGuiObject()->save($a_feed_block);
549  $a_feed_block->setType($this->getBlockType());
550  }
551 
556  public function exitSaveFeedBlock()
557  {
558  $this->getGuiObject()->exitSave();
559  }
560 
565  public function cancelUpdateFeedBlock()
566  {
567  $this->getGuiObject()->cancelUpdate();
568  }
569 
574  public function exitUpdateFeedBlock()
575  {
576  $this->getGuiObject()->update($this->external_feed_block);
577  }
578 }
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.
$_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.
global $DIC
Definition: saml.php:7
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.
static isRepositoryObject()
Get block type.
Import class.
setEnableNumInfo($a_enablenuminfo)
Set Enable Item Number Info.
user()
Definition: user.php:4
Handles external Feeds via Magpie library.
fillRow($item)
Fill feed item row.
GUI class for external news feed custom block.
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.
addBlockCommand( $a_href, $a_text, $a_target="", $a_img="", $a_right_aligned=false, $a_checked=false, $a_html="")
Add Block Command.
getData()
Get Data.
setLimit($a_limit)
Set Limit.
settings()
Definition: settings.php:2
getRefId()
Get Ref Id (only used if isRepositoryObject() is true).
BlockGUI class for external feed block.
global $ilSetting
Definition: privfeed.php:17
initFormFeedBlock($a_mode)
FORM FeedBlock: Init form.
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.