first commit

This commit is contained in:
2025-07-18 16:20:14 +07:00
commit 98af45c018
16382 changed files with 3148096 additions and 0 deletions

View File

@@ -0,0 +1,156 @@
<?php
/* KE Software Open Source Licence
**
** Notice: Copyright (c) 2011-2013 KE SOFTWARE PTY LTD (ACN 006 213 298)
** (the "Owner"). All rights reserved.
**
** Licence: Permission is hereby granted, free of charge, to any person
** obtaining a copy of this software and associated documentation files
** (the "Software"), to deal with the Software without restriction,
** including without limitation the rights to use, copy, modify, merge,
** publish, distribute, sublicense, and/or sell copies of the Software,
** and to permit persons to whom the Software is furnished to do so,
** subject to the following conditions.
**
** Conditions: The Software is licensed on condition that:
**
** (1) Redistributions of source code must retain the above Notice,
** these Conditions and the following Limitations.
**
** (2) Redistributions in binary form must reproduce the above Notice,
** these Conditions and the following Limitations in the
** documentation and/or other materials provided with the distribution.
**
** (3) Neither the names of the Owner, nor the names of its contributors
** may be used to endorse or promote products derived from this
** Software without specific prior written permission.
**
** Limitations: Any person exercising any of the permissions in the
** relevant licence will be taken to have accepted the following as
** legally binding terms severally with the Owner and any other
** copyright owners (collectively "Participants"):
**
** TO THE EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS",
** WITHOUT ANY REPRESENTATION, WARRANTY OR CONDITION OF ANY KIND, EXPRESS
** OR IMPLIED, INCLUDING (WITHOUT LIMITATION) AS TO MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. TO THE EXTENT
** PERMITTED BY LAW, IN NO EVENT SHALL ANY PARTICIPANT BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
**
** WHERE BY LAW A LIABILITY (ON ANY BASIS) OF ANY PARTICIPANT IN RELATION
** TO THE SOFTWARE CANNOT BE EXCLUDED, THEN TO THE EXTENT PERMITTED BY
** LAW THAT LIABILITY IS LIMITED AT THE OPTION OF THE PARTICIPANT TO THE
** REPLACEMENT, REPAIR OR RESUPPLY OF THE RELEVANT GOODS OR SERVICES
** (INCLUDING BUT NOT LIMITED TO SOFTWARE) OR THE PAYMENT OF THE COST OF SAME.
*/
require_once __DIR__ . '/IMu.php';
class IMuConfig
{
public function
__construct()
{
$this->values = null;
}
public $values;
public function
load($file)
{
$doc = new DOMDocument;
if (! @$doc->load($file))
throw new IMuException('ConfigLoad', $file);
$xpath = new DOMXpath($doc);
$values = $this->loadNode($xpath, $doc->documentElement);
$this->mergeValue($this->values, $values);
}
public function
merge($values)
{
$this->mergeValue($this, $values);
}
protected function
loadNode($xpath, $node)
{
$children = $xpath->query('*', $node);
$length = $children->length;
if ($length == 0)
return $node->nodeValue;
if ($length == 1)
{
$type = $node->getAttribute('type');
if ($type == '')
$type = 'set';
}
else
{
$type = 'list';
$first = $children->item(0)->nodeName;
for ($i = 1; $i < $length; $i++)
{
$child = $children->item($i);
if ($child->nodeName != $first)
{
$type = 'set';
break;
}
}
}
if ($type == 'list')
{
$list = array();
for ($i = 0; $i < $length; $i++)
{
$child = $children->item($i);
$list[] = $this->loadNode($xpath, $child);
}
return $list;
}
$set = array();
for ($i = 0; $i < $length; $i++)
{
$child = $children->item($i);
$name = $child->nodeName;
$set[$name] = $this->loadNode($xpath, $child);
}
return $set;
}
protected function
mergeValue(&$old, $new)
{
if (! is_array($old))
$old = $new;
else if (array_keys($old) === range(0, count($old) - 1))
{
/* list */
if (is_array($new))
{
foreach ($new as $name => $value)
$old[] = $value;
}
else
$old[] = $new;
}
else
{
/* set */
if (is_array($new))
{
foreach ($new as $name => $value)
{
if (array_key_exists($name, $old))
$this->mergeValue($old[$name], $value);
else
$old[$name] = $value;
}
}
}
}
}
?>

View File

@@ -0,0 +1,284 @@
<?php
/* KE Software Open Source Licence
**
** Notice: Copyright (c) 2011-2013 KE SOFTWARE PTY LTD (ACN 006 213 298)
** (the "Owner"). All rights reserved.
**
** Licence: Permission is hereby granted, free of charge, to any person
** obtaining a copy of this software and associated documentation files
** (the "Software"), to deal with the Software without restriction,
** including without limitation the rights to use, copy, modify, merge,
** publish, distribute, sublicense, and/or sell copies of the Software,
** and to permit persons to whom the Software is furnished to do so,
** subject to the following conditions.
**
** Conditions: The Software is licensed on condition that:
**
** (1) Redistributions of source code must retain the above Notice,
** these Conditions and the following Limitations.
**
** (2) Redistributions in binary form must reproduce the above Notice,
** these Conditions and the following Limitations in the
** documentation and/or other materials provided with the distribution.
**
** (3) Neither the names of the Owner, nor the names of its contributors
** may be used to endorse or promote products derived from this
** Software without specific prior written permission.
**
** Limitations: Any person exercising any of the permissions in the
** relevant licence will be taken to have accepted the following as
** legally binding terms severally with the Owner and any other
** copyright owners (collectively "Participants"):
**
** TO THE EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS",
** WITHOUT ANY REPRESENTATION, WARRANTY OR CONDITION OF ANY KIND, EXPRESS
** OR IMPLIED, INCLUDING (WITHOUT LIMITATION) AS TO MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. TO THE EXTENT
** PERMITTED BY LAW, IN NO EVENT SHALL ANY PARTICIPANT BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
**
** WHERE BY LAW A LIABILITY (ON ANY BASIS) OF ANY PARTICIPANT IN RELATION
** TO THE SOFTWARE CANNOT BE EXCLUDED, THEN TO THE EXTENT PERMITTED BY
** LAW THAT LIABILITY IS LIMITED AT THE OPTION OF THE PARTICIPANT TO THE
** REPLACEMENT, REPAIR OR RESUPPLY OF THE RELEVANT GOODS OR SERVICES
** (INCLUDING BUT NOT LIMITED TO SOFTWARE) OR THE PAYMENT OF THE COST OF SAME.
*/
require_once __DIR__ . '/IMu.php';
require_once IMu::$api . '/Exception.php';
require_once IMu::$api . '/Trace.php';
class IMuDocument
{
/* Ideally IMuDocument would be a subclass of DOMDocument (as it was
** in earlier IMu versions).
**
** However, if a DOM document is constructed using new DOMDocument() [or
** by constructing a subclass] the document cannot be given a DTD.
**
** Creating DOM documents with DTDs is required by the IMu web framework.
** This means that the only effective way to construct the document is to
** use DOMImplementation::createDocument().
**
** However, in PHP this mechanism cannot construct objects which are
** subclasses of DOMDocument, only DOMDocument objects themselves.
** (See http://bugs.php.net/bug.php?id=53286 for more information)
**
** Because of this IMuDocument is implemented as a wrapper around
** DOMDocument rather than a subclass.
*/
public function
__construct($name = null, $public = null, $system = null)
{
/* DOMImplementation methods seem to be very fussy about how
** they are passed arguments. We do it this way to reduce errors and
** warnings that we don't need.
*/
$impl = new DOMImplementation();
if (is_null($name))
$this->_dom = $impl->createDocument('', '');
else
{
$dtd = $impl->createDocumentType($name, $public, $system);
$this->_dom = $impl->createDocument('', '', $dtd);
}
$this->elementClass();
$this->_stack = array($this->_dom);
}
/* Node construction */
public function
comment($data)
{
return $this->newComment($data, $this->_stack[0]);
}
public function
element($name)
{
return $this->newElement($name, $this->_stack[0]);
}
public function
text($content)
{
return $this->newTextNode($content, $this->_stack[0]);
}
public function
fragment($xml)
{
return $this->newDocumentFragment($xml, $this->_stack[0]);
}
public function
push($node)
{
array_unshift($this->_stack, $node);
}
public function
pop($node = null)
{
$count = count($this->_stack);
if ($node === null)
$count--;
else
{
for ($i = 0; $i < $count; $i++)
{
if ($this->_stack[$i] === $node)
{
$count -= $i + 1;
break;
}
}
}
while (count($this->_stack) > $count)
array_shift($this->_stack);
}
public function
top()
{
return $this->_stack[0];
}
/* Node constructors */
public function
elementClass($class = 'IMuDocumentElement')
{
/* Prior to PHP version 5.2.2, a previously registered class had
** to be unregistered before being able to register a new class
** extending the same base class.
**
** See http://www.php.net/manual/en/domdocument.registernodeclass.php
*/
$this->_dom->registerNodeClass('DOMElement', null);
$this->_dom->registerNodeClass('DOMElement', $class);
}
public function
newComment($data, $parent)
{
$node = $this->_dom->createComment($data);
$parent->appendChild($node);
return $node;
}
public function
newElement($name, $parent)
{
$node = $this->createElement($name);
$parent->appendChild($node);
return $node;
}
public function
newTextNode($content, $parent)
{
$node = $this->_dom->createTextNode($content);
$parent->appendChild($node);
return $node;
}
public function
newDocumentFragment($xml, $parent)
{
$node = $this->_dom->createDocumentFragment();
$node->appendXML($xml);
$parent->appendChild($node);
}
/* DOM wrapper */
public function
getDOM()
{
return $this->_dom;
}
/* properties */
public function
__get($name)
{
return $this->_dom->$name;
}
public function
__set($name, $value)
{
$this->_dom->$name = $value;
}
/* methods */
public function
createElement($name, $value = '')
{
$node = $this->_dom->createElement($name, $value);
$node->document = $this;
return $node;
}
public function
__call($name, $args)
{
return call_user_func_array(array($this->_dom, $name), $args);
}
protected $_dom;
protected $_stack;
}
class IMuDocumentElement extends DOMElement
{
public $document;
public function
attr($name, $value = null)
{
if ($value !== null)
$this->setAttribute($name, $value);
return $this->getAttribute($name);
}
public function
comment($data)
{
return $this->document->newComment($data, $this);
}
public function
element($name)
{
return $this->document->newElement($name, $this);
}
public function
text($content)
{
return $this->document->newTextNode($content, $this);
}
public function
fragment($xml)
{
return $this->document->newDocumentFragment($xml, $this);
}
public function
push()
{
$this->document->push($this);
}
public function
pop()
{
$this->document->pop($this);
}
}
?>

View File

@@ -0,0 +1,114 @@
<?php
/* KE Software Open Source Licence
**
** Notice: Copyright (c) 2011-2013 KE SOFTWARE PTY LTD (ACN 006 213 298)
** (the "Owner"). All rights reserved.
**
** Licence: Permission is hereby granted, free of charge, to any person
** obtaining a copy of this software and associated documentation files
** (the "Software"), to deal with the Software without restriction,
** including without limitation the rights to use, copy, modify, merge,
** publish, distribute, sublicense, and/or sell copies of the Software,
** and to permit persons to whom the Software is furnished to do so,
** subject to the following conditions.
**
** Conditions: The Software is licensed on condition that:
**
** (1) Redistributions of source code must retain the above Notice,
** these Conditions and the following Limitations.
**
** (2) Redistributions in binary form must reproduce the above Notice,
** these Conditions and the following Limitations in the
** documentation and/or other materials provided with the distribution.
**
** (3) Neither the names of the Owner, nor the names of its contributors
** may be used to endorse or promote products derived from this
** Software without specific prior written permission.
**
** Limitations: Any person exercising any of the permissions in the
** relevant licence will be taken to have accepted the following as
** legally binding terms severally with the Owner and any other
** copyright owners (collectively "Participants"):
**
** TO THE EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS",
** WITHOUT ANY REPRESENTATION, WARRANTY OR CONDITION OF ANY KIND, EXPRESS
** OR IMPLIED, INCLUDING (WITHOUT LIMITATION) AS TO MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. TO THE EXTENT
** PERMITTED BY LAW, IN NO EVENT SHALL ANY PARTICIPANT BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
**
** WHERE BY LAW A LIABILITY (ON ANY BASIS) OF ANY PARTICIPANT IN RELATION
** TO THE SOFTWARE CANNOT BE EXCLUDED, THEN TO THE EXTENT PERMITTED BY
** LAW THAT LIABILITY IS LIMITED AT THE OPTION OF THE PARTICIPANT TO THE
** REPLACEMENT, REPAIR OR RESUPPLY OF THE RELEVANT GOODS OR SERVICES
** (INCLUDING BUT NOT LIMITED TO SOFTWARE) OR THE PAYMENT OF THE COST OF SAME.
*/
require_once __DIR__ . '/IMu.php';
require_once IMu::$api . '/Trace.php';
class IMuException extends Exception
{
/* Constructor */
public function
__construct($id)
{
parent::__construct();
$this->code = 500;
$this->_id = $id;
$args = func_get_args();
array_shift($args);
$this->_args = $args;
IMuTrace::write(2, 'exception: %s', $this->__toString());
}
/* Properties */
public function
getArgs()
{
return $this->_args;
}
public function
getID()
{
return $this->_id;
}
public function
setArgs($args)
{
$this->_args = $args;
}
public function
setCode($code)
{
$this->code = $code;
}
public function
setSystem($system)
{
$this->_system = $system;
}
/* Methods */
public function
__toString()
{
$str = $this->_id;
if ($this->_args != null && count($this->_args) > 0)
$str .= ' (' . implode(',', $this->_args) . ')';
$str .= ' [' . $this->getCode() . ']';
if (isset($this->_system))
$str .= ': ' . $this->_system;
return $str;
}
private $_id;
private $_args;
private $_system;
}
?>

264
plugins/emu/lib/imu_api/HTML.php Executable file
View File

