1 package Newslash::Model::Skins;
2 use Newslash::Model::Base -base;
7 ## This is legacy from slash. deprecated, and you can use only backword-compatible.
9 use constant MAINPAGE_SKID => 1;
11 ########################################################
12 # Allow lookup of a skin by either numeric primary key ID,
13 # or by name. skins.name is a unique column so that will
14 # not present a problem.
16 my($self, $skid, $options) = @_;
19 #if ($ENV{GATEWAY_INTERFACE}) {
20 # #errorLog("cannot getSkin for empty skid");
22 #$skid = getCurrentStatic('mainpage_skid');
23 $skid = MAINPAGE_SKID;
26 my $skins = $self->getSkins($options);
27 if ($skid !~ /^\d+$/) {
28 for my $id (sort keys %$skins) {
29 next unless (exists($skins->{$id}{name}));
30 if ($skins->{$id}{name} eq $skid) {
36 return $skins->{$skid};
39 ########################################################
41 my($self, $options) = @_;
42 my $db = $self->new_instance_of('Newslash::Model::LegacyDB');
45 my($self, $options) = @_;
46 #my $constants = getCurrentStatic();
48 #my $colors = $self->sqlSelectAllHashref([qw( skid name )], "*", "skin_colors", "", "GROUP BY skid, name");
49 #my $skins_ref = $self->sqlSelectAllHashref( "skid", "*", "skins");
50 my $colors = $db->sqlSelectAllHashref([qw( skid name )], "*", "skin_colors", "", "GROUP BY skid, name");
51 my $skins_ref = $db->sqlSelectAllHashref( "skid", "*", "skins");
52 #if (my $regex = $constants->{debughash_getSkins}) {
53 # $skins_ref = debugHash($regex, $skins_ref);
56 for my $skid (keys %$skins_ref) {
57 # Set rootdir etc., based on hostname/url, or mainpage's if none
58 #my $host_skid = $skins_ref->{$skid}{hostname} ? $skid : $constants->{mainpage_skid};
59 #my $url_skid = $skins_ref->{$skid}{url} ? $skid : $constants->{mainpage_skid};
60 #my $color_skid = $colors->{$skid} ? $skid : $constants->{mainpage_skid};
61 my $host_skid = $skins_ref->{$skid}{hostname} ? $skid : MAINPAGE_SKID;
62 my $url_skid = $skins_ref->{$skid}{url} ? $skid : MAINPAGE_SKID;
63 my $color_skid = $colors->{$skid} ? $skid : MAINPAGE_SKID;
65 # Blank index_handler defaults to index.pl.
66 $skins_ref->{$skid}{index_handler} ||= 'index.pl';
68 # Adjust min and max and warn if wacky value.
69 $skins_ref->{$skid}{artcount_max} = $skins_ref->{$skid}{artcount_min}
70 if $skins_ref->{$skid}{artcount_max} < $skins_ref->{$skid}{artcount_min};
71 #warn "skin $skid has artcount_max of 0" if !$skins_ref->{$skid}{artcount_max};
72 $self->warn("skin $skid has artcount_max of 0") if !$skins_ref->{$skid}{artcount_max};
74 # Convert an index_handler of foo.pl to an index_static of
75 # foo.shtml, for convenience.
76 ($skins_ref->{$skid}{index_static} = $skins_ref->{$skid}{index_handler}) =~ s/\.pl$/.shtml/;
78 # Massage the skin_colors data into this hashref in an
80 for my $name (keys %{$colors->{$color_skid}}) {
81 $skins_ref->{$skid}{skincolors}{$name} = $colors->{$color_skid}{$name}{skincolor};
84 $skins_ref->{$skid}{basedomain} = $skins_ref->{$host_skid}{hostname};
86 $skins_ref->{$skid}{absolutedir} = $skins_ref->{$url_skid}{url}
87 || "http://$skins_ref->{$skid}{basedomain}";
88 $skins_ref->{$skid}{absolutedir} =~ s{/+$}{};
90 my $rootdir_uri = URI->new($skins_ref->{$skid}{absolutedir});
92 $rootdir_uri->scheme('');
93 $skins_ref->{$skid}{rootdir} = $rootdir_uri->as_string;
94 $skins_ref->{$skid}{rootdir} =~ s{/+$}{};
95 #if (!$skins_ref->{$skid}{rootdir}) { print STDERR scalar(localtime) . " MySQL.pm No rootdir for skid $skid hostname $skins_ref->{$skid}{hostname}\n" }
97 # XXXSKIN - untested; can we reuse $rootdir_uri ?
98 #if ($constants->{use_https_for_absolutedir_secure}) {
99 # $rootdir_uri->scheme('https');
100 # $skins_ref->{$skid}{absolutedir_secure} = $rootdir_uri->as_string;
101 # $skins_ref->{$skid}{absolutedir_secure} =~ s{/+$}{};
103 $skins_ref->{$skid}{absolutedir_secure} = $skins_ref->{$skid}{absolutedir};
108 #return $self->cache_local_and_memcached('getSkins', $ref_func);
109 return $ref_func->($options);