Dotclear

source: themes/ductile/_public.php @ 1096:3c0cfbe684cc

Revision 1096:3c0cfbe684cc, 17.2 KB checked in by franck <carnet.franck.paul@…>, 13 years ago (diff)

Preview of comment may not be mandatory before posting for Ductile theme (new option in config)

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

Sites map