人人商城

functions.php 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. function es_empty()
  3. {
  4. $empty_file = ES_CONTROLLER_PATH . ES_EMPTY_CONTROLLER . '.php';
  5. if (is_file($empty_file)) {
  6. require $empty_file;
  7. $empty_controller = ES_EMPTY_CONTROLLER . 'Controller';
  8. $empty_class = new $empty_controller();
  9. $empty_class->index();
  10. exit();
  11. }
  12. trigger_error('Empty Controller Not Found!');
  13. exit();
  14. }
  15. function webUrl($route = '', $scheme = false)
  16. {
  17. if (is_array($route)) {
  18. if (strncmp($route[0], '/', 1) === 0) {
  19. ltrim($route[0], '/');
  20. }
  21. $routeArr = explode('/', strtolower($route[0]));
  22. if (1 < count($routeArr)) {
  23. $classMethod = '?c=' . $routeArr[0] . '&a=' . $routeArr[1];
  24. }
  25. else {
  26. $classMethod = '?c=' . $routeArr[0] . '&a=index';
  27. }
  28. unset($route[0]);
  29. unset($route['c']);
  30. unset($route['a']);
  31. $url = '';
  32. foreach ($route as $key => $value ) {
  33. $url .= '&' . $key . '=' . $value;
  34. }
  35. }
  36. if (is_string($route)) {
  37. $routeArr = explode('/', strtolower($route));
  38. if (1 < count($routeArr)) {
  39. $classMethod = '?c=' . $routeArr[0] . '&a=' . $routeArr[1];
  40. }
  41. else {
  42. $classMethod = '?c=' . $routeArr[0] . '&a=index';
  43. }
  44. }
  45. if (($route == '') || is_bool($route)) {
  46. $classMethod = '?c=' . ES_DEFAULT_CONTROLLER . '&a=' . ES_DEFAULT_ACTION;
  47. }
  48. if ($scheme) {
  49. return ES_URL . 'index.php' . $classMethod . $url;
  50. }
  51. return ES_SCRIPT_NAME . $classMethod . $url;
  52. }
  53. function pctomedia($src, $local_path = false)
  54. {
  55. global $_W;
  56. if (empty($src)) {
  57. return '';
  58. }
  59. if (strpos($src, './addons') === 0) {
  60. return $_W['siteroot'] . str_replace('./', '', $src);
  61. }
  62. if (strexists($src, $_W['siteroot']) && !(strexists($src, '/addons/'))) {
  63. $urls = parse_url($src);
  64. $src = $t = substr($urls['path'], strpos($urls['path'], 'images'));
  65. }
  66. $t = strtolower($src);
  67. if (strexists($t, 'http://') || strexists($t, 'https://')) {
  68. return $src;
  69. }
  70. $http_type = (((isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on')) || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://'));
  71. if ($local_path || empty($_W['setting']['remote']['type']) || file_exists(IA_ROOT . '/' . $_W['config']['upload']['attachdir'] . '/' . $src)) {
  72. $src = $http_type . $_SERVER['SERVER_NAME'] . '/' . $_W['config']['upload']['attachdir'] . '/' . $src;
  73. }
  74. else {
  75. $src = $_W['attachurl_remote'] . $src;
  76. }
  77. return $src;
  78. }
  79. ?>