Added feature #16420: Add link validator module (Thanks to Patrick Gaumond)
[Packages/TYPO3.CMS.git] / typo3 / sysext / linkvalidator / lib / class.tx_linkvalidator_scheduler_linkAdditionalFieldProvider.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2005 - 2010 Michael Miousse (michael.miousse@infoglobe.ca)
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 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24 /**
25 * This class provides Scheduler Additional Field plugin implementation.
26 *
27 * @author Dimitri K├Ânig <dk@cabag.ch>
28 * @author Michael Miousse <michael.miousse@infoglobe.ca>
29 */
30 class tx_linkvalidator_scheduler_linkAdditionalFieldProvider implements tx_scheduler_AdditionalFieldProvider {
31
32 /**
33 * Render additional information fields within the scheduler backend
34 *
35 * @param array $taksInfo: array information of task to return
36 * @param task $task: task object
37 * @param tx_scheduler_Module $schedulerModule: reference to the calling object (Scheduler's BE module)
38 * @return array additionnal fields
39 * @see interfaces/tx_scheduler_AdditionalFieldProvider#getAdditionalFields($taskInfo, $task, $schedulerModule)
40 */
41 public function getAdditionalFields(array &$taskInfo, $task, tx_scheduler_Module $schedulerModule) {
42 $additionalFields = array();
43 if (empty($taskInfo['configuration'])) {
44 if ($schedulerModule->CMD == 'add') {
45 $taskInfo['configuration'] = '';
46 } elseif ($schedulerModule->CMD == 'edit') {
47 $taskInfo['configuration'] = $task->configuration;
48 } else {
49 $taskInfo['configuration'] = $task->configuration;
50 }
51 }
52
53 if (empty($taskInfo['depth'])) {
54 if ($schedulerModule->CMD == 'add') {
55 $taskInfo['depth'] = array();
56 } elseif ($schedulerModule->CMD == 'edit') {
57 $taskInfo['depth'] = $task->depth;
58 } else {
59 $taskInfo['depth'] = $task->depth;
60 }
61 }
62
63 if (empty($taskInfo['page'])) {
64 if ($schedulerModule->CMD == 'add') {
65 $taskInfo['page'] = '';
66 } elseif ($schedulerModule->CMD == 'edit') {
67 $taskInfo['page'] = $task->page;
68 } else {
69 $taskInfo['page'] = $task->page;
70 }
71 }
72 if (empty($taskInfo['email'])) {
73 if ($schedulerModule->CMD == 'add') {
74 $taskInfo['email'] = '';
75 } elseif ($schedulerModule->CMD == 'edit') {
76 $taskInfo['email'] = $task->email;
77 } else {
78 $taskInfo['email'] = $task->email;
79 }
80 }
81
82 if (empty($taskInfo['emailonbrokenlinkonly'])) {
83 if ($schedulerModule->CMD == 'add') {
84 $taskInfo['emailonbrokenlinkonly'] = 1;
85 $task->emailonbrokenlinkonly = 1;
86 } elseif ($schedulerModule->CMD == 'edit') {
87 $taskInfo['emailonbrokenlinkonly'] = $task->emailonbrokenlinkonly;
88 } else {
89 $taskInfo['emailonbrokenlinkonly'] = $task->emailonbrokenlinkonly;
90 }
91 }
92 if (empty($taskInfo['emailfile'])) {
93 if ($schedulerModule->CMD == 'add') {
94 $taskInfo['emailfile'] = 'EXT:linkvalidator/res/mailTemplate.html';
95 } elseif ($schedulerModule->CMD == 'edit') {
96 $taskInfo['emailfile'] = $task->emailfile;
97 } else {
98 $taskInfo['emailfile'] = $task->emailfile;
99 }
100 }
101
102
103 $fieldID = 'task_page';
104 $fieldCode = '<input type="text" name="tx_scheduler[page]" id="' . $fieldID . '" value="' . $taskInfo['page'] . '"/>';
105
106
107 $additionalFields[$fieldID] = array(
108 'code' => $fieldCode,
109 'label' => 'LLL:EXT:linkvalidator/locallang.xml:link.page'
110 );
111
112 // input for depth
113 $fieldID = 'task_depth';
114 $fieldValueArray = array(
115 '0' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.depth_0'),
116 '1' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.depth_1'),
117 '2' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.depth_2'),
118 '3' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.depth_3'),
119 '4' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.depth_4'),
120 '999' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.depth_infi'),
121 );
122 $fieldCode = '<select name="tx_scheduler[depth]" id="' . $fieldID . '">';
123
124 foreach ($fieldValueArray as $key => $label) {
125 $fieldCode .= "\t" . '<option value="' . $key . '"' . (($key == $taskInfo['depth']) ? ' selected="selected"' : '') . '>' . $label . '</option>';
126 }
127
128 $fieldCode .= '</select>';
129 $additionalFields[$fieldID] = array(
130 'code' => $fieldCode,
131 'label' => 'LLL:EXT:linkvalidator/locallang.xml:link.depth'
132 );
133
134 $fieldID = 'task_configuration';
135 $fieldCode = '<textarea name="tx_scheduler[configuration]" id="' . $fieldID . '" >' . $taskInfo['configuration'] . '</textarea>';
136
137 $additionalFields[$fieldID] = array(
138 'code' => $fieldCode,
139 'label' => 'LLL:EXT:linkvalidator/locallang.xml:link.conf'
140 );
141
142 $fieldID = 'task_email';
143 $fieldCode = '<input type="text" name="tx_scheduler[email]" id="' . $fieldID . '" value="' . $taskInfo['email'] . '" />';
144
145 $additionalFields[$fieldID] = array(
146 'code' => $fieldCode,
147 'label' => 'LLL:EXT:linkvalidator/locallang.xml:link.email'
148 );
149 $fieldID = 'task_emailonbrokenlinkonly';
150 $fieldCode = '<input type="checkbox" name="tx_scheduler[emailonbrokenlinkonly]" id="' . $fieldID . '" ' . ($taskInfo['emailonbrokenlinkonly'] ? 'checked="checked"' : '') . ' />';
151
152 $additionalFields[$fieldID] = array(
153 'code' => $fieldCode,
154 'label' => 'LLL:EXT:linkvalidator/locallang.xml:link.emailonbrokenlinkonly'
155 );
156 $fieldID = 'task_emailfile';
157 $fieldCode = '<input type="text" name="tx_scheduler[emailfile]" id="' . $fieldID . '" value="' . $taskInfo['emailfile'] . '" />';
158
159 $additionalFields[$fieldID] = array(
160 'code' => $fieldCode,
161 'label' => 'LLL:EXT:linkvalidator/locallang.xml:link.emailfile'
162 );
163
164 return $additionalFields;
165 } // end function getAdditionalFields()
166
167 /**
168 * Mark current value as selected by returning the "selected" attribute
169 *
170 * @param array $configurationArray: array of configuration
171 * @param string $currentValue: value of selector object
172 * @return string Selected html or empty
173 * @access protected
174 */
175 protected function getSelectedState($configurationArray, $currentValue) {
176 $selected = '';
177 for ($i = 0; $i < count($configurationArray); $i++) {
178 if (strcmp($configurationArray[$i], $currentValue) === 0) {
179 $selected = 'selected="selected" ';
180 }
181 }
182 return $selected;
183 }
184
185 /**
186 * This method checks any additional data that is relevant to the specific task
187 * If the task class is not relevant, the method is expected to return TRUE
188 *
189 * @param array $submittedData: reference to the array containing the data submitted by the user
190 * @param tx_scheduler_module1 $parentObject: reference to the calling object (Scheduler's BE module)
191 * @return boolean True if validation was ok (or selected class is not relevant), FALSE otherwise
192 */
193 public function validateAdditionalFields(array &$submittedData, tx_scheduler_Module $schedulerModule) {
194 $isValid = TRUE;
195
196 //!TODO add validation to validate the $submittedData['configuration'] wich is normally a comma seperated string
197 if (!empty($submittedData['email'])) {
198 $emailList = t3lib_div::trimExplode(',', $submittedData['email']);
199 foreach ($emailList as $emailAdd) {
200 if (!t3lib_div::validEmail($emailAdd)) {
201 $isValid = FALSE;
202 $schedulerModule->addMessage(
203 $GLOBALS['LANG']->sL('LLL:EXT:linkvalidator/locallang.xml:linkvalidator_im.invalidEmail'),
204 t3lib_FlashMessage::ERROR
205 );
206 }
207 }
208 }
209
210 if ($res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'pages', 'uid = ' . $submittedData['page'])) {
211 if ($GLOBALS['TYPO3_DB']->sql_num_rows($res) != 1) {
212 $isValid = FALSE;
213 $schedulerModule->addMessage(
214 $GLOBALS['LANG']->sL('LLL:EXT:linkvalidator/locallang.xml:linkvalidator_im.invalidPage'),
215 t3lib_FlashMessage::ERROR
216 );
217 }
218 } else {
219 $isValid = FALSE;
220 $schedulerModule->addMessage(
221 $GLOBALS['LANG']->sL('LLL:EXT:linkvalidator/locallang.xml:linkvalidator_im.invalidPage'),
222 t3lib_FlashMessage::ERROR
223 );
224 }
225
226 if ($submittedData['depth'] < 0) {
227 $isValid = FALSE;
228 $schedulerModule->addMessage(
229 $GLOBALS['LANG']->sL('LLL:EXT:linkvalidator/locallang.xml:linkvalidator_im.invalidDepth'),
230 t3lib_FlashMessage::ERROR
231 );
232 }
233
234 return $isValid;
235 }
236
237 /**
238 * This method is used to save any additional input into the current task object
239 * if the task class matches
240 *
241 * @param array $submittedData: array containing the data submitted by the user
242 * @param tx_scheduler_Task $task: reference to the current task object
243 * @return void
244 */
245 public function saveAdditionalFields(array $submittedData, tx_scheduler_Task $task) {
246 $task->depth = $submittedData['depth'];
247 $task->page = $submittedData['page'];
248 $task->email = $submittedData['email'];
249 $task->emailonbrokenlinkonly = $submittedData['emailonbrokenlinkonly'];
250 $task->configuration = $submittedData['configuration'];
251 $task->emailfile = $submittedData['emailfile'];
252
253 }
254
255 }
256
257 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/linkvalidator/lib/class.tx_linkvalidator_scheduler_linkAdditionalFieldProvider.php']) {
258 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/linkvalidator/lib/class.tx_linkvalidator_scheduler_linkAdditionalFieldProvider.php']);
259 }
260
261 ?>