Changeset 14077
- Timestamp:
- 07/25/08 22:40:45 (5 years ago)
- Files:
-
- 1 modified
-
trunk/cgi-bin/LJ/User.pm (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/cgi-bin/LJ/User.pm
r14070 r14077 2437 2437 my $u = shift; 2438 2438 2439 # FIXME: both of these solutions suck2440 # - ensure that LJ::S2 is loaded via Class::Autouse by calling a method on it2439 # FIXME: this solution sucks 2440 # - ensure that these packages are loaded via Class::Autouse by calling a method on them 2441 2441 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; 2445 2447 2446 2448 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} : ''; 2447 2451 2448 2452 my %style = LJ::S2::get_style($u, "verify"); 2449 2453 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); 2458 2455 2459 2456 # check to see if the user is using a custom layout or theme 2460 2457 # 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; 2470 2461 } 2471 2462 2472 2463 # 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; 2476 2474 2477 2475 # 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; 2479 2478 if ($styleid) { 2480 2479 $style_exists = 1; … … 2491 2490 next if $name eq ""; 2492 2491 next unless $public->{$name}; 2493 my $id = $public->{$name}->{ 's2lid'};2492 my $id = $public->{$name}->{s2lid}; 2494 2493 $style{$layer} = $id if $id; 2495 2494 } 2496 2495 2497 2496 # 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; 2500 2499 2501 2500 # make sure the other layers were set … … 2506 2505 # create the style 2507 2506 if ($style_exists) { 2508 LJ:: cmize::s2_implicit_style_create($u, %style);2507 LJ::Customize->implicit_style_create($u, %style); 2509 2508 } 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; 2520 2523 } 2521 2524
