This repository has been archived by the owner on Apr 4, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
ContentMediaElement.php
165 lines (135 loc) · 4.12 KB
/
ContentMediaElement.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?php if (!defined('TL_ROOT')) die('You cannot access this file directly!');
/**
* Contao Open Source CMS
* Copyright (C) 2005-2011 Leo Feyer
*
* Formerly known as TYPOlight Open Source CMS.
*
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program. If not, please visit the Free
* Software Foundation website at <http://www.gnu.org/licenses/>.
*
* PHP version 5
* @copyright Andreas Schempp 2011
* @author Andreas Schempp <andreas@schempp.ch>
* @license http://opensource.org/licenses/lgpl-3.0.html
* @version $Id: ContentMediaElement.php 43 2011-12-19 18:12:53Z A.Schempp $
*/
class ContentMediaElement extends ContentElement
{
/**
* Template
* @var string
*/
protected $strTemplate = 'ce_mediaelement';
/**
* Element type
* @param string
*/
protected $strType;
/**
* Supported file types
* @var array
*/
protected $arrFileTypes = array
(
'video' => array
(
'mp4' => 'video/mp4',
'webm' => 'video/webm',
'ogv' => 'video/ogg',
),
'audio' => array
(
'mp3' => 'audio/mpeg',
'ogg' => 'audio/ogg',
),
'flash' => array
(
'mp4',
),
);
public function generate()
{
$this->strType = $this->type == 'mediaelement_audio' ? 'audio' : 'video';
if (TL_MODE == 'BE')
{
$objTemplate = new BackendTemplate('be_wildcard');
$objTemplate->wildcard = '### MEDIA ELEMENT (' . strtoupper($this->strType) . ') ###';
return $objTemplate->parse();
}
$GLOBALS['TL_JAVASCRIPT'][] = 'system/modules/mediaelement/html/mediaelement-and-player.js';
$GLOBALS['TL_CSS'][] = 'system/modules/mediaelement/html/mediaelementplayer.css';
$this->multiSRC = deserialize($this->multiSRC, true);
$this->arrFileTypes['poster'] = trimsplit(',', $GLOBALS['TL_CONFIG']['validImageTypes']);
return parent::generate();
}
protected function compile()
{
$arrSize = deserialize($this->mejs_size, true);
$arrFiles = array();
$strFlash = null;
$strPoster = null;
foreach( $this->multiSRC as $file )
{
if (!file_exists(TL_ROOT . '/' . $file))
continue;
if (is_dir(TL_ROOT . '/' . $file))
{
foreach( scan(TL_ROOT . '/' . $file) as $subfile )
{
$type = pathinfo(TL_ROOT . '/' . $file . '/' . $subfile, PATHINFO_EXTENSION);
if (isset($this->arrFileTypes[$this->strType][$type]))
{
$arrFiles[$type] = array('type'=>$this->arrFileTypes[$this->strType][$type], 'src'=>$file . '/' . $subfile);
}
if (in_array($type, $this->arrFileTypes['flash']))
{
$strFlash = $file . '/' . $subfile;
}
if (in_array($type, $this->arrFileTypes['poster']))
{
$strPoster = $file . '/' . $subfile;
}
}
continue;
}
$type = pathinfo(TL_ROOT . '/' . $file, PATHINFO_EXTENSION);
if (isset($this->arrFileTypes[$this->strType][$type]))
{
$arrFiles[$type] = array('type'=>$this->arrFileTypes[$this->strType][$type], 'src'=>$file);
}
if (in_array($type, $this->arrFileTypes['flash']))
{
$strFlash = $file;
}
if (in_array($type, $this->arrFileTypes['poster']))
{
$strPoster = $file;
}
}
$this->Template->id = $this->id;
$this->Template->type = $this->strType;
$this->Template->hasPoster = false;
$this->Template->hasFlash = $strFlash !== null;
$this->Template->flash = $strFlash;
$this->Template->files = $arrFiles;
$this->Template->width = (int) $arrSize[0];
$this->Template->height = (int) $arrSize[1];
if ($strPoster !== null)
{
$this->Template->hasPoster = true;
$this->Template->poster = $this->getImage($strPoster, $arrSize[0], $arrSize[1]);
}
}
}