[dw-free] Make site schemes siteviews S2 layout have inheritable themes
[commit: http://hg.dwscoalition.org/dw-free/rev/abe1fed9e575]
http://bugs.dwscoalition.org/show_bug.cgi?id=3189
Allow ?style=site on journals to be customized per site skin.
Patch by
exor674.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=3189
Allow ?style=site on journals to be customized per site skin.
Patch by
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
Files modified:
- bin/upgrading/s2layers/siteviews/layout.s2
- bin/upgrading/s2layers/siteviews/themes.s2
- cgi-bin/DW/SiteScheme.pm
- cgi-bin/LJ/S2.pm
-------------------------------------------------------------------------------- diff -r efb505eb22d0 -r abe1fed9e575 bin/upgrading/s2layers/siteviews/layout.s2 --- a/bin/upgrading/s2layers/siteviews/layout.s2 Tue Nov 16 18:03:46 2010 +0800 +++ b/bin/upgrading/s2layers/siteviews/layout.s2 Tue Nov 16 18:10:42 2010 +0800 @@ -21,7 +21,8 @@ function Page::print() { if ( $*SITEVIEWS ) { $*SITEVIEWS->start_capture(); $this->print_head(); - $this->print_stylesheets(); + $this->print_default_stylesheet(); + $this->print_theme_stylesheet(); $*SITEVIEWS->set_content("head",$*SITEVIEWS->end_capture()); $*SITEVIEWS->set_content("windowtitle",$this->view_title()); @@ -31,6 +32,8 @@ function Page::print() { } } -function Page::print_stylesheets() { +function Page::print_default_stylesheet() { # Do not actually *print* any stylesheets here, but you can $*SITEVIEWS->need_res(...); here to pull in anything. } + +function Page::print_theme_stylesheet() {} diff -r efb505eb22d0 -r abe1fed9e575 bin/upgrading/s2layers/siteviews/themes.s2 --- a/bin/upgrading/s2layers/siteviews/themes.s2 Tue Nov 16 18:03:46 2010 +0800 +++ b/bin/upgrading/s2layers/siteviews/themes.s2 Tue Nov 16 18:10:42 2010 +0800 @@ -2,3 +2,8 @@ layerinfo type = "theme"; layerinfo type = "theme"; layerinfo name = "Default Theme"; layerinfo redist_uniq = "siteviews/default"; + +function Page::print_theme_stylesheet() { + # Do not actually *print* any stylesheets here, but you can $*SITEVIEWS->need_res(...); here to pull in anything. +} + diff -r efb505eb22d0 -r abe1fed9e575 cgi-bin/DW/SiteScheme.pm --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cgi-bin/DW/SiteScheme.pm Tue Nov 16 18:10:42 2010 +0800 @@ -0,0 +1,109 @@ +#!/usr/bin/perl +# +# DW::SiteScheme +# +# SiteScheme related functions +# +# Authors: +# Andrea Nall <anall@andreanall.com> +# +# Copyright (c) 2010 by Dreamwidth Studios, LLC. +# +# This program is free software; you may redistribute it and/or modify it under +# the same terms as Perl itself. For a copy of the license, please reference +# 'perldoc perlartistic' or 'perldoc perlgpl'. +# + +=head1 NAME + +DW::SiteScheme - SiteScheme related functions + +=head1 SYNOPSIS + +=cut + +package DW::SiteScheme; +use strict; + +my %sitescheme_inheritance = ( + blueshift => 'common', + celerity => 'common', + common => 'global', + 'gradation-horizontal' => 'common', + 'gradation-vertical' => 'common', + lynx => 'common', +); + +my $default_sitescheme = "blueshift"; + +eval "use DW::SiteScheme::Local;"; + +# no POD, should only be called from Local module +# DW::SiteScheme->register_siteschemes( foo => 'bar' ); +sub register_siteschemes { + my ( $self, %data ) = @_; + %sitescheme_inheritance = ( + %sitescheme_inheritance, + %data + ); +} + +# no POD, should only be called from Local module +# DW::SiteScheme->register_siteschemes( 'foo' ); +sub register_default_sitescheme { + $default_sitescheme = $_[1]; +} + +=head2 C<< DW::SiteScheme->determine_current_sitescheme >> + +Determine the siteschehe, using the following in order: + +=over + +=item bml_use_scheme note + +=item usescheme GET argument + +=item BMLschemepref cookie + +=item Default sitescheme + +=item 'global' + +=back + +=cut + +sub determine_current_sitescheme { + my $r = DW::Request->get; + + my $rv; + + if ( defined $r ) { + $rv = $r->note( 'bml_use_scheme' ) || + $r->get_args->{usescheme} || + $r->cookie( 'BMLschemepref' ); + } + return $rv || + $default_sitescheme || + 'global'; +} + +=head2 C<< DW::SiteScheme->get_sitescheme_inheritance( $scheme ) >> + +Scheme defaults to the current sitescheme. + +Returns the inheritance array, with the provided scheme being at the start of the list. + +=cut + +sub get_sitescheme_inheritance { + my ( $self, $scheme ) = @_; + $scheme ||= $self->determine_current_sitescheme; + my @scheme; + push @scheme, $scheme; + push @scheme, $scheme while ( $scheme = $sitescheme_inheritance{$scheme} ); + return @scheme; +} + +1; \ No newline at end of file diff -r efb505eb22d0 -r abe1fed9e575 cgi-bin/LJ/S2.pm --- a/cgi-bin/LJ/S2.pm Tue Nov 16 18:03:46 2010 +0800 +++ b/cgi-bin/LJ/S2.pm Tue Nov 16 18:10:42 2010 +0800 @@ -37,6 +37,8 @@ use Apache2::Const qw/ :common /; use Apache2::Const qw/ :common /; use POSIX (); +use DW::SiteScheme; + # TEMP HACK sub get_s2_reader { return LJ::get_dbh("s2slave", "slave", "master"); @@ -894,10 +896,17 @@ sub siteviews_style { my %style; my $public = get_public_layers(); + my $theme = "siteviews/default"; + foreach my $candidate ( DW::SiteScheme->get_sitescheme_inheritance ) { + if ( $public->{"siteviews/$candidate"} ) { + $theme = "siteviews/$candidate"; + last; + } + } %style = ( core => "core2", layout => "siteviews/layout", - theme => "siteviews/default", + theme => $theme, ); # convert the value names to s2layerid --------------------------------------------------------------------------------