Dotclear

source: themes/ductile/_public.php @ 815:556cca249698

Revision 815:556cca249698, 13.3 KB checked in by franck <carnet.franck.paul@…>, 13 years ago (diff)

Fix warning on improper callback spec in array_filter()

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

Sites map