Changeset 10441 for extensions


Ignore:
Timestamp:
Apr 17, 2011, 11:17:41 AM (13 years ago)
Author:
patdenice
Message:

Compatible with piwigo 2.2

Location:
extensions/Ajax_Thumbnailer
Files:
2 added
1 deleted
2 edited
1 copied

Legend:

Unmodified
Added
Removed
  • extensions/Ajax_Thumbnailer

    • Property svn:ignore set to
      img
  • extensions/Ajax_Thumbnailer/ajaxThumbnailer.tpl

    r10438 r10441  
    1 <script type="text/javascript">
    2         var path="{$plugin.path}";
    3 </script>
    4 <script type="text/javascript" src="{$plugin.path}/admin/js/jquery.ajaxmanager.js"></script>
    5 <script type="text/javascript" src="{$plugin.path}/admin/js/thumbnailer.js"></script>
     1{combine_script id='jquery.ajaxmanager' load='footer' path='themes/default/js/plugins/jquery.ajaxmanager.js'}
     2
     3{footer_script}{literal}
     4var queuedManager = $.manageAjax.create('queued', {
     5        queue: true, 
     6        cacheResponse: false,
     7        maxRequests: 3
     8});
     9
     10function processThumbs(width,height,gd_version) {
     11  var square=$('input[name="square"]').attr('checked');
     12  var done=0;
     13        $('tr.nothumb').each(function() {
     14                var file=$(this).find('td.filepath').text();
     15                $(this).find('td.thumbpic').html('<img src="plugins/Ajax_Thumbnailer/ajax-loader.gif">');
     16                var td=this;
     17                queuedManager.add({
     18                        type: 'GET',
     19                        url: 'ws.php',
     20                        data: {method: 'pwg.images.createThumbnail',picture:file,format:'json',width: width,height: height, gd_version: gd_version, square: square},
     21                        dataType: 'json',
     22                        success: (function(row) { return function(data) {
     23                                        if (data.stat =='ok') {
     24                                                        $(row).find('td.thumbpic').html('<img src="'+data.result.tn_file+'"/>');
     25                                                        $(row).find('td.thumbdim').html(""+data.result.tn_width+"X"+data.result.tn_height);
     26                                                        $(row).find('td.thumbgentime').html(""+data.result.tn_time);
     27                                                        $(row).find('td.thumbsize').html(""+data.result.tn_size);
     28                                                        $(row).removeClass("nothumb");
     29                                                } else {
     30                                                        $(row).find('td.thumbpic').html('#ERR#'+data.err+"# : "+data.message);
     31                                                        $(row).removeClass("nothumb");
     32                                                        $(row).addClass("error");
     33                                                }
     34          if (done++ == 20) {
     35              $('tr.item:not(.nothumb)').remove();
     36              done = 0;
     37            }
     38                                        };})(td)
     39                        });
     40        });
     41}
     42
     43$(document).ready(function(){
     44  $('input#proceed').click (function () {
     45    var width = $('#width')[0].value;
     46    var height = $('#height')[0].value;
     47    var gd_version=$("input[@name='gd']:checked").val();
     48    $("input:not(.nodisable)").attr("disabled",true);
     49
     50   
     51    processThumbs(width,height,gd_version);
     52  });
     53
     54  $('input#cancel').click (function () {
     55    queuedManager.clear();
     56    queuedManager.abort();
     57    $("input:not(.nodisable)").attr("disabled",false);
     58    $('tr.nothumb td.thumbpic').html("&nbsp;");
     59   
     60  });
     61
     62  $('input#clear').click (function () {
     63    $('tr.item:not(.nothumb)').remove();
     64  });
     65});
     66{/literal}{/footer_script}
    667
    768<div class="titrePage">
    8   <h2>{'title_thumbnails'|@translate}</h2>
     69  <h2>{'Thumbnail creation'|@translate}</h2>
    970</div>
    10 
    1171
    1272{if isset($params) }
     
    1474
    1575  <fieldset>
    16     <legend>{'tn_params_title'|@translate}</legend>
     76    <legend>{'Thumbnail creation'|@translate}</legend>
    1777
    1878    <ul>
    1979      <li>
    20         <span class="property">{'tn_params_GD'|@translate}</span>
     80        <span class="property">{'GD version'|@translate}</span>
    2181        <label>
    2282          <input type="radio" name="gd" value="2" {if $params.GD_SELECTED==2}checked="checked"{/if}>2.x
     
    51111{/if} {*isset params*}
    52112
    53 {if !empty($wo_thumbnails) }
    54 <div class="admin">{$TOTAL_NB_REMAINING} {'tn_alone_title'|@translate}</div>
     113{if !empty($remainings) }
     114<div class="admin">{$TOTAL_NB_REMAINING} {'Number of thumbnails to create'|@translate}</div>
    55115<table style="width:100%;">
    56116  <tr class="throw">
    57117    <td>&nbsp;</td>
    58118    <td style="width:60%;">{'Path'|@translate}</td>
    59     <td>{'filesize'|@translate}</td>
     119    <td>{'Filesize'|@translate}</td>
    60120    <td>{'Dimensions'|@translate}</td>
    61     <td>{'thumbnail'|@translate}</td>
    62     <td>{'tn_results_gen_time'|@translate}</td>
    63     <td>{'filesize'|@translate}</td>
     121    <td>{'Thumbnail'|@translate}</td>
     122    <td>{'generated in'|@translate}</td>
     123    <td>{'Filesize'|@translate}</td>
    64124    <td>{'Dimensions'|@translate}</td>
    65125  </tr>
    66   {foreach from=$wo_thumbnails item=elt name=remain_loop}
     126  {foreach from=$remainings item=elt name=remain_loop}
    67127  <tr class="{if $smarty.foreach.remain_loop.index is odd}row1{else}row2{/if} nothumb item" id="th_{$smarty.foreach.remain_loop.iteration}">
    68128    <td>{$smarty.foreach.remain_loop.iteration}</td>
     
    78138</table>
    79139{else}
    80 <div style="text-align:center;font-weight:bold;margin:10px;"> [ {'tn_no_missing'|@translate} ]</div>
     140<div style="text-align:center;font-weight:bold;margin:10px;"> [ {'No missing thumbnail'|@translate} ]</div>
    81141{/if}
  • extensions/Ajax_Thumbnailer/main.inc.php

    r4549 r10441  
    99*/
    1010
    11 ini_set('error_reporting', E_ALL);
    12 ini_set('display_errors', true);
    13 
    1411if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    1512
    16 class AjaxThumbnailer
     13add_event_handler('ws_add_methods', 'add_thumbnail_create_method');
     14
     15function add_thumbnail_create_method($arr)
    1716{
    18         /* This function is almost the same as the ont in admin/thumbnail.php , tuned
    19                 for web-service purposes */
    20         function RatioResizeImg($path, $newWidth, $newHeight, $tn_ext,$gd_version=2) {
    21                 global $conf, $lang, $page;
    22                
    23                 $starttime = get_moment();
     17  include_once('ws_functions.inc.php');
     18}
    2419
    25                 if (!function_exists('gd_info'))
    26                         return new PwgError(WS_ERR_INVALID_PARAM,  'no gd');
     20add_event_handler('loc_begin_admin', 'ajaxThumbnailer_admin_modify');
    2721
    28                 if (!file_exists($path))
    29                         return new PwgError(WS_ERR_INVALID_PARAM,  'file not found');
     22function ajaxThumbnailer_admin_modify()
     23{
     24  global $page, $template;
    3025
    31                 $filename = basename($path);
    32                 $dirname = dirname($path);
     26  if (isset($_GET['page']) and $_GET['page'] == 'thumbnail')
     27  {
     28    load_language('plugin.lang', dirname(__FILE__).'/');
     29    $template->set_extent(dirname(__FILE__).'/AjaxThumbnailer.tpl', 'thumbnail');
     30  }
     31}
    3332
    34                 // extension of the picture filename
    35                 $extension = get_extension($filename);
    36 
    37                 if (in_array($extension, array('jpg', 'JPG', 'jpeg', 'JPEG'))) {
    38                         $srcImage = @imagecreatefromjpeg($path);
    39                 }
    40                 elseif ($extension == 'png' or $extension == 'PNG') {
    41                         $srcImage = @imagecreatefrompng($path);
    42                 } else {
    43                         unset($extension);
    44                 }
    45 
    46                 if ( isset( $srcImage ) ) {
    47                         // width/height
    48                         $srcWidth    = imagesx( $srcImage );
    49                         $srcHeight   = imagesy( $srcImage );
    50                         $ratioWidth  = $srcWidth/$newWidth;
    51                         $ratioHeight = $srcHeight/$newHeight;
    52 
    53                         // maximal size exceeded ?
    54                         if ( ( $ratioWidth > 1 ) or ( $ratioHeight > 1 ) ) {
    55                                 if ( $ratioWidth < $ratioHeight) {
    56                                         $destWidth = $srcWidth/$ratioHeight;
    57                                         $destHeight = $newHeight;
    58                                 } else {
    59                                         $destWidth = $newWidth;
    60                                         $destHeight = $srcHeight/$ratioWidth;
    61                                 }
    62                         } else {
    63                                 $destWidth = $srcWidth;
    64                                 $destHeight = $srcHeight;
    65                         }
    66                         // according to the GD version installed on the server
    67                         if ( $gd_version == 2 ) {
    68                                 // GD 2.0 or more recent -> good results (but slower)
    69                                 $destImage = imagecreatetruecolor( $destWidth, $destHeight);
    70                                 imagecopyresampled( $destImage, $srcImage, 0, 0, 0, 0,
    71                                         $destWidth,$destHeight,$srcWidth,$srcHeight );
    72                         } else {
    73                                 // GD prior to version  2 -> pretty bad results :-/ (but fast)
    74                                 $destImage = imagecreate( $destWidth, $destHeight);
    75                                 imagecopyresized( $destImage, $srcImage, 0, 0, 0, 0,
    76                                         $destWidth,$destHeight,$srcWidth,$srcHeight );
    77                         }
    78 
    79                         if (($tndir = mkget_thumbnail_dir($dirname)) == false) {
    80                                 return new PwgError(WS_ERR_INVALID_PARAM,  '['.$tndir.'] : '.l10n('no_write_access'));
    81                         }
    82 
    83                         $dest_file = $tndir.'/'.$conf['prefix_thumbnail'];
    84                         $dest_file.= get_filename_wo_extension($filename);
    85                         $dest_file.= '.'.$tn_ext;
    86 
    87                         // creation and backup of final picture
    88                         if (!is_writable($tndir))
    89                                 return new PwgError(WS_ERR_INVALID_PARAM,  '['.$tndir.'] : '.l10n('no_write_access'));
    90                                
    91                         imagejpeg($destImage, $dest_file, $conf['tn_compression_level']);
    92                         // freeing memory ressources
    93                         imagedestroy( $srcImage );
    94                         imagedestroy( $destImage );
    95 
    96                         list($tn_width, $tn_height) = getimagesize($dest_file);
    97                         $tn_size = floor(filesize($dest_file) / 1024).' KB';
    98 
    99                         $endtime = get_moment();
    100                        
    101                         $info = array( 'path'      => $path,
    102                         'tn_file'   => $dest_file,
    103                         'tn_width'  => $tn_width,
    104                         'tn_height' => $tn_height,
    105                         'tn_size'   => $tn_size,
    106                         'tn_time'       => number_format(($endtime - $starttime) * 1000, 2, '.', ' ').' ms');
    107                         return $info;
    108                 } else {
    109                         // error
    110                         $err=l10n('tn_no_support');
    111                         if ( isset( $extension ) )
    112                                 $err .= l10n('tn_format').' '.$extension;
    113                         else
    114                                 $err .= l10n('tn_thisformat');
    115                         return new PwgError(WS_ERR_INVALID_PARAM, $err);
    116                 }
    117         }
    118 
    119         function plugin_admin_menu($menu) {
    120         array_push($menu,
    121             array(
    122                 'NAME' => 'Ajax Thumbnailer',
    123                 'URL' => get_admin_plugin_menu_link(dirname(__FILE__).'/admin/thumbnailer_admin.php')
    124             )
    125         );
    126         return $menu;
    127     }
    128 
    129         function ws_methods($arr) {
    130                 $service = &$arr[0];
    131                 $service->addMethod('pwg.thumbnail.create', array($this,'create_thumb'),
    132                   array(
    133                         'picture'=>array(),
    134                         'width'=>array('default'=>"128"),
    135                         'height'=>array('default'=>"128"),
    136                         'ext'=>array('default'=>"jpg")
    137                   ),
    138                   'Creates a thumbnail for a given image,
    139                 <br><b>picture</b> is the name of the picture to create thumbnail from.'
    140                 );
    141                
    142         }
    143        
    144         function create_thumb($params, $service) {
    145                 $picture = $params['picture'];
    146                 $width = (integer)$params['width'];
    147                 $height = (integer)$params['height'];
    148                 $gd_version = (integer)$params['gd_version'];           
    149                 $ext =$params['ext'];
    150                 return $this->RatioResizeImg($picture,$width,$height,$ext,$gd_version);
    151         }
    152        
    153 }
    154 $obj = new AjaxThumbnailer();
    155 
    156 add_event_handler('ws_add_methods', array(&$obj, 'ws_methods'));
    157 add_event_handler('get_admin_plugin_menu_links', array(&$obj, 'plugin_admin_menu') );
    158 set_plugin_data($plugin['id'], $obj);
     33//add_event_handler('get_admin_plugin_menu_links', 'ajaxThumbnailer_admin_menu');
    15934
    16035?>
Note: See TracChangeset for help on using the changeset viewer.