[ Index ] |
PHP Cross Reference of vtigercrm-6.1.0 |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** This file is part of KCFinder project 4 * 5 * @desc Path helper class 6 * @package KCFinder 7 * @version 2.21 8 * @author Pavel Tzonkov <[email protected]> 9 * @copyright 2010 KCFinder Project 10 * @license http://www.opensource.org/licenses/gpl-2.0.php GPLv2 11 * @license http://www.opensource.org/licenses/lgpl-2.1.php LGPLv2 12 * @link http://kcfinder.sunhater.com 13 */ 14 15 class path { 16 17 /** Get the absolute URL path of the given one. Returns FALSE if the URL 18 * is not valid or the current directory cannot be resolved (getcwd()) 19 * @param string $path 20 * @return string */ 21 22 static function rel2abs_url($path) { 23 //added so absolute url's used instead of url's relative to server's root. 24 require '../config.inc.php'; 25 $return = $site_URL."/$path"; 26 27 return $return; 28 } 29 30 /** Resolve full filesystem path of given URL. Returns FALSE if the URL 31 * cannot be resolved 32 * @param string $url 33 * @return string */ 34 35 static function url2fullPath($url) { 36 $url = self::normalize($url); 37 38 $uri = isset($_SERVER['SCRIPT_NAME']) 39 ? $_SERVER['SCRIPT_NAME'] : (isset($_SERVER['PHP_SELF']) 40 ? $_SERVER['PHP_SELF'] 41 : false); 42 43 $uri = self::normalize($uri); 44 45 if (substr($url, 0, 1) !== "/") { 46 if ($uri === false) return false; 47 $url = dirname($uri) . "/$url"; 48 } 49 50 if (isset($_SERVER['DOCUMENT_ROOT'])) { 51 return self::normalize($_SERVER['DOCUMENT_ROOT'] . "/$url"); 52 53 } else { 54 if ($uri === false) return false; 55 56 if (isset($_SERVER['SCRIPT_FILENAME'])) { 57 $scr_filename = self::normalize($_SERVER['SCRIPT_FILENAME']); 58 return self::normalize(substr($scr_filename, 0, -strlen($uri)) . "/$url"); 59 } 60 61 $count = count(explode('/', $uri)) - 1; 62 for ($i = 0, $chdir = ""; $i < $count; $i++) 63 $chdir .= "../"; 64 $chdir = self::normalize($chdir); 65 66 $dir = getcwd(); 67 if (($dir === false) || !@chdir($chdir)) 68 return false; 69 $rdir = getcwd(); 70 chdir($dir); 71 return ($rdir !== false) ? self::normalize($rdir . "/$url") : false; 72 } 73 } 74 75 /** Normalize the given path. On Windows servers backslash will be replaced 76 * with slash. Remobes unnecessary doble slashes and double dots. Removes 77 * last slash if it exists. Examples: 78 * path::normalize("C:\\any\\path\\") returns "C:/any/path" 79 * path::normalize("/your/path/..//home/") returns "/your/home" 80 * @param string $path 81 * @return string */ 82 83 static function normalize($path) { 84 if (strtoupper(substr(PHP_OS, 0, 3)) == "WIN") { 85 $path = preg_replace('/([^\\\])\\\([^\\\])/', "$1/$2", $path); 86 if (substr($path, -1) == "\\") $path = substr($path, 0, -1); 87 if (substr($path, 0, 1) == "\\") $path = "/" . substr($path, 1); 88 } 89 90 $path = preg_replace('/\/+/s', "/", $path); 91 92 $path = "/$path"; 93 if (substr($path, -1) != "/") 94 $path .= "/"; 95 96 $expr = '/\/([^\/]{1}|[^\.\/]{2}|[^\/]{3,})\/\.\.\//s'; 97 while (preg_match($expr, $path)) 98 $path = preg_replace($expr, "/", $path); 99 100 $path = substr($path, 0, -1); 101 $path = substr($path, 1); 102 return $path; 103 } 104 105 /** Encode URL Path 106 * @param string $path 107 * @return string */ 108 109 static function urlPathEncode($path) { 110 $path = self::normalize($path); 111 $encoded = ""; 112 foreach (explode("/", $path) as $dir) 113 $encoded .= rawurlencode($dir) . "/"; 114 $encoded = substr($encoded, 0, -1); 115 return $encoded; 116 } 117 118 /** Decode URL Path 119 * @param string $path 120 * @return string */ 121 122 static function urlPathDecode($path) { 123 $path = self::normalize($path); 124 $decoded = ""; 125 foreach (explode("/", $path) as $dir) 126 $decoded .= rawurldecode($dir) . "/"; 127 $decoded = substr($decoded, 0, -1); 128 return $decoded; 129 } 130 } 131 132 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:08:37 2014 | Cross-referenced by PHPXref 0.7.1 |