@@ -0,0 +1,264 @@
<?php
/* KE Software Open Source Licence
**
** Notice: Copyright (c) 2011-2013 KE SOFTWARE PTY LTD (ACN 006 213 298)
** (the "Owner"). All rights reserved.
**
** Licence: Permission is hereby granted, free of charge, to any person
** obtaining a copy of this software and associated documentation files
** (the "Software"), to deal with the Software without restriction,
** including without limitation the rights to use, copy, modify, merge,
** publish, distribute, sublicense, and/or sell copies of the Software,
** and to permit persons to whom the Software is furnished to do so,
** subject to the following conditions.
**
** Conditions: The Software is licensed on condition that:
**
** (1) Redistributions of source code must retain the above Notice,
** these Conditions and the following Limitations.
**
** (2) Redistributions in binary form must reproduce the above Notice,
** these Conditions and the following Limitations in the
** documentation and/or other materials provided with the distribution.
**
** (3) Neither the names of the Owner, nor the names of its contributors
** may be used to endorse or promote products derived from this
** Software without specific prior written permission.
**
** Limitations: Any person exercising any of the permissions in the
** relevant licence will be taken to have accepted the following as
** legally binding terms severally with the Owner and any other
** copyright owners (collectively "Participants"):
**
** TO THE EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS",
** WITHOUT ANY REPRESENTATION, WARRANTY OR CONDITION OF ANY KIND, EXPRESS
** OR IMPLIED, INCLUDING (WITHOUT LIMITATION) AS TO MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. TO THE EXTENT
** PERMITTED BY LAW, IN NO EVENT SHALL ANY PARTICIPANT BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
**
** WHERE BY LAW A LIABILITY (ON ANY BASIS) OF ANY PARTICIPANT IN RELATION
** TO THE SOFTWARE CANNOT BE EXCLUDED, THEN TO THE EXTENT PERMITTED BY
** LAW THAT LIABILITY IS LIMITED AT THE OPTION OF THE PARTICIPANT TO THE
** REPLACEMENT, REPAIR OR RESUPPLY OF THE RELEVANT GOODS OR SERVICES
** (INCLUDING BUT NOT LIMITED TO SOFTWARE) OR THE PAYMENT OF THE COST OF SAME.
*/
require_once __DIR__ . '/IMu.php';
require_once IMu::$api . '/Document.php';
require_once IMu::$api . '/Trace.php';
class IMuHTMLDocument extends IMuDocument
{
public function
__construct($public = 'strict', $url = '')
{
if ($public == 'strict')
{
$public = '-//W3C//DTD HTML 4.01//EN';
$url = 'http://www.w3.org/TR/html4/strict.dtd';
}
else if ($public == 'transitional')
{
$public = '-//W3C//DTD HTML 4.01 Transitional//EN';
$url = 'http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd';
}
parent::__construct('html', $public, $url);
$this->elementClass('IMuHTMLElement');
}
public function
output()
{
header('Content-type: text/html');
print $this->saveHTML();
}
public function
newDocumentFragment($fragment, $parent)
{
/* Load the fragment by creating a separate HTML document and
** extracting the nodes from that.
**
** The fragment is embedded in a UTF-8 compliant HTML document.
** This is as described in various user comments at
** http://www.php.net/manual/en/domdocument.loadhtml.php
*/
$html = <<<EOF
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body>
$fragment
</body>
</html>
EOF;
$dom = new DOMDocument();
if (! $dom->loadHTML($html))
{
IMuTrace(3, 'newDocumentFragment: loadHTML failed');
return;
}
$list = $dom->getElementsByTagName('body');
$body = $list->item(0);
$list = $body->childNodes;
$length = $list->length;
for ($i = 0; $i < $length; $i++)
{
$node = $list->item($i);
$node = $parent->ownerDocument->importNode($node, true);
$parent->appendChild($node);
}
}
/* Convenience */
/* head elements */
public function
css($name, $media = null)
{
if (! preg_match('/\.css$/', $name))
$name .= '.css';
$node = $this->element('link', false);
$node->attr('rel', 'stylesheet');
$node->attr('type', 'text/css');
$node->attr('href', $name);
if ($media !== null)
$node->attr('media', $media);
return $node;
}
public function
js($name)
{
if (! preg_match('/\.js$/', $name))
$name .= '.js';
$node = $this->element('script', false);
$node->attr('type', 'text/javascript');
$node->attr('src', $name);
return $node;
}
public function
title($text)
{
$node = $this->element('title', false);
$node->text($text);
return $node;
}
}
class IMuHTMLElement extends IMuDocumentElement
{
public function
addClass($value)
{
$class = $this->getClassArray();
$index = array_search($value, $class);
if ($index === false)
{
$class[] = $value;
$this->attr('class', implode(' ', $class));
}
return $this->attr('class');
}
public function
css($name, $value = null)
{
$styles = $this->attr('style');
if ($styles == '')
$styles = array();
else
$styles = preg_split('/;\s*/', $styles);
$entries = array();
foreach ($styles as $style)
{
if (! preg_match('/^([^:]*):(.*)$/', $style, $m))
continue;
$styleName = $m[1];
$styleValue = $m[2];
$styleName = preg_replace('/^\s+/', '', $styleName);
$styleName = preg_replace('/\s+$/', '', $styleName);
$styleValue = preg_replace('/^\s+/', '', $styleValue);
$styleValue = preg_replace('/\s+$/', '', $styleValue);
$entries[] = array($styleName, $styleValue);
}
$index = -1;
for ($i = 0; $i < count($entries); $i++)
{
if ($entries[$i][0] == $name)
{
$index = $i;
break;
}
}
if ($value === null)
{
if ($index < 0)
return '';
return $entries[$index][1];
}
if ($index < 0)
$entries[] = array($name, $value);
else
$entries[$index][1] = $value;
$style = '';
for ($i = 0; $i < count($entries); $i++)
{
if ($i > 0)
$style .= ' ';
$style .= $entries[$i][0] . ': ' . $entries[$i][1] . ';';
}
$this->attr('style', $style);
}
public function
hasClass($value)
{
$class = $this->getClassArray();
return array_search($value, $class) !== false;
}
public function
id($value = null)
{
if ($value !== null)
$this->attr('id', $value);
return $this->attr('id');
}
public function
removeClass($value)
{
$class = $this->getClassArray();
$index = array_search($value, $class);
if ($index !== false)
{
array_splice($class, $index, 1);
$this->attr('class', implode(' ', $class));
}
return $this->attr('class');
}
protected function
getClassArray()
{
$class = $this->attr('class');
if ($class == '')
return array();
return preg_split('/\s+/', $class);
}
}
?>

View File

@@ -0,0 +1,226 @@
<?php
/* KE Software Open Source Licence
**
** Notice: Copyright (c) 2011-2013 KE SOFTWARE PTY LTD (ACN 006 213 298)
** (the "Owner"). All rights reserved.
**
** Licence: Permission is hereby granted, free of charge, to any person
** obtaining a copy of this software and associated documentation files
** (the "Software"), to deal with the Software without restriction,
** including without limitation the rights to use, copy, modify, merge,
** publish, distribute, sublicense, and/or sell copies of the Software,
** and to permit persons to whom the Software is furnished to do so,
** subject to the following conditions.
**
** Conditions: The Software is licensed on condition that:
**
** (1) Redistributions of source code must retain the above Notice,
** these Conditions and the following Limitations.
**
** (2) Redistributions in binary form must reproduce the above Notice,
** these Conditions and the following Limitations in the
** documentation and/or other materials provided with the distribution.
**
** (3) Neither the names of the Owner, nor the names of its contributors
** may be used to endorse or promote products derived from this
** Software without specific prior written permission.
**
** Limitations: Any person exercising any of the permissions in the
** relevant licence will be taken to have accepted the following as
** legally binding terms severally with the Owner and any other
** copyright owners (collectively "Participants"):
**
** TO THE EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS",
** WITHOUT ANY REPRESENTATION, WARRANTY OR CONDITION OF ANY KIND, EXPRESS
** OR IMPLIED, INCLUDING (WITHOUT LIMITATION) AS TO MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. TO THE EXTENT
** PERMITTED BY LAW, IN NO EVENT SHALL ANY PARTICIPANT BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
**
** WHERE BY LAW A LIABILITY (ON ANY BASIS) OF ANY PARTICIPANT IN RELATION
** TO THE SOFTWARE CANNOT BE EXCLUDED, THEN TO THE EXTENT PERMITTED BY
** LAW THAT LIABILITY IS LIMITED AT THE OPTION OF THE PARTICIPANT TO THE
** REPLACEMENT, REPAIR OR RESUPPLY OF THE RELEVANT GOODS OR SERVICES
** (INCLUDING BUT NOT LIMITED TO SOFTWARE) OR THE PAYMENT OF THE COST OF SAME.
*/
require_once __DIR__ . '/IMu.php';
require_once IMu::$api . '/Session.php';
class IMuHandler
{
/* Constructor */
public function
__construct($session = null)
{
if ($session === null)
$this->_session = new IMuSession;
else
$this->_session = $session;
$this->_create = null;
$this->_destroy = null;
$this->_id = null;
$this->_language = null;
$this->_name = null;
}
/* Properties */
public function
getCreate()
{
return $this->_create;
}
public function
setCreate($create)
{
$this->_create = $create;
}
public function
getDestroy()
{
if ($this->_destroy === null)
return false;
return $this->_destroy;
}
public function
setDestroy($destroy)
{
$this->_destroy = $destroy;
}
public function
getID()
{
return $this->_id;
}
public function
setID($id)
{
$this->_id = $id;
}
public function
getLanguage()
{
return $this->_language;
}
public function
setLanguage($language)
{
$this->_language = $language;
}
public function
getName()
{
return $this->_name;
}
public function
setName($name)
{
$this->_name = $name;
}
public function
getSession()
{
return $this->_session;
}
public function
__get($name)
{
switch ($name)
{
case 'create':
return $this->getCreate();
case 'destroy':
return $this->getDestroy();
case 'id':
return $this->getID();
case 'language':
return $this->getLanguage();
case 'name':
return $this->getName();
case 'session':
return $this->getSession();
default:
throw new IMuException('HandlerProperty', $name);
}
}
public function
__set($name, $value)
{
switch ($name)
{
case 'create':
return $this->setCreate($value);
case 'destroy':
return $this->setDestroy($value);
case 'id':
return $this->setID($value);
case 'language':
return $this->setLanguage($value);
case 'name':
return $this->setName($value);
case 'session':
throw new IMuException('HandlerSessionReadOnly');
default:
throw new IMuException('HandlerProperty', $name);
}
}
/* Methods */
public function
call($method, $params = null)
{
$request = array();
$request['method'] = $method;
if ($params !== null)
$request['params'] = $params;
$response = $this->request($request);
return $response['result'];
}
public function
request($request)
{
if ($this->_id !== null)
$request['id'] = $this->_id;
else if ($this->_name !== null)
{
$request['name'] = $this->_name;
if ($this->_create !== null)
$request['create'] = $this->_create;
}
if ($this->_destroy !== null)
$request['destroy'] = $this->_destroy;
if ($this->_language !== null)
$request['language'] = $this->_language;
$response = $this->_session->request($request);
if (array_key_exists('id', $response))
$this->_id = $response['id'];
return $response;
}
protected $_session;
protected $_create;
protected $_destroy;
protected $_id;
protected $_language;
protected $_name;
}
?>

60
plugins/emu/lib/imu_api/IMu.php Executable file
View File

@@ -0,0 +1,60 @@
<?php
/* KE Software Open Source Licence
**
** Notice: Copyright (c) 2011-2013 KE SOFTWARE PTY LTD (ACN 006 213 298)
** (the "Owner"). All rights reserved.
**
** Licence: Permission is hereby granted, free of charge, to any person
** obtaining a copy of this software and associated documentation files
** (the "Software"), to deal with the Software without restriction,
** including without limitation the rights to use, copy, modify, merge,
** publish, distribute, sublicense, and/or sell copies of the Software,
** and to permit persons to whom the Software is furnished to do so,
** subject to the following conditions.
**
** Conditions: The Software is licensed on condition that:
**
** (1) Redistributions of source code must retain the above Notice,
** these Conditions and the following Limitations.
**
** (2) Redistributions in binary form must reproduce the above Notice,
** these Conditions and the following Limitations in the
** documentation and/or other materials provided with the distribution.
**
** (3) Neither the names of the Owner, nor the names of its contributors
** may be used to endorse or promote products derived from this
** Software without specific prior written permission.
**
** Limitations: Any person exercising any of the permissions in the
** relevant licence will be taken to have accepted the following as
** legally binding terms severally with the Owner and any other
** copyright owners (collectively "Participants"):
**
** TO THE EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS",
** WITHOUT ANY REPRESENTATION, WARRANTY OR CONDITION OF ANY KIND, EXPRESS
** OR IMPLIED, INCLUDING (WITHOUT LIMITATION) AS TO MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. TO THE EXTENT
** PERMITTED BY LAW, IN NO EVENT SHALL ANY PARTICIPANT BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
**
** WHERE BY LAW A LIABILITY (ON ANY BASIS) OF ANY PARTICIPANT IN RELATION
** TO THE SOFTWARE CANNOT BE EXCLUDED, THEN TO THE EXTENT PERMITTED BY
** LAW THAT LIABILITY IS LIMITED AT THE OPTION OF THE PARTICIPANT TO THE
** REPLACEMENT, REPAIR OR RESUPPLY OF THE RELEVANT GOODS OR SERVICES
** (INCLUDING BUT NOT LIMITED TO SOFTWARE) OR THE PAYMENT OF THE COST OF SAME.
*/
class IMu
{
const VERSION = '2.0';
public static $api;
public static $lib;
public static $language;
}
IMu::$api = __DIR__;
IMu::$lib = IMu::$api;
IMu::$language = 'en';
?>

