|
1 | 1 | <?php
|
2 | 2 | /*
|
3 | 3 | phpGSB - PHP Google Safe Browsing Implementation
|
4 |
| -Version 0.2.3 |
| 4 | +Version 0.2.4 |
5 | 5 | Released under New BSD License (see LICENSE)
|
6 |
| -Copyright (c) 2010-2011, Sam Cleaver (Beaver6813, Beaver6813.com) |
| 6 | +Copyright (c) 2010-2012, Sam Cleaver (Beaver6813, Beaver6813.com) |
7 | 7 | All rights reserved.
|
8 | 8 | */
|
9 | 9 | ob_start();
|
10 | 10 | class phpGSB
|
11 | 11 | {
|
12 | 12 | var $apikey = "";
|
13 | 13 | var $version = "0.2";
|
14 |
| - var $realversion= "0.2.3"; |
| 14 | + var $realversion= "0.2.4"; |
15 | 15 | //DO NOT CHANGE API VERSION
|
16 | 16 | var $apiversion = "2.2";
|
17 | 17 |
|
@@ -671,50 +671,42 @@ function validateMethod()
|
671 | 671 |
|
672 | 672 | }
|
673 | 673 | }
|
674 |
| - /*From PHP.NET thanks to FredLudd at gmail dot com and theoriginalmarksimpson at gmail dot com |
675 |
| - Parses URL into its component parts, decided to use this against inbuilt function as it |
676 |
| - appears to be more accurate and flexible*/ |
| 674 | + /*Special thanks Steven Levithan (stevenlevithan.com) for the ridiculously complicated regex |
| 675 | + required to parse urls. This is used over parse_url as it robustly provides access to |
| 676 | + port, userinfo etc and handles mangled urls very well. |
| 677 | + Expertly integrated into phpGSB by Sam Cleaver ;) |
| 678 | + Thanks to mikegillis677 for finding the seg. fault issue in the old function. |
| 679 | + Passed validateMethod() check on 17/01/12*/ |
677 | 680 | function j_parseUrl($url)
|
678 | 681 | {
|
679 |
| - $r = "(?:([a-z0-9+-._]+)://)?"; |
680 |
| - $r .= "(?:"; |
681 |
| - $r .= "(?:((?:[a-z0-9-._~!$&'()*+,;=:]|%[0-9a-f]{2})*)@)?"; |
682 |
| - $r .= "(?:\[((?:[a-z0-9:])*)\])?"; |
683 |
| - $r .= "((?:[a-z0-9-._~!$&'()*+,;=]|%[0-9a-f]{2})*)"; |
684 |
| - $r .= "(?::(\d*))?"; |
685 |
| - $r .= "(/(?:[a-z0-9-._~!$&'()*+,;=:@/]|%[0-9a-f]{2})*)?"; |
686 |
| - $r .= "|"; |
687 |
| - $r .= "(/?"; |
688 |
| - $r .= "(?:[a-z0-9-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+"; |
689 |
| - $r .= "(?:[a-z0-9-._~!$&'()*+,;=:@\/]|%[0-9a-f]{2})*"; |
690 |
| - $r .= ")?"; |
691 |
| - $r .= ")"; |
692 |
| - $r .= "(?:\?((?:[a-z0-9-._~!$&'()*+,;=:\/?@]|%[0-9a-f]{2})*))?"; |
693 |
| - $r .= "(?:#((?:[a-z0-9-._~!$&'()*+,;=:\/?@]|%[0-9a-f]{2})*))?"; |
694 |
| - preg_match("`$r`i", $url, $match); |
695 |
| - $parts = array( |
696 |
| - "scheme"=>'', |
697 |
| - "userinfo"=>'', |
698 |
| - "authority"=>'', |
699 |
| - "host"=> '', |
700 |
| - "port"=>'', |
701 |
| - "path"=>'', |
702 |
| - "query"=>'', |
703 |
| - "fragment"=>''); |
704 |
| - switch (count ($match)) { |
705 |
| - case 10: $parts['fragment'] = $match[9]; |
706 |
| - case 9: $parts['query'] = $match[8]; |
707 |
| - case 8: $parts['path'] = $match[7]; |
708 |
| - case 7: $parts['path'] = $match[6] . $parts['path']; |
709 |
| - case 6: $parts['port'] = $match[5]; |
710 |
| - case 5: $parts['host'] = $match[3]?"[".$match[3]."]":$match[4]; |
711 |
| - case 4: $parts['userinfo'] = $match[2]; |
712 |
| - case 3: $parts['scheme'] = $match[1]; |
| 682 | + $strict = '/^(?:([^:\/?#]+):)?(?:\/\/\/?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?(((?:\/(\w:))?((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/'; |
| 683 | + $loose = '/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/\/?)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((?:\/(\w:))?(\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/'; |
| 684 | + preg_match($loose, $url, $match); |
| 685 | + if(empty($match)) |
| 686 | + { |
| 687 | + //As odd as its sounds, we'll fall back to strict (as technically its more correct and so may salvage completely mangled urls) |
| 688 | + unset($match); |
| 689 | + preg_match($strict, $url, $match); |
| 690 | + } |
| 691 | + $parts = array("source"=>'',"scheme"=>'',"authority"=>'',"userinfo"=>'',"user"=>'',"password"=>'',"host"=>'',"port"=>'',"relative"=>'',"path"=>'',"drive"=>'',"directory"=>'',"file"=>'',"query"=>'',"fragment"=>''); |
| 692 | + switch (count ($match)) { |
| 693 | + case 15: $parts['fragment'] = $match[14]; |
| 694 | + case 14: $parts['query'] = $match[13]; |
| 695 | + case 13: $parts['file'] = $match[12]; |
| 696 | + case 12: $parts['directory'] = $match[11]; |
| 697 | + case 11: $parts['drive'] = $match[10]; |
| 698 | + case 10: $parts['path'] = $match[9]; |
| 699 | + case 9: $parts['relative'] = $match[8]; |
| 700 | + case 8: $parts['port'] = $match[7]; |
| 701 | + case 7: $parts['host'] = $match[6]; |
| 702 | + case 6: $parts['password'] = $match[5]; |
| 703 | + case 5: $parts['user'] = $match[4]; |
| 704 | + case 4: $parts['userinfo'] = $match[3]; |
| 705 | + case 3: $parts['authority'] = $match[2]; |
| 706 | + case 2: $parts['scheme'] = $match[1]; |
| 707 | + case 1: $parts['source'] = $match[0]; |
713 | 708 | }
|
714 |
| - $parts['authority'] = ($parts['userinfo']?$parts['userinfo']."@":""). |
715 |
| - $parts['host']. |
716 |
| - ($parts['port']?":".$parts['port']:""); |
717 |
| - return $parts; |
| 709 | + return $parts; |
718 | 710 | }
|
719 | 711 | /*Regex to check if its a numerical IP address*/
|
720 | 712 | function is_ip($ip)
|
|
0 commit comments