[0] | 1 | <?php |
---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
| 3 | # |
---|
| 4 | # This file is part of Dotclear 2. |
---|
| 5 | # |
---|
[1179] | 6 | # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear |
---|
[0] | 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 | |
---|
[665] | 16 | # Loading navigation, extra widgets and custom widgets |
---|
[0] | 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 | } |
---|
[665] | 25 | $widgets_custom = null; |
---|
| 26 | if ($core->blog->settings->widgets->widgets_custom) { |
---|
| 27 | $widgets_custom = dcWidgets::load($core->blog->settings->widgets->widgets_custom); |
---|
| 28 | } |
---|
[0] | 29 | |
---|
| 30 | $append_combo = array( |
---|
| 31 | '-' => 0, |
---|
| 32 | __('navigation') => 'nav', |
---|
[665] | 33 | __('extra') => 'extra', |
---|
| 34 | __('custom') => 'custom' |
---|
[0] | 35 | ); |
---|
| 36 | |
---|
[902] | 37 | function literalNullString($v) |
---|
| 38 | { |
---|
| 39 | if ($v == '') { |
---|
| 40 | return '<'.__('empty string').'>'; |
---|
| 41 | } |
---|
| 42 | return $v; |
---|
| 43 | } |
---|
| 44 | |
---|
[0] | 45 | # Adding widgets to sidebars |
---|
| 46 | if (!empty($_POST['append']) && is_array($_POST['addw'])) |
---|
| 47 | { |
---|
| 48 | # Filter selection |
---|
| 49 | $addw = array(); |
---|
| 50 | foreach ($_POST['addw'] as $k => $v) { |
---|
[665] | 51 | if (($v == 'extra' || $v == 'nav' || $v == 'custom') && $__widgets->{$k} !== null ) { |
---|
[0] | 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 | } |
---|
[665] | 65 | if (!($widgets_custom instanceof dcWidgets)) { |
---|
| 66 | $widgets_custom = new dcWidgets(); |
---|
| 67 | } |
---|
[0] | 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; |
---|
[665] | 78 | case 'custom': |
---|
| 79 | $widgets_custom->append($__widgets->{$k}); |
---|
| 80 | break; |
---|
[0] | 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()); |
---|
[665] | 88 | $core->blog->settings->widgets->put('widgets_custom',$widgets_custom->store()); |
---|
[0] | 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 |
---|
| 98 | if (!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 | } |
---|
[665] | 122 | if (!isset($_POST['w']['custom'])) { |
---|
| 123 | $_POST['w']['custom'] = array(); |
---|
| 124 | } |
---|
[0] | 125 | |
---|
| 126 | $widgets_nav = dcWidgets::loadArray($_POST['w']['nav'],$__widgets); |
---|
| 127 | $widgets_extra = dcWidgets::loadArray($_POST['w']['extra'],$__widgets); |
---|
[665] | 128 | $widgets_custom = dcWidgets::loadArray($_POST['w']['custom'],$__widgets); |
---|
[0] | 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()); |
---|
[665] | 133 | $core->blog->settings->widgets->put('widgets_custom',$widgets_custom->store()); |
---|
[0] | 134 | $core->blog->triggerBlog(); |
---|
| 135 | |
---|
| 136 | http::redirect($p_url); |
---|
| 137 | } |
---|
| 138 | catch (Exception $e) |
---|
| 139 | { |
---|
| 140 | $core->error->add($e->getMessage()); |
---|
| 141 | } |
---|
| 142 | } |
---|
| 143 | elseif (!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',''); |
---|
[665] | 150 | $core->blog->settings->widgets->put('widgets_custom',''); |
---|
[0] | 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> |
---|
[1648] | 167 | <script type="text/javascript" src="js/jquery/jquery-ui.custom.js"></script> |
---|
| 168 | <script type="text/javascript" src="index.php?pf=widgets/widgets.js"></script> |
---|
[183] | 169 | <?php |
---|
| 170 | $core->auth->user_prefs->addWorkspace('accessibility'); |
---|
| 171 | $user_dm_nodragdrop = $core->auth->user_prefs->accessibility->nodragdrop; |
---|
| 172 | ?> |
---|
| 173 | <?php if (!$user_dm_nodragdrop) : ?> |
---|
[0] | 174 | <script type="text/javascript" src="index.php?pf=widgets/dragdrop.js"></script> |
---|
[183] | 175 | <?php endif; ?> |
---|
[0] | 176 | <script type="text/javascript"> |
---|
| 177 | //<![CDATA[ |
---|
| 178 | <?php echo dcPage::jsVar('dotclear.msg.confirm_widgets_reset', |
---|
| 179 | __('Are you sure you want to reset sidebars?')); ?> |
---|
| 180 | //]]> |
---|
| 181 | </script> |
---|
| 182 | <?php echo(dcPage::jsConfirmClose('sidebarsWidgets')); ?> |
---|
| 183 | </head> |
---|
| 184 | <body> |
---|
| 185 | <?php |
---|
[1358] | 186 | echo dcPage::breadcrumb( |
---|
[1339] | 187 | array( |
---|
| 188 | html::escapeHTML($core->blog->name) => '', |
---|
| 189 | '<span class="page-title">'.__('Widgets').'</span>' => '' |
---|
| 190 | )); |
---|
[0] | 191 | |
---|
| 192 | # All widgets |
---|
| 193 | echo |
---|
| 194 | '<form id="listWidgets" action="'.$p_url.'" method="post" class="widgets">'. |
---|
[1483] | 195 | '<h3>'.__('Available widgets').'</h3>'. |
---|
[1518] | 196 | '<p>'.__('Move widgets from this list to one of the sidebars.').'</p>'. |
---|
[1659] | 197 | '<ul id="widgets-ref">'; |
---|
[0] | 198 | |
---|
[117] | 199 | $j = 0; |
---|
[0] | 200 | foreach ($__widgets->elements(true) as $w) { |
---|
| 201 | echo |
---|
[1648] | 202 | '<li>'.form::hidden(array('w[void][0][id]'),html::escapeHTML($w->id())). |
---|
[1659] | 203 | '<p class="widget-name">'.form::field(array('w[void][0][order]'),2,3,0,'hide','',0,'title="'.__('order').'"').' '.$w->name(). |
---|
[1650] | 204 | ($w->desc() != '' ? ' <span class="form-note">'.__($w->desc()).'</span>' : '').'</p>'. |
---|
[1659] | 205 | '<p class="manual-move remove-if-drag"><label class="classic">'.__('Append to:').'</label> '. |
---|
[1454] | 206 | form::combo(array('addw['.$w->id().']'),$append_combo).'</p>'. |
---|
[1657] | 207 | '<div class="widgetSettings hidden-if-drag">'.$w->formSettings('w[void][0]',$j).'</div>'. |
---|
[1648] | 208 | '</li>'; |
---|
[117] | 209 | $j++; |
---|
[0] | 210 | } |
---|
| 211 | |
---|
| 212 | echo |
---|
[1648] | 213 | '</ul>'. |
---|
| 214 | $core->formNonce(). |
---|
[1657] | 215 | '<p class="remove-if-drag"><input type="submit" name="append" value="'.__('Add widgets to sidebars').'" /></p>'. |
---|
[0] | 216 | '</form>'; |
---|
| 217 | |
---|
| 218 | echo '<form id="sidebarsWidgets" action="'.$p_url.'" method="post">'; |
---|
| 219 | # Nav sidebar |
---|
| 220 | echo |
---|
[1483] | 221 | '<div id="sidebarNav" class="widgets fieldset">'. |
---|
[117] | 222 | sidebarWidgets('dndnav',__('Navigation sidebar'),$widgets_nav,'nav',$__default_widgets['nav'],$j). |
---|
[1650] | 223 | '</div>'. |
---|
[1657] | 224 | '<ul class="sortable-delete"><li class="sortable-delete-placeholder">'.__('Drag here to delete').'</li></ul>'; |
---|
[0] | 225 | |
---|
| 226 | # Extra sidebar |
---|
| 227 | echo |
---|
[1483] | 228 | '<div id="sidebarExtra" class="widgets fieldset">'. |
---|
[117] | 229 | sidebarWidgets('dndextra',__('Extra sidebar'),$widgets_extra,'extra',$__default_widgets['extra'],$j). |
---|
[1650] | 230 | '</div>'. |
---|
[1657] | 231 | '<ul class="sortable-delete"><li class="sortable-delete-placeholder">'.__('Drag here to delete').'</li></ul>'; |
---|
[0] | 232 | |
---|
[665] | 233 | # Custom sidebar |
---|
| 234 | echo |
---|
[1483] | 235 | '<div id="sidebarCustom" class="widgets fieldset">'. |
---|
[665] | 236 | sidebarWidgets('dndcustom',__('Custom sidebar'),$widgets_custom,'custom',$__default_widgets['custom'],$j). |
---|
[1650] | 237 | '</div>'. |
---|
[1657] | 238 | '<ul class="sortable-delete"><li class="sortable-delete-placeholder">'.__('Drag here to delete').'</li></ul>'; |
---|
[665] | 239 | |
---|
[0] | 240 | echo |
---|
| 241 | '<p id="sidebarsControl">'. |
---|
| 242 | $core->formNonce(). |
---|
[665] | 243 | '<input type="submit" name="wup" value="'.__('Update sidebars').'" /> '. |
---|
| 244 | '<input type="submit" class="reset" name="wreset" value="'.__('Reset sidebars').'" /></p>'. |
---|
[0] | 245 | '</form>'; |
---|
| 246 | |
---|
| 247 | $widget_elements = new stdClass; |
---|
| 248 | $widget_elements->content = |
---|
[731] | 249 | '<h3 class="clear">'.__('Use of widgets').'</h3>'. |
---|
| 250 | '<p>'.__('Widgets may be used to add various blocks of content to be displayed on your public pages. To add a widget, '. |
---|
| 251 | 'drag it from the Available widgets list on the left to one of the sidebars on the right of this page. You can order '. |
---|
[735] | 252 | 'your widgets in a sidebar by dragging them up or down. You must update sidebars to apply your changes.').'</p>'. |
---|
[1354] | 253 | '<p>'.__('Once included in a sidebar, widgets have configuration options that you can reach by clicking on the arrow next '. |
---|
[731] | 254 | 'to their name.').'</p>'. |
---|
[735] | 255 | '<p>'.__('Reset sidebars to get back to default widgets installation.').'</p>'. |
---|
[0] | 256 | '<h3 class="clear">'.__('Widget templates tags').'</h3>'. |
---|
| 257 | '<div id="widgets-tpl">'. |
---|
| 258 | '<p>'.__('If you are allowed to edit your theme templates, you can directly add widgets as '. |
---|
| 259 | 'templates tags, with their own configuration.').'</p>'. |
---|
| 260 | '<p>'.__('To add a widget in your template, you need to write code like this:').'</p>'. |
---|
| 261 | '<pre><tpl:Widget id="<strong>'.__('Widget ID').'</strong>"> |
---|
| 262 | <setting name="<strong>'.__('Setting name').'</strong>"><strong>'.__('Setting value').'</strong></setting> |
---|
| 263 | ... |
---|
| 264 | </tpl:Widget></pre>'. |
---|
| 265 | '<p>'.__('Here are the following available widgets for your blog:').'</p>'; |
---|
| 266 | |
---|
| 267 | $widget_elements->content .= '<dl>'; |
---|
| 268 | foreach ($__widgets->elements() as $w) |
---|
| 269 | { |
---|
| 270 | $widget_elements->content .= |
---|
| 271 | '<dt><strong>'.html::escapeHTML($w->name()).'</strong> ('. |
---|
[954] | 272 | __('Widget ID:').' <strong>'.html::escapeHTML($w->id()).'</strong>)'. |
---|
| 273 | ($w->desc() != '' ? ' <span class="form-note">'.__($w->desc()).'</span>' : '').'</dt>'. |
---|
[0] | 274 | '<dd>'; |
---|
| 275 | |
---|
| 276 | $w_settings = $w->settings(); |
---|
| 277 | if (empty($w_settings)) |
---|
| 278 | { |
---|
| 279 | $widget_elements->content .= '<p>'.__('No setting for this widget').'</p>'; |
---|
| 280 | } |
---|
| 281 | else |
---|
| 282 | { |
---|
| 283 | $widget_elements->content .= '<ul>'; |
---|
| 284 | foreach ($w->settings() as $n => $s) |
---|
| 285 | { |
---|
| 286 | switch ($s['type']) { |
---|
| 287 | case 'check': |
---|
[902] | 288 | $s_type = __('boolean').", ".__('possible values:')." <code>0</code> ".__('or')." <code>1</code>"; |
---|
[0] | 289 | break; |
---|
| 290 | case 'combo': |
---|
[902] | 291 | $s['options'] = array_map("literalNullString", $s['options']); |
---|
| 292 | $s_type = __('listitem').", ".__('possible values:')." <code>".implode('</code>, <code>',$s['options'])."</code>"; |
---|
[0] | 293 | break; |
---|
| 294 | case 'text': |
---|
| 295 | case 'textarea': |
---|
| 296 | default: |
---|
[902] | 297 | $s_type = __('string'); |
---|
[0] | 298 | break; |
---|
| 299 | } |
---|
| 300 | |
---|
| 301 | $widget_elements->content .= |
---|
| 302 | '<li>'. |
---|
| 303 | __('Setting name:').' <strong>'.html::escapeHTML($n).'</strong>'. |
---|
| 304 | ' ('.$s_type.')'. |
---|
| 305 | '</li>'; |
---|
| 306 | } |
---|
| 307 | $widget_elements->content .= '</ul>'; |
---|
| 308 | } |
---|
| 309 | $widget_elements->content .= '</dd>'; |
---|
| 310 | } |
---|
| 311 | $widget_elements->content .= '</dl></div>'; |
---|
| 312 | |
---|
| 313 | dcPage::helpBlock($widget_elements); |
---|
| 314 | |
---|
[117] | 315 | function sidebarWidgets($id,$title,$widgets,$pr,$default_widgets,&$j) |
---|
[0] | 316 | { |
---|
[1648] | 317 | $res = '<h3>'.$title.'</h3>'; |
---|
[0] | 318 | |
---|
| 319 | if (!($widgets instanceof dcWidgets)) |
---|
| 320 | { |
---|
| 321 | $widgets = $default_widgets; |
---|
| 322 | } |
---|
| 323 | |
---|
| 324 | if ($widgets->isEmpty()) { |
---|
| 325 | $res .= '<p class="empty-widgets">'.__('No widget.').'</p>'; |
---|
[1648] | 326 | } else { |
---|
| 327 | $res .= '<p class="empty-widgets" style="display: none;">'.__('No widget.').'</p>'; |
---|
[0] | 328 | } |
---|
| 329 | |
---|
[1648] | 330 | $res .= '<ul id="'.$id.'" class="connected">'; |
---|
| 331 | |
---|
[0] | 332 | $i = 0; |
---|
| 333 | foreach ($widgets->elements() as $w) |
---|
| 334 | { |
---|
| 335 | $iname = 'w['.$pr.']['.$i.']'; |
---|
| 336 | |
---|
| 337 | $res .= |
---|
[1650] | 338 | '<li>'.form::hidden(array($iname.'[id]'),html::escapeHTML($w->id())). |
---|
[1657] | 339 | '<p class="widget-name">'.form::field(array($iname.'[order]'),2,3,(string) $i,'hidden-if-drag','',0,'title="'.__('order').'"').' '.$w->name(). |
---|
[1650] | 340 | ($w->desc() != '' ? ' <span class="form-note">'.__($w->desc()).'</span>' : '').'</p>'. |
---|
[1657] | 341 | '<p class="removeWidget remove-if-drag"><label class="classic">'. |
---|
[0] | 342 | form::checkbox(array($iname.'[_rem]'),'1',0).' '.__('Remove widget'). |
---|
| 343 | '</label></p>'. |
---|
[1657] | 344 | '<div class="widgetSettings hidden-if-drag">'.$w->formSettings($iname,$j).'</div>'. |
---|
[1648] | 345 | '</li>'; |
---|
[0] | 346 | |
---|
| 347 | $i++; |
---|
[117] | 348 | $j++; |
---|
[0] | 349 | } |
---|
| 350 | |
---|
[1648] | 351 | $res .= '</ul>'; |
---|
[0] | 352 | |
---|
| 353 | return $res; |
---|
| 354 | } |
---|
| 355 | ?> |
---|
| 356 | </body> |
---|
| 357 | </html> |
---|