GalleryAnimationItem
* @g2 GalleryDataItem
* @g2
* @g2 1
* @g2 0
* @g2
* @g2
*
* @package GalleryCore
* @subpackage Classes
* @author Bharat Mediratta
* @version $Revision: 18060 $
*/
class GalleryAnimationItem extends GalleryDataItem {
/**
* The width of this animation.
* @var int
*
* @g2
* @g2 width
* @g2 INTEGER
* @g2
* @g2 FULL
* @g2
*/
var $width;
/**
* The height of this animation.
* @var int
*
* @g2
* @g2 height
* @g2 INTEGER
* @g2
* @g2 FULL
* @g2
*/
var $height;
/**
* @see GalleryDataItem::canBeViewedInline
*/
function canBeViewedInline() {
/* The mimeTypes listed here should provide a render() output */
static $mimeList = array(
'application/x-shockwave-flash',
'application/x-director',
);
return $this->_canBeViewedInline(
($this->getWidth() > 0 && $this->getHeight() > 0) ? $mimeList : null);
}
/**
* Create a new GalleryAnimationItem from a animation file
*
* @param int $parentId the id of the parent GalleryItem
* @param string $animationFileName the path to the source animation
* @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 GalleryStatus a status code
*/
function create($parentId, $animationFileName, $mimeType, $targetName=null, $symlink=false) {
global $gallery;
$platform =& $gallery->getPlatform();
/* Validate the input filename */
if (empty($animationFileName)) {
return GalleryCoreApi::error(ERROR_BAD_PARAMETER);
}
if (!$platform->file_exists($animationFileName)) {
return GalleryCoreApi::error(ERROR_BAD_PATH);
}
/* Create our data item */
$ret = parent::create($parentId, $animationFileName, $mimeType, $targetName, $symlink);
if ($ret) {
return $ret;
}
/* Default to empty dimensions */
$this->setWidth(0);
$this->setHeight(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');
if ($ret) {
return $ret;
}
if (isset($toolkit)) {
list ($ret, $dimensions) = $toolkit->getProperty($mimeType, 'dimensions', $path);
if ($ret) {
/*
* If we can't get the dimensions, it's probably a bad image.
* Or our graphics code is broken. Hard to tell which at this point.
*/
$ret->addErrorCode(ERROR_BAD_DATA_TYPE);
return $ret;
}
$this->setWidth($dimensions[0]);
$this->setHeight($dimensions[1]);
}
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('Animation'), $core->translate('animation'));
}
}
return array('Animation', 'animation');
}
/**
* @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' => !empty($params['forceFullUrl'])));
list ($width, $height) = array($this->getWidth(), $this->getHeight());
switch($this->getMimeType()) {
case 'application/x-shockwave-flash':
return sprintf('',
/* IE Object */
!empty($params['class']) ? 'class="' . $params['class'] . '"' : '',
$width,
$height,
$src,
$fallback,
/* Mozilla Object */
!empty($params['class']) ? 'class="' . $params['class'] . '"' : '',
$this->getMimeType(),
$src,
$width,
$height,
$src,
$fallback);
case 'application/x-director':
return sprintf('',
/* IE Object */
!empty($params['class']) ? 'class="' . $params['class'] . '"' : '',
$width,
$height,
$src,
$fallback,
/* Mozilla Object */
!empty($params['class']) ? 'class="' . $params['class'] . '"' : '',
$this->getMimeType(),
$src,
$width,
$height,
$fallback);
default:
return $fallback;
}
default:
return null;
}
}
/**
* @see GalleryEntity::getClassName
*/
function getClassName() {
return 'GalleryAnimationItem';
}
function getWidth() {
return $this->width;
}
function setWidth($width) {
$this->width = $width;
}
function getHeight() {
return $this->height;
}
function setHeight($height) {
$this->height = $height;
}
}
?>