package DADA::Template::Widgets; use lib qw(./ ../ ./dada ../dada ./DADA ../DADA ./DADA/perllib ../DADA/perllib); use DADA::Config; use DADA::App::Guts; use CGI; my $q = new CGI; my $wierd_abs_path = __FILE__; $wierd_abs_path =~ s/^\///g; my $First_Guess; my $Templates; eval { require File::Spec }; if(!$ALTERNATIVE_HTML_TEMPLATE_PATH && !$@){ $Templates = File::Spec->rel2abs($wierd_abs_path); $Templates =~ s/Widgets\.pm$//g; $Templates =~ s/\/$//; # cut off the first slash, if it's there; $Templates .= '/templates'; $First_Guess = $Templates; }elsif(!$ALTERNATIVE_HTML_TEMPLATE_PATH && $@){ warn "$PROGRAM_NAME warning: File::Spec isn't working correctly: ". $@; warn 'You may want to setup the, "$ALTERNATIVE_HTML_TEMPLATE_PATH" Config variable!'; }else{ $Templates = $ALTERNATIVE_HTML_TEMPLATE_PATH; $First_Guess = $Templates; } # This gets REAL annoying . #warn "$PROGRAM_NAME warning: '$Templates' is not a directory!" # unless -d $Templates; my $second_guess_template = $wierd_abs_path; $second_guess_template =~ s/Widgets\.pm$//g; $second_guess_template =~ s/\/$//; $second_guess_template .= '/templates'; $second_guess_template = '/' . $second_guess_template; require Exporter; @ISA = qw(Exporter); @EXPORT = qw( global_list_sending_checkbox_widget templates_dir list_popup_menu list_popup_login_form list_popup_subscription_form default_screen send_email_screen send_url_email_screen login_switch_widget screen ); use strict; use vars qw( @EXPORT ); my %Global_Template_Variables = ( NO_ONE_SUBSCRIBED => $NO_ONE_SUBSCRIBED, GOOD_JOB_MESSAGE => $GOOD_JOB_MESSAGE, ROOT_PASS_IS_ENCRYPTED => $ROOT_PASS_IS_ENCRYPTED, PROGRAM_NAME => $PROGRAM_NAME, PROGRAM_URL => $PROGRAM_URL, S_PROGRAM_URL => $S_PROGRAM_URL, SHOW_ADMIN_LINK => $SHOW_ADMIN_LINK, SHOW_HELP_LINKS => $SHOW_HELP_LINKS, HELP_LINKS_URL => $HELP_LINKS_URL, MAILPROG => $MAILPROG, FILES => $FILES, VER => $VER, HTML_FOOTER => $HTML_FOOTER, HTMLAREA_URL => $HTMLAREA_URL, GLOBAL_LIST_SENDING => $GLOBAL_LIST_SENDING, ARCHIVE_EDITOR_URL => $ARCHIVE_EDITOR_URL, ); my %Global_Template_Options = ( #debug => 1, path => [$TEMPLATES, $second_guess_template, $Templates, 'templates', 'Templates/templates', 'DADA/Templates/templates', '../DADA/Templates/templates'], die_on_bad_params => 0, loop_context_vars => 1, ); =pod =head1 Name DADA::Template::Widgets =head1 Description Holds commonly used HTML 'widgets' =head1 Subroutines =cut =pod =head2 list_popup_menu returns a popup menu holding all the list names as labels and list shortnames as values =cut sub templates_dir { return $First_Guess; } sub list_popup_menu { my %args = (-show_hidden => 0, -name => 'list', @_); my $labels = {}; require DADA::MailingList::Settings; my @lists = available_lists(-Dont_Die => 1); return ' ' if !@lists; # This needs its own method... foreach my $list( @lists ){ my $ls = DADA::MailingList::Settings->new(-List => $list); my $li = $ls->get; next if $args{-show_hidden} == 0 && $li->{hide_list} == 1; $labels->{$list} = $li->{list_name}; } my @opt_labels = sort { uc($labels->{$a}) cmp uc($labels->{$b}) } keys %$labels; # # return $q->popup_menu( -name => $args{-name}, -id => $args{-name}, '-values' => [@opt_labels], -labels => $labels, -style => 'width:200px'); } sub list_popup_login_form { my %args = (-show_hidden => 0, @_); require HTML::Template::Expr; my $list_popup_menu = list_popup_menu(-name => 'admin_list', -show_hidden => $args{-show_hidden}, ); my $template = HTML::Template::Expr->new(%Global_Template_Options, filename => 'list_popup_login_form.tmpl', ); $template->param(%Global_Template_Variables, list_popup_menu => $list_popup_menu); return $template->output(); } sub list_popup_subscription_form { require HTML::Template::Expr; my %args = (-show_hidden => 0, -name => 'list', -email => undef, -set_flavor => 'subscribe', @_); $args{-set_flavor} = 'u' if $args{-set_flavor} eq 'unsubscribe'; my $list_popup_menu = list_popup_menu(%args); my $email = $args{-email}; my $template = HTML::Template::Expr->new( %Global_Template_Options, filename => 'list_popup_subscription_form.tmpl', ); $template->param( %Global_Template_Variables, list_popup_menu => $list_popup_menu, email => $args{-email}, set_flavor => $args{-set_flavor}, ); return $template->output(); } sub global_list_sending_checkbox_widget { my $list = shift || undef; require DADA::MailingList::Settings; my @available_lists = available_lists(); my @f_a_lists; foreach(@available_lists){ next if $_ eq $list; push(@f_a_lists, $_); } my %list_names; foreach(@f_a_lists){ my $ls = DADA::MailingList::Settings->new(-List => $_); my $li = $ls->get; $list_names{$_} = $_ . ' (' . $li->{list_name} . ')'; } return $q->checkbox_group(-name => 'alternative_list', '-values' => [@f_a_lists], -linebreak =>'true', -labels => \%list_names, -columns => 3, ); } sub default_screen { my %args = ( -show_hidden => undef, -name => undef, -email => undef, -set_flavor => undef, @_ ); require HTML::Template::Expr; require DADA::MailingList::Settings; require DADA::MailingList::Archives; my @list_information = (); # my $reusable_dbh = undef; my $reusable_parser = undef; foreach my $list(available_lists(-In_Order => 1)){ my $ls = DADA::MailingList::Settings->new(-List => $list); my $all_list_info = $ls->get; # well, that didn't work.. #my $ah = DADA::MailingList::Archives->new(-List => $all_list_info, (($reusable_dbh) ? (-dbh => $reusable_dbh) : ()), (($reusable_parser) ? (-parser => $reusable_parser) : ())); my $ah = DADA::MailingList::Archives->new(-List => $all_list_info, (($reusable_parser) ? (-parser => $reusable_parser) : ())); #$reusable_dbh = $ah->{dbh} if ! $reusable_dbh; if($all_list_info->{hide_list} ne "1"){ # should we do this here, or in the template? my $tmpl_list_information = {}; my $html_info = $all_list_info->{info}; $html_info = webify_plain_text($html_info); # Just trying this out... for($all_list_info->{list_owner_email}, $all_list_info->{admin_email}, $all_list_info->{discussion_pop_email}, ){ my $look_e = quotemeta($_); my $protected_e = entity_protected_str($_); $html_info =~ s/$look_e/$protected_e/g; } #/ end that... $tmpl_list_information->{uri_escaped_list} = uriescape($all_list_info->{list}); $tmpl_list_information->{list_name} = $all_list_info->{list_name}; $tmpl_list_information->{info} = $all_list_info->{info}; $tmpl_list_information->{html_info} = $html_info; my $ne = $ah->newest_entry; my $subject = $ah->get_archive_subject($ne); $tmpl_list_information->{newest_archive_blurb} = $ah->message_blurb(); $tmpl_list_information->{newest_archive_subject} = $subject; $tmpl_list_information->{show_archives} = $all_list_info->{show_archives}; push(@list_information, $tmpl_list_information); $reusable_parser = $ah->{parser} if ! $reusable_parser; } } my $list_popup_menu = list_popup_menu(-email => $args{email}, -list => $args{list}, -set_flavor => $args{set_flavor}, ); my $template = HTML::Template::Expr->new( %Global_Template_Options, filename => 'default_screen.tmpl', ); $template->param( %Global_Template_Variables, SHOW_ADMIN_LINK => $SHOW_ADMIN_LINK, list_popup_menu => $list_popup_menu, email => $args{-email}, set_flavor => $args{-set_flavor}, list_information => \@list_information, ); return $template->output(); } sub send_email_screen { my %args = (-list => undef, -vars => {}, @_); die "no list!" if ! $args{-list}; require HTML::Template::Expr; require DADA::MailingList::Settings; my $ls = DADA::MailingList::Settings->new(-List => $args{-list}); my $list_info = $ls->get; my $precendence_popup_menu = $q->popup_menu(-name => 'Precedence', -values => \@PRECEDENCES, -default => $list_info->{precedence}); my $priority_popup_menu = $q->popup_menu(-name =>'Priority', -values =>[keys %PRIORITIES], -labels => \%PRIORITIES, -default => $list_info->{priority}, ); my $template = HTML::Template::Expr->new( %Global_Template_Options, filename => 'send_email_screen.tmpl', ); $template->param( %Global_Template_Variables, %$list_info, %{$args{-vars}}, precendence_popup_menu => $precendence_popup_menu, ); return $template->output(); } sub list_page { my %args = (-list => undef, -email => undef, -set_flavor => undef, @_); $args{-set_flavor} = 'u' if defined($args{-set_flavor}) && $args{-set_flavor} eq 'unsubscribe'; require HTML::Template::Expr; require DADA::MailingList::Settings; my $ls = DADA::MailingList::Settings->new(-List => $args{-list}); my $list_info = $ls->get; my $tmpl_list_information = {}; my $info = $list_info->{info}; my $html_info = $list_info->{info}; $html_info = webify_plain_text($html_info); # Just trying this out... for($list_info->{list_owner_email}, $list_info->{admin_email}, $list_info->{discussion_pop_email}, ){ my $look_e = quotemeta($_); my $protected_e = entity_protected_str($_); $html_info =~ s/$look_e/$protected_e/g; } #/ end that... my $html_privacy_policy = $list_info->{privacy_policy}; $html_privacy_policy =~ s/\n\n/

