Changeset 5713 in subversion for trunk/roundcubemail/program/include/main.inc
- Timestamp:
- Jan 5, 2012 4:51:41 AM (18 months ago)
- File:
-
- 1 edited
-
trunk/roundcubemail/program/include/main.inc (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/roundcubemail/program/include/main.inc
r5707 r5713 2094 2094 public function callback($matches) 2095 2095 { 2096 return $matches[1] . '="' . make_absolute_url($matches[3], $this->base_url) . '"'; 2096 return $matches[1] . '="' . self::absolute_url($matches[3], $this->base_url) . '"'; 2097 } 2098 2099 public function replace($body) 2100 { 2101 return preg_replace_callback(array( 2102 '/(src|background|href)=(["\']?)([^"\'\s]+)(\2|\s|>)/Ui', 2103 '/(url\s*\()(["\']?)([^"\'\)\s]+)(\2)\)/Ui', 2104 ), 2105 array($this, 'callback'), $body); 2106 } 2107 2108 /** 2109 * Convert paths like ../xxx to an absolute path using a base url 2110 * 2111 * @param string $path Relative path 2112 * @param string $base_url Base URL 2113 * 2114 * @return string Absolute URL 2115 */ 2116 public static function absolute_url($path, $base_url) 2117 { 2118 $host_url = $base_url; 2119 $abs_path = $path; 2120 2121 // check if path is an absolute URL 2122 if (preg_match('/^[fhtps]+:\/\//', $path)) { 2123 return $path; 2124 } 2125 2126 // check if path is a content-id scheme 2127 if (strpos($path, 'cid:') === 0) { 2128 return $path; 2129 } 2130 2131 // cut base_url to the last directory 2132 if (strrpos($base_url, '/') > 7) { 2133 $host_url = substr($base_url, 0, strpos($base_url, '/', 7)); 2134 $base_url = substr($base_url, 0, strrpos($base_url, '/')); 2135 } 2136 2137 // $path is absolute 2138 if ($path[0] == '/') { 2139 $abs_path = $host_url.$path; 2140 } 2141 else { 2142 // strip './' because its the same as '' 2143 $path = preg_replace('/^\.\//', '', $path); 2144 2145 if (preg_match_all('/\.\.\//', $path, $matches, PREG_SET_ORDER)) { 2146 foreach ($matches as $a_match) { 2147 if (strrpos($base_url, '/')) { 2148 $base_url = substr($base_url, 0, strrpos($base_url, '/')); 2149 } 2150 $path = substr($path, 3); 2151 } 2152 } 2153 2154 $abs_path = $base_url.'/'.$path; 2155 } 2156 2157 return $abs_path; 2097 2158 } 2098 2159 }
Note: See TracChangeset
for help on using the changeset viewer.
