Dotclear

source: themes/ductile/_public.php @ 828:56898bb91d9d

Revision 828:56898bb91d9d, 14.2 KB checked in by franck <carnet.franck.paul@…>, 13 years ago (diff)

Now Ductile configuration is blog independent

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

Sites map