3 * Name: Remote Permissions
4 * Description: Allow the recipients of private posts to see who else can see the post by clicking the lock icon
6 * Author: Zach <https://f.shmuz.in/profile/techcity>
11 function remote_permissions_install() {
12 register_hook('lockview_content', 'addon/remote_permissions/remote_permissions.php', 'remote_permissions_content');
13 register_hook('plugin_settings', 'addon/remote_permissions/remote_permissions.php', 'remote_permissions_settings');
14 register_hook('plugin_settings_post', 'addon/remote_permissions/remote_permissions.php', 'remote_permissions_settings_post');
17 function remote_permissions_uninstall() {
18 unregister_hook('lockview_content', 'addon/remote_permissions/remote_permissions.php', 'remote_permissions_content');
19 unregister_hook('plugin_settings', 'addon/remote_permissions/remote_permissions.php', 'remote_permissions_settings');
20 unregister_hook('plugin_settings_post', 'addon/remote_permissions/remote_permissions.php', 'remote_permissions_settings_post');
23 function remote_permissions_settings(&$a,&$o) {
28 $global = get_config("remote_perms", "global");
32 /* Add our stylesheet to the page so we can make our settings look nice */
34 $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/remote_permissions/settings.css' . '" media="all" />' . "\r\n";
36 /* Get the current state of our config variable */
38 $remote_perms = get_pconfig(local_user(),'remote_perms','show');
40 /* Add some HTML to the existing form */
42 $t = file_get_contents( $a->get_baseurl() . "/addon/remote_permissions/settings.tpl" );
43 $o .= replace_macros($t, array(
44 '$remote_perms_title' => t('Remote Permissions Settings'),
45 '$remote_perms_label' => t('Allow recipients of your private posts to see the other recipients of the posts'),
46 '$checked' => (($remote_perms == 1) ? 'checked="checked"' : ''),
47 '$submit' => t('Submit')
52 function remote_permissions_settings_post($a,$post) {
53 if(! local_user() || (! x($_POST,'remote-perms-submit')))
56 set_pconfig(local_user(),'remote_perms','show',intval($_POST['remote-perms']));
57 info( t('Remote Permissions settings updated.') . EOL);
60 function remote_permissions_content($a, $item_copy) {
62 if($item_copy['uid'] != local_user())
65 if(get_config('remote_perms','global') == 0) {
66 // Admin has set Individual choice. We need to find
67 // the original poster. First, get the contact's info
68 $r = q("SELECT nick, url FROM contact WHERE id = %d LIMIT 1",
69 intval($item_copy['contact-id'])
74 // Find out if the contact lives here
75 $baseurl = $a->get_baseurl();
76 $baseurl = substr($baseurl, strpos($baseurl, '://') + 3);
77 if(strpos($r[0]['url'], $baseurl) === false)
80 // The contact lives here. Get his/her user info
81 $nick = $r[0]['nick'];
82 $r = q("SELECT uid FROM user WHERE nickname = '%s' LIMIT 1",
88 if(get_pconfig($r[0]['uid'],'remote_perms','show') == 0)
92 if(($item_copy['private'] == 1) && (! strlen($item_copy['allow_cid'])) && (! strlen($item_copy['allow_gid']))
93 && (! strlen($item_copy['deny_cid'])) && (! strlen($item_copy['deny_gid']))) {
95 $allow_names = array();
97 // Check for the original post here -- that's the only way
98 // to definitely get all of the recipients
100 if($item_copy['uri'] === $item_copy['parent-uri']) {
101 // Lockview for a top-level post
102 $r = q("SELECT allow_cid, allow_gid, deny_cid, deny_gid FROM item WHERE uri = '%s' AND type = 'wall' LIMIT 1",
103 dbesc($item_copy['uri'])
107 // Lockview for a comment
108 $r = q("SELECT allow_cid, allow_gid, deny_cid, deny_gid FROM item WHERE uri = '%s'
109 AND parent = ( SELECT id FROM item WHERE uri = '%s' AND type = 'wall' ) LIMIT 1",
110 dbesc($item_copy['uri']),
111 dbesc($item_copy['parent-uri'])
118 $allowed_users = expand_acl($item['allow_cid']);
119 $allowed_groups = expand_acl($item['allow_gid']);
120 $deny_users = expand_acl($item['deny_cid']);
121 $deny_groups = expand_acl($item['deny_gid']);
123 $o = t('Visible to:') . '<br />';
127 if(count($allowed_groups)) {
128 $r = q("SELECT DISTINCT `contact-id` FROM group_member WHERE gid IN ( %s )",
129 dbesc(implode(', ', $allowed_groups))
132 $allow[] = $rr['contact-id'];
134 $allow = array_unique($allow + $allowed_users);
136 if(count($deny_groups)) {
137 $r = q("SELECT DISTINCT `contact-id` FROM group_member WHERE gid IN ( %s )",
138 dbesc(implode(', ', $deny_groups))
141 $deny[] = $rr['contact-id'];
143 $deny = $deny + $deny_users;
147 $r = q("SELECT name FROM contact WHERE id IN ( %s )",
148 dbesc(implode(', ', array_diff($allow, $deny)))
151 $allow_names[] = $rr['name'];
155 // We don't have the original post. Let's try for the next best thing:
156 // checking who else has the post on our own server. Note that comments
157 // that were sent to Diaspora and were relayed to others on our server
158 // will have different URIs than the original. We can match the GUID for
160 $r = q("SELECT `uid` FROM item WHERE uri = '%s' OR guid = '%s'",
161 dbesc($item_copy['uri']),
162 dbesc($item_copy['guid'])
169 $allow[] = $rr['uid'];
171 $r = q("SELECT username FROM user WHERE uid IN ( %s )",
172 dbesc(implode(', ', $allow))
177 $o = t('Visible to') . ' (' . t('may only be a partial list') . '):<br />';
180 $allow_names[] = $rr['username'];
183 // Sort the names alphabetically, case-insensitive
184 natcasesort($allow_names);
185 echo $o . implode(', ', $allow_names);
192 function remote_permissions_plugin_admin(&$a, &$o){
193 $t = file_get_contents( $a->get_baseurl() . "/addon/remote_permissions/admin.tpl" );
194 $o = replace_macros($t, array(
195 '$submit' => t('Submit'),
196 '$global' => array('remotepermschoice', t('Global'), 1, t('The posts of every user on this server show the post recipients'), get_config('remote_perms', 'global') == 1),
197 '$individual' => array('remotepermschoice', t('Individual'), 2, t('Each user chooses whether his/her posts show the post recipients'), get_config('remote_perms', 'global') == 0)
201 function remote_permissions_plugin_admin_post(&$a){
202 $choice = ((x($_POST,'remotepermschoice')) ? notags(trim($_POST['remotepermschoice'])) : '');
203 set_config('remote_perms','global',($choice == 1 ? 1 : 0));
204 info( t('Settings updated.'). EOL );