1230
plugins/emu/lib/imu_api/MIME.php Executable file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,250 @@
<?php
/* KE Software Open Source Licence
**
** Notice: Copyright (c) 2011-2013 KE SOFTWARE PTY LTD (ACN 006 213 298)
** (the "Owner"). All rights reserved.
**
** Licence: Permission is hereby granted, free of charge, to any person
** obtaining a copy of this software and associated documentation files
** (the "Software"), to deal with the Software without restriction,
** including without limitation the rights to use, copy, modify, merge,
** publish, distribute, sublicense, and/or sell copies of the Software,
** and to permit persons to whom the Software is furnished to do so,
** subject to the following conditions.
**
** Conditions: The Software is licensed on condition that:
**
** (1) Redistributions of source code must retain the above Notice,
** these Conditions and the following Limitations.
**
** (2) Redistributions in binary form must reproduce the above Notice,
** these Conditions and the following Limitations in the
** documentation and/or other materials provided with the distribution.
**
** (3) Neither the names of the Owner, nor the names of its contributors
** may be used to endorse or promote products derived from this
** Software without specific prior written permission.
**
** Limitations: Any person exercising any of the permissions in the
** relevant licence will be taken to have accepted the following as
** legally binding terms severally with the Owner and any other
** copyright owners (collectively "Participants"):
**
** TO THE EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS",
** WITHOUT ANY REPRESENTATION, WARRANTY OR CONDITION OF ANY KIND, EXPRESS
** OR IMPLIED, INCLUDING (WITHOUT LIMITATION) AS TO MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. TO THE EXTENT
** PERMITTED BY LAW, IN NO EVENT SHALL ANY PARTICIPANT BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
**
** WHERE BY LAW A LIABILITY (ON ANY BASIS) OF ANY PARTICIPANT IN RELATION
** TO THE SOFTWARE CANNOT BE EXCLUDED, THEN TO THE EXTENT PERMITTED BY
** LAW THAT LIABILITY IS LIMITED AT THE OPTION OF THE PARTICIPANT TO THE
** REPLACEMENT, REPAIR OR RESUPPLY OF THE RELEVANT GOODS OR SERVICES
** (INCLUDING BUT NOT LIMITED TO SOFTWARE) OR THE PAYMENT OF THE COST OF SAME.
*/
require_once __DIR__ . '/IMu.php';
require_once IMu::$api . '/Handler.php';
class IMuModule extends IMuHandler
{
/* Constructor */
public function
__construct($table, $session = null)
{
parent::__construct($session);
$this->_name = 'Module';
$this->_create = $table;
$this->_table = $table;
}
/* Properties */
public function
getTable()
{
return $this->_table;
}
public function
__get($name)
{
switch ($name)
{
case 'table':
return $this->getTable();
default:
return parent::__get($name);
}
}
/* Methods */
public function
addFetchSet($name, $columns)
{
$args = array();
$args['name'] = $name;
$args['columns'] = $columns;
return $this->call('addFetchSet', $args) + 0;
}
public function
addFetchSets($sets)
{
return $this->call('addFetchSets', $sets) + 0;
}
public function
addSearchAlias($name, $columns)
{
$args = array();
$args['name'] = $name;
$args['columns'] = $columns;
return $this->call('addSearchAlias', $args) + 0;
}
public function
addSearchAliases($aliases)
{
return $this->call('addSearchAliases', $aliases) + 0;
}
public function
addSortSet($name, $columns)
{
$args = array();
$args['name'] = $name;
$args['columns'] = $columns;
return $this->call('addSortSet', $args) + 0;
}
public function
addSortSets($sets)
{
return $this->call('addSortSets', $sets) + 0;
}
public function
fetch($flag, $offset, $count, $columns = null)
{
$args = array();
$args['flag'] = $flag;
$args['offset'] = $offset;
$args['count'] = $count;
if ($columns !== null)
$args['columns'] = $columns;
return $this->makeResult($this->call('fetch', $args));
}
public function
findKey($key)
{
return $this->call('findKey', $key) + 0;
}
public function
findKeys($keys)
{
return $this->call('findKeys', $keys) + 0;
}
public function
findTerms($terms)
{
$class = 'IMuTerms';
if ($terms instanceof $class)
{
$terms = $terms->toArray();
}
return $this->call('findTerms', $terms) + 0;
}
public function
findWhere($where)
{
return $this->call('findWhere', $where) + 0;
}
public function
insert($values, $columns = null)
{
$args = array();
$args['values'] = $values;
if ($columns !== null)
$args['columns'] = $columns;
return $this->call('insert', $args);
}
public function
remove($flag, $offset, $count = null)
{
$args = array();
$args['flag'] = $flag;
$args['offset'] = $offset;
if ($count !== null)
$args['count'] = $count;
return $this->call('remove', $args) + 0;
}
public function
restoreFromFile($file)
{
$args = array();
$args['file'] = $file;
return $this->call('restoreFromFile', $args) + 0;
}
public function
restoreFromTemp($file)
{
$args = array();
$args['file'] = $file;
return $this->call('restoreFromTemp', $args) + 0;
}
public function
sort($columns, $flags = null)
{
$args = array();
$args['columns'] = $columns;
if ($flags !== null)
$args['flags'] = $flags;
return $this->call('sort', $args);
}
public function
update($flag, $offset, $count, $values, $columns = null)
{
$args = array();
$args['flag'] = $flag;
$args['offset'] = $offset;
$args['count'] = $count;
$args['values'] = $values;
if ($columns !== null)
$args['columns'] = $columns;
return $this->makeResult($this->call('update', $args));
}
protected $_table;
protected function
makeResult($data)
{
$result = new IMuModuleFetchResult;
$result->hits = $data['hits'];
$result->rows = $data['rows'];
$result->count = count($result->rows);
return $result;
}
}
class IMuModuleFetchResult
{
public $count;
public $hits;
public $rows;
}
?>

View File

@@ -0,0 +1,74 @@
<?php
/* KE Software Open Source Licence
**
** Notice: Copyright (c) 2011-2013 KE SOFTWARE PTY LTD (ACN 006 213 298)
** (the "Owner"). All rights reserved.
**
** Licence: Permission is hereby granted, free of charge, to any person
** obtaining a copy of this software and associated documentation files
** (the "Software"), to deal with the Software without restriction,
** including without limitation the rights to use, copy, modify, merge,
** publish, distribute, sublicense, and/or sell copies of the Software,
** and to permit persons to whom the Software is furnished to do so,
** subject to the following conditions.
**
** Conditions: The Software is licensed on condition that:
**
** (1) Redistributions of source code must retain the above Notice,
** these Conditions and the following Limitations.
**
** (2) Redistributions in binary form must reproduce the above Notice,
** these Conditions and the following Limitations in the
** documentation and/or other materials provided with the distribution.
**
** (3) Neither the names of the Owner, nor the names of its contributors
** may be used to endorse or promote products derived from this
** Software without specific prior written permission.
**
** Limitations: Any person exercising any of the permissions in the
** relevant licence will be taken to have accepted the following as
** legally binding terms severally with the Owner and any other
** copyright owners (collectively "Participants"):
**
** TO THE EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS",
** WITHOUT ANY REPRESENTATION, WARRANTY OR CONDITION OF ANY KIND, EXPRESS
** OR IMPLIED, INCLUDING (WITHOUT LIMITATION) AS TO MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. TO THE EXTENT
** PERMITTED BY LAW, IN NO EVENT SHALL ANY PARTICIPANT BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
**
** WHERE BY LAW A LIABILITY (ON ANY BASIS) OF ANY PARTICIPANT IN RELATION
** TO THE SOFTWARE CANNOT BE EXCLUDED, THEN TO THE EXTENT PERMITTED BY
** LAW THAT LIABILITY IS LIMITED AT THE OPTION OF THE PARTICIPANT TO THE
** REPLACEMENT, REPAIR OR RESUPPLY OF THE RELEVANT GOODS OR SERVICES
** (INCLUDING BUT NOT LIMITED TO SOFTWARE) OR THE PAYMENT OF THE COST OF SAME.
*/
require_once(__DIR__ . '/../IMu.php');
require_once(IMu::$lib . '/Module.php');
class IMuLuts extends IMuModule
{
public function
__construct($session = null)
{
parent::__construct('eluts', $session);
$this->_name = 'Module::Luts';
$this->_create = null;
}
public function
lookup($name, $langid, $level = 0, $keys = false)
{
$params = array();
$params['name'] = $name;
$params['langid'] = $langid;
$params['level'] = $level;
if ($keys !== false)
$params['keys'] = $keys;
return $this->call('lookup', $params);
}
}
?>

View File

@@ -0,0 +1,86 @@
<?php
/* KE Software Open Source Licence
**
** Notice: Copyright (c) 2011-2013 KE SOFTWARE PTY LTD (ACN 006 213 298)
** (the "Owner"). All rights reserved.
**
** Licence: Permission is hereby granted, free of charge, to any person
** obtaining a copy of this software and associated documentation files
** (the "Software"), to deal with the Software without restriction,
** including without limitation the rights to use, copy, modify, merge,
** publish, distribute, sublicense, and/or sell copies of the Software,
** and to permit persons to whom the Software is furnished to do so,
** subject to the following conditions.
**
** Conditions: The Software is licensed on condition that:
**
** (1) Redistributions of source code must retain the above Notice,
** these Conditions and the following Limitations.
**
** (2) Redistributions in binary form must reproduce the above Notice,
** these Conditions and the following Limitations in the
** documentation and/or other materials provided with the distribution.
**
** (3) Neither the names of the Owner, nor the names of its contributors
** may be used to endorse or promote products derived from this
** Software without specific prior written permission.
**
** Limitations: Any person exercising any of the permissions in the
** relevant licence will be taken to have accepted the following as
** legally binding terms severally with the Owner and any other
** copyright owners (collectively "Participants"):
**
** TO THE EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS",
** WITHOUT ANY REPRESENTATION, WARRANTY OR CONDITION OF ANY KIND, EXPRESS
** OR IMPLIED, INCLUDING (WITHOUT LIMITATION) AS TO MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. TO THE EXTENT
** PERMITTED BY LAW, IN NO EVENT SHALL ANY PARTICIPANT BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
**
** WHERE BY LAW A LIABILITY (ON ANY BASIS) OF ANY PARTICIPANT IN RELATION
** TO THE SOFTWARE CANNOT BE EXCLUDED, THEN TO THE EXTENT PERMITTED BY
** LAW THAT LIABILITY IS LIMITED AT THE OPTION OF THE PARTICIPANT TO THE
** REPLACEMENT, REPAIR OR RESUPPLY OF THE RELEVANT GOODS OR SERVICES
** (INCLUDING BUT NOT LIMITED TO SOFTWARE) OR THE PAYMENT OF THE COST OF SAME.
*/
require_once(__DIR__ . '/../IMu.php');
require_once(IMu::$lib . '/Module.php');
class IMuRegistry extends IMuModule
{
public function
__construct($session = null)
{
parent::__construct('eregistry', $session);
$this->_name = 'Module::Registry';
$this->_create = null;
}
public function
getValue($keys = false)
{
$params = array();
if ($keys !== false)
$params['keys'] = $keys;
return $this->call('getValue', $params);
}
public function
setValue($keys = false, $value = false)
{
$params = array();
if ($keys !== false)
$params['keys'] = $keys;
if ($value !== false)
$params['value'] = $value;
return $this->call('setValue', $params);
}
}
?>

View File

@@ -0,0 +1,86 @@
<?php
/* KE Software Open Source Licence
**
** Notice: Copyright (c) 2011-2013 KE SOFTWARE PTY LTD (ACN 006 213 298)
** (the "Owner"). All rights reserved.
**
** Licence: Permission is hereby granted, free of charge, to any person
** obtaining a copy of this software and associated documentation files
** (the "Software"), to deal with the Software without restriction,
** including without limitation the rights to use, copy, modify, merge,
** publish, distribute, sublicense, and/or sell copies of the Software,
** and to permit persons to whom the Software is furnished to do so,
** subject to the following conditions.
**
** Conditions: The Software is licensed on condition that:
**
** (1) Redistributions of source code must retain the above Notice,
** these Conditions and the following Limitations.
**
** (2) Redistributions in binary form must reproduce the above Notice,
** these Conditions and the following Limitations in the
** documentation and/or other materials provided with the distribution.
**
** (3) Neither the names of the Owner, nor the names of its contributors
** may be used to endorse or promote products derived from this
** Software without specific prior written permission.
**
** Limitations: Any person exercising any of the permissions in the
** relevant licence will be taken to have accepted the following as
** legally binding terms severally with the Owner and any other
** copyright owners (collectively "Participants"):
**
** TO THE EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS",
** WITHOUT ANY REPRESENTATION, WARRANTY OR CONDITION OF ANY KIND, EXPRESS
** OR IMPLIED, INCLUDING (WITHOUT LIMITATION) AS TO MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. TO THE EXTENT
** PERMITTED BY LAW, IN NO EVENT SHALL ANY PARTICIPANT BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
**
** WHERE BY LAW A LIABILITY (ON ANY BASIS) OF ANY PARTICIPANT IN RELATION
** TO THE SOFTWARE CANNOT BE EXCLUDED, THEN TO THE EXTENT PERMITTED BY
** LAW THAT LIABILITY IS LIMITED AT THE OPTION OF THE PARTICIPANT TO THE
** REPLACEMENT, REPAIR OR RESUPPLY OF THE RELEVANT GOODS OR SERVICES
** (INCLUDING BUT NOT LIMITED TO SOFTWARE) OR THE PAYMENT OF THE COST OF SAME.
*/
require_once(__DIR__ . '/../IMu.php');
require_once(IMu::$lib . '/Module.php');
class IMuStatistics extends IMuModule
{
public function
__construct($session = false)
{
parent::__construct('estatistics', $session);
$this->name = 'Module::Statistics';
unset($this->create);
}
public function
getValue($keys, $from = null, $to = null)
{
$params = array();
$params['keys'] = $keys;
if (! is_null($from))
$params['from'] = $from;
if (! is_null($to))
$params['to'] = $to;
return $this->call('getValue', $params);
}
public function
getValues($keys, $from = null, $to = null)
{
$params = array();
$params['keys'] = $keys;
if (! is_null($from))
$params['from'] = $from;
if (! is_null($to))
$params['to'] = $to;
return $this->call('getValues', $params);
}
}
?>

View File

