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: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347: 348: 349: 350: 351: 352: 353: 354: 355: 356: 357: 358: 359: 360: 361: 362: 363: 364: 365: 366: 367: 368: 369: 370: 371: 372: 373: 374: 375: 376: 377: 378: 379: 380: 381: 382: 383: 384: 385: 386: 387: 388: 389: 390: 391: 392: 393: 394: 395: 396: 397: 398: 399: 400: 401: 402: 403: 404: 405: 406: 407: 408: 409: 410: 411: 412: 413: 414: 415: 416: 417: 418: 419: 420: 421: 422: 423: 424: 425: 426: 427: 428: 429: 430: 431: 432: 433: 434: 435: 436: 437: 438: 439: 440: 441: 442: 443: 444: 445: 446: 447: 448: 449: 450: 451: 452:
<?php
$plugin_is_filter = 990 | CLASS_PLUGIN;
$plugin_description = gettext('The Zenphoto <em>audio-video</em> handler.');
$plugin_notice = gettext('This plugin must always be enabled to use multimedia content. It supports mp4/m4v video and mp3 audio natively in capable browsers. For more support you should also enable a multimedia player. See the info of the player you use to see how it is configured.');
$plugin_author = "Stephen Billard (sbillard), Malte Müller (acrylian)";
$plugin_category = gettext('Media');
Gallery::addImageHandler('mp4', 'Video');
Gallery::addImageHandler('m4v', 'Video');
Gallery::addImageHandler('m4a', 'Video');
Gallery::addImageHandler('mp3', 'Video');
$option_interface = 'VideoObject_Options';
define('GETID3_INCLUDEPATH', SERVERPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/class-video/getid3/');
require_once(dirname(__FILE__) . '/class-video/getid3/getid3.php');
class VideoObject_Options {
function __construct() {
purgeOption('class-video_mov_w');
purgeOption('class-video_mov_h');
purgeOption('class-video_3gp_w');
purgeOption('class-video_3gp_h');
purgeOption('class-video_videoalt');
}
function getOptionsSupported() {
return array(gettext('Watermark default images') => array(
'key' => 'video_watermark_default_images',
'type' => OPTION_TYPE_CHECKBOX,
'order' => 0,
'desc' => gettext('Check to place watermark image on default thumbnail images.'))
);
}
}
class Video extends Image {
var $videoalt = array();
function __construct($album, $filename, $quiet = false) {
global $_zp_supported_images;
$msg = false;
if (!is_object($album) || !$album->exists) {
$msg = gettext('Invalid video instantiation: Album does not exist');
} else if (!$this->classSetup($album, $filename) || !file_exists($this->localpath) || is_dir($this->localpath)) {
$msg = gettext('Invalid video instantiation: file does not exist.');
}
if ($msg) {
$this->exists = false;
if (!$quiet) {
trigger_error($msg, E_USER_ERROR);
}
return;
}
$alts = explode(',', extensionEnabled('class-video_videoalt'));
foreach ($alts as $alt) {
$this->videoalt[] = trim(strtolower($alt));
}
$this->sidecars = $_zp_supported_images;
$this->video = true;
$this->objectsThumb = checkObjectsThumb($this->localpath);
$album_name = $album->name;
$this->updateDimensions();
$new = $this->instantiate('images', array('filename' => $filename, 'albumid' => $this->album->getID()), 'filename', true, empty($album_name));
if ($new || $this->filemtime != $this->get('mtime')) {
if ($new)
$this->setTitle($this->displayname);
$this->updateMetaData();
$this->set('mtime', $this->filemtime);
$this->save();
if ($new)
zp_apply_filter('new_image', $this);
}
}
function updateDimensions() {
global $_zp_multimedia_extension;
$ext = getSuffix($this->filename);
$h = $_zp_multimedia_extension->getHeight($this);
$w = $_zp_multimedia_extension->getWidth($this);
$this->set('width', $w);
$this->set('height', $h);
}
function getThumbImageFile($path = NULL) {
global $_zp_gallery;
if (is_null($path))
$path = SERVERPATH;
if (is_null($this->objectsThumb)) {
$suffix = getSuffix($this->filename);
switch ($suffix) {
case "mp3":
$img = '/mp3Default.png';
break;
case "mp4":
$img = '/mp4Default.png';
break;
case "m4v":
$img = '/m4vDefault.png';
break;
case "m4a":
$img = '/m4aDefault.png';
break;
default:
$img = '/multimediaDefault.png';
break;
}
$imgfile = $path . '/' . THEMEFOLDER . '/' . internalToFilesystem($_zp_gallery->getCurrentTheme()) . '/images' . $img;
if (!file_exists($imgfile)) {
$imgfile = $path . '/' . THEMEFOLDER . '/' . internalToFilesystem($_zp_gallery->getCurrentTheme()) . '/images/multimediaDefault.png';
if (!file_exists($imgfile)) {
$imgfile = $path . "/" . ZENFOLDER . '/' . PLUGIN_FOLDER . '/' . substr(basename(__FILE__), 0, -4) . $img;
}
}
} else {
$imgfile = ALBUM_FOLDER_SERVERPATH . internalToFilesystem($this->imagefolder) . '/' . $this->objectsThumb;
}
return $imgfile;
}
function getThumb($type = 'image') {
$ts = getOption('thumb_size');
if (getOption('thumb_crop')) {
$crop = true;
$sw = getOption('thumb_crop_width');
$sh = getOption('thumb_crop_height');
list($custom, $cw, $ch, $cx, $cy) = $this->getThumbCropping($ts, $sw, $sh);
} else {
$crop = false;
$sw = $sh = $cw = $ch = $cx = $cy = null;
}
$wmt = getOption('Video_watermark');
if (empty($wmt)) {
$wmt = getWatermarkParam($this, WATERMARK_THUMB);
}
if ($this->objectsThumb == NULL) {
$mtime = $cx = $cy = NULL;
$filename = makeSpecialImageName($this->getThumbImageFile());
if (!getOption('video_watermark_default_images')) {
$wmt = '!';
}
} else {
$filename = filesystemToInternal($this->objectsThumb);
$mtime = filemtime(ALBUM_FOLDER_SERVERPATH . '/' . internalToFilesystem($this->imagefolder) . '/' . $this->objectsThumb);
}
$args = getImageParameters(array($ts, $sw, $sh, $cw, $ch, $cx, $cy, null, true, $crop, true, $wmt, NULL, NULL), $this->album->name);
return getImageURI($args, $this->album->name, $filename, $mtime);
}
function getThumbDimensions() {
if (!is_null($this->thumbdimensions)) {
return $this->thumbdimensions;
}
$imgfile = $this->getThumbImageFile();
$image = zp_imageGet($imgfile);
$width = zp_imageWidth($image);
$height = zp_imageHeight($image);
return $this->thumbdimensions = array(
'width' => $width,
'height' => $height
);
}
function getCustomImage($size, $width, $height, $cropw, $croph, $cropx, $cropy, $thumbStandin = false, $effects = NULL) {
if ($thumbStandin) {
$wmt = getOption('Video_watermark');
if (empty($wmt)) {
$wmt = getWatermarkParam($this, WATERMARK_THUMB);
}
} else {
$wmt = NULL;
}
if ($thumbStandin & 1) {
$args = array($size, $width, $height, $cropw, $croph, $cropx, $cropy, NULL, $thumbStandin, NULL, $thumbStandin, NULL, NULL, NULL);
if ($this->objectsThumb == NULL) {
$filename = makeSpecialImageName($this->getThumbImageFile());
if (!getOption('video_watermark_default_images')) {
$args[11] = '!';
}
$mtime = NULL;
} else {
$filename = filesystemToInternal($this->objectsThumb);
$mtime = filemtime(ALBUM_FOLDER_SERVERPATH . '/' . internalToFilesystem($this->imagefolder) . '/' . $this->objectsThumb);
}
return getImageURI($args, $this->album->name, $filename, $this->filemtime);
} else {
$args = getImageParameters(array($size, $width, $height, $cropw, $croph, $cropx, $cropy, NULL, $thumbStandin, NULL, $thumbStandin, $wmt, NULL, $effects), $this->album->name);
$filename = $this->filename;
return getImageURI($args, $this->album->name, $filename, $this->filemtime);
}
}
function getSizedImage($size) {
$width = $this->getWidth();
$height = $this->getHeight();
if ($width > $height) {
$height = $height * $size / $width;
} else {
$width = $width * $size / $height;
}
return $this->getContent($width, $height);
}
function getFullImageURL() {
if ($vid = parent::getFullImageURL()) {
$folder = ALBUM_FOLDER_SERVERPATH . internalToFilesystem($this->album->getFileName());
$video = stripSuffix($this->filename);
$curdir = getcwd();
chdir($folder);
$candidates = safe_glob($video . '.*');
chdir($curdir);
foreach ($candidates as $target) {
$ext = getSuffix($target);
if (in_array($ext, $this->videoalt)) {
$vid = stripSuffix($vid) . '.' . substr(strrchr($target, "."), 1);
}
}
}
return $vid;
}
function getContent($w = NULL, $h = NULL) {
global $_zp_multimedia_extension;
if (is_null($w))
$w = $this->getWidth();
if (is_null($h))
$h = $this->getHeight();
$ext = getSuffix($this->getFullImage());
return $_zp_multimedia_extension->getPlayerConfig($this, NULL, NULL, $w, $h);
}
private function getMetaDataID3() {
$suffix = getSuffix($this->localpath);
if (in_array($suffix, array('m4a', 'm4v', 'mp3', 'mp4'))) {
$getID3 = new getID3;
@set_time_limit(30);
$ThisFileInfo = $getID3->analyze($this->localpath);
getid3_lib::CopyTagsToComments($ThisFileInfo);
if (is_array($ThisFileInfo)) {
return $ThisFileInfo;
}
}
return NULL;
}
function updateMetaData() {
global $_zp_exifvars;
parent::updateMetaData();
$process = array();
foreach ($_zp_exifvars as $field => $exifvar) {
if ($exifvar[5] && $exifvar[0] == 'VIDEO') {
$process[$field] = $exifvar;
}
}
if (!empty($process)) {
$ThisFileInfo = $this->getMetaDataID3();
if (is_array($ThisFileInfo)) {
foreach ($ThisFileInfo as $key => $info) {
if (is_array($info)) {
switch ($key) {
case 'comments':
foreach ($info as $key1 => $data) {
$ThisFileInfo[$key1] = array_shift($data);
}
break;
case 'audio':
case 'video':
foreach ($info as $key1 => $data) {
$ThisFileInfo[$key1] = $data;
}
break;
case 'error':
$msg = sprintf(gettext('getid3 exceptions for %1$s::%2$s'), $this->album->name, $this->filename);
foreach ($info as $data) {
$msg .= "\n" . $data;
}
debugLog($msg);
break;
default:
break;
}
unset($ThisFileInfo[$key]);
}
}
foreach ($process as $field => $exifvar) {
if (isset($ThisFileInfo[$exifvar[1]])) {
$data = $ThisFileInfo[$exifvar[1]];
if (!empty($data)) {
$this->set($field, $data);
$this->set('hasMetadata', 1);
}
}
}
$title = $this->get('VideoTitle');
if (!empty($title)) {
$this->setTitle($title);
}
}
}
}
}
class pseudoPlayer {
public $name = '';
private $width = 480;
private $height = 360;
function getWidth($dummy) {
return $this->width;
}
function getHeight($dummy) {
return $this->height;
}
function getPlayerConfig($obj, $movietitle = NULL, $count = NULL) {
$movie = $obj->getFullImage(FULLWEBPATH);
$suffix = getSuffix($movie);
$poster = $obj->getCustomImage(null, $obj->getWidth(), $obj->getHeight(), $obj->getWidth(), $obj->getHeight(), null, null, true);
$content = '';
switch ($suffix) {
case 'mp4':
case 'm4v':
$content = '<video poster="' . html_encode($poster) . '" src="' . html_encode($movie) . '" controls width="100%">';
$content .= gettext('Your browser sadly does not support this video format.');
$content .= '</video>';
break;
case 'm4a':
case 'mp3':
$content = '<audio src="' . html_encode($movie) . '" controls>';
$content .= gettext('Your browser sadly does not support this audio format.');
$content .= '</audio>';
break;
}
if (empty($content)) {
return '<img src="' . WEBPATH . '/' . ZENFOLDER . '/images/err-noflashplayer.png" alt="' . gettext('No multimedia extension installed for this format.') . '" />';
}
return $content;
}
}
$_zp_multimedia_extension = new pseudoPlayer();