Author SHA1 Message Date
Anthony Le Mansec 5ac64b551b doc: note regarding upcoming oo merge 2010-10-05 15:55:55 +02:00
Anthony Le Mansec 85f0f57067 doc: markdown fix on unordered list 2010-10-04 16:08:49 +02:00
Anthony Le Mansec 4db7f848da doc: markdown unordered lists fix. 2010-10-04 16:07:55 +02:00
Anthony Le Mansec 6dff861062 doc: switched to markdown markup
- NOTE: 'objectoriented-staging' branch will soon provide oo access to opensimwebassets features. Merge will occur upon completion/tests.
2010-10-04 16:03:46 +02:00
34 changed files with 58 additions and 790 deletions
+12 -4
View File
@@ -1,14 +1,22 @@
WebAssets for OpenSimulator
===========================
This small set of php classes provides easy access to OpenSimulator
This small set of php functions provides easy access to OpenSimulator
assets, adding another level of caching, thus limiting load on given
asset server.
Typical usage includes web publication of avatar's profile pictures, library and user
stored textures, user snapshots...
stored textures, region maptiles, user and regions/lands snapshots.
It was updated and tested on September 2010, with following software :
classes availability
--------------------
oo classes are currently beeing worked on ('objectoriented-staging' branch). Merge will occur upon completion/successful tests.
Tested on
---------
Updated and tested on September 2010, with following software :
WebServer :
@@ -27,6 +35,6 @@ OpenSimulator AssetServer :
Installation
------------
See included INSTALL file.
See included **INSTALL** file.
+2 -5
View File
@@ -1,8 +1,5 @@
[ ] use spl_autoload_register() to register our autoloader.
- Basic ImageMagick exceptions/error handling
[ ] write a CachedConfig engine, extending our ConfigEngine class
- Make a clean oo interface to this.
[ ] move remaining code from non-object functions to proper classes.
[ ] Basic ImageMagick exceptions/error handling
-56
View File
@@ -1,56 +0,0 @@
<?php
/*
* This file is part of WebAssets for OpenSimulator.
*
* WebAssets for OpenSimulator 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.
*
* WebAssets for OpenSimulator 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 WebAssets for OpenSimulator. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file bootstrap.php
* @brief simple autoloader initialization.
* @details our autoloader lookups interfaces under 'interfaces/Ifoo.interface.php' (IFoo interface)
* and classes under 'classes/FirstWord/SecondWord.class.php' ('FirstWord_SecondWord' class)
*/
define('SEP', DIRECTORY_SEPARATOR);
define('ROOT', dirname(__FILE__));
define('CLASSES', ROOT . SEP . 'classes' . SEP);
define('INTERFACES', ROOT . SEP . 'interfaces' . SEP);
define('CONFIG_INI', ROOT . SEP . 'config' . SEP . 'default.ini');
/**
* @brief simple autoloader, for our classes and interfaces.
* @details lookups interfaces under 'interfaces/Ifoo.interface.php' (IFoo interface)
* and classes under 'classes/FirstWord/SecondWord.class.php' ('FirstWord_SecondWord' class)
* @throws RuntimeException when requested class/interface is not found.
*/
function __autoload($className) {
// looking for classes :
$classFile = CLASSES . str_replace('_', SEP, $className.'.class.php');
if (file_exists($classFile)) {
require_once($classFile);
return;
}
// looking for interfaces :
$interfaceFile = INTERFACES . str_replace('_', SEP, $className.'.interface.php');
if (file_exists($interfaceFile)) {
require_once($interfaceFile);
return;
}
throw new RuntimeException('unable to load '.$class_name);
}
?>
View File
-50
View File
@@ -1,50 +0,0 @@
<?
/*
* This file is part of WebAssets for OpenSimulator.
*
* WebAssets for OpenSimulator 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.
*
* WebAssets for OpenSimulator 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 WebAssets for OpenSimulator. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file Engine.class.php
* @brief Config Engine abstract class declaration
*/
/** @addtogroup Config */
/** @{ */
/**
* @brief Config Engine class abstract
* @details Our Config engine class signature
* @abstract
*/
abstract class Config_Engine implements IConfigEngine {
/** @brief pointer to current instance */
protected static $_instance;
/** @brief singleton mechanism */
abstract public static function instance();
/** @brief per-extending class custom initialization */
abstract protected function init();
function __construct() {
$this->init();
}
}
/** @} */
?>
-113
View File
@@ -1,113 +0,0 @@
<?php
/*
* This file is part of WebAssets for OpenSimulator.
*
* WebAssets for OpenSimulator 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.
*
* WebAssets for OpenSimulator 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 WebAssets for OpenSimulator. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file Ini.class.php
* @brief Config_Engine_Ini class implementation
*/
/** @addtogroup Config */
/** @{ */
/**
* @brief INI file configuration class
* @details Simple ini-file accessor
*/
class Config_Engine_Ini extends Config_Engine {
/** @brief currently loaded ini file */
private $_filename;
/** @brief currently loaded config array */
private $_config;
function __destruct() {
}
protected function init() {
$this->_config = array();
$this->_filename = "";
if (defined('CONFIG_INI'))
$this->load(CONFIG_INI);
}
public static function instance() {
if (!self::$_instance)
self::$_instance = new Config_Engine_Ini();
return (self::$_instance);
}
public function load($cfg_identifier) {
if (!is_file($cfg_identifier))
throw new RuntimeException('invalid config identifier');
$process_sections = true;
$this->_config = parse_ini_file($cfg_identifier, $process_sections);
$this->_filename = $cfg_identifier;
}
/**
* @todo implement this
*/
public function save() {
}
/**
* @brief returns given key within given section
* @param group - ini section where to load given key
* @param key - key to retrieve
* @return mixed - given key value within given section
*/
public function getkey($group, $key) {
if (!array_key_exists($group, $this->_config))
return ("");
if (!array_key_exists($key, $this->_config[$group]))
return ("");
return ($this->_config[$group][$key]);
}
/**
* @todo implement this
*/
public function setkey($group, $key, $val) {
}
/**
* @brief returns currently loaded config as an array
* @return array - associative array representing loaded ini file
*/
public function get() {
return ($this->_config);
}
/**
* @brief get given ini section, as an array
* @param $group string - ini section to load
* @return array - loaded section as an associative array
*/
public function getGroup($group) {
if (!array_key_exists($group, $this->_config))
return (array());
return ($this->_config[$group]);
}
}
/** @} */
?>
-80
View File
@@ -1,80 +0,0 @@
<?php
/*
* This file is part of WebAssets for OpenSimulator.
*
* WebAssets for OpenSimulator 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.
*
* WebAssets for OpenSimulator 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 WebAssets for OpenSimulator. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file Xml.class.php
* @brief Config_Engine_Xml class implementation
*/
/** @addtogroup Config */
/** @{ */
/**
* @brief XML config loader
* @details Simple xml-config accessor
*/
class Config_Engine_Xml extends Config_Engine {
function __destruct() {
}
protected function init() {
}
public static function instance() {
if (!self::$_instance)
self::$_instance = new Config_Engine_Xml();
return (self::$_instance);
}
/** @todo implement this */
public function load($cfg_identifier) {
}
/** @todo implement this */
public function save() {
}
/** @todo implement this */
public function getkey($group, $key) {
}
/** @todo implement this */
public function setkey($group, $key, $val) {
}
/** @todo implement this */
public function get() {
}
/** @todo implement this */
public function getGroup($group) {
}
}
/** @} */
?>
-7
View File
@@ -1,7 +0,0 @@
<?php
class WaException_Cache extends Exception {
}
?>
@@ -1,7 +0,0 @@
<?php
class WaException_Convert extends Exception {
}
?>
-7
View File
@@ -1,7 +0,0 @@
<?php
class WaException_Fetch extends Exception {
}
?>
@@ -1,7 +0,0 @@
<?php
class WaException_Timeout extends Exception {
}
?>
-52
View File
@@ -1,52 +0,0 @@
<?php
/*
* This file is part of WebAssets for OpenSimulator.
*
* WebAssets for OpenSimulator 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.
*
* WebAssets for OpenSimulator 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 WebAssets for OpenSimulator. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file WebAsset.class.php
* @brief WebAsset class implementation.
*/
/**
* @brief An opensim asset, suitable for opensimWebAsset usage.
* @details Represents an opensim asset suitable for opensimWebAssets usage.
*/
class WebAsset implements IOpensimAsset {
protected $uuid; /**< asset's UUID, internally assigned by Opensimulator */
function __construct($id) {
$this->uuid = $id;
}
/**
* @brief sets current WebAsset's UUID
* @param id (string) opensim UUID for asset. ex: "00000000-0000-0000-0000-000000000000"
* @return void
*/
public function setUUID($id) {
$this->uuid = $id;
}
/**
* @brief returns UUID associated to current asset.
* @return (string) asset's UUID.
*/
public function getUUID() {
return ($this->uuid);
}
}
?>
-40
View File
@@ -1,40 +0,0 @@
<?php
class WebAsset_Cache implements IAssetCache {
private static $_instance;
public static function instance() {
if (!self::$_instance) {
self::$_instance = new WebAsset_Cache();
}
return (self::$_instance);
}
public function isFormatCached($asset, $format) {
}
public function isCached($asset) {
return (false);
}
public function retrieveFormat($asset, $format) {
}
public function retrieve($asset) {
// if (read fails) throw new WaException_Cache("fopen / fread error msg");
}
public function storeFormat($asset, $format, $datas) {
}
public function store($asset, $datas) {
}
}
?>
-20
View File
@@ -1,20 +0,0 @@
<?php
class WebAsset_Converter {
private static $_instance;
public static function instance() {
if (!self::$_instance) {
self::$_instance = new WebAsset_Converter();
}
return (self::$_instance);
}
/** @todo implement this */
public function convert($asset, $toFormat) {
}
}
?>
-42
View File
@@ -1,42 +0,0 @@
<?php
class WebAsset_Fetcher {
private static $_instance;
public static function instance() {
if (!self::$_instance) {
self::$_instance = new WebAsset_Fetcher();
}
return (self::$_instance);
}
public function fetch($asset) {
$config = Config_Engine_Ini::instance();
$asset_server = "http://" . $config->getkey('assetServer', 'host') . ':'
. $config->getkey('assetServer', 'port') . "/assets/";
$asset_url = $asset_server . $asset->getUUID();
$h = @fopen($asset_url, "rb");
if (!$h) {
throw new WaException_Fetch("unable to connect to asset server [".$asset_url."]");
}
stream_set_timeout($h, $config->getkey('assetServer', 'timeout'));
$asset_xmldatas = stream_get_contents($h);
fclose($h);
try {
$xml = new SimpleXMLElement($asset_xmldatas);
} catch (Exception $e) {
throw new WaException_Fetch("unable to read asset xml [".$asset->getUUID()."]");
}
$datas = base64_decode($xml->Data);
return ($datas);
}
}
?>
-88
View File
@@ -1,88 +0,0 @@
<?php
/*
* This file is part of WebAssets for OpenSimulator.
*
* WebAssets for OpenSimulator 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.
*
* WebAssets for OpenSimulator 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 WebAssets for OpenSimulator. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @todo implement this :p
*/
class WebAsset_Viewer implements IAssetViewer {
private static $_instance; /**< pointer to current instance */
private $_asset;
/**
* @brief simple singleton mechanism
* @return (WebAsset_Viewer) newly_created or current instance
*/
public static function instance() {
if (!self::$_instance) {
self::$_instance = new WebAsset_Viewer();
}
return (self::$_instance);
}
public function load($asset) {
// if (fetch timeout) throw new WaException_Timeout("asset fetch timed out");
// if (connect failed) throw new WaException_Fetch("unable to connect...");
// if (cache or read failed) throw new WaException_Cache("write permission denied");
// if (conversion failed) throw new WaException_Convert("Imagick error msg..")
$this->_asset = $asset;
$cache = WebAsset_Cache::instance();
if ($cache->isCached($asset)) {
// available in cache, no need to fetch asset
// FIXME : if cache expires between load() and renderImage() | getImageDatas(), read fails
return;
}
$fetcher = WebAsset_Fetcher::instance();
$cache->store($asset, $fetcher->fetch($asset));
}
public function renderImage($toFormat) {
}
public function getImageDatas($toFormat) {
$cache = WebAsset_Cache::instance();
$is_cached = $cache->isFormatCached($this->_asset, $toFormat);
if ($is_cached) {
return ($cache->retrieveFormat($this->_asset, $toFormat));
}
// convert to requested format:
$converter = WebAsset_Converter::instance();
$datas = $converter->convert($this->_asset, $toFormat);
// store converted asset to cache:
$cache->storeFormat($this->_asset, $toFormat, $datas);
return ($datas);
}
public function renderSound() {
}
public function renderAnimation() {
}
}
?>
View File
-36
View File
@@ -1,36 +0,0 @@
;
; config/default.ini :
; opensimWebAssets default configuration file.
;
[webAssets]
debug = false
log_enable = false
log_file = "/tmp/webassets.log"
[assetServer]
; host=myhost port=4242 will use http://myhost:4242/assets/
host = "assets.osgrid.org"
port = 8003
timeout = 10
[localCache]
; jp2_dir : local cache directory for fetched assets (jpeg2k)
jp2_dir = "/var/www/datas/webassets/tmp/cache/jp2/"
; pic_dir : converted pictures local cache dir
pic_dir = "/var/www/datas/webassets/tmp/cache/pic/"
; max_age : re-use locally cached files (jp2 & converted) for this amount of seconds:
max_age = 86400
[images]
default_format = "JPEG"
; resize_enable : wether to enable image resizing or not (true/false)
resize_enable = true
; resize_width : resized image width in pixels
resize_width = 150
; notfound_uuid_fallback : fallback on this asset on malformed query / notfound
notfound_uuid_fallback = "cb2052ae-d161-43e9-b11b-c834217823cd"
; notfound_image_fallback : display this picture (extension automatically added) on error/notfound:
notfound_image_fallback = "/var/www/mysite.com/webassets/htdocs/pic/uuid_zero"
+44
View File
@@ -0,0 +1,44 @@
<?php
/*
* This file is part of WebAssets for OpenSimulator.
*
* WebAssets for OpenSimulator 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.
*
* WebAssets for OpenSimulator 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 WebAssets for OpenSimulator. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file config.php
* @brief Misc configuration variables.
*
* @author Anthony Le Mansec <a.lm@free.fr>
*/
define('ASSET_SERVER', 'http://assets.osgrid.org:8003/assets/'); // (OpenSim.ini: asset_server_url . "/assets/")
define('ASSET_SERVER_TIMEOUT', 8); // timeout in seconds, to wait while requesting an asset (default to 8)
define('ASSET_DO_RESIZE', true); // shall we resize picture to width=ASSET_RESIZE_FIXED_WIDTH ?
define('ASSET_RESIZE_FIXED_WIDTH', 150); // width in pixels
/* Will show following image if no asset was requested (malformed query) : */
define('ASSET_ID_NOTFOUND', 'cb2052ae-d161-43e9-b11b-c834217823cd');
/* will show following picture for Zero UUID (not found / malformed assets) : */
define('IMAGE_ID_ZERO', '/var/www/mysite.com/webassets/pic/uuid_zero'); // no extension here
define('IMAGE_DEFAULT_FORMAT', 'JPEG');
/* Re-use locally cached pictures (jp2k & converted) for 1 day before re-requesting it : */
define('CACHE_MAX_AGE', 86400); // 1 day
/* where to store cached pictures ? (user running your webserver needs write-permissions there : */
define('JP2_CACHE_DIR', '/var/www/datas/webassets/cache/jp2/');
define('PIC_CACHE_DIR', '/var/www/datas/webassets/cache/pic/');
?>
-53
View File
@@ -1,53 +0,0 @@
<?php
interface IAssetCache {
/**
* @brief checks wether given asset is locally cached in given format.
* @details an asset fetched and converted to given format is
* locally cached for configured max_age seconds (see config/default.ini).
* @param asset (WebAsset object) asset
* @param format (string) previously converted format to lookup in cache.
* @return (boolean) true if asset is available in cache, false otherwise.
*/
function isFormatCached($asset, $format);
/**
* @brief checks wether given asset is locally cached in raw format.
* @details assets are locally cached in their opensim-format for max_age seconds
* @return (boolean) true if datas are locally cached (and not expired).
*/
function isCached($asset);
/**
* @brief reads and returns given asset from local cache, in given format.
* @param $asset (WebAsset) asset.
* @param $format (string) previously converted format to lookup in cache.
* @return (binary) raw asset datas (in given format).
*/
function retrieveFormat($asset, $format);
/**
* @brief reads and returns raw asset datas from local cache.
* @param asset (WebAsset) asset to read from local cache.
* @return (binary) raw asset datas, in opensim native format.
*/
function retrieve($asset);
/**
* @brief writes given asset datas, in given format, to local cache.
* @param asset (WebAsset) asset to save to cache.
* @param format (string) format of datas to cache (eg: "JPEG")
* @param datas (binary) asset binary datas, in given format.
*/
function storeFormat($asset, $format, $datas);
/**
* @brief writes given asset datas, in opensim native format, to local cache.
* @param asset (WebAsset) asset to save to cache.
* @param datas (binary) asset binary datas, in opensim native format.
*/
function store($asset, $datas);
}
?>
-37
View File
@@ -1,37 +0,0 @@
<?php
interface IAssetViewer {
/**
* @brief loads given asset from configured asset server.
* @param assetUUID (string) asset's UUID
* @return void
* @throw WaException_Timeout on fetch timeout
* @throw WaException_Cache on cache read/write failure
* @throw WaException_Convert on conversion failure
*/
function load($assetUUID);
/**
* @brief renders currently loaded image asset to given format.
* @param toFormat (string) format identifier to convert image to (eg: "JPEG")
* @return (void) sets http content-type header and outputs raw image datas.
*/
function renderImage($toFormat);
/**
* @brief gets image asset raw datas, after conversion to toFormat.
* @param toFormat (string) format identifier to convert image to (eg: "JPEG")
* @return (binary) raw image datas.
*/
function getImageDatas($toFormat);
/** @todo find sound assets, experiment and implement this. */
function renderSound();
/** @todo find animation assets, experiment and find a way to render anims */
function renderAnimation();
}
?>
@@ -1,42 +0,0 @@
<?php
/*
* This file is part of WebAssets for OpenSimulator.
*
* WebAssets for OpenSimulator 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.
*
* WebAssets for OpenSimulator 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 WebAssets for OpenSimulator. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @brief interface describing a ConfigEngine
*/
interface IConfigEngine {
/** @brief loads given config */
function load($cfg_identifier);
/** @brief saves current configuration */
function save();
/** @brief retrieve given key, within given group */
function getkey($group, $key);
/** @brief assign given val to given group/key */
function setkey($group, $group, $val);
/** @brief returns current config as a php array */
function get();
/** @brief returns given config group as an array */
function getGroup($group);
}
?>
@@ -1,29 +0,0 @@
<?php
/*
* This file is part of WebAssets for OpenSimulator.
*
* WebAssets for OpenSimulator 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.
*
* WebAssets for OpenSimulator 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 WebAssets for OpenSimulator. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @brief interface representing an opensimulator asser
* @todo add more asset properties/accessors
*/
interface IOpensimAsset {
function setUUID($uuid);
function getUUID();
}
?>

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 4.1 KiB

-15
View File
@@ -1,15 +0,0 @@
<?php
/**
* @file test.php
* @brief bare test script.
* @details local testing of our classes.
*/
require_once('bootstrap.php');
$viewer = WebAsset_Viewer::instance();
//$viewer->load(new WebAsset("cb2052ae-d161-43e9-b11b-c834217823cd"));
$viewer->load(new WebAsset("00000000-0000-0000-0000-000000000000"));
$rawImage = $viewer->getImageDatas("JPEG");
?>
View File
View File