Dotclear

source: themes/ductile/_config.php @ 646:8e8a24c6642e

Revision 646:8e8a24c6642e, 15.0 KB checked in by Franck <carnet.franck.paul@…>, 14 years ago (diff)

Présélection des formats de liste de billets par défaut

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
85$ductile_base = array(
86     // HTML
87     'subtitle_hidden' => null,
88     // CSS
89     'body_font' => null,
90     'alternate_font' => null,
91     'blog_title_w' => null,
92     'blog_title_s' => null,
93     'blog_title_c' => null,
94     'post_title_w' => null,
95     'post_title_s' => null,
96     'post_title_c' => null,
97     'post_link_w' => null,
98     'post_link_v_c' => null,
99     'post_link_f_c' => null,
100     'blog_title_w_m' => null,
101     'blog_title_s_m' => null,
102     'blog_title_c_m' => null,
103     'post_title_w_m' => null,
104     'post_title_s_m' => null,
105     'post_title_c_m' => null,
106     'post_simple_title_c' => null
107);
108
109$ductile_lists_base = array(
110     'default' => 'short',
111     'default-page' => 'short',
112     'category' => 'short',
113     'tag' => 'short',
114     'search' => 'short',
115     'archive' => 'title'
116);
117
118$ductile_counts_base = array(
119     'default' => null,
120     'category' => null,
121     'tag' => null,
122     'search' => null
123);
124
125$ductile_user = $core->blog->settings->themes->get($core->blog->settings->system->theme.'_style');
126$ductile_user = @unserialize($ductile_user);
127if (!is_array($ductile_user)) {
128     $ductile_user = array();
129}
130$ductile_user = array_merge($ductile_base,$ductile_user);
131
132$ductile_lists = $core->blog->settings->themes->get($core->blog->settings->system->theme.'_entries_lists');
133$ductile_lists = @unserialize($ductile_lists);
134if (!is_array($ductile_lists)) {
135     $ductile_lists = $ductile_lists_base;
136}
137
138$ductile_counts = $core->blog->settings->themes->get($core->blog->settings->system->theme.'_entries_counts');
139$ductile_counts = @unserialize($ductile_counts);
140if (!is_array($ductile_counts)) {
141     $ductile_counts = $ductile_counts_base;
142}
143
144$ductile_stickers = $core->blog->settings->themes->get($core->blog->settings->system->theme.'_stickers');
145$ductile_stickers = @unserialize($ductile_stickers);
146
147// If no stickers defined, add feed Atom one
148if (!is_array($ductile_stickers)) {
149     $ductile_stickers = array(array(
150          'label' => __('Subscribe'),
151          'url' => $core->blog->url.$core->url->getBase('feed').'/atom',
152          'image' => 'sticker-feed.png'
153          ));
154}
155
156$ductile_stickers_full = array();
157// Get all sticker images already used
158if (is_array($ductile_stickers)) {
159     foreach ($ductile_stickers as $v) {
160          $ductile_stickers_full[] = $v['image'];
161     }
162}
163// Get all sticker-*.png in img folder of theme
164$ductile_stickers_images = files::scandir($img_path);
165if (is_array($ductile_stickers_images)) {
166     foreach ($ductile_stickers_images as $v) {
167          if (preg_match('/^sticker\-(.*)\.png$/',$v)) {
168               if (!in_array($v,$ductile_stickers_full)) {
169                    // image not already used
170                    $ductile_stickers[] = array(
171                         'label' => null,
172                         'url' => null,
173                         'image' => $v);
174               }
175          }
176     }
177}
178
179$conf_tab = isset($_POST['conf_tab']) ? $_POST['conf_tab'] : 'html';
180
181if (!empty($_POST))
182{
183     try
184     {
185          # HTML
186          if ($conf_tab == 'html') {
187               $ductile_user['subtitle_hidden'] = (integer) !empty($_POST['subtitle_hidden']);
188
189               $ductile_stickers = array();
190               for ($i = 0; $i < count($_POST['sticker_image']); $i++) {
191                    $ductile_stickers[] = array(
192                         'label' => $_POST['sticker_label'][$i],
193                         'url' => $_POST['sticker_url'][$i],
194                         'image' => $_POST['sticker_image'][$i]
195                    );
196               }
197
198               $order = array();
199               if (empty($_POST['ds_order']) && !empty($_POST['order'])) {
200                    $order = $_POST['order'];
201                    asort($order);
202                    $order = array_keys($order);
203               }
204               if (!empty($order)) {
205                    $new_ductile_stickers = array();
206                    foreach ($order as $i => $k) {
207                         $new_ductile_stickers[] = array(
208                              'label' => $ductile_stickers[$k]['label'],
209                              'url' => $ductile_stickers[$k]['url'],
210                              'image' => $ductile_stickers[$k]['image']
211                         );
212                    }
213                    $ductile_stickers = $new_ductile_stickers;
214               }
215               
216               for ($i = 0; $i < count($_POST['list_type']); $i++) {
217                    $ductile_lists[$_POST['list_ctx'][$i]] = $_POST['list_type'][$i];
218               }
219               
220               for ($i = 0; $i < count($_POST['count_nb']); $i++) {
221                    $ductile_counts[$_POST['count_ctx'][$i]] = $_POST['count_nb'][$i];
222               }
223               
224          }
225         
226          # CSS
227          if ($conf_tab == 'css') {
228               $ductile_user['body_font'] = $_POST['body_font'];
229               $ductile_user['alternate_font'] = $_POST['alternate_font'];
230
231               $ductile_user['blog_title_w'] = (integer) !empty($_POST['blog_title_w']);
232               $ductile_user['blog_title_s'] = adjustFontSize($_POST['blog_title_s']);
233               $ductile_user['blog_title_c'] = adjustColor($_POST['blog_title_c']);
234         
235               $ductile_user['post_title_w'] = (integer) !empty($_POST['post_title_w']);
236               $ductile_user['post_title_s'] = adjustFontSize($_POST['post_title_s']);
237               $ductile_user['post_title_c'] = adjustColor($_POST['post_title_c']);
238         
239               $ductile_user['post_link_w'] = (integer) !empty($_POST['post_link_w']);
240               $ductile_user['post_link_v_c'] = adjustColor($_POST['post_link_v_c']);
241               $ductile_user['post_link_f_c'] = adjustColor($_POST['post_link_f_c']);
242         
243               $ductile_user['post_simple_title_c'] = adjustColor($_POST['post_simple_title_c']);
244         
245               $ductile_user['blog_title_w_m'] = (integer) !empty($_POST['blog_title_w_m']);
246               $ductile_user['blog_title_s_m'] = adjustFontSize($_POST['blog_title_s_m']);
247               $ductile_user['blog_title_c_m'] = adjustColor($_POST['blog_title_c_m']);
248         
249               $ductile_user['post_title_w_m'] = (integer) !empty($_POST['post_title_w_m']);
250               $ductile_user['post_title_s_m'] = adjustFontSize($_POST['post_title_s_m']);
251               $ductile_user['post_title_c_m'] = adjustColor($_POST['post_title_c_m']);
252          }
253         
254          $core->blog->settings->addNamespace('themes');
255          $core->blog->settings->themes->put($core->blog->settings->system->theme.'_style',serialize($ductile_user));
256          $core->blog->settings->themes->put($core->blog->settings->system->theme.'_stickers',serialize($ductile_stickers));
257          $core->blog->settings->themes->put($core->blog->settings->system->theme.'_entries_lists',serialize($ductile_lists));
258          $core->blog->settings->themes->put($core->blog->settings->system->theme.'_entries_counts',serialize($ductile_counts));
259
260          // Blog refresh
261          $core->blog->triggerBlog();
262
263          // Template cache reset
264          $core->emptyTemplatesCache();
265         
266          echo
267          '<div class="message"><p>'.
268          __('Theme configuration upgraded.').
269          '</p></div>';
270     }
271     catch (Exception $e)
272     {
273          $core->error->add($e->getMessage());
274     }
275}
276
277// Legacy mode
278if (!$standalone_config) echo '</form>';
279
280# HTML Tab
281
282echo '<div class="multi-part" id="themes-list'.($conf_tab == 'html' ? '' : '-html').'" title="'.__('Content').'">';
283
284echo '<form id="theme_config" action="blog_theme.php?conf=1" method="post" enctype="multipart/form-data">';
285
286echo '<fieldset><legend>'.__('Header').'</legend>'.
287'<p class="field"><label for="subtitle_hidden">'.__('Hide blog description:').' '.
288form::checkbox('subtitle_hidden',1,$ductile_user['subtitle_hidden']).'</label>'.'</p>';
289if ($core->plugins->moduleExists('simpleMenu'))
290{
291     echo '<p>'.sprintf(__('To configure the top menu go to the <a href="%s">Simple Menu administration page</a>.'),'plugin.php?p=simpleMenu').'</p>';
292}
293echo '</fieldset>';
294
295echo '<fieldset><legend>'.__('Stickers').'</legend>';
296
297echo '<table class="dragable">'.'<caption>'.__('Stickers (footer)').'</caption>'.
298'<thead>'.
299'<tr>'.
300'<th scope="col">'.'</th>'.
301'<th scope="col">'.__('Image').'</th>'.
302'<th scope="col">'.__('Label').'</th>'.
303'<th scope="col">'.__('URL').'</th>'.
304'</tr>'.
305'</thead>'.
306'<tbody id="stickerslist">';
307$count = 0;
308foreach ($ductile_stickers as $i => $v) {
309     $count++;
310     echo 
311     '<tr class="line" id="l_'.$i.'">'.
312     '<td class="handle minimal">'.form::field(array('order['.$i.']'),2,3,$count,'position','',false).
313          form::hidden(array('dynorder[]','dynorder-'.$i),$i).'</td>'.
314     '<td>'.form::hidden(array('sticker_image[]'),$v['image']).'<img src="'.$img_url.$v['image'].'" /> '.'</td>'.
315     '<td scope="raw">'.form::field(array('sticker_label[]','dsl-'.$i),20,255,$v['label']).'</td>'.
316     '<td>'.form::field(array('sticker_url[]','dsu-'.$i),40,255,$v['url']).'</td>'.
317     '</tr>';
318}
319echo
320'</tbody>'.
321'</table>';
322
323echo '</fieldset>';
324
325echo '<fieldset><legend>'.__('Entries list types and limits').'</legend>';
326
327echo '<table id="entrieslist">'.'<caption>'.__('Entries lists').'</caption>'.
328'<thead>'.
329'<tr>'.
330'<th scope="col">'.__('Context').'</th>'.
331'<th scope="col">'.__('Entries list type').'</th>'.
332'<th scope="col">'.__('Number of entries').'</th>'.
333'</tr>'.
334'</thead>'.
335'<tbody>';
336foreach ($ductile_lists as $k => $v) {
337     echo 
338          '<tr>'.
339          '<td scope="raw">'.$contexts[$k].'</td>'.
340          '<td>'.form::hidden(array('list_ctx[]'),$k).form::combo(array('list_type[]'),$list_types,$v).'</td>';
341     if (array_key_exists($k,$ductile_counts)) {
342          echo '<td>'.form::hidden(array('count_ctx[]'),$k).form::field(array('count_nb[]'),2,3,$ductile_counts[$k]).'</td>';
343     } else {
344          echo '<td></td>';
345     }
346     echo
347          '</tr>';
348}
349echo
350'</tbody>'.
351'</table>';
352
353echo '</fieldset>';
354
355echo '<input type="hidden" name="conf_tab" value="html">';
356echo '<p class="clear">'.form::hidden('ds_order','').'<input type="submit" value="'.__('Save').'" />'.$core->formNonce().'</p>';
357echo '</form>';
358
359echo '</div>'; // Close tab
360
361# CSS tab
362
363echo '<div class="multi-part" id="themes-list'.($conf_tab == 'css' ? '' : '-css').'" title="'.__('Presentation').'">';
364
365echo '<form id="theme_config" action="blog_theme.php?conf=1" method="post" enctype="multipart/form-data">';
366
367echo '<h3>'.__('General settings').'</h3>';
368
369echo '<fieldset><legend>'.__('Fonts').'</legend>'.
370'<p class="field"><label for="body_font">'.__('Main:').' '.
371form::combo('body_font',$fonts,$ductile_user['body_font']).'</label></p>'.
372
373'<p class="field"><label for="alternate_font">'.__('Secondary:').' '.
374form::combo('alternate_font',$fonts,$ductile_user['alternate_font']).'</label></p>'.
375'</fieldset>';
376
377echo '<div class="two-cols">';
378echo '<div class="col">';
379
380echo '<fieldset><legend>'.__('Blog title').'</legend>'.
381'<p class="field"><label for="blog_title_w">'.__('In bold:').' '.
382form::checkbox('blog_title_w',1,$ductile_user['blog_title_w']).'</label>'.'</p>'.
383
384'<p class="field"><label for="blog_title_s">'.__('Font size (in em by default):').'</label> '.
385form::field('blog_title_s',7,7,$ductile_user['blog_title_s']).'</p>'.
386
387'<p class="field picker"><label for="blog_title_c">'.__('Color:').'</label> '.
388form::field('blog_title_c',7,7,$ductile_user['blog_title_c'],'colorpicker').'</p>'.
389'</fieldset>';
390
391echo '</div>';
392echo '<div class="col">';
393
394echo '<fieldset><legend>'.__('Post title').'</legend>'.
395'<p class="field"><label for="post_title_w">'.__('In bold:').' '.
396form::checkbox('post_title_w',1,$ductile_user['post_title_w']).'</label>'.'</p>'.
397
398'<p class="field"><label for="post_title_s">'.__('Font size (in em by default):').'</label> '.
399form::field('post_title_s',7,7,$ductile_user['post_title_s']).'</p>'.
400
401'<p class="field picker"><label for="post_title_c">'.__('Color:').'</label> '.
402form::field('post_title_c',7,7,$ductile_user['post_title_c'],'colorpicker').'</p>'.
403'</fieldset>';
404
405echo '</div>';
406echo '</div>';
407
408echo '<fieldset><legend>'.__('Titles without link').'</legend>'.
409
410'<p class="field picker"><label for="post_simple_title_c">'.__('Color:').'</label> '.
411form::field('post_simple_title_c',7,7,$ductile_user['post_simple_title_c'],'colorpicker').'</p>'.
412'</fieldset>';
413
414echo '<fieldset><legend>'.__('Inside posts links').'</legend>'.
415'<p class="field"><label for="post_link_w">'.__('In bold:').' '.
416form::checkbox('post_link_w',1,$ductile_user['post_link_w']).'</label>'.'</p>'.
417
418'<p class="field picker"><label for="post_link_v_c">'.__('Normal and visited links color:').'</label> '.
419form::field('post_link_v_c',7,7,$ductile_user['post_link_v_c'],'colorpicker').'</p>'.
420
421'<p class="field picker"><label for="body_link_f_c">'.__('Active, hover and focus links color:').'</label> '.
422form::field('post_link_f_c',7,7,$ductile_user['post_link_f_c'],'colorpicker').'</p>'.
423'</fieldset>';
424
425echo '<h3>'.__('Mobile specific settings').'</h3>';
426
427echo '<div class="two-cols">';
428echo '<div class="col">';
429
430echo '<fieldset><legend>'.__('Blog title').'</legend>'.
431'<p class="field"><label for="blog_title_w_m">'.__('In bold:').' '.
432form::checkbox('blog_title_w_m',1,$ductile_user['blog_title_w_m']).'</label>'.'</p>'.
433
434'<p class="field"><label for="blog_title_s_m">'.__('Font size (in em by default):').'</label> '.
435form::field('blog_title_s_m',7,7,$ductile_user['blog_title_s_m']).'</p>'.
436
437'<p class="field picker"><label for="blog_title_c_m">'.__('Color:').'</label> '.
438form::field('blog_title_c_m',7,7,$ductile_user['blog_title_c_m'],'colorpicker').'</p>'.
439'</fieldset>';
440
441echo '</div>';
442echo '<div class="col">';
443
444echo '<fieldset><legend>'.__('Post title').'</legend>'.
445'<p class="field"><label for="post_title_w_m">'.__('In bold:').' '.
446form::checkbox('post_title_w_m',1,$ductile_user['post_title_w_m']).'</label>'.'</p>'.
447
448'<p class="field"><label for="post_title_s_m">'.__('Font size (in em by default):').'</label> '.
449form::field('post_title_s_m',7,7,$ductile_user['post_title_s_m']).'</p>'.
450
451'<p class="field picker"><label for="post_title_c_m">'.__('Color:').'</label> '.
452form::field('post_title_c_m',7,7,$ductile_user['post_title_c_m'],'colorpicker').'</p>'.
453'</fieldset>';
454
455echo '</div>';
456echo '</div>';
457
458echo '<input type="hidden" name="conf_tab" value="css">';
459echo '<p class="clear"><input type="submit" value="'.__('Save').'" />'.$core->formNonce().'</p>';
460echo '</form>';
461
462echo '</div>'; // Close tab
463
464dcPage::helpBlock('ductile');
465
466// Legacy mode
467if (!$standalone_config) echo '<form style="display:none">';
468?>
Note: See TracBrowser for help on using the repository browser.

Sites map