예제 #1
0
function IIRS_0_akismet_comment_check($author_data)
{
    // Passes back TRUE (its spam) or FALSE (its ham)
    // or an IIRS_Error if a system level issue occurs
    $ret = FALSE;
    // not SPAM
    $url = 'http://' . IIRS_AKISMET_API_KEY . '.rest.akismet.com/1.1/comment-check';
    $akismet_ua = 'WordPress/3.8.1 | Akismet/2.5.9';
    $response_body = null;
    IIRS_0_debug_print("akismet spam check:");
    IIRS_0_debug_var_dump($author_data);
    $response_body = IIRS_0_http_request($url, $author_data, null, $akismet_ua);
    if (IIRS_is_error($response_body)) {
        // the low level HTTP request got an error, so return it
        $ret = $response_body;
    } elseif ('' == $response_body) {
        $ret = new IIRS_Error(IIRS_AKISMET_NOTHING, 'Failed to check the entries against the Akismet SPAM database. Please try again tomorrow :)', 'Akismet returned an invalid response (empty string)', IIRS_MESSAGE_EXTERNAL_SYSTEM_ERROR, IIRS_MESSAGE_NO_USER_ACTION, $author_data);
    } elseif (is_null($response_body)) {
        $ret = new IIRS_Error(IIRS_AKISMET_FAILED, 'Failed to check the entries against the Akismet SPAM database. Please try again tomorrow :)', 'Akismet returned a big fat nothing', IIRS_MESSAGE_EXTERNAL_SYSTEM_ERROR, IIRS_MESSAGE_NO_USER_ACTION, $author_data);
    } else {
        IIRS_0_debug_print("Akismet HTTP response:");
        IIRS_0_debug_var_dump($response_body);
        $ret = 'true' == $response_body;
        IIRS_0_debug_print($ret ? 'is SPAM' : 'not spam');
    }
    return $ret;
}
 //domain_other will be filled out if it has not already been checked by the previous domain_lookup
 if ($is_unchecked_domain) {
     $domain = trim($domain);
     $domain = preg_replace('/^(https?:\\/\\/)?(www\\.)?([^\\/?]*).*/i', '$3', $domain);
     IIRS_0_debug_print("domain: carrying out DNS [and WHOIS] lookup on [{$domain}]");
     $ip_address = gethostbyname($domain);
     // gethostbyname PHP 4,5
     $valid_dns = $ip_address != $domain;
 }
 if ($valid_dns) {
     IIRS_0_debug_print("DNS valid [{$ip_address}], updating domain to [{$domain}]");
     IIRS_0_TI_update_TI(array('domain' => $domain));
     //----------------------------------------------------- about us section from domain
     $old_error_reporting = error_reporting(0);
     $timeout = 1.0;
     if (!IIRS_is_error($aboutus = IIRS_0_http_request("http://{$domain}/aboutus", null, $timeout)) || !IIRS_is_error($aboutus = IIRS_0_http_request("http://{$domain}/about", null, $timeout)) || !IIRS_is_error($aboutus = IIRS_0_http_request("http://{$domain}/about_us", null, $timeout)) || !IIRS_is_error($aboutus = IIRS_0_http_request("http://{$domain}/", null, $timeout))) {
         $oAboutUs = new DOMDocument();
         $oAboutUs->loadHTML($aboutus);
         $xpath = new DOMXpath($oAboutUs);
         $elements = $xpath->query("//*[@id='content'] | //*[@class='layout-container']");
         if (!is_null($elements) && $elements->length) {
             $summary_from_website .= ' (' . IIRS_0_translation('from the website') . ')';
             foreach ($elements as $element) {
                 $summaryFromDomain .= $element->textContent . "\n";
             }
             $summaryFromDomain = preg_replace('/\\n\\s*\\n/', "\n", $summaryFromDomain);
             $summaryFromDomain = preg_replace('/\\n\\s*\\n/', "\n", $summaryFromDomain);
             $summaryFromDomain = preg_replace('/^\\s+|\\s+$|^\\s+/', "", $summaryFromDomain);
         } else {
             IIRS_0_debug_print("cannot find content in the aboutus response.");
         }
예제 #3
0
function IIRS_0_lookup_country_code_of_IPaddress($domain)
{
    //now get the public ip address of this domain (either this server, or the referer)
    $hostIP = gethostbyname($domain);
    //gethostbyname() PHP 4.0
    //host web-server IP caller location
    //NOTE: it will be the loopback when testing on my laptop
    //TODO: we may be able to download a copy of this geo-IP-DB to speed up requests
    //http://ipinfo.io/developers
    //  "You are limited to 1,000 API requests per day. If you need to make more requests, or need SSL support, see our paid plans."
    if ($hostIP == '127.0.0.1') {
        $hostIP = '46.107.207.154';
    }
    $ipinfo = IIRS_0_http_request("http://ipinfo.io/{$hostIP}/json");
    //we are not using json_decode() here in order to maintain backward compatability to PHP 4
    //preg_match('/"city": "([^"]+)"/mi',    $ipinfo, $matchesCity);
    //preg_match('/"region": "([^"]+)"/mi',  $ipinfo, $matchesRegion);
    preg_match('/"country": "([^"]+)"/mi', $ipinfo, $matchesCountryCode);
    //$remote_city        = $matchesCity[1];
    //$remote_region      = $matchesRegion[1];
    return $matchesCountryCode && isset($matchesCountryCode[1]) ? strtolower($matchesCountryCode[1]) : NULL;
}
예제 #4
0
function IIRS_0_geocode($town_name, $format = 'xml')
{
    global $location_is_example, $IIRS_host_TLD, $IIRS_common_dir;
    $location_arrays = array();
    // http://open.mapquestapi.com/geocoding/
    // see also http://en.wikipedia.org/wiki/Country_code_top-level_domain
    //   for region bias codes
    // NOTE: the country bias DOES NOT work for MapQuest. we are using a calculated bounding box instead
    //   boundingBox=61.06,-14.02,49.67,2.09
    $bounds_param = '';
    $region_bias = IIRS_0_setting('region_bias');
    if (!$region_bias || $region_bias == 'region_bias') {
        $region_bias = $IIRS_host_TLD;
    }
    if ($region_bias == 'dev' || $region_bias == 'org') {
        $region_bias = 'uk';
    }
    if ($bounds_details = IIRS_0_tld_bounds($region_bias)) {
        $bounds_min = $bounds_details['min'];
        $bounds_max = $bounds_details['max'];
        $bounds_min_lng = $bounds_min['lng'];
        $bounds_min_lat = $bounds_min['lat'];
        $bounds_max_lng = $bounds_max['lng'];
        $bounds_max_lat = $bounds_max['lat'];
        $bounds_param = 'boundingBox=' . $bounds_max_lat . ',' . $bounds_min_lng . ',' . $bounds_min_lat . ',' . $bounds_max_lng;
        IIRS_0_debug_print("located the country bounds for [{$IIRS_host_TLD} / {$region_bias}] => [{$bounds_param}]");
    } else {
        IIRS_0_debug_print("failed to locate the country bounds for [{$IIRS_host_TLD} / {$region_bias}]");
    }
    $town_name_encoded = urlencode($town_name);
    $url_request = "http://open.mapquestapi.com/geocoding/v1/address?key=Fmjtd%7Cluu829uan1%2C8n%3Do5-9w1a9r&location={$town_name_encoded}&callback=renderGeocode&outFormat={$format}&{$bounds_param}";
    IIRS_0_debug_print("region_bias:[" . IIRS_0_setting('region_bias') . "] => {$region_bias}");
    IIRS_0_debug_print($url_request);
    // http://wiki.openstreetmap.org/wiki/Nominatim#Parameters
    if ($location_is_example) {
        IIRS_0_debug_print("loading example file...");
        $xml = file_get_contents("{$IIRS_common_dir}/location_providers/example_data/mapquest.{$format}");
    } else {
        $xml = IIRS_0_http_request($url_request);
    }
    IIRS_0_debug_print($xml);
    if (IIRS_is_error($xml)) {
        $location_arrays = $xml;
    } else {
        $doc = new DOMDocument();
        $doc->loadXML($xml);
        $oXPath = new DOMXpath($doc);
        // translate the results in to a standardised array
        if (!$doc->documentElement || !$doc->documentElement->childNodes) {
            $location_arrays = new IIRS_Error(IIRS_LOCATION_XML_INVALID, 'Oops, it seems that the our servers are not responding! The manager has been informed and is trying to solve the problem. Please come back here tomorrow :)', 'Invalid XML returned', IIRS_MESSAGE_EXTERNAL_SYSTEM_ERROR, IIRS_MESSAGE_NO_USER_ACTION);
        } else {
            // handle no results (not an error as such!)
            if ($doc->documentElement->childNodes->length == 0) {
                IIRS_0_debug_print("no results from lookup");
            } else {
                // get places info into an associative array
                $placeNodes = $oXPath->query('/response/results/result/locations/location');
                IIRS_0_debug_print("{$placeNodes->length} results from lookup");
                foreach ($placeNodes as $placeNode) {
                    if ($placeNode->nodeType == XML_ELEMENT_NODE) {
                        /*
                          <street></street>
                          <adminArea5 type="City"></adminArea5>
                          <adminArea3 type="State">England</adminArea3>
                          <adminArea4 type="County">Bedford</adminArea4>
                          <postalCode></postalCode>
                          <adminArea1 type="Country">GB</adminArea1>
                          <geocodeQuality>COUNTY</geocodeQuality>
                          <geocodeQualityCode>A4XAX</geocodeQualityCode>
                          <dragPoint>false</dragPoint>
                          <sideOfStreet>N</sideOfStreet>
                          <displayLatLng><latLng><lat>52.136381</lat><lng>-0.467504</lng></latLng></displayLatLng>
                          <linkId>0</linkId>
                          <type>s</type>
                          <latLng><lat>52.136381</lat><lng>-0.467504</lng></latLng>
                          <mapUrl>
                        */
                        $location_array = array();
                        // assemble place description
                        $description = '';
                        foreach ($placeNode->childNodes as $placeValueNode) {
                            $sPlaceKey = $placeValueNode->nodeName;
                            if ($sPlaceKey != 'geocodeQuality' && $sPlaceKey != 'geocodeQualityCode' && $sPlaceKey != 'dragPoint' && $sPlaceKey != 'sideOfStreet' && $sPlaceKey != 'displayLatLng' && $sPlaceKey != 'linkId' && $sPlaceKey != 'type' && $sPlaceKey != 'latLng' && $sPlaceKey != 'mapUrl') {
                                $sPlaceValue = trim($placeValueNode->nodeValue);
                                if ($sPlaceValue) {
                                    $description .= "{$sPlaceValue}, ";
                                }
                            }
                        }
                        if ($description) {
                            $description = substr($description, 0, -2);
                        }
                        // entry and add in to the array
                        $location_array['description'] = $description;
                        $location_array['latitude'] = IIRS_0_get_DOM_value($placeNode, 'latLng/lat');
                        $location_array['longitude'] = IIRS_0_get_DOM_value($placeNode, 'latLng/lng');
                        $location_array['granuality'] = IIRS_0_get_DOM_value($placeNode, 'geocodeQuality');
                        $location_array['country'] = IIRS_0_get_DOM_value($placeNode, "adminArea1[@type='Country']");
                        $location_array['full_address'] = $description;
                        $location_array['bounds'] = '';
                        $location_arrays[] = $location_array;
                    }
                }
            }
        }
    }
    return $location_arrays;
}
예제 #5
0
function IIRS_0_geocode($town_name, $format = 'xml')
{
    global $location_is_example, $IIRS_host_TLD, $IIRS_common_dir;
    $location_arrays = array();
    // http://maps.google.com/maps/api/geocode/xml?sensor=false&address=bedford
    // see also http://en.wikipedia.org/wiki/Country_code_top-level_domain
    //   for region bias codes
    $region_bias = IIRS_0_setting('region_bias');
    if (!$region_bias || $region_bias == 'region_bias') {
        $region_bias = $IIRS_host_TLD;
    }
    if ($region_bias == 'dev' || $region_bias == 'org') {
        $region_bias = 'uk';
    }
    $town_name_encoded = urlencode($town_name);
    $url_request = "https://maps.google.com/maps/api/geocode/{$format}?sensor=false&region={$region_bias}&address={$town_name_encoded}&key=" . IIRS_GOOGLE_API_KEY;
    IIRS_0_debug_print($url_request);
    if ($location_is_example) {
        IIRS_0_debug_print("loading example file...");
        $xml = file_get_contents("{$IIRS_common_dir}/location_providers/example_data/google.{$format}");
    } else {
        $xml = IIRS_0_http_request($url_request, null, 5.0);
    }
    IIRS_0_debug_print($xml);
    if (IIRS_is_error($xml)) {
        $location_arrays = $xml;
    } else {
        // DOMDocument and DOMXpath ( PHP5 )
        // PHP >= 5 should be checked for in the installation procedure ( IIRS.install )
        $doc = new DOMDocument();
        $doc->loadXML($xml);
        $oXPath = new DOMXpath($doc);
        // translate the results in to a standardised array
        if (!$doc->documentElement || !$doc->documentElement->childNodes) {
            $location_arrays = new IIRS_Error(IIRS_LOCATION_XML_INVALID, 'Oops, it seems that the our servers are not responding! The manager has been informed and is trying to solve the problem. Please come back here tomorrow :)', 'Invalid XML returned', IIRS_MESSAGE_EXTERNAL_SYSTEM_ERROR, IIRS_MESSAGE_NO_USER_ACTION, array('$url_request' => $url_request));
        } else {
            // IIRS_0_debug_var_dump( $xml );
            if ($doc->documentElement->childNodes->length == 0) {
                // handle no results
                IIRS_0_debug_print("no results for lookup");
            } else {
                // get places info into an associative array
                $placeNodes = $doc->documentElement->childNodes;
                foreach ($placeNodes as $placeNode) {
                    if ($placeNode->nodeType == XML_ELEMENT_NODE && $placeNode->nodeName == 'result') {
                        $location_array = array();
                        // entry and add in to the array
                        // basic values
                        $location_array['description'] = IIRS_0_get_DOM_value($placeNode, 'formatted_address');
                        $location_array['latitude'] = IIRS_0_get_DOM_value($placeNode, 'geometry/location/lat');
                        $location_array['longitude'] = IIRS_0_get_DOM_value($placeNode, 'geometry/location/lng');
                        $location_array['granuality'] = IIRS_0_get_DOM_value($placeNode, 'type');
                        // full address
                        $fullAddress = '';
                        $nodeList = $oXPath->query('address_component', $placeNode);
                        foreach ($nodeList as $address_component) {
                            $address_level = IIRS_0_get_DOM_value($address_component, "type[1]");
                            $address_name = IIRS_0_get_DOM_value($address_component, 'long_name');
                            $fullAddress .= $address_name . ', ';
                            if ($address_level == 'country') {
                                $location_array['country'] = $address_name;
                            }
                        }
                        if ($fullAddress) {
                            $fullAddress = substr($fullAddress, 0, -2);
                        }
                        $location_array['full_address'] = $fullAddress;
                        // bounds
                        $northeast = IIRS_0_get_DOM_value($placeNode, 'geometry/bounds/northeast/lat') . ',' . IIRS_0_get_DOM_value($placeNode, 'geometry/bounds/northeast/lng');
                        $southwest = IIRS_0_get_DOM_value($placeNode, 'geometry/bounds/southwest/lat') . ',' . IIRS_0_get_DOM_value($placeNode, 'geometry/bounds/southwest/lng');
                        $location_array['bounds'] = "{$northeast};{$southwest}";
                        $location_arrays[] = $location_array;
                    }
                }
            }
        }
    }
    return $location_arrays;
}
function IIRS_0_geocode($town_name, $format = 'xml')
{
    global $location_is_example, $IIRS_host_TLD, $IIRS_common_dir;
    $location_arrays = array();
    // OSM has a usage limit, use of Nominatim is discouraged...
    // 403 Forbidden codes can come through if you over use the OSM API
    // http://wiki.openstreetmap.org/wiki/Nominatim_usage_policy
    // Open Street Map does not support post codes!
    // not using Services_Openstreetmap module because it requires PEAR HTTP_Request2
    // http://wiki.openstreetmap.org/wiki/API
    // https://github.com/kenguest/Services_Openstreetmap/tree/master/examples
    // $osm = new Services_OpenStreetMap( );
    // IIRS_0_debug_var_dump( $osm->getPlace( $town_name ));
    $town_name_encoded = urlencode($town_name);
    $url_request = "http://nominatim.openstreetmap.org/search?q={$town_name_encoded}&format={$format}&polygon_kml=1&addressdetails=1";
    IIRS_0_debug_print($url_request);
    // http://wiki.openstreetmap.org/wiki/Nominatim#Parameters
    if ($location_is_example) {
        IIRS_0_debug_print("loading example file...");
        $xml = file_get_contents("{$IIRS_common_dir}/registration/example_data/openstreetmap.{$format}");
    } else {
        $xml = IIRS_0_http_request($url_request);
    }
    if (IIRS_is_error($xml)) {
        $location_arrays = $xml;
    } else {
        $doc = new DOMDocument();
        $doc->loadXML($xml);
        // translate the results in to a standardised array
        if (!$doc->documentElement || !$doc->documentElement->childNodes) {
            $location_arrays = new IIRS_Error(IIRS_LOCATION_XML_INVALID, 'Oops, it seems that the our servers are not responding! The manager has been informed and is trying to solve the problem. Please come back here tomorrow :)', 'Invalid XML returned', IIRS_MESSAGE_EXTERNAL_SYSTEM_ERROR, IIRS_MESSAGE_NO_USER_ACTION);
        } else {
            // handle no results (not an error as such!)
            if ($doc->documentElement->childNodes->length == 0) {
                IIRS_0_debug_print("no results for lookup");
            } else {
                // get places info into an associative array
                $placeNodes = $doc->documentElement->childNodes;
                foreach ($placeNodes as $placeNode) {
                    if ($placeNode->nodeType == XML_ELEMENT_NODE && $placeNode->nodeName == 'place') {
                        $location_array = array();
                        // assemble place description
                        $description = '';
                        foreach ($placeNode->childNodes as $placeValueNode) {
                            $sPlaceKey = $placeValueNode->nodeName;
                            if ($sPlaceKey != 'geokml' && $sPlaceKey != 'country_code' && $sPlaceKey != 'station') {
                                $sPlaceValue = trim($placeValueNode->nodeValue);
                                if ($sPlaceValue) {
                                    $description .= "{$sPlaceValue}, ";
                                }
                            }
                        }
                        if ($description) {
                            $description = substr($description, 0, -2);
                        }
                        // entry and add in to the array
                        $location_array['description'] = $description;
                        // TODO: calculate the centre point from the geoxml
                        // we can do this *if* we choose to use OSM again...
                        $location_array['latitude'] = '52';
                        $location_array['longitude'] = '0';
                        $location_array['granuality'] = '';
                        $location_array['country'] = '';
                        $location_array['full_address'] = '';
                        $location_array['bounds'] = '';
                        $location_arrays[] = $location_array;
                    }
                }
            }
        }
    }
    return $location_arrays;
}