Dotclear

Changeset 1144:4af82896ca3d for admin


Ignore:
Timestamp:
06/04/13 22:51:35 (12 years ago)
Author:
Nicolas <nikrou77@…>
Branch:
default
Message:

Remplacement de l'upload utilisant swfupload par le plugin jQuery-File-Upload

Todo:

  • Gestion des suppressions
  • Gestion des annulations
  • Gestion des mises de l'interface sans rechargement de la page
  • Simplification (moins de javascript) ?
Location:
admin
Files:
9 added
4 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • admin/js/_media.js

    r1140 r1144  
    11$(function() { 
    2      // Replace remove links by a POST on hidden form 
    3      fileRemoveAct(); 
    4       
    5      function fileRemoveAct() { 
    6           $('a.media-remove').click(function() { 
    7                var m_name = $(this).parents('ul').find('li:first>a').text(); 
    8                if (window.confirm(dotclear.msg.confirm_delete_media.replace('%s',m_name))) { 
    9                     var f = $('#media-remove-hide').get(0); 
    10                     f.elements['remove'].value = this.href.replace(/^(.*)&remove=(.*?)(&|$)/,'$2'); 
    11                     this.href = ''; 
    12                     f.submit(); 
    13                } 
    14                return false; 
    15           }); 
    16      } 
    17       
    18      if (!$.browser.opera) { 
    19           var upldr = $('<a href="#" id="cu-enable">' + dotclear.msg.activate_enhanced_uploader + '</a>').click( function() { 
    20                candyUploadInit(); 
    21                return false; 
    22           }); 
    23           $('#media-upload').append($('<div></div>').append(upldr)); 
    24           if ((dotclear.candyUpload_force_init == '1') || (($.cookie('dc_candy_upl') == 1))) { 
    25                candyUploadInit(); 
    26           } 
    27      } 
    28       
    29      function candyUploadInit() 
    30      { 
    31           var candy_upload_success = false; 
    32           var candy_upload_form_url = $('#media-upload').attr('action') + '&file_sort=date-desc&d=' + $('#media-upload input[name=d]').val(); 
    33           var candy_upload_limit = $('#media-upload input[name=MAX_FILE_SIZE]').val(); 
    34           $('#media-upload').candyUpload({ 
    35                upload_url: dotclear.candyUpload.base_url + '/media.php', 
    36                flash_movie: dotclear.candyUpload.movie_url, 
    37                file_size_limit: candy_upload_limit + 'b', 
    38                params: 'swfupload=1&amp;' + dotclear.candyUpload.params, 
    39                 
    40                callbacks: { 
    41                     createControls: function() { 
    42                          var _this = this; 
    43                          this.ctrl.btn_browse.hide(); 
    44                          this.ctrl.msg.html(dotclear.msg.load_enhanced_uploader); 
    45                          var l = $('<a href="#">' + dotclear.msg.disable_enhanced_uploader + '</a>').click(function() { 
    46                               _this.upldr.destroy(); 
    47                               _this.ctrl.block.empty().remove(); 
    48                               $('#media-upload').show(); 
    49                               delete _this; 
    50                               $.cookie('dc_candy_upl','',{expires:-1}); 
    51                               return false; 
    52                          }); 
    53                          this.ctrl.disable = $('<div class="cu-disable"></div>').append(l).appendTo(this.ctrl.block); 
    54                     }, 
    55                     flashReady: function() { 
    56                          var _this = this; 
    57                          this.ctrl.msg.fadeOut('fast',function() { 
    58                               $(this).text(_this.locales.no_file_in_queue).fadeIn('fast'); 
    59                               _this.ctrl.btn_browse.fadeIn('fast',function() { 
    60                                    _this.upldr.container.children().css({ 
    61                                         width: $('.cu-btn-browse').width(), 
    62                                         height: $('.cu-btn-browse').height() 
    63                                    }); 
    64                               }); 
    65                          }); 
    66                     }, 
    67                     uploadSuccess: function(o,data) { 
    68                          if (data == 'ok') { 
    69                               candy_upload_success = true; 
    70                               this.fileMsg(o.id,this.locales.file_uploaded); 
    71                          } else { 
    72                               this.fileErrorMsg(o.id,data); 
    73                          } 
    74                           
    75                          // uploads finished and at least one success 
    76                          if (candy_upload_success && $('div.cu-file:has(span.cu-filecancel a)',this.ctrl.files).length == 0) { 
    77                               $.cookie('dc_candy_upl','1',{expires: 30}); 
    78                               $.get(candy_upload_form_url,function(data) { 
    79                                    var media = $('div.media-list'); 
    80                                    media.after($('div.media-list',data)).remove(); 
    81                                    fileRemoveAct(); 
    82                               }); 
    83                          } 
    84                     }, 
    85                     fileQueued: function() { 
    86                          ; 
    87                     } 
    88                } 
    89           }); 
    90      } 
     2    $('#fileupload') 
     3     .fileupload({ 
     4         url: $('#fileupload').attr('action'), 
     5         autoUpload: false 
     6     }); 
     7 
     8    // Load existing files: 
     9    $('#fileupload').addClass('fileupload-processing'); 
     10    $.ajax({ 
     11        url: $('#fileupload').fileupload('option', 'url'), 
     12        dataType: 'json', 
     13        context: $('#fileupload')[0] 
     14    }).always(function (result) { 
     15        $(this).removeClass('fileupload-processing'); 
     16    }).done(function (result) { 
     17        $(this).fileupload('option', 'done') 
     18            .call(this, null, {result: result}); 
     19    }); 
     20 
     21    // Replace remove links by a POST on hidden form 
     22    fileRemoveAct(); 
     23 
     24    function fileRemoveAct() { 
     25     $('a.media-remove').click(function() { 
     26         var m_name = $(this).parents('ul').find('li:first>a').text(); 
     27         if (window.confirm(dotclear.msg.confirm_delete_media.replace('%s',m_name))) { 
     28          var f = $('#media-remove-hide').get(0); 
     29          f.elements['remove'].value = this.href.replace(/^(.*)&remove=(.*?)(&|$)/,'$2'); 
     30          this.href = ''; 
     31          f.submit(); 
     32         } 
     33         return false; 
     34     }); 
     35    } 
    9136}); 
  • admin/js/jquery/jquery-ui.custom.js

    • Property exe deleted
  • admin/js/jquery/jquery.js

    • Property exe deleted
  • admin/media.php

    r1039 r1144  
    1010# 
    1111# -- END LICENSE BLOCK ----------------------------------------- 
    12  
    13 /* Upload backend 
    14 -------------------------------------------------------- */ 
    15 if (!empty($_POST['swfupload'])) 
    16 { 
    17      header('content-type: text/plain'); 
    18      try 
    19      { 
    20           if (empty($_POST['sess_id']) || empty($_POST['sess_uid'])) { 
    21                throw new Exception('No credentials.'); 
    22           } 
    23           define('DC_AUTH_SESS_ID',$_POST['sess_id']); 
    24           define('DC_AUTH_SESS_UID',$_POST['sess_uid']); 
    25            
    26           require dirname(__FILE__).'/../inc/admin/prepend.php'; 
    27            
    28           if (!$core->auth->check('media,media_admin',$core->blog->id)) { 
    29                throw new Exception('Permission denied.'); 
    30           } 
    31            
    32           $d = isset($_POST['d']) ? $_POST['d'] : null; 
    33           $core->media = new dcMedia($core); 
    34           $core->media->chdir($d); 
    35           $core->media->getDir(); 
    36           $dir =& $core->media->dir; 
    37            
    38           if (empty($_FILES['Filedata'])) { 
    39                throw new Exception('No file to upload.'); 
    40           } 
    41            
    42           files::uploadStatus($_FILES['Filedata']); 
    43           $core->media->uploadFile($_FILES['Filedata']['tmp_name'],$_FILES['Filedata']['name']); 
    44            
    45           echo 'ok'; 
    46      } 
    47      catch (Exception $e) { 
    48           echo __('Error:').' '.__($e->getMessage()); 
    49      } 
    50      exit; 
    51 } 
    52  
    5312 
    5413/* HTML page 
     
    175134if ($dir && !empty($_FILES['upfile'])) 
    176135{ 
    177      try 
    178      { 
    179           files::uploadStatus($_FILES['upfile']); 
    180            
    181           $f_title = (isset($_POST['upfiletitle']) ? $_POST['upfiletitle'] : ''); 
    182           $f_private = (isset($_POST['upfilepriv']) ? $_POST['upfilepriv'] : false); 
    183            
    184           $core->media->uploadFile($_FILES['upfile']['tmp_name'],$_FILES['upfile']['name'],$f_title,$f_private); 
    185           http::redirect($page_url.'&d='.rawurlencode($d).'&upok=1'); 
    186      } 
    187      catch (Exception $e) 
    188      { 
    189           $core->error->add($e->getMessage()); 
    190      } 
    191 } 
    192  
     136  $upfile = array('name' => $_FILES['upfile']['name'][0], 
     137                  'type' => $_FILES['upfile']['type'][0], 
     138                  'tmp_name' => $_FILES['upfile']['tmp_name'][0], 
     139                  'error' => $_FILES['upfile']['error'][0], 
     140                  'size' => $_FILES['upfile']['size'][0] 
     141                  ); 
     142 
     143     try { 
     144    files::uploadStatus($upfile); 
     145 
     146    $core->media->uploadFile($upfile['tmp_name'],$upfile['name']); 
     147 
     148    if (!empty($_SERVER['HTTP_X_REQUESTED_WITH'])) { 
     149      header('Content-type: application/json'); 
     150      $message = array(); 
     151      $message['files'][] = array('name' => $upfile['name']); 
     152 
     153      echo json_encode($message); 
     154      exit(); 
     155    } else { 
     156        http::redirect($page_url.'&d='.rawurlencode($d).'&upok=1'); 
     157    } 
     158     } catch (Exception $e) { 
     159    if (!empty($_SERVER['HTTP_X_REQUESTED_WITH'])) { 
     160      header('Content-type: application/json'); 
     161      $message = array(); 
     162      $message['files'][] = array('name' => $upfile['name'], 
     163                                  'error' => $e->getMessage() 
     164                                  ); 
     165      echo json_encode($message); 
     166      exit(); 
     167    } else { 
     168      $core->error->add($e->getMessage()); 
     169    } 
     170     } 
     171} 
    193172 
    194173# Removing item 
     
    215194     } 
    216195} 
    217  
    218196 
    219197# DISPLAY confirm page for rmdir & rmfile 
     
    245223 
    246224call_user_func($open_f,__('Media manager'), 
    247      '<script type="text/javascript">'."\n". 
    248      "//<![CDATA["."\n". 
    249      dcPage::jsVar('dotclear.candyUpload_force_init',$user_ui_enhanceduploader)."\n". 
    250      "//]]>". 
    251      "</script>". 
    252225     dcPage::jsLoad('js/_media.js'). 
    253      ($core_media_writable ? dcPage::jsCandyUpload(array('d='.$d)) : '') 
     226     ($core_media_writable ? dcPage::jsUpload(array('d='.$d)) : '') 
    254227     ); 
    255228 
     
    339312} 
    340313 
     314 
    341315if ($core_media_writable) 
    342316{ 
     
    344318      
    345319     echo 
    346      '<div class="col">'. 
    347      '<fieldset id="add-file-f"><legend>'.__('Add files').'</legend>'. 
    348      '<p>'.__('Please take care to publish media that you own and that are not protected by copyright.').'</p>'. 
    349      '<form id="media-upload" class="clear" action="'.html::escapeURL($page_url).'" method="post" enctype="multipart/form-data">'. 
    350      '<div>'.form::hidden(array('MAX_FILE_SIZE'),DC_MAX_UPLOAD_SIZE). 
    351      $core->formNonce().'</div>'. 
    352      '<p><label for="upfile">'.__('Choose a file:'). 
    353      ' ('.sprintf(__('Maximum size %s'),files::size(DC_MAX_UPLOAD_SIZE)).')'. 
    354      '<input type="file" id="upfile" name="upfile" size="20" />'. 
    355      '</label></p>'. 
    356      '<p><label for="upfiletitle">'.__('Title:').form::field(array('upfiletitle','upfiletitle'),35,255).'</label></p>'. 
    357      '<p><label for="upfilepriv" class="classic">'.form::checkbox(array('upfilepriv','upfilepriv'),1).' '. 
    358      __('Private').'</label></p>'; 
    359      if (!$user_ui_enhanceduploader) { 
    360           echo 
    361           '<p class="form-help info">'.__('To send several files at the same time, you can activate the enhanced uploader in'). 
    362           ' <a href="preferences.php?tab=user-options">'.__('My preferences').'</a></p>'; 
    363      } 
    364      echo 
    365      '<p><input type="submit" value="'.__('Send').'" />'. 
    366      form::hidden(array('d'),$d).'</p>'. 
    367      '</fieldset>'. 
    368      '</form>'. 
    369      '</div>'; 
     320  '<div class="col">'. 
     321  '<fieldset id="add-file-f"><legend>'.__('Add files').'</legend>'. 
     322  '<p>'.__('Please take care to publish media that you own and that are not protected by copyright.').'</p>'. 
     323  ' <form id="fileupload" action="'.html::escapeURL($page_url).'" method="POST" enctype="multipart/form-data">'. 
     324  '<div>'.form::hidden(array('MAX_FILE_SIZE'),DC_MAX_UPLOAD_SIZE). 
     325    $core->formNonce().'</div>'. 
     326  '<div class="fileupload-buttonbar">'. 
     327  '<span class="button-add button"><label for="upfile">'.__('Add files').'</label>'. 
     328  '<input type="file" id="upfile" name="upfile[]" size="20" multiple="multiple" data-url="'.html::escapeURL($page_url).'" />'. 
     329  '</span>'. 
     330  '<button type="submit" class="button start"><span>'.__('Send').'</span></button>'. 
     331  '</div>'. 
     332  '<table role="presentation" class="table table-striped"><tbody class="files" data-toggle="modal-gallery" data-target="#modal-gallery"></tbody></table>'. 
     333    form::hidden(array('d'),$d).'</p>'. 
     334  '</fieldset>'. 
     335  '</form>'. 
     336  '</div>'; 
    370337      
    371338     echo 
Note: See TracChangeset for help on using the changeset viewer.

Sites map