Example #1
0
/* Manual Initiative Profile listing page
 * NOTE: this should NOT normally be used
 * The framework system should list the posts / nodes / whatevers natively
 * thus using the local templating system and all fitting in rather nicely
 * use that page instead and override the edit function
 *
 * Redirect all TI editing to /IIRS/edit to prevent users from going in to the host framework editing suite
 */
global $debug_environment;
require_once IIRS__COMMON_DIR . 'utility.php';
require_once IIRS__COMMON_DIR . 'framework_abstraction_layer.php';
require_once IIRS__COMMON_DIR . 'environment.php';
IIRS_0_debug_print($debug_environment);
$all_TIs = IIRS_0_TIs_all();
usort($all_TIs, 'IIRS_0_sort_date_desc');
$usersTI = IIRS_0_details_TI_user();
?>
</pre></div>

<div id="IIRS_0">
  <style>
    body .entry-meta {display:block;}
  </style>

  <div class="IIRS_0_h1"><?php 
IIRS_0_print_translated_HTML_text(IGNORE_TRANSLATION, 'list of Transition Initiative around the world');
?>
    <?php 
IIRS_0_print_language_selector();
?>
  </div>
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;
}