@@ -0,0 +1,332 @@
<?php
/* KE Software Open Source Licence
**
** Notice: Copyright (c) 2011-2013 KE SOFTWARE PTY LTD (ACN 006 213 298)
** (the "Owner"). All rights reserved.
**
** Licence: Permission is hereby granted, free of charge, to any person
** obtaining a copy of this software and associated documentation files
** (the "Software"), to deal with the Software without restriction,
** including without limitation the rights to use, copy, modify, merge,
** publish, distribute, sublicense, and/or sell copies of the Software,
** and to permit persons to whom the Software is furnished to do so,
** subject to the following conditions.
**
** Conditions: The Software is licensed on condition that:
**
** (1) Redistributions of source code must retain the above Notice,
** these Conditions and the following Limitations.
**
** (2) Redistributions in binary form must reproduce the above Notice,
** these Conditions and the following Limitations in the
** documentation and/or other materials provided with the distribution.
**
** (3) Neither the names of the Owner, nor the names of its contributors
** may be used to endorse or promote products derived from this
** Software without specific prior written permission.
**
** Limitations: Any person exercising any of the permissions in the
** relevant licence will be taken to have accepted the following as
** legally binding terms severally with the Owner and any other
** copyright owners (collectively "Participants"):
**
** TO THE EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS",
** WITHOUT ANY REPRESENTATION, WARRANTY OR CONDITION OF ANY KIND, EXPRESS
** OR IMPLIED, INCLUDING (WITHOUT LIMITATION) AS TO MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. TO THE EXTENT
** PERMITTED BY LAW, IN NO EVENT SHALL ANY PARTICIPANT BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
**
** WHERE BY LAW A LIABILITY (ON ANY BASIS) OF ANY PARTICIPANT IN RELATION
** TO THE SOFTWARE CANNOT BE EXCLUDED, THEN TO THE EXTENT PERMITTED BY
** LAW THAT LIABILITY IS LIMITED AT THE OPTION OF THE PARTICIPANT TO THE
** REPLACEMENT, REPAIR OR RESUPPLY OF THE RELEVANT GOODS OR SERVICES
** (INCLUDING BUT NOT LIMITED TO SOFTWARE) OR THE PAYMENT OF THE COST OF SAME.
*/
require_once __DIR__ . '/IMu.php';
require_once IMu::$api . '/Handler.php';
class IMuModules extends IMuHandler
{
/* Constructor */
public function
__construct($session = null)
{
parent::__construct($session);
$this->_name = 'Modules';
$this->_modules = null;
}
/* Methods */
public function
addFetchSet($name, $set)
{
$args = array();
$args['name'] = $name;
$args['set'] = $set;
return $this->call('addFetchSet', $args) + 0;
}
public function
addFetchSets($sets)
{
return $this->call('addFetchSets', $sets) + 0;
}
public function
addSearchAlias($name, $set)
{
$args = array();
$args['name'] = $name;
$args['set'] = $set;
return $this->call('addSearchAlias', $args) + 0;
}
public function
addSearchAliases($aliases)
{
return $this->call('addSearchAliases', $aliases) + 0;
}
public function
addSortSet($name, $set)
{
$args = array();
$args['name'] = $name;
$args['set'] = $set;
return $this->call('addSortSet', $args) + 0;
}
public function
addSortSets($sets)
{
return $this->call('addSortSets', $sets) + 0;
}
public function
fetch($flag, $offset, $count, $columns = null)
{
$args = array();
$args['flag'] = $flag;
$args['offset'] = $offset;
$args['count'] = $count;
if ($columns !== null)
$args['columns'] = $columns;
return $this->makeResult($this->call('fetch', $args));
}
public function
fetchMany($list, $columns = null)
{
$args = array();
$args['list'] = $list;
if ($columns !== null)
$args['columns'] = $columns;
$data = $this->call('fetchMany', $args);
// TODO
$result = $data;
return $result;
}
public function
findAttachments($table, $column, $key)
{
$args = array();
$args['table'] = $table;
$args['column'] = $column;
$args['key'] = $key;
return $this->call('findAttachments', $args) + 0;
}
public function
findKeys($keys, $include = null)
{
$args = array();
$args['keys'] = $keys;
if ($include !== null)
$args['include'] = $include;
return $this->call('findKeys', $args);
}
public function
findTerms($terms, $include = null)
{
$class = 'IMuTerms';
if ($terms instanceof $class)
{
$terms = $terms->toArray();
}
$args = array();
$args['terms'] = $terms;
if ($include !== null)
$args['include'] = $include;
return $this->call('findTerms', $args);
}
public function
getAllHits()
{
return $this->call('getAllHits');
}
public function
getHits($module = null)
{
return $this->call('getHits', $module) + 0;
}
public function
restoreFromFile($file, $module = null)
{
$args = array();
$args['file'] = $file;
if ($module !== null)
$args['module'] = $module;
return $this->call('restoreFromFile', $args);
}
public function
restoreFromTemp($file, $module = null)
{
$args = array();
$args['file'] = $file;
if ($module !== null)
$args['module'] = $module;
return $this->call('restoreFromTemp', $args);
}
public function
setModules($list)
{
$this->_modules = $list;
return $this->call('setModules', $list) + 0;
}
public function
sort($set, $flags = null)
{
$args = array();
$args['set'] = $set;
if ($flags !== null)
$args['flags'] = $flags;
return $this->call('sort', $args);
}
public function
update($flag, $offset, $count, $values, $columns = null)
{
$args = array();
$args['flag'] = $flag;
$args['offset'] = $offset;
$args['count'] = $count;
$args['values'] = $values;
if ($columns !== null)
$args['columns'] = $columns;
return $this->makeResult($this->call('update', $args));
}
protected $_modules;
protected function
makePosition($array)
{
$flag = $array['flag'];
$offset = $array['offset'] + 0;
return new IMuModulesFetchPosition($flag, $offset);
}
protected function
makeResult($data)
{
$result = new IMuModulesFetchResult;
$result->count = $data['count'] + 0;
$result->modules = array();
foreach ($data['modules'] as $item)
{
$module = new IMuModulesFetchModule;
$module->hits = $item['hits'] + 0;
$module->index = $item['index'] + 0;
$module->name = $item['name'];
$module->rows = $item['rows'];
$result->modules[] = $module;
}
if (array_key_exists('current', $data))
$result->current = $this->makePosition($data['current']);
if (array_key_exists('next', $data))
$result->next = $this->makePosition($data['next']);
if (array_key_exists('prev', $data))
$result->prev = $this->makePosition($data['prev']);
return $result;
}
}
class IMuModulesFetchResult
{
public $count;
public $current;
public $modules;
public $next;
public $prev;
public function
__construct()
{
$this->count = 0;
$this->current = null;
$this->modules = null;
$this->next = null;
$this->prev = null;
}
}
class IMuModulesFetchModule
{
public $hits;
public $index;
public $name;
public $rows;
public function
__construct()
{
$this->hits = 0;
$this->index = -1;
$this->name = null;
$this->rows = null;
}
}
class IMuModulesFetchPosition
{
public $flag;
public $offset;
public function
__construct($flag, $offset)
{
$this->flag = $flag;
$this->offset = $offset;;
}
}
class IMuModulesFetchManyResult
{
public $count;
public $rows;
public function
__construct()
{
$this->count = 0;
$this->rows = null;
}
}
?>

View File

@@ -0,0 +1,132 @@
<?php
/* KE Software Open Source Licence
**
** Notice: Copyright (c) 2011-2013 KE SOFTWARE PTY LTD (ACN 006 213 298)
** (the "Owner"). All rights reserved.
**
** Licence: Permission is hereby granted, free of charge, to any person
** obtaining a copy of this software and associated documentation files
** (the "Software"), to deal with the Software without restriction,
** including without limitation the rights to use, copy, modify, merge,
** publish, distribute, sublicense, and/or sell copies of the Software,
** and to permit persons to whom the Software is furnished to do so,
** subject to the following conditions.
**
** Conditions: The Software is licensed on condition that:
**
** (1) Redistributions of source code must retain the above Notice,
** these Conditions and the following Limitations.
**
** (2) Redistributions in binary form must reproduce the above Notice,
** these Conditions and the following Limitations in the
** documentation and/or other materials provided with the distribution.
**
** (3) Neither the names of the Owner, nor the names of its contributors
** may be used to endorse or promote products derived from this
** Software without specific prior written permission.
**
** Limitations: Any person exercising any of the permissions in the
** relevant licence will be taken to have accepted the following as
** legally binding terms severally with the Owner and any other
** copyright owners (collectively "Participants"):
**
** TO THE EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS",
** WITHOUT ANY REPRESENTATION, WARRANTY OR CONDITION OF ANY KIND, EXPRESS
** OR IMPLIED, INCLUDING (WITHOUT LIMITATION) AS TO MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. TO THE EXTENT
** PERMITTED BY LAW, IN NO EVENT SHALL ANY PARTICIPANT BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
**
** WHERE BY LAW A LIABILITY (ON ANY BASIS) OF ANY PARTICIPANT IN RELATION
** TO THE SOFTWARE CANNOT BE EXCLUDED, THEN TO THE EXTENT PERMITTED BY
** LAW THAT LIABILITY IS LIMITED AT THE OPTION OF THE PARTICIPANT TO THE
** REPLACEMENT, REPAIR OR RESUPPLY OF THE RELEVANT GOODS OR SERVICES
** (INCLUDING BUT NOT LIMITED TO SOFTWARE) OR THE PAYMENT OF THE COST OF SAME.
*/
require_once __DIR__ . '/IMu.php';
class IMuParams
{
const REPEATS_NEVER = 0;
const REPEATS_AS_NEEDED = 1;
const REPEATS_ALWAYS = 2;
public function
__construct($repeats = REPEATS_NEVER)
{
$this->repeats = $repeats;
$this->list = array();
/* GET */
$this->load($_SERVER['QUERY_STRING']);
/* POST */
$this->load(file_get_contents('php://input'));
}
public $repeats;
public $list;
public function
get($name, $value = null)
{
if (array_key_exists($name, $this->list))
$value = $this->list[$name];
return $value;
}
public function
has($name)
{
return array_key_exists($name, $this->list);
}
public function
remove($name, $value = null)
{
if (array_key_exists($name, $this->list))
{
$value = $this->list[$name];
unset($this->list[$name]);
}
return $value;
}
private function
load($string)
{
if ($string == '')
return;
foreach (explode('&', $string) as $pair)
{
$pair = explode('=', $pair);
$name = urldecode($pair[0]);
$value = urldecode($pair[1]);
switch ($this->repeats)
{
case self::REPEATS_AS_NEEDED:
if (! array_key_exists($name, $this->list))
$this->list[$name] = $value;
else if (! is_array($this->list[$name]))
$this->list[$name] = array($this->list[$name], $value);
else
$this->list[$name][] = $value;
break;
case self::REPEATS_ALWAYS:
$this->list[$name][] = $value;
break;
case self::REPEATS_NEVER:
default:
$this->list[$name] = $value;
break;
}
}
}
}
?>

202
plugins/emu/lib/imu_api/RSS.php Executable file
View File

@@ -0,0 +1,202 @@
<?php
/* KE Software Open Source Licence
**
** Notice: Copyright (c) 2011-2013 KE SOFTWARE PTY LTD (ACN 006 213 298)
** (the "Owner"). All rights reserved.
**
** Licence: Permission is hereby granted, free of charge, to any person
** obtaining a copy of this software and associated documentation files
** (the "Software"), to deal with the Software without restriction,
** including without limitation the rights to use, copy, modify, merge,
** publish, distribute, sublicense, and/or sell copies of the Software,
** and to permit persons to whom the Software is furnished to do so,
** subject to the following conditions.
**
** Conditions: The Software is licensed on condition that:
**
** (1) Redistributions of source code must retain the above Notice,
** these Conditions and the following Limitations.
**
** (2) Redistributions in binary form must reproduce the above Notice,
** these Conditions and the following Limitations in the
** documentation and/or other materials provided with the distribution.
**
** (3) Neither the names of the Owner, nor the names of its contributors
** may be used to endorse or promote products derived from this
** Software without specific prior written permission.
**
** Limitations: Any person exercising any of the permissions in the
** relevant licence will be taken to have accepted the following as
** legally binding terms severally with the Owner and any other
** copyright owners (collectively "Participants"):
**
** TO THE EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS",
** WITHOUT ANY REPRESENTATION, WARRANTY OR CONDITION OF ANY KIND, EXPRESS
** OR IMPLIED, INCLUDING (WITHOUT LIMITATION) AS TO MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. TO THE EXTENT
** PERMITTED BY LAW, IN NO EVENT SHALL ANY PARTICIPANT BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
**
** WHERE BY LAW A LIABILITY (ON ANY BASIS) OF ANY PARTICIPANT IN RELATION
** TO THE SOFTWARE CANNOT BE EXCLUDED, THEN TO THE EXTENT PERMITTED BY
** LAW THAT LIABILITY IS LIMITED AT THE OPTION OF THE PARTICIPANT TO THE
** REPLACEMENT, REPAIR OR RESUPPLY OF THE RELEVANT GOODS OR SERVICES
** (INCLUDING BUT NOT LIMITED TO SOFTWARE) OR THE PAYMENT OF THE COST OF SAME.
*/
require_once __DIR__ . '/IMu.php';
require_once IMu::$api . '/XML.php';
class IMuRSS
{
public $encoding;
/* Mandatory elements */
public $description;
public $link;
public $title;
/* Optional elements */
public $author;
public $category;
public $copyright;
public $language;
/* iTunes-specific settings */
public $iTunes;
public $iTunesNS;
/* iTunes-specific elements */
public $explicit;
public $image;
public function
__construct()
{
$this->encoding = 'UTF-8';
$this->items = array();
$this->description = '';
$this->link = '';
$this->title = '';
$this->iTunes = false;
$this->iTunesNS = 'http://www.itunes.com/dtds/podcast-1.0.dtd';
}
public function
addItem()
{
$item = new IMuRSSItem;
$this->items[] = $item;
return $item;
}
public function
createXML()
{
$xml = new IMuXMLDocument();
$elem = $xml->element('rss');
$elem->attr('version', '2.0');
if ($this->iTunes)
$elem->attr('xmlns:itunes', $this->iTunesNS);
$elem->push();
$elem = $xml->element('channel');
$elem->push();
// Mandatory
$xml->element('description', $this->description);
$xml->element('link', $this->link);
$xml->element('title', $this->title);
// Not mandatory but always included
$date = date('r');
$xml->element('lastBuildDate', $date);
$xml->element('pubDate', $date);
// Optional
if (isset($this->author))
$xml->element('author', $this->author);
if (isset($this->category))
$xml->element('category', $this->category);
if (isset($this->copyright))
$xml->element('copyright', $this->copyright);
if (isset($this->language))
$xml->element('language', $this->language);
// iTunes-specific
if ($this->iTunes)
{
if (isset($this->explicit))
{
$explicit = $this->explicit;
if (is_bool($explicit))
$explicit = $explicit ? 'Yes' : 'No';
$xml->element('itunes:explicit', $explicit);
}
if (isset($this->image))
$xml->element('itunes:image', $this->image);
}
foreach ($this->items as $item)
$item->createXML($xml);
return $xml->saveXML();
}
private $items;
}
class IMuRSSItem
{
public $author;
public $category;
public $description;
public $length;
public $link;
public $mimeType;
public $pubDate;
public $title;
public $url;
public function
__construct()
{
$this->author = '';
$this->category = '';
$this->description = '';
$this->length = '';
$this->link = '';
$this->mimeType = '';
$this->pubDate = '';
$this->title = '';
$this->url = '';
}
public function
createXML($xml)
{
$elem = $xml->element('item');
$elem->push();
if (isset($this->author) && $this->author != '')
$xml->element('author', $this->author);
if (isset($this->category) && $this->category != '')
$xml->element('category', $this->category);
$xml->element('description', $this->description);
$elem = $xml->element('enclosure');
$elem->attr('url', $this->url);
$elem->attr('length', $this->length);
$elem->attr('type', $this->mimeType);
$xml->element('guid', $this->link);
$xml->element('link', $this->link);
$xml->element('pubDate', $this->pubDate);
$xml->element('title', $this->title);
}
}
?>

