Skip to content

Commit

Permalink
make camera finder work properly for makes/models with spaces; update…
Browse files Browse the repository at this point in the history
… everything else accordingly
  • Loading branch information
thisisaaronland committed Nov 24, 2011
1 parent c0e5ba3 commit 103a7c1
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 14 deletions.
7 changes: 4 additions & 3 deletions www/.htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,10 @@ RewriteRule ^photos/(([0-9a-zA-Z-_]+)|([0-9]+@N[0-9]+))/places/(\d+)(/page([0-9]

RewriteRule ^photos/(([0-9a-zA-Z-_]+)|([0-9]+@N[0-9]+))/cameras/?$ /flickr_photos_user_cameras.php?path=$2&nsid=$3&%{QUERY_STRING} [L]

# TO DO: make this better (whitespace, etc.)
RewriteRule ^photos/(([0-9a-zA-Z-_]+)|([0-9]+@N[0-9]+))/cameras/([0-9a-zA-z-_]+)(/page([0-9]+))?/?$ /flickr_photos_user_camera.php?path=$2&nsid=$3&make=$4&page=$6&%{QUERY_STRING} [L]
RewriteRule ^photos/(([0-9a-zA-Z-_]+)|([0-9]+@N[0-9]+))/cameras/([0-9a-zA-z-_]+)(/([^/]+))?(/page([0-9]+))?/?$ /flickr_photos_user_camera.php?path=$2&nsid=$3&make=$4&model=$6&page=$8&%{QUERY_STRING} [L]
RewriteRule ^photos/(([0-9a-zA-Z-_]+)|([0-9]+@N[0-9]+))/cameras/([0-9a-zA-z-_\s\+]+)(/page([0-9]+))?/?$ /flickr_photos_user_camera.php?path=$2&nsid=$3&make=$4&page=$6&%{QUERY_STRING} [L]

RewriteRule ^photos/(([0-9a-zA-Z-_]+)|([0-9]+@N[0-9]+))/cameras/([0-9a-zA-z-_\s\+]+)/([0-9a-zA-z-_\s\+]+)(/page([0-9]+))?/?$ /flickr_photos_user_camera.php?path=$2&nsid=$3&make=$4&model=$5&page=$7&%{QUERY_STRING} [L]


# timecapsule
# TO DO: finish
Expand Down
7 changes: 7 additions & 0 deletions www/include/lib_exif_tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

#################################################################

function exif_tools_scrub_string($str){

return sanitize(trim($str), 'str');
}

#################################################################

function exif_tools_rational2float($value){

$parts = explode('/', $value);
Expand Down
2 changes: 1 addition & 1 deletion www/include/lib_flickr_photos_exif.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function flickr_photos_exif_read(&$photo){

foreach ($to_simplejoin as $tag){

if (isset($exif[$tag])){
if (is_array($exif[$tag])){
$exif[$tag] = implode(",", $exif[$tag]);
}
}
Expand Down
20 changes: 14 additions & 6 deletions www/include/lib_flickr_photos_search.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ function flickr_photos_search(&$query, $more=array()){
foreach ($rsp['rows'] as $row){
$photo = flickr_photos_get_by_id($row['photo_id']);

$photo['can_view_geo'] = ($photo['hasgeo'] && flickr_geo_permissions_can_view_photo($photo, $more['viewer_id'])) ? 1 : 0;
$can_view_geo = ($photo['hasgeo'] && flickr_geo_permissions_can_view_photo($photo, $more['viewer_id'])) ? 1 : 0;

$photo['can_view_geo'] = $can_view_geo;
$photos[] = $photo;
}

Expand Down Expand Up @@ -189,14 +191,20 @@ function flickr_photos_search_index_photo(&$photo){

$exif = $rsp['rows'];

# TO DO: normalize (and probably sanitize)
if (isset($exif['Make'])){

if (isset($exif['Model'])){
$doc['camera_model'] = trim($exif['Model']);
if ($make = exif_tools_scrub_string($exif['Make'])){

$doc['camera_make'] = ucwords($make);
}
}

if (isset($exif['Make'])){
$doc['camera_make'] = trim($exif['Make']);
if (isset($exif['Model'])){

if ($model = exif_tools_scrub_string($exif['Model'])){

$doc['camera_model'] = $model;
}
}

# EXIF: what else?
Expand Down
16 changes: 13 additions & 3 deletions www/include/lib_solr_utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ function solr_utils_hash2query(&$hash, $join=null){

$k = urlencode($k);

# allow foo:[* TO *] queries

$v = (preg_match("/^raw:(.*)$/", $v, $m)) ? $m[1] : urlencode($v);
$v = (preg_match("/^raw:(.*)$/", $v, $m)) ? $m[1] : solr_utils_escape($v);

$q[] = "{$k}:{$v}";
}
Expand All @@ -25,4 +23,16 @@ function solr_utils_hash2query(&$hash, $join=null){
}

#################################################################

# http://e-mats.org/2010/01/escaping-characters-in-a-solr-query-solr-url/

function solr_utils_escape($string){

$match = array('\\', '+', '-', '&', '|', '!', '(', ')', '{', '}', '[', ']', '^', '~', '*', '?', ':', '"', ';', ' ');
$replace = array('\\\\', '\\+', '\\-', '\\&', '\\|', '\\!', '\\(', '\\)', '\\{', '\\}', '\\[', '\\]', '\\^', '\\~', '\\*', '\\?', '\\:', '\\"', '\\;', '\\ ');
$string = str_replace($match, $replace, $string);
return $string;
}

#################################################################
?>
1 change: 1 addition & 0 deletions www/templates/inc_flickr_photo_map.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{if $cfg.enable_feature_slippymaps}

{if $photo.hasgeo and $photo.can_view_geo}

<div class="photo_map">
<div class="map" data-provider="{$cfg.slippymap_provider|escape}" data-center="{$photo.latitude|escape},{$photo.longitude|escape}" data-zoom="{$photo.accuracy-2|escape}" data-interactive="false" id="map_{$photo.id|escape}">
<div class="marker" data-location="{$photo.latitude|escape},{$photo.longitude|escape}"><span class="marker_text">{$photo.latitude|string_format:"%.3f"|escape},{$photo.longitude|string_format:"%.3f"|escape}</span></div>
Expand Down
2 changes: 1 addition & 1 deletion www/templates/page_flickr_photos_user_camera.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ You've taken one photo with a {$camera_make|escape}{if $camera_model} {$camera_m
</div>

<div class="photo_sidebar" style="margin-top:0px;">
{include file="inc_flickr_photo_map.txt"}
{include file="inc_flickr_photo_map.txt" photo=$row}
</div>

<br clear="all" />
Expand Down

0 comments on commit 103a7c1

Please sign in to comment.