Changeset 12691


Ignore:
Timestamp:
12/03/11 18:11:54 (8 years ago)
Author:
patdenice
Message:

Display cache informations on admin page.
Add possibility to clear the cache.
Resize method is now applied on big images.

Location:
extensions/GThumb
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • extensions/GThumb/admin.php

    r12678 r12691  
    99include(dirname(__FILE__).'/config_default.inc.php'); 
    1010$params = $conf['GThumb']; 
     11 
     12// Delete cache 
     13if (isset($_GET['deletecache'])) 
     14{ 
     15  check_pwg_token(); 
     16  gtdeltree(GTHUMB_CACHE_DIR); 
     17  redirect('admin.php?page=plugin-GThumb'); 
     18} 
    1119 
    1220// Save configuration 
     
    6068); 
    6169 
     70// Informations 
     71$data = gtdirsize(GTHUMB_CACHE_DIR); 
     72if ($data['size'] > 1024 * 1024) 
     73  $data['size'] = round($data['size'] / (1024 * 1024), 2).' MB'; 
     74else 
     75  $data['size'] = round($data['size'] / 1024, 2).' KB'; 
     76 
     77$template->assign( 
     78  array( 
     79    'NB_ELEMENTS' => l10n_dec('%d photo', '%d photos', $data['nb_files']), 
     80    'ELEMENTS_SIZE' => $data['size'], 
     81    'PWG_TOKEN' => get_pwg_token(), 
     82  ) 
     83); 
     84 
    6285$template->set_filenames(array('plugin_admin_content' => dirname(__FILE__) . '/template/admin.tpl')); 
    6386$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); 
  • extensions/GThumb/functions.inc.php

    r12678 r12691  
    131131} 
    132132 
     133function gtdirsize($path, &$size=0, &$nb_files=0) 
     134{ 
     135  if (is_dir($path)) 
     136  { 
     137    $fh = opendir($path); 
     138    while ($file = readdir($fh)) 
     139    { 
     140      if ($file != '.' and $file != '..' and $file != 'index.htm') 
     141      { 
     142        $pathfile = $path . '/' . $file; 
     143        if (is_dir($pathfile)) 
     144        { 
     145          $data = gtdirsize($pathfile, $size, $nb_files); 
     146        } 
     147        else 
     148        { 
     149          $size += filesize($pathfile); 
     150          $nb_files++; 
     151        } 
     152      } 
     153    } 
     154    closedir($fh); 
     155  } 
     156  return array( 
     157    'size' => $size, 
     158    'nb_files' => $nb_files, 
     159  ); 
     160} 
     161 
    133162?> 
  • extensions/GThumb/js/gthumb.js

    r12680 r12691  
    7373 
    7474      // Compute best size for landscape picture (we choose bigger height) 
    75       min_ratio = Math.min(1, this.big_thumb.width/this.big_thumb.height); 
     75      min_ratio = Math.min(1.05, this.big_thumb.width/this.big_thumb.height); 
    7676 
    7777      for(width = this.big_thumb.width; width/best_size.height>=min_ratio; width--) { 
     
    118118      } 
    119119      this.t[0].crop = best_size.width; 
    120       this.resize(first_thumb, this.big_thumb.width, this.big_thumb.height, best_size.width, best_size.height, 'crop'); 
     120      this.resize(first_thumb, this.big_thumb.width, this.big_thumb.height, best_size.width, best_size.height, true); 
    121121 
    122122    } 
     
    164164            new_width = Math.round(new_width); 
    165165          } 
    166           this.resize(jQuery('#gt'+thumb_process[j].id), thumb_process[j].width, thumb_process[j].height, new_width, new_height, this.method); 
     166          this.resize(jQuery('#gt'+thumb_process[j].id), thumb_process[j].width, thumb_process[j].height, new_width, new_height, false); 
    167167 
    168168          width_count += new_width + this.margin; 
     
    177177    // Last line does not need to be cropped 
    178178    for (j=0;j<thumb_process.length;j++) { 
    179       this.resize(jQuery('#gt'+thumb_process[j].id), thumb_process[j].width, thumb_process[j].height, thumb_process[j].width, max_height, this.method); 
     179      this.resize(jQuery('#gt'+thumb_process[j].id), thumb_process[j].width, thumb_process[j].height, thumb_process[j].width, max_height, false); 
    180180    } 
    181181 
     
    185185  }, 
    186186 
    187   resize: function(thumb, width, height, new_width, new_height, method) { 
    188  
    189     if (method == 'resize') { 
     187  resize: function(thumb, width, height, new_width, new_height, is_big) { 
     188 
     189    if (this.method == 'resize') { 
     190      real_width = Math.min(new_width, width); 
     191      real_height = Math.min(new_height, height); 
     192      width_crop = 0; 
     193      height_crop = 0; 
     194 
     195      if (is_big) { 
     196        if (width - new_width > height - new_height) { 
     197          real_width = Math.round(new_height * width / height); 
     198          width_crop = Math.round((real_width - new_width)/2); 
     199        } else { 
     200          real_height = Math.round(new_width * height / width); 
     201          height_crop = Math.round((real_height - new_height)/2); 
     202        } 
     203      } 
    190204      thumb.css({ 
    191         height: new_height+'px', 
    192         width: new_width+'px' 
     205        height: real_height+'px', 
     206        width: real_width+'px' 
    193207      }); 
    194       height_crop = 0; 
    195       width_crop = 0; 
    196208    } else { 
    197209      thumb.css({height: '', width: ''}); 
  • extensions/GThumb/language/en_UK/plugin.lang.php

    r12678 r12691  
    66$lang['Cache the big thumbnails (recommended)'] = 'Cache the big thumbnails (recommended)'; 
    77$lang['Scale thumbnails'] = 'Scale thumbnails'; 
     8$lang['Cache Informations'] = 'Cache Informations'; 
     9$lang['Clear the cache'] = 'Clear the cache'; 
    810 
    911?> 
  • extensions/GThumb/language/fr_FR/plugin.lang.php

    r12678 r12691  
    66$lang['Cache the big thumbnails (recommended)'] = 'Mettre en cache les grosse miniatures (recommandé)'; 
    77$lang['Scale thumbnails'] = 'Redimensionner les miniatures'; 
     8$lang['Cache Informations'] = 'Informations du cache'; 
     9$lang['Clear the cache'] = 'Effacer le cache'; 
    810 
    911?> 
  • extensions/GThumb/template/admin.tpl

    r12678 r12691  
    5050</form> 
    5151 
     52<fieldset id="cacheinfo"> 
     53<legend>{'Cache Informations'|@translate}</legend> 
     54<p> 
     55{$NB_ELEMENTS}, {$ELEMENTS_SIZE}<br> 
     56<a href="admin.php?page=plugin-GThumb&amp;pwg_token={$PWG_TOKEN}&amp;deletecache=true" onclick="return confirm('{'Are you sure?'|@translate}');">{'Clear the cache'|@translate}</a> 
     57</p> 
     58</fieldset> 
     59 
    5260{html_head}{literal} 
    53 <style type="text/css">#GThumb td { padding-bottom: 12px; }</style> 
     61<style type="text/css"> 
     62#GThumb td { padding-bottom: 12px; } 
     63#cacheinfo p { text-align:left; line-height:20px; margin:20px } 
     64</style> 
    5465{/literal}{/html_head} 
  • extensions/GThumb/template/gthumb.css

    r12678 r12691  
    1616  position: absolute; 
    1717} 
     18 
     19.thumbnail, .thumbnail:hover { 
     20  border: 0 none; 
     21} 
  • extensions/GThumb/template/gthumb.tpl

    r12678 r12691  
    1818GThumb.margin = {$GThumb.margin}; 
    1919GThumb.method = '{$GThumb.method}'; 
    20  
     20GThumb.small_thumb = {ldelim}id:{$small_thumb.id},src:'{$small_thumb.src}',width:{$small_thumb.width},height:{$small_thumb.height}{rdelim}; 
    2121{if isset($big_thumb)} 
    2222GThumb.big_thumb = {ldelim}id:{$big_thumb.id},src:'{$big_thumb.src}',width:{$big_thumb.width},height:{$big_thumb.height}{rdelim}; 
    23 GThumb.small_thumb = {ldelim}id:{$small_thumb.id},src:'{$small_thumb.src}',width:{$small_thumb.width},height:{$small_thumb.height}{rdelim}; 
    2423{/if} 
    2524 
Note: See TracChangeset for help on using the changeset viewer.