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; }
$location_options = IIRS_0_location_search_options($town_name); if (IIRS_is_error($location_options)) { $IIRS_error = $location_options; } else { $towns_found = !empty($location_options); } if (!$towns_found) { $no_towns_found_disabled = 'disabled="1"'; $no_towns_found_disabled_class = 'IIRS_0_disabled'; IIRS_0_debug_print("sending extra geocode fail message"); $non_fatal_error_email = "No towns found for [{$town_name}]"; //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.');