SSFavorites Messages
\n
\n";
$fav_list = '';
@Favs = ();
$explicit = 0;
#Rest of head is useless if not logged in
if($login::username ne '') {
#Set @Favs before anything else.
if(-e "$blosxom::plugin_state_dir/fav/$login::username") {
if(not(open(FAV, "$blosxom::plugin_state_dir/fav/$login::username"))) {
$messages .= "Didn't open user's favorites file for reading.
\n";
} else { #File was opened, now read it (aloud and slowly) to @Favs list
$messages .= "Opened and read users file ($blosxom::plugin_state_dir/fav/$login::username).
\n";
@Favs = ;
$messages .= "
Favorites in file:
\n";
$messages .= "- " . join("
\n- ", @Favs) . "
\n";
close(FAV);
}
} else {
$messages .= "File ($blosxom::plugin_state_dir/fav/$login::username) does not exist.
\n";
}
&make_fav_list();
#If user just pushed a button, then act {&add || &remove} and optionally print $RedirectPage.
if((request_method() eq 'POST') and (param('plugin') eq 'ssfavorites')) {
$messages .= "Found POST data. ";
if(param('task') eq 'add') {
&add(param('fav_string'));
} elsif(param('task') eq 'remove') {
&remove(param('fakeurl'));
}
}
}
$messages .= "
\n
\n";
}
sub make_fav_list {
#Make $fav_list
$fav_list = "SSFavorites Messages
\n
\n";
$truemtime = &get_mtime("$blosxom::datadir$path/$filename.$blosxom::file_extension");
if($login::username ne "") { #User is logged in
$messages .= "LOGGED IN AS $login::username" . br;
$messages .= "Read file:
\n$blosxom::plugin_state_dir/fav/$login::username
\n";
#Check for the current "story" in the user's favorites list
for my $i (0 .. @Favs) {
my ($fakeurl, $title, $mdate) = split(/&&/, $Favs[$i]);
if("$blosxom::url$path/$filename.$blosxom::$default_flavour" eq $fakeurl) {
$button = $remove_form;
return 1;
}
}
$button = $add_form;
} else {$messages .= "NOT LOGGED IN.
\n"}
1;
}
sub sort {
return undef;
}
sub foot {
#Currently this is in foot, but would like to put it in head if there is a way to determine if the user has viewed this story, even with others on the page.
my ($currentdir, $foot_ref) = @_;
$messages = "
SSFavorites Update Messages
\n
\n";
if($explicit == 1) {
&add("1&&" . &remove($explicit_story));
} else {
$messages .= "Did not update favorites: There were more than 1 stories ($explicit)
\n";
}
$messages .= "
\n
\n";
1;
}
sub make_fakeurl {
my $fileurl = pop;
my $fakeurl = $blosxom::url . substr($fileurl, length($blosxom::datadir), -4) . ".$blosxom::default_flavour";
return($fakeurl);
$messages .= "Used &make_fakeurl() here.
\n";
}
sub make_fileurl {
my $fakeurl = pop;
my $fileurl = $blosxom::datadir . substr($fakeurl, length($blosxom::url), -4) . $blosxom::file_extension;
return($fileurl);
}
1;
__END__
=head1 NAME
Blosxom Plug-in: SSFavorites
=head1 DESCRIPTION
A sort of server-side "favorites" or "watching" list
=head1 VERSION
Version 2.01
=head1 AUTHOR
Daniel C. Parker (writedanielp@hotmail.com)
=head1 LICENSE
This source is submitted to the public domain. Feel free to use and modify it. If you like, a comment in your modified source attributing credit for my original work would be appreciated.
THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT ANY WARRANTY OF ANY KIND.
=head1 INSTALLATION
Everything self-installs:
1. Just put this in your plugins directory. (The order for this doesn't matter.)
2. There are two variables to put in your "page" file:
"$ssfavorites::fav_list" and "$ssfavorites::button".
-. Variable "$ssfavorites::messages" is for debugging, though you never should need it.
NOTE: This requires the LOGIN PLUGIN to be functioning as well.
See the LOGIN plugin's NOTES as well.