/** * The on_submit event handles all file uploads immediately. They are passed through * the type at that point. This is required, since we do not have persistent upload * file management on the QF side. Deletions take precedence over uploads. */ function on_submit($results) { // TODO: refactor these checks to separate methods if (array_key_exists("{$this->name}_delete", $results)) { if (!$this->_type->delete_all_attachments()) { debug_add("Failed to delete all attached old images on the field {$this->name}.", MIDCOM_LOG_ERROR); } // Adapt the form: $this->_cast_formgroup_to_upload(); } else { if (array_key_exists("{$this->name}_rotate", $results)) { // The direction is the key (since the value is the point clicked on the image input) list($direction, $dummy) = each($results["{$this->name}_rotate"]); if (!$this->_type->rotate($direction)) { debug_add("Failed to rotate image on the field {$this->name}.", MIDCOM_LOG_ERROR); } } else { if ($this->_upload_element->isUploadedFile()) { $file = $this->_upload_element->getValue(); if ($this->show_title) { $title = $results["{$this->name}_title"]; } else { $title = ''; } if (!$this->_type->set_image($file['name'], $file['tmp_name'], $title)) { debug_add("Failed to process image {$this->name}.", MIDCOM_LOG_INFO); $this->_cast_formgroup_to_upload(); } else { $this->_cast_formgroup_to_replacedelete(); } } } } }
/** * Override createElement event to add max files */ function onQuickFormEvent($event, $arg, &$caller) { if ($event == 'createElement') { $className = get_class($this); $this->{$className}($arg[0], $arg[1] . ' (' . get_string('maxsize', '', display_size($caller->getMaxFileSize())) . ')', $arg[2]); return true; } return parent::onQuickFormEvent($event, $arg, $caller); }
/** * @param $value array Uploaded file info (from $_FILES) * @param null $options * @return bool */ public function validate($elementValue, $maxSize) { if (!empty($elementValue['error']) && (UPLOAD_ERR_FORM_SIZE == $elementValue['error'] || UPLOAD_ERR_INI_SIZE == $elementValue['error'])) { return false; } if (!HTML_QuickForm_file::_ruleIsUploadedFile($elementValue)) { return true; } return $maxSize >= @filesize($elementValue['tmp_name']); }
/** * Checks if the given element contains an uploaded file of the right mime type * * @param array Uploaded file info (from $_FILES) * @param mixed Mime Type (can be an array of allowed types) * @access private * @return bool true if mimetype is correct, false otherwise */ public function validate($elementValue, $mimeType) { if (!HTML_QuickForm_file::_ruleIsUploadedFile($elementValue)) { return true; } if (is_array($mimeType)) { return in_array($elementValue['type'], $mimeType); } return $elementValue['type'] == $mimeType; }
function toHtml() { $field =& $this->getFieldDef(); $ID = 'temp' . rand(1, 1000000); //$_REQUEST['ID'];//get current user's ID whose video will be recorded if ($this->record and $this->record->getValue('id')) { $ID = $this->record->getValue('id'); } $value = $ID; //get ray directory $ray_dir = "http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_NAME']); if ($ray_dir[strlen($ray_dir) - 1] != '/') { $ray_dir .= '/'; } $ray_xml = $ray_dir . "get_xml.php"; $out = <<<END <div class="help">If you have a web camera you can press the <em>Record</em> button below to record your piece. <a href="troubleshooting.php">Troubleshooting instructions</a>.</div> <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="348" height="248" id="ray_recorder" align="middle"> <param name="allowScriptAccess" value="always" /> <param name="movie" value="{$ray_dir}ray_recorder.swf" /> <param name="quality" value="high" /> <param name="wmode" value="TRANSPARENT" /> <param name="FlashVars" value="ID={$ID}&url={$ray_xml}" /> <embed src="{$ray_dir}ray_recorder.swf" WMODE="TRANSPARENT" quality="high" bgcolor="#ffffff" width="348" height="248" name="ray_recorder" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" FlashVars="ID={$ID}&url={$ray_xml}" pluginspage="http://www.macromedia.com/go/getflashplayer" /> </object><br/> <div class="help">Or upload a movie file from your camera, phone, or computer...</div> <input name="{$this->getName()}__webcam__" type="hidden" value="{$value}" /> END; return $out . parent::toHtml(); }
/** * Checks if the given element contains an uploaded file of the filename regex * * @param array Uploaded file info (from $_FILES) * @param string Regular expression * @access private * @return bool true if name matches regex, false otherwise */ function _ruleCheckFileName($elementValue, $regex) { if (!HTML_QuickForm_file::_ruleIsUploadedFile($elementValue)) { return true; } return preg_match($regex, $elementValue['name']); }
function _findValue(&$values) { if (is_null(parent::_findValue())) { return HTML_QuickForm_Input::_findValue($values); } }
/** * Checks if the element contains an uploaded file * * @access public * @return bool true if file has been uploaded, false otherwise */ public function isUploadedFile() { return HTML_QuickForm_file::_ruleIsUploadedFile($this->_value); }