aboutsummaryrefslogtreecommitdiffstats
path: root/include/photos.php
diff options
context:
space:
mode:
Diffstat (limited to 'include/photos.php')
-rw-r--r--include/photos.php86
1 files changed, 63 insertions, 23 deletions
diff --git a/include/photos.php b/include/photos.php
index 885d2f958..8902761c4 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;
}
@@ -175,26 +177,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';
@@ -208,9 +210,9 @@ function photo_upload($channel, $observer, $args) {
$arr['deny_gid'] = $str_group_deny;
- $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);
@@ -222,7 +224,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 +244,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 +286,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, 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 +370,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,9 +390,9 @@ 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);
return $item_id;