View File

@@ -0,0 +1,371 @@
<?php
/* KE Software Open Source Licence
**
** Notice: Copyright (c) 2011-2013 KE SOFTWARE PTY LTD (ACN 006 213 298)
** (the "Owner"). All rights reserved.
**
** Licence: Permission is hereby granted, free of charge, to any person
** obtaining a copy of this software and associated documentation files
** (the "Software"), to deal with the Software without restriction,
** including without limitation the rights to use, copy, modify, merge,
** publish, distribute, sublicense, and/or sell copies of the Software,
** and to permit persons to whom the Software is furnished to do so,
** subject to the following conditions.
**
** Conditions: The Software is licensed on condition that:
**
** (1) Redistributions of source code must retain the above Notice,
** these Conditions and the following Limitations.
**
** (2) Redistributions in binary form must reproduce the above Notice,
** these Conditions and the following Limitations in the
** documentation and/or other materials provided with the distribution.
**
** (3) Neither the names of the Owner, nor the names of its contributors
** may be used to endorse or promote products derived from this
** Software without specific prior written permission.
**
** Limitations: Any person exercising any of the permissions in the
** relevant licence will be taken to have accepted the following as
** legally binding terms severally with the Owner and any other
** copyright owners (collectively "Participants"):
**
** TO THE EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS",
** WITHOUT ANY REPRESENTATION, WARRANTY OR CONDITION OF ANY KIND, EXPRESS
** OR IMPLIED, INCLUDING (WITHOUT LIMITATION) AS TO MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. TO THE EXTENT
** PERMITTED BY LAW, IN NO EVENT SHALL ANY PARTICIPANT BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
**
** WHERE BY LAW A LIABILITY (ON ANY BASIS) OF ANY PARTICIPANT IN RELATION
** TO THE SOFTWARE CANNOT BE EXCLUDED, THEN TO THE EXTENT PERMITTED BY
** LAW THAT LIABILITY IS LIMITED AT THE OPTION OF THE PARTICIPANT TO THE
** REPLACEMENT, REPAIR OR RESUPPLY OF THE RELEVANT GOODS OR SERVICES
** (INCLUDING BUT NOT LIMITED TO SOFTWARE) OR THE PAYMENT OF THE COST OF SAME.
*/
require_once __DIR__ . '/IMu.php';
require_once IMu::$api . '/Exception.php';
require_once IMu::$api . '/Stream.php';
require_once IMu::$api . '/Trace.php';
class IMuSession
{
/* Static Properties */
public static function
getDefaultHost()
{
return self::$_defaultHost;
}
public static function
setDefaultHost($host)
{
self::$_defaultHost = $host;
}
public static function
getDefaultPort()
{
return self::$_defaultPort;
}
public static function
setDefaultPort($port)
{
self::$_defaultPort = $port;
}
public static function
getDefaultTimeout()
{
return self::$_defaultTimeout;
}
public static function
setDefaultTimeout($timeout)
{
self::$_defaultTimeout = $timeout;
}
/* Constructor */
public function
__construct($host = null, $port = null, $timeout = null)
{
$this->initialise();
if ($host !== null)
$this->_host = $host;
if ($port !== null)
$this->_port = $port;
if ($timeout !== null)
$this->_timeout = $timeout;
}
/* Properties */
public function
getClose()
{
if ($this->_close === null)
return false;
return $this->_close;
}
public function
setClose($close)
{
$this->_close = $close;
}
public function
getContext()
{
return $this->_context;
}
public function
setContext($context)
{
$this->_context = $context;
}
public function
getHost()
{
return $this->_host;
}
public function
setHost($host)
{
$this->_host = $host;
}
public function
getPort()
{
return $this->_port;
}
public function
setPort($port)
{
$this->_port = $port;
}
public function
getSuspend()
{
if ($this->_suspend === null)
return false;
return $this->_suspend;
}
public function
setSuspend($suspend)
{
$this->_suspend = $suspend;
}
public function
getTimeout()
{
return $this->_timeout;
}
public function
setTimeout($timeout)
{
$this->_timeout = $timeout;
}
public function
__get($name)
{
switch ($name)
{
case 'close':
return $this->getClose();
break;
case 'context':
return $this->getContext();
break;
case 'host':
return $this->getHost();
break;
case 'port':
return $this->getPort();
break;
case 'suspend':
return $this->getSuspend();
break;
case 'timeout':
return $this->getTimeout();
break;
default:
throw new IMuException('SessionProperty', $name);
}
}
public function
__set($name, $value)
{
switch ($name)
{
case 'close':
return $this->setClose($value);
break;
case 'context':
return $this->setContext($value);
break;
case 'host':
return $this->setHost($value);
break;
case 'port':
return $this->setPort($value);
break;
case 'suspend':
return $this->setSuspend($value);
break;
case 'timeout':
return $this->setTimeout($value);
break;
default:
throw new IMuException('SessionProperty', $name);
}
}
/* Methods */
public function
connect()
{
if ($this->_socket !== null)
return;
IMuTrace::write(2, 'connecting to %s:%d', $this->_host, $this->_port);
$socket = @fsockopen($this->_host, $this->_port, $errno, $errstr);
if ($socket === false)
throw new IMuException('SessionConnect', $this->_host, $this->_port,
$errstr);
IMuTrace::write(2, 'connected ok');
if ($this->_timeout !== null)
{
IMuTrace::write(2, 'setting timeout to %s', $this->_timeout);
stream_set_timeout($socket, $this->_timeout);
}
$this->_socket = $socket;
$this->_stream = new IMuStream($this->_socket);
}
public function
disconnect()
{
if ($this->_socket === null)
return;
IMuTrace::write(2, 'closing connection');
@fclose($this->_socket);
$this->initialise();
}
public function
login($login, $password = null, $spawn = true)
{
$request = array();
$request['login'] = $login;
$request['password'] = $password;
$request['spawn'] = $spawn;
return $this->request($request);
}
public function
logout()
{
$request = array();
$request['logout'] = true;
return $this->request($request);
}
public function
request($request)
{
$this->connect();
if ($this->_close !== null)
$request['close'] = $this->_close;
if ($this->_context !== null)
$request['context'] = $this->_context;
if ($this->suspend !== null)
$request['suspend'] = $this->_suspend;
$this->_stream->put($request);
$response = $this->_stream->get();
$type = gettype($response);
if ($type != 'array')
throw new IMuException('SessionResponse', $type);
if (array_key_exists('context', $response))
$this->_context = $response['context'];
if (array_key_exists('reconnect', $response))
$this->_port = $response['reconnect'];
$disconnect = false;
if ($this->_close !== null)
$disconnect = $this->_close;
if ($disconnect)
$this->disconnect();
$status = $response['status'];
if ($status == 'error')
{
IMuTrace::write(2, 'server error %s', $response);
$id = 'SessionServerError';
if (array_key_exists('error', $response))
$id = $response['error'];
else if (array_key_exists('id', $response))
$id = $response['id'];
$e = new IMuException($id);
if (isset($response['args']))
$e->setArgs($response['args']);
if (isset($response['code']))
$e->setCode($response['code']);
IMuTrace::write(2, 'throwing exception %s', $e->__toString());
throw $e;
}
return $response;
}
private static $_defaultHost = '127.0.0.1';
private static $_defaultPort = 40000;
private static $_defaultTimeout = null; // use system default in php.ini
private $_close;
private $_context;
private $_host;
private $_port;
private $_socket;
private $_stream;
private $_suspend;
private $_timeout;
private function
initialise()
{
$this->_close = null;
$this->_context = null;
$this->_host = self::$_defaultHost;
$this->_port = self::$_defaultPort;
$this->_socket = null;
$this->_stream = null;
$this->_suspend = null;
$this->_timeout = self::$_defaultTimeout;
}
}
?>

View File

