Line 22... |
Line 22... |
22 |
// |
22 |
// |
23 |
// utils.inc |
23 |
// utils.inc |
24 |
// |
24 |
// |
25 |
// General utility commands |
25 |
// General utility commands |
26 |
|
26 |
|
27 |
#require_once 'php5compat.inc'; |
- |
|
28 |
|
- |
|
29 |
// {{{ createDirLinks |
27 |
// {{{ createDirLinks |
30 |
// |
28 |
// |
31 |
// Create a list of links to the current path that'll be available from the template |
29 |
// Create a list of links to the current path that'll be available from the template |
32 |
|
30 |
|
33 |
function createDirLinks($rep, $path, $rev, $showchanged) |
31 |
function createDirLinks($rep, $path, $rev, $showchanged) |
Line 151... |
Line 149... |
151 |
# trimmed via CSS (use the "white-space: pre;" properties). ~J |
149 |
# trimmed via CSS (use the "white-space: pre;" properties). ~J |
152 |
# in the meantime, here's an improved function (does nothing) |
150 |
# in the meantime, here's an improved function (does nothing) |
153 |
|
151 |
|
154 |
function hardspace($s) |
152 |
function hardspace($s) |
155 |
{ |
153 |
{ |
156 |
return '<code>'.$s.'</code>'; |
154 |
return '<code>' . expandTabs($s) . '</code>'; |
- |
|
155 |
} |
- |
|
156 |
|
- |
|
157 |
// }}} |
- |
|
158 |
|
- |
|
159 |
// {{{ expandTabs |
- |
|
160 |
|
- |
|
161 |
/** |
- |
|
162 |
* Expands the tabs in a line that may or may not include HTML. |
- |
|
163 |
* |
- |
|
164 |
* Enscript generates code with HTML, so we need to take that into account. |
- |
|
165 |
* |
- |
|
166 |
* @param string $s Line of possibly HTML-encoded text to expand |
- |
|
167 |
* @param int $tabwidth Tab width, -1 to use repository's default, 0 to collapse |
- |
|
168 |
* all tabs. |
- |
|
169 |
* @return string The expanded line. |
- |
|
170 |
* @since 2.1 |
- |
|
171 |
*/ |
- |
|
172 |
|
- |
|
173 |
function expandTabs($s, $tabwidth = -1) |
- |
|
174 |
{ |
- |
|
175 |
global $rep; |
- |
|
176 |
|
- |
|
177 |
if ($tabwidth == -1) |
- |
|
178 |
$tabwidth = $rep->getExpandTabsBy(); |
- |
|
179 |
$pos = 0; |
- |
|
180 |
|
- |
|
181 |
// Parse the string into chunks that are either 1 of: HTML tag, tab char, run of any other stuff |
- |
|
182 |
$chunks = preg_split("/((?:<.+?>)|(?:&.+?;)|(?:\t))/", $s, -1, PREG_SPLIT_DELIM_CAPTURE); |
- |
|
183 |
|
- |
|
184 |
// Count the sizes of the chunks and replace tabs as we go |
- |
|
185 |
for ($i = 0; $i < count($chunks); $i++) |
- |
|
186 |
{ |
- |
|
187 |
# make sure we're not dealing with an empty string |
- |
|
188 |
if (empty($chunks[$i])) continue; |
- |
|
189 |
switch ($chunks[$i]{0}) |
- |
|
190 |
{ |
- |
|
191 |
case '<': // HTML tag : ignore its width by doing nothing |
- |
|
192 |
break; |
- |
|
193 |
|
- |
|
194 |
case '&': // HTML entity: count its width as 1 char |
- |
|
195 |
$pos += 1; |
- |
|
196 |
break; |
- |
|
197 |
|
- |
|
198 |
case "\t": // Tab char: replace it with a run of spaces between length tabwidth and 1 |
- |
|
199 |
$tabsize = $tabwidth - ($pos % $tabwidth); |
- |
|
200 |
$chunks[$i] = str_repeat(' ', $tabsize); |
- |
|
201 |
$pos += $tabsize; |
- |
|
202 |
break; |
- |
|
203 |
|
- |
|
204 |
default: // Anything else: just keep track of its width |
- |
|
205 |
$pos += strlen($chunks[$i]); |
- |
|
206 |
break; |
- |
|
207 |
} |
- |
|
208 |
} |
- |
|
209 |
|
- |
|
210 |
// Put the chunks back together and we've got the original line, detabbed. |
- |
|
211 |
return join('', $chunks); |
157 |
} |
212 |
} |
158 |
|
213 |
|
159 |
// }}} |
214 |
// }}} |
160 |
|
215 |
|
161 |
// {{{ datetimeFormatDuration |
216 |
// {{{ datetimeFormatDuration |
Line 225... |
Line 280... |
225 |
// |
280 |
// |
226 |
// Get the relative URL (PHP_SELF) with GET and POST data |
281 |
// Get the relative URL (PHP_SELF) with GET and POST data |
227 |
|
282 |
|
228 |
function getParameterisedSelfUrl($params = true) |
283 |
function getParameterisedSelfUrl($params = true) |
229 |
{ |
284 |
{ |
- |
|
285 |
global $config; |
- |
|
286 |
|
230 |
$url = null; |
287 |
$url = null; |
231 |
|
288 |
|
232 |
if ($config->multiViews) |
289 |
if ($config->multiViews) |
233 |
{ |
290 |
{ |
234 |
// Get rid of the file's name |
291 |
// Get rid of the file's name |
Line 254... |
Line 311... |
254 |
return $url; |
311 |
return $url; |
255 |
} |
312 |
} |
256 |
|
313 |
|
257 |
// }}} |
314 |
// }}} |
258 |
|
315 |
|
- |
|
316 |
// {{{ getUserLanguage |
- |
|
317 |
|
- |
|
318 |
function getUserLanguage() { |
- |
|
319 |
$languages = !empty($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : 'en'; |
- |
|
320 |
if (strpos($languages, ',') === false) return $languages; # only one specified |
- |
|
321 |
# split off the languages into an array of languages and q-values |
- |
|
322 |
$qvals = array(); |
- |
|
323 |
$langs = array(); |
- |
|
324 |
preg_match_all('#(\S+?)\s*(?:;q=([01](?:\.\d{1,3})?))?\s*,\s*#', $languages, $qvals, PREG_SET_ORDER); |
- |
|
325 |
foreach ($qvals as $q) { |
- |
|
326 |
$langs[] = array ( |
- |
|
327 |
$q[1], |
- |
|
328 |
floatval(!empty($q[2]) ? $q[2] : 1.0) |
- |
|
329 |
); |
- |
|
330 |
} |
- |
|
331 |
# XXX: now, we should loop through our available languages and choose an |
- |
|
332 |
# appropriate one for the user |
- |
|
333 |
# note that we shouldn't match the region unless we have a specific region |
- |
|
334 |
# to use (e.g. zh-CN vs. zh-TW) |
- |
|
335 |
# FIXME: see above; otherwise, this function doesn't really do anything |
- |
|
336 |
} |
- |
|
337 |
|
- |
|
338 |
// }}} |
- |
|
339 |
|
259 |
?> |
340 |
?> |