Skip to content

Commit

Permalink
Merge pull request #6 from JamesJohns/generalplugin-checksum
Browse files Browse the repository at this point in the history
Add md5 and sha1 checksum to General.
  • Loading branch information
Gavin Davies committed Aug 20, 2013
2 parents 8b42a3a + 8ddca3e commit d8b7da1
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions lib/BoxUK/Describr/Plugins/BoxUK/GeneralPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,16 @@ public function getMatchingFileExtensions()
}

/**
* @return array with keys "extension", "type", "mimeType"
* @return array with keys "extension", "type", "mimeType", "fileSizeInBytes", "md5Checksum" and "sha1Checksum"
*/
public function setAttributes()
{
$this->attributes['extension'] = $this->getFileExtension();
$this->attributes['type'] = $this->getFileType();
$this->attributes['mimeType'] = $this->mimeTypeOfCurrentFile;
$this->attributes['fileSizeInBytes'] = $this->getFileSizeInBytes();
$this->attributes['md5Checksum'] = $this->getFileMd5Checksum();
$this->attributes['sha1Checksum'] = $this->getFileSha1Checksum();

$this->addAutoTagsByFileSize();
}
Expand Down Expand Up @@ -85,10 +87,10 @@ private function addAutoTagsByFileSize()
return;
}

$sizeInKb = filesize ($this->fullPathToFileOnDisk) / 1024;
$sizeInKb = filesize($this->fullPathToFileOnDisk) / 1024;

$function = 'getSizeOf' . ucfirst($this->getFileType());
if(!function_exists($function)) {
if (!function_exists($function)) {
$function = 'getSizeOf';
}
$fileSizeDescription = $this->$function($sizeInKb);
Expand All @@ -108,7 +110,7 @@ protected function getSizeOf($sizeInKb)
$fileSizeDescription = 'Extra Large';
if ($sizeInKb < 32) {
$fileSizeDescription = 'Extra Small';
}else if ($sizeInKb < 128) {
} elseif ($sizeInKb < 128) {
$fileSizeDescription = 'Small';
} elseif ($sizeInKb < 512) {
$fileSizeDescription = 'Medium';
Expand All @@ -128,7 +130,7 @@ protected function getSizeOfImage($sizeInKb)
$fileSizeDescription = 'Extra Large';
if ($sizeInKb < 16) {
$fileSizeDescription = 'Extra Small';
}else if ($sizeInKb < 32) {
} elseif ($sizeInKb < 32) {
$fileSizeDescription = 'Small';
} elseif ($sizeInKb < 64) {
$fileSizeDescription = 'Medium';
Expand Down Expand Up @@ -158,7 +160,7 @@ protected function getSizeOfDocument($sizeInKb)
$fileSizeDescription = 'Extra Large';
if ($sizeInKb < 32) {
$fileSizeDescription = 'Extra Small';
}else if ($sizeInKb < 256) {
} elseif ($sizeInKb < 256) {
$fileSizeDescription = 'Small';
} elseif ($sizeInKb < 1024) {
$fileSizeDescription = 'Medium';
Expand All @@ -178,7 +180,7 @@ protected function getSizeOfMovie($sizeInKb)
$fileSizeDescription = 'Extra Large';
if ($sizeInKb < 128) {
$fileSizeDescription = 'Extra Small';
}else if ($sizeInKb < 512) {
} elseif ($sizeInKb < 512) {
$fileSizeDescription = 'Small';
} elseif ($sizeInKb < 2048) {
$fileSizeDescription = 'Medium';
Expand All @@ -187,4 +189,22 @@ protected function getSizeOfMovie($sizeInKb)
}
return $fileSizeDescription;
}

/**
* Get file md5 hash.
* @return string
*/
protected function getFileMd5Checksum()
{
return md5_file($this->fullPathToFileOnDisk);
}

/**
* Get file sha1 hash.
* @return string
*/
protected function getFileSha1Checksum()
{
return sha1_file($this->fullPathToFileOnDisk);
}
}

0 comments on commit d8b7da1

Please sign in to comment.