TYPO3 CMS  TYPO3_8-7
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 {
35  protected $languageFile = 'LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf';
36 
46  public function getAdditionalFields(array &$taskInfo, $task, SchedulerModuleController $schedulerModule)
47  {
48  $additionalFields = [];
49  if (empty($taskInfo['configuration'])) {
50  if ($schedulerModule->CMD === 'add') {
51  $taskInfo['configuration'] = $taskInfo['linkvalidator']['configuration'];
52  } elseif ($schedulerModule->CMD === 'edit') {
53  $taskInfo['configuration'] = $task->getConfiguration();
54  } else {
55  $taskInfo['configuration'] = $task->getConfiguration();
56  }
57  }
58  if (empty($taskInfo['depth'])) {
59  if ($schedulerModule->CMD === 'add') {
60  $taskInfo['depth'] = $taskInfo['linkvalidator']['depth'];
61  } elseif ($schedulerModule->CMD === 'edit') {
62  $taskInfo['depth'] = $task->getDepth();
63  } else {
64  $taskInfo['depth'] = $task->getDepth();
65  }
66  }
67  if (empty($taskInfo['page'])) {
68  if ($schedulerModule->CMD === 'add') {
69  $taskInfo['page'] = $taskInfo['linkvalidator']['page'];
70  } elseif ($schedulerModule->CMD === 'edit') {
71  $taskInfo['page'] = $task->getPage();
72  } else {
73  $taskInfo['page'] = $task->getPage();
74  }
75  }
76  if (empty($taskInfo['email'])) {
77  if ($schedulerModule->CMD === 'add') {
78  $taskInfo['email'] = $taskInfo['linkvalidator']['email'];
79  } elseif ($schedulerModule->CMD === 'edit') {
80  $taskInfo['email'] = $task->getEmail();
81  } else {
82  $taskInfo['email'] = $task->getEmail();
83  }
84  }
85  if (empty($taskInfo['emailOnBrokenLinkOnly'])) {
86  if ($schedulerModule->CMD === 'add') {
87  $taskInfo['emailOnBrokenLinkOnly'] = $taskInfo['linkvalidator']['emailOnBrokenLinkOnly'] ? $taskInfo['linkvalidator']['emailOnBrokenLinkOnly'] : 1;
88  } elseif ($schedulerModule->CMD === 'edit') {
89  $taskInfo['emailOnBrokenLinkOnly'] = $task->getEmailOnBrokenLinkOnly();
90  } else {
91  $taskInfo['emailOnBrokenLinkOnly'] = $task->getEmailOnBrokenLinkOnly();
92  }
93  }
94  if (empty($taskInfo['emailTemplateFile'])) {
95  if ($schedulerModule->CMD === 'add') {
96  $taskInfo['emailTemplateFile'] = $taskInfo['linkvalidator']['emailTemplateFile'] ? $taskInfo['linkvalidator']['emailTemplateFile'] : 'EXT:linkvalidator/Resources/Private/Templates/mailtemplate.html';
97  } elseif ($schedulerModule->CMD === 'edit') {
98  $taskInfo['emailTemplateFile'] = $task->getEmailTemplateFile();
99  } else {
100  $taskInfo['emailTemplateFile'] = $task->getEmailTemplateFile();
101  }
102  }
103  $fieldId = 'task_page';
104  $fieldCode = '<input type="number" min="0" class="form-control" name="tx_scheduler[linkvalidator][page]" id="'
105  . $fieldId
106  . '" value="'
107  . htmlspecialchars($taskInfo['page'])
108  . '">';
109  $lang = $this->getLanguageService();
110  $label = $lang->sL($this->languageFile . ':tasks.validate.page');
111  $label = BackendUtility::wrapInHelp('linkvalidator', $fieldId, $label);
112  $pageTitle = '';
113  if (!empty($taskInfo['page'])) {
114  $pageTitle = $this->getPageTitle((int)$taskInfo['page']);
115  }
116  $additionalFields[$fieldId] = [
117  'browser' => 'page',
118  'pageTitle' => $pageTitle,
119  'code' => $fieldCode,
120  'label' => $label
121  ];
122  // input for depth
123  $fieldId = 'task_depth';
124  $fieldValueArray = [
125  '0' => $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.depth_0'),
126  '1' => $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.depth_1'),
127  '2' => $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.depth_2'),
128  '3' => $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.depth_3'),
129  '4' => $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.depth_4'),
130  '999' => $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.depth_infi')
131  ];
132  $fieldCode = '<select class="form-control" name="tx_scheduler[linkvalidator][depth]" id="' . $fieldId . '">';
133  foreach ($fieldValueArray as $depth => $label) {
134  $fieldCode .= "\t" . '<option value="' . htmlspecialchars($depth) . '"'
135  . (($depth == $taskInfo['depth']) ? ' selected="selected"' : '') . '>'
136  . $label
137  . '</option>';
138  }
139  $fieldCode .= '</select>';
140  $label = $lang->sL($this->languageFile . ':tasks.validate.depth');
141  $label = BackendUtility::wrapInHelp('linkvalidator', $fieldId, $label);
142  $additionalFields[$fieldId] = [
143  'code' => $fieldCode,
144  'label' => $label
145  ];
146  $fieldId = 'task_configuration';
147  $fieldCode = '<textarea class="form-control" name="tx_scheduler[linkvalidator][configuration]" id="'
148  . $fieldId
149  . '" >'
150  . htmlspecialchars($taskInfo['configuration'])
151  . '</textarea>';
152  $label = $lang->sL($this->languageFile . ':tasks.validate.conf');
153  $label = BackendUtility::wrapInHelp('linkvalidator', $fieldId, $label);
154  $additionalFields[$fieldId] = [
155  'code' => $fieldCode,
156  'label' => $label
157  ];
158  $fieldId = 'task_email';
159  $fieldCode = '<textarea class="form-control" rows="5" cols="50" name="tx_scheduler[linkvalidator][email]" id="'
160  . $fieldId
161  . '">'
162  . htmlspecialchars($taskInfo['email'])
163  . '</textarea>';
164  $label = $lang->sL($this->languageFile . ':tasks.validate.email');
165  $label = BackendUtility::wrapInHelp('linkvalidator', $fieldId, $label);
166  $additionalFields[$fieldId] = [
167  'code' => $fieldCode,
168  'label' => $label
169  ];
170  $fieldId = 'task_emailOnBrokenLinkOnly';
171  $fieldCode = '<div class="checkbox"><label>'
172  . '<input type="checkbox" name="tx_scheduler[linkvalidator][emailOnBrokenLinkOnly]" id="' . $fieldId . '" '
173  . (htmlspecialchars($taskInfo['emailOnBrokenLinkOnly']) ? 'checked="checked"' : '')
174  . '></label></div>';
175  $label = $lang->sL($this->languageFile . ':tasks.validate.emailOnBrokenLinkOnly');
176  $label = BackendUtility::wrapInHelp('linkvalidator', $fieldId, $label);
177  $additionalFields[$fieldId] = [
178  'code' => $fieldCode,
179  'label' => $label
180  ];
181  $fieldId = 'task_emailTemplateFile';
182  $fieldCode = '<input class="form-control" type="text" name="tx_scheduler[linkvalidator][emailTemplateFile]" '
183  . 'id="'
184  . $fieldId
185  . '" value="'
186  . htmlspecialchars($taskInfo['emailTemplateFile'])
187  . '">';
188  $label = $lang->sL($this->languageFile . ':tasks.validate.emailTemplateFile');
189  $label = BackendUtility::wrapInHelp('linkvalidator', $fieldId, $label);
190  $additionalFields[$fieldId] = [
191  'code' => $fieldCode,
192  'label' => $label
193  ];
194  return $additionalFields;
195  }
196 
204  protected function getSelectedState(array $configurationArray, $currentValue)
205  {
206  $selected = '';
207  if (in_array($currentValue, $configurationArray, true)) {
208  $selected = 'selected="selected" ';
209  }
210  return $selected;
211  }
212 
221  public function validateAdditionalFields(array &$submittedData, SchedulerModuleController $schedulerModule)
222  {
223  $isValid = true;
224  // @todo add validation to validate the $submittedData['configuration']
225  // @todo which is normally a comma separated string
226  $lang = $this->getLanguageService();
227  if (!empty($submittedData['linkvalidator']['email'])) {
228  if (strpos($submittedData['linkvalidator']['email'], ',') !== false) {
229  $emailList = GeneralUtility::trimExplode(',', $submittedData['linkvalidator']['email']);
230  } else {
231  $emailList = GeneralUtility::trimExplode(LF, $submittedData['linkvalidator']['email']);
232  }
233  foreach ($emailList as $emailAdd) {
234  if (!GeneralUtility::validEmail($emailAdd)) {
235  $isValid = false;
236  $schedulerModule->addMessage(
237  $lang->sL($this->languageFile . ':tasks.validate.invalidEmail'),
239  );
240  }
241  }
242  }
243 
244  $row = BackendUtility::getRecord('pages', (int)$submittedData['linkvalidator']['page'], '*', '', false);
245  if (empty($row)) {
246  $isValid = false;
247  $schedulerModule->addMessage(
248  $lang->sL($this->languageFile . ':tasks.validate.invalidPage'),
250  );
251  }
252  if ($submittedData['linkvalidator']['depth'] < 0) {
253  $isValid = false;
254  $schedulerModule->addMessage(
255  $lang->sL($this->languageFile . ':tasks.validate.invalidDepth'),
257  );
258  }
259  return $isValid;
260  }
261 
269  public function saveAdditionalFields(array $submittedData, AbstractTask $task)
270  {
272  $task->setDepth($submittedData['linkvalidator']['depth']);
273  $task->setPage($submittedData['linkvalidator']['page']);
274  $task->setEmail($submittedData['linkvalidator']['email']);
275  if ($submittedData['linkvalidator']['emailOnBrokenLinkOnly']) {
276  $task->setEmailOnBrokenLinkOnly(1);
277  } else {
278  $task->setEmailOnBrokenLinkOnly(0);
279  }
280  $task->setConfiguration($submittedData['linkvalidator']['configuration']);
281  $task->setEmailTemplateFile($submittedData['linkvalidator']['emailTemplateFile']);
282  }
283 
290  private function getPageTitle($pageId)
291  {
292  $page = BackendUtility::getRecord('pages', $pageId, 'title', '', false);
293  if ($page === null) {
294  return '';
295  }
296  return $page['title'];
297  }
298 
302  protected function getLanguageService()
303  {
304  return $GLOBALS['LANG'];
305  }
306 }
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)
static getRecord($table, $uid, $fields=' *', $where='', $useDeleteClause=true)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']