diff options
Diffstat (limited to 'include/photos.php')
-rw-r--r-- | include/photos.php | 148 |
1 files changed, 113 insertions, 35 deletions
diff --git a/include/photos.php b/include/photos.php index 885d2f958..65532e6c2 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) { @@ -75,6 +77,7 @@ function photo_upload($channel, $observer, $args) { $filesize = intval($_FILES['userfile']['size']); $type = $_FILES['userfile']['type']; } + if (! $type) $type=guess_image_type($filename); @@ -100,12 +103,10 @@ function photo_upload($channel, $observer, $args) { $imagedata = @file_get_contents($src); - $r = q("select sum(size) as total from photo where uid = %d and scale = 0 ", - intval($channel_id) + $r = q("select sum(size) as total from photo where aid = %d and scale = 0 ", + intval($account_id) ); -// FIXME service class limits should probably apply to accounts and not channels - $limit = service_class_fetch($channel_id,'photo_upload_limit'); if(($r) && ($limit !== false) && (($r[0]['total'] + strlen($imagedata)) > $limit)) { @@ -116,13 +117,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 +149,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,11 +170,13 @@ 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; } + if($errors) { q("delete from photo where resource_id = '%s' and uid = %d", @@ -175,26 +185,30 @@ 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; } + // This will be the width and height of the smallest representation + + $width_x_height = $ph->getWidth() . 'x' . $ph->getHeight(); + $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 +220,21 @@ 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['plink'] = z_root() . '/channel/' . $channel['channel_address'] . '/?f=&mid=' . $arr['mid']; - $arr['body'] = '[url=' . z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo_hash . ']' - . '[img]' . z_root() . "/photo/{$photo_hash}-{$smallest}.".$ph->getExt() . '[/img]' - . '[/url]'; + if ($width_x_height) + $tag = '[zmg=' . $width_x_height. ']'; + else + $tag = '[zmg]'; + + $arr['body'] = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo_hash . ']' + . $tag . 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 +244,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 +264,29 @@ 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'], + 'url' => z_root() . '/photos/' . $channel['channel_address'] . '/album/' . bin2hex($album['album']), + 'urlencode' => urlencode($album['album']), + 'bin2hex' => bin2hex($album['album'])); + $ret[] = $entry; } } - return $albums; + return $ret; } @@ -262,8 +294,16 @@ function photos_album_widget($channelx,$observer,$albums = null) { $o = ''; - if(! $albums) - $albums = photos_albums_list($channelx,$observer); + // If we weren't passed an album list, see if the photos module + // dropped one for us to find in $a->data['albums']. + // If all else fails, load it. + + if(! $albums) { + if(array_key_exists('albums', get_app()->data)) + $albums = get_app()->data['albums']; + else + $albums = photos_albums_list($channelx,$observer); + } if($albums) { $o = replace_macros(get_markup_template('photo_albums.tpl'),array( @@ -278,6 +318,41 @@ 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, 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 ", + intval($channel_id), + intval(PHOTO_NORMAL), + intval(PHOTO_PROFILE) + ); + + if($r) { + for($x = 0; $x < count($r); $x ++) { + $r[$x]['src'] = z_root() . '/photo/' . $r[$x]['resource_id'] . '-' . $r[$x]['scale']; + } + $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 +405,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'; @@ -349,12 +424,15 @@ function photos_create_item($channel, $creator_hash, $photo, $visible = false) { $arr['allow_gid'] = $photo['allow_gid']; $arr['deny_cid'] = $photo['deny_cid']; $arr['deny_gid'] = $photo['deny_gid']; + + $arr['plink'] = z_root() . '/channel/' . $channel['channel_address'] . '/?f=&mid=' . $arr['mid']; - $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 +} |