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("addon/remote_permissions/settings.tpl" );
43 $t = get_markup_template("settings.tpl", "addon/remote_permissions/" );
44 $o .= replace_macros($t, array(
45 '$remote_perms_title' => t('Remote Permissions Settings'),
46 '$remote_perms_label' => t('Allow recipients of your private posts to see the other recipients of the posts'),
47 '$checked' => (($remote_perms == 1) ? 'checked="checked"' : ''),
48 '$submit' => t('Save Settings')
53 function remote_permissions_settings_post($a,$post) {
54 if(! local_user() || (! x($_POST,'remote-perms-submit')))
57 set_pconfig(local_user(),'remote_perms','show',intval($_POST['remote-perms']));
58 info( t('Remote Permissions settings updated.') . EOL);
61 function remote_permissions_content($a, $item_copy) {
63 if($item_copy['uid'] != local_user())
66 if(get_config('remote_perms','global') == 0) {
67 // Admin has set Individual choice. We need to find
68 // the original poster. First, get the contact's info
69 $r = q("SELECT nick, url FROM contact WHERE id = %d LIMIT 1",
70 intval($item_copy['contact-id'])
75 // Find out if the contact lives here
76 $baseurl = $a->get_baseurl();
77 $baseurl = substr($baseurl, strpos($baseurl, '://') + 3);
78 if(strpos($r[0]['url'], $baseurl) === false)
81 // The contact lives here. Get his/her user info
82 $nick = $r[0]['nick'];
83 $r = q("SELECT uid FROM user WHERE nickname = '%s' LIMIT 1",
89 if(get_pconfig($r[0]['uid'],'remote_perms','show') == 0)
93 if(($item_copy['private'] == 1) && (! strlen($item_copy['allow_cid'])) && (! strlen($item_copy['allow_gid']))
94 && (! strlen($item_copy['deny_cid'])) && (! strlen($item_copy['deny_gid']))) {
96 $allow_names = array();
98 // Check for the original post here -- that's the only way
99 // to definitely get all of the recipients
101 if($item_copy['uri'] === $item_copy['parent-uri']) {
102 // Lockview for a top-level post
103 $r = q("SELECT allow_cid, allow_gid, deny_cid, deny_gid FROM item WHERE uri = '%s' AND type = 'wall' LIMIT 1",
104 dbesc($item_copy['uri'])
108 // Lockview for a comment
109 $r = q("SELECT allow_cid, allow_gid, deny_cid, deny_gid FROM item WHERE uri = '%s'
110 AND parent = ( SELECT id FROM item WHERE uri = '%s' AND type = 'wall' ) LIMIT 1",
111 dbesc($item_copy['uri']),
112 dbesc($item_copy['parent-uri'])
119 $allowed_users = expand_acl($item['allow_cid']);
120 $allowed_groups = expand_acl($item['allow_gid']);
121 $deny_users = expand_acl($item['deny_cid']);
122 $deny_groups = expand_acl($item['deny_gid']);
124 $o = t('Visible to:') . '<br />';
128 if(count($allowed_groups)) {
129 $r = q("SELECT DISTINCT `contact-id` FROM group_member WHERE gid IN ( %s )",
130 dbesc(implode(', ', $allowed_groups))
133 $allow[] = $rr['contact-id'];
135 $allow = array_unique($allow + $allowed_users);
137 if(count($deny_groups)) {
138 $r = q("SELECT DISTINCT `contact-id` FROM group_member WHERE gid IN ( %s )",
139 dbesc(implode(', ', $deny_groups))
142 $deny[] = $rr['contact-id'];
144 $deny = $deny + $deny_users;
148 $r = q("SELECT name FROM contact WHERE id IN ( %s )",
149 dbesc(implode(', ', array_diff($allow, $deny)))
152 $allow_names[] = $rr['name'];
156 // We don't have the original post. Let's try for the next best thing:
157 // checking who else has the post on our own server. Note that comments
158 // that were sent to Diaspora and were relayed to others on our server
159 // will have different URIs than the original. We can match the GUID for
161 $r = q("SELECT `uid` FROM item WHERE uri = '%s' OR guid = '%s'",
162 dbesc($item_copy['uri']),
163 dbesc($item_copy['guid'])
170 $allow[] = $rr['uid'];
172 $r = q("SELECT username FROM user WHERE uid IN ( %s )",
173 dbesc(implode(', ', $allow))
178 $o = t('Visible to') . ' (' . t('may only be a partial list') . '):<br />';
181 $allow_names[] = $rr['username'];
184 // Sort the names alphabetically, case-insensitive
185 natcasesort($allow_names);
186 echo $o . implode(', ', $allow_names);
193 function remote_permissions_plugin_admin(&$a, &$o){
194 $t = get_markup_template( "admin.tpl", "addon/remote_permissions/" );
195 $o = replace_macros($t, array(
196 '$submit' => t('Save Settings'),
197 '$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),
198 '$individual' => array('remotepermschoice', t('Individual'), 2, t('Each user chooses whether his/her posts show the post recipients'), get_config('remote_perms', 'global') == 0)
202 function remote_permissions_plugin_admin_post(&$a){
203 $choice = ((x($_POST,'remotepermschoice')) ? notags(trim($_POST['remotepermschoice'])) : '');
204 set_config('remote_perms','global',($choice == 1 ? 1 : 0));
205 info( t('Settings updated.'). EOL );