1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
3 | # |
---|
4 | # This file is part of Dotclear 2. |
---|
5 | # |
---|
6 | # Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear |
---|
7 | # Licensed under the GPL version 2.0 license. |
---|
8 | # See LICENSE file or |
---|
9 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
10 | # |
---|
11 | # -- END LICENSE BLOCK ----------------------------------------- |
---|
12 | |
---|
13 | if (!defined('DC_RC_PATH')) { return; } |
---|
14 | |
---|
15 | # Behaviors |
---|
16 | $core->addBehavior('publicHeadContent',array('tplDuctileTheme','publicHeadContent')); |
---|
17 | |
---|
18 | # Template items |
---|
19 | $core->tpl->addValue('Stickers',array('tplDuctileTheme','showStickers')); |
---|
20 | |
---|
21 | class tplDuctileTheme |
---|
22 | { |
---|
23 | public static function showStickers($attr) |
---|
24 | { |
---|
25 | $res = ''; |
---|
26 | $default = false; |
---|
27 | $img_url = $GLOBALS['core']->blog->settings->system->themes_url.'/'.$GLOBALS['core']->blog->settings->system->theme.'/img/'; |
---|
28 | |
---|
29 | $s = $GLOBALS['core']->blog->settings->themes->get($GLOBALS['core']->blog->settings->system->theme.'_stickers'); |
---|
30 | |
---|
31 | if ($s === null) { |
---|
32 | $default = true; |
---|
33 | } else { |
---|
34 | $s = @unserialize($s); |
---|
35 | if (!is_array($s)) { |
---|
36 | $default = true; |
---|
37 | } else { |
---|
38 | $s = array_filter($s,"self::cleanStickers"); |
---|
39 | if (count($s) == 0) { |
---|
40 | $default = true; |
---|
41 | } else { |
---|
42 | $count = 1; |
---|
43 | foreach ($s as $sticker) { |
---|
44 | $res .= self::setSticker($count,($count == count($s)),$sticker['label'],$sticker['url'],$img_url.$sticker['image']); |
---|
45 | $count++; |
---|
46 | } |
---|
47 | } |
---|
48 | } |
---|
49 | } |
---|
50 | |
---|
51 | if ($default || $res == '') { |
---|
52 | $res = self::setSticker(1,true,__('Feed'),$GLOBALS['core']->blog->url.$GLOBALS['core']->url->getBase('feed').'/atom',$img_url.'sticker-feed.png'); |
---|
53 | } |
---|
54 | |
---|
55 | if ($res != '') { |
---|
56 | $res = '<ul id="stickers">'."\n".$res.'</ul>'."\n"; |
---|
57 | return $res; |
---|
58 | } |
---|
59 | } |
---|
60 | |
---|
61 | protected static function cleanStickers($s) |
---|
62 | { |
---|
63 | if (is_array($s)) { |
---|
64 | if (isset($s['label']) && isset($s['url']) && isset($s['image'])) { |
---|
65 | if ($s['label'] != null && $s['url'] != null && $s['image'] != null) { |
---|
66 | return true; |
---|
67 | } |
---|
68 | } |
---|
69 | } |
---|
70 | return false; |
---|
71 | } |
---|
72 | |
---|
73 | protected static function setSticker($position,$last,$label,$url,$image) |
---|
74 | { |
---|
75 | return '<li id="sticker'.$position.'"'.($last ? ' class="last"' : '').'>'."\n". |
---|
76 | '<a href="'.$url.'">'."\n". |
---|
77 | '<img alt="" src="'.$image.'" />'."\n". |
---|
78 | '<span>'.$label.'</span>'."\n". |
---|
79 | '</a>'."\n". |
---|
80 | '</li>'."\n"; |
---|
81 | } |
---|
82 | |
---|
83 | public static function publicHeadContent($core) |
---|
84 | { |
---|
85 | echo |
---|
86 | '<style type="text/css">'."\n". |
---|
87 | '/* Additionnal style directives */'."\n". |
---|
88 | self::ductileStyleHelper(). |
---|
89 | "</style>\n"; |
---|
90 | } |
---|
91 | |
---|
92 | public static function ductileStyleHelper() |
---|
93 | { |
---|
94 | $s = $GLOBALS['core']->blog->settings->themes->get($GLOBALS['core']->blog->settings->system->theme.'_style'); |
---|
95 | |
---|
96 | if ($s === null) { |
---|
97 | return; |
---|
98 | } |
---|
99 | |
---|
100 | $s = @unserialize($s); |
---|
101 | if (!is_array($s)) { |
---|
102 | return; |
---|
103 | } |
---|
104 | |
---|
105 | $css = array(); |
---|
106 | |
---|
107 | # Properties |
---|
108 | |
---|
109 | # Blog description |
---|
110 | $selectors = '#blogdesc'; |
---|
111 | if (isset($s['subtitle_hidden'])) self::prop($css,$selectors,'display',($s['subtitle_hidden'] ? 'none' : null)); |
---|
112 | |
---|
113 | # Main font |
---|
114 | $selectors = 'body, #supranav li a span, #comments.me, a.comment-number'; |
---|
115 | if (isset($s['body_font'])) self::prop($css,$selectors,'font-family',self::fontDef($s['body_font'])); |
---|
116 | |
---|
117 | # Secondary font |
---|
118 | $selectors = '#blogdesc, #supranav, #content-info, #subcategories, #comments-feed, #sidebar h2, #sidebar h3, #footer p'; |
---|
119 | if (isset($s['alternate_font'])) self::prop($css,$selectors,'font-family',self::fontDef($s['alternate_font'])); |
---|
120 | |
---|
121 | # Inside posts links font weight |
---|
122 | $selectors = '.post-excerpt a, .post-content a'; |
---|
123 | if (isset($s['post_link_w'])) self::prop($css,$selectors,'font-weight',($s['post_link_w'] ? 'bold' : 'normal')); |
---|
124 | |
---|
125 | # Inside posts links colors (normal, visited) |
---|
126 | $selectors = '.post-excerpt a:link, .post-excerpt a:visited, .post-content a:link, .post-content a:visited'; |
---|
127 | if (isset($s['post_link_v_c'])) self::prop($css,$selectors,'color',$s['post_link_v_c']); |
---|
128 | |
---|
129 | # Inside posts links colors (hover, active, focus) |
---|
130 | $selectors = '.post-excerpt a:hover, .post-excerpt a:active, .post-excerpt a:focus, .post-content a:hover, .post-content a:active, .post-content a:focus'; |
---|
131 | if (isset($s['post_link_f_c'])) self::prop($css,$selectors,'color',$s['post_link_f_c']); |
---|
132 | |
---|
133 | # Style directives |
---|
134 | $res = ''; |
---|
135 | foreach ($css as $selector => $values) { |
---|
136 | $res .= $selector." {\n"; |
---|
137 | foreach ($values as $k => $v) { |
---|
138 | $res .= $k.':'.$v.";\n"; |
---|
139 | } |
---|
140 | $res .= "}\n"; |
---|
141 | } |
---|
142 | |
---|
143 | # Large screens |
---|
144 | $css_large = array(); |
---|
145 | |
---|
146 | # Blog title font weight |
---|
147 | $selectors = 'h1, h1 a:link, h1 a:visited, h1 a:hover, h1 a:visited, h1 a:focus'; |
---|
148 | if (isset($s['blog_title_w'])) self::prop($css_large,$selectors,'font-weight',($s['blog_title_w'] ? 'bold' : 'normal')); |
---|
149 | |
---|
150 | # Blog title font size |
---|
151 | $selectors = 'h1'; |
---|
152 | if (isset($s['blog_title_s'])) self::prop($css_large,$selectors,'font-size',$s['blog_title_s']); |
---|
153 | |
---|
154 | # Blog title color |
---|
155 | $selectors = 'h1 a:link, h1 a:visited, h1 a:hover, h1 a:visited, h1 a:focus'; |
---|
156 | if (isset($s['blog_title_c'])) self::prop($css_large,$selectors,'color',$s['blog_title_c']); |
---|
157 | |
---|
158 | # Post title font weight |
---|
159 | $selectors = 'h2.post-title, h2.post-title a:link, h2.post-title a:visited, h2.post-title a:hover, h2.post-title a:visited, h2.post-title a:focus'; |
---|
160 | if (isset($s['post_title_w'])) self::prop($css_large,$selectors,'font-weight',($s['post_title_w'] ? 'bold' : 'normal')); |
---|
161 | |
---|
162 | # Post title font size |
---|
163 | $selectors = 'h2.post-title'; |
---|
164 | if (isset($s['post_title_s'])) self::prop($css_large,$selectors,'font-size',$s['post_title_s']); |
---|
165 | |
---|
166 | # Post title color |
---|
167 | $selectors = 'h2.post-title a:link, h2.post-title a:visited, h2.post-title a:hover, h2.post-title a:visited, h2.post-title a:focus'; |
---|
168 | if (isset($s['post_title_c'])) self::prop($css_large,$selectors,'color',$s['post_title_c']); |
---|
169 | |
---|
170 | # Style directives for large screens |
---|
171 | if (count($css_large)) { |
---|
172 | $res .= '@media only screen and (min-width: 481px) {'."\n"; |
---|
173 | foreach ($css_large as $selector => $values) { |
---|
174 | $res .= $selector." {\n"; |
---|
175 | foreach ($values as $k => $v) { |
---|
176 | $res .= $k.':'.$v.";\n"; |
---|
177 | } |
---|
178 | $res .= "}\n"; |
---|
179 | } |
---|
180 | $res .= "}\n"; |
---|
181 | } |
---|
182 | |
---|
183 | # Small screens |
---|
184 | $css_small = array(); |
---|
185 | |
---|
186 | # Blog title font weight |
---|
187 | $selectors = 'h1, h1 a:link, h1 a:visited, h1 a:hover, h1 a:visited, h1 a:focus'; |
---|
188 | if (isset($s['blog_title_w_m'])) self::prop($css_small,$selectors,'font-weight',($s['blog_title_w_m'] ? 'bold' : 'normal')); |
---|
189 | |
---|
190 | # Blog title font size |
---|
191 | $selectors = 'h1'; |
---|
192 | if (isset($s['blog_title_s_m'])) self::prop($css_small,$selectors,'font-size',$s['blog_title_s_m']); |
---|
193 | |
---|
194 | # Blog title color |
---|
195 | $selectors = 'h1 a:link, h1 a:visited, h1 a:hover, h1 a:visited, h1 a:focus'; |
---|
196 | if (isset($s['blog_title_c_m'])) self::prop($css_small,$selectors,'color',$s['blog_title_c_m']); |
---|
197 | |
---|
198 | # Post title font weight |
---|
199 | $selectors = 'h2.post-title, h2.post-title a:link, h2.post-title a:visited, h2.post-title a:hover, h2.post-title a:visited, h2.post-title a:focus'; |
---|
200 | if (isset($s['post_title_w_m'])) self::prop($css_small,$selectors,'font-weight',($s['post_title_w_m'] ? 'bold' : 'normal')); |
---|
201 | |
---|
202 | # Post title font size |
---|
203 | $selectors = 'h2.post-title'; |
---|
204 | if (isset($s['post_title_s_m'])) self::prop($css_small,$selectors,'font-size',$s['post_title_s_m']); |
---|
205 | |
---|
206 | # Post title color |
---|
207 | $selectors = 'h2.post-title a:link, h2.post-title a:visited, h2.post-title a:hover, h2.post-title a:visited, h2.post-title a:focus'; |
---|
208 | if (isset($s['post_title_c_m'])) self::prop($css_small,$selectors,'color',$s['post_title_c_m']); |
---|
209 | |
---|
210 | # Style directives for small screens |
---|
211 | if (count($css_small)) { |
---|
212 | $res .= '@media only screen and (max-width: 480px) {'."\n"; |
---|
213 | foreach ($css_small as $selector => $values) { |
---|
214 | $res .= $selector." {\n"; |
---|
215 | foreach ($values as $k => $v) { |
---|
216 | $res .= $k.':'.$v.";\n"; |
---|
217 | } |
---|
218 | $res .= "}\n"; |
---|
219 | } |
---|
220 | $res .= "}\n"; |
---|
221 | } |
---|
222 | |
---|
223 | return $res; |
---|
224 | } |
---|
225 | |
---|
226 | protected static $fonts = array( |
---|
227 | // Theme standard |
---|
228 | 'Ductile body' => '"Century Schoolbook", "Century Schoolbook L", Georgia, serif', |
---|
229 | 'Ductile alternate' => '"Franklin gothic medium", "arial narrow", "DejaVu Sans Condensed", "helvetica neue", helvetica, sans-serif', |
---|
230 | |
---|
231 | // Serif families |
---|
232 | 'Times New Roman' => 'Cambria, "Hoefler Text", Utopia, "Liberation Serif", "Nimbus Roman No9 L Regular", Times, "Times New Roman", serif', |
---|
233 | 'Georgia' => 'Constantia, "Lucida Bright", Lucidabright, "Lucida Serif", Lucida, "DejaVu Serif," "Bitstream Vera Serif", "Liberation Serif", Georgia, serif', |
---|
234 | 'Garamond' => '"Palatino Linotype", Palatino, Palladio, "URW Palladio L", "Book Antiqua", Baskerville, "Bookman Old Style", "Bitstream Charter", "Nimbus Roman No9 L", Garamond, "Apple Garamond", "ITC Garamond Narrow", "New Century Schoolbook", "Century Schoolbook", "Century Schoolbook L", Georgia, serif', |
---|
235 | |
---|
236 | // Sans-serif families |
---|
237 | 'Helvetica/Arial' => 'Frutiger, "Frutiger Linotype", Univers, Calibri, "Gill Sans", "Gill Sans MT", "Myriad Pro", Myriad, "DejaVu Sans Condensed", "Liberation Sans", "Nimbus Sans L", Tahoma, Geneva, "Helvetica Neue", Helvetica, Arial, sans-serif', |
---|
238 | 'Verdana' => 'Corbel, "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", "DejaVu Sans", "Bitstream Vera Sans", "Liberation Sans", Verdana, "Verdana Ref", sans-serif', |
---|
239 | 'Trebuchet MS' => '"Segoe UI", Candara, "Bitstream Vera Sans", "DejaVu Sans", "Bitstream Vera Sans", "Trebuchet MS", Verdana, "Verdana Ref", sans-serif', |
---|
240 | |
---|
241 | // Cursive families |
---|
242 | 'Impact' => 'Impact, Haettenschweiler, "Franklin Gothic Bold", Charcoal, "Helvetica Inserat", "Bitstream Vera Sans Bold", "Arial Black", sans-serif', |
---|
243 | |
---|
244 | // Monospace families |
---|
245 | 'Monospace' => 'Consolas, "Andale Mono WT", "Andale Mono", "Lucida Console", "Lucida Sans Typewriter", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Liberation Mono", "Nimbus Mono L", Monaco, "Courier New", Courier, monospace' |
---|
246 | ); |
---|
247 | |
---|
248 | protected static function fontDef($c) |
---|
249 | { |
---|
250 | return isset(self::$fonts[$c]) ? self::$fonts[$c] : null; |
---|
251 | } |
---|
252 | |
---|
253 | protected static function prop(&$css,$selector,$prop,$value) |
---|
254 | { |
---|
255 | if ($value) { |
---|
256 | $css[$selector][$prop] = $value; |
---|
257 | } |
---|
258 | } |
---|
259 | } |
---|
260 | ?> |
---|