Sindbad~EG File Manager

Current Path : /var/www/web3/modules/core/classes/
Upload File :
Current File : /var/www/web3/modules/core/classes/GalleryMovieItem.class

<?php
/*
 * Gallery - a web based photo album viewer and editor
 * Copyright (C) 2000-2007 Bharat Mediratta
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 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
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA  02110-1301, USA.
 */

GalleryCoreApi::requireOnce('modules/core/classes/GalleryDataItem.class');

/**
 * A subclass of DataItem for containing Movies.
 * A GalleryItem whose source is a movie of some kind (like an MPEG or an AVI).
 *
 * @g2 <class-name>GalleryMovieItem</class-name>
 * @g2 <parent-class-name>GalleryDataItem</parent-class-name>
 * @g2 <schema>
 * @g2   <schema-major>1</schema-major>
 * @g2   <schema-minor>0</schema-minor>
 * @g2 </schema>
 * @g2 <requires-id/>
 *
 * @package GalleryCore
 * @subpackage Classes
 * @author Bharat Mediratta <bharat@menalto.com>
 * @version $Revision: 15559 $
 */
class GalleryMovieItem extends GalleryDataItem {

    /**
     * The width of this movie.
     * @var int
     *
     * @g2 <member>
     * @g2   <member-name>width</member-name>
     * @g2   <member-type>INTEGER</member-type>
     * @g2   <linked/>
     * @g2   <member-external-access>FULL</member-external-access>
     * @g2 </member>
     */
    var $width;

    /**
     * The height of this movie.
     * @var int
     *
     * @g2 <member>
     * @g2   <member-name>height</member-name>
     * @g2   <member-type>INTEGER</member-type>
     * @g2   <linked/>
     * @g2   <member-external-access>FULL</member-external-access>
     * @g2 </member>
     */
    var $height;

    /**
     * The duration of the movie in seconds
     * @var int
     *
     * @g2 <member>
     * @g2   <member-name>duration</member-name>
     * @g2   <member-type>INTEGER</member-type>
     * @g2   <linked/>
     * @g2   <member-external-access>FULL</member-external-access>
     * @g2 </member>
     */
    var $duration;


    /**
     * @see GalleryDataItem::canBeViewedInline
     */
    function canBeViewedInline() {
	/* The mimeTypes listed here should provide a render() output */
	static $mimeList = array(
	    'video/quicktime',
	    'video/mpeg',
	    'video/mp4',
	    'video/x-msvideo',
	    'video/x-ms-wmv',
	    'video/x-ms-asf',
	    'video/x-ms-asx',
	);
	return $this->_canBeViewedInline(
		($this->getWidth() > 0 && $this->getHeight() > 0) ? $mimeList : null);
    }

    /**
     * Create a new GalleryMovieItem from a video file
     *
     * @param int $parentId the id of the parent GalleryItem
     * @param string $videoFileName the path to the source video
     * @param string $mimeType
     * @param string $targetName the desired name of the new item
     * @param boolean $symlink (optional) a boolean true if we should symlink instead
     *        of copy (default is false).
     * @return object GalleryStatus a status code
     */
    function create($parentId, $videoFileName, $mimeType, $targetName=null, $symlink=false) {
	global $gallery;
	$platform =& $gallery->getPlatform();

	/* Validate the input filename */
	if (empty($videoFileName)) {
	    return GalleryCoreApi::error(ERROR_BAD_PARAMETER);
	}

	if (!$platform->file_exists($videoFileName)) {
	    return GalleryCoreApi::error(ERROR_BAD_PATH);
	}

	/* Create our data item */
	$ret = parent::create($parentId, $videoFileName, $mimeType, $targetName, $symlink);
	if ($ret) {
	    return $ret;
	}

	/* Default to empty dimensions */
	$this->setWidth(0);
	$this->setHeight(0);
	$this->setDuration(0);

	/* We're linkable */
	$this->setIsLinkable(true);

	/* Detect our dimensions, if possible */
	$ret = $this->rescan();
	if ($ret) {
	    /* Cleanup our datafile on failure */
	    list ($ret2, $path) = $this->fetchPath();
	    if (!$ret2) {
		@$platform->unlink($path);
	    }
	    return $ret;
	}

	return null;
    }

