Changeset 2263


Ignore:
Timestamp:
Mar 7, 2008, 11:42:51 AM (16 years ago)
Author:
patdenice
Message:

Use class for plugins management

Location:
trunk
Files:
1 added
1 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin.php

    r2239 r2263  
    115115    array(
    116116      'NAME' => l10n('admin'),
    117       'URL' => $link_start.'plugins'
     117      'URL' => $link_start.'plugins_list'
    118118    )
    119119  );
  • trunk/admin/include/functions_plugins.inc.php

    r2255 r2263  
    2525// +-----------------------------------------------------------------------+
    2626
    27 /* Returns an array of plugins defined in the plugin directory
    28 */
    29 function get_fs_plugins()
    30 {
    31   $plugins = array();
    32 
    33   $dir = opendir(PHPWG_PLUGINS_PATH);
    34   while ($file = readdir($dir))
    35   {
    36     if ($file!='.' and $file!='..')
    37     {
    38       $path = PHPWG_PLUGINS_PATH.$file;
    39       if (is_dir($path) and !is_link($path)
    40           and preg_match('/^[a-zA-Z0-9-_]+$/', $file )
    41           and file_exists($path.'/main.inc.php')
    42           )
    43       {
    44         $plugin = array(
    45             'name'=>$file,
    46             'version'=>'0',
    47             'uri'=>'',
    48             'description'=>'',
    49             'author'=>'',
    50           );
    51         $plg_data = implode( '', file($path.'/main.inc.php') );
    52 
    53         if ( preg_match("|Plugin Name: (.*)|", $plg_data, $val) )
    54         {
    55           $plugin['name'] = trim( $val[1] );
    56         }
    57         if (preg_match("|Version: (.*)|", $plg_data, $val))
    58         {
    59           $plugin['version'] = trim($val[1]);
    60         }
    61         if ( preg_match("|Plugin URI: (.*)|", $plg_data, $val) )
    62         {
    63           $plugin['uri'] = trim($val[1]);
    64         }
    65         if ( preg_match("|Description: (.*)|", $plg_data, $val) )
    66         {
    67           $plugin['description'] = trim($val[1]);
    68         }
    69         if ( preg_match("|Author: (.*)|", $plg_data, $val) )
    70         {
    71           $plugin['author'] = trim($val[1]);
    72         }
    73         if ( preg_match("|Author URI: (.*)|", $plg_data, $val) )
    74         {
    75           $plugin['author uri'] = trim($val[1]);
    76         }
    77         // IMPORTANT SECURITY !
    78         $plugin = array_map('htmlspecialchars', $plugin);
    79         $plugins[$file] = $plugin;
    80       }
    81     }
    82   }
    83   closedir($dir);
    84   return $plugins;
    85 }
    86 
    87 /**
    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  */
    92 function 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 = '
    124 UPDATE ' . 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  */
    137 function 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 = '
    158 UPDATE ' . 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 
    17427/**
    17528 * Retrieves an url for a plugin page.
     
    19447  return $url;
    19548}
    196 
    197 /**
    198  * Sort plugins by status
    199  */
    200 function sort_plugins_by_state($plugins, $db_plugins_by_id)
    201 {
    202   $active_plugins = array();
    203   $inactive_plugins = array();
    204   $not_installed = array();
    205 
    206   foreach($plugins as $plugin_id => $plugin)
    207   {
    208     if (isset($db_plugins_by_id[$plugin_id]))
    209     {
    210       $db_plugins_by_id[$plugin_id]['state'] == 'active' ?
    211         $active_plugins[$plugin_id] = $plugin : $inactive_plugins[$plugin_id] = $plugin;
    212     }
    213     else
    214     {
    215       $not_installed[$plugin_id] = $plugin;
    216     }
    217   }
    218   return $active_plugins + $inactive_plugins + $not_installed;
    219 }
    220 
    221 
    222 /**
    223  * Retrieve PEM server datas
    224  * @param bool (true for retrieve new extensions)
    225  */
    226 function check_server_plugins(& $fs_plugins, $newext=false)
    227 {
    228   foreach($fs_plugins as $plugin_id => $fs_plugin)
    229   {
    230     if (!empty($fs_plugin['uri']) and strpos($fs_plugin['uri'] , 'extension_view.php?eid='))
    231     {
    232       list( , $extension) = explode('extension_view.php?eid=', $fs_plugin['uri']);
    233       if (!is_numeric($extension)) continue;
    234       $plugins_to_check[] = $extension;
    235       $fs_plugins[$plugin_id]['extension'] = $extension;
    236     }
    237   }
    238 
    239   $url = PEM_URL . '/uptodate.php?version=' . rawurlencode(PHPWG_VERSION) . '&extensions=' . implode(',', $plugins_to_check);
    240   $url .= $newext ? '&newext=Plugin' : '';
    241 
    242   if (!empty($plugins_to_check) and $source = @file_get_contents($url))
    243   {
    244     return @unserialize($source);
    245   }
    246   return false;
    247 }
    248 
    249 
    250 /**
    251  * Extract plugin files from archive
    252  * @param string - install or upgrade
    253  *  @param string - archive URL
    254   * @param string - destination path
    255  */
    256 function extract_plugin_files($action, $source, $dest)
    257 {
    258   if ($archive = tempnam( PHPWG_PLUGINS_PATH, 'zip'))
    259   {
    260     if (@copy(PEM_URL . str_replace(' ', '%20', $source), $archive))
    261     {
    262       $zip = new PclZip($archive);
    263       if ($list = $zip->listContent())
    264       {
    265         foreach ($list as $file)
    266         {
    267           // we search main.inc.php in archive
    268           if (basename($file['filename']) == 'main.inc.php'
    269             and (!isset($main_filepath)
    270             or strlen($file['filename']) < strlen($main_filepath)))
    271           {
    272             $main_filepath = $file['filename'];
    273           }
    274         }
    275         if (isset($main_filepath))
    276         {
    277           $root = dirname($main_filepath); // main.inc.php path in archive
    278           if ($action == 'upgrade')
    279           {
    280             $extract_path = PHPWG_PLUGINS_PATH.$dest;
    281           }
    282           else
    283           {
    284             $extract_path = PHPWG_PLUGINS_PATH
    285                 . ($root == '.' ? 'extension_' . $dest : basename($root));
    286           }
    287           if($result = $zip->extract(PCLZIP_OPT_PATH, $extract_path,
    288                                      PCLZIP_OPT_REMOVE_PATH, $root,
    289                                      PCLZIP_OPT_REPLACE_NEWER))
    290           {
    291             foreach ($result as $file)
    292             {
    293               if ($file['stored_filename'] == $main_filepath)
    294               {
    295                 $status = $file['status'];
    296                 break;
    297               }
    298             }
    299           }
    300           else $status = 'extract_error';
    301         }
    302         else $status = 'archive_error';
    303       }
    304       else $status = 'archive_error';
    305     }
    306     else $status = 'dl_archive_error';
    307   }
    308   else $status = 'temp_path_error';
    309 
    310   @unlink($archive);
    311   return $status;
    312 }
    313 
    314 
    315 /**
    316  * delete $path directory
    317  * @param string - path
    318  */
    319 function deltree($path)
    320 {
    321   if (is_dir($path))
    322   {
    323     $fh = opendir($path);
    324     while ($file = readdir($fh))
    325     {
    326       if ($file != '.' and $file != '..')
    327       {
    328         $pathfile = $path . '/' . $file;
    329         if (is_dir($pathfile))
    330         {
    331           deltree($pathfile);
    332         }
    333         else
    334         {
    335           @unlink($pathfile);
    336         }
    337       }
    338     }
    339     closedir($fh);
    340     return @rmdir($path);
    341   }
    342 }
    343 
    344 
    345 /**
    346  * send $path to trash directory
    347   * @param string - path
    348  */
    349 function send_to_trash($path)
    350 {
    351   $trash_path = PHPWG_PLUGINS_PATH . 'trash';
    352   if (!is_dir($trash_path))
    353   {
    354     @mkdir($trash_path);
    355     $file = @fopen($trash_path . '/.htaccess', 'w');
    356     @fwrite($file, 'deny from all');
    357     @fclose($file);
    358   }
    359   while ($r = $trash_path . '/' . md5(uniqid(rand(), true)))
    360   {
    361     if (!is_dir($r))
    362     {
    363       @rename($path, $r);
    364       break;
    365     }
    366   }
    367 }
    368 
    369 
    370 /**
    371  * Sort functions
    372  */
    373 function extension_name_compare($a, $b)
    374 {
    375   return strcmp(strtolower($a['ext_name']), strtolower($b['ext_name']));
    376 }
    377 
    378 function extension_author_compare($a, $b)
    379 {
    380   $r = strcmp(strtolower($a['author']), strtolower($b['author']));
    381   if ($r == 0) return extension_name_compare($a, $b);
    382   else return $r;
    383 }
    384 
    385 function plugin_author_compare($a, $b)
    386 {
    387   return strcasecmp( $a['author'], $b['author']);
    388 }
    389 
    390 function plugin_version_compare($a, $b)
    391 {
    392   return version_compare( $a['version'], $b['version']);
    393 }
    394 
    39549?>
  • trunk/admin/plugins_list.php

    r2256 r2263  
    22// +-----------------------------------------------------------------------+
    33// | PhpWebGallery - a PHP based picture gallery                           |
    4 // | Copyright (C) 2003-2008 PhpWebGallery Team - http://phpwebgallery.net |
     4// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
    55// +-----------------------------------------------------------------------+
    66// | file          : $Id$
     
    2929}
    3030
     31include_once(PHPWG_ROOT_PATH.'admin/include/plugins.class.php');
    3132
    32 // +-----------------------------------------------------------------------+
    33 // |                     perform requested actions                         |
    34 // +-----------------------------------------------------------------------+
     33$template->set_filenames(array('plugins' => 'admin/plugins_list.tpl'));
     34
     35$order = isset($_GET['order']) ? $_GET['order'] : 'name';
     36$plugins = new plugins($page['page'], $order);
     37
     38//--------------------------------------------------perform requested actions
    3539if (isset($_GET['action']) and isset($_GET['plugin']) and !is_adviser())
    3640{
    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 = '
    76 INSERT 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 = '
    96 DELETE 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   }
     41  $page['errors'] =
     42    $plugins->perform_action($_GET['action'], $_GET['plugin'], $page['errors']);
     43   
     44  if (empty($page['errors'])) redirect($plugins->my_base_url);
    13145}
    132 
    133 
    134 $fs_plugins = get_fs_plugins();
    135 $db_plugins = get_db_plugins();
    136 $db_plugins_by_id = array();
    137 foreach ($db_plugins as $db_plugin)
    138 {
    139   $db_plugins_by_id[$db_plugin['id']] = $db_plugin;
    140 }
    141 
    14246
    14347// +-----------------------------------------------------------------------+
    14448// |                     start template output                             |
    14549// +-----------------------------------------------------------------------+
    146 
    147 $template->set_filenames(array('plugins' => 'admin/plugins_list.tpl'));
    148 
    149 $base_url = get_root_url().'admin.php';
    150 
    151 //----------------------------------------------------------------sort options
    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.'&amp;order=name' => l10n('Name'),
    159       $url.'&amp;order=status' => l10n('Status'),
    160       $url.'&amp;order=author' => l10n('Author'),
    161       $url.'&amp;order=id' => 'Id',
    162     )
    163   );
    164 
    165 $template->assign('selected', $url.'&amp;order='.$selected_order);
    166 
    167 switch ($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') );
    187 
    188 foreach($fs_plugins as $plugin_id => $fs_plugin)
     50$plugins->tabsheet();
     51$plugins->sort_fs_plugins();
     52$plugins->set_order_options(array(
     53    'name' => l10n('Name'),
     54    'status' => l10n('Status'),
     55    'author' => l10n('Author'),
     56    'id' => 'Id'));
     57 
     58foreach($plugins->fs_plugins as $plugin_id => $fs_plugin)
    18959{
    19060  $display_name = $fs_plugin['name'];
     
    21585          'DESCRIPTION' => $desc);
    21686
    217   $action_url = $url.'&amp;plugin='.$plugin_id;
     87  $action_url = $plugins->html_base_url . '&amp;plugin=' . $plugin_id;
    21888
    219   if (isset($db_plugins_by_id[$plugin_id]))
    220   {
    221     switch ($db_plugins_by_id[$plugin_id]['state'])
     89  if (isset($plugins->db_plugins_by_id[$plugin_id]))
     90  { 
     91    switch ($plugins->db_plugins_by_id[$plugin_id]['state'])
    22292    {
    22393      case 'active':
     
    246116    $tpl_plugin['actions'][] =
    247117        array('U_ACTION' => $action_url . '&amp;action=delete',
    248                 'L_ACTION' => l10n('plugins_delete'),
    249                 'CONFIRM' => l10n('plugins_confirm_delete'));
     118              'L_ACTION' => l10n('plugins_delete'),
     119              'CONFIRM' => l10n('plugins_confirm_delete'));
    250120  }
    251121  $template->append('plugins', $tpl_plugin);
     
    253123
    254124$missing_plugin_ids = array_diff(
    255     array_keys($db_plugins_by_id), array_keys($fs_plugins)
     125    array_keys($plugins->db_plugins_by_id), array_keys($plugins->fs_plugins)
    256126    );
    257127
    258128foreach($missing_plugin_ids as $plugin_id)
    259129{
    260   $action_url = $url.'&amp;plugin='.$plugin_id;
     130  $action_url = $plugins->html_base_url.'&amp;plugin='.$plugin_id;
    261131
    262132  $template->append( 'plugins',
    263133      array(
    264134        'NAME' => $plugin_id,
    265         'VERSION' => $db_plugins_by_id[$plugin_id]['version'],
     135        'VERSION' => $plugins->db_plugins_by_id[$plugin_id]['version'],
    266136        'DESCRIPTION' => "ERROR: THIS PLUGIN IS MISSING BUT IT IS INSTALLED! UNINSTALL IT NOW !",
    267137        'actions' => array ( array (
  • trunk/admin/plugins_new.php

    r2255 r2263  
    22// +-----------------------------------------------------------------------+
    33// | PhpWebGallery - a PHP based picture gallery                           |
    4 // | Copyright (C) 2003-2008 PhpWebGallery Team - http://phpwebgallery.net |
     4// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
    55// +-----------------------------------------------------------------------+
    66// | file          : $Id$
     
    2929}
    3030
    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 
     31include_once(PHPWG_ROOT_PATH.'admin/include/plugins.class.php');
    3532
    3633$template->set_filenames(array('plugins' => 'admin/plugins_new.tpl'));
    3734
     35$order = isset($_GET['order']) ? $_GET['order'] : 'date';
     36
     37$plugins = new plugins($page['page'], $order);
    3838
    3939//------------------------------------------------------automatic installation
    4040if (isset($_GET['install']) and isset($_GET['extension']) and !is_adviser())
    4141{
    42   include(PHPWG_ROOT_PATH.'admin/include/pclzip.lib.php');
    43 
    44   $install_status  = extract_plugin_files('install',
    45                       $_GET['install'],
    46                       $_GET['extension']);
    47 
    48   redirect($my_base_url . '&installstatus=' . $install_status);
     42  $plugins->install($_GET['install'], $_GET['extension']);
    4943}
    50 
    5144
    5245//--------------------------------------------------------------install result
    5346if (isset($_GET['installstatus']))
    5447{
    55   switch ($_GET['installstatus'])
    56   {
    57   case 'ok':
    58     array_push($page['infos'], l10n('plugins_install_ok'), l10n('plugins_install_need_activate'));
    59     break;
    60 
    61   case 'temp_path_error':
    62     array_push($page['errors'], l10n('plugins_temp_path_error'));
    63     break;
    64 
    65   case 'dl_archive_error':
    66     array_push($page['errors'], l10n('plugins_dl_archive_error'));
    67     break;
    68 
    69   case 'archive_error':
    70     array_push($page['errors'], l10n('plugins_archive_error'));
    71     break;
    72 
    73   default:
    74     array_push($page['errors'], sprintf(l10n('plugins_extract_error'), $_GET['installstatus']), l10n('plugins_check_chmod'));
    75   }
     48  $plugins->get_result($_GET['installstatus']);
    7649}
    77 
    78 
    79 //----------------------------------------------------------------sort options
    80 $order = isset($_GET['order']) ? $_GET['order'] : 'date';
    81 
    82 $template->assign('order',
    83     array($my_base_url.'&amp;order=date' => l10n('Post date'),
    84           $my_base_url.'&amp;order=name' => l10n('Name'),
    85           $my_base_url.'&amp;order=author' => l10n('Author')));
    86 
    87 $template->assign('selected', $my_base_url.'&amp;order='.$order);
    88 
    8950
    9051// +-----------------------------------------------------------------------+
    9152// |                     start template output                             |
    9253// +-----------------------------------------------------------------------+
    93 $plugins_infos = check_server_plugins($fs_plugins, true);
    94 if ($plugins_infos !== false)
     54$plugins->tabsheet();
     55$plugins->check_server_plugins();
     56$plugins->set_order_options(array(
     57    'date' => l10n('Post date'),
     58    'name' => l10n('Name'),
     59    'author' => l10n('Author')));
     60
     61if ($plugins->server_plugins !== false)
    9562{
    96   if ($order == 'date') krsort($plugins_infos);
    97   else uasort($plugins_infos, 'extension_'.$order.'_compare');
    98 
    99   foreach($plugins_infos as $plugin)
     63  foreach($plugins->server_plugins as $plugin)
    10064  {
    10165    $ext_desc = nl2br(htmlspecialchars(strip_tags(
     
    10872              utf8_encode($plugin['description'])))));
    10973
    110     $url_auto_install = $my_base_url
    111         . '&amp;extension=' . $plugin['id_extension']
    112         . '&amp;install=%2Fupload%2Fextension-' . $plugin['id_extension']
    113         . '%2Frevision-' . $plugin['id_revision'] . '%2F'
    114         .  str_replace(' ', '%20',$plugin['url']);
     74    $url_auto_install = $plugins->html_base_url
     75      . '&amp;extension=' . $plugin['id_extension']
     76      . '&amp;install=%2Fupload%2Fextension-' . $plugin['id_extension']
     77      . '%2Frevision-' . $plugin['id_revision'] . '%2F'
     78      .  str_replace(' ', '%20',$plugin['url']);
    11579
    11680    $url_download = PEM_URL .'/upload/extension-'.$plugin['id_extension']
    117         . '/revision-' . $plugin['id_revision']
    118         . '/' . $plugin['url'];
     81      . '/revision-' . $plugin['id_revision']
     82      . '/' . str_replace(' ', '%20',$plugin['url']);
    11983
    12084    $template->append('plugins',
  • trunk/admin/plugins_update.php

    r2255 r2263  
    22// +-----------------------------------------------------------------------+
    33// | PhpWebGallery - a PHP based picture gallery                           |
    4 // | Copyright (C) 2003-2008 PhpWebGallery Team - http://phpwebgallery.net |
     4// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
    55// +-----------------------------------------------------------------------+
    66// | file          : $Id$
     
    2929}
    3030
    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();
    36 foreach ($db_plugins as $db_plugin)
    37 {
    38   $db_plugins_by_id[$db_plugin['id']] = $db_plugin;
    39 }
     31include_once(PHPWG_ROOT_PATH.'admin/include/plugins.class.php');
    4032
    4133$template->set_filenames(array('plugins' => 'admin/plugins_update.tpl'));
    4234
     35$plugins = new plugins($page['page']);
    4336
    4437//-----------------------------------------------------------automatic upgrade
    4538if (isset($_GET['upgrade']) and isset($_GET['plugin']) and !is_adviser())
    4639{
    47   include(PHPWG_ROOT_PATH.'admin/include/pclzip.lib.php');
    48 
    49   $upgrade_status  = extract_plugin_files('upgrade',
    50                       $_GET['upgrade'],
    51                       $_GET['plugin']);
    52 
    53   $my_base_url .= isset($_GET['reactivate']) ? '&action=activate' : '';
    54 
    55   redirect($my_base_url.'&plugin='.$_GET['plugin'].'&upgradestatus='.$upgrade_status);
     40  $plugins->upgrade($_GET['upgrade'], $_GET['plugin']);
    5641}
    57 
    5842
    5943//--------------------------------------------------------------upgrade result
    6044if (isset($_GET['upgradestatus']) and isset($_GET['plugin']))
    6145{
    62   switch ($_GET['upgradestatus'])
    63   {
    64   case 'ok':
    65     array_push($page['infos'],
    66                sprintf(l10n('plugins_upgrade_ok'),
    67                $fs_plugins[$_GET['plugin']]['name']));
    68     break;
    69 
    70   case 'temp_path_error':
    71     array_push($page['errors'], l10n('plugins_temp_path_error'));
    72     break;
    73 
    74   case 'dl_archive_error':
    75     array_push($page['errors'], l10n('plugins_dl_archive_error'));
    76     break;
    77 
    78   case 'archive_error':
    79     array_push($page['errors'], l10n('plugins_archive_error'));
    80     break;
    81 
    82   default:
    83     array_push($page['errors'],
    84                sprintf(l10n('plugins_extract_error'),
    85                $_GET['upgradestatus']));
    86   }
     46  $plugins->get_result($_GET['upgradestatus'], $_GET['plugin']);
    8747}
    88 
    8948
    9049// +-----------------------------------------------------------------------+
    9150// |                     start template output                             |
    9251// +-----------------------------------------------------------------------+
    93 $plugins_infos = check_server_plugins($fs_plugins);
     52$plugins->tabsheet();
     53$plugins->check_server_plugins();
    9454
    95 if ($plugins_infos !== false)
     55if ($plugins->server_plugins !== false)
    9656{
    97   foreach($fs_plugins as $plugin_id => $fs_plugin)
     57  foreach($plugins->fs_plugins as $plugin_id => $fs_plugin)
    9858  {
    9959    if (isset($fs_plugin['extension'])
    100       and isset($plugins_infos[$fs_plugin['extension']]))
     60      and isset($plugins->server_plugins[$fs_plugin['extension']]))
    10161    {
    102       $plugin_info = $plugins_infos[$fs_plugin['extension']];
     62      $plugin_info = $plugins->server_plugins[$fs_plugin['extension']];
    10363
    10464      $ext_desc = nl2br(htmlspecialchars(strip_tags(
     
    10666
    10767      $ver_desc = sprintf(l10n('plugins_description'),
    108               $plugin_info['version'],
    109               date('Y-m-d', $plugin_info['date']),
    110               nl2br(htmlspecialchars(strip_tags(
    111                 utf8_encode($plugin_info['description'])))));
     68          $plugin_info['version'],
     69          date('Y-m-d', $plugin_info['date']),
     70          nl2br(htmlspecialchars(strip_tags(
     71              utf8_encode($plugin_info['description'])))));
    11272
    113       if ($plugin_info['version'] == $fs_plugin['version'])
     73      if ($plugins->plugin_version_compare($fs_plugin, $plugin_info) >= 0)
    11474      {
    11575        // Plugin is up to date
     
    11878                'NAME' => $fs_plugin['name'],
    11979                'EXT_DESC' => $ext_desc,
    120                 'VERSION' => $fs_plugin['version'],
    121                 'VER_DESC' => $ver_desc));
     80                'VERSION' => $fs_plugin['version']));
    12281      }
    12382      else
    12483      {
    12584        // Plugin need upgrade
    126         $url_auto_update = $my_base_url
     85        $url_auto_update = $plugins->html_base_url
    12786          . '&amp;plugin=' . $plugin_id
    128           . (
    129               (isset($db_plugins_by_id[$plugin_id])
    130                 and $db_plugins_by_id[$plugin_id]['state'] == 'active') ?
    131                   '&amp;action=deactivate' : ''
    132             )
    13387          . '&amp;upgrade=%2Fupload%2Fextension-' . $fs_plugin['extension']
    13488          . '%2Frevision-' . $plugin_info['id_revision']
    135           . '%2F' . $plugin_info['url'];
     89          . '%2F' . str_replace(' ', '%20',$plugin_info['url']);
    13690
    13791        $url_download = PEM_URL.'/upload/extension-'. $fs_plugin['extension']
    138             . '/revision-' . $plugin_info['id_revision']
    139             . '/' . $plugin_info['url'];
     92          . '/revision-' . $plugin_info['id_revision']
     93          . '/' . str_replace(' ', '%20',$plugin_info['url']);
    14094
    14195        $template->append('plugins_not_uptodate',
  • trunk/template/yoga/admin/plugins_list.tpl

    r2243 r2263  
    66{'Sort order'|@translate} :
    77  <select onchange="document.location = this.options[this.selectedIndex].value;" style="width:100px">
    8         {html_options options=$order selected=$selected}
     8        {html_options options=$order_options selected=$order_selected}
    99  </select>
    1010
  • trunk/template/yoga/admin/plugins_new.tpl

    r2243 r2263  
    66{'Sort order'|@translate} :
    77  <select onchange="document.location = this.options[this.selectedIndex].value;" style="width:120px">
    8         {html_options options=$order selected=$selected}
     8        {html_options options=$order_options selected=$order_selected}
    99  </select>
    1010
  • trunk/template/yoga/admin/plugins_update.tpl

    r2245 r2263  
    4545    <td><a href="{$plugin.URL}" onclick="window.open(this.href); return false;" class="tooltip">{$plugin.NAME}
    4646        <span>{$plugin.EXT_DESC}</span></a></td>
    47     <td style="text-align:center;"><span class="tooltip">{$plugin.VERSION}<span>{$plugin.VER_DESC}</span></span></td>
     47    <td style="text-align:center;">{$plugin.VERSION}</td>
    4848  </tr>
    4949{/foreach}
Note: See TracChangeset for help on using the changeset viewer.