Esempio n. 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;
}
        //prevent the error appearing in the translations system
        new IIRS_Error(IIRS_GEOCODE_RESULTS_EMPTY, $non_fatal_error_email, "Geocode [{$mapping_provider}] returned zero results for [{$town_name}]", IIRS_MESSAGE_EXTERNAL_SYSTEM_ERROR, NULL);
    }
    // ------------------------------------------------------------------------- check for already registered initiative_name
    $TI_same_name = IIRS_0_TI_same_name($town_name);
    // returns a TI or FALSE or [system] IIRS_Error
    if (is_array($TI_same_name)) {
        // ok, so we have a registration with an identical initiative name
        // same name entries are not necessarily close by. America and UK will have many name conflicts
        // reject this currently. ask for an alternative name
        // this might cause the user to experience surprise, anger, competition.
        // needs to be handled with emotional intelligence, i.e.:
        //   hey! we've found someone you can chat and work with in your space!
        //   OR
        //   someone OWNS this name and you are not permitted to create an Initiative here.
        IIRS_0_debug_var_dump($TI_same_name);
        $set_message_id = IIRS_TI_EXISTS_SAME_NAME;
        $set_message = IIRS_0_translation('We have found your town or area. However, the Initiative name already exists');
        $set_message .= " [{$town_name}]. ";
        $set_message .= IIRS_0_translation('Please add something to the initiative name below to make it unique.');
        $set_message .= IIRS_0_translation('For Example:');
        $set_message .= " [west{$town_name}] or [energy_subgroup_{$town_name}].";
        $duplicate_validation_issue = 'IIRS_0_validation_fail';
    }
} else {
    $IIRS_error = new IIRS_Error(IIRS_NO_INPUTS, "Oops, we didn't recieve your data. Please try again", "No inputs", IIRS_MESSAGE_USER_ERROR, IIRS_JAVASCRIPT_BACK);
}
?>
</pre></div>

