Changeset 12879 for trunk/admin


Ignore:
Timestamp:
Jan 12, 2012, 10:37:28 PM (12 years ago)
Author:
plg
Message:

feature 2548, multiple size:

  • adapt the upload script
  • remove the resize settings screen
  • add a new screen [Administration > Configuration > Options > Photo Sizes] with the ability to resize original after upload
Location:
trunk/admin
Files:
2 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/batch_manager_global.php

    r12831 r12879  
    3434
    3535include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
    36 include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');
    37 
    38 $upload_form_config = get_upload_form_config();
    39 foreach ($upload_form_config as $param_shortname => $param)
    40 {
    41   $param_name = 'upload_form_'.$param_shortname;
    42   $form_values[$param_shortname] = $conf[$param_name];
    43 }
    4436
    4537// +-----------------------------------------------------------------------+
     
    464456    'selection' => $collection,
    465457    'all_elements' => $page['cat_elements_id'],
    466     'upload_form_settings' => $form_values,
    467458    'U_DISPLAY'=>$base_url.get_query_string_diff(array('display')),
    468459    'F_ACTION'=>$base_url.get_query_string_diff(array('cat')),
  • trunk/admin/configuration.php

    r12872 r12879  
    2828
    2929include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
     30include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');
    3031include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
    3132
     
    5455    'allow_user_customization',
    5556   );
     57
     58$sizes_checkboxes = array(
     59    'original_resize',
     60  );
    5661
    5762$history_checkboxes = array(
     
    183188      break;
    184189    }
     190    case 'sizes' :
     191    {
     192      $fields = array(
     193        'original_resize',
     194        'original_resize_maxwidth',
     195        'original_resize_maxheight',
     196        'original_resize_quality',
     197        );
     198
     199      $updates = array();
     200     
     201      foreach ($fields as $field)
     202      {
     203        $value = !empty($_POST[$field]) ? $_POST[$field] : null;
     204        $form_values[$field] = $value;
     205        $updates[$field] = $value;
     206      }
     207
     208      save_upload_form_config($updates, $page['errors']);
     209 
     210      if (count($page['errors']) == 0)
     211      {
     212        array_push(
     213          $page['infos'],
     214          l10n('Your configuration settings are saved')
     215          );
     216      }
     217
     218      break;
     219    }
    185220    case 'history' :
    186221    {
     
    229264
    230265  // updating configuration if no error found
    231   if (count($page['errors']) == 0)
     266  if ('sizes' != $page['section'] and count($page['errors']) == 0)
    232267  {
    233268    //echo '<pre>'; print_r($_POST); echo '</pre>';
     
    269304// TabSheet initialization
    270305$tabsheet->add('main', l10n('Main'), $conf_link.'main');
     306$tabsheet->add('sizes', l10n('Photo Sizes'), $conf_link.'sizes');
    271307$tabsheet->add('display', l10n('Display'), $conf_link.'display');
    272308$tabsheet->add('history', l10n('History'), $conf_link.'history');
     
    440476    break;
    441477  }
     478  case 'sizes' :
     479  {
     480    $template->assign(
     481      'sizes',
     482      array(
     483        'original_resize_maxwidth' => $conf['original_resize_maxwidth'],
     484        'original_resize_maxheight' => $conf['original_resize_maxheight'],
     485        'original_resize_quality' => $conf['original_resize_quality'],
     486        )
     487      );
     488   
     489    foreach ($sizes_checkboxes as $checkbox)
     490    {
     491      $template->append(
     492        'sizes',
     493        array(
     494          $checkbox => $conf[$checkbox]
     495          ),
     496        true
     497        );
     498    }
     499
     500    break;
     501  }
    442502}
    443503
  • trunk/admin/include/functions_upload.inc.php

    r12831 r12879  
    3333  // default configuration for upload
    3434  $upload_form_config = array(
    35     'websize_resize' => array(
    36       'default' => true,
    37       'can_be_null' => false,
    38       ),
    39    
    40     'websize_maxwidth' => array(
    41       'default' => 800,
    42       'min' => 100,
    43       'max' => 1600,
    44       'pattern' => '/^\d+$/',
    45       'can_be_null' => true,
    46       'error_message' => l10n('The websize maximum width must be a number between %d and %d'),
    47       ),
    48  
    49     'websize_maxheight' => array(
    50       'default' => 600,
    51       'min' => 100,
    52       'max' => 1200,
    53       'pattern' => '/^\d+$/',
    54       'can_be_null' => true,
    55       'error_message' => l10n('The websize maximum height must be a number between %d and %d'),
    56       ),
    57  
    58     'websize_quality' => array(
    59       'default' => 95,
    60       'min' => 50,
    61       'max' => 100,
    62       'pattern' => '/^\d+$/',
    63       'can_be_null' => false,
    64       'error_message' => l10n('The websize image quality must be a number between %d and %d'),
    65       ),
    66  
    67     'thumb_maxwidth' => array(
    68       'default' => 128,
    69       'min' => 50,
    70       'max' => 300,
    71       'pattern' => '/^\d+$/',
    72       'can_be_null' => false,
    73       'error_message' => l10n('The thumbnail maximum width must be a number between %d and %d'),
    74       ),
    75  
    76     'thumb_maxheight' => array(
    77       'default' => 96,
    78       'min' => 50,
    79       'max' => 300,
    80       'pattern' => '/^\d+$/',
    81       'can_be_null' => false,
    82       'error_message' => l10n('The thumbnail maximum height must be a number between %d and %d'),
    83       ),
    84  
    85     'thumb_quality' => array(
    86       'default' => 95,
    87       'min' => 50,
    88       'max' => 100,
    89       'pattern' => '/^\d+$/',
    90       'can_be_null' => false,
    91       'error_message' => l10n('The thumbnail image quality must be a number between %d and %d'),
    92       ),
    93 
    94     'thumb_crop' => array(
     35    'original_resize' => array(
    9536      'default' => false,
    9637      'can_be_null' => false,
    9738      ),
    98 
    99     'thumb_follow_orientation' => array(
    100       'default' => true,
    101       'can_be_null' => false,
    102       ),
    103  
    104     'hd_keep' => array(
    105       'default' => true,
    106       'can_be_null' => false,
    107       ),
    108  
    109     'hd_resize' => array(
    110       'default' => false,
    111       'can_be_null' => false,
    112       ),
    113  
    114     'hd_maxwidth' => array(
     39 
     40    'original_resize_maxwidth' => array(
    11541      'default' => 2000,
    11642      'min' => 500,
     
    11844      'pattern' => '/^\d+$/',
    11945      'can_be_null' => false,
    120       'error_message' => l10n('The high definition maximum width must be a number between %d and %d'),
     46      'error_message' => l10n('The original maximum width must be a number between %d and %d'),
    12147      ),
    12248 
    123     'hd_maxheight' => array(
     49    'original_resize_maxheight' => array(
    12450      'default' => 2000,
    125       'min' => 500,
     51      'min' => 300,
    12652      'max' => 20000,
    12753      'pattern' => '/^\d+$/',
    12854      'can_be_null' => false,
    129       'error_message' => l10n('The high definition maximum height must be a number between %d and %d'),
     55      'error_message' => l10n('The original maximum height must be a number between %d and %d'),
    13056      ),
    13157 
    132     'hd_quality' => array(
     58    'original_resize_quality' => array(
    13359      'default' => 95,
    13460      'min' => 50,
    135       'max' => 100,
     61      'max' => 98,
    13662      'pattern' => '/^\d+$/',
    13763      'can_be_null' => false,
    138       'error_message' => l10n('The high definition image quality must be a number between %d and %d'),
     64      'error_message' => l10n('The original image quality must be a number between %d and %d'),
    13965      ),
    14066    );
     
    17197
    17298      $updates[] = array(
    173         'param' => 'upload_form_'.$field,
     99        'param' => $field,
    174100        'value' => boolean_to_string($value)
    175101        );
     
    178104    {
    179105      $updates[] = array(
    180         'param' => 'upload_form_'.$field,
     106        'param' => $field,
    181107        'value' => 'false'
    182108        );
     
    191117      {
    192118         $updates[] = array(
    193           'param' => 'upload_form_'.$field,
     119          'param' => $field,
    194120          'value' => $value
    195121          );
     
    227153function add_uploaded_file($source_filepath, $original_filename=null, $categories=null, $level=null, $image_id=null)
    228154{
    229   // Here is the plan
    230   //
    231155  // 1) move uploaded file to upload/2010/01/22/20100122003814-449ada00.jpg
    232156  //
    233   // 2) if taller than max_height or wider than max_width, move to pwg_high
    234   //    + web sized creation
     157  // 2) keep/resize original
    235158  //
    236   // 3) thumbnail creation from web sized
    237   //
    238   // 4) register in database
     159  // 3) register in database
    239160 
    240161  // TODO
     
    248169  if (isset($image_id))
    249170  {
    250     // we are performing an update
     171    // this photo already exists, we update it
    251172    $query = '
    252173SELECT
     
    317238  }
    318239
    319   if ($conf['upload_form_websize_resize']
    320       and need_resize($file_path, $conf['upload_form_websize_maxwidth'], $conf['upload_form_websize_maxheight']))
    321   {
    322     $high_path = file_path_for_type($file_path, 'high');
    323     $high_dir = dirname($high_path);
    324     prepare_directory($high_dir);
    325    
    326     rename($file_path, $high_path);
    327     $high_infos = pwg_image_infos($high_path);
    328    
    329     $img = new pwg_image($high_path);
    330 
    331     $img->pwg_resize(
    332       $file_path,
    333       $conf['upload_form_websize_maxwidth'],
    334       $conf['upload_form_websize_maxheight'],
    335       $conf['upload_form_websize_quality'],
    336       $conf['upload_form_automatic_rotation'],
    337       false
    338       );
    339 
    340     if ($img->library != 'gd')
    341     {
    342       if ($conf['upload_form_hd_keep'])
     240  if (pwg_image::get_library() != 'gd')
     241  {
     242    if ($conf['original_resize'])
     243    {
     244      $need_resize = need_resize($file_path, $conf['original_resize_maxwidth'], $conf['original_resize_maxheight']);
     245     
     246      if ($need_resize)
    343247      {
    344         if ($conf['upload_form_hd_resize'])
    345         {
    346           $need_resize = need_resize($high_path, $conf['upload_form_hd_maxwidth'], $conf['upload_form_hd_maxheight']);
     248        $img = new pwg_image($file_path);
     249           
     250        $img->pwg_resize(
     251          $file_path,
     252          $conf['original_resize_maxwidth'],
     253          $conf['original_resize_maxheight'],
     254          $conf['original_resize_quality'],
     255          $conf['upload_form_automatic_rotation'],
     256          false
     257          );
    347258       
    348           if ($need_resize)
    349           {
    350             $img->pwg_resize(
    351               $high_path,
    352               $conf['upload_form_hd_maxwidth'],
    353               $conf['upload_form_hd_maxheight'],
    354               $conf['upload_form_hd_quality'],
    355               $conf['upload_form_automatic_rotation'],
    356               false
    357               );
    358             $high_infos = pwg_image_infos($high_path);
    359           }
    360         }
     259        $img->destroy();
    361260      }
    362       else
    363       {
    364         unlink($high_path);
    365         $high_infos = null;
    366       }
    367     }
    368     $img->destroy();
     261    }
    369262  }
    370263
    371264  $file_infos = pwg_image_infos($file_path);
    372265 
    373   $thumb_path = file_path_for_type($file_path, 'thumb');
    374   $thumb_dir = dirname($thumb_path);
    375   prepare_directory($thumb_dir);
    376 
    377   $img = new pwg_image($file_path);
    378   $img->pwg_resize(
    379     $thumb_path,
    380     $conf['upload_form_thumb_maxwidth'],
    381     $conf['upload_form_thumb_maxheight'],
    382     $conf['upload_form_thumb_quality'],
    383     false,
    384     true,
    385     $conf['upload_form_thumb_crop'],
    386     $conf['upload_form_thumb_follow_orientation']
    387     );
    388   $img->destroy();
    389  
    390   $thumb_infos = pwg_image_infos($thumb_path);
    391 
    392266  if (isset($image_id))
    393267  {
    394268    $update = array(
    395       'id' => $image_id,
    396269      'file' => pwg_db_real_escape_string(isset($original_filename) ? $original_filename : basename($file_path)),
    397270      'filesize' => $file_infos['filesize'],
     
    402275      );
    403276   
    404     if (isset($high_infos))
    405     {
    406       $update['has_high'] = 'true';
    407       $update['high_filesize'] = $high_infos['filesize'];
    408       $update['high_width'] = $high_infos['width'];
    409       $update['high_height'] = $high_infos['height'];
    410     }
    411     else
    412     {
    413       $update['has_high'] = 'false';
    414       $update['high_filesize'] = null;
    415       $update['high_width'] = null;
    416       $update['high_height'] = null;
    417     }
    418 
    419277    if (isset($level))
    420278    {
     
    422280    }
    423281
    424     mass_updates(
     282    single_update(
    425283      IMAGES_TABLE,
    426       array(
    427         'primary' => array('id'),
    428         'update' => array_keys($update)
    429         ),
    430       array($update)
     284      $update,
     285      array('id' => $image_id)
    431286      );
    432287  }
     
    458313      $insert['level'] = $level;
    459314    }
    460  
    461     mass_inserts(
    462       IMAGES_TABLE,
    463       array_keys($insert),
    464       array($insert)
    465       );
     315
     316    single_insert(IMAGES_TABLE, $insert);
    466317 
    467318    $image_id = pwg_db_insert_id(IMAGES_TABLE);
  • trunk/admin/include/photos_add_direct_process.inc.php

    r11975 r12879  
    203203    $thumbnail['file'] = $image_infos['file'];
    204204   
    205     $thumbnail['src'] = get_thumbnail_location(
    206       array(
    207         'path' => $image_infos['path'],
    208         'tn_ext' => $image_infos['tn_ext'],
    209         )
    210       );
     205    $thumbnail['src'] = DerivativeImage::thumb_url($image_infos);
    211206
    212207    // TODO: when implementing this plugin in Piwigo core, we should have
  • trunk/admin/include/uploadify/uploadify.php

    r11963 r12879  
    7373$image_infos = pwg_db_fetch_assoc(pwg_query($query));
    7474
    75 $thumbnail_url = preg_replace('#^'.PHPWG_ROOT_PATH.'#', './', get_thumbnail_url($image_infos));
     75$thumbnail_url = preg_replace('#^'.PHPWG_ROOT_PATH.'#', './', DerivativeImage::thumb_url($image_infos));
    7676
    7777$return = array(
  • trunk/admin/photos_add.php

    r10653 r12879  
    5555    'code' => 'direct',
    5656    'label' => l10n('Upload Photos'),
    57     ),
    58   array(
    59     'code' => 'settings',
    60     'label' => l10n('Settings'),
    6157    ),
    6258  array(
  • trunk/admin/themes/default/template/configuration.tpl

    r12878 r12879  
    248248</div> <!-- configContent -->
    249249
     250{if isset($sizes)}
     251
     252{footer_script}{literal}
     253jQuery(document).ready(function(){
     254  function toggleResizeFields(prefix) {
     255    var checkbox = jQuery("#"+prefix+"_resize");
     256    var needToggle = jQuery("input[name^="+prefix+"_]").not(checkbox).parents('tr');
     257
     258    if (jQuery(checkbox).is(':checked')) {
     259      needToggle.show();
     260    }
     261    else {
     262      needToggle.hide();
     263    }
     264  }
     265
     266  toggleResizeFields("original");
     267  jQuery("#original_resize").click(function () {toggleResizeFields("original")});
     268});
     269{/literal}{/footer_script}
     270
     271<fieldset id="sizesConf">
     272  <legend>{'Original Size'|@translate}</legend>
     273
     274  <table>
     275    <tr>
     276      <th><label for="original_resize">{'Resize after upload'|@translate}</label></th>
     277      <td><input type="checkbox" name="original_resize" id="original_resize" {if ($sizes.original_resize)}checked="checked"{/if}></td>
     278    </tr>
     279    <tr>
     280      <th>{'Maximum Width'|@translate}</th>
     281      <td><input type="text" name="original_resize_maxwidth" value="{$sizes.original_resize_maxwidth}" size="4" maxlength="4"> {'pixels'|@translate}</td>
     282    </tr>
     283    <tr>
     284      <th>{'Maximum Height'|@translate}</th>
     285      <td><input type="text" name="original_resize_maxheight" value="{$sizes.original_resize_maxheight}" size="4" maxlength="4"> {'pixels'|@translate}</td>
     286    </tr>
     287    <tr>
     288      <th>{'Image Quality'|@translate}</th>
     289      <td><input type="text" name="original_resize_quality" value="{$sizes.original_resize_quality}" size="3" maxlength="3"> %</td>
     290    </tr>
     291  </table>
     292
     293</fieldset>
     294{/if}
     295
    250296{if isset($default)}
    251297{$PROFILE_CONTENT}
     
    446492{if !isset($default)}
    447493  <p>
    448     <input class="submit" type="submit" name="submit" value="{'Submit'|@translate}">
     494    <input class="submit" type="submit" name="submit" value="{'Save Settings'|@translate}">
    449495    <input class="submit" type="reset" name="reset" value="{'Reset'|@translate}">
    450496  </p>
Note: See TracChangeset for help on using the changeset viewer.