Ignore:
Timestamp:
Jun 23, 2013, 7:50:07 PM (11 years ago)
Author:
mistic100
Message:

somes fixes and improvments

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/plugin_lang_analysis/admin.php

    r23467 r23472  
    77
    88include_once(PLA_PATH . 'include/functions.inc.php');
    9 include_once(PHPWG_ROOT_PATH . '/admin/include/plugins.class.php');
     9include_once(PHPWG_ROOT_PATH . 'admin/include/plugins.class.php');
    1010$plugins = new plugins();
    1111
    12 /* PLUGINS LIST */
     12/* SELECT */
    1313if (!isset($_GET['plugin_id']))
    1414{
     
    2020}
    2121
    22 /* FILES LIST */
     22/* CONFIG */
    2323else if (!isset($_GET['analyze']))
    2424{
     
    4545  foreach ($files as &$file)
    4646  {
    47     if (isset($saved_files[$file]))
    48     {
    49       $file = $saved_files[$file];
     47    if (isset($saved_files[ $file ]))
     48    {
     49      $file = $saved_files[ $file ];
    5050      $file['lang_files'] = array_intersect($file['lang_files'], array_keys($language_files));
    5151    }
     
    6565    'PLA_PLUGIN' => $plugins->fs_plugins[ $_GET['plugin_id'] ],
    6666    'PLA_FILES' => $files,
    67     'PLA_LANG_FILES' => $language_files,
     67    'PLA_LANG_FILES' => array_keys($language_files),
    6868    'F_ACTION' => PLA_ADMIN.'&plugin_id='.$_GET['plugin_id'].'&analyze',
    6969    'U_BACK' => PLA_ADMIN,
    7070    ));
    7171}
     72
     73/* ANALYSIS */
    7274else
    7375{
     
    7880    foreach ($_POST['files'] as $file => $data)
    7981    {
    80       $files[$file] = array(
     82      $files[ $file ] = array(
    8183        'path' => $file,
    8284        'is_admin' => $data['is_admin']=='true',
     
    8587      if (!empty($data['lang_files']))
    8688      {
    87         $files[$file]['lang_files'] = array_keys(array_filter($data['lang_files'], create_function('$f', 'return $f=="true";')));
     89        $files[ $file ]['lang_files'] = array_keys(array_filter($data['lang_files'], create_function('$f', 'return $f=="true";')));
    8890      }
    8991    }
     
    125127  }
    126128 
    127   // analyze
     129  // analyse
    128130  foreach ($strings as $string => &$string_data)
    129131  {
    130     // find where teh string is defined
     132    // find where the string is defined
    131133    $string_data['in_common'] = array_key_exists($string, $lang_common);
    132134    $string_data['in_admin'] = array_key_exists($string, $lang_admin);
     
    137139    }
    138140   
     141    // very rare case
     142    if (count($string_data['in_plugin'])>1)
     143    {
     144      $string_data['warnings'][] = l10n('This string is translated in multiple files');
     145    }
     146   
    139147    $missing = $useless = $ok = false;
    140148    $string_data['is_admin'] = true;
    141149   
    142     // analyze for each file where the string exists
     150    // analyse for each file where the string exists
    143151    foreach ($string_data['files'] as $file => &$file_data)
    144152    {
     
    147155     
    148156      // find if the string is translated in one of the language files included in this file
    149       $exists = false;
    150       foreach ($file_data['lang_files'] as $lang_file)
    151       {
    152         if (in_array($lang_file, $string_data['in_plugin']))
    153         {
    154           $exists = true;
    155           break;
    156         }
    157       }
     157      $exists = count(array_intersect($file_data['lang_files'], $string_data['in_plugin'])) > 0;
    158158     
    159159      // useless if translated in the plugin AND in common or admin
     
    193193    else
    194194    {
     195      // another very rare case
     196      if ($useless)
     197      {
     198        $string_data['warnings'][] = l10n('This string is useless in some files');
     199      }
     200     
    195201      $string_data['stat'] = 'ok';
    196202      $counts['ok']++;
     
    199205  unset($string_data);
    200206 
    201   uksort($strings, 'strnatcasecmp');
     207  uksort($strings, 'strnatcasecmp'); // natural sort
    202208  $counts['total'] = array_sum($counts);
    203209 
     
    206212    'PLA_PLUGIN' => $plugins->fs_plugins[ $_GET['plugin_id'] ],
    207213    'PLA_STRINGS' => $strings,
    208     'PLA_LANG_FILES' => $language_files,
     214    'PLA_LANG_FILES' => array_keys($language_files),
    209215    'PLA_COUNTS' => $counts,
    210216    'U_BACK' => PLA_ADMIN.'&plugin_id='.$_GET['plugin_id'],
     
    215221$template->assign(array(
    216222  'PLA_PATH'=> PLA_PATH,
    217   'PLA_ABS_PATH'=> realpath(PLA_PATH),
     223  'PLA_ABS_PATH'=> realpath(PLA_PATH).'/',
    218224  'PLA_ADMIN' => PLA_ADMIN,
    219225  ));
Note: See TracChangeset for help on using the changeset viewer.