diff options
author | friendica <info@friendica.com> | 2013-08-07 01:42:45 -0700 |
---|---|---|
committer | friendica <info@friendica.com> | 2013-08-07 01:42:45 -0700 |
commit | 20b22421d3731bfcc8b349fbc082156d001a099a (patch) | |
tree | 14c8591e7340eb61689bfa0143e6be0c196617f1 /include | |
parent | 809a53a2f8175f0fe61be531f234968a10fb5dc2 (diff) | |
download | volse-hubzilla-20b22421d3731bfcc8b349fbc082156d001a099a.tar.gz volse-hubzilla-20b22421d3731bfcc8b349fbc082156d001a099a.tar.bz2 volse-hubzilla-20b22421d3731bfcc8b349fbc082156d001a099a.zip |
big changes to photo->store() which is now photo->save() and takes an array instead of a list of args. Also the beginning of the migration to using photo_flags to indicate special purpose photos such as profile photos and contact photos and "thing" photos.
Diffstat (limited to 'include')
-rw-r--r-- | include/photo/photo_driver.php | 130 | ||||
-rw-r--r-- | include/photos.php | 16 |
2 files changed, 136 insertions, 10 deletions
diff --git a/include/photo/photo_driver.php b/include/photo/photo_driver.php index 25f53f400..38210ba26 100644 --- a/include/photo/photo_driver.php +++ b/include/photo/photo_driver.php @@ -271,6 +271,111 @@ abstract class photo_driver { } + public function save($arr) { + + $p = array(); + + $p['aid'] = ((intval($arr['aid'])) ? intval($arr['aid']) : 0); + $p['uid'] = ((intval($arr['uid'])) ? intval($arr['uid']) : 0); + $p['xchan'] = (($arr['xchan']) ? $arr['xchan'] : ''); + $p['resource_id'] = (($arr['resource_id']) ? $arr['resource_id'] : ''); + $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'] : ''); + $p['deny_gid'] = (($arr['deny_gid']) ? $arr['deny_gid'] : ''); + + // 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); + + + $x = q("select id from photo where resource_id = '%s' and uid = %d and xchan = '%s' and `scale` = %d limit 1", + dbesc($p['resource_id']), + intval($p['uid']), + dbesc($p['xchan']), + intval($p['scale']) + ); + if($x) { + $r = q("UPDATE `photo` set + `aid` = %d, + `uid` = %d, + `xchan` = '%s', + `resource_id` = '%s', + `created` = '%s', + `edited` = '%s', + `filename` = '%s', + `type` = '%s', + `album` = '%s', + `height` = %d, + `width` = %d, + `data` = '%s', + `size` = %d, + `scale` = %d, + `profile` = %d, + `photo_flags` = %d, + `allow_cid` = '%s', + `allow_gid` = '%s', + `deny_cid` = '%s', + `deny_gid` = '%s' + where id = %d limit 1", + + intval($p['aid']), + intval($p['uid']), + dbesc($p['xchan']), + dbesc($p['resource_id']), + dbesc(datetime_convert()), + dbesc(datetime_convert()), + dbesc(basename($p['filename'])), + dbesc($this->getType()), + dbesc($p['album']), + intval($this->getHeight()), + intval($this->getWidth()), + dbesc($this->imageString()), + intval(strlen($this->imageString())), + intval($p['scale']), + intval($p['profile']), + intval($p['photo_flags']), + dbesc($p['allow_cid']), + dbesc($p['allow_gid']), + dbesc($p['deny_cid']), + dbesc($p['deny_gid']), + intval($x[0]['id']) + ); + } + else { + $r = q("INSERT INTO `photo` + ( `aid`, `uid`, `xchan`, `resource_id`, `created`, `edited`, `filename`, type, `album`, `height`, `width`, `data`, `size`, `scale`, `profile`, `photo_flags`, `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' )", + intval($p['aid']), + intval($p['uid']), + dbesc($p['xchan']), + dbesc($p['resource_id']), + dbesc(datetime_convert()), + dbesc(datetime_convert()), + dbesc(basename($filename)), + dbesc($this->getType()), + dbesc($p['album']), + intval($this->getHeight()), + intval($this->getWidth()), + dbesc($this->imageString()), + intval(strlen($this->imageString())), + intval($p['scale']), + intval($p['profile']), + intval($p['photo_flags']), + dbesc($p['allow_cid']), + dbesc($p['allow_gid']), + dbesc($p['deny_cid']), + dbesc($p['deny_gid']) + ); + } + return $r; + } + public function store($aid, $uid, $xchan, $rid, $filename, $album, $scale, $profile = 0, $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", @@ -356,6 +461,11 @@ abstract class photo_driver { + + + + + /** * Guess image mimetype from filename or from Content-Type header * @@ -434,21 +544,25 @@ function import_profile_photo($photo,$xchan) { $img->scaleImageSquare(175); - $r = $img->store(0, 0, $xchan, $hash, $filename, 'Contact Photos', 4 ); + $p = array('xchan' => $xchan,'resource_id' => $hash, 'filename' => 'Contact Photos', 'photo_flags' => PHOTO_XCHAN, 'scale' => 4); + + $r = $img->save($p); if($r === false) $photo_failure = true; $img->scaleImage(80); + $p['scale'] = 5; - $r = $img->store(0, 0, $xchan, $hash, $filename, 'Contact Photos', 5 ); + $r = $img->save($p); if($r === false) $photo_failure = true; $img->scaleImage(48); + $p['scale'] = 6; - $r = $img->store(0, 0, $xchan, $hash, $filename, 'Contact Photos', 6 ); + $r = $img->save($p); if($r === false) $photo_failure = true; @@ -492,21 +606,25 @@ function import_channel_photo($photo,$type,$aid,$uid) { $img->scaleImageSquare(175); - $r = $img->store($aid,$uid,'', $hash, $filename, t('Profile Photos'), 4, true); + $p = array('aid' => $aid, 'uid' => $uid, 'resource_id' => $hash, 'filename' => $filename, 'album' => t('Profile Photos'), 'photo_flags' => PHOTO_PROFILE, 'scale' => 4); + + $r = $img->save($p); if($r === false) $photo_failure = true; $img->scaleImage(80); + $p['scale'] = 5; - $r = $img->store($aid,$uid,'', $hash, $filename, t('Profile Photos'), 5, true); + $r = $img->save($p); if($r === false) $photo_failure = true; $img->scaleImage(48); + $p['scale'] = 6; - $r = $img->store($aid,$uid,'', $hash, $filename, t('Profile Photos'), 6, true); + $r = $img->save($p); if($r === false) $photo_failure = true; diff --git a/include/photos.php b/include/photos.php index 8902761c4..c670bd90c 100644 --- a/include/photos.php +++ b/include/photos.php @@ -150,13 +150,20 @@ function photo_upload($channel, $observer, $args) { $errors = false; - $r1 = $ph->store($account_id, $channel_id, $visitor, $photo_hash, $filename, $album, 0 , 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny); + $p = array('aid' => $account_id, 'uid' => $channel_id, 'xchan' => $visitor, 'resource_id' => $photo_hash, + 'filename' => $filename, 'album' => $album, 'scale' => 0, 'photo_flags' => PHOTO_NORMAL, + 'allow_cid' => $str_contact_allow, 'allow_gid' => $str_group_allow, + 'deny_cid' => $str_contact_deny, 'deny_gid' => $str_group_deny + ); + + $r1 = $ph->save($p); if(! $r1) $errors = true; if(($width > 640 || $height > 640) && (! $errors)) { $ph->scaleImage(640); - $r2 = $ph->store($account_id, $channel_id, $visitor, $photo_hash, $filename, $album, 1, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny); + $p['scale'] = 1; + $r2 = $ph->save($p); $smallest = 1; if(! $r2) $errors = true; @@ -164,7 +171,8 @@ function photo_upload($channel, $observer, $args) { if(($width > 320 || $height > 320) && (! $errors)) { $ph->scaleImage(320); - $r3 = $ph->store($account_id, $channel_id, $visitor, $photo_hash, $filename, $album, 2, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny); + $p['scale'] = 2; + $r3 = $ph->save($p); $smallest = 2; if(! $r3) $errors = true; @@ -302,7 +310,7 @@ function photos_list_photos($channel,$observer,$album = '') { $ret = array('success' => false); - $r = q("select resource_id, created, edited, title, `desc`, album, filename, `type`, height, width, `size`, `scale`, profile, 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, `desc`, 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 ", intval($channel_id), intval(PHOTO_NORMAL), intval(PHOTO_PROFILE) |