aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Module/Thing.php
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2024-03-04 21:24:21 +0000
committerMario <mario@mariovavti.com>2024-03-04 21:24:21 +0000
commitd7ceb977daec6aa07ba3a8e4bbc1d493d59509d1 (patch)
tree8095858670f3158e48412e7f04a028d5056bc305 /Zotlabs/Module/Thing.php
parent3f32a5239d7d95410de9b53396a8751556a41ec5 (diff)
downloadvolse-hubzilla-d7ceb977daec6aa07ba3a8e4bbc1d493d59509d1.tar.gz
volse-hubzilla-d7ceb977daec6aa07ba3a8e4bbc1d493d59509d1.tar.bz2
volse-hubzilla-d7ceb977daec6aa07ba3a8e4bbc1d493d59509d1.zip
basic AS2 support for things
Diffstat (limited to 'Zotlabs/Module/Thing.php')
-rw-r--r--Zotlabs/Module/Thing.php104
1 files changed, 60 insertions, 44 deletions
diff --git a/Zotlabs/Module/Thing.php b/Zotlabs/Module/Thing.php
index b065b0022..d51310b3a 100644
--- a/Zotlabs/Module/Thing.php
+++ b/Zotlabs/Module/Thing.php
@@ -6,26 +6,45 @@
namespace Zotlabs\Module;
use Zotlabs\Lib\Libsync;
-
-require_once('include/items.php');
-require_once('include/security.php');
-require_once('include/selectors.php');
-require_once('include/acl_selectors.php');
+use Zotlabs\Lib\Activity;
+use Zotlabs\Lib\ActivityStreams;
+use Zotlabs\Lib\Libzot;
class Thing extends \Zotlabs\Web\Controller {
function init() {
+ if (argv(1) && ActivityStreams::is_as_request()) {
+ $r = q("select obj_channel from obj where obj_type = %d and obj_obj = '%s' limit 1",
+ intval(TERM_OBJ_THING),
+ dbesc(argv(1))
+ );
- if(! local_channel())
- return;
+ if($r) {
+ $sql_extra = permissions_sql($r[0]['obj_channel']);
+ }
- $channel = \App::get_channel();
+ $r = q("select * from obj where obj_type = %d and obj_obj = '%s' $sql_extra limit 1",
+ intval(TERM_OBJ_THING),
+ dbesc(argv(1))
+ );
- if($_SERVER['REQUEST_METHOD'] === 'GET' && argc() < 2) {
- profile_load($channel['channel_address']);
+ if ($r) {
+ $channel = channelx_by_n($r[0]['obj_channel']);
+ as_return_and_die(Activity::fetch_thing(['id' => $r[0]['obj_obj']]), $channel);
+ }
+
+ http_status_exit(404, 'Not found');
}
+ }
+
+ function post() {
+
+ if(! local_channel())
+ return;
+
+ $channel = \App::get_channel();
$term_hash = (($_REQUEST['term_hash']) ? $_REQUEST['term_hash'] : '');
@@ -36,7 +55,7 @@ class Thing extends \Zotlabs\Web\Controller {
$url = $_REQUEST['url'];
$photo = $_REQUEST['img'];
- $hash = random_string();
+ $hash = new_uuid();
$verbs = obj_verbs();
@@ -77,13 +96,7 @@ class Thing extends \Zotlabs\Web\Controller {
return;
$acl = new \Zotlabs\Access\AccessList($channel);
-
- if(array_key_exists('contact_allow',$_REQUEST)
- || array_key_exists('group_allow',$_REQUEST)
- || array_key_exists('contact_deny',$_REQUEST)
- || array_key_exists('group_deny',$_REQUEST)) {
- $acl->set_from_array($_REQUEST);
- }
+ $acl->set_from_array($_REQUEST);
$x = $acl->get();
@@ -181,28 +194,20 @@ class Thing extends \Zotlabs\Web\Controller {
intval(local_channel()),
dbesc($hash)
);
+
if($r) {
Libsync::build_sync_packet(0, array('obj' => $r));
}
if($activity) {
- $arr = array();
- $links = array(array('rel' => 'alternate','type' => 'text/html', 'href' => $url));
- if($local_photo)
- $links[] = array('rel' => 'photo', 'type' => $local_photo_type, 'href' => $local_photo);
- $objtype = ACTIVITY_OBJ_THING;
-
- $obj = json_encode(array(
- 'type' => $objtype,
- 'id' => $url,
- 'link' => $links,
- 'title' => $name,
- 'content' => $name
- ));
+ $obj = Activity::fetch_thing(['id' => $r[0]['obj_obj']]);
$bodyverb = str_replace('OBJ: ', '',t('OBJ: %1$s %2$s %3$s'));
+ $arr['uuid'] = $r[0]['obj_obj'];
+ $arr['mid'] = z_root() . '/thing/' . $arr['uuid'];
+
$arr['owner_xchan'] = $channel['channel_hash'];
$arr['author_xchan'] = $channel['channel_hash'];
@@ -213,29 +218,37 @@ class Thing extends \Zotlabs\Web\Controller {
$ulink = '[zrl=' . $channel['xchan_url'] . ']' . $channel['channel_name'] . '[/zrl]';
$plink = '[zrl=' . $url . ']' . $name . '[/zrl]';
- $arr['body'] = sprintf( $bodyverb, $ulink, $translated_verb, $plink );
+ $arr['body'] = sprintf($bodyverb, $ulink, $translated_verb, $plink);
if($local_photo)
- $arr['body'] .= "\n\n[zmg]" . $local_photo . "[/zmg]";
+ $arr['body'] .= "\n\n" . '[zmg]' . $local_photo . '[/zmg]';
- $arr['verb'] = $verb;
- $arr['obj_type'] = $objtype;
+ $arr['verb'] = 'Create';
+ $arr['obj_type'] = 'Page';
$arr['obj'] = $obj;
- if(! $profile['is_default']) {
+ $arr['allow_cid'] = $x['allow_cid'];
+ $arr['allow_gid'] = $x['allow_gid'];
+ $arr['deny_cid'] = $x['deny_cid'];
+ $arr['deny_gid'] = $x['deny_gid'];
+
+ if (!$profile['is_default']) {
$arr['item_private'] = true;
- $str = '';
+
$r = q("select abook_xchan from abook where abook_channel = %d and abook_profile = '%s'",
intval(local_channel()),
dbesc($profile_guid)
);
+
if($r) {
$arr['allow_cid'] = '';
- foreach($r as $rr)
+ foreach($r as $rr) {
$arr['allow_cid'] .= '<' . $rr['abook_xchan'] . '>';
+ }
}
- else
+ else {
$arr['allow_cid'] = '<' . get_observer_hash() . '>';
+ }
}
$ret = post_activity_item($arr);
@@ -263,12 +276,16 @@ class Thing extends \Zotlabs\Web\Controller {
);
if($r) {
+ $channel = channelx_by_n($r[0]['obj_channel']);
+ profile_load($channel['channel_address']);
+
return replace_macros(get_markup_template('show_thing.tpl'), array(
- '$header' => t('Show Thing'),
+ '$header' => $channel['xchan_name'] . ' ' . $r[0]['obj_verb'],
'$edit' => t('Edit'),
'$delete' => t('Delete'),
'$canedit' => ((local_channel() && local_channel() == $r[0]['obj_channel']) ? true : false),
- '$thing' => $r[0] ));
+ '$thing' => $r[0]
+ ));
}
else {
notice( t('item not found.') . EOL);
@@ -319,7 +336,7 @@ class Thing extends \Zotlabs\Web\Controller {
'$img_lbl' => t('URL for photo of thing (optional)'),
'$imgurl' => $r[0]['obj_imgurl'],
'$permissions' => t('Permissions'),
- '$aclselect' => populate_acl($channel_acl,false),
+ '$aclselect' => populate_acl($channel_acl, false, \Zotlabs\Lib\PermissionDescription::fromGlobalPermission('view_pages')),
'$allow_cid' => acl2json($channel_acl['allow_cid']),
'$allow_gid' => acl2json($channel_acl['allow_gid']),
'$deny_cid' => acl2json($channel_acl['deny_cid']),
@@ -344,7 +361,6 @@ class Thing extends \Zotlabs\Web\Controller {
return '';
}
-
delete_thing_photo($r[0]['obj_imgurl'],get_observer_hash());
$x = q("delete from obj where obj_obj = '%s' and obj_type = %d and obj_channel = %d",
@@ -372,7 +388,7 @@ class Thing extends \Zotlabs\Web\Controller {
'$url_lbl' => t('URL of thing (optional)'),
'$img_lbl' => t('URL for photo of thing (optional)'),
'$permissions' => t('Permissions'),
- '$aclselect' => populate_acl($channel_acl,false),
+ '$aclselect' => populate_acl($channel_acl, false, \Zotlabs\Lib\PermissionDescription::fromGlobalPermission('view_pages')),
'$allow_cid' => acl2json($channel_acl['allow_cid']),
'$allow_gid' => acl2json($channel_acl['allow_gid']),
'$deny_cid' => acl2json($channel_acl['deny_cid']),