Dotclear

source: themes/ductile/_public.php @ 2716:b4abeeea33f2

Revision 2716:b4abeeea33f2, 17.5 KB checked in by franck <carnet.franck.paul@…>, 11 years ago (diff)

Use default Ductile logo if themes prefs not yet saved

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

Sites map