Changeset 12733 for extensions/GThumb


Ignore:
Timestamp:
Dec 14, 2011, 5:54:42 PM (13 years ago)
Author:
patdenice
Message:

Thumbnails can be generated in admin pannel.

Location:
extensions/GThumb
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • extensions/GThumb/admin.php

    r12696 r12733  
    33if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    44
    5 global $template, $conf;
     5global $template, $conf, $page;
    66
    77load_language('plugin.lang', GTHUMB_PATH);
     
    1616  gtdeltree(GTHUMB_CACHE_DIR);
    1717  redirect('admin.php?page=plugin-GThumb');
     18}
     19
     20// Generate cache
     21if (isset($_GET['generatecache']))
     22{
     23  if ($_GET['generatecache'] == 'complete')
     24  {
     25    array_push($page['infos'], l10n('Cache have been generated'));
     26  }
     27  else
     28  {
     29    $query = 'SELECT id, path, md5sum, tn_ext FROM '.IMAGES_TABLE.';';
     30    $result = pwg_query($query);
     31    $cache_dir = GTHUMB_CACHE_DIR.'/'.$conf['GThumb']['height'].'/';
     32    $missing = array();
     33
     34    while ($row = pwg_db_fetch_assoc($result))
     35    {
     36      if (!is_file($cache_dir.md5($row['path'].(!empty($row['md5sum']) ? $row['md5sum'] : '')).'.'.$row['tn_ext'])
     37        and in_array(get_extension($row['path']), $conf['picture_ext']))
     38      {
     39        array_push($missing, $row['id']);
     40      }
     41    }
     42    echo json_encode($missing);
     43    exit();
     44  }
    1845}
    1946
     
    7097// Informations
    7198$data = gtdirsize(GTHUMB_CACHE_DIR);
    72 if ($data['size'] > 1024 * 1024)
    73   $data['size'] = round($data['size'] / (1024 * 1024), 2).' MB';
    74 else
    75   $data['size'] = round($data['size'] / 1024, 2).' KB';
    7699
    77100$template->assign(
    78101  array(
    79     'NB_ELEMENTS' => l10n_dec('%d file', '%d files', $data['nb_files']),
    80     'ELEMENTS_SIZE' => $data['size'],
     102    'NB_FILES' => $data['nb_files'],
     103    'CACHE_SIZE' => $data['size'],
    81104    'PWG_TOKEN' => get_pwg_token(),
    82105  )
  • extensions/GThumb/functions.inc.php

    r12732 r12733  
    8080    'width' => $result['width'],
    8181    'height' => $result['height'],
     82    'filesize' => filesize($file),
    8283  );
    8384}
  • extensions/GThumb/language/en_UK/plugin.lang.php

    r12696 r12733  
    77$lang['Scale thumbnails'] = 'Scale thumbnails';
    88$lang['Cache Informations'] = 'Cache Informations';
    9 $lang['Clear the cache'] = 'Clear the cache';
     9$lang['Purge thumbnails cache'] = 'Purge thumbnails cache';
    1010$lang['%d file'] = '%d file';
    1111$lang['%d files'] = '%d files';
     12$lang['Cache have been generated'] = 'Cache have been generated';
     13$lang['Pre-cache thumbnails'] = 'Pre-cache thumbnails';
    1214
    1315?>
  • extensions/GThumb/language/fr_FR/plugin.lang.php

    r12696 r12733  
    77$lang['Scale thumbnails'] = 'Redimensionner les miniatures';
    88$lang['Cache Informations'] = 'Informations du cache';
    9 $lang['Clear the cache'] = 'Effacer le cache';
     9$lang['Purge thumbnails cache'] = 'Vider le cache';
    1010$lang['%d file'] = '%d fichier';
    1111$lang['%d files'] = '%d fichiers';
     12$lang['Cache have been generated'] = 'Le cache a été généré';
     13$lang['Pre-cache thumbnails'] = 'Mettre en cache les miniatures';
    1214
    1315?>
  • extensions/GThumb/main.inc.php

    r12732 r12733  
    144144  global $conf;
    145145
    146   if (!in_array(get_extension($picture['file']), $conf['picture_ext']))
     146  if (!in_array(get_extension($picture['path']), $conf['picture_ext']))
    147147  {
    148148    $file = get_thumbnail_url($picture);
  • extensions/GThumb/template/admin.tpl

    r12691 r12733  
    5252<fieldset id="cacheinfo">
    5353<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>
     54<p id="cache_data">&nbsp;</p>
     55<p id="GThumbAction">
     56  <button onclick="GThumb.deletecache();">{'Purge thumbnails cache'|@translate}</button>
     57  <button onclick="GThumb.generatecache();">{'Pre-cache thumbnails'|@translate}</button>
    5758</p>
     59<div id="GThumbProgressbar" style="display:none;">
     60  {'Generating cache, please wait...'|@translate}<br>
     61  <div id="progressbar"></div>
     62</div>
    5863</fieldset>
    5964
     
    6166<style type="text/css">
    6267#GThumb td { padding-bottom: 12px; }
    63 #cacheinfo p { text-align:left; line-height:20px; margin:20px }
     68#cacheinfo p, #GThumbProgressbar { text-align:left; line-height:20px; margin:20px }
     69.ui-progressbar-value { background-image: url(plugins/GThumb/template/pbar-ani.gif); }
    6470</style>
    6571{/literal}{/html_head}
     72
     73{combine_script id='jquery.ui.progressbar' load='footer'}
     74{combine_script id='jquery.ajaxmanager' load='footer' path='themes/default/js/plugins/jquery.ajaxmanager.js'}
     75
     76{footer_script}
     77var pwg_token = '{$PWG_TOKEN}';
     78var confirm_message = '{'Are you sure?'|@translate}';
     79var nb_files_str  = '{'%d file'|@translate}';
     80var nb_files_str_plur = '{'%d files'|@translate}';
     81var lang_info_zero_plural = {if $lang_info.zero_plural}true{else}false{/if};
     82var cache_size = {$CACHE_SIZE};
     83var nb_files = {$NB_FILES};
     84
     85{literal}
     86var GThumb = {
     87
     88  total: 0,
     89  done: 0,
     90
     91  queue: jQuery.manageAjax.create('queued', {
     92    queue: true, 
     93    cacheResponse: false,
     94    maxRequests: 3
     95  }),
     96
     97  deletecache: function() {
     98    if (confirm(confirm_message)) {
     99      window.location = 'admin.php?page=plugin-GThumb&deletecache=true&pwg_token='+pwg_token;
     100    }
     101  },
     102
     103  generatecache: function() {
     104    jQuery("#progressbar").progressbar({value: 0});
     105    jQuery.ajax({
     106      url: 'admin.php?page=plugin-GThumb&generatecache=request',
     107      dataType: 'json',
     108      success: function(data) {
     109        if (data.length > 0) {
     110          jQuery("#GThumbProgressbar, #GThumbAction").toggle();
     111          GThumb.total = data.length;
     112          for (i=0;i<data.length;i++) {
     113            GThumb.queue.add({
     114              type: 'GET',
     115              url: 'ws.php',
     116              data: {
     117                method: 'pwg.images.getGThumbPlusThumbnail',
     118                image_id: data[i],
     119                format: 'json'
     120              },
     121              dataType: 'json',
     122              success: function(data) {
     123                nb_files++;
     124                cache_size += data.result.filesize;
     125                updateCacheSizeAndFiles();
     126                GThumb.progressbar();
     127              },
     128              error: GThumb.progressbar
     129            });
     130          }
     131        } else {
     132          window.location = 'admin.php?page=plugin-GThumb&generatecache=complete';
     133        }
     134      },
     135      error: function() {
     136        alert('An error occured');
     137      }
     138    });
     139    return false;
     140  },
     141
     142  progressbar: function() {
     143    jQuery( "#progressbar" ).progressbar({
     144      value: Math.round(++GThumb.done * 100 / GThumb.total)
     145    });
     146    if (GThumb.done == GThumb.total) {
     147      window.location = 'admin.php?page=plugin-GThumb&generatecache=complete';
     148    }
     149  }
     150};
     151
     152function updateCacheSizeAndFiles() {
     153 
     154  if ( nb_files > 1 || (nb_files == 0 && lang_info_zero_plural)) {
     155    nbstr = nb_files_str_plur;
     156  } else {
     157    nbstr = nb_files_str;
     158  }
     159
     160  ret = nbstr.replace('%d', nb_files) + ', ';
     161
     162  if (cache_size > 1024 * 1024)
     163    ret += Math.round((cache_size / (1024 * 1024))*100)/100 + ' MB';
     164  else
     165    ret += Math.round((cache_size / 1024)*100)/100 + ' KB';
     166
     167  jQuery("#cache_data").html(ret);
     168}
     169
     170updateCacheSizeAndFiles();
     171{/literal}{/footer_script}
Note: See TracChangeset for help on using the changeset viewer.