more work on the photo album mess

This commit is contained in:
zotlabs 2017-03-21 22:05:36 -07:00 committed by Mario Vavti
parent 032b6f193d
commit 9d0e2cbd89
2 changed files with 71 additions and 97 deletions

View File

@ -15,13 +15,10 @@ class Photos extends \Zotlabs\Web\Controller {
function init() { function init() {
if(observer_prohibited()) { if(observer_prohibited()) {
return; return;
} }
$o = '';
if(argc() > 1) { if(argc() > 1) {
$nick = argv(1); $nick = argv(1);
@ -54,7 +51,6 @@ class Photos extends \Zotlabs\Web\Controller {
logger('mod-photos: photos_post: begin' , LOGGER_DEBUG); logger('mod-photos: photos_post: begin' , LOGGER_DEBUG);
logger('mod_photos: REQUEST ' . print_r($_REQUEST,true), LOGGER_DATA); logger('mod_photos: REQUEST ' . print_r($_REQUEST,true), LOGGER_DATA);
logger('mod_photos: FILES ' . print_r($_FILES,true), LOGGER_DATA); logger('mod_photos: FILES ' . print_r($_FILES,true), LOGGER_DATA);
@ -94,7 +90,6 @@ class Photos extends \Zotlabs\Web\Controller {
$album = argv(3); $album = argv(3);
if(! photos_album_exists($page_owner_uid, get_observer_hash(), $album)) { if(! photos_album_exists($page_owner_uid, get_observer_hash(), $album)) {
notice( t('Album not found.') . EOL); notice( t('Album not found.') . EOL);
goaway(z_root() . '/' . $_SESSION['photo_return']); goaway(z_root() . '/' . $_SESSION['photo_return']);
@ -117,7 +112,7 @@ class Photos extends \Zotlabs\Web\Controller {
$folder_hash = ''; $folder_hash = '';
$r = q("select * from attach where is_dir = 1 and uid = %d and filename = '%s'", $r = q("select * from attach where is_dir = 1 and uid = %d and hash = '%s'",
intval($page_owner_uid), intval($page_owner_uid),
dbesc($album) dbesc($album)
); );
@ -125,14 +120,7 @@ class Photos extends \Zotlabs\Web\Controller {
notice( t('Album not found.') . EOL); notice( t('Album not found.') . EOL);
return; return;
} }
if(count($r) > 1) {
notice( t('Multiple storage folders exist with this album name, but within different directories. Please remove the desired folder or folders using the Files manager') . EOL);
return;
}
else {
$folder_hash = $r[0]['hash']; $folder_hash = $r[0]['hash'];
}
$res = array(); $res = array();
@ -481,12 +469,10 @@ class Photos extends \Zotlabs\Web\Controller {
if(! $r['success']) { if(! $r['success']) {
notice($r['message'] . EOL); notice($r['message'] . EOL);
goaway(z_root() . '/photos/' . \App::$data['channel']['channel_address']);
} }
if($_REQUEST['newalbum']) goaway(z_root() . '/photos/' . \App::$data['channel']['channel_address'] . '/album/' . $r['data']['folder']);
goaway(z_root() . '/photos/' . \App::$data['channel']['channel_address'] . '/album/' . bin2hex($_REQUEST['newalbum']));
else
goaway(z_root() . '/photos/' . \App::$data['channel']['channel_address'] . '/album/' . bin2hex(datetime_convert('UTC',date_default_timezone_get(),'now', 'Y')));
} }
@ -565,7 +551,9 @@ class Photos extends \Zotlabs\Web\Controller {
return; return;
} }
$sql_extra = permissions_sql($owner_uid); $sql_item = item_permissions_sql($owner_uid,get_observer_hash());
$sql_extra = permissions_sql($owner_uid,get_observer_hash(),'photo');
$sql_attach = permissions_sql($owner_uid,get_observer_hash(),'attach');
$o = ""; $o = "";
@ -676,9 +664,6 @@ class Photos extends \Zotlabs\Web\Controller {
if($datatype === 'album') { if($datatype === 'album') {
$album = $datum;
\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"; \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";
if($x = photos_album_exists($owner_uid, get_observer_hash(), $datum)) { if($x = photos_album_exists($owner_uid, get_observer_hash(), $datum)) {
@ -788,10 +773,10 @@ class Photos extends \Zotlabs\Web\Controller {
$o .= replace_macros($tpl, array( $o .= replace_macros($tpl, array(
'$photos' => $photos, '$photos' => $photos,
'$album' => $album, '$album' => $album,
'$album_id' => bin2hex($album), '$album_id' => $datum),
'$album_edit' => array(t('Edit Album'), $album_edit), '$album_edit' => array(t('Edit Album'), $album_edit),
'$can_post' => $can_post, '$can_post' => $can_post,
'$upload' => array(t('Upload'), z_root() . '/photos/' . \App::$data['channel']['channel_address'] . '/upload/' . bin2hex($album)), '$upload' => array(t('Upload'), z_root() . '/photos/' . \App::$data['channel']['channel_address'] . '/upload/' . $datum),
'$order' => $order, '$order' => $order,
'$upload_form' => $upload_form, '$upload_form' => $upload_form,
'$usage' => $usage_message '$usage' => $usage_message
@ -805,8 +790,6 @@ class Photos extends \Zotlabs\Web\Controller {
killme(); killme();
} }
// $o .= paginate($a);
return $o; return $o;
} }
@ -819,6 +802,11 @@ 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"; \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";
$x = q("select folder from attach where hash = '%s' and uid = %d $sql_attach limit 1",
dbesc($datum),
intval($owner_uid)
);
// fetch image, item containing image, then comments // fetch image, item containing image, then comments
$ph = q("SELECT id,aid,uid,xchan,resource_id,created,edited,title,description,album,filename,mimetype,height,width,filesize,imgscale,photo_usage,is_nsfw,allow_cid,allow_gid,deny_cid,deny_gid FROM photo WHERE uid = %d AND resource_id = '%s' $ph = q("SELECT id,aid,uid,xchan,resource_id,created,edited,title,description,album,filename,mimetype,height,width,filesize,imgscale,photo_usage,is_nsfw,allow_cid,allow_gid,deny_cid,deny_gid FROM photo WHERE uid = %d AND resource_id = '%s'
@ -827,7 +815,7 @@ class Photos extends \Zotlabs\Web\Controller {
dbesc($datum) dbesc($datum)
); );
if(! $ph) { if(! ($ph && $x)) {
/* Check again - this time without specifying permissions */ /* Check again - this time without specifying permissions */
@ -853,15 +841,16 @@ class Photos extends \Zotlabs\Web\Controller {
$order = 'DESC'; $order = 'DESC';
$prvnxt = q("SELECT resource_id FROM photo WHERE album = '%s' AND uid = %d AND imgscale = 0
$sql_extra ORDER BY created $order ", $prvnxt = q("SELECT hash FROM attach WHERE folder = '%s' AND uid = %d AND is_photo = 1
dbesc($ph[0]['album']), $sql_attach ORDER BY created $order ",
dbesc($x[0]['folder']),
intval($owner_uid) intval($owner_uid)
); );
if(count($prvnxt)) { if(count($prvnxt)) {
for($z = 0; $z < count($prvnxt); $z++) { for($z = 0; $z < count($prvnxt); $z++) {
if($prvnxt[$z]['resource_id'] == $ph[0]['resource_id']) { if($prvnxt[$z]['hash'] == $ph[0]['hash']) {
$prv = $z - 1; $prv = $z - 1;
$nxt = $z + 1; $nxt = $z + 1;
if($prv < 0) if($prv < 0)
@ -890,7 +879,7 @@ class Photos extends \Zotlabs\Web\Controller {
} }
} }
$album_link = z_root() . '/photos/' . \App::$data['channel']['channel_address'] . '/album/' . bin2hex($ph[0]['album']); $album_link = z_root() . '/photos/' . \App::$data['channel']['channel_address'] . '/album/' . $x[0]['folder'];
$tools = Null; $tools = Null;
$lock = Null; $lock = Null;
@ -930,7 +919,7 @@ class Photos extends \Zotlabs\Web\Controller {
// Do we have an item for this photo? // Do we have an item for this photo?
$linked_items = q("SELECT * FROM item WHERE resource_id = '%s' and resource_type = 'photo' $linked_items = q("SELECT * FROM item WHERE resource_id = '%s' and resource_type = 'photo'
$sql_extra LIMIT 1", $sql_item LIMIT 1",
dbesc($datum) dbesc($datum)
); );
@ -945,7 +934,7 @@ class Photos extends \Zotlabs\Web\Controller {
$item_normal = item_normal(); $item_normal = item_normal();
$r = q("select * from item where parent_mid = '%s' $r = q("select * from item where parent_mid = '%s'
$item_normal and uid = %d $sql_extra ", $item_normal and uid = %d $sql_item ",
dbesc($link_item['mid']), dbesc($link_item['mid']),
intval($link_item['uid']) intval($link_item['uid'])
@ -991,13 +980,6 @@ class Photos extends \Zotlabs\Web\Controller {
$edit = null; $edit = null;
if($can_post) { if($can_post) {
$m = q("select folder from attach where hash = '%s' and uid = %d limit 1",
dbesc($ph[0]['resource_id']),
intval($ph[0]['uid'])
);
if($m)
$album_hash = $m[0]['folder'];
$album_e = $ph[0]['album']; $album_e = $ph[0]['album'];
$caption_e = $ph[0]['description']; $caption_e = $ph[0]['description'];
$aclselect_e = (($_is_owner) ? populate_acl($ph[0], true, \Zotlabs\Lib\PermissionDescription::fromGlobalPermission('view_storage')) : ''); $aclselect_e = (($_is_owner) ? populate_acl($ph[0], true, \Zotlabs\Lib\PermissionDescription::fromGlobalPermission('view_storage')) : '');
@ -1007,14 +989,14 @@ class Photos extends \Zotlabs\Web\Controller {
$folder_list = attach_folder_select_list($ph[0]['uid']); $folder_list = attach_folder_select_list($ph[0]['uid']);
$edit = array( $edit = [
'edit' => t('Edit photo'), 'edit' => t('Edit photo'),
'id' => $link_item['id'], 'id' => $link_item['id'],
'rotatecw' => t('Rotate CW (right)'), 'rotatecw' => t('Rotate CW (right)'),
'rotateccw' => t('Rotate CCW (left)'), 'rotateccw' => t('Rotate CCW (left)'),
'albums' => $albums['albums'], 'albums' => $albums['albums'],
'album' => $album_e, 'album' => $album_e,
'album_select' => [ 'move_to_album', t('Move photo to album'), $album_hash, '', $folder_list ], 'album_select' => [ 'move_to_album', t('Move photo to album'), $x[0]['folder'], '', $folder_list ],
'newalbum_label' => t('Enter a new album name'), 'newalbum_label' => t('Enter a new album name'),
'newalbum_placeholder' => t('or select an existing one (doubleclick)'), 'newalbum_placeholder' => t('or select an existing one (doubleclick)'),
'nickname' => \App::$data['channel']['channel_address'], 'nickname' => \App::$data['channel']['channel_address'],
@ -1035,7 +1017,7 @@ class Photos extends \Zotlabs\Web\Controller {
'adult' => array('adult',t('Flag as adult in album view'), intval($ph[0]['is_nsfw']),''), 'adult' => array('adult',t('Flag as adult in album view'), intval($ph[0]['is_nsfw']),''),
'submit' => t('Submit'), 'submit' => t('Submit'),
'delete' => t('Delete Photo') 'delete' => t('Delete Photo')
); ];
} }
if(count($linked_items)) { if(count($linked_items)) {
@ -1049,13 +1031,13 @@ class Photos extends \Zotlabs\Web\Controller {
$likebuttons = ''; $likebuttons = '';
if($can_post || $can_comment) { if($can_post || $can_comment) {
$likebuttons = array( $likebuttons = [
'id' => $link_item['id'], 'id' => $link_item['id'],
'likethis' => t("I like this \x28toggle\x29"), 'likethis' => t("I like this \x28toggle\x29"),
'nolike' => t("I don't like this \x28toggle\x29"), 'nolike' => t("I don't like this \x28toggle\x29"),
'share' => t('Share'), 'share' => t('Share'),
'wait' => t('Please wait') 'wait' => t('Please wait')
); ];
} }
$comments = ''; $comments = '';
@ -1260,25 +1242,13 @@ 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"; \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 photo_usage in ( %d, %d ) and is_nsfw = %d $sql_extra GROUP BY resource_id",
intval(\App::$data['channel']['channel_id']),
intval(PHOTO_NORMAL),
intval(PHOTO_PROFILE),
intval($unsafe)
);
if($r) {
\App::set_pager_total(count($r));
\App::set_pager_itemspage(60);
}
*/
\App::set_pager_itemspage(60); \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 p $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 INNER JOIN ( SELECT resource_id, attach.folder as folder, max(imgscale) imgscale FROM photo left join attach on
WHERE uid = %d AND photo_usage IN ( %d, %d ) photo.resource_id = attach.hash
WHERE photo.uid = %d AND photo_usage IN ( %d, %d )
AND is_nsfw = %d $sql_extra group by resource_id ) ph AND is_nsfw = %d $sql_extra group by resource_id ) ph
ON (p.resource_id = ph.resource_id and p.imgscale = ph.imgscale) ON (p.resource_id = ph.resource_id and p.imgscale = ph.imgscale)
ORDER by p.created DESC LIMIT %d OFFSET %d", ORDER by p.created DESC LIMIT %d OFFSET %d",
@ -1311,6 +1281,9 @@ class Photos extends \Zotlabs\Web\Controller {
$name_e = $rr['album']; $name_e = $rr['album'];
} }
$photos[] = array( $photos[] = array(
'id' => $rr['id'], 'id' => $rr['id'],
'twist' => ' ' . $twist . rand(2,4), 'twist' => ' ' . $twist . rand(2,4),

View File

@ -623,14 +623,15 @@ function photos_album_rename($channel_id, $oldname, $newname) {
*/ */
function photos_album_get_db_idstr($channel_id, $album, $remote_xchan = '') { function photos_album_get_db_idstr($channel_id, $album, $remote_xchan = '') {
if ($remote_xchan) { if($remote_xchan) {
$r = q("SELECT distinct resource_id from photo where xchan = '%s' and uid = %d and album = '%s' ", $r = q("SELECT hash from attach where creator = '%s' and uid = %d and folder = '%s' ",
dbesc($remote_xchan), dbesc($remote_xchan),
intval($channel_id), intval($channel_id),
dbesc($album) dbesc($album)
); );
} else { }
$r = q("SELECT distinct resource_id from photo where uid = %d and album = '%s' ", else {
$r = q("SELECT hash from attach where uid = %d and folder = '%s' ",
intval($channel_id), intval($channel_id),
dbesc($album) dbesc($album)
); );
@ -638,7 +639,7 @@ function photos_album_get_db_idstr($channel_id, $album, $remote_xchan = '') {
if ($r) { if ($r) {
$arr = array(); $arr = array();
foreach ($r as $rr) { foreach ($r as $rr) {
$arr[] = "'" . dbesc($rr['resource_id']) . "'" ; $arr[] = "'" . dbesc($rr['hash']) . "'" ;
} }
$str = implode(',',$arr); $str = implode(',',$arr);
return $str; return $str;