Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
0f13ae0ade
@ -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) {
|
||||
|
||||
|
@ -635,7 +635,7 @@ function decode_tags($t) {
|
||||
$ret = array();
|
||||
foreach($t as $x) {
|
||||
$tag = array();
|
||||
$tag['term'] = htmlentities($x['term'], ENT_COMPAT,'UTF-8',false);
|
||||
$tag['term'] = htmlentities($x['tag'], ENT_COMPAT,'UTF-8',false);
|
||||
$tag['url'] = htmlentities($x['url'], ENT_COMPAT,'UTF-8',false);
|
||||
switch($x['type']) {
|
||||
case 'hashtag':
|
||||
|
@ -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;
|
||||
|
||||
}
|
@ -229,8 +229,10 @@ function zot_refresh($them,$channel = null) {
|
||||
|
||||
$j = json_decode($result['body'],true);
|
||||
|
||||
if(! (($j) && ($j['success'])))
|
||||
if(! (($j) && ($j['success']))) {
|
||||
logger('zot_refresh: result not decodable');
|
||||
return false;
|
||||
}
|
||||
|
||||
$x = import_xchan($j);
|
||||
|
||||
@ -548,10 +550,10 @@ function import_xchan($arr) {
|
||||
&& ($arr['site']['url'] != z_root()))
|
||||
$arr['searchable'] = false;
|
||||
|
||||
|
||||
$hidden = (1 - intval($arr['searchable']));
|
||||
|
||||
// Be careful - XCHAN_FLAGS_HIDDEN should evaluate to 1
|
||||
if(($r[0]['xchan_flags'] & XCHAN_FLAGS_HIDDEN) != $arr['searchable'])
|
||||
if(($r[0]['xchan_flags'] & XCHAN_FLAGS_HIDDEN) != $hidden)
|
||||
$new_flags = $r[0]['xchan_flags'] ^ XCHAN_FLAGS_HIDDEN;
|
||||
else
|
||||
$new_flags = $r[0]['xchan_flags'];
|
||||
|
@ -434,7 +434,7 @@ function item_post(&$a) {
|
||||
'uid' => $profile_uid,
|
||||
'type' => $success['termtype'],
|
||||
'otype' => TERM_OBJ_POST,
|
||||
'term' => substr($tag,1),
|
||||
'term' => $success['term'],
|
||||
'url' => $success['url']
|
||||
);
|
||||
}
|
||||
@ -853,7 +853,7 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag) {
|
||||
$str_tags .= ',';
|
||||
$str_tags .= $newtag;
|
||||
}
|
||||
return array('replaced' => $replaced, 'termtype' => $termtype, 'url' => $url, 'contact' => $r[0]);
|
||||
return array('replaced' => $replaced, 'termtype' => $termtype, 'term' => $basetag, 'url' => $url, 'contact' => $r[0]);
|
||||
}
|
||||
//is it a person tag?
|
||||
if(strpos($tag,'@') === 0) {
|
||||
@ -965,7 +965,7 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag) {
|
||||
}
|
||||
}
|
||||
|
||||
return array('replaced' => $replaced, 'termtype' => $termtype, 'url' => $url, 'contact' => $r[0]);
|
||||
return array('replaced' => $replaced, 'termtype' => $termtype, 'term' => $newname, 'url' => $url, 'contact' => $r[0]);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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;
|
||||
|
245
mod/photos.php
245
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
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -1 +1 @@
|
||||
2013-01-31.217
|
||||
2013-02-01.218
|
||||
|
@ -57,6 +57,7 @@ function connectForum() {
|
||||
$('#me_id_perms_view_storage').attr('checked','checked');
|
||||
$('#me_id_perms_view_pages').attr('checked','checked');
|
||||
$('#me_id_perms_send_stream').attr('checked','checked');
|
||||
$('#me_id_perms_post_wall').attr('checked','checked');
|
||||
$('#me_id_perms_post_comments').attr('checked','checked');
|
||||
$('#me_id_perms_post_mail').attr('checked','checked');
|
||||
$('#me_id_perms_tag_deliver').attr('checked','checked');
|
||||
|
Reference in New Issue
Block a user