diff options
author | friendica <info@friendica.com> | 2013-01-26 02:24:07 -0800 |
---|---|---|
committer | friendica <info@friendica.com> | 2013-01-26 02:24:07 -0800 |
commit | 91126d8dd33bdfa86ab1013561833b0c3c224a14 (patch) | |
tree | 6f8b1a86dccd7f753015270156ddf2b89614f1ea | |
parent | 70aa8421b37a6ad7318172ef515bbb56e2d33917 (diff) | |
download | volse-hubzilla-91126d8dd33bdfa86ab1013561833b0c3c224a14.tar.gz volse-hubzilla-91126d8dd33bdfa86ab1013561833b0c3c224a14.tar.bz2 volse-hubzilla-91126d8dd33bdfa86ab1013561833b0c3c224a14.zip |
more photo backend stuff
-rw-r--r-- | include/Contact.php | 7 | ||||
-rw-r--r-- | include/photos.php | 29 | ||||
-rw-r--r-- | mod/photos.php | 46 | ||||
-rw-r--r-- | view/tpl/photo_albums.tpl | 13 | ||||
-rw-r--r-- | view/tpl/smarty3/photo_albums.tpl | 18 |
5 files changed, 74 insertions, 39 deletions
diff --git a/include/Contact.php b/include/Contact.php index be4bd9212..2ace23f01 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -19,6 +19,13 @@ function abook_self($channel_id) { return(($r) ? $r[0] : array()); } +function channelx_by_nick($nick) { + return q("SELECT * FROM channel left join xchan on channel_hash = xchan_hash WHERE channel_address = '%s' LIMIT 1", + dbesc($nick) + ); +} + + function vcard_from_xchan($xchan, $observer = null, $mode = '') { $connect = false; diff --git a/include/photos.php b/include/photos.php index 7ccfd31c6..6609a6fa8 100644 --- a/include/photos.php +++ b/include/photos.php @@ -230,7 +230,7 @@ function photo_upload($channel, $observer, $args) { function photos_albums_list($channel,$observer) { - $channel_id = $channel['channel_id']; + $channel_id = $channel['channel_id']; $observer_xchan = (($observer) ? $observer['xchan_hash'] : ''); if(! perm_is_allowed($channel_id,$observer_xchan,'view_photos')) @@ -244,7 +244,34 @@ function photos_albums_list($channel,$observer) { intval($channel_id) ); + // add various encodings to the array so we can just loop through and pick them out in a template + + if($albums) { + foreach($albums as $k => $album) { + $albums[$k]['urlencode'] = urlencode($album['album']); + $albums[$k]['bin2hex'] = bin2hex($album['album']); + } + } return $albums; } +function photos_album_widget($channelx,$observer,$albums = null) { + + $o = ''; + + if(! $albums) + $albums = photos_albums_list($channelx,$observer); + + if($albums) { + $o = replace_macros(get_markup_template('photo_albums.tpl'),array( + '$nick' => $channelx['channel_address'], + '$title' => t('Photo Albums'), + '$albums' => $albums, + '$baseurl' => z_root(), + '$upload' => ((perm_is_allowed($channelx['channel_id'],(($observer) ? $observer['xchan_hash'] : ''),'post_photos')) + ? t('Upload New Photos') : '') + )); + } + return $o; +}
\ No newline at end of file diff --git a/mod/photos.php b/mod/photos.php index 00985ab9b..68b1bcb6b 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -18,62 +18,32 @@ function photos_init(&$a) { if(argc() > 1) { $nick = argv(1); - $r = q("SELECT * FROM channel left join xchan on channel_hash = xchan_hash WHERE channel_address = '%s' LIMIT 1", - dbesc($nick) - ); + $channelx = channelx_by_nick($nick); - if(! $r) + if(! $channelx) return; - $a->data['channel'] = $r[0]; + $a->data['channel'] = $channelx[0]; $observer = $a->get_observer(); $a->data['observer'] = $observer; $observer_xchan = (($observer) ? $observer['xchan_hash'] : ''); - $a->data['perms'] = get_all_perms($r[0]['channel_id'],$observer_xchan); - - $o .= vcard_from_xchan($a->data['channel'],$observer_xchan); - - $albums = photos_albums_list($a->data['channel'],$observer); + $a->data['perms'] = get_all_perms($channelx[0]['channel_id'],$observer_xchan); - if($albums) { - $a->data['albums'] = $albums; -// FIXME - $albums_visible = ((intval($a->data['user']['hidewall']) && (! local_user()) && (! remote_user())) ? false : true); + $a->set_widget('vcard',vcard_from_xchan($a->data['channel'],$observer)); - if($albums_visible) { - $o .= '<div id="side-bar-photos-albums" class="widget">'; - $o .= '<h3>' . '<a href="' . $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '">' . t('Photo Albums') . '</a></h3>'; - - $o .= '<ul>'; - foreach($albums as $album) { + if($a->data['perms']['view_photos']) { - // don't show contact photos. We once translated this name, but then you could still access it under - // a different language setting. Now we store the name in English and check in English (and translated for legacy albums). + $a->data['albums'] = photos_albums_list($a->data['channel'],$observer); - if((! strlen($album['album'])) || ($album['album'] === 'Contact Photos') || ($album['album'] === t('Contact Photos'))) - continue; - $o .= '<li>' . '<a href="photos/' . $a->argv[1] . '/album/' . bin2hex($album['album']) . '" >' . $album['album'] . '</a></li>'; - } - $o .= '</ul>'; - } - if(local_user() && $a->data['channel']['channel_id'] == local_user()) { - $o .= '<div id="photo-albums-upload-link"><a href="' . $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/upload" >' .t('Upload New Photos') . '</a></div>'; - } + $a->set_widget('photo_albums',photos_album_widget($a->data['channel'],$observer,$a->data['albums'])); - $o .= '</div>'; } - if(! x($a->page,'aside')) - $a->page['aside'] = ''; - $a->page['aside'] .= $o; - - $a->page['htmlhead'] .= "<script> var ispublic = '" . t('everybody') . "';</script>" ; - } return; diff --git a/view/tpl/photo_albums.tpl b/view/tpl/photo_albums.tpl new file mode 100644 index 000000000..eccc3660a --- /dev/null +++ b/view/tpl/photo_albums.tpl @@ -0,0 +1,13 @@ +<div id="side-bar-photos-albums" class="widget"> +<h3><a href="$baseurl/photos/$nick" title="$title" >$title</a></h3> +{{ if $albums }} +<ul> +{{ for $albums as $al }} +<li><a href="$baseurl/photos/$nick/$al.bin2hex">$al.album</a></li> +{{ endfor }} +</ul> +{{ endif }} +{{ if $upload }} +<div id="photo-albums-upload-link"><a href="$baseurl/photos/$nick/upload" title="$upload">$upload</a></div> +{{ endif }} +</div> diff --git a/view/tpl/smarty3/photo_albums.tpl b/view/tpl/smarty3/photo_albums.tpl new file mode 100644 index 000000000..8a31e030c --- /dev/null +++ b/view/tpl/smarty3/photo_albums.tpl @@ -0,0 +1,18 @@ +{{* + * AUTOMATICALLY GENERATED TEMPLATE + * DO NOT EDIT THIS FILE, CHANGES WILL BE OVERWRITTEN + * + *}} +<div id="side-bar-photos-albums" class="widget"> +<h3><a href="{{$baseurl}}/photos/{{$nick}}" title="{{$title}}" >{{$title}}</a></h3> +{{if $albums}} +<ul> +{{foreach $albums as $al}} +<li><a href="{{$baseurl}}/photos/{{$nick}}/{{$al.bin2hex}}">{{$al.album}}</a></li> +{{/foreach}} +</ul> +{{/if}} +{{if $upload}} +<div id="photo-albums-upload-link"><a href="{{$baseurl}}/photos/{{$nick}}/upload" title="{{$upload}}">{{$upload}}</a></div> +{{/if}} +</div> |