Dotclear

source: themes/ductile/_config.php @ 649:add06bab4a57

Revision 649:add06bab4a57, 16.2 KB checked in by Franck <carnet.franck.paul@…>, 14 years ago (diff)

Affichage des ratios de contraste des couleurs choisies dans le configurateur

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 -----------------------------------------
11if (!defined('DC_CONTEXT_ADMIN')) { return; }
12
13l10n::set(dirname(__FILE__).'/locales/'.$_lang.'/admin');
14
15$img_url = $core->blog->settings->system->themes_url.'/'.$core->blog->settings->system->theme.'/img/';
16$img_url = http::concatURL($core->blog->url,$img_url);
17$img_path = dirname(__FILE__).'/img/';
18
19$standalone_config = (boolean) $core->themes->moduleInfo($core->blog->settings->system->theme,'standalone_config');
20
21$list_types = array(
22     __('Title') => 'title',
23     __('Short') => 'short',
24     __('Full') => 'full'
25);
26
27$contexts = array(
28     'default' => __('Home (first page)'),
29     'default-page' => __('Home (other pages)'),
30     'category' => __('Entries for a category'),
31     'tag' => __('Entries for a tag'),
32     'search' => __('Search result entries'),
33     'archive' => __('Month archive entries')
34);
35
36$fonts = array(
37     __('default') => '',
38     __('Ductile primary') => 'Ductile body',
39     __('Ductile secondary') => 'Ductile alternate',
40     __('Times New Roman') => 'Times New Roman',
41     __('Georgia') => 'Georgia',
42     __('Garamond') => 'Garamond',
43     __('Helvetica/Arial') => 'Helvetica/Arial',
44     __('Verdana') => 'Verdana',
45     __('Trebuchet MS') => 'Trebuchet MS',
46     __('Impact') => 'Impact',
47     __('Monospace') => 'Monospace'
48);
49
50function adjustFontSize($s)
51{
52     if (preg_match('/^([0-9.]+)\s*(%|pt|px|em|ex)?$/',$s,$m)) {
53          if (empty($m[2])) {
54               $m[2] = 'em';
55          }
56          return $m[1].$m[2];
57     }
58
59     return null;
60}
61
62function adjustColor($c)
63{
64     if ($c === '') {
65          return '';
66     }
67
68     $c = strtoupper($c);
69
70     if (preg_match('/^[A-F0-9]{3,6}$/',$c)) {
71          $c = '#'.$c;
72     }
73
74     if (preg_match('/^#[A-F0-9]{6}$/',$c)) {
75          return $c;
76     }
77
78     if (preg_match('/^#[A-F0-9]{3,}$/',$c)) {
79          return '#'.substr($c,1,1).substr($c,1,1).substr($c,2,1).substr($c,2,1).substr($c,3,1).substr($c,3,1);
80     }
81
82     return '';
83}
84
85function computeContrastRatio($c,$b)
86{
87     // Compute contrast ratio between two colors
88     
89     $c = adjustColor($c);
90     if (($c == '') || (strlen($c) != 7)) return 0;
91     $b = adjustColor($b);
92     if (($b == '') || (strlen($b) != 7)) return 0;
93     
94     $l1 = (0.2126 * pow(hexdec(substr($c,1,2))/255,2.2)) + (0.7152 * pow(hexdec(substr($c,3,2))/255,2.2)) + (0.0722 * pow(hexdec(substr($c,5,2))/255,2.2));
95     $l2 = (0.2126 * pow(hexdec(substr($b,1,2))/255,2.2)) + (0.7152 * pow(hexdec(substr($b,3,2))/255,2.2)) + (0.0722 * pow(hexdec(substr($b,5,2))/255,2.2));
96
97     if ($l1 > $l2) {
98          $r = ($l1 + 0.05) / ($l2 + 0.05);
99     } else {
100          $r = ($l2 + 0.05) / ($l1 + 0.05);
101     }
102     return $r;
103}
104
105function contrastRatio($c,$b) {
106     if (($c != '') && ($b != '')) {
107          $r = computeContrastRatio($c,$b);
108          return '<span style="position:absolute;top:0;left:23em;">('.sprintf(__('contrast ratio = %.1f:1'),$r).')</span>';
109     }
110     return '';
111}
112
113$ductile_base = array(
114     // HTML
115     'subtitle_hidden' => null,
116     // CSS
117     'body_font' => null,
118     'alternate_font' => null,
119     'blog_title_w' => null,
120     'blog_title_s' => null,
121     'blog_title_c' => null,
122     'post_title_w' => null,
123     'post_title_s' => null,
124     'post_title_c' => null,
125     'post_link_w' => null,
126     'post_link_v_c' => null,
127     'post_link_f_c' => null,
128     'blog_title_w_m' => null,
129     'blog_title_s_m' => null,
130     'blog_title_c_m' => null,
131     'post_title_w_m' => null,
132     'post_title_s_m' => null,
133     'post_title_c_m' => null,
134     'post_simple_title_c' => null
135);
136
137$ductile_lists_base = array(
138     'default' => 'short',
139     'default-page' => 'short',
140     'category' => 'short',
141     'tag' => 'short',
142     'search' => 'short',
143     'archive' => 'title'
144);
145
146$ductile_counts_base = array(
147     'default' => null,
148     'category' => null,
149     'tag' => null,
150     'search' => null
151);
152
153$ductile_user = $core->blog->settings->themes->get($core->blog->settings->system->theme.'_style');
154$ductile_user = @unserialize($ductile_user);
155if (!is_array($ductile_user)) {
156     $ductile_user = array();
157}
158$ductile_user = array_merge($ductile_base,$ductile_user);
159
160$ductile_lists = $core->blog->settings->themes->get($core->blog->settings->system->theme.'_entries_lists');
161$ductile_lists = @unserialize($ductile_lists);
162if (!is_array($ductile_lists)) {
163     $ductile_lists = $ductile_lists_base;
164}
165
166$ductile_counts = $core->blog->settings->themes->get($core->blog->settings->system->theme.'_entries_counts');
167$ductile_counts = @unserialize($ductile_counts);
168if (!is_array($ductile_counts)) {
169     $ductile_counts = $ductile_counts_base;
170}
171
172$ductile_stickers = $core->blog->settings->themes->get($core->blog->settings->system->theme.'_stickers');
173$ductile_stickers = @unserialize($ductile_stickers);
174
175// If no stickers defined, add feed Atom one
176if (!is_array($ductile_stickers)) {
177     $ductile_stickers = array(array(
178          'label' => __('Subscribe'),
179          'url' => $core->blog->url.$core->url->getBase('feed').'/atom',
180          'image' => 'sticker-feed.png'
181          ));
182}
183
184$ductile_stickers_full = array();
185// Get all sticker images already used
186if (is_array($ductile_stickers)) {
187     foreach ($ductile_stickers as $v) {
188          $ductile_stickers_full[] = $v['image'];
189     }
190}
191// Get all sticker-*.png in img folder of theme
192$ductile_stickers_images = files::scandir($img_path);
193if (is_array($ductile_stickers_images)) {
194     foreach ($ductile_stickers_images as $v) {
195          if (preg_match('/^sticker\-(.*)\.png$/',$v)) {
196               if (!in_array($v,$ductile_stickers_full)) {
197                    // image not already used
198                    $ductile_stickers[] = array(
199                         'label' => null,
200                         'url' => null,
201                         'image' => $v);
202               }
203          }
204     }
205}
206
207$conf_tab = isset($_POST['conf_tab']) ? $_POST['conf_tab'] : 'html';
208
209if (!empty($_POST))
210{
211     try
212     {
213          # HTML
214          if ($conf_tab == 'html') {
215               $ductile_user['subtitle_hidden'] = (integer) !empty($_POST['subtitle_hidden']);
216
217               $ductile_stickers = array();
218               for ($i = 0; $i < count($_POST['sticker_image']); $i++) {
219                    $ductile_stickers[] = array(
220                         'label' => $_POST['sticker_label'][$i],
221                         'url' => $_POST['sticker_url'][$i],
222                         'image' => $_POST['sticker_image'][$i]
223                    );
224               }
225
226               $order = array();
227               if (empty($_POST['ds_order']) && !empty($_POST['order'])) {
228                    $order = $_POST['order'];
229                    asort($order);
230                    $order = array_keys($order);
231               }
232               if (!empty($order)) {
233                    $new_ductile_stickers = array();
234                    foreach ($order as $i => $k) {
235                         $new_ductile_stickers[] = array(
236                              'label' => $ductile_stickers[$k]['label'],
237                              'url' => $ductile_stickers[$k]['url'],
238                              'image' => $ductile_stickers[$k]['image']
239                         );
240                    }
241                    $ductile_stickers = $new_ductile_stickers;
242               }
243               
244               for ($i = 0; $i < count($_POST['list_type']); $i++) {
245                    $ductile_lists[$_POST['list_ctx'][$i]] = $_POST['list_type'][$i];
246               }
247               
248               for ($i = 0; $i < count($_POST['count_nb']); $i++) {
249                    $ductile_counts[$_POST['count_ctx'][$i]] = $_POST['count_nb'][$i];
250               }
251               
252          }
253         
254          # CSS
255          if ($conf_tab == 'css') {
256               $ductile_user['body_font'] = $_POST['body_font'];
257               $ductile_user['alternate_font'] = $_POST['alternate_font'];
258
259               $ductile_user['blog_title_w'] = (integer) !empty($_POST['blog_title_w']);
260               $ductile_user['blog_title_s'] = adjustFontSize($_POST['blog_title_s']);
261               $ductile_user['blog_title_c'] = adjustColor($_POST['blog_title_c']);
262         
263               $ductile_user['post_title_w'] = (integer) !empty($_POST['post_title_w']);
264               $ductile_user['post_title_s'] = adjustFontSize($_POST['post_title_s']);
265               $ductile_user['post_title_c'] = adjustColor($_POST['post_title_c']);
266         
267               $ductile_user['post_link_w'] = (integer) !empty($_POST['post_link_w']);
268               $ductile_user['post_link_v_c'] = adjustColor($_POST['post_link_v_c']);
269               $ductile_user['post_link_f_c'] = adjustColor($_POST['post_link_f_c']);
270         
271               $ductile_user['post_simple_title_c'] = adjustColor($_POST['post_simple_title_c']);
272         
273               $ductile_user['blog_title_w_m'] = (integer) !empty($_POST['blog_title_w_m']);
274               $ductile_user['blog_title_s_m'] = adjustFontSize($_POST['blog_title_s_m']);
275               $ductile_user['blog_title_c_m'] = adjustColor($_POST['blog_title_c_m']);
276         
277               $ductile_user['post_title_w_m'] = (integer) !empty($_POST['post_title_w_m']);
278               $ductile_user['post_title_s_m'] = adjustFontSize($_POST['post_title_s_m']);
279               $ductile_user['post_title_c_m'] = adjustColor($_POST['post_title_c_m']);
280          }
281         
282          $core->blog->settings->addNamespace('themes');
283          $core->blog->settings->themes->put($core->blog->settings->system->theme.'_style',serialize($ductile_user));
284          $core->blog->settings->themes->put($core->blog->settings->system->theme.'_stickers',serialize($ductile_stickers));
285          $core->blog->settings->themes->put($core->blog->settings->system->theme.'_entries_lists',serialize($ductile_lists));
286          $core->blog->settings->themes->put($core->blog->settings->system->theme.'_entries_counts',serialize($ductile_counts));
287
288          // Blog refresh
289          $core->blog->triggerBlog();
290
291          // Template cache reset
292          $core->emptyTemplatesCache();
293         
294          echo
295          '<div class="message"><p>'.
296          __('Theme configuration upgraded.').
297          '</p></div>';
298     }
299     catch (Exception $e)
300     {
301          $core->error->add($e->getMessage());
302     }
303}
304
305// Legacy mode
306if (!$standalone_config) echo '</form>';
307
308# HTML Tab
309
310echo '<div class="multi-part" id="themes-list'.($conf_tab == 'html' ? '' : '-html').'" title="'.__('Content').'">';
311
312echo '<form id="theme_config" action="blog_theme.php?conf=1" method="post" enctype="multipart/form-data">';
313
314echo '<fieldset><legend>'.__('Header').'</legend>'.
315'<p class="field"><label for="subtitle_hidden">'.__('Hide blog description:').' '.
316form::checkbox('subtitle_hidden',1,$ductile_user['subtitle_hidden']).'</label>'.'</p>';
317if ($core->plugins->moduleExists('simpleMenu'))
318{
319     echo '<p>'.sprintf(__('To configure the top menu go to the <a href="%s">Simple Menu administration page</a>.'),'plugin.php?p=simpleMenu').'</p>';
320}
321echo '</fieldset>';
322
323echo '<fieldset><legend>'.__('Stickers').'</legend>';
324
325echo '<table class="dragable">'.'<caption>'.__('Stickers (footer)').'</caption>'.
326'<thead>'.
327'<tr>'.
328'<th scope="col">'.'</th>'.
329'<th scope="col">'.__('Image').'</th>'.
330'<th scope="col">'.__('Label').'</th>'.
331'<th scope="col">'.__('URL').'</th>'.
332'</tr>'.
333'</thead>'.
334'<tbody id="stickerslist">';
335$count = 0;
336foreach ($ductile_stickers as $i => $v) {
337     $count++;
338     echo 
339     '<tr class="line" id="l_'.$i.'">'.
340     '<td class="handle minimal">'.form::field(array('order['.$i.']'),2,3,$count,'position','',false).
341          form::hidden(array('dynorder[]','dynorder-'.$i),$i).'</td>'.
342     '<td>'.form::hidden(array('sticker_image[]'),$v['image']).'<img src="'.$img_url.$v['image'].'" /> '.'</td>'.
343     '<td scope="raw">'.form::field(array('sticker_label[]','dsl-'.$i),20,255,$v['label']).'</td>'.
344     '<td>'.form::field(array('sticker_url[]','dsu-'.$i),40,255,$v['url']).'</td>'.
345     '</tr>';
346}
347echo
348'</tbody>'.
349'</table>';
350
351echo '</fieldset>';
352
353echo '<fieldset><legend>'.__('Entries list types and limits').'</legend>';
354
355echo '<table id="entrieslist">'.'<caption>'.__('Entries lists').'</caption>'.
356'<thead>'.
357'<tr>'.
358'<th scope="col">'.__('Context').'</th>'.
359'<th scope="col">'.__('Entries list type').'</th>'.
360'<th scope="col">'.__('Number of entries').'</th>'.
361'</tr>'.
362'</thead>'.
363'<tbody>';
364foreach ($ductile_lists as $k => $v) {
365     echo 
366          '<tr>'.
367          '<td scope="raw">'.$contexts[$k].'</td>'.
368          '<td>'.form::hidden(array('list_ctx[]'),$k).form::combo(array('list_type[]'),$list_types,$v).'</td>';
369     if (array_key_exists($k,$ductile_counts)) {
370          echo '<td>'.form::hidden(array('count_ctx[]'),$k).form::field(array('count_nb[]'),2,3,$ductile_counts[$k]).'</td>';
371     } else {
372          echo '<td></td>';
373     }
374     echo
375          '</tr>';
376}
377echo
378'</tbody>'.
379'</table>';
380
381echo '</fieldset>';
382
383echo '<input type="hidden" name="conf_tab" value="html">';
384echo '<p class="clear">'.form::hidden('ds_order','').'<input type="submit" value="'.__('Save').'" />'.$core->formNonce().'</p>';
385echo '</form>';
386
387echo '</div>'; // Close tab
388
389# CSS tab
390
391echo '<div class="multi-part" id="themes-list'.($conf_tab == 'css' ? '' : '-css').'" title="'.__('Presentation').'">';
392
393echo '<form id="theme_config" action="blog_theme.php?conf=1" method="post" enctype="multipart/form-data">';
394
395echo '<h3>'.__('General settings').'</h3>';
396
397echo '<fieldset><legend>'.__('Fonts').'</legend>'.
398'<p class="field"><label for="body_font">'.__('Main:').' '.
399form::combo('body_font',$fonts,$ductile_user['body_font']).'</label></p>'.
400
401'<p class="field"><label for="alternate_font">'.__('Secondary:').' '.
402form::combo('alternate_font',$fonts,$ductile_user['alternate_font']).'</label></p>'.
403'</fieldset>';
404
405echo '<div class="two-cols">';
406echo '<div class="col">';
407
408echo '<fieldset><legend>'.__('Blog title').'</legend>'.
409'<p class="field"><label for="blog_title_w">'.__('In bold:').' '.
410form::checkbox('blog_title_w',1,$ductile_user['blog_title_w']).'</label>'.'</p>'.
411
412'<p class="field"><label for="blog_title_s">'.__('Font size (in em by default):').'</label> '.
413form::field('blog_title_s',7,7,$ductile_user['blog_title_s']).'</p>'.
414
415'<p class="field picker"><label for="blog_title_c">'.__('Color:').'</label> '.
416form::field('blog_title_c',7,7,$ductile_user['blog_title_c'],'colorpicker').contrastRatio($ductile_user['blog_title_c'],'#ffffff').'</p>'.
417'</fieldset>';
418
419echo '</div>';
420echo '<div class="col">';
421
422echo '<fieldset><legend>'.__('Post title').'</legend>'.
423'<p class="field"><label for="post_title_w">'.__('In bold:').' '.
424form::checkbox('post_title_w',1,$ductile_user['post_title_w']).'</label>'.'</p>'.
425
426'<p class="field"><label for="post_title_s">'.__('Font size (in em by default):').'</label> '.
427form::field('post_title_s',7,7,$ductile_user['post_title_s']).'</p>'.
428
429'<p class="field picker"><label for="post_title_c">'.__('Color:').'</label> '.
430form::field('post_title_c',7,7,$ductile_user['post_title_c'],'colorpicker').contrastRatio($ductile_user['post_title_c'],'#ffffff').'</p>'.
431'</fieldset>';
432
433echo '</div>';
434echo '</div>';
435
436echo '<fieldset><legend>'.__('Titles without link').'</legend>'.
437
438'<p class="field picker"><label for="post_simple_title_c">'.__('Color:').'</label> '.
439form::field('post_simple_title_c',7,7,$ductile_user['post_simple_title_c'],'colorpicker').contrastRatio($ductile_user['post_simple_title_c'],'#ffffff').'</p>'.
440'</fieldset>';
441
442echo '<fieldset><legend>'.__('Inside posts links').'</legend>'.
443'<p class="field"><label for="post_link_w">'.__('In bold:').' '.
444form::checkbox('post_link_w',1,$ductile_user['post_link_w']).'</label>'.'</p>'.
445
446'<p class="field picker"><label for="post_link_v_c">'.__('Normal and visited links color:').'</label> '.
447form::field('post_link_v_c',7,7,$ductile_user['post_link_v_c'],'colorpicker').contrastRatio($ductile_user['post_link_v_c'],'#ffffff').'</p>'.
448
449'<p class="field picker"><label for="post_link_f_c">'.__('Active, hover and focus links color:').'</label> '.
450form::field('post_link_f_c',7,7,$ductile_user['post_link_f_c'],'colorpicker').contrastRatio($ductile_user['post_link_f_c'],'#ebebee').'</p>'.
451'</fieldset>';
452
453echo '<h3>'.__('Mobile specific settings').'</h3>';
454
455echo '<div class="two-cols">';
456echo '<div class="col">';
457
458echo '<fieldset><legend>'.__('Blog title').'</legend>'.
459'<p class="field"><label for="blog_title_w_m">'.__('In bold:').' '.
460form::checkbox('blog_title_w_m',1,$ductile_user['blog_title_w_m']).'</label>'.'</p>'.
461
462'<p class="field"><label for="blog_title_s_m">'.__('Font size (in em by default):').'</label> '.
463form::field('blog_title_s_m',7,7,$ductile_user['blog_title_s_m']).'</p>'.
464
465'<p class="field picker"><label for="blog_title_c_m">'.__('Color:').'</label> '.
466form::field('blog_title_c_m',7,7,$ductile_user['blog_title_c_m'],'colorpicker').contrastRatio($ductile_user['blog_title_c_m'],'#d7d7dc').'</p>'.
467'</fieldset>';
468
469echo '</div>';
470echo '<div class="col">';
471
472echo '<fieldset><legend>'.__('Post title').'</legend>'.
473'<p class="field"><label for="post_title_w_m">'.__('In bold:').' '.
474form::checkbox('post_title_w_m',1,$ductile_user['post_title_w_m']).'</label>'.'</p>'.
475
476'<p class="field"><label for="post_title_s_m">'.__('Font size (in em by default):').'</label> '.
477form::field('post_title_s_m',7,7,$ductile_user['post_title_s_m']).'</p>'.
478
479'<p class="field picker"><label for="post_title_c_m">'.__('Color:').'</label> '.
480form::field('post_title_c_m',7,7,$ductile_user['post_title_c_m'],'colorpicker').contrastRatio($ductile_user['post_title_c_m'],'#ffffff').'</p>'.
481'</fieldset>';
482
483echo '</div>';
484echo '</div>';
485
486echo '<input type="hidden" name="conf_tab" value="css">';
487echo '<p class="clear"><input type="submit" value="'.__('Save').'" />'.$core->formNonce().'</p>';
488echo '</form>';
489
490echo '</div>'; // Close tab
491
492dcPage::helpBlock('ductile');
493
494// Legacy mode
495if (!$standalone_config) echo '<form style="display:none">';
496?>
Note: See TracBrowser for help on using the repository browser.

Sites map