Changeset 24623 for extensions


Ignore:
Timestamp:
Sep 25, 2013, 10:28:20 AM (11 years ago)
Author:
plg
Message:

ability to update the pwg_representative instead of the main file (for non picture files, see $confpicture_ext)

Location:
extensions/photo_update
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • extensions/photo_update/admin.php

    r16982 r24623  
    6969  else
    7070  {
    71     add_uploaded_file(
    72       $_FILES['photo_update']['tmp_name'],
    73       $_FILES['photo_update']['name'],
    74       null,
    75       null,
    76       $_GET['image_id']
    77       );
    78 
    79     $page['photo_update_refresh_thumbnail'] = true;
    80 
    81     array_push(
    82       $page['infos'],
    83       l10n('The photo was updated')
    84       );
     71    $file_to_update = 'main';
     72    if (isset($_POST['file_to_update']) and in_array($_POST['file_to_update'], array('main', 'representative')))
     73    {
     74      $file_to_update = $_POST['file_to_update'];
     75    }
     76
     77    $image_id = $_GET['image_id'];
     78     
     79    $query = '
     80SELECT
     81    id, path, representative_ext
     82  FROM '.IMAGES_TABLE.'
     83  WHERE id = '.$image_id.'
     84;';
     85    $result = pwg_query($query);
     86    $row = pwg_db_fetch_assoc($result);
     87
     88    if ('main' == $file_to_update)
     89    {
     90      add_uploaded_file(
     91        $_FILES['photo_update']['tmp_name'],
     92        $_FILES['photo_update']['name'],
     93        null,
     94        null,
     95        $_GET['image_id']
     96        );
     97     
     98      array_push(
     99        $page['infos'],
     100        l10n('The photo was updated')
     101        );
     102    }
     103   
     104    if ('representative' == $file_to_update)
     105    {
     106      $file_path = $row['path'];
     107
     108      // move the uploaded file to pwg_representative sub-directory
     109      $representative_file_path = dirname($file_path).'/pwg_representative/';     
     110      $representative_file_path.= get_filename_wo_extension(basename($file_path)).'.';
     111
     112      $old_representative_file_path = $representative_file_path.$row['representative_ext'];
     113
     114      $representative_ext = get_extension($_FILES['photo_update']['name']);
     115
     116      // in case we replace a *.jpg by *.png we have to safely remove the
     117      // *.jpg becase move_uploaded_file won't remove it
     118      if ($representative_ext != $row['representative_ext'])
     119      {
     120        @unlink($representative_file_path.$row['representative_ext']);
     121      }
     122     
     123      $representative_file_path.= $representative_ext;
     124
     125      prepare_directory(dirname($representative_file_path));
     126
     127      move_uploaded_file($_FILES['photo_update']['tmp_name'], $representative_file_path);
     128
     129      $file_infos = pwg_image_infos($representative_file_path);
     130     
     131      single_update(
     132        IMAGES_TABLE,
     133        array(
     134          'representative_ext' => $representative_ext,
     135          'width' => $file_infos['width'],
     136          'height' => $file_infos['height'],
     137          ),
     138        array('id' => $image_id)
     139        );
     140     
     141      array_push(
     142        $page['infos'],
     143        l10n('The representative picture was updated')
     144        );
     145    }
     146
     147    // force refresh of multiple sizes
     148    delete_element_derivatives($row);
    85149  }
    86150}
     
    117181$row = pwg_db_fetch_assoc(pwg_query($query));
    118182
     183if (!in_array(get_extension($row['path']), $conf['picture_ext']) or !empty($row['representative_ext']))
     184{
     185  $template->assign('show_file_to_update', true);
     186}
     187
    119188$template->assign(
    120189  array(
    121     'TN_SRC' => DerivativeImage::thumb_url($row).(isset($_FILES['photo_update']) ? '?'.time() : ''),
     190    'TN_SRC' => DerivativeImage::thumb_url($row),
     191    'original_filename' => $row['file'],
    122192    'TITLE' => render_element_name($row),
    123193    )
  • extensions/photo_update/admin.tpl

    r16982 r24623  
    55  <table>
    66    <tr>
    7       <td id="albumThumbnail">
     7      <td id="albumThumbnail" style="vertical-align:top">
    88        <img src="{$TN_SRC}" alt="{'Thumbnail'|@translate}" class="Thumbnail">
    99      </td>
    1010      <td style="vertical-align:top">
    1111        <form id="photo_update" method="post" action="" enctype="multipart/form-data">
     12{if isset($show_file_to_update)}
     13          <p style="text-align:left; margin-top:0;">
     14            <strong>{'File to update'|@translate}</strong><br>
     15            <label><input type="radio" name="file_to_update" value="main"> {'main file'|@translate} ({$original_filename})</label>
     16            <label><input type="radio" name="file_to_update" value="representative" checked="checked"> {'representative picture'|@translate}</label>
     17          </p>
     18{/if}
    1219          <p style="text-align:left; margin-top:0;">
    1320            <strong>{'Select a file'|@translate}</strong><br>
  • extensions/photo_update/language/en_UK/plugin.lang.php

    r11651 r24623  
    33$lang['Photo Update'] = 'Photo Update';
    44$lang['Update'] = 'Update';
     5$lang['File to update'] = 'File to update';
     6$lang['main file'] = 'main file';
     7$lang['representative picture'] = 'representative picture';
    58?>
  • extensions/photo_update/language/fr_FR/plugin.lang.php

    r11651 r24623  
    33$lang['Photo Update'] = 'Mise à jour de la photo';
    44$lang['Update'] = 'Mettre à jour';
     5$lang['File to update'] = 'Fichier à mettre à jour';
     6$lang['main file'] = 'fichier principal';
     7$lang['representative picture'] = 'image représentante';
    58?>
Note: See TracChangeset for help on using the changeset viewer.