Пример #1
0
function getGlobalAcceptanceInstances()
{
    $instances = apc_fetch('all_instances');
    if (empty($instances) || getenv('ADT_DEV_MODE')) {
        $instances = array();
        if (getenv('ADT_DEV_MODE')) {
            // Emulate decode/encode with json because they are converting array into objects
            // TBD : Cleanup JSON decode/encode and array/objects
            $instances = json_decode(json_encode(getLocalAcceptanceInstances()));
        } else {
            $servers = explode(",", getenv('ACCEPTANCE_SERVERS'));
            foreach ($servers as $server) {
                $instances = append_data($server . '/rest/local-instances.php', $instances);
            }
        }
        // Instances will be cached for 2 min
        apc_store('all_instances', $instances, 120);
    }
    return $instances;
}
Пример #2
0
function get_archive_data($caches)
{
    $cachelist = "(" . implode(",", $caches) . ")";
    $data = array();
    $admins = array();
    // make waypoint index
    $rs = sql("SELECT `cache_id`, `wp_oc` FROM `caches` WHERE `cache_id` IN " . $cachelist);
    while ($r = sql_fetch_assoc($rs)) {
        $wp_oc[$r['cache_id']] = $r['wp_oc'];
    }
    sql_free_result($rs);
    // cache coordinates
    $rs = sql("SELECT\n            `cache_id`,\n            LEFT(`date_created`,10) AS `date_modified`,\n            `longitude`,\n            `latitude`,\n            `restored_by`\n        FROM `cache_coordinates`\n        WHERE `cache_id` IN " . $cachelist . "\n        ORDER BY `date_created` ASC");
    // order is relevant, because multiple changes per day possible
    $lastcoord = array();
    while ($r = sql_fetch_assoc($rs)) {
        $coord = new coordinate($r['latitude'], $r['longitude']);
        $coord = $coord->getDecimalMinutes();
        $coord = $coord['lat'] . " " . $coord['lon'];
        if (isset($lastcoord[$r['cache_id']]) && $coord != $lastcoord[$r['cache_id']]) {
            // the database contains lots of old coord records with unchanged coords, wtf?
            append_data($data, $admins, $wp_oc, $r, "coord", $lastcoord[$r['cache_id']], $coord);
        }
        $lastcoord[$r['cache_id']] = $coord;
    }
    sql_free_result($rs);
    // cache country
    $rs = sql("SELECT `cache_id`, LEFT(`date_created`,10) AS `date_modified`, `country`, `restored_by`\n               FROM `cache_countries`\n                         WHERE `cache_id` IN " . $cachelist . "\n                         ORDER BY `date_created` ASC");
    // order is relevant, because multiple changes per day possible
    $lastcountry = array();
    while ($r = sql_fetch_assoc($rs)) {
        if (isset($lastcountry[$r['cache_id']]) && $r['country'] != $lastcountry[$r['cache_id']]) {
            // the database contains some old country records with unchanged coords, wtf?
            append_data($data, $admins, $wp_oc, $r, "country", $lastcountry[$r['cache_id']], $r['country']);
        }
        $lastcountry[$r['cache_id']] = $r['country'];
    }
    sql_free_result($rs);
    // all other cache data
    // first the current data ...
    $nextcd = array();
    $rs = sql("SELECT * FROM `caches` WHERE `cache_id` IN " . $cachelist);
    while ($r = sql_fetch_assoc($rs)) {
        $nextcd[$r['wp_oc']] = $r;
        $user_id = $r['user_id'];
        // is used later for logs
    }
    sql_free_result($rs);
    // .. and then the changes
    $rs = sql("SELECT * FROM `caches_modified`\n        WHERE `cache_id` IN " . $cachelist . "\n        ORDER BY `date_modified` DESC");
    while ($r = sql_fetch_assoc($rs)) {
        $wp = $wp_oc[$r['cache_id']];
        if ($r['name'] != $nextcd[$wp]['name']) {
            append_data($data, $admins, $wp_oc, $r, "name", $r['name'], $nextcd[$wp]['name']);
        }
        if ($r['type'] != $nextcd[$wp]['type']) {
            append_data($data, $admins, $wp_oc, $r, "type", labels::getLabelValue('cache_type', $r['type']), labels::getLabelValue('cache_type', $nextcd[$wp]['type']));
        }
        if ($r['size'] != $nextcd[$wp]['size']) {
            append_data($data, $admins, $wp_oc, $r, "size", labels::getLabelValue('cache_size', $r['size']), labels::getLabelValue('cache_size', $nextcd[$wp]['size']));
        }
        if ($r['difficulty'] != $nextcd[$wp]['difficulty']) {
            append_data($data, $admins, $wp_oc, $r, "D", $r['difficulty'] / 2, $nextcd[$wp]['difficulty'] / 2);
        }
        if ($r['terrain'] != $nextcd[$wp]['terrain']) {
            append_data($data, $admins, $wp_oc, $r, "T", $r['terrain'] / 2, $nextcd[$wp]['terrain'] / 2);
        }
        if ($r['search_time'] != $nextcd[$wp]['search_time']) {
            append_data($data, $admins, $wp_oc, $r, "time", $r['search_time'] . ' h', $nextcd[$wp]['search_time'] . ' h');
        }
        if ($r['way_length'] != $nextcd[$wp]['way_length']) {
            append_data($data, $admins, $wp_oc, $r, "way", $r['way_length'] . ' km', $nextcd[$wp]['way_length'] . ' km');
        }
        if ($r['wp_gc'] != $nextcd[$wp]['wp_gc']) {
            append_data($data, $admins, $wp_oc, $r, "GC ", format_wp($r['wp_gc']), format_wp($nextcd[$wp]['wp_gc']));
        }
        if ($r['wp_nc'] != $nextcd[$wp]['wp_nc']) {
            append_data($data, $admins, $wp_oc, $r, "GC ", format_wp($r['wp_nc']), format_wp($nextcd[$wp]['wp_nc']));
        }
        if ($r['date_hidden'] != $nextcd[$wp]['date_hidden']) {
            append_data($data, $admins, $wp_oc, $r, "hidden", $r['date_hidden'], $nextcd[$wp]['date_hidden']);
        }
        $nextcd[$wp] = $r;
    }
    sql_free_result($rs);
    // attributes
    $rs = sql("SELECT * FROM `caches_attributes_modified`\n         WHERE `cache_id` IN " . $cachelist . "  /* OConly attrib is shown, but not restorable */\n         ORDER BY `date_modified` ASC");
    // order doesn't matter as long it is date only
    while ($r = sql_fetch_assoc($rs)) {
        append_data($data, $admins, $wp_oc, $r, "attrib", ($r['was_set'] ? "-" : "+") . labels::getLabelValue('cache_attrib', $r['attrib_id']), '');
    }
    sql_free_result($rs);
    // descriptions
    // first the current data ...
    $nextdesc = array();
    $rs = sql("SELECT\n            `cache_id`,\n            `language`,\n            LENGTH(`desc`) AS `dl`,\n            LENGTH(`hint`) AS `hl`,\n            LENGTH(`short_desc`) AS `sdl`\n        FROM `cache_desc`\n        WHERE `cache_id` IN " . $cachelist);
    while ($r = sql_fetch_assoc($rs)) {
        if (!isset($nextdesc[$r['cache_id']])) {
            $nextdesc[$r['cache_id']] = [];
        }
        $nextdesc[$r['cache_id']][$r['language']] = $r;
    }
    sql_free_result($rs);
    // ... and then the changes
    $rs = sql("SELECT\n            `cache_id`,\n            `date_modified`,\n            `language`,\n            LENGTH(`desc`) AS `dl`,\n            LENGTH(`hint`) AS `hl`,\n            LENGTH(`short_desc`) AS `sdl`,\n            `restored_by`\n        FROM `cache_desc_modified`\n        WHERE `cache_id` IN " . $cachelist . "\n        ORDER BY `date_modified` DESC");
    // order doesn't matter as long only one change per day is recorded
    while ($r = sql_fetch_assoc($rs)) {
        $wp = $wp_oc[$r['cache_id']];
        if (!isset($nextdesc[$r['cache_id']]) || !isset($nextdesc[$r['cache_id']][$r['language']])) {
            $next = ['dl' => 0, 'hl' => 0, 'sdl' => 0];
        } else {
            $next = $nextdesc[$r['cache_id']][$r['language']];
        }
        if ($r['dl'] + 0 != $next['dl'] + 0) {
            append_data($data, $admins, $wp_oc, $r, "desc(" . $r['language'] . ")", $r['dl'] + 0, $next['dl'] + 0 . ' bytes');
        }
        if ($r['hl'] + 0 != $next['hl'] + 0) {
            append_data($data, $admins, $wp_oc, $r, "hint(" . $r['language'] . ")", $r['hl'] + 0, $next['hl'] + 0 . ' bytes');
        }
        if ($r['sdl'] + 0 != $next['sdl'] + 0) {
            append_data($data, $admins, $wp_oc, $r, "shortdesc(" . $r['language'] . ")", $r['sdl'] + 0, $next['sdl'] + 0 . ' bytes');
        }
        $nextdesc[$r['cache_id']][$r['language']] = $r;
    }
    sql_free_result($rs);
    // logs
    $rs = sql("SELECT\n            `op`,\n            LEFT(`date_modified`,10) AS `date_modified`,\n            `cache_id`,\n            `logs`.`user_id`,\n            `type`,\n            `date`,\n            `restored_by`,\n            `username`\n        FROM\n              (SELECT 1 AS `op`, `deletion_date` AS `date_modified`, `cache_id`,\n                    `user_id`, `type`, `date`, `restored_by`\n                   FROM `cache_logs_archived`\n                  WHERE `cache_id` IN " . $cachelist . "AND `deleted_by`='&1' AND `user_id`<>'&1'\n                  UNION\n                  SELECT 2 AS `op`, `date_modified`, `cache_id`,\n                       (SELECT `user_id` FROM `cache_logs_archived` WHERE `id`=`original_id`),\n                       (SELECT `type` FROM `cache_logs_archived` WHERE `id`=`original_id`),\n                       (SELECT `date` FROM `cache_logs_archived` WHERE `id`=`original_id`),\n                       `restored_by`\n                 FROM `cache_logs_restored`\n                  WHERE `cache_id` IN " . $cachelist . ") `logs`\n                INNER JOIN `user` ON `user`.`user_id`=`logs`.`user_id`\n              ORDER BY `logs`.`date_modified` ASC", $user_id);
    while ($r = sql_fetch_assoc($rs)) {
        append_data($data, $admins, $wp_oc, $r, $r["op"] == 1 ? "dellog" : "restorelog", "<a href='viewprofile.php?userid=" . $r['user_id'] . "' target='_blank'>" . $r['username'] . "</a>/" . $r['date'], '');
    }
    sql_free_result($rs);
    // pictures
    /* For sake of simplification, we
     *   - have stored the name of inserted pictures in pictures_modified
     *   - give no detailed information on picture property changes. This will be very
     *       rare in case of vandalism ...
     */
    $piccacheid = "IF(`object_type`=2, `object_id`, IF(`object_type`=1, IFNULL((SELECT `cache_id` FROM `cache_logs` WHERE `id`=`object_id`),(SELECT `cache_id` FROM `cache_logs_archived` WHERE `id`=`object_id`)), 0))";
    $rs = sql("SELECT *, " . $piccacheid . "AS `cache_id` FROM `pictures_modified`\n         WHERE " . $piccacheid . " IN " . $cachelist . "\n         ORDER BY `date_modified` ASC");
    // order is relevant for the case of restore-reverts
    while ($r = sql_fetch_assoc($rs)) {
        $r['date_modified'] = substr($r['date_modified'], 0, 10);
        switch ($r['operation']) {
            case 'I':
                $picchange = "add";
                break;
            case 'U':
                $picchange = "mod";
                break;
            case 'D':
                $picchange = "del";
                break;
        }
        switch ($r['object_type']) {
            case 1:
                $picchange .= "-log";
                break;
            case 2:
                $picchange .= "-cache";
                break;
        }
        append_data($data, $admins, $wp_oc, $r, $picchange . "pic", $r['title'], '');
    }
    sql_free_result($rs);
    // admins
    foreach ($admins as $adate => $adata) {
        foreach ($adata as $awp => $alist) {
            $data[$adate][$awp] .= "<br /><strong class='adminrestore'>admins:</strong> " . implode(',', $alist);
        }
    }
    // done
    ksort($data);
    return array_reverse($data, true);
}