Changeset 10098


Ignore:
Timestamp:
Apr 6, 2011, 11:43:46 AM (14 years ago)
Author:
patdenice
Message:

feature:2250
Incompatible plugins and obsolete plugins may not be activated.

Location:
trunk
Files:
4 edited

Legend:

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

    r8728 r10098  
    2727  var $db_plugins_by_id = array();
    2828  var $server_plugins = array();
     29  var $default_plugins = array('LocalFilesEditor', 'language_switch', 'c13y_upgrade', 'admin_multi_view');
    2930
    3031  /**
     
    186187          break;
    187188        }
     189        $query = '
     190DELETE FROM ' . PLUGINS_TABLE . ' WHERE id=\'' . $plugin_id . '\'';
     191        pwg_query($query);
    188192        if (!$this->deltree(PHPWG_PLUGINS_PATH . $plugin_id))
    189193        {
     
    284288  }
    285289
     290  // Retrieve PEM versions
     291  function get_versions_to_check($version=PHPWG_VERSION)
     292  {
     293    $versions_to_check = array();
     294    $url = PEM_URL . '/api/get_version_list.php?category=12&format=php';
     295    if (fetchRemote($url, $result) and $pem_versions = @unserialize($result))
     296    {
     297      if (!preg_match('/^\d+\.\d+\.\d+/', $version))
     298      {
     299        $version = $pem_versions[0]['name'];
     300      }
     301      $branch = substr($version, 0, strrpos($version, '.'));
     302      foreach ($pem_versions as $pem_version)
     303      {
     304        if (strpos($pem_version['name'], $branch) === 0)
     305        {
     306          $versions_to_check[] = $pem_version['id'];
     307        }
     308      }
     309    }
     310    return $versions_to_check;
     311  }
     312
    286313  /**
    287314   * Retrieve PEM server datas to $server_plugins
     
    291318    global $user;
    292319
     320    $versions_to_check = $this->get_versions_to_check();
     321    if (empty($versions_to_check))
     322    {
     323      return false;
     324    }
     325
     326    // Plugins to check
     327    $plugins_to_check = array();
     328    foreach($this->fs_plugins as $fs_plugin)
     329    {
     330      if (isset($fs_plugin['extension']))
     331      {
     332        $plugins_to_check[] = $fs_plugin['extension'];
     333      }
     334    }
     335
     336    // Retrieve PEM plugins infos
     337    $url = PEM_URL . '/api/get_revision_list.php';
    293338    $get_data = array(
    294339      'category_id' => 12,
    295340      'format' => 'php',
    296     );
    297 
    298     // Retrieve PEM versions
    299     $version = PHPWG_VERSION;
    300     $versions_to_check = array();
    301     $url = PEM_URL . '/api/get_version_list.php';
    302     if (fetchRemote($url, $result, $get_data) and $pem_versions = @unserialize($result))
    303     {
    304       if (!preg_match('/^\d+\.\d+\.\d+/', $version))
    305       {
    306         $version = $pem_versions[0]['name'];
    307       }
    308       $branch = substr($version, 0, strrpos($version, '.'));
    309       foreach ($pem_versions as $pem_version)
    310       {
    311         if (strpos($pem_version['name'], $branch) === 0)
    312         {
    313           $versions_to_check[] = $pem_version['id'];
    314         }
    315       }
    316     }
    317     if (empty($versions_to_check))
    318     {
    319       return false;
    320     }
    321 
    322     // Plugins to check
    323     $plugins_to_check = array();
    324     foreach($this->fs_plugins as $fs_plugin)
    325     {
    326       if (isset($fs_plugin['extension']))
    327       {
    328         $plugins_to_check[] = $fs_plugin['extension'];
    329       }
    330     }
    331 
    332     // Retrieve PEM plugins infos
    333     $url = PEM_URL . '/api/get_revision_list.php';
    334     $get_data = array_merge($get_data, array(
    335341      'last_revision_only' => 'true',
    336342      'version' => implode(',', $versions_to_check),
    337343      'lang' => substr($user['language'], 0, 2),
    338344      'get_nb_downloads' => 'true',
    339       )
    340345    );
    341346
     
    363368      }
    364369      return true;
     370    }
     371    return false;
     372  }
     373
     374  function get_incompatible_plugins()
     375  {
     376    if (isset($_SESSION['incompatible_plugins']))
     377    {
     378      return $_SESSION['incompatible_plugins'];
     379    }
     380
     381    $_SESSION['incompatible_plugins'] = array();
     382
     383    $versions_to_check = $this->get_versions_to_check();
     384    if (empty($versions_to_check))
     385    {
     386      return false;
     387    }
     388
     389    // Plugins to check
     390    $plugins_to_check = array();
     391    foreach($this->fs_plugins as $fs_plugin)
     392    {
     393      if (isset($fs_plugin['extension']))
     394      {
     395        $plugins_to_check[] = $fs_plugin['extension'];
     396      }
     397    }
     398
     399    // Retrieve PEM plugins infos
     400    $url = PEM_URL . '/api/get_revision_list.php';
     401    $get_data = array(
     402      'category_id' => 12,
     403      'format' => 'php',
     404      'version' => implode(',', $versions_to_check),
     405      'extension_include' => implode(',', $plugins_to_check),
     406    );
     407
     408    if (fetchRemote($url, $result, $get_data))
     409    {
     410      $pem_plugins = @unserialize($result);
     411      if (!is_array($pem_plugins))
     412      {
     413        return false;
     414      }
     415
     416      $server_plugins = array();
     417      foreach ($pem_plugins as $plugin)
     418      {
     419        if (!isset($server_plugins[$plugin['extension_id']]))
     420        {
     421          $server_plugins[$plugin['extension_id']] = array();
     422        }
     423        array_push($server_plugins[$plugin['extension_id']], $plugin['revision_name']);
     424      }
     425
     426      foreach ($this->fs_plugins as $plugin_id => $fs_plugin)
     427      {
     428        if (isset($fs_plugin['extension'])
     429          and !in_array($plugin_id, $this->default_plugins)
     430          and $fs_plugin['version'] != 'auto'
     431          and (!isset($server_plugins[$fs_plugin['extension']]) or !in_array($fs_plugin['version'], $server_plugins[$fs_plugin['extension']])))
     432        {
     433          $_SESSION['incompatible_plugins'][$plugin_id] = $fs_plugin['version'];
     434        }
     435      }
     436      return $_SESSION['incompatible_plugins'];
    365437    }
    366438    return false;
     
    484556    return $status;
    485557  }
     558
     559  function get_merged_extensions($version=PHPWG_VERSION)
     560  {
     561    if (!isset($_SESSION['merged_extensions']))
     562    {
     563      $_SESSION['merged_extensions'] = array();
     564      if (fetchRemote(MERGED_EXTENSIONS_URL, $result))
     565      {
     566        $rows = explode("\n", $result);
     567        foreach ($rows as $row)
     568        {
     569          if (preg_match('/^(\d+\.\d+): *(.*)$/', $row, $match))
     570          {
     571            if (version_compare($version, $match[1], '>='))
     572            {
     573              $extensions = explode(',', trim($match[2]));
     574              $_SESSION['merged_extensions'] = array_merge($_SESSION['merged_extensions'], $extensions);
     575            }
     576          }
     577        }
     578      }
     579    }
     580    return $_SESSION['merged_extensions'];
     581  }
    486582 
    487583  /**
  • trunk/admin/plugins_list.php

    r9995 r10098  
    6868
    6969$plugins->sort_fs_plugins('name');
     70$plugins->get_merged_extensions();
     71$plugins->get_incompatible_plugins();
     72$merged_plugins = array();
    7073
    7174foreach($plugins->fs_plugins as $plugin_id => $fs_plugin)
    7275{
     76  if (isset($_SESSION['incompatible_plugins'][$plugin_id])
     77    and $fs_plugin['version'] != $_SESSION['incompatible_plugins'][$plugin_id])
     78  {
     79    // Incompatible plugins must be reinitilized
     80    unset($_SESSION['incompatible_plugins']);
     81    $plugins->get_incompatible_plugins();
     82  }
     83
    7384  $tpl_plugin = array(
    7485    'NAME' => $fs_plugin['name'],
     
    7889    'AUTHOR' => $fs_plugin['author'],
    7990    'AUTHOR_URL' => @$fs_plugin['author uri'],
    80     'U_ACTION' => sprintf($action_url, $plugin_id)
     91    'U_ACTION' => sprintf($action_url, $plugin_id),
     92    'INCOMPATIBLE' => isset($_SESSION['incompatible_plugins'][$plugin_id]),
    8193    );
     94
     95  if (isset($fs_plugin['extension']) and in_array($fs_plugin['extension'], $_SESSION['merged_extensions']))
     96  {
     97    $tpl_plugin['STATE'] = 'merged';
     98    array_push($merged_plugins, $tpl_plugin);
     99    continue;
     100  }
    82101
    83102  if (isset($plugins->db_plugins_by_id[$plugin_id]))
     
    93112}
    94113
     114$template->append('plugin_states', 'active');
     115$template->append('plugin_states', 'inactive');
     116$template->append('plugin_states', 'uninstalled');
     117
    95118$missing_plugin_ids = array_diff(
    96119  array_keys($plugins->db_plugins_by_id),
     
    98121  );
    99122
    100 foreach($missing_plugin_ids as $plugin_id)
     123if (count($missing_plugin_ids) > 0)
    101124{
    102   $template->append(
    103     'plugins',
    104     array(
    105       'NAME' => $plugin_id,
    106       'VERSION' => $plugins->db_plugins_by_id[$plugin_id]['version'],
    107       'DESC' => "ERROR: THIS PLUGIN IS MISSING BUT IT IS INSTALLED! UNINSTALL IT NOW !",
    108       'U_ACTION' => sprintf($action_url, $plugin_id),
    109       'STATE' => 'missing',
    110       )
    111     );
     125  foreach($missing_plugin_ids as $plugin_id)
     126  {
     127    $template->append(
     128      'plugins',
     129      array(
     130        'NAME' => $plugin_id,
     131        'VERSION' => $plugins->db_plugins_by_id[$plugin_id]['version'],
     132        'DESC' => "ERROR: THIS PLUGIN IS MISSING BUT IT IS INSTALLED! UNINSTALL IT NOW !",
     133        'U_ACTION' => sprintf($action_url, $plugin_id),
     134        'STATE' => 'missing',
     135        )
     136      );
     137  }
     138  $template->append('plugin_states', 'missing');
    112139}
    113140
    114 $template->append('plugin_states', 'active');
    115 $template->append('plugin_states', 'inactive');
    116 $template->append('plugin_states', 'uninstalled');
    117 
    118 if (count($missing_plugin_ids) > 0)
     141if (count($merged_plugins) > 0)
    119142{
    120   $template->append('plugin_states', 'missing');
     143  foreach($merged_plugins as $tpl_plugin)
     144  {
     145    $tpl_plugin['DESC'] = l10n("THIS PLUGIN IS NOW PART OF PIWIGO CORE. UNINSTALL IT NOW.");
     146    $template->append('plugins', $tpl_plugin);
     147  }
     148  $template->append('plugin_states', 'merged');
    121149}
    122150
  • trunk/admin/themes/default/template/plugins_list.tpl

    r6363 r10098  
     1{footer_script}
     2var incompatible_msg = '{'WARNING! This plugin does not seem to be compatible with this version of Piwigo.'|@translate|@escape:'javascript'}';
     3incompatible_msg += '\n';
     4incompatible_msg += '{'Do you want to activate anyway?'|@translate|@escape:'javascript'}';
     5
     6{literal}
     7jQuery(document).ready(function() {
     8  jQuery('.incompatible').click(function() {
     9    return confirm(incompatible_msg);
     10  });
     11});
     12{/literal}{/footer_script}
     13
    114<div class="titrePage">
    215  <h2>{'Plugins'|@translate}</h2>
     
    2033  {'Missing Plugins'|@translate}
    2134
     35  {elseif $plugin_state == 'merged'}
     36  {'Obsolete Plugins'|@translate}
     37
    2238  {/if}
    2339  </legend>
     
    3652
    3753    {elseif $plugin_state == 'inactive'}
    38           <a href="{$plugin.U_ACTION}&amp;action=activate">{'Activate'|@translate}</a>
     54          <a href="{$plugin.U_ACTION}&amp;action=activate" {if $plugin.INCOMPATIBLE}class="incompatible"{/if}>{'Activate'|@translate}</a>
    3955          | <a href="{$plugin.U_ACTION}&amp;action=uninstall" onclick="return confirm('{'Are you sure?'|@translate|@escape:'javascript'}');">{'Uninstall'|@translate}</a>
    4056
     
    4359          | <a href="{$plugin.U_ACTION}&amp;action=delete" onclick="return confirm('{'Are you sure you want to delete this plugin?'|@translate|@escape:'javascript'}');">{'Delete'|@translate}</a>
    4460
    45     {elseif $plugin_state == 'missing'}
     61    {elseif $plugin_state == 'missing' or $plugin_state == 'merged'}
    4662          <a href="{$plugin.U_ACTION}&amp;action=uninstall" onclick="return confirm('{'Are you sure?'|@translate|@escape:'javascript'}');">{'Uninstall'|@translate}</a>
    4763
  • trunk/include/common.inc.php

    r8728 r10098  
    157157  define('PEM_URL', 'http://'.PHPWG_DOMAIN.'/ext');
    158158}
     159define('MERGED_EXTENSIONS_URL', 'http://'.PHPWG_DOMAIN.'/download/merged_extensions.txt');
    159160
    160161
Note: See TracChangeset for help on using the changeset viewer.