<?php
//
// +---------------------------------------------------------------------------+
// | Nitro :: Module :: FLASH |
// +---------------------------------------------------------------------------+
// | Copyright (c) 2006 June Systems BV |
// +---------------------------------------------------------------------------+
// | This library 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 2.1 of the License, or (at |
// | your option) any later version. |
// | |
// | This library 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 library; if not, write to the Free Software Foundation, |
// | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
// +---------------------------------------------------------------------------+
// | Authors: Siggi Oskarsson <hide@address.com> |
// | Jesper Avot <hide@address.com |
// +---------------------------------------------------------------------------+
//
// $Id: Flash.inc.php 229 2008-04-17 09:20:31Z oli $
//
// Nitro's default Flash handling class
//
/**
* This file contains the Nitro Flash Module
*
* @author Siggi Oskarsson
* @copyright June Systems BV, 2006
* @version $Revision: 1.4 $
* @package Modules
*/
/**
* Include prototype module class
*/
require_once "Nitro/Module.inc.php";
/**
* Flash module class
*
* This module contains the Nitro Flash class.
*
* @package Modules
* @author Siggi Oskarsson <hide@address.com>
* @author Jesper Avot <hide@address.com>
* @copyright June Systems BV, 2006
* @access public
* @todo Remove $_GET['TAG'] usage and clean up the tag code
*/
class NitroModuleFlash extends NitroModule {
/**
* @var string Module ID string
*/
var $IDString = 'NitroModuleFlash';
/**
* FLASH module constructor function
*
* @param string $ObjectID String with the current ObjectID
* @param mixed $Settings Array with the Module Settings, default is FALSE
* @access public
*/
function NitroModuleFlash($ObjectID, $Settings = FALSE)
{
/**
* Call the parent constructor
*/
parent::NitroModule();
/**
* Set ObjectID and ModuleSettings
*/
$this->ObjectID = $ObjectID;
$this->SetModuleSettings($Settings);
}
/**
* GetModuleDataConfiguration
*
* @return array Array for the form libraries.
*/
function GetModuleDataConfiguration()
{
return Array('Name' => 'READONLY',
'Type' => 'READONLY',
'Flash' => 'FILE/TYPE=FLASH',
'Preview' => 'PREVIEW/TYPE=FLASH/TAG=Default',
'Width' => 'TEXT',
'Height' => 'TEXT',
'URLSetting' => 'TEXT',
'AltName' => 'READONLY',
'AltType' => 'READONLY',
'AltImage' => 'FILE/TYPE=IMAGE',
'AltPreview' => 'PREVIEW/TYPE=IMAGE/TAG=ALT',
'AltWidth' => 'READONLY',
'AltHeight' => 'READONLY');
}
/**
* SaveModuleDataConfiguration function
*
* @param mixed $SaveSettings The settings to save. (We use only the Flash savesettings to save the image.)
* @return mixed The saved settings or in case of failure FALSE.
*/
function SaveModuleDataConfiguration($SaveSettings)
{
$Name = $SaveSettings['Name'];
$Type = $SaveSettings['Type'];
$Width = $SaveSettings['Width'];
$Height = $SaveSettings['Height'];
/**
* Alternative if Flash is not supported
*/
$AltName = $SaveSettings['AltName'];
$AltType = $SaveSettings['AltType'];
$AltWidth = $SaveSettings['AltWidth'];
$AltHeight = $SaveSettings['AltHeight'];
if ($SaveSettings['Flash']['tmp_name']) {
/**
* Create the required directories.
*/
if (strlen($this->Conf['Paths']['Flash'])) {
$FlashDir = $this->Conf['Paths']['Flash'];
} elseif (strlen($this->Conf['Paths']['Image'])) {
$FlashDir = $this->Conf['Paths']['Image'];
} else {
$FlashDir = $this->Conf['Paths']['NitroCommon'].'Image'.DIRECTORY_SEPARATOR;
}
// If path set in ini is relative, prepend NITRO_ROOT to it
//TODO: this will not work on Windows, fix!
if (strpos($FlashDir, DIRECTORY_SEPARATOR) !== 0) $FlashDir = NITRO_ROOT.$FlashDir;
if(!file_exists($FlashDir)) mkdir($FlashDir);
$FlashDir.= ($this->ObjectLanguage ? $this->ObjectLanguage : "Default").DIRECTORY_SEPARATOR;
if(!file_exists($FlashDir)) mkdir($FlashDir);
$FlashDir.= $this->ObjectVersion.DIRECTORY_SEPARATOR;
if(!file_exists($FlashDir)) mkdir($FlashDir);
/**
* Create the link to the file and delete it (instead of replacing) before uploading it.
*/
$FlashFile = $FlashDir . $this->ObjectID;
@unlink($FlashFile);
if (@move_uploaded_file($SaveSettings['Flash']['tmp_name'], $FlashFile)) {
$Name = $SaveSettings['Flash']['name'];
$Type = $SaveSettings['Flash']['type'];
}
}
if ($SaveSettings['AltImage']['tmp_name']) {
/**
* Create the required directories.
*/
$ImageDir = $this->Conf['Paths']['Image'];
if(!file_exists($ImageDir)) mkdir($ImageDir);
$ImageDir.= ($this->ObjectLanguage ? $this->ObjectLanguage : "Default") . DIRECTORY_SEPARATOR;
if(!file_exists($ImageDir)) mkdir($ImageDir);
$ImageDir.= $this->ObjectVersion . DIRECTORY_SEPARATOR;
if(!file_exists($ImageDir)) mkdir($ImageDir);
/**
* Create the link to the file and delete it (instead of replacing) before uploading it.
*/
$ImageFile = $ImageDir.$this->ObjectID . "_ALT";
@unlink($ImageFile);
if (@move_uploaded_file($SaveSettings['AltImage']['tmp_name'], $ImageFile)) {
$AltName = $SaveSettings['AltImage']['name'];
$AltType = $SaveSettings['AltImage']['type'];
$size = getimagesize($ImageFile);
$AltWidth = $size[0];
$AltHeight = $size[1];
}
}
$Settings = Array('Name' => $Name,
'Type' => $Type,
'Width' => $Width,
'Height' => $Height,
'URLSetting' => $SaveSettings['URLSetting'],
'AltName' => $AltName,
'AltType' => $AltType,
'AltWidth' => $AltWidth,
'AltHeight' => $AltHeight);
return $Settings;
}
/**
* Draw function
*
* @param mixed $RunTimeSettings RunTimeSettings for the Object, default is FALSE
* @return string The drawn HTML link to the File.
*/
function Draw($RuntimeSettings)
{
$this->ObjectIDString = $this->DB->getOne("SELECT
IDString
FROM
`Object`
WHERE
ObjectID = " . (int)$this->ObjectID);
if ($_GET['TAG'] == "ALT") {
$RV = "<img src='" . $this->GetObjectURL($this->ObjectIDString) . "&TAG=ALT' width='" . $this->Settings['AltWidth'] . "' height='" . $this->Settings['AltHeight'] . "' border='0' />";
} else {
$RV = "
<script type='text/javascript' language='javascript' src='/GetObject.php?NitroDefault=Scripts/ufo.js'></script>
<script type='text/javascript' language='javascript'>
var FO = { movie:\"".$this->GetObjectURL($this->ObjectIDString)."\", width:\"".$this->Settings['Width']."\", height:\"".$this->Settings['Height']."\", majorversion:\"7\", build:\"0\", flashvars:\"".$this->Settings['URLSetting']."\", wmode:\"transparent\", quality:\"high\" };
UFO.create(FO, 'FlashContent');
</script>
<div id='FlashContent'>
<object type='application/x-shockwave-flash' data='".$this->GetObjectURL($this->ObjectIDString).$this->Settings['URLSetting']."' width='".$this->Settings['Width']."' height='".$this->Settings['Height']."'>
<param name='movie' value='".$this->GetObjectURL($this->ObjectIDString).$this->Settings['URLSetting']."&t=".time()."' />
<param NAME='wmode' VALUE='transparent' />
<param NAME='quality' VALUE='high' />
<img src='".$this->GetObjectURL($this->ObjectIDString)."&TAG=ALT' width='".$this->Settings['Width']."' height='".$this->Settings['Height']."' alt='' />
</object>
</div>
";
}
return $RV;
}
/**
* DrawObject function
*
* @param mixed $RunTimeSettings RunTimeSettings for the object, default is FALSE
*/
function DrawObject($RuntimeSettings = FALSE)
{
$FlashDir = $this->Conf['Paths']['Image'] . DIRECTORY_SEPARATOR . ($this->ObjectLanguage ? $this->ObjectLanguage : 'Default') . DIRECTORY_SEPARATOR . $this->ObjectVersion . DIRECTORY_SEPARATOR;
$FlashFile = $FlashDir . $this->ObjectID;
if ($_GET['TAG']) $FlashFile.= "_ALT";
if (file_exists($FlashFile) && is_file($FlashFile)) {
header("Content-Type: " . ($_GET['TAG'] == "ALT" ? $this->Settings['AltType'] : $this->Settings['Type']));
header("Content-Length: " . filesize($FlashFile));
header("Expires: " . gmdate("D, d M Y H:i:s", strtotime("+1 day")) . " GMT");
/**
* The Header below is very important, Internet Explorer does not works with inline files over a secured connection (HTTPS [SSL]).
* So we need to set this header, because PHP sets the Pragma default to 'no-cache'
*/
header("Pragma: cache");
header("Cache-Control: public");
readfile($FlashFile);
} else {
echo "Flash " . $FlashFile . " cannot be found";
}
}
/**
* isCacheable function
*
* Check if this Module is cacheable or not.
*
* @return mixed Is the Module allowed to be cached or not.
*/
function isCacheable()
{
return $this->cacheID();
}
}
?>