/
css.tag
126 lines (106 loc) · 2.67 KB
/
css.tag
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# Copyright 2003-2009 Interchange Development Group and others
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. See the LICENSE file for details.
UserTag css Order name
UserTag css addAttr
UserTag css Version 1.9
UserTag css Routine <<EOR
sub {
my ($name, $opt) = @_;
use vars qw/$Tag/;
return unless $name;
my $bn = lc $name;
$bn .= '.css';
my $dir = $opt->{output_dir} ||= 'images';
my $id = "";
if (! $opt->{no_imagedir} ) {
$id = $opt->{imagedir} || $Vend::Cfg->{ImageDir};
$id =~ s:/*$:/:;
}
$dir =~ s:/+$::;
if($opt->{relative}) {
my @dirs = split m{/}, $Global::Variable->{MV_PAGE};
pop @dirs;
if(@dirs) {
$id .= join "/", @dirs, '';
$dir = join "/", $dir, @dirs;
}
}
my $sourcetime;
if($opt->{basefile}) {
$sourcetime = (stat($opt->{basefile}))[9];
#::logDebug("basefile=$opt->{basefile} sourcetime=$sourcetime");
}
my $url = "$id$bn";
my $fn = "$dir/$bn";
my $write;
my $success;
my @stat = stat($fn);
my $writable;
if(@stat) {
$writable = -w _;
if($opt->{basefile}) {
if($sourcetime > $stat[9]) {
#::logDebug("Found a basefile, out of date at modtime=$stat[9]");
$write = 1;
}
else {
#::logDebug("Found a basefile, in date at modtime=$stat[9]");
$success = 1;
}
}
elsif($opt->{timed}) {
my $now = time();
$opt->{timed} .= ' min' if $opt->{timed} =~ /^\d+$/;
my $fliptime = adjust_time($opt->{timed}, $stat[9]);
#::logDebug("fliptime=$fliptime now=$now");
if ($fliptime <= $now) {
$write = 1;
}
else {
$success = 1;
}
}
else {
$success = 1;
}
}
else {
$writable = -w $dir;
$write = 1;
}
my $extra = '';
$extra .= qq{ media="$opt->{media}"} if $opt->{media};
my $css;
$css = length($opt->{literal})
? $opt->{literal}
: interpolate_html($Tag->var($name));
$css =~ s/^\s*<style.*?>\s*//si;
$css =~ s:\s*</style>\s*$:\n:i;
WRITE: {
last WRITE unless $write;
if(! $writable) {
if(@stat) {
logError("CSS file %s has no write permission.", $fn);
}
else {
if ( -d $dir ) {
logError("CSS dir %s has no write permission.", $dir);
}
else {
logError("CSS dir %s does not exist.", $dir);
}
}
last WRITE;
}
my $mode = $opt->{mode} ? oct($opt->{mode}) : 0644;
$success = $Tag->write_relative_file($fn, $css) && chmod($mode, $fn)
or logError("Error writing CSS file %s, returning in page", $fn);
}
return qq{<link rel="stylesheet" href="$url"$extra>} if $success;
return qq{<style type="text/css">\n$css</style>};
}
EOR