aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorzotlabs <mike@macgirvin.com>2017-03-21 20:11:48 -0700
committerzotlabs <mike@macgirvin.com>2017-03-21 20:11:48 -0700
commitbedc39342514a37d311274210f30a4abd14284fa (patch)
tree09bdc14e4126ceff42ff2eb91638742cd482f4d1 /include
parentc1cc7bfc945e4da4150c9ed99dc11981767b4ccb (diff)
downloadvolse-hubzilla-bedc39342514a37d311274210f30a4abd14284fa.tar.gz
volse-hubzilla-bedc39342514a37d311274210f30a4abd14284fa.tar.bz2
volse-hubzilla-bedc39342514a37d311274210f30a4abd14284fa.zip
begin the process of using the relevant attach directory/path for photo albums instead of an album basename which may not be unique. Created an 'ellipsify()' function to shorten long names and keep the beginning and end intact
Diffstat (limited to 'include')
-rw-r--r--include/photos.php48
-rw-r--r--include/text.php11
2 files changed, 45 insertions, 14 deletions
diff --git a/include/photos.php b/include/photos.php
index b4d297bfd..e68290c9d 100644
--- a/include/photos.php
+++ b/include/photos.php
@@ -443,7 +443,7 @@ function photo_upload($channel, $observer, $args) {
* * \e array \b albums
*/
-function photos_albums_list($channel, $observer, $sort_key = 'album', $direction = 'asc') {
+function photos_albums_list($channel, $observer, $sort_key = 'display_path', $direction = 'asc') {
$channel_id = $channel['channel_id'];
$observer_xchan = (($observer) ? $observer['xchan_hash'] : '');
@@ -456,16 +456,31 @@ function photos_albums_list($channel, $observer, $sort_key = 'album', $direction
$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)
- //);
-
- // this query provides the same results but might perform better
- $albums = q("SELECT count( distinct resource_id ) as total, album from photo where uid = %d and os_storage = 1 $sql_extra group by album order by $sort_key $direction",
+ $r = q("select display_path, hash from attach where is_dir = 1 and uid = %d order by $sort_key $direction",
intval($channel_id)
);
+ array_unshift($r,[ 'display_path' => '/', 'hash' => '' ]);
+ $str = ids_to_querystr($r,'hash',true);
+
+ $albums = [];
+
+ if($str) {
+ $x = q("select count( distinct hash ) as total, folder from attach where is_photo = 1 and uid = %d and folder in ( $str ) group by folder ",
+ intval($channel_id)
+ );
+ if($x) {
+ foreach($r as $rv) {
+ foreach($x as $xv) {
+ if($xv['folder'] === $rv['hash']) {
+ if($xv['total'] != 0) {
+ $albums[] = [ 'album' => $rv['display_path'], 'folder' => $xv['folder'], 'total' => $xv['total'] ];
+ }
+ continue;
+ }
+ }
+ }
+ }
+ }
// add various encodings to the array so we can just loop through and pick them out in a template
@@ -477,11 +492,12 @@ function photos_albums_list($channel, $observer, $sort_key = 'album', $direction
foreach($albums as $k => $album) {
$entry = array(
'text' => (($album['album']) ? $album['album'] : '/'),
+ 'shorttext' => (($album['album']) ? ellipsify($album['album'],28) : '/'),
'jstext' => (($album['album']) ? addslashes($album['album']) : '/'),
'total' => $album['total'],
- 'url' => z_root() . '/photos/' . $channel['channel_address'] . '/album/' . bin2hex($album['album']),
+ 'url' => z_root() . '/photos/' . $channel['channel_address'] . '/album/' . $album['folder'],
'urlencode' => urlencode($album['album']),
- 'bin2hex' => bin2hex($album['album'])
+ 'bin2hex' => $album['folder']
);
$ret['albums'][] = $entry;
}
@@ -492,7 +508,7 @@ function photos_albums_list($channel, $observer, $sort_key = 'album', $direction
return $ret;
}
-function photos_album_widget($channelx,$observer,$sortkey = 'album',$direction = 'asc') {
+function photos_album_widget($channelx,$observer,$sortkey = 'display_path',$direction = 'asc') {
$o = '';
@@ -505,6 +521,7 @@ function photos_album_widget($channelx,$observer,$sortkey = 'album',$direction =
$o = replace_macros(get_markup_template('photo_albums.tpl'),array(
'$nick' => $channelx['channel_address'],
'$title' => t('Photo Albums'),
+ '$recent' => t('Recent Photos'),
'$albums' => $albums['albums'],
'$baseurl' => z_root(),
'$upload' => ((perm_is_allowed($channelx['channel_id'],(($observer) ? $observer['xchan_hash'] : ''),'write_storage'))
@@ -565,12 +582,15 @@ function photos_list_photos($channel, $observer, $album = '') {
*/
function photos_album_exists($channel_id, $album) {
- $r = q("SELECT id FROM photo WHERE album = '%s' AND uid = %d limit 1",
+
+ $sql_extra = permissions_sql($channel_id);
+
+ $r = q("SELECT folder, hash, is_dir, filename, os_path, display_path FROM attach WHERE hash = '%s' AND is_dir = 1 AND uid = %d $sql_extra limit 1",
dbesc($album),
intval($channel_id)
);
- return (($r) ? true : false);
+ return (($r) ? $r[0] : false);
}
/**
diff --git a/include/text.php b/include/text.php
index 500c87ad5..49b588f13 100644
--- a/include/text.php
+++ b/include/text.php
@@ -3113,3 +3113,14 @@ function array_escape_tags(&$v,$k) {
$v = escape_tags($v);
}
+function ellipsify($s,$maxlen) {
+ if($maxlen & 1)
+ $maxlen --;
+ if($maxlen < 4)
+ $maxlen = 4;
+
+ if(mb_strlen($s) < $maxlen)
+ return $s;
+
+ return mb_substr($s,0,$maxlen / 2) . '...' . mb_substr($s,mb_strlen($s) - ($maxlen / 2));
+} \ No newline at end of file