Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class user_powermailhelp {
- // Function preflight() will be used from typoscript
- function preflight($content='', $conf=array()) {
- #t3lib_div::debug($conf);
- $value = $GLOBALS['TSFE']->fe_user->sesData['powermail_'.$conf['userFunc.']['formuid']][$conf['userFunc.']['field']];
- return $this->getDate($value);
- }
- // Main getDate() changes a date in any format to an unix timestamp
- function getDate($string, $default = 'now', $timestamp = 1) {
- $error = 0; // no error at the beginning
- $string = str_replace(array('-', '_', ':', '+', ','), '.', $string); // change 23-12-2009 -> 23.12.2009
- if (method_exists('t3lib_div', 'trimExplode')) $dateParts = t3lib_div::trimExplode('.', $string, 1); else $dateParts = explode('.', $string); // split at .
- if (count($dateParts) === 3) { // only if there are three parts
- if (strlen($dateParts[0]) <= 2 && strlen($dateParts[1]) <= 2 && strlen($dateParts[2]) <= 2) { // xx.xx.xx
- $string = strtotime($dateParts[2].'-'.$dateParts[1].'-'.$dateParts[0]); // change to timestamp
- }
- elseif (strlen($dateParts[0]) == 4 && strlen($dateParts[1]) <= 2 && strlen($dateParts[2]) <= 2) { // xxxx.xx.xx
- $string = strtotime($dateParts[0].'-'.$dateParts[1].'-'.$dateParts[2]); // change to timestamp
- }
- elseif (strlen($dateParts[0]) <= 2 && strlen($dateParts[1]) <= 2 && strlen($dateParts[2]) == 4) { // xx.xx.xxxx
- $string = strtotime($dateParts[2].'-'.$dateParts[1].'-'.$dateParts[0]); // change to timestamp
- }
- else { // error
- $error = 1; // error
- }
- } else { // more than 3 parts - so error
- $error = 1; // error
- }
- $string = date('Y-m-d', $string); // For default: change 1234567 -> 1.1.1979
- if ($timestamp) $string = strtotime($string); // Change back 1.1.1979 -> 1234567
- if ($error) $string = ($default == 'now' ? time() : $default); // show default value
- return $string;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement