b2evolution PHP Cross Reference Blogging Systems

Source: /inc/files/views/_file_upload.view.php - 363 lines - 13583 bytes - Summary - Text - Print

Description: This file implements the UI for file upload. This file is part of the evoCore framework - {@link http://evocore.net/} See also {@link http://sourceforge.net/projects/evocms/}.

   1  <?php
   2  /**
   3   * This file implements the UI for file upload.
   4   *
   5   * This file is part of the evoCore framework - {@link http://evocore.net/}
   6   * See also {@link http://sourceforge.net/projects/evocms/}.
   7   *
   8   * @copyright (c)2003-2014 by Francois Planque - {@link http://fplanque.com/}
   9   * Parts of this file are copyright (c)2004-2006 by Daniel HAHLER - {@link http://thequod.de/contact}.
  10   *
  11   * {@internal License choice
  12   * - If you have received this file as part of a package, please find the license.txt file in
  13   *   the same folder or the closest folder above for complete license terms.
  14   * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)
  15   *   then you must choose one of the following licenses before using the file:
  16   *   - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
  17   *   - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php
  18   * }}
  19   *
  20   * {@internal Open Source relicensing agreement:
  21   * Daniel HAHLER grants Francois PLANQUE the right to license
  22   * Daniel HAHLER's contributions to this file and the b2evolution project
  23   * under any OSI approved OSS license (http://www.opensource.org/licenses/).
  24   * }}
  25   *
  26   * @package admin
  27   *
  28   * {@internal Below is a list of authors who have contributed to design/coding of this file: }}
  29   * @author blueyed: Daniel HAHLER.
  30   * @author fplanque: Francois PLANQUE.
  31   *
  32   * @version $Id: _file_upload.view.php 6136 2014-03-08 07:59:48Z manuel $
  33   */
  34  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  35  
  36  /**
  37   * @var Settings
  38   */
  39  global $Settings;
  40  
  41  global $upload_quickmode, $failedFiles, $ads_list_path, $tab3, $renamedMessages, $renamedFiles;
  42  
  43  global $fm_FileRoot;
  44  
  45  
  46  /* TODO: dh> move JS to external file. */
  47  ?>
  48  
  49  <script type="text/javascript">
  50      <!--
  51      /**
  52       * Mighty cool function to append an input or textarea element onto another element.
  53       *
  54       * @usedby addAnotherFileInput()
  55       */
  56  	function appendLabelAndInputElements( appendTo, labelText, labelBr, inputOrTextarea, inputName,
  57                                            inputSizeOrCols, inputMaxLengthOrRows, inputType, inputClass )
  58      {
  59          var id = inputName.replace(/\[(\d+)\]/, '_$1');
  60          // LABEL:
  61          var fileLabel = jQuery(appendTo).append(jQuery('<label for="'+id+'">'+labelText+'</label>'));
  62  
  63          // Dow we want a BR after the label:
  64          if( labelBr )
  65          { // We want a BR after the label:
  66              appendTo.appendChild( document.createElement('br') );
  67          }
  68          else
  69          {
  70              appendTo.appendChild( document.createTextNode( ' ' ) );
  71          }
  72  
  73          // INPUT:
  74          var fileInput = document.createElement( inputOrTextarea );
  75          fileInput.name = inputName;
  76          fileInput.id = id;
  77          if( inputOrTextarea == "input" )
  78          {
  79              fileInput.type = typeof( inputType ) !== 'undefined' ? inputType : "text";
  80              fileInput.size = inputSizeOrCols;
  81              if( typeof( inputMaxLengthOrRows ) != 'undefined' )
  82              {
  83                  fileInput.maxlength = inputMaxLengthOrRows;
  84              }
  85          }
  86          else
  87          {
  88              fileInput.cols = inputSizeOrCols;
  89              fileInput.rows = inputMaxLengthOrRows;
  90          }
  91  
  92          fileInput.className = inputClass;
  93  
  94          appendTo.appendChild( fileInput );
  95          appendTo.appendChild( document.createElement('br') );
  96      }
  97  
  98  
  99      /**
 100       * Add a new fileinput area to the upload form.
 101       */
 102  	function addAnotherFileInput()
 103      {
 104          var uploadfiles = document.getElementById("uploadfileinputs");
 105          var newLI = document.createElement("li");
 106          var closeLink = document.createElement("a");
 107          closeLink.innerHTML = '<?php echo get_icon( 'close' ); ?>';
 108          var closeImage = jQuery( closeLink ).children( 'span' );
 109  
 110          uploadfiles.appendChild( newLI );
 111          newLI.appendChild( closeLink );
 112          newLI.className = "clear";
 113  
 114          <?php
 115          if( get_icon( 'close', 'rollover' ) )
 116          { // handle rollover images ('close' by default is one).
 117              ?>
 118              closeLink.className = 'rollover_sprite'; // dh> use "+=" to append class?
 119              <?php
 120          }
 121          // add handler to image to close the parent LI and add css to float right.
 122          ?>
 123          jQuery(closeImage)
 124              .click( function() {jQuery(this).closest("li").remove()} )
 125              .css('float', 'right');
 126  
 127          evo_upload_fields_count++;
 128          // first radio
 129          var radioFile = document.createElement('input');
 130          radioFile.type = "radio";
 131          radioFile.name = "uploadfile_source["+ evo_upload_fields_count +"]";
 132          radioFile.value = "file";
 133  
 134          // second radio
 135          var radioURL = radioFile.cloneNode(true);
 136          radioURL.value = "upload";
 137  
 138          radioFile.checked = true;
 139  
 140          newLI.appendChild( radioFile );
 141          appendLabelAndInputElements( newLI, '<?php echo TS_('Choose a file'); ?>:', false, 'input', 'uploadfile['+evo_upload_fields_count+']', '70', '0', 'file', 'upload_file' );
 142          newLI.appendChild( radioURL );
 143          appendLabelAndInputElements( newLI, '<?php echo TS_('Upload by URL'); ?>:', false, 'input', 'uploadfile_url['+evo_upload_fields_count+']', '70', '0', 'text', 'upload_file' );
 144          <?php
 145          if( $tab3 == 'advanced' )
 146          {    // We want file properties on the upload form:
 147              ?>
 148          appendLabelAndInputElements( newLI, '<?php echo TS_('Filename on server (optional)'); ?>:', false, 'input', 'uploadfile_name[]', '50', '80', 'text', '' );
 149          appendLabelAndInputElements( newLI, '<?php echo TS_('Long title'); ?>:', true, 'input', 'uploadfile_title[]', '50', '255', 'text', 'large' );
 150          appendLabelAndInputElements( newLI, '<?php echo TS_('Alternative text (useful for images)'); ?>:', true, 'input', 'uploadfile_alt[]', '50', '255', 'text', 'large' );
 151          appendLabelAndInputElements( newLI, '<?php echo TS_('Caption/Description of the file'); ?>:', true, 'textarea', 'uploadfile_desc[]', '38', '3', '', 'large' );
 152              <?php
 153          }
 154          ?>
 155      }
 156      // -->
 157  </script>
 158  
 159  
 160  <?php
 161      // Begin payload block:
 162      $this->disp_payload_begin();
 163  
 164      $Form = new Form( NULL, 'fm_upload_checkchanges', 'post', 'none', 'multipart/form-data' );
 165      $Form->begin_form( 'fform' );
 166      $Form->add_crumb( 'file' );
 167      $Form->hidden_ctrl();
 168      $Form->hidden( 'MAX_FILE_SIZE', $Settings->get( 'upload_maxkb' )*1024 ); // Just a hint for the browser.
 169      $Form->hidden( 'upload_quickmode', $upload_quickmode );
 170      $Form->hidden( 'tab3_onsubmit', $tab3 );
 171      $Form->hiddens_by_key( get_memorized() );
 172  
 173      $Widget = new Widget( 'file_browser' );
 174      $Widget->global_icon( T_('Quit upload mode!'), 'close', regenerate_url( 'ctrl,fm_mode', 'ctrl=files' ) );
 175      $Widget->title = T_('File upload').get_manual_link('upload_multiple');
 176      $Widget->disp_template_replaced( 'block_start' );
 177  ?>
 178  
 179  <table id="fm_browser" cellspacing="0" cellpadding="0">
 180      <tbody>
 181          <tr>
 182              <?php
 183              echo '<td id="fm_dirtree">';
 184  
 185              // Version with all roots displayed
 186              echo get_directory_tree( NULL, NULL, $ads_list_path, true, NULL, false, 'add' );
 187  
 188              // Version with only the current root displayed:
 189              // echo get_directory_tree( $fm_FileRoot, $fm_FileRoot->ads_path, $ads_list_path, true );
 190  
 191              echo '</td>';
 192  
 193              echo '<td id="fm_files">';
 194  
 195  
 196          if( count( $failedFiles ) )
 197          {
 198              echo '<p class="error">'.T_('Some file uploads failed. Please check the errors below.').'</p>';
 199          }
 200          if( count( $renamedMessages) )
 201          {
 202              echo '<p class="error">'.T_('Some uploaded files have been renamed due to conflicting file names. Please check the messages below:').'</p>';
 203          }
 204          ?>
 205  
 206              <div class="upload_title"><?php echo T_('Files to upload') ?></div>
 207  
 208              <ul id="uploadfileinputs">
 209                  <?php
 210                      if( empty($failedFiles) && empty($renamedMessages) )
 211                      { // No failed files, no renamed files display 5 empty input blocks:
 212                          $displayFiles = array( NULL, NULL, NULL, NULL, NULL );
 213                      }
 214                      elseif ( ! empty($failedFiles) )
 215                      { // Display failed files:
 216                          $displayFiles = & $failedFiles;
 217                          if( ! empty($renamedMessages) )
 218                          { // There are renamed files
 219                              foreach( $renamedMessages as $lKey => $data )
 220                              {
 221                                  if( $displayFiles[$lKey] == null )
 222                                  {
 223                                      $displayFiles[$lKey] = $data['message'];
 224                                  }
 225                              }
 226                          }
 227                      }
 228                      else
 229                      { // Display renamed files:
 230                          foreach( $renamedMessages as $lKey => $data )
 231                          {
 232                              $displayFiles[$lKey] = $data['message'];
 233                          }
 234                      }
 235  
 236                      global $uploadfile_alt, $uploadfile_desc, $uploadfile_name, $uploadfile_title;
 237                      global $uploadfile_url, $uploadfile_source;
 238                      foreach( $displayFiles as $lKey => $lMessage )
 239                      { // For each file upload block to display:
 240  
 241                          if( ($lMessage !== NULL) )
 242                          {
 243                              if( ! array_key_exists( $lKey, $renamedMessages ) )
 244                              { // This is a failed upload:
 245                                  echo '<li class="invalid" title="'
 246                                                  ./* TRANS: will be displayed as title for failed file uploads */ T_('Invalid submission.').'">';
 247                              }
 248                              else
 249                              { // This filename arlready exists:
 250                                  echo '<li class="invalid" title="'
 251                                                  ./* TRANS: will be displayed as title in case of renamed file uploads */ T_('File name changed.').'">';
 252                              }
 253                              echo '<p class="error">'.$lMessage.'</p>';
 254                          }
 255                          else
 256                          { // Not a failed upload, display normal block:
 257                              echo '<li>';
 258                          }
 259  
 260                          // fp> TODO: would be cool to add a close icon starting at the 2nd <li>
 261                          // dh> TODO: it may be useful to add the "accept" attrib to the INPUT elements to give the browser a hint about the accepted MIME types
 262  
 263                          if( ! array_key_exists( $lKey, $renamedMessages ) )
 264                          {
 265                              ?>
 266  
 267                              <input type="radio" name="uploadfile_source[<?php echo $lKey ?>]" value="file"
 268                                  <?php echo ! isset($uploadfile_source[$lKey]) || $uploadfile_source[$lKey] == 'file' ? ' checked="checked"' : '' ?> />
 269                              <label for="uploadfile_<?php echo $lKey ?>"><?php echo T_('Choose a file'); ?>:</label>
 270                              <input name="uploadfile[]" id="uploadfile_<?php echo $lKey ?>" size="70" type="file" class="upload_file" /><br />
 271  
 272                              <input type="radio" name="uploadfile_source[<?php echo $lKey ?>]" value="upload"
 273                                  <?php echo isset($uploadfile_source[$lKey]) && $uploadfile_source[$lKey] == 'upload' ? ' checked="checked"' : '' ?> />
 274                              <label for="uploadfile_url_<?php echo $lKey ?>"><?php echo T_('Get from URL'); ?>:</label>
 275                              <input name="uploadfile_url[]" id="uploadfile_url_<?php echo $lKey ?>" size="70" type="text" class="upload_file"
 276                                      value="<?php echo ( isset( $uploadfile_url[$lKey] ) ? format_to_output( $uploadfile_url[$lKey], 'formvalue' ) : '' );
 277                                      ?>" /><br />
 278  
 279                              <?php
 280                          }
 281                          else
 282                          {
 283                              ?>
 284                              <input type="radio" name="<?php echo 'Renamed_'.$lKey ?>" value="Yes" id=" <?php echo 'Yes_'.$lKey ?>"/>
 285                              <label for="<?php echo 'Yes_'.$lKey ?>">
 286                              <?php echo sprintf( T_("Replace the old version %s with the new version %s and keep old version as %s."), $renamedMessages[$lKey]['oldThumb'], $renamedMessages[$lKey]['newThumb'], $renamedFiles[$lKey]['newName'] ) ?></label><br />
 287                              <input type="radio" name="<?php echo 'Renamed_'.$lKey ?>" value="No" id=" <?php echo 'No_'.$lKey ?>"  checked="checked"/>
 288                              <label for="<?php echo 'Yes_'.$lKey ?>"><?php echo sprintf( T_("Don't touch the old version and keep the new version as %s."), $renamedFiles[$lKey]['newName'] ) ?> </label><br />
 289                              <?php
 290                          }
 291                          if( $tab3 == 'advanced' )
 292                          {    // We want file properties on the upload form:
 293                              ?>
 294                              <label><?php echo T_('Filename on server (optional)'); ?>:</label>
 295                              <input name="uploadfile_name[]" type="text" size="50" maxlength="80"
 296                                  value="<?php echo ( isset( $uploadfile_name[$lKey] ) ? format_to_output( $uploadfile_name[$lKey], 'formvalue' ) : '' ) ?>" /><br />
 297  
 298                              <label><?php echo T_('Long title'); ?>:</label><br />
 299                              <input name="uploadfile_title[]" type="text" size="50" maxlength="255" class="large"
 300                                  value="<?php echo ( isset( $uploadfile_title[$lKey] ) ? format_to_output( $uploadfile_title[$lKey], 'formvalue' ) : '' );
 301                                  ?>" /><br />
 302  
 303                              <label><?php echo T_('Alternative text (useful for images)'); ?>:</label><br />
 304                              <input name="uploadfile_alt[]" type="text" size="50" maxlength="255" class="large"
 305                                  value="<?php echo ( isset( $uploadfile_alt[$lKey] ) ? format_to_output( $uploadfile_alt[$lKey], 'formvalue' ) : '' );
 306                                  ?>" /><br />
 307  
 308                              <label><?php echo T_('Caption/Description of the file'); /* TODO: maxlength (DB) */ ?>:</label><br />
 309                              <textarea name="uploadfile_desc[]" rows="3" cols="38" class="large"><?php
 310                                  echo ( isset( $uploadfile_desc[$lKey] ) ? $uploadfile_desc[$lKey] : '' )
 311                              ?></textarea><br />
 312                              <?php
 313                          }
 314  
 315                          echo '</li>';
 316                          // no text after </li> or JS will bite you! (This is where additional blocks get inserted)
 317                      }
 318  
 319                  ?>
 320              </ul>
 321  
 322              <script type="text/javascript">
 323                  (function()
 324                  {
 325                      var handler = function()
 326                      {
 327                          jQuery(this).prevAll("[type=radio]").eq(0).attr("checked", "checked")
 328                      }
 329                      jQuery( document ).on("click", ".upload_file", handler);
 330                      jQuery( document ).on("keyup", ".upload_file", handler);
 331                      jQuery( document ).on("change", ".upload_file", handler);
 332                  })();
 333                  var evo_upload_fields_count = jQuery("#uploadfileinputs li").length-1;
 334              </script>
 335  
 336              <p class="uploadfileinputs"><a href="#" onclick="addAnotherFileInput(); return false;" class="small"><?php echo T_('Add another file'); ?></a></p>
 337  
 338              <div class="upload_foot">
 339                  <input type="submit" value="<?php echo format_to_output( T_('Upload to server now'), 'formvalue' ); ?>" class="ActionButton" >
 340                  <input type="reset" value="<?php echo format_to_output( T_('Reset'), 'formvalue' ); ?>" class="ResetButton">
 341  
 342                  <p class="note">
 343                      <?php
 344                      echo get_upload_restriction();
 345                      ?>
 346                  </p>
 347              </div>
 348  
 349          </td>
 350          </tr>
 351      </tbody>
 352  </table>
 353  
 354  
 355  <?php
 356  $Widget->disp_template_raw( 'block_end' );
 357  
 358  $Form->end_form();
 359  
 360  // End payload block:
 361  $this->disp_payload_end();
 362  
 363  ?>

title

Description

title

Description

title

Description

title

title

Body