summaryrefslogtreecommitdiff
path: root/lib/privacy.pm
diff options
context:
space:
mode:
authorJules Laplace <carbon@melanarchy.org>2013-08-02 17:14:41 -0500
committerJules Laplace <carbon@melanarchy.org>2013-08-02 17:14:41 -0500
commite9192b3d42660a5781101df4357d276318151e8a (patch)
tree059eb6ace6147cf9559af74ed1ab5e221c80e280 /lib/privacy.pm
parent79670053c7247d3a49b607960efd284e93f057e5 (diff)
cgi-bin & lib
Diffstat (limited to 'lib/privacy.pm')
-rw-r--r--lib/privacy.pm133
1 files changed, 133 insertions, 0 deletions
diff --git a/lib/privacy.pm b/lib/privacy.pm
new file mode 100644
index 0000000..fcf3188
--- /dev/null
+++ b/lib/privacy.pm
@@ -0,0 +1,133 @@
+sub check_privacy
+ {
+ my ($t, $k) = @_;
+ $k = -1 unless (defined($k));
+ if ($USER == -1 && $t->{private} > 0)
+ { return 0; }
+ if ($t->{private} < 2)
+ { return 1; }
+ if ($t->{username} eq $USER->{username})
+ { return 1; }
+ if (check_key($t->{allowed}, $USER->{id}))
+ { return 1; }
+ if ($USER->{ulevel} == 3) # A:.H:.
+ { return 1; }
+ if ($k != -1)
+ {
+ if ($k->{owner} eq $USER->{username})
+ { return 1; }
+ if ($k->{public} == 1 && $t->{private} != 2)
+ { return 1; }
+ if (check_key($k->{ops}, $USER->{id}))
+ { return 1; }
+ }
+ return 0;
+ }
+
+sub check_participation
+ {
+ my ($files, $comments) = @_;
+ foreach my $f (@$files)
+ {
+ return 2 if ($f->{username} eq $USER->{username});
+ }
+ foreach my $c (@$comments)
+ {
+ return 1 if ($c->{username} eq $USER->{username});
+ }
+ return 0;
+ }
+
+sub check_keyword
+ {
+ my ($k) = @_;
+ if ($k != -1)
+ {
+ print "keyword: $k->{keyword}<br>owner: $k->{owner}<br>" if ($DEBUG);
+ print "ops: $k->{ops}<br>" if ($DEBUG);
+ print "public: $k->{public}<br>" if ($DEBUG);
+ if ($k->{public} == 1)
+ { return 1; }
+ return 0 if ($USER == -1);
+ if ($k->{owner} eq $USER->{username})
+ { return 1; }
+ if (check_key($k->{ops}, $USER->{id}))
+ { return 1; }
+ }
+ return 0;
+ }
+sub check_op
+ {
+ my ($k) = @_;
+ if ($k != -1)
+ {
+ print "keyword: $k->{keyword}<br>owner: $k->{owner}<br>" if ($DEBUG);
+ print "ops: $k->{ops}<br>" if ($DEBUG);
+ print "public: $k->{public}<br>" if ($DEBUG);
+ if ($k->{owner} eq $USER->{username})
+ { return 1; }
+ if (check_key($k->{ops}, $USER->{id}))
+ { return 1; }
+ if ($k->{public} == 1)
+ { return 0; }
+ }
+ return 0;
+ }
+
+sub user_checkerboard
+ {
+ my ($selected, $skip, $owner) = @_;
+ my $users = get_all_users((time - 2*28*24*3600));
+ my $i = 0;
+ my $j = 0;
+ my $r = 0;
+
+ print qq!<table border=1 cellpadding=3 cellspacing=0>!;
+
+ foreach my $duder (sort { $a->{username} cmp $b->{username} } @$users)
+ {
+ next if (check_key($skip, $duder->{id}));
+ $checked = check_key($selected, $duder->{id});
+
+ print qq[<tr>\n] if ($j == 0);
+ print qq[<td class="row$r" nobreak><nobr>];
+ print qq[<input type="checkbox" name="user$i" value="$duder->{username}"];
+ print " checked" if ($checked);
+ print qq[>&nbsp;<a href="$BUCKY/profile/$duder->{username}" class="quietlink">$duder->{username}</a>];
+ print qq[</nobr></td>\n];
+ print qq[</tr>\n] if ($j == 3);
+
+ $r = $r ? 0 : 1;
+ $r = $j == 3 ? int(!$r) : $r;
+ $j = $j == 3 ? 0 : $j+1;
+ $i++;
+ $checked = 0;
+ }
+
+ print "</table>\n";
+ }
+
+sub update_whitelist
+ {
+ my $whitelist = make_whitelist();
+ if ($whitelist eq " ")
+ { print "whitelist cleared<br>"; }
+ else
+ { print "new whitelist: $whitelist<br>"; }
+ switch_whitelist($id, $whitelist);
+ return $whitelist;
+ }
+
+sub make_whitelist
+ {
+ my $whitelist = " ";
+ foreach my $name (corral($input, "user"))
+ {
+ my $nextid = get_uid($name);
+ $whitelist .= $nextid." ";
+ }
+ return $whitelist;
+ }
+
+1;
+