Dotclear

source: plugins/widgets/index.php @ 2369:461cfb68d9c7

Revision 2369:461cfb68d9c7, 9.5 KB checked in by franck <carnet.franck.paul@…>, 12 years ago (diff)

Revamp contextual help for widgets plugin

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2013 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
14include dirname(__FILE__).'/_default_widgets.php';
15
16# Loading navigation, extra widgets and custom widgets
17$widgets_nav = null;
18if ($core->blog->settings->widgets->widgets_nav) {
19     $widgets_nav = dcWidgets::load($core->blog->settings->widgets->widgets_nav);
20}
21$widgets_extra = null;
22if ($core->blog->settings->widgets->widgets_extra) {
23     $widgets_extra = dcWidgets::load($core->blog->settings->widgets->widgets_extra);
24}
25$widgets_custom = null;
26if ($core->blog->settings->widgets->widgets_custom) {
27     $widgets_custom = dcWidgets::load($core->blog->settings->widgets->widgets_custom);
28}
29
30$append_combo = array(
31     '-' => 0,
32     __('navigation') => 'nav',
33     __('extra') => 'extra',
34     __('custom') => 'custom'
35);
36
37function literalNullString($v)
38{
39     if ($v == '') {
40          return '&lt;'.__('empty string').'&gt;';
41     }
42     return $v;
43}
44
45# Adding widgets to sidebars
46if (!empty($_POST['append']) && is_array($_POST['addw']))
47{
48     # Filter selection
49     $addw = array();
50     foreach ($_POST['addw'] as $k => $v) {
51          if (($v == 'extra' || $v == 'nav' || $v == 'custom') && $__widgets->{$k} !== null ) {
52               $addw[$k] = $v;
53          }
54     }
55     
56     # Append widgets
57     if (!empty($addw))
58     {
59          if (!($widgets_nav instanceof dcWidgets)) {
60               $widgets_nav = new dcWidgets;
61          }
62          if (!($widgets_extra instanceof dcWidgets)) {
63               $widgets_extra = new dcWidgets();
64          }
65          if (!($widgets_custom instanceof dcWidgets)) {
66               $widgets_custom = new dcWidgets();
67          }
68         
69          foreach ($addw as $k => $v)
70          {
71               switch ($v) {
72                    case 'nav':
73                         $widgets_nav->append($__widgets->{$k});
74                         break;
75                    case 'extra':
76                         $widgets_extra->append($__widgets->{$k});
77                         break;
78                    case 'custom':
79                         $widgets_custom->append($__widgets->{$k});
80                         break;
81               }
82          }
83         
84          try {
85               $core->blog->settings->addNamespace('widgets');
86               $core->blog->settings->widgets->put('widgets_nav',$widgets_nav->store());
87               $core->blog->settings->widgets->put('widgets_extra',$widgets_extra->store());
88               $core->blog->settings->widgets->put('widgets_custom',$widgets_custom->store());
89               $core->blog->triggerBlog();
90               http::redirect($p_url);
91          } catch (Exception $e) {
92               $core->error->add($e->getMessage());
93          }
94     }
95}
96
97# Update sidebars
98if (!empty($_POST['wup']))
99{
100     if (!isset($_POST['w']) || !is_array($_POST['w'])) {
101          $_POST['w'] = array();
102     }
103     
104     try
105     {
106          # Removing mark as _rem widgets
107          foreach ($_POST['w'] as $nsid => $nsw) {
108               foreach ($nsw as $i => $v) {
109                    if (!empty($v['_rem'])) {
110                         unset($_POST['w'][$nsid][$i]);
111                         continue;
112                    }
113               }
114          }
115         
116          if (!isset($_POST['w']['nav'])) {
117               $_POST['w']['nav'] = array();
118          }
119          if (!isset($_POST['w']['extra'])) {
120               $_POST['w']['extra'] = array();
121          }
122          if (!isset($_POST['w']['custom'])) {
123               $_POST['w']['custom'] = array();
124          }
125         
126          $widgets_nav = dcWidgets::loadArray($_POST['w']['nav'],$__widgets);
127          $widgets_extra = dcWidgets::loadArray($_POST['w']['extra'],$__widgets);
128          $widgets_custom = dcWidgets::loadArray($_POST['w']['custom'],$__widgets);
129         
130          $core->blog->settings->addNamespace('widgets');
131          $core->blog->settings->widgets->put('widgets_nav',$widgets_nav->store());
132          $core->blog->settings->widgets->put('widgets_extra',$widgets_extra->store());
133          $core->blog->settings->widgets->put('widgets_custom',$widgets_custom->store());
134          $core->blog->triggerBlog();
135         
136          http::redirect($p_url);
137     }
138     catch (Exception $e)
139     {
140          $core->error->add($e->getMessage());
141     }
142}
143elseif (!empty($_POST['wreset']))
144{
145     try
146     {
147          $core->blog->settings->addNamespace('widgets');
148          $core->blog->settings->widgets->put('widgets_nav','');
149          $core->blog->settings->widgets->put('widgets_extra','');
150          $core->blog->settings->widgets->put('widgets_custom','');
151          $core->blog->triggerBlog();
152         
153          http::redirect($p_url);
154     }
155     catch (Exception $e)
156     {
157          $core->error->add($e->getMessage());
158     }
159}
160?>
161<html>
162<head>
163  <title><?php echo __('Widgets'); ?></title>
164  <style type="text/css">
165  <?php echo file_get_contents(dirname(__FILE__).'/style.css'); ?>
166  </style>
167  <?php
168          echo
169               dcPage::jsLoad('js/jquery/jquery-ui.custom.js').
170               dcPage::jsLoad('index.php?pf=widgets/widgets.js');
171  ?>
172  <?php 
173     $core->auth->user_prefs->addWorkspace('accessibility'); 
174     $user_dm_nodragdrop = $core->auth->user_prefs->accessibility->nodragdrop;
175  ?>
176  <?php if (!$user_dm_nodragdrop) : ?>
177  <script type="text/javascript" src="index.php?pf=widgets/dragdrop.js"></script>
178  <?php endif; ?>
179  <script type="text/javascript">
180  //<![CDATA[
181  <?php echo dcPage::jsVar('dotclear.msg.confirm_widgets_reset',
182     __('Are you sure you want to reset sidebars?')); ?>
183  //]]>
184  </script>
185  <?php echo(dcPage::jsConfirmClose('sidebarsWidgets')); ?>
186</head>
187<body>
188<?php
189echo dcPage::breadcrumb(
190     array(
191          html::escapeHTML($core->blog->name) => '',
192          __('Widgets') => ''
193     )).
194     dcPage::notices();
195
196# All widgets
197echo
198'<form id="listWidgets" action="'.$p_url.'" method="post"  class="widgets">'.
199'<h3>'.__('Available widgets').'</h3>'.
200'<p>'.__('Move widgets from this list to one of the sidebars.').'</p>'.
201'<ul id="widgets-ref">';
202
203$j = 0;
204foreach ($__widgets->elements(true) as $w) {
205     echo
206     '<li>'.form::hidden(array('w[void][0][id]'),html::escapeHTML($w->id())).
207     '<p class="widget-name">'.form::field(array('w[void][0][order]'),2,3,0,'hide','',0,'title="'.__('order').'"').' '.$w->name().
208     ($w->desc() != '' ? ' <span class="form-note">'.__($w->desc()).'</span>' : '').'</p>'.
209     '<p class="manual-move remove-if-drag"><label class="classic">'.__('Append to:').'</label> '.
210     form::combo(array('addw['.$w->id().']'),$append_combo).'</p>'.
211     '<div class="widgetSettings hidden-if-drag">'.$w->formSettings('w[void][0]',$j).'</div>'.
212     '</li>';
213     $j++;
214}
215
216echo
217'</ul>'.
218$core->formNonce().
219'<p class="remove-if-drag"><input type="submit" name="append" value="'.__('Add widgets to sidebars').'" /></p>'.
220'</form>';
221
222echo '<form id="sidebarsWidgets" action="'.$p_url.'" method="post">';
223# Nav sidebar
224echo
225'<div id="sidebarNav" class="widgets fieldset">'.
226sidebarWidgets('dndnav',__('Navigation sidebar'),$widgets_nav,'nav',$__default_widgets['nav'],$j);
227echo '</div>';
228
229# Extra sidebar
230echo
231'<div id="sidebarExtra" class="widgets fieldset">'.
232sidebarWidgets('dndextra',__('Extra sidebar'),$widgets_extra,'extra',$__default_widgets['extra'],$j);
233echo '</div>';
234
235# Custom sidebar
236echo
237'<div id="sidebarCustom" class="widgets fieldset">'.
238sidebarWidgets('dndcustom',__('Custom sidebar'),$widgets_custom,'custom',$__default_widgets['custom'],$j);
239echo '</div>';
240
241echo
242'<p id="sidebarsControl">'.
243$core->formNonce().
244'<input type="submit" name="wup" value="'.__('Update sidebars').'" /> '.
245'<input type="submit" class="reset" name="wreset" value="'.__('Reset sidebars').'" /></p>'.
246'</form>';
247
248$widget_elements = new stdClass;
249$widget_elements->content = '<dl>';
250foreach ($__widgets->elements() as $w)
251{
252     $widget_elements->content .=
253     '<dt><strong>'.html::escapeHTML($w->name()).'</strong> ('.
254     __('Widget ID:').' <strong>'.html::escapeHTML($w->id()).'</strong>)'.
255     ($w->desc() != '' ? ' <span class="form-note">'.__($w->desc()).'</span>' : '').'</dt>'.
256     '<dd>';
257     
258     $w_settings = $w->settings();
259     if (empty($w_settings))
260     {
261          $widget_elements->content .= '<p>'.__('No setting for this widget').'</p>';
262     }
263     else
264     {
265          $widget_elements->content .= '<ul>';
266          foreach ($w->settings() as $n => $s)
267          {
268               switch ($s['type']) {
269                    case 'check':
270                         $s_type = __('boolean').", ".__('possible values:')." <code>0</code> ".__('or')." <code>1</code>";
271                         break;
272                    case 'combo':
273                         $s['options'] = array_map("literalNullString", $s['options']);
274                         $s_type = __('listitem').", ".__('possible values:')." <code>".implode('</code>, <code>',$s['options'])."</code>";
275                         break;
276                    case 'text':
277                    case 'textarea':
278                    default:
279                         $s_type = __('string');
280                         break;
281               }
282               
283               $widget_elements->content .=
284               '<li>'.
285               __('Setting name:').' <strong>'.html::escapeHTML($n).'</strong>'.
286               ' ('.$s_type.')'.
287               '</li>';
288          }
289          $widget_elements->content .= '</ul>';
290     }
291     $widget_elements->content .= '</dd>';
292}
293$widget_elements->content .= '</dl></div>';
294
295dcPage::helpBlock('widgets',$widget_elements);
296
297function sidebarWidgets($id,$title,$widgets,$pr,$default_widgets,&$j)
298{
299     $res = '<h3>'.$title.'</h3>';
300     
301     if (!($widgets instanceof dcWidgets))
302     {
303          $widgets = $default_widgets;
304     }
305     
306     $res .= '<p class="empty-widgets" '.(!$widgets->isEmpty() ? 'style="display: none;"' : '').'>'.__('No widget.').'</p>';
307     
308     $res .= '<ul id="'.$id.'" class="connected">';
309     
310     $i = 0;
311     foreach ($widgets->elements() as $w)
312     {
313          $iname = 'w['.$pr.']['.$i.']';
314         
315          $res .=
316          '<li>'.form::hidden(array($iname.'[id]'),html::escapeHTML($w->id())).
317          '<p class="widget-name">'.form::field(array($iname.'[order]'),2,3,(string) $i,'hidden-if-drag','',0,'title="'.__('order').'"').' '.$w->name().
318          ($w->desc() != '' ? ' <span class="form-note">'.__($w->desc()).'</span>' : '').'</p>'.
319          '<p class="removeWidget remove-if-drag"><label class="classic">'.
320          form::checkbox(array($iname.'[_rem]'),'1',0).' '.__('Remove widget').
321          '</label></p>'.
322          '<div class="widgetSettings hidden-if-drag">'.$w->formSettings($iname,$j).'</div>'.
323          '</li>';
324         
325          $i++;
326          $j++;
327     }
328     
329     $res .= '</ul>';
330
331     if ($i > 0) {
332          $res .= '<ul class="sortable-delete"><li class="sortable-delete-placeholder">'.
333               __('Drag widgets here to remove them from this sidebar.').'</li></ul>';
334     }
335     
336     return $res;
337}
338?>
339</body>
340</html>
Note: See TracBrowser for help on using the repository browser.

Sites map