@@ -0,0 +1,539 @@
<?php
/* KE Software Open Source Licence
**
** Notice: Copyright (c) 2011-2013 KE SOFTWARE PTY LTD (ACN 006 213 298)
** (the "Owner"). All rights reserved.
**
** Licence: Permission is hereby granted, free of charge, to any person
** obtaining a copy of this software and associated documentation files
** (the "Software"), to deal with the Software without restriction,
** including without limitation the rights to use, copy, modify, merge,
** publish, distribute, sublicense, and/or sell copies of the Software,
** and to permit persons to whom the Software is furnished to do so,
** subject to the following conditions.
**
** Conditions: The Software is licensed on condition that:
**
** (1) Redistributions of source code must retain the above Notice,
** these Conditions and the following Limitations.
**
** (2) Redistributions in binary form must reproduce the above Notice,
** these Conditions and the following Limitations in the
** documentation and/or other materials provided with the distribution.
**
** (3) Neither the names of the Owner, nor the names of its contributors
** may be used to endorse or promote products derived from this
** Software without specific prior written permission.
**
** Limitations: Any person exercising any of the permissions in the
** relevant licence will be taken to have accepted the following as
** legally binding terms severally with the Owner and any other
** copyright owners (collectively "Participants"):
**
** TO THE EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS",
** WITHOUT ANY REPRESENTATION, WARRANTY OR CONDITION OF ANY KIND, EXPRESS
** OR IMPLIED, INCLUDING (WITHOUT LIMITATION) AS TO MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. TO THE EXTENT
** PERMITTED BY LAW, IN NO EVENT SHALL ANY PARTICIPANT BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
**
** WHERE BY LAW A LIABILITY (ON ANY BASIS) OF ANY PARTICIPANT IN RELATION
** TO THE SOFTWARE CANNOT BE EXCLUDED, THEN TO THE EXTENT PERMITTED BY
** LAW THAT LIABILITY IS LIMITED AT THE OPTION OF THE PARTICIPANT TO THE
** REPLACEMENT, REPAIR OR RESUPPLY OF THE RELEVANT GOODS OR SERVICES
** (INCLUDING BUT NOT LIMITED TO SOFTWARE) OR THE PAYMENT OF THE COST OF SAME.
*/
require_once __DIR__ . '/IMu.php';
require_once IMu::$api . '/Exception.php';
require_once IMu::$api . '/Trace.php';
class IMuStream
{
/* Static Properties */
public static function
getBlockSize()
{
return self::$_blockSize;
}
public static function
setBlockSize(int $size)
{
self::$_blockSize = $size;
}
/* Constructor */
public function
__construct($socket)
{
$this->_socket = $socket;
$this->_next = '';
$this->_token = null;
$this->_string = null;
$this->_file = null;
$this->_buffer = '';
$this->_length = 0;
}
/* Methods */
public function
get()
{
$what = null;
try
{
$this->getNext();
$this->getToken();
$what = $this->getValue();
}
catch (IMuException $e)
{
throw $e;
}
catch (Exception $e)
{
throw new IMuException("StreamGet", $e->getMessage());
}
return $what;
}
public function
put($what)
{
try
{
$this->putValue($what, 0);
$this->putLine();
$this->putFlush();
}
catch (IMuException $e)
{
throw $e;
}
catch (Exception $e)
{
throw new IMuException("StreamPut", $e->getMessage());
}
}
private static $_blockSize = 8192;
private $_socket;
private $_next;
private $_token;
private $_string;
private $_file;
private $_buffer;
private $_length;
private function
getValue()
{
if ($this->_token == 'end')
return null;
if ($this->_token == 'string')
return $this->_string;
if ($this->_token == 'number')
return $this->_string + 0;
if ($this->_token == '{')
{
$array = array();
$this->getToken();
while ($this->_token != '}')
{
if ($this->_token == 'string')
$name = $this->_string;
else if ($this->_token == 'identifier')
// Extension - allow simple identifiers
$name = $this->_string;
else
throw new IMuException('StreamSyntaxName', $this->_token);
$this->getToken();
if ($this->_token != ':')
throw new IMuException('StreamSyntaxColon', $this->_token);
$this->getToken();
$array[$name] = $this->getValue();
$this->getToken();
if ($this->_token == ',')
$this->getToken();
}
return $array;
}
if ($this->_token == '[')
{
$array = array();
$this->getToken();
while ($this->_token != ']')
{
$array[] = $this->getValue();
$this->getToken();
if ($this->_token == ',')
$this->getToken();
}
return $array;
}
if ($this->_token == 'true')
return true;
if ($this->_token == 'false')
return false;
if ($this->_token == 'null')
return null;
if ($this->_token == 'binary')
return $this->_file;
throw new IMuException('StreamSyntaxToken', $this->_token);
}
private function
getToken()
{
while (ctype_space($this->_next))
$this->getNext();
$this->_string = '';
$this->_file = null;
if ($this->_next == '"')
{
$this->_token = 'string';
$this->getNext();
while ($this->_next != '"')
{
if ($this->_next == '\\')
{
$this->getNext();
if ($this->_next == 'b')
$this->_next = "\b";
else if ($this->_next == 'f')
$this->_next = "\f";
else if ($this->_next == 'n')
$this->_next = "\n";
else if ($this->_next == 'r')
$this->_next = "\r";
else if ($this->_next == 't')
$this->_next = "\t";
else if ($this->_next == 'u')
{
$this->getNext();
$str = "";
for ($i = 0; $i < 4; $i++)
{
if (! ctype_xdigit($this->_next))
break;
$str .= $this->_next;
$this->getNext();
}
if ($str == '')
throw new IMuException('StreamSyntaxUnicode');
$this->_next = chr($str);
}
}
$this->_string .= $this->_next;
$this->getNext();
}
$this->getNext();
}
else if (ctype_digit($this->_next) || $this->_next == '-')
{
$this->_token = 'number';
$this->_string .= $this->_next;
$this->getNext();
while (ctype_digit($this->_next))
{
$this->_string .= $this->_next;
$this->getNext();
}
if ($this->_next == '.')
{
$this->_string .= $this->_next;
$this->getNext();
while (ctype_digit($this->_next))
{
$this->_string .= $this->_next;
$this->getNext();
}
}
if ($this->_next == 'e' || $this->_next == 'E')
{
$this->_string .= 'e';
$this->getNext();
if ($this->_next == '+')
{
$this->_string .= '+';
$this->getNext();
}
else if ($this->_next == '-')
{
$this->_string .= '-';
$this->getNext();
}
while (ctype_digit($this->_next))
{
$this->_string .= $this->_next;
$this->getNext();
}
}
}
else if (ctype_alpha($this->_next) || $this->_next == '_')
{
$this->_token = 'identifier';
while (ctype_alnum($this->_next) || $this->_next == '_')
{
$this->_string .= $this->_next;
$this->getNext();
}
$lower = strtolower($this->_string);
if ($lower == 'false')
$this->_token = 'false';
else if ($lower == 'null')
$this->_token = 'null';
else if ($lower == 'true')
$this->_token = 'true';
}
else if ($this->_next == '*')
{
// Extension - allow embedded binary data
$this->_token = 'binary';
$this->getNext();
while (ctype_digit($this->_next))
{
$this->_string .= $this->_next;
$this->getNext();
}
if ($this->_string == '')
throw new IMuException('StreamSyntaxBinary');
$size = $this->_string + 0;
while ($this->_next != "\n")
$this->getNext();
// Save data into a temporary file
$temp = tmpfile();
if ($temp === false)
throw new IMuException('StreamTempFile', sys_get_temp_dir());
$left = $size;
while ($left > 0)
{
$read = self::$_blockSize;
if ($read > $left)
$read = $left;
$data = fread($this->_socket, $read);
if ($data === false)
throw new IMuException('StreamInput');
$done = strlen($data);
if ($done == 0)
throw new IMuException('StreamEOF', 'binary');
fwrite($temp, $data);
$left -= $done;
}
fseek($temp, 0, SEEK_SET);
$this->_file = $temp;
$this->getNext();
}
else
{
$this->_token = $this->_next;
$this->getNext();
}
}
private function
getNext()
{
$c = fgetc($this->_socket);
if ($c === false)
throw new IMuException('StreamEOF', 'character');
$this->_next = $c;
return $this->_next;
}
private function
putValue($what, $indent)
{
$type = gettype($what);
if ($type == 'NULL')
$this->putData('null');
else if ($type == 'string')
$this->putString($what);
else if ($type == 'integer')
$this->putData(sprintf('%d', $what));
else if ($type == 'double')
$this->putData(sprintf('%g', $what));
else if ($type == 'object')
$this->putObject(get_object_vars($what), $indent);
else if ($type == 'array')
{
/* A bit magical.
**
** If the array is empty treat it as an array rather than
** a JSON object. Also, if the keys of the array are exactly
** from 0 to count - 1 then put a JSON array otherwise put a
** JSON object.
*/
if (empty($what))
$this->putArray($what, $indent);
else if (array_keys($what) === range(0, count($what) - 1))
$this->putArray($what, $indent);
else
$this->putObject($what, $indent);
}
else if ($type == 'boolean')
$this->putData($what ? 'true' : 'false');
else if ($type == 'resource')
$this->putResource($what);
else
throw new IMuException('StreamType', $type);
}
private function
putString($what)
{
$this->putData('"');
$what = preg_replace('/\\\\/', '\\\\\\\\', $what);
$what = preg_replace('/"/', '\\"', $what);
$this->putData($what);
$this->putData('"');
}
private function
putObject($what, $indent)
{
$this->putData('{');
$this->putLine();
$count = count($what);
$i = 0;
foreach ($what as $name => $what)
{
$this->putIndent($indent + 1);
$this->putString($name);
$this->putData(' : ');
$this->putValue($what, $indent + 1);
if ($i < $count - 1)
$this->putData(',');
$this->putLine();
$i++;
}
$this->putIndent($indent);
$this->putData('}');
}
private function
putArray($what, $indent)
{
$this->putData('[');
$this->putLine();
$count = count($what);
$i = 0;
foreach ($what as $what)
{
$this->putIndent($indent + 1);
$this->putValue($what, $indent + 1);
if ($i < $count - 1)
$this->putData(',');
$this->putLine();
$i++;
}
$this->putIndent($indent);
$this->putData(']');
}
private function
putResource($what)
{
if (fseek($what, 0, SEEK_END) < 0)
throw new IMuException('StreamFileSeek');
$size = ftell($what);
if (fseek($what, 0, SEEK_SET) < 0)
throw new IMuException('StreamFileSeek');
$this->putData('*');
$this->putData($size);
$this->putLine();
$left = $size;
while ($left > 0)
{
$need = self::$_blockSize;
if ($need > $left)
$need = $left;
$data = fread($what, $need);
if ($data === false)
throw new IMuException('StreamFileRead');
$done = strlen($data);
if ($done == 0)
break;
$this->putData($data);
$left -= $done;
}
if ($left > 0)
{
/* The file did not contain enough bytes
** so the output is padded with nulls
*/
while ($left > 0)
{
$need = self::$blockSize;
if ($need > $left)
$need = $left;
$data = str_repeat(chr(0), $need);
$this->putData($data);
$left -= $need;
}
}
}
private function
putIndent($indent)
{
$string = '';
for ($i = 0; $i < $indent; $i++)
$string .= "\t";
$this->putData($string);
}
private function
putLine()
{
$this->putData("\r\n");
}
private function
putData($data)
{
$this->_buffer .= $data;
$this->_length += strlen($data);
if ($this->_length >= self::$_blockSize)
$this->putFlush();
}
private function
putFlush()
{
if ($this->_length > 0)
{
while ($this->_length > 0)
{
$wrote = fwrite($this->_socket, $this->_buffer);
if ($wrote === false)
throw new IMuException('StreamWriteError');
if ($wrote == 0)
throw new IMuException('StreamWriteError');
$this->_buffer = substr($this->_buffer, $wrote);
$this->_length -= $wrote;
}
fflush($this->_socket);
$this->_buffer = '';
$this->_length = 0;
}
}
}
?>

159
plugins/emu/lib/imu_api/Terms.php Executable file
View File

@@ -0,0 +1,159 @@
<?php
/* KE Software Open Source Licence
**
** Notice: Copyright (c) 2011-2013 KE SOFTWARE PTY LTD (ACN 006 213 298)
** (the "Owner"). All rights reserved.
**
** Licence: Permission is hereby granted, free of charge, to any person
** obtaining a copy of this software and associated documentation files
** (the "Software"), to deal with the Software without restriction,
** including without limitation the rights to use, copy, modify, merge,
** publish, distribute, sublicense, and/or sell copies of the Software,
** and to permit persons to whom the Software is furnished to do so,
** subject to the following conditions.
**
** Conditions: The Software is licensed on condition that:
**
** (1) Redistributions of source code must retain the above Notice,
** these Conditions and the following Limitations.
**
** (2) Redistributions in binary form must reproduce the above Notice,
** these Conditions and the following Limitations in the
** documentation and/or other materials provided with the distribution.
**
** (3) Neither the names of the Owner, nor the names of its contributors
** may be used to endorse or promote products derived from this
** Software without specific prior written permission.
**
** Limitations: Any person exercising any of the permissions in the
** relevant licence will be taken to have accepted the following as
** legally binding terms severally with the Owner and any other
** copyright owners (collectively "Participants"):
**
** TO THE EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS",
** WITHOUT ANY REPRESENTATION, WARRANTY OR CONDITION OF ANY KIND, EXPRESS
** OR IMPLIED, INCLUDING (WITHOUT LIMITATION) AS TO MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. TO THE EXTENT
** PERMITTED BY LAW, IN NO EVENT SHALL ANY PARTICIPANT BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
**
** WHERE BY LAW A LIABILITY (ON ANY BASIS) OF ANY PARTICIPANT IN RELATION
** TO THE SOFTWARE CANNOT BE EXCLUDED, THEN TO THE EXTENT PERMITTED BY
** LAW THAT LIABILITY IS LIMITED AT THE OPTION OF THE PARTICIPANT TO THE
** REPLACEMENT, REPAIR OR RESUPPLY OF THE RELEVANT GOODS OR SERVICES
** (INCLUDING BUT NOT LIMITED TO SOFTWARE) OR THE PAYMENT OF THE COST OF SAME.
*/
class IMuTerms
{
public function
__construct($kind = 'and')
{
$kind = strtolower($kind);
if ($kind != 'and' && $kind != 'or')
{
throw new Exception("Illegal kind: $kind");
}
$this->kind = $kind;
$this->list = array();
}
public function
getKind()
{
return($this->kind);
}
public function
getList()
{
return($this->list);
}
public function
add($name, $value, $op = null)
{
$term = array($name, $value, $op);
$this->list[] = $term;
}
public function
addTerms($kind)
{
$child = new IMuTerms($kind);
$this->list[] = $child;
return($child);
}
public function
addAnd()
{
return($this->addTerms('and'));
}
public function
addOr()
{
return($this->addTerms('or'));
}
public function
toArray()
{
$result = array();
$result[0] = $this->kind;
$list = array();
for ($i = 0; $i < count($this->list); $i++)
{
$term = $this->list[$i];
if ($term instanceof IMuTerms)
{
$term = $term->toArray();
}
$list[$i] = $term;
}
$result[1] = $list;
return($result);
}
public function
__toString()
{
$result = '[';
$result .= $this->kind;
$result .= ', [';
for ($i = 0; $i < count($this->list); $i++)
{
if ($i > 0)
{
$result .= ', ';
}
$term = $this->list[$i];
if ($term instanceof IMuTerms)
{
$term = $term->__toString();
}
else
{
$term = '[' . implode(', ', $term) . ']';
}
$result .= $term;
}
$result .= ']]';
return($result);
}
public function
toString()
{
return($this->__toString());
}
private $kind = null;
private $list = null;
}
?>

260
plugins/emu/lib/imu_api/Trace.php Executable file
View File

