TYPO3 CMS  TYPO3_6-2
ValidatorTaskAdditionalFieldProvider.php
Go to the documentation of this file.
1 <?php
3 
18 
26 
36  public function getAdditionalFields(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $schedulerModule) {
37  $additionalFields = array();
38  if (empty($taskInfo['configuration'])) {
39  if ($schedulerModule->CMD == 'add') {
40  $taskInfo['configuration'] = '';
41  } elseif ($schedulerModule->CMD == 'edit') {
42  $taskInfo['configuration'] = $task->getConfiguration();
43  } else {
44  $taskInfo['configuration'] = $task->getConfiguration();
45  }
46  }
47  if (empty($taskInfo['depth'])) {
48  if ($schedulerModule->CMD == 'add') {
49  $taskInfo['depth'] = array();
50  } elseif ($schedulerModule->CMD == 'edit') {
51  $taskInfo['depth'] = $task->getDepth();
52  } else {
53  $taskInfo['depth'] = $task->getDepth();
54  }
55  }
56  if (empty($taskInfo['page'])) {
57  if ($schedulerModule->CMD == 'add') {
58  $taskInfo['page'] = '';
59  } elseif ($schedulerModule->CMD == 'edit') {
60  $taskInfo['page'] = $task->getPage();
61  } else {
62  $taskInfo['page'] = $task->getPage();
63  }
64  }
65  if (empty($taskInfo['email'])) {
66  if ($schedulerModule->CMD == 'add') {
67  $taskInfo['email'] = '';
68  } elseif ($schedulerModule->CMD == 'edit') {
69  $taskInfo['email'] = $task->getEmail();
70  } else {
71  $taskInfo['email'] = $task->getEmail();
72  }
73  }
74  if (empty($taskInfo['emailOnBrokenLinkOnly'])) {
75  if ($schedulerModule->CMD == 'add') {
76  $taskInfo['emailOnBrokenLinkOnly'] = 1;
77  } elseif ($schedulerModule->CMD == 'edit') {
78  $taskInfo['emailOnBrokenLinkOnly'] = $task->getEmailOnBrokenLinkOnly();
79  } else {
80  $taskInfo['emailOnBrokenLinkOnly'] = $task->getEmailOnBrokenLinkOnly();
81  }
82  }
83  if (empty($taskInfo['emailTemplateFile'])) {
84  if ($schedulerModule->CMD == 'add') {
85  $taskInfo['emailTemplateFile'] = 'EXT:linkvalidator/Resources/Private/Templates/mailtemplate.html';
86  } elseif ($schedulerModule->CMD == 'edit') {
87  $taskInfo['emailTemplateFile'] = $task->getEmailTemplateFile();
88  } else {
89  $taskInfo['emailTemplateFile'] = $task->getEmailTemplateFile();
90  }
91  }
92  $fieldId = 'task_page';
93  $fieldCode = '<input type="text" name="tx_scheduler[linkvalidator][page]" id="' . $fieldId . '" value="' . htmlspecialchars($taskInfo['page']) . '"/>';
94  $label = $GLOBALS['LANG']->sL('LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.validate.page');
95  $label = BackendUtility::wrapInHelp('linkvalidator', $fieldId, $label);
96  $additionalFields[$fieldId] = array(
97  'code' => $fieldCode,
98  'label' => $label
99  );
100  // input for depth
101  $fieldId = 'task_depth';
102  $fieldValueArray = array(
103  '0' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_0'),
104  '1' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_1'),
105  '2' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_2'),
106  '3' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_3'),
107  '4' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_4'),
108  '999' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_infi')
109  );
110  $fieldCode = '<select name="tx_scheduler[linkvalidator][depth]" id="' . $fieldId . '">';
111  foreach ($fieldValueArray as $depth => $label) {
112  $fieldCode .= "\t" . '<option value="' . htmlspecialchars($depth) . '"' .
113  (($depth == $taskInfo['depth']) ? ' selected="selected"' : '') .
114  '>' . $label . '</option>';
115  }
116  $fieldCode .= '</select>';
117  $label = $GLOBALS['LANG']->sL('LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.validate.depth');
118  $label = BackendUtility::wrapInHelp('linkvalidator', $fieldId, $label);
119  $additionalFields[$fieldId] = array(
120  'code' => $fieldCode,
121  'label' => $label
122  );
123  $fieldId = 'task_configuration';
124  $fieldCode = '<textarea name="tx_scheduler[linkvalidator][configuration]" id="' . $fieldId . '" >' .
125  htmlspecialchars($taskInfo['configuration']) . '</textarea>';
126  $label = $GLOBALS['LANG']->sL('LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.validate.conf');
127  $label = BackendUtility::wrapInHelp('linkvalidator', $fieldId, $label);
128  $additionalFields[$fieldId] = array(
129  'code' => $fieldCode,
130  'label' => $label
131  );
132  $fieldId = 'task_email';
133  $fieldCode = '<input type="text" name="tx_scheduler[linkvalidator][email]" id="' . $fieldId . '" value="' .
134  htmlspecialchars($taskInfo['email']) . '" />';
135  $label = $GLOBALS['LANG']->sL('LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.validate.email');
136  $label = BackendUtility::wrapInHelp('linkvalidator', $fieldId, $label);
137  $additionalFields[$fieldId] = array(
138  'code' => $fieldCode,
139  'label' => $label
140  );
141  $fieldId = 'task_emailOnBrokenLinkOnly';
142  $fieldCode = '<input type="checkbox" name="tx_scheduler[linkvalidator][emailOnBrokenLinkOnly]" id="' . $fieldId . '" ' .
143  (htmlspecialchars($taskInfo['emailOnBrokenLinkOnly']) ? 'checked="checked"' : '') . ' />';
144  $label = $GLOBALS['LANG']->sL('LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.validate.emailOnBrokenLinkOnly');
145  $label = BackendUtility::wrapInHelp('linkvalidator', $fieldId, $label);
146  $additionalFields[$fieldId] = array(
147  'code' => $fieldCode,
148  'label' => $label
149  );
150  $fieldId = 'task_emailTemplateFile';
151  $fieldCode = '<input type="text" name="tx_scheduler[linkvalidator][emailTemplateFile]" id="' . $fieldId .
152  '" value="' . htmlspecialchars($taskInfo['emailTemplateFile']) . '" />';
153  $label = $GLOBALS['LANG']->sL('LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.validate.emailTemplateFile');
154  $label = BackendUtility::wrapInHelp('linkvalidator', $fieldId, $label);
155  $additionalFields[$fieldId] = array(
156  'code' => $fieldCode,
157  'label' => $label
158  );
159  return $additionalFields;
160  }
161 
169  protected function getSelectedState(array $configurationArray, $currentValue) {
170  $selected = '';
171  if (in_array($currentValue, $configurationArray, TRUE)) {
172  $selected = 'selected="selected" ';
173  }
174  return $selected;
175  }
176 
185  public function validateAdditionalFields(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $schedulerModule) {
186  $isValid = TRUE;
187  //TODO add validation to validate the $submittedData['configuration'] which is normally a comma separated string
188  if (!empty($submittedData['linkvalidator']['email'])) {
189  $emailList = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $submittedData['linkvalidator']['email']);
190  foreach ($emailList as $emailAdd) {
191  if (!\TYPO3\CMS\Core\Utility\GeneralUtility::validEmail($emailAdd)) {
192  $isValid = FALSE;
193  $schedulerModule->addMessage($GLOBALS['LANG']->sL('LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.validate.invalidEmail'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
194  }
195  }
196  }
197  if ($res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'pages', 'uid = ' . (int)$submittedData['linkvalidator']['page'])) {
198  if ($GLOBALS['TYPO3_DB']->sql_num_rows($res) == 0 && $submittedData['linkvalidator']['page'] > 0) {
199  $isValid = FALSE;
200  $schedulerModule->addMessage(
201  $GLOBALS['LANG']->sL('LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.validate.invalidPage'),
202  \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
203  );
204  }
205  $GLOBALS['TYPO3_DB']->sql_free_result($res);
206  } else {
207  $isValid = FALSE;
208  $schedulerModule->addMessage(
209  $GLOBALS['LANG']->sL('LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.validate.invalidPage'),
210  \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
211  );
212  }
213  if ($submittedData['linkvalidator']['depth'] < 0) {
214  $isValid = FALSE;
215  $schedulerModule->addMessage(
216  $GLOBALS['LANG']->sL('LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.validate.invalidDepth'),
217  \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
218  );
219  }
220  return $isValid;
221  }
222 
231  public function saveAdditionalFields(array $submittedData, \TYPO3\CMS\Scheduler\Task\AbstractTask $task) {
233  $task->setDepth($submittedData['linkvalidator']['depth']);
234  $task->setPage($submittedData['linkvalidator']['page']);
235  $task->setEmail($submittedData['linkvalidator']['email']);
236  if ($submittedData['linkvalidator']['emailOnBrokenLinkOnly']) {
237  $task->setEmailOnBrokenLinkOnly(1);
238  } else {
239  $task->setEmailOnBrokenLinkOnly(0);
240  }
241  $task->setConfiguration($submittedData['linkvalidator']['configuration']);
242  $task->setEmailTemplateFile($submittedData['linkvalidator']['emailTemplateFile']);
243  }
244 
245 }
validateAdditionalFields(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $schedulerModule)
static trimExplode($delim, $string, $removeEmptyValues=FALSE, $limit=0)
saveAdditionalFields(array $submittedData, \TYPO3\CMS\Scheduler\Task\AbstractTask $task)
static wrapInHelp($table, $field, $text='', array $overloadHelpText=array())
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
getAdditionalFields(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $schedulerModule)