Skip to content

Commit

Permalink
Added meaningful titles to atlas and snapshot collections pages
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Migurski committed Mar 22, 2012
1 parent 00f2854 commit 351f96b
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 0 deletions.
66 changes: 66 additions & 0 deletions site/lib/data.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,38 @@ function get_pagination($input)
return array(max(0, $count), max(0, $offset), max(0, $perpage), max(1, $page));
}

function get_args_title(&$dbh, $args)
{
$parts = array();

if(isset($args['date']) && $time = strtotime($args['date']))
{
$date = date('M jS, Y', $time);
$parts[] = "on $date";
}

if(isset($args['month']) && $time = strtotime("{$args['month']}-01"))
{
$month = date('F Y', $time);
$parts[] = "during $month";
}

if(isset($args['place']))
{
$place_info = woeid_placeinfo($args['place']);
$place_name = nice_placename($place_info[4]);
$parts[] = "in $place_name";
}

if(isset($args['user']) && $user = get_user($dbh, $args['user']))
{
$user_name = empty($user['name']) ? 'someone' : $user['name'];
$parts[] = "by $user_name";
}

return join(' ', $parts);
}

if(!function_exists('json_encode'))
{
function json_encode($value)
Expand Down Expand Up @@ -651,6 +683,40 @@ function placename_latlon($name)
return null;
}

function woeid_placeinfo($woeid)
{
$req = new HTTP_Request('http://api.flickr.com/services/rest/');
$req->addQueryString('method', 'flickr.places.getInfo');
$req->addQueryString('woe_id', $woeid);
$req->addQueryString('format', 'php_serial');
$req->addQueryString('api_key', FLICKR_KEY);

$res = $req->sendRequest();

if(PEAR::isError($res))
return array(null, null, null, null, null, null);

$rsp = unserialize($req->getResponseBody());

if(is_array($rsp) && is_array($rsp['place']))
{
$place_type = $rsp['place']['place_type'];
$place = $rsp['place'][$place_type];

list($place_name, $place_woeid) = array($place['_content'], $place['woeid']);

list($country, $region) = array($rsp['place']['country'], $rsp['place']['region']);

if(is_array($country))
list($country_name, $country_woeid) = array($country['_content'], $country['woeid']);

if(is_array($region))
list($region_name, $region_woeid) = array($region['_content'], $region['woeid']);
}

return array($country_name, $country_woeid, $region_name, $region_woeid, $place_name, $place_woeid);
}

function latlon_placeinfo($lat, $lon, $zoom)
{
$req = new HTTP_Request('http://api.flickr.com/services/rest/');
Expand Down
1 change: 1 addition & 0 deletions site/templates/atlases.html.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<body>
{include file="navigation.htmlf.tpl"}
<div class="container">
<h1>Atlases {$title|escape}</h1>
<h2>Atlases | <a href="{$base_dir}/uploads.php">Uploads</a></h2>

{foreach from=$prints item="print" name="index"}
Expand Down
1 change: 1 addition & 0 deletions site/templates/uploads.html.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<body>
{include file="navigation.htmlf.tpl"}
<div class="container">
<h1>Snapshots {$title|escape}</h1>
<h2><a href="{$base_dir}/atlases.php">Atlases</a> | Uploads</h2>

{foreach from=$scans item="scan" name="index"}
Expand Down
2 changes: 2 additions & 0 deletions site/www/atlases.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
'user' => preg_match('/^\w+$/', $_GET['user']) ? $_GET['user'] : null
);

$title = get_args_title($context->db, $print_args);
$prints = get_prints($context->db, $print_args, 50);
$users = array();

Expand All @@ -31,6 +32,7 @@
$prints[$i]['user'] = $users[$user_id];
}

$context->sm->assign('title', $title);
$context->sm->assign('prints', $prints);

if($context->type == 'text/html') {
Expand Down
2 changes: 2 additions & 0 deletions site/www/uploads.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
'user' => preg_match('/^\w+$/', $_GET['user']) ? $_GET['user'] : null
);

$title = get_args_title($context->db, $scan_args);
$scans = get_scans($context->db, $scan_args, 50);
$users = array();

Expand All @@ -28,6 +29,7 @@
$scans[$i]['user'] = $users[$user_id];
}

$context->sm->assign('title', $title);
$context->sm->assign('scans', $scans);

if($context->type == 'text/html') {
Expand Down

0 comments on commit 351f96b

Please sign in to comment.