public function set_path($new_path) { $pathinfo = awpcp_utf8_pathinfo($new_path); $this->file->path = $new_path; $this->file->name = $pathinfo['basename']; $this->file->dirname = $pathinfo['dirname']; $this->file->filename = $pathinfo['filename']; $this->file->extension = $pathinfo['extension']; }
public function delete() { global $wpdb; $info = awpcp_utf8_pathinfo(AWPCPUPLOADDIR . $this->name); $filename = preg_replace("/\\.{$info['extension']}/", '', $info['basename']); $filenames = array(AWPCPUPLOADDIR . "{$info['basename']}", AWPCPUPLOADDIR . "{$filename}-large.{$info['extension']}", AWPCPTHUMBSUPLOADDIR . "{$info['basename']}", AWPCPTHUMBSUPLOADDIR . "{$filename}-primary.{$info['extension']}"); foreach ($filenames as $filename) { if (file_exists($filename)) { @unlink($filename); } } $query = 'DELETE FROM ' . AWPCP_TABLE_ADPHOTOS . ' WHERE key_id = %d'; $result = $wpdb->query($wpdb->prepare($query, $this->id)); return $result === false ? false : true; }
private function get_uploaded_file_info($realname, $file_path, $progress = 'incomplete') { $mime_type = $this->mime_types->get_file_mime_type($file_path); $pathinfo = awpcp_utf8_pathinfo($file_path); return (object) array('path' => $file_path, 'realname' => strtolower($realname), 'name' => $pathinfo['basename'], 'dirname' => $pathinfo['dirname'], 'filename' => $pathinfo['filename'], 'extension' => $pathinfo['extension'], 'mime_type' => $mime_type, 'is_complete' => $progress === 'complete' ? true : false); }
/** * Resize images if they're too wide or too tall based on admin's Image Settings. * Requires both max width and max height to be set otherwise no resizing * takes place. If the image exceeds either max width or max height then the * image is resized proportionally. * * @deprecated 3.4 */ function awpcp_resizer($filename, $dir) { $maxwidth = get_awpcp_option('imgmaxwidth'); $maxheight = get_awpcp_option('imgmaxheight'); if ('' == trim($maxheight) || '' == trim($maxwidth)) { return false; } $parts = awpcp_utf8_pathinfo($filename); if ('jpg' == $parts['extension'] || 'jpeg' == $parts['extension']) { $src = imagecreatefromjpeg($dir . $filename); } else { if ('png' == $parts['extension']) { $src = imagecreatefrompng($dir . $filename); } else { $src = imagecreatefromgif($dir . $filename); } } list($width, $height) = getimagesize($dir . $filename); if ($width < $maxwidth && $height < $maxheight) { return true; } $newwidth = ''; $newheight = ''; $aspect_ratio = (double) $height / $width; $newheight = $maxheight; $newwidth = round($newheight / $aspect_ratio); if ($newwidth > $maxwidth) { $newwidth = $maxwidth; $newheight = round($newwidth * $aspect_ratio); } $tmp = imagecreatetruecolor($newwidth, $newheight); imagecopyresampled($tmp, $src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); $newname = $dir . $filename; switch ($parts['extension']) { case 'gif': @imagegif($tmp, $newname); break; case 'png': @imagepng($tmp, $newname, 0); break; case 'jpg': case 'jpeg': @imagejpeg($tmp, $newname, 100); break; } imagedestroy($src); imagedestroy($tmp); return true; }
public function create_thumbnail_for_media($media, $source_image) { $filename = sprintf("%s-%d", awpcp_utf8_pathinfo($media->name, PATHINFO_FILENAME), $media->id); return $this->create_thumbnail($source_image, $filename); }
/** * XXX: Moved to ImageFileProcessor class. */ function awpcp_make_intermediate_size($file, $directory, $width, $height, $crop = false, $suffix = '') { $path_info = awpcp_utf8_pathinfo($file); $filename = preg_replace("/\\.{$path_info['extension']}/", '', $path_info['basename']); $suffix = empty($suffix) ? '.' : "-{$suffix}."; $newpath = trailingslashit($directory) . $filename . $suffix . $path_info['extension']; $image = image_make_intermediate_size($file, $width, $height, $crop); if (!is_writable($directory)) { @chmod($directory, awpcp_directory_permissions()); } if (is_array($image) && !empty($image)) { $tmppath = trailingslashit($path_info['dirname']) . $image['file']; $result = rename($tmppath, $newpath); } else { $result = copy($file, $newpath); } @chmod($newpath, 0644); return $result; }
public function delete($media) { global $wpdb; $query = 'DELETE FROM ' . AWPCP_TABLE_MEDIA . ' WHERE id = %d'; $result = $wpdb->query($wpdb->prepare($query, $media->id)); if ($result === false) { return false; } $info = awpcp_utf8_pathinfo(AWPCPUPLOADDIR . $media->name); $filenames = apply_filters('awpcp-file-associated-paths', array(AWPCPUPLOADDIR . "{$media->path}", AWPCPUPLOADDIR . "{$info['basename']}", AWPCPUPLOADDIR . "{$info['filename']}-large.{$info['extension']}", AWPCPTHUMBSUPLOADDIR . "{$info['basename']}", AWPCPTHUMBSUPLOADDIR . "{$info['filename']}-primary.{$info['extension']}"), $media); foreach ($filenames as $filename) { if (file_exists($filename)) { @unlink($filename); } } return true; }
/** * @param string $path Path to the file whose unique filename needs to be generated. * @param string $filename Target filename. The unique filename will be as similar as * possible to this name. * @param array $directories The generated name must be unique in all directories in this array. * @since 3.4 */ function awpcp_unique_filename($path, $filename, $directories) { $pathinfo = awpcp_utf8_pathinfo($filename); $name = $pathinfo['filename']; $extension = $pathinfo['extension']; $file_size = filesize($path); $timestamp = microtime(); $salt = wp_salt(); $counter = 0; do { $hash = hash('crc32b', "{$name}-{$extension}-{$file_size}-{$timestamp}-{$salt}-{$counter}"); $new_filename = "{$name}-{$hash}.{$extension}"; $counter = $counter + 1; } while (awpcp_is_filename_already_used($new_filename, $directories)); return $new_filename; }