PageRenderTime 49ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/aoliz/core/model/utility/mdl.url.php

http://phpfor.googlecode.com/
PHP | 177 lines | 108 code | 31 blank | 38 comment | 16 complexity | 62d279d911cd0b102b433ccbf4cbcac8 MD5 | raw file
  1. <?php
  2. /**
  3. * mdl_url
  4. *
  5. * @uses modelFactory
  6. * @package
  7. * @version $Id$
  8. * @copyright 2003-2007 ShopEx
  9. * @author Wanglei <flaboy@shopex.cn>
  10. * @license Commercial
  11. */
  12. class mdl_url extends modelFactory{
  13. /**
  14. * map
  15. * ??plugins/function/urlmap
  16. *
  17. * @param mixed $url
  18. * @access public
  19. * @return void
  20. */
  21. function map($url){
  22. $map = null;
  23. if(include(PLUGIN_DIR.'/functions/urlmap.php')){
  24. if(is_array($map) && ($url!=($result = preg_replace(array_keys($map),$map,$url)))) {
  25. $result = explode('|',$result);
  26. if(count($result)>2){
  27. $ctl = array_shift($result);
  28. $act = array_shift($result);
  29. return $this->system->mkUrl($ctl,$act,$result);
  30. }else{
  31. return $this->system->mkUrl($result[0],$result[1]);
  32. }
  33. }else{
  34. return false;
  35. }
  36. }else{
  37. return false;
  38. }
  39. }
  40. /**
  41. * oldVersionShopEx
  42. * gOo???
  43. *
  44. * @param mixed $action
  45. * @access public
  46. * @return void
  47. */
  48. function oldVersionShopEx($action){
  49. if($ret = $this->getGOO($action)){
  50. return $ret;
  51. }else{
  52. $action['gOo'] = base64_decode($action['gOo']);
  53. if($ret = $this->getGOO($action)){
  54. return $ret;
  55. }else{
  56. return $this->system->mkUrl('sitemap','index');
  57. }
  58. }
  59. }
  60. function getGOO($action){
  61. switch($action['gOo']){
  62. case 'goods_search_list.dwt':
  63. case 'goods_category.dwt':
  64. return $this->system->mkUrl('gallery',$this->system->getConf('gallery.default_view'),array($action['gcat'],null,0,null,$action['p']));
  65. case 'goods_details.dwt':
  66. return $this->system->mkUrl('product','index',array($action['goodsid']));
  67. case 'article_list.dwt':
  68. return $this->system->mkUrl('artlist','index',array($action['acat']));
  69. case 'article_details.dwt':
  70. return $this->system->mkUrl('article','index',array($action['articleid']));
  71. case 'register.dwt':
  72. return $this->system->mkUrl('passport','signup');
  73. case 'logout_act.do':
  74. return $this->system->mkUrl('passport','logout');
  75. case 'forget.dwt':
  76. return $this->system->mkUrl('passport','forget');
  77. case 'discuz_reply.do':
  78. include_once(CORE_DIR."/func_ext.php");
  79. return $this->system->mkUrl('passport','callback',array('discuz')).'?action='.http_build_query($action);
  80. // case 'shopbbs.dwt':
  81. // break;
  82. // case 'linkmore.dwt':
  83. // break;
  84. case 'logout_act.do':
  85. return $this->system->mkUrl('passport','logout');
  86. default :
  87. return false;
  88. }
  89. }
  90. }
  91. if (!function_exists('http_build_query')) { //??func_ext??
  92. function http_build_query($formdata, $numeric_prefix = null)
  93. {
  94. // If $formdata is an object, convert it to an array
  95. if (is_object($formdata)) {
  96. $formdata = get_object_vars($formdata);
  97. }
  98. // Check we have an array to work with
  99. if (!is_array($formdata)) {
  100. user_error('http_build_query() Parameter 1 expected to be Array or Object. Incorrect value given.',
  101. E_USER_WARNING);
  102. return false;
  103. }
  104. // If the array is empty, return null
  105. if (empty($formdata)) {
  106. return;
  107. }
  108. // Argument seperator
  109. $separator = ini_get('arg_separator.output');
  110. // Start building the query
  111. $tmp = array ();
  112. foreach ($formdata as $key => $val) {
  113. if (is_integer($key) && $numeric_prefix != null) {
  114. $key = $numeric_prefix . $key;
  115. }
  116. if (is_scalar($val)) {
  117. array_push($tmp, urlencode($key).'='.urlencode($val));
  118. continue;
  119. }
  120. // If the value is an array, recursively parse it
  121. if (is_array($val)) {
  122. array_push($tmp, __http_build_query($val, urlencode($key)));
  123. continue;
  124. }
  125. }
  126. return implode($separator, $tmp);
  127. }
  128. // Helper function
  129. function __http_build_query ($array, $name)
  130. {
  131. $tmp = array ();
  132. foreach ($array as $key => $value) {
  133. if (is_array($value)) {
  134. array_push($tmp, __http_build_query($value, sprintf('%s[%s]', $name, $key)));
  135. } elseif (is_scalar($value)) {
  136. array_push($tmp, sprintf('%s[%s]=%s', $name, urlencode($key), urlencode($value)));
  137. } elseif (is_object($value)) {
  138. array_push($tmp, __http_build_query(get_object_vars($value), sprintf('%s[%s]', $name, $key)));
  139. }
  140. }
  141. // Argument seperator
  142. $separator = ini_get('arg_separator.output');
  143. return implode($separator, $tmp);
  144. }
  145. }
  146. ?>