Development

Changeset 16150

You must first sign up to be able to contribute.

Changeset 16150

Show
Ignore:
Timestamp:
03/10/09 21:21:58 (4 years ago)
Author:
boutell
Message:

About to move this attempt at iframe-based handling of persistent
file uploads to a fork

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/pkPersistentFileUploadPlugin/trunk/README

    r15684 r16150  
    224224You can reach Tom at [tom@punkave.com](mailto:punkave.com). 
    225225 
     226## TODO 
     227 
     228Finish support for individual iframes, allowing progress display and 
     229simultaneous uploads and eliminating the need for the main display 
     230to be an iframe in order to achieve progress display. It's a good idea but it 
     231doesn't work yet. 
     232 
    226233## Changelog 
    227234 
  • plugins/pkPersistentFileUploadPlugin/trunk/lib/validator/pkValidatorFilePersistent.class.php

    r16004 r16150  
    213213  } 
    214214 
     215  static public function setFileInfo($persistid, $data) 
     216  { 
     217    if (!self::validPersistId($persistid)) 
     218    { 
     219      // Roll our eyes at the hackers 
     220      return false; 
     221    } 
     222    $persistentDir = self::getPersistentDir(); 
     223    $infoPath = "$persistentDir/$persistid.data"; 
     224    file_put_contents($infoPath, serialize($data)); 
     225    return true; 
     226  } 
    215227  static public function validPersistId($persistid) 
    216228  { 
  • plugins/pkPersistentFileUploadPlugin/trunk/lib/widget/pkWidgetFormInputFilePersistent.class.php

    r16005 r16150  
    2828 
    2929    $this->addOption('type', 'file'); 
     30    $this->addOption('iframe', null); 
     31    $this->addOption('progress', null); 
     32    $this->addOption('iframe-content', null); 
    3033    $this->addOption('existing-html', false); 
    3134    $this->addOption('image-preview', null); 
     35    $this->addOption('persistid', null); 
    3236    $this->setOption('needs_multipart', true); 
    3337  } 
     
    5054  { 
    5155    $exists = false; 
    52     if (isset($value['persistid']) && strlen($value['persistid'])) 
     56    if ($this->hasOption('persistid')) 
     57    { 
     58      $persistid = $this->getOption('persistid'); 
     59    } 
     60    elseif (isset($value['persistid']) && strlen($value['persistid'])) 
    5361    { 
    5462      $persistid = $value['persistid']; 
     63    } 
     64    if (isset($persistid)) 
     65    { 
    5566      $info = pkValidatorFilePersistent::getFileInfo($persistid); 
    56       if ($info
     67      if (isset($info['tmp_name'])
    5768      { 
    5869        $exists = true; 
     
    107118            $imagePreview['height']); 
    108119        } 
    109         $result .= "<img src='$url' />";  
     120        if ($this->getOption('iframe-content')) 
     121        { 
     122          // This is not security related, it just forces a refresh 
     123          $salt = time(); 
     124          $salted = "$url?$salt"; 
     125          $result .= "<script>pkPersistentFileUploadUpdatePreview(json_encode($persistid), json_encode($salted));</script>"; 
     126        } 
     127        else 
     128        { 
     129          $result .= "<img id='pk-persistent-upload-preview-$persistid' src='" . json_encode($url) . " />";  
     130        } 
    110131      } 
    111132      $result .= $this->getOption('existing-html'); 
    112133    } 
    113     return $result . 
    114       $this->renderTag('input', 
    115         array_merge( 
     134    else 
     135    { 
     136      if ($this->hasOption('image-preview') && $this->hasOption('iframe')) 
     137      { 
     138        $result .= "<img id='pk-persistent-upload-preview-$persistid' style='display: none' />";  
     139      } 
     140    } 
     141    if ($this->getOption('iframe')) 
     142    { 
     143      $iframe = $this->getOption('iframe'); 
     144      if (isset($iframe['width'])) 
     145      { 
     146        $width = $iframe['width']; 
     147      } 
     148      else 
     149      { 
     150        $width = 400; 
     151      } 
     152      if (isset($iframe['height'])) 
     153      { 
     154        $height = $iframe['height']; 
     155      } 
     156      else 
     157      { 
     158        $height = 50; 
     159      } 
     160      $result .= "<iframe class='pk-persistent-upload-iframe' id='pk-persistent-upload-iframe-$persistid' width='$width' height='$height' src='" . url_for("pkPersistentFileUpload/iframe?persistid=$persistid") . "'></iframe>"; 
     161      // We continue to build the result string as the fallback for a 
     162      // device that doesn't do iframes 
     163      $info = pkValidatorFilePersistent::getFileInfo($persistid); 
     164      if ($info === false) 
     165      { 
     166        // That's OK, it's just the first pass 
     167        $info = array(); 
     168      } 
     169      // We need these so we can render it correctly from the 
     170      // action in the iframe 
     171      $info['options'] = $this->getOptions(); 
     172      $info['attributes'] = $this->getAttributes(); 
     173      pkValidatorFilePersistent::setFileInfo($persistid, $info); 
     174      if ($this->hasOption('progress')) 
     175      { 
     176        $result .= "<div class='pk-persistent-upload-progress' id='pk-persistent-upload-progress-$persistid'>"; 
     177        { 
     178          $result .= $this->getOption('progress'); 
     179        } 
     180        $result .= "</div>"; 
     181      } 
     182    } 
     183    else 
     184    { 
     185      $result .= 
     186        $this->renderTag('input', 
     187          array_merge( 
     188            array( 
     189              'type' => $this->getOption('type'), 
     190              'name' => $name . '[newfile]'), 
     191            $attributes)); 
     192      $result .=  
     193        $this->renderTag('input', 
    116194          array( 
    117             'type' => $this->getOption('type'), 
    118             'name' => $name . '[newfile]'), 
    119           $attributes)) . 
    120       $this->renderTag('input', 
    121         array( 
    122           'type' => 'hidden', 
    123           'name' => $name . '[persistid]', 
    124           'value' => $persistid)); 
     195            'type' => 'hidden', 
     196            'name' => $name . '[persistid]', 
     197            'value' => $persistid)); 
     198    } 
     199    return $result; 
    125200  } 
    126  
    127201}