ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 {
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 {
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 {
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 {
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 7 => "1 " . $lng->txt("week"),
340 30 => "1 " . $lng->txt("month"),
341 366 => "1 " . $lng->txt("year"));
342
343 $unset = array();
344 foreach ($per_opts as $k => $opt) {
345 if (!$allow_shorter_periods && ($k < $default_per)) {
346 $unset[$k] = $k;
347 }
348 if (!$allow_longer_periods && ($k > $default_per)) {
349 $unset[$k] = $k;
350 }
351 }
352 foreach ($unset as $k) {
353 unset($per_opts[$k]);
354 }
355
356 $per_sel = new ilSelectInputGUI(
357 $lng->txt("news_pd_period"),
358 "news_pd_period"
359 );
360 //$per_sel->setInfo($lng->txt("news_pd_period_info"));
361 $per_sel->setOptions($per_opts);
362 $per_sel->setValue((int) $per);
363 $form->addItem($per_sel);
364
365 //$form->addCheckboxProperty($lng->txt("news_public_feed"), "notifications_public_feed",
366 // "1", $public_feed, $lng->txt("news_public_feed_info"));
367 //if ($this->getProperty("public_notifications_option"))
368 //{
369 // $form->addCheckboxProperty($lng->txt("news_notifications_public"), "notifications_public",
370 // "1", $public, $lng->txt("news_notifications_public_info"));
371 //}
372 $form->addCommandButton("saveSettings", $lng->txt("save"));
373 $form->addCommandButton("cancelSettings", $lng->txt("cancel"));
374
375 $returnForm = $form->getHTML();
376 }
377
378 if ($enable_private_feed) {
379 if (!$a_private_form) {
380 $a_private_form = $this->initPrivateSettingsForm();
381 }
382 $returnForm .= ($returnForm == "")
383 ? $a_private_form->getHTML()
384 : "<br>" . $a_private_form->getHTML();
385 }
386
387 return $returnForm;
388 }
389
390 protected function initPrivateSettingsForm()
391 {
395
396 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
397 $feed_form = new ilPropertyFormGUI();
398 $feed_form->setFormAction($ilCtrl->getFormaction($this));
399 $feed_form->setTitle($lng->txt("priv_feed_settings"));
400
401 $feed_form->setTableWidth("100%");
402
403 $enable_private_feed = new ilCheckboxInputGUI($lng->txt("news_enable_private_feed"), "enable_private_feed");
404 $enable_private_feed->setChecked($ilUser->_getFeedPass($ilUser->getId()));
405 $feed_form->addItem($enable_private_feed);
406
407 $passwd = new ilPasswordInputGUI($lng->txt("password"), "desired_password");
408 $passwd->setRequired(true);
409 $passwd->setInfo(ilUtil::getPasswordRequirementsInfo());
410 $enable_private_feed->addSubItem($passwd);
411
412 $feed_form->addCommandButton("changeFeedSettings", $lng->txt("save"));
413 $feed_form->addCommandButton("cancelSettings", $lng->txt("cancel"));
414
415 return $feed_form;
416 }
417
421 public function cancelSettings()
422 {
424
425 $ilCtrl->returnToParent($this);
426 }
427
431 public function saveSettings()
432 {
435
436 $news_set = new ilSetting("news");
437 $enable_internal_rss = $news_set->get("enable_rss_for_internal");
438
440 $this->getBlockType(),
441 "news_pd_period",
442 $_POST["news_pd_period"],
443 $ilUser->getId(),
444 $this->block_id
445 );
446
447 include_once("./Services/News/classes/class.ilNewsCache.php");
448 $cache = new ilNewsCache();
449 $cache->deleteEntry($ilUser->getId() . ":0");
450
451 $ilCtrl->returnToParent($this);
452 }
453
457 public function changeFeedSettings()
458 {
462
463 $form = $this->initPrivateSettingsForm();
464 if ($form->checkInput()) {
465 // Deactivate private Feed - just delete the password
466 if (!$form->getInput("enable_private_feed")) {
467 $ilUser->_setFeedPass($ilUser->getId(), "");
468 ilUtil::sendSuccess($lng->txt("priv_feed_disabled"), true);
469 // $ilCtrl->returnToParent($this);
470 $ilCtrl->redirect($this, "showFeedUrl");
471 } else {
472 $passwd = $form->getInput("desired_password");
473 require_once 'Services/User/classes/class.ilUserPasswordManager.php';
474 if (ilUserPasswordManager::getInstance()->verifyPassword($ilUser, $passwd)) {
475 $form->getItemByPostVar("desired_password")->setAlert($lng->txt("passwd_equals_ilpasswd"));
476 ilUtil::sendFailure($lng->txt("form_input_not_valid"));
477 } else {
478 $ilUser->_setFeedPass($ilUser->getId(), $passwd);
479 ilUtil::sendSuccess($lng->txt("saved_successfully"), true);
480 // $ilCtrl->returnToParent($this);
481 $ilCtrl->redirect($this, "showFeedUrl");
482 }
483 }
484 }
485
486 $form->setValuesByPost();
487 return $this->editSettings($form);
488 }
489}
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()
global $ilCtrl
Definition: ilias.php:18
global $ilSetting
Definition: privfeed.php:17
settings()
Definition: settings.php:2
$ilUser
Definition: imgupload.php:18
$DIC
Definition: xapitoken.php:46