Changeset 10131


Ignore:
Timestamp:
Apr 7, 2011, 11:47:01 AM (13 years ago)
Author:
patdenice
Message:

merge r10098,r10100,r10101,r10113,r10128,r10129 from trunk to branch 2.2
feature:2250
Incompatible plugins and obsolete plugins may not be activated.
Deactivate and uninstall obsolete plugins.
Add warning icon and tiptip
Add languages keys.
Add expire parameter.
Clean code.
Remove useless query for delete.

Location:
branches/2.2
Files:
7 edited
2 copied

Legend:

Unmodified
Added
Removed
  • branches/2.2/admin/include/plugins.class.php

    r8728 r10131  
    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  /**
     
    284285  }
    285286
     287  // Retrieve PEM versions
     288  function get_versions_to_check($version=PHPWG_VERSION)
     289  {
     290    $versions_to_check = array();
     291    $url = PEM_URL . '/api/get_version_list.php?category=12&format=php';
     292    if (fetchRemote($url, $result) and $pem_versions = @unserialize($result))
     293    {
     294      if (!preg_match('/^\d+\.\d+\.\d+/', $version))
     295      {
     296        $version = $pem_versions[0]['name'];
     297      }
     298      $branch = substr($version, 0, strrpos($version, '.'));
     299      foreach ($pem_versions as $pem_version)
     300      {
     301        if (strpos($pem_version['name'], $branch) === 0)
     302        {
     303          $versions_to_check[] = $pem_version['id'];
     304        }
     305      }
     306    }
     307    return $versions_to_check;
     308  }
     309
    286310  /**
    287311   * Retrieve PEM server datas to $server_plugins
     
    291315    global $user;
    292316
     317    $versions_to_check = $this->get_versions_to_check();
     318    if (empty($versions_to_check))
     319    {
     320      return false;
     321    }
     322
     323    // Plugins to check
     324    $plugins_to_check = array();
     325    foreach($this->fs_plugins as $fs_plugin)
     326    {
     327      if (isset($fs_plugin['extension']))
     328      {
     329        $plugins_to_check[] = $fs_plugin['extension'];
     330      }
     331    }
     332
     333    // Retrieve PEM plugins infos
     334    $url = PEM_URL . '/api/get_revision_list.php';
    293335    $get_data = array(
    294336      'category_id' => 12,
    295337      '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(
    335338      'last_revision_only' => 'true',
    336339      'version' => implode(',', $versions_to_check),
    337340      'lang' => substr($user['language'], 0, 2),
    338341      'get_nb_downloads' => 'true',
    339       )
    340342    );
    341343
     
    363365      }
    364366      return true;
     367    }
     368    return false;
     369  }
     370
     371  function get_incompatible_plugins($actualize=false)
     372  {
     373    if (isset($_SESSION['incompatible_plugins']) and !$actualize
     374      and $_SESSION['incompatible_plugins']['~~expire~~'] > time())
     375    {
     376      return $_SESSION['incompatible_plugins'];
     377    }
     378
     379    $_SESSION['incompatible_plugins'] = array('~~expire~~' => time() + 300);
     380
     381    $versions_to_check = $this->get_versions_to_check();
     382    if (empty($versions_to_check))
     383    {
     384      return false;
     385    }
     386
     387    // Plugins to check
     388    $plugins_to_check = array();
     389    foreach($this->fs_plugins as $fs_plugin)
     390    {
     391      if (isset($fs_plugin['extension']))
     392      {
     393        $plugins_to_check[] = $fs_plugin['extension'];
     394      }
     395    }
     396
     397    // Retrieve PEM plugins infos
     398    $url = PEM_URL . '/api/get_revision_list.php';
     399    $get_data = array(
     400      'category_id' => 12,
     401      'format' => 'php',
     402      'version' => implode(',', $versions_to_check),
     403      'extension_include' => implode(',', $plugins_to_check),
     404    );
     405
     406    if (fetchRemote($url, $result, $get_data))
     407    {
     408      $pem_plugins = @unserialize($result);
     409      if (!is_array($pem_plugins))
     410      {
     411        return false;
     412      }
     413
     414      $server_plugins = array();
     415      foreach ($pem_plugins as $plugin)
     416      {
     417        if (!isset($server_plugins[$plugin['extension_id']]))
     418        {
     419          $server_plugins[$plugin['extension_id']] = array();
     420        }
     421        array_push($server_plugins[$plugin['extension_id']], $plugin['revision_name']);
     422      }
     423
     424      foreach ($this->fs_plugins as $plugin_id => $fs_plugin)
     425      {
     426        if (isset($fs_plugin['extension'])
     427          and !in_array($plugin_id, $this->default_plugins)
     428          and $fs_plugin['version'] != 'auto'
     429          and (!isset($server_plugins[$fs_plugin['extension']]) or !in_array($fs_plugin['version'], $server_plugins[$fs_plugin['extension']])))
     430        {
     431          $_SESSION['incompatible_plugins'][$plugin_id] = $fs_plugin['version'];
     432        }
     433      }
     434      return $_SESSION['incompatible_plugins'];
    365435    }
    366436    return false;
     
    484554    return $status;
    485555  }
     556
     557  function get_merged_extensions($version=PHPWG_VERSION)
     558  {
     559    if (isset($_SESSION['merged_extensions']) and $_SESSION['merged_extensions']['~~expire~~'] > time())
     560    {
     561      return $_SESSION['merged_extensions'];
     562    }
     563
     564    $_SESSION['merged_extensions'] = array('~~expire~~' => time() + 600);
     565
     566    if (fetchRemote(PHPWG_URL.'/download/merged_extensions.txt', $result))
     567    {
     568      $rows = explode("\n", $result);
     569      foreach ($rows as $row)
     570      {
     571        if (preg_match('/^(\d+\.\d+): *(.*)$/', $row, $match))
     572        {
     573          if (version_compare($version, $match[1], '>='))
     574          {
     575            $extensions = explode(',', trim($match[2]));
     576            $_SESSION['merged_extensions'] = array_merge($_SESSION['merged_extensions'], $extensions);
     577          }
     578        }
     579      }
     580    }
     581
     582    return $_SESSION['merged_extensions'];
     583  }
    486584 
    487585  /**
  • branches/2.2/admin/plugins_list.php

    r10007 r10131  
    6868
    6969$plugins->sort_fs_plugins('name');
     70$plugins->get_merged_extensions();
     71$plugins->get_incompatible_plugins();
     72$merged_plugins = false;
    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    $plugins->get_incompatible_plugins(true);
     81  }
     82
    7383  $tpl_plugin = array(
    7484    'NAME' => $fs_plugin['name'],
     
    7888    'AUTHOR' => $fs_plugin['author'],
    7989    'AUTHOR_URL' => @$fs_plugin['author uri'],
    80     'U_ACTION' => sprintf($action_url, $plugin_id)
     90    'U_ACTION' => sprintf($action_url, $plugin_id),
     91    'INCOMPATIBLE' => isset($_SESSION['incompatible_plugins'][$plugin_id]),
    8192    );
    8293
     
    90101  }
    91102
     103  if (isset($fs_plugin['extension']) and in_array($fs_plugin['extension'], $_SESSION['merged_extensions']))
     104  {
     105    switch($tpl_plugin['STATE'])
     106    {
     107      case 'active': $plugins->perform_action('deactivate', $plugin_id);
     108      case 'inactive': $plugins->perform_action('uninstall', $plugin_id);
     109    }
     110    $tpl_plugin['STATE'] = 'merged';
     111    $tpl_plugin['DESC'] = l10n('THIS PLUGIN IS NOW PART OF PIWIGO CORE! DELETE IT NOW.');
     112    $merged_plugins = true;
     113  }
     114
    92115  $template->append('plugins', $tpl_plugin);
     116}
     117
     118$template->append('plugin_states', 'active');
     119$template->append('plugin_states', 'inactive');
     120$template->append('plugin_states', 'uninstalled');
     121
     122if ($merged_plugins)
     123{
     124  $template->append('plugin_states', 'merged');
    93125}
    94126
     
    98130  );
    99131
    100 foreach($missing_plugin_ids as $plugin_id)
    101 {
    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     );
    112 }
    113 
    114 $template->append('plugin_states', 'active');
    115 $template->append('plugin_states', 'inactive');
    116 $template->append('plugin_states', 'uninstalled');
    117 
    118132if (count($missing_plugin_ids) > 0)
    119133{
     134  foreach($missing_plugin_ids as $plugin_id)
     135  {
     136    $template->append(
     137      'plugins',
     138      array(
     139        'NAME' => $plugin_id,
     140        'VERSION' => $plugins->db_plugins_by_id[$plugin_id]['version'],
     141        'DESC' => l10n('ERROR: THIS PLUGIN IS MISSING BUT IT IS INSTALLED! UNINSTALL IT NOW.'),
     142        'U_ACTION' => sprintf($action_url, $plugin_id),
     143        'STATE' => 'missing',
     144        )
     145      );
     146  }
    120147  $template->append('plugin_states', 'missing');
    121148}
  • branches/2.2/admin/themes/default/template/plugins_list.tpl

    r6363 r10131  
     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  jQuery('.warning').tipTip({
     12    'delay' : 0,
     13    'fadeIn' : 200,
     14    'fadeOut' : 200
     15  });
     16});
     17{/literal}{/footer_script}
     18
    119<div class="titrePage">
    220  <h2>{'Plugins'|@translate}</h2>
     
    2038  {'Missing Plugins'|@translate}
    2139
     40  {elseif $plugin_state == 'merged'}
     41  {'Obsolete Plugins'|@translate}
     42
    2243  {/if}
    2344  </legend>
     
    2748    <table>
    2849      <tr>
    29         <td class="pluginBoxNameCell">{$plugin.NAME}</td>
     50        <td class="pluginBoxNameCell{if $plugin.INCOMPATIBLE} warning" title="{'WARNING! This plugin does not seem to be compatible with this version of Piwigo.'|@translate|@escape:'html'}{/if}">
     51          {$plugin.NAME}
     52        </td>
    3053        <td>{$plugin.DESC}</td>
    3154      </tr>
     
    3659
    3760    {elseif $plugin_state == 'inactive'}
    38           <a href="{$plugin.U_ACTION}&amp;action=activate">{'Activate'|@translate}</a>
     61          <a href="{$plugin.U_ACTION}&amp;action=activate" {if $plugin.INCOMPATIBLE}class="incompatible"{/if}>{'Activate'|@translate}</a>
    3962          | <a href="{$plugin.U_ACTION}&amp;action=uninstall" onclick="return confirm('{'Are you sure?'|@translate|@escape:'javascript'}');">{'Uninstall'|@translate}</a>
    4063
     
    4669          <a href="{$plugin.U_ACTION}&amp;action=uninstall" onclick="return confirm('{'Are you sure?'|@translate|@escape:'javascript'}');">{'Uninstall'|@translate}</a>
    4770
     71    {elseif $plugin_state == 'merged'}
     72          <a href="{$plugin.U_ACTION}&amp;action=delete">{'Delete'|@translate}</a>
    4873    {/if}
    4974        </td>
  • branches/2.2/admin/themes/default/theme.css

    r9951 r10131  
    10441044#batchManagerGlobal #applyFilterBlock {margin-top:20px;}
    10451045#batchManagerGlobal .useFilterCheckbox {display:none}
     1046
     1047.warning {
     1048  background:url(icon/warning.png) no-repeat top left;
     1049  width: 130px;
     1050  padding-left: 20px;
     1051}
  • branches/2.2/include/common.inc.php

    r8728 r10131  
    158158}
    159159
    160 
    161160// language files
    162161load_language('common.lang');
  • branches/2.2/language/en_UK/admin.lang.php

    r9936 r10131  
    778778$lang['Visit language site'] = 'Visit language site';
    779779$lang['New Version'] = 'New Version';
     780$lang['Obsolete Plugins'] = 'Obsolete Plugins';
     781$lang['WARNING! This plugin does not seem to be compatible with this version of Piwigo.'] = 'WARNING! This plugin does not seem to be compatible with this version of Piwigo.';
     782$lang['Do you want to activate anyway?'] = 'Do you want to activate anyway?';
     783$lang['THIS PLUGIN IS NOW PART OF PIWIGO CORE! DELETE IT NOW.'] = 'THIS PLUGIN IS NOW PART OF PIWIGO CORE! UNINSTALL IT NOW!';
     784$lang['ERROR: THIS PLUGIN IS MISSING BUT IT IS INSTALLED! UNINSTALL IT NOW.'] = 'ERROR: THIS PLUGIN IS MISSING BUT IT IS INSTALLED! UNINSTALL IT NOW.';
    780785?>
  • branches/2.2/language/fr_FR/admin.lang.php

    r10040 r10131  
    789789$lang['Visit language site'] = 'Visitez le site de la langue';
    790790$lang['New Version'] = 'Nouvelle version';
     791$lang['Obsolete Plugins'] = 'Plugins obsolètes';
     792$lang['WARNING! This plugin does not seem to be compatible with this version of Piwigo.'] = 'ATTENTION! Ce plugin n\'a pas l\'air d\'être compatible avec votre version de Piwigo.';
     793$lang['Do you want to activate anyway?'] = 'Voulez-vous l\'activer quand même?';
     794$lang['THIS PLUGIN IS NOW PART OF PIWIGO CORE! DELETE IT NOW.'] = 'CE PLUGIN FAIT DÉSORMAIS PARTIE DU CORE DE PIWIGO! SUPPRIMEZ-LE.';
     795$lang['ERROR: THIS PLUGIN IS MISSING BUT IT IS INSTALLED! UNINSTALL IT NOW.'] = 'ERREUR: CE PLUGIN EST MANQUANT MAIS TOUJOURS INSTALLÉ! DÉSINSTALLEZ-LE.';
    791796?>
Note: See TracChangeset for help on using the changeset viewer.