OSDN Git Service

Model::Base: remove deprecated / unused functions
[newslash/newslash.git] / src / newslash_web / lib / Newslash / Model / Skins.pm
1 package Newslash::Model::Skins;
2 use Newslash::Model::Base -base;
3
4 use URI ();
5
6 ## WORNING:
7 ## This is legacy from slash. deprecated, and you can use only backword-compatible.
8
9 use constant MAINPAGE_SKID => 1;
10
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.
15 sub getSkin {
16     my($self, $skid, $options) = @_;
17
18     if (!$skid) {
19         #if ($ENV{GATEWAY_INTERFACE}) {
20         #    #errorLog("cannot getSkin for empty skid");
21         #}
22         #$skid = getCurrentStatic('mainpage_skid');
23         $skid = MAINPAGE_SKID;
24 ;
25     }
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) {
31                 return $skins->{$id};
32             }
33         }
34         return undef;
35     }
36     return $skins->{$skid};
37 }
38
39 ########################################################
40 sub getSkins {
41     my($self, $options) = @_;
42     my $db = $self->new_instance_of('Newslash::Model::LegacyDB');
43
44     my $ref_func = sub{
45         my($self, $options) = @_;
46         #my $constants = getCurrentStatic();
47
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);
54         #}
55
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;
64
65             # Blank index_handler defaults to index.pl.
66             $skins_ref->{$skid}{index_handler} ||= 'index.pl';
67
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};
73
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/;
77
78             # Massage the skin_colors data into this hashref in an
79             # appropriate place.
80             for my $name (keys %{$colors->{$color_skid}}) {
81                 $skins_ref->{$skid}{skincolors}{$name} = $colors->{$color_skid}{$name}{skincolor};
82             }
83
84             $skins_ref->{$skid}{basedomain} = $skins_ref->{$host_skid}{hostname};
85
86             $skins_ref->{$skid}{absolutedir} = $skins_ref->{$url_skid}{url}
87               || "http://$skins_ref->{$skid}{basedomain}";
88             $skins_ref->{$skid}{absolutedir} =~ s{/+$}{};
89
90             my $rootdir_uri = URI->new($skins_ref->{$skid}{absolutedir});
91
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" }
96
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{/+$}{};
102             #} else {
103                 $skins_ref->{$skid}{absolutedir_secure} = $skins_ref->{$skid}{absolutedir};
104             #}
105         }
106         return $skins_ref;
107     };
108     #return $self->cache_local_and_memcached('getSkins', $ref_func);
109     return $ref_func->($options);
110 }
111
112
113 1;