@@ -0,0 +1,260 @@
<?php
/* KE Software Open Source Licence
**
** Notice: Copyright (c) 2011-2013 KE SOFTWARE PTY LTD (ACN 006 213 298)
** (the "Owner"). All rights reserved.
**
** Licence: Permission is hereby granted, free of charge, to any person
** obtaining a copy of this software and associated documentation files
** (the "Software"), to deal with the Software without restriction,
** including without limitation the rights to use, copy, modify, merge,
** publish, distribute, sublicense, and/or sell copies of the Software,
** and to permit persons to whom the Software is furnished to do so,
** subject to the following conditions.
**
** Conditions: The Software is licensed on condition that:
**
** (1) Redistributions of source code must retain the above Notice,
** these Conditions and the following Limitations.
**
** (2) Redistributions in binary form must reproduce the above Notice,
** these Conditions and the following Limitations in the
** documentation and/or other materials provided with the distribution.
**
** (3) Neither the names of the Owner, nor the names of its contributors
** may be used to endorse or promote products derived from this
** Software without specific prior written permission.
**
** Limitations: Any person exercising any of the permissions in the
** relevant licence will be taken to have accepted the following as
** legally binding terms severally with the Owner and any other
** copyright owners (collectively "Participants"):
**
** TO THE EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS",
** WITHOUT ANY REPRESENTATION, WARRANTY OR CONDITION OF ANY KIND, EXPRESS
** OR IMPLIED, INCLUDING (WITHOUT LIMITATION) AS TO MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. TO THE EXTENT
** PERMITTED BY LAW, IN NO EVENT SHALL ANY PARTICIPANT BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
**
** WHERE BY LAW A LIABILITY (ON ANY BASIS) OF ANY PARTICIPANT IN RELATION
** TO THE SOFTWARE CANNOT BE EXCLUDED, THEN TO THE EXTENT PERMITTED BY
** LAW THAT LIABILITY IS LIMITED AT THE OPTION OF THE PARTICIPANT TO THE
** REPLACEMENT, REPAIR OR RESUPPLY OF THE RELEVANT GOODS OR SERVICES
** (INCLUDING BUT NOT LIMITED TO SOFTWARE) OR THE PAYMENT OF THE COST OF SAME.
*/
class IMuTrace
{
/* Initializer */
public static function
init()
{
self::$_cli = php_sapi_name() === 'cli';
if (self::$_cli)
{
self::$_file = 'STDOUT';
self::$_handle = STDOUT;
}
else
{
self::$_file = '';
self::$_handle = null;
}
self::$_level = 1;
self::$_prefix = '%D %T: ';
}
/* Static Properties */
public static function
getFile()
{
return self::$_file;
}
public static function
setFile($file = null)
{
self::$_file = $file;
if (self::$_handle !== null && ! self::isSTDOUT())
fclose(self::$_handle);
if (self::$_file === null || self::$_file == '')
{
self::$_file = '';
self::$_handle = null;
}
else if (self::$_file == 'STDOUT')
{
if (self::$_cli)
self::$_handle = STDOUT;
else
{
self::$_file = '';
self::$_handle = null;
}
}
else
{
self::$_handle = @fopen(self::$_file, 'a');
if (self::$_handle === false)
{
self::$_file = '';
self::$_handle = null;
}
}
}
public static function
getLevel()
{
return self::$_level;
}
public static function
setLevel($level)
{
self::$_level = $level;
}
public static function
getPrefix()
{
return self::$_prefix;
}
public static function
setPrefix($prefix)
{
self::$_prefix = $prefix;
}
public static function
write($level, $format)
{
$args = func_get_args();
array_shift($args);
array_shift($args);
self::writeArgs($level, $format, $args);
}
public static function
writeArgs($level, $format, $args)
{
if (self::$_handle === null)
return;
if ($level > self::$_level)
return;
/* time */
$y = date('Y');
$m = date('m');
$d = date('d');
$D = "$y-$m-$d";
$H = date('H');
$M = date('i');
$S = date('s');
$T = "$H:$M:$S";
/* process id */
$p = getmypid();
/* function information */
$F = '(unknown)';
$L = '(unknown)';
$f = '(none)';
$g = '(none)';
$trace = debug_backtrace();
$count = count($trace);
for ($i = 0; $i < $count; $i++)
{
$frame = $trace[$i];
if ($frame['file'] != __FILE__)
{
$F = $frame['file'];
$L = $frame['line'];
if ($i < $count - 1)
{
$frame = $trace[$i + 1];
if (array_key_exists('class', $frame))
$f = $frame['class'] . '::' . $frame['function'];
else
$f = $frame['function'];
$g = preg_replace('/^IMu/', '', $f);
}
break;
}
}
/* Build the prefix */
$prefix = self::$_prefix;
$prefix = preg_replace('/%y/', $y, $prefix);
$prefix = preg_replace('/%m/', $m, $prefix);
$prefix = preg_replace('/%d/', $d, $prefix);
$prefix = preg_replace('/%D/', $D, $prefix);
$prefix = preg_replace('/%H/', $H, $prefix);
$prefix = preg_replace('/%M/', $M, $prefix);
$prefix = preg_replace('/%S/', $S, $prefix);
$prefix = preg_replace('/%T/', $T, $prefix);
$prefix = preg_replace('/%p/', $p, $prefix);
$prefix = preg_replace('/%F/', $F, $prefix);
$prefix = preg_replace('/%L/', $L, $prefix);
$prefix = preg_replace('/%f/', $f, $prefix);
$prefix = preg_replace('/%g/', $g, $prefix);
/* Build the string */
$strs = array();
foreach ($args as $arg)
$strs[] = print_r($arg, true);
$format = "$format";
if (count($args) > 0)
$format = vsprintf($format, $strs);
$text = $prefix . $format;
$text = preg_replace('/\r?\n/', PHP_EOL, $text);
$text = preg_replace('/\s+$/', '', $text);
$text .= PHP_EOL;
/* Write it out */
if (! self::isSTDOUT())
{
/* Lock */
if (! flock(self::$_handle, LOCK_EX))
return;
/* Append */
if (fseek(self::$_handle, 0, SEEK_END) != 0)
{
flock(self::$_handle, LOCK_UN);
return;
}
}
fwrite(self::$_handle, $text);
fflush(self::$_handle);
if (! self::isSTDOUT())
flock(self::$_handle, LOCK_UN);
}
private static $_cli;
private static $_file;
private static $_handle;
private static $_level;
private static $_prefix;
private static function
isSTDOUT()
{
if (! self::$_cli)
return false;
return self::$_handle == STDOUT;
}
}
IMuTrace::init();
?>

View File

@@ -0,0 +1,294 @@
<?php
/* KE Software Open Source Licence
**
** Notice: Copyright (c) 2011-2013 KE SOFTWARE PTY LTD (ACN 006 213 298)
** (the "Owner"). All rights reserved.
**
** Licence: Permission is hereby granted, free of charge, to any person
** obtaining a copy of this software and associated documentation files
** (the "Software"), to deal with the Software without restriction,
** including without limitation the rights to use, copy, modify, merge,
** publish, distribute, sublicense, and/or sell copies of the Software,
** and to permit persons to whom the Software is furnished to do so,
** subject to the following conditions.
**
** Conditions: The Software is licensed on condition that:
**
** (1) Redistributions of source code must retain the above Notice,
** these Conditions and the following Limitations.
**
** (2) Redistributions in binary form must reproduce the above Notice,
** these Conditions and the following Limitations in the
** documentation and/or other materials provided with the distribution.
**
** (3) Neither the names of the Owner, nor the names of its contributors
** may be used to endorse or promote products derived from this
** Software without specific prior written permission.
**
** Limitations: Any person exercising any of the permissions in the
** relevant licence will be taken to have accepted the following as
** legally binding terms severally with the Owner and any other
** copyright owners (collectively "Participants"):
**
** TO THE EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS",
** WITHOUT ANY REPRESENTATION, WARRANTY OR CONDITION OF ANY KIND, EXPRESS
** OR IMPLIED, INCLUDING (WITHOUT LIMITATION) AS TO MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. TO THE EXTENT
** PERMITTED BY LAW, IN NO EVENT SHALL ANY PARTICIPANT BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
**
** WHERE BY LAW A LIABILITY (ON ANY BASIS) OF ANY PARTICIPANT IN RELATION
** TO THE SOFTWARE CANNOT BE EXCLUDED, THEN TO THE EXTENT PERMITTED BY
** LAW THAT LIABILITY IS LIMITED AT THE OPTION OF THE PARTICIPANT TO THE
** REPLACEMENT, REPAIR OR RESUPPLY OF THE RELEVANT GOODS OR SERVICES
** (INCLUDING BUT NOT LIMITED TO SOFTWARE) OR THE PAYMENT OF THE COST OF SAME.
*/
require_once __DIR__ . '/../IMu.php';
class IMuWebPlatform
{
public function
__construct()
{
/* Determine client platform
**
** We could use PHP's get_browser() but this requires installing
** a browscap.ini file and editing php.ini to point to it.
** Unfortunately this cannot be done with ini_set().
**
** Because our requirements are pretty rudimentary we roll our
** own.
*/
$this->agent = $_SERVER['HTTP_USER_AGENT'];
$this->profile = '';
if (isset($_SERVER['HTTP_X_WAP_PROFILE']))
$this->profile = $_SERVER['HTTP_X_WAP_PROFILE'];
$a = strtolower($this->agent);
$p = strtolower($this->profile);
$this->device = new stdClass;
$this->device->name = 'unknown';
$this->device->type = 'unknown';
$this->device->is = new stdClass;
$this->device->is->android = false;
$this->device->is->desktop = false;
$this->device->is->ipad = false;
$this->device->is->iphone = false;
$this->device->is->linux = false;
$this->device->is->mac = false;
$this->device->is->mobile = false;
$this->device->is->pc = false;
$this->device->is->phone = false;
$this->device->is->tablet = false;
$this->os = new stdClass;
$this->os->name = 'unknown';
$this->os->version = 'unknown';
$this->os->is = new stdClass;
$this->os->is->android = false;
$this->os->is->ios = false;
$this->os->is->mac = false;
$this->os->is->other = true;
$this->os->is->unix = false;
$this->os->is->windows = false;
$this->browser = new stdClass;
$this->browser->name = 'unknown';
$this->browser->version = 'unknown';
$this->browser->is = new stdClass;
$this->browser->is->android = false;
$this->browser->is->chrome = false;
$this->browser->is->firefox = false;
$this->browser->is->ie = false;
$this->browser->is->konqueror = false;
$this->browser->is->opera = false;
$this->browser->is->safari = false;
/* device & os
*/
if (preg_match('/windows nt (\d+\.\d+)/', $a, $m))
{
$this->device->name = 'desktop';
$this->device->is->pc = true;
$this->device->type = 'desktop';
$this->device->is->desktop = true;
$this->os->name = 'windows';
if ($m[1] == '6.1')
$this->os->version = '7';
else if ($m[1] == '6.0')
$this->os->version = 'vista';
else if ($m[1] == '5.2')
$this->os->version = 'server-2003';
else if ($m[1] == '5.1')
$this->os->version = 'xp';
$this->os->is->windows = true;
}
else if (preg_match('/\(ipad;.*\bos (\d+(_\d+)*)/', $a, $m))
{
$this->device->name = 'ipad';
$this->device->is->ipad = true;
$this->device->type = 'tablet';
$this->device->is->mobile = true;
$this->device->is->tablet = true;
$this->os->name = 'ios';
$this->os->version = $m[1];
$this->os->is->ios = true;
}
else if (preg_match('/\(iphone;.*\bos (\d+(_\d+)*)/', $a, $m))
{
$this->device->name = 'iphone';
$this->device->is->iphone = true;
$this->device->type = 'phone';
$this->device_mobile = true;
$this->device_phone = true;
$this->os->name = 'ios';
$this->os->version = $m[1];
$this->os->is->ios = true;
}
else if (preg_match('/\bandroid(\s+(\d+(\.\d+)*))?/', $a, $m))
{
$this->device->name = 'android';
$this->device->is->android = true;
$this->device->type = 'mobile';
$this->device->is->mobile = true;
$this->os->name = 'android';
if (isset($m[2]))
$this->os->version = $m[2];
$this->os->is->android = true;
/* It's very hard to separate android phones from tablets
**
** There is scope to use User Agent Profiles (passed in
** HTTP_X_WAP_PROFILE) but we don't need it (yet).
**
** We know about a few so we hard-code checks for them here.
*/
// HTC
if (preg_match('/\bhtc\b/', $a))
{
$this->device->name = 'htc-phone';
$this->device->type = 'phone';
$this->device->is->phone = true;
}
// Samsung
else if (preg_match('/\bgt-i9300\b/', $a))
{
$this->device->name = 'samsung-phone';
$this->device->type = 'phone';
$this->device->is->phone = true;
}
else if (preg_match('/\bgt-p7500\b/', $a))
{
$this->device->name = 'samsung-tablet';
$this->device->type = 'tablet';
$this->device->is->tablet = true;
}
}
else if (preg_match('/\(macintosh;.*\bos [a-z]* (\d+(_\d+)*)/', $a, $m))
{
$this->device->name = 'desktop';
$this->device->is->mac = true;
$this->device->type = 'desktop';
$this->device->is->desktop = true;
$this->os->name = 'mac';
$this->os->version = $m[1];
$this->os->is->mac = true;
}
else if (preg_match('/\blinux\b/', $a, $m))
{
$this->device->name = 'linux';
$this->device->is->linux = true;
$this->device->type = 'desktop';
$this->device->is->desktop = true;
$this->os->name = 'unix';
$this->os->is->unix = true;
}
/* browser
*/
if (preg_match('/msie[\/ ](\\d+(\\.\\d+)*)/', $a, $m))
{
$this->browser->name = 'ie';
$this->browser->version = $m[1];
$this->browser->is->ie = true;
}
else if (preg_match('/(chrome|crios)[\/ ](\\d+(\\.\\d+)*)/', $a, $m))
{
$this->browser->name = 'chrome';
$this->browser->version = $m[2];
$this->browser->is->chrome = true;
}
else if (preg_match('/firefox[\/ ](\\d+(\\.\\d+)*)/', $a, $m))
{
$this->browser->name = 'firefox';
$this->browser->version = $m[1];
$this->browser->is->firefox = true;
}
else if (preg_match('/opera[\/ ](\\d+(\\.\\d+)*)/', $a, $m))
{
$this->browser->name = 'opera';
$this->browser->version = $m[1];
$this->browser->is->opera = true;
}
else if (preg_match('/konqueror[\/ ](\\d+(\\.\\d+)*)/', $a, $m))
{
$this->browser->name = 'konqueror';
$this->browser->version = $m[1];
$this->browser->is->konqueror = true;
}
else if (preg_match('/android[\/ ](\\d+(\\.\\d+)*)/', $a, $m))
{
$this->browser->name = 'android';
$this->browser->version = $m[1];
$this->browser->is->android = true;
}
else if (preg_match('/safari[\/ ](\\d+(\\.\\d+)*)/', $a, $m))
{
$this->browser->name = 'safari';
$this->browser->version = $m[1];
$this->browser->is->safari = true;
}
/* attributes
*/
$this->attributes = array();
foreach (get_object_vars($this->device->is) as $name => $value)
if ($value)
$this->attributes[$name] = true;
foreach (get_object_vars($this->os->is) as $name => $value)
if ($value)
$this->attributes[$name] = true;
foreach (get_object_vars($this->browser->is) as $name => $value)
if ($value)
$this->attributes[$name] = true;
}
public $agent;
public $profile;
public $device;
public $os;
public $browser;
public $attributes;
}
?>

View File

