Dotclear

source: plugins/widgets/index.php @ 2398:c06651a81e7e

Revision 2398:c06651a81e7e, 11.9 KB checked in by Lepeltier kévin <kevin@…>, 12 years ago (diff)

Fusion avec default

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

Sites map