aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2024-02-29 17:05:48 +0000
committerMario <mario@mariovavti.com>2024-02-29 17:05:48 +0000
commit46f67eaa1e40954267088ba67726adc0d389628c (patch)
tree245878793f90aeb8f7a1c3ac586606166e853761
parent291e12574aeb3b71200b23d8ffc630a36f170008 (diff)
downloadvolse-hubzilla-46f67eaa1e40954267088ba67726adc0d389628c.tar.gz
volse-hubzilla-46f67eaa1e40954267088ba67726adc0d389628c.tar.bz2
volse-hubzilla-46f67eaa1e40954267088ba67726adc0d389628c.zip
AS2 Update and implement a first draft of AS2 Profile activities
-rw-r--r--Zotlabs/Lib/Activity.php27
-rw-r--r--Zotlabs/Lib/Libzot.php1
-rw-r--r--Zotlabs/Module/Cover_photo.php45
-rw-r--r--Zotlabs/Module/Profile_photo.php2
-rw-r--r--Zotlabs/Module/Profiles.php6
-rw-r--r--boot.php2
-rw-r--r--include/activities.php122
-rw-r--r--include/contact_widgets.php2
-rw-r--r--include/items.php51
-rw-r--r--include/taxonomy.php4
-rw-r--r--include/text.php2
11 files changed, 83 insertions, 181 deletions
diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php
index b4ce4b5d0..eef4f8036 100644
--- a/Zotlabs/Lib/Activity.php
+++ b/Zotlabs/Lib/Activity.php
@@ -172,10 +172,6 @@ class Activity {
}
static function fetch_person($x) {
- return self::fetch_profile($x);
- }
-
- static function fetch_profile($x) {
$r = q("select * from xchan where xchan_url = '%s' limit 1",
dbesc($x['id'])
);
@@ -189,7 +185,14 @@ class Activity {
return [];
return self::encode_person($r[0]);
+ }
+
+ static function fetch_profile($x) {
+ if (isset($x['describes'])) {
+ return $x;
+ }
+ return [];
}
static function fetch_thing($x) {
@@ -978,6 +981,7 @@ class Activity {
$ret['to'] = [ACTIVITY_PUBLIC_INBOX];
}
+
$hookinfo = [
'item' => $i,
'encoded' => $ret
@@ -2049,6 +2053,10 @@ class Activity {
$s['mid'] = $act->obj['data']['id'];
}
+ if ($act->objprop('type') === 'Profile') {
+ $s['mid'] = $act->id;
+ }
+
if (!$s['mid']) {
return false;
}
@@ -2293,6 +2301,14 @@ class Activity {
if (!$response_activity) {
+ if ($act->objprop('type') === 'Profile') {
+ $s['parent_mid'] = $s['mid'];
+ $s['item_thread_top'] = 1;
+ $s['summary'] = '';
+ $s['body'] = self::bb_content($content, 'summary');
+ }
+
+
// we will need a hook here to extract magnet links e.g. peertube
// right now just link to the largest mp4 we find that will fit in our
// standard content region
@@ -2438,7 +2454,6 @@ class Activity {
}
}
-
if ($act->objprop('type') === 'Page' && !$s['body']) {
$ptr = null;
@@ -2479,7 +2494,7 @@ class Activity {
}
}
- if (in_array($act->objprop('type', ''), ['Note', 'Article', 'Page'])) {
+ if (in_array($act->objprop('type'), ['Note', 'Article', 'Page'])) {
$ptr = null;
if (array_key_exists('url', $act->obj)) {
diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php
index a98ae8f20..942c3082a 100644
--- a/Zotlabs/Lib/Libzot.php
+++ b/Zotlabs/Lib/Libzot.php
@@ -1143,7 +1143,6 @@ class Libzot {
if ($env['encoding'] === 'activitystreams') {
$AS = new ActivityStreams($data);
-
if (!$AS->is_valid()) {
logger('Activity rejected: ' . print_r($data, true));
return;
diff --git a/Zotlabs/Module/Cover_photo.php b/Zotlabs/Module/Cover_photo.php
index 1ecbfce3e..f4f9480c0 100644
--- a/Zotlabs/Module/Cover_photo.php
+++ b/Zotlabs/Module/Cover_photo.php
@@ -93,8 +93,6 @@ class Cover_photo extends \Zotlabs\Web\Controller {
$image_id = substr($image_id,0,-2);
}
-
-
$srcX = intval($_POST['xstart']);
$srcY = intval($_POST['ystart']);
$srcW = intval($_POST['xfinal']) - $srcX;
@@ -228,7 +226,7 @@ class Cover_photo extends \Zotlabs\Web\Controller {
return;
}
- $this->send_cover_photo_activity($channel,$base_image,$profile);
+ profile_activity([t('Cover Photo')], $base_image['resource_id']);
$sync = attach_export_data($channel,$base_image['resource_id']);
if($sync)
@@ -245,7 +243,6 @@ class Cover_photo extends \Zotlabs\Web\Controller {
}
-
$hash = photo_new_resource();
$smallest = 0;
@@ -287,45 +284,6 @@ class Cover_photo extends \Zotlabs\Web\Controller {
}
- function send_cover_photo_activity($channel,$photo,$profile) {
-
- $arr = array();
- $arr['item_thread_top'] = 1;
- $arr['item_origin'] = 1;
- $arr['item_wall'] = 1;
-
- if($profile && stripos($profile['gender'],t('female')) !== false)
- $t = t('%1$s updated her %2$s');
- elseif($profile && stripos($profile['gender'],t('male')) !== false)
- $t = t('%1$s updated his %2$s');
- else
- $t = t('%1$s updated their %2$s');
-
- $ptext = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo['resource_id'] . ']' . t('cover photo') . '[/zrl]';
-
- $ltext = '[zrl=' . z_root() . '/profile/' . $channel['channel_address'] . ']' . '[zmg]' . z_root() . '/photo/' . $photo['resource_id'] . '-8[/zmg][/zrl]';
-
- $arr['body'] = sprintf($t,$channel['channel_name'],$ptext) . "\n\n" . $ltext;
-
- $acl = new \Zotlabs\Access\AccessList($channel);
- $x = $acl->get();
- $arr['allow_cid'] = $x['allow_cid'];
-
- $arr['allow_gid'] = $x['allow_gid'];
- $arr['deny_cid'] = $x['deny_cid'];
- $arr['deny_gid'] = $x['deny_gid'];
-
- $arr['uid'] = $channel['channel_id'];
- $arr['aid'] = $channel['channel_account_id'];
-
- $arr['owner_xchan'] = $channel['channel_hash'];
- $arr['author_xchan'] = $channel['channel_hash'];
-
- post_activity_item($arr);
-
-
- }
-
/**
* @brief Generate content of profile-photo view
@@ -334,7 +292,6 @@ class Cover_photo extends \Zotlabs\Web\Controller {
*
*/
-
function get() {
if(! local_channel()) {
diff --git a/Zotlabs/Module/Profile_photo.php b/Zotlabs/Module/Profile_photo.php
index d7e2bbce1..8601a7508 100644
--- a/Zotlabs/Module/Profile_photo.php
+++ b/Zotlabs/Module/Profile_photo.php
@@ -223,7 +223,7 @@ class Profile_photo extends Controller {
intval(local_channel())
);
- send_profile_photo_activity($channel, $base_image, $profile);
+ profile_activity([t('Profile Photo')], $base_image['resource_id']);
}
else {
q("update profile set photo = '%s', thumb = '%s' where id = %d and uid = %d",
diff --git a/Zotlabs/Module/Profiles.php b/Zotlabs/Module/Profiles.php
index ce496252b..15252d6e6 100644
--- a/Zotlabs/Module/Profiles.php
+++ b/Zotlabs/Module/Profiles.php
@@ -3,10 +3,6 @@ namespace Zotlabs\Module;
use Zotlabs\Lib\Libsync;
-require_once('include/channel.php');
-require_once('include/selectors.php');
-
-
class Profiles extends \Zotlabs\Web\Controller {
function init() {
@@ -492,7 +488,7 @@ class Profiles extends \Zotlabs\Web\Controller {
$publish = ((x($_POST, 'profile_in_directory') && (intval($_POST['profile_in_directory']) == 1)) ? 1 : 0);
- profile_activity($changes,$value);
+ profile_activity($changes, $value);
}
diff --git a/boot.php b/boot.php
index d11934c3c..5ed8d1ff0 100644
--- a/boot.php
+++ b/boot.php
@@ -60,6 +60,8 @@ require_once('include/bbcode.php');
require_once('include/items.php');
require_once('include/conversation.php');
require_once('include/acl_selectors.php');
+require_once('include/selectors.php');
+require_once('include/activities.php');
define('PLATFORM_NAME', 'hubzilla');
define('STD_VERSION', '8.9.9');
diff --git a/include/activities.php b/include/activities.php
index f5f0e55da..bb80e7906 100644
--- a/include/activities.php
+++ b/include/activities.php
@@ -1,100 +1,80 @@
<?php /** @file */
-function profile_activity($changed, $value) {
-
- // TODO: we should probably send an Update/Profile or Person activity here.
- // We could also just send a Note with some changed info?
- // Profiles are currently a hubzilla specific thing.
- return;
+use Zotlabs\Lib\Activity;
+use Zotlabs\Daemon\Master;
- if(! local_channel() || ! is_array($changed) || ! count($changed))
- return;
+function profile_activity($changed, $value) {
- if(! get_pconfig(local_channel(),'system','post_profilechange'))
+ if (!local_channel() || !is_array($changed) || !count($changed)) {
return;
+ }
- require_once('include/items.php');
-
- $self = App::get_channel();
-
- if(! count($self))
+ if (!get_pconfig(local_channel(), 'system', 'post_profilechange')) {
return;
+ }
- $arr = array();
- $arr['uuid'] = item_message_id();
- $arr['mid'] = $arr['parent_mid'] = z_root() . '/item/' . $arr['uuid'];
- $arr['uid'] = local_channel();
- $arr['aid'] = $self['channel_account_id'];
- $arr['owner_xchan'] = $arr['author_xchan'] = $self['xchan_hash'];
-
- $arr['item_wall'] = 1;
- $arr['item_origin'] = 1;
- $arr['item_thread_top'] = 1;
- $arr['verb'] = ACTIVITY_UPDATE;
- $arr['obj_type'] = 'Profile';
-
- $arr['plink'] = z_root() . '/channel/' . $self['channel_address'] . '/?f=&mid=' . urlencode($arr['mid']);
+ $channel = App::get_channel();
- $A = '[url=' . z_root() . '/channel/' . $self['channel_address'] . ']' . $self['channel_name'] . '[/url]';
+ $arr['verb'] = 'Update';
+ $arr['obj_type'] = 'Profile';
+ $channel_link = '[url=' . z_root() . '/channel/' . $channel['channel_address'] . ']' . $channel['channel_name'] . '[/url]';
$changes = '';
$t = count($changed);
$z = 0;
- foreach($changed as $ch) {
- if(strlen($changes)) {
- if ($z == ($t - 1))
+ $photo = false;
+ foreach ($changed as $ch) {
+ if (strlen($changes)) {
+ if ($z == ($t - 1)) {
$changes .= t(' and ');
- else
- $changes .= ', ';
+ } else {
+ $changes .= t(', ');
+ }
+ }
+
+ if (in_array($ch, [t('Profile Photo'), t('Cover Photo')])) {
+ $photo = true;
+ $photo_size = (($ch === t('Profile Photo')) ? 4 : 8);
}
- $z ++;
+
+ $z++;
$changes .= $ch;
}
- $prof = '[url=' . z_root() . '/profile/' . $self['channel_address'] . ']' . t('public profile') . '[/url]';
+ $profile_link = '[url=' . z_root() . '/profile/' . $channel['channel_address'] . ']' . t('public profile') . '[/url]';
- if($t == 1 && strlen($value)) {
+ if ($t == 1 && strlen($value)) {
// if it's a url, the HTML quotes will mess it up, so link it and don't try and zidify it because we don't know what it points to.
- $value = preg_replace_callback("/([^\]\='".'"'."]|^|\#\^)(https?\:\/\/[a-zA-Z0-9\pL\:\/\-\?\&\;\.\=\@\_\~\#\%\$\!\+\,]+)/ismu", 'red_zrl_callback', $value);
+ $value = preg_replace_callback("/([^='" . '"' . "]|^|#\^)(https?:\/\/[a-zA-Z0-9\pL:\/\-?&;.=@_~#%\$!+,]+)/ismu", 'red_zrl_callback', $value);
// take out the bookmark indicator
- if(substr($value,0,2) === '#^')
- $value = str_replace('#^','',$value);
+ if (str_starts_with($value, '#^')) {
+ $value = str_replace('#^', '', $value);
+ }
- $message = sprintf( t('%1$s changed %2$s to &ldquo;%3$s&rdquo;'), $A, $changes, $value);
- $message .= "\n\n" . sprintf( t('Visit %1$s\'s %2$s'), $A, $prof);
- }
- else
- $message = sprintf( t('%1$s has an updated %2$s, changing %3$s.'), $A, $prof, $changes);
+ if ($photo) {
+ $value = "\n\n" . '[zmg=' . z_root() . '/photo/' . $value . '-' . $photo_size . ']' . $ch . '[/zmg]';
+ }
+ $message = sprintf(t('%1$s updated %2$s to %3$s'), $channel_link, $changes, $value);
+ $message .= "\n\n" . sprintf(t('Visit %1$s\'s %2$s'), $channel_link, $profile_link);
+ } else {
+ $message = sprintf(t('%1$s has updated %2$s, changing %3$s.'), $channel_link, $profile_link, $changes);
+ }
$arr['body'] = $message;
- $links = array();
- $links[] = array('rel' => 'alternate', 'type' => 'text/html',
- 'href' => z_root() . '/profile/' . $self['channel_address']);
- $links[] = array('rel' => 'photo', 'type' => $self['xchan_photo_mimetype'],
- 'href' => $self['xchan_photo_l']);
-
- $arr['object'] = json_encode(array(
- 'type' => 'Profile',
- 'title' => $self['channel_name'],
- 'id' => $self['xchan_url'] . '/' . $self['xchan_hash'],
- 'link' => $links
- ));
-
-
- $arr['allow_cid'] = $self['channel_allow_cid'];
- $arr['allow_gid'] = $self['channel_allow_gid'];
- $arr['deny_cid'] = $self['channel_deny_cid'];
- $arr['deny_gid'] = $self['channel_deny_gid'];
-
- $res = item_store($arr);
- $i = $res['item_id'];
-
- if($i) {
- // FIXME - limit delivery in notifier.php to those specificed in the perms argument
- Zotlabs\Daemon\Master::Summon(array('Notifier','activity', $i, 'PERMS_R_PROFILE'));
- }
+ $arr['obj'] = [
+ 'type' => 'Profile',
+ 'summary' => bbcode($message),
+ 'source' => [
+ 'summary' => $message,
+ 'mediaType' => 'text/bbcode'
+ ],
+ 'describes' => Activity::encode_person($channel),
+ 'url' => z_root() . '/profile/' . $channel['channel_address']
+ ];
+
+ post_activity_item($arr);
}
diff --git a/include/contact_widgets.php b/include/contact_widgets.php
index 182f674ca..c05ecaf7c 100644
--- a/include/contact_widgets.php
+++ b/include/contact_widgets.php
@@ -85,7 +85,7 @@ function categories_widget($baseurl,$selected = '') {
AND term.otype = %d
AND item.owner_xchan = '%s'
AND item.item_wall = 1
- AND item.verb != '%s'
+ AND item.verb NOT IN ('Update', '%s')
$item_normal
$sql_extra
ORDER BY term.term ASC",
diff --git a/include/items.php b/include/items.php
index 8a0af5679..a9cbd4075 100644
--- a/include/items.php
+++ b/include/items.php
@@ -459,7 +459,7 @@ function post_activity_item($arr, $allow_code = false, $deliver = true) {
if(! $arr['mid']) {
- $arr['uuid'] = ((x($arr,'uuid')) ? $arr['uuid'] : item_message_id());
+ $arr['uuid'] = ((x($arr,'uuid')) ? $arr['uuid'] : new_uuid());
}
$arr['mid'] = ((x($arr,'mid')) ? $arr['mid'] : z_root() . '/item/' . $arr['uuid']);
$arr['parent_mid'] = ((x($arr,'parent_mid')) ? $arr['parent_mid'] : $arr['mid']);
@@ -520,7 +520,7 @@ function post_activity_item($arr, $allow_code = false, $deliver = true) {
return $ret;
if($post_id && $deliver) {
- Master::Summon([ 'Notifier','activity',$post_id ]);
+ Master::Summon(['Notifier','activity', $post_id]);
}
$ret['success'] = true;
@@ -4790,54 +4790,7 @@ function comment_local_origin($item) {
return false;
}
-
-
-function send_profile_photo_activity($channel,$photo,$profile) {
-
- // for now only create activities for the default profile
-
- if(! intval($profile['is_default']))
- return;
-
- $arr = array();
- $arr['item_thread_top'] = 1;
- $arr['item_origin'] = 1;
- $arr['item_wall'] = 1;
-
- if(stripos($profile['gender'],t('female')) !== false)
- $t = t('%1$s updated her %2$s');
- elseif(stripos($profile['gender'],t('male')) !== false)
- $t = t('%1$s updated his %2$s');
- else
- $t = t('%1$s updated their %2$s');
-
- $ptext = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo['resource_id'] . ']' . t('profile photo') . '[/zrl]';
-
- $ltext = '[zrl=' . z_root() . '/profile/' . $channel['channel_address'] . ']' . '[zmg=150x150]' . z_root() . '/photo/' . $photo['resource_id'] . '-4[/zmg][/zrl]';
-
- $arr['body'] = sprintf($t,$channel['channel_name'],$ptext) . "\n\n" . $ltext;
-
- $acl = new Zotlabs\Access\AccessList($channel);
- $x = $acl->get();
-
- $arr['allow_cid'] = $x['allow_cid'];
-
- $arr['allow_gid'] = $x['allow_gid'];
- $arr['deny_cid'] = $x['deny_cid'];
- $arr['deny_gid'] = $x['deny_gid'];
-
- $arr['uid'] = $channel['channel_id'];
- $arr['aid'] = $channel['channel_account_id'];
-
- $arr['owner_xchan'] = $channel['channel_hash'];
- $arr['author_xchan'] = $channel['channel_hash'];
-
- post_activity_item($arr);
-}
-
-
function sync_an_item($channel_id,$item_id) {
-
$r = q("select * from item where id = %d",
intval($item_id)
);
diff --git a/include/taxonomy.php b/include/taxonomy.php
index cfec8414a..90ccb6142 100644
--- a/include/taxonomy.php
+++ b/include/taxonomy.php
@@ -58,7 +58,7 @@ function term_item_parent_query($uid,$table,$s,$type = TERM_UNKNOWN, $type2 = ''
$s = str_replace('*','%',$s);
if($type2) {
- $r = q("select parent from item left join term on term.oid = item.id where term.ttype in (%d, %d) and term.term like '%s' and term.uid = %d and term.otype = 1 and item.verb != '%s'",
+ $r = q("select parent from item left join term on term.oid = item.id where term.ttype in (%d, %d) and term.term like '%s' and term.uid = %d and term.otype = 1 and item.verb NOT IN ('Update', '%s')",
intval($type),
intval($type2),
dbesc($s),
@@ -67,7 +67,7 @@ function term_item_parent_query($uid,$table,$s,$type = TERM_UNKNOWN, $type2 = ''
);
}
else {
- $r = q("select parent from item left join term on term.oid = item.id where term.ttype = %d and term.term like '%s' and term.uid = %d and term.otype = 1 and item.verb != '%s'",
+ $r = q("select parent from item left join term on term.oid = item.id where term.ttype = %d and term.term like '%s' and term.uid = %d and term.otype = 1 and item.verb NOT IN ('Update', '%s')",
intval($type),
dbesc($s),
intval($uid),
diff --git a/include/text.php b/include/text.php
index d6256b75b..aa9650a25 100644
--- a/include/text.php
+++ b/include/text.php
@@ -1750,7 +1750,7 @@ function prepare_body(&$item,$attach = false,$opts = false) {
}
- $poll = (($item['obj_type'] === 'Question' && in_array($item['verb'],['Create', ACTIVITY_POST, ACTIVITY_UPDATE, ACTIVITY_SHARE])) ? format_poll($item, $s, $opts) : false);
+ $poll = (($item['obj_type'] === 'Question' && in_array($item['verb'],['Create', 'Update', ACTIVITY_POST, ACTIVITY_UPDATE, ACTIVITY_SHARE])) ? format_poll($item, $s, $opts) : false);
if ($poll) {
$s = $poll;
}