Changeset 156 for trunk/preferences.cgi

Show
Ignore:
Timestamp:
05/14/03 22:29:51 (6 years ago)
Author:
kake
Message:

0.12 14 May 2003

Added OpenGuides::CGI to manage cookies and things, used this to
do more code tidying. Added edit box position option to preferences.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/preferences.cgi

    r52 r156  
    33use strict; 
    44use CGI; 
    5 use CGI::Cookie; 
    65use Config::Tiny; 
    7 use Template; 
     6use OpenGuides::CGI; 
     7use OpenGuides::Utils; 
     8use OpenGuides::Template; 
    89 
     10my $config = Config::Tiny->read("wiki.conf"); 
     11my $wiki = OpenGuides::Utils->make_wiki_object( config => $config ); 
    912my $cgi = CGI->new(); 
    1013my $action = $cgi->param('action') || ''; 
     
    1922 
    2023sub set_preferences { 
    21     my $username = $cgi->param("username") || ""; 
    22     my $gc_link  = $cgi->param('include_geocache_link') || 0, 
    23     my @cookies; 
    24     push @cookies, CGI::Cookie->new( -name    => 'username', 
    25                                      -value   => $username, 
    26                                      -expires => '+12M', 
     24    my $username  = $cgi->param("username") || ""; 
     25    my $gc_link   = $cgi->param('include_geocache_link') || 0; 
     26    my $pre_above = $cgi->param('preview_above_edit_box') || 0; 
     27    my $cookie = OpenGuides::CGI->make_prefs_cookie( 
     28        config => $config, 
     29        username => $username, 
     30        include_geocache_link => $gc_link, 
     31        preview_above_edit_box => $pre_above 
    2732    ); 
    28  
    29     push @cookies, CGI::Cookie->new( -name    => 'include_geocache_link', 
    30                                      -value   => $gc_link, 
    31                                      -expires => '+12M', 
     33    print OpenGuides::Template->output( 
     34        wiki     => $wiki, 
     35        config   => $config, 
     36        template => "preferences.tt", 
     37        cookies  => $cookie, 
     38        vars     => { not_editable           => 1, 
     39                      username               => $username, 
     40                      include_geocache_link  => $gc_link, 
     41                      preview_above_edit_box => $pre_above 
     42                    } 
    3243    ); 
    33     print $cgi->header( -cookie => \@cookies ); 
    34  
    35     process_prefs_template( username              => $username, 
    36                             include_geocache_link => $gc_link ); 
    3744} 
    38  
    3945 
    4046sub show_form { 
    4147    # Get defaults for form fields from cookies. 
    42     my %cookies = CGI::Cookie->fetch; 
    43     my $username = $cookies{"username"} ? $cookies{"username"}->value : ""; 
    44     my $gc_link  = $cookies{"include_geocache_link"} ? $cookies{"include_geocache_link"}->value : 0; 
     48    my %prefs = OpenGuides::CGI->get_prefs_from_cookie( config => $config ); 
    4549 
    46     print $cgi->header; 
    47     process_prefs_template( show_form             => 1, 
    48                             username              => $username, 
    49                             include_geocache_link => $gc_link ); 
     50    print OpenGuides::Template->output( 
     51        wiki     => $wiki, 
     52        config   => $config, 
     53        template => "preferences.tt", 
     54        vars     => { %prefs, 
     55                      not_editable => 1, 
     56                      show_form    => 1 
     57                    } 
     58    ); 
    5059} 
    51  
    52  
    53 sub process_prefs_template { 
    54     # Some TT params are passed in to the sub. 
    55     my %tt_vars = @_; 
    56  
    57     # Others are global and we get them from the config file. 
    58     my $config = Config::Tiny->read("wiki.conf"); 
    59     foreach my $param ( qw( site_name stylesheet_url script_name home_name 
    60                             ) ) { 
    61         $tt_vars{$param} = $config->{_}->{$param}; 
    62     } 
    63  
    64     # This isn't a page you can edit. 
    65     $tt_vars{not_editable} = 1; 
    66  
    67     my %tt_conf = ( INCLUDE_PATH => $config->{_}->{template_path}, 
    68     ); 
    69  
    70     my $tt = Template->new( \%tt_conf ); 
    71     $tt->process( "preferences.tt", \%tt_vars ) or warn $tt->error; 
    72 } 
    73