PageRenderTime 23ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/addons/DynamicMTML.pack/php/lib/mt_util.php

http://github.com/movabletype/DynamicMTML
PHP | 52 lines | 44 code | 7 blank | 1 comment | 11 complexity | 5e9d08bef4273335493fe7d17ba7a65b MD5 | raw file
Possible License(s): MIT, GPL-2.0
  1. <?php
  2. // Moved from mt.php
  3. function is_valid_email( $addr ) {
  4. if ( preg_match('/[ |\t|\r|\n]*\"?([^\"]+\"?@[^ <>\t]+\.[^ <>\t][^ <>\t]+)[ |\t|\r|\n]*/', $addr, $matches ) ) {
  5. return $matches[1];
  6. } else {
  7. return 0;
  8. }
  9. }
  10. $spam_protect_map = array( ':' => '&#58;', '@' => '&#64;', '.' => '&#46;' );
  11. function spam_protect ( $str ) {
  12. global $spam_protect_map;
  13. return strtr( $str, $spam_protect_map );
  14. }
  15. function offset_time ( $ts, $blog = NULL, $dir = NULL ) {
  16. if ( isset( $blog ) ) {
  17. if (! is_array( $blog ) ) {
  18. global $mt;
  19. $blog = $mt->db()->fetch_blog( $blog->id );
  20. }
  21. $offset = $blog->blog_server_offset;
  22. } else {
  23. global $mt;
  24. $offset = $mt->config( 'TimeOffset' );
  25. }
  26. intval( $offset ) or $offset = 0;
  27. $tsa = localtime( $ts );
  28. if ( $tsa[8] ) { // daylight savings offset
  29. $offset++;
  30. }
  31. if ( $dir == '-' ) {
  32. $offset *= -1;
  33. }
  34. $ts += $offset * 3600;
  35. return $ts;
  36. }
  37. function translate_phrase_param( $str, $params = NULL ) {
  38. if ( is_array( $params ) && ( strpos( $str, '[_' ) !== FALSE ) ) {
  39. for ( $i = 1; $i <= count( $params ); $i++ ) {
  40. $str = preg_replace( "/\\[_$i\\]/", $params[$i-1], $str );
  41. }
  42. }
  43. return $str;
  44. }
  45. ?>