aboutsummaryrefslogtreecommitdiffstats
path: root/include/activities.php
blob: bb80e790696a6a35961896b99115fefae853bb1a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php /** @file */

use Zotlabs\Lib\Activity;
use Zotlabs\Daemon\Master;

function profile_activity($changed, $value) {

	if (!local_channel() || !is_array($changed) || !count($changed)) {
		return;
	}

	if (!get_pconfig(local_channel(), 'system', 'post_profilechange')) {
		return;
	}

	$channel = App::get_channel();

	$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;
	$photo = false;
	foreach ($changed as $ch) {
		if (strlen($changes)) {
			if ($z == ($t - 1)) {
				$changes .= t(' and ');
			} else {
				$changes .= t(', ');
			}
		}

		if (in_array($ch, [t('Profile Photo'), t('Cover Photo')])) {
			$photo = true;
			$photo_size = (($ch === t('Profile Photo')) ? 4 : 8);
		}

		$z++;
		$changes .= $ch;
	}

	$profile_link = '[url=' . z_root() . '/profile/' . $channel['channel_address'] . ']' . t('public profile') . '[/url]';

	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);
		// take out the bookmark indicator
		if (str_starts_with($value, '#^')) {
			$value = str_replace('#^', '', $value);
		}

		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;

	$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);

}