<?php
-// $Id: spam_pickup.php,v 1.63 2008/12/27 11:50:21 henoheno Exp $
+// $Id: spam_pickup.php,v 1.66 2009/01/02 09:30:50 henoheno Exp $
// Copyright (C) 2006-2007 PukiWiki Developers Team
// License: GPL v2 or (at your option) any later version
//
'[a-z0-9_-][a-z0-9_.-]+[a-z0-9_-]' . // hostname(FQDN) : foo.example.org
')' .
'(?::([0-9]*))?' . // 4: Port
- '((?:/+[^\s<>"\'\[\]/\#]+)*/+)?' . // 5: Directory path or path-info
+ '((?:/+[^\s<>"\'\[\]/\#]+)*/+)?' . // 5: Directory path
'([^\s<>"\'\[\]\#?]+)?' . // 6: File?
'(?:\?([^\s<>"\'\[\]\#]+))?' . // 7: Query string
'(?:\#([a-z0-9._~%!$&\'()*+,;=:@-]*))?' . // 8: Fragment
$string, $array, PREG_SET_ORDER | PREG_OFFSET_CAPTURE
);
- // Format the $array
+ // Reformat the $array
static $parts = array(
1 => 'scheme', 2 => 'userinfo', 3 => 'host', 4 => 'port',
5 => 'path', 6 => 'file', 7 => 'query', 8 => 'fragment'
);
- $default = array('');
+ $default = array(0 => '', 1 => -1);
foreach(array_keys($array) as $uri) {
$_uri = & $array[$uri];
array_rename_keys($_uri, $parts, TRUE, $default);
$offset = $_uri['scheme'][1]; // Scheme's offset = URI's offset
foreach(array_keys($_uri) as $part) {
- $_uri[$part] = & $_uri[$part][0]; // Remove offsets
+ $_uri[$part] = $_uri[$part][0]; // Remove offsets
}
}
// Normalize an array of URI arrays
// NOTE: Give me the uri_pickup() results
-function uri_pickup_normalize(& $pickups, $destructive = TRUE)
+function uri_pickup_normalize(& $pickups, $destructive = TRUE, $pathfile = FALSE)
{
if (! is_array($pickups)) return $pickups;
}
}
+ if ($pathfile) {
+ return uri_pickup_normalize_pathfile($pickups);
+ } else {
+ return $pickups;
+ }
+}
+
+// Normalize: 'path' + 'file' = 'path' (Similar structure using PHP's "parse_url()" function)
+// NOTE: In some case, 'file' DOES NOT mean _filename_.
+// [EXAMPLE] http://example.com/path/to/directory-accidentally-not-ended-with-slash
+function uri_pickup_normalize_pathfile(& $pickups)
+{
+ if (! is_array($pickups)) return $pickups;
+
+ foreach (array_keys($pickups) as $key) {
+ $_key = & $pickups[$key];
+ if (isset($_key['path'], $_key['file'])) {
+ $_key['path'] = $_key['path'] . $_key['file'];
+ unset($_key['file']);
+ }
+ }
+
return $pickups;
}
}
// Remove 'offset's for area_measure()
- foreach(array_keys($array) as $key)
+ foreach(array_keys($array) as $key) {
unset($array[$key]['area']['offset']);
+ }
return $array;
}