Dotclear

source: themes/ductile/_public.php @ 674:79102c5b5346

Revision 674:79102c5b5346, 12.4 KB checked in by Franck <carnet.franck.paul@…>, 14 years ago (diff)

Version 0.9.3

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

Sites map