[ Index ]
 

Code source de Dotclear 2.0-beta6

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/plugins/widgets/ -> index.php (source)

   1  <?php
   2  # ***** BEGIN LICENSE BLOCK *****
   3  # This file is part of DotClear.
   4  # Copyright (c) 2005 Olivier Meunier and contributors. All rights
   5  # reserved.
   6  #
   7  # DotClear is free software; you can redistribute it and/or modify
   8  # it under the terms of the GNU General Public License as published by
   9  # the Free Software Foundation; either version 2 of the License, or
  10  # (at your option) any later version.
  11  # 
  12  # DotClear is distributed in the hope that it will be useful,
  13  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15  # GNU General Public License for more details.
  16  # 
  17  # You should have received a copy of the GNU General Public License
  18  # along with DotClear; if not, write to the Free Software
  19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  20  #
  21  # ***** END LICENSE BLOCK *****
  22  if (!defined('DC_CONTEXT_ADMIN')) { exit; }
  23  
  24  # Loading navigation and extra widgets
  25  $widgets_nav = null;
  26  if ($core->blog->settings->widgets_nav) {
  27      $widgets_nav = dcWidgets::load($core->blog->settings->widgets_nav);
  28  }
  29  $widgets_extra = null;
  30  if ($core->blog->settings->widgets_extra) {
  31      $widgets_extra = dcWidgets::load($core->blog->settings->widgets_extra);
  32  }
  33  
  34  $append_combo = array(
  35      '-' => 0,
  36      __('navigation') => 'nav',
  37      __('extra') => 'extra'
  38  );
  39  
  40  # Adding widgets to sidebars
  41  if (!empty($_POST['append']) && is_array($_POST['addw']))
  42  {
  43      # Filter selection
  44      $addw = array();
  45      foreach ($_POST['addw'] as $k => $v) {
  46          if (($v == 'extra' || $v == 'nav') && $__widgets->{$k} !== null ) {
  47              $addw[$k] = $v;
  48          }
  49      }
  50      
  51      # Append widgets
  52      if (!empty($addw))
  53      {
  54          if (!($widgets_nav instanceof dcWidgets)) {
  55              $widgets_nav = new dcWidgets;
  56          }
  57          if (!($widgets_extra instanceof dcWidgets)) {
  58              $widgets_extra = 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                  
  71              }
  72          }
  73          
  74          try {
  75              $core->blog->settings->setNameSpace('widgets');
  76              $core->blog->settings->put('widgets_nav',$widgets_nav->store());
  77              $core->blog->settings->put('widgets_extra',$widgets_extra->store());
  78              $core->blog->triggerBlog();
  79              http::redirect($p_url);
  80          } catch (Exception $e) {
  81              $core->error->add($e->getMessage());
  82          }
  83      }
  84  }
  85  
  86  # Update sidebars
  87  if (!empty($_POST['wup']))
  88  {
  89      if (!isset($_POST['w']) || !is_array($_POST['w'])) {
  90          $_POST['w'] = array();
  91      }
  92      
  93      try
  94      {
  95          # Removing mark as _rem widgets
  96          foreach ($_POST['w'] as $nsid => $nsw) {
  97              foreach ($nsw as $i => $v) {
  98                  if (!empty($v['_rem'])) {
  99                      unset($_POST['w'][$nsid][$i]);
 100                      continue;
 101                  }
 102              }
 103          }
 104          
 105          if (!isset($_POST['w']['nav'])) {
 106              $_POST['w']['nav'] = array();
 107          }
 108          if (!isset($_POST['w']['extra'])) {
 109              $_POST['w']['extra'] = array();
 110          }
 111          
 112          $widgets_nav = dcWidgets::loadArray($_POST['w']['nav'],$__widgets);
 113          $widgets_extra = dcWidgets::loadArray($_POST['w']['extra'],$__widgets);
 114          
 115          $core->blog->settings->setNameSpace('widgets');
 116          $core->blog->settings->put('widgets_nav',$widgets_nav->store());
 117          $core->blog->settings->put('widgets_extra',$widgets_extra->store());
 118          $core->blog->triggerBlog();
 119          
 120          http::redirect($p_url);
 121      }
 122      catch (Exception $e)
 123      {
 124          $core->error->add($e->getMessage());
 125      }
 126  }
 127  elseif (!empty($_POST['wreset']))
 128  {
 129      try
 130      {
 131          $core->blog->settings->setNameSpace('widgets');
 132          $core->blog->settings->put('widgets_nav','');
 133          $core->blog->settings->put('widgets_extra','');
 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  ?>
 144  <html>
 145  <head>
 146    <title><?php echo __('Widgets'); ?></title>
 147    <style type="text/css">
 148    <?php echo file_get_contents(dirname(__FILE__).'/style.css'); ?>
 149    </style>
 150    <script type="text/javascript" src="js/tool-man/core.js"></script>
 151    <script type="text/javascript" src="js/tool-man/events.js"></script>
 152    <script type="text/javascript" src="js/tool-man/css.js"></script>
 153    <script type="text/javascript" src="js/tool-man/coordinates.js"></script>
 154    <script type="text/javascript" src="js/tool-man/drag.js"></script>
 155    <script type="text/javascript" src="index.php?pf=widgets/dragdrop.js"></script>
 156    <script type="text/javascript" src="index.php?pf=widgets/widgets.js"></script>
 157    <script type="text/javascript">
 158    //<![CDATA[
 159    <?php echo dcPage::jsVar('dotclear.msg.confirm_widgets_reset',
 160        __('Are you sure you want to reset sidebars?')); ?>
 161    //]]>
 162    </script>
 163  </head>
 164  <body>
 165  <?php
 166  echo '<h2>'.html::escapeHTML($core->blog->name).' &gt; '.__('Widgets').'</h2>';
 167  
 168  # All widgets
 169  echo
 170  '<form id="listWidgets" action="'.$p_url.'" method="post"  class="widgets">'.
 171  '<fieldset><legend>'.__('Available widgets').'</legend>'.
 172  '<div id="widgets">';
 173  
 174  foreach ($__widgets->elements() as $w) {
 175      echo
 176      '<div>'.form::hidden(array('w[void][0][id]'),html::escapeHTML($w->id())).
 177      '<h4>'.form::field(array('w[void][0][order]'),2,3,0,'hideControl').' '.
 178      $w->name().'</h4>'.
 179      '<p class="js-remove"><label class="classic">'.__('Append to:').' '.
 180      form::combo(array('addw['.$w->id().']'),$append_combo).'</label></p>'.
 181      '<div class="widgetSettings">'.$w->formSettings('w[void][0]').'</div>'.
 182      '</div>';
 183  }
 184  
 185  echo
 186  '</div>'.
 187  '</fieldset>'.
 188  '<p><input type="submit" class="js-remove" name="append" value="'.__('add widgets to sidebars').'" /></p>'.
 189  '</form>';
 190  
 191  echo '<form id="sidebarsWidgets" action="'.$p_url.'" method="post">';
 192  # Nav sidebar
 193  echo
 194  '<div id="sidebarNav" class="widgets">'.
 195  sidebarWidgets('dndnav',__('Navigation sidebar'),$widgets_nav,'nav',$__default_widgets['nav']).
 196  '</div>';
 197  
 198  # Extra sidebar
 199  echo
 200  '<div id="sidebarExtra" class="widgets">'.
 201  sidebarWidgets('dndextra',__('Extra sidebar'),$widgets_extra,'extra',$__default_widgets['extra']).
 202  '</div>';
 203  
 204  echo
 205  '<p id="sidebarsControl">'.
 206  '<input type="submit" name="wup" value="'.__('update sidebars').'" /> '.
 207  '<input type="submit" name="wreset" value="'.__('reset sidebars').'" /></p>'.
 208  '</form>';
 209  
 210  function sidebarWidgets($id,$title,&$widgets,$pr,$default_widgets)
 211  {
 212      $res = '<fieldset><legend>'.$title.'</legend><div id="'.$id.'">';
 213      
 214      if (!($widgets instanceof dcWidgets))
 215      {
 216          $widgets = $default_widgets;
 217      }
 218      
 219      if ($widgets->isEmpty()) {
 220          $res .= '<p class="empty-widgets">'.__('No widget.').'</p>';
 221      }
 222      
 223      $i = 0;
 224      foreach ($widgets->elements() as $w)
 225      {
 226          $iname = 'w['.$pr.']['.$i.']';
 227          
 228          $res .=
 229          '<div>'.form::hidden(array($iname.'[id]'),html::escapeHTML($w->id())).
 230          '<h4>'.form::field(array($iname.'[order]'),2,3,(string) $i,'js-hide','',0,'title="'.__('order').'"').' '.
 231          $w->name().'</h4>'.
 232          '<p class="removeWidget js-remove"><label class="classic">'.
 233          form::checkbox(array($iname.'[_rem]'),'1',0).' '.__('Remove widget').
 234          '</label></p>'.
 235          '<div class="widgetSettings">'.$w->formSettings($iname).'</div>'.
 236          '</div>';
 237          
 238          $i++;
 239      }
 240      
 241      $res .= '</div></fieldset>';
 242      
 243      return $res;
 244  }
 245  ?>
 246  </body>
 247  </html>


Généré le : Fri Feb 23 22:16:06 2007 par Balluche grâce à PHPXref 0.7