Dotclear

source: plugins/widgets/index.php @ 864:73d1af790506

Revision 864:73d1af790506, 10.1 KB checked in by Dsls <dsls@…>, 13 years ago (diff)

Fixed forgotten PHP>=5.3 pass by reference.

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

Sites map