Added feature #13868: Integrate TYPO3 donate notice in the backend
[Packages/TYPO3.CMS.git] / typo3 / classes / class.donatewindow.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010 Oliver Hader <oliver@typo3.org>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * AJAX handler for the donate window shown in the TYPO3 backend.
29 *
30 * @author Oliver Hader <oliver@typo3.org>
31 */
32 class DonateWindow implements t3lib_Singleton {
33 const FLAG_DonateWindowDisabled = 'DonateWindowDisabled';
34 const FLAG_DonateWindowPostponed = 'DonateWindowPostponed';
35 const VALUE_DonateWindowAppearsAfterDays = 90;
36 const VALUE_DonateWindowPostponeDays = 14;
37
38 /**
39 * @var t3lib_beUserAuth
40 */
41 protected $backendUser;
42
43 /**
44 * Constructs this object.
45 */
46 public function __construct() {
47 $this->setBackendUser($GLOBALS['BE_USER']);
48 }
49
50 /**
51 * Sets the backend user.
52 *
53 * @param t3lib_beUserAuth $backendUser
54 * @return void
55 */
56 public function setBackendUser(t3lib_beUserAuth $backendUser) {
57 $this->backendUser = $backendUser;
58 }
59
60 /**
61 * Disables the donate window - thus it won't be shown again for this user.
62 *
63 * @param array $parameters: Parameters (not used)
64 * @param TYPO3AJAX $ajaxObj: The calling parent AJAX object
65 * @return void
66 */
67 public function disable(array $parameters, TYPO3AJAX $ajaxObj) {
68 $this->backendUser->uc[self::FLAG_DonateWindowDisabled] = TYPO3_version;
69 $this->backendUser->writeUC();
70 }
71
72 /**
73 * Postpones the donate window - thus it will be shown again at a later time.
74 *
75 * @param array $parameters: Parameters (not used)
76 * @param TYPO3AJAX $ajaxObj: The calling parent AJAX object
77 * @return void
78 */
79 public function postpone(array $parameters, TYPO3AJAX $ajaxObj) {
80 $this->backendUser->uc[self::FLAG_DonateWindowPostponed] = $GLOBALS['EXEC_TIME'];
81 $this->backendUser->writeUC();
82 }
83
84
85 /**
86 * Determines whether the donate window is allowed to be displayed.
87 *
88 * @return boolean Whether the donate window is allowed to be displayed.
89 */
90 public function isDonateWindowAllowed() {
91 $uc = $this->backendUser->uc;
92 $isAdmin = $this->backendUser->isAdmin();
93 $firstLogin = $this->getFirstLoginTimeStamp();
94 $isTriggered = ($firstLogin && $GLOBALS['EXEC_TIME'] - $firstLogin > self::VALUE_DonateWindowAppearsAfterDays * 86400);
95 $isAllowed = (bool) $GLOBALS['TYPO3_CONF_VARS']['BE']['allowDonateWindow'];
96 $isCancelled = (isset($uc[self::FLAG_DonateWindowDisabled]) && !empty($uc[self::FLAG_DonateWindowDisabled]));
97 $isPostponed = (isset($uc[self::FLAG_DonateWindowPostponed]) && $uc[self::FLAG_DonateWindowPostponed] > $GLOBALS['EXEC_TIME'] - self::VALUE_DonateWindowPostponeDays * 86400);
98
99 return ($isAdmin && $isAllowed && !$isCancelled && !$isPostponed);
100 }
101
102 /**
103 * Gets the timestamp of the first login of the current backend user.
104 *
105 * @return integer Timestamp of the first login
106 */
107 public function getFirstLoginTimeStamp() {
108 $firstLogin = NULL;
109
110 if (isset($this->backendUser->uc['firstLoginTimeStamp'])) {
111 $firstLogin = $this->backendUser->uc['firstLoginTimeStamp'];
112 }
113
114 return $firstLogin;
115 }
116 }
117
118 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/classes/class.donatewindow.php']) {
119 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/classes/class.donatewindow.php']);
120 }
121
122 ?>