Dotclear

source: themes/ductile/_public.php @ 614:851d5791c6d4

Revision 614:851d5791c6d4, 12.3 KB checked in by Franck <carnet.franck.paul@…>, 14 years ago (diff)

Ajout en premier choix du sticker Feed si aucun n'est enregistré

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

Sites map