aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/attach.php200
-rw-r--r--include/bbcode.php135
-rw-r--r--include/channel.php2
-rw-r--r--include/conversation.php16
-rw-r--r--include/event.php2
-rwxr-xr-xinclude/items.php10
-rw-r--r--include/network.php4
-rw-r--r--include/photos.php4
-rw-r--r--include/text.php12
-rw-r--r--include/zid.php5
-rw-r--r--include/zot.php2
11 files changed, 355 insertions, 37 deletions
diff --git a/include/attach.php b/include/attach.php
index d986f4af1..80f71b9ea 100644
--- a/include/attach.php
+++ b/include/attach.php
@@ -12,6 +12,9 @@
*/
use Zotlabs\Lib\Libsync;
+use Zotlabs\Lib\Activity;
+use Zotlabs\Access\PermissionLimits;
+use Zotlabs\Daemon\Master;
require_once('include/permissions.php');
require_once('include/security.php');
@@ -1024,9 +1027,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) {
}
if($notify) {
- $cloudPath = z_root() . '/cloud/' . $channel['channel_address'] . '/' . $r['0']['display_path'];
- $object = get_file_activity_object($channel['channel_id'], $r['0']['hash'], $cloudPath);
- file_activity($channel['channel_id'], $object, $r['0']['allow_cid'], $r['0']['allow_gid'], $r['0']['deny_cid'], $r['0']['deny_gid'], 'post', $notify);
+ attach_store_item($channel, $observer, $r[0]);
}
return $ret;
@@ -1452,9 +1453,6 @@ function attach_delete($channel_id, $resource, $is_photo = 0) {
return;
}
- $url = get_cloud_url($channel_id, $channel_address, $resource);
- $object = get_file_activity_object($channel_id, $resource, $url);
-
// If resource is a directory delete everything in the directory recursive
if(intval($r[0]['is_dir'])) {
$x = q("SELECT hash, os_storage, is_dir, flags FROM attach WHERE folder = '%s' AND uid = %d",
@@ -1498,6 +1496,9 @@ function attach_delete($channel_id, $resource, $is_photo = 0) {
if($r[0]['is_photo']) {
attach_drop_photo($channel_id,$resource);
}
+ else {
+ attach_drop_item($channel_id,$resource);
+ }
// update the parent folder's lastmodified timestamp
@@ -1517,8 +1518,6 @@ function attach_delete($channel_id, $resource, $is_photo = 0) {
*/
call_hooks('attach_delete', $arr);
- file_activity($channel_id, $object, $object['allow_cid'], $object['allow_gid'], $object['deny_cid'], $object['deny_gid'], 'update', true);
-
return;
}
@@ -1553,6 +1552,21 @@ function attach_drop_photo($channel_id,$resource) {
}
+function attach_drop_item($channel_id,$resource) {
+
+ $x = q("select id, item_hidden from item where resource_id = '%s' and resource_type = 'attach' and uid = %d and item_deleted = 0",
+ dbesc($resource),
+ intval($channel_id)
+ );
+
+ if($x) {
+ $stage = (($x[0]['item_hidden']) ? DROPITEM_NORMAL : DROPITEM_PHASE1);
+ $interactive = (($x[0]['item_hidden']) ? false : true);
+ drop_item($x[0]['id'], $interactive, $stage);
+ }
+
+}
+
/**
* @brief Returns path to file in cloud/.
@@ -1754,6 +1768,7 @@ function pipe_streams($in, $out, $bufsize = 16384) {
* @param string $verb
* @param boolean $notify
*/
+/*
function file_activity($channel_id, $object, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $verb, $notify) {
require_once('include/items.php');
@@ -1802,7 +1817,7 @@ function file_activity($channel_id, $object, $allow_cid, $allow_gid, $deny_cid,
$uuid = item_message_id();
$mid = z_root() . '/item/' . $uuid;
- $objtype = ACTIVITY_OBJ_FILE;
+ $objtype = 'ACTIVITY_OBJ_FILE';
$arr = array();
$arr['aid'] = get_account_id();
@@ -1901,6 +1916,148 @@ function file_activity($channel_id, $object, $allow_cid, $allow_gid, $deny_cid,
return;
}
+*/
+
+
+function attach_store_item($channel, $observer, $file) {
+
+
+ if(is_string($file)) {
+ $r = q("SELECT * FROM attach WHERE uid = %d AND hash = '%s' LIMIT 1",
+ intval($channel['channel_id']),
+ dbesc($file)
+ );
+
+ if(! $r)
+ return;
+
+ $file = $r[0];
+
+ }
+
+ $path = z_root() . '/cloud/' . $channel['channel_address'] . '/' . $file['display_path'];
+
+ $r = q("SELECT * FROM item WHERE resource_id = '%s' AND resource_type = 'attach' and uid = %d LIMIT 1",
+ dbesc($file['hash']),
+ intval($channel['channel_id'])
+ );
+
+ if($r) {
+
+ // At the moment only file permission edits are possible.
+ // Since we do not support permission editing on posts yet,
+ // we will delete the item and create a new one with the new permissions for now.
+
+ if($r[0]['allow_cid'] === $file['allow_cid'] && $r[0]['allow_gid'] === $file['allow_gid'] && $r[0]['deny_cid'] === $file['deny_cid'] && $r[0]['deny_gid'] === $file['deny_gid']) {
+
+ /* once possible, other edits (eg rename) can be done here.
+
+ q("UPDATE item SET title = '%s' WHERE id = %d AND uid = %d",
+ dbesc($file['filename'])
+ );
+
+ $meta = [
+ 'name' => $file['filename'],
+ 'type' => $file['filetype'],
+ 'size' => $file['filesize'],
+ 'revision' => $file['revision'],
+ 'size' => $file['filesize'],
+ 'created' => $file['created'],
+ 'edited' => $file['edited'],
+ 'path' => $path
+ ];
+
+ set_iconfig($r[0], 'attach', 'meta' , $meta, true);
+
+ $post = item_store($arr);
+
+ $item_id = $post['item_id'];
+
+ if($item_id) {
+ Master::Summon(['Notifier', 'activity', $item_id]);
+ }
+
+ */
+
+ return;
+
+ }
+
+ $stage = (($r[0]['item_hidden']) ? DROPITEM_NORMAL : DROPITEM_PHASE1);
+ $interactive = (($r[0]['item_hidden']) ? false : true);
+ drop_item($r[0]['id'], $interactive, $stage);
+
+ }
+
+ $filetype_parts = explode('/', $file['filetype']);
+
+ switch($filetype_parts[0]) {
+ case 'image':
+ $type = 'Image';
+ break;
+ case 'audio':
+ $type = 'Audio';
+ break;
+ case 'video':
+ $type = 'Video';
+ break;
+ default:
+ $type = 'Document';
+ }
+
+ $resource_id = $file['hash'];
+ $uuid = new_uuid();
+
+ $mid = z_root() . '/item/' . $uuid;
+
+ $arr = []; // Initialize the array of parameters for the post
+ $arr['aid'] = $channel['channel_account_id'];
+ $arr['uuid'] = $uuid;
+ $arr['uid'] = $channel['channel_id'];
+ $arr['mid'] = $mid;
+ $arr['parent_mid'] = $mid;
+ $arr['resource_type'] = 'attach';
+ $arr['resource_id'] = $resource_id;
+ $arr['owner_xchan'] = $channel['channel_hash'];
+ $arr['author_xchan'] = $observer['xchan_hash'];
+ $arr['title'] = $file['filename'];
+ $arr['allow_cid'] = $file['allow_cid'];
+ $arr['allow_gid'] = $file['allow_gid'];
+ $arr['deny_cid'] = $file['deny_cid'];
+ $arr['deny_gid'] = $file['deny_gid'];
+ $arr['item_wall'] = 1;
+ $arr['item_origin'] = 1;
+ $arr['item_thread_top'] = 1;
+ $arr['item_private'] = (($file['allow_cid'] || $file['allow_gid'] || $file['deny_cid'] || $file['deny_gid']) ? 1 : 0);
+ $arr['verb'] = ACTIVITY_CREATE;
+ $arr['obj_type'] = $type;
+ $arr['title'] = $file['filename'];
+ $body_str = sprintf(t('%s shared a %s with you'), '[zrl=' . $observer['xchan_url'] . ']' . $observer['xchan_name'] . '[/zrl]', '[zrl=' . $path . ']' . t('file') . '[/zrl]');
+ $arr['body'] = $body_str;
+
+ $meta = [
+ 'name' => $file['filename'],
+ 'type' => $file['filetype'],
+ 'size' => $file['filesize'],
+ 'revision' => $file['revision'],
+ 'size' => $file['filesize'],
+ 'created' => $file['created'],
+ 'edited' => $file['edited'],
+ 'path' => $path
+ ];
+
+ set_iconfig($arr, 'attach', 'meta' , $meta, true);
+
+ $post = item_store($arr);
+
+ $item_id = $post['item_id'];
+
+ if($item_id) {
+ Master::Summon(['Notifier', 'activity', $item_id]);
+ }
+
+}
+
/**
* @brief Create file activity object.
@@ -1917,17 +2074,28 @@ function get_file_activity_object($channel_id, $hash, $url) {
dbesc($hash)
);
- $url = rawurlencode($url);
-
- $links = array();
- $links[] = array(
+ $links = [];
+ $links[] = [
'rel' => 'alternate',
- 'type' => 'text/html',
+ 'type' => $x[0]['filetype'],
'href' => $url
- );
+ ];
+
+ $filetype_parts = explode('/', $x[0]['filetype']);
+
+ switch($filetype_parts[0]) {
+ case 'audio':
+ $type = 'Audio';
+ break;
+ case 'video':
+ $type = 'Video';
+ break;
+ default:
+ $type = 'Document';
+ }
$object = array(
- 'type' => ACTIVITY_OBJ_FILE,
+ 'type' => $type,
'title' => $x[0]['filename'],
'id' => $url,
'link' => $links,
diff --git a/include/bbcode.php b/include/bbcode.php
index b2e3f1d3b..e846e38db 100644
--- a/include/bbcode.php
+++ b/include/bbcode.php
@@ -319,6 +319,139 @@ function translate_design_element($type) {
return $ret;
}
+function bb_format_attachdata($body) {
+
+ $data = getAttachmentData($body);
+
+ if($data) {
+ $txt = '';
+ if($data['url'] && $data['title']) {
+ $txt .= "\n\n" . '[url=' . $data['url'] . ']' . $data['title'] . '[/url]';
+ }
+ else {
+ if($data['url']) {
+ $txt .= "\n\n" . $data['url'];
+ }
+ if($data['title']) {
+ $txt .= "\n\n" . $data['title'];
+ }
+ }
+ if($data['preview']) {
+ $txt .= "\n\n" . '[img]' . $data['preview'] . '[/img]';
+ }
+ if($data['image']) {
+ $txt .= "\n\n" . '[img]' . $data['image'] . '[/img]';
+ }
+
+
+ $txt .= "\n\n" . $data['text'];
+ return preg_replace('/\[attachment(.*?)\](.*?)\[\/attachment\]/ism',$txt,$body);
+ }
+
+ return $body;
+}
+
+function getAttachmentData($body) {
+
+ $data = [];
+
+ if (! preg_match("/\[attachment(.*?)\](.*?)\[\/attachment\]/ism", $body, $match)) {
+ return null;
+ }
+
+ $attributes = $match[1];
+
+ $data["text"] = trim($match[2]);
+
+ $type = "";
+ preg_match("/type='(.*?)'/ism", $attributes, $matches);
+
+ if (x($matches, 1)) {
+ $type = strtolower($matches[1]);
+ }
+
+ preg_match('/type=\&quot\;(.*?)\&quot\;/ism', $attributes, $matches);
+ if (x($matches, 1)) {
+ $type = strtolower($matches[1]);
+ }
+
+ if ($type == "") {
+ return [];
+ }
+
+ if (!in_array($type, ["link", "audio", "photo", "video"])) {
+ return [];
+ }
+
+ if ($type != "") {
+ $data["type"] = $type;
+ }
+ $url = "";
+ preg_match("/url='(.*?)'/ism", $attributes, $matches);
+ if (x($matches, 1)) {
+ $url = $matches[1];
+ }
+
+ preg_match('/url=\&quot\;(.*?)\&quot\;/ism', $attributes, $matches);
+ if (x($matches, 1)) {
+ $url = $matches[1];
+ }
+
+ if ($url != "") {
+ $data["url"] = html_entity_decode($url, ENT_QUOTES, 'UTF-8');
+ }
+
+ $title = "";
+ preg_match("/title='(.*?)'/ism", $attributes, $matches);
+ if (x($matches, 1)) {
+ $title = $matches[1];
+ }
+
+ preg_match('/title=\&quot\;(.*?)\&quot\;/ism', $attributes, $matches);
+ if (x($matches, 1)) {
+ $title = $matches[1];
+ }
+ if ($title != "") {
+ $title = html_entity_decode($title, ENT_QUOTES, 'UTF-8');
+ $title = str_replace(["[", "]"], ["[", "]"], $title);
+ $data["title"] = $title;
+ }
+
+ $image = "";
+ preg_match("/image='(.*?)'/ism", $attributes, $matches);
+ if (x($matches, 1)) {
+ $image = $matches[1];
+ }
+
+ preg_match('/image=\&quot\;(.*?)\&quot\;/ism', $attributes, $matches);
+ if (x($matches, 1)) {
+ $image = $matches[1];
+ }
+
+ if ($image != "") {
+ $data["image"] = html_entity_decode($image, ENT_QUOTES, 'UTF-8');
+ }
+
+ $preview = "";
+ preg_match("/preview='(.*?)'/ism", $attributes, $matches);
+ if (x($matches, 1)) {
+ $preview = $matches[1];
+ }
+
+ preg_match('/preview=\&quot\;(.*?)\&quot\;/ism', $attributes, $matches);
+ if (x($matches, 1)) {
+ $preview = $matches[1];
+ }
+ if ($preview != "") {
+ $data["preview"] = html_entity_decode($preview, ENT_QUOTES, 'UTF-8');
+ }
+
+ $data["description"] = trim($match[3]);
+
+ $data["after"] = trim($match[4]);
+
+ return $data;
+}
function bb_ShareAttributes($match) {
@@ -935,6 +1068,8 @@ function bbcode($Text, $options = []) {
$Text = preg_replace_callback("/\[pre\](.*?)\[\/pre\]/ism", 'bb_spacefy',$Text);
}
+ $Text = bb_format_attachdata($Text);
+
// If we find any event code, turn it into an event.
// After we're finished processing the bbcode we'll
// replace all of the event code with a reformatted version.
diff --git a/include/channel.php b/include/channel.php
index be58f154a..742d9e3a7 100644
--- a/include/channel.php
+++ b/include/channel.php
@@ -1930,7 +1930,7 @@ function zid_init() {
Master::Summon(array('Gprobe',bin2hex($tmp_str)));
}
if($r) {
- $r = zot_record_preferred($r);
+ $r = Libzot::zot_record_preferred($r);
}
if($r && remote_channel() && remote_channel() === $r['hubloc_hash'])
return;
diff --git a/include/conversation.php b/include/conversation.php
index 49dd411fb..b0e81b7e2 100644
--- a/include/conversation.php
+++ b/include/conversation.php
@@ -423,10 +423,18 @@ function visible_activity($item) {
}
}
-
-
- if(is_edit_activity($item))
- return false;
+ // We only need edit activities for other federated protocols
+ // which do not support edits natively. While this does federate
+ // edits, it presents a number of issues locally - such as #757 and #758.
+ // The SQL check for an edit activity would not perform that well so to fix these issues
+ // requires an additional item flag (perhaps 'item_edit_activity') that we can add to the
+ // query for searches and notifications.
+
+ // For now we'll just forget about trying to make edits work on network protocols that
+ // don't support them.
+
+ // if(is_edit_activity($item))
+ // return false;
return true;
}
diff --git a/include/event.php b/include/event.php
index 6161175f6..82f6ca81e 100644
--- a/include/event.php
+++ b/include/event.php
@@ -1275,7 +1275,7 @@ function event_store_item($arr, $event) {
// otherwise we'll fallback to /display/$message_id
if($wall)
- $item_arr['plink'] = z_root() . '/channel/' . $z[0]['channel_address'] . '/?f=&mid=' . gen_link_id($item_arr['mid']);
+ $item_arr['plink'] = $item_arr['mid'];
else
$item_arr['plink'] = z_root() . '/display/' . gen_link_id($item_arr['mid']);
diff --git a/include/items.php b/include/items.php
index 6fe5e1f0b..87ae5c6a5 100755
--- a/include/items.php
+++ b/include/items.php
@@ -239,19 +239,19 @@ function comments_are_now_closed($item) {
function item_normal() {
return " and item.item_hidden = 0 and item.item_type = 0 and item.item_deleted = 0
and item.item_unpublished = 0 and item.item_delayed = 0 and item.item_pending_remove = 0
- and item.item_blocked = 0 and item.obj_type != '" . ACTIVITY_OBJ_FILE . "' ";
+ and item.item_blocked = 0 ";
}
function item_normal_search() {
return " and item.item_hidden = 0 and item.item_type in (0,3,6,7) and item.item_deleted = 0
and item.item_unpublished = 0 and item.item_delayed = 0 and item.item_pending_remove = 0
- and item.item_blocked = 0 and item.obj_type != '" . ACTIVITY_OBJ_FILE . "' ";
+ and item.item_blocked = 0 ";
}
function item_normal_update() {
return " and item.item_hidden = 0 and item.item_type = 0
and item.item_unpublished = 0 and item.item_delayed = 0 and item.item_pending_remove = 0
- and item.item_blocked = 0 and item.obj_type != '" . ACTIVITY_OBJ_FILE . "' ";
+ and item.item_blocked = 0 ";
}
@@ -267,7 +267,7 @@ function is_item_normal($item) {
if(intval($item['item_hidden']) || intval($item['item_type']) || intval($item['item_deleted'])
|| intval($item['item_unpublished']) || intval($item['item_delayed']) || intval($item['item_pending_remove'])
- || intval($item['item_blocked']) || ($item['obj_type'] == ACTIVITY_OBJ_FILE))
+ || intval($item['item_blocked']))
return false;
return true;
@@ -423,7 +423,7 @@ function post_activity_item($arr, $allow_code = false, $deliver = true) {
if(! array_key_exists('item_origin',$arr))
$arr['item_origin'] = 1;
if(! array_key_exists('item_wall',$arr) && (! $is_comment))
- $arr['item_wall'] = 1;
+ $arr['item_wall'] = 0;
if(! array_key_exists('item_thread_top',$arr) && (! $is_comment))
$arr['item_thread_top'] = 1;
diff --git a/include/network.php b/include/network.php
index c2edb4f8a..80d19797b 100644
--- a/include/network.php
+++ b/include/network.php
@@ -61,7 +61,8 @@ function z_fetch_url($url, $binary = false, $redirects = 0, $opts = array()) {
@curl_setopt($ch, CURLOPT_CAINFO, get_capath());
@curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
@curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
- @curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; zot)");
+ @curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; zot)');
+ @curl_setopt($ch, CURLOPT_ENCODING, '');
$ciphers = @get_config('system','curl_ssl_ciphers');
if($ciphers)
@@ -257,6 +258,7 @@ function z_post_url($url, $params, $redirects = 0, $opts = array()) {
@curl_setopt($ch, CURLOPT_POST,1);
@curl_setopt($ch, CURLOPT_POSTFIELDS,$params);
@curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; zot)");
+ @curl_setopt($ch, CURLOPT_ENCODING, '');
$ciphers = @get_config('system','curl_ssl_ciphers');
if($ciphers)
diff --git a/include/photos.php b/include/photos.php
index 631660d7a..11dd07586 100644
--- a/include/photos.php
+++ b/include/photos.php
@@ -469,7 +469,7 @@ function photo_upload($channel, $observer, $args) {
'body' => $summary
];
- $arr['plink'] = z_root() . '/channel/' . $channel['channel_address'] . '/?f=&mid=' . urlencode($arr['mid']);
+ $arr['plink'] = $mid;
if($lat && $lon)
$arr['coord'] = $lat . ' ' . $lon;
@@ -850,7 +850,7 @@ function photos_create_item($channel, $creator_hash, $photo, $visible = false) {
$arr['deny_cid'] = $photo['deny_cid'];
$arr['deny_gid'] = $photo['deny_gid'];
- $arr['plink'] = z_root() . '/channel/' . $channel['channel_address'] . '/?f=&mid=' . urlencode($arr['mid']);
+ $arr['plink'] = $mid;
$arr['body'] = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo['resource_id'] . ']'
. '[zmg]' . z_root() . '/photo/' . $photo['resource_id'] . '-' . $photo['imgscale'] . '[/zmg]'
diff --git a/include/text.php b/include/text.php
index 5d1cf6eff..a2e5ce37a 100644
--- a/include/text.php
+++ b/include/text.php
@@ -1010,7 +1010,7 @@ function contact_block() {
if(count($r)) {
$contacts = t('Connections');
- $micropro = Array();
+ $micropro = [];
foreach($r as $rr) {
// There is no setting to discover if you are bi-directionally connected
@@ -1037,6 +1037,9 @@ function contact_block() {
$rr['perminfo']['connperms'] .= t('Nothing');
}
+ if(!$is_owner && $rr['perminfo']['connpermcount'] !== 0)
+ unset($rr['perminfo']);
+
$micropro[] = micropro($rr,true,'mpfriend');
}
}
@@ -1047,7 +1050,7 @@ function contact_block() {
'$contacts' => $contacts,
'$nickname' => App::$profile['channel_address'],
'$viewconnections' => (($total > $shown) ? sprintf(t('View all %s connections'),$total) : ''),
- '$micropro' => $micropro,
+ '$micropro' => $micropro
));
$arr = ['contacts' => $r, 'output' => $o];
@@ -2237,6 +2240,9 @@ function item_post_type($item) {
if(strlen($item['verb']) && (! activity_match($item['verb'],ACTIVITY_POST)))
$post_type = t('activity');
+ if($item['obj_type'] === 'Question')
+ $post_type = t('poll');
+
return $post_type;
}
@@ -3732,7 +3738,7 @@ function array_path_exists($str,$arr) {
if($search) {
foreach($search as $s) {
- if($ptr && array_key_exists($s,$ptr)) {
+ if(is_array($ptr) && array_key_exists($s,$ptr)) {
$ptr = $ptr[$s];
}
else {
diff --git a/include/zid.php b/include/zid.php
index 325af5580..10e09e212 100644
--- a/include/zid.php
+++ b/include/zid.php
@@ -1,5 +1,6 @@
<?php
+use Zotlabs\Lib\Libzot;
use Zotlabs\Lib\Verify;
use Zotlabs\Zot\Finger;
@@ -402,9 +403,7 @@ function observer_auth($ob_hash) {
return;
}
- // Note: this has no Libzot namespace so prefers zot over zot6
-
- $hubloc = zot_record_preferred($r);
+ $hubloc = Libzot::zot_record_preferred($r);
$_SESSION['authenticated'] = 1;
diff --git a/include/zot.php b/include/zot.php
index 8b9cb0767..fb0804aa7 100644
--- a/include/zot.php
+++ b/include/zot.php
@@ -408,7 +408,7 @@ function zot_refresh($them, $channel = null, $force = false) {
if($channel) {
$postvars['target'] = $channel['xchan_guid'];
- $postvars['target_sig'] = $channel['xchan_guid_sig'];
+ $postvars['target_sig'] = str_replace('sha256.', '', $channel['xchan_guid_sig']);
$postvars['key'] = $channel['channel_pubkey'];
}