Changeset 14077

Show
Ignore:
Timestamp:
07/25/08 22:40:45 (5 years ago)
Author:
janine
Message:

LJSUP-2532

Refactor this code so that it uses LJ::S2Theme and LJ::Customize more, and so that it's a little simpler.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/cgi-bin/LJ/User.pm

    r14070 r14077  
    24372437    my $u = shift; 
    24382438 
    2439     # FIXME: both of these solutions suck 
    2440     # - ensure that LJ::S2 is loaded via Class::Autouse by calling a method on it 
     2439    # FIXME: this solution sucks 
     2440    # - ensure that these packages are loaded via Class::Autouse by calling a method on them 
    24412441    LJ::S2->can("dostuff"); 
    2442  
    2443     # - also require LJ::customize 
    2444     require "customizelib.pl"; 
     2442    LJ::S2Theme->can("dostuff"); 
     2443    LJ::Customize->can("dostuff"); 
     2444 
     2445    my $current_theme = LJ::Customize->get_current_theme($u); 
     2446    return unless $current_theme; 
    24452447 
    24462448    my $default_style = LJ::run_hook('get_default_style', $u) || $LJ::DEFAULT_STYLE; 
     2449    my $default_layout_uniq = exists $default_style->{layout} ? $default_style->{layout} : ''; 
     2450    my $default_theme_uniq = exists $default_style->{theme} ? $default_style->{theme} : ''; 
    24472451 
    24482452    my %style = LJ::S2::get_style($u, "verify"); 
    24492453    my $public = LJ::S2::get_public_layers(); 
    2450     my @custom_layouts = LJ::cmize::s2_custom_layer_list($u, 'layout', 'core'); 
    2451     my @custom_themes = LJ::cmize::s2_custom_layer_list($u, 'theme', 'layout'); 
    2452     my $layout = $public->{$style{'layout'}}; 
    2453     my $theme = $public->{$style{'theme'}}; 
    2454     my $default_layout_uniq = exists $default_style->{'layout'} ? $default_style->{'layout'} : ''; 
    2455     my $default_theme_uniq = exists $default_style->{theme} ? $default_style->{theme} : ''; 
    2456     my $style_exists = 0; 
    2457     my $using_custom_layer = 0; 
     2454    my $userlay = LJ::S2::get_layers_of_user($u); 
    24582455 
    24592456    # check to see if the user is using a custom layout or theme 
    24602457    # if so, we want to let them keep using it 
    2461     foreach my $custom_layout (@custom_layouts) { 
    2462         if ($custom_layout == $style{'layout'}) { 
    2463             $using_custom_layer = 1; 
    2464         } 
    2465     } 
    2466     foreach my $custom_theme (@custom_themes) { 
    2467         if ($custom_theme == $style{'theme'}) { 
    2468             $using_custom_layer = 1; 
    2469         } 
     2458    foreach my $layerid (keys %$userlay) { 
     2459        return if $current_theme->layoutid == $layerid; 
     2460        return if $current_theme->themeid == $layerid; 
    24702461    } 
    24712462 
    24722463    # if the user cannot use the layout, switch to the default style (if it's defined) 
    2473     # if the user can use the layout but not the theme, switch to the default theme of that layout 
    2474     if ($default_layout_uniq ne '' && $default_theme_uniq ne '' && ! $using_custom_layer && ! LJ::S2::can_use_layer($u, $layout->{'uniq'})) { 
    2475         my $theme_obj = LJ::S2Theme->load_by_uniq($default_theme_uniq); 
     2464    if (($default_layout_uniq || $default_theme_uniq) && !LJ::S2::can_use_layer($u, $current_theme->layout_uniq)) { 
     2465        my $new_theme; 
     2466        if ($default_theme_uniq) { 
     2467            $new_theme = LJ::S2Theme->load_by_uniq($default_theme_uniq); 
     2468        } else { 
     2469            my $layoutid = $public->{$default_layout_uniq}->{s2lid} if $public->{$default_layout_uniq} && $public->{$default_layout_uniq}->{type} eq "layout"; 
     2470            $new_theme = LJ::S2Theme->load_default_of($layoutid, user => $u) if $layoutid; 
     2471        } 
     2472 
     2473        return unless $new_theme; 
    24762474 
    24772475        # look for a style that uses the default layout/theme, and use it if it exists 
    2478         my $styleid = $theme_obj->get_styleid_for_theme($u); 
     2476        my $styleid = $new_theme->get_styleid_for_theme($u); 
     2477        my $style_exists = 0; 
    24792478        if ($styleid) { 
    24802479            $style_exists = 1; 
     
    24912490            next if $name eq ""; 
    24922491            next unless $public->{$name}; 
    2493             my $id = $public->{$name}->{'s2lid'}; 
     2492            my $id = $public->{$name}->{s2lid}; 
    24942493            $style{$layer} = $id if $id; 
    24952494        } 
    24962495 
    24972496        # make sure core was set 
    2498         $style{'core'} = $public->{$default_layout_uniq->{'b2lid'}} 
    2499             if $style{'core'} == 0; 
     2497        $style{core} = $new_theme->coreid 
     2498            if $style{core} == 0; 
    25002499 
    25012500        # make sure the other layers were set 
     
    25062505        # create the style 
    25072506        if ($style_exists) { 
    2508             LJ::cmize::s2_implicit_style_create($u, %style); 
     2507            LJ::Customize->implicit_style_create($u, %style); 
    25092508        } else { 
    2510             LJ::cmize::s2_implicit_style_create({ 'force' => 1 }, $u, %style); 
    2511         } 
    2512  
    2513     } elsif (! $using_custom_layer && LJ::S2::can_use_layer($u, $layout->{'uniq'}) && ($theme && ! LJ::S2::can_use_layer($u, $theme->{'uniq'}))) { 
    2514         my $theme_obj = LJ::S2Theme->load_default_of($style{layout}, user => $u); 
    2515         $style{theme} = $theme_obj->themeid; 
    2516  
    2517         # create the style 
    2518         LJ::cmize::s2_implicit_style_create($u, %style); 
    2519     } 
     2509            LJ::Customize->implicit_style_create({ 'force' => 1 }, $u, %style); 
     2510        } 
     2511 
     2512    # if the user can use the layout but not the theme, switch to the default theme of that layout 
     2513    } elsif (LJ::S2::can_use_layer($u, $current_theme->layout_uniq) && !LJ::S2::can_use_layer($u, $current_theme->uniq)) { 
     2514        my $new_theme = LJ::S2Theme->load_default_of($current_theme->layoutid, user => $u); 
     2515 
     2516        return unless $new_theme; 
     2517 
     2518        $style{theme} = $new_theme->themeid; 
     2519        LJ::Customize->implicit_style_create($u, %style); 
     2520    } 
     2521 
     2522    return; 
    25202523} 
    25212524