Permalink
Browse files

ENHANCEMENT File::$app_categories to replace switch statement in File…

…->appCategory(), and expose data to other use cases (such as filter drop downs in AssetAdmin)
  • Loading branch information...
1 parent ef77b70 commit 98e1fed7463730a2d9d1939d58a90e7854dd2a87 @chillu chillu committed Mar 2, 2012
Showing with 25 additions and 20 deletions.
  1. +25 −20 filesystem/File.php
View
@@ -120,6 +120,28 @@ class File extends DataObject {
'xml','pdf',
);
+ /**
+ * @var array Category identifiers mapped to commonly used extensions.
+ */
+ static $app_categories = array(
+ 'audio' => array(
+ "aif" ,"au" ,"mid" ,"midi" ,"mp3" ,"ra" ,"ram" ,"rm","mp3" ,"wav" ,"m4a" ,"snd" ,"aifc" ,"aiff" ,"wma" ,"apl",
+ "avr" ,"cda" ,"mp4" ,"ogg"
+ ),
+ 'mov' => array(
+ "mpeg" ,"mpg" ,"m1v" ,"mp2" ,"mpa" ,"mpe" ,"ifo" ,"vob","avi" ,"wmv" ,"asf" ,"m2v" ,"qt"
+ ),
+ 'zip' => array(
+ "arc" ,"rar" ,"tar" ,"gz" ,"tgz" ,"bz2" ,"dmg" ,"jar","ace" ,"arj" ,"bz" ,"cab"
+ ),
+ 'image' => array(
+ "bmp" ,"gif" ,"jpg" ,"jpeg" ,"pcx" ,"tif" ,"png" ,"alpha","als" ,"cel" ,"icon" ,"ico" ,"ps"
+ ),
+ 'flash' => array(
+ 'swf', 'fla'
+ )
+ );
+
/**
* @var If this is true, then restrictions set in {@link $allowed_max_file_size} and
* {@link $allowed_extensions} will be applied to users with admin privileges as
@@ -328,27 +350,10 @@ function getCMSFields() {
*/
public function appCategory() {
$ext = strtolower($this->Extension);
- switch($ext) {
- case "aif": case "au": case "mid": case "midi": case "mp3": case "ra": case "ram": case "rm":
- case "mp3": case "wav": case "m4a": case "snd": case "aifc": case "aiff": case "wma": case "apl":
- case "avr": case "cda": case "mp4": case "ogg":
- return "audio";
-
- case "mpeg": case "mpg": case "m1v": case "mp2": case "mpa": case "mpe": case "ifo": case "vob":
- case "avi": case "wmv": case "asf": case "m2v": case "qt":
- return "mov";
-
- case "arc": case "rar": case "tar": case "gz": case "tgz": case "bz2": case "dmg": case "jar":
- case "ace": case "arj": case "bz": case "cab":
- return "zip";
-
- case "bmp": case "gif": case "jpg": case "jpeg": case "pcx": case "tif": case "png": case "alpha":
- case "als": case "cel": case "icon": case "ico": case "ps":
- return "image";
-
- case "swf":
- return "flash";
+ foreach(self::$app_categories as $category => $exts) {
+ if(in_array($ext, $exts)) return $category;
}
+ return false;
}
function CMSThumbnail() {

1 comment on commit 98e1fed

Owner

sminnee commented on 98e1fed Mar 5, 2012

Looks good. The new ability to modify app_categories from config is a nice touch.

Please sign in to comment.