Dotclear

source: themes/ductile/_config.php @ 604:163de7c22e02

Revision 604:163de7c22e02, 14.0 KB checked in by Franck <carnet.franck.paul@…>, 14 years ago (diff)

Nouvelle gestion des stickers, step 1

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

Sites map