[ Index ]
 

Code source de Dotclear 2.0-beta6

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

title

Body

[fermer]

/admin/ -> plugins.php (source)

   1  <?php
   2  # ***** BEGIN LICENSE BLOCK *****
   3  # This file is part of DotClear.
   4  # Copyright (c) 2006 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  
  23  require dirname(__FILE__).'/../inc/admin/prepend.php';
  24  
  25  dcPage::checkSuper();
  26  
  27  $default_tab = !empty($_REQUEST['tab']) ? html::escapeHTML($_REQUEST['tab']) : 'plugins';
  28  
  29  $p_paths = explode(PATH_SEPARATOR, DC_PLUGINS_ROOT);
  30  $p_path = array_pop($p_paths);
  31  unset($p_paths);
  32  
  33  $is_writable = false;
  34  if (is_dir($p_path) && is_writeable($p_path)) {
  35      $is_writable = true;
  36      $p_path_pat = preg_quote($p_path);
  37  }
  38  
  39  if ($is_writable) {
  40      # Plugin deletion
  41      if (!empty($_POST['plugin_del']) && is_array($_POST['plugin_del']))
  42      {
  43          try
  44          {
  45              foreach ($_POST['plugin_del'] as $plugin_id => $v)
  46              {
  47                  if (!$is_writable) {
  48                      throw new Exception(__('Plugins root is not writable.'));
  49                  }
  50                  
  51                  if (!$core->plugins->moduleExists($plugin_id)) {
  52                      throw new Exception(__('No such plugin.'));
  53                  }
  54                  
  55                  $plugin = $core->plugins->getModules($plugin_id);
  56                  $plugin['id'] = $plugin_id;
  57                  
  58                  if (!preg_match('!^'.$p_path_pat.'!', $plugin['root'])) {
  59                      throw new Exception(__('You don\'t have permissions to delete this plugin.'));
  60                  }
  61                  
  62                  # --BEHAVIOR-- pluginBeforeDelete
  63                  $core->callBehavior('pluginsBeforeDelete', $plugin);
  64                  
  65                  if (!files::deltree($p_path.'/'.$plugin_id)) {
  66                      throw new Exception(__('An error occurred during plugin deletion.'));
  67                  }
  68                  
  69                  # --BEHAVIOR-- pluginAfterDelete
  70                  $core->callBehavior('pluginsAfterDelete', $plugin);
  71              }
  72              http::redirect('plugins.php?removed=1');
  73          }
  74          catch (Exception $e)
  75          {
  76              $core->error->add($e->getMessage());
  77          }
  78      }
  79      # Plugin upload
  80      elseif ((!empty($_POST['upload_pkg']) && !empty($_FILES['pkg_file'])) ||
  81          (!empty($_POST['fetch_pkg']) && !empty($_POST['pkg_url'])))
  82      {
  83          try
  84          {
  85              if (!empty($_POST['upload_pkg']))
  86              {
  87                  files::uploadStatus($_FILES['pkg_file']);
  88                  
  89                  $dest = $p_path.'/'.$_FILES['pkg_file']['name'];
  90                  if (!move_uploaded_file($_FILES['pkg_file']['tmp_name'],$dest)) {
  91                      throw new Exception(__('Unable to move uploaded file.'));
  92                  }
  93              }
  94              else
  95              {
  96                  $url = html::escapeHTML($_POST['pkg_url']);
  97                  $dest = $p_path.'/'.basename($url);
  98                  
  99                  try
 100                  {
 101                      $client = netHttp::initClient($url,$path,10);
 102                      $client->setUserAgent('Dotclear - http://www.dotclear.net/');
 103                      $client->useGzip(false);
 104                      $client->setPersistReferers(false);
 105                      $client->setOutput($dest);
 106                      $client->get($path);
 107                  }
 108                  catch( Exception $e)
 109                  {
 110                      throw new Exception(__('An error occured while downloading the file.'));
 111                  }
 112                  
 113                  unset($client);
 114              }
 115              
 116              files::installPackage($dest);
 117              http::redirect('plugins.php?added=1');
 118          }
 119          catch (Exception $e)
 120          {
 121              $core->error->add($e->getMessage());
 122              $default_tab = 'addplugin';
 123          }
 124      }
 125  }
 126  
 127  dcPage::open(__('Plugins management'),
 128      dcPage::jsLoad('js/_plugins.js').
 129      dcPage::jsPageTabs($default_tab)
 130  );
 131  
 132  echo
 133  '<h2>'.__('Plugins management').'</h2>';
 134  
 135  if (!empty($_GET['removed'])) {
 136      echo
 137      '<p class="message">'.__('Plugins have been successfully deleted.').'</p>';
 138  }
 139  if (!empty($_GET['added'])) {
 140      echo
 141      '<p class="message">'.__('Plugin has been successfully added.').'</p>';
 142  }
 143  
 144  # List all active plugins
 145  echo
 146  '<div class="multi-part" id="plugins" title="'.__('Plugins').'">';
 147  
 148  $p_available = $core->plugins->getModules();
 149  if (!empty($p_available)) 
 150  {
 151      echo
 152      '<form action="plugins.php" method="post" id="form-plugins">'.
 153      '<table class="clear"><tr>'.
 154      '<th colspan="2">'.__('Plugin').'</th>'.
 155      '<th class="nowrap">'.__('Version').'</th>'.
 156      '<th class="nowrap">'.__('Description').'</th>'.
 157      '</tr>';
 158  
 159      foreach ($p_available as $k => $v)
 160      {
 161          $is_deletable = $is_writable && preg_match('!^'.$p_path_pat.'!',$v['root']);
 162          
 163          echo
 164          '<tr class="line">'.
 165          '<td>'.($is_deletable ? form::checkbox(array('plugin_del['.html::escapeHTML($k).']'),1) : '').'</td>'.
 166          '<td class="minimal">'.$v['name'].'</td>'.
 167          '<td class="minimal">'.$v['version'].'</td>'.
 168          '<td class="maximal">'.$v['desc'].'</td>'.
 169          '</tr>';
 170      }
 171      echo
 172      '</table>'.
 173      '<p><input type="submit" value="'.__('Remove selected plugins').'" /></p>'.
 174      '</form>';
 175  }
 176  
 177  echo '</div>';
 178  
 179  if ($is_writable) {
 180      # Add a new plugin
 181      echo
 182      '<div class="multi-part" id="addplugin" title="'.__('Add a new plugin').'">';
 183      
 184      # 'Upload plugin' form
 185      echo
 186      '<form method="post" action="plugins.php" id="uploadpkg" enctype="multipart/form-data">'.
 187      '<fieldset>'.
 188      '<legend>'.__('Upload a plugin package').'</legend>'.
 189      '<p><label class=" classic required" title="'.__('Required field').'">'.__('Package file :').' '.
 190      '<input type="file" name="pkg_file" /></label></p>'.
 191      '<input type="submit" name="upload_pkg" value="'.__('Upload package').'" />'.
 192      '</fieldset>'.
 193      '</form>';
 194      
 195      # 'Fetch plugin' form
 196      echo
 197      '<form method="post" action="plugins.php" id="fetchpkg">'.
 198      '<fieldset>'.
 199      '<legend>'.__('Fetch a plugin package').'</legend>'.
 200      '<p><label class=" classic required" title="'.__('Required field').'">'.__('Package URL :').' '.
 201      form::field(array('pkg_url'),40,255).'</label></p>'.
 202      '<input type="submit" name="fetch_pkg" value="'.__('Fetch package').'" />'.
 203      '</fieldset>'.
 204      '</form>';
 205      
 206      echo
 207      '</div>';
 208  }
 209  
 210  # --BEHAVIOR-- pluginsToolsTabs
 211  $core->callBehavior('pluginsToolsTabs',$core);
 212  
 213  dcPage::close();
 214  ?>


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