/** * Alter and/or hide the file name field depending upon the state of the asset * * - if just received, find a safe name, populate the field, and hide it - after the redirect * - if state is "existing" - don't do anything - the field remains editable * - if state is "pending" or "ready" (new) hide the field * */ function pre_error_check_actions() { $asset = $this->get_element('asset'); // on an upload, set the file_name field to a safe value $filename = $asset->state == 'received' ? $asset->file["name"] : $this->get_value('file_name'); if ($filename) { $filename = $this->get_safer_filename($filename); $filename = sanitize_filename_for_web_hosting($filename); $filename = reason_get_unique_asset_filename($filename, $this->get_value("site_id"), $this->_id); $this->set_value('file_name', $filename); } // hide the file_name field unless it is an existing valid asset if ($asset->state != 'existing') { $this->change_element_type('file_name', 'hidden'); } else { $this->add_required('file_name'); } }
/** * Get a unique filename we'll use for an asset, considering the site_id, desired file_name, and existing asset_id (if any) */ function _reason_get_asset_filename($site_id, $desired_filename, $asset_id = null) { // lets munge our filename for greater safety. $file_name = _reason_get_safer_asset_filename($desired_filename); // lets sanitize the filename for uniqueness. $file_name = reason_get_unique_asset_filename($file_name, $site_id, $asset_id); return $file_name; }