<style>
Esempio n. 3
0
function IIRS_0_TI_verify_add_TI($user_ID, $IIRS_host_domain, $initiative_name, $town_name, $location_latitude, $location_longitude, $location_description, $location_country, $location_full_address, $location_granuality, $location_bounds, $domain)
{
    // on success returns the native TI ID
    // on failure returns NULL
    $ret = null;
    // --------------------------------------- 1) check data input validity
    // the user is already registered, so we can use IIRS_0_details_user()
    // TODO: concurrency issues with registration
    if (!is_numeric($location_latitude) || !is_numeric($location_longitude)) {
        $ret = new IIRS_Error(IIRS_INVALID_TI_INPUTS, 'We think you are a SPAM robot. please email us to resolve this issue.', 'location data is not numeric', IIRS_MESSAGE_USER_ERROR, IIRS_MESSAGE_NO_USER_ACTION, array('$location_latitude' => $location_latitude, '$location_longitude' => $location_longitude));
    }
    // --------------------------------------- 2) check user 1-1 TI relation
    if (!$ret) {
        $TI = IIRS_0_details_TI_user();
        // returns NULL if no TI associated
        if (is_array($TI)) {
            $ret = new IIRS_Error(IIRS_USER_ALREADY_HAS_TI, 'You have already registered a Transition Initiative under this username. Please logout and re-register', "User already associated with TI [{$TI['name']}]", IIRS_MESSAGE_USER_ERROR, IIRS_MESSAGE_NO_USER_ACTION, $TI);
        } elseif (IIRS_is_error($TI)) {
            $ret = $TI;
        }
    }
    // --------------------------------------- 3) check duplicate registration by vicinity
    // currently disabled. will always return ok
    if (!$ret) {
        $vicinity_match = IIRS_0_TI_vicinity_match($location_latitude, $location_longitude, $location_description);
        if ($vicinity_match === TRUE || IIRS_is_error($vicinity_match)) {
            $ret = $vicinity_match;
        }
    }
    // --------------------------------------- 4) check duplicate TI name
    if (!$ret) {
        $TI_same_name = IIRS_0_TI_same_name($initiative_name);
        // returns a TI or FALSE or [system] IIRS_Error
        if (is_array($TI_same_name)) {
            // ok, so we have a registration with an identical name
            // same name entries are not necessarily close by. America and UK will have many name conflicts
            // reject this currently. ask for an alternative name
            // this might cause the user to experience surprise, anger, competition.
            // needs to be handled with emotional intelligence, i.e.:
            //   hey! we've found someone you can chat and work with in your space!
            //   OR
            //   someone OWNS this name and you are not permitted to create an Initiative here.
            IIRS_0_debug_var_dump($TI_same_name);
            $ret = new IIRS_Error(IIRS_TI_EXISTS_SAME_NAME, 'A Transition Initiative already exists with this name. Please add something to the name or change it and try again', 'TI Name matched exactly in data verification stage', IIRS_MESSAGE_USER_WARNING, IIRS_MESSAGE_NO_USER_ACTION, array('$TI_same_name' => $TI_same_name));
        } elseif (IIRS_is_error($TI_same_name)) {
            $ret = $TI_same_name;
        }
    }
    // --------------------------------------- 5) check for SPAM using AKISMET
    // IIRS_0_akismet_check_ti_registration_name() returns true for is SPAM
    if (!$ret) {
        $is_SPAM = IIRS_0_akismet_check_ti_registration_name(IIRS_0_details_user(), $initiative_name);
        if ($is_SPAM === TRUE) {
            $ret = new IIRS_Error(IIRS_AKISMET_SAYS_SPAM, 'Akismet thinks that your entry is SPAM. So we cannot accept it. Sorry.', 'Akismet returned true for SPAM detection', IIRS_MESSAGE_USER_ERROR, IIRS_MESSAGE_NO_USER_ACTION, array('$initiative_name' => $initiative_name));
        } elseif (IIRS_is_error($is_SPAM)) {
            $ret = $is_SPAM;
        }
    }
    // --------------------------------------- F) FINAL: if no vertification issues registrered then everything ok
    if (!$ret) {
        // ask host framework to add the TI
        $ret = IIRS_0_TI_add_TI($user_ID, $IIRS_host_domain, $initiative_name, $town_name, $location_latitude, $location_longitude, $location_description, $location_country, $location_full_address, $location_granuality, $location_bounds, $domain);
    }
    return $ret;
}
        }
    }
}
if (!$TI_save_error) {
    //------------------------------------- debug
    IIRS_0_debug_print("details:");
    IIRS_0_debug_print("  native_user_ID:{$native_user_ID} (don't forget that all emails on dev point to annesley newholms yahoo email address)");
    IIRS_0_debug_print("  native_ti_ID:{$native_ti_ID}");
    //------------------------------------- get some nice domain names for this town
    $domains_found = false;
    $domain_part = $location_is_example ? 'bedford' : $town_name;
    $nice_domains_html = '';
    // internationalisation of nice_domain array and TLD array
    $nice_domains = IIRS_0_get_nice_domains($domain_part);
    IIRS_0_debug_print('nice_domain stems:');
    IIRS_0_debug_var_dump($nice_domains);
    //using our tld list is too time consuming
    //could use threads but beyond scope for now
    /*
    $effective_tld_names = file_get_contents(__DIR__ . '/effective_tld_names.dat.txt');
    $aAllFileEntries     = explode("\n", $effective_tld_names);
    $all_TLDs               = array();
    foreach ($aAllFileEntries as $entry) {
      if (strlen($entry) && substr($entry, 0, 2) != '//') {
        $all_TLDs[] = $entry;
      }
    }
    IIRS_0_debug_print("check potential domain string [$domain_part] combinations against [" . count($all_TLDs) . "] TLDs:");
    */
    $all_TLDs = IIRS_0_get_nice_TLDs();
    $option = 1;