Add collect_public_recipients hook

This commit is contained in:
DM42.Net (Matt Dent) 2019-01-12 22:37:44 -05:00
parent f6f4e40a64
commit 598cbf2210
3 changed files with 62 additions and 2 deletions

View File

@ -0,0 +1,42 @@
[h2]collect_public_recipients[/h2]
Replace the default list of public recipients (i.e., all contacts).
Allow plugins to create a list of recipients for public messages instead of the default
of all channel connections.
Called with the following array:
[
'recipients' => [],
'item' => $item,
'private_envelope' => $private_envelope,
'include_groups' => $include_groups
];
[code]
if(array_key_exists('public_policy',$item) && $item['public_policy'] !== 'self') {
$hookinfo = [
'recipients' => [],
'item' => $item,
'private_envelope' => $private_envelope,
'include_groups' => $include_groups
];
call_hooks('collect_public_recipients',$hookinfo);
if ($hookinfo['recipients']) {
$r = $hookinfo['recipients'];
} else {
$r = q("select abook_xchan, xchan_network from abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d and abook_self = 0 and abook_pending = 0 and abook_archived = 0 ",
intval($item['uid'])
);
}
if($r) {
. . .
[/code]
see: include/item.php

View File

@ -136,6 +136,9 @@ Hooks allow plugins/addons to "hook into" the code at many points and alter the
[zrl=[baseurl]/help/hook/check_siteallowed]check_siteallowed[/zrl]
Used to over-ride or bypass the site black/white block lists
[zrl=[baseurl]/help/hook/collect_public_recipients]collect_public_recipients[/zrl]
Used to establish a list of recipients to send a public message to.
[zrl=[baseurl]/help/hook/comment_buttons]comment_buttons[/zrl]
Called when rendering the edit buttons for comments

View File

@ -95,9 +95,24 @@ function collect_recipients($item, &$private_envelope,$include_groups = true) {
//$sys = get_sys_channel();
if(array_key_exists('public_policy',$item) && $item['public_policy'] !== 'self') {
$hookinfo = [
'recipients' => [],
'item' => $item,
'private_envelope' => $private_envelope,
'include_groups' => $include_groups
];
call_hooks('collect_public_recipients',$hookinfo);
if ($hookinfo['recipients']) {
$r = $hookinfo['recipients'];
} else {
$r = q("select abook_xchan, xchan_network from abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d and abook_self = 0 and abook_pending = 0 and abook_archived = 0 ",
intval($item['uid'])
);
}
if($r) {
// filter out restrictive public_policy settings from remote networks