#!/usr/bin/perl ######################################### # index # - do all index stuff, also deal with keyword admin ######################################### use localbucky; $dbh = DBI->connect ($dsn); our ($USER, $lastlog) = checkin(); my $k; my $tag; # check name of the calling script: index, tag, keyword $input->{script} ||= $input->{script_from_uri} if defined($input->{script_from_uri}); # load the tag or keyword into the input params, if they don't exit already if ( $input->{script} eq $BUCKY_LEXICON_TAG ) { $input->{tag} ||= $input->{object_from_uri} if defined($input->{object_from_uri}); } elsif ( $input->{script} eq $BUCKY_LEXICON_KEYWORD ) { $input->{keyword} ||= $input->{object_from_uri} if defined($input->{object_from_uri}); } # Get keyword if (exists($input->{keyword}) && $input->{keyword} ne "new" && $input->{keyword} ne "unsorted") { $k = get_keyword($input->{keyword}); } # Create New Keyword? FORM if (exists($input->{keyword}) && $input->{keyword} eq "new") { my $t; header("add new category"); if (exists($input->{thread})) { $t = get_thread($input->{thread}); } menu(); print "

"; my %faek = ( keyword => $input->{keyword}, thread => $input->{thread} ); keyword_form($input->{keyword}, \%faek, $t); footer(); } # Edit settings for keyword elsif ($input->{c} eq "edit" && (check_op($k) || $USER->{ulevel} == 3)) { header( { title => "settings for category '$input->{keyword}'", sticky => $input->{keyword} } ); # 20070903 - marc - new menu args calling style my $menu_args; $menu_args->{keywords} = $k if $k; menu( $menu_args ); # menu($k); print "

"; keyword_form($k->{keyword}, $k); print qq!
!; my $threads = get_threads_by_keyword($k->{keyword}); thread_box({ threads => $threads, kw => $k }); print qq!
!; footer(); } # Create new keyword? Process form results elsif ($input->{c} eq "create") { if (!defined($input->{keyword})) { error("no keyword specified!"); } if (get_keyword($input->{keyword}) != -1) { error("keyword already exists!"); } my %nk = ( keyword => $input->{keyword}, threads => " $input->{thread} ", owner => $USER->{username}, public => $input->{public}, agglutinate => $input->{agglutinate}, color => $input->{color}, ops => (make_whitelist()) ); if ($DEBUG) { header("Creating keyword $input->{keyword}"); menu(); foreach my $ky (keys %nk) { print "$ky => $nk{$ky}
\n"; } } add_keyword(\%nk); update_thread_keyword($input->{thread}, $input->{keyword}); redirect("$BUCKY/$BUCKY_LEXICON_KEYWORD/$input->{keyword}"); } # Edit settings for keyword? Process form results elsif ($input->{c} eq "update") { if (!defined($input->{keyword})) { error("no keyword specified!"); } my %nk = ( threads => " $input->{thread} ", public => (exists($input->{public}) ? 1 : 0), agglutinate => (exists($input->{agglutinate})) ? $input->{agglutinate} : 0, color => $input->{color} ); if (!exists($input->{public})) { $nk{ops} = make_whitelist(); } if ($DEBUG) { header("Updating keyword $input->{keyword}"); menu(); foreach my $ky (keys %nk) { print "$ky => $nk{$ky}
\n"; } } update_keyword($input->{keyword}, \%nk); redirect("$BUCKY/$BUCKY_LEXICON_KEYWORD/$input->{keyword}"); } # Assign keyword processing form action elsif ($input->{c} eq "assign") { keyword_assign_mechanism($input->{keyword}, $input->{thread}, $k); redirect("$BUCKY/maintain/$input->{thread}"); # redirect("$BUCKY/index?keyword=$input->{keyword}"); } # Detach keyword action elsif ($input->{c} eq "detach") { my $t; if (!defined($input->{thread})) { error("no post specified!"); } $t = get_thread($input->{thread}); $k = get_keyword($t->{keyword}); my %nk = ( threads => delete_key($k->{threads}, $input->{thread}) ); if ($DEBUG) { header("Detaching post from $t->{keyword}"); menu(); foreach my $ky (keys %nk) { print "$ky => $nk{$ky}
\n"; } print "keyword ==> $t->{keyword}
\n"; print "detaching $t->{title} from $t->{keyword}
\n"; } update_keyword($t->{keyword}, \%nk); update_thread_keyword($t->{id}, "NULL"); redirect("$BUCKY/maintain/$t->{id}"); } # Display main index page else { my $tag = exists($input->{tag}) ? $input->{tag} : undef; my $keyword = exists($input->{keyword}) ? $input->{keyword} : "all"; my $limit = exists($input->{limit}) ? int($input->{limit}) : 40; my $date = exists($input->{start}) ? int($input->{start}) : "now"; header({ title => get_random_line("titles"), sticky => $input->{keyword} }); my $keywords = get_keywords(); my $tags = get_tags(); my $menu_args; $menu_args->{keywords} = $keywords->{$keyword} if $keywords->{$keyword}; menu( $menu_args ); print qq(); print qq(); ############################# # KEYWORD LIST print qq(\n); print qq(); } else { welcome_box() if (check_key($USER->{boxes}, "welcome")); bPod_box() if (check_key($USER->{boxes}, "bPod")); radio_box() if (check_key($USER->{boxes}, "radio")); upload_form($keyword) if (check_key($USER->{boxes}, "postform")); hoot_box() if (check_key($USER->{boxes}, "hootbox")); } print qq(\n); print qq(); print qq(
\n); print qq(
); my $p = ''; my $l = ''; my $with_letter = 0; my $s = ''; my $pre = ''; my $start = ''; foreach my $k (sort { lc($a) cmp lc($b) } keys %$keywords) { my $style; $l = substr($k,0,1); $start ||= $l; if ($p && lc($l) ne lc($p)) { if ($with_letter > 3) { print qq($start - $pre
); print $s; print qq(
); print qq(
); $s = ''; $with_letter = 1; $p=''; $start = $l; } } $with_letter += 1; $p||=$l; $pre=$l; $s .= qq($k
); } if ($s) { print qq($start - $pre
); print $s; print qq(
); print qq(
); } print qq(
); print qq(
); print qq(.: unsorted :.
); print qq(
\n); alerts(); if ($USER == -1) { bPod_box(); print qq(
\n); if (check_key($USER->{boxes}, "photostream") || ($USER == -1) ) { if ( $keyword ne "all" ) { photostream({ keyword => $keyword, vertical => 0, count => 4 }); } elsif ( $tag ) { photostream({ tag => $tag, vertical => 0, count => 4 }); } else { photostream({ user => 1, vertical => 0, count => 4 }); } } print qq(
); if ($keyword ne "all") { my $threads = throttle_threads({ keyword => $keyword, newest => $date }); thread_box({ threads => $threads, kw => $keywords->{$keyword} }); } elsif ($tag) { my $threads = throttle_threads({ tag => $tag, newest => $date }); thread_box({ threads => $threads, tag => $tags->{$tag} }); } else { alpha_index($keywords, $limit, $date); } print qq(
); print qq(
\n\n); footer(); } $dbh->disconnect (); print "Index: " . &report_time() . "\n" if $timer;