• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Services/Feeds/classes/class.ilPDExternalFeedBlockGUI.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2006 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
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 ilPDExternalFeedBlockGUI extends ilExternalFeedBlockGUIGen
00040 {
00041         static $block_type = "pdfeed";
00042         
00046         function ilPDExternalFeedBlockGUI()
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                 
00057                 $this->setLimit(5);
00058                 $this->setRowTemplate("tpl.block_external_feed_row.html", "Services/Feeds");
00059         }
00060                 
00066         static function getBlockType()
00067         {
00068                 return self::$block_type;
00069         }
00070 
00076         static function isRepositoryObject()
00077         {
00078                 return false;
00079         }
00080         
00084         static function getScreenMode()
00085         {
00086                 global $ilCtrl;
00087                 
00088                 switch($ilCtrl->getCmd())
00089                 {
00090                         case "create":
00091                         case "edit":
00092                         case "saveFeedBlock":
00093                         case "updateFeedBlock":
00094                         case "editFeedBlock":
00095                         case "showFeedItem":
00096                         case "confirmDeleteFeedBlock":
00097                                 return IL_SCREEN_CENTER;
00098                                 break;
00099                                 
00100                         default:
00101                                 return IL_SCREEN_SIDE;
00102                                 break;
00103                 }
00104         }
00105 
00109         function setBlock($a_block)
00110         {
00111                 global $ilCtrl;
00112 
00113                 // init block
00114                 $this->feed_block = $a_block;
00115                 $this->setTitle($this->feed_block->getTitle());
00116                 $this->setBlockId($this->feed_block->getId());
00117                 
00118                 // get feed object
00119                 include_once("./Services/Feeds/classes/class.ilExternalFeed.php");
00120                 $this->feed = new ilExternalFeed();
00121                 $this->feed->setUrl($this->feed_block->getFeedUrl());
00122                 
00123                 // init details
00124                 $this->setAvailableDetailLevels(2);
00125                 
00126                 $ilCtrl->setParameter($this, "block_id", $this->feed_block->getId());
00127         }
00128 
00132         function &executeCommand()
00133         {
00134                 global $ilCtrl;
00135 
00136                 $next_class = $ilCtrl->getNextClass();
00137                 $cmd = $ilCtrl->getCmd("getHTML");
00138 
00139                 switch ($next_class)
00140                 {
00141                         default:
00142                                 return $this->$cmd();
00143                 }
00144         }
00145 
00149         function fillDataSection()
00150         {
00151                 if ($this->getDynamic())
00152                 {
00153                         $this->setDataSection($this->getDynamicReload());
00154                 }
00155                 else if ($this->getCurrentDetailLevel() > 1 && count($this->getData()) > 0)
00156                 {
00157                         parent::fillDataSection();
00158                 }
00159                 else
00160                 {
00161                         $this->setDataSection($this->getOverview());
00162                 }
00163         }
00164 
00168         function getHTML()
00169         {
00170                 global $ilCtrl, $lng, $ilUser, $ilAccess, $ilSetting;
00171                 
00172                 $feed_set = new ilSetting("feed");
00173                 
00174                 if ($ilSetting->get("block_limit_pdfeed") == 0)
00175                 {
00176                         return "";
00177                 }
00178 
00179                 if ($this->getCurrentDetailLevel() == 0)
00180                 {
00181                         return "";
00182                 }
00183 
00184                 
00185                 // if no dynamic reload
00186                 if (!$this->getDynamic())
00187                 {
00188                         $this->feed->fetch();
00189                         $this->setData($this->feed->getItems());
00190                 }
00191 
00192                 $ilCtrl->setParameter($this, "external_feed_block_id",
00193                         $this->getBlockId());
00194                 $this->addBlockCommand(
00195                         $ilCtrl->getLinkTarget($this,
00196                                 "editFeedBlock"),
00197                         $lng->txt("edit"));
00198                 $this->addBlockCommand(
00199                         $ilCtrl->getLinkTarget($this,
00200                                 "confirmDeleteFeedBlock"),
00201                         $lng->txt("delete"));
00202                 $ilCtrl->setParameter($this, "external_feed_block_id", "");
00203 
00204                 // JS enabler
00205                 $add = "";
00206                 if ($_SESSION["il_feed_js"] == "n" ||
00207                         ($ilUser->getPref("il_feed_js") == "n" && $_SESSION["il_feed_js"] != "y"))
00208                 {
00209                         $add = $this->getJSEnabler();
00210                 }
00211                 
00212                 return parent::getHTML().$add;
00213         }
00214         
00215         function getDynamic()
00216         {
00217                 global $ilCtrl, $ilUser;
00218                 
00219                 if ($ilCtrl->getCmdClass() != "ilcolumngui" && $ilCtrl->getCmd() != "enableJS")
00220                 {
00221                         if ($_SESSION["il_feed_js"] != "n" &&
00222                                 ($ilUser->getPref("il_feed_js") != "n" || $_SESSION["il_feed_js"] == "y"))
00223                         {
00224                                 // do not get feed dynamically, if cache hit is given.
00225                                 if (!$this->feed->checkCacheHit())
00226                                 {
00227                                         return true;
00228                                 }
00229                         }
00230                 }
00231                 
00232                 return false;
00233         }
00234 
00235         function getDynamicReload()
00236         {
00237                 global $ilCtrl, $lng;
00238                 
00239                 $ilCtrl->setParameterByClass("ilcolumngui", "block_id",
00240                         "block_pdfeed_".$this->getBlockId());
00241 
00242                 $rel_tpl = new ilTemplate("tpl.dynamic_reload.html", true, true, "Services/Feeds");
00243                 $rel_tpl->setVariable("TXT_LOADING", $lng->txt("feed_loading_feed"));
00244                 $rel_tpl->setVariable("BLOCK_ID", "block_pdfeed_".$this->getBlockId());
00245                 $rel_tpl->setVariable("TARGET", 
00246                         $ilCtrl->getLinkTargetByClass("ilcolumngui", "updateBlock", "", true));
00247                         
00248                 // no JS
00249                 $rel_tpl->setVariable("TXT_FEED_CLICK_HERE", $lng->txt("feed_no_js_click_here"));
00250                 $rel_tpl->setVariable("TARGET_NO_JS", 
00251                         $ilCtrl->getLinkTargetByClass("ilpdexternalfeedblockgui", "disableJS"));
00252 
00253                 return $rel_tpl->get();
00254         }
00255         
00256         function getJSEnabler()
00257         {
00258                 global $ilCtrl, $lng;
00259                 
00260                 $ilCtrl->setParameterByClass("ilcolumngui", "block_id",
00261                         "block_pdfeed_".$this->getBlockId());
00262 
00263                 $rel_tpl = new ilTemplate("tpl.js_enabler.html", true, true, "Services/Feeds");
00264                 $rel_tpl->setVariable("BLOCK_ID", "block_pdfeed_".$this->getBlockId());
00265                 $rel_tpl->setVariable("TARGET", 
00266                         $ilCtrl->getLinkTargetByClass("ilpdexternalfeedblockgui", "enableJS", true));
00267                         
00268                 return $rel_tpl->get();
00269         }
00270         
00271         
00272         function disableJS()
00273         {
00274                 global $ilCtrl, $ilUser;
00275                 
00276                 $_SESSION["il_feed_js"] = "n";
00277                 $ilUser->writePref("il_feed_js", "n");
00278                 $ilCtrl->redirectByClass("ilpersonaldesktopgui", "show");
00279         }
00280         
00281         function enableJS()
00282         {
00283                 global $ilUser;
00284                 
00285                 $_SESSION["il_feed_js"] = "y";
00286                 $ilUser->writePref("il_feed_js", "y");
00287                 echo $this->getHTML();
00288                 exit;
00289         }
00290         
00294         function fillRow($item)
00295         {
00296                 global $ilUser, $ilCtrl, $lng;
00297 
00298                 $ilCtrl->setParameter($this, "feed_item_id", $item->getId());
00299                 $this->tpl->setVariable("VAL_TITLE", $item->getTitle());
00300                 $this->tpl->setVariable("HREF_SHOW",
00301                         $ilCtrl->getLinkTarget($this, "showFeedItem"));
00302                 $ilCtrl->setParameter($this, "feed_item_id", "");
00303         }
00304 
00308         function getOverview()
00309         {
00310                 global $ilUser, $lng, $ilCtrl;
00311                 
00312                 $this->setEnableNumInfo(false);
00313                 return '<div class="small">'.((int) count($this->getData()))." ".$lng->txt("feed_feed_items")."</div>";
00314         }
00315 
00319         function showFeedItem()
00320         {
00321                 global $lng, $ilCtrl;
00322                 
00323                 include_once("./Services/News/classes/class.ilNewsItem.php");
00324 
00325                 $this->feed->fetch();
00326                 foreach($this->feed->getItems() as $item)
00327                 {
00328                         if ($item->getId() == $_GET["feed_item_id"])
00329                         {
00330                                 $c_item = $item;
00331                                 break;
00332                         }
00333                 }
00334                 
00335                 $tpl = new ilTemplate("tpl.show_feed_item.html", true, true, "Services/Feeds");
00336                 
00337                 if (is_object($c_item))
00338                 {
00339                         if (trim($c_item->getSummary()) != "")          // summary
00340                         {
00341                                 $tpl->setCurrentBlock("content");
00342                                 $tpl->setVariable("VAL_CONTENT", $c_item->getSummary());
00343                                 $tpl->parseCurrentBlock();
00344                         }
00345                         if (trim($c_item->getDate()) != "" || trim($c_item->getAuthor()) != "")         // date
00346                         {
00347                                 $tpl->setCurrentBlock("date_author");
00348                                 if (trim($c_item->getAuthor()) != "")
00349                                 {
00350                                         $tpl->setVariable("VAL_AUTHOR", $c_item->getAuthor()." - ");
00351                                 }
00352                                 $tpl->setVariable("VAL_DATE", $c_item->getDate());
00353                                 $tpl->parseCurrentBlock();
00354                         }
00355 
00356                         if (trim($c_item->getLink()) != "")             // link
00357                         {
00358                                 $tpl->setCurrentBlock("plink");
00359                                 $tpl->setVariable("HREF_LINK", $c_item->getLink());
00360                                 $tpl->setVariable("TXT_LINK", $lng->txt("feed_open_source_page"));
00361                                 $tpl->parseCurrentBlock();
00362                         }
00363                         $tpl->setVariable("VAL_TITLE", $c_item->getTitle());                    // title
00364                 }
00365                 
00366                 include_once("./Services/PersonalDesktop/classes/class.ilPDContentBlockGUI.php");
00367                 $content_block = new ilPDContentBlockGUI();
00368                 $content_block->setContent($tpl->get());
00369                 $content_block->setTitle($this->getTitle());
00370                 $content_block->setImage(ilUtil::getImagePath("icon_feed.gif"));
00371                 $content_block->addHeaderCommand($ilCtrl->getParentReturn($this),
00372                         $lng->txt("selected_items_back"));
00373 
00374                 return $content_block->getHTML();
00375         }
00376         
00380         function create()
00381         {
00382                 return $this->createFeedBlock();
00383         }
00384 
00391         public function initFormFeedBlock($a_mode)
00392         {
00393                 global $lng;
00394                 
00395                 $lng->loadLanguageModule("block");
00396                 
00397                 include("Services/Form/classes/class.ilPropertyFormGUI.php");
00398                 
00399                 $this->form_gui = new ilPropertyFormGUI();
00400                 
00401                 // Property Title
00402                 $text_input = new ilTextInputGUI($lng->txt("block_feed_block_title"), "block_title");
00403                 $text_input->setInfo("");
00404                 $text_input->setRequired(true);
00405                 $text_input->setMaxLength(200);
00406                 $this->form_gui->addItem($text_input);
00407                 
00408                 // Property FeedUrl
00409                 $text_input = new ilFeedUrlInputGUI($lng->txt("block_feed_block_feed_url"), "block_feed_url");
00410                 $text_input->setInfo($lng->txt("block_feed_block_feed_url_info"));
00411                 $text_input->setRequired(true);
00412                 $text_input->setMaxLength(250);
00413                 $this->form_gui->addItem($text_input);
00414                 
00415                 
00416                 // save and cancel commands
00417                 if (in_array($a_mode, array(IL_FORM_CREATE,IL_FORM_RE_CREATE)))
00418                 {
00419                         $this->form_gui->addCommandButton("saveFeedBlock", $lng->txt("save"));
00420                         $this->form_gui->addCommandButton("cancelSaveFeedBlock", $lng->txt("cancel"));
00421                 }
00422                 else
00423                 {
00424                         $this->form_gui->addCommandButton("updateFeedBlock", $lng->txt("save"));
00425                         $this->form_gui->addCommandButton("cancelUpdateFeedBlock", $lng->txt("cancel"));
00426                 }
00427                 
00428                 $this->form_gui->setTitle($lng->txt("block_feed_block_head"));
00429                 $this->form_gui->setFormAction($this->ctrl->getFormAction($this));
00430                 
00431                 $this->prepareFormFeedBlock($this->form_gui);
00432 
00433         }
00434 
00440         public function prepareSaveFeedBlock(&$a_feed_block)
00441         {
00442                 global $ilCtrl;
00443                 
00444                 $a_feed_block->setContextObjId($ilCtrl->getContextObjId());
00445                 $a_feed_block->setContextObjType($ilCtrl->getContextObjType());
00446                 $a_feed_block->setType("pdfeed");
00447         }
00448 
00452         function confirmDeleteFeedBlock()
00453         {
00454                 global $ilCtrl, $lng;
00455                 
00456                 include_once("Services/Utilities/classes/class.ilConfirmationGUI.php");
00457                 $c_gui = new ilConfirmationGUI();
00458                 
00459                 // set confirm/cancel commands
00460                 $c_gui->setFormAction($ilCtrl->getFormAction($this, "deleteFeedBlock"));
00461                 $c_gui->setHeaderText($lng->txt("info_delete_sure"));
00462                 $c_gui->setCancel($lng->txt("cancel"), "exitDeleteFeedBlock");
00463                 $c_gui->setConfirm($lng->txt("confirm"), "deleteFeedBlock");
00464 
00465                 // add items to delete
00466                 $c_gui->addItem("external_feed_block_id",
00467                         $this->feed_block->getId(), $this->feed_block->getTitle(),
00468                         ilUtil::getImagePath("icon_feed.gif"));
00469                 
00470                 return $c_gui->getHTML();
00471         }
00472         
00476         function exitDeleteFeedBlock()
00477         {
00478                 global $ilCtrl;
00479 
00480                 $ilCtrl->returnToParent($this);
00481         }
00482 
00486         function deleteFeedBlock()
00487         {
00488                 global $ilCtrl;
00489 
00490                 $this->feed_block->delete();
00491                 $ilCtrl->returnToParent($this);
00492         }
00493 }
00494 
00495 ?>

Generated on Fri Dec 13 2013 17:56:57 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1