Example #1
0
require_once "../init.php";
// Build the feeds from the config
global $characters, $corporations, $alliances;
if ($characters != null) {
    foreach ($characters as $character) {
        doFetch('character', $character);
    }
}
if ($corporations != null) {
    foreach ($corporations as $corporation) {
        doFetch('corporation', $corporation);
    }
}
if ($alliances != null) {
    foreach ($alliances as $alliance) {
        doFetch('alliance', $alliance);
    }
}
function doFetch($type, $id)
{
    global $redis, $debug;
    $key = "zkb:zkbFeed:{$type}:{$id}";
    $fetched = $redis->get($key);
    if ($fetched == true) {
        return;
    }
    if ($debug) {
        Util::out("Fetching {$type} {$id}");
    }
    $lastFetchedID = (int) $redis->get("zkb:lastFetchedID:{$type}:{$id}");
    do {
<?php

/*
Template Name: Map Gallery Vote
*/
if ($_GET['action'] && $_GET['action'] == 'fetch') {
    doFetch();
} else {
    doForm();
}
/* 
Fetch votes in last hour by IP address and return as JSON 
*/
function doFetch()
{
    header('Content-type: application/json');
    //Get IP address of client
    $ip = $_SERVER['REMOTE_ADDR'] ?: getenv('HTTP_CLIENT_IP') ?: getenv('HTTP_X_FORWARDED_FOR') ?: getenv('HTTP_X_FORWARDED') ?: getenv('HTTP_FORWARDED_FOR') ?: getenv('HTTP_FORWARDED');
    //Generate nonce (number used once) for allowing voting via Ajax
    $nonce = wp_create_nonce('nf_form_' + absint(4));
    //Get all votes
    $vote_recs = ninja_forms_get_all_subs(4);
    $votes = array();
    //Package vote info we care about
    foreach ($vote_recs as $vote_rec) {
        $vote_vals = unserialize($vote_rec['data']);
        $vote = array();
        foreach ($vote_vals as $vote_val) {
            switch ($vote_val['field_id']) {
                case 31:
                    $vote['mapid'] = intval($vote_val['user_value']);