aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorHaakon Meland Eriksen <haakon.eriksen@far.no>2015-08-27 17:57:59 +0200
committerHaakon Meland Eriksen <haakon.eriksen@far.no>2015-08-27 17:57:59 +0200
commit1b82fb7349a7a4048755d92e757efc5dc227b227 (patch)
treee614f70f830ed518b185f22203f42c91aea36db0 /include
parent092e7378cdaeefaa7b4a954bd865bba1960f01aa (diff)
parent7b28c42693ff41da61abe4974c7a0a7412b6d6e5 (diff)
downloadvolse-hubzilla-1b82fb7349a7a4048755d92e757efc5dc227b227.tar.gz
volse-hubzilla-1b82fb7349a7a4048755d92e757efc5dc227b227.tar.bz2
volse-hubzilla-1b82fb7349a7a4048755d92e757efc5dc227b227.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'include')
-rw-r--r--include/Contact.php3
-rw-r--r--include/api.php22
-rw-r--r--include/attach.php79
-rw-r--r--include/conversation.php13
-rw-r--r--include/event.php8
-rwxr-xr-xinclude/items.php4
-rw-r--r--include/photos.php150
-rw-r--r--include/session.php3
-rw-r--r--include/zot.php8
9 files changed, 216 insertions, 74 deletions
diff --git a/include/Contact.php b/include/Contact.php
index 6b5f9388c..008574d8f 100644
--- a/include/Contact.php
+++ b/include/Contact.php
@@ -174,9 +174,6 @@ function abook_toggle_flag($abook,$flag) {
);
}
- $a = get_app();
- if($a->data['abook'])
- $a->data['abook']['abook_flags'] = $a->data['abook']['abook_flags'] ^ $flag;
return $r;
}
diff --git a/include/api.php b/include/api.php
index 369992332..6d71cfc33 100644
--- a/include/api.php
+++ b/include/api.php
@@ -645,7 +645,27 @@ require_once('include/items.php');
if(array_key_exists('os_storage',$r[0]) && intval($r[0]['os_storage']))
$data = file_get_contents($data);
$r[0]['data'] = base64_encode($data);
- json_return_and_die($r[0]);
+ $ret = array('photo' => $r[0]);
+ $i = q("select id from item where uid = %d and resource_type = 'photo' and resource_id = '%s' limit 1",
+ intval(local_channel()),
+ dbesc($_REQUEST['photo_id'])
+ );
+ if($i) {
+ $ii = q("select * from item where parent = %d order by id",
+ intval($i[0]['id'])
+ );
+ if($ii) {
+ xchan_query($ii,true,0);
+ $ii = fetch_post_tags($ii,true);
+ if($ii) {
+ $ret['item'] = array();
+ foreach($ii as $iii)
+ $ret['item'][] = encode_item($iii,true);
+ }
+ }
+ }
+
+ json_return_and_die($ret);
}
killme();
}
diff --git a/include/attach.php b/include/attach.php
index 71fad86a8..620c7620c 100644
--- a/include/attach.php
+++ b/include/attach.php
@@ -414,9 +414,19 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
$hash = (($arr && $arr['hash']) ? $arr['hash'] : null);
$upload_path = (($arr && $arr['directory']) ? $arr['directory'] : '');
- logger('arr: ' . print_r($arr,true));
+ $observer = array();
- if(! perm_is_allowed($channel_id,get_observer_hash(), 'write_storage')) {
+ if($observer_hash) {
+ $x = q("select * from xchan where xchan_hash = '%s' limit 1",
+ dbesc($observer_hash)
+ );
+ if($x)
+ $observer = $x[0];
+ }
+
+ logger('arr: ' . print_r($arr,true));
+
+ if(! perm_is_allowed($channel_id,$observer_hash, 'write_storage')) {
$ret['message'] = t('Permission denied.');
return $ret;
}
@@ -434,7 +444,13 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
// revise or update must provide $arr['hash'] of the thing to revise/update
- if($options !== 'update') {
+ if($options === 'import') {
+ $src = $arr['src'];
+ $filename = $arr['filename'];
+ $filesize = @filesize($src);
+ $hash = $arr['resource_id'];
+ }
+ elseif($options !== 'update') {
if(! x($_FILES,'userfile')) {
$ret['message'] = t('No source file.');
return $ret;
@@ -480,12 +496,19 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
-
+ $def_extension = '';
$is_photo = 0;
$gis = @getimagesize($src);
logger('getimagesize: ' . print_r($gis,true), LOGGER_DATA);
if(($gis) && ($gis[2] === IMAGETYPE_GIF || $gis[2] === IMAGETYPE_JPEG || $gis[2] === IMAGETYPE_PNG)) {
$is_photo = 1;
+ if($gis[2] === IMAGETYPE_GIF)
+ $def_extension = '.gif';
+ if($gis[2] === IMAGETYPE_JPEG)
+ $def_extension = '.jpg';
+ if($gis[2] === IMAGETYPE_PNG)
+ $def_extension = '.png';
+
}
$pathname = '';
@@ -527,7 +550,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
$folder_hash = '';
}
- if(! $options) {
+ if((! $options) || ($options === 'import')) {
// A freshly uploaded file. Check for duplicate and resolve with the channel's overwrite settings.
@@ -544,9 +567,18 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
$hash = $x[0]['hash'];
}
else {
+ if(strpos($filename,'.') !== false) {
+ $basename = substr($filename,0,strrpos($filename,'.'));
+ $ext = substr($filename,strrpos($filename,'.'));
+ }
+ else {
+ $basename = $filename;
+ $ext = $def_extension;
+ }
+
$r = q("select filename from attach where ( filename = '%s' OR filename like '%s' ) and folder = '%s' ",
- dbesc($filename),
- dbesc($filename . '(%)'),
+ dbesc($basename . $ext),
+ dbesc($basename . '(%)' . $ext),
dbesc($folder_hash)
);
@@ -556,7 +588,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
do {
$found = false;
foreach($r as $rr) {
- if($rr['filename'] === $filename . '(' . $x . ')') {
+ if($rr['filename'] === $basename . '(' . $x . ')' . $ext) {
$found = true;
break;
}
@@ -565,8 +597,10 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
$x++;
}
while($found);
- $filename = $filename . '(' . $x . ')';
+ $filename = $basename . '(' . $x . ')' . $ext;
}
+ else
+ $filename = $basename . $ext;
}
}
}
@@ -614,7 +648,16 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
if($src)
@file_put_contents($os_basepath . $os_relpath,@file_get_contents($src));
- $created = datetime_convert();
+ if(array_key_exists('created', $arr))
+ $created = $arr['created'];
+ else
+ $created = datetime_convert();
+
+ if(array_key_exists('edited', $arr))
+ $edited = $arr['edited'];
+ else
+ $edited = $created;
+
if($options === 'replace') {
$r = q("update attach set filename = '%s', filetype = '%s', folder = '%s', filesize = %d, os_storage = %d, is_photo = %d, data = '%s', edited = '%s' where id = %d and uid = %d",
@@ -704,7 +747,21 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
$args['contact_deny'] = $arr['contact_deny'];
if($arr['group_deny'])
$args['group_deny'] = $arr['group_deny'];
- $p = photo_upload($channel,get_app()->get_observer(),$args);
+ if(array_key_exists('allow_cid',$arr))
+ $args['allow_cid'] = $arr['allow_cid'];
+ if(array_key_exists('allow_gid',$arr))
+ $args['allow_gid'] = $arr['allow_gid'];
+ if(array_key_exists('deny_cid',$arr))
+ $args['deny_cid'] = $arr['deny_cid'];
+ if(array_key_exists('deny_gid',$arr))
+ $args['deny_gid'] = $arr['deny_gid'];
+
+ $args['created'] = $created;
+ $args['edited'] = $edited;
+ if($arr['item'])
+ $args['item'] = $arr['item'];
+
+ $p = photo_upload($channel,$observer,$args);
if($p['success']) {
$ret['body'] = $p['body'];
}
diff --git a/include/conversation.php b/include/conversation.php
index e58429255..a3fdf39df 100644
--- a/include/conversation.php
+++ b/include/conversation.php
@@ -395,7 +395,9 @@ function count_descendants($item) {
* @brief Check if the activity of the item is visible.
*
* likes (etc.) can apply to other things besides posts. Check if they are post
- * children, in which case we handle them specially.
+ * children, in which case we handle them specially. Activities which are unrecognised
+ * as having special meaning and hidden will be treated as posts or comments and visible
+ * in the stream.
*
* @param array $item
* @return boolean
@@ -403,12 +405,21 @@ function count_descendants($item) {
function visible_activity($item) {
$hidden_activities = array(ACTIVITY_LIKE, ACTIVITY_DISLIKE, ACTIVITY_AGREE, ACTIVITY_DISAGREE, ACTIVITY_ABSTAIN, ACTIVITY_ATTEND, ACTIVITY_ATTENDNO, ACTIVITY_ATTENDMAYBE);
+ $post_types = array(ACTIVITY_OBJ_NOTE,ACTIVITY_OBJ_COMMENT,basename(ACTIVITY_OBJ_NOTE),basename(ACTIVITY_OBJ_COMMENT));
+
foreach ($hidden_activities as $act) {
if ((activity_match($item['verb'], $act)) && ($item['mid'] != $item['parent_mid'])) {
return false;
}
}
+ // In order to share edits with networks which have no concept of editing, we'll create
+ // separate activities to indicate the edit. Our network will not require them, since our
+ // edits are automatically applied and the activity indicated.
+
+ if(($item['verb'] === ACTIVITY_UPDATE) && (in_array($item['obj_type'],$post_types)))
+ return false;
+
return true;
}
diff --git a/include/event.php b/include/event.php
index c468420c0..6670bc53b 100644
--- a/include/event.php
+++ b/include/event.php
@@ -778,7 +778,12 @@ function event_store_item($arr, $event) {
$private = (($arr['allow_cid'] || $arr['allow_gid'] || $arr['deny_cid'] || $arr['deny_gid']) ? 1 : 0);
- q("UPDATE item SET title = '%s', body = '%s', object = '%s', allow_cid = '%s', allow_gid = '%s', deny_cid = '%s', deny_gid = '%s', edited = '%s', item_flags = %d, item_private = %d, obj_type = '%s' WHERE id = %d AND uid = %d",
+ // @FIXME can only update sig if we have the author's channel on this site
+ // Until fixed, set it to nothing so it won't give us signature errors
+
+ $sig = '';
+
+ q("UPDATE item SET title = '%s', body = '%s', object = '%s', allow_cid = '%s', allow_gid = '%s', deny_cid = '%s', deny_gid = '%s', edited = '%s', sig = '%s', item_flags = %d, item_private = %d, obj_type = '%s' WHERE id = %d AND uid = %d",
dbesc($arr['summary']),
dbesc($prefix . format_event_bbcode($arr)),
dbesc($object),
@@ -787,6 +792,7 @@ function event_store_item($arr, $event) {
dbesc($arr['deny_cid']),
dbesc($arr['deny_gid']),
dbesc($arr['edited']),
+ dbesc($sig),
intval($r[0]['item_flags']),
intval($private),
dbesc(ACTIVITY_OBJ_EVENT),
diff --git a/include/items.php b/include/items.php
index 0079e0e55..2701c3fa2 100755
--- a/include/items.php
+++ b/include/items.php
@@ -272,6 +272,8 @@ function can_comment_on_post($observer_xchan, $item) {
}
if(strstr($item['comment_policy'],'network:') && strstr($item['comment_policy'],'red'))
return true;
+ if(strstr($item['comment_policy'],'network:') && strstr($item['comment_policy'],'diaspora'))
+ return true;
if(strstr($item['comment_policy'],'site:') && strstr($item['comment_policy'],get_app()->get_hostname()))
return true;
@@ -4366,7 +4368,7 @@ function delete_item_lowlevel($item, $stage = DROPITEM_NORMAL, $force = false) {
);
}
else {
- $r = q("UPDATE item set item_deleted = 1, changed = '%s', edited = '%s' where if = %d",
+ $r = q("UPDATE item set item_deleted = 1, changed = '%s', edited = '%s' where id = %d",
dbesc(datetime_convert()),
dbesc(datetime_convert()),
intval($item['id'])
diff --git a/include/photos.php b/include/photos.php
index cb7fabc98..04018ac0d 100644
--- a/include/photos.php
+++ b/include/photos.php
@@ -52,12 +52,21 @@ function photo_upload($channel, $observer, $args) {
// Set to default channel permissions. If the parent directory (album) has permissions set,
// use those instead. If we have specific permissions supplied, they take precedence over
- // all other settings.
-
- $str_group_allow = $channel['channel_allow_gid'];
- $str_contact_allow = $channel['channel_allow_cid'];
- $str_group_deny = $channel['channel_deny_gid'];
- $str_contact_deny = $channel['channel_deny_cid'];
+ // all other settings. 'allow_cid' being passed from an external source takes priority over channel settings.
+ // ...messy... needs re-factoring once the photos/files integration stabilises
+
+ if(array_key_exists('allow_cid',$args)) {
+ $str_group_allow = $args['allow_gid'];
+ $str_contact_allow = $args['allow_cid'];
+ $str_group_deny = $args['deny_gid'];
+ $str_contact_deny = $args['deny_cid'];
+ }
+ else {
+ $str_group_allow = $channel['channel_allow_gid'];
+ $str_contact_allow = $channel['channel_allow_cid'];
+ $str_group_deny = $channel['channel_deny_gid'];
+ $str_contact_deny = $channel['channel_deny_cid'];
+ }
if($args['directory']) {
$str_group_allow = $args['directory']['allow_gid'];
@@ -261,62 +270,105 @@ function photo_upload($channel, $observer, $args) {
}
}
- $title = '';
- $mid = item_message_id();
+ if($args['item']) {
+ foreach($args['item'] as $i) {
- $arr = array();
+ $item = get_item_elements($i);
+ $force = false;
- if($lat && $lon)
- $arr['coord'] = $lat . ' ' . $lon;
-
- $arr['aid'] = $account_id;
- $arr['uid'] = $channel_id;
- $arr['mid'] = $mid;
- $arr['parent_mid'] = $mid;
- $arr['item_hidden'] = $item_hidden;
- $arr['resource_type'] = 'photo';
- $arr['resource_id'] = $photo_hash;
- $arr['owner_xchan'] = $channel['channel_hash'];
- $arr['author_xchan'] = $observer['xchan_hash'];
- $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['verb'] = ACTIVITY_POST;
- $arr['item_wall'] = 1;
- $arr['item_origin'] = 1;
- $arr['item_thread_top'] = 1;
+ if($item['mid'] === $item['parent_mid']) {
- $arr['plink'] = z_root() . '/channel/' . $channel['channel_address'] . '/?f=&mid=' . $arr['mid'];
+ $item['body'] = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo_hash . ']'
+ . $tag . z_root() . "/photo/{$photo_hash}-{$smallest}.".$ph->getExt() . '[/zmg]'
+ . '[/zrl]';
- // We should also put a width_x_height on large photos. Left as an exercise for
- // devs looking fo simple stuff to fix.
+ if($item['author_xchan'] === $channel['channel_hash']) {
+ $item['sig'] = base64url_encode(rsa_sign($item['body'],$channel['channel_prvkey']));
+ $item['item_verified'] = 1;
+ }
+ else {
+ $item['sig'] = '';
+ }
+ $force = true;
- $larger = feature_enabled($channel['channel_id'], 'large_photos');
- if($larger) {
- $tag = '[zmg]';
- if($r2)
- $smallest = 1;
- else
- $smallest = 0;
+ }
+ $r = q("select id, edited from item where mid = '%s' and uid = %d limit 1",
+ dbesc($item['mid']),
+ intval($channel['channel_id'])
+ );
+ if($r) {
+ if(($item['edited'] > $r[0]['edited']) || $force) {
+ $item['id'] = $r[0]['id'];
+ $item['uid'] = $channel['channel_id'];
+ item_store_update($item);
+ continue;
+ }
+ }
+ else {
+ $item['aid'] = $channel['channel_account_id'];
+ $item['uid'] = $channel['channel_id'];
+ $item_result = item_store($item);
+ }
+ }
}
else {
- if ($width_x_height)
- $tag = '[zmg=' . $width_x_height. ']';
- else
+ $title = '';
+ $mid = item_message_id();
+
+ $arr = array();
+
+ if($lat && $lon)
+ $arr['coord'] = $lat . ' ' . $lon;
+
+ $arr['aid'] = $account_id;
+ $arr['uid'] = $channel_id;
+ $arr['mid'] = $mid;
+ $arr['parent_mid'] = $mid;
+ $arr['item_hidden'] = $item_hidden;
+ $arr['resource_type'] = 'photo';
+ $arr['resource_id'] = $photo_hash;
+ $arr['owner_xchan'] = $channel['channel_hash'];
+ $arr['author_xchan'] = $observer['xchan_hash'];
+ $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['verb'] = ACTIVITY_POST;
+ $arr['item_wall'] = 1;
+ $arr['item_origin'] = 1;
+ $arr['item_thread_top'] = 1;
+
+ $arr['plink'] = z_root() . '/channel/' . $channel['channel_address'] . '/?f=&mid=' . $arr['mid'];
+
+ // We should also put a width_x_height on large photos. Left as an exercise for
+ // devs looking for simple stuff to fix.
+
+ $larger = feature_enabled($channel['channel_id'], 'large_photos');
+ if($larger) {
$tag = '[zmg]';
- }
+ if($r2)
+ $smallest = 1;
+ else
+ $smallest = 0;
+ }
+ else {
+ if ($width_x_height)
+ $tag = '[zmg=' . $width_x_height. ']';
+ else
+ $tag = '[zmg]';
+ }
- $arr['body'] = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo_hash . ']'
+ $arr['body'] = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo_hash . ']'
. $tag . z_root() . "/photo/{$photo_hash}-{$smallest}.".$ph->getExt() . '[/zmg]'
. '[/zrl]';
- $result = item_store($arr);
- $item_id = $result['item_id'];
+ $result = item_store($arr);
+ $item_id = $result['item_id'];
- if($visible)
- proc_run('php', "include/notifier.php", 'wall-new', $item_id);
+ if($visible)
+ proc_run('php', "include/notifier.php", 'wall-new', $item_id);
+ }
$ret['success'] = true;
$ret['item'] = $arr;
diff --git a/include/session.php b/include/session.php
index 31b3f0614..92004bc18 100644
--- a/include/session.php
+++ b/include/session.php
@@ -98,9 +98,6 @@ function ref_session_destroy ($id) {
function ref_session_gc($expire) {
q("DELETE FROM session WHERE expire < %d", dbesc(time()));
- if (! get_config('system', 'innodb'))
- db_optimizetable('session');
-
return true;
}
diff --git a/include/zot.php b/include/zot.php
index 17330838b..4cc22ac12 100644
--- a/include/zot.php
+++ b/include/zot.php
@@ -294,12 +294,12 @@ function zot_refresh($them, $channel = null, $force = false) {
if ($them['hubloc_url']) {
$url = $them['hubloc_url'];
} else {
- $r = q("select hubloc_url, hubloc_flags from hubloc where hubloc_hash = '%s'",
+ $r = q("select hubloc_url, hubloc_primary from hubloc where hubloc_hash = '%s'",
dbesc($them['xchan_hash'])
);
if ($r) {
foreach ($r as $rr) {
- if ($rr['hubloc_flags'] & HUBLOC_FLAGS_PRIMARY) {
+ if (intval($rr['hubloc_primary'])) {
$url = $rr['hubloc_url'];
break;
}
@@ -2207,7 +2207,7 @@ function sync_locations($sender, $arr, $absolute = false) {
dbesc(datetime_convert()),
intval($r[0]['hubloc_id'])
);
- $r[0]['hubloc_flags'] = $r[0]['hubloc_flags'] ^ HUBLOC_FLAGS_PRIMARY;
+ $r[0]['hubloc_primary'] = intval($location['primary']);
hubloc_change_primary($r[0]);
$what .= 'primary_hub ';
$changed = true;
@@ -2911,6 +2911,7 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) {
$total_feeds ++;
}
+
$disallowed = array('abook_id','abook_account','abook_channel','abook_rating','abook_rating_text');
foreach($arr['abook'] as $abook) {
@@ -2999,7 +3000,6 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) {
foreach($clean as $k => $v) {
if($k == 'abook_dob')
$v = dbescdate($v);
-
$r = dbq("UPDATE abook set " . dbesc($k) . " = '" . dbesc($v)
. "' where abook_xchan = '" . dbesc($clean['abook_xchan']) . "' and abook_channel = " . intval($channel['channel_id']));
}