bring the new photo schema into play

This commit is contained in:
redmatrix 2015-05-18 19:43:53 -07:00
parent eae241df56
commit da7abbb089
5 changed files with 37 additions and 53 deletions

View File

@ -302,7 +302,6 @@ abstract class photo_driver {
$p['filename'] = (($arr['filename']) ? $arr['filename'] : '');
$p['album'] = (($arr['album']) ? $arr['album'] : '');
$p['scale'] = ((intval($arr['scale'])) ? intval($arr['scale']) : 0);
$p['photo_flags'] = ((intval($arr['photo_flags'])) ? intval($arr['photo_flags']) : 0);
$p['allow_cid'] = (($arr['allow_cid']) ? $arr['allow_cid'] : '');
$p['allow_gid'] = (($arr['allow_gid']) ? $arr['allow_gid'] : '');
$p['deny_cid'] = (($arr['deny_cid']) ? $arr['deny_cid'] : '');
@ -311,11 +310,7 @@ abstract class photo_driver {
$p['edited'] = (($arr['edited']) ? $arr['edited'] : $p['created']);
$p['title'] = (($arr['title']) ? $arr['title'] : '');
$p['description'] = (($arr['description']) ? $arr['description'] : '');
// temporary until we get rid of photo['profile'] and just use photo['photo_flags']
// but this will require updating all existing photos in the DB.
$p['profile'] = (($p['photo_flags'] & PHOTO_PROFILE) ? 1 : 0);
$p['photo_usage'] = intval($arr['photo_usage']);
$x = q("select id from photo where resource_id = '%s' and uid = %d and xchan = '%s' and `scale` = %d limit 1",
@ -340,8 +335,7 @@ abstract class photo_driver {
`data` = '%s',
`size` = %d,
`scale` = %d,
`profile` = %d,
`photo_flags` = %d,
`photo_usage` = %d,
`title` = '%s',
`description` = '%s',
`allow_cid` = '%s',
@ -364,8 +358,7 @@ abstract class photo_driver {
dbescbin($this->imageString()),
intval(strlen($this->imageString())),
intval($p['scale']),
intval($p['profile']),
intval($p['photo_flags']),
intval($p['photo_usage']),
dbesc($p['title']),
dbesc($p['description']),
dbesc($p['allow_cid']),
@ -377,7 +370,7 @@ abstract class photo_driver {
}
else {
$r = q("INSERT INTO `photo`
( `aid`, `uid`, `xchan`, `resource_id`, `created`, `edited`, `filename`, type, `album`, `height`, `width`, `data`, `size`, `scale`, `profile`, `photo_flags`, `title`, `description`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid` )
( `aid`, `uid`, `xchan`, `resource_id`, `created`, `edited`, `filename`, type, `album`, `height`, `width`, `data`, `size`, `scale`, `photo_usage`, `title`, `description`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid` )
VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', %d, %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s' )",
intval($p['aid']),
intval($p['uid']),
@ -393,8 +386,7 @@ abstract class photo_driver {
dbescbin($this->imageString()),
intval(strlen($this->imageString())),
intval($p['scale']),
intval($p['profile']),
intval($p['photo_flags']),
intval($p['photo_usage']),
dbesc($p['title']),
dbesc($p['description']),
dbesc($p['allow_cid']),
@ -406,7 +398,7 @@ abstract class photo_driver {
return $r;
}
public function store($aid, $uid, $xchan, $rid, $filename, $album, $scale, $profile = 0, $allow_cid = '', $allow_gid = '', $deny_cid = '', $deny_gid = '') {
public function store($aid, $uid, $xchan, $rid, $filename, $album, $scale, $usage = PHOTO_NORMAL, $allow_cid = '', $allow_gid = '', $deny_cid = '', $deny_gid = '') {
$x = q("select id from photo where `resource_id` = '%s' and uid = %d and `xchan` = '%s' and `scale` = %d limit 1",
dbesc($rid),
@ -430,7 +422,7 @@ abstract class photo_driver {
`data` = '%s',
`size` = %d,
`scale` = %d,
`profile` = %d,
`photo_usage` = %d,
`allow_cid` = '%s',
`allow_gid` = '%s',
`deny_cid` = '%s',
@ -451,7 +443,7 @@ abstract class photo_driver {
dbescbin($this->imageString()),
intval(strlen($this->imageString())),
intval($scale),
intval($profile),
intval($photo_usage),
dbesc($allow_cid),
dbesc($allow_gid),
dbesc($deny_cid),
@ -461,7 +453,7 @@ abstract class photo_driver {
}
else {
$r = q("INSERT INTO `photo`
( `aid`, `uid`, `xchan`, `resource_id`, `created`, `edited`, `filename`, type, `album`, `height`, `width`, `data`, `size`, `scale`, `profile`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid` )
( `aid`, `uid`, `xchan`, `resource_id`, `created`, `edited`, `filename`, type, `album`, `height`, `width`, `data`, `size`, `scale`, `photo_usage`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid` )
VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', %d, %d, %d, '%s', '%s', '%s', '%s' )",
intval($aid),
intval($uid),
@ -477,7 +469,7 @@ abstract class photo_driver {
dbescbin($this->imageString()),
intval(strlen($this->imageString())),
intval($scale),
intval($profile),
intval($photo_usage),
dbesc($allow_cid),
dbesc($allow_gid),
dbesc($deny_cid),
@ -569,7 +561,7 @@ function import_profile_photo($photo,$xchan,$thing = false) {
if($thing)
$hash = photo_new_resource();
else {
$r = q("select resource_id from photo where xchan = '%s' and (photo_flags & %d )>0 and scale = 4 limit 1",
$r = q("select resource_id from photo where xchan = '%s' and photo_usage = %d and scale = 4 limit 1",
dbesc($xchan),
intval(PHOTO_XCHAN)
);
@ -622,7 +614,7 @@ function import_profile_photo($photo,$xchan,$thing = false) {
else
$photo_failure = true;
$p = array('xchan' => $xchan,'resource_id' => $hash, 'filename' => basename($photo), 'album' => $album, 'photo_flags' => $flags, 'scale' => 4);
$p = array('xchan' => $xchan,'resource_id' => $hash, 'filename' => basename($photo), 'album' => $album, 'photo_usage' => $flags, 'scale' => 4);
$r = $img->save($p);
@ -684,7 +676,7 @@ function import_channel_photo($photo,$type,$aid,$uid) {
$img->scaleImageSquare(175);
$p = array('aid' => $aid, 'uid' => $uid, 'resource_id' => $hash, 'filename' => $filename, 'album' => t('Profile Photos'), 'photo_flags' => PHOTO_PROFILE, 'scale' => 4);
$p = array('aid' => $aid, 'uid' => $uid, 'resource_id' => $hash, 'filename' => $filename, 'album' => t('Profile Photos'), 'photo_usage' => PHOTO_PROFILE, 'scale' => 4);
$r = $img->save($p);

View File

@ -156,7 +156,7 @@ function photo_upload($channel, $observer, $args) {
$errors = false;
$p = array('aid' => $account_id, 'uid' => $channel_id, 'xchan' => $visitor, 'resource_id' => $photo_hash,
'filename' => $filename, 'album' => $album, 'scale' => 0, 'photo_flags' => PHOTO_NORMAL,
'filename' => $filename, 'album' => $album, 'scale' => 0, 'photo_usage' => PHOTO_NORMAL,
'allow_cid' => $str_contact_allow, 'allow_gid' => $str_group_allow,
'deny_cid' => $str_contact_deny, 'deny_gid' => $str_group_deny
);
@ -313,7 +313,7 @@ function photos_albums_list($channel, $observer) {
$sql_extra = permissions_sql($channel_id);
$albums = q("SELECT count( distinct resource_id ) as total, album from photo where uid = %d and ( photo_flags = %d or photo_flags = %d ) $sql_extra group by album order by max(created) desc",
$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 max(created) desc",
intval($channel_id),
intval(PHOTO_NORMAL),
intval(PHOTO_PROFILE)
@ -393,7 +393,7 @@ function photos_list_photos($channel, $observer, $album = '') {
$ret = array('success' => false);
$r = q("select resource_id, created, edited, title, description, album, filename, type, height, width, size, scale, profile, photo_flags, allow_cid, allow_gid, deny_cid, deny_gid from photo where uid = %d and ( photo_flags = %d or photo_flags = %d ) $sql_extra ",
$r = q("select resource_id, created, edited, title, description, album, filename, type, height, width, size, scale, photo_usage, allow_cid, allow_gid, deny_cid, deny_gid from photo where uid = %d and photo_usage in ( %d, %d ) $sql_extra ",
intval($channel_id),
intval(PHOTO_NORMAL),
intval(PHOTO_PROFILE)

View File

@ -830,7 +830,7 @@ CREATE TABLE IF NOT EXISTS `photo` (
`size` int(10) unsigned NOT NULL DEFAULT '0',
`data` mediumblob NOT NULL,
`scale` tinyint(3) NOT NULL DEFAULT '0',
`usage` smallint(6) NOT NULL DEFAULT '0',
`photo_usage` smallint(6) NOT NULL DEFAULT '0',
`profile` tinyint(1) NOT NULL DEFAULT '0',
`is_nsfw` tinyint(1) NOT NULL DEFAULT '0',
`os_storage` tinyint(1) NOT NULL DEFAULT '0',
@ -854,7 +854,7 @@ CREATE TABLE IF NOT EXISTS `photo` (
KEY `resource_id` (`resource_id`),
KEY `is_nsfw` (`is_nsfw`),
KEY `os_storage` (`os_storage`),
KEY `usage` (`usage`)
KEY `photo_usage` (`photo_usage`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `poll` (

View File

@ -578,11 +578,12 @@ function photos_content(&$a) {
$album = hex2bin($datum);
$r = q("SELECT `resource_id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
AND `scale` <= 4 and ((photo_flags = %d) or (photo_flags & %d ) > 0) $sql_extra GROUP BY `resource_id`",
AND `scale` <= 4 and photo_usage IN ( %d, %d ) and is_nsfw = %d $sql_extra GROUP BY `resource_id`",
intval($owner_uid),
dbesc($album),
intval(PHOTO_NORMAL),
intval(($unsafe) ? (PHOTO_PROFILE|PHOTO_ADULT) : PHOTO_PROFILE)
intval(PHOTO_PROFILE),
intval($unsafe)
);
if(count($r)) {
$a->set_pager_total(count($r));
@ -598,13 +599,14 @@ function photos_content(&$a) {
$r = q("SELECT p.resource_id, p.id, p.filename, p.type, p.scale, p.description, p.created FROM photo p INNER JOIN
(SELECT resource_id, max(scale) scale FROM photo WHERE uid = %d AND album = '%s' AND scale <= 4 AND (photo_flags = %d or photo_flags = %d ) $sql_extra GROUP BY resource_id) ph
(SELECT resource_id, max(scale) scale FROM photo WHERE uid = %d AND album = '%s' AND scale <= 4 AND photo_usage IN ( %d, %d ) and is_nsfw = %d $sql_extra GROUP BY resource_id) ph
ON (p.resource_id = ph.resource_id AND p.scale = ph.scale)
ORDER BY created $order LIMIT %d OFFSET %d",
intval($owner_uid),
dbesc($album),
intvaL(PHOTO_NORMAL),
intval(($unsafe) ? (PHOTO_PROFILE|PHOTO_ADULT) : PHOTO_PROFILE),
intval(PHOTO_NORMAL),
intval(PHOTO_PROFILE),
intval($unsafe),
intval($a->pager['itemspage']),
intval($a->pager['start'])
);
@ -1140,12 +1142,13 @@ function photos_content(&$a) {
//$o = '';
$r = q("SELECT `resource_id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
and ((photo_flags = %d) or (photo_flags & %d) > 0) $sql_extra GROUP BY `resource_id`",
and photo_usage in ( %d, %d ) and is_nsfw = %d $sql_extra GROUP BY `resource_id`",
intval($a->data['channel']['channel_id']),
dbesc('Contact Photos'),
dbesc( t('Contact Photos')),
intval(PHOTO_NORMAL),
intval(($unsafe) ? (PHOTO_PROFILE|PHOTO_ADULT) : PHOTO_PROFILE)
intval(PHOTO_PROFILE),
intval($unsafe)
);
if(count($r)) {
$a->set_pager_total(count($r));
@ -1155,13 +1158,14 @@ function photos_content(&$a) {
$r = q("SELECT p.resource_id, p.id, p.filename, p.type, p.album, p.scale, p.created FROM photo p INNER JOIN
(SELECT resource_id, max(scale) scale FROM photo
WHERE uid=%d AND album != '%s' AND album != '%s'
AND (photo_flags = %d or ( photo_flags & %d ) > 0 ) $sql_extra group by resource_id) ph
AND photo_usage IN ( %d, %d ) and is_nsfw = %d $sql_extra group by resource_id) ph
ON (p.resource_id = ph.resource_id and p.scale = ph.scale) ORDER by p.created DESC LIMIT %d OFFSET %d",
intval($a->data['channel']['channel_id']),
dbesc('Contact Photos'),
dbesc( t('Contact Photos')),
intval(PHOTO_NORMAL),
intval(($unsafe) ? (PHOTO_PROFILE|PHOTO_ADULT) : PHOTO_PROFILE),
intval(PHOTO_PROFILE),
intval($unsafe),
intval($a->pager['itemspage']),
intval($a->pager['start'])
);

View File

@ -143,7 +143,7 @@ function profile_photo_post(&$a) {
'filename' => $base_image['filename'], 'album' => t('Profile Photos'));
$p['scale'] = 4;
$p['photo_flags'] = (($is_default_profile) ? PHOTO_PROFILE : PHOTO_NORMAL);
$p['photo_usage'] = (($is_default_profile) ? PHOTO_PROFILE : PHOTO_NORMAL);
$r1 = $im->save($p);
@ -170,13 +170,9 @@ function profile_photo_post(&$a) {
// If setting for the default profile, unset the profile photo flag from any other photos I own
if($is_default_profile) {
$r = q("UPDATE photo SET profile = 0 WHERE profile = 1 AND resource_id != '%s' AND `uid` = %d",
dbesc($base_image['resource_id']),
intval(local_channel())
);
$r = q("UPDATE photo SET photo_flags = ( photo_flags & ~%d ) WHERE ( photo_flags & %d )>0
$r = q("UPDATE photo SET photo_usage = %d WHERE photo_usage = %d
AND resource_id != '%s' AND `uid` = %d",
intval(PHOTO_PROFILE),
intval(PHOTO_NORMAL),
intval(PHOTO_PROFILE),
dbesc($base_image['resource_id']),
intval(local_channel())
@ -301,20 +297,12 @@ function profile_photo_content(&$a) {
if(($r[0]['album'] == t('Profile Photos')) && ($havescale)) {
// unset any existing profile photos
$r = q("UPDATE photo SET profile = 0 WHERE profile = 1 AND uid = %d",
intval(local_channel()));
$r = q("UPDATE photo SET photo_flags = (photo_flags & ~%d ) WHERE (photo_flags & %d )>0 AND uid = %d",
intval(PHOTO_PROFILE),
$r = q("UPDATE photo SET photo_usage = %d WHERE photo_usage = %d AND uid = %d",
intval(PHOTO_NORMAL),
intval(PHOTO_PROFILE),
intval(local_channel()));
// set all sizes of this one as profile photos
$r = q("UPDATE photo SET profile = 1 WHERE uid = %d AND resource_id = '%s'",
intval(local_channel()),
dbesc($resource_id)
);
$r = q("UPDATE photo SET photo_flags = ( photo_flags | %d ) WHERE uid = %d AND resource_id = '%s'",
$r = q("UPDATE photo SET photo_usage = %d WHERE uid = %d AND resource_id = '%s'",
intval(PHOTO_PROFILE),
intval(local_channel()),
dbesc($resource_id)