'recent photos' query was buggered, also fix issue #163 by adding configurable sort order to the album widget - default is album name ascending

This commit is contained in:
redmatrix 2016-06-07 16:23:14 -07:00
parent 037cd74e8e
commit a50e555515
3 changed files with 21 additions and 25 deletions

View File

@ -510,7 +510,7 @@ class Photos extends \Zotlabs\Web\Controller {
function get() {
function get() {
// URLs:
// photos/name
@ -1277,11 +1277,9 @@ class Photos extends \Zotlabs\Web\Controller {
\App::$page['htmlhead'] .= "\r\n" . '<link rel="alternate" type="application/json+oembed" href="' . z_root() . '/oep?f=&url=' . urlencode(z_root() . '/' . \App::$cmd) . '" title="oembed" />' . "\r\n";
$r = q("SELECT `resource_id`, max(`imgscale`) AS `imgscale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
$r = q("SELECT `resource_id`, max(`imgscale`) AS `imgscale` FROM `photo` WHERE `uid` = %d
and photo_usage in ( %d, %d ) and is_nsfw = %d $sql_extra GROUP BY `resource_id`",
intval(\App::$data['channel']['channel_id']),
dbesc('Contact Photos'),
dbesc( t('Contact Photos')),
intval(PHOTO_NORMAL),
intval(PHOTO_PROFILE),
intval($unsafe)
@ -1291,15 +1289,13 @@ class Photos extends \Zotlabs\Web\Controller {
\App::set_pager_itemspage(60);
}
$r = q("SELECT p.resource_id, p.id, p.filename, p.mimetype, p.album, p.imgscale, p.created FROM photo as p
INNER JOIN ( SELECT resource_id, max(imgscale) as imgscale FROM photo
$r = q("SELECT p.resource_id, p.id, p.filename, p.mimetype, p.album, p.imgscale, p.created FROM photo p
INNER JOIN ( SELECT resource_id, max(imgscale) imgscale FROM photo
WHERE uid = %d AND photo_usage IN ( %d, %d )
AND is_nsfw = %d $sql_extra group by resource_id ) as ph
AND is_nsfw = %d $sql_extra group by resource_id ) ph
ON (p.resource_id = ph.resource_id and p.imgscale = ph.imgscale)
ORDER by p.created DESC LIMIT %d OFFSET %d",
intval(\App::$data['channel']['channel_id']),
dbesc('Contact Photos'),
dbesc( t('Contact Photos')),
intval(PHOTO_NORMAL),
intval(PHOTO_PROFILE),
intval($unsafe),

View File

@ -443,7 +443,7 @@ function photo_upload($channel, $observer, $args) {
* * success (bool)
* * albums (array)
*/
function photos_albums_list($channel, $observer) {
function photos_albums_list($channel, $observer, $sort_key = 'album', $direction = 'asc') {
$channel_id = $channel['channel_id'];
$observer_xchan = (($observer) ? $observer['xchan_hash'] : '');
@ -451,11 +451,15 @@ function photos_albums_list($channel, $observer) {
if(! perm_is_allowed($channel_id, $observer_xchan, 'view_storage'))
return false;
/** @FIXME create a permissions SQL which works on arbitrary observers and channels, regardless of login or web status */
$sql_extra = permissions_sql($channel_id);
$sql_extra = permissions_sql($channel_id,$observer_xchan);
$albums = q("SELECT count( distinct resource_id ) as total, album from photo where uid = %d and photo_usage IN ( %d, %d ) $sql_extra group by album order by max(created) desc",
$sort_key = dbesc($sort_key);
$direction = dbesc($direction);
$albums = q("SELECT count( distinct resource_id ) as total, album from photo where uid = %d and photo_usage IN ( %d, %d ) $sql_extra group by album order by $sort_key $direction",
intval($channel_id),
intval(PHOTO_NORMAL),
intval(PHOTO_PROFILE)
@ -483,20 +487,14 @@ function photos_albums_list($channel, $observer) {
return $ret;
}
function photos_album_widget($channelx,$observer,$albums = null) {
function photos_album_widget($channelx,$observer,$sortkey = 'album',$direction = 'asc') {
$o = '';
// If we weren't passed an album list, see if the photos module
// dropped one for us to find in App::$data['albums'].
// If all else fails, load it.
if(! $albums) {
if(array_key_exists('albums', App::$data))
$albums = App::$data['albums'];
else
$albums = photos_albums_list($channelx,$observer);
}
if(array_key_exists('albums', App::$data))
$albums = App::$data['albums'];
else
$albums = photos_albums_list($channelx,$observer,$sortkey,$direction);
if($albums['success']) {
$o = replace_macros(get_markup_template('photo_albums.tpl'),array(

View File

@ -799,8 +799,10 @@ function widget_photo_albums($arr) {
if((! $channelx) || (! perm_is_allowed(App::$profile['profile_uid'], get_observer_hash(), 'view_storage')))
return '';
require_once('include/photos.php');
$sortkey = ((array_key_exists('sortkey',$arr)) ? $arr['sortkey'] : 'album');
$direction = ((array_key_exists('direction',$arr)) ? $arr['direction'] : 'asc');
return photos_album_widget($channelx, App::get_observer());
return photos_album_widget($channelx, App::get_observer(),$sortkey,$direction);
}