Permalink
Browse files

Merge pull request #21 from mncaudill/photostream-context

Photostream context
  • Loading branch information...
2 parents 43bf6af + 8cb4b71 commit eddc559c08e0a60841e0231c5444dd462777ea06 Aaron Straup Cope committed May 22, 2012
Showing with 55 additions and 6 deletions.
  1. +1 −0 www/.htaccess
  2. +5 −0 www/flickr_photos_user.php
  3. +11 −6 www/include/lib_db.php
  4. +38 −0 www/include/lib_flickr_photos.php
View
@@ -96,6 +96,7 @@ RewriteRule ^photos/friends/faves(/page([0-9]+))?/?$ flickr_photos_friends_fav
RewriteRule ^photos/(([0-9a-zA-Z-_]+)|([0-9]+@N[0-9]+))/activity/?$ flickr_photos_user_recent_activity.php?path=$2&nsid=$3&%{QUERY_STRING} [L]
RewriteRule ^photos/(([0-9a-zA-Z-_]+)|([0-9]+@N[0-9]+))(/page([0-9]+))?/?$ flickr_photos_user.php?path=$2&nsid=$3&page=$5&%{QUERY_STRING} [L]
+RewriteRule ^photos/(([0-9a-zA-Z-_]+)|([0-9]+@N[0-9]+))/with/([0-9]+)/?$ flickr_photos_user.php?path=$2&nsid=$3&with=$4&%{QUERY_STRING} [L]
RewriteRule ^buddyicon/([0-9]+@N[0-9]+).jpg$ flickr_buddyicon.php?nsid=$1 [L]
@@ -27,6 +27,11 @@
'viewer_id' => $GLOBALS['cfg']['user']['id'],
);
+ $with = get_int64('with');
+ if ($with) {
+ $more['with'] = $with;
+ }
+
$rsp = flickr_photos_for_user($owner, $more);
$photos = $rsp['rows'];
@@ -363,17 +363,22 @@ function _db_fetch_paginated($sql, $args, $cluster, $k=null){
#
# build sql
#
-
- $sql .= " LIMIT $start, $limit";
-
- $ret = _db_fetch($sql, $cluster, $k);
-
- $ret['pagination'] = array(
+ $pagination = array(
'total_count' => (int)$total_count,
'page' => $page,
'per_page' => $per_page,
'page_count' => $page_count,
);
+
+ if (isset($args['just_pagination'])) {
+ return $pagination;
+ }
+
+ $sql .= " LIMIT $start, $limit";
+
+ $ret = _db_fetch($sql, $cluster, $k);
+
+ $ret['pagination'] = $pagination;
if ($GLOBALS['cfg']['pagination_assign_smarty_variable']) {
$GLOBALS['smarty']->assign('pagination', $ret['pagination']);
@@ -198,6 +198,44 @@ function flickr_photos_for_user(&$user, $more=array()){
}
$sql = "SELECT * FROM FlickrPhotos WHERE user_id='{$enc_user}' {$extra} ORDER BY dateupload DESC";
+
+ if (isset($more['with'])) {
+ # Here, we are asking for a the page which a particular photo occurs in a person's stream, which
+ # means we'll be passing in the determining the page number ourselves. We do this by figuring out
+ # how many photos are before this one in the stream and then dividing.
+
+ $photo = flickr_photos_get_by_id($more['with']);
+ $can_see_photo = $photo ? flickr_photos_permissions_can_view_photo($photo, $GLOBALS['cfg']['user']['id']) : false;
+
+ if ($can_see_photo) {
+
+ # The only reason we need this is for spill messing with per-page amounts
+ $pagination_more = $more;
+ $pagination_more['just_pagination'] = 1;
+
+ $pagination = db_fetch_paginated_users($cluster_id, $sql, $pagination_more);
+
+ $offset_where = " AND dateupload >= '{$photo['dateupload']}'";
+
+ $offset_sql = "SELECT COUNT(*) FROM FlickrPhotos WHERE user_id='{$enc_user}' {$extra} {$offset_where} ORDER BY dateupload DESC";
+
+ $ret = db_fetch_users($cluster_id, $offset_sql);
+ if($ret['ok']) {
+ $offset_count = intval(array_pop($ret['rows'][0]));
+
+ $per_page = isset($more['per_page']) ? max(1, $more['per_page']) : $GLOBALS['cfg']['pagination_per_page'];
+
+ $page = ceil($offset_count / $per_page);
+
+ if ($page > $pagination['page_count']){
+ $page--;
+ }
+
+ $more['page'] = $page;
+ }
+ }
+ }
+
return db_fetch_paginated_users($cluster_id, $sql, $more);
}

0 comments on commit eddc559

Please sign in to comment.