|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 2010 - 2011 Michael Miousse (michael.miousse@infoglobe.ca) 00006 * All rights reserved 00007 * 00008 * This script is part of the TYPO3 project. The TYPO3 project is 00009 * free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * The GNU General Public License can be found at 00015 * http://www.gnu.org/copyleft/gpl.html. 00016 * 00017 * This script is distributed in the hope that it will be useful, 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 * GNU General Public License for more details. 00021 * 00022 * This copyright notice MUST APPEAR in all copies of the script! 00023 ***************************************************************/ 00024 /** 00025 * This class provides Scheduler Additional Field plugin implementation. 00026 * 00027 * @author Dimitri König <dk@cabag.ch> 00028 * @author Michael Miousse <michael.miousse@infoglobe.ca> 00029 * @package TYPO3 00030 * @subpackage linkvalidator 00031 */ 00032 class tx_linkvalidator_tasks_ValidatorAdditionalFieldProvider implements tx_scheduler_AdditionalFieldProvider { 00033 00034 /** 00035 * Render additional information fields within the scheduler backend. 00036 * 00037 * @param array $taksInfo: array information of task to return 00038 * @param task $task: task object 00039 * @param tx_scheduler_Module $schedulerModule: reference to the calling object (BE module of the Scheduler) 00040 * @return array additional fields 00041 * @see interfaces/tx_scheduler_AdditionalFieldProvider#getAdditionalFields($taskInfo, $task, $schedulerModule) 00042 */ 00043 public function getAdditionalFields(array &$taskInfo, $task, tx_scheduler_Module $schedulerModule) { 00044 $additionalFields = array(); 00045 if (empty($taskInfo['configuration'])) { 00046 if ($schedulerModule->CMD == 'add') { 00047 $taskInfo['configuration'] = ''; 00048 } elseif ($schedulerModule->CMD == 'edit') { 00049 $taskInfo['configuration'] = $task->getConfiguration(); 00050 } else { 00051 $taskInfo['configuration'] = $task->getConfiguration(); 00052 } 00053 } 00054 00055 if (empty($taskInfo['depth'])) { 00056 if ($schedulerModule->CMD == 'add') { 00057 $taskInfo['depth'] = array(); 00058 } elseif ($schedulerModule->CMD == 'edit') { 00059 $taskInfo['depth'] = $task->getDepth(); 00060 } else { 00061 $taskInfo['depth'] = $task->getDepth(); 00062 } 00063 } 00064 00065 if (empty($taskInfo['page'])) { 00066 if ($schedulerModule->CMD == 'add') { 00067 $taskInfo['page'] = ''; 00068 } elseif ($schedulerModule->CMD == 'edit') { 00069 $taskInfo['page'] = $task->getPage(); 00070 } else { 00071 $taskInfo['page'] = $task->getPage(); 00072 } 00073 } 00074 if (empty($taskInfo['email'])) { 00075 if ($schedulerModule->CMD == 'add') { 00076 $taskInfo['email'] = ''; 00077 } elseif ($schedulerModule->CMD == 'edit') { 00078 $taskInfo['email'] = $task->getEmail(); 00079 } else { 00080 $taskInfo['email'] = $task->getEmail(); 00081 } 00082 } 00083 00084 if (empty($taskInfo['emailOnBrokenLinkOnly'])) { 00085 if ($schedulerModule->CMD == 'add') { 00086 $taskInfo['emailOnBrokenLinkOnly'] = 1; 00087 } elseif ($schedulerModule->CMD == 'edit') { 00088 $taskInfo['emailOnBrokenLinkOnly'] = $task->getEmailOnBrokenLinkOnly(); 00089 } else { 00090 $taskInfo['emailOnBrokenLinkOnly'] = $task->getEmailOnBrokenLinkOnly(); 00091 } 00092 } 00093 if (empty($taskInfo['emailTemplateFile'])) { 00094 if ($schedulerModule->CMD == 'add') { 00095 $taskInfo['emailTemplateFile'] = 'EXT:linkvalidator/res/mailtemplate.html'; 00096 } elseif ($schedulerModule->CMD == 'edit') { 00097 $taskInfo['emailTemplateFile'] = $task->getEmailTemplateFile(); 00098 } else { 00099 $taskInfo['emailTemplateFile'] = $task->getEmailTemplateFile(); 00100 } 00101 } 00102 00103 00104 $fieldID = 'task_page'; 00105 $fieldCode = '<input type="text" name="tx_scheduler[linkvalidator][page]" id="' . $fieldID . '" value="' . htmlspecialchars($taskInfo['page']) . '"/>'; 00106 $label = $GLOBALS['LANG']->sL('LLL:EXT:linkvalidator/locallang.xml:tasks.validate.page'); 00107 $label = t3lib_BEfunc::wrapInHelp('linkvalidator', $fieldID, $label); 00108 $additionalFields[$fieldID] = array( 00109 'code' => $fieldCode, 00110 'label' => $label 00111 ); 00112 00113 // input for depth 00114 $fieldID = 'task_depth'; 00115 $fieldValueArray = array( 00116 '0' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.depth_0'), 00117 '1' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.depth_1'), 00118 '2' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.depth_2'), 00119 '3' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.depth_3'), 00120 '4' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.depth_4'), 00121 '999' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.depth_infi'), 00122 ); 00123 $fieldCode = '<select name="tx_scheduler[linkvalidator][depth]" id="' . $fieldID . '">'; 00124 00125 foreach ($fieldValueArray as $depth => $label) { 00126 $fieldCode .= "\t" . '<option value="' . htmlspecialchars($depth) . '"' . (($depth ==$taskInfo['depth']) ? ' selected="selected"' : '') . '>' . $label . '</option>'; 00127 } 00128 00129 $fieldCode .= '</select>'; 00130 $label = $GLOBALS['LANG']->sL('LLL:EXT:linkvalidator/locallang.xml:tasks.validate.depth'); 00131 $label = t3lib_BEfunc::wrapInHelp('linkvalidator', $fieldID, $label); 00132 $additionalFields[$fieldID] = array( 00133 'code' => $fieldCode, 00134 'label' => $label 00135 ); 00136 00137 $fieldID = 'task_configuration'; 00138 $fieldCode = '<textarea name="tx_scheduler[linkvalidator][configuration]" id="' . $fieldID . '" >' . htmlspecialchars($taskInfo['configuration']) . '</textarea>'; 00139 $label = $GLOBALS['LANG']->sL('LLL:EXT:linkvalidator/locallang.xml:tasks.validate.conf'); 00140 $label = t3lib_BEfunc::wrapInHelp('linkvalidator', $fieldID, $label); 00141 $additionalFields[$fieldID] = array( 00142 'code' => $fieldCode, 00143 'label' => $label 00144 ); 00145 00146 $fieldID = 'task_email'; 00147 $fieldCode = '<input type="text" name="tx_scheduler[linkvalidator][email]" id="' . $fieldID . '" value="' . htmlspecialchars($taskInfo['email']) . '" />'; 00148 $label = $GLOBALS['LANG']->sL('LLL:EXT:linkvalidator/locallang.xml:tasks.validate.email'); 00149 $label = t3lib_BEfunc::wrapInHelp('linkvalidator', $fieldID, $label); 00150 $additionalFields[$fieldID] = array( 00151 'code' => $fieldCode, 00152 'label' => $label 00153 ); 00154 $fieldID = 'task_emailOnBrokenLinkOnly'; 00155 $fieldCode = '<input type="checkbox" name="tx_scheduler[linkvalidator][emailOnBrokenLinkOnly]" id="' . $fieldID . '" ' . (htmlspecialchars($taskInfo['emailOnBrokenLinkOnly']) ? 'checked="checked"' : '') . ' />'; 00156 $label = $GLOBALS['LANG']->sL('LLL:EXT:linkvalidator/locallang.xml:tasks.validate.emailOnBrokenLinkOnly'); 00157 $label = t3lib_BEfunc::wrapInHelp('linkvalidator', $fieldID, $label); 00158 $additionalFields[$fieldID] = array( 00159 'code' => $fieldCode, 00160 'label' => $label 00161 ); 00162 00163 $fieldID = 'task_emailTemplateFile'; 00164 $fieldCode = '<input type="text" name="tx_scheduler[linkvalidator][emailTemplateFile]" id="' . $fieldID . '" value="' . htmlspecialchars($taskInfo['emailTemplateFile']) . '" />'; 00165 $label = $GLOBALS['LANG']->sL('LLL:EXT:linkvalidator/locallang.xml:tasks.validate.emailTemplateFile'); 00166 $label = t3lib_BEfunc::wrapInHelp('linkvalidator', $fieldID, $label); 00167 $additionalFields[$fieldID] = array( 00168 'code' => $fieldCode, 00169 'label' => $label 00170 ); 00171 00172 return $additionalFields; 00173 } 00174 00175 00176 /** 00177 * Mark current value as selected by returning the "selected" attribute. 00178 * 00179 * @param array $configurationArray: array of configuration 00180 * @param string $currentValue: value of selector object 00181 * @return string Html fragment for a selected option or empty 00182 * @access protected 00183 */ 00184 protected function getSelectedState($configurationArray, $currentValue) { 00185 $selected = ''; 00186 for ($i = 0; $i < count($configurationArray); $i++) { 00187 if (strcmp($configurationArray[$i], $currentValue) === 0) { 00188 $selected = 'selected="selected" '; 00189 } 00190 } 00191 return $selected; 00192 } 00193 00194 00195 /** 00196 * This method checks any additional data that is relevant to the specific task. 00197 * If the task class is not relevant, the method is expected to return TRUE. 00198 * 00199 * @param array $submittedData: reference to the array containing the data submitted by the user 00200 * @param tx_scheduler_module1 $parentObject: reference to the calling object (BE module of the Scheduler) 00201 * @return boolean True if validation was ok (or selected class is not relevant), FALSE otherwise 00202 */ 00203 public function validateAdditionalFields(array &$submittedData, tx_scheduler_Module $schedulerModule) { 00204 $isValid = TRUE; 00205 00206 //!TODO add validation to validate the $submittedData['configuration'] wich is normally a comma seperated string 00207 if (!empty($submittedData['linkvalidator']['email'])) { 00208 $emailList = t3lib_div::trimExplode(',', $submittedData['linkvalidator']['email']); 00209 foreach ($emailList as $emailAdd) { 00210 if (!t3lib_div::validEmail($emailAdd)) { 00211 $isValid = FALSE; 00212 $schedulerModule->addMessage( 00213 $GLOBALS['LANG']->sL('LLL:EXT:linkvalidator/locallang.xml:tasks.validate.invalidEmail'), 00214 t3lib_FlashMessage::ERROR 00215 ); 00216 } 00217 } 00218 } 00219 00220 if ($res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'pages', 'uid = ' . $submittedData['linkvalidator']['page'])) { 00221 if ($GLOBALS['TYPO3_DB']->sql_num_rows($res) == 0 && $submittedData['linkvalidator']['page'] > 0) { 00222 $isValid = FALSE; 00223 $schedulerModule->addMessage( 00224 $GLOBALS['LANG']->sL('LLL:EXT:linkvalidator/locallang.xml:tasks.validate.invalidPage'), 00225 t3lib_FlashMessage::ERROR 00226 ); 00227 } 00228 } else { 00229 $isValid = FALSE; 00230 $schedulerModule->addMessage( 00231 $GLOBALS['LANG']->sL('LLL:EXT:linkvalidator/locallang.xml:tasks.validate.invalidPage'), 00232 t3lib_FlashMessage::ERROR 00233 ); 00234 } 00235 00236 if ($submittedData['linkvalidator']['depth'] < 0) { 00237 $isValid = FALSE; 00238 $schedulerModule->addMessage( 00239 $GLOBALS['LANG']->sL('LLL:EXT:linkvalidator/locallang.xml:tasks.validate.invalidDepth'), 00240 t3lib_FlashMessage::ERROR 00241 ); 00242 } 00243 00244 return $isValid; 00245 } 00246 00247 00248 /** 00249 * This method is used to save any additional input into the current task object 00250 * if the task class matches. 00251 * 00252 * @param array $submittedData: array containing the data submitted by the user 00253 * @param tx_scheduler_Task $task: reference to the current task object 00254 * @return void 00255 */ 00256 public function saveAdditionalFields(array $submittedData, tx_scheduler_Task $task) { 00257 $task->setDepth($submittedData['linkvalidator']['depth']); 00258 $task->setPage($submittedData['linkvalidator']['page']); 00259 $task->setEmail($submittedData['linkvalidator']['email']); 00260 if($submittedData['linkvalidator']['emailOnBrokenLinkOnly']){ 00261 $task->setEmailOnBrokenLinkOnly(1); 00262 } 00263 else{ 00264 $task->setEmailOnBrokenLinkOnly(0); 00265 } 00266 $task->setConfiguration($submittedData['linkvalidator']['configuration']); 00267 $task->setEmailTemplateFile($submittedData['linkvalidator']['emailTemplateFile']); 00268 } 00269 00270 00271 } 00272 00273 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/linkvalidator/classes/tasks/class.tx_linkvalidator_tasks_validatoradditionalfieldprovider.php'])) { 00274 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/linkvalidator/classes/tasks/class.tx_linkvalidator_tasks_validatoradditionalfieldprovider.php']); 00275 } 00276 00277 ?>
1.8.0