ILIAS  release_7 Revision v7.30-3-g800a261c036
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
39 // NOT ilNewsForContextBlockGUI::__construct() !
41
42 $lng->loadLanguageModule("news");
43 include_once("./Services/News/classes/class.ilNewsItem.php");
44
45 $this->setLimit(5);
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 } else {
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();
69 } else {
71 }
72 }
73
74 $this->setTitle($lng->txt("news_internal_news"));
75 $this->setRowTemplate("tpl.block_row_news_for_context.html", "Services/News");
76
77 $this->setData($data);
78
79 $this->handleView();
80
81 // reset access check results
82 $ilAccess->setResults($this->acc_results);
83
84 $this->setPresentation(self::PRES_SEC_LIST);
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
116 public function getBlockType() : string
117 {
118 return self::$block_type;
119 }
120
124 protected function isRepositoryObject() : bool
125 {
126 return false;
127 }
128
132 public static function getScreenMode()
133 {
134 global $DIC;
135
136 $ilCtrl = $DIC->ctrl();
137
138 $cmd = $_GET["cmd"];
139 if ($cmd == "post" && is_array($_POST["cmd"])) {
140 $cmd = array_pop(array_keys($_POST["cmd"]));
141 }
142
143 switch ($cmd) {
144 case "showNews":
145 case "showFeedUrl":
146 case "editSettings":
147 case "changeFeedSettings":
148 return IL_SCREEN_CENTER;
149
150 default:
151 return IL_SCREEN_SIDE;
152 }
153 }
154
158 public function executeCommand()
159 {
160 $ilCtrl = $this->ctrl;
161
162 $next_class = $ilCtrl->getNextClass();
163 $cmd = $ilCtrl->getCmd("getHTML");
164
165 switch ($next_class) {
166 default:
167 return $this->$cmd();
168 }
169 }
170
174 public function fillDataSection()
175 {
176 if ($this->dynamic) {
177 $this->setDataSection($this->getDynamicReload());
178 } elseif (count($this->getData()) > 0) {
179 parent::fillDataSection();
180 } else {
181 $this->setEnableNumInfo(false);
182 $this->setDataSection($this->getOverview());
183 }
184 }
185
189 public function getHTML()
190 {
191 $ilCtrl = $this->ctrl;
194
195 // @todo: find another solution for this
196 //$this->setFooterInfo($lng->txt("news_block_information"), true);
197
198 $news_set = new ilSetting("news");
199 $enable_internal_rss = $news_set->get("enable_rss_for_internal");
200 $allow_shorter_periods = $news_set->get("allow_shorter_periods");
201 $allow_longer_periods = $news_set->get("allow_longer_periods");
202 $enable_private_feed = $news_set->get("enable_private_feed");
203
204 // subscribe/unsibscribe link
205 include_once("./Services/News/classes/class.ilNewsSubscription.php");
206
207 // show feed url
208 if ($enable_internal_rss) {
209 include_once("./Services/News/classes/class.ilRSSButtonGUI.php");
210 // @todo: rss icon html ilRSSButtonGUI::get(ilRSSButtonGUI::ICON_RSS)
211 $this->addBlockCommand(
212 $ilCtrl->getLinkTarget($this, "showFeedUrl"),
213 $lng->txt("news_get_feed_url")
214 );
215 }
216
217 if ($allow_shorter_periods || $allow_longer_periods || $enable_private_feed) {
218 $this->addBlockCommand(
219 $ilCtrl->getLinkTarget($this, "editSettings"),
220 $lng->txt("settings")
221 );
222 }
223
224 $en = "";
225 if ($ilUser->getPref("il_feed_js") == "n") {
226 $en = $this->getJSEnabler();
227 }
228
229 return ilBlockGUI::getHTML() . $en;
230 }
231
232
236 public function showFeedUrl()
237 {
239 $ilCtrl = $this->ctrl;
242
243 $news_set = new ilSetting("news");
244
245
246 include_once("./Services/News/classes/class.ilNewsItem.php");
247
248 if ($news_set->get("enable_private_feed")) {
249 $tpl = new ilTemplate("tpl.show_priv_feed_url.html", true, true, "Services/News");
250
251 $tpl->setVariable("TXT_PRIV_TITLE", $lng->txt("news_get_priv_feed_title"));
252
253 // #14365
254 if ($ilUser->_getFeedPass($GLOBALS['DIC']['ilUser']->getId())) {
255 $tpl->setVariable("TXT_PRIV_INFO", $lng->txt("news_get_priv_feed_info"));
256 $tpl->setVariable("TXT_PRIV_FEED_URL", $lng->txt("news_feed_url"));
257 $tpl->setVariable(
258 "VAL_PRIV_FEED_URL",
259 str_replace("://", "://" . $ilUser->getLogin() . ":-password-@", ILIAS_HTTP_PATH) . "/privfeed.php?client_id=" . rawurlencode(CLIENT_ID) . "&user_id=" . $ilUser->getId() .
260 "&hash=" . ilObjUser::_lookupFeedHash($ilUser->getId(), true)
261 );
262 $tpl->setVariable(
263 "VAL_PRIV_FEED_URL_TXT",
264 str_replace("://", "://" . $ilUser->getLogin() . ":-password-@", ILIAS_HTTP_PATH) . "/privfeed.php?client_id=" . rawurlencode(CLIENT_ID) . "&<br />user_id=" . $ilUser->getId() .
265 "&hash=" . ilObjUser::_lookupFeedHash($ilUser->getId(), true)
266 );
267 } else {
268 $tpl->setVariable("TXT_PRIV_INFO", $lng->txt("news_inactive_private_feed_info"));
269 $tpl->setVariable("EDIT_SETTINGS_URL", $ilCtrl->getLinkTarget($this, "editSettings"));
270 $tpl->setVariable("EDIT_SETTINGS_TXT", $lng->txt("news_edit_news_settings"));
271 }
272 } else {
273 $tpl = new ilTemplate("tpl.show_feed_url.html", true, true, "Services/News");
274 }
275 $tpl->setVariable("TXT_TITLE", $lng->txt("news_get_feed_title"));
276 $tpl->setVariable("TXT_INFO", $lng->txt("news_get_feed_info"));
277 $tpl->setVariable("TXT_FEED_URL", $lng->txt("news_feed_url"));
278 $tpl->setVariable(
279 "VAL_FEED_URL",
280 ILIAS_HTTP_PATH . "/feed.php?client_id=" . rawurlencode(CLIENT_ID) . "&user_id=" . $ilUser->getId() .
281 "&hash=" . ilObjUser::_lookupFeedHash($ilUser->getId(), true)
282 );
283 $tpl->setVariable(
284 "VAL_FEED_URL_TXT",
285 ILIAS_HTTP_PATH . "/feed.php?client_id=" . rawurlencode(CLIENT_ID) . "&<br />user_id=" . $ilUser->getId() .
286 "&hash=" . ilObjUser::_lookupFeedHash($ilUser->getId(), true)
287 );
288
289 $content_block = new ilDashboardContentBlockGUI();
290 $content_block->setContent($tpl->get());
291 $content_block->setTitle($lng->txt("news_internal_news"));
292
293 return $content_block->getHTML();
294 }
295
299 public function showNews()
300 {
301 // workaround for dynamic mode (if cache is disabled, showNews has no data)
302 // if (empty(self::$st_data))
303 // {
304 // $this->setData($this->getNewsData());
305 // }
306
307 return parent::showNews();
308 }
309
313 public function editSettings(ilPropertyFormGUI $a_private_form = null)
314 {
317 $ilCtrl = $this->ctrl;
319
320 $news_set = new ilSetting("news");
321 $enable_internal_rss = $news_set->get("enable_rss_for_internal");
322 $allow_shorter_periods = $news_set->get("allow_shorter_periods");
323 $allow_longer_periods = $news_set->get("allow_longer_periods");
324 $enable_private_feed = $news_set->get("enable_private_feed");
325
326 if (!$a_private_form && ($allow_shorter_periods || $allow_longer_periods)) {
327 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
328 $form = new ilPropertyFormGUI();
329 $form->setFormAction($ilCtrl->getFormaction($this));
330 $form->setTitle($lng->txt("news_settings"));
331
332 include_once("./Services/News/classes/class.ilNewsItem.php");
333 $default_per = ilNewsItem::_lookupDefaultPDPeriod();
335
336 $form->setTableWidth("100%");
337
338 $per_opts = array(
339 2 => "2 " . $lng->txt("days"),
340 3 => "3 " . $lng->txt("days"),
341 5 => "5 " . $lng->txt("days"),
342 7 => "1 " . $lng->txt("week"),
343 14 => "2 " . $lng->txt("weeks"),
344 30 => "1 " . $lng->txt("month"),
345 60 => "2 " . $lng->txt("months"),
346 120 => "4 " . $lng->txt("months"),
347 180 => "6 " . $lng->txt("months"),
348 366 => "1 " . $lng->txt("year"));
349
350 $unset = array();
351 foreach ($per_opts as $k => $opt) {
352 if (!$allow_shorter_periods && ($k < $default_per)) {
353 $unset[$k] = $k;
354 }
355 if (!$allow_longer_periods && ($k > $default_per)) {
356 $unset[$k] = $k;
357 }
358 }
359 foreach ($unset as $k) {
360 unset($per_opts[$k]);
361 }
362
363 $per_sel = new ilSelectInputGUI(
364 $lng->txt("news_pd_period"),
365 "news_pd_period"
366 );
367 //$per_sel->setInfo($lng->txt("news_pd_period_info"));
368 $per_sel->setOptions($per_opts);
369 $per_sel->setValue((int) $per);
370 $form->addItem($per_sel);
371
372 //$form->addCheckboxProperty($lng->txt("news_public_feed"), "notifications_public_feed",
373 // "1", $public_feed, $lng->txt("news_public_feed_info"));
374 //if ($this->getProperty("public_notifications_option"))
375 //{
376 // $form->addCheckboxProperty($lng->txt("news_notifications_public"), "notifications_public",
377 // "1", $public, $lng->txt("news_notifications_public_info"));
378 //}
379 $form->addCommandButton("saveSettings", $lng->txt("save"));
380 $form->addCommandButton("cancelSettings", $lng->txt("cancel"));
381
382 $returnForm = $form->getHTML();
383 }
384
385 if ($enable_private_feed) {
386 if (!$a_private_form) {
387 $a_private_form = $this->initPrivateSettingsForm();
388 }
389 $returnForm .= ($returnForm == "")
390 ? $a_private_form->getHTML()
391 : "<br>" . $a_private_form->getHTML();
392 }
393
394 return $returnForm;
395 }
396
397 protected function initPrivateSettingsForm()
398 {
399 $ilCtrl = $this->ctrl;
402
403 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
404 $feed_form = new ilPropertyFormGUI();
405 $feed_form->setFormAction($ilCtrl->getFormaction($this));
406 $feed_form->setTitle($lng->txt("priv_feed_settings"));
407
408 $feed_form->setTableWidth("100%");
409
410 $enable_private_feed = new ilCheckboxInputGUI($lng->txt("news_enable_private_feed"), "enable_private_feed");
411 $enable_private_feed->setChecked($ilUser->_getFeedPass($ilUser->getId()));
412 $feed_form->addItem($enable_private_feed);
413
414 $passwd = new ilPasswordInputGUI($lng->txt("password"), "desired_password");
415 $passwd->setRequired(true);
416 $passwd->setInfo(ilUtil::getPasswordRequirementsInfo());
417 $enable_private_feed->addSubItem($passwd);
418
419 $feed_form->addCommandButton("changeFeedSettings", $lng->txt("save"));
420 $feed_form->addCommandButton("cancelSettings", $lng->txt("cancel"));
421
422 return $feed_form;
423 }
424
428 public function cancelSettings()
429 {
430 $ilCtrl = $this->ctrl;
431
432 $ilCtrl->returnToParent($this);
433 }
434
438 public function saveSettings()
439 {
440 $ilCtrl = $this->ctrl;
442
443 $news_set = new ilSetting("news");
444 $enable_internal_rss = $news_set->get("enable_rss_for_internal");
445
447 $this->getBlockType(),
448 "news_pd_period",
449 $_POST["news_pd_period"],
450 $ilUser->getId(),
451 $this->block_id
452 );
453
454 include_once("./Services/News/classes/class.ilNewsCache.php");
455 $cache = new ilNewsCache();
456 $cache->deleteEntry($ilUser->getId() . ":0");
457
458 $ilCtrl->returnToParent($this);
459 }
460
464 public function changeFeedSettings()
465 {
466 $ilCtrl = $this->ctrl;
469
470 $form = $this->initPrivateSettingsForm();
471 if ($form->checkInput()) {
472 // Deactivate private Feed - just delete the password
473 if (!$form->getInput("enable_private_feed")) {
474 $ilUser->_setFeedPass($ilUser->getId(), "");
475 ilUtil::sendSuccess($lng->txt("priv_feed_disabled"), true);
476 // $ilCtrl->returnToParent($this);
477 $ilCtrl->redirect($this, "showFeedUrl");
478 } else {
479 $passwd = $form->getInput("desired_password");
480 require_once 'Services/User/classes/class.ilUserPasswordManager.php';
481 if (ilUserPasswordManager::getInstance()->verifyPassword($ilUser, $passwd)) {
482 $form->getItemByPostVar("desired_password")->setAlert($lng->txt("passwd_equals_ilpasswd"));
483 ilUtil::sendFailure($lng->txt("form_input_not_valid"));
484 } else {
485 $ilUser->_setFeedPass($ilUser->getId(), $passwd);
486 ilUtil::sendSuccess($lng->txt("saved_successfully"), true);
487 // $ilCtrl->returnToParent($this);
488 $ilCtrl->redirect($this, "showFeedUrl");
489 }
490 }
491 }
492
493 $form->setValuesByPost();
494 return $this->editSettings($form);
495 }
496}
user()
Definition: user.php:4
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
$_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.
setData($a_data)
Set Data.
setPresentation(int $type)
Set presentation.
__construct()
Constructor.
setDataSection($a_content)
Call this from overwritten fillDataSection(), if standard row based data is not used.
addBlockCommand(string $a_href, string $a_text, string $a_onclick="")
Add Block Command.
setTitle($a_title)
Set Title.
setEnableNumInfo($a_enablenuminfo)
Set Enable Item Number Info.
getData()
Get Data.
getHTML()
Get HTML.
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 (centered) Content on Personal Desktop.
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 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.
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.
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()
const CLIENT_ID
Definition: constants.php:39
global $DIC
Definition: goto.php:24
$ilUser
Definition: imgupload.php:18
global $ilSetting
Definition: privfeed.php:17
settings()
Definition: settings.php:2