/** * 根据参数生成完整的URL,如:url::build('site://zotop/index/default/arg1/arg2',array('param1'=>'1'),'#top') * * @param string $uri 如:{application}://{module}/{controller}/{action}/{arg1}/arg2 组成 * @param array|string $params URL参数 ,一般为数组,也可以是字符串,如:param1/1/param2/2 * @param string $extra 额外数据:如锚点信息等 * @return string 如:/index.php/module/controller/action/arg1/arg2?param1=1¶m2=2#top */ public static function build($uri = '', $params = null, $extra = '') { $application = ''; if (strpos($uri, '://')) { list($application, $uri) = explode('://', $uri); } //获取入口文件地址 if (empty($application)) { $base = url::scriptname(); } else { $base = zotop::application($application, 'url') . '/' . zotop::application($application, 'base'); $base = url::decode($base); } //uri处理 if ($u = explode('/', trim($uri, '/'))) { //获取namespace 和 arguments $namespace = array_slice($u, 0, 3); $namespace = implode('/', $namespace); $arguments = array_slice($u, 3); //namespace切换 $namespace = zotop::filter('zotop.namespace', $namespace, &$arguments); foreach ($arguments as $arg) { $querystring .= '/' . $arg; } //querystring $querystring = $namespace . $querystring; $querystring = empty($querystring) ? '' : '/' . $uri; $querystring .= empty($suffix) ? '' : $suffix; } //处理id/5/n/6 形式的参数 if (!is_array($params)) { $args = explode('/', $params); while ($key = array_shift($args)) { $params[$key] = array_shift($args); } } if (is_array($params) && !empty($params)) { if (strpos($querystring, '?')) { $querystring .= '&' . http_build_query($params); } else { $querystring .= '?' . http_build_query($params); } } //组装url $url = $base . $querystring . $extra; $url = url::clean($url); return $url; }
/** * 根据参数生成完整的URL,如:url::build('zotop/index/default',array('id'=>'1')) * * @param string $uri 一般由{app}://{module}/{controller}/{action}组成 * @param array|string $params 动作参数 ,一般为数组 * @param array|string $arguments URL参数 ,一般为数组 * @param string $fragment 锚点 * @return string */ public static function build($uri, $params = null, $arguments = '', $fragment = '') { $uri = trim($uri, '/'); $app = ''; if (strpos($url, '://') !== false) { $u = explode('://', $uri); $app = $u[0]; $uri = $u[1]; } //获取入口文件地址 if (empty($app)) { $base = url::scriptname(); } else { $base = zotop::applicationes($app, 'url') . '/' . zotop::applicationes($app, 'base'); } //获取module/controller/action if ($u = explode('/', trim($uri, '/'))) { $namespace = implode('/', array_slice($u, 0, 3)); } //处理id/5/n/6 形式的参数 if (!is_array($params)) { $args = array(); $array = explode('/', $params); while ($key = array_shift($array)) { $args[$key] = array_shift($array); } $params = $args; } //合并参数 $str = ''; foreach ($params as $key => $value) { $str .= '/' . rawurlencode($value); } //组装url $url = $base . '/' . $namespace . $str . $fragment; $url = url::clean($url); return $url; }
/** * 根据参数生成完整的URL,如:url::build('zotop/index/default',array('id'=>'1')) * * @param string $uri 一般由{module}/{controller}/{action}组成 * @param array|string $params URL参数 ,一般为数组 * @param string $extra 额外参数 ,一般为数组 * @return string */ public static function build($uri, $params = '', $extra = '') { $app = ''; $uri = trim($uri, '/'); if (strpos($uri, '://') !== false) { $uris = explode('://', $uri); $app = $uris[0]; $uri = $uris[1]; } $urls = array(); $urls['base'] = empty($app) ? url::scriptname() : url::application($app); if ($paths = explode('/', trim($uri, '/'))) { $urls['module'] = $paths[0]; $urls['controller'] = $paths[1]; $urls['action'] = $paths[2]; } $url = $urls['base']; $url = $url . '/' . $urls['module'] . '/' . $urls['controller'] . '/' . $urls['action']; if (!empty($params)) { if (is_string($params)) { $keyvalues = explode('&', $params); $params = array(); foreach ($keyvalues as $keyvalue) { list($key, $value) = explode('=', $keyvalue); if ($value) { $params[$key] = $value; } } } foreach ($params as $key => $value) { $url .= '/' . url::encodeParam($value); } } if (is_string($extra)) { $url .= $extra; } return url::clean(rtrim($url, '/')); }
public function actionIndex($dir = '') { $dir = url::clean($dir); $path = ZOTOP_PATH_ROOT . DS . trim($dir, DS); $path = path::clean($path); //获取当前目录的子目录及子文件 $folders = (array) dir::folders($path); $files = (array) dir::files($path); $position = '<a href="' . zotop::url('webftp/index/index') . '">wwwroot</a>'; $dirs = arr::dirpath($dir, '/'); foreach ($dirs as $d) { $position .= ' / <a href="' . zotop::url('webftp/index/index', array('dir' => rawurlencode($d[1]))) . '">' . $d[0] . '</a>'; } $page = new page(); $page->title = '文件管理器'; $page->set('position', $position); $page->set('navbar', $this->navbar($dir)); $page->set('folders', $folders); $page->set('files', $files); $page->set('path', $path); $page->set('dir', $dir); $page->display(); }
public static function abs($href) { if (strpos($href, '://') === false) { //如果格式如 /system/admin/themes/default/css/system.css if ($href[0] === '/') { $root = url::root(); $href = $root . '/' . ltrim($href, $root); } else { $base = dirname(url::base()); $href = $base . '/' . $href; } } return url::clean($href); }
public static function script($href, $attrs = array()) { static $scripts = array(); $str = ''; if (is_array($href)) { foreach ($href as $src) { $str .= html::script($src, $attrs); } } else { //如果不是是直接输出的话 if (strpos($href, ';') == 0) { $href = url::clean($href); $href = url::decode($href); //一个页面只允许加载一次 if (isset($scripts[strtolower($href)])) { return ''; } $scripts[strtolower($href)] = true; $attrs['type'] = 'text/javascript'; $attrs['src'] = $href . '?v' . zotop::config('zotop.version'); $str = '<script' . html::attributes($attrs) . '></script>'; } else { $attrs['type'] = 'text/javascript'; $str = '<script' . html::attributes($attrs) . '>' . $href . '</script>'; } } return $str; }