#!/usr/local/bin/perl # $Id: default.cgi,v 1.6 2003/08/07 04:35:43 erik Exp $ use strict; use warnings; use Data::Dumper; use lib '.'; use ELJ; my %methods = ( 'Do Nothing' => \&doNothing, 'Friends Only' => \&FriendsOnly, 'Friends Only Plus' => \&FriendsOnlyPlus, 'Friends Custom Security' => \&CustomSecurity, 'Private' => \&allPrivate, 'Public' => \&allPublic, 'Unmarked Secure Posts' => \&FindUnmarked, 'List Picture Keywords' => \&PictureKeywords ); ELJ::MainLoop(%methods,"http://www.valdemar.net/~erik/lj/scripts/default.cgi"); sub doNothing (\%$) { # very trivial example, does nothing to an entry my %post = %{(shift)}; print "
\n", Dumper(\%post), "\n
\n"; return 0; }; sub FriendsOnly (\%$) { # sets all posts that aren't private or with a custom group mask to friends only my %post = %{(shift)}; if(defined($post{"security"})) { # not public # leave private entries alone return 0 if($post{"security"} eq 'private'); # leave custom, friendsonly, and weird allowmasks alone return 0 if($post{"allowmask"} >= 0); } $post{"security"} = "usemask"; $post{"allowmask"} = 1; ELJ::EditEvent(%post); print "...changed to friends only\n"; return 0; } sub FriendsOnlyPlus (\%$) { # adds "(group friends only)" to the first line of the event when changing my %post = %{(shift)}; $post{"event"} = "%28group+friends+only%29%0A%0A" . $post{"event"}; # predicated on unchanged FriendsOnly subroutine above so event won't # really change unless the security is changed return FriendsOnly(%post,@_); } sub CustomSecurity (\%$) { # sets all posts that aren't private or with a custom group mask to friends only my %post = %{(shift)}; my $option = shift; my $allowmask; if ($option eq "") { print "
\n"; my %groups = ELJ::GetFriendsGroups(); print "0 -> Private
\n1 -> Friends Only
\n"; foreach (sort keys(%groups)) { my $mask = 2**($_); print "$mask -> ", $groups{$_}, "
\n"; } print "
Put your desired mask in the parameter field to set. You can add multiple masks to allow multiple groups access.\n"; return 2; } else { $allowmask = $option || 1; } if(defined($post{"security"})) { # not public # leave private entries alone return 0 if($post{"security"} eq 'private'); # leave custom, friendsonly, and weird allowmasks alone return 0 if($post{"allowmask"} >= 0); } $post{"security"} = "usemask"; $post{"allowmask"} = $allowmask; ELJ::EditEvent(%post); print "... changed to $allowmask only\n"; return 0; } sub FindUnmarked (\%$) { my %post = %{(shift)}; return 0 if(!defined($post{'security'})); if($post{'event'} !~ m#%28[Gg]roup#ms) { print "  needs '(group <groupname> only)'"; } return 0; } sub PictureKeywords (\%$) { my %post = %{(shift)}; print "  $post{prop_picture_keyword}" if(defined($post{"prop_picture_keyword"})); return 0; } sub allPrivate (\%$) { # thanks lj user = znemesis my %post = %{(shift)}; return 0 if ($post{"security"} eq 'private'); $post{"security"} = 'private'; delete $post{"allowmask"} if (defined($post{"allowmask"})); ELJ::EditEvent(%post); print "...changed to private only\n"; return 0; } sub allPublic (\%$) { # thanks lj user = arlecchina my %post = %{(shift)}; return 0 if ($post{"security"} eq 'public'); $post{"security"} = 'public'; delete $post{"allowmask"} if (defined($post{"allowmask"})); ELJ::EditEvent(%post); print "...changed to public\n"; return 0; } exit 0;