Advertisement
Guest User

Alex

a guest
Jan 23rd, 2009
1,345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. <?php
  2.  
  3. class user_powermailhelp {
  4.  
  5.  
  6. // Function preflight() will be used from typoscript
  7. function preflight($content='', $conf=array()) {
  8. #t3lib_div::debug($conf);
  9. $value = $GLOBALS['TSFE']->fe_user->sesData['powermail_'.$conf['userFunc.']['formuid']][$conf['userFunc.']['field']];
  10. return $this->getDate($value);
  11. }
  12.  
  13.  
  14. // Main getDate() changes a date in any format to an unix timestamp
  15. function getDate($string, $default = 'now', $timestamp = 1) {
  16. $error = 0; // no error at the beginning
  17. $string = str_replace(array('-', '_', ':', '+', ','), '.', $string); // change 23-12-2009 -> 23.12.2009
  18. if (method_exists('t3lib_div', 'trimExplode')) $dateParts = t3lib_div::trimExplode('.', $string, 1); else $dateParts = explode('.', $string); // split at .
  19.  
  20. if (count($dateParts) === 3) { // only if there are three parts
  21. if (strlen($dateParts[0]) <= 2 && strlen($dateParts[1]) <= 2 && strlen($dateParts[2]) <= 2) { // xx.xx.xx
  22. $string = strtotime($dateParts[2].'-'.$dateParts[1].'-'.$dateParts[0]); // change to timestamp
  23. }
  24. elseif (strlen($dateParts[0]) == 4 && strlen($dateParts[1]) <= 2 && strlen($dateParts[2]) <= 2) { // xxxx.xx.xx
  25. $string = strtotime($dateParts[0].'-'.$dateParts[1].'-'.$dateParts[2]); // change to timestamp
  26. }
  27. elseif (strlen($dateParts[0]) <= 2 && strlen($dateParts[1]) <= 2 && strlen($dateParts[2]) == 4) { // xx.xx.xxxx
  28. $string = strtotime($dateParts[2].'-'.$dateParts[1].'-'.$dateParts[0]); // change to timestamp
  29. }
  30. else { // error
  31. $error = 1; // error
  32. }
  33. } else { // more than 3 parts - so error
  34. $error = 1; // error
  35. }
  36. $string = date('Y-m-d', $string); // For default: change 1234567 -> 1.1.1979
  37. if ($timestamp) $string = strtotime($string); // Change back 1.1.1979 -> 1234567
  38. if ($error) $string = ($default == 'now' ? time() : $default); // show default value
  39.  
  40. return $string;
  41. }
  42. }
  43.  
  44. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement