Dotclear

source: themes/ductile/_public.php @ 583:c7f81168aa22

Revision 583:c7f81168aa22, 12.1 KB checked in by Franck <carnet.franck.paul@…>, 14 years ago (diff)

Configuration du nb de billets par page pour les contextes home (toute page), catégorie, tag, recherche.

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     
170     public static function ductileStyleHelper()
171     {
172          $s = $GLOBALS['core']->blog->settings->themes->get($GLOBALS['core']->blog->settings->system->theme.'_style');
173
174          if ($s === null) {
175               return;
176          }
177
178          $s = @unserialize($s);
179          if (!is_array($s)) {
180               return;
181          }
182
183          $css = array();
184
185          # Properties
186         
187          # Blog description
188          $selectors = '#blogdesc';
189          if (isset($s['subtitle_hidden'])) self::prop($css,$selectors,'display',($s['subtitle_hidden'] ? 'none' : null));
190
191          # Main font
192          $selectors = 'body, #supranav li a span, #comments.me, a.comment-number';
193          if (isset($s['body_font'])) self::prop($css,$selectors,'font-family',self::fontDef($s['body_font']));
194
195          # Secondary font
196          $selectors = '#blogdesc, #supranav, #content-info, #subcategories, #comments-feed, #sidebar h2, #sidebar h3, #footer p';
197          if (isset($s['alternate_font'])) self::prop($css,$selectors,'font-family',self::fontDef($s['alternate_font']));
198         
199          # Inside posts links font weight
200          $selectors = '.post-excerpt a, .post-content a';
201          if (isset($s['post_link_w'])) self::prop($css,$selectors,'font-weight',($s['post_link_w'] ? 'bold' : 'normal'));
202
203          # Inside posts links colors (normal, visited)
204          $selectors = '.post-excerpt a:link, .post-excerpt a:visited, .post-content a:link, .post-content a:visited';
205          if (isset($s['post_link_v_c'])) self::prop($css,$selectors,'color',$s['post_link_v_c']);
206
207          # Inside posts links colors (hover, active, focus)
208          $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';
209          if (isset($s['post_link_f_c'])) self::prop($css,$selectors,'color',$s['post_link_f_c']);
210
211          # Style directives
212          $res = '';
213          foreach ($css as $selector => $values) {
214               $res .= $selector." {\n";
215               foreach ($values as $k => $v) {
216                    $res .= $k.':'.$v.";\n";
217               }
218               $res .= "}\n";
219          }
220
221          # Large screens
222          $css_large = array();
223
224          # Blog title font weight
225          $selectors = 'h1, h1 a:link, h1 a:visited, h1 a:hover, h1 a:visited, h1 a:focus';
226          if (isset($s['blog_title_w'])) self::prop($css_large,$selectors,'font-weight',($s['blog_title_w'] ? 'bold' : 'normal'));
227         
228          # Blog title font size
229          $selectors = 'h1';
230          if (isset($s['blog_title_s'])) self::prop($css_large,$selectors,'font-size',$s['blog_title_s']);
231         
232          # Blog title color
233          $selectors = 'h1 a:link, h1 a:visited, h1 a:hover, h1 a:visited, h1 a:focus';
234          if (isset($s['blog_title_c'])) self::prop($css_large,$selectors,'color',$s['blog_title_c']);
235
236          # Post title font weight
237          $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';
238          if (isset($s['post_title_w'])) self::prop($css_large,$selectors,'font-weight',($s['post_title_w'] ? 'bold' : 'normal'));
239         
240          # Post title font size
241          $selectors = 'h2.post-title';
242          if (isset($s['post_title_s'])) self::prop($css_large,$selectors,'font-size',$s['post_title_s']);
243         
244          # Post title color
245          $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';
246          if (isset($s['post_title_c'])) self::prop($css_large,$selectors,'color',$s['post_title_c']);
247
248          # Simple title color (title without link)
249          $selectors = '#content-info h2, .post-title, .post h3, .post h4, .post h5, .post h6, .arch-block h3';
250          if (isset($s['post_simple_title_c'])) self::prop($css_large,$selectors,'color',$s['post_simple_title_c']);
251
252          # Style directives for large screens
253          if (count($css_large)) {
254               $res .= '@media only screen and (min-width: 481px) {'."\n";
255               foreach ($css_large as $selector => $values) {
256                    $res .= $selector." {\n";
257                    foreach ($values as $k => $v) {
258                         $res .= $k.':'.$v.";\n";
259                    }
260                    $res .= "}\n";
261               }
262               $res .= "}\n";
263          }
264
265          # Small screens
266          $css_small = array();
267
268          # Blog title font weight
269          $selectors = 'h1, h1 a:link, h1 a:visited, h1 a:hover, h1 a:visited, h1 a:focus';
270          if (isset($s['blog_title_w_m'])) self::prop($css_small,$selectors,'font-weight',($s['blog_title_w_m'] ? 'bold' : 'normal'));
271         
272          # Blog title font size
273          $selectors = 'h1';
274          if (isset($s['blog_title_s_m'])) self::prop($css_small,$selectors,'font-size',$s['blog_title_s_m']);
275         
276          # Blog title color
277          $selectors = 'h1 a:link, h1 a:visited, h1 a:hover, h1 a:visited, h1 a:focus';
278          if (isset($s['blog_title_c_m'])) self::prop($css_small,$selectors,'color',$s['blog_title_c_m']);
279
280          # Post title font weight
281          $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';
282          if (isset($s['post_title_w_m'])) self::prop($css_small,$selectors,'font-weight',($s['post_title_w_m'] ? 'bold' : 'normal'));
283         
284          # Post title font size
285          $selectors = 'h2.post-title';
286          if (isset($s['post_title_s_m'])) self::prop($css_small,$selectors,'font-size',$s['post_title_s_m']);
287         
288          # Post title color
289          $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';
290          if (isset($s['post_title_c_m'])) self::prop($css_small,$selectors,'color',$s['post_title_c_m']);
291
292          # Style directives for small screens
293          if (count($css_small)) {
294               $res .= '@media only screen and (max-width: 480px) {'."\n";
295               foreach ($css_small as $selector => $values) {
296                    $res .= $selector." {\n";
297                    foreach ($values as $k => $v) {
298                         $res .= $k.':'.$v.";\n";
299                    }
300                    $res .= "}\n";
301               }
302               $res .= "}\n";
303          }
304         
305          return $res;
306     }
307
308     protected static $fonts = array(
309          // Theme standard
310          'Ductile body' => '"Century Schoolbook", "Century Schoolbook L", Georgia, serif',
311          'Ductile alternate' => '"Franklin gothic medium", "arial narrow", "DejaVu Sans Condensed", "helvetica neue", helvetica, sans-serif',
312
313          // Serif families
314          'Times New Roman' => 'Cambria, "Hoefler Text", Utopia, "Liberation Serif", "Nimbus Roman No9 L Regular", Times, "Times New Roman", serif',
315          'Georgia' => 'Constantia, "Lucida Bright", Lucidabright, "Lucida Serif", Lucida, "DejaVu Serif," "Bitstream Vera Serif", "Liberation Serif", Georgia, serif',
316          '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',
317
318          // Sans-serif families
319          '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',
320          'Verdana' => 'Corbel, "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", "DejaVu Sans", "Bitstream Vera Sans", "Liberation Sans", Verdana, "Verdana Ref", sans-serif',
321          'Trebuchet MS' => '"Segoe UI", Candara, "Bitstream Vera Sans", "DejaVu Sans", "Bitstream Vera Sans", "Trebuchet MS", Verdana, "Verdana Ref", sans-serif',
322
323          // Cursive families
324          'Impact' => 'Impact, Haettenschweiler, "Franklin Gothic Bold", Charcoal, "Helvetica Inserat", "Bitstream Vera Sans Bold", "Arial Black", sans-serif',
325
326          // Monospace families
327          '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'
328     );
329
330     protected static function fontDef($c)
331     {
332          return isset(self::$fonts[$c]) ? self::$fonts[$c] : null;
333     }
334
335     protected static function prop(&$css,$selector,$prop,$value)
336     {
337          if ($value) {
338               $css[$selector][$prop] = $value;
339          }
340     }
341}
342?>
Note: See TracBrowser for help on using the repository browser.

Sites map