Changeset 2264


Ignore:
Timestamp:
Mar 7, 2008, 6:15:46 PM (16 years ago)
Author:
patdenice
Message:

Corrections in plugins management.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/include/plugins.class.php

    r2263 r2264  
    2727class plugins
    2828{
    29   var $page = '';
    30   var $order = '';
    31   var $my_base_url = '';
    32   var $html_base_url = '';
    3329  var $fs_plugins = array();
    3430  var $db_plugins_by_id = array();
    3531  var $server_plugins = array();
    3632
    37   function plugins($page='', $order='')
    38   {
    39     $this->page = $page;
    40     $this->order = $order;
    41 
    42     $this->my_base_url = get_root_url().'admin.php?page='.$this->page;
    43     if (!empty($this->order))
    44     {
    45       $this->my_base_url .= '&order=' . $this->order;
    46     }
    47     $this->html_base_url = htmlentities($this->my_base_url);
    48 
     33  /**
     34   * Initialize $fs_plugins and $db_plugins_by_id
     35  */
     36  function plugins()
     37  {
    4938    $this->get_fs_plugins();
     39
    5040    foreach (get_db_plugins() as $db_plugin)
    5141    {
     
    5444  }
    5545
    56   /**
    57    * Assign tabsheet
    58    */
    59   function tabsheet()
    60   {
    61     include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
    62     $link = PHPWG_ROOT_PATH.'admin.php?page=';
    63 
    64     $tabsheet = new tabsheet();
    65     $tabsheet->add('plugins_list', l10n('plugins_tab_list'), $link.'plugins_list');
    66     $tabsheet->add('plugins_update', l10n('plugins_tab_update'), $link.'plugins_update');
    67     $tabsheet->add('plugins_new', l10n('plugins_tab_new'), $link.'plugins_new');
    68     $tabsheet->select($this->page);
    69     $tabsheet->assign();
    70   }
    71 
    72   /**
    73    * Set order
    74   *  @param array - order options
    75    */
    76   function set_order_options($options)
    77   {
    78     global $template;
    79 
    80     $link = get_root_url().'admin.php?page='.$this->page.'&order=';
    81     foreach($options as $key => $value)
    82     {
    83       $tpl_options[$link . $key] = $value;
    84     }
    85     $template->assign('order_options', $tpl_options);
    86     $template->assign('order_selected', $link . $this->order);
    87   }
    88  
    8946 /**
    9047   * Perform requested actions
    9148  *  @param string - action
    9249  * @param string - plugin id
    93   * @param string - errors
     50  * @param array - errors
    9451  */
    9552  function perform_action($action, $plugin_id, $errors=array())
     
    220177
    221178  /**
    222   *  Returns an array of plugins defined in the plugin directory
     179  *  Get plugins defined in the plugin directory
    223180  */ 
    224181  function get_fs_plugins()
     
    283240
    284241  /**
    285    * sort fs_plugins
    286    */
    287   function sort_fs_plugins()
    288   {
    289     switch ($this->order)
    290     {
     242   * Sort fs_plugins
     243   */
     244  function sort_fs_plugins($order='name')
     245  {
     246    switch ($order)
     247    {
     248      case 'name':
     249        uasort($this->fs_plugins, 'name_compare');
     250        break;
    291251      case 'status':
    292252        $this->sort_plugins_by_state();
     
    298258        uksort($this->fs_plugins, 'strcasecmp');
    299259        break;
    300       default: //sort by plugin name
    301         uasort($this->fs_plugins, 'name_compare');
    302     }
    303   }
    304 
    305   /**
    306    * Retrieve PEM server datas
    307    */
    308   function check_server_plugins()
    309   {
    310     foreach($this->fs_plugins as $plugin_id => $fs_plugin)
     260    }
     261  }
     262
     263  /**
     264   * Retrieve PEM server datas to $server_plugins
     265   */
     266  function get_server_plugins($new=false)
     267  {
     268    foreach($this->fs_plugins as $fs_plugin)
    311269    {
    312270      if (isset($fs_plugin['extension']))
     
    316274    }
    317275    $url = PEM_URL . '/uptodate.php?version=' . rawurlencode(PHPWG_VERSION) . '&extensions=' . implode(',', $plugins_to_check);
    318     $url .= $this->page == 'plugins_new' ? '&newext=Plugin' : '';
     276    $url .= $new ? '&newext=Plugin' : '';
    319277
    320278    if (!empty($plugins_to_check) and $source = @file_get_contents($url))
    321279    {
    322280      $this->server_plugins = @unserialize($source);
    323       switch ($this->order)
    324       {
    325         case 'name':
    326           uasort($this->server_plugins, array($this, 'extension_name_compare'));
    327           break;
    328         case 'author':
    329           uasort($this->server_plugins, array($this, 'extension_author_compare'));
    330           break;
    331         default: // sort by id desc
    332           krsort($this->server_plugins);
    333       }
    334281    }
    335282    else
     
    338285    }
    339286  }
    340 
    341  /**
    342    * Upgrade plugin
    343   *  @param string - archive URL
    344   * @param string - plugin id
    345   */
    346   function upgrade($source, $plugin_id)
    347   {
    348     if (isset($this->db_plugins_by_id[$plugin_id])
    349       and $this->db_plugins_by_id[$plugin_id]['state'] == 'active')
    350     {
    351       $this->perform_action('deactivate', $plugin_id);
    352 
    353       redirect(
    354         $this->my_base_url
    355         . '&upgrade=' . $source
    356         . '&plugin=' . $plugin_id
    357         . '&reactivate=true');
    358     }
    359 
    360     include(PHPWG_ROOT_PATH.'admin/include/pclzip.lib.php');
    361     $upgrade_status = $this->extract_plugin_files('upgrade', $source, $plugin_id);
    362 
    363     if (isset($_GET['reactivate']))
    364     {
    365       $this->perform_action('activate', $plugin_id);
    366     }
    367     redirect($this->my_base_url.'&plugin='.$plugin_id.'&upgradestatus='.$upgrade_status);
    368   }
    369 
    370 
    371   /**
    372    * Install plugin
    373   *  @param string - archive URL
    374   * @param string - extension id
    375   */
    376   function install($source, $extension)
    377   {
    378     include(PHPWG_ROOT_PATH.'admin/include/pclzip.lib.php');
    379     $install_status = $this->extract_plugin_files('install', $source, $extension);
    380 
    381     redirect($this->my_base_url.'&installstatus='.$install_status);
    382   }
    383 
     287 
     288  /**
     289   * Sort $server_plugins
     290   */
     291  function sort_server_plugins($order='date')
     292  {
     293    switch ($order)
     294    {
     295      case 'date':
     296        krsort($this->server_plugins);
     297        break;
     298      case 'name':
     299        uasort($this->server_plugins, array($this, 'extension_name_compare'));
     300        break;
     301      case 'author':
     302        uasort($this->server_plugins, array($this, 'extension_author_compare'));
     303        break;
     304    }
     305  }
    384306
    385307  /**
     
    395317      if (@copy(PEM_URL . str_replace(' ', '%20', $source), $archive))
    396318      {
     319        include(PHPWG_ROOT_PATH.'admin/include/pclzip.lib.php');
    397320        $zip = new PclZip($archive);
    398321        if ($list = $zip->listContent())
     
    448371 
    449372  /**
    450    * get install or upgrade result
    451    */
    452   function get_result($result, $plugin='')
    453   {
    454     global $page;
    455 
    456     switch ($result)
    457     {
    458       case 'ok':
    459         if ($this->page == 'plugins_update')
    460         {
    461           array_push($page['infos'],
    462              sprintf(
    463                 l10n('plugins_upgrade_ok'),
    464                 $this->fs_plugins[$plugin]['name']));
    465         }
    466         else
    467         {
    468           array_push($page['infos'],
    469             l10n('plugins_install_ok'),
    470             l10n('plugins_install_need_activate'));
    471         }
    472         break;
    473 
    474       case 'temp_path_error':
    475         array_push($page['errors'], l10n('plugins_temp_path_error'));
    476         break;
    477 
    478       case 'dl_archive_error':
    479         array_push($page['errors'], l10n('plugins_dl_archive_error'));
    480         break;
    481 
    482       case 'archive_error':
    483         array_push($page['errors'], l10n('plugins_archive_error'));
    484         break;
    485 
    486       default:
    487         array_push($page['errors'],
    488           sprintf(l10n('plugins_extract_error'), $result),
    489           l10n('plugins_check_chmod'));
    490     } 
    491   }
    492 
    493   /**
    494373   * delete $path directory
    495374   * @param string - path
     
    522401  /**
    523402   * send $path to trash directory
    524     * @param string - path
     403   * @param string - path
    525404   */
    526405  function send_to_trash($path)
  • trunk/admin/plugins_list.php

    r2263 r2264  
    3434
    3535$order = isset($_GET['order']) ? $_GET['order'] : 'name';
    36 $plugins = new plugins($page['page'], $order);
     36$base_url = get_root_url().'admin.php?page='.$page['page'].'&order='.$order;
     37
     38$plugins = new plugins();
    3739
    3840//--------------------------------------------------perform requested actions
     
    4143  $page['errors'] =
    4244    $plugins->perform_action($_GET['action'], $_GET['plugin'], $page['errors']);
    43    
    44   if (empty($page['errors'])) redirect($plugins->my_base_url);
     45
     46  if (empty($page['errors'])) redirect($base_url);
    4547}
     48
     49//--------------------------------------------------------------------Tabsheet
     50include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
     51$link = get_root_url().'admin.php?page=';
     52$tabsheet = new tabsheet();
     53$tabsheet->add('plugins_list', l10n('plugins_tab_list'), $link.'plugins_list');
     54$tabsheet->add('plugins_update', l10n('plugins_tab_update'), $link.'plugins_update');
     55$tabsheet->add('plugins_new', l10n('plugins_tab_new'), $link.'plugins_new');
     56$tabsheet->select($page['page']);
     57$tabsheet->assign();
     58
     59//---------------------------------------------------------------Order options
     60$link .= $page['page'].'&order=';
     61$template->assign('order_options',
     62  array(
     63    $link.'name' => l10n('Name'),
     64    $link.'status' => l10n('Status'),
     65    $link.'author' => l10n('Author'),
     66    $link.'id' => 'Id'));
     67$template->assign('order_selected', $link.$order);
    4668
    4769// +-----------------------------------------------------------------------+
    4870// |                     start template output                             |
    4971// +-----------------------------------------------------------------------+
    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  
     72$plugins->sort_fs_plugins($order);
     73
    5874foreach($plugins->fs_plugins as $plugin_id => $fs_plugin)
    5975{
     
    85101          'DESCRIPTION' => $desc);
    86102
    87   $action_url = $plugins->html_base_url . '&plugin=' . $plugin_id;
     103  $action_url = htmlentities($base_url).'&plugin='.$plugin_id;
    88104
    89105  if (isset($plugins->db_plugins_by_id[$plugin_id]))
     
    128144foreach($missing_plugin_ids as $plugin_id)
    129145{
    130   $action_url = $plugins->html_base_url.'&plugin='.$plugin_id;
     146  $action_url = htmlentities($base_url).'&plugin='.$plugin_id;
    131147
    132148  $template->append( 'plugins',
  • trunk/admin/plugins_new.php

    r2263 r2264  
    3434
    3535$order = isset($_GET['order']) ? $_GET['order'] : 'date';
     36$base_url = get_root_url().'admin.php?page='.$page['page'].'&order='.$order;
    3637
    37 $plugins = new plugins($page['page'], $order);
     38$plugins = new plugins();
    3839
    3940//------------------------------------------------------automatic installation
    4041if (isset($_GET['install']) and isset($_GET['extension']) and !is_adviser())
    4142{
    42   $plugins->install($_GET['install'], $_GET['extension']);
     43  $install_status =
     44    $plugins->extract_plugin_files('install', $_GET['install'], $_GET['extension']);
     45
     46  redirect($base_url.'&installstatus='.$install_status);
    4347}
    4448
     
    4650if (isset($_GET['installstatus']))
    4751{
    48   $plugins->get_result($_GET['installstatus']);
     52  switch ($_GET['installstatus'])
     53  {
     54    case 'ok':
     55      array_push($page['infos'],
     56        l10n('plugins_install_ok'),
     57        l10n('plugins_install_need_activate'));
     58      break;
     59
     60    case 'temp_path_error':
     61      array_push($page['errors'], l10n('plugins_temp_path_error'));
     62      break;
     63
     64    case 'dl_archive_error':
     65      array_push($page['errors'], l10n('plugins_dl_archive_error'));
     66      break;
     67
     68    case 'archive_error':
     69      array_push($page['errors'], l10n('plugins_archive_error'));
     70      break;
     71
     72    default:
     73      array_push($page['errors'],
     74        sprintf(l10n('plugins_extract_error'), $_GET['installstatus']),
     75        l10n('plugins_check_chmod'));
     76  } 
    4977}
     78
     79//--------------------------------------------------------------------Tabsheet
     80include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
     81$link = get_root_url().'admin.php?page=';
     82$tabsheet = new tabsheet();
     83$tabsheet->add('plugins_list', l10n('plugins_tab_list'), $link.'plugins_list');
     84$tabsheet->add('plugins_update', l10n('plugins_tab_update'), $link.'plugins_update');
     85$tabsheet->add('plugins_new', l10n('plugins_tab_new'), $link.'plugins_new');
     86$tabsheet->select($page['page']);
     87$tabsheet->assign();
     88
     89//---------------------------------------------------------------Order options
     90$link .= $page['page'].'&order=';
     91$template->assign('order_options',
     92  array(
     93    $link.'date' => l10n('Post date'),
     94    $link.'name' => l10n('Name'),
     95    $link.'author' => l10n('Author')));
     96$template->assign('order_selected', $link.$order);
    5097
    5198// +-----------------------------------------------------------------------+
    5299// |                     start template output                             |
    53100// +-----------------------------------------------------------------------+
    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')));
     101$plugins->get_server_plugins(true);
     102$plugins->sort_server_plugins($order);
    60103
    61104if ($plugins->server_plugins !== false)
     
    72115              utf8_encode($plugin['description'])))));
    73116
    74     $url_auto_install = $plugins->html_base_url
     117    $url_auto_install = htmlentities($base_url)
    75118      . '&extension=' . $plugin['id_extension']
    76119      . '&install=%2Fupload%2Fextension-' . $plugin['id_extension']
  • trunk/admin/plugins_update.php

    r2263 r2264  
    3333$template->set_filenames(array('plugins' => 'admin/plugins_update.tpl'));
    3434
    35 $plugins = new plugins($page['page']);
     35$base_url = get_root_url().'admin.php?page='.$page['page'];
     36
     37$plugins = new plugins();
    3638
    3739//-----------------------------------------------------------automatic upgrade
    3840if (isset($_GET['upgrade']) and isset($_GET['plugin']) and !is_adviser())
    3941{
    40   $plugins->upgrade($_GET['upgrade'], $_GET['plugin']);
     42  $plugin_id = $_GET['plugin'];
     43
     44  if (isset($plugins->db_plugins_by_id[$plugin_id])
     45    and $plugins->db_plugins_by_id[$plugin_id]['state'] == 'active')
     46  {
     47    $plugins->perform_action('deactivate', $plugin_id);
     48
     49    redirect($base_url
     50      . '&upgrade=' . $_GET['upgrade']
     51      . '&plugin=' . $plugin_id
     52      . '&reactivate=true');
     53  }
     54
     55  $upgrade_status =
     56    $plugins->extract_plugin_files('upgrade', $_GET['upgrade'], $plugin_id);
     57
     58  if (isset($_GET['reactivate']))
     59  {
     60    $plugins->perform_action('activate', $plugin_id);
     61  }
     62  redirect($base_url.'&plugin='.$plugin_id.'&upgradestatus='.$upgrade_status);
    4163}
    4264
     
    4466if (isset($_GET['upgradestatus']) and isset($_GET['plugin']))
    4567{
    46   $plugins->get_result($_GET['upgradestatus'], $_GET['plugin']);
     68  switch ($_GET['upgradestatus'])
     69  {
     70    case 'ok':
     71      array_push($page['infos'],
     72         sprintf(
     73            l10n('plugins_upgrade_ok'),
     74            $plugins->fs_plugins[$_GET['plugin']]['name']));
     75      break;
     76
     77    case 'temp_path_error':
     78      array_push($page['errors'], l10n('plugins_temp_path_error'));
     79      break;
     80
     81    case 'dl_archive_error':
     82      array_push($page['errors'], l10n('plugins_dl_archive_error'));
     83      break;
     84
     85    case 'archive_error':
     86      array_push($page['errors'], l10n('plugins_archive_error'));
     87      break;
     88
     89    default:
     90      array_push($page['errors'],
     91        sprintf(l10n('plugins_extract_error'), $_GET['installstatus']),
     92        l10n('plugins_check_chmod'));
     93  } 
    4794}
     95
     96//--------------------------------------------------------------------Tabsheet
     97include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
     98$link = get_root_url().'admin.php?page=';
     99$tabsheet = new tabsheet();
     100$tabsheet->add('plugins_list', l10n('plugins_tab_list'), $link.'plugins_list');
     101$tabsheet->add('plugins_update', l10n('plugins_tab_update'), $link.'plugins_update');
     102$tabsheet->add('plugins_new', l10n('plugins_tab_new'), $link.'plugins_new');
     103$tabsheet->select($page['page']);
     104$tabsheet->assign();
    48105
    49106// +-----------------------------------------------------------------------+
    50107// |                     start template output                             |
    51108// +-----------------------------------------------------------------------+
    52 $plugins->tabsheet();
    53 $plugins->check_server_plugins();
     109$plugins->get_server_plugins();
    54110
    55111if ($plugins->server_plugins !== false)
     
    83139      {
    84140        // Plugin need upgrade
    85         $url_auto_update = $plugins->html_base_url
     141        $url_auto_update = $base_url
    86142          . '&plugin=' . $plugin_id
    87143          . '&upgrade=%2Fupload%2Fextension-' . $fs_plugin['extension']
  • trunk/include/constants.php

    r2242 r2264  
    2929define('PHPWG_DOMAIN', 'phpwebgallery.net');
    3030define('PHPWG_URL', 'http://www.'.PHPWG_DOMAIN);
    31 define('PEM_URL', PHPWG_URL . '/ext');
     31define('PEM_URL', 'http://' . PHPWG_DOMAIN . '/ext');
    3232define('PHPWG_DEFAULT_LANGUAGE', 'en_UK');
    3333define('PHPWG_DEFAULT_TEMPLATE', 'yoga/clear');
Note: See TracChangeset for help on using the changeset viewer.