@@ -0,0 +1,316 @@
<?php
/* KE Software Open Source Licence
**
** Notice: Copyright (c) 2011-2013 KE SOFTWARE PTY LTD (ACN 006 213 298)
** (the "Owner"). All rights reserved.
**
** Licence: Permission is hereby granted, free of charge, to any person
** obtaining a copy of this software and associated documentation files
** (the "Software"), to deal with the Software without restriction,
** including without limitation the rights to use, copy, modify, merge,
** publish, distribute, sublicense, and/or sell copies of the Software,
** and to permit persons to whom the Software is furnished to do so,
** subject to the following conditions.
**
** Conditions: The Software is licensed on condition that:
**
** (1) Redistributions of source code must retain the above Notice,
** these Conditions and the following Limitations.
**
** (2) Redistributions in binary form must reproduce the above Notice,
** these Conditions and the following Limitations in the
** documentation and/or other materials provided with the distribution.
**
** (3) Neither the names of the Owner, nor the names of its contributors
** may be used to endorse or promote products derived from this
** Software without specific prior written permission.
**
** Limitations: Any person exercising any of the permissions in the
** relevant licence will be taken to have accepted the following as
** legally binding terms severally with the Owner and any other
** copyright owners (collectively "Participants"):
**
** TO THE EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS",
** WITHOUT ANY REPRESENTATION, WARRANTY OR CONDITION OF ANY KIND, EXPRESS
** OR IMPLIED, INCLUDING (WITHOUT LIMITATION) AS TO MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. TO THE EXTENT
** PERMITTED BY LAW, IN NO EVENT SHALL ANY PARTICIPANT BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
**
** WHERE BY LAW A LIABILITY (ON ANY BASIS) OF ANY PARTICIPANT IN RELATION
** TO THE SOFTWARE CANNOT BE EXCLUDED, THEN TO THE EXTENT PERMITTED BY
** LAW THAT LIABILITY IS LIMITED AT THE OPTION OF THE PARTICIPANT TO THE
** REPLACEMENT, REPAIR OR RESUPPLY OF THE RELEVANT GOODS OR SERVICES
** (INCLUDING BUT NOT LIMITED TO SOFTWARE) OR THE PAYMENT OF THE COST OF SAME.
*/
require_once __DIR__ . '/../IMu.php';
require_once IMu::$lib . '/Exception.php';
require_once IMu::$lib . '/Handler.php';
require_once IMu::$lib . '/Session.php';
require_once IMu::$lib . '/Trace.php';
/**
* @brief A helper class for implementing %IMu web services.
* @code{.php}
* require_once IMu::$lib . '/Web/Service.php';
* @endcode
* @copyright 2011-2012 KE SOFTWARE PTY LTD
* @version 2.0
*/
class IMuWebService
{
/**
* @details The base web service directory. Supplied in the constructor.
* @var string $dir
* @see __construct()
*/
public $dir;
/**
* @details The full request URL. Generated at construction.
* @var string $url
* @see __construct()
*/
public $url;
/**
* @details The configuration options. Loaded from files at construction.
* @var array $config
* @see __construct()
* @see loadConfig()
*/
public $config;
/**
* @details The HTTP GET & POST parameters. Generated at construction.
* @var array $params
* @see __construct()
*/
public $params;
/**
* @details Determines the full request URL, loads all GET & POST parameters
* to a common variable and loads config files relative to #$dir param.
*
* @param string $dir
* The base web service directory.
* @see loadConfig()
*/
public function
__construct($dir)
{
$this->dir = $dir;
$this->url = strtolower(preg_replace('/\/.*$/', '', $_SERVER['SERVER_PROTOCOL']));
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
$this->url .= 's';
$this->url .= '://' . $_SERVER['SERVER_NAME'];
if ($_SERVER['SERVER_PORT'] != 80)
$this->url .= ':' . $_SERVER['SERVER_PORT'];
$this->url .= $_SERVER['REQUEST_URI'];
$this->params = array();
global $_GET;
foreach ($_GET as $name => $value)
$this->params[$name] = $value;
global $_POST;
foreach ($_POST as $name => $value)
$this->params[$name] = $value;
/* Configure */
$config = array();
/* ... defaults */
$config['host'] = IMuSession::getDefaultHost();
$config['port'] = IMuSession::getDefaultPort();
/* ... service-specific */
$this->loadConfig($config);
$this->config = $config;
if (array_key_exists('trace-file', $this->config))
IMuTrace::setFile($this->config['trace-file']);
if (array_key_exists('trace-level', $this->config))
IMuTrace::setLevel($this->config['trace-level']);
}
/**
* @details Remove and return the value for the HTTP parameter specified by
* $name from #$params or just return $default if the parameter does not
* exists.
*
* @param string $name
* The name of the parameter to remove and return.
* @param string $default
* The value to return if no value exists for $name.
*
* @retval mixed
* The value of the parameter specified by $name or $default.
*/
public function
extractParam($name, $default = false)
{
if (! array_key_exists($name, $this->params))
return $default;
$value = $this->params[$name];
unset($this->params[$name]);
return $value;
}
/**
* @details Return the value for the HTTP parameter specified by $name from
* #$params or just return $default if the parameter does not exists.
*
* @param string $name
* The name of the parameter to return.
* @param string $default
* The value to return if no value exists for $name.
*
* @retval mixed
* The value of the parameter specified by $name or $default.
*/
public function
getParam($name, $default = false)
{
if (! array_key_exists($name, $this->params))
return $default;
return $this->params[$name];
}
/**
* @details Check for the presence of the HTTP parameter specified by $name
* in #$params.
*
* @param string $name
* The name of the parameter to check.
*
* @retval boolean
* True if $name exists, false otherwise.
*/
public function
hasParam($name)
{
return array_key_exists($name, $this->params);
}
/**
* @details Set the HTTP parameter specified by $name in #$params.
*
* @param string $name
* The name of the parameter to set.
* @param string $value
* The value to set the parameter specified by $name.
*/
public function
setParam($name, $value)
{
$this->params[$name] = $value;
}
/**
* @details An empty method definition. The convention is to overridden this
* method in a subclass and call it to process web service requests.
*
* @internal
* @note This should probably be abstract or removed. I don't see any
* value in this function. It could literally just be a convention to use
* process() as the entry point to web service request processing.
*/
public function
process()
{
/* Do nothing by default */
}
/**
* @details An IMuSession object. Only accessible after the connect()
* method has been called.
* @var IMuSession $session
* @see connect()
*/
protected $session;
/**
* @details Construct an IMuSession object and invoke its @link
* IMuSession#connect() connect()@endlink method using the `host` and
* `port` parameters of the #$config variable.
*
* @see $session
*/
protected function
connect()
{
$this->session = new IMuSession;
$this->session->host = $this->config['host'];
$this->session->port = $this->config['port'];
$this->session->connect();
}
/**
* @details Disconnect from the IMuSession.
*
* @see $session
*/
protected function
disconnect()
{
$this->session->disconnect();
}
/**
* @details Load configuration options from the files:
* - /ws/common/config.php
* - /ws/client/config.php
* - /ws/local/config.php
*
* relative to #$dir.
*
* @param array &$config
* @see __construct()
*/
protected function
loadConfig(&$config)
{
@include $this->dir . '/ws/common/config.php';
@include $this->dir . '/ws/client/config.php';
@include $this->dir . '/ws/local/config.php';
}
}
/**
* @details Write an error to the trace file and throw an IMuException.
* @note Optionally, any number of additional parameters can be supplied when
* calling this function. Usually these are messages or values that provide
* more information about the error that is being raised.
*
* Usage examples:
* @code{.php}
* raise(400, 'UpdateNoFiles');
* raise(500, 'MultimediaTempFileOpen', $tempName);
* @endcode
*
* @param int $code
* Usually the HTTP error code that should be used in the HTTP response.
* @param string $id
* A string that identifies the exception.
*
* @throws IMuException
*/
function
raise($code, $id)
{
$exception = new IMuException($id);
$args = func_get_args();
array_shift($args);
array_shift($args);
$exception->setArgs($args);
$exception->setCode($code);
IMuTrace::write(2, 'raising exception %s', $exception);
throw $exception;
}
?>

185
plugins/emu/lib/imu_api/XML.php Executable file
View File

@@ -0,0 +1,185 @@
<?php
/* KE Software Open Source Licence
**
** Notice: Copyright (c) 2011-2013 KE SOFTWARE PTY LTD (ACN 006 213 298)
** (the "Owner"). All rights reserved.
**
** Licence: Permission is hereby granted, free of charge, to any person
** obtaining a copy of this software and associated documentation files
** (the "Software"), to deal with the Software without restriction,
** including without limitation the rights to use, copy, modify, merge,
** publish, distribute, sublicense, and/or sell copies of the Software,
** and to permit persons to whom the Software is furnished to do so,
** subject to the following conditions.
**
** Conditions: The Software is licensed on condition that:
**
** (1) Redistributions of source code must retain the above Notice,
** these Conditions and the following Limitations.
**
** (2) Redistributions in binary form must reproduce the above Notice,
** these Conditions and the following Limitations in the
** documentation and/or other materials provided with the distribution.
**
** (3) Neither the names of the Owner, nor the names of its contributors
** may be used to endorse or promote products derived from this
** Software without specific prior written permission.
**
** Limitations: Any person exercising any of the permissions in the
** relevant licence will be taken to have accepted the following as
** legally binding terms severally with the Owner and any other
** copyright owners (collectively "Participants"):
**
** TO THE EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS",
** WITHOUT ANY REPRESENTATION, WARRANTY OR CONDITION OF ANY KIND, EXPRESS
** OR IMPLIED, INCLUDING (WITHOUT LIMITATION) AS TO MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. TO THE EXTENT
** PERMITTED BY LAW, IN NO EVENT SHALL ANY PARTICIPANT BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
**
** WHERE BY LAW A LIABILITY (ON ANY BASIS) OF ANY PARTICIPANT IN RELATION
** TO THE SOFTWARE CANNOT BE EXCLUDED, THEN TO THE EXTENT PERMITTED BY
** LAW THAT LIABILITY IS LIMITED AT THE OPTION OF THE PARTICIPANT TO THE
** REPLACEMENT, REPAIR OR RESUPPLY OF THE RELEVANT GOODS OR SERVICES
** (INCLUDING BUT NOT LIMITED TO SOFTWARE) OR THE PAYMENT OF THE COST OF SAME.
*/
require_once __DIR__ . '/IMu.php';
require_once IMu::$api . '/Document.php';
class IMuXMLDocument extends IMuDocument
{
public function
__construct($name = null, $public = null, $system = null)
{
parent::__construct($name, $public, $system);
$this->_dom->formatOutput = true;
$this->_options = array();
}
public function
element($name, $value = '')
{
$elem = parent::element($name);
$elem->push();
if (is_array($value))
{
if (array_keys($value) === range(0, count($value) - 1))
$this->writeList($name, $value);
else
$this->writeHash($name, $value);
}
else if (is_object($value))
$this->writeObject($name, $value);
else
$this->writeText($name, $value);
$elem->pop();
return $elem;
}
public function
getTagOption($tag, $name, $default = false)
{
if (! array_key_exists($tag, $this->_options))
return $default;
if (! array_key_exists($name, $this->_options[$tag]))
return $default;
return $this->_options[$tag][$name];
}
public function
hasTagOption($tag, $name)
{
if (! array_key_exists($tag, $this->_options))
return false;
return array_key_exists($name, $this->_options[$tag]);
}
public function
setTagOption($tag, $name, $value)
{
if (! array_key_exists($tag, $this->_options))
$this->_options[$tag] = array();
$this->_options[$tag][$name] = $value;
}
protected $_options;
protected function
writeList($tag, $list)
{
/* This is an ugly hack */
if ($this->hasTagOption($tag, 'child'))
$child = $this->getTagOption($tag, 'child');
else if (preg_match('/(.*)s$/', $tag, $match))
$child = $match[1];
else if (preg_match('/(.*)_tab$/', $tag, $match))
$child = $match[1];
else if (preg_match('/(.*)0$/', $tag, $match))
$child = $match[1];
else if (preg_match('/(.*)_nesttab$/', $tag, $match))
$child = $match[1] . '_tab';
else
$child = 'item';
foreach ($list as $item)
$this->element($child, $item);
}
protected function
writeHash($tag, $hash)
{
foreach ($hash as $name => $value)
$this->element($name, $value);
}
protected function
writeObject($tag, $object)
{
foreach (get_object_vars($object) as $name => $value)
$this->element($name, $value);
}
protected function
writeText($tag, $text)
{
if ($text !== '')
{
$type = gettype($text);
if ($type == 'boolean')
$text = $text ? 'true' : 'false';
/* Check if special processing is required
*/
if ($this->getTagOption($tag, 'html', false))
$this->writeHTML($text);
else if ($this->getTagOption($tag, 'xml', false))
$this->writeXML($text);
/* Deprecated: use 'xml' option instead */
else if ($this->getTagOption($tag, 'raw', false))
$this->writeXML($text);
else
$this->top()->text($text);
}
}
protected function
writeHTML($text)
{
/* Transform entities as these break the XML processing
*/
$text = preg_replace('/&nbsp;/', '&#160;', $text);
// TODO other transformations
return $this->writeXML($text);
}
protected function
writeXML($text)
{
$this->top()->fragment($text);
}
}
?>

View File

@@ -0,0 +1,45 @@
KE Software Open Source Licence
Notice: Copyright (c) 2011-2013 KE SOFTWARE PTY LTD (ACN 006 213 298)
(the "Owner"). All rights reserved.
Licence: Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation files
(the "Software"), to deal with the Software without restriction,
including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so,
subject to the following conditions.
Conditions: The Software is licensed on condition that:
(1) Redistributions of source code must retain the above Notice,
these Conditions and the following Limitations.
(2) Redistributions in binary form must reproduce the above Notice,
these Conditions and the following Limitations in the
documentation and/or other materials provided with the distribution.
(3) Neither the names of the Owner, nor the names of its contributors
may be used to endorse or promote products derived from this
Software without specific prior written permission.
Limitations: Any person exercising any of the permissions in the
relevant licence will be taken to have accepted the following as
legally binding terms severally with the Owner and any other
copyright owners (collectively "Participants"):
TO THE EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS",
WITHOUT ANY REPRESENTATION, WARRANTY OR CONDITION OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING (WITHOUT LIMITATION) AS TO MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. TO THE EXTENT
PERMITTED BY LAW, IN NO EVENT SHALL ANY PARTICIPANT BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
WHERE BY LAW A LIABILITY (ON ANY BASIS) OF ANY PARTICIPANT IN RELATION
TO THE SOFTWARE CANNOT BE EXCLUDED, THEN TO THE EXTENT PERMITTED BY
LAW THAT LIABILITY IS LIMITED AT THE OPTION OF THE PARTICIPANT TO THE
REPLACEMENT, REPAIR OR RESUPPLY OF THE RELEVANT GOODS OR SERVICES
(INCLUDING BUT NOT LIMITED TO SOFTWARE) OR THE PAYMENT OF THE COST OF SAME.