[0] | 1 | <?php |
---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
| 3 | # |
---|
| 4 | # This file is part of Dotclear 2. |
---|
| 5 | # |
---|
| 6 | # Copyright (c) 2003-2010 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 ----------------------------------------- |
---|
| 12 | if (!defined('DC_CONTEXT_ADMIN')) { return; } |
---|
| 13 | |
---|
| 14 | include dirname(__FILE__).'/_default_widgets.php'; |
---|
| 15 | |
---|
| 16 | # Loading navigation and extra widgets |
---|
| 17 | $widgets_nav = null; |
---|
| 18 | if ($core->blog->settings->widgets->widgets_nav) { |
---|
| 19 | $widgets_nav = dcWidgets::load($core->blog->settings->widgets->widgets_nav); |
---|
| 20 | } |
---|
| 21 | $widgets_extra = null; |
---|
| 22 | if ($core->blog->settings->widgets->widgets_extra) { |
---|
| 23 | $widgets_extra = dcWidgets::load($core->blog->settings->widgets->widgets_extra); |
---|
| 24 | } |
---|
| 25 | |
---|
| 26 | $append_combo = array( |
---|
| 27 | '-' => 0, |
---|
| 28 | __('navigation') => 'nav', |
---|
| 29 | __('extra') => 'extra' |
---|
| 30 | ); |
---|
| 31 | |
---|
| 32 | # Adding widgets to sidebars |
---|
| 33 | if (!empty($_POST['append']) && is_array($_POST['addw'])) |
---|
| 34 | { |
---|
| 35 | # Filter selection |
---|
| 36 | $addw = array(); |
---|
| 37 | foreach ($_POST['addw'] as $k => $v) { |
---|
| 38 | if (($v == 'extra' || $v == 'nav') && $__widgets->{$k} !== null ) { |
---|
| 39 | $addw[$k] = $v; |
---|
| 40 | } |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | # Append widgets |
---|
| 44 | if (!empty($addw)) |
---|
| 45 | { |
---|
| 46 | if (!($widgets_nav instanceof dcWidgets)) { |
---|
| 47 | $widgets_nav = new dcWidgets; |
---|
| 48 | } |
---|
| 49 | if (!($widgets_extra instanceof dcWidgets)) { |
---|
| 50 | $widgets_extra = new dcWidgets(); |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | foreach ($addw as $k => $v) |
---|
| 54 | { |
---|
| 55 | switch ($v) { |
---|
| 56 | case 'nav': |
---|
| 57 | $widgets_nav->append($__widgets->{$k}); |
---|
| 58 | break; |
---|
| 59 | case 'extra': |
---|
| 60 | $widgets_extra->append($__widgets->{$k}); |
---|
| 61 | break; |
---|
| 62 | |
---|
| 63 | } |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | try { |
---|
| 67 | $core->blog->settings->addNamespace('widgets'); |
---|
| 68 | $core->blog->settings->widgets->put('widgets_nav',$widgets_nav->store()); |
---|
| 69 | $core->blog->settings->widgets->put('widgets_extra',$widgets_extra->store()); |
---|
| 70 | $core->blog->triggerBlog(); |
---|
| 71 | http::redirect($p_url); |
---|
| 72 | } catch (Exception $e) { |
---|
| 73 | $core->error->add($e->getMessage()); |
---|
| 74 | } |
---|
| 75 | } |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | # Update sidebars |
---|
| 79 | if (!empty($_POST['wup'])) |
---|
| 80 | { |
---|
| 81 | if (!isset($_POST['w']) || !is_array($_POST['w'])) { |
---|
| 82 | $_POST['w'] = array(); |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | try |
---|
| 86 | { |
---|
| 87 | # Removing mark as _rem widgets |
---|
| 88 | foreach ($_POST['w'] as $nsid => $nsw) { |
---|
| 89 | foreach ($nsw as $i => $v) { |
---|
| 90 | if (!empty($v['_rem'])) { |
---|
| 91 | unset($_POST['w'][$nsid][$i]); |
---|
| 92 | continue; |
---|
| 93 | } |
---|
| 94 | } |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | if (!isset($_POST['w']['nav'])) { |
---|
| 98 | $_POST['w']['nav'] = array(); |
---|
| 99 | } |
---|
| 100 | if (!isset($_POST['w']['extra'])) { |
---|
| 101 | $_POST['w']['extra'] = array(); |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | $widgets_nav = dcWidgets::loadArray($_POST['w']['nav'],$__widgets); |
---|
| 105 | $widgets_extra = dcWidgets::loadArray($_POST['w']['extra'],$__widgets); |
---|
| 106 | |
---|
| 107 | $core->blog->settings->addNamespace('widgets'); |
---|
| 108 | $core->blog->settings->widgets->put('widgets_nav',$widgets_nav->store()); |
---|
| 109 | $core->blog->settings->widgets->put('widgets_extra',$widgets_extra->store()); |
---|
| 110 | $core->blog->triggerBlog(); |
---|
| 111 | |
---|
| 112 | http::redirect($p_url); |
---|
| 113 | } |
---|
| 114 | catch (Exception $e) |
---|
| 115 | { |
---|
| 116 | $core->error->add($e->getMessage()); |
---|
| 117 | } |
---|
| 118 | } |
---|
| 119 | elseif (!empty($_POST['wreset'])) |
---|
| 120 | { |
---|
| 121 | try |
---|
| 122 | { |
---|
| 123 | $core->blog->settings->addNamespace('widgets'); |
---|
| 124 | $core->blog->settings->widgets->put('widgets_nav',''); |
---|
| 125 | $core->blog->settings->widgets->put('widgets_extra',''); |
---|
| 126 | $core->blog->triggerBlog(); |
---|
| 127 | |
---|
| 128 | http::redirect($p_url); |
---|
| 129 | } |
---|
| 130 | catch (Exception $e) |
---|
| 131 | { |
---|
| 132 | $core->error->add($e->getMessage()); |
---|
| 133 | } |
---|
| 134 | } |
---|
| 135 | ?> |
---|
| 136 | <html> |
---|
| 137 | <head> |
---|
| 138 | <title><?php echo __('Widgets'); ?></title> |
---|
| 139 | <style type="text/css"> |
---|
| 140 | <?php echo file_get_contents(dirname(__FILE__).'/style.css'); ?> |
---|
| 141 | </style> |
---|
| 142 | <script type="text/javascript" src="js/tool-man/core.js"></script> |
---|
| 143 | <script type="text/javascript" src="js/tool-man/events.js"></script> |
---|
| 144 | <script type="text/javascript" src="js/tool-man/css.js"></script> |
---|
| 145 | <script type="text/javascript" src="js/tool-man/coordinates.js"></script> |
---|
| 146 | <script type="text/javascript" src="js/tool-man/drag.js"></script> |
---|
| 147 | <script type="text/javascript" src="index.php?pf=widgets/dragdrop.js"></script> |
---|
| 148 | <script type="text/javascript" src="index.php?pf=widgets/widgets.js"></script> |
---|
| 149 | <script type="text/javascript"> |
---|
| 150 | //<![CDATA[ |
---|
| 151 | <?php echo dcPage::jsVar('dotclear.msg.confirm_widgets_reset', |
---|
| 152 | __('Are you sure you want to reset sidebars?')); ?> |
---|
| 153 | //]]> |
---|
| 154 | </script> |
---|
| 155 | <?php echo(dcPage::jsConfirmClose('sidebarsWidgets')); ?> |
---|
| 156 | </head> |
---|
| 157 | <body> |
---|
| 158 | <?php |
---|
| 159 | echo '<h2>'.html::escapeHTML($core->blog->name).' › '.__('Widgets').'</h2>'; |
---|
| 160 | |
---|
| 161 | # All widgets |
---|
| 162 | echo |
---|
| 163 | '<form id="listWidgets" action="'.$p_url.'" method="post" class="widgets">'. |
---|
| 164 | '<fieldset><legend>'.__('Available widgets').'</legend>'. |
---|
| 165 | '<div id="widgets">'; |
---|
| 166 | |
---|
| 167 | foreach ($__widgets->elements(true) as $w) { |
---|
| 168 | echo |
---|
| 169 | '<div>'.form::hidden(array('w[void][0][id]'),html::escapeHTML($w->id())). |
---|
| 170 | '<p class="widget-name">'.form::field(array('w[void][0][order]'),2,3,0,'hideControl').' '. |
---|
| 171 | $w->name().'</p>'. |
---|
| 172 | '<p class="js-remove"><label class="classic">'.__('Append to:').' '. |
---|
| 173 | form::combo(array('addw['.$w->id().']'),$append_combo).'</label></p>'. |
---|
| 174 | '<div class="widgetSettings">'.$w->formSettings('w[void][0]').'</div>'. |
---|
| 175 | '</div>'; |
---|
| 176 | } |
---|
| 177 | |
---|
| 178 | echo |
---|
| 179 | '</div>'. |
---|
| 180 | '</fieldset>'. |
---|
| 181 | '<p><input type="submit" class="js-remove" name="append" value="'.__('add widgets to sidebars').'" />'. |
---|
| 182 | $core->formNonce().'</p>'. |
---|
| 183 | '</form>'; |
---|
| 184 | |
---|
| 185 | echo '<form id="sidebarsWidgets" action="'.$p_url.'" method="post">'; |
---|
| 186 | # Nav sidebar |
---|
| 187 | echo |
---|
| 188 | '<div id="sidebarNav" class="widgets">'. |
---|
| 189 | sidebarWidgets('dndnav',__('Navigation sidebar'),$widgets_nav,'nav',$__default_widgets['nav']). |
---|
| 190 | '</div>'; |
---|
| 191 | |
---|
| 192 | # Extra sidebar |
---|
| 193 | echo |
---|
| 194 | '<div id="sidebarExtra" class="widgets">'. |
---|
| 195 | sidebarWidgets('dndextra',__('Extra sidebar'),$widgets_extra,'extra',$__default_widgets['extra']). |
---|
| 196 | '</div>'; |
---|
| 197 | |
---|
| 198 | echo |
---|
| 199 | '<p id="sidebarsControl">'. |
---|
| 200 | $core->formNonce(). |
---|
| 201 | '<input type="submit" name="wup" value="'.__('update sidebars').'" /> '. |
---|
| 202 | '<input type="submit" name="wreset" value="'.__('reset sidebars').'" /></p>'. |
---|
| 203 | '</form>'; |
---|
| 204 | |
---|
| 205 | $widget_elements = new stdClass; |
---|
| 206 | $widget_elements->content = |
---|
| 207 | '<h3 class="clear">'.__('Widget templates tags').'</h3>'. |
---|
| 208 | '<div id="widgets-tpl">'. |
---|
| 209 | '<p>'.__('If you are allowed to edit your theme templates, you can directly add widgets as '. |
---|
| 210 | 'templates tags, with their own configuration.').'</p>'. |
---|
| 211 | '<p>'.__('To add a widget in your template, you need to write code like this:').'</p>'. |
---|
| 212 | '<pre><tpl:Widget id="<strong>'.__('Widget ID').'</strong>"> |
---|
| 213 | <setting name="<strong>'.__('Setting name').'</strong>"><strong>'.__('Setting value').'</strong></setting> |
---|
| 214 | ... |
---|
| 215 | </tpl:Widget></pre>'. |
---|
| 216 | '<p>'.__('Here are the following available widgets for your blog:').'</p>'; |
---|
| 217 | |
---|
| 218 | $widget_elements->content .= '<dl>'; |
---|
| 219 | foreach ($__widgets->elements() as $w) |
---|
| 220 | { |
---|
| 221 | $widget_elements->content .= |
---|
| 222 | '<dt><strong>'.html::escapeHTML($w->name()).'</strong> ('. |
---|
| 223 | __('Widget ID:').' <strong>'.html::escapeHTML($w->id()).'</strong>)</dt>'. |
---|
| 224 | '<dd>'; |
---|
| 225 | |
---|
| 226 | $w_settings = $w->settings(); |
---|
| 227 | if (empty($w_settings)) |
---|
| 228 | { |
---|
| 229 | $widget_elements->content .= '<p>'.__('No setting for this widget').'</p>'; |
---|
| 230 | } |
---|
| 231 | else |
---|
| 232 | { |
---|
| 233 | $widget_elements->content .= '<ul>'; |
---|
| 234 | foreach ($w->settings() as $n => $s) |
---|
| 235 | { |
---|
| 236 | switch ($s['type']) { |
---|
| 237 | case 'check': |
---|
| 238 | $s_type = '0|1'; |
---|
| 239 | break; |
---|
| 240 | case 'combo': |
---|
| 241 | $s_type = implode('|',$s['options']); |
---|
| 242 | break; |
---|
| 243 | case 'text': |
---|
| 244 | case 'textarea': |
---|
| 245 | default: |
---|
| 246 | $s_type = 'text'; |
---|
| 247 | break; |
---|
| 248 | } |
---|
| 249 | |
---|
| 250 | $widget_elements->content .= |
---|
| 251 | '<li>'. |
---|
| 252 | __('Setting name:').' <strong>'.html::escapeHTML($n).'</strong>'. |
---|
| 253 | ' ('.$s_type.')'. |
---|
| 254 | '</li>'; |
---|
| 255 | } |
---|
| 256 | $widget_elements->content .= '</ul>'; |
---|
| 257 | } |
---|
| 258 | $widget_elements->content .= '</dd>'; |
---|
| 259 | } |
---|
| 260 | $widget_elements->content .= '</dl></div>'; |
---|
| 261 | |
---|
| 262 | dcPage::helpBlock($widget_elements); |
---|
| 263 | |
---|
| 264 | function sidebarWidgets($id,$title,$widgets,$pr,$default_widgets) |
---|
| 265 | { |
---|
| 266 | $res = '<fieldset><legend>'.$title.'</legend><div id="'.$id.'">'; |
---|
| 267 | |
---|
| 268 | if (!($widgets instanceof dcWidgets)) |
---|
| 269 | { |
---|
| 270 | $widgets = $default_widgets; |
---|
| 271 | } |
---|
| 272 | |
---|
| 273 | if ($widgets->isEmpty()) { |
---|
| 274 | $res .= '<p class="empty-widgets">'.__('No widget.').'</p>'; |
---|
| 275 | } |
---|
| 276 | |
---|
| 277 | $i = 0; |
---|
| 278 | foreach ($widgets->elements() as $w) |
---|
| 279 | { |
---|
| 280 | $iname = 'w['.$pr.']['.$i.']'; |
---|
| 281 | |
---|
| 282 | $res .= |
---|
| 283 | '<div>'.form::hidden(array($iname.'[id]'),html::escapeHTML($w->id())). |
---|
| 284 | '<p class="widget-name">'.form::field(array($iname.'[order]'),2,3,(string) $i,'js-hide','',0,'title="'.__('order').'"').' '. |
---|
| 285 | $w->name().'</p>'. |
---|
| 286 | '<p class="removeWidget js-remove"><label class="classic">'. |
---|
| 287 | form::checkbox(array($iname.'[_rem]'),'1',0).' '.__('Remove widget'). |
---|
| 288 | '</label></p>'. |
---|
| 289 | '<div class="widgetSettings">'.$w->formSettings($iname).'</div>'. |
---|
| 290 | '</div>'; |
---|
| 291 | |
---|
| 292 | $i++; |
---|
| 293 | } |
---|
| 294 | |
---|
| 295 | $res .= '</div></fieldset>'; |
---|
| 296 | |
---|
| 297 | return $res; |
---|
| 298 | } |
---|
| 299 | ?> |
---|
| 300 | </body> |
---|
| 301 | </html> |
---|