/** * Update a hole * * @static * @param array $data Array of values (urlx,directoryx,role) * @return boolean **/ function update($data) { global $wpdb; $directory = DH_Hole::sanitize_dir($data['directoryx']); if ($directory != $this->directory && $directory != '' && is_writable(dirname($directory)) && file_exists($this->directory)) { wp_mkdir_p(dirname($directory)); @rename($this->directory, $directory); } $this->hotlink = isset($data['hotlink']) ? true : false; $this->directory = $directory; $url = DH_Hole::sanitize_url($data['urlx']); // Check for duplicate name if ($url != $this->url && $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->prefix}drainhole_holes WHERE url LIKE '{$url}'") != 0) { return false; } if ($data['role'] == '-') { $this->role = 'NULL'; } else { $this->role = "'" . $data['role'] . "'"; } $this->url = $url; $this->role_error_url = $wpdb->escape($data['redirect_urlx']); $url = $wpdb->escape($this->url); $directory = $wpdb->escape($this->directory); return $wpdb->query("UPDATE {$wpdb->prefix}drainhole_holes SET url='{$url}', directory='{$directory}', role={$this->role}, role_error_url='{$this->role_error_url}', hotlink='{$this->hotlink}' WHERE id='{$this->id}'"); }
/** * Accepts a FORM-based upload and replaces the file's underlying data * * @param DH_Hole $hole Hole in which the file lives * @return boolean true if successfully uploaded, false if the upload was invalid **/ function upload($hole, $filename, $filedata) { global $wpdb; // If no filename is given then use the uploaded data if ($filename == '' && is_uploaded_file($filedata['tmp_name'])) { $filename = DH_Hole::sanitize_dir(ltrim($filedata['name'], '/')); } if ($filename) { if (is_uploaded_file($filedata['tmp_name'])) { move_uploaded_file($filedata['tmp_name'], $hole->directory . DIRECTORY_SEPARATOR . $filename); } return DH_File::create($hole->id, $filename); } return false; }