From 91126d8dd33bdfa86ab1013561833b0c3c224a14 Mon Sep 17 00:00:00 2001 From: friendica Date: Sat, 26 Jan 2013 02:24:07 -0800 Subject: more photo backend stuff --- include/Contact.php | 7 ++++++ include/photos.php | 29 +++++++++++++++++++++++- mod/photos.php | 46 +++++++-------------------------------- view/tpl/photo_albums.tpl | 13 +++++++++++ view/tpl/smarty3/photo_albums.tpl | 18 +++++++++++++++ 5 files changed, 74 insertions(+), 39 deletions(-) create mode 100644 view/tpl/photo_albums.tpl create mode 100644 view/tpl/smarty3/photo_albums.tpl 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 .= ''; } - if(! x($a->page,'aside')) - $a->page['aside'] = ''; - $a->page['aside'] .= $o; - - $a->page['htmlhead'] .= "" ; - } 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 @@ + 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 + * + *}} + -- cgit v1.2.3