Changeset 13652


Ignore:
Timestamp:
Mar 20, 2012, 11:32:30 PM (12 years ago)
Author:
patdenice
Message:

Compatible with Piwigo 2.4

Location:
extensions/GThumb
Files:
1 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • extensions/GThumb/admin.php

    r12758 r13652  
    33if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    44
     5function delete_gthumb_cache($height)
     6{
     7  $pattern = '#.*-cu_s9999x'.$height.'\.[a-zA-Z0-9]{3,4}$#';
     8  if ($contents = @opendir(PHPWG_ROOT_PATH.PWG_DERIVATIVE_DIR))
     9  {
     10    while (($node = readdir($contents)) !== false)
     11    {
     12      if ($node != '.'
     13          and $node != '..'
     14          and is_dir(PHPWG_ROOT_PATH.PWG_DERIVATIVE_DIR.$node))
     15      {
     16        clear_derivative_cache_rec(PHPWG_ROOT_PATH.PWG_DERIVATIVE_DIR.$node, $pattern);
     17      }
     18    }
     19    closedir($contents);
     20  }
     21}
     22
     23if (isset($_GET['getMissingDerivative']))
     24{
     25  list($max_id, $image_count) = pwg_db_fetch_row( pwg_query('SELECT MAX(id)+1, COUNT(*) FROM '.IMAGES_TABLE) );
     26  $start_id = intval($_POST['prev_page']);
     27  $max_urls = intval($_POST['max_urls']);
     28  if ($start_id<=0)
     29  {
     30    $start_id = $max_id;
     31  }
     32
     33  $uid = '&b='.time();
     34  global $conf;
     35  $conf['question_mark_in_urls'] = $conf['php_extension_in_urls'] = true;
     36  $conf['derivative_url_style']=2; //script
     37
     38  $qlimit = min(5000, ceil(max($image_count/500, $max_urls)));
     39
     40  $query_model = 'SELECT id, path, representative_ext, width, height
     41  FROM '.IMAGES_TABLE.'
     42  WHERE id < start_id
     43  ORDER BY id DESC
     44  LIMIT '.$qlimit;
     45
     46  $urls=array();
     47  do
     48  {
     49    $result = pwg_query( str_replace('start_id', $start_id, $query_model));
     50    $is_last = pwg_db_num_rows($result) < $qlimit;
     51    while ($row=pwg_db_fetch_assoc($result))
     52    {
     53      $start_id = $row['id'];
     54      $src_image = new SrcImage($row);
     55      if ($src_image->is_mimetype())
     56        continue;
     57      $derivative = new DerivativeImage(ImageStdParams::get_custom(9999, $conf['GThumb']['height']), $src_image);
     58      if (@filemtime($derivative->get_path())===false)
     59      {
     60        $urls[] = $derivative->get_url().$uid;
     61      }
     62      if (count($urls)>=$max_urls && !$is_last)
     63        break;
     64    }
     65    if ($is_last)
     66    {
     67      $start_id = 0;
     68    }
     69  }while (count($urls)<$max_urls && $start_id);
     70
     71  $ret = array();
     72  if ($start_id)
     73  {
     74    $ret['next_page']=$start_id;
     75  }
     76  $ret['urls']=$urls;
     77  echo json_encode($ret);
     78  exit();
     79}
     80
    581global $template, $conf, $page;
    682
    783load_language('plugin.lang', GTHUMB_PATH);
    8 include_once(GTHUMB_PATH.'functions.inc.php');
    984include(dirname(__FILE__).'/config_default.inc.php');
    1085$params = $conf['GThumb'];
    1186
    1287// Delete cache
    13 if (isset($_GET['deletecache']))
     88if (isset($_POST['cachedelete']))
    1489{
    15   check_pwg_token();                             
    16   gtdeltree(GTHUMB_CACHE_DIR);
     90  check_pwg_token();
     91  delete_gthumb_cache($conf['GThumb']['height']);
     92  delete_gthumb_cache($conf['GThumb']['height'] * 2 + $conf['GThumb']['margin']);
    1793  redirect('admin.php?page=plugin-GThumb');
    18 }
    19 
    20 // Generate cache
    21 if (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   }
    4594}
    4695
     
    72121  if ($params['height'] != $conf['GThumb']['height'])
    73122  {
    74     gtdeltree(GTHUMB_CACHE_DIR);
     123    delete_gthumb_cache($conf['GThumb']['height']);
    75124  }
    76125  elseif ($params['margin'] != $conf['GThumb']['margin'])
    77126  {
    78     gtdeltree(GTHUMB_CACHE_DIR.'/'.($conf['GThumb']['height'] * 2 + $conf['GThumb']['margin']));
     127    delete_gthumb_cache($conf['GThumb']['height'] * 2 + $conf['GThumb']['margin']);
    79128  }
    80129
     
    101150    'CACHE_BIG_THUMB' => $params['cache_big_thumb'],
    102151    'METHOD'          => $params['method'],
    103   )
    104 );
    105 
    106 // Informations
    107 $data = gtdirsize(GTHUMB_CACHE_DIR);
    108 
    109 $template->assign(
    110   array(
    111     'NB_FILES' => $data['nb_files'],
    112     'CACHE_SIZE' => $data['size'],
    113     'PWG_TOKEN' => get_pwg_token(),
     152    'PWG_TOKEN'       => get_pwg_token(),
    114153  )
    115154);
  • extensions/GThumb/js/gthumb.js

    r12857 r13652  
    11var GThumb = {
    22
    3   root: './',
    43  max_height: 200,
    54  margin: 10,
     
    109  t: new Array,
    1110
    12   queue: jQuery.manageAjax.create('queued', {
    13     queue: true, 
    14     cacheResponse: false,
    15     maxRequests: 3,
    16     preventDoubleRequests: false
    17   }),
    18 
    1911  build: function () {
    2012
    2113    GThumb.t = new Array;
    22     jQuery('#thumbnails img.thumbnail').each(function() {
    23       id = parseInt(this.id.substring(2));
     14    jQuery('#thumbnails img.thumbnail').each(function(index) {
    2415      width = parseInt(jQuery(this).attr('width'));
    2516      height = parseInt(jQuery(this).attr('height'));
    26       th = {id:id,width:width,height:height,real_width:width,real_height:height};
     17      th = {index:index,width:width,height:height,real_width:width,real_height:height};
    2718      if (height < GThumb.max_height) {
    2819        th.width = Math.round(GThumb.max_height * width / height);
     
    3021      }
    3122      GThumb.t.push(th);
     23    });
    3224
    33       if (jQuery(this).attr('src') == '') {
    34         GThumb.addToQueue(id, 1);
    35       }
    36     });
     25    first = GThumb.t[0];
     26    GThumb.small_thumb = {index:first.index,width:first.real_width,height:first.real_height,src:jQuery('#thumbnails img:first').attr('src')}
    3727
    3828    jQuery.resize.throttleWindow = false;
    3929    jQuery.resize.delay = 50;
    4030    GThumb.process();
    41   },
    42 
    43   addToQueue: function (id, loop) {
    44 
    45     GThumb.queue.add({
    46       type: 'GET',
    47       url: GThumb.root+'ws.php',
    48       data: {
    49         method: 'pwg.images.getGThumbPlusThumbnail',
    50         image_id: id,
    51         format: 'json'
    52       },
    53       dataType: 'json',
    54       success: function(data) {
    55         if (data.stat == 'ok') {
    56           jQuery('#gt'+data.result.id).prop('src', GThumb.root+data.result.src).show();
    57         } else if (loop < 4) {
    58           GThumb.addToQueue(id, ++loop);
    59         }
    60       },
    61       error: function() {
    62         if (loop < 4) GThumb.addToQueue(id, ++loop);
    63       }
    64     });
    6531  },
    6632
     
    9864            if (line > 2) {
    9965              if (height >= best_size.height && width/height >= min_ratio && height<=GThumb.big_thumb.height) {
    100                 best_size = {width:width,height:height}
     66                best_size = {width:width,height:height};
    10167              }
    10268              break;
     
    153119      if (width_count > available_width) {
    154120
    155         last_thumb = GThumb.t[i].id;
     121        last_thumb = GThumb.t[i].index;
    156122        ratio = width_count / available_width;
    157123        new_height = Math.round(max_height / ratio);
     
    161127        for (j=0;j<thumb_process.length;j++) {
    162128
    163           if (thumb_process[j].id == last_thumb) {
     129          if (thumb_process[j].index == last_thumb) {
    164130            new_width = available_width - width_count - GThumb.margin;
    165131          } else {
     
    168134            new_width = Math.round(new_width);
    169135          }
    170           GThumb.resize(jQuery('#gt'+thumb_process[j].id), thumb_process[j].real_width, thumb_process[j].real_height, new_width, new_height, false);
     136          GThumb.resize(jQuery('#thumbnails img.thumbnail').eq(thumb_process[j].index), thumb_process[j].real_width, thumb_process[j].real_height, new_width, new_height, false);
    171137
    172138          width_count += new_width + GThumb.margin;
     
    181147    // Last line does not need to be cropped
    182148    for (j=0;j<thumb_process.length;j++) {
    183       GThumb.resize(jQuery('#gt'+thumb_process[j].id), thumb_process[j].real_width, thumb_process[j].real_height, thumb_process[j].width, max_height, false);
     149      GThumb.resize(jQuery('#thumbnails img.thumbnail').eq(thumb_process[j].index), thumb_process[j].real_width, thumb_process[j].real_height, thumb_process[j].width, max_height, false);
    184150    }
    185151
  • extensions/GThumb/main.inc.php

    r12924 r13652  
    1414
    1515define('GTHUMB_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/');
    16 define('GTHUMB_CACHE_DIR', PHPWG_ROOT_PATH.PWG_LOCAL_DIR.'GThumb');
    1716
    1817$conf['GThumb'] = unserialize($conf['GThumb']);
     
    2625
    2726add_event_handler('loc_begin_index', 'GThumb_init', 60);
    28 add_event_handler('ws_add_methods', 'add_gthumb_thumbnails_method');
    2927add_event_handler('get_admin_plugin_menu_links', 'GThumb_admin_menu');
    3028
     
    4846  $template->assign('GThumb', $conf['GThumb']);
    4947
    50   include_once(PHPWG_ROOT_PATH.'admin/include/image.class.php');
     48  $template->assign('GThumb_derivative_params', ImageStdParams::get_custom(9999, $conf['GThumb']['height']));
    5149
    52   foreach ($tpl_vars as $key => &$tpl_var)
     50  if ($conf['GThumb']['big_thumb'] and !empty($tpl_vars[0]))
    5351  {
    54     $data = get_gthumb_data($pictures[$key]);
    55 
    56     $tpl_var['TN_SRC'] = $data['src'];
    57     $tpl_var['TN_WIDTH'] = $data['width'];
    58     $tpl_var['TN_HEIGHT'] = $data['height'];
     52    $derivative_params = ImageStdParams::get_custom(9999, 2 * $conf['GThumb']['height'] + $conf['GThumb']['margin']);
     53    $template->assign('GThumb_big', new DerivativeImage($derivative_params, $tpl_vars[0]['src_image']));
    5954  }
    6055
    61   if ($conf['GThumb']['big_thumb'])
    62   {
    63     $ft = &$tpl_vars[0];
    64 
    65     // Small thumb data
    66     $small_thumb = array(
    67       'id' => $ft['ID'],
    68       'src' => $ft['TN_SRC'],
    69       'width' => $ft['TN_WIDTH'],
    70       'height' => $ft['TN_HEIGHT'],
    71     );
    72 
    73     if (empty($small_thumb['src']))
    74     {
    75       include_once(GTHUMB_PATH.'functions.inc.php');
    76       $data = get_gthumb_data($pictures[0]);
    77       $result = make_gthumb_image($pictures[0], $data);
    78       $small_thumb['src'] = $result['destination'];
    79     }
    80 
    81     // Big thumb data
    82     $data = get_gthumb_data($pictures[0], 'big');
    83 
    84     $big_thumb = array(
    85       'id' => $ft['ID'],
    86       'src' => $data['src'],
    87       'width' => $data['width'],
    88       'height' => $data['height'],
    89     );
    90     if (empty($big_thumb['src']))
    91     {
    92       if ($conf['GThumb']['cache_big_thumb'])
    93       {
    94         include_once(GTHUMB_PATH.'functions.inc.php');
    95         $result = make_gthumb_image($pictures[0], $data);
    96         $big_thumb['src'] = embellish_url(get_root_url().$result['destination']);
    97       }
    98       else
    99       {
    100         $big_thumb['src'] = get_root_url().'ws.php?method=pwg.images.getGThumbPlusThumbnail&image_id='.$ft['ID'].'&size=big&return=true';
    101       }
    102     }
    103 
    104     $template->assign(
    105       array(
    106         'small_thumb' => $small_thumb,
    107         'big_thumb' => $big_thumb,
    108       )
    109     );
    110     $ft['TN_SRC'] = $big_thumb['src'];
    111     $ft['TN_WIDTH'] = $big_thumb['width'];
    112     $ft['TN_HEIGHT'] = $big_thumb['height'];
    113   }
    114  
    11556  return $tpl_vars;
    116 }
    117 
    118 function add_gthumb_thumbnails_method($arr)
    119 {
    120   include_once(GTHUMB_PATH.'functions.inc.php');
    121 
    122   $service = &$arr[0];
    123   $service->addMethod(
    124     'pwg.images.getGThumbPlusThumbnail',
    125     'ws_images_getGThumbPlusThumbnail',
    126     array(
    127       'image_id' => array(),
    128       'size' => array('default'=>'small'),
    129       'return' => array('default'=>false),
    130     ),
    131     'Get thumbnail for GThumb+ plugin. Size parameter can be "small" or "big".'
    132   );
    133 }
    134 
    135 function get_gthumb_data($picture, $size='small')
    136 {
    137   global $conf;
    138 
    139   $picture_ext = array('jpg', 'jpeg', 'png', 'gif');
    140 
    141   if (!in_array(strtolower(get_extension($picture['path'])), $picture_ext))
    142   {
    143     list($width, $height) = getimagesize(get_thumbnail_path($picture));
    144 
    145     return array(
    146       'src' => get_thumbnail_url($picture),
    147       'width' => $width,
    148       'height' => $height,
    149     );
    150   }
    151 
    152   $new_height = $size == 'small' ? $conf['GThumb']['height'] : $conf['GThumb']['height'] * 2 + $conf['GThumb']['margin'];
    153   $file = GTHUMB_CACHE_DIR.'/'.$new_height.'/'.md5($picture['path'].(!empty($picture['md5sum']) ? $picture['md5sum'] : '')).'.'.$picture['tn_ext'];
    154 
    155   if (file_exists($file))
    156   {
    157     list($width, $height) = getimagesize($file);
    158 
    159     return array(
    160       'src' => embellish_url(get_root_url().$file),
    161       'width' => $width,
    162       'height' => $height,
    163     );
    164   }
    165 
    166   if ( !empty($picture['tn_ext']) )
    167   {
    168     $file = substr_replace(get_filename_wo_extension($picture['path']), '/thumbnail/GT-',strrpos($picture['path'],'/'),1).'.'.$picture['tn_ext'];
    169     if (file_exists($file))
    170     {
    171       list($width, $height) = getimagesize($file);
    172 
    173       return array(
    174         'src' => embellish_url(get_root_url().$file),
    175         'width' => $width,
    176         'height' => $height,
    177       );
    178     }
    179   }
    180 
    181   $width = $picture['width'];
    182   $height = $picture['height'];
    183   $use_high = false;
    184 
    185   if ($height < $new_height and $picture['has_high'] == 'true')
    186   {
    187     $width = $picture['high_width'];
    188     $height = $picture['high_height'];
    189     $use_high = true;
    190   }
    191 
    192   if ($size == 'big')
    193   {
    194     $width = min($width, round(max($height, $new_height) * 1.15));
    195   }
    196 
    197   $result = pwg_image::get_resize_dimensions($width, $height, 5000, $new_height);
    198   $result['src'] = '';
    199 
    200   // Test thumbnail size
    201   list($width, $height) = getimagesize(get_thumbnail_path($picture));
    202   if ($result['width'] == $width and $result['height'] == $height)
    203   {
    204     $result['src'] = get_thumbnail_url($picture);
    205   }
    206 
    207   $result['use_high'] = $use_high;
    208   $result['cache_path'] = GTHUMB_CACHE_DIR.'/'.$new_height.'/';
    209   $result['size'] = $size;
    210 
    211   return $result;
    21257}
    21358
  • extensions/GThumb/maintain.inc.php

    r12758 r13652  
    1515function plugin_uninstall()
    1616{
    17   include_once(dirname(__FILE__).'/functions.inc.php');
    18   gtdeltree(PHPWG_ROOT_PATH.PWG_LOCAL_DIR.'GThumb');
     17  if (is_dir(PHPWG_ROOT_PATH.PWG_LOCAL_DIR.'GThumb'))
     18  {
     19    gtdeltree(PHPWG_ROOT_PATH.PWG_LOCAL_DIR.'GThumb');
     20  }
    1921 
    2022  $query = 'DELETE FROM ' . CONFIG_TABLE . ' WHERE param="GThumb" LIMIT 1;';
     
    2426function plugin_activate($plugin_id, $version)
    2527{
    26   if (in_array($version, array('2.3.a', '2.3.b')))
     28  if (is_dir(PHPWG_ROOT_PATH.PWG_LOCAL_DIR.'GThumb'))
    2729  {
    28     include_once(PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/functions.inc.php');
    2930    gtdeltree(PHPWG_ROOT_PATH.PWG_LOCAL_DIR.'GThumb');
    3031  }
    3132}
    3233
     34function gtdeltree($path)
     35{
     36  if (is_dir($path))
     37  {
     38    $fh = opendir($path);
     39    while ($file = readdir($fh))
     40    {
     41      if ($file != '.' and $file != '..')
     42      {
     43        $pathfile = $path . '/' . $file;
     44        if (is_dir($pathfile))
     45        {
     46          gtdeltree($pathfile);
     47        }
     48        else
     49        {
     50          @unlink($pathfile);
     51        }
     52      }
     53    }
     54    closedir($fh);
     55    return @rmdir($path);
     56  }
     57}
     58
    3359?>
  • extensions/GThumb/template/admin.tpl

    r12857 r13652  
    4747</fieldset>
    4848
    49 <p><input type="submit" name="submit" value="{'Submit'|@translate}"></p>
     49<p>
     50  <input type="hidden" name="pwg_token" value="{$PWG_TOKEN}">
     51  <input type="submit" name="submit" value="{'Submit'|@translate}">
     52  <input type="submit" name="cachedelete" value="{'Purge thumbnails cache'|@translate}" title="{'Delete images in GThumb+ cache.'|@translate}" onclick="return confirm('{'Are you sure?'|@translate}');">
     53  <input type="button" name="cachebuild" value="{'Pre-cache thumbnails'|@translate}" title="{'Finds images that have not been cached and creates the cached version.'|@translate}" onclick="start()">
     54</p>
    5055</form>
    5156
    52 <fieldset id="cacheinfo">
    53 <legend>{'Cache Informations'|@translate}</legend>
    54 <p id="cache_data">&nbsp;</p>
    55 <p id="GThumbAction">
    56   <button onclick="GThumb.deletecache();" title="{'Delete images in GThumb+ cache.'|@translate}">{'Purge thumbnails cache'|@translate}</button>
    57   <button onclick="GThumb.generatecache();" title="{'Finds images that have not been cached and creates the cached version.'|@translate}">{'Pre-cache thumbnails'|@translate}</button>
     57<fieldset id="generate_cache">
     58<legend>{'Pre-cache thumbnails'|@translate}</legend>
     59<p>
     60<table>
     61        <tr>
     62                <td>Errors</td>
     63                <td id="errors">0</td>
     64        </tr>
     65        <tr>
     66                <td>Loaded</td>
     67                <td id="loaded">0</td>
     68        </tr>
     69        <tr>
     70                <td>Remaining</td>
     71                <td id="remaining">0</td>
     72        </tr>
     73</table>
    5874</p>
    59 <div id="GThumbProgressbar" style="display:none;">
    60   {'Generating cache, please wait...'|@translate}<br>
    61   <div id="progressbar"></div>
    62   <p><button onclick="GThumb.abort();">{'Cancel'|@translate}</button></p>
     75<p>
     76        <input id="startLink" value="{'Start'|@translate}" onclick="start()" type="button">
     77        <input id="pauseLink" value="{'Pause'|@translate}" onclick="pause()" type="button" disabled="disbled">
     78        <input id="stopLink" value="{'Stop'|@translate}" onclick="stop()" type="button" disabled="disbled">
     79</p>
     80<div id="feedbackWrap" style="height:320px; min-height:320px;">
     81<img id="feedbackImg">
     82</div>
     83
     84<div id="errorList">
    6385</div>
    6486</fieldset>
     
    6991#cacheinfo p, #GThumbProgressbar { text-align:left; line-height:20px; margin:20px }
    7092.ui-progressbar-value { background-image: url(plugins/GThumb/template/pbar-ani.gif); }
     93#generate_cache { display: none; }
    7194</style>
    7295{/literal}{/html_head}
    7396
    74 {combine_script id='jquery.ui.progressbar' load='footer'}
    75 {combine_script id='jquery.ajaxmanager' load='footer' path='themes/default/js/plugins/jquery.ajaxmanager.js'}
    76 
    77 {footer_script}
    78 var pwg_token = '{$PWG_TOKEN}';
    79 var confirm_message = '{'Are you sure?'|@translate}';
    80 var nb_files_str  = '{'%d file'|@translate}';
    81 var nb_files_str_plur = '{'%d files'|@translate}';
    82 var lang_info_zero_plural = {if $lang_info.zero_plural}true{else}false{/if};
    83 var cache_size = {$CACHE_SIZE};
    84 var nb_files = {$NB_FILES};
    85 
    86 {literal}
    87 var GThumb = {
    88 
    89   total: 0,
    90   done: 0,
    91 
    92   queue: jQuery.manageAjax.create('queued', {
    93     queue: true, 
    94     cacheResponse: false,
    95     maxRequests: 3
    96   }),
    97 
    98   deletecache: function() {
    99     if (confirm(confirm_message)) {
    100       window.location = 'admin.php?page=plugin-GThumb&deletecache=true&pwg_token='+pwg_token;
    101     }
    102   },
    103 
    104   generatecache: function() {
    105     GThumb.total = nb_files;
    106     GThumb.done = nb_files;
    107     jQuery("#progressbar").progressbar({value: 1});
    108     jQuery.ajax({
    109       url: 'admin.php?page=plugin-GThumb&generatecache=request',
    110       dataType: 'json',
    111       success: function(data) {
    112         if (data.length > 0) {
    113           jQuery("#GThumbProgressbar, #GThumbAction").toggle();
    114           GThumb.total = data.length + GThumb.done;
    115           jQuery("#progressbar").progressbar({value: Math.ceil(GThumb.done * 100 / GThumb.total)});
    116           for (i=0;i<data.length;i++) {
    117             GThumb.queue.add({
    118               type: 'GET',
    119               url: 'ws.php',
    120               data: {
    121                 method: 'pwg.images.getGThumbPlusThumbnail',
    122                 image_id: data[i],
    123                 format: 'json'
    124               },
    125               dataType: 'json',
    126               success: function(data) {
    127                 nb_files++;
    128                 cache_size += data.result.filesize;
    129                 updateCacheSizeAndFiles();
    130                 GThumb.progressbar();
    131               },
    132               error: GThumb.progressbar
    133             });
    134           }
    135         } else {
    136           window.location = 'admin.php?page=plugin-GThumb&generatecache=complete';
    137         }
    138       },
    139       error: function() {
    140         alert('An error occured');
    141       }
    142     });
    143     return false;
    144   },
    145 
    146   progressbar: function() {
    147     jQuery( "#progressbar" ).progressbar({
    148       value: Math.ceil(++GThumb.done * 100 / GThumb.total)
    149     });
    150     if (GThumb.done == GThumb.total) {
    151       window.location = 'admin.php?page=plugin-GThumb&generatecache=complete';
    152     }
    153   },
    154 
    155   abort: function() {
    156     GThumb.queue.clear();
    157     GThumb.queue.abort();
    158     jQuery("#GThumbProgressbar, #GThumbAction").toggle();
     97{combine_script id='iloader' load='footer' path='themes/default/js/image.loader.js'}
     98
     99{footer_script require='jquery.effects.slide'}{literal}
     100jQuery('input[name^="cache"]').tipTip({'delay' : 0, 'fadeIn' : 200, 'fadeOut' : 200});
     101
     102var loader = new ImageLoader( {onChanged: loaderChanged, maxRequests:1 } )
     103        , pending_next_page = null
     104        , last_image_show_time = 0
     105        , allDoneDfd, urlDfd;
     106
     107function start() {
     108        allDoneDfd = jQuery.Deferred();
     109        urlDfd = jQuery.Deferred();
     110
     111        allDoneDfd.always( function() {
     112                        jQuery("#startLink").attr('disabled', false).css("opacity", 1);
     113                        jQuery("#pauseLink,#stopLink").attr('disabled', true).css("opacity", 0.5);
     114                } );
     115
     116        urlDfd.always( function() {
     117                if (loader.remaining()==0)
     118                        allDoneDfd.resolve();
     119                } );
     120
     121  jQuery('#generate_cache').show();
     122        jQuery("#startLink").attr('disabled', true).css("opacity", 0.5);
     123        jQuery("#pauseLink,#stopLink").attr('disabled', false).css("opacity", 1);
     124
     125        loader.pause(false);
     126        updateStats();
     127        getUrls('0');
     128}
     129
     130function pause() {
     131        loader.pause( !loader.pause() );
     132}
     133
     134function stop() {
     135        loader.clear();
     136        urlDfd.resolve();
     137}
     138
     139function getUrls(page_token) {
     140        data = {prev_page: page_token, max_urls: 195, types: []};
     141        jQuery.post( '{/literal}{$ROOT_URL}{literal}admin.php?page=plugin-GThumb&getMissingDerivative=',
     142                data, wsData, "json").fail( wsError );
     143}
     144
     145function wsData(data) {
     146  if (data.urls.length == 0) {
     147    jQuery('#generate_cache, input[name="cachebuild"]').hide();
    159148  }
    160 };
    161 
    162 function updateCacheSizeAndFiles() {
    163  
    164   if ( nb_files > 1 || (nb_files == 0 && lang_info_zero_plural)) {
    165     nbstr = nb_files_str_plur;
    166   } else {
    167     nbstr = nb_files_str;
    168   }
    169 
    170   ret = nbstr.replace('%d', nb_files) + ', ';
    171 
    172   if (cache_size > 1024 * 1024)
    173     ret += Math.round((cache_size / (1024 * 1024))*100)/100 + ' MB';
    174   else
    175     ret += Math.round((cache_size / 1024)*100)/100 + ' KB';
    176 
    177   jQuery("#cache_data").html(ret);
    178 }
    179 
    180 updateCacheSizeAndFiles();
    181 
    182 jQuery('#GThumbAction button').tipTip({'delay' : 0, 'fadeIn' : 200, 'fadeOut' : 200});
     149        loader.add( data.urls );
     150        if (data.next_page) {
     151                if (loader.pause() || loader.remaining() > 100) {
     152                        pending_next_page = data.next_page;
     153                }
     154                else {
     155                        getUrls(data.next_page);
     156                }
     157        }
     158}
     159
     160function wsError() {
     161        urlDfd.reject();
     162}
     163
     164function updateStats() {
     165        jQuery("#loaded").text( loader.loaded );
     166        jQuery("#errors").text( loader.errors );
     167        jQuery("#remaining").text( loader.remaining() );
     168}
     169
     170function loaderChanged(type, img) {
     171        updateStats();
     172        if (img) {
     173                if (type==="load") {
     174                        var now = jQuery.now();
     175                        if (now - last_image_show_time > 3000) {
     176                                last_image_show_time = now;
     177                                var h=img.height, url=img.src;
     178                                jQuery("#feedbackWrap").hide("slide", {direction:'down'}, function() {
     179                                        last_image_show_time = jQuery.now();
     180                                        if (h > 300 )
     181                                                jQuery("#feedbackImg").attr("height", 300);
     182                                        else
     183                                                jQuery("#feedbackImg").removeAttr("height");
     184                                        jQuery("#feedbackImg").attr("src", url);
     185                                        jQuery("#feedbackWrap").show("slide", {direction:'up'} );
     186                                        } );
     187                        }
     188                }
     189                else {
     190                        jQuery("#errorList").prepend( '<a href="'+img.src+'">'+img.src+'</a>' + "<br>");
     191                }
     192        }
     193        if (pending_next_page && 100 > loader.remaining() )     {
     194                getUrls(pending_next_page);
     195                pending_next_page = null;
     196        }
     197        else if (loader.remaining() == 0 && (urlDfd.isResolved() || urlDfd.isRejected()))       {
     198                allDoneDfd.resolve();
     199        }
     200}
    183201{/literal}{/footer_script}
  • extensions/GThumb/template/gthumb.tpl

    r13579 r13652  
    11{if !empty($thumbnails)}
    2 {strip}{foreach from=$thumbnails item=thumbnail}
     2{foreach from=$thumbnails item=thumbnail}
     3{assign var=derivative value=$pwg->derivative($GThumb_derivative_params, $thumbnail.src_image)}
    34<li class="gthumb">
    45  <a href="{$thumbnail.URL}">
    5     <img id="gt{$thumbnail.ID}" class="thumbnail" src="{$thumbnail.TN_SRC}" alt="{$thumbnail.TN_ALT}" title="{$thumbnail.TN_TITLE}"
    6          width="{$thumbnail.TN_WIDTH}" height="{$thumbnail.TN_HEIGHT}" {if empty($thumbnail.TN_SRC)}style="display:none;"{/if}>
     6    <img class="thumbnail" {if !$derivative->is_cached()}data-{/if}src="{$derivative->get_url()}" alt="{$thumbnail.TN_ALT}" title="{$thumbnail.TN_TITLE}" {$derivative->get_size_htm()}>
    77  </a>
    88</li>
    9 {/foreach}{/strip}
     9{/foreach}
    1010
    1111{combine_css path="plugins/GThumb/template/gthumb.css"}
    12 {combine_script id='jquery.ajaxmanager' path='themes/default/js/plugins/jquery.ajaxmanager.js' load="footer"}
     12{combine_script id='jquery.ajaxmanager' path='themes/default/js/plugins/jquery.ajaxmanager.js' load='footer'}
     13{combine_script id='thumbnails.loader' path='themes/default/js/thumbnails.loader.js' require='jquery.ajaxmanager' load='footer'}
    1314{combine_script id='jquery.ba-resize' path='plugins/GThumb/js/jquery.ba-resize.min.js' load="footer"}
    14 {combine_script id='gthumb' require='jquery,jquery.ajaxmanager,jquery.ba-resize' path='plugins/GThumb/js/gthumb.js' load="footer"}
     15{combine_script id='gthumb' require='jquery,jquery.ba-resize' path='plugins/GThumb/js/gthumb.js' load="footer"}
    1516
    1617{footer_script require="gthumb"}
    17 GThumb.root = '{$ROOT_URL}';
    1818GThumb.max_height = {$GThumb.height};
    1919GThumb.margin = {$GThumb.margin};
    2020GThumb.method = '{$GThumb.method}';
    2121
    22 {if isset($big_thumb)}
    23 GThumb.small_thumb = {ldelim}id:{$small_thumb.id},src:'{$small_thumb.src}',width:{$small_thumb.width},height:{$small_thumb.height}{rdelim};
    24 GThumb.big_thumb = {ldelim}id:{$big_thumb.id},src:'{$big_thumb.src}',width:{$big_thumb.width},height:{$big_thumb.height}{rdelim};
     22{if isset($GThumb_big)}
     23{assign var=gt_size value=$GThumb_big->get_size()}
     24GThumb.big_thumb = {ldelim}id:{$GThumb_big->src_image->id},src:'{$GThumb_big->get_url()}',width:{$gt_size[0]},height:{$gt_size[1]}{rdelim};
    2525{/if}
    2626
Note: See TracChangeset for help on using the changeset viewer.