function sheets_lookup_by_fingerprint($fingerprint, $user_id = 0)
{
    $cache_key = "sheets_lookup_fingerprint_{$fingerprint}";
    $cache = cache_get($cache_key);
    if ($cache['ok']) {
        return $cache['data'];
    }
    #
    $enc_fingerprint = AddSlashes($fingerprint);
    $sql = "SELECT * FROM SheetsLookup WHERE fingerprint='{$enc_fingerprint}'";
    if ($user_id) {
        $enc_id = AddSlashes($user_id);
        $sql .= " AND user_id='{$enc_id}'";
    }
    $rsp = db_fetch($sql);
    $sheets = array();
    foreach ($rsp['rows'] as $row) {
        $more = array('sheet_user_id' => $row['user_id']);
        if ($sheet = sheets_get_sheet($row['sheet_id'], $user_id, $more)) {
            $sheets[] = $sheet;
        }
    }
    cache_set($cache_key, $sheets);
    return $sheets;
}
function _search_sheets_all($where, $viewer_id, $more = array())
{
    $sql = "SELECT DISTINCT(d.sheet_id) FROM DotsSearch d WHERE ";
    if ($more['has_extras']) {
        $sql = "SELECT DISTINCT(d.sheet_id) FROM DotsSearch d, DotsSearchExtras e WHERE d.dot_id=e.dot_id AND ";
    }
    #
    $sql .= implode(" AND ", $where);
    $rsp = db_fetch_paginated($sql, $more);
    if (!$rsp['ok']) {
        return $rsp;
    }
    $sheets = array();
    $sheet_more = array('load_user' => 1, 'load_extent' => 1);
    foreach ($rsp['rows'] as $row) {
        if (!$row['sheet_id']) {
            continue;
        }
        $sheet_more['sheet_user_id'] = $row['user_id'];
        $sheets[] = sheets_get_sheet($row['sheet_id'], $viewer_id, $sheet_more);
    }
    return array('ok' => 1, 'sheets' => &$sheets);
}
# $Id$
#
include "include/init.php";
loadlib("export");
loadlib("export_cache");
loadlib("formats");
#################################################################
#
# Ensure the user, the sheet and perms
#
$owner = users_ensure_valid_user_from_url();
$sheet_id = get_int64('sheet_id');
if (!$sheet_id) {
    error_404();
}
$sheet = sheets_get_sheet($sheet_id, $GLOBALS['cfg']['user']['id'], array('load_extent' => 1));
if (!$sheet) {
    error_404();
}
if (!sheets_can_view_sheet($sheet, $GLOBALS['cfg']['user']['id'])) {
    error_403();
}
$is_own = $sheet['user_id'] == $GLOBALS['cfg']['user']['id'] ? 1 : 0;
#
# Ensure that this is something we can export
#
$format = get_str('format');
if (!$format) {
    $format = 'csv';
}
$map = formats_valid_export_map('key by extension');
        $ok_cache = 0;
    }
    if (in_array($format, $GLOBALS['cfg']['export_cache_exclude_formats'])) {
        $ok_cache = 0;
    }
    if (!is_dir($GLOBALS['cfg']['export_cache_root'])) {
        $ok_cache = 0;
    }
}
#
if (!$ok_cache) {
    $export = export_dots($dots, $format, $export_more);
} else {
    $owner_ids = array_keys($owner_ids);
    $sheet_ids = array_keys($sheet_ids);
    $sheet = sheets_get_sheet($sheet_ids[0]);
    $is_own = $owner_ids[0] == $GLOBALS['cfg']['user']['id'] ? 1 : 0;
    $tmp = $export_more;
    $tmp['dot_ids'] = $dot_ids;
    unset($tmp['viewer_id']);
    $fingerprint = md5(serialize($tmp));
    $filename = "{$sheet['id']}_{$is_own}_{$fingerprint}.{$format}";
    $cache_more = array('filename' => $filename);
    $cache_path = export_cache_path_for_sheet($sheet, $cache_more);
    if (file_exists($cache_path)) {
        $export = $cache_path;
    } else {
        $export = export_dots($dots, $format, $export_more);
        if ($export) {
            $cache_rsp = export_cache_store_file($export, $cache_path);
            if (!$cache_rsp['ok']) {
function sheets_recently_created($viewer_id = 0, $more = array())
{
    $defaults = array('per_page' => 50);
    $args = array_merge($defaults, $more);
    $sql = "SELECT * FROM SheetsLookup WHERE deleted=0 AND count_dots_public > 0 ORDER BY created DESC";
    $rsp = db_fetch_paginated($sql, $args);
    if (!$rsp['ok']) {
        return $rsp;
    }
    $sheets = array();
    foreach ($rsp['rows'] as $row) {
        $more = array('sheet_user_id' => $row['user_id'], 'load_extent' => 1, 'load_user' => 1);
        if ($sheet = sheets_get_sheet($row['sheet_id'], $viewer_id, $more)) {
            $sheets[] = $sheet;
        }
    }
    $ok = count($sheets) ? 1 : 0;
    return array('ok' => $ok, 'sheets' => &$sheets);
}
Beispiel #6
0
function dots_load_details(&$dot, $viewer_id = 0, $more = array())
{
    $index_on = array();
    if ($GLOBALS['cfg']['enable_feature_dots_indexing']) {
        if ($dot['index_on']) {
            $index_on = explode(",", $dot['index_on']);
        }
        $dot['index_on'] = $index_on;
    } else {
        $index_on = array('location', 'type');
    }
    #
    $dot['details'] = json_decode($dot['details_json'], 1);
    $geo_bits = array('latitude', 'longitude', 'geohash');
    foreach (array_merge($geo_bits, $index_on) as $what) {
        # Edge cases. that's where I'm a viking! I was pretty sure this
        # was going to happen and started to write the code to deal with
        # it and then decided to JUST SHIP and here I am now. I blame Kellan.
        # Even though he had nothing to do with this... (20110726/straup)
        $key = in_array($what, $GLOBALS['dots_reserved']) ? "sheet:{$what}" : $what;
        $dot[$key] = isset($dot['details'][$what]) ? $dot['details'][$what][0]['value'] : '';
    }
    $listview = array();
    foreach ($dot['details'] as $label => $ignore) {
        if (!isset($dot[$label])) {
            $listview[] = $label;
        }
    }
    $dot['details_listview'] = implode(", ", $listview);
    #
    if ($more['load_sheet']) {
        $sheet_more = array('sheet_user_id' => $dot['user_id']);
        $dot['sheet'] = sheets_get_sheet($dot['sheet_id'], $viewer_id, $sheet_more);
    }
    if ($more['load_user']) {
        $dot['user'] = users_get_by_id($dot['user_id']);
    }
}
Beispiel #7
0
<?php

#
# $Id$
#
include "include/init.php";
loadlib("geo_geocode");
loadlib("formats");
$owner = users_ensure_valid_user_from_url();
$sheet_id = get_int64('sheet_id');
if (!$sheet_id) {
    error_404();
}
$more = array('load_extent' => 1);
$sheet = sheets_get_sheet($sheet_id, $GLOBALS['cfg']['user']['id'], $more);
if (!$sheet) {
    error_404();
}
if ($sheet['deleted']) {
    $GLOBALS['smarty']->display("page_sheet_deleted.txt");
    exit;
}
if ($sheet['user_id'] != $owner['id']) {
    error_404();
}
if (!sheets_can_view_sheet($sheet, $GLOBALS['cfg']['user']['id'])) {
    error_403();
}
#
$is_own = $owner['id'] == $GLOBALS['cfg']['user']['id'] ? 1 : 0;
$smarty->assign("is_own", $is_own);