[TASK] Cleanup character after PHP closing tag
[Packages/TYPO3.CMS.git] / typo3 / sysext / linkvalidator / Classes / Task / ValidatorTaskAdditionalFieldProvider.php
1 <?php
2 namespace TYPO3\CMS\Linkvalidator\Task;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2010 - 2011 Michael Miousse (michael.miousse@infoglobe.ca)
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26 /**
27 * This class provides Scheduler Additional Field plugin implementation
28 *
29 * @author Dimitri K├Ânig <dk@cabag.ch>
30 * @author Michael Miousse <michael.miousse@infoglobe.ca>
31 * @package TYPO3
32 * @subpackage linkvalidator
33 */
34 class ValidatorTaskAdditionalFieldProvider implements \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface {
35
36 /**
37 * Render additional information fields within the scheduler backend.
38 *
39 * @param array $taskInfo Array information of task to return
40 * @param task $task Task object
41 * @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $schedulerModule Reference to the calling object (BE module of the Scheduler)
42 * @return array Additional fields
43 * @see interfaces/tx_scheduler_AdditionalFieldProvider#getAdditionalFields($taskInfo, $task, $schedulerModule)
44 */
45 public function getAdditionalFields(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $schedulerModule) {
46 $additionalFields = array();
47 if (empty($taskInfo['configuration'])) {
48 if ($schedulerModule->CMD == 'add') {
49 $taskInfo['configuration'] = '';
50 } elseif ($schedulerModule->CMD == 'edit') {
51 $taskInfo['configuration'] = $task->getConfiguration();
52 } else {
53 $taskInfo['configuration'] = $task->getConfiguration();
54 }
55 }
56 if (empty($taskInfo['depth'])) {
57 if ($schedulerModule->CMD == 'add') {
58 $taskInfo['depth'] = array();
59 } elseif ($schedulerModule->CMD == 'edit') {
60 $taskInfo['depth'] = $task->getDepth();
61 } else {
62 $taskInfo['depth'] = $task->getDepth();
63 }
64 }
65 if (empty($taskInfo['page'])) {
66 if ($schedulerModule->CMD == 'add') {
67 $taskInfo['page'] = '';
68 } elseif ($schedulerModule->CMD == 'edit') {
69 $taskInfo['page'] = $task->getPage();
70 } else {
71 $taskInfo['page'] = $task->getPage();
72 }
73 }
74 if (empty($taskInfo['email'])) {
75 if ($schedulerModule->CMD == 'add') {
76 $taskInfo['email'] = '';
77 } elseif ($schedulerModule->CMD == 'edit') {
78 $taskInfo['email'] = $task->getEmail();
79 } else {
80 $taskInfo['email'] = $task->getEmail();
81 }
82 }
83 if (empty($taskInfo['emailOnBrokenLinkOnly'])) {
84 if ($schedulerModule->CMD == 'add') {
85 $taskInfo['emailOnBrokenLinkOnly'] = 1;
86 } elseif ($schedulerModule->CMD == 'edit') {
87 $taskInfo['emailOnBrokenLinkOnly'] = $task->getEmailOnBrokenLinkOnly();
88 } else {
89 $taskInfo['emailOnBrokenLinkOnly'] = $task->getEmailOnBrokenLinkOnly();
90 }
91 }
92 if (empty($taskInfo['emailTemplateFile'])) {
93 if ($schedulerModule->CMD == 'add') {
94 $taskInfo['emailTemplateFile'] = 'EXT:linkvalidator/res/mailtemplate.html';
95 } elseif ($schedulerModule->CMD == 'edit') {
96 $taskInfo['emailTemplateFile'] = $task->getEmailTemplateFile();
97 } else {
98 $taskInfo['emailTemplateFile'] = $task->getEmailTemplateFile();
99 }
100 }
101 $fieldID = 'task_page';
102 $fieldCode = '<input type="text" name="tx_scheduler[linkvalidator][page]" id="' . $fieldID . '" value="' . htmlspecialchars($taskInfo['page']) . '"/>';
103 $label = $GLOBALS['LANG']->sL('LLL:EXT:linkvalidator/locallang.xml:tasks.validate.page');
104 $label = \TYPO3\CMS\Backend\Utility\BackendUtility::wrapInHelp('linkvalidator', $fieldID, $label);
105 $additionalFields[$fieldID] = array(
106 'code' => $fieldCode,
107 'label' => $label
108 );
109 // input for depth
110 $fieldID = 'task_depth';
111 $fieldValueArray = array(
112 '0' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.depth_0'),
113 '1' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.depth_1'),
114 '2' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.depth_2'),
115 '3' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.depth_3'),
116 '4' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.depth_4'),
117 '999' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.depth_infi')
118 );
119 $fieldCode = '<select name="tx_scheduler[linkvalidator][depth]" id="' . $fieldID . '">';
120 foreach ($fieldValueArray as $depth => $label) {
121 $fieldCode .= "\t" . '<option value="' . htmlspecialchars($depth) . '"'
122 . (($depth == $taskInfo['depth']) ? ' selected="selected"' : '')
123 . '>' . $label . '</option>';
124 }
125 $fieldCode .= '</select>';
126 $label = $GLOBALS['LANG']->sL('LLL:EXT:linkvalidator/locallang.xml:tasks.validate.depth');
127 $label = \TYPO3\CMS\Backend\Utility\BackendUtility::wrapInHelp('linkvalidator', $fieldID, $label);
128 $additionalFields[$fieldID] = array(
129 'code' => $fieldCode,
130 'label' => $label
131 );
132 $fieldID = 'task_configuration';
133 $fieldCode = '<textarea name="tx_scheduler[linkvalidator][configuration]" id="' . $fieldID . '" >'
134 . htmlspecialchars($taskInfo['configuration']) . '</textarea>';
135 $label = $GLOBALS['LANG']->sL('LLL:EXT:linkvalidator/locallang.xml:tasks.validate.conf');
136 $label = \TYPO3\CMS\Backend\Utility\BackendUtility::wrapInHelp('linkvalidator', $fieldID, $label);
137 $additionalFields[$fieldID] = array(
138 'code' => $fieldCode,
139 'label' => $label
140 );
141 $fieldID = 'task_email';
142 $fieldCode = '<input type="text" name="tx_scheduler[linkvalidator][email]" id="' . $fieldID . '" value="'
143 . htmlspecialchars($taskInfo['email']) . '" />';
144 $label = $GLOBALS['LANG']->sL('LLL:EXT:linkvalidator/locallang.xml:tasks.validate.email');
145 $label = \TYPO3\CMS\Backend\Utility\BackendUtility::wrapInHelp('linkvalidator', $fieldID, $label);
146 $additionalFields[$fieldID] = array(
147 'code' => $fieldCode,
148 'label' => $label
149 );
150 $fieldID = 'task_emailOnBrokenLinkOnly';
151 $fieldCode = '<input type="checkbox" name="tx_scheduler[linkvalidator][emailOnBrokenLinkOnly]" id="' . $fieldID . '" '
152 . (htmlspecialchars($taskInfo['emailOnBrokenLinkOnly']) ? 'checked="checked"' : '') . ' />';
153 $label = $GLOBALS['LANG']->sL('LLL:EXT:linkvalidator/locallang.xml:tasks.validate.emailOnBrokenLinkOnly');
154 $label = \TYPO3\CMS\Backend\Utility\BackendUtility::wrapInHelp('linkvalidator', $fieldID, $label);
155 $additionalFields[$fieldID] = array(
156 'code' => $fieldCode,
157 'label' => $label
158 );
159 $fieldID = 'task_emailTemplateFile';
160 $fieldCode = '<input type="text" name="tx_scheduler[linkvalidator][emailTemplateFile]" id="' . $fieldID
161 . '" value="' . htmlspecialchars($taskInfo['emailTemplateFile']) . '" />';
162 $label = $GLOBALS['LANG']->sL('LLL:EXT:linkvalidator/locallang.xml:tasks.validate.emailTemplateFile');
163 $label = \TYPO3\CMS\Backend\Utility\BackendUtility::wrapInHelp('linkvalidator', $fieldID, $label);
164 $additionalFields[$fieldID] = array(
165 'code' => $fieldCode,
166 'label' => $label
167 );
168 return $additionalFields;
169 }
170
171 /**
172 * Mark current value as selected by returning the "selected" attribute
173 *
174 * @param array $configurationArray Array of configuration
175 * @param string $currentValue Value of selector object
176 * @return string Html fragment for a selected option or empty
177 */
178 protected function getSelectedState(array $configurationArray, $currentValue) {
179 $selected = '';
180 for ($i = 0; $i < count($configurationArray); $i++) {
181 if (strcmp($configurationArray[$i], $currentValue) === 0) {
182 $selected = 'selected="selected" ';
183 }
184 }
185 return $selected;
186 }
187
188 /**
189 * This method checks any additional data that is relevant to the specific task.
190 * If the task class is not relevant, the method is expected to return TRUE.
191 *
192 * @param array $submittedData Reference to the array containing the data submitted by the user
193 * @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $schedulerModule Reference to the calling object (BE module of the Scheduler)
194 * @return boolean TRUE if validation was ok (or selected class is not relevant), FALSE otherwise
195 */
196 public function validateAdditionalFields(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $schedulerModule) {
197 $isValid = TRUE;
198 //TODO add validation to validate the $submittedData['configuration'] which is normally a comma separated string
199 if (!empty($submittedData['linkvalidator']['email'])) {
200 $emailList = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $submittedData['linkvalidator']['email']);
201 foreach ($emailList as $emailAdd) {
202 if (!\TYPO3\CMS\Core\Utility\GeneralUtility::validEmail($emailAdd)) {
203 $isValid = FALSE;
204 $schedulerModule->addMessage($GLOBALS['LANG']->sL('LLL:EXT:linkvalidator/locallang.xml:tasks.validate.invalidEmail'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
205 }
206 }
207 }
208 if ($res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'pages', 'uid = ' . intval($submittedData['linkvalidator']['page']))) {
209 if ($GLOBALS['TYPO3_DB']->sql_num_rows($res) == 0 && $submittedData['linkvalidator']['page'] > 0) {
210 $isValid = FALSE;
211 $schedulerModule->addMessage($GLOBALS['LANG']->sL('LLL:EXT:linkvalidator/locallang.xml:tasks.validate.invalidPage'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
212 }
213 $GLOBALS['TYPO3_DB']->sql_free_result($res);
214 } else {
215 $isValid = FALSE;
216 $schedulerModule->addMessage($GLOBALS['LANG']->sL('LLL:EXT:linkvalidator/locallang.xml:tasks.validate.invalidPage'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
217 }
218 if ($submittedData['linkvalidator']['depth'] < 0) {
219 $isValid = FALSE;
220 $schedulerModule->addMessage($GLOBALS['LANG']->sL('LLL:EXT:linkvalidator/locallang.xml:tasks.validate.invalidDepth'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
221 }
222 return $isValid;
223 }
224
225 /**
226 * This method is used to save any additional input into the current task object
227 * if the task class matches.
228 *
229 * @param array $submittedData Array containing the data submitted by the user
230 * @param \TYPO3\CMS\Scheduler\Task $task Reference to the current task object
231 * @return void
232 */
233 public function saveAdditionalFields(array $submittedData, \TYPO3\CMS\Scheduler\Task $task) {
234 $task->setDepth($submittedData['linkvalidator']['depth']);
235 $task->setPage($submittedData['linkvalidator']['page']);
236 $task->setEmail($submittedData['linkvalidator']['email']);
237 if ($submittedData['linkvalidator']['emailOnBrokenLinkOnly']) {
238 $task->setEmailOnBrokenLinkOnly(1);
239 } else {
240 $task->setEmailOnBrokenLinkOnly(0);
241 }
242 $task->setConfiguration($submittedData['linkvalidator']['configuration']);
243 $task->setEmailTemplateFile($submittedData['linkvalidator']['emailTemplateFile']);
244 }
245
246 }
247 ?>