Dotclear

source: themes/ductile/_public.php @ 592:2434338d7ea1

Revision 592:2434338d7ea1, 12.3 KB checked in by Franck <carnet.franck.paul@…>, 14 years ago (diff)

Ajout d'un script de repli accessible des widgets si l'écran < 1024px

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

Sites map