ILIAS  release_8 Revision v8.24
class.ilPDNewsBlockGUI.php
Go to the documentation of this file.
1<?php
2
20
28{
29 public static string $block_type = "pdnews";
30 protected bool $cache_hit = false;
32 protected bool $dynamic = false;
33 protected bool $acc_results = false;
35
36 public function __construct()
37 {
38 global $DIC;
39
41
42 $lng = $DIC->language();
43 $ilAccess = $DIC->access();
44 $this->obj_definition = $DIC["objDefinition"];
45
46 // NOT ilNewsForContextBlockGUI::__construct() !
48
49 $lng->loadLanguageModule("news");
50 $this->setLimit(5);
51
52 $this->dynamic = false;
53
54 $this->std_request = new StandardGUIRequest(
55 $DIC->http(),
56 $DIC->refinery()
57 );
58
59 $this->acache = new ilNewsCache();
60 $cres = unserialize($this->acache->getEntry($this->user->getId() . ":0"), ["allowed_classes" => false]);
61 $this->cache_hit = false;
62 if (is_array($cres) && $this->acache->getLastAccessStatus() === "hit") {
63 self::$st_data = ilNewsItem::prepareNewsDataFromCache($cres);
64 $this->cache_hit = true;
65 }
66
67 if (!$this->cache_hit && $this->getDynamic()) {
68 $this->dynamic = true;
69 $data = [];
70 } else {
71 // do not ask two times for the data (e.g. if user displays a
72 // single item on the personal desktop and the news block is
73 // displayed at the same time)
74 if (empty(self::$st_data)) {
75 self::$st_data = $this->getNewsData();
76 }
78 }
79
80 $this->setTitle($lng->txt("news_internal_news"));
81 $this->setRowTemplate("tpl.block_row_news_for_context.html", "Services/News");
82
83 $this->setData($data);
84
85 $this->handleView();
86
87 // reset access check results
88 $ilAccess->setResults((array) $this->acc_results);
89
90 $this->setPresentation(self::PRES_SEC_LIST);
91 }
92
93 public function getNewsData(): array
94 {
96
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
115 public function getBlockType(): string
116 {
117 return self::$block_type;
118 }
119
120 public static function getScreenMode(): string
121 {
122 global $DIC;
123
124 $cmd = $DIC->ctrl()->getCmd();
125
126 switch ($cmd) {
127 case "showNews":
128 case "showFeedUrl":
129 case "editSettings":
130 case "changeFeedSettings":
131 return IL_SCREEN_CENTER;
132
133 default:
134 return IL_SCREEN_SIDE;
135 }
136 }
137
138 public function executeCommand()
139 {
140 $ilCtrl = $this->ctrl;
141
142 $next_class = $ilCtrl->getNextClass();
143 $cmd = $ilCtrl->getCmd("getHTML");
144
145 switch ($next_class) {
146 default:
147 return $this->$cmd();
148 }
149 }
150
151 public function fillDataSection(): void
152 {
153 if ($this->dynamic) {
154 $this->setDataSection($this->getDynamicReload());
155 } elseif (count($this->getData()) > 0) {
156 parent::fillDataSection();
157 } else {
158 $this->setEnableNumInfo(false);
159 $this->setDataSection($this->getOverview());
160 }
161 }
162
163 public function getHTML(): string
164 {
165 $ilCtrl = $this->ctrl;
168
169 // @todo: find another solution for this
170 //$this->setFooterInfo($lng->txt("news_block_information"), true);
171
172 $news_set = new ilSetting("news");
173 $enable_internal_rss = $news_set->get("enable_rss_for_internal");
174 $allow_shorter_periods = $news_set->get("allow_shorter_periods");
175 $allow_longer_periods = $news_set->get("allow_longer_periods");
176 $enable_private_feed = $news_set->get("enable_private_feed");
177 // show feed url
178 if ($enable_internal_rss) {
179 // @todo: rss icon html ilRSSButtonGUI::get(ilRSSButtonGUI::ICON_RSS)
180 $this->addBlockCommand(
181 $ilCtrl->getLinkTarget($this, "showFeedUrl"),
182 $lng->txt("news_get_feed_url")
183 );
184 }
185
186 if ($allow_shorter_periods || $allow_longer_periods || $enable_private_feed) {
187 $this->addBlockCommand(
188 $ilCtrl->getLinkTarget($this, "editSettings"),
189 $lng->txt("settings")
190 );
191 }
192
193 $en = "";
194 if ($ilUser->getPref("il_feed_js") === "n") {
195 $en = $this->getJSEnabler();
196 }
197
198 return ilBlockGUI::getHTML() . $en;
199 }
200
201
202 public function showFeedUrl(): string
203 {
205 $ilCtrl = $this->ctrl;
207
208 $news_set = new ilSetting("news");
209
210 if ($news_set->get("enable_private_feed")) {
211 $tpl = new ilTemplate("tpl.show_priv_feed_url.html", true, true, "Services/News");
212
213 $tpl->setVariable("TXT_PRIV_TITLE", $lng->txt("news_get_priv_feed_title"));
214
215 // #14365
216 if (ilObjUser::_getFeedPass($GLOBALS['DIC']['ilUser']->getId())) {
217 $tpl->setVariable("TXT_PRIV_INFO", $lng->txt("news_get_priv_feed_info"));
218 $tpl->setVariable("TXT_PRIV_FEED_URL", $lng->txt("news_feed_url"));
220 "VAL_PRIV_FEED_URL",
221 str_replace("://", "://" . $ilUser->getLogin() . ":-password-@", ILIAS_HTTP_PATH) . "/privfeed.php?client_id=" . rawurlencode(CLIENT_ID) . "&user_id=" . $ilUser->getId() .
222 "&hash=" . ilObjUser::_lookupFeedHash($ilUser->getId(), true)
223 );
225 "VAL_PRIV_FEED_URL_TXT",
226 str_replace("://", "://" . $ilUser->getLogin() . ":-password-@", ILIAS_HTTP_PATH) . "/privfeed.php?client_id=" . rawurlencode(CLIENT_ID) . "&<br />user_id=" . $ilUser->getId() .
227 "&hash=" . ilObjUser::_lookupFeedHash($ilUser->getId(), true)
228 );
229 } else {
230 $tpl->setVariable("TXT_PRIV_INFO", $lng->txt("news_inactive_private_feed_info"));
231 $tpl->setVariable("EDIT_SETTINGS_URL", $ilCtrl->getLinkTarget($this, "editSettings"));
232 $tpl->setVariable("EDIT_SETTINGS_TXT", $lng->txt("news_edit_news_settings"));
233 }
234 } else {
235 $tpl = new ilTemplate("tpl.show_feed_url.html", true, true, "Services/News");
236 }
237 $tpl->setVariable("TXT_TITLE", $lng->txt("news_get_feed_title"));
238 $tpl->setVariable("TXT_INFO", $lng->txt("news_get_feed_info"));
239 $tpl->setVariable("TXT_FEED_URL", $lng->txt("news_feed_url"));
241 "VAL_FEED_URL",
242 ILIAS_HTTP_PATH . "/feed.php?client_id=" . rawurlencode(CLIENT_ID) . "&user_id=" . $ilUser->getId() .
243 "&hash=" . ilObjUser::_lookupFeedHash($ilUser->getId(), true)
244 );
246 "VAL_FEED_URL_TXT",
247 ILIAS_HTTP_PATH . "/feed.php?client_id=" . rawurlencode(CLIENT_ID) . "&<br />user_id=" . $ilUser->getId() .
248 "&hash=" . ilObjUser::_lookupFeedHash($ilUser->getId(), true)
249 );
250
251
252 $panel = $this->ui->factory()->panel()->standard(
253 $lng->txt("news_internal_news"),
254 $this->ui->factory()->legacy($tpl->get())
255 );
256
257 return $this->ui->renderer()->render($panel);
258 }
259
260 public function editSettings(ilPropertyFormGUI $a_private_form = null): string
261 {
264 $ilCtrl = $this->ctrl;
265 $returnForm = "";
266
267 $news_set = new ilSetting("news");
268 $allow_shorter_periods = $news_set->get("allow_shorter_periods");
269 $allow_longer_periods = $news_set->get("allow_longer_periods");
270 $enable_private_feed = $news_set->get("enable_private_feed");
271
272 if (!$a_private_form && ($allow_shorter_periods || $allow_longer_periods)) {
273 $form = new ilPropertyFormGUI();
274 $form->setFormAction($ilCtrl->getFormAction($this));
275 $form->setTitle($lng->txt("news_settings"));
276
277 $default_per = ilNewsItem::_lookupDefaultPDPeriod();
279
280 $form->setTableWidth("100%");
281
282 $per_opts = [
283 2 => "2 " . $lng->txt("days"),
284 3 => "3 " . $lng->txt("days"),
285 5 => "5 " . $lng->txt("days"),
286 7 => "1 " . $lng->txt("week"),
287 14 => "2 " . $lng->txt("weeks"),
288 30 => "1 " . $lng->txt("month"),
289 60 => "2 " . $lng->txt("months"),
290 120 => "4 " . $lng->txt("months"),
291 180 => "6 " . $lng->txt("months"),
292 366 => "1 " . $lng->txt("year")
293 ];
294
295 $unset = [];
296 foreach ($per_opts as $k => $opt) {
297 if (!$allow_shorter_periods && ($k < $default_per)) {
298 $unset[$k] = $k;
299 }
300 if (!$allow_longer_periods && ($k > $default_per)) {
301 $unset[$k] = $k;
302 }
303 }
304 foreach ($unset as $k) {
305 unset($per_opts[$k]);
306 }
307
308 $per_sel = new ilSelectInputGUI(
309 $lng->txt("news_pd_period"),
310 "news_pd_period"
311 );
312 $per_sel->setOptions($per_opts);
313 $per_sel->setValue((string) $per);
314 $form->addItem($per_sel);
315
316 $form->addCommandButton("saveSettings", $lng->txt("save"));
317 $form->addCommandButton("cancelSettings", $lng->txt("cancel"));
318
319 $returnForm = $form->getHTML();
320 }
321
322 if ($enable_private_feed) {
323 if (!$a_private_form) {
324 $a_private_form = $this->initPrivateSettingsForm();
325 }
326 $returnForm .= ($returnForm === "")
327 ? $a_private_form->getHTML()
328 : "<br>" . $a_private_form->getHTML();
329 }
330
331 return $returnForm;
332 }
333
335 {
336 $ilCtrl = $this->ctrl;
339
340 $feed_form = new ilPropertyFormGUI();
341 $feed_form->setFormAction($ilCtrl->getFormAction($this));
342 $feed_form->setTitle($lng->txt("priv_feed_settings"));
343
344 $feed_form->setTableWidth("100%");
345
346 $enable_private_feed = new ilCheckboxInputGUI($lng->txt("news_enable_private_feed"), "enable_private_feed");
347 $enable_private_feed->setChecked((bool) ilObjUser::_getFeedPass($ilUser->getId()));
348 $feed_form->addItem($enable_private_feed);
349
350 $passwd = new ilPasswordInputGUI($lng->txt("password"), "desired_password");
351 $passwd->setRequired(true);
353 $enable_private_feed->addSubItem($passwd);
354
355 $feed_form->addCommandButton("changeFeedSettings", $lng->txt("save"));
356 $feed_form->addCommandButton("cancelSettings", $lng->txt("cancel"));
357
358 return $feed_form;
359 }
360
361 public function saveSettings(): string
362 {
363 $ilCtrl = $this->ctrl;
365
366 $news_set = new ilSetting("news");
367
369 $this->getBlockType(),
370 "news_pd_period",
371 $this->std_request->getDashboardPeriod(),
372 $ilUser->getId(),
373 0
374 );
375
376 $cache = new ilNewsCache();
377 $cache->deleteEntry($ilUser->getId() . ":0");
378
379 $ilCtrl->returnToParent($this);
380 return "";
381 }
382
383 public function changeFeedSettings(): string
384 {
385 $ilCtrl = $this->ctrl;
388
389 $form = $this->initPrivateSettingsForm();
390 if ($form->checkInput()) {
391 // Deactivate private Feed - just delete the password
392 if (!$form->getInput("enable_private_feed")) {
393 ilObjUser::_setFeedPass($ilUser->getId(), "");
394 $this->main_tpl->setOnScreenMessage('success', $lng->txt("priv_feed_disabled"), true);
395 // $ilCtrl->returnToParent($this);
396 $ilCtrl->redirect($this, "showFeedUrl");
397 } else {
398 $passwd = $form->getInput("desired_password");
399 if (ilUserPasswordManager::getInstance()->verifyPassword($ilUser, $passwd)) {
400 $form->getItemByPostVar("desired_password")->setAlert($lng->txt("passwd_equals_ilpasswd"));
401 $this->main_tpl->setOnScreenMessage('failure', $lng->txt("form_input_not_valid"));
402 } else {
403 ilObjUser::_setFeedPass($ilUser->getId(), $passwd);
404 $this->main_tpl->setOnScreenMessage('success', $lng->txt("saved_successfully"), true);
405 $ilCtrl->redirect($this, "showFeedUrl");
406 }
407 }
408 }
409
410 $form->setValuesByPost();
411 return $this->editSettings($form);
412 }
413}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:514
const IL_SCREEN_SIDE
const IL_SCREEN_CENTER
setData(array $a_data)
ilLanguage $lng
setDataSection(string $a_content)
Call this from overwritten fillDataSection(), if standard row based data is not used.
setTitle(string $a_title)
setPresentation(int $type)
ilTemplate $tpl
addBlockCommand(string $a_href, string $a_text, string $a_onclick="")
ilObjUser $user
setLimit(int $a_limit)
setEnableNumInfo(bool $a_enablenuminfo)
setRowTemplate(string $a_rowtemplatename, string $a_rowtemplatedir="")
Set Row Template Name.
static _write(string $a_type, string $a_setting, string $a_value, int $a_user=0, int $a_block_id=0)
Write setting to database.
This class represents a checkbox property in a property form.
getNextClass($a_gui_class=null)
@inheritDoc
loadLanguageModule(string $a_module)
Load language module.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
BlockGUI class for block NewsForContext.
handleView()
Handles show/hide notification view and removes notifications if hidden.
static _lookupUserPDPeriod(int $a_user_id)
static _getNewsItemsOfUser(int $a_user_id, bool $a_only_public=false, bool $a_prevent_aggregation=false, int $a_per=0, array &$a_cnt=[])
Get all news items for a user.
static prepareNewsDataFromCache(array $a_cres)
Prepare news data from cache.
static _lookupDefaultPDPeriod()
static _lookupFeedHash(int $a_user_id, bool $a_create=false)
Lookup news feed hash for user.
static _setFeedPass(int $a_user_id, string $a_password)
Set news feed password for user.
static _getFeedPass(int $a_user_id)
Lookup news feed password for user.
BlockGUI class for block NewsForContext.
StandardGUIRequest $std_request
fillDataSection()
Standard implementation for row based data.
editSettings(ilPropertyFormGUI $a_private_form=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a property form user interface.
static getPasswordRequirementsInfo()
infotext for ilPasswordInputGUI setInfo()
This class represents a selection list property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
special template class to simplify handling of ITX/PEAR
get(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
Returns a block with all replacements done.
static getInstance()
Singleton method to reduce footprint (included files, created instances)
const CLIENT_ID
Definition: constants.php:41
global $DIC
Definition: feed.php:28
if(isset($_FILES['img_file']) &&is_array($_FILES['img_file'])) $panel
Definition: imgupload.php:198
$ilUser
Definition: imgupload.php:34
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc