blog->settings->widgets->widgets_nav) { $widgets_nav = dcWidgets::load($core->blog->settings->widgets->widgets_nav); } $widgets_extra = null; if ($core->blog->settings->widgets->widgets_extra) { $widgets_extra = dcWidgets::load($core->blog->settings->widgets->widgets_extra); } $widgets_custom = null; if ($core->blog->settings->widgets->widgets_custom) { $widgets_custom = dcWidgets::load($core->blog->settings->widgets->widgets_custom); } $append_combo = array( '-' => 0, __('navigation') => 'nav', __('extra') => 'extra', __('custom') => 'custom' ); function literalNullString($v) { if ($v == '') { return '<'.__('empty string').'>'; } return $v; } # Adding widgets to sidebars if (!empty($_POST['append']) && is_array($_POST['addw'])) { # Filter selection $addw = array(); foreach ($_POST['addw'] as $k => $v) { if (($v == 'extra' || $v == 'nav' || $v == 'custom') && $__widgets->{$k} !== null ) { $addw[$k] = $v; } } # Append widgets if (!empty($addw)) { if (!($widgets_nav instanceof dcWidgets)) { $widgets_nav = new dcWidgets; } if (!($widgets_extra instanceof dcWidgets)) { $widgets_extra = new dcWidgets(); } if (!($widgets_custom instanceof dcWidgets)) { $widgets_custom = new dcWidgets(); } foreach ($addw as $k => $v) { switch ($v) { case 'nav': $widgets_nav->append($__widgets->{$k}); break; case 'extra': $widgets_extra->append($__widgets->{$k}); break; case 'custom': $widgets_custom->append($__widgets->{$k}); break; } } try { $core->blog->settings->addNamespace('widgets'); $core->blog->settings->widgets->put('widgets_nav',$widgets_nav->store()); $core->blog->settings->widgets->put('widgets_extra',$widgets_extra->store()); $core->blog->settings->widgets->put('widgets_custom',$widgets_custom->store()); $core->blog->triggerBlog(); http::redirect($p_url); } catch (Exception $e) { $core->error->add($e->getMessage()); } } } # Update sidebars if (!empty($_POST['wup'])) { if (!isset($_POST['w']) || !is_array($_POST['w'])) { $_POST['w'] = array(); } try { # Removing mark as _rem widgets foreach ($_POST['w'] as $nsid => $nsw) { foreach ($nsw as $i => $v) { if (!empty($v['_rem'])) { unset($_POST['w'][$nsid][$i]); continue; } } } if (!isset($_POST['w']['nav'])) { $_POST['w']['nav'] = array(); } if (!isset($_POST['w']['extra'])) { $_POST['w']['extra'] = array(); } if (!isset($_POST['w']['custom'])) { $_POST['w']['custom'] = array(); } $widgets_nav = dcWidgets::loadArray($_POST['w']['nav'],$__widgets); $widgets_extra = dcWidgets::loadArray($_POST['w']['extra'],$__widgets); $widgets_custom = dcWidgets::loadArray($_POST['w']['custom'],$__widgets); $core->blog->settings->addNamespace('widgets'); $core->blog->settings->widgets->put('widgets_nav',$widgets_nav->store()); $core->blog->settings->widgets->put('widgets_extra',$widgets_extra->store()); $core->blog->settings->widgets->put('widgets_custom',$widgets_custom->store()); $core->blog->triggerBlog(); http::redirect($p_url); } catch (Exception $e) { $core->error->add($e->getMessage()); } } elseif (!empty($_POST['wreset'])) { try { $core->blog->settings->addNamespace('widgets'); $core->blog->settings->widgets->put('widgets_nav',''); $core->blog->settings->widgets->put('widgets_extra',''); $core->blog->settings->widgets->put('widgets_custom',''); $core->blog->triggerBlog(); http::redirect($p_url); } catch (Exception $e) { $core->error->add($e->getMessage()); } } ?> <?php echo __('Widgets'); ?> auth->user_prefs->addWorkspace('accessibility'); $user_dm_nodragdrop = $core->auth->user_prefs->accessibility->nodragdrop; ?> '.html::escapeHTML($core->blog->name).' › '.__('Widgets').''; # All widgets echo '
'. '
'.__('Available widgets').''. '
'; $j = 0; foreach ($__widgets->elements(true) as $w) { echo '
'.form::hidden(array('w[void][0][id]'),html::escapeHTML($w->id())). '

'.form::field(array('w[void][0][order]'),2,3,0,'hideControl').' '. $w->name().'

'. '

'. '
'.$w->formSettings('w[void][0]',$j).'
'. '
'; $j++; } echo '
'. '
'. '

'. $core->formNonce().'

'. '
'; echo '
'; # Nav sidebar echo '
'. sidebarWidgets('dndnav',__('Navigation sidebar'),$widgets_nav,'nav',$__default_widgets['nav'],$j). '
'; # Extra sidebar echo '
'. sidebarWidgets('dndextra',__('Extra sidebar'),$widgets_extra,'extra',$__default_widgets['extra'],$j). '
'; # Custom sidebar echo '
'. sidebarWidgets('dndcustom',__('Custom sidebar'),$widgets_custom,'custom',$__default_widgets['custom'],$j). '
'; echo '

'. $core->formNonce(). ' '. '

'. '
'; $widget_elements = new stdClass; $widget_elements->content = '

'.__('Use of widgets').'

'. '

'.__('Widgets may be used to add various blocks of content to be displayed on your public pages. To add a widget, '. 'drag it from the Available widgets list on the left to one of the sidebars on the right of this page. You can order '. 'your widgets in a sidebar by dragging them up or down. You must update sidebars to apply your changes.').'

'. '

'.__('Once included in a sidebar, widgets have configuration options that you can reach by clicking on the + sign next '. 'to their name.').'

'. '

'.__('Reset sidebars to get back to default widgets installation.').'

'. '

'.__('Widget templates tags').'

'. '
'. '

'.__('If you are allowed to edit your theme templates, you can directly add widgets as '. 'templates tags, with their own configuration.').'

'. '

'.__('To add a widget in your template, you need to write code like this:').'

'. '
<tpl:Widget id="'.__('Widget ID').'">
  <setting name="'.__('Setting name').'">'.__('Setting value').'</setting>
  ...
</tpl:Widget>
'. '

'.__('Here are the following available widgets for your blog:').'

'; $widget_elements->content .= '
'; foreach ($__widgets->elements() as $w) { $widget_elements->content .= '
'.html::escapeHTML($w->name()).' ('. __('Widget ID:').' '.html::escapeHTML($w->id()).')
'. '
'; $w_settings = $w->settings(); if (empty($w_settings)) { $widget_elements->content .= '

'.__('No setting for this widget').'

'; } else { $widget_elements->content .= '
    '; foreach ($w->settings() as $n => $s) { switch ($s['type']) { case 'check': $s_type = __('boolean').", ".__('possible values:')." 0 ".__('or')." 1"; break; case 'combo': $s['options'] = array_map("literalNullString", $s['options']); $s_type = __('listitem').", ".__('possible values:')." ".implode(', ',$s['options']).""; break; case 'text': case 'textarea': default: $s_type = __('string'); break; } $widget_elements->content .= '
  • '. __('Setting name:').' '.html::escapeHTML($n).''. ' ('.$s_type.')'. '
  • '; } $widget_elements->content .= '
'; } $widget_elements->content .= '
'; } $widget_elements->content .= '
'; dcPage::helpBlock($widget_elements); function sidebarWidgets($id,$title,$widgets,$pr,$default_widgets,&$j) { $res = '
'.$title.'
'; if (!($widgets instanceof dcWidgets)) { $widgets = $default_widgets; } if ($widgets->isEmpty()) { $res .= '

'.__('No widget.').'

'; } $i = 0; foreach ($widgets->elements() as $w) { $iname = 'w['.$pr.']['.$i.']'; $res .= '
'.form::hidden(array($iname.'[id]'),html::escapeHTML($w->id())). '

'.form::field(array($iname.'[order]'),2,3,(string) $i,'js-hide','',0,'title="'.__('order').'"').' '. $w->name().'

'. '

'. '
'.$w->formSettings($iname,$j).'
'. '
'; $i++; $j++; } $res .= '
'; return $res; } ?>