aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/attach.php11
-rw-r--r--include/photos.php38
-rw-r--r--mod/network.php4
-rw-r--r--mod/photos.php245
-rw-r--r--version.inc2
5 files changed, 57 insertions, 243 deletions
diff --git a/include/attach.php b/include/attach.php
index b2c57f36f..e4ef28637 100644
--- a/include/attach.php
+++ b/include/attach.php
@@ -1,5 +1,14 @@
<?php
+/*
+ * File/attach API with the potential for revision control.
+ *
+ * TODO: a filesystem storage abstraction which maintains security (and 'data' contains a system filename
+ * which is inaccessible from the web). This could get around PHP storage limits and store videos and larger
+ * items, using fread or OS methods or native code to read/write or chunk it through.
+ * Also an 'append' option to the storage function might be a useful addition.
+ */
+
require_once('include/permissions.php');
function z_mime_content_type($filename) {
@@ -151,6 +160,8 @@ function attach_list_files($channel_id, $observer, $hash = '', $filename = '', $
}
+// Find an attachment by hash and revision. Returns the entire attach structure including data.
+// This could exhaust memory so most useful only when immediately sending the data.
function attach_by_hash($hash,$rev = 0) {
diff --git a/include/photos.php b/include/photos.php
index 0d0750c22..8e07c612f 100644
--- a/include/photos.php
+++ b/include/photos.php
@@ -181,7 +181,6 @@ function photo_upload($channel, $observer, $args) {
$basename = basename($filename);
$uri = item_message_id();
-
// Create item container
$item_flags = ITEM_WALL|ITEM_ORIGIN|ITEM_THREAD_TOP;
@@ -319,3 +318,40 @@ function photos_album_get_db_idstr($channel_id,$album,$remote_xchan = '') {
return false;
}
+
+function photos_create_item($channel, $creator_hash, $photo, $visible = false) {
+
+ // Create item container
+
+ $item_flags = ITEM_WALL|ITEM_ORIGIN|ITEM_THREAD_TOP;
+ $item_restrict = (($visible) ? ITEM_HIDDEN : ITEM_VISIBLE);
+
+ $title = '';
+ $uri = item_message_id();
+
+ $arr = array();
+
+ $arr['aid'] = $channel['channel_account_id'];
+ $arr['uid'] = $channel['channel_id'];
+ $arr['uri'] = $uri;
+ $arr['parent_uri'] = $uri;
+ $arr['item_flags'] = $item_flags;
+ $arr['item_restrict'] = $item_restrict;
+ $arr['resource_type'] = 'photo';
+ $arr['resource_id'] = $photo['resource_id'];
+ $arr['owner_xchan'] = $channel['channel_hash'];
+ $arr['author_xchan'] = $creator_hash;
+
+ $arr['allow_cid'] = $photo['allow_cid'];
+ $arr['allow_gid'] = $photo['allow_gid'];
+ $arr['deny_cid'] = $photo['deny_cid'];
+ $arr['deny_gid'] = $photo['deny_gid'];
+
+ $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $channel['channel_address'] . '/image/' . $photo['resource_id'] . ']'
+ . '[img]' . $a->get_baseurl() . '/photo/' . $photo['resource_id'] . '-' . $photo['scale'] . '[/img]'
+ . '[/url]';
+
+ $item_id = item_store($arr);
+ return $item_id;
+
+} \ No newline at end of file
diff --git a/mod/network.php b/mod/network.php
index cca69dc52..4176f0047 100644
--- a/mod/network.php
+++ b/mod/network.php
@@ -707,8 +707,8 @@ function network_content(&$a, $update = 0, $load = false) {
if(! $update)
$o .= alt_pager($a,count($items));
-// logger('parent dba_timer: ' . sprintf('%01.4f',$first - $start));
-// logger('child dba_timer: ' . sprintf('%01.4f',$second - $first));
+ logger('parent dba_timer: ' . sprintf('%01.4f',$first - $start));
+ logger('child dba_timer: ' . sprintf('%01.4f',$second - $first));
return $o;
diff --git a/mod/photos.php b/mod/photos.php
index 127ea4893..101cb20b2 100644
--- a/mod/photos.php
+++ b/mod/photos.php
@@ -305,41 +305,7 @@ function photos_post(&$a) {
$visibility = 1;
if(! $item_id) {
-
- // Create item container
-
- $item_flags = ITEM_WALL|ITEM_ORIGIN|ITEM_THREAD_TOP;
- $item_restrict = (($visibility) ? ITEM_HIDDEN : ITEM_VISIBLE);
-
- $title = '';
- $uri = item_message_id();
-
- $arr = array();
-
- $arr['aid'] = $a->data['channel']['channel_account_id'];
- $arr['uid'] = $page_owner_uid;
- $arr['uri'] = $uri;
- $arr['parent_uri'] = $uri;
- $arr['item_flags'] = $item_flags;
- $arr['item_restrict'] = $item_restrict;
- $arr['resource_type'] = 'photo';
- $arr['resource_id'] = $p[0]['resource_id'];
- $arr['owner_xchan'] = $a->data['channel']['channel_hash'];
- $arr['author_xchan'] = $a->data['channel']['channel_hash']; // FIXME for AUTH guests
-
- $arr['title'] = $title;
- $arr['allow_cid'] = $p[0]['allow_cid'];
- $arr['allow_gid'] = $p[0]['allow_gid'];
- $arr['deny_cid'] = $p[0]['deny_cid'];
- $arr['deny_gid'] = $p[0]['deny_gid'];
-
-
-
- $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/image/' . $p[0]['resource_id'] . ']'
- . '[img]' . $a->get_baseurl() . '/photo/' . $p[0]['resource_id'] . '-' . $p[0]['scale'] . '[/img]'
- . '[/url]';
-
- $item_id = item_store($arr);
+ $item_id = photos_create_item($a->data['channel'],get_observer_hash(),$p[0],$visibility);
}
@@ -559,213 +525,14 @@ function photos_post(&$a) {
* default post action - upload a photo
*/
- call_hooks('photo_post_init', $_POST);
-
- /**
- * Determine the album to use
- */
-
- $album = notags(trim($_REQUEST['album']));
- $newalbum = notags(trim($_REQUEST['newalbum']));
-
- logger('mod/photos.php: photos_post(): album= ' . $album . ' newalbum= ' . $newalbum , LOGGER_DEBUG);
-
- if(! strlen($album)) {
- if(strlen($newalbum))
- $album = $newalbum;
- else
- $album = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
- }
-
- /**
- *
- * We create a wall item for every photo, but we don't want to
- * overwhelm the data stream with a hundred newly uploaded photos.
- * So we will make the first photo uploaded to this album in the last several hours
- * visible by default, the rest will become visible over time when and if
- * they acquire comments, likes, dislikes, and/or tags
- *
- */
-
- $r = q("SELECT * FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `created` > UTC_TIMESTAMP() - INTERVAL 3 HOUR ",
- dbesc($album),
- intval($page_owner_uid)
- );
- if((! count($r)) || ($album == t('Profile Photos')))
- $visible = 1;
- else
- $visible = 0;
-
- if(intval($_REQUEST['not_visible']) || $_REQUEST['not_visible'] === 'true')
- $visible = 0;
-
- $str_group_allow = perms2str(((is_array($_REQUEST['group_allow'])) ? $_REQUEST['group_allow'] : explode(',',$_REQUEST['group_allow'])));
- $str_contact_allow = perms2str(((is_array($_REQUEST['contact_allow'])) ? $_REQUEST['contact_allow'] : explode(',',$_REQUEST['contact_allow'])));
- $str_group_deny = perms2str(((is_array($_REQUEST['group_deny'])) ? $_REQUEST['group_deny'] : explode(',',$_REQUEST['group_deny'])));
- $str_contact_deny = perms2str(((is_array($_REQUEST['contact_deny'])) ? $_REQUEST['contact_deny'] : explode(',',$_REQUEST['contact_deny'])));
-
- $ret = array('src' => '', 'filename' => '', 'filesize' => 0, 'type' => '');
-
- call_hooks('photo_post_file',$ret);
-
- if(x($ret,'src') && x($ret,'filesize')) {
- $src = $ret['src'];
- $filename = $ret['filename'];
- $filesize = $ret['filesize'];
- $type = $ret['type'];
- }
- else {
- $src = $_FILES['userfile']['tmp_name'];
- $filename = basename($_FILES['userfile']['name']);
- $filesize = intval($_FILES['userfile']['size']);
- $type = $_FILES['userfile']['type'];
- }
- if ($type=="") $type=guess_image_type($filename);
-
- logger('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes', LOGGER_DEBUG);
-
- $maximagesize = get_config('system','maximagesize');
-
- if(($maximagesize) && ($filesize > $maximagesize)) {
- notice( t('Image exceeds size limit of ') . $maximagesize . EOL);
- @unlink($src);
- $foo = 0;
- call_hooks('photo_post_end',$foo);
- return;
- }
-
- if(! $filesize) {
- notice( t('Image file is empty.') . EOL);
- @unlink($src);
- $foo = 0;
- call_hooks('photo_post_end',$foo);
- return;
- }
-
- logger('mod/photos.php: photos_post(): loading the contents of ' . $src , LOGGER_DEBUG);
-
- $imagedata = @file_get_contents($src);
-
-
-
- $r = q("select sum(size) as total from photo where uid = %d and scale = 0 ",
- intval($a->data['channel']['channel_id'])
- );
-
- $limit = service_class_fetch($a->data['channel']['channel_id'],'photo_upload_limit');
-
- if(($limit !== false) && (($r[0]['total'] + strlen($imagedata)) > $limit)) {
- notice( upgrade_message() . EOL );
- @unlink($src);
- $foo = 0;
- call_hooks('photo_post_end',$foo);
- killme();
- }
-
-
- $ph = new Photo($imagedata, $type);
-
- if(! $ph->is_valid()) {
- logger('mod/photos.php: photos_post(): unable to process image' , LOGGER_DEBUG);
- notice( t('Unable to process image.') . EOL );
- @unlink($src);
- $foo = 0;
- call_hooks('photo_post_end',$foo);
- killme();
- }
-
- $ph->orient($src);
- @unlink($src);
-
- $max_length = get_config('system','max_image_length');
- if(! $max_length)
- $max_length = MAX_IMAGE_LENGTH;
- if($max_length > 0)
- $ph->scaleImage($max_length);
-
- $width = $ph->getWidth();
- $height = $ph->getHeight();
-
- $smallest = 0;
-
- $photo_hash = photo_new_resource();
-
- $page_owner_aid = $a->data['channel']['channel_account_id'];
- $r = $ph->store($page_owner_aid, $page_owner_uid, $visitor, $photo_hash, $filename, $album, 0 , 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
-
- if(! $r) {
- logger('mod/photos.php: photos_post(): image store failed' , LOGGER_DEBUG);
- notice( t('Image upload failed.') . EOL );
- killme();
- }
-
- if($width > 640 || $height > 640) {
- $ph->scaleImage(640);
- $ph->store($page_owner_aid, $page_owner_uid, $visitor, $photo_hash, $filename, $album, 1, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
- $smallest = 1;
- }
-
- if($width > 320 || $height > 320) {
- $ph->scaleImage(320);
- $ph->store($page_owner_aid, $page_owner_uid, $visitor, $photo_hash, $filename, $album, 2, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
- $smallest = 2;
- }
-
- $basename = basename($filename);
- $uri = item_message_id();
-
-
- // Create item container
-
- $item_flags = ITEM_WALL|ITEM_ORIGIN|ITEM_THREAD_TOP;
- $item_restrict = (($visibility) ? ITEM_HIDDEN : ITEM_VISIBLE);
- $title = '';
- $uri = item_message_id();
-
- $arr = array();
-
- $arr['aid'] = $a->data['channel']['channel_account_id'];
- $arr['uid'] = $page_owner_uid;
- $arr['uri'] = $uri;
- $arr['parent_uri'] = $uri;
- $arr['item_flags'] = $item_flags;
- $arr['item_restrict'] = $item_restrict;
- $arr['resource_type'] = 'photo';
- $arr['resource_id'] = $photo_hash;
- $arr['owner_xchan'] = $a->data['channel']['channel_hash'];
- $arr['author_xchan'] = $a->data['channel']['channel_hash']; // FIXME for AUTH guests
- $arr['title'] = $title;
- $arr['allow_cid'] = $str_contact_allow;
- $arr['allow_gid'] = $str_group_allow;
- $arr['deny_cid'] = $str_contact_deny;
- $arr['deny_gid'] = $str_group_deny;
-
-
- $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/image/' . $photo_hash . ']'
- . '[img]' . $a->get_baseurl() . "/photo/{$photo_hash}-{$smallest}.".$ph->getExt() . '[/img]'
- . '[/url]';
-
- $item_id = item_store($arr);
-
- if($item_id) {
- q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1",
- dbesc($a->get_baseurl() . '/display/' . $owner_record['nickname'] . '/' . $item_id),
- intval($page_owner_uid),
- intval($item_id)
- );
- }
-
- if($visible)
- proc_run('php', "include/notifier.php", 'wall-new', $item_id);
-
- call_hooks('photo_post_end',intval($item_id));
-
- // addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook
- // if they do not wish to be redirected
+ $r = photo_upload($a->channel,$a->get_observer(), $_REQUEST);
+ if(! $r['success']) {
+ notice($r['message'] . EOL);
+ }
goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
- // NOTREACHED
+
}
diff --git a/version.inc b/version.inc
index 629a3deb4..c1c5fa011 100644
--- a/version.inc
+++ b/version.inc
@@ -1 +1 @@
-2013-01-31.217
+2013-02-01.218