2 // $Id: spam_pickup.php,v 1.65 2008/12/31 15:44:14 henoheno Exp $
3 // Copyright (C) 2006-2007 PukiWiki Developers Team
4 // License: GPL v2 or (at your option) any later version
6 // Functions for Concept-work of spam-uri metrics
9 // ---------------------
12 // Return an array of URIs in the $string
13 // [OK] http://nasty.example.org#nasty_string
14 // [OK] http://nasty.example.org:80/foo/xxx#nasty_string/bar
15 // [OK] ftp://nasty.example.org:80/dfsdfs
16 // [OK] ftp://cnn.example.com&story=breaking_news@10.0.0.1/top_story.htm (from RFC3986)
17 function uri_pickup($string = '')
19 if (! is_string($string)) return array();
21 // Not available for: IDN(ignored)
24 // scheme://userinfo@host:port/path/or/pathinfo/maybefile.and?query=string#fragment
25 // Refer RFC3986 (Regex below is not strict)
26 '#(\b[a-z][a-z0-9.+-]{1,8}):[/\\\]+' . // 1: Scheme
28 '([^\s<>"\'\[\]/\#?@]*)' . // 2: Userinfo (Username)
32 '\[[0-9a-f:.]+\]' . '|' . // IPv6([colon-hex and dot]): RFC2732
33 '(?:[0-9]{1,3}\.){3}[0-9]{1,3}' . '|' . // IPv4(dot-decimal): 001.22.3.44
34 '[a-z0-9_-][a-z0-9_.-]+[a-z0-9_-]' . // hostname(FQDN) : foo.example.org
36 '(?::([0-9]*))?' . // 4: Port
37 '((?:/+[^\s<>"\'\[\]/\#]+)*/+)?' . // 5: Directory path or path-info
38 '([^\s<>"\'\[\]\#?]+)?' . // 6: File?
39 '(?:\?([^\s<>"\'\[\]\#]+))?' . // 7: Query string
40 '(?:\#([a-z0-9._~%!$&\'()*+,;=:@-]*))?' . // 8: Fragment
42 $string, $array, PREG_SET_ORDER | PREG_OFFSET_CAPTURE
45 // Reformat the $array
46 static $parts = array(
47 1 => 'scheme', 2 => 'userinfo', 3 => 'host', 4 => 'port',
48 5 => 'path', 6 => 'file', 7 => 'query', 8 => 'fragment'
50 $default = array(0 => '', 1 => -1);
51 foreach(array_keys($array) as $uri) {
52 $_uri = & $array[$uri];
53 array_rename_keys($_uri, $parts, TRUE, $default);
54 $offset = $_uri['scheme'][1]; // Scheme's offset = URI's offset
55 foreach(array_keys($_uri) as $part) {
56 $_uri[$part] = $_uri[$part][0]; // Remove offsets
60 foreach(array_keys($array) as $uri) {
61 $_uri = & $array[$uri];
62 if ($_uri['scheme'] === '') {
63 unset($array[$uri]); // Considererd harmless
66 unset($_uri[0]); // Matched string itself
67 $_uri['area']['offset'] = $offset; // Area offset for area_measure()
73 // Pickupped URI array => An URI (See uri_pickup())
75 // $pickups = uri_pickup('a string include some URIs');
77 // foreach (array_keys($pickups) as $key) {
78 // $uris[$key] = uri_pickup_implode($pickups[$key]);
80 function uri_pickup_implode($uri = array())
82 if (empty($uri) || ! is_array($uri)) return NULL;
85 if (isset($uri['scheme']) && $uri['scheme'] !== '') {
86 $tmp[] = & $uri['scheme'];
89 if (isset($uri['userinfo']) && $uri['userinfo'] !== '') {
90 $tmp[] = & $uri['userinfo'];
93 if (isset($uri['host']) && $uri['host'] !== '') {
94 $tmp[] = & $uri['host'];
96 if (isset($uri['port']) && $uri['port'] !== '') {
98 $tmp[] = & $uri['port'];
100 if (isset($uri['pathtofile']) && $uri['pathtofile'] !== '') {
101 $tmp[] = & $uri['pathtofile'];
103 if (isset($uri['path']) && $uri['path'] !== '') {
104 $tmp[] = & $uri['path'];
106 if (isset($uri['file']) && $uri['file'] !== '') {
107 $tmp[] = & $uri['file'];
110 if (isset($uri['query']) && $uri['query'] !== '') {
112 $tmp[] = & $uri['query'];
114 if (isset($uri['fragment']) && $uri['fragment'] !== '') {
116 $tmp[] = & $uri['fragment'];
119 return implode('', $tmp);
122 // ---------------------
125 // Normalize an array of URI arrays
126 // NOTE: Give me the uri_pickup() results
127 function uri_pickup_normalize(& $pickups, $destructive = TRUE, $pathtofile = FALSE)
129 if (! is_array($pickups)) return $pickups;
132 foreach (array_keys($pickups) as $key) {
133 $_key = & $pickups[$key];
134 $_key['scheme'] = isset($_key['scheme']) ? scheme_normalize($_key['scheme']) : '';
135 $_key['host'] = isset($_key['host']) ? host_normalize($_key['host']) : '';
136 $_key['port'] = isset($_key['port']) ? port_normalize($_key['port'], $_key['scheme'], FALSE) : '';
137 $_key['path'] = isset($_key['path']) ? strtolower(path_normalize($_key['path'])) : '';
138 $_key['file'] = isset($_key['file']) ? file_normalize($_key['file']) : '';
139 $_key['query'] = isset($_key['query']) ? query_normalize($_key['query']) : '';
140 $_key['fragment'] = isset($_key['fragment']) ? strtolower($_key['fragment']) : '';
143 foreach (array_keys($pickups) as $key) {
144 $_key = & $pickups[$key];
145 $_key['scheme'] = isset($_key['scheme']) ? scheme_normalize($_key['scheme']) : '';
146 $_key['host'] = isset($_key['host']) ? strtolower($_key['host']) : '';
147 $_key['port'] = isset($_key['port']) ? port_normalize($_key['port'], $_key['scheme'], FALSE) : '';
148 $_key['path'] = isset($_key['path']) ? path_normalize($_key['path']) : '';
153 return uri_pickup_normalize_pathtofile($pickups, TRUE);
159 // Normalize: 'path' + 'file' = 'pathtofile'
160 // In some case, 'file' DOES NOT mean _filename_.
161 // [EXAMPLE] http://example.com/path/to/directory-accidentally-not-ended-with-slash
162 function uri_pickup_normalize_pathtofile(& $pickups, $removeoriginal = TRUE)
164 if (! is_array($pickups)) return $pickups;
166 foreach (array_keys($pickups) as $key) {
167 $_key = & $pickups[$key];
168 if (! isset($_key['pathtofile']) && isset($_key['path'], $_key['file'])) {
169 $_key['pathtofile'] = $_key['path'] . $_key['file'];
170 if ($removeoriginal) unset($_key['path'], $_key['file']);
177 // Scheme normalization: Renaming the schemes
178 // snntp://example.org => nntps://example.org
179 // NOTE: Keep the static lists simple. See also port_normalize().
180 function scheme_normalize($scheme = '', $abbrevs_harmfull = TRUE)
182 // Abbreviations they have no intention of link
183 static $abbrevs = array(
188 // Aliases => normalized ones
189 static $aliases = array(
199 if (! is_string($scheme)) return '';
201 $scheme = strtolower($scheme);
202 if (isset($abbrevs[$scheme])) {
203 $scheme = $abbrevs_harmfull ? $abbrevs[$scheme] : '';
205 if (isset($aliases[$scheme])) {
206 $scheme = $aliases[$scheme];
212 // Hostname normlization (Destructive)
213 // www.foo => www.foo ('foo' seems TLD)
214 // www.foo.bar => foo.bar
215 // www.10.20 => www.10.20 (Invalid hostname)
217 // 'www' is basically traditional hostname for WWW server.
218 // In these case, 'www.foo.bar' MAY be identical with 'foo.bar'.
219 function host_normalize($host = '')
221 if (! is_string($host)) return '';
223 $host = strtolower($host);
226 if (preg_match('/^www\.(.+\.[a-z]+)$/', $host, $matches)) {
233 // Port normalization: Suppress the (redundant) default port
234 // HTTP://example.org:80/ => http://example.org/
235 // HTTP://example.org:8080/ => http://example.org:8080/
236 // HTTPS://example.org:443/ => https://example.org/
237 function port_normalize($port, $scheme, $scheme_normalize = FALSE)
239 // Schemes that users _maybe_ want to add protocol-handlers
240 // to their web browsers. (and attackers _maybe_ want to use ...)
241 // Reference: http://www.iana.org/assignments/port-numbers
242 static $array = array(
243 // scheme => default port
269 // intval() converts '0-1' to '0', so preg_match() rejects these invalid ones
270 if (! is_numeric($port) || $port < 0 || preg_match('/[^0-9]/i', $port))
273 $port = intval($port);
274 if ($scheme_normalize) $scheme = scheme_normalize($scheme);
275 if (isset($array[$scheme]) && $port == $array[$scheme])
276 $port = ''; // Ignore the defaults
281 // Path normalization
282 // http://example.org => http://example.org/
283 // http://example.org#hoge => http://example.org/#hoge
284 // http://example.org/path/a/b/./c////./d => http://example.org/path/a/b/c/d
285 // http://example.org/path/../../a/../back => http://example.org/back
286 function path_normalize($path = '', $divider = '/', $add_root = TRUE)
288 if (! is_string($divider)) return is_string($path) ? $path : '';
291 $first_div = & $divider;
295 if (! is_string($path) || $path == '') return $first_div;
297 if (strpos($path, $divider, strlen($path) - strlen($divider)) === FALSE) {
300 $last_div = & $divider;
303 $array = explode($divider, $path);
305 // Remove paddings ('//' and '/./')
306 foreach(array_keys($array) as $key) {
307 if ($array[$key] == '' || $array[$key] == '.') {
312 // Remove back-tracks ('/../')
314 foreach($array as $value) {
315 if ($value == '..') {
318 array_push($tmp, $value);
326 return $first_div . implode($divider, $array) . $last_div;
330 // DirectoryIndex normalize (Destructive and rough)
331 // TODO: sample.en.ja.html.gz => sample.html
332 function file_normalize($file = 'index.html.en')
334 static $simple_defaults = array(
335 'default.htm' => TRUE,
336 'default.html' => TRUE,
337 'default.asp' => TRUE,
338 'default.aspx' => TRUE,
339 'index' => TRUE, // Some system can omit the suffix
342 static $content_suffix = array(
343 // index.xxx, sample.xxx
358 static $language_suffix = array(
359 // Reference: Apache 2.0.59 'AddLanguage' default
388 // Reference: Apache 2.0.59 default 'index.html' variants
394 static $charset_suffix = array(
395 // Reference: Apache 2.0.59 'AddCharset' default
396 'iso8859-1' => TRUE, // ISO-8859-1
397 'latin1' => TRUE, // ISO-8859-1
398 'iso8859-2' => TRUE, // ISO-8859-2
399 'latin2' => TRUE, // ISO-8859-2
400 'cen' => TRUE, // ISO-8859-2
401 'iso8859-3' => TRUE, // ISO-8859-3
402 'latin3' => TRUE, // ISO-8859-3
403 'iso8859-4' => TRUE, // ISO-8859-4
404 'latin4' => TRUE, // ISO-8859-4
405 'iso8859-5' => TRUE, // ISO-8859-5
406 'latin5' => TRUE, // ISO-8859-5
407 'cyr' => TRUE, // ISO-8859-5
408 'iso-ru' => TRUE, // ISO-8859-5
409 'iso8859-6' => TRUE, // ISO-8859-6
410 'latin6' => TRUE, // ISO-8859-6
411 'arb' => TRUE, // ISO-8859-6
412 'iso8859-7' => TRUE, // ISO-8859-7
413 'latin7' => TRUE, // ISO-8859-7
414 'grk' => TRUE, // ISO-8859-7
415 'iso8859-8' => TRUE, // ISO-8859-8
416 'latin8' => TRUE, // ISO-8859-8
417 'heb' => TRUE, // ISO-8859-8
418 'iso8859-9' => TRUE, // ISO-8859-9
419 'latin9' => TRUE, // ISO-8859-9
420 'trk' => TRUE, // ISO-8859-9
421 'iso2022-jp'=> TRUE, // ISO-2022-JP
422 'jis' => TRUE, // ISO-2022-JP
423 'iso2022-kr'=> TRUE, // ISO-2022-KR
424 'kis' => TRUE, // ISO-2022-KR
425 'iso2022-cn'=> TRUE, // ISO-2022-CN
426 'cis' => TRUE, // ISO-2022-CN
428 'cp-1251' => TRUE, // ru, WINDOWS-1251
429 'win-1251' => TRUE, // ru, WINDOWS-1251
430 'cp866' => TRUE, // ru
431 'koi8-r' => TRUE, // ru, KOI8-r
432 'koi8-ru' => TRUE, // ru, KOI8-r
433 'koi8-uk' => TRUE, // ru, KOI8-ru
434 'ua' => TRUE, // ru, KOI8-ru
435 'ucs2' => TRUE, // ru, ISO-10646-UCS-2
436 'ucs4' => TRUE, // ru, ISO-10646-UCS-4
439 // Reference: Apache 2.0.59 default 'index.html' variants
444 // May uncompress by web browsers on the fly
445 // Must be at the last of the filename
446 // Reference: Apache 2.0.59 'AddEncoding'
447 static $encoding_suffix = array(
452 if (! is_string($file)) return '';
453 $_file = strtolower($file);
454 if (isset($simple_defaults[$_file])) return '';
456 // Roughly removing language/character-set/encoding suffixes
458 // * Apache 2 document about 'Content-negotiaton', 'mod_mime' and 'mod_negotiation'
459 // http://httpd.apache.org/docs/2.0/content-negotiation.html
460 // http://httpd.apache.org/docs/2.0/mod/mod_mime.html
461 // http://httpd.apache.org/docs/2.0/mod/mod_negotiation.html
462 // * http://www.iana.org/assignments/character-sets
463 // * RFC3066: Tags for the Identification of Languages
464 // http://www.ietf.org/rfc/rfc3066.txt
465 // * ISO 639: codes of 'language names'
466 $suffixes = explode('.', $_file);
467 $body = array_shift($suffixes);
469 // Remove the last .gz/.z
470 $last_key = end(array_keys($suffixes));
471 if (isset($encoding_suffix[$suffixes[$last_key]])) {
472 unset($suffixes[$last_key]);
475 // Cut language and charset suffixes
476 foreach($suffixes as $key => $value){
477 if (isset($language_suffix[$value]) || isset($charset_suffix[$value])) {
478 unset($suffixes[$key]);
481 if (empty($suffixes)) return $body;
484 $count = count($suffixes);
486 $current = current($suffixes);
487 if ($body == 'index' && $count == 1 && isset($content_suffix[$current])) return '';
492 // Sort query-strings if possible (Destructive and rough)
493 // [OK] &&&&f=d&b&d&c&a=0dd => a=0dd&b&c&d&f=d
494 // [OK] nothing==&eg=dummy&eg=padding&eg=foobar => eg=foobar
495 function query_normalize($string = '', $equal = TRUE, $equal_cutempty = TRUE, $stortolower = TRUE)
497 if (! is_string($string)) return '';
498 if ($stortolower) $string = strtolower($string);
500 $array = explode('&', $string);
502 // Remove '&' paddings
503 foreach(array_keys($array) as $key) {
504 if ($array[$key] == '') {
509 // Consider '='-sepalated input and paddings
511 $equals = $not_equals = array();
512 foreach ($array as $part) {
513 if (strpos($part, '=') === FALSE) {
514 $not_equals[] = $part;
516 list($key, $value) = explode('=', $part, 2);
517 $value = ltrim($value, '=');
518 if (! $equal_cutempty || $value != '') {
519 $equals[$key] = $value;
524 $array = & $not_equals;
525 foreach ($equals as $key => $value) {
526 $array[] = $key . '=' . $value;
532 return implode('&', $array);
535 // ---------------------
538 // Pickup all of markup areas
539 function area_pickup($string = '', $method = array())
542 if (empty($method)) return $area;
544 // Anchor tag pair by preg_match and preg_match_all()
546 // [OK] <a href= >Good site!</a>
547 // [OK] <a href= "#" >test</a>
548 // [OK] <a href="http://nasty.example.com">visit http://nasty.example.com/</a>
549 // [OK] <a href=\'http://nasty.example.com/\' >discount foobar</a>
550 // [NG] <a href="http://ng.example.com">visit http://ng.example.com _not_ended_
551 $regex = '#<a\b[^>]*\bhref\b[^>]*>.*?</a\b[^>]*(>)#is';
552 if (isset($method['area_anchor'])) {
554 $count = isset($method['asap']) ?
555 preg_match($regex, $string) :
556 preg_match_all($regex, $string, $areas);
557 if (! empty($count)) $area['area_anchor'] = $count;
559 if (isset($method['uri_anchor'])) {
561 preg_match_all($regex, $string, $areas, PREG_SET_ORDER | PREG_OFFSET_CAPTURE);
562 foreach(array_keys($areas) as $_area) {
563 $areas[$_area] = array(
564 $areas[$_area][0][1], // Area start (<a href>)
565 $areas[$_area][1][1], // Area end (</a>)
568 if (! empty($areas)) $area['uri_anchor'] = $areas;
571 // phpBB's "BBCode" pair by preg_match and preg_match_all()
573 // [OK] [url]http://nasty.example.com/[/url]
574 // [OK] [link]http://nasty.example.com/[/link]
575 // [OK] [url=http://nasty.example.com]visit http://nasty.example.com/[/url]
576 // [OK] [link http://nasty.example.com/]buy something[/link]
577 $regex = '#\[(url|link|img|email)\b[^\]]*\].*?\[/\1\b[^\]]*(\])#is';
578 if (isset($method['area_bbcode'])) {
580 $count = isset($method['asap']) ?
581 preg_match($regex, $string) :
582 preg_match_all($regex, $string, $areas, PREG_SET_ORDER);
583 if (! empty($count)) $area['area_bbcode'] = $count;
585 if (isset($method['uri_bbcode'])) {
587 preg_match_all($regex, $string, $areas, PREG_SET_ORDER | PREG_OFFSET_CAPTURE);
588 foreach(array_keys($areas) as $_area) {
589 $areas[$_area] = array(
590 $areas[$_area][0][1], // Area start ([url])
591 $areas[$_area][2][1], // Area end ([/url])
594 if (! empty($areas)) $area['uri_bbcode'] = $areas;
597 // Various Wiki syntax
598 // [text_or_uri>text_or_uri]
599 // [text_or_uri:text_or_uri]
600 // [text_or_uri|text_or_uri]
601 // [text_or_uri->text_or_uri]
602 // [text_or_uri text_or_uri] // MediaWiki
603 // MediaWiki: [http://nasty.example.com/ visit http://nasty.example.com/]
608 // If in doubt, it's a little doubtful
609 // if (Area => inside <= Area) $brief += -1
610 function area_measure($areas, & $array, $belief = -1, $a_key = 'area', $o_key = 'offset')
612 if (! is_array($areas) || ! is_array($array)) return;
614 $areas_keys = array_keys($areas);
615 foreach(array_keys($array) as $u_index) {
616 $offset = isset($array[$u_index][$o_key]) ?
617 intval($array[$u_index][$o_key]) : 0;
618 foreach($areas_keys as $a_index) {
619 if (isset($array[$u_index][$a_key])) {
620 $offset_s = intval($areas[$a_index][0]);
621 $offset_e = intval($areas[$a_index][1]);
622 // [Area => inside <= Area]
623 if ($offset_s < $offset && $offset < $offset_e) {
624 $array[$u_index][$a_key] += $belief;
632 // ---------------------
635 // Preprocess: Removing/Modifying uninterest part for URI detection
636 function spam_uri_removing_hocus_pocus($binary = '', $method = array())
638 $from = $to = array();
640 // Remove sequential spaces and too short lines
641 $length = 4 ; // 'http'(1) and '://'(2) and 'fqdn'(1)
642 if (is_array($method)) {
643 // '<a'(2) or 'href='(5) or '>'(1) or '</a>'(4)
644 // '[uri'(4) or ']'(1) or '[/uri]'(6)
645 if (isset($method['area_anchor']) || isset($method['uri_anchor']) ||
646 isset($method['area_bbcode']) || isset($method['uri_bbcode']))
647 $length = 1; // Seems not effective
649 $binary = strings($binary, $length, TRUE, FALSE); // Multibyte NOT needed
651 // Remove/Replace quoted-spaces within tags
652 $from[] = '#(<\w+ [^<>]*?\w ?= ?")([^"<>]*? [^"<>]*)("[^<>]*?>)#ie';
653 $to[] = "'$1' . str_replace(' ' , '%20' , trim('$2')) . '$3'";
655 // Remove words (has no '<>[]:') between spaces
656 $from[] = '/[ \t][\w.,()\ \t]+[ \t]/';
659 return preg_replace($from, $to, $binary);
662 // Preprocess: Domain exposure callback (See spam_uri_pickup_preprocess())
663 // http://victim.example.org/?foo+site:nasty.example.com+bar
664 // => http://nasty.example.com/?refer=victim.example.org
665 // NOTE: 'refer=' is not so good for (at this time).
666 // Consider about using IP address of the victim, try to avoid that.
667 function _preg_replace_callback_domain_exposure($matches = array())
671 // Preserve the victim URI as a complicity or ...
672 if (isset($matches[5])) {
674 $matches[1] . '://' . // scheme
675 $matches[2] . '/' . // victim.example.org
676 $matches[3]; // The rest of all (before victim)
680 if (isset($matches[4])) {
682 $matches[1] . '://' . // scheme
683 $matches[4] . // nasty.example.com
684 '/?refer=' . strtolower($matches[2]) . // victim.example.org
691 // Preprocess: minor-rawurldecode() and adding space(s) and something
692 // to detect/count some URIs _if possible_
693 // NOTE: It's maybe danger to var_dump(result). [e.g. 'javascript:']
694 // [OK] http://victim.example.org/?site:nasty.example.org
695 // [OK] http://victim.example.org/nasty.example.org
696 // [OK] http://victim.example.org/go?http%3A%2F%2Fnasty.example.org
697 // [OK] http://victim.example.org/http://nasty.example.org
698 function spam_uri_pickup_preprocess($string = '', $method = array())
700 if (! is_string($string)) return '';
702 // rawurldecode(), just to catch encoded 'http://path/to/file', not to change '%20' to ' '
715 $string = spam_uri_removing_hocus_pocus($string, $method);
717 // Domain exposure (simple)
718 // http://victim.example.org/nasty.example.org/path#frag
719 // => http://nasty.example.org/?refer=victim.example.org and original
720 $string = preg_replace(
724 'aboutus\.org/' . '|' .
725 'alexa\.com/data/details\?url=' . '|' .
726 'ime\.(?:nu|st)/' . '|' . // 2ch.net
727 'link\.toolbot\.com/' . '|' .
729 'big5.51job.com/gate/big5/' . '|' .
730 'big5.china.com/gate/big5/' . '|' .
731 'big5.shippingchina.com:8080/' . '|' .
732 'big5.xinhuanet.com/gate/big5/' . '|' .
733 'bhomiyo.com/en.xliterate/' . '|' .
734 'google.com/translate_c\?u=(?:http://)?' . '|' .
735 'web.archive.org/web/2[^/]*/(?:http://)?' . '|' .
736 'technorati.com/blogs/' .
738 '([a-z0-9.%_-]+\.[a-z0-9.%_-]+)' . // nasty.example.org
740 'http://$2/?refer=$1 $0', // Preserve $0 or remove?
744 // Domain exposure (site:) See _preg_replace_callback_domain_exposure()
745 $string = preg_replace_callback(
747 '#(h?ttp)://' . // 1:Scheme
750 '(?:[a-z0-9_.-]+\.)?[a-z0-9_-]+\.[a-z0-9_-]+' .
751 // Something Google: http://www.google.com/supported_domains
752 // AltaVista: http://es.altavista.com/web/results?q=site%3Anasty.example.org+foobar
753 // Live Search: search.live.com
754 // MySpace: http://sads.myspace.com/Modules/Search/Pages/Search.aspx?_snip_&searchString=site:nasty.example.org
755 // (also searchresults.myspace.com)
758 // search.orange.co.uk
762 //TODO: Specify URL-enable characters
763 '([a-z0-9?=&.,%_/\'\\\+-]+)' . // 3:path/?query=foo+bar+
764 '(?:\b|%20)site:([a-z0-9.%_-]+\.[a-z0-9.%_-]+)' . // 4:site:nasty.example.com
765 '()' . // 5:Preserve or remove?
768 '_preg_replace_callback_domain_exposure',
772 // URI exposure (uriuri => uri uri)
773 $string = preg_replace(
775 '#(?<! )(?:https?|ftp):/#i',
776 // '#[a-z][a-z0-9.+-]{1,8}://#i',
777 // '#[a-z][a-z0-9.+-]{1,8}://#i'
786 // Main function of spam-uri pickup,
787 // A wrapper function of uri_pickup()
788 function spam_uri_pickup($string = '', $method = array())
790 if (! is_array($method) || empty($method)) {
791 $method = check_uri_spam_method();
794 $string = spam_uri_pickup_preprocess($string, $method);
796 $array = uri_pickup($string);
798 // Area elevation of URIs, for '(especially external)link' intension
799 if (! empty($array)) {
801 if (isset($method['uri_anchor'])) $_method['uri_anchor'] = & $method['uri_anchor'];
802 if (isset($method['uri_bbcode'])) $_method['uri_bbcode'] = & $method['uri_bbcode'];
803 $areas = area_pickup($string, $_method, TRUE);
804 if (! empty($areas)) {
805 $area_shadow = array();
806 foreach (array_keys($array) as $key) {
807 $area_shadow[$key] = & $array[$key]['area'];
808 foreach (array_keys($_method) as $_key) {
809 $area_shadow[$key][$_key] = 0;
812 foreach (array_keys($_method) as $_key) {
813 if (isset($areas[$_key])) {
814 area_measure($areas[$_key], $area_shadow, 1, $_key);
820 // Remove 'offset's for area_measure()
821 foreach(array_keys($array) as $key) {
822 unset($array[$key]['area']['offset']);