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