Changeset 12417 for extensions


Ignore:
Timestamp:
Oct 12, 2011, 8:40:15 PM (13 years ago)
Author:
Dsls
Message:

rotateImage v0.3 :

  • thumbnails are correctly refreshed
  • strengthened ws
  • small tuning on form display
  • it is now possible to select whether HD should be rotated or not
Location:
extensions/rotateImage
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • extensions/rotateImage/language/fr_FR/plugin.lang.php

    r12409 r12417  
    22$lang['Images rotation in progress...'] = 'Rotation des images en cours...';
    33$lang['Rotate images'] = 'Pivoter les images';
    4 $lang['Rotate 90° right'] = 'Rotation de 90° à droite';
    5 $lang['Rotate 90° left'] = 'Rotation de 90° à gauche';
    6 $lang['Rotate 180°'] = 'Rotation de 180°';
    7 
     4$lang['Angle'] = 'Angle';
     5$lang['Also rotate HD image'] = 'Pivoter aussi l\'image HD';
     6$lang['90° right'] = '90° à droite';
     7$lang['90° left'] = '90° à gauche';
     8$lang['180°'] = '180°';
    89?>
  • extensions/rotateImage/main.inc.php

    r12410 r12417  
    22/*
    33Plugin Name: Rotate Image
    4 Version: 0.2
     4Version: 0.3
    55Description: enables to rotate images in batch processing
    66Plugin URI: http://fr.piwigo.org/ext/extension_view.php?eid=578
     
    1010add_event_handler('loc_begin_element_set_global', 'rotate_image_set_template_data');
    1111add_event_handler('ws_add_methods', 'add_image_rotate_method');
     12add_event_handler('element_set_global_action', 'rotate_image_element_action', 50, 2);
    1213
    1314function add_image_rotate_method($arr)
    1415{
    15   include_once('ws_functions.inc.php');
     16 include_once('ws_functions.inc.php');
    1617}
    1718
    1819function rotate_image_set_template_data() {
    19         global $template,$lang;
    20     load_language('plugin.lang', dirname(__FILE__).'/');
    21         $template->set_filename('rotate_image', realpath(dirname(__FILE__).'/rotate_image.tpl'));
    22         $template->append('element_set_global_plugins_actions', array(
     20  global $template,$lang;
     21  load_language('plugin.lang', dirname(__FILE__).'/');
     22  $angles = array (
     23    array('value' => 90, 'name' => l10n('90° left')),
     24    array('value' => 270, 'name' => l10n('90° right')),
     25    array('value' => 180, 'name' => l10n('180°'))
     26  );
     27 
     28  $template->assign(array(
     29    'RI_PWG_TOKEN' => get_pwg_token(),
     30    'angles' => $angles,
     31    'angle_value' => 90
     32  ));
     33  $template->set_filename('rotate_image', realpath(dirname(__FILE__).'/rotate_image.tpl'));
     34  $template->append('element_set_global_plugins_actions', array(
    2335    'ID' => 'rotateImg',
    2436    'NAME' => l10n('Rotate images'),
    25     'CONTENT' => $template->parse('rotate_image', true),
    26     )
     37    'CONTENT' => $template->parse('rotate_image', true))
    2738  );
    2839}
    2940
    30 
     41function rotate_image_element_action($action, $collection) {
     42  global $template;
     43  if ($action == 'rotateImg') {
     44    //flush thumbnails links by regenerating ramdom ids to uris
     45    $template->delete_compiled_templates();
     46  }
     47}
    3148
    3249?>
  • extensions/rotateImage/rotate_image.tpl

    r12409 r12417  
    1 {footer_script}
     1{footer_script}
    22var rotateImagesMessage = "{'Images rotation in progress...'|@translate}";
    3 
     3var ri_pwg_token = '{$RI_PWG_TOKEN}';
    44{literal}
    55  jQuery('#applyAction').click(function(e) {
     
    1010    else if (jQuery('[name="selectAction"]').val() == 'rotateImg')
    1111    {
    12       angle = jQuery('input[name="rotate_angle"]:checked').val();
     12      angle = jQuery('select[name="rotate_angle"]').val();
    1313      e.stopPropagation();
    1414    }
     
    5555          format: 'json',
    5656          angle: angle,
     57          pwg_token: ri_pwg_token,
    5758          image_id: elements[i]
    5859        },
     
    6869
    6970<div id="rotate_image" class="bulkAction">
    70   <p>{'Select angle :'|@translate}</p>
    71   <label><input type="radio" name="rotate_angle" value="90" checked="checked"> {'Rotate 90° left'|@translate}</label>
    72   <label><input type="radio" name="rotate_angle" value="270"> {'Rotate 90° right'|@translate}</label>
    73   <label><input type="radio" name="rotate_angle" value="180"> {'Rotate 180°'|@translate}</label>
     71      <table style="margin-left:20px;">
     72        <tr>
     73          <th id="thumb_width_th">{'Angle'|@translate}</th>
     74          <td>
     75          <select name="rotate_angle">
     76            {foreach from=$angles item=angle}
     77              <option value="{$angle.value}" {if $saved_angle eq $angle.value}selected="selected"{/if}>{$angle.name}</option>
     78            {/foreach}
     79          </select>
     80          </td>
     81        </tr>
     82        <tr>
     83          <th><label for="rotate_hd">{'Also rotate HD image'|@translate}</label></th>
     84          <td><input type="checkbox" name="rotate_hd" id="rotate_hd" {if $upload_form_settings.thumb_crop}checked="checked"{/if}></td>
     85        </tr>
     86      </table>
    7487</div>
  • extensions/rotateImage/ws_functions.inc.php

    r12409 r12417  
    99  'image_id'=>array(),
    1010  'angle'=>array('default'=>"90"),
     11  'pwg_token' => array(),
     12  'rotate_hd' => array('default'=>0)
    1113  ),
    1214  'Rotates a given image'
     
    2527  }
    2628
     29  if (empty($params['pwg_token']) or get_pwg_token() != $params['pwg_token'])
     30  {
     31    return new PwgError(403, 'Invalid security token');
     32  }
     33
    2734  include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');
    2835  include_once(PHPWG_ROOT_PATH.'admin/include/image.class.php');
    2936  $image_id=(int)$params['image_id'];
    3037  $angle=(int)$params['angle'];
     38  $rotate_hd = (int) $params['rotate_hd'];
    3139  $query='
    3240SELECT id, path, tn_ext, has_high
     
    4957  $img->write($image_path);
    5058  update_metadata(array($image_id=>$image_path));
     59  if ($rotate_hd) {
     60    $sizes = array('thumb','high');
     61  } else {
     62    $sizes = array('thumb');
     63  }
    5164 
    52   foreach (array('thumb','high') as $size) {
     65  foreach ($sizes as $size) {
    5366    $resized_path = file_path_for_type($image_path,$size);
    5467    if (file_exists($resized_path)) {
     
    5972  }
    6073  return true;
    61  
    6274}
    6375
Note: See TracChangeset for help on using the changeset viewer.