Example #1
0
function _search_dots_all($where, $viewer_id, $more = array())
{
    $sql = 'SELECT * FROM DotsSearch d WHERE ';
    if ($more['has_extras']) {
        $sql = 'SELECT d.*, e.name, e.value FROM DotsSearch d, DotsSearchExtras e WHERE d.dot_id=e.dot_id AND ';
    }
    #
    $sql .= implode(" AND ", $where);
    if (isset($more['order'])) {
        $sql .= " ORDER BY d.{$more['order']['by']} {$more['order']['sort']}";
    }
    $rsp = db_fetch_paginated($sql, $more);
    if (!$rsp['ok']) {
        return $rsp;
    }
    $dots = array();
    $dot_more = array('load_user' => 1);
    foreach ($rsp['rows'] as $row) {
        if (!$row['dot_id']) {
            continue;
        }
        $dot_more['dot_user_id'] = $row['user_id'];
        $dots[] = dots_get_dot($row['dot_id'], $viewer_id, $dot_more);
    }
    return array('ok' => 1, 'dots' => &$dots);
}
Example #2
0
function gpx_export_dots(&$dots, &$more)
{
    $ns_map = array('' => 'http://www.topografix.com/GPX/1/1', 'dotspotting' => 'x-urn:dotspotting#internal', 'sheet' => 'x-urn:dotspotting#sheet');
    $skip = array('latitude', 'longitude', 'elevation', 'created');
    $doc = new DomDocument('1.0', 'UTF-8');
    $gpx = $doc->createElement('gpx');
    $gpx = $doc->appendChild($gpx);
    $_ver = $doc->createTextNode('1.1');
    $ver = $doc->createAttribute("version");
    $ver->appendChild($_ver);
    $gpx->appendChild($ver);
    $_creator = $doc->createTextNode('Dotspotting');
    $creator = $doc->createAttribute('creator');
    $creator->appendChild($_creator);
    $gpx->appendChild($creator);
    foreach ($ns_map as $prefix => $uri) {
        $xmlns = $prefix ? "xmlns:{$prefix}" : "xmlns";
        $attr = $doc->createAttribute($xmlns);
        $uri = $doc->createTextNode($uri);
        $attr->appendChild($uri);
        $gpx->appendChild($attr);
    }
    $trk = $doc->createElement('trk');
    $trk = $gpx->appendChild($trk);
    $_dot = dots_get_dot($dots[0]['dotspotting:id']);
    $_name = $_dot['sheet']['label'] ? "Dots from the sheet '{$_dot['sheet']['label']}'" : "Dots from sheet ID #{$_dot['sheet']['id']}";
    $_name = $doc->createTextNode(htmlspecialchars($_name));
    $name = $doc->createElement('name');
    $name->appendChild($_name);
    $trk->appendChild($name);
    $_desc = $doc->createTextNode("n/a");
    $desc = $doc->createElement('desc');
    $desc->appendChild($_desc);
    $trk->appendChild($desc);
    $trkseg = $doc->createElement('trkseg');
    $trkseg = $trk->appendChild($trkseg);
    foreach ($dots as $dot) {
        $trkpt = $doc->createElement('trkpt');
        $_lat = $doc->createTextNode($dot['latitude']);
        $_lon = $doc->createTextNode($dot['longitude']);
        $lat = $doc->createAttribute("lat");
        $lat->appendChild($_lat);
        $lon = $doc->createAttribute("lon");
        $lon->appendChild($_lon);
        $trkpt->appendChild($lat);
        $trkpt->appendChild($lon);
        #
        $elevation = isset($dot['elevation']) ? $dot['elevation'] : '0.000000';
        $_ele = $doc->createTextNode($elevation);
        $ele = $doc->createElement('ele');
        $ele->appendChild($_ele);
        $trkpt->appendChild($ele);
        #
        $created = strtotime($dot['created']);
        $created = gmdate('Y-m-d\\TH:m:s\\Z', $created);
        $_time = $doc->createTextNode($created);
        $time = $doc->createElement('time');
        $time->appendChild($_time);
        $trkpt->appendChild($time);
        # non-standard elements makes tools by garmin cry...
        # (20110113/straup)
        $trkseg->appendChild($trkpt);
    }
    $doc->save($more['path']);
    return $more['path'];
}
$format = get_str('format');
if (!$format) {
    $format = 'csv';
}
if (!isset($map[$format])) {
    $format = 'csv';
}
$page = get_str('page');
#
$dots = array();
$dot_ids = array();
$sheet_ids = array();
$owner_ids = array();
if ($ids = get_str('ids')) {
    foreach (explode(",", $ids) as $id) {
        $dot = dots_get_dot($id, $GLOBALS['cfg']['user']['id']);
        if (!$dot['id']) {
            continue;
        }
        $sheet_ids[$dot['sheet_id']]++;
        $owner_ids[$dot['user_id']]++;
        $dot_ids[] = $dot['id'];
        $dots[] = $dot;
    }
} else {
    $more = array('page' => $page);
    $rsp = search_dots($_GET, $GLOBALS['cfg']['user']['id'], $more);
    if (!$rsp['ok']) {
        exit;
    }
    $dots = $rsp['dots'];
Example #4
0
function dots_get_dots_recently_imported($to_fetch = 15)
{
    # CACHING: This doesn't really lend itself to caching.
    # That may become an issue (20110301/straup)
    $recent = array();
    $sheet_sql = "SELECT * FROM SheetsLookup WHERE deleted=0 ORDER BY created DESC";
    $sheet_args = array('page' => 1);
    $page_count = null;
    $total_count = null;
    $iters = 0;
    $max_iters = 15;
    while (!isset($page_count) || $page_count >= $sheet_args['page']) {
        $sheet_rsp = db_fetch_paginated($sheet_sql, $sheet_args);
        if (!$sheet_rsp['ok']) {
            break;
        }
        if (!isset($page_count)) {
            $page_count = $sheet_rsp['pagination']['page_count'];
            $total_count = $sheet_rsp['pagination']['total_count'];
        }
        foreach ($sheet_rsp['rows'] as $sheet) {
            $enc_sheet = AddSlashes($sheet['sheet_id']);
            $dot_sql = "SELECT * FROM DotsSearch WHERE sheet_id='{$enc_sheet}' AND perms=0 ORDER BY imported DESC";
            $dot_args = array('per_page' => 15);
            $dot_rsp = db_fetch_paginated($dot_sql, $dot_args);
            if (!$dot_rsp['ok']) {
                break;
            }
            $default_limit = 3;
            # sudo, make me smarter
            $limit = min($default_limit, count($dot_rsp['rows']));
            if ($limit) {
                shuffle($dot_rsp['rows']);
                foreach (array_slice($dot_rsp['rows'], 0, $limit) as $row) {
                    $viewer_id = 0;
                    $more = array('load_user' => 1);
                    $recent[] = dots_get_dot($row['dot_id'], $viewer_id, $more);
                }
                if (count($recent) == $to_fetch) {
                    break;
                }
            }
        }
        if (count($recent) == $to_fetch) {
            break;
        }
        $sheet_args['page']++;
        $iters++;
        if ($iters == $max_iters) {
            break;
        }
    }
    shuffle($recent);
    return $recent;
}
Example #5
0
function ppt_export_dots(&$dots, &$more)
{
    $maps = array();
    $w = 960;
    $h = 720;
    $ppt = new PHPPowerPoint();
    $ppt->getProperties()->setTitle($more['title']);
    $ppt->getProperties()->setCreator("Dotspotting");
    # set title here
    # $slide = $ppt->getActiveSlide();
    $ppt->removeSlideByIndex(0);
    # draw the maps
    $dot_per_slide = 1;
    $img_more = array('width' => $w, 'height' => $h, 'dot_size' => 20);
    if (!$dot_per_slide || count($dots) == 0) {
        $maps[] = maps_png_for_dots($dots, $img_more);
    } else {
        $img_more['dot_size'] = 25;
        $img_more['width'] = $img_more['height'];
        $img_more['img_prefix'] = 'ppt';
        # remember: 1 dot per slide
        $_dots = array();
        foreach ($dots as $dot) {
            $_dots[] = array($dot);
        }
        # See this? It's to prevent Dotspoting from accidentally
        # DOS-ing itself.
        $enable_multigets = $GLOBALS['cfg']['wscompose_enable_multigets'];
        if ($dot_per_slide && count($dots) > $GLOBALS['cfg']['wscompose_max_dots_for_multigets']) {
            $GLOBALS['cfg']['wscompose_enable_multigets'] = 0;
        }
        $maps = maps_png_for_dots_multi($_dots, $img_more);
        $GLOBALS['cfg']['wscompose_enable_multigets'] = $enable_multigets;
    }
    # now draw all the maps...
    $count_maps = count($maps);
    for ($i = 0; $i < $count_maps; $i++) {
        $map = $maps[$i];
        $slide = $ppt->createSlide();
        $shape = $slide->createDrawingShape();
        $shape->setName('map');
        $shape->setDescription('');
        $shape->setPath($map);
        $shape->setWidth($w);
        $shape->setHeight($h);
        $shape->setOffsetX(0);
        $shape->setOffsetY(0);
        if ($dot_per_slide) {
            $dot = $dots[$i];
            if (!$dot['id']) {
                continue;
            }
            $_dot = dots_get_dot($dot['id'], $more['viewer_id']);
            if (!$_dot['id']) {
                continue;
            }
            $shape = $slide->createDrawingShape();
            $shape->setName('map');
            $shape->setDescription('');
            $shape->setPath($map);
            $text = $slide->createRichTextShape();
            $text->setHeight($h);
            $text->setWidth($w - $h);
            $text->setOffsetX($h + 20);
            $text->setOffsetY(0 + 20);
            $align = $text->getAlignment();
            $align->setHorizontal(PHPPowerPoint_Style_Alignment::HORIZONTAL_LEFT);
            $cols = array_merge($_dot['index_on'], array('latitude', 'longitude', 'created', 'id'));
            foreach ($cols as $col) {
                $value = trim($dot[$col]);
                if (!$value) {
                    continue;
                }
                $body = $text->createTextRun("{$col}:\n");
                $body->getFont()->setSize(18);
                $body->getFont()->setBold(false);
                # default bold font is not what do say "pretty"
                $body = $text->createTextRun("{$dot[$col]}\n\n");
                $body->getFont()->setSize(14);
                $body->getFont()->setBold(false);
            }
        }
    }
    #
    $writer = PHPPowerPoint_IOFactory::createWriter($ppt, 'PowerPoint2007');
    $writer->save($more['path']);
    $writer = null;
    foreach ($maps as $path) {
        if ($path && !file_exists($path) && !unlink($path)) {
            error_log("[EXPORT] (ppt) failed to unlink {$path}");
        }
    }
    return $more['path'];
}
Example #6
0
function rss_export_dots(&$dots, &$more)
{
    $_dot = dots_get_dot($dots[0]['id']);
    $channel_data = array('title' => "Dots from sheet ID {$_dot['sheet']['id']}", 'link' => urls_url_for_sheet($_dot['sheet']), 'description' => "Dots from sheet ID {$_dot['sheet']['id']}", 'pubDate' => gmdate("c", time()), 'lastBuildDate' => gmdate("c", time()), 'generator' => 'Dotspotting');
    $ns_map = array('geo' => 'http://www.georss.org/georss', 'dotspotting' => 'x-urn:dotspotting#internal', 'sheet' => 'x-urn:dotspotting#sheet');
    $skip = array('latitude', 'longitude', 'altitude', 'title', 'description');
    $doc = new DomDocument('1.0', 'UTF-8');
    $rss = $doc->createElement('rss');
    $rss = $doc->appendChild($rss);
    foreach ($ns_map as $prefix => $uri) {
        $xmlns = $prefix ? "xmlns:{$prefix}" : "xmlns";
        $attr = $doc->createAttribute($xmlns);
        $uri = $doc->createTextNode($uri);
        $attr->appendChild($uri);
        $rss->appendChild($attr);
    }
    $channel = $doc->createElement('channel');
    $channel = $rss->appendChild($channel);
    foreach ($channel_data as $key => $value) {
        $text = $doc->createTextNode($value);
        $el = $doc->createElement($key);
        $el->appendChild($text);
        $channel->appendChild($el);
    }
    foreach ($dots as $dot) {
        $properties = array();
        $item = $doc->createElement('item');
        foreach ($dot as $key => $value) {
            if (in_array($key, $skip)) {
                continue;
            }
            $properties[] = implode("\t", array(htmlspecialchars($key), htmlspecialchars($value)));
            # maybe do OSM-style k= v= pairs? (20110114/straup)
            if (0) {
                if (!preg_match("/^dotspotting:/", $key)) {
                    $key = "sheet:{$key}";
                }
                $el = $doc->createElement($key);
                $text = $doc->createTextNode($value);
                $el->appendChild($text);
                $item->appendChild($el);
            }
        }
        $coords = array($dot['latitude'], $dot['longitude']);
        $_geo = $doc->createTextNode(implode(",", $coords));
        $geo = $doc->createElement('geo:point');
        $geo->appendChild($_geo);
        $_title = $doc->createTextNode("Dot #{$dot['id']}");
        if (isset($dot['title'])) {
            $_title = $doc->createTextNode($dot['title']);
        }
        $title = $doc->createElement('title');
        $title->appendChild($_title);
        $_dot = dots_get_dot($dot['id']);
        $_link = $doc->createTextNode(urls_url_for_dot($_dot));
        $link = $doc->createElement('link');
        $link->appendChild($_link);
        # see above inre: osm style tags
        $_description = $doc->createTextNode(implode("<br />", $properties));
        $description = $doc->createElement('description');
        $description->appendChild($_description);
        $item->appendChild($title);
        $item->appendChild($link);
        $item->appendChild($description);
        $item->appendChild($geo);
        $channel->appendChild($item);
    }
    $doc->save($more['path']);
    return $more['path'];
}