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