diff options
Diffstat (limited to 'include/photos.php')
-rw-r--r-- | include/photos.php | 108 |
1 files changed, 79 insertions, 29 deletions
diff --git a/include/photos.php b/include/photos.php index 885d2f958..ea4b494e0 100644 --- a/include/photos.php +++ b/include/photos.php @@ -1,7 +1,9 @@ -<?php +<?php /** @file */ require_once('include/permissions.php'); require_once('include/items.php'); +require_once('include/photo/photo_driver.php'); + function photo_upload($channel, $observer, $args) { @@ -116,13 +118,13 @@ function photo_upload($channel, $observer, $args) { } - $ph = new Photo($imagedata, $type); + $ph = photo_factory($imagedata, $type); if(! $ph->is_valid()) { $ret['message'] = t('Unable to process image'); logger('photo_upload: unable to process image'); @unlink($src); - call_hooks('photo_post_end',$ret); + call_hooks('photo_upload_end',$ret); return $ret; } @@ -148,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; @@ -162,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; @@ -175,26 +185,26 @@ function photo_upload($channel, $observer, $args) { ); $ret['message'] = t('Photo storage failed.'); logger('photo_upload: photo store failed.'); - call_hooks('photo_post_end',$ret); + call_hooks('photo_upload_end',$ret); return $ret; } $basename = basename($filename); - $uri = item_message_id(); + $mid = item_message_id(); // Create item container $item_flags = ITEM_WALL|ITEM_ORIGIN|ITEM_THREAD_TOP; $item_restrict = (($visible) ? ITEM_VISIBLE : ITEM_HIDDEN); $title = ''; - $uri = item_message_id(); + $mid = item_message_id(); $arr = array(); $arr['aid'] = $account_id; $arr['uid'] = $channel_id; - $arr['uri'] = $uri; - $arr['parent_uri'] = $uri; + $arr['mid'] = $mid; + $arr['parent_mid'] = $mid; $arr['item_flags'] = $item_flags; $arr['item_restrict'] = $item_restrict; $arr['resource_type'] = 'photo'; @@ -206,13 +216,14 @@ function photo_upload($channel, $observer, $args) { $arr['allow_gid'] = $str_group_allow; $arr['deny_cid'] = $str_contact_deny; $arr['deny_gid'] = $str_group_deny; + $arr['verb'] = ACTIVITY_POST; - - $arr['body'] = '[url=' . z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo_hash . ']' - . '[img]' . z_root() . "/photo/{$photo_hash}-{$smallest}.".$ph->getExt() . '[/img]' - . '[/url]'; + $arr['body'] = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo_hash . ']' + . '[zmg]' . z_root() . "/photo/{$photo_hash}-{$smallest}.".$ph->getExt() . '[/zmg]' + . '[/zrl]'; - $item_id = item_store($arr); + $result = item_store($arr); + $item_id = $result['item_id']; if($visible) proc_run('php', "include/notifier.php", 'wall-new', $item_id); @@ -222,7 +233,7 @@ function photo_upload($channel, $observer, $args) { $ret['resource_id'] = $photo_hash; $ret['photoitem_id'] = $item_id; - call_hooks('photo_post_end',$ret); + call_hooks('photo_upload_end',$ret); return $ret; } @@ -242,19 +253,25 @@ function photos_albums_list($channel,$observer) { $sql_extra = permissions_sql($channel_id); - $albums = q("SELECT distinct album from photo where uid = %d $sql_extra order by created desc", - intval($channel_id) + $albums = q("SELECT distinct album from photo where uid = %d and ( photo_flags = %d or photo_flags = %d ) $sql_extra order by created desc", + intval($channel_id), + intval(PHOTO_NORMAL), + intval(PHOTO_PROFILE) + ); // add various encodings to the array so we can just loop through and pick them out in a template + $ret = array('success' => false); + if($albums) { + $ret['success'] = true; foreach($albums as $k => $album) { - $albums[$k]['urlencode'] = urlencode($album['album']); - $albums[$k]['bin2hex'] = bin2hex($album['album']); + $entry = array('text' => $album['album'], 'urlencode' => urlencode($album['album']),'bin2hex' => bin2hex($album['album'])); + $ret[] = $entry; } } - return $albums; + return $ret; } @@ -278,6 +295,38 @@ function photos_album_widget($channelx,$observer,$albums = null) { return $o; } + +function photos_list_photos($channel,$observer,$album = '') { + + $channel_id = $channel['channel_id']; + $observer_xchan = (($observer) ? $observer['xchan_hash'] : ''); + + if(! perm_is_allowed($channel_id,$observer_xchan,'view_photos')) + return false; + + $sql_extra = permissions_sql($channel_id); + + if($album) + $sql_extra .= " and album = '" . protect_sprintf(dbesc($album)) . "' "; + + $ret = array('success' => false); + + $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) + ); + + if($r) { + $ret['success'] = true; + $ret['photos'] = $r; + } + + return $ret; +} + + + function photos_album_exists($channel_id,$album) { $r = q("SELECT id from photo where album = '%s' and uid = %d limit 1", dbesc($album), @@ -330,14 +379,14 @@ function photos_create_item($channel, $creator_hash, $photo, $visible = false) { $item_restrict = (($visible) ? ITEM_HIDDEN : ITEM_VISIBLE); $title = ''; - $uri = item_message_id(); + $mid = item_message_id(); $arr = array(); $arr['aid'] = $channel['channel_account_id']; $arr['uid'] = $channel['channel_id']; - $arr['uri'] = $uri; - $arr['parent_uri'] = $uri; + $arr['mid'] = $mid; + $arr['parent_mid'] = $mid; $arr['item_flags'] = $item_flags; $arr['item_restrict'] = $item_restrict; $arr['resource_type'] = 'photo'; @@ -350,11 +399,12 @@ function photos_create_item($channel, $creator_hash, $photo, $visible = false) { $arr['deny_cid'] = $photo['deny_cid']; $arr['deny_gid'] = $photo['deny_gid']; - $arr['body'] = '[url=' . z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo['resource_id'] . ']' - . '[img]' . z_root() . '/photo/' . $photo['resource_id'] . '-' . $photo['scale'] . '[/img]' - . '[/url]'; + $arr['body'] = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo['resource_id'] . ']' + . '[zmg]' . z_root() . '/photo/' . $photo['resource_id'] . '-' . $photo['scale'] . '[/zmg]' + . '[/zrl]'; - $item_id = item_store($arr); + $result = item_store($arr); + $item_id = $result['item_id']; return $item_id; }
\ No newline at end of file |