/** * TrashFile function. * * @access protected * @param mixed $FileID * @return void */ protected function TrashFile($FileID) { $Media = $this->MediaModel()->GetID($FileID); if ($Media) { $this->MediaModel()->Delete($Media); $Deleted = FALSE; if (!$Deleted) { $DirectPath = MediaModel::PathUploads() . DS . $Media->Path; if (file_exists($DirectPath)) { $Deleted = @unlink($DirectPath); } } if (!$Deleted) { $CalcPath = FileUploadPlugin::FindLocalMedia($Media, TRUE, TRUE); if (file_exists($CalcPath)) { $Deleted = @unlink($CalcPath); } } } }
/** * Delete an uploaded file & its media record. * * @access protected * @param int $MediaID Unique ID on Media table. */ protected function TrashFile($MediaID) { $Media = $this->MediaModel()->GetID($MediaID); if ($Media) { $this->MediaModel()->Delete($Media); $Deleted = FALSE; // Allow interception $this->EventArguments['Parsed'] = Gdn_Upload::Parse($Media->Path); $this->EventArguments['Handled'] =& $Deleted; // Allow skipping steps below $this->FireEvent('TrashFile'); if (!$Deleted) { $DirectPath = MediaModel::PathUploads() . DS . $Media->Path; if (file_exists($DirectPath)) { $Deleted = @unlink($DirectPath); } } if (!$Deleted) { $CalcPath = FileUploadPlugin::FindLocalMedia($Media, TRUE, TRUE); if (file_exists($CalcPath)) { $Deleted = @unlink($CalcPath); } } } }
public function Delete($Media, $DeleteFile = TRUE) { $MediaID = FALSE; if (is_a($Media, 'stdClass')) { $Media = (array) $Media; } if (is_numeric($Media)) { $MediaID = $Media; } elseif (array_key_exists('MediaID', $Media)) { $MediaID = $Media['MediaID']; } if ($MediaID) { $Media = $this->GetID($MediaID); $this->SQL->Delete($this->Name, array('MediaID' => $MediaID), FALSE); if ($DeleteFile) { $DirectPath = MediaModel::PathUploads() . DS . GetValue('Path', $Media); if (file_exists($DirectPath)) { @unlink($DirectPath); } } } else { $this->SQL->Delete($this->Name, $Media, FALSE); } }
public static function ThumbnailUrl($Media) { $Width = GetValue('ImageWidth', $Media); $Height = GetValue('ImageHeight', $Media); if (!$Width || !$Height) { return '/plugins/FileUpload/images/file.png'; } $RequiresThumbnail = FALSE; if (self::ThumbnailHeight() && $Height > self::ThumbnailHeight()) { $RequiresThumbnail = TRUE; } elseif (self::ThumbnailWidth() && $Width > self::ThumbnailWidth()) { $RequiresThumbnail = TRUE; } $Path = ltrim(GetValue('Path', $Media), '/'); if ($RequiresThumbnail) { $ThumbPath = MediaModel::PathUploads() . "/thumbnails/{$Path}"; if (file_exists(MediaModel::PathUploads() . "/thumbnails/{$Path}")) { $Result = "/uploads/thumbnails/{$Path}"; } else { $Result = "/utility/thumbnail/{$Path}"; } } else { $Result = "/uploads/{$Path}"; } return $Result; }