00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 include_once("./Services/Block/classes/class.ilBlockGUI.php");
00025 include_once("./Services/Block/classes/class.ilExternalFeedBlockGUIGen.php");
00026 include_once("./Services/Feeds/classes/class.ilExternalFeed.php");
00027
00039 class ilExternalFeedBlockGUI extends ilExternalFeedBlockGUIGen
00040 {
00041 static $block_type = "feed";
00042
00046 function ilExternalFeedBlockGUI()
00047 {
00048 global $ilCtrl, $lng;
00049
00050 parent::__construct();
00051 parent::ilBlockGUI();
00052
00053 $this->setImage(ilUtil::getImagePath("icon_feed_s.gif"));
00054
00055 $lng->loadLanguageModule("feed");
00056 $this->setLimit(5);
00057 $this->setRowTemplate("tpl.block_external_feed_row.html", "Services/Feeds");
00058 }
00059
00065 static function getBlockType()
00066 {
00067 return self::$block_type;
00068 }
00069
00075 static function isRepositoryObject()
00076 {
00077 return true;
00078 }
00079
00083 static function getScreenMode()
00084 {
00085 global $ilCtrl;
00086
00087 switch($ilCtrl->getCmd())
00088 {
00089 case "create":
00090 case "edit":
00091 case "saveFeedBlock":
00092 case "updateFeedBlock":
00093 case "editFeedBlock":
00094 case "showFeedItem":
00095 case "confirmDeleteFeedBlock":
00096 return IL_SCREEN_CENTER;
00097 break;
00098
00099 default:
00100 return IL_SCREEN_SIDE;
00101 break;
00102 }
00103 }
00104
00108 function setBlock($a_block)
00109 {
00110 global $ilCtrl;
00111
00112
00113 $this->feed_block = $a_block;
00114 $this->setTitle($this->feed_block->getTitle());
00115 $this->setBlockId($this->feed_block->getId());
00116
00117
00118 include_once("./Services/Feeds/classes/class.ilExternalFeed.php");
00119 $this->feed = new ilExternalFeed();
00120 $this->feed->setUrl($this->feed_block->getFeedUrl());
00121
00122
00123 $this->setAvailableDetailLevels(2);
00124
00125 $ilCtrl->setParameter($this, "block_id", $this->feed_block->getId());
00126 }
00127
00131 function &executeCommand()
00132 {
00133 global $ilCtrl;
00134
00135 $next_class = $ilCtrl->getNextClass();
00136 $cmd = $ilCtrl->getCmd("getHTML");
00137
00138 switch ($next_class)
00139 {
00140 default:
00141 return $this->$cmd();
00142 }
00143 }
00144
00148 function fillDataSection()
00149 {
00150 if ($this->getDynamic())
00151 {
00152 $this->setDataSection($this->getDynamicReload());
00153 }
00154 else if ($this->getCurrentDetailLevel() > 1 && count($this->getData()) > 0)
00155 {
00156 parent::fillDataSection();
00157 }
00158 else
00159 {
00160 $this->setDataSection($this->getOverview());
00161 }
00162 }
00163
00167 function getHTML()
00168 {
00169 global $ilCtrl, $lng, $ilUser, $ilAccess, $ilSetting;
00170
00171 if ($this->getCurrentDetailLevel() == 0)
00172 {
00173 return "";
00174 }
00175
00176 $feed_set = new ilSetting("feed");
00177
00178 if ($feed_set->get("disable_rep_feeds"))
00179 {
00180 return "";
00181 }
00182
00183
00184 if (!$this->getDynamic())
00185 {
00186 $this->feed->fetch();
00187 $this->setData($this->feed->getItems());
00188 }
00189
00190
00191 $this->setData($this->feed->getItems());
00192
00193 if ($ilAccess->checkAccess("write", "", $this->getRefId()))
00194 {
00195 $ilCtrl->setParameterByClass("ilobjexternalfeedgui",
00196 "ref_id", $this->getRefId());
00197 $ilCtrl->setParameter($this, "external_feed_block_id", $this->getBlockId());
00198 $this->addBlockCommand(
00199 $ilCtrl->getLinkTargetByClass(array("ilrepositorygui", "ilobjexternalfeedgui",
00200 "ilexternalfeedblockgui"),
00201 "editFeedBlock"),
00202 $lng->txt("edit"));
00203 $ilCtrl->clearParametersByClass("ilobjexternalfeedgui");
00204 }
00205
00206
00207 $add = "";
00208 if ($_SESSION["il_feed_js"] == "n" ||
00209 ($ilUser->getPref("il_feed_js") == "n" && $_SESSION["il_feed_js"] != "y"))
00210 {
00211 $add = $this->getJSEnabler();
00212 }
00213
00214 return parent::getHTML().$add;
00215 }
00216
00217 function getDynamic()
00218 {
00219 global $ilCtrl, $ilUser;
00220
00221 if ($ilCtrl->getCmdClass() != "ilcolumngui" && $ilCtrl->getCmd() != "enableJS")
00222 {
00223 if ($_SESSION["il_feed_js"] != "n" &&
00224 ($ilUser->getPref("il_feed_js") != "n" || $_SESSION["il_feed_js"] == "y"))
00225 {
00226
00227 if (!$this->feed->checkCacheHit())
00228 {
00229 return true;
00230 }
00231 }
00232 }
00233
00234 return false;
00235 }
00236
00237 function getDynamicReload()
00238 {
00239 global $ilCtrl, $lng;
00240
00241 $ilCtrl->setParameterByClass("ilcolumngui", "block_id",
00242 "block_feed_".$this->getBlockId());
00243
00244 $rel_tpl = new ilTemplate("tpl.dynamic_reload.html", true, true, "Services/Feeds");
00245 $rel_tpl->setVariable("TXT_LOADING", $lng->txt("feed_loading_feed"));
00246 $rel_tpl->setVariable("BLOCK_ID", "block_feed_".$this->getBlockId());
00247 $rel_tpl->setVariable("TARGET",
00248 $ilCtrl->getLinkTargetByClass("ilcolumngui", "updateBlock", "", true));
00249
00250
00251 $rel_tpl->setVariable("TXT_FEED_CLICK_HERE", $lng->txt("feed_no_js_click_here"));
00252 $rel_tpl->setVariable("TARGET_NO_JS",
00253 $ilCtrl->getLinkTargetByClass("ilexternalfeedblockgui", "disableJS"));
00254
00255 return $rel_tpl->get();
00256 }
00257
00258 function getJSEnabler()
00259 {
00260 global $ilCtrl, $lng;
00261
00262 $ilCtrl->setParameterByClass("ilcolumngui", "block_id",
00263 "block_feed_".$this->getBlockId());
00264
00265 $rel_tpl = new ilTemplate("tpl.js_enabler.html", true, true, "Services/Feeds");
00266 $rel_tpl->setVariable("BLOCK_ID", "block_feed_".$this->getBlockId());
00267 $rel_tpl->setVariable("TARGET",
00268 $ilCtrl->getLinkTargetByClass("ilexternalfeedblockgui", "enableJS", true));
00269
00270 return $rel_tpl->get();
00271 }
00272
00273
00274 function disableJS()
00275 {
00276 global $ilCtrl, $ilUser;
00277
00278 $_SESSION["il_feed_js"] = "n";
00279 $ilUser->writePref("il_feed_js", "n");
00280 $ilCtrl->returnToParent($this);
00281 }
00282
00283 function enableJS()
00284 {
00285 global $ilUser;
00286
00287 $_SESSION["il_feed_js"] = "y";
00288 $ilUser->writePref("il_feed_js", "y");
00289 echo $this->getHTML();
00290 exit;
00291 }
00292
00296 function fillRow($item)
00297 {
00298 global $ilUser, $ilCtrl, $lng, $ilAccess;
00299
00300 if ($this->isRepositoryObject() && !$ilAccess->checkAccess("read", "", $this->getRefId()))
00301 {
00302 $this->tpl->setVariable("TXT_TITLE", $item->getTitle());
00303 }
00304 else
00305 {
00306 $ilCtrl->setParameter($this, "feed_item_id", $item->getId());
00307 $this->tpl->setCurrentBlock("feed_link");
00308 $this->tpl->setVariable("VAL_TITLE", $item->getTitle());
00309 $this->tpl->setVariable("HREF_SHOW",
00310 $ilCtrl->getLinkTarget($this, "showFeedItem"));
00311 $ilCtrl->setParameter($this, "feed_item_id", "");
00312 $this->tpl->parseCurrentBlock();
00313 }
00314 }
00315
00319 function getOverview()
00320 {
00321 global $ilUser, $lng, $ilCtrl;
00322
00323 $this->setEnableNumInfo(false);
00324 return '<div class="small">'.((int) count($this->getData()))." ".$lng->txt("feed_feed_items")."</div>";
00325 }
00326
00330 function showFeedItem()
00331 {
00332 global $lng, $ilCtrl;
00333
00334 include_once("./Services/News/classes/class.ilNewsItem.php");
00335
00336 $this->feed->fetch();
00337 foreach($this->feed->getItems() as $item)
00338 {
00339 if ($item->getId() == $_GET["feed_item_id"])
00340 {
00341 $c_item = $item;
00342 break;
00343 }
00344 }
00345
00346 $tpl = new ilTemplate("tpl.show_feed_item.html", true, true, "Services/Feeds");
00347
00348 if (is_object($c_item))
00349 {
00350 if (trim($c_item->getSummary()) != "")
00351 {
00352 $tpl->setCurrentBlock("content");
00353 $tpl->setVariable("VAL_CONTENT", $c_item->getSummary());
00354 $tpl->parseCurrentBlock();
00355 }
00356 if (trim($c_item->getDate()) != "" || trim($c_item->getAuthor()) != "")
00357 {
00358 $tpl->setCurrentBlock("date_author");
00359 if (trim($c_item->getAuthor()) != "")
00360 {
00361 $tpl->setVariable("VAL_AUTHOR", $c_item->getAuthor()." - ");
00362 }
00363 $tpl->setVariable("VAL_DATE", $c_item->getDate());
00364 $tpl->parseCurrentBlock();
00365 }
00366
00367 if (trim($c_item->getLink()) != "")
00368 {
00369 $tpl->setCurrentBlock("plink");
00370 $tpl->setVariable("HREF_LINK", $c_item->getLink());
00371 $tpl->setVariable("TXT_LINK", $lng->txt("feed_open_source_page"));
00372 $tpl->parseCurrentBlock();
00373 }
00374 $tpl->setVariable("VAL_TITLE", $c_item->getTitle());
00375 }
00376
00377 include_once("./Services/PersonalDesktop/classes/class.ilPDContentBlockGUI.php");
00378 $content_block = new ilPDContentBlockGUI();
00379 $content_block->setContent($tpl->get());
00380 $content_block->setTitle($this->getTitle());
00381 $content_block->setImage(ilUtil::getImagePath("icon_feed.gif"));
00382 $content_block->addHeaderCommand($ilCtrl->getParentReturn($this),
00383 $lng->txt("close"), true);
00384
00385 return $content_block->getHTML();
00386 }
00387
00391 function create()
00392 {
00393 return $this->createFeedBlock();
00394 }
00395
00402 public function initFormFeedBlock($a_mode)
00403 {
00404 global $lng;
00405
00406 $lng->loadLanguageModule("block");
00407
00408 include("Services/Form/classes/class.ilPropertyFormGUI.php");
00409
00410 $this->form_gui = new ilPropertyFormGUI();
00411
00412
00413 $text_input = new ilTextInputGUI($lng->txt("block_feed_block_title"), "block_title");
00414 $text_input->setInfo("");
00415 $text_input->setRequired(true);
00416 $text_input->setMaxLength(200);
00417 $this->form_gui->addItem($text_input);
00418
00419
00420 $text_input = new ilFeedUrlInputGUI($lng->txt("block_feed_block_feed_url"), "block_feed_url");
00421 $text_input->setInfo($lng->txt("block_feed_block_feed_url_info"));
00422 $text_input->setRequired(true);
00423 $text_input->setMaxLength(250);
00424 $this->form_gui->addItem($text_input);
00425
00426
00427
00428 if (in_array($a_mode, array(IL_FORM_CREATE,IL_FORM_RE_CREATE)))
00429 {
00430 $this->form_gui->addCommandButton("saveFeedBlock", $lng->txt("save"));
00431 $this->form_gui->addCommandButton("cancelSaveFeedBlock", $lng->txt("cancel"));
00432 }
00433 else
00434 {
00435 $this->form_gui->addCommandButton("updateFeedBlock", $lng->txt("save"));
00436 $this->form_gui->addCommandButton("cancelUpdateFeedBlock", $lng->txt("cancel"));
00437 }
00438
00439 $this->form_gui->setTitle($lng->txt("block_feed_block_head"));
00440 $this->form_gui->setFormAction($this->ctrl->getFormAction($this));
00441
00442 $this->prepareFormFeedBlock($this->form_gui);
00443
00444 }
00445
00451 public function prepareSaveFeedBlock(&$a_feed_block)
00452 {
00453 global $ilCtrl;
00454
00455 $ref_id = $this->getGuiObject()->save($a_feed_block);
00456 $a_feed_block->setType($this->getBlockType());
00457
00458
00459 }
00460
00465 public function exitSaveFeedBlock()
00466 {
00467 global $ilCtrl;
00468
00469 $this->getGuiObject()->exitSave();
00470 }
00471
00476 public function cancelUpdateFeedBlock()
00477 {
00478 global $ilCtrl;
00479
00480 $this->getGuiObject()->cancelUpdate();
00481 }
00482
00487 public function exitUpdateFeedBlock()
00488 {
00489 global $ilCtrl;
00490
00491 $this->getGuiObject()->update($this->external_feed_block);
00492 }
00493
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00523
00524
00525
00526
00527
00528
00529
00530
00531
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545 }
00546
00547 ?>