more photo backend stuff

This commit is contained in:
friendica 2013-01-26 02:24:07 -08:00
parent 70aa8421b3
commit 91126d8dd3
5 changed files with 74 additions and 39 deletions

View File

@ -19,6 +19,13 @@ function abook_self($channel_id) {
return(($r) ? $r[0] : array()); 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 = '') { function vcard_from_xchan($xchan, $observer = null, $mode = '') {
$connect = false; $connect = false;

View File

@ -230,7 +230,7 @@ function photo_upload($channel, $observer, $args) {
function photos_albums_list($channel,$observer) { function photos_albums_list($channel,$observer) {
$channel_id = $channel['channel_id']; $channel_id = $channel['channel_id'];
$observer_xchan = (($observer) ? $observer['xchan_hash'] : ''); $observer_xchan = (($observer) ? $observer['xchan_hash'] : '');
if(! perm_is_allowed($channel_id,$observer_xchan,'view_photos')) if(! perm_is_allowed($channel_id,$observer_xchan,'view_photos'))
@ -244,7 +244,34 @@ function photos_albums_list($channel,$observer) {
intval($channel_id) 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; 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;
}

View File

@ -18,62 +18,32 @@ function photos_init(&$a) {
if(argc() > 1) { if(argc() > 1) {
$nick = argv(1); $nick = argv(1);
$r = q("SELECT * FROM channel left join xchan on channel_hash = xchan_hash WHERE channel_address = '%s' LIMIT 1", $channelx = channelx_by_nick($nick);
dbesc($nick)
);
if(! $r) if(! $channelx)
return; return;
$a->data['channel'] = $r[0]; $a->data['channel'] = $channelx[0];
$observer = $a->get_observer(); $observer = $a->get_observer();
$a->data['observer'] = $observer; $a->data['observer'] = $observer;
$observer_xchan = (($observer) ? $observer['xchan_hash'] : ''); $observer_xchan = (($observer) ? $observer['xchan_hash'] : '');
$a->data['perms'] = get_all_perms($r[0]['channel_id'],$observer_xchan); $a->data['perms'] = get_all_perms($channelx[0]['channel_id'],$observer_xchan);
$o .= vcard_from_xchan($a->data['channel'],$observer_xchan); $a->set_widget('vcard',vcard_from_xchan($a->data['channel'],$observer));
$albums = photos_albums_list($a->data['channel'],$observer); if($a->data['perms']['view_photos']) {
if($albums) { $a->data['albums'] = photos_albums_list($a->data['channel'],$observer);
$a->data['albums'] = $albums;
// FIXME
$albums_visible = ((intval($a->data['user']['hidewall']) && (! local_user()) && (! remote_user())) ? false : true);
if($albums_visible) { $a->set_widget('photo_albums',photos_album_widget($a->data['channel'],$observer,$a->data['albums']));
$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) {
// 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).
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>';
}
$o .= '</div>';
} }
if(! x($a->page,'aside'))
$a->page['aside'] = '';
$a->page['aside'] .= $o;
$a->page['htmlhead'] .= "<script> var ispublic = '" . t('everybody') . "';</script>" ; $a->page['htmlhead'] .= "<script> var ispublic = '" . t('everybody') . "';</script>" ;
} }
return; return;

13
view/tpl/photo_albums.tpl Normal file
View File

@ -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>

View File

@ -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>