TYPO3 CMS  TYPO3_7-6
ValidatorTaskAdditionalFieldProvider.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
24 
29 {
39  public function getAdditionalFields(array &$taskInfo, $task, SchedulerModuleController $schedulerModule)
40  {
41  $additionalFields = [];
42  if (empty($taskInfo['configuration'])) {
43  if ($schedulerModule->CMD === 'add') {
44  $taskInfo['configuration'] = '';
45  } elseif ($schedulerModule->CMD === 'edit') {
46  $taskInfo['configuration'] = $task->getConfiguration();
47  } else {
48  $taskInfo['configuration'] = $task->getConfiguration();
49  }
50  }
51  if (empty($taskInfo['depth'])) {
52  if ($schedulerModule->CMD === 'add') {
53  $taskInfo['depth'] = [];
54  } elseif ($schedulerModule->CMD === 'edit') {
55  $taskInfo['depth'] = $task->getDepth();
56  } else {
57  $taskInfo['depth'] = $task->getDepth();
58  }
59  }
60  if (empty($taskInfo['page'])) {
61  if ($schedulerModule->CMD === 'add') {
62  $taskInfo['page'] = '';
63  } elseif ($schedulerModule->CMD === 'edit') {
64  $taskInfo['page'] = $task->getPage();
65  } else {
66  $taskInfo['page'] = $task->getPage();
67  }
68  }
69  if (empty($taskInfo['email'])) {
70  if ($schedulerModule->CMD === 'add') {
71  $taskInfo['email'] = '';
72  } elseif ($schedulerModule->CMD === 'edit') {
73  $taskInfo['email'] = $task->getEmail();
74  } else {
75  $taskInfo['email'] = $task->getEmail();
76  }
77  }
78  if (empty($taskInfo['emailOnBrokenLinkOnly'])) {
79  if ($schedulerModule->CMD === 'add') {
80  $taskInfo['emailOnBrokenLinkOnly'] = 1;
81  } elseif ($schedulerModule->CMD === 'edit') {
82  $taskInfo['emailOnBrokenLinkOnly'] = $task->getEmailOnBrokenLinkOnly();
83  } else {
84  $taskInfo['emailOnBrokenLinkOnly'] = $task->getEmailOnBrokenLinkOnly();
85  }
86  }
87  if (empty($taskInfo['emailTemplateFile'])) {
88  if ($schedulerModule->CMD === 'add') {
89  $taskInfo['emailTemplateFile'] = 'EXT:linkvalidator/Resources/Private/Templates/mailtemplate.html';
90  } elseif ($schedulerModule->CMD === 'edit') {
91  $taskInfo['emailTemplateFile'] = $task->getEmailTemplateFile();
92  } else {
93  $taskInfo['emailTemplateFile'] = $task->getEmailTemplateFile();
94  }
95  }
96  $fieldId = 'task_page';
97  $fieldCode = '<input type="text" class="form-control" name="tx_scheduler[linkvalidator][page]" id="' . $fieldId . '" value="' . htmlspecialchars($taskInfo['page']) . '">';
98  $lang = $this->getLanguageService();
99  $label = $lang->sL('LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.validate.page');
100  $label = BackendUtility::wrapInHelp('linkvalidator', $fieldId, $label);
101  $additionalFields[$fieldId] = [
102  'code' => $fieldCode,
103  'label' => $label
104  ];
105  // input for depth
106  $fieldId = 'task_depth';
107  $fieldValueArray = [
108  '0' => $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_0'),
109  '1' => $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_1'),
110  '2' => $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_2'),
111  '3' => $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_3'),
112  '4' => $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_4'),
113  '999' => $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_infi')
114  ];
115  $fieldCode = '<select class="form-control" name="tx_scheduler[linkvalidator][depth]" id="' . $fieldId . '">';
116  foreach ($fieldValueArray as $depth => $label) {
117  $fieldCode .= "\t" . '<option value="' . htmlspecialchars($depth) . '"' .
118  (($depth == $taskInfo['depth']) ? ' selected="selected"' : '') .
119  '>' . $label . '</option>';
120  }
121  $fieldCode .= '</select>';
122  $label = $lang->sL('LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.validate.depth');
123  $label = BackendUtility::wrapInHelp('linkvalidator', $fieldId, $label);
124  $additionalFields[$fieldId] = [
125  'code' => $fieldCode,
126  'label' => $label
127  ];
128  $fieldId = 'task_configuration';
129  $fieldCode = '<textarea class="form-control" name="tx_scheduler[linkvalidator][configuration]" id="' . $fieldId . '" >' .
130  htmlspecialchars($taskInfo['configuration']) . '</textarea>';
131  $label = $lang->sL('LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.validate.conf');
132  $label = BackendUtility::wrapInHelp('linkvalidator', $fieldId, $label);
133  $additionalFields[$fieldId] = [
134  'code' => $fieldCode,
135  'label' => $label
136  ];
137  $fieldId = 'task_email';
138  $fieldCode = '<textarea class="form-control" rows="5" cols="50" name="tx_scheduler[linkvalidator][email]" id="' . $fieldId . '">' .
139  htmlspecialchars($taskInfo['email']) . '</textarea>';
140  $label = $lang->sL('LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.validate.email');
141  $label = BackendUtility::wrapInHelp('linkvalidator', $fieldId, $label);
142  $additionalFields[$fieldId] = [
143  'code' => $fieldCode,
144  'label' => $label
145  ];
146  $fieldId = 'task_emailOnBrokenLinkOnly';
147  $fieldCode = '<div class="checkbox"><label><input type="checkbox" name="tx_scheduler[linkvalidator][emailOnBrokenLinkOnly]" id="' . $fieldId . '" ' .
148  (htmlspecialchars($taskInfo['emailOnBrokenLinkOnly']) ? 'checked="checked"' : '') . '></label></div>';
149  $label = $lang->sL('LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.validate.emailOnBrokenLinkOnly');
150  $label = BackendUtility::wrapInHelp('linkvalidator', $fieldId, $label);
151  $additionalFields[$fieldId] = [
152  'code' => $fieldCode,
153  'label' => $label
154  ];
155  $fieldId = 'task_emailTemplateFile';
156  $fieldCode = '<input class="form-control" type="text" name="tx_scheduler[linkvalidator][emailTemplateFile]" id="' . $fieldId .
157  '" value="' . htmlspecialchars($taskInfo['emailTemplateFile']) . '">';
158  $label = $lang->sL('LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.validate.emailTemplateFile');
159  $label = BackendUtility::wrapInHelp('linkvalidator', $fieldId, $label);
160  $additionalFields[$fieldId] = [
161  'code' => $fieldCode,
162  'label' => $label
163  ];
164  return $additionalFields;
165  }
166 
174  protected function getSelectedState(array $configurationArray, $currentValue)
175  {
176  $selected = '';
177  if (in_array($currentValue, $configurationArray, true)) {
178  $selected = 'selected="selected" ';
179  }
180  return $selected;
181  }
182 
191  public function validateAdditionalFields(array &$submittedData, SchedulerModuleController $schedulerModule)
192  {
193  $isValid = true;
194  // @todo add validation to validate the $submittedData['configuration'] which is normally a comma separated string
195  $lang = $this->getLanguageService();
196  if (!empty($submittedData['linkvalidator']['email'])) {
197  $emailList = GeneralUtility::trimExplode(',', $submittedData['linkvalidator']['email']);
198  foreach ($emailList as $emailAdd) {
199  if (!GeneralUtility::validEmail($emailAdd)) {
200  $isValid = false;
201  $schedulerModule->addMessage($lang->sL('LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.validate.invalidEmail'), FlashMessage::ERROR);
202  }
203  }
204  }
205  if ($res = $this->getDatabaseConnection()->exec_SELECTquery('*', 'pages', 'uid = ' . (int)$submittedData['linkvalidator']['page'])) {
206  if ($this->getDatabaseConnection()->sql_num_rows($res) == 0 && $submittedData['linkvalidator']['page'] > 0) {
207  $isValid = false;
208  $schedulerModule->addMessage(
209  $lang->sL('LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.validate.invalidPage'),
211  );
212  }
213  $this->getDatabaseConnection()->sql_free_result($res);
214  } else {
215  $isValid = false;
216  $schedulerModule->addMessage(
217  $lang->sL('LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.validate.invalidPage'),
219  );
220  }
221  if ($submittedData['linkvalidator']['depth'] < 0) {
222  $isValid = false;
223  $schedulerModule->addMessage(
224  $lang->sL('LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.validate.invalidDepth'),
226  );
227  }
228  return $isValid;
229  }
230 
239  public function saveAdditionalFields(array $submittedData, AbstractTask $task)
240  {
242  $task->setDepth($submittedData['linkvalidator']['depth']);
243  $task->setPage($submittedData['linkvalidator']['page']);
244  $task->setEmail($submittedData['linkvalidator']['email']);
245  if ($submittedData['linkvalidator']['emailOnBrokenLinkOnly']) {
246  $task->setEmailOnBrokenLinkOnly(1);
247  } else {
248  $task->setEmailOnBrokenLinkOnly(0);
249  }
250  $task->setConfiguration($submittedData['linkvalidator']['configuration']);
251  $task->setEmailTemplateFile($submittedData['linkvalidator']['emailTemplateFile']);
252  }
253 
257  protected function getLanguageService()
258  {
259  return $GLOBALS['LANG'];
260  }
261 
265  protected function getDatabaseConnection()
266  {
267  return $GLOBALS['TYPO3_DB'];
268  }
269 }
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
saveAdditionalFields(array $submittedData, \TYPO3\CMS\Scheduler\Task\AbstractTask $task)
getAdditionalFields(array &$taskInfo, $task, SchedulerModuleController $schedulerModule)
validateAdditionalFields(array &$submittedData, SchedulerModuleController $schedulerModule)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']