ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilPDNewsBlockGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once("Services/News/classes/class.ilNewsForContextBlockGUI.php");
5 
17 {
18  public static $block_type = "pdnews";
19  public static $st_data;
20  protected $acc_results = false;
21 
25  public function __construct()
26  {
27  global $DIC;
28 
29  $this->lng = $DIC->language();
30  $this->user = $DIC->user();
31  $this->access = $DIC->access();
32  $this->ctrl = $DIC->ctrl();
33  $this->settings = $DIC->settings();
34  $lng = $DIC->language();
35  $ilUser = $DIC->user();
36  $ilAccess = $DIC->access();
37 
38  // NOT ilNewsForContextBlockGUI::__construct() !
40 
41  $lng->loadLanguageModule("news");
42  include_once("./Services/News/classes/class.ilNewsItem.php");
43 
44  $this->setLimit(5);
45  $this->setAvailableDetailLevels(3);
46 
47  $this->dynamic = false;
48 
49  include_once("./Services/News/classes/class.ilNewsCache.php");
50  $this->acache = new ilNewsCache();
51  $cres = unserialize($this->acache->getEntry($ilUser->getId() . ":0"));
52  $this->cache_hit = false;
53  if ($this->acache->getLastAccessStatus() == "hit" && is_array($cres)) {
54  self::$st_data = ilNewsItem::prepareNewsDataFromCache($cres);
55  ;
56  $this->cache_hit = true;
57  }
58 
59  if ($this->getDynamic() && !$this->cache_hit) {
60  $this->dynamic = true;
61  $data = array();
62  } elseif ($this->getCurrentDetailLevel() > 0) {
63  // do not ask two times for the data (e.g. if user displays a
64  // single item on the personal desktop and the news block is
65  // displayed at the same time)
66  if (empty(self::$st_data)) {
67  self::$st_data = $this->getNewsData();
68  $data = self::$st_data;
69  } else {
70  $data = self::$st_data;
71  }
72  } else {
73  $data = array();
74  }
75 
76  $this->setTitle($lng->txt("news_internal_news"));
77  $this->setRowTemplate("tpl.block_row_news_for_context.html", "Services/News");
78 
79  $this->setData($data);
80 
81  $this->handleView();
82 
83  // reset access check results
84  $ilAccess->setResults($this->acc_results);
85  }
86 
90  public function getNewsData()
91  {
93 
94  include_once("./Services/News/classes/class.ilNewsCache.php");
95  $this->acache = new ilNewsCache();
96 
99  $ilUser->getId(),
100  false,
101  false,
102  $per
103  );
104 
105  $this->acache->storeEntry(
106  $ilUser->getId() . ":0",
107  serialize($data)
108  );
109 
110  return $data;
111  }
112 
118  public static function getBlockType()
119  {
120  return self::$block_type;
121  }
122 
128  public static function isRepositoryObject()
129  {
130  return false;
131  }
132 
136  public static function getScreenMode()
137  {
138  global $DIC;
139 
140  $ilCtrl = $DIC->ctrl();
141 
142  $cmd = $_GET["cmd"];
143  if ($cmd == "post" && is_array($_POST["cmd"])) {
144  $cmd = array_pop(array_keys($_POST["cmd"]));
145  }
146 
147  switch ($cmd) {
148  case "showNews":
149  case "showFeedUrl":
150  case "editSettings":
151  case "changeFeedSettings":
152  return IL_SCREEN_CENTER;
153 
154  default:
155  return IL_SCREEN_SIDE;
156  }
157  }
158 
162  public function executeCommand()
163  {
165 
166  $next_class = $ilCtrl->getNextClass();
167  $cmd = $ilCtrl->getCmd("getHTML");
168 
169  switch ($next_class) {
170  default:
171  return $this->$cmd();
172  }
173  }
174 
178  public function fillDataSection()
179  {
180  if ($this->dynamic) {
181  $this->setDataSection($this->getDynamicReload());
182  } elseif ($this->getCurrentDetailLevel() > 1 && count($this->getData()) > 0) {
183  parent::fillDataSection();
184  } else {
185  $this->setEnableNumInfo(false);
186  if (count($this->getData()) == 0) {
187  $this->setEnableDetailRow(false);
188  }
189  $this->setDataSection($this->getOverview());
190  }
191  }
192 
196  public function getHTML()
197  {
199  $lng = $this->lng;
201 
202  // set footer info
203  $this->setFooterInfo($lng->txt("news_block_information"), true);
204 
205  $news_set = new ilSetting("news");
206  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
207  $allow_shorter_periods = $news_set->get("allow_shorter_periods");
208  $allow_longer_periods = $news_set->get("allow_longer_periods");
209  $enable_private_feed = $news_set->get("enable_private_feed");
210 
211  // subscribe/unsibscribe link
212  include_once("./Services/News/classes/class.ilNewsSubscription.php");
213 
214  // show feed url
215  if ($enable_internal_rss) {
216  include_once("./Services/News/classes/class.ilRSSButtonGUI.php");
217  $this->addBlockCommand(
218  $ilCtrl->getLinkTarget($this, "showFeedUrl"),
219  $lng->txt("news_get_feed_url"),
220  "",
221  "",
222  true,
223  false,
225  );
226  }
227 
228  if ($allow_shorter_periods || $allow_longer_periods || $enable_private_feed) {
229  $this->addBlockCommand(
230  $ilCtrl->getLinkTarget($this, "editSettings"),
231  $lng->txt("settings")
232  );
233  }
234 
235  $per = ilNewsItem::_lookupUserPDPeriod($ilUser->getId());
236 
237  if ($per > 0) {
238  switch ($per) {
239  case 2:
240  case 3:
241  case 5: $per_str = sprintf($lng->txt("news_period_x_days"), $per); break;
242  case 7: $per_str = $lng->txt("news_period_1_week"); break;
243  case 14: $per_str = sprintf($lng->txt("news_period_x_weeks"), 2); break;
244  case 30: $per_str = $lng->txt("news_period_1_month"); break;
245  case 60: $per_str = sprintf($lng->txt("news_period_x_months"), 2); break;
246  case 120: $per_str = sprintf($lng->txt("news_period_x_months"), 4); break;
247  case 180: $per_str = sprintf($lng->txt("news_period_x_months"), 6); break;
248  case 366: $per_str = $lng->txt("news_period_1_year"); break;
249  }
250  if ($per_str != "") {
251  $this->setTitle($this->getTitle() . ' <span style="font-weight:normal;">- ' . $per_str . "</span>");
252  }
253  }
254 
255  if ($this->getCurrentDetailLevel() == 0) {
256  return "";
257  }
258 
259  $en = "";
260  if ($ilUser->getPref("il_feed_js") == "n") {
261  $en = $this->getJSEnabler();
262  }
263 
264  return ilBlockGUI::getHTML() . $en;
265  }
266 
267 
271  public function showFeedUrl()
272  {
273  $lng = $this->lng;
277 
278  $news_set = new ilSetting("news");
279 
280 
281  include_once("./Services/News/classes/class.ilNewsItem.php");
282 
283  if ($news_set->get("enable_private_feed")) {
284  $tpl = new ilTemplate("tpl.show_priv_feed_url.html", true, true, "Services/News");
285 
286  $tpl->setVariable("TXT_PRIV_TITLE", $lng->txt("news_get_priv_feed_title"));
287 
288  // #14365
289  if ($ilUser->_getFeedPass($GLOBALS['DIC']['ilUser']->getId())) {
290  $tpl->setVariable("TXT_PRIV_INFO", $lng->txt("news_get_priv_feed_info"));
291  $tpl->setVariable("TXT_PRIV_FEED_URL", $lng->txt("news_feed_url"));
292  $tpl->setVariable(
293  "VAL_PRIV_FEED_URL",
294  str_replace("://", "://" . $ilUser->getLogin() . ":-password-@", ILIAS_HTTP_PATH) . "/privfeed.php?client_id=" . rawurlencode(CLIENT_ID) . "&user_id=" . $ilUser->getId() .
295  "&hash=" . ilObjUser::_lookupFeedHash($ilUser->getId(), true)
296  );
297  $tpl->setVariable(
298  "VAL_PRIV_FEED_URL_TXT",
299  str_replace("://", "://" . $ilUser->getLogin() . ":-password-@", ILIAS_HTTP_PATH) . "/privfeed.php?client_id=" . rawurlencode(CLIENT_ID) . "&<br />user_id=" . $ilUser->getId() .
300  "&hash=" . ilObjUser::_lookupFeedHash($ilUser->getId(), true)
301  );
302  } else {
303  $tpl->setVariable("TXT_PRIV_INFO", $lng->txt("news_inactive_private_feed_info"));
304  $tpl->setVariable("EDIT_SETTINGS_URL", $ilCtrl->getLinkTarget($this, "editSettings"));
305  $tpl->setVariable("EDIT_SETTINGS_TXT", $lng->txt("news_edit_news_settings"));
306  }
307  } else {
308  $tpl = new ilTemplate("tpl.show_feed_url.html", true, true, "Services/News");
309  }
310  $tpl->setVariable("TXT_TITLE", $lng->txt("news_get_feed_title"));
311  $tpl->setVariable("TXT_INFO", $lng->txt("news_get_feed_info"));
312  $tpl->setVariable("TXT_FEED_URL", $lng->txt("news_feed_url"));
313  $tpl->setVariable(
314  "VAL_FEED_URL",
315  ILIAS_HTTP_PATH . "/feed.php?client_id=" . rawurlencode(CLIENT_ID) . "&user_id=" . $ilUser->getId() .
316  "&hash=" . ilObjUser::_lookupFeedHash($ilUser->getId(), true)
317  );
318  $tpl->setVariable(
319  "VAL_FEED_URL_TXT",
320  ILIAS_HTTP_PATH . "/feed.php?client_id=" . rawurlencode(CLIENT_ID) . "&<br />user_id=" . $ilUser->getId() .
321  "&hash=" . ilObjUser::_lookupFeedHash($ilUser->getId(), true)
322  );
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->addHeaderCommand(
329  $ilCtrl->getParentReturn($this),
330  $lng->txt("selected_items_back")
331  );
332 
333  return $content_block->getHTML();
334  }
335 
336  public function addCloseCommand($a_content_block)
337  {
338  $lng = $this->lng;
340 
341  $a_content_block->addHeaderCommand(
342  $ilCtrl->getParentReturn($this),
343  $lng->txt("selected_items_back")
344  );
345  }
346 
347 
351  public function showNews()
352  {
353  // workaround for dynamic mode (if cache is disabled, showNews has no data)
354  // if (empty(self::$st_data))
355  // {
356  // $this->setData($this->getNewsData());
357  // }
358 
359  return parent::showNews();
360  }
361 
365  public function editSettings(ilPropertyFormGUI $a_private_form = null)
366  {
368  $lng = $this->lng;
371 
372  $news_set = new ilSetting("news");
373  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
374  $allow_shorter_periods = $news_set->get("allow_shorter_periods");
375  $allow_longer_periods = $news_set->get("allow_longer_periods");
376  $enable_private_feed = $news_set->get("enable_private_feed");
377 
378  if (!$a_private_form && ($allow_shorter_periods || $allow_longer_periods)) {
379  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
380  $form = new ilPropertyFormGUI();
381  $form->setFormAction($ilCtrl->getFormaction($this));
382  $form->setTitle($lng->txt("news_settings"));
383 
384  include_once("./Services/News/classes/class.ilNewsItem.php");
385  $default_per = ilNewsItem::_lookupDefaultPDPeriod();
386  $per = ilNewsItem::_lookupUserPDPeriod($ilUser->getId());
387 
388  $form->setTableWidth("100%");
389 
390  $per_opts = array(
391  2 => "2 " . $lng->txt("days"),
392  3 => "3 " . $lng->txt("days"),
393  5 => "5 " . $lng->txt("days"),
394  7 => "1 " . $lng->txt("week"),
395  14 => "2 " . $lng->txt("weeks"),
396  30 => "1 " . $lng->txt("month"),
397  60 => "2 " . $lng->txt("months"),
398  120 => "4 " . $lng->txt("months"),
399  180 => "6 " . $lng->txt("months"),
400  366 => "1 " . $lng->txt("year"));
401 
402  $unset = array();
403  foreach ($per_opts as $k => $opt) {
404  if (!$allow_shorter_periods && ($k < $default_per)) {
405  $unset[$k] = $k;
406  }
407  if (!$allow_longer_periods && ($k > $default_per)) {
408  $unset[$k] = $k;
409  }
410  }
411  foreach ($unset as $k) {
412  unset($per_opts[$k]);
413  }
414 
415  $per_sel = new ilSelectInputGUI(
416  $lng->txt("news_pd_period"),
417  "news_pd_period"
418  );
419  //$per_sel->setInfo($lng->txt("news_pd_period_info"));
420  $per_sel->setOptions($per_opts);
421  $per_sel->setValue((int) $per);
422  $form->addItem($per_sel);
423 
424  //$form->addCheckboxProperty($lng->txt("news_public_feed"), "notifications_public_feed",
425  // "1", $public_feed, $lng->txt("news_public_feed_info"));
426  //if ($this->getProperty("public_notifications_option"))
427  //{
428  // $form->addCheckboxProperty($lng->txt("news_notifications_public"), "notifications_public",
429  // "1", $public, $lng->txt("news_notifications_public_info"));
430  //}
431  $form->addCommandButton("saveSettings", $lng->txt("save"));
432  $form->addCommandButton("cancelSettings", $lng->txt("cancel"));
433 
434  $returnForm = $form->getHTML();
435  }
436 
437  if ($enable_private_feed) {
438  if (!$a_private_form) {
439  $a_private_form = $this->initPrivateSettingsForm();
440  }
441  $returnForm .= ($returnForm=="")
442  ? $a_private_form->getHTML()
443  : "<br>" . $a_private_form->getHTML();
444  }
445 
446  return $returnForm;
447  }
448 
449  protected function initPrivateSettingsForm()
450  {
452  $lng = $this->lng;
454 
455  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
456  $feed_form = new ilPropertyFormGUI();
457  $feed_form->setFormAction($ilCtrl->getFormaction($this));
458  $feed_form->setTitle($lng->txt("priv_feed_settings"));
459 
460  $feed_form->setTableWidth("100%");
461 
462  $enable_private_feed = new ilCheckboxInputGUI($lng->txt("news_enable_private_feed"), "enable_private_feed");
463  $enable_private_feed->setChecked($ilUser->_getFeedPass($ilUser->getId()));
464  $feed_form->addItem($enable_private_feed);
465 
466  $passwd = new ilPasswordInputGUI($lng->txt("password"), "desired_password");
467  $passwd->setRequired(true);
468  $passwd->setInfo(ilUtil::getPasswordRequirementsInfo());
469  $enable_private_feed->addSubItem($passwd);
470 
471  $feed_form->addCommandButton("changeFeedSettings", $lng->txt("save"));
472  $feed_form->addCommandButton("cancelSettings", $lng->txt("cancel"));
473 
474  return $feed_form;
475  }
476 
480  public function cancelSettings()
481  {
483 
484  $ilCtrl->returnToParent($this);
485  }
486 
490  public function saveSettings()
491  {
494 
495  $news_set = new ilSetting("news");
496  $enable_internal_rss = $news_set->get("enable_rss_for_internal");
497 
499  $this->getBlockType(),
500  "news_pd_period",
501  $_POST["news_pd_period"],
502  $ilUser->getId(),
504  );
505 
506  include_once("./Services/News/classes/class.ilNewsCache.php");
507  $cache = new ilNewsCache();
508  $cache->deleteEntry($ilUser->getId() . ":0");
509 
510  $ilCtrl->returnToParent($this);
511  }
512 
516  public function changeFeedSettings()
517  {
519  $lng = $this->lng;
521 
522  $form = $this->initPrivateSettingsForm();
523  if ($form->checkInput()) {
524  // Deactivate private Feed - just delete the password
525  if (!$form->getInput("enable_private_feed")) {
526  $ilUser->_setFeedPass($ilUser->getId(), "");
527  ilUtil::sendSuccess($lng->txt("priv_feed_disabled"), true);
528  // $ilCtrl->returnToParent($this);
529  $ilCtrl->redirect($this, "showFeedUrl");
530  } else {
531  $passwd = $form->getInput("desired_password");
532  require_once 'Services/User/classes/class.ilUserPasswordManager.php';
533  if (ilUserPasswordManager::getInstance()->verifyPassword($ilUser, $passwd)) {
534  $form->getItemByPostVar("desired_password")->setAlert($lng->txt("passwd_equals_ilpasswd"));
535  ilUtil::sendFailure($lng->txt("form_input_not_valid"));
536  } else {
537  $ilUser->_setFeedPass($ilUser->getId(), $passwd);
538  ilUtil::sendSuccess($lng->txt("saved_successfully"), true);
539  // $ilCtrl->returnToParent($this);
540  $ilCtrl->redirect($this, "showFeedUrl");
541  }
542  }
543  }
544 
545  $form->setValuesByPost();
546  return $this->editSettings($form);
547  }
548 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static get($a_type, $a_href="")
Get icon html.
__construct()
Constructor.
fillDataSection()
Fill data section.
static _getNewsItemsOfUser( $a_user_id, $a_only_public=false, $a_prevent_aggregation=false, $a_per=0, &$a_cnt=null)
Get all news items for a user.
static _write($a_type, $a_setting, $a_value, $a_user=0, $a_block_id=0)
Write setting to database.
This class represents a selection list property in a property form.
This class represents a property form user interface.
global $DIC
Definition: saml.php:7
handleView()
Handles show/hide notification view and removes notifications if hidden.
setDataSection($a_content)
Call this from overwritten fillDataSection(), if standard row based data is not used.
$_GET["client_id"]
setFooterInfo($a_footerinfo, $a_hide_and_icon=false)
Set Footer Info.
static _lookupUserPDPeriod($a_user_id)
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
This class represents a checkbox property in a property form.
setEnableNumInfo($a_enablenuminfo)
Set Enable Item Number Info.
BlockGUI class for block NewsForContext.
static prepareNewsDataFromCache($a_cres)
Prepare news data from cache.
editSettings(ilPropertyFormGUI $a_private_form=null)
Show settings screen.
user()
Definition: user.php:4
static getPasswordRequirementsInfo()
infotext for ilPasswordInputGUI setInfo()
News cache.
global $ilCtrl
Definition: ilias.php:18
setChecked($a_checked)
Set Checked.
static getScreenMode()
Get Screen Mode for current command.
showFeedUrl()
Show feed URL.
saveSettings()
Save settings.
if(isset($_POST['submit'])) $form
setTitle($a_title)
Set Title.
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 password property in a property form.
$ilUser
Definition: imgupload.php:18
const IL_SCREEN_CENTER
cancelSettings()
Cancel settings.
setOptions($a_options)
Set Options.
Create styles array
The data for the language used.
__construct()
Constructor.
getHTML()
Handle config status.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
getNewsData()
Get news for context.
addBlockCommand( $a_href, $a_text, $a_target="", $a_img="", $a_right_aligned=false, $a_checked=false, $a_html="")
Add Block Command.
addCloseCommand($a_content_block)
getData()
Get Data.
setLimit($a_limit)
Set Limit.
static isRepositoryObject()
Is block used in repository object?
settings()
Definition: settings.php:2
global $ilSetting
Definition: privfeed.php:17
static getBlockType()
Get block type.
static _lookupFeedHash($a_user_id, $a_create=false)
Lookup news feed hash for user.
BlockGUI class for (centered) Content on Personal Desktop.
changeFeedSettings()
change user password
BlockGUI class for block NewsForContext.
const IL_SCREEN_SIDE
executeCommand()
execute command
setRowTemplate($a_rowtemplatename, $a_rowtemplatedir="")
Set Row Template Name.
setEnableDetailRow($a_enabledetailrow)
Set EnableDetailRow.
$_POST["username"]
getTitle()
Get Title.
static getInstance()
Single method to reduce footprint (included files, created instances)
setRequired($a_required)
Set Required.
static _lookupDefaultPDPeriod()
getCurrentDetailLevel()
Get Current Detail Level.
getHTML()
Get bloch HTML code.