-
Notifications
You must be signed in to change notification settings - Fork 25
/
MediaManager.php
84 lines (75 loc) · 2.82 KB
/
MediaManager.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
/*
* This file is part of the simple cms project for Yii2
*
* (c) Schallschlucker Agency Paul Kerspe - project homepage <https://github.com/pkerspe/yii2-simple-cms>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace schallschlucker\simplecms;
use Yii;
use yii\base\InvalidConfigException;
/**
* The simple cms media manager to deliver iamages to backend and frontend clients
*
* @author Paul Kerspe
*/
class MediaManager extends \yii\base\Module {
const VERSION = '0.2';
public $controllerNamespace = 'schallschlucker\simplecms\controllers\mediacontroller';
public $defaultRoute='media';
public $mediarepositoryPath;
public $mimetypeMediaTypeMapping = [
'IMAGE' => ['image/jpeg','image/gif','image/png'],
'AUDIO' => ['audio/wav','audio/mpeg3','audio/x-mpeg-3','audio/x-mpequrl'],
'VIDEO' => ['video/mpeg','video/quicktime','video/vdo','application/x-troff-msvideo','video/msvideo'],
];
/**
* @var string The prefix for the frontend module URL.
* @See [[GroupUrlRule::prefix]]
*/
public $urlPrefix = 'media'; //for the url in the forntend to be called
public $routePrefix = 'media_manager'; //to map to the module id given in the config
/**
* Returns module components.
*
* @return array
*/
protected function getModuleComponents() {
return [
];
}
/**
* @inheritdoc
*/
public function __construct($id, $parent = null, $config = []) {
foreach ( $this->getModuleComponents () as $name => $component ) {
if (! isset ( $config ['components'] [$name] )) {
$config ['components'] [$name] = $component;
} elseif (is_array ( $config ['components'] [$name] ) && ! isset ( $config ['components'] [$name] ['class'] )) {
$config ['components'] [$name] ['class'] = $component ['class'];
}
}
if( empty($this->mediarepositoryPath) ){
$this->mediarepositoryPath = Yii::getAlias('@webroot').DIRECTORY_SEPARATOR.'mediarepository';
}
parent::__construct ( $id, $parent, $config );
}
public function getMediaTypeForMimeType($mimeTypeString){
foreach($this->mimetypeMediaTypeMapping as $mediaType => $mimetypes){
/* @var $mimetypes array */
if(in_array($mimeTypeString,$mimetypes)) return $mediaType;
}
return MediaController::$MEDIA_TYPE_UNKNOWN;
}
public function getMediarepositoryBasePath(){
//use FileHelper::normalizePath () here maybe, to make sure path is somewhat cleaned
return $this->mediarepositoryPath;
//return Yii::getAlias('@webroot').DIRECTORY_SEPARATOR.'mediarepository';
}
public function getThumbnailRepostoryPath(){
return $this->mediarepositoryPath.DIRECTORY_SEPARATOR.'thumbnail_repository';
//return Yii::getAlias('@webroot').DIRECTORY_SEPARATOR.'mediarepository'.DIRECTORY_SEPARATOR.'thumbnail_repository';
}
}