Dotclear

source: themes/ductile/_config.php @ 605:2fc355faae09

Revision 605:2fc355faae09, 15.6 KB checked in by Franck <carnet.franck.paul@…>, 14 years ago (diff)

Nouvelle gestion des stickers, step 2 (drag'n'drop)

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$ductile_user = $core->blog->settings->themes->get($core->blog->settings->system->theme.'_style');
130$ductile_user = @unserialize($ductile_user);
131if (!is_array($ductile_user)) {
132     $ductile_user = array();
133}
134$ductile_user = array_merge($ductile_base,$ductile_user);
135
136$ductile_lists = $core->blog->settings->themes->get($core->blog->settings->system->theme.'_entries_lists');
137$ductile_lists = @unserialize($ductile_lists);
138if (!is_array($ductile_lists)) {
139     $ductile_lists = $ductile_lists_base;
140}
141
142$ductile_counts = $core->blog->settings->themes->get($core->blog->settings->system->theme.'_entries_counts');
143$ductile_counts = @unserialize($ductile_counts);
144if (!is_array($ductile_counts)) {
145     $ductile_counts = $ductile_counts_base;
146}
147
148$ductile_stickers = $core->blog->settings->themes->get($core->blog->settings->system->theme.'_stickers');
149$ductile_stickers = @unserialize($ductile_stickers);
150
151$ductile_stickers_full = array();
152// Get all sticker images already used
153if (is_array($ductile_stickers)) {
154     foreach ($ductile_stickers as $v) {
155          $ductile_stickers_full[] = $v['image'];
156     }
157}
158// Get all sticker-*.png in img folder of theme
159$ductile_stickers_images = files::scandir($img_path);
160if (is_array($ductile_stickers_images)) {
161     foreach ($ductile_stickers_images as $v) {
162          if (preg_match('/^sticker\-(.*)\.png$/',$v)) {
163               if (!in_array($v,$ductile_stickers_full)) {
164                    // image not already used
165                    $ductile_stickers[] = array(
166                         'label' => null,
167                         'url' => null,
168                         'image' => $v);
169               }
170          }
171     }
172}
173
174$conf_tab = isset($_POST['conf_tab']) ? $_POST['conf_tab'] : 'html';
175
176if (!empty($_POST))
177{
178     try
179     {
180          # HTML
181          if ($conf_tab == 'html') {
182               $ductile_user['subtitle_hidden'] = (integer) !empty($_POST['subtitle_hidden']);
183
184               $ductile_stickers = array();
185               for ($i = 0; $i < count($_POST['sticker_image']); $i++) {
186                    $ductile_stickers[] = array(
187                         'label' => $_POST['sticker_label'][$i],
188                         'url' => $_POST['sticker_url'][$i],
189                         'image' => $_POST['sticker_image'][$i]
190                    );
191               }
192
193               $order = array();
194               if (empty($_POST['ds_order']) && !empty($_POST['order'])) {
195                    $order = $_POST['order'];
196                    asort($order);
197                    $order = array_keys($order);
198               }
199               if (!empty($order)) {
200                    $new_ductile_stickers = array();
201                    foreach ($order as $i => $k) {
202                         $new_ductile_stickers[] = array(
203                              'label' => $ductile_stickers[$k]['label'],
204                              'url' => $ductile_stickers[$k]['url'],
205                              'image' => $ductile_stickers[$k]['image']
206                         );
207                    }
208                    $ductile_stickers = $new_ductile_stickers;
209               }
210               
211               for ($i = 0; $i < count($_POST['list_type']); $i++) {
212                    $ductile_lists[$_POST['list_ctx'][$i]] = $_POST['list_type'][$i];
213               }
214               
215               for ($i = 0; $i < count($_POST['count_nb']); $i++) {
216                    $ductile_counts[$_POST['count_ctx'][$i]] = $_POST['count_nb'][$i];
217               }
218               
219          }
220         
221          # CSS
222          if ($conf_tab == 'css') {
223               $ductile_user['body_font'] = $_POST['body_font'];
224               $ductile_user['alternate_font'] = $_POST['alternate_font'];
225
226               $ductile_user['blog_title_w'] = (integer) !empty($_POST['blog_title_w']);
227               $ductile_user['blog_title_s'] = adjustFontSize($_POST['blog_title_s']);
228               $ductile_user['blog_title_c'] = adjustColor($_POST['blog_title_c']);
229         
230               $ductile_user['post_title_w'] = (integer) !empty($_POST['post_title_w']);
231               $ductile_user['post_title_s'] = adjustFontSize($_POST['post_title_s']);
232               $ductile_user['post_title_c'] = adjustColor($_POST['post_title_c']);
233         
234               $ductile_user['post_link_w'] = (integer) !empty($_POST['post_link_w']);
235               $ductile_user['post_link_v_c'] = adjustColor($_POST['post_link_v_c']);
236               $ductile_user['post_link_f_c'] = adjustColor($_POST['post_link_f_c']);
237         
238               $ductile_user['post_simple_title_c'] = adjustColor($_POST['post_simple_title_c']);
239         
240               $ductile_user['blog_title_w_m'] = (integer) !empty($_POST['blog_title_w_m']);
241               $ductile_user['blog_title_s_m'] = adjustFontSize($_POST['blog_title_s_m']);
242               $ductile_user['blog_title_c_m'] = adjustColor($_POST['blog_title_c_m']);
243         
244               $ductile_user['post_title_w_m'] = (integer) !empty($_POST['post_title_w_m']);
245               $ductile_user['post_title_s_m'] = adjustFontSize($_POST['post_title_s_m']);
246               $ductile_user['post_title_c_m'] = adjustColor($_POST['post_title_c_m']);
247          }
248         
249          $core->blog->settings->addNamespace('themes');
250          $core->blog->settings->themes->put($core->blog->settings->system->theme.'_style',serialize($ductile_user));
251          $core->blog->settings->themes->put($core->blog->settings->system->theme.'_stickers',serialize($ductile_stickers));
252          $core->blog->settings->themes->put($core->blog->settings->system->theme.'_entries_lists',serialize($ductile_lists));
253          $core->blog->settings->themes->put($core->blog->settings->system->theme.'_entries_counts',serialize($ductile_counts));
254
255          // Blog refresh
256          $core->blog->triggerBlog();
257
258          // Template cache reset
259          $core->emptyTemplatesCache();
260         
261          echo
262          '<div class="message"><p>'.
263          __('Theme configuration upgraded.').
264          '</p></div>';
265     }
266     catch (Exception $e)
267     {
268          $core->error->add($e->getMessage());
269     }
270}
271
272// To be deleted when adminThemeConfigManaged behaviour will be implemented in admin/blog_themes.php :
273echo '</form>';
274
275# HTML Tab
276
277echo '<div class="multi-part" id="themes-list'.($conf_tab == 'html' ? '' : '-html').'" title="'.__('Content').'">';
278
279echo '<form id="theme_config" action="blog_theme.php?conf=1" method="post" enctype="multipart/form-data">';
280
281echo '<fieldset><legend>'.__('Header').'</legend>'.
282'<p class="field"><label for="subtitle_hidden">'.__('Hide blog description:').' '.
283form::checkbox('subtitle_hidden',1,$ductile_user['subtitle_hidden']).'</label>'.'</p>'.
284'</fieldset>';
285
286echo '<fieldset><legend>'.__('Stickers').'</legend>';
287
288echo '<table class="dragable">'.'<caption>'.__('Stickers (footer)').'</caption>'.
289'<thead>'.
290'<tr>'.
291'<th scope="col">'.'</th>'.
292'<th scope="col">'.__('Image').'</th>'.
293'<th scope="col">'.__('Label').'</th>'.
294'<th scope="col">'.__('URL').'</th>'.
295'</tr>'.
296'</thead>'.
297'<tbody id="stickerslist">';
298$count = 0;
299foreach ($ductile_stickers as $i => $v) {
300     $count++;
301     echo 
302     '<tr class="line" id="l_'.$i.'">'.
303     '<td class="handle minimal">'.form::field(array('order['.$i.']'),2,3,$count,'position','',false).
304          form::hidden(array('dynorder[]','dynorder-'.$i),$i).'</td>'.
305     '<td>'.form::hidden(array('sticker_image[]'),$v['image']).'<img src="'.$img_url.$v['image'].'" /> '.'</td>'.
306     '<td scope="raw">'.form::field(array('sticker_label[]','dsl-'.$i),20,255,$v['label']).'</td>'.
307     '<td>'.form::field(array('sticker_url[]','dsu-'.$i),40,255,$v['url']).'</td>'.
308     '</tr>';
309}
310echo
311'</tbody>'.
312'</table>';
313
314echo '</fieldset>';
315
316echo '<fieldset><legend>'.__('Entries list types and limits').'</legend>';
317
318echo '<table id="entrieslist">'.'<caption>'.__('Entries lists').'</caption>'.
319'<thead>'.
320'<tr>'.
321'<th scope="col">'.__('Context').'</th>'.
322'<th scope="col">'.__('Entries list type').'</th>'.
323'<th scope="col">'.__('Number of entries').'</th>'.
324'</tr>'.
325'</thead>'.
326'<tbody>';
327foreach ($ductile_lists as $k => $v) {
328     echo 
329          '<tr>'.
330          '<td scope="raw">'.$contexts[$k].'</td>'.
331          '<td>'.form::hidden(array('list_ctx[]'),$k).form::combo(array('list_type[]'),$list_types,$v).'</td>';
332     if (array_key_exists($k,$ductile_counts)) {
333          echo '<td>'.form::hidden(array('count_ctx[]'),$k).form::field(array('count_nb[]'),2,3,$ductile_counts[$k]).'</td>';
334     } else {
335          echo '<td></td>';
336     }
337     echo
338          '</tr>';
339}
340echo
341'</tbody>'.
342'</table>';
343
344echo '</fieldset>';
345
346echo '<input type="hidden" name="conf_tab" value="html">';
347echo '<p class="clear">'.form::hidden('ds_order','').'<input type="submit" value="'.__('Save').'" />'.$core->formNonce().'</p>';
348echo '</form>';
349
350echo '</div>'; // Close tab
351
352# CSS tab
353
354echo '<div class="multi-part" id="themes-list'.($conf_tab == 'css' ? '' : '-css').'" title="'.__('Presentation').'">';
355
356echo '<form id="theme_config" action="blog_theme.php?conf=1" method="post" enctype="multipart/form-data">';
357
358echo '<h3>'.__('General settings').'</h3>';
359
360echo '<fieldset><legend>'.__('Fonts').'</legend>'.
361'<p class="field"><label for="body_font">'.__('Main:').' '.
362form::combo('body_font',$fonts,$ductile_user['body_font']).'</label></p>'.
363
364'<p class="field"><label for="alternate_font">'.__('Secondary:').' '.
365form::combo('alternate_font',$fonts,$ductile_user['alternate_font']).'</label></p>'.
366'</fieldset>';
367
368echo '<div class="two-cols">';
369echo '<div class="col">';
370
371echo '<fieldset><legend>'.__('Blog title').'</legend>'.
372'<p class="field"><label for="blog_title_w">'.__('In bold:').' '.
373form::checkbox('blog_title_w',1,$ductile_user['blog_title_w']).'</label>'.'</p>'.
374
375'<p class="field"><label for="blog_title_s">'.__('Font size (in em by default):').'</label> '.
376form::field('blog_title_s',7,7,$ductile_user['blog_title_s']).'</p>'.
377
378'<p class="field picker"><label for="blog_title_c">'.__('Color:').'</label> '.
379form::field('blog_title_c',7,7,$ductile_user['blog_title_c'],'colorpicker').'</p>'.
380'</fieldset>';
381
382echo '</div>';
383echo '<div class="col">';
384
385echo '<fieldset><legend>'.__('Post title').'</legend>'.
386'<p class="field"><label for="post_title_w">'.__('In bold:').' '.
387form::checkbox('post_title_w',1,$ductile_user['post_title_w']).'</label>'.'</p>'.
388
389'<p class="field"><label for="post_title_s">'.__('Font size (in em by default):').'</label> '.
390form::field('post_title_s',7,7,$ductile_user['post_title_s']).'</p>'.
391
392'<p class="field picker"><label for="post_title_c">'.__('Color:').'</label> '.
393form::field('post_title_c',7,7,$ductile_user['post_title_c'],'colorpicker').'</p>'.
394'</fieldset>';
395
396echo '</div>';
397echo '</div>';
398
399echo '<fieldset><legend>'.__('Titles without link').'</legend>'.
400
401'<p class="field picker"><label for="post_simple_title_c">'.__('Color:').'</label> '.
402form::field('post_simple_title_c',7,7,$ductile_user['post_simple_title_c'],'colorpicker').'</p>'.
403'</fieldset>';
404
405echo '<fieldset><legend>'.__('Inside posts links').'</legend>'.
406'<p class="field"><label for="post_link_w">'.__('In bold:').' '.
407form::checkbox('post_link_w',1,$ductile_user['post_link_w']).'</label>'.'</p>'.
408
409'<p class="field picker"><label for="post_link_v_c">'.__('Normal and visited links color:').'</label> '.
410form::field('post_link_v_c',7,7,$ductile_user['post_link_v_c'],'colorpicker').'</p>'.
411
412'<p class="field picker"><label for="body_link_f_c">'.__('Active, hover and focus links color:').'</label> '.
413form::field('post_link_f_c',7,7,$ductile_user['post_link_f_c'],'colorpicker').'</p>'.
414'</fieldset>';
415
416echo '<h3>'.__('Mobile specific settings').'</h3>';
417
418echo '<div class="two-cols">';
419echo '<div class="col">';
420
421echo '<fieldset><legend>'.__('Blog title').'</legend>'.
422'<p class="field"><label for="blog_title_w_m">'.__('In bold:').' '.
423form::checkbox('blog_title_w_m',1,$ductile_user['blog_title_w_m']).'</label>'.'</p>'.
424
425'<p class="field"><label for="blog_title_s_m">'.__('Font size (in em by default):').'</label> '.
426form::field('blog_title_s_m',7,7,$ductile_user['blog_title_s_m']).'</p>'.
427
428'<p class="field picker"><label for="blog_title_c_m">'.__('Color:').'</label> '.
429form::field('blog_title_c_m',7,7,$ductile_user['blog_title_c_m'],'colorpicker').'</p>'.
430'</fieldset>';
431
432echo '</div>';
433echo '<div class="col">';
434
435echo '<fieldset><legend>'.__('Post title').'</legend>'.
436'<p class="field"><label for="post_title_w_m">'.__('In bold:').' '.
437form::checkbox('post_title_w_m',1,$ductile_user['post_title_w_m']).'</label>'.'</p>'.
438
439'<p class="field"><label for="post_title_s_m">'.__('Font size (in em by default):').'</label> '.
440form::field('post_title_s_m',7,7,$ductile_user['post_title_s_m']).'</p>'.
441
442'<p class="field picker"><label for="post_title_c_m">'.__('Color:').'</label> '.
443form::field('post_title_c_m',7,7,$ductile_user['post_title_c_m'],'colorpicker').'</p>'.
444'</fieldset>';
445
446echo '</div>';
447echo '</div>';
448
449echo '<input type="hidden" name="conf_tab" value="css">';
450echo '<p class="clear"><input type="submit" value="'.__('Save').'" />'.$core->formNonce().'</p>';
451echo '</form>';
452
453echo '</div>'; // Close tab
454
455// To be deleted when adminThemeConfigManaged behaviour will be implemented in admin/blog_themes.php :
456echo '<form style="display:none">';
457
458// Need some more Js
459$core->auth->user_prefs->addWorkspace('accessibility'); 
460$user_dm_nodragdrop = $core->auth->user_prefs->accessibility->nodragdrop;
461echo dcPage::jsToolMan();
462
463?>
464<?php if (!$user_dm_nodragdrop) : ?>
465<script type="text/javascript">
466//<![CDATA[
467
468var dragsort = ToolMan.dragsort();
469$(function() {
470     dragsort.makeTableSortable($("#stickerslist").get(0),
471     dotclear.sortable.setHandle,dotclear.sortable.saveOrder);
472});
473
474dotclear.sortable = {
475     setHandle: function(item) {
476          var handle = $(item).find('td.handle').get(0);
477          while (handle.firstChild) {
478               handle.removeChild(handle.firstChild);
479          }
480
481          item.toolManDragGroup.setHandle(handle);
482          handle.className = handle.className+' handler';
483     },
484
485     saveOrder: function(item) {
486          var group = item.toolManDragGroup;
487          var order = document.getElementById('ds_order');
488          group.register('dragend', function() {
489               order.value = '';
490               items = item.parentNode.getElementsByTagName('tr');
491
492               for (var i=0; i<items.length; i++) {
493                    order.value += items[i].id.substr(2)+',';
494               }
495          });
496     }
497};
498//]]>
499</script>
500<?php endif; ?>
Note: See TracBrowser for help on using the repository browser.

Sites map