    /**
     * @see GalleryDataItem::rescan
     */
    function rescan() {
	global $gallery;

	$ret = parent::rescan();
	if ($ret) {
	    return $ret;
	}

	list ($ret, $path) = $this->fetchPath();
	if ($ret) {
	    return $ret;
	}

	$mimeType = $this->getMimeType();
	list ($ret, $toolkit) =
	    GalleryCoreApi::getToolkitByProperty($mimeType, 'dimensions-and-duration');
	if ($ret) {
	    return $ret;
	}

	if (isset($toolkit)) {
	    list ($ret, $dimensions) =
		$toolkit->getProperty($mimeType, 'dimensions-and-duration', $path);
	    if ($ret) {
		if (!($ret->getErrorCode() & ERROR_STORAGE_FAILURE)) {
		    /*
		     * We can't get the dimensions.  It may be a bad movie, or the graphics toolkit
		     * may be broken.  We can't tell, so set everything to zero for now.
		     *
		     * TODO: trapping everything but storage failures is too broad.  Trap only
		     * toolkit failures after we refactor all toolkits to set the
		     * ERROR_TOOLKIT_FAILURE bit on every error that they generate or pass
		     * through.
		     */
		    $dimensions = array(0, 0, 0);
		} else {
		    return $ret;
		}
	    }

	    $this->setWidth($dimensions[0]);
	    $this->setHeight($dimensions[1]);
	    $this->setDuration(round($dimensions[2]));
	}

	return null;
    }

    /**
     * @see GalleryEntity::itemTypeName
     */
    function itemTypeName($localized = true) {
	global $gallery;
	if ($localized) {
	    list ($ret, $core) = GalleryCoreApi::loadPlugin('module', 'core');
	    if (! $ret) {
		return array($core->translate('Movie'), $core->translate('movie'));
	    }
	}
	return array('Movie', 'movie');
    }

    /**
     * @see GalleryDataItem::render
     */
    function render($format, $params) {
	global $gallery;

	$fallback = trim(preg_replace("/[\r\n]/", '', $params['fallback']));

	switch ($format) {
	case 'HTML':
	    $urlGenerator =& $gallery->getUrlGenerator();
	    $src = $urlGenerator->generateUrl(
		array('view' => 'core.DownloadItem', 'itemId' => $this->getId(),
		      'serialNumber' => $this->getSerialNumber()),
		array('forceFullUrl' => true, 'forceSessionId' => true));

	    list ($width, $height) = array($this->getWidth(), $this->getHeight());
	    switch ($this->getMimeType()) {
	    case 'video/quicktime':
		return sprintf(
		'<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"
			 codebase="http://www.apple.com/qtactivex/qtplugin.cab"
			 width="%s" height="%s" id="%s"%s>
			   <param name="src" value="%s"/>
			   <param name="controller" value="true"/>
			   <param name="autoplay" value="true"/>
			   <param name="loop" value="false"/>
			   <embed src="%s" width="%s" height="%s" type="%s"
				  pluginspage="http://www.apple.com/quicktime/download/"
				  controller="true" autoplay="true" loop="false"/>
			   <noembed>%s</noembed>
		 </object>',

		$width, $height + 16,
		!empty($params['id']) ? $params['id'] : 'movie',
		!empty($params['class']) ? ' class="' . $params['class'] . '"' : '',
		$src, $src,
		$width, $height + 16,
		$this->getMimeType(),
		$fallback);

	    case 'video/mpeg':
	    case 'video/mp4':
	    case 'video/x-msvideo':
	    case 'video/x-ms-wmv':
		$classId = 'CLSID:05589FA1-C356-11CE-BF01-00AA0055595A';
	    case 'video/x-ms-asf':
	    case 'video/x-ms-asx':
		if (!isset($classId)) {
		    $classId = 'CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95';
		}
		return sprintf(
		'<object classid="%s" width="%s" height="%s" id="%s"%s>
			   <param name="ShowDisplay" value="0"/>
			   <param name="ShowControls" value="1"/>
			   <param name="AutoStart" value="1"/>
			   <param name="AutoRewind" value="-1"/>
			   <param name="Volume" value="0"/>
			   <param name="FileName" value="%s"/>
			   <embed src="%s" width="%s" height="%s" type="%s"
				  controller="true" autoplay="true" loop="false"/>
			   <noembed>%s</noembed>
		 </object>',

		$classId, $width, $height + 50,
		!empty($params['id']) ? $params['id'] : 'movie',
		!empty($params['class']) ? ' class="' . $params['class'] . '"' : '',
		$src, $src,
		$width, $height + 50,
		$this->getMimeType(),
		$fallback);

	    default:
		return $fallback;
	    }

	default:
	    return null;
	}
    }

    /**
     * @see GalleryEntity::getClassName
     */
    function getClassName() {
	return 'GalleryMovieItem';
    }

    function getWidth() {
	return $this->width;
    }

    function setWidth($width) {
	$this->width = $width;
    }

    function getHeight() {
	return $this->height;
    }

    function setHeight($height) {
	$this->height = $height;
    }

    function getDuration() {
	return $this->duration;
    }

    function setDuration($duration) {
	$this->duration = $duration;
    }
}
?>

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists