Dotclear

source: themes/ductile/_public.php @ 444:e6ceb8be48a7

Revision 444:e6ceb8be48a7, 9.6 KB checked in by Franck <carnet.franck.paul@…>, 14 years ago (diff)

PHP 5.2 n'aime pas mon self::

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
19class tplDuctileTheme
20{
21     public static function publicInsideFooter($core)
22     {
23          $res = '';
24          $default = false;
25          $img_url = $core->blog->settings->system->themes_url.'/'.$core->blog->settings->system->theme.'/img/';
26
27          $s = $core->blog->settings->themes->get($core->blog->settings->system->theme.'_stickers');
28
29          if ($s === null) {
30               $default = true;
31          } else {
32               $s = @unserialize($s);
33               if (!is_array($s)) {
34                    $default = true;
35               } else {
36                    $s = array_filter($s,"tplDuctileTheme::cleanStickers");
37                    if (count($s) == 0) {
38                         $default = true;
39                    } else {
40                         $count = 1;
41                         foreach ($s as $sticker) {
42                              $res .= self::setSticker($count,($count == count($s)),$sticker['label'],$sticker['url'],$img_url.$sticker['image']);
43                              $count++;
44                         }
45                    }
46               }
47          }
48
49          if ($default || $res == '') {
50               $res = self::setSticker(1,true,__('Feed'),$core->blog->url.$core->url->getBase('feed').'/atom',$img_url.'sticker-feed.png');
51          }
52
53          if ($res != '') {
54               $res = '<ul id="stickers">'."\n".$res.'</ul>'."\n";
55               echo $res;
56          }
57     }
58     
59     protected static function cleanStickers($s)
60     {
61          if (is_array($s)) {
62               if (isset($s['label']) && isset($s['url']) && isset($s['image'])) {
63                    if ($s['label'] != null && $s['url'] != null && $s['image'] != null) {
64                         return true;
65                    }
66               }
67          }
68          return false;
69     }
70     
71     protected static function setSticker($position,$last,$label,$url,$image)
72     {
73          return '<li id="sticker'.$position.'"'.($last ? ' class="last"' : '').'>'."\n".
74               '<a href="'.$url.'">'."\n".
75               '<img alt="" src="'.$image.'" />'."\n".
76               '<span>'.$label.'</span>'."\n".
77               '</a>'."\n".
78               '</li>'."\n";
79     }
80
81     public static function publicHeadContent($core)
82     {
83          echo 
84               '<style type="text/css">'."\n".
85               '/* '.__('Additionnal style directives').' */'."\n".
86               self::ductileStyleHelper().
87               "</style>\n";
88     }
89     
90     public static function ductileStyleHelper()
91     {
92          $s = $GLOBALS['core']->blog->settings->themes->get($GLOBALS['core']->blog->settings->system->theme.'_style');
93
94          if ($s === null) {
95               return;
96          }
97
98          $s = @unserialize($s);
99          if (!is_array($s)) {
100               return;
101          }
102
103          $css = array();
104
105          # Properties
106         
107          # Blog description
108          $selectors = '#blogdesc';
109          if (isset($s['subtitle_hidden'])) self::prop($css,$selectors,'display',($s['subtitle_hidden'] ? 'none' : null));
110
111          # Main font
112          $selectors = 'body, #supranav li a span, #comments.me, a.comment-number';
113          if (isset($s['body_font'])) self::prop($css,$selectors,'font-family',self::fontDef($s['body_font']));
114
115          # Secondary font
116          $selectors = '#blogdesc, #supranav, #content-info, #subcategories, #comments-feed, #sidebar h2, #sidebar h3, #footer p';
117          if (isset($s['alternate_font'])) self::prop($css,$selectors,'font-family',self::fontDef($s['alternate_font']));
118         
119          # Inside posts links font weight
120          $selectors = '.post-excerpt a, .post-content a';
121          if (isset($s['post_link_w'])) self::prop($css,$selectors,'font-weight',($s['post_link_w'] ? 'bold' : 'normal'));
122
123          # Inside posts links colors (normal, visited)
124          $selectors = '.post-excerpt a:link, .post-excerpt a:visited, .post-content a:link, .post-content a:visited';
125          if (isset($s['post_link_v_c'])) self::prop($css,$selectors,'color',$s['post_link_v_c']);
126
127          # Inside posts links colors (hover, active, focus)
128          $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';
129          if (isset($s['post_link_f_c'])) self::prop($css,$selectors,'color',$s['post_link_f_c']);
130
131          # Style directives
132          $res = '';
133          foreach ($css as $selector => $values) {
134               $res .= $selector." {\n";
135               foreach ($values as $k => $v) {
136                    $res .= $k.':'.$v.";\n";
137               }
138               $res .= "}\n";
139          }
140
141          # Large screens
142          $css_large = array();
143
144          # Blog title font weight
145          $selectors = 'h1, h1 a:link, h1 a:visited, h1 a:hover, h1 a:visited, h1 a:focus';
146          if (isset($s['blog_title_w'])) self::prop($css_large,$selectors,'font-weight',($s['blog_title_w'] ? 'bold' : 'normal'));
147         
148          # Blog title font size
149          $selectors = 'h1';
150          if (isset($s['blog_title_s'])) self::prop($css_large,$selectors,'font-size',$s['blog_title_s']);
151         
152          # Blog title color
153          $selectors = 'h1 a:link, h1 a:visited, h1 a:hover, h1 a:visited, h1 a:focus';
154          if (isset($s['blog_title_c'])) self::prop($css_large,$selectors,'color',$s['blog_title_c']);
155
156          # Post title font weight
157          $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';
158          if (isset($s['post_title_w'])) self::prop($css_large,$selectors,'font-weight',($s['post_title_w'] ? 'bold' : 'normal'));
159         
160          # Post title font size
161          $selectors = 'h2.post-title';
162          if (isset($s['post_title_s'])) self::prop($css_large,$selectors,'font-size',$s['post_title_s']);
163         
164          # Post title color
165          $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';
166          if (isset($s['post_title_c'])) self::prop($css_large,$selectors,'color',$s['post_title_c']);
167
168          # Style directives for large screens
169          if (count($css_large)) {
170               $res .= '@media only screen and (min-width: 481px) {'."\n";
171               foreach ($css_large as $selector => $values) {
172                    $res .= $selector." {\n";
173                    foreach ($values as $k => $v) {
174                         $res .= $k.':'.$v.";\n";
175                    }
176                    $res .= "}\n";
177               }
178               $res .= "}\n";
179          }
180
181          # Small screens
182          $css_small = array();
183
184          # Blog title font weight
185          $selectors = 'h1, h1 a:link, h1 a:visited, h1 a:hover, h1 a:visited, h1 a:focus';
186          if (isset($s['blog_title_w_m'])) self::prop($css_small,$selectors,'font-weight',($s['blog_title_w_m'] ? 'bold' : 'normal'));
187         
188          # Blog title font size
189          $selectors = 'h1';
190          if (isset($s['blog_title_s_m'])) self::prop($css_small,$selectors,'font-size',$s['blog_title_s_m']);
191         
192          # Blog title color
193          $selectors = 'h1 a:link, h1 a:visited, h1 a:hover, h1 a:visited, h1 a:focus';
194          if (isset($s['blog_title_c_m'])) self::prop($css_small,$selectors,'color',$s['blog_title_c_m']);
195
196          # Post title font weight
197          $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';
198          if (isset($s['post_title_w_m'])) self::prop($css_small,$selectors,'font-weight',($s['post_title_w_m'] ? 'bold' : 'normal'));
199         
200          # Post title font size
201          $selectors = 'h2.post-title';
202          if (isset($s['post_title_s_m'])) self::prop($css_small,$selectors,'font-size',$s['post_title_s_m']);
203         
204          # Post title color
205          $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';
206          if (isset($s['post_title_c_m'])) self::prop($css_small,$selectors,'color',$s['post_title_c_m']);
207
208          # Style directives for small screens
209          if (count($css_small)) {
210               $res .= '@media only screen and (max-width: 480px) {'."\n";
211               foreach ($css_small as $selector => $values) {
212                    $res .= $selector." {\n";
213                    foreach ($values as $k => $v) {
214                         $res .= $k.':'.$v.";\n";
215                    }
216                    $res .= "}\n";
217               }
218               $res .= "}\n";
219          }
220         
221          return $res;
222     }
223
224     protected static $fonts = array(
225          // Theme standard
226          'Ductile body' => '"Century Schoolbook", "Century Schoolbook L", Georgia, serif',
227          'Ductile alternate' => '"Franklin gothic medium", "arial narrow", "DejaVu Sans Condensed", "helvetica neue", helvetica, sans-serif',
228
229          // Serif families
230          'Times New Roman' => 'Cambria, "Hoefler Text", Utopia, "Liberation Serif", "Nimbus Roman No9 L Regular", Times, "Times New Roman", serif',
231          'Georgia' => 'Constantia, "Lucida Bright", Lucidabright, "Lucida Serif", Lucida, "DejaVu Serif," "Bitstream Vera Serif", "Liberation Serif", Georgia, serif',
232          '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',
233
234          // Sans-serif families
235          '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',
236          'Verdana' => 'Corbel, "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", "DejaVu Sans", "Bitstream Vera Sans", "Liberation Sans", Verdana, "Verdana Ref", sans-serif',
237          'Trebuchet MS' => '"Segoe UI", Candara, "Bitstream Vera Sans", "DejaVu Sans", "Bitstream Vera Sans", "Trebuchet MS", Verdana, "Verdana Ref", sans-serif',
238
239          // Cursive families
240          'Impact' => 'Impact, Haettenschweiler, "Franklin Gothic Bold", Charcoal, "Helvetica Inserat", "Bitstream Vera Sans Bold", "Arial Black", sans-serif',
241
242          // Monospace families
243          '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'
244     );
245
246     protected static function fontDef($c)
247     {
248          return isset(self::$fonts[$c]) ? self::$fonts[$c] : null;
249     }
250
251     protected static function prop(&$css,$selector,$prop,$value)
252     {
253          if ($value) {
254               $css[$selector][$prop] = $value;
255          }
256     }
257}
258?>
Note: See TracBrowser for help on using the repository browser.

Sites map