ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPDNewsBlockGUI.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/News/classes/class.ilNewsForContextBlockGUI.php");
25 
37 {
38  static $block_type = "pdnews";
39  static $st_data;
40 
44  function ilPDNewsBlockGUI()
45  {
46  global $ilCtrl, $lng, $ilUser, $ilBench, $ilAccess, $ilCtrl;
47 
48  $ilBench->start("News", "ilPDNewsBlockGUI_Constructor");
49  $news_set = new ilSetting("news");
50 
52 
53  $this->setImage(ilUtil::getImagePath("icon_news_s.gif"));
54 
55  $lng->loadLanguageModule("news");
56  include_once("./Services/News/classes/class.ilNewsItem.php");
57 
58  $this->setLimit(5);
59  $this->setAvailableDetailLevels(3);
60 
61  $this->dynamic = false;
62 
63  // store current access check results
64  $this->acc_results = $ilAccess->getResults();
65 
66  // read access cache
67  $this->acc_cache_hit = $ilAccess->readCache(
68  ((int) $news_set->get("acc_cache_mins")) * 60);
69 
70  if ($this->getDynamic() && !$this->acc_cache_hit)
71  {
72  $this->dynamic = true;
73  $data = array();
74  }
75  else if ($this->getCurrentDetailLevel() > 0)
76  {
77  // do not ask two times for the data (e.g. if user displays a
78  // single item on the personal desktop and the news block is
79  // displayed at the same time)
80  if (empty(self::$st_data))
81  {
82  self::$st_data = $this->getNewsData();
84  }
85  else
86  {
88  }
89  }
90  else
91  {
92  $data = array();
93  }
94 
95  $this->setTitle($lng->txt("news_internal_news"));
96  $this->setRowTemplate("tpl.block_row_news_for_context.html", "Services/News");
97 
98  $this->setData($data);
99 
100  $this->handleView();
101 
102  // reset access check results
103  $ilAccess->setResults($this->acc_results);
104 
105  $ilBench->stop("News", "ilPDNewsBlockGUI_Constructor");
106  }
107 
111  function getNewsData()
112  {
113  global $ilUser, $ilAccess;
114 
115  $per = ilNewsItem::_lookupUserPDPeriod($ilUser->getId());
116  $data = ilNewsItem::_getNewsItemsOfUser($ilUser->getId(), false,
117  false, $per);
118  if (!$this->acc_cache_hit)
119  {
120  $ilAccess->storeCache();
121  }
122  return $data;
123  }
124 
130  static function getBlockType()
131  {
132  return self::$block_type;
133  }
134 
140  static function isRepositoryObject()
141  {
142  return false;
143  }
144 
148  static function getScreenMode()
149  {
150  global $ilCtrl;
151 
152  switch($_GET["cmd"])
153  {
154  case "showNews":
155  case "showFeedUrl":
156  case "editSettings":
157  return IL_SCREEN_CENTER;
158  break;
159 
160  default:
161  return IL_SCREEN_SIDE;
162  break;
163  }
164  }
165 
169  function &executeCommand()
170  {
171  global $ilCtrl;
172 
173  $next_class = $ilCtrl->getNextClass();
174  $cmd = $ilCtrl->getCmd("getHTML");
175 
176  switch ($next_class)
177  {
178  default:
179  return $this->$cmd();
180  }
181  }
182 
186  function fillDataSection()
187  {
188  global $ilBench;
189 
190  if ($this->dynamic)
191  {
192  $this->setDataSection($this->getDynamicReload());
193  }
194  else if ($this->getCurrentDetailLevel() > 1 && count($this->getData()) > 0)
195  {
196  $ilBench->start("News", "ilPDNewsBlockGUI_fillDataSection");
198  $ilBench->stop("News", "ilPDNewsBlockGUI_fillDataSection");
199  }
200  else
201  {
202  $this->setEnableNumInfo(false);
203  if (count($this->getData()) == 0)
204  {
205  $this->setEnableDetailRow(false);
206  }
207  $this->setDataSection($this->getOverview());
208  }
209  }
210 
214  function getHTML()
215  {
216  global $ilCtrl, $lng, $ilUser;
217 
218  // set footer info
219  $this->setFooterInfo($lng->txt("news_block_information"), true);
220 
221  $news_set = new ilSetting("news");
222  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
223  $allow_shorter_periods = $news_set->get("allow_shorter_periods");
224  $allow_longer_periods = $news_set->get("allow_longer_periods");
225  $enable_private_feed = $news_set->get("enable_private_feed");
226 
227  // subscribe/unsibscribe link
228  include_once("./Services/News/classes/class.ilNewsSubscription.php");
229 
230  // show feed url
231  if ($enable_internal_rss)
232  {
233  $this->addBlockCommand(
234  $ilCtrl->getLinkTarget($this, "showFeedUrl"),
235  $lng->txt("news_get_feed_url"), "", ilUtil::getImagePath("rss.gif"), true);
236  }
237 
238  if ($allow_shorter_periods || $allow_longer_periods || $enable_private_feed)
239  {
240  $this->addBlockCommand(
241  $ilCtrl->getLinkTarget($this, "editSettings"),
242  $lng->txt("settings"));
243  }
244 
245  $per = ilNewsItem::_lookupUserPDPeriod($ilUser->getId());
246 
247  if ($per > 0)
248  {
249  switch ($per)
250  {
251  case 2:
252  case 3:
253  case 5: $per_str = sprintf($lng->txt("news_period_x_days"), $per); break;
254  case 7: $per_str = $lng->txt("news_period_1_week"); break;
255  case 14: $per_str = sprintf($lng->txt("news_period_x_weeks"), 2); break;
256  case 30: $per_str = $lng->txt("news_period_1_month"); break;
257  case 60: $per_str = sprintf($lng->txt("news_period_x_months"), 2); break;
258  case 120: $per_str = sprintf($lng->txt("news_period_x_months"), 4); break;
259  case 180: $per_str = sprintf($lng->txt("news_period_x_months"), 6); break;
260  case 366: $per_str = $lng->txt("news_period_1_year"); break;
261  }
262  if ($per_str != "")
263  {
264  $this->setTitle($this->getTitle().' <span style="font-weight:normal;">- '.$per_str."</span>");
265  }
266  }
267 
268  if ($this->getCurrentDetailLevel() == 0)
269  {
270  return "";
271  }
272 
273  $en = "";
274  if ($ilUser->getPref("il_feed_js") == "n")
275  {
276  $en = $this->getJSEnabler();
277  }
278 
279  return ilBlockGUI::getHTML().$en;
280  }
281 
282 
286  function showFeedUrl()
287  {
288  global $lng, $ilCtrl, $ilUser, $ilSetting;
289 
290  $news_set = new ilSetting("news");
291 
292 
293  include_once("./Services/News/classes/class.ilNewsItem.php");
294 
295  if ($news_set->get("enable_private_feed") && $ilUser->_getFeedPass($_SESSION["AccountId"]))
296  {
297  $tpl = new ilTemplate("tpl.show_priv_feed_url.html", true, true, "Services/News");
298 
299  $tpl->setVariable("IMG_PRIV_RSS", ilUtil::getImagePath("privrss.gif"));
300  $tpl->setVariable("TXT_PRIV_TITLE", $lng->txt("news_get_priv_feed_title"));
301  $tpl->setVariable("TXT_PRIV_INFO", $lng->txt("news_get_priv_feed_info"));
302  $tpl->setVariable("TXT_PRIV_FEED_URL", $lng->txt("news_feed_url"));
303  $tpl->setVariable("VAL_PRIV_FEED_URL",
304  str_replace("://", "://" . $ilUser->getLogin() . ":-password-@", ILIAS_HTTP_PATH)."/privfeed.php?client_id=".rawurlencode(CLIENT_ID)."&user_id=".$ilUser->getId().
305  "&hash=".ilObjUser::_lookupFeedHash($ilUser->getId(), true));
306  $tpl->setVariable("VAL_PRIV_FEED_URL_TXT",
307  str_replace("://", "://" . $ilUser->getLogin() . ":-password-@", ILIAS_HTTP_PATH)."/privfeed.php?client_id=".rawurlencode(CLIENT_ID)."&<br />user_id=".$ilUser->getId().
308  "&hash=".ilObjUser::_lookupFeedHash($ilUser->getId(), true));
309  }
310  else
311  {
312  $tpl = new ilTemplate("tpl.show_feed_url.html", true, true, "Services/News");
313  }
314  $tpl->setVariable("TXT_TITLE", $lng->txt("news_get_feed_title"));
315  $tpl->setVariable("TXT_INFO", $lng->txt("news_get_feed_info"));
316  $tpl->setVariable("TXT_FEED_URL", $lng->txt("news_feed_url"));
317  $tpl->setVariable("VAL_FEED_URL",
318  ILIAS_HTTP_PATH."/feed.php?client_id=".rawurlencode(CLIENT_ID)."&user_id=".$ilUser->getId().
319  "&hash=".ilObjUser::_lookupFeedHash($ilUser->getId(), true));
320  $tpl->setVariable("VAL_FEED_URL_TXT",
321  ILIAS_HTTP_PATH."/feed.php?client_id=".rawurlencode(CLIENT_ID)."&<br />user_id=".$ilUser->getId().
322  "&hash=".ilObjUser::_lookupFeedHash($ilUser->getId(), true));
323 
324  include_once("./Services/PersonalDesktop/classes/class.ilPDContentBlockGUI.php");
325  $content_block = new ilPDContentBlockGUI();
326  $content_block->setContent($tpl->get());
327  $content_block->setTitle($lng->txt("news_internal_news"));
328  $content_block->setImage(ilUtil::getImagePath("icon_news.gif"));
329  $content_block->addHeaderCommand($ilCtrl->getParentReturn($this),
330  $lng->txt("selected_items_back"));
331 
332  return $content_block->getHTML();
333  }
334 
335  function addCloseCommand($a_content_block)
336  {
337  global $lng, $ilCtrl;
338 
339  $a_content_block->addHeaderCommand($ilCtrl->getParentReturn($this),
340  $lng->txt("selected_items_back"));
341  }
342 
343 
347  function showNews()
348  {
349  // workaround for dynamic mode (if cache is disabled, showNews has no data)
350 // if (empty(self::$st_data))
351 // {
352 // $this->setData($this->getNewsData());
353 // }
354 
355  return parent::showNews();
356  }
357 
361  function editSettings()
362  {
363  global $ilUser, $lng, $ilCtrl, $ilSetting;
364 
365  $news_set = new ilSetting("news");
366  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
367  $allow_shorter_periods = $news_set->get("allow_shorter_periods");
368  $allow_longer_periods = $news_set->get("allow_longer_periods");
369  $enable_private_feed = $news_set->get("enable_private_feed");
370 
371  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
372 
373  if ($allow_shorter_periods || $allow_longer_periods )
374  {
375  $form = new ilPropertyFormGUI();
376  include_once("./Services/News/classes/class.ilNewsItem.php");
377  $default_per = ilNewsItem::_lookupDefaultPDPeriod();
378  $per = ilNewsItem::_lookupUserPDPeriod($ilUser->getId());
379 
380  $form->setTitle($lng->txt("news_settings"));
381  $form->setTitleIcon(ilUtil::getImagePath("icon_news.gif"));
382 
383  $form->setTableWidth("100%");
384 
385  $per_opts = array(
386  2 => "2 ".$lng->txt("days"),
387  3 => "3 ".$lng->txt("days"),
388  5 => "5 ".$lng->txt("days"),
389  7 => "1 ".$lng->txt("week"),
390  14 => "2 ".$lng->txt("weeks"),
391  30 => "1 ".$lng->txt("month"),
392  60 => "2 ".$lng->txt("months"),
393  120 => "4 ".$lng->txt("months"),
394  180 => "6 ".$lng->txt("months"),
395  366 => "1 ".$lng->txt("year"));
396 
397  $unset = array();
398  foreach($per_opts as $k => $opt)
399  {
400  if (!$allow_shorter_periods && ($k < $default_per)) $unset[$k] = $k;
401  if (!$allow_longer_periods && ($k > $default_per)) $unset[$k] = $k;
402  }
403  foreach($unset as $k)
404  {
405  unset($per_opts[$k]);
406  }
407 
408  $per_sel = new ilSelectInputGUI($lng->txt("news_pd_period"),
409  "news_pd_period");
410  //$per_sel->setInfo($lng->txt("news_pd_period_info"));
411  $per_sel->setOptions($per_opts);
412  $per_sel->setValue((int) $per);
413  $form->addItem($per_sel);
414 
415  //$form->addCheckboxProperty($lng->txt("news_public_feed"), "notifications_public_feed",
416  // "1", $public_feed, $lng->txt("news_public_feed_info"));
417  //if ($this->getProperty("public_notifications_option"))
418  //{
419  // $form->addCheckboxProperty($lng->txt("news_notifications_public"), "notifications_public",
420  // "1", $public, $lng->txt("news_notifications_public_info"));
421  //}
422  $form->addCommandButton("saveSettings", $lng->txt("save"));
423  $form->addCommandButton("cancelSettings", $lng->txt("cancel"));
424  $form->setFormAction($ilCtrl->getFormaction($this));
425 
426  $returnForm = $form->getHTML();
427  }
428 
429  if ($enable_private_feed)
430  {
431  $feed_form = new ilPropertyFormGUI();
432  $feed_form->setTitle($lng->txt("priv_feed_settings"));
433  $feed_form->setTitleIcon(ilUtil::getImagePath("privrss.gif"));
434 
435  $feed_form->setTableWidth("100%");
436 
437  $enable_private_feed = new ilCheckboxInputGUI($lng->txt("news_enable_private_feed"), "enable_private_feed");
438 
439 
440  $retype_pass = new ilTextInputGUI($lng->txt("retype_password"), "retype_password");
441  $desired_pass = new ilTextInputGUI($lng->txt("desired_password"), "desired_password");
442 
443  // user has already valid password
444  if (ilObjUser::_getFeedPass($_SESSION[AccountId]) != false)
445  {
446  $enable_private_feed->setChecked(true);
447  $desired_pass->setValue("******");
448  }
449  $desired_pass->setInputType("password");
450 
451  $retype_pass->setInputType("password");
452 
453  $feed_form->addItem($enable_private_feed);
454  $feed_form->addItem($desired_pass);
455  $feed_form->addItem($retype_pass);
456 
457  $feed_form->addCommandButton("changeFeedSettings", $lng->txt("save"));
458  $feed_form->addCommandButton("cancelSettings", $lng->txt("cancel"));
459  $feed_form->setFormAction($ilCtrl->getFormaction($this));
460 
461  $returnForm .= ($returnForm=="")?$feed_form->getHTML():"<br>".$feed_form->getHTML();
462  }
463 
464  return $returnForm;
465  }
466 
470  function cancelSettings()
471  {
472  global $ilCtrl;
473 
474  $ilCtrl->returnToParent($this);
475  }
476 
480  function saveSettings()
481  {
482  global $ilCtrl, $ilUser;
483 
484  $news_set = new ilSetting("news");
485  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
486 
487  ilBlockSetting::_write($this->getBlockType(), "news_pd_period",
488  $_POST["news_pd_period"],
489  $ilUser->getId(), $this->block_id);
490 
491  $ilCtrl->returnToParent($this);
492  }
493 
498  {
499  global $ilCtrl, $lng, $ilUser;
500 
501  // Deactivate private Feed - just delete the password
502  if (empty($_POST["enable_private_feed"]))
503  {
504  ilUtil::sendInfo($lng->txt("priv_feed_disabled"),true);
505  $ilUser->_setFeedPass($_SESSION["AccountId"],"");
506  $ilCtrl->returnToParent($this);
507  }
508  else
509  {
510  // check old password
511  if ($_POST["desired_password"] != $_POST["retype_password"])
512  {
513  ilUtil::sendInfo($lng->txt("passwd_not_match"),true);
514  $ilCtrl->redirectByClass("ilPDNewsBlockGUI", "editSettings");
515  }
516  // validate password
517  else if (!ilUtil::isPassword($_POST["desired_password"]))
518  {
519  ilUtil::sendInfo($lng->txt("passwd_invalid"),true);
520  $ilCtrl->redirectByClass("ilPDNewsBlockGUI", "editSettings");
521  }
522  // only works for ILIAS3 passwords
523  else if (md5($_POST["desired_password"]) == $ilUser->getPasswd())
524  {
525  ilUtil::sendInfo($lng->txt("passwd_equals_ilpasswd"),true);
526  $ilCtrl->redirectByClass("ilPDNewsBlockGUI", "editSettings");
527  }
528  else if ($_POST["desired_password"] != "")
529  {
530  ilUtil::sendInfo($lng->txt("saved_successfully"),true);
531  $ilUser->_setFeedPass($_SESSION["AccountId"],$_POST["desired_password"]);
532  $ilCtrl->returnToParent($this);
533  }
534  }
535  }
536 
537 }
538 
539 ?>