/** * Deletes all files older than a specific time in a temporary upload folder. * Settings for the threshold time and the folder are made in TypoScript. * * Here is an example: * <code> * plugin.Tx_Formhandler.settings.files.clearTempFilesOlderThanHours = 24 * plugin.Tx_Formhandler.settings.files.tmpUploadFolder = uploads/formhandler/tmp * </code> * * @param integer $olderThan Delete files older than $olderThan hours. * @return void * @author Reinhard Führicht <*****@*****.**> */ protected function clearTempFiles($uploadFolder, $olderThanValue, $olderThanUnit) { if (!$olderThanValue) { return; } //build absolute path to upload folder $path = Tx_Formhandler_StaticFuncs::getDocumentRoot() . $uploadFolder; //read files in directory $tmpFiles = t3lib_div::getFilesInDir($path); Tx_Formhandler_StaticFuncs::debugMessage('cleaning_temp_files', array($path)); //calculate threshold timestamp //hours * 60 * 60 = millseconds $threshold = Tx_Formhandler_StaticFuncs::getTimestamp($olderThanValue, $olderThanUnit); //for all files in temp upload folder foreach ($tmpFiles as $idx => $file) { //if creation timestamp is lower than threshold timestamp //delete the file $creationTime = filemtime($path . $file); //fix for different timezones $creationTime += date('O') / 100 * 60; if ($creationTime < $threshold) { unlink($path . $file); Tx_Formhandler_StaticFuncs::debugMessage('deleting_file', array($file)); } } }
/** * Checks if the form got submitted too often and throws Exception if TRUE. * * @param int Timebase value * @param string Timebase unit (seconds|minutes|hours|days) * @param int maximum amount of submissions in given time base. * @param boolean add IP address to where clause * @return void */ private function check($value, $unit, $maxValue, $addIPToWhere = TRUE) { $timestamp = Tx_Formhandler_StaticFuncs::getTimestamp($value, $unit); $where = 'crdate >= ' . $timestamp; if ($addIPToWhere) { $where = 'ip=\'' . t3lib_div::getIndpEnv('REMOTE_ADDR') . '\' AND ' . $where; } $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,ip,crdate,params', $this->logTable, $where); if ($res && $GLOBALS['TYPO3_DB']->sql_num_rows($res) >= $maxValue) { $this->log(TRUE); $message = 'You are not allowed to send more mails because form got submitted too many times '; if ($addIPToWhere) { $message .= 'by your IP address '; } $message .= 'in the last ' . $value . ' ' . $unit . '!'; if ($this->settings['report.']['email']) { while (FALSE !== ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))) { $rows[] = $row; } $intervalValue = $this->settings['report.']['interval.']['value']; $intervalUnit = $this->settings['report.']['interval.']['unit']; $send = TRUE; if ($intervalUnit && $intervalValue) { $intervalTstamp = Tx_Formhandler_StaticFuncs::getTimestamp($intervalValue, $intervalUnit); $where = 'pid=' . $GLOBALS['TSFE']->id . ' AND crdate>' . $intervalTstamp; if ($addIPToWhere) { $where .= ' AND ip=\'' . t3lib_div::getIndpEnv('REMOTE_ADDR') . '\''; } $res_log = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', $this->reportTable, $where); if ($res_log && $GLOBALS['TYPO3_DB']->sql_num_rows($res_log) > 0) { $send = FALSE; $GLOBALS['TYPO3_DB']->sql_free_result($res_log); } } if ($send) { if ($addIPToWhere) { $this->sendReport('ip', $rows); } else { $this->sendReport('global', $rows); } } else { Tx_Formhandler_StaticFuncs::debugMessage('alert_mail_not_sent', array(), 2); } } $GLOBALS['TYPO3_DB']->sql_free_result($res); if ($this->settings['redirectPage']) { Tx_Formhandler_StaticFuncs::doRedirect($this->settings['redirectPage'], $this->settings['correctRedirectUrl'], $this->settings['additionalParams.']); Tx_Formhandler_StaticFuncs::debugMessage('redirect_failed', array(), 2); exit(0); } else { throw new Exception($message); } } }