Changeset 4875


Ignore:
Timestamp:
Feb 11, 2010, 12:29:29 AM (11 years ago)
Author:
plg
Message:

feature 1141 added: multiple select and progress bar with uploadify (jQuery
plugin).

Note: the HTML upload is disabled but I will provide a switch, either you use
Uploadify OR you use HTML multiple file boxes.

Location:
extensions/upload_form
Files:
7 added
3 edited

Legend:

Unmodified
Added
Removed
  • extensions/upload_form/include/functions_upload.inc.php

    r4829 r4875  
    8484    'date_available' => $dbnow,
    8585    'tn_ext' => 'jpg',
    86     'path' => $file_path,
     86    'path' => preg_replace('/^.*?upload/', './upload', $file_path),
    8787    'filesize' => $file_infos['filesize'],
    8888    'width' => $file_infos['width'],
  • extensions/upload_form/upload.php

    r4829 r4875  
    7676if (isset($_POST['submit_upload']))
    7777{
     78//   echo '<pre>POST'."\n"; print_r($_POST); echo '</pre>';
     79//   echo '<pre>FILES'."\n"; print_r($_FILES); echo '</pre>';
     80//   echo '<pre>SESSION'."\n"; print_r($_SESSION); echo '</pre>';
     81//   exit();
     82 
    7883  $category_id = null;
    7984  if ('existing' == $_POST['category_type'])
     
    112117
    113118  $image_ids = array();
    114   $page['thumbnails'] = array();
    115      
    116   $starttime = get_moment();
    117  
     119       
     120  if (isset($_FILES) and !empty($_FILES['image_upload']))
     121  {
     122    $starttime = get_moment();
     123
    118124  foreach ($_FILES['image_upload']['error'] as $idx => $error)
    119125  {
     
    197203
    198204        // TODO: if $image_id is not an integer, something went wrong
    199 
    200         // we could return the list of properties from the add_uploaded_file
    201         // function, but I like the "double check". And it costs nothing
    202         // compared to the upload process.
    203         $thumbnail = array();
     205      }
     206    }
     207  }
     208 
     209  $endtime = get_moment();
     210  $elapsed = ($endtime - $starttime) * 1000;
     211  // printf('%.2f ms', $elapsed);
     212
     213  } // if (!empty($_FILES))
     214
     215  if (isset($_POST['upload_id']))
     216  {
     217    // we're on a multiple upload, with uploadify and so on
     218    $image_ids = $_SESSION['uploads'][ $_POST['upload_id'] ];
     219
     220    associate_images_to_categories(
     221      $image_ids,
     222      array($category_id)
     223      );
     224
     225    $query = '
     226UPDATE '.IMAGES_TABLE.'
     227  SET level = '.$_POST['level'].'
     228  WHERE id IN ('.implode(', ', $image_ids).')
     229;';
     230    pwg_query($query);
     231   
     232    invalidate_user_cache();
     233  }
     234 
     235  $page['thumbnails'] = array();
     236  foreach ($image_ids as $image_id)
     237  {
     238    // we could return the list of properties from the add_uploaded_file
     239    // function, but I like the "double check". And it costs nothing
     240    // compared to the upload process.
     241    $thumbnail = array();
    204242     
    205         $query = '
     243    $query = '
    206244SELECT
    207245    file,
     
    211249  WHERE id = '.$image_id.'
    212250;';
    213         $image_infos = mysql_fetch_assoc(pwg_query($query));
    214 
    215         $thumbnail['file'] = $image_infos['file'];
    216      
    217         $thumbnail['src'] = get_thumbnail_location(
    218           array(
    219             'path' => $image_infos['path'],
    220             'tn_ext' => $image_infos['tn_ext'],
    221             )
    222           );
    223 
    224         // TODO: when implementing this plugin in Piwigo core, we should have
    225         // a function get_image_name($name, $file) (if name is null, then
    226         // compute a temporary name from filename) that would be also used in
    227         // picture.php. UPDATE: in fact, "get_name_from_file($file)" already
    228         // exists and is used twice (element_set_unit + comments, but not in
    229         // picture.php I don't know why) with the same pattern if
    230         // (empty($name)) {$name = get_name_from_file($file)}, a clean
    231         // function get_image_name($name, $file) would be better
    232         $thumbnail['title'] = get_name_from_file($image_infos['file']);
    233 
    234         $thumbnail['link'] = PHPWG_ROOT_PATH.'admin.php?page=picture_modify'
    235           .'&amp;image_id='.$image_id
    236           .'&amp;cat_id='.$category_id
    237           ;
    238 
    239         array_push($page['thumbnails'], $thumbnail);
    240       }
    241     }
     251    $image_infos = mysql_fetch_assoc(pwg_query($query));
     252
     253    $thumbnail['file'] = $image_infos['file'];
     254   
     255    $thumbnail['src'] = get_thumbnail_location(
     256      array(
     257        'path' => $image_infos['path'],
     258        'tn_ext' => $image_infos['tn_ext'],
     259        )
     260      );
     261
     262    // TODO: when implementing this plugin in Piwigo core, we should have
     263    // a function get_image_name($name, $file) (if name is null, then
     264    // compute a temporary name from filename) that would be also used in
     265    // picture.php. UPDATE: in fact, "get_name_from_file($file)" already
     266    // exists and is used twice (element_set_unit + comments, but not in
     267    // picture.php I don't know why) with the same pattern if
     268    // (empty($name)) {$name = get_name_from_file($file)}, a clean
     269    // function get_image_name($name, $file) would be better
     270    $thumbnail['title'] = get_name_from_file($image_infos['file']);
     271
     272    $thumbnail['link'] = PHPWG_ROOT_PATH.'admin.php?page=picture_modify'
     273      .'&amp;image_id='.$image_id
     274      .'&amp;cat_id='.$category_id
     275      ;
     276
     277    array_push($page['thumbnails'], $thumbnail);
    242278  }
    243279 
    244   $endtime = get_moment();
    245   $elapsed = ($endtime - $starttime) * 1000;
    246   // printf('%.2f ms', $elapsed);
    247 
    248280  if (!empty($page['thumbnails']))
    249281  {
     
    312344  );
    313345
     346$template->assign(
     347    array(
     348      'upload_mode' => 'multiple',
     349      'upload_id' => md5(rand()),
     350      'session_id' => session_id(),
     351      'pwg_token' => get_pwg_token(),
     352    )
     353  );
     354
     355$template->append(
     356  'head_elements',
     357  '<link rel="stylesheet" type="text/css" href="'.UPLOAD_FORM_PATH.'uploadify/uploadify.css">'."\n"
     358  );
     359
    314360if (isset($page['thumbnails']))
    315361{
  • extensions/upload_form/upload.tpl

    r4829 r4875  
    1414{/literal}
    1515
    16 <script type="text/javascript" src="{$plugin_path}/include/upload.js"></script>
     16{if $upload_mode eq 'html'}
     17<script type="text/javascript" src="{$plugin_path}include/upload.js"></script>
     18{elseif $upload_mode eq 'multiple'}
     19<script type="text/javascript" src="{$plugin_path}uploadify/swfobject.js"></script>
     20<script type="text/javascript" src="{$plugin_path}uploadify/jquery.uploadify.v2.1.0.min.js"></script>
     21
     22<script type="text/javascript">
     23var basepath = '{$plugin_path}';
     24var upload_id = '{$upload_id}';
     25var session_id = '{$session_id}';
     26var pwg_token = '{$pwg_token}';
     27var buttonText = '{"Select files"|@translate}';
     28
     29{literal}
     30jQuery(document).ready(function() {
     31  jQuery("#uploadify").uploadify({
     32    'uploader'       : basepath + 'uploadify/uploadify.swf',
     33    'script'         : basepath + 'uploadify/uploadify.php',
     34    'scriptData'     : {
     35      'upload_id' : upload_id,
     36      'session_id' : session_id,
     37      'pwg_token' : pwg_token,
     38    },
     39    'cancelImg'      : basepath + 'uploadify/cancel.png',
     40    'queueID'        : 'fileQueue',
     41    'auto'           : false,
     42    'displayData'    : 'speed',
     43    'buttonText'     : buttonText,
     44    'multi'          : true,
     45    'onAllComplete'  : function(event, data) {
     46      if (data.errors) {
     47        return false;
     48      }
     49      else {
     50        $("input[name=submit_upload]").click();
     51      }
     52    }
     53  });
     54});
     55{/literal}
     56</script>
     57{/if}
    1758
    1859{literal}
     
    59100
    60101
    61 <form enctype="multipart/form-data" method="post" action="{$F_ACTION}" class="properties">
     102<form id="uploadForm" enctype="multipart/form-data" method="post" action="{$F_ACTION}" class="properties">
     103{if $upload_mode eq 'multiple'}
     104<input name="upload_id" value="{$upload_id}" type="hidden">
     105{/if}
    62106  <fieldset>
    63107    <legend>{'Upload Photos'|@translate}</legend>
     
    108152      </tr>
    109153
     154{if $upload_mode eq 'html'}
    110155      <tr>
    111156        <td colspan="2">
     
    126171      <input class="submit" type="submit" name="submit_upload" value="{'Upload'|@translate}" {$TAG_INPUT_ENABLED}/>
    127172    </p>
     173{elseif $upload_mode eq 'multiple'}
     174    </table>
     175
     176    <p>
     177      <input type="file" name="uploadify" id="uploadify" />
     178    </p>
     179
     180    <div id="fileQueue"></div>
     181
     182    <p>
     183      <input class="submit" type="button" value="{'Upload'|@translate}" onclick="javascript:jQuery('#uploadify').uploadifyUpload()"/>
     184      <input type="submit" name="submit_upload" style="display:none"/>
     185    </p>
     186{/if}
    128187  </fieldset>
    129188</form>
Note: See TracChangeset for help on using the changeset viewer.