/
class-html5media.php
166 lines (147 loc) · 4.7 KB
/
class-html5media.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
165
166
<?php
/**
* HTML5Media plugin for zenphoto
* just drop into your plugins directory
*
* built from class-textobject
* @author Richard Laskey (rlaskey.org)
* @package plugins
*/
$plugin_is_filter = 9|CLASS_PLUGIN;
$plugin_description = gettext('HTML5 video and audio handling.');
$plugin_author = 'Richard Laskey (rlaskey.org)';
$plugin_version = '1.0.0';
# audio
addPluginType('ogg','HTML5Media');
addPluginType('oga','HTML5Media');
addPluginType('mp3','HTML5Media');
addPluginType('m4a','HTML5Media');
addPluginType('wma','HTML5Media');
# video
addPluginType('ogv','HTML5Media');
addPluginType('mp4','HTML5Media');
addPluginType('m4v','HTML5Media');
addPluginType('mov','HTML5Media');
addPluginType('3gp','HTML5Media');
addPluginType('flv','HTML5Media');
addPluginType('mpg','HTML5Media');
addPluginType('avi','HTML5Media');
addPluginType('wmv','HTML5Media');
class HTML5Media extends _Image {
/* corresponding to HTML5 tags and their file extensions.
* yes, I'm way over-doing it in terms of what browser actually support.
* a blanked out <video> tag is not the end of the world, however. */
public $mediaTypes = array(
'audio' => array('ogg','oga','mp3','m4a','wma'),
'video' => array('ogv','mp4','m4v','mov','3gp','flv','mpg','avi','wmv')
);
/**
* @param object $album the owner album
* @param string $filename the filename of the media file
*/
function __construct(&$album, $filename) {
global $_zp_supported_images;
// $album is an Album object; it should already be created.
if ( ! is_object($album)) return NULL;
if ( ! $this->classSetup($album, $filename)) { // spoof attempt
$this->exists = FALSE;
return;
}
$this->sidecars = $_zp_supported_images;
$this->objectsThumb = checkObjectsThumb($album->localpath, $filename);
// Check if the file exists.
if ( ! file_exists($this->localpath) || is_dir($this->localpath)) {
$this->exists = FALSE;
return;
}
/* check the file extension, and then set the mediaType if supported */
$extension = substr(strtolower(strrchr($this->localpath,'.')),1);
foreach ($this->mediaTypes AS $t => $l) {
if (in_array($extension,$l)) {
$this->mediaType = $t;
break;
}
}
unset($t,$l);
$this->updateDimensions();
if (parent::PersistentObject('images', array('filename'=>$filename, 'albumid'=>$this->album->id), 'filename', FALSE, FALSE)) {
$this->set('mtime', $ts = filemtime($this->localpath));
$this->updateMetaData();
$this->save();
zp_apply_filter('new_image', $this);
}
}
/**
* Required template function
*
* @return string replacement for the <img /> normally inserted by template
*/
function getBody()
{
/* the result here is wrapped around a <div><strong><a>
* so, we are closing those tags and starting new ones */
$uri = $this->getFullImage();
return
'</a></strong>'.
(isset($this->mediaType) ? '<'.$this->mediaType.' src="'.$uri.
'" controls="true"></'.$this->mediaType.'>'
: '').
'</div>'.
'<p>'.
'<a href="'.$uri.'">Right-click, download file</a>.'.
'</p>'.
'<div><strong><a>';
}
/**
* @param string $alt Alt text for the url
* @param int $size size
* @param int $width width
* @param int $height height
* @param int $cropw crop width
* @param int $croph crop height
* @param int $cropx crop x axis
* @param int $cropy crop y axis
* @param string $class Optional style class
* @param string $id Optional style id
* @param bool $thumbStandin set to true to treat as thumbnail
* @param bool $effects ignored
* @return string
*/
function getCustomImage($size, $width, $height, $cropw, $croph, $cropx, $cropy, $thumbStandin = FALSE, $effects = NULL) {
return $this->getBody();
}
function getSizedImage($size) {return $this->getBody();}
/**
* @param string $path override path
* @return string filesystem path, for internal processing
*/
function getThumbImageFile($path = NULL) {
if (is_null($path)) {$path = SERVERPATH;}
if ($this->objectsThumb != NULL) {
$imgfile = getAlbumFolder().$this->album->name.'/'.$this->objectsThumb;
} else {
/* use a small filmstrip JPG in ZP;
* check if it's in the current theme, first */
$img = 'movie.jpg';
$imgfile = $path.'/'.THEMEFOLDER.'/'.
internalToFilesystem($this->album->gallery->getCurrentTheme()).
'/images/'.$img;
if ( ! file_exists($imgfile)) {
$imgfile = $path.'/plugins/'.substr(basename(__FILE__), 0, -4).
'/'.$img;
}
}
return $imgfile;
}
/**
* @param string $type 'image' or 'album'
* @return string the URL for the thumbnail image
*/
function getThumb($type='image') {
return WEBPATH.'/zp-core/images/movie.jpg';
}
function updateDimensions() {
$this->set('width', getOption('image_size'));
$this->set('height', getOption('image_size'));
}
}