ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 static $block_type = "pdnews";
19 static $st_data;
20 protected $acc_results = false;
21
25 function __construct()
26 {
27 global $ilCtrl, $lng, $ilUser, $ilBench, $ilAccess, $ilCtrl;
28
29 $ilBench->start("News", "ilPDNewsBlockGUI_Constructor");
30 $news_set = new ilSetting("news");
31
32 // NOT ilNewsForContextBlockGUI::__construct() !
34
35 $lng->loadLanguageModule("news");
36 include_once("./Services/News/classes/class.ilNewsItem.php");
37
38 $this->setLimit(5);
40
41 $this->dynamic = false;
42
43 // store current access check results
44// $this->acc_results = $ilAccess->getResults();
45
46 // read access cache
47// $this->acc_cache_hit = $ilAccess->readCache(
48// ((int) $news_set->get("acc_cache_mins")) * 60);
49
50 include_once("./Services/News/classes/class.ilNewsCache.php");
51 $this->acache = new ilNewsCache();
52 $cres = unserialize($this->acache->getEntry($ilUser->getId().":0"));
53 $this->cache_hit = false;
54 if ($this->acache->getLastAccessStatus() == "hit" && is_array($cres))
55 {
56 self::$st_data = ilNewsItem::prepareNewsDataFromCache($cres);;
57 $this->cache_hit = true;
58 }
59
60 if ($this->getDynamic() && !$this->cache_hit)
61 {
62 $this->dynamic = true;
63 $data = array();
64 }
65 else if ($this->getCurrentDetailLevel() > 0)
66 {
67 // do not ask two times for the data (e.g. if user displays a
68 // single item on the personal desktop and the news block is
69 // displayed at the same time)
70 if (empty(self::$st_data))
71 {
72 self::$st_data = $this->getNewsData();
74 }
75 else
76 {
78 }
79 }
80 else
81 {
82 $data = array();
83 }
84
85 $this->setTitle($lng->txt("news_internal_news"));
86 $this->setRowTemplate("tpl.block_row_news_for_context.html", "Services/News");
87
88 $this->setData($data);
89
90 $this->handleView();
91
92 // reset access check results
93 $ilAccess->setResults($this->acc_results);
94
95 $ilBench->stop("News", "ilPDNewsBlockGUI_Constructor");
96 }
97
101 function getNewsData()
102 {
103 global $ilUser, $ilAccess;
104
105 include_once("./Services/News/classes/class.ilNewsCache.php");
106 $this->acache = new ilNewsCache();
107
110 false, $per);
111// if (!$this->acc_cache_hit)
112// {
113// $ilAccess->storeCache();
114// }
115
116 $this->acache->storeEntry($ilUser->getId().":0",
117 serialize($data));
118
119 return $data;
120 }
121
127 static function getBlockType()
128 {
129 return self::$block_type;
130 }
131
137 static function isRepositoryObject()
138 {
139 return false;
140 }
141
145 static function getScreenMode()
146 {
147 global $ilCtrl;
148
149 $cmd = $_GET["cmd"];
150 if($cmd == "post" && is_array($_POST["cmd"]))
151 {
152 $cmd = array_pop(array_keys($_POST["cmd"]));
153 }
154
155 switch($cmd)
156 {
157 case "showNews":
158 case "showFeedUrl":
159 case "editSettings":
160 case "changeFeedSettings":
161 return IL_SCREEN_CENTER;
162
163 default:
164 return IL_SCREEN_SIDE;
165 }
166 }
167
171 function executeCommand()
172 {
173 global $ilCtrl;
174
175 $next_class = $ilCtrl->getNextClass();
176 $cmd = $ilCtrl->getCmd("getHTML");
177
178 switch ($next_class)
179 {
180 default:
181 return $this->$cmd();
182 }
183 }
184
189 {
190 global $ilBench;
191
192 if ($this->dynamic)
193 {
194 $this->setDataSection($this->getDynamicReload());
195 }
196 else if ($this->getCurrentDetailLevel() > 1 && count($this->getData()) > 0)
197 {
198 $ilBench->start("News", "ilPDNewsBlockGUI_fillDataSection");
199 parent::fillDataSection();
200 $ilBench->stop("News", "ilPDNewsBlockGUI_fillDataSection");
201 }
202 else
203 {
204 $this->setEnableNumInfo(false);
205 if (count($this->getData()) == 0)
206 {
207 $this->setEnableDetailRow(false);
208 }
209 $this->setDataSection($this->getOverview());
210 }
211 }
212
216 function getHTML()
217 {
218 global $ilCtrl, $lng, $ilUser;
219
220 // set footer info
221 $this->setFooterInfo($lng->txt("news_block_information"), true);
222
223 $news_set = new ilSetting("news");
224 $enable_internal_rss = $news_set->get("enable_rss_for_internal");
225 $allow_shorter_periods = $news_set->get("allow_shorter_periods");
226 $allow_longer_periods = $news_set->get("allow_longer_periods");
227 $enable_private_feed = $news_set->get("enable_private_feed");
228
229 // subscribe/unsibscribe link
230 include_once("./Services/News/classes/class.ilNewsSubscription.php");
231
232 // show feed url
233 if ($enable_internal_rss)
234 {
235 include_once("./Services/News/classes/class.ilRSSButtonGUI.php");
236 $this->addBlockCommand(
237 $ilCtrl->getLinkTarget($this, "showFeedUrl"),
238 $lng->txt("news_get_feed_url"), "", "", true, false, ilRSSButtonGUI::get(ilRSSButtonGUI::ICON_RSS));
239 }
240
241 if ($allow_shorter_periods || $allow_longer_periods || $enable_private_feed)
242 {
243 $this->addBlockCommand(
244 $ilCtrl->getLinkTarget($this, "editSettings"),
245 $lng->txt("settings"));
246 }
247
249
250 if ($per > 0)
251 {
252 switch ($per)
253 {
254 case 2:
255 case 3:
256 case 5: $per_str = sprintf($lng->txt("news_period_x_days"), $per); break;
257 case 7: $per_str = $lng->txt("news_period_1_week"); break;
258 case 14: $per_str = sprintf($lng->txt("news_period_x_weeks"), 2); break;
259 case 30: $per_str = $lng->txt("news_period_1_month"); break;
260 case 60: $per_str = sprintf($lng->txt("news_period_x_months"), 2); break;
261 case 120: $per_str = sprintf($lng->txt("news_period_x_months"), 4); break;
262 case 180: $per_str = sprintf($lng->txt("news_period_x_months"), 6); break;
263 case 366: $per_str = $lng->txt("news_period_1_year"); break;
264 }
265 if ($per_str != "")
266 {
267 $this->setTitle($this->getTitle().' <span style="font-weight:normal;">- '.$per_str."</span>");
268 }
269 }
270
271 if ($this->getCurrentDetailLevel() == 0)
272 {
273 return "";
274 }
275
276 $en = "";
277 if ($ilUser->getPref("il_feed_js") == "n")
278 {
279 $en = $this->getJSEnabler();
280 }
281
282 return ilBlockGUI::getHTML().$en;
283 }
284
285
289 function showFeedUrl()
290 {
291 global $lng, $ilCtrl, $ilUser, $ilSetting;
292
293 $news_set = new ilSetting("news");
294
295
296 include_once("./Services/News/classes/class.ilNewsItem.php");
297
298 if ($news_set->get("enable_private_feed"))
299 {
300 $tpl = new ilTemplate("tpl.show_priv_feed_url.html", true, true, "Services/News");
301
302 $tpl->setVariable("TXT_PRIV_TITLE", $lng->txt("news_get_priv_feed_title"));
303
304 // #14365
305 if($ilUser->_getFeedPass($GLOBALS['DIC']['ilUser']->getId()))
306 {
307 $tpl->setVariable("TXT_PRIV_INFO", $lng->txt("news_get_priv_feed_info"));
308 $tpl->setVariable("TXT_PRIV_FEED_URL", $lng->txt("news_feed_url"));
309 $tpl->setVariable("VAL_PRIV_FEED_URL",
310 str_replace("://", "://" . $ilUser->getLogin() . ":-password-@", ILIAS_HTTP_PATH)."/privfeed.php?client_id=".rawurlencode(CLIENT_ID)."&user_id=".$ilUser->getId().
311 "&hash=".ilObjUser::_lookupFeedHash($ilUser->getId(), true));
312 $tpl->setVariable("VAL_PRIV_FEED_URL_TXT",
313 str_replace("://", "://" . $ilUser->getLogin() . ":-password-@", ILIAS_HTTP_PATH)."/privfeed.php?client_id=".rawurlencode(CLIENT_ID)."&<br />user_id=".$ilUser->getId().
314 "&hash=".ilObjUser::_lookupFeedHash($ilUser->getId(), true));
315 }
316 else
317 {
318 $tpl->setVariable("TXT_PRIV_INFO", $lng->txt("news_inactive_private_feed_info"));
319 $tpl->setVariable("EDIT_SETTINGS_URL", $ilCtrl->getLinkTarget($this, "editSettings"));
320 $tpl->setVariable("EDIT_SETTINGS_TXT", $lng->txt("news_edit_news_settings"));
321 }
322 }
323 else
324 {
325 $tpl = new ilTemplate("tpl.show_feed_url.html", true, true, "Services/News");
326 }
327 $tpl->setVariable("TXT_TITLE", $lng->txt("news_get_feed_title"));
328 $tpl->setVariable("TXT_INFO", $lng->txt("news_get_feed_info"));
329 $tpl->setVariable("TXT_FEED_URL", $lng->txt("news_feed_url"));
330 $tpl->setVariable("VAL_FEED_URL",
331 ILIAS_HTTP_PATH."/feed.php?client_id=".rawurlencode(CLIENT_ID)."&user_id=".$ilUser->getId().
332 "&hash=".ilObjUser::_lookupFeedHash($ilUser->getId(), true));
333 $tpl->setVariable("VAL_FEED_URL_TXT",
334 ILIAS_HTTP_PATH."/feed.php?client_id=".rawurlencode(CLIENT_ID)."&<br />user_id=".$ilUser->getId().
335 "&hash=".ilObjUser::_lookupFeedHash($ilUser->getId(), true));
336
337 include_once("./Services/PersonalDesktop/classes/class.ilPDContentBlockGUI.php");
338 $content_block = new ilPDContentBlockGUI();
339 $content_block->setContent($tpl->get());
340 $content_block->setTitle($lng->txt("news_internal_news"));
341 $content_block->addHeaderCommand($ilCtrl->getParentReturn($this),
342 $lng->txt("selected_items_back"));
343
344 return $content_block->getHTML();
345 }
346
347 function addCloseCommand($a_content_block)
348 {
349 global $lng, $ilCtrl;
350
351 $a_content_block->addHeaderCommand($ilCtrl->getParentReturn($this),
352 $lng->txt("selected_items_back"));
353 }
354
355
359 function showNews()
360 {
361 // workaround for dynamic mode (if cache is disabled, showNews has no data)
362// if (empty(self::$st_data))
363// {
364// $this->setData($this->getNewsData());
365// }
366
367 return parent::showNews();
368 }
369
373 function editSettings(ilPropertyFormGUI $a_private_form = null)
374 {
375 global $ilUser, $lng, $ilCtrl, $ilSetting;
376
377 $news_set = new ilSetting("news");
378 $enable_internal_rss = $news_set->get("enable_rss_for_internal");
379 $allow_shorter_periods = $news_set->get("allow_shorter_periods");
380 $allow_longer_periods = $news_set->get("allow_longer_periods");
381 $enable_private_feed = $news_set->get("enable_private_feed");
382
383 if (!$a_private_form && ($allow_shorter_periods || $allow_longer_periods))
384 {
385 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
386 $form = new ilPropertyFormGUI();
387 $form->setFormAction($ilCtrl->getFormaction($this));
388 $form->setTitle($lng->txt("news_settings"));
389
390 include_once("./Services/News/classes/class.ilNewsItem.php");
391 $default_per = ilNewsItem::_lookupDefaultPDPeriod();
393
394 $form->setTableWidth("100%");
395
396 $per_opts = array(
397 2 => "2 ".$lng->txt("days"),
398 3 => "3 ".$lng->txt("days"),
399 5 => "5 ".$lng->txt("days"),
400 7 => "1 ".$lng->txt("week"),
401 14 => "2 ".$lng->txt("weeks"),
402 30 => "1 ".$lng->txt("month"),
403 60 => "2 ".$lng->txt("months"),
404 120 => "4 ".$lng->txt("months"),
405 180 => "6 ".$lng->txt("months"),
406 366 => "1 ".$lng->txt("year"));
407
408 $unset = array();
409 foreach($per_opts as $k => $opt)
410 {
411 if (!$allow_shorter_periods && ($k < $default_per)) $unset[$k] = $k;
412 if (!$allow_longer_periods && ($k > $default_per)) $unset[$k] = $k;
413 }
414 foreach($unset as $k)
415 {
416 unset($per_opts[$k]);
417 }
418
419 $per_sel = new ilSelectInputGUI($lng->txt("news_pd_period"),
420 "news_pd_period");
421 //$per_sel->setInfo($lng->txt("news_pd_period_info"));
422 $per_sel->setOptions($per_opts);
423 $per_sel->setValue((int) $per);
424 $form->addItem($per_sel);
425
426 //$form->addCheckboxProperty($lng->txt("news_public_feed"), "notifications_public_feed",
427 // "1", $public_feed, $lng->txt("news_public_feed_info"));
428 //if ($this->getProperty("public_notifications_option"))
429 //{
430 // $form->addCheckboxProperty($lng->txt("news_notifications_public"), "notifications_public",
431 // "1", $public, $lng->txt("news_notifications_public_info"));
432 //}
433 $form->addCommandButton("saveSettings", $lng->txt("save"));
434 $form->addCommandButton("cancelSettings", $lng->txt("cancel"));
435
436 $returnForm = $form->getHTML();
437 }
438
439 if ($enable_private_feed)
440 {
441 if(!$a_private_form)
442 {
443 $a_private_form = $this->initPrivateSettingsForm();
444 }
445 $returnForm .= ($returnForm=="")
446 ? $a_private_form->getHTML()
447 : "<br>".$a_private_form->getHTML();
448 }
449
450 return $returnForm;
451 }
452
453 protected function initPrivateSettingsForm()
454 {
455 global $ilCtrl, $lng, $ilUser;
456
457 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
458 $feed_form = new ilPropertyFormGUI();
459 $feed_form->setFormAction($ilCtrl->getFormaction($this));
460 $feed_form->setTitle($lng->txt("priv_feed_settings"));
461
462 $feed_form->setTableWidth("100%");
463
464 $enable_private_feed = new ilCheckboxInputGUI($lng->txt("news_enable_private_feed"), "enable_private_feed");
465 $enable_private_feed->setChecked($ilUser->_getFeedPass($ilUser->getId()));
466 $feed_form->addItem($enable_private_feed);
467
468 $passwd = new ilPasswordInputGUI($lng->txt("password"), "desired_password");
469 $passwd->setRequired(true);
470 $passwd->setInfo(ilUtil::getPasswordRequirementsInfo());
471 $enable_private_feed->addSubItem($passwd);
472
473 $feed_form->addCommandButton("changeFeedSettings", $lng->txt("save"));
474 $feed_form->addCommandButton("cancelSettings", $lng->txt("cancel"));
475
476 return $feed_form;
477 }
478
482 function cancelSettings()
483 {
484 global $ilCtrl;
485
486 $ilCtrl->returnToParent($this);
487 }
488
492 function saveSettings()
493 {
494 global $ilCtrl, $ilUser;
495
496 $news_set = new ilSetting("news");
497 $enable_internal_rss = $news_set->get("enable_rss_for_internal");
498
499 ilBlockSetting::_write($this->getBlockType(), "news_pd_period",
500 $_POST["news_pd_period"],
501 $ilUser->getId(), $this->block_id);
502
503 include_once("./Services/News/classes/class.ilNewsCache.php");
504 $cache = new ilNewsCache();
505 $cache->deleteEntry($ilUser->getId().":0");
506
507 $ilCtrl->returnToParent($this);
508 }
509
514 {
515 global $ilCtrl, $lng, $ilUser;
516
517 $form = $this->initPrivateSettingsForm();
518 if($form->checkInput())
519 {
520 // Deactivate private Feed - just delete the password
521 if (!$form->getInput("enable_private_feed"))
522 {
523 $ilUser->_setFeedPass($ilUser->getId(), "");
524 ilUtil::sendSuccess($lng->txt("priv_feed_disabled"),true);
525 // $ilCtrl->returnToParent($this);
526 $ilCtrl->redirect($this, "showFeedUrl");
527 }
528 else
529 {
530 $passwd = $form->getInput("desired_password");
531 require_once 'Services/User/classes/class.ilUserPasswordManager.php';
532 if(ilUserPasswordManager::getInstance()->verifyPassword($ilUser, $passwd))
533 {
534 $form->getItemByPostVar("desired_password")->setAlert($lng->txt("passwd_equals_ilpasswd"));
535 ilUtil::sendFailure($lng->txt("form_input_not_valid"));
536 }
537 else
538 {
539 $ilUser->_setFeedPass($ilUser->getId(), $passwd);
540 ilUtil::sendSuccess($lng->txt("saved_successfully"),true);
541 // $ilCtrl->returnToParent($this);
542 $ilCtrl->redirect($this, "showFeedUrl");
543 }
544 }
545 }
546
547 $form->setValuesByPost();
548 return $this->editSettings($form);
549 }
550
551}
552
553?>
sprintf('%.4f', $callTime)
global $tpl
Definition: ilias.php:8
$_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.
addBlockCommand($a_href, $a_text, $a_target="", $a_img="", $a_right_aligned=false, $a_checked=false, $a_html="")
Add Block Command.
getTitle()
Get Title.
setTitle($a_title)
Set Title.
setEnableNumInfo($a_enablenuminfo)
Set Enable Item Number Info.
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 _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 prepareNewsDataFromCache($a_cres)
Prepare news data from cache.
static _lookupUserPDPeriod($a_user_id)
static _lookupDefaultPDPeriod()
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.
static getBlockType()
Get block type.
static getScreenMode()
Get Screen Mode for current command.
editSettings(ilPropertyFormGUI $a_private_form=null)
Show settings screen.
static isRepositoryObject()
Is block used in repository object?
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 sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static getPasswordRequirementsInfo()
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
global $ilBench
Definition: ilias.php:18
global $ilCtrl
Definition: ilias.php:18
global $lng
Definition: privfeed.php:17
global $ilSetting
Definition: privfeed.php:17
$cmd
Definition: sahs_server.php:35
$ilUser
Definition: imgupload.php:18