Dotclear

source: themes/ductile/_public.php @ 625:dc37efbbd722

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

Typo

RevLine 
[345]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
[603]15l10n::set(dirname(__FILE__).'/locales/'.$_lang.'/main');
16
[419]17# Behaviors
[345]18$core->addBehavior('publicHeadContent',array('tplDuctileTheme','publicHeadContent'));
[429]19$core->addBehavior('publicInsideFooter',array('tplDuctileTheme','publicInsideFooter'));
[419]20
[563]21# Templates
22$core->tpl->addValue('ductileEntriesList',array('tplDuctileTheme','ductileEntriesList'));
[574]23$core->tpl->addBlock('EntryIfContentIsCut',array('tplDuctileTheme','EntryIfContentIsCut'));
[583]24$core->tpl->addValue('ductileNbEntryPerPage',array('tplDuctileTheme','ductileNbEntryPerPage'));
[563]25
[345]26class tplDuctileTheme
27{
[583]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     
[574]60     public static function EntryIfContentIsCut($attr,$content)
61     {
62          global $core;
63         
[619]64          if (empty($attr['cut_string']) || !empty($attr['full'])) {
[574]65               return '';
66          }
67         
68          $urls = '0';
69          if (!empty($attr['absolute_urls'])) {
70               $urls = '1';
71          }
[619]72
[574]73          $short = $core->tpl->getFilters($attr);
[619]74          $cut = $attr['cut_string'];
[574]75          $attr['cut_string'] = 0;
76          $full = $core->tpl->getFilters($attr);
[619]77          $attr['cut_string'] = $cut;
[574]78
79          return '<?php if (strlen('.sprintf($full,'$_ctx->posts->getContent('.$urls.')').') > '.
80               'strlen('.sprintf($short,'$_ctx->posts->getContent('.$urls.')').')) : ?>'.
81               $content.
82               '<?php endif; ?>';
83     }   
84     
[563]85     public static function ductileEntriesList($attr)
86     {
87          global $core;
88          $default = isset($attr['default']) ? trim($attr['default']) : 'short';
89
90          $model = '';
91          $s = $core->blog->settings->themes->get($core->blog->settings->system->theme.'_entries_lists');
92          if ($s !== null) {
93               $s = @unserialize($s);
94               if (is_array($s)) {
95                    if (isset($s[$core->url->type])) {
96                         $model = $s[$core->url->type];
97                    }
98               }
99          }
100
101          $local_attr = array('src' => '_entry-'.($model ? $model : $default).'.html');
102          return $core->tpl->includeFile($local_attr);
103     }
104
[429]105     public static function publicInsideFooter($core)
[419]106     {
107          $res = '';
108          $default = false;
[429]109          $img_url = $core->blog->settings->system->themes_url.'/'.$core->blog->settings->system->theme.'/img/';
[419]110
[429]111          $s = $core->blog->settings->themes->get($core->blog->settings->system->theme.'_stickers');
[419]112
113          if ($s === null) {
114               $default = true;
115          } else {
116               $s = @unserialize($s);
117               if (!is_array($s)) {
118                    $default = true;
119               } else {
[444]120                    $s = array_filter($s,"tplDuctileTheme::cleanStickers");
[419]121                    if (count($s) == 0) {
122                         $default = true;
123                    } else {
124                         $count = 1;
125                         foreach ($s as $sticker) {
126                              $res .= self::setSticker($count,($count == count($s)),$sticker['label'],$sticker['url'],$img_url.$sticker['image']);
127                              $count++;
128                         }
129                    }
130               }
131          }
132
133          if ($default || $res == '') {
[614]134               $res = self::setSticker(1,true,__('Subscribe'),$core->blog->url.$core->url->getBase('feed').'/atom',$img_url.'sticker-feed.png');
[419]135          }
136
137          if ($res != '') {
138               $res = '<ul id="stickers">'."\n".$res.'</ul>'."\n";
[429]139               echo $res;
[419]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
[345]165     public static function publicHeadContent($core)
166     {
[357]167          echo 
168               '<style type="text/css">'."\n".
[421]169               '/* '.__('Additionnal style directives').' */'."\n".
[357]170               self::ductileStyleHelper().
171               "</style>\n";
[592]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";
[357]177     }
178     
179     public static function ductileStyleHelper()
180     {
[394]181          $s = $GLOBALS['core']->blog->settings->themes->get($GLOBALS['core']->blog->settings->system->theme.'_style');
[357]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
[389]195         
196          # Blog description
197          $selectors = '#blogdesc';
198          if (isset($s['subtitle_hidden'])) self::prop($css,$selectors,'display',($s['subtitle_hidden'] ? 'none' : null));
[357]199
[376]200          # Main font
[387]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']));
[376]203
[378]204          # Secondary font
[387]205          $selectors = '#blogdesc, #supranav, #content-info, #subcategories, #comments-feed, #sidebar h2, #sidebar h3, #footer p';
206          if (isset($s['alternate_font'])) self::prop($css,$selectors,'font-family',self::fontDef($s['alternate_font']));
[378]207         
208          # Inside posts links font weight
[387]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'));
[376]211
[378]212          # Inside posts links colors (normal, visited)
[387]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']);
[378]215
216          # Inside posts links colors (hover, active, focus)
[387]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']);
[357]219
[376]220          # Style directives
[357]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
[387]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
[515]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
[387]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         
[357]314          return $res;
315     }
316
[376]317     protected static $fonts = array(
[377]318          // Theme standard
[376]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',
[377]321
322          // Serif families
[376]323          'Times New Roman' => 'Cambria, "Hoefler Text", Utopia, "Liberation Serif", "Nimbus Roman No9 L Regular", Times, "Times New Roman", serif',
[625]324          'Georgia' => 'Constantia, "Lucida Bright", Lucidabright, "Lucida Serif", Lucida, "DejaVu Serif", "Bitstream Vera Serif", "Liberation Serif", Georgia, serif',
[376]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',
[377]326
327          // Sans-serif families
[376]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',
[377]331
332          // Cursive families
[376]333          'Impact' => 'Impact, Haettenschweiler, "Franklin Gothic Bold", Charcoal, "Helvetica Inserat", "Bitstream Vera Sans Bold", "Arial Black", sans-serif',
[377]334
335          // Monospace families
[376]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
[357]344     protected static function prop(&$css,$selector,$prop,$value)
345     {
346          if ($value) {
347               $css[$selector][$prop] = $value;
348          }
[345]349     }
350}
351?>
Note: See TracBrowser for help on using the repository browser.

Sites map