Dotclear

source: themes/ductile/_public.php @ 830:59e1dc63add7

Revision 830:59e1dc63add7, 14.5 KB checked in by franck <carnet.franck.paul@…>, 13 years ago (diff)

Cope with all entry-xxx.html (other than full, short and title)

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

Sites map