Changeset 23472


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

somes fixes and improvments

Location:
extensions/plugin_lang_analysis
Files:
3 added
3 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  ));
  • extensions/plugin_lang_analysis/template/main.tpl

    r23467 r23472  
    1 {combine_css path=$PLA_PATH|@cat:"template/style.css"}
    2 {combine_css path=$PLA_PATH|@cat:"template/fontello/css/fontello_pla.css"}
    3 
     1{combine_css path=$PLA_PATH|cat:'template/style.css'}
     2{combine_css path=$PLA_PATH|cat:'template/fontello/css/fontello_pla.css'}
    43
    54<div class="titrePage">
    6         <h2>Plugin Language Analysis</h2>
     5        <h2>
     6    Plugin Language Analysis
     7    {if isset($PLA_PLUGIN)}[{$PLA_PLUGIN.name}]{/if}
     8  </h2>
    79</div>
     10
     11{include file=$PLA_ABS_PATH|cat:'template/'|cat:$PLA_STEP|cat:'.tpl'}
    812
    913{if isset($U_BACK)}
    1014<p style="text-align:left;margin-left:20px;"><a href="{$U_BACK}" class="buttonLike">{'Back'|@translate}</a></p>
    1115{/if}
    12 
    13 
    14 {* <!-- select --> *}
    15 {if $PLA_STEP=='select'}
    16 {footer_script}{literal}
    17 $('form#pla').submit(function() {
    18   window.location.href = location.href + '&plugin_id=' + $(this).find('select').val();
    19   return false;
    20 });
    21 {/literal}{/footer_script}
    22 
    23 <form method="GET" action="{$F_ACTION}" class="properties" id="pla">
    24 <fieldset>
    25   <legend>{'How to use?'|@translate}</legend>
    26 
    27   <p>
    28     This tool analyzes each file of the selected plugin, searching for <b>l10n</b>, <b>l10n_dec</b> and <b>translate</b> functions.<br>
    29     Then it compares the matched strings to the content of the plugin language file and the common and admin core language files.<br>
    30     Each file of the plugin can be configured as <b>Common</b> (public) or <b>Admin</b>.<br>
    31     <br>
    32     When the analysis is complete, each string can have one of these three status :
    33   </p>
    34  
    35   <dl style="margin-left:30px;">
    36     <dt class="iconpla-attention">missing</dt>
    37     <dd>
    38       not in the plugin language file<br>
    39       <b>AND</b> not in the common language file<br>
    40       <b>AND</b> (<br>
    41       &nbsp;&nbsp;&nbsp;&nbsp;belonging to at least one common file<br>
    42       &nbsp;&nbsp;&nbsp;&nbsp;<b>OR</b> not in the admin language file<br>
    43       )
    44     </dd>
    45  
    46     <dt class="iconpla-attention-circled">useless</dt>
    47     <dd>
    48       in the plugin language file<br>
    49       <b>AND</b> (<br>
    50       &nbsp;&nbsp;&nbsp;&nbsp;in the common language file<br>
    51       &nbsp;&nbsp;&nbsp;&nbsp;<b>OR</b> (<br>
    52       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;not belonging to any common file<br>
    53       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>AND</b> in the admin language file<br>
    54       &nbsp;&nbsp;&nbsp;&nbsp;)<br>
    55       )
    56     </dd>
    57  
    58     <dt class="iconpla-ok-squared">ok</dt>
    59     <dd>
    60       any other case
    61     </dd>
    62   </dl>
    63  
    64   <p>
    65     You can click the <span class="iconpla-plus-circled"></span> icon on the left of each string to see where it is located.
    66   </p>
    67 </fieldset>
    68 
    69 <fieldset>
    70   <legend>{'Select a plugin'|@translate}</legend>
    71  
    72   <select name="plugin_id">
    73   {foreach from=$PLA_PLUGINS item=plugin key=plugin_id}
    74     <option value="{$plugin_id}">{$plugin.name} ({$plugin.version})</option>
    75   {/foreach}
    76   </select>
    77 
    78   <p class="formButtons"><input type="submit" value="{'Continue'|@translate}"></p>
    79 </fieldset>
    80 </form>
    81 
    82 {* <!-- configure --> *}
    83 {elseif $PLA_STEP=='config'}
    84 {footer_script}{literal}
    85 $('.switch-button.type span').click(function() {
    86   $(this).siblings('span').removeClass('active');
    87   $(this).addClass('active');
    88  
    89   if ($(this).hasClass('common')) {
    90     $(this).nextAll('input').val('false');
    91   }
    92   else {
    93     $(this).nextAll('input').val('true');
    94   }
    95 });
    96 $('.switch-button.other span').click(function() {
    97   if ($(this).hasClass('active')) {
    98     $(this).removeClass('active');
    99     $(this).next('input').val('false');
    100   }
    101   else {
    102     $(this).addClass('active');
    103     $(this).next('input').val('true');
    104   }
    105 });
    106 {/literal}{/footer_script}
    107 
    108 <form method="POST" action="{$F_ACTION}" class="properties">
    109 <fieldset>
    110   <legend>{'Select dependencies'|@translate}</legend>
    111  
    112   <table class="files">
    113   <thead>
    114     <tr>
    115       <th></th>
    116       <th>{'Core dependency'|@translate}</th>
    117       <th>{'Local dependencies'|@translate}</th>
    118     </tr>
    119   </thead>
    120  
    121   <tbody>
    122   {foreach from=$PLA_FILES item=file}
    123     <tr>
    124       <td>{$file.path}</td>
    125       <td>
    126         <div class="switch-button type">
    127           <span class="item common {if not $file.is_admin}active{/if}">{'Common'|@translate}</span>
    128           <span class="item admin {if $file.is_admin}active{/if}">{'Admin'|@translate}</span>
    129           <input type="hidden" name="files[{$file.path}][is_admin]" value="{if $file.is_admin}true{else}false{/if}">
    130         </div>
    131       </td>
    132       <td>
    133         <div class="switch-button other">
    134         {foreach from=$PLA_LANG_FILES item=path key=lang_file}
    135           <span class="item other {if $lang_file|in_array:$file.lang_files}active{/if}">{$lang_file}</span>
    136           <input type="hidden" name="files[{$file.path}][lang_files][{$lang_file}]" value="{if $lang_file|in_array:$file.lang_files}true{else}false{/if}">
    137         {/foreach}
    138         </div>
    139       </td>
    140     </tr>
    141   {/foreach}
    142   </tbody>
    143   </table>
    144  
    145   <p class="formButtons"><input type="submit" value="{'Continue'|@translate}"></p>
    146 </fieldset>
    147 </form>
    148 
    149 {* <!-- analysis --> *}
    150 {elseif $PLA_STEP=='analysis'}
    151 {footer_script}{literal}
    152 $('.strings tr.string td.toggler').click(function() {
    153   if ($(this).hasClass('iconpla-plus-circled')) {
    154     $(this).removeClass('iconpla-plus-circled').addClass('iconpla-minus-circled');
    155     $(this).parent().nextUntil('tr.string').show();
    156   }
    157   else {
    158     $(this).removeClass('iconpla-minus-circled').addClass('iconpla-plus-circled');
    159     $(this).parent().nextUntil('tr.string').hide();
    160   }
    161 });
    162 
    163 $('.strings tr.string').hover(
    164   function() {
    165     $(this).addClass('hover').nextUntil('tr.string').addClass('hover');
    166   },
    167   function() {
    168     $(this).removeClass('hover').nextUntil('tr.string').removeClass('hover');
    169   }
    170 );
    171 $('.strings tr.file').hover(
    172   function() {
    173     $(this).prevAll('tr.string:first').addClass('hover').nextUntil('tr.string').addClass('hover');
    174   },
    175   function() {
    176     $(this).prevAll('tr.string:first').removeClass('hover').nextUntil('tr.string').removeClass('hover');
    177   }
    178 );
    179 
    180 $('.open-all').click(function() {
    181   $('.strings tr.file').show();
    182 });
    183 $('.open-missing').click(function() {
    184   $('.strings tr.file.string-missing').show();
    185 });
    186 $('.close-all').click(function() {
    187   $('.strings tr.file').hide();
    188 });
    189 {/literal}{/footer_script}
    190 
    191 {html_style}
    192 .strings tr td:nth-last-child(-n+{math equation="2+x" x=$PLA_LANG_FILES|@count}) {ldelim}
    193   text-align:center;
    194 }
    195 {/html_style}
    196 
    197 <fieldset>
    198   <legend>{$PLA_PLUGIN.name}</legend>
    199  
    200   <p style="text-align:left;">
    201     <a class="open-all">{'Expand all'|@translate}</a>
    202     / <a class="open-missing">{'Expand missing'|@translate}</a>
    203     / <a class="close-all">{'Collapse all'|@translate}</a>
    204   </p>
    205  
    206   <table class="strings">
    207   <thead>
    208     <tr>
    209       <th></th>
    210       <th class="legend">
    211         <span class="missing">{'Missing'|@translate}</span>
    212         <span class="useless">{'Useless'|@translate}</span>
    213       </th>
    214       <th>{'Dependency'|@translate}</th>
    215     {foreach from=$PLA_LANG_FILES item=path key=lang_file}
    216       <th>{$lang_file}</th>
    217     {/foreach}
    218       <th>common.lang</th>
    219       <th>admin.lang</th>
    220     </tr>
    221   </thead>
    222    
    223   <tbody>
    224   {foreach from=$PLA_STRINGS item=data key=string}
    225     <!-- begin string -->
    226     <tr class="string {$data.stat}">
    227       <td class="toggler iconpla-plus-circled"></td>
    228       <td>{$string|htmlspecialchars}</td>
    229       {if $data.is_admin}<td class="text-admin">{'Admin'|@translate}</td>
    230       {else}<td class="text-common">{'Common'|@translate}</td>{/if}
    231     {foreach from=$PLA_LANG_FILES item=path key=lang_file}
    232       <td>{if $lang_file|in_array:$data.in_plugin}<b>{'Yes'|@translate}</b>{else}{'No'|@translate}{/if}</td>
    233     {/foreach}
    234       <td>{if $data.in_common}<b>{'Yes'|@translate}</b>{else}{'No'|@translate}{/if}</td>
    235       <td>{if $data.in_admin}<b>{'Yes'|@translate}</b>{else}{'No'|@translate}{/if}</td>
    236     </tr>
    237     {foreach from=$data.files item=file_data key=file}
    238       <!-- begin file -->
    239       <tr class="file string-{$data.stat} {$file_data.stat}">
    240         <td></td>
    241         <td>{$file} <i>({', '|@implode:$file_data.lines})</i></td>
    242         {if $file_data.is_admin}<td class="text-admin">{'Admin'|@translate}</td>
    243         {else}<td class="text-common">{'Common'|@translate}</td>{/if}
    244       {foreach from=$PLA_LANG_FILES item=path key=lang_file}
    245         <td>{if $lang_file|in_array:$file_data.lang_files}<b>{'Yes'|@translate}</b>{else}{'No'|@translate}{/if}</td>
    246       {/foreach}
    247         <td></td>
    248         <td></td>
    249       </tr>
    250     {/foreach} {* <!-- end file --> *}
    251   {/foreach} {* <!-- end string --> *}
    252   </tbody>
    253  
    254   <tfoot>
    255     <tr>
    256       <th></th>
    257       <th>{'%d strings : %d missing and %d useless.'|@translate|sprintf:$PLA_COUNTS.total:$PLA_COUNTS.missing:$PLA_COUNTS.useless}</th>
    258       <th></th>
    259       <th></th>
    260       <th></th>
    261       <th></th>
    262       <th></th>
    263     </tr>
    264   </tfoot>
    265   </table>
    266 </fieldset>
    267 
    268 {/if}
  • extensions/plugin_lang_analysis/template/style.css

    r23467 r23472  
    1313    padding:5px 8px;
    1414    background:#e6e6e6;
    15     color:#555;
     15    color:#888;
    1616    cursor:pointer;
    1717  }
     18    .switch-button span:hover {
     19      text-decoration:underline;
     20    }
    1821    .switch-button span.active {
    1922      color:#212121;
     
    126129      background:#BFE599;
    127130    }
    128  
     131
     132.tiptip {
     133  cursor:help;
     134}
Note: See TracChangeset for help on using the changeset viewer.