function render($blockContent = NULL) { $loader = WFYAHOO_yuiloader::sharedYuiLoader(); // jquery $loader->addModule('jquery', 'js', NULL, 'http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.js', NULL, NULL, NULL, NULL); // jquery-ui $loader->addModule('jqueryui-css', 'css', NULL, 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css', NULL, NULL, NULL, NULL); $loader->addModule('jqueryui', 'js', NULL, 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.js', array('jquery', 'jqueryui-css'), NULL, NULL, NULL); // query-file-uploader $loader->addModule('jquery-file-uploader', 'js', NULL, $this->getWidgetWWWDir() . '/jquery.fileupload.js', array('jquery'), NULL, NULL, NULL); // and the UI $loader->addModule('jquery-file-uploader-ui-css', 'css', NULL, $this->getWidgetWWWDir() . '/jquery.fileupload-ui.css', NULL, NULL, array('jqueryui-css'), NULL); $loader->addModule('jquery-file-uploader-ui', 'js', NULL, $this->getWidgetWWWDir() . '/jquery.fileupload-ui.js', array('jquery-file-uploader', 'jqueryui', 'jquery-file-uploader-ui-css'), NULL, NULL, NULL); $loader->yuiRequire('jquery-file-uploader-ui'); // @todo In future this should not need to be a WFForm subclass; should be able to drop it in a form anywhere. //$form = $this->getForm(); //if (!$form) throw new WFException("WFHTML5_Uploader must be a child of a WFForm."); $form = $this; // craft a WFRPC that we can insert into the form stream to have our callback fire $rpc = WFRPC::RPC()->setInvocationPath($this->page->module()->invocation()->invocationPath())->setTarget('#page#' . $this->id)->setAction('_handleAsyncSingleUpload')->setForm($this)->setIsAjax(true); $uploadFormData = json_encode($rpc->rpcAsParameters($this)); // figure out vars for drop-in into HTML block $sequentialUploads = var_export($this->maxConcurrentUploads == 1, true); $autoupload = var_export($this->autoupload, true); $fileInputName = "{$this->getInputFileName()}[]"; // HTML $formInnardsHTML = <<<END {$blockContent} <input type="file" name="{$fileInputName}" multiple> <button type="submit" name="action|{$this->id}">Upload</button> <div class="file_upload_label">Click or Drop to Upload</div> END; $html = parent::render($formInnardsHTML); $maxUploadBytesJSON = WFJSON::encode($this->maxUploadBytes); // progress indicators after form since the blueimp plugin takes over the entire form area for drag-n-drop $html .= <<<END <div id="{$this->id}_progressAll" style="display: none;"></div> <table id="{$this->id}_table" style="display: none;"></table> END; $withJqueryJS = <<<END function() { jQuery.noConflict(); jQuery(function () { window.uploader = jQuery('#{$form->id()}').fileUploadUI({ formData: {$uploadFormData}, sequentialUploads: {$sequentialUploads}, beforeSend: function (event, files, index, xhr, handler, callBack) { document.fire ('WFHTML5_Uploader:uploadStart'); jQuery('#{$this->id}_table, #{$this->id}_progressAll').show(); var fileSize = files[index].fileSize ? files[index].fileSize : files[index].size // Firefox calls it file.size instead of file.fileSize if ({$maxUploadBytesJSON} && fileSize > {$maxUploadBytesJSON}) { var json = { 'name': files[index].name, 'description': ('File exceeds maximum file size of ' + {$maxUploadBytesJSON} + ' bytes.'), 'uploadOK': false }; handler.downloadRow = handler.buildDownloadRow(json, handler); handler.replaceNode(handler.uploadRow, handler.downloadRow, null); return; } if ({$autoupload}) { callBack(); } }, progressAllNode: jQuery('#{$this->id}_progressAll'), uploadTable: jQuery('#{$this->id}_table'), onCompleteAll: function() { var autoRedirectToUrlOnCompleteAll = '{$this->autoRedirectToUrlOnCompleteAll}'; if (autoRedirectToUrlOnCompleteAll) { document.fire ('WFHTML5_Uploader:uploadAllComplete'); window.location.href = autoRedirectToUrlOnCompleteAll; } }, buildUploadRow: function (files, index) { return jQuery('<tr>' + '<td width="175">' + files[index].name + '<\\/td>' + '<td width="1"> <\\/td>' + '<td width="250"> <\\/td>' + '<td width="16" class="file_upload_cancel">' + '<button class="ui-state-default ui-corner-all" title="Cancel">' + '<span class="ui-icon ui-icon-cancel">Cancel<\\/span>' + '<\\/button><\\/td>' + '<td class="file_upload_progress" style="width: 160px"><div><\\/div><\\/td>' + '<\\/tr>'); }, buildDownloadRow: function (file, handler) { var thumbHTML = ' '; if (file.thumb) { thumbHTML = '<img s'+'rc="'+file.thumb+'" style="float: right;"/>'; } return jQuery('<tr>' + '<td width="175">' + file.name + '<\\/td>' + '<td width="' + (thumbHTML ? 100 : 1) + '">' + thumbHTML + '<\\/td>' + '<td width="250">' + file.description + '<\\/td>' + '<td width="16"><span class="ui-icon ' + (file.uploadOK ? 'ui-icon-check' : 'ui-icon-alert') + '"><\\/span><\\/td>' + '<td><\\/td>' + '<\\/tr>'); } }); }); } END; $bootstrapJS = $loader->jsLoaderCode($withJqueryJS); $html .= <<<END <script> {$bootstrapJS} </script> END; return $html; }
/** * Constructor. * * Sets up the smarty object for this module. */ function __construct($id, $page) { parent::__construct($id, $page); if ($this->page->module()->invocation()->targetRootModule() and !$this->page->module()->invocation()->isRootInvocation()) { // invocation path of "root" module $this->action = WWW_ROOT . '/' . $this->page->module()->invocation()->rootInvocation()->invocationPath(); } else { // invocation path of the current page, with the current invocation paramenters (these can be overridden by form variables of the same name) $this->action = WWW_ROOT . '/' . $this->page->module()->invocation()->modulePath() . '/' . $this->page->pageName() . $this->page->module()->invocation()->parametersAsPathInfo(); } $this->method = WFForm::METHOD_POST; $this->target = ''; $this->autocomplete = true; $this->disableEnterKeySubmit = false; $this->defaultSubmitID = $this->calculatedDefaultSubmitID = NULL; $this->numberOfSubmitButtons = 0; $this->fieldsToHideFromFormSubmission = array(); $this->isAjax = false; // set up the extra form parameters we need to enable phocoa form detection and processing... $this->phocoaFormParameters = array(); $this->phocoaFormParameters['__modulePath'] = $this->page->module()->invocation()->modulePath() . '/' . $this->page->pageName(); $this->phocoaFormParameters['__formName'] = $this->id; // Calculate CSRF Protetion $csrfParams = WFForm::calculateCSRFParams(); $this->phocoaFormParameters['instanceid'] = $csrfParams['instanceid']; $this->phocoaFormParameters['auth'] = $csrfParams['auth']; }
function restoreState() { // must call super parent::restoreState(); if (isset($_FILES[$this->name])) { if (is_array($_FILES[$this->name]['name'])) { throw new Exception("WFPostletUpload expected a single upload files but multiple found."); } if ($_FILES[$this->name]['error'] == UPLOAD_ERR_OK) { if (is_uploaded_file($_FILES[$this->name]['tmp_name'])) { $this->hasUpload = true; $this->tmpFileName = $_FILES[$this->name]['tmp_name']; $this->originalFileName = $_FILES[$this->name]['name']; $this->mimeType = $_FILES[$this->name]['type']; } else { throw new WFException("File: '{$_FILES[$this->name]['name']}' is not a legitimate PHP upload. This is a hack attempt."); } } else { if ($_FILES[$this->name]['error'] != UPLOAD_ERR_NO_FILE) { // send back error+noretry print "POSTLET REPLY\nPOSTLET:NO\nPOSTLET:UNKNOWN ERROR\nPOSTLET:ABORT THIS\nEND POSTLET REPLY"; exit; } } } }