Dotclear

source: themes/ductile/_public.php @ 574:6430df826043

Revision 574:6430df826043, 11.1 KB checked in by Franck <carnet.franck.paul@…>, 14 years ago (diff)

Nouvelle balise de test du contenu coupé. Permet de ne pas afficher "lire la suite…" lorsque le billet est complètement affiché.

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear
7# Licensed under the GPL version 2.0 license.
8# See LICENSE file or
9# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10#
11# -- END LICENSE BLOCK -----------------------------------------
12
13if (!defined('DC_RC_PATH')) { return; }
14
15# Behaviors
16$core->addBehavior('publicHeadContent',array('tplDuctileTheme','publicHeadContent'));
17$core->addBehavior('publicInsideFooter',array('tplDuctileTheme','publicInsideFooter'));
18
19# Templates
20$core->tpl->addValue('ductileEntriesList',array('tplDuctileTheme','ductileEntriesList'));
21$core->tpl->addBlock('EntryIfContentIsCut',array('tplDuctileTheme','EntryIfContentIsCut'));
22
23class tplDuctileTheme
24{
25     public static function EntryIfContentIsCut($attr,$content)
26     {
27          global $core;
28         
29          if (empty($attr['cut_string']) || empty($attr['cut_string'])) {
30               return '';
31          }
32         
33          $urls = '0';
34          if (!empty($attr['absolute_urls'])) {
35               $urls = '1';
36          }
37         
38          $short = $core->tpl->getFilters($attr);
39          $attr['cut_string'] = 0;
40          $full = $core->tpl->getFilters($attr);
41
42          return '<?php if (strlen('.sprintf($full,'$_ctx->posts->getContent('.$urls.')').') > '.
43               'strlen('.sprintf($short,'$_ctx->posts->getContent('.$urls.')').')) : ?>'.
44               $content.
45               '<?php endif; ?>';
46     }   
47     
48     public static function ductileEntriesList($attr)
49     {
50          global $core;
51          $default = isset($attr['default']) ? trim($attr['default']) : 'short';
52
53          $model = '';
54          $s = $core->blog->settings->themes->get($core->blog->settings->system->theme.'_entries_lists');
55          if ($s !== null) {
56               $s = @unserialize($s);
57               if (is_array($s)) {
58                    if (isset($s[$core->url->type])) {
59                         $model = $s[$core->url->type];
60                    }
61               }
62          }
63
64          $local_attr = array('src' => '_entry-'.($model ? $model : $default).'.html');
65          return $core->tpl->includeFile($local_attr);
66     }
67
68     public static function publicInsideFooter($core)
69     {
70          $res = '';
71          $default = false;
72          $img_url = $core->blog->settings->system->themes_url.'/'.$core->blog->settings->system->theme.'/img/';
73
74          $s = $core->blog->settings->themes->get($core->blog->settings->system->theme.'_stickers');
75
76          if ($s === null) {
77               $default = true;
78          } else {
79               $s = @unserialize($s);
80               if (!is_array($s)) {
81                    $default = true;
82               } else {
83                    $s = array_filter($s,"tplDuctileTheme::cleanStickers");
84                    if (count($s) == 0) {
85                         $default = true;
86                    } else {
87                         $count = 1;
88                         foreach ($s as $sticker) {
89                              $res .= self::setSticker($count,($count == count($s)),$sticker['label'],$sticker['url'],$img_url.$sticker['image']);
90                              $count++;
91                         }
92                    }
93               }
94          }
95
96          if ($default || $res == '') {
97               $res = self::setSticker(1,true,__('Feed'),$core->blog->url.$core->url->getBase('feed').'/atom',$img_url.'sticker-feed.png');
98          }
99
100          if ($res != '') {
101               $res = '<ul id="stickers">'."\n".$res.'</ul>'."\n";
102               echo $res;
103          }
104     }
105     
106     protected static function cleanStickers($s)
107     {
108          if (is_array($s)) {
109               if (isset($s['label']) && isset($s['url']) && isset($s['image'])) {
110                    if ($s['label'] != null && $s['url'] != null && $s['image'] != null) {
111                         return true;
112                    }
113               }
114          }
115          return false;
116     }
117     
118     protected static function setSticker($position,$last,$label,$url,$image)
119     {
120          return '<li id="sticker'.$position.'"'.($last ? ' class="last"' : '').'>'."\n".
121               '<a href="'.$url.'">'."\n".
122               '<img alt="" src="'.$image.'" />'."\n".
123               '<span>'.$label.'</span>'."\n".
124               '</a>'."\n".
125               '</li>'."\n";
126     }
127
128     public static function publicHeadContent($core)
129     {
130          echo 
131               '<style type="text/css">'."\n".
132               '/* '.__('Additionnal style directives').' */'."\n".
133               self::ductileStyleHelper().
134               "</style>\n";
135     }
136     
137     public static function ductileStyleHelper()
138     {
139          $s = $GLOBALS['core']->blog->settings->themes->get($GLOBALS['core']->blog->settings->system->theme.'_style');
140
141          if ($s === null) {
142               return;
143          }
144
145          $s = @unserialize($s);
146          if (!is_array($s)) {
147               return;
148          }
149
150          $css = array();
151
152          # Properties
153         
154          # Blog description
155          $selectors = '#blogdesc';
156          if (isset($s['subtitle_hidden'])) self::prop($css,$selectors,'display',($s['subtitle_hidden'] ? 'none' : null));
157
158          # Main font
159          $selectors = 'body, #supranav li a span, #comments.me, a.comment-number';
160          if (isset($s['body_font'])) self::prop($css,$selectors,'font-family',self::fontDef($s['body_font']));
161
162          # Secondary font
163          $selectors = '#blogdesc, #supranav, #content-info, #subcategories, #comments-feed, #sidebar h2, #sidebar h3, #footer p';
164          if (isset($s['alternate_font'])) self::prop($css,$selectors,'font-family',self::fontDef($s['alternate_font']));
165         
166          # Inside posts links font weight
167          $selectors = '.post-excerpt a, .post-content a';
168          if (isset($s['post_link_w'])) self::prop($css,$selectors,'font-weight',($s['post_link_w'] ? 'bold' : 'normal'));
169
170          # Inside posts links colors (normal, visited)
171          $selectors = '.post-excerpt a:link, .post-excerpt a:visited, .post-content a:link, .post-content a:visited';
172          if (isset($s['post_link_v_c'])) self::prop($css,$selectors,'color',$s['post_link_v_c']);
173
174          # Inside posts links colors (hover, active, focus)
175          $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';
176          if (isset($s['post_link_f_c'])) self::prop($css,$selectors,'color',$s['post_link_f_c']);
177
178          # Style directives
179          $res = '';
180          foreach ($css as $selector => $values) {
181               $res .= $selector." {\n";
182               foreach ($values as $k => $v) {
183                    $res .= $k.':'.$v.";\n";
184               }
185               $res .= "}\n";
186          }
187
188          # Large screens
189          $css_large = array();
190
191          # Blog title font weight
192          $selectors = 'h1, h1 a:link, h1 a:visited, h1 a:hover, h1 a:visited, h1 a:focus';
193          if (isset($s['blog_title_w'])) self::prop($css_large,$selectors,'font-weight',($s['blog_title_w'] ? 'bold' : 'normal'));
194         
195          # Blog title font size
196          $selectors = 'h1';
197          if (isset($s['blog_title_s'])) self::prop($css_large,$selectors,'font-size',$s['blog_title_s']);
198         
199          # Blog title color
200          $selectors = 'h1 a:link, h1 a:visited, h1 a:hover, h1 a:visited, h1 a:focus';
201          if (isset($s['blog_title_c'])) self::prop($css_large,$selectors,'color',$s['blog_title_c']);
202
203          # Post title font weight
204          $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';
205          if (isset($s['post_title_w'])) self::prop($css_large,$selectors,'font-weight',($s['post_title_w'] ? 'bold' : 'normal'));
206         
207          # Post title font size
208          $selectors = 'h2.post-title';
209          if (isset($s['post_title_s'])) self::prop($css_large,$selectors,'font-size',$s['post_title_s']);
210         
211          # Post title color
212          $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';
213          if (isset($s['post_title_c'])) self::prop($css_large,$selectors,'color',$s['post_title_c']);
214
215          # Simple title color (title without link)
216          $selectors = '#content-info h2, .post-title, .post h3, .post h4, .post h5, .post h6, .arch-block h3';
217          if (isset($s['post_simple_title_c'])) self::prop($css_large,$selectors,'color',$s['post_simple_title_c']);
218
219          # Style directives for large screens
220          if (count($css_large)) {
221               $res .= '@media only screen and (min-width: 481px) {'."\n";
222               foreach ($css_large as $selector => $values) {
223                    $res .= $selector." {\n";
224                    foreach ($values as $k => $v) {
225                         $res .= $k.':'.$v.";\n";
226                    }
227                    $res .= "}\n";
228               }
229               $res .= "}\n";
230          }
231
232          # Small screens
233          $css_small = array();
234
235          # Blog title font weight
236          $selectors = 'h1, h1 a:link, h1 a:visited, h1 a:hover, h1 a:visited, h1 a:focus';
237          if (isset($s['blog_title_w_m'])) self::prop($css_small,$selectors,'font-weight',($s['blog_title_w_m'] ? 'bold' : 'normal'));
238         
239          # Blog title font size
240          $selectors = 'h1';
241          if (isset($s['blog_title_s_m'])) self::prop($css_small,$selectors,'font-size',$s['blog_title_s_m']);
242         
243          # Blog title color
244          $selectors = 'h1 a:link, h1 a:visited, h1 a:hover, h1 a:visited, h1 a:focus';
245          if (isset($s['blog_title_c_m'])) self::prop($css_small,$selectors,'color',$s['blog_title_c_m']);
246
247          # Post title font weight
248          $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';
249          if (isset($s['post_title_w_m'])) self::prop($css_small,$selectors,'font-weight',($s['post_title_w_m'] ? 'bold' : 'normal'));
250         
251          # Post title font size
252          $selectors = 'h2.post-title';
253          if (isset($s['post_title_s_m'])) self::prop($css_small,$selectors,'font-size',$s['post_title_s_m']);
254         
255          # Post title color
256          $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';
257          if (isset($s['post_title_c_m'])) self::prop($css_small,$selectors,'color',$s['post_title_c_m']);
258
259          # Style directives for small screens
260          if (count($css_small)) {
261               $res .= '@media only screen and (max-width: 480px) {'."\n";
262               foreach ($css_small as $selector => $values) {
263                    $res .= $selector." {\n";
264                    foreach ($values as $k => $v) {
265                         $res .= $k.':'.$v.";\n";
266                    }
267                    $res .= "}\n";
268               }
269               $res .= "}\n";
270          }
271         
272          return $res;
273     }
274
275     protected static $fonts = array(
276          // Theme standard
277          'Ductile body' => '"Century Schoolbook", "Century Schoolbook L", Georgia, serif',
278          'Ductile alternate' => '"Franklin gothic medium", "arial narrow", "DejaVu Sans Condensed", "helvetica neue", helvetica, sans-serif',
279
280          // Serif families
281          'Times New Roman' => 'Cambria, "Hoefler Text", Utopia, "Liberation Serif", "Nimbus Roman No9 L Regular", Times, "Times New Roman", serif',
282          'Georgia' => 'Constantia, "Lucida Bright", Lucidabright, "Lucida Serif", Lucida, "DejaVu Serif," "Bitstream Vera Serif", "Liberation Serif", Georgia, serif',
283          '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',
284
285          // Sans-serif families
286          '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',
287          'Verdana' => 'Corbel, "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", "DejaVu Sans", "Bitstream Vera Sans", "Liberation Sans", Verdana, "Verdana Ref", sans-serif',
288          'Trebuchet MS' => '"Segoe UI", Candara, "Bitstream Vera Sans", "DejaVu Sans", "Bitstream Vera Sans", "Trebuchet MS", Verdana, "Verdana Ref", sans-serif',
289
290          // Cursive families
291          'Impact' => 'Impact, Haettenschweiler, "Franklin Gothic Bold", Charcoal, "Helvetica Inserat", "Bitstream Vera Sans Bold", "Arial Black", sans-serif',
292
293          // Monospace families
294          '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'
295     );
296
297     protected static function fontDef($c)
298     {
299          return isset(self::$fonts[$c]) ? self::$fonts[$c] : null;
300     }
301
302     protected static function prop(&$css,$selector,$prop,$value)
303     {
304          if ($value) {
305               $css[$selector][$prop] = $value;
306          }
307     }
308}
309?>
Note: See TracBrowser for help on using the repository browser.

Sites map