Changeset 2255


Ignore:
Timestamp:
Mar 6, 2008, 3:29:29 AM (16 years ago)
Author:
rvelices
Message:
  • plugins.php does only the tabsheet - nothing else
  • need to review plugins_update.php upgrade action
Location:
trunk/admin
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/include/functions_plugins.inc.php

    r2245 r2255  
    8686
    8787/**
     88 * Activates a plugin. It will be loaded only on the next page ...
     89 * @param string $plugin_id the plugin to activate
     90 * @param array $errors errors to be returned
     91 */
     92function activate_plugin($plugin_id, &$errors)
     93{
     94  // the plugin_id must exist in the DB as inactive
     95  $db_plugins = get_db_plugins('', $plugin_id);
     96  if (!empty($db_plugins))
     97  {
     98    $crt_db_plugin = $db_plugins[0];
     99    if ($crt_db_plugin['state'] != 'inactive')
     100    {
     101      array_push($errors, 'CANNOT ACTIVATE - INVALID CURRENT STATE ' . $crt_db_plugin['state']);
     102      return false;
     103    }
     104  }
     105  else
     106  {
     107    array_push($errors, 'CANNOT ACTIVATE - NOT INSTALLED');
     108    return false;
     109  }
     110
     111  // now try to activate it
     112  $file_to_include = PHPWG_PLUGINS_PATH . $plugin_id . '/maintain.inc.php';
     113  if (file_exists($file_to_include))
     114  {
     115    include_once($file_to_include);
     116    if (function_exists('plugin_activate'))
     117    {
     118      plugin_activate($plugin_id, $crt_db_plugin['version'], $errors);
     119    }
     120  }
     121  if (empty($errors))
     122  {
     123    $query = '
     124UPDATE ' . PLUGINS_TABLE . ' SET state="active" WHERE id="' . $plugin_id . '"';
     125    pwg_query($query);
     126    return true;
     127  }
     128  return false;
     129}
     130
     131
     132/**
     133 * Deactivates a plugin. It will be unloaded only on the next page ...
     134 * @param string $plugin_id the plugin to activate
     135 * @param array $errors errors to be returned
     136 */
     137function deactivate_plugin($plugin_id, &$errors)
     138{
     139  // the plugin_id must exist in the DB as inactive
     140  $db_plugins = get_db_plugins('', $plugin_id);
     141  if (!empty($db_plugins))
     142  {
     143    $crt_db_plugin = $db_plugins[0];
     144    if ($crt_db_plugin['state'] != 'active')
     145    {
     146      array_push($errors, 'CANNOT DEACTIVATE - INVALID CURRENT STATE ' . $crt_db_plugin['state']);
     147      return false;
     148    }
     149  }
     150  else
     151  {
     152    array_push($errors, 'CANNOT DEACTIVATE - NOT INSTALLED');
     153    return false;
     154  }
     155
     156  // now try to deactivate it
     157  $query = '
     158UPDATE ' . PLUGINS_TABLE . ' SET state="inactive" WHERE id="' . $plugin_id . '"';
     159  pwg_query($query);
     160
     161  $file_to_include = PHPWG_PLUGINS_PATH . $plugin_id . '/maintain.inc.php';
     162  if (file_exists($file_to_include))
     163  {
     164    include_once($file_to_include);
     165    if (function_exists('plugin_deactivate'))
     166    {
     167      plugin_deactivate($plugin_id);
     168    }
     169  }
     170  return true;
     171}
     172
     173
     174/**
    88175 * Retrieves an url for a plugin page.
    89176 * @param string file - php script full name
     
    288375  return strcmp(strtolower($a['ext_name']), strtolower($b['ext_name']));
    289376}
     377
    290378function extension_author_compare($a, $b)
    291379{
     
    295383}
    296384
     385function plugin_author_compare($a, $b)
     386{
     387  return strcasecmp( $a['author'], $b['author']);
     388}
     389
     390function plugin_version_compare($a, $b)
     391{
     392  return version_compare( $a['version'], $b['version']);
     393}
     394
    297395?>
  • trunk/admin/plugins.php

    r2253 r2255  
    3232check_status(ACCESS_ADMINISTRATOR);
    3333
    34 $my_base_url = PHPWG_ROOT_PATH.'admin.php?page=plugins';
    35 
    3634
    3735// +-----------------------------------------------------------------------+
     
    4745}
    4846
    49 $tab_link = $my_base_url . '&section=';
     47$tab_link = get_root_url().'admin.php?page=plugins&section=';
    5048
    5149// TabSheet
     
    6058$tabsheet->assign();
    6159
    62 $my_base_url .= '&section=' . $page['section'];
    63 
    64 
    65 // +-----------------------------------------------------------------------+
    66 // |                     perform requested actions                         |
    67 // +-----------------------------------------------------------------------+
    68 if (isset($_GET['action']) and isset($_GET['plugin']) and !is_adviser())
    69 {
    70   $plugin_id = $_GET['plugin'];
    71   $crt_db_plugin = get_db_plugins('', $plugin_id);
    72   if (!empty($crt_db_plugin))
    73   {
    74       $crt_db_plugin = $crt_db_plugin[0];
    75   }
    76   else
    77   {
    78     unset($crt_db_plugin);
    79   }
    80 
    81   $errors = array();
    82   $file_to_include = PHPWG_PLUGINS_PATH . $plugin_id . '/maintain.inc.php';
    83 
    84   switch ($_GET['action'])
    85   {
    86     case 'install':
    87       if (!empty($crt_db_plugin))
    88       {
    89         array_push($errors, 'CANNOT install - ALREADY INSTALLED');
    90         break;
    91       }
    92       $fs_plugins = get_fs_plugins();
    93       if (!isset($fs_plugins[$plugin_id]))
    94       {
    95         array_push($errors, 'CANNOT install - NO SUCH PLUGIN');
    96         break;
    97       }
    98       if (file_exists($file_to_include))
    99       {
    100         include_once($file_to_include);
    101         if (function_exists('plugin_install'))
    102         {
    103           plugin_install($plugin_id, $fs_plugins[$plugin_id]['version'], $errors);
    104         }
    105       }
    106       if (empty($errors))
    107       {
    108         $query = '
    109 INSERT INTO ' . PLUGINS_TABLE . ' (id,version) VALUES ("'
    110 . $plugin_id . '","' . $fs_plugins[$plugin_id]['version'] . '"
    111 )';
    112         pwg_query($query);
    113       }
    114       break;
    115 
    116     case 'activate':
    117       if (!isset($crt_db_plugin))
    118       {
    119         array_push($errors, 'CANNOT ' . $_GET['action'] . ' - NOT INSTALLED');
    120         break;
    121       }
    122       if ($crt_db_plugin['state'] != 'inactive')
    123       {
    124         array_push($errors, 'invalid current state ' . $crt_db_plugin['state']);
    125         break;
    126       }
    127       if (file_exists($file_to_include))
    128       {
    129         include_once($file_to_include);
    130         if (function_exists('plugin_activate'))
    131         {
    132           plugin_activate($plugin_id, $crt_db_plugin['version'], $errors);
    133         }
    134       }
    135       if (empty($errors))
    136       {
    137         $query = '
    138 UPDATE ' . PLUGINS_TABLE . ' SET state="active" WHERE id="' . $plugin_id . '"';
    139         pwg_query($query);
    140       }
    141       break;
    142 
    143     case 'deactivate':
    144       if (!isset($crt_db_plugin))
    145       {
    146         die ('CANNOT ' . $_GET['action'] . ' - NOT INSTALLED');
    147       }
    148       if ($crt_db_plugin['state'] != 'active')
    149       {
    150         die('invalid current state ' . $crt_db_plugin['state']);
    151       }
    152       $query = '
    153 UPDATE ' . PLUGINS_TABLE . ' SET state="inactive" WHERE id="' . $plugin_id . '"';
    154       pwg_query($query);
    155       if (file_exists($file_to_include))
    156       {
    157         include_once($file_to_include);
    158         if (function_exists('plugin_deactivate'))
    159         {
    160           plugin_deactivate($plugin_id);
    161         }
    162       }
    163       break;
    164 
    165     case 'uninstall':
    166       if (!isset($crt_db_plugin))
    167       {
    168         die ('CANNOT ' . $_GET['action'] . ' - NOT INSTALLED');
    169       }
    170       $query = '
    171 DELETE FROM ' . PLUGINS_TABLE . ' WHERE id="' . $plugin_id . '"';
    172       pwg_query($query);
    173       if (file_exists($file_to_include))
    174       {
    175         include_once($file_to_include);
    176         if (function_exists('plugin_uninstall'))
    177         {
    178           plugin_uninstall($plugin_id);
    179         }
    180       }
    181         break;
    182      
    183     case 'delete':
    184       if (!empty($crt_db_plugin))
    185       {
    186         array_push($errors, 'CANNOT delete - PLUGIN IS INSTALLED');
    187       }
    188       elseif (!deltree(PHPWG_PLUGINS_PATH . $plugin_id))
    189       {
    190         send_to_trash(PHPWG_PLUGINS_PATH . $plugin_id);
    191       }
    192       break;
    193   }
    194   if (empty($errors))
    195   {
    196     $my_base_url .= isset($_GET['upgrade']) ?
    197       '&plugin='.$plugin_id.'&upgrade='.$_GET['upgrade'].'&reactivate=true':'';
    198 
    199     $my_base_url .= isset($_GET['upgradestatus']) ?
    200       '&plugin='.$plugin_id.'&upgradestatus='.$_GET['upgradestatus']:'';
    201 
    202     redirect($my_base_url);
    203     }
    204   else
    205   {
    206     $page['errors'] = array_merge($page['errors'], $errors);
    207   }
    208 }
    209 
    21060
    21161// +-----------------------------------------------------------------------+
    21262// |                     start template output                             |
    21363// +-----------------------------------------------------------------------+
    214 $fs_plugins = get_fs_plugins();
    215 uasort($fs_plugins, 'name_compare');
    216 $db_plugins = get_db_plugins();
    217 $db_plugins_by_id = array();
    218 foreach ($db_plugins as $db_plugin) {
    219     $db_plugins_by_id[$db_plugin['id']] = $db_plugin;
    220 }
    22164
    22265include(PHPWG_ROOT_PATH.'admin/plugins_'.$page['section'].'.php');
    223 
    224 $template->assign_var_from_handle('ADMIN_CONTENT', 'plugins');
    225 
    22666?>
  • trunk/admin/plugins_list.php

    r2243 r2255  
    2929}
    3030
     31
     32// +-----------------------------------------------------------------------+
     33// |                     perform requested actions                         |
     34// +-----------------------------------------------------------------------+
     35if (isset($_GET['action']) and isset($_GET['plugin']) and !is_adviser())
     36{
     37  $plugin_id = $_GET['plugin'];
     38  $crt_db_plugin = get_db_plugins('', $plugin_id);
     39  if (!empty($crt_db_plugin))
     40  {
     41      $crt_db_plugin = $crt_db_plugin[0];
     42  }
     43  else
     44  {
     45    unset($crt_db_plugin);
     46  }
     47
     48  $errors = array();
     49  $file_to_include = PHPWG_PLUGINS_PATH . $plugin_id . '/maintain.inc.php';
     50
     51  switch ($_GET['action'])
     52  {
     53    case 'install':
     54      if (!empty($crt_db_plugin))
     55      {
     56        array_push($errors, 'CANNOT install - ALREADY INSTALLED');
     57        break;
     58      }
     59      $fs_plugins = get_fs_plugins();
     60      if (!isset($fs_plugins[$plugin_id]))
     61      {
     62        array_push($errors, 'CANNOT install - NO SUCH PLUGIN');
     63        break;
     64      }
     65      if (file_exists($file_to_include))
     66      {
     67        include_once($file_to_include);
     68        if (function_exists('plugin_install'))
     69        {
     70          plugin_install($plugin_id, $fs_plugins[$plugin_id]['version'], $errors);
     71        }
     72      }
     73      if (empty($errors))
     74      {
     75        $query = '
     76INSERT INTO ' . PLUGINS_TABLE . ' (id,version) VALUES ("'
     77. $plugin_id . '","' . $fs_plugins[$plugin_id]['version'] . '"
     78)';
     79        pwg_query($query);
     80      }
     81      break;
     82
     83    case 'activate':
     84      activate_plugin($plugin_id, $errors);
     85      break;
     86    case 'deactivate':
     87      deactivate_plugin($plugin_id, $errors);
     88      break;
     89
     90    case 'uninstall':
     91      if (!isset($crt_db_plugin))
     92      {
     93        die ('CANNOT ' . $_GET['action'] . ' - NOT INSTALLED');
     94      }
     95      $query = '
     96DELETE FROM ' . PLUGINS_TABLE . ' WHERE id="' . $plugin_id . '"';
     97      pwg_query($query);
     98      if (file_exists($file_to_include))
     99      {
     100        include_once($file_to_include);
     101        if (function_exists('plugin_uninstall'))
     102        {
     103          plugin_uninstall($plugin_id);
     104        }
     105      }
     106        break;
     107
     108    case 'delete':
     109      if (!empty($crt_db_plugin))
     110      {
     111        array_push($errors, 'CANNOT delete - PLUGIN IS INSTALLED');
     112      }
     113      elseif (!deltree(PHPWG_PLUGINS_PATH . $plugin_id))
     114      {
     115        send_to_trash(PHPWG_PLUGINS_PATH . $plugin_id);
     116      }
     117      break;
     118  }
     119  if (empty($errors))
     120  {
     121    redirect(
     122        get_root_url()
     123        .'admin.php'
     124        .get_query_string_diff( array('action', 'plugin') )
     125      );
     126  }
     127  else
     128  {
     129     $page['errors'] = array_merge($page['errors'], $errors);
     130  }
     131}
     132
     133
     134$fs_plugins = get_fs_plugins();
     135$db_plugins = get_db_plugins();
     136$db_plugins_by_id = array();
     137foreach ($db_plugins as $db_plugin)
     138{
     139  $db_plugins_by_id[$db_plugin['id']] = $db_plugin;
     140}
     141
     142
     143// +-----------------------------------------------------------------------+
     144// |                     start template output                             |
     145// +-----------------------------------------------------------------------+
     146
    31147$template->set_filenames(array('plugins' => 'admin/plugins_list.tpl'));
    32148
     149$base_url = get_root_url().'admin.php';
     150
    33151//----------------------------------------------------------------sort options
    34 $order = isset($_GET['order']) ? $_GET['order'] : 'name';
    35 
    36 $template->assign('order',
    37     array(htmlentities($my_base_url.'&order=name') => l10n('Name'),
    38           htmlentities($my_base_url.'&order=status') => l10n('Status')
     152$selected_order = isset($_GET['order']) ? $_GET['order'] : 'name';
     153
     154$url = $base_url.get_query_string_diff( array('action', 'plugin', 'order'));
     155
     156$template->assign('order',
     157    array(
     158      $url.'&order=name' => l10n('Name'),
     159      $url.'&order=status' => l10n('Status'),
     160      $url.'&order=author' => l10n('Author'),
     161      $url.'&order=id' => l10n('Id'),
    39162    )
    40163  );
    41          
    42 $template->assign('selected', htmlentities($my_base_url.'&order=').$order);
    43 
    44 
    45 // +-----------------------------------------------------------------------+
    46 // |                     start template output                             |
    47 // +-----------------------------------------------------------------------+
    48 
    49 if ($order == 'status')
    50 {
    51   $fs_plugins = sort_plugins_by_state($fs_plugins, $db_plugins_by_id);
    52 }
     164
     165$template->assign('selected', $url.'&order='.$selected_order);
     166
     167switch ($selected_order)
     168{
     169  case 'name':
     170    uasort($fs_plugins, 'name_compare');
     171    break;
     172  case 'id':
     173    uksort($fs_plugins, 'strcasecmp');
     174    break;
     175  case 'author':
     176    uasort($fs_plugins, 'plugin_author_compare');
     177    break;
     178  case 'status':
     179    $fs_plugins = sort_plugins_by_state($fs_plugins, $db_plugins_by_id);
     180    break;
     181}
     182
     183
     184//--------------------------------------------------------------display plugins
     185
     186$url = $base_url.get_query_string_diff( array('action', 'plugin') );
    53187
    54188foreach($fs_plugins as $plugin_id => $fs_plugin)
     
    81215          'DESCRIPTION' => $desc);
    82216
    83   $action_url = htmlentities($my_base_url) . '&plugin=' . $plugin_id;
     217  $action_url = $url.'&plugin='.$plugin_id;
    84218
    85219  if (isset($db_plugins_by_id[$plugin_id]))
    86   { 
     220  {
    87221    switch ($db_plugins_by_id[$plugin_id]['state'])
    88222    {
    89223      case 'active':
    90         $tpl_plugin['actions'][] = 
     224        $tpl_plugin['actions'][] =
    91225            array('U_ACTION' => $action_url . '&action=deactivate',
    92226                  'L_ACTION' => l10n('Deactivate'));
     
    94228
    95229      case 'inactive':
    96         $tpl_plugin['actions'][] = 
     230        $tpl_plugin['actions'][] =
    97231            array('U_ACTION' => $action_url . '&action=activate',
    98232                  'L_ACTION' => l10n('Activate'));
    99         $tpl_plugin['actions'][] = 
     233        $tpl_plugin['actions'][] =
    100234            array('U_ACTION' => $action_url . '&action=uninstall',
    101235                  'L_ACTION' => l10n('Uninstall'),
     
    106240  else
    107241  {
    108     $tpl_plugin['actions'][] = 
     242    $tpl_plugin['actions'][] =
    109243        array('U_ACTION' => $action_url . '&action=install',
    110244              'L_ACTION' => l10n('Install'),
    111245              'CONFIRM' => l10n('Are you sure?'));
    112     $tpl_plugin['actions'][] = 
     246    $tpl_plugin['actions'][] =
    113247        array('U_ACTION' => $action_url . '&action=delete',
    114248                'L_ACTION' => l10n('plugins_delete'),
     
    124258foreach($missing_plugin_ids as $plugin_id)
    125259{
    126   $action_url = $my_base_url.'&plugin='.$plugin_id;
     260  $action_url = $url.'&plugin='.$plugin_id;
    127261
    128262  $template->append( 'plugins',
     
    139273}
    140274
     275$template->assign_var_from_handle('ADMIN_CONTENT', 'plugins');
    141276?>
  • trunk/admin/plugins_new.php

    r2245 r2255  
    22// +-----------------------------------------------------------------------+
    33// | PhpWebGallery - a PHP based picture gallery                           |
    4 // | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
     4// | Copyright (C) 2003-2008 PhpWebGallery Team - http://phpwebgallery.net |
    55// +-----------------------------------------------------------------------+
    66// | file          : $Id$
     
    2828  die ("Hacking attempt!");
    2929}
     30
     31
     32$fs_plugins = get_fs_plugins();
     33$my_base_url= get_root_url().'admin.php'.get_query_string_diff( array('install', 'extension', 'installstatus', 'order') );
     34
    3035
    3136$template->set_filenames(array('plugins' => 'admin/plugins_new.tpl'));
     
    7681
    7782$template->assign('order',
    78     array(htmlentities($my_base_url.'&order=date') => l10n('Post date'),
    79           htmlentities($my_base_url.'&order=name') => l10n('Name'),
    80           htmlentities($my_base_url.'&order=author') => l10n('Author')));
     83    array($my_base_url.'&order=date' => l10n('Post date'),
     84          $my_base_url.'&order=name' => l10n('Name'),
     85          $my_base_url.'&order=author' => l10n('Author')));
    8186
    82 $template->assign('selected', htmlentities($my_base_url.'&order=').$order);
     87$template->assign('selected', $my_base_url.'&order='.$order);
    8388
    8489
     
    103108              utf8_encode($plugin['description'])))));
    104109
    105     $url_auto_install = htmlentities($my_base_url)
     110    $url_auto_install = $my_base_url
    106111        . '&extension=' . $plugin['id_extension']
    107112        . '&install=%2Fupload%2Fextension-' . $plugin['id_extension']
     
    130135}
    131136
     137$template->assign_var_from_handle('ADMIN_CONTENT', 'plugins');
    132138?>
  • trunk/admin/plugins_update.php

    r2245 r2255  
    22// +-----------------------------------------------------------------------+
    33// | PhpWebGallery - a PHP based picture gallery                           |
    4 // | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
     4// | Copyright (C) 2003-2008 PhpWebGallery Team - http://phpwebgallery.net |
    55// +-----------------------------------------------------------------------+
    66// | file          : $Id$
     
    2727{
    2828  die ("Hacking attempt!");
     29}
     30
     31$fs_plugins = get_fs_plugins();
     32$my_base_url= get_root_url().'admin.php'.get_query_string_diff( array('upgrade', 'plugin', 'reactivate', 'action', 'upgradestatus') );
     33
     34$db_plugins = get_db_plugins();
     35$db_plugins_by_id = array();
     36foreach ($db_plugins as $db_plugin)
     37{
     38  $db_plugins_by_id[$db_plugin['id']] = $db_plugin;
    2939}
    3040
     
    114124      {
    115125        // Plugin need upgrade
    116         $url_auto_update = htmlentities($my_base_url)
     126        $url_auto_update = $my_base_url
    117127          . '&plugin=' . $plugin_id
    118128          . (
     
    155165}
    156166
     167$template->assign_var_from_handle('ADMIN_CONTENT', 'plugins');
    157168?>
Note: See TracChangeset for help on using the changeset viewer.