/gio; $html_privacy_policy =~ s/\n/
/gio; for (qw( show_archives list_name info privacy_policy )){ $tmpl_list_information->{$_} = $list_info->{$_}; } $tmpl_list_information->{uri_escaped_list} = uriescape($list_info->{list}); $tmpl_list_information->{info} = $info; $tmpl_list_information->{html_info} = $html_info; $tmpl_list_information->{html_privacy_policy} = $html_privacy_policy; my $html_archive_list = html_archive_list($args{-list}); my $template = HTML::Template::Expr->new( %Global_Template_Options, filename => 'list_page_screen.tmpl', ); $template->param( list => $args{-list}, email => $args{-email}, set_flavor => $args{-set_flavor}, html_archive_list => $html_archive_list, %$tmpl_list_information, %Global_Template_Variables, ); return $template->output(); } sub admin { my %args = (-login_widget => $LOGIN_WIDGET, @_, ); my $login_widget = $LOGIN_WIDGET; # Why is this so BIG?! if($args{-login_widget} eq 'text_box'){ $login_widget = 'text_box'; } elsif($LOGIN_WIDGET eq 'popup_menu'){ $login_widget = 'popup_menu'; } elsif($LOGIN_WIDGET eq 'text_box') { $login_widget = 'text_box'; } else { warn "'\$LOGIN_WIDGET' misconfigured!"; } my @available_lists = available_lists(); my $list_max_reached = 0; $list_max_reached = 1 if(($LIST_QUOTA) && (($#available_lists + 1) >= $LIST_QUOTA)); my $list_popup_menu = list_popup_menu(-name => 'admin_list', -show_hidden => 0, ); require HTML::Template::Expr; my $template = HTML::Template::Expr->new(%Global_Template_Options, filename => 'admin_screen.tmpl', ); $template->param( %Global_Template_Variables, login_widget => $login_widget, list_popup_menu => $list_popup_menu, list_max_reached => $list_max_reached, ); return $template->output(); } sub html_archive_list { # god, what a mess... my $list = shift; my $t = ""; require HTML::Template::Expr; require DADA::MailingList::Archives; require DADA::MailingList::Settings; my $ls = DADA::MailingList::Settings->new(-List => $list); my $li = $ls->get; my $archive = DADA::MailingList::Archives->new(-List => $li); my $entries = $archive->get_archive_entries(); $t = $q->h3("Archives:") if defined($entries->[0]); my ($begin, $stop) = $archive->create_index(0); my $i; my $stopped_at = $begin; my $num = $begin; $num++; my @archive_nums; my @archive_links; my $th_entries = []; # iterate and save for($i = $begin; $i <=$stop; $i++){ my $link; if(defined($entries->[$i])){ my ($subject, $message, $format, $raw_msg) = $archive->get_archive_info($entries->[$i]); # this is so atrocious. my $date = date_this(-Packed_Date => $entries->[$i], -Write_Month => $li->{archive_show_month}, -Write_Day => $li->{archive_show_day}, -Write_Year => $li->{archive_show_year}, -Write_H_And_M => $li->{archive_show_hour_and_minute}, -Write_Second => $li->{archive_show_second}); my $entry = { id => $entries->[$i], date => $date, subject => $subject, 'format' => $format, list => $list, uri_escaped_list => uriescape($list), PROGRAM_URL => $PROGRAM_URL, message_blurb => $archive->message_blurb(-key => $entries->[$i]), }; $stopped_at++; push(@archive_nums, $num); push(@archive_links, $link); $num++; push(@$th_entries, $entry); } } my $ii; for($ii=0;$ii<=$#archive_links; $ii++){ my $bullet = $archive_nums[$ii]; #fix if we're doing reverse chronologic $bullet = (($#{$entries}+1) - ($archive_nums[$ii]) +1) if($li->{sort_archives_in_reverse} == 1); # yeah, whatever. $th_entries->[$ii]->{bullet} = $bullet; } $t .= screen(-screen => 'archive_list_widget.tmpl', -vars => { entries => $th_entries, list => $list, list_name => $li->{list_name}, }); $t .= qq{

(archive rss, atom )

} if $li->{publish_archives_rss} == 1; $t .= $archive->create_index_nav($li->{list}, $stopped_at); $t .= $archive->make_search_form($li->{list}) if( ( $li->{archive_search_form} eq "1") && (defined($entries->[0]))); #$t .= $q->hr() if defined($entries->[0]); return $t; } sub login_switch_widget { my $args = shift; die "no list!" if ! $args->{-list}; my @lists = available_lists(); my %label = (); foreach my $list( @lists ){ my $ls = DADA::MailingList::Settings->new(-List => $list); my $li = $ls->get; $label{$list} = $li->{list_name} . ' (' . $list . ')'; } # a complete guess. my $location = $q->self_url || $S_PROGRAM_URL . '?flavor=' . $args->{-f}; $label{$args->{-list}} = '----------'; if($lists[1]){ return $q->start_form(-action => $S_PROGRAM_URL, -method => "post", ) . $q->popup_menu(-style => 'width:75px', -name => 'change_to_list', -value => [@lists], -default => $args->{-list}, -labels => {%label}, ) . $q->hidden(-name => 'location', -value => $location, ) . $q->hidden(-name => 'flavor', -value => 'change_login', -override => 1, ) . $q->submit(-value => 'switch', -class=>'plain') . $q->end_form(); }else{ return ''; } } sub screen { my %args = (-screen => undef, -list => undef, #nothin' doin'?! -vars => {}, -expr => 0, -data => undef, @_ ); die "no screen! or data" if ! $args{-screen} && ! $args{-data}; my $template; if($args{-expr}){ if($args{-screen}){ require HTML::Template::Expr; $template = HTML::Template::Expr->new(%Global_Template_Options, filename => $args{-screen}, ); }elsif($args{-data}){ require HTML::Template::Expr; $template = HTML::Template::Expr->new(%Global_Template_Options, scalarref => $args{-data}, ); }else{ warn "what are you trying to do?!"; } }else{ if($args{-screen}){ require HTML::Template; $template = HTML::Template->new(%Global_Template_Options, filename => $args{-screen}, ); }elsif($args{-data}){ require HTML::Template; $template = HTML::Template->new(%Global_Template_Options, scalarref => $args{-data}, ); }else{ warn "what are you trying to do?!"; } } $template->param( %Global_Template_Variables, %{$args{-vars}}, ); if($args{-list}){ $template->param('list', $args{-list}); } return $template->output(); } 1; =pod =head1 COPYRIGHT Copyright (c) 1999 - 2005 Justin Simoni http://justinsimoni.com All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. =cut