1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
3 | # This file is part of Ductile, a theme for Dotclear |
---|
4 | # |
---|
5 | # Copyright (c) 2011 - Association Dotclear |
---|
6 | # Licensed under the GPL version 2.0 license. |
---|
7 | # See LICENSE file or |
---|
8 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
9 | # |
---|
10 | # -- END LICENSE BLOCK ----------------------------------------- |
---|
11 | |
---|
12 | if (!defined('DC_RC_PATH')) { return; } |
---|
13 | |
---|
14 | l10n::set(dirname(__FILE__).'/locales/'.$_lang.'/main'); |
---|
15 | |
---|
16 | # Behaviors |
---|
17 | $core->addBehavior('publicHeadContent',array('tplDuctileTheme','publicHeadContent')); |
---|
18 | $core->addBehavior('publicInsideFooter',array('tplDuctileTheme','publicInsideFooter')); |
---|
19 | |
---|
20 | # Templates |
---|
21 | $core->tpl->addValue('ductileEntriesList',array('tplDuctileTheme','ductileEntriesList')); |
---|
22 | $core->tpl->addBlock('EntryIfContentIsCut',array('tplDuctileTheme','EntryIfContentIsCut')); |
---|
23 | $core->tpl->addValue('ductileNbEntryPerPage',array('tplDuctileTheme','ductileNbEntryPerPage')); |
---|
24 | |
---|
25 | class tplDuctileTheme |
---|
26 | { |
---|
27 | public static function ductileNbEntryPerPage($attr) |
---|
28 | { |
---|
29 | global $core; |
---|
30 | |
---|
31 | $nb = 0; |
---|
32 | $s = $core->blog->settings->themes->get($core->blog->settings->system->theme.'_entries_counts'); |
---|
33 | if ($s !== null) { |
---|
34 | $s = @unserialize($s); |
---|
35 | if (is_array($s)) { |
---|
36 | if (isset($s[$core->url->type])) { |
---|
37 | // Nb de billets par page défini par la config du thème |
---|
38 | $nb = (integer) $s[$core->url->type]; |
---|
39 | } else { |
---|
40 | if (($core->url->type == 'default-page') && (isset($s['default']))) { |
---|
41 | // Les pages 2 et suivantes de la home ont le même nombre de billet que la première page |
---|
42 | $nb = (integer) $s['default']; |
---|
43 | } |
---|
44 | } |
---|
45 | } |
---|
46 | } |
---|
47 | |
---|
48 | if ($nb == 0) { |
---|
49 | if (!empty($attr['nb'])) { |
---|
50 | // Nb de billets par page défini par défaut dans le template |
---|
51 | $nb = (integer) $attr['nb']; |
---|
52 | } |
---|
53 | } |
---|
54 | |
---|
55 | if ($nb > 0) |
---|
56 | return '<?php $_ctx->nb_entry_per_page = '.$nb.' ; ?>'; |
---|
57 | } |
---|
58 | |
---|
59 | public static function EntryIfContentIsCut($attr,$content) |
---|
60 | { |
---|
61 | global $core; |
---|
62 | |
---|
63 | if (empty($attr['cut_string']) || !empty($attr['full'])) { |
---|
64 | return ''; |
---|
65 | } |
---|
66 | |
---|
67 | $urls = '0'; |
---|
68 | if (!empty($attr['absolute_urls'])) { |
---|
69 | $urls = '1'; |
---|
70 | } |
---|
71 | |
---|
72 | $short = $core->tpl->getFilters($attr); |
---|
73 | $cut = $attr['cut_string']; |
---|
74 | $attr['cut_string'] = 0; |
---|
75 | $full = $core->tpl->getFilters($attr); |
---|
76 | $attr['cut_string'] = $cut; |
---|
77 | |
---|
78 | return '<?php if (strlen('.sprintf($full,'$_ctx->posts->getContent('.$urls.')').') > '. |
---|
79 | 'strlen('.sprintf($short,'$_ctx->posts->getContent('.$urls.')').')) : ?>'. |
---|
80 | $content. |
---|
81 | '<?php endif; ?>'; |
---|
82 | } |
---|
83 | |
---|
84 | public static function ductileEntriesList($attr) |
---|
85 | { |
---|
86 | global $core; |
---|
87 | $default = isset($attr['default']) ? trim($attr['default']) : 'short'; |
---|
88 | |
---|
89 | $model = ''; |
---|
90 | $s = $core->blog->settings->themes->get($core->blog->settings->system->theme.'_entries_lists'); |
---|
91 | if ($s !== null) { |
---|
92 | $s = @unserialize($s); |
---|
93 | if (is_array($s)) { |
---|
94 | if (isset($s[$core->url->type])) { |
---|
95 | $model = $s[$core->url->type]; |
---|
96 | } |
---|
97 | } |
---|
98 | } |
---|
99 | |
---|
100 | $local_attr = array('src' => '_entry-'.($model ? $model : $default).'.html'); |
---|
101 | return $core->tpl->includeFile($local_attr); |
---|
102 | } |
---|
103 | |
---|
104 | public static function publicInsideFooter($core) |
---|
105 | { |
---|
106 | $res = ''; |
---|
107 | $default = false; |
---|
108 | $img_url = $core->blog->settings->system->themes_url.'/'.$core->blog->settings->system->theme.'/img/'; |
---|
109 | |
---|
110 | $s = $core->blog->settings->themes->get($core->blog->settings->system->theme.'_stickers'); |
---|
111 | |
---|
112 | if ($s === null) { |
---|
113 | $default = true; |
---|
114 | } else { |
---|
115 | $s = @unserialize($s); |
---|
116 | if (!is_array($s)) { |
---|
117 | $default = true; |
---|
118 | } else { |
---|
119 | $s = array_filter($s,"tplDuctileTheme::cleanStickers"); |
---|
120 | if (count($s) == 0) { |
---|
121 | $default = true; |
---|
122 | } else { |
---|
123 | $count = 1; |
---|
124 | foreach ($s as $sticker) { |
---|
125 | $res .= self::setSticker($count,($count == count($s)),$sticker['label'],$sticker['url'],$img_url.$sticker['image']); |
---|
126 | $count++; |
---|
127 | } |
---|
128 | } |
---|
129 | } |
---|
130 | } |
---|
131 | |
---|
132 | if ($default || $res == '') { |
---|
133 | $res = self::setSticker(1,true,__('Subscribe'),$core->blog->url. |
---|
134 | $core->url->getURLFor('feed','atom'),$img_url.'sticker-feed.png'); |
---|
135 | } |
---|
136 | |
---|
137 | if ($res != '') { |
---|
138 | $res = '<ul id="stickers">'."\n".$res.'</ul>'."\n"; |
---|
139 | echo $res; |
---|
140 | } |
---|
141 | } |
---|
142 | |
---|
143 | protected static function cleanStickers($s) |
---|
144 | { |
---|
145 | if (is_array($s)) { |
---|
146 | if (isset($s['label']) && isset($s['url']) && isset($s['image'])) { |
---|
147 | if ($s['label'] != null && $s['url'] != null && $s['image'] != null) { |
---|
148 | return true; |
---|
149 | } |
---|
150 | } |
---|
151 | } |
---|
152 | return false; |
---|
153 | } |
---|
154 | |
---|
155 | protected static function setSticker($position,$last,$label,$url,$image) |
---|
156 | { |
---|
157 | return '<li id="sticker'.$position.'"'.($last ? ' class="last"' : '').'>'."\n". |
---|
158 | '<a href="'.$url.'">'."\n". |
---|
159 | '<img alt="" src="'.$image.'" />'."\n". |
---|
160 | '<span>'.$label.'</span>'."\n". |
---|
161 | '</a>'."\n". |
---|
162 | '</li>'."\n"; |
---|
163 | } |
---|
164 | |
---|
165 | public static function publicHeadContent($core) |
---|
166 | { |
---|
167 | echo |
---|
168 | '<style type="text/css">'."\n". |
---|
169 | '/* '.__('Additionnal style directives').' */'."\n". |
---|
170 | self::ductileStyleHelper(). |
---|
171 | "</style>\n"; |
---|
172 | |
---|
173 | echo |
---|
174 | '<script type="text/javascript" src="'. |
---|
175 | $core->blog->settings->system->themes_url.'/'.$core->blog->settings->system->theme. |
---|
176 | '/ductile.js"></script>'."\n"; |
---|
177 | } |
---|
178 | |
---|
179 | public static function ductileStyleHelper() |
---|
180 | { |
---|
181 | $s = $GLOBALS['core']->blog->settings->themes->get($GLOBALS['core']->blog->settings->system->theme.'_style'); |
---|
182 | |
---|
183 | if ($s === null) { |
---|
184 | return; |
---|
185 | } |
---|
186 | |
---|
187 | $s = @unserialize($s); |
---|
188 | if (!is_array($s)) { |
---|
189 | return; |
---|
190 | } |
---|
191 | |
---|
192 | $css = array(); |
---|
193 | |
---|
194 | # Properties |
---|
195 | |
---|
196 | # Blog description |
---|
197 | $selectors = '#blogdesc'; |
---|
198 | if (isset($s['subtitle_hidden'])) self::prop($css,$selectors,'display',($s['subtitle_hidden'] ? 'none' : null)); |
---|
199 | |
---|
200 | # Main font |
---|
201 | $selectors = 'body, .supranav li a span, #comments.me, a.comment-number'; |
---|
202 | if (isset($s['body_font'])) self::prop($css,$selectors,'font-family',self::fontDef($s['body_font'])); |
---|
203 | |
---|
204 | # Secondary font |
---|
205 | $selectors = '#blogdesc, .supranav, #content-info, #subcategories, #comments-feed, #sidebar h2, #sidebar h3, #footer'; |
---|
206 | if (isset($s['alternate_font'])) self::prop($css,$selectors,'font-family',self::fontDef($s['alternate_font'])); |
---|
207 | |
---|
208 | # Inside posts links font weight |
---|
209 | $selectors = '.post-excerpt a, .post-content a'; |
---|
210 | if (isset($s['post_link_w'])) self::prop($css,$selectors,'font-weight',($s['post_link_w'] ? 'bold' : 'normal')); |
---|
211 | |
---|
212 | # Inside posts links colors (normal, visited) |
---|
213 | $selectors = '.post-excerpt a:link, .post-excerpt a:visited, .post-content a:link, .post-content a:visited'; |
---|
214 | if (isset($s['post_link_v_c'])) self::prop($css,$selectors,'color',$s['post_link_v_c']); |
---|
215 | |
---|
216 | # Inside posts links colors (hover, active, focus) |
---|
217 | $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'; |
---|
218 | if (isset($s['post_link_f_c'])) self::prop($css,$selectors,'color',$s['post_link_f_c']); |
---|
219 | |
---|
220 | # Style directives |
---|
221 | $res = ''; |
---|
222 | foreach ($css as $selector => $values) { |
---|
223 | $res .= $selector." {\n"; |
---|
224 | foreach ($values as $k => $v) { |
---|
225 | $res .= $k.':'.$v.";\n"; |
---|
226 | } |
---|
227 | $res .= "}\n"; |
---|
228 | } |
---|
229 | |
---|
230 | # Large screens |
---|
231 | $css_large = array(); |
---|
232 | |
---|
233 | # Blog title font weight |
---|
234 | $selectors = 'h1, h1 a:link, h1 a:visited, h1 a:hover, h1 a:visited, h1 a:focus'; |
---|
235 | if (isset($s['blog_title_w'])) self::prop($css_large,$selectors,'font-weight',($s['blog_title_w'] ? 'bold' : 'normal')); |
---|
236 | |
---|
237 | # Blog title font size |
---|
238 | $selectors = 'h1'; |
---|
239 | if (isset($s['blog_title_s'])) self::prop($css_large,$selectors,'font-size',$s['blog_title_s']); |
---|
240 | |
---|
241 | # Blog title color |
---|
242 | $selectors = 'h1 a:link, h1 a:visited, h1 a:hover, h1 a:visited, h1 a:focus'; |
---|
243 | if (isset($s['blog_title_c'])) self::prop($css_large,$selectors,'color',$s['blog_title_c']); |
---|
244 | |
---|
245 | # Post title font weight |
---|
246 | $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'; |
---|
247 | if (isset($s['post_title_w'])) self::prop($css_large,$selectors,'font-weight',($s['post_title_w'] ? 'bold' : 'normal')); |
---|
248 | |
---|
249 | # Post title font size |
---|
250 | $selectors = 'h2.post-title'; |
---|
251 | if (isset($s['post_title_s'])) self::prop($css_large,$selectors,'font-size',$s['post_title_s']); |
---|
252 | |
---|
253 | # Post title color |
---|
254 | $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'; |
---|
255 | if (isset($s['post_title_c'])) self::prop($css_large,$selectors,'color',$s['post_title_c']); |
---|
256 | |
---|
257 | # Simple title color (title without link) |
---|
258 | $selectors = '#content-info h2, .post-title, .post h3, .post h4, .post h5, .post h6, .arch-block h3'; |
---|
259 | if (isset($s['post_simple_title_c'])) self::prop($css_large,$selectors,'color',$s['post_simple_title_c']); |
---|
260 | |
---|
261 | # Style directives for large screens |
---|
262 | if (count($css_large)) { |
---|
263 | $res .= '@media only screen and (min-width: 481px) {'."\n"; |
---|
264 | foreach ($css_large as $selector => $values) { |
---|
265 | $res .= $selector." {\n"; |
---|
266 | foreach ($values as $k => $v) { |
---|
267 | $res .= $k.':'.$v.";\n"; |
---|
268 | } |
---|
269 | $res .= "}\n"; |
---|
270 | } |
---|
271 | $res .= "}\n"; |
---|
272 | } |
---|
273 | |
---|
274 | # Small screens |
---|
275 | $css_small = array(); |
---|
276 | |
---|
277 | # Blog title font weight |
---|
278 | $selectors = 'h1, h1 a:link, h1 a:visited, h1 a:hover, h1 a:visited, h1 a:focus'; |
---|
279 | if (isset($s['blog_title_w_m'])) self::prop($css_small,$selectors,'font-weight',($s['blog_title_w_m'] ? 'bold' : 'normal')); |
---|
280 | |
---|
281 | # Blog title font size |
---|
282 | $selectors = 'h1'; |
---|
283 | if (isset($s['blog_title_s_m'])) self::prop($css_small,$selectors,'font-size',$s['blog_title_s_m']); |
---|
284 | |
---|
285 | # Blog title color |
---|
286 | $selectors = 'h1 a:link, h1 a:visited, h1 a:hover, h1 a:visited, h1 a:focus'; |
---|
287 | if (isset($s['blog_title_c_m'])) self::prop($css_small,$selectors,'color',$s['blog_title_c_m']); |
---|
288 | |
---|
289 | # Post title font weight |
---|
290 | $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'; |
---|
291 | if (isset($s['post_title_w_m'])) self::prop($css_small,$selectors,'font-weight',($s['post_title_w_m'] ? 'bold' : 'normal')); |
---|
292 | |
---|
293 | # Post title font size |
---|
294 | $selectors = 'h2.post-title'; |
---|
295 | if (isset($s['post_title_s_m'])) self::prop($css_small,$selectors,'font-size',$s['post_title_s_m']); |
---|
296 | |
---|
297 | # Post title color |
---|
298 | $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'; |
---|
299 | if (isset($s['post_title_c_m'])) self::prop($css_small,$selectors,'color',$s['post_title_c_m']); |
---|
300 | |
---|
301 | # Style directives for small screens |
---|
302 | if (count($css_small)) { |
---|
303 | $res .= '@media only screen and (max-width: 480px) {'."\n"; |
---|
304 | foreach ($css_small as $selector => $values) { |
---|
305 | $res .= $selector." {\n"; |
---|
306 | foreach ($values as $k => $v) { |
---|
307 | $res .= $k.':'.$v.";\n"; |
---|
308 | } |
---|
309 | $res .= "}\n"; |
---|
310 | } |
---|
311 | $res .= "}\n"; |
---|
312 | } |
---|
313 | |
---|
314 | return $res; |
---|
315 | } |
---|
316 | |
---|
317 | protected static $fonts = array( |
---|
318 | // Theme standard |
---|
319 | 'Ductile body' => '"Century Schoolbook", "Century Schoolbook L", Georgia, serif', |
---|
320 | 'Ductile alternate' => '"Franklin gothic medium", "arial narrow", "DejaVu Sans Condensed", "helvetica neue", helvetica, sans-serif', |
---|
321 | |
---|
322 | // Serif families |
---|
323 | 'Times New Roman' => 'Cambria, "Hoefler Text", Utopia, "Liberation Serif", "Nimbus Roman No9 L Regular", Times, "Times New Roman", serif', |
---|
324 | 'Georgia' => 'Constantia, "Lucida Bright", Lucidabright, "Lucida Serif", Lucida, "DejaVu Serif", "Bitstream Vera Serif", "Liberation Serif", Georgia, serif', |
---|
325 | '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', |
---|
326 | |
---|
327 | // Sans-serif families |
---|
328 | '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', |
---|
329 | 'Verdana' => 'Corbel, "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", "DejaVu Sans", "Bitstream Vera Sans", "Liberation Sans", Verdana, "Verdana Ref", sans-serif', |
---|
330 | 'Trebuchet MS' => '"Segoe UI", Candara, "Bitstream Vera Sans", "DejaVu Sans", "Bitstream Vera Sans", "Trebuchet MS", Verdana, "Verdana Ref", sans-serif', |
---|
331 | |
---|
332 | // Cursive families |
---|
333 | 'Impact' => 'Impact, Haettenschweiler, "Franklin Gothic Bold", Charcoal, "Helvetica Inserat", "Bitstream Vera Sans Bold", "Arial Black", sans-serif', |
---|
334 | |
---|
335 | // Monospace families |
---|
336 | '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' |
---|
337 | ); |
---|
338 | |
---|
339 | protected static function fontDef($c) |
---|
340 | { |
---|
341 | return isset(self::$fonts[$c]) ? self::$fonts[$c] : null; |
---|
342 | } |
---|
343 | |
---|
344 | protected static function prop(&$css,$selector,$prop,$value) |
---|
345 | { |
---|
346 | if ($value) { |
---|
347 | $css[$selector][$prop] = $value; |
---|
348 | } |
---|
349 | } |
---|
350 | } |
---|
351 | ?> |
---|