First commit, current version 0.2
This commit is contained in:
commit
872acdbc01
353 changed files with 45771 additions and 0 deletions
806
onyx2/include/JSON.php
Normal file
806
onyx2/include/JSON.php
Normal file
|
|
@ -0,0 +1,806 @@
|
|||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Converts to and from JSON format.
|
||||
*
|
||||
* JSON (JavaScript Object Notation) is a lightweight data-interchange
|
||||
* format. It is easy for humans to read and write. It is easy for machines
|
||||
* to parse and generate. It is based on a subset of the JavaScript
|
||||
* Programming Language, Standard ECMA-262 3rd Edition - December 1999.
|
||||
* This feature can also be found in Python. JSON is a text format that is
|
||||
* completely language independent but uses conventions that are familiar
|
||||
* to programmers of the C-family of languages, including C, C++, C#, Java,
|
||||
* JavaScript, Perl, TCL, and many others. These properties make JSON an
|
||||
* ideal data-interchange language.
|
||||
*
|
||||
* This package provides a simple encoder and decoder for JSON notation. It
|
||||
* is intended for use with client-side Javascript applications that make
|
||||
* use of HTTPRequest to perform server communication functions - data can
|
||||
* be encoded into JSON notation for use in a client-side javascript, or
|
||||
* decoded from incoming Javascript requests. JSON format is native to
|
||||
* Javascript, and can be directly eval()'ed with no further parsing
|
||||
* overhead
|
||||
*
|
||||
* All strings should be in ASCII or UTF-8 format!
|
||||
*
|
||||
* LICENSE: Redistribution and use in source and binary forms, with or
|
||||
* without modification, are permitted provided that the following
|
||||
* conditions are met: Redistributions of source code must retain the
|
||||
* above copyright notice, this list of conditions and the following
|
||||
* disclaimer. Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
||||
* NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
||||
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
||||
* DAMAGE.
|
||||
*
|
||||
* @category
|
||||
* @package Services_JSON
|
||||
* @author Michal Migurski <mike-json@teczno.com>
|
||||
* @author Matt Knapp <mdknapp[at]gmail[dot]com>
|
||||
* @author Brett Stimmerman <brettstimmerman[at]gmail[dot]com>
|
||||
* @copyright 2005 Michal Migurski
|
||||
* @version CVS: $Id: JSON.php,v 1.31 2006/06/28 05:54:17 migurski Exp $
|
||||
* @license http://www.opensource.org/licenses/bsd-license.php
|
||||
* @link http://pear.php.net/pepr/pepr-proposal-show.php?id=198
|
||||
*/
|
||||
|
||||
/**
|
||||
* Marker constant for Services_JSON::decode(), used to flag stack state
|
||||
*/
|
||||
define('SERVICES_JSON_SLICE', 1);
|
||||
|
||||
/**
|
||||
* Marker constant for Services_JSON::decode(), used to flag stack state
|
||||
*/
|
||||
define('SERVICES_JSON_IN_STR', 2);
|
||||
|
||||
/**
|
||||
* Marker constant for Services_JSON::decode(), used to flag stack state
|
||||
*/
|
||||
define('SERVICES_JSON_IN_ARR', 3);
|
||||
|
||||
/**
|
||||
* Marker constant for Services_JSON::decode(), used to flag stack state
|
||||
*/
|
||||
define('SERVICES_JSON_IN_OBJ', 4);
|
||||
|
||||
/**
|
||||
* Marker constant for Services_JSON::decode(), used to flag stack state
|
||||
*/
|
||||
define('SERVICES_JSON_IN_CMT', 5);
|
||||
|
||||
/**
|
||||
* Behavior switch for Services_JSON::decode()
|
||||
*/
|
||||
define('SERVICES_JSON_LOOSE_TYPE', 16);
|
||||
|
||||
/**
|
||||
* Behavior switch for Services_JSON::decode()
|
||||
*/
|
||||
define('SERVICES_JSON_SUPPRESS_ERRORS', 32);
|
||||
|
||||
/**
|
||||
* Converts to and from JSON format.
|
||||
*
|
||||
* Brief example of use:
|
||||
*
|
||||
* <code>
|
||||
* // create a new instance of Services_JSON
|
||||
* $json = new Services_JSON();
|
||||
*
|
||||
* // convert a complexe value to JSON notation, and send it to the browser
|
||||
* $value = array('foo', 'bar', array(1, 2, 'baz'), array(3, array(4)));
|
||||
* $output = $json->encode($value);
|
||||
*
|
||||
* print($output);
|
||||
* // prints: ["foo","bar",[1,2,"baz"],[3,[4]]]
|
||||
*
|
||||
* // accept incoming POST data, assumed to be in JSON notation
|
||||
* $input = file_get_contents('php://input', 1000000);
|
||||
* $value = $json->decode($input);
|
||||
* </code>
|
||||
*/
|
||||
class Services_JSON
|
||||
{
|
||||
/**
|
||||
* constructs a new JSON instance
|
||||
*
|
||||
* @param int $use object behavior flags; combine with boolean-OR
|
||||
*
|
||||
* possible values:
|
||||
* - SERVICES_JSON_LOOSE_TYPE: loose typing.
|
||||
* "{...}" syntax creates associative arrays
|
||||
* instead of objects in decode().
|
||||
* - SERVICES_JSON_SUPPRESS_ERRORS: error suppression.
|
||||
* Values which can't be encoded (e.g. resources)
|
||||
* appear as NULL instead of throwing errors.
|
||||
* By default, a deeply-nested resource will
|
||||
* bubble up with an error, so all return values
|
||||
* from encode() should be checked with isError()
|
||||
*/
|
||||
function Services_JSON($use = 0)
|
||||
{
|
||||
$this->use = $use;
|
||||
}
|
||||
|
||||
/**
|
||||
* convert a string from one UTF-16 char to one UTF-8 char
|
||||
*
|
||||
* Normally should be handled by mb_convert_encoding, but
|
||||
* provides a slower PHP-only method for installations
|
||||
* that lack the multibye string extension.
|
||||
*
|
||||
* @param string $utf16 UTF-16 character
|
||||
* @return string UTF-8 character
|
||||
* @access private
|
||||
*/
|
||||
function utf162utf8($utf16)
|
||||
{
|
||||
// oh please oh please oh please oh please oh please
|
||||
if(function_exists('mb_convert_encoding')) {
|
||||
return mb_convert_encoding($utf16, 'UTF-8', 'UTF-16');
|
||||
}
|
||||
|
||||
$bytes = (ord($utf16{0}) << 8) | ord($utf16{1});
|
||||
|
||||
switch(true) {
|
||||
case ((0x7F & $bytes) == $bytes):
|
||||
// this case should never be reached, because we are in ASCII range
|
||||
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||
return chr(0x7F & $bytes);
|
||||
|
||||
case (0x07FF & $bytes) == $bytes:
|
||||
// return a 2-byte UTF-8 character
|
||||
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||
return chr(0xC0 | (($bytes >> 6) & 0x1F))
|
||||
. chr(0x80 | ($bytes & 0x3F));
|
||||
|
||||
case (0xFFFF & $bytes) == $bytes:
|
||||
// return a 3-byte UTF-8 character
|
||||
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||
return chr(0xE0 | (($bytes >> 12) & 0x0F))
|
||||
. chr(0x80 | (($bytes >> 6) & 0x3F))
|
||||
. chr(0x80 | ($bytes & 0x3F));
|
||||
}
|
||||
|
||||
// ignoring UTF-32 for now, sorry
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* convert a string from one UTF-8 char to one UTF-16 char
|
||||
*
|
||||
* Normally should be handled by mb_convert_encoding, but
|
||||
* provides a slower PHP-only method for installations
|
||||
* that lack the multibye string extension.
|
||||
*
|
||||
* @param string $utf8 UTF-8 character
|
||||
* @return string UTF-16 character
|
||||
* @access private
|
||||
*/
|
||||
function utf82utf16($utf8)
|
||||
{
|
||||
// oh please oh please oh please oh please oh please
|
||||
if(function_exists('mb_convert_encoding')) {
|
||||
return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8');
|
||||
}
|
||||
|
||||
switch(strlen($utf8)) {
|
||||
case 1:
|
||||
// this case should never be reached, because we are in ASCII range
|
||||
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||
return $utf8;
|
||||
|
||||
case 2:
|
||||
// return a UTF-16 character from a 2-byte UTF-8 char
|
||||
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||
return chr(0x07 & (ord($utf8{0}) >> 2))
|
||||
. chr((0xC0 & (ord($utf8{0}) << 6))
|
||||
| (0x3F & ord($utf8{1})));
|
||||
|
||||
case 3:
|
||||
// return a UTF-16 character from a 3-byte UTF-8 char
|
||||
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||
return chr((0xF0 & (ord($utf8{0}) << 4))
|
||||
| (0x0F & (ord($utf8{1}) >> 2)))
|
||||
. chr((0xC0 & (ord($utf8{1}) << 6))
|
||||
| (0x7F & ord($utf8{2})));
|
||||
}
|
||||
|
||||
// ignoring UTF-32 for now, sorry
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* encodes an arbitrary variable into JSON format
|
||||
*
|
||||
* @param mixed $var any number, boolean, string, array, or object to be encoded.
|
||||
* see argument 1 to Services_JSON() above for array-parsing behavior.
|
||||
* if var is a strng, note that encode() always expects it
|
||||
* to be in ASCII or UTF-8 format!
|
||||
*
|
||||
* @return mixed JSON string representation of input var or an error if a problem occurs
|
||||
* @access public
|
||||
*/
|
||||
function encode($var)
|
||||
{
|
||||
switch (gettype($var)) {
|
||||
case 'boolean':
|
||||
return $var ? 'true' : 'false';
|
||||
|
||||
case 'NULL':
|
||||
return 'null';
|
||||
|
||||
case 'integer':
|
||||
return (int) $var;
|
||||
|
||||
case 'double':
|
||||
case 'float':
|
||||
return (float) $var;
|
||||
|
||||
case 'string':
|
||||
// STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT
|
||||
$ascii = '';
|
||||
$strlen_var = strlen($var);
|
||||
|
||||
/*
|
||||
* Iterate over every character in the string,
|
||||
* escaping with a slash or encoding to UTF-8 where necessary
|
||||
*/
|
||||
for ($c = 0; $c < $strlen_var; ++$c) {
|
||||
|
||||
$ord_var_c = ord($var{$c});
|
||||
|
||||
switch (true) {
|
||||
case $ord_var_c == 0x08:
|
||||
$ascii .= '\b';
|
||||
break;
|
||||
case $ord_var_c == 0x09:
|
||||
$ascii .= '\t';
|
||||
break;
|
||||
case $ord_var_c == 0x0A:
|
||||
$ascii .= '\n';
|
||||
break;
|
||||
case $ord_var_c == 0x0C:
|
||||
$ascii .= '\f';
|
||||
break;
|
||||
case $ord_var_c == 0x0D:
|
||||
$ascii .= '\r';
|
||||
break;
|
||||
|
||||
case $ord_var_c == 0x22:
|
||||
case $ord_var_c == 0x2F:
|
||||
case $ord_var_c == 0x5C:
|
||||
// double quote, slash, slosh
|
||||
$ascii .= '\\'.$var{$c};
|
||||
break;
|
||||
|
||||
case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)):
|
||||
// characters U-00000000 - U-0000007F (same as ASCII)
|
||||
$ascii .= $var{$c};
|
||||
break;
|
||||
|
||||
case (($ord_var_c & 0xE0) == 0xC0):
|
||||
// characters U-00000080 - U-000007FF, mask 110XXXXX
|
||||
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||
$char = pack('C*', $ord_var_c, ord($var{$c + 1}));
|
||||
$c += 1;
|
||||
$utf16 = $this->utf82utf16($char);
|
||||
$ascii .= sprintf('\u%04s', bin2hex($utf16));
|
||||
break;
|
||||
|
||||
case (($ord_var_c & 0xF0) == 0xE0):
|
||||
// characters U-00000800 - U-0000FFFF, mask 1110XXXX
|
||||
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||
$char = pack('C*', $ord_var_c,
|
||||
ord($var{$c + 1}),
|
||||
ord($var{$c + 2}));
|
||||
$c += 2;
|
||||
$utf16 = $this->utf82utf16($char);
|
||||
$ascii .= sprintf('\u%04s', bin2hex($utf16));
|
||||
break;
|
||||
|
||||
case (($ord_var_c & 0xF8) == 0xF0):
|
||||
// characters U-00010000 - U-001FFFFF, mask 11110XXX
|
||||
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||
$char = pack('C*', $ord_var_c,
|
||||
ord($var{$c + 1}),
|
||||
ord($var{$c + 2}),
|
||||
ord($var{$c + 3}));
|
||||
$c += 3;
|
||||
$utf16 = $this->utf82utf16($char);
|
||||
$ascii .= sprintf('\u%04s', bin2hex($utf16));
|
||||
break;
|
||||
|
||||
case (($ord_var_c & 0xFC) == 0xF8):
|
||||
// characters U-00200000 - U-03FFFFFF, mask 111110XX
|
||||
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||
$char = pack('C*', $ord_var_c,
|
||||
ord($var{$c + 1}),
|
||||
ord($var{$c + 2}),
|
||||
ord($var{$c + 3}),
|
||||
ord($var{$c + 4}));
|
||||
$c += 4;
|
||||
$utf16 = $this->utf82utf16($char);
|
||||
$ascii .= sprintf('\u%04s', bin2hex($utf16));
|
||||
break;
|
||||
|
||||
case (($ord_var_c & 0xFE) == 0xFC):
|
||||
// characters U-04000000 - U-7FFFFFFF, mask 1111110X
|
||||
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||
$char = pack('C*', $ord_var_c,
|
||||
ord($var{$c + 1}),
|
||||
ord($var{$c + 2}),
|
||||
ord($var{$c + 3}),
|
||||
ord($var{$c + 4}),
|
||||
ord($var{$c + 5}));
|
||||
$c += 5;
|
||||
$utf16 = $this->utf82utf16($char);
|
||||
$ascii .= sprintf('\u%04s', bin2hex($utf16));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return '"'.$ascii.'"';
|
||||
|
||||
case 'array':
|
||||
/*
|
||||
* As per JSON spec if any array key is not an integer
|
||||
* we must treat the the whole array as an object. We
|
||||
* also try to catch a sparsely populated associative
|
||||
* array with numeric keys here because some JS engines
|
||||
* will create an array with empty indexes up to
|
||||
* max_index which can cause memory issues and because
|
||||
* the keys, which may be relevant, will be remapped
|
||||
* otherwise.
|
||||
*
|
||||
* As per the ECMA and JSON specification an object may
|
||||
* have any string as a property. Unfortunately due to
|
||||
* a hole in the ECMA specification if the key is a
|
||||
* ECMA reserved word or starts with a digit the
|
||||
* parameter is only accessible using ECMAScript's
|
||||
* bracket notation.
|
||||
*/
|
||||
|
||||
// treat as a JSON object
|
||||
if (is_array($var) && count($var) && (array_keys($var) !== range(0, sizeof($var) - 1))) {
|
||||
$properties = array_map(array($this, 'name_value'),
|
||||
array_keys($var),
|
||||
array_values($var));
|
||||
|
||||
foreach($properties as $property) {
|
||||
if(Services_JSON::isError($property)) {
|
||||
return $property;
|
||||
}
|
||||
}
|
||||
|
||||
return '{' . join(',', $properties) . '}';
|
||||
}
|
||||
|
||||
// treat it like a regular array
|
||||
$elements = array_map(array($this, 'encode'), $var);
|
||||
|
||||
foreach($elements as $element) {
|
||||
if(Services_JSON::isError($element)) {
|
||||
return $element;
|
||||
}
|
||||
}
|
||||
|
||||
return '[' . join(',', $elements) . ']';
|
||||
|
||||
case 'object':
|
||||
$vars = get_object_vars($var);
|
||||
|
||||
$properties = array_map(array($this, 'name_value'),
|
||||
array_keys($vars),
|
||||
array_values($vars));
|
||||
|
||||
foreach($properties as $property) {
|
||||
if(Services_JSON::isError($property)) {
|
||||
return $property;
|
||||
}
|
||||
}
|
||||
|
||||
return '{' . join(',', $properties) . '}';
|
||||
|
||||
default:
|
||||
return ($this->use & SERVICES_JSON_SUPPRESS_ERRORS)
|
||||
? 'null'
|
||||
: new Services_JSON_Error(gettype($var)." can not be encoded as JSON string");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* array-walking function for use in generating JSON-formatted name-value pairs
|
||||
*
|
||||
* @param string $name name of key to use
|
||||
* @param mixed $value reference to an array element to be encoded
|
||||
*
|
||||
* @return string JSON-formatted name-value pair, like '"name":value'
|
||||
* @access private
|
||||
*/
|
||||
function name_value($name, $value)
|
||||
{
|
||||
$encoded_value = $this->encode($value);
|
||||
|
||||
if(Services_JSON::isError($encoded_value)) {
|
||||
return $encoded_value;
|
||||
}
|
||||
|
||||
return $this->encode(strval($name)) . ':' . $encoded_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* reduce a string by removing leading and trailing comments and whitespace
|
||||
*
|
||||
* @param $str string string value to strip of comments and whitespace
|
||||
*
|
||||
* @return string string value stripped of comments and whitespace
|
||||
* @access private
|
||||
*/
|
||||
function reduce_string($str)
|
||||
{
|
||||
$str = preg_replace(array(
|
||||
|
||||
// eliminate single line comments in '// ...' form
|
||||
'#^\s*//(.+)$#m',
|
||||
|
||||
// eliminate multi-line comments in '/* ... */' form, at start of string
|
||||
'#^\s*/\*(.+)\*/#Us',
|
||||
|
||||
// eliminate multi-line comments in '/* ... */' form, at end of string
|
||||
'#/\*(.+)\*/\s*$#Us'
|
||||
|
||||
), '', $str);
|
||||
|
||||
// eliminate extraneous space
|
||||
return trim($str);
|
||||
}
|
||||
|
||||
/**
|
||||
* decodes a JSON string into appropriate variable
|
||||
*
|
||||
* @param string $str JSON-formatted string
|
||||
*
|
||||
* @return mixed number, boolean, string, array, or object
|
||||
* corresponding to given JSON input string.
|
||||
* See argument 1 to Services_JSON() above for object-output behavior.
|
||||
* Note that decode() always returns strings
|
||||
* in ASCII or UTF-8 format!
|
||||
* @access public
|
||||
*/
|
||||
function decode($str)
|
||||
{
|
||||
$str = $this->reduce_string($str);
|
||||
|
||||
switch (strtolower($str)) {
|
||||
case 'true':
|
||||
return true;
|
||||
|
||||
case 'false':
|
||||
return false;
|
||||
|
||||
case 'null':
|
||||
return null;
|
||||
|
||||
default:
|
||||
$m = array();
|
||||
|
||||
if (is_numeric($str)) {
|
||||
// Lookie-loo, it's a number
|
||||
|
||||
// This would work on its own, but I'm trying to be
|
||||
// good about returning integers where appropriate:
|
||||
// return (float)$str;
|
||||
|
||||
// Return float or int, as appropriate
|
||||
return ((float)$str == (integer)$str)
|
||||
? (integer)$str
|
||||
: (float)$str;
|
||||
|
||||
} elseif (preg_match('/^("|\').*(\1)$/s', $str, $m) && $m[1] == $m[2]) {
|
||||
// STRINGS RETURNED IN UTF-8 FORMAT
|
||||
$delim = substr($str, 0, 1);
|
||||
$chrs = substr($str, 1, -1);
|
||||
$utf8 = '';
|
||||
$strlen_chrs = strlen($chrs);
|
||||
|
||||
for ($c = 0; $c < $strlen_chrs; ++$c) {
|
||||
|
||||
$substr_chrs_c_2 = substr($chrs, $c, 2);
|
||||
$ord_chrs_c = ord($chrs{$c});
|
||||
|
||||
switch (true) {
|
||||
case $substr_chrs_c_2 == '\b':
|
||||
$utf8 .= chr(0x08);
|
||||
++$c;
|
||||
break;
|
||||
case $substr_chrs_c_2 == '\t':
|
||||
$utf8 .= chr(0x09);
|
||||
++$c;
|
||||
break;
|
||||
case $substr_chrs_c_2 == '\n':
|
||||
$utf8 .= chr(0x0A);
|
||||
++$c;
|
||||
break;
|
||||
case $substr_chrs_c_2 == '\f':
|
||||
$utf8 .= chr(0x0C);
|
||||
++$c;
|
||||
break;
|
||||
case $substr_chrs_c_2 == '\r':
|
||||
$utf8 .= chr(0x0D);
|
||||
++$c;
|
||||
break;
|
||||
|
||||
case $substr_chrs_c_2 == '\\"':
|
||||
case $substr_chrs_c_2 == '\\\'':
|
||||
case $substr_chrs_c_2 == '\\\\':
|
||||
case $substr_chrs_c_2 == '\\/':
|
||||
if (($delim == '"' && $substr_chrs_c_2 != '\\\'') ||
|
||||
($delim == "'" && $substr_chrs_c_2 != '\\"')) {
|
||||
$utf8 .= $chrs{++$c};
|
||||
}
|
||||
break;
|
||||
|
||||
case preg_match('/\\\u[0-9A-F]{4}/i', substr($chrs, $c, 6)):
|
||||
// single, escaped unicode character
|
||||
$utf16 = chr(hexdec(substr($chrs, ($c + 2), 2)))
|
||||
. chr(hexdec(substr($chrs, ($c + 4), 2)));
|
||||
$utf8 .= $this->utf162utf8($utf16);
|
||||
$c += 5;
|
||||
break;
|
||||
|
||||
case ($ord_chrs_c >= 0x20) && ($ord_chrs_c <= 0x7F):
|
||||
$utf8 .= $chrs{$c};
|
||||
break;
|
||||
|
||||
case ($ord_chrs_c & 0xE0) == 0xC0:
|
||||
// characters U-00000080 - U-000007FF, mask 110XXXXX
|
||||
//see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||
$utf8 .= substr($chrs, $c, 2);
|
||||
++$c;
|
||||
break;
|
||||
|
||||
case ($ord_chrs_c & 0xF0) == 0xE0:
|
||||
// characters U-00000800 - U-0000FFFF, mask 1110XXXX
|
||||
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||
$utf8 .= substr($chrs, $c, 3);
|
||||
$c += 2;
|
||||
break;
|
||||
|
||||
case ($ord_chrs_c & 0xF8) == 0xF0:
|
||||
// characters U-00010000 - U-001FFFFF, mask 11110XXX
|
||||
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||
$utf8 .= substr($chrs, $c, 4);
|
||||
$c += 3;
|
||||
break;
|
||||
|
||||
case ($ord_chrs_c & 0xFC) == 0xF8:
|
||||
// characters U-00200000 - U-03FFFFFF, mask 111110XX
|
||||
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||
$utf8 .= substr($chrs, $c, 5);
|
||||
$c += 4;
|
||||
break;
|
||||
|
||||
case ($ord_chrs_c & 0xFE) == 0xFC:
|
||||
// characters U-04000000 - U-7FFFFFFF, mask 1111110X
|
||||
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
||||
$utf8 .= substr($chrs, $c, 6);
|
||||
$c += 5;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $utf8;
|
||||
|
||||
} elseif (preg_match('/^\[.*\]$/s', $str) || preg_match('/^\{.*\}$/s', $str)) {
|
||||
// array, or object notation
|
||||
|
||||
if ($str{0} == '[') {
|
||||
$stk = array(SERVICES_JSON_IN_ARR);
|
||||
$arr = array();
|
||||
} else {
|
||||
if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
|
||||
$stk = array(SERVICES_JSON_IN_OBJ);
|
||||
$obj = array();
|
||||
} else {
|
||||
$stk = array(SERVICES_JSON_IN_OBJ);
|
||||
$obj = new stdClass();
|
||||
}
|
||||
}
|
||||
|
||||
array_push($stk, array('what' => SERVICES_JSON_SLICE,
|
||||
'where' => 0,
|
||||
'delim' => false));
|
||||
|
||||
$chrs = substr($str, 1, -1);
|
||||
$chrs = $this->reduce_string($chrs);
|
||||
|
||||
if ($chrs == '') {
|
||||
if (reset($stk) == SERVICES_JSON_IN_ARR) {
|
||||
return $arr;
|
||||
|
||||
} else {
|
||||
return $obj;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//print("\nparsing {$chrs}\n");
|
||||
|
||||
$strlen_chrs = strlen($chrs);
|
||||
|
||||
for ($c = 0; $c <= $strlen_chrs; ++$c) {
|
||||
|
||||
$top = end($stk);
|
||||
$substr_chrs_c_2 = substr($chrs, $c, 2);
|
||||
|
||||
if (($c == $strlen_chrs) || (($chrs{$c} == ',') && ($top['what'] == SERVICES_JSON_SLICE))) {
|
||||
// found a comma that is not inside a string, array, etc.,
|
||||
// OR we've reached the end of the character list
|
||||
$slice = substr($chrs, $top['where'], ($c - $top['where']));
|
||||
array_push($stk, array('what' => SERVICES_JSON_SLICE, 'where' => ($c + 1), 'delim' => false));
|
||||
//print("Found split at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
|
||||
|
||||
if (reset($stk) == SERVICES_JSON_IN_ARR) {
|
||||
// we are in an array, so just push an element onto the stack
|
||||
array_push($arr, $this->decode($slice));
|
||||
|
||||
} elseif (reset($stk) == SERVICES_JSON_IN_OBJ) {
|
||||
// we are in an object, so figure
|
||||
// out the property name and set an
|
||||
// element in an associative array,
|
||||
// for now
|
||||
$parts = array();
|
||||
|
||||
if (preg_match('/^\s*(["\'].*[^\\\]["\'])\s*:\s*(\S.*),?$/Uis', $slice, $parts)) {
|
||||
// "name":value pair
|
||||
$key = $this->decode($parts[1]);
|
||||
$val = $this->decode($parts[2]);
|
||||
|
||||
if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
|
||||
$obj[$key] = $val;
|
||||
} else {
|
||||
$obj->$key = $val;
|
||||
}
|
||||
} elseif (preg_match('/^\s*(\w+)\s*:\s*(\S.*),?$/Uis', $slice, $parts)) {
|
||||
// name:value pair, where name is unquoted
|
||||
$key = $parts[1];
|
||||
$val = $this->decode($parts[2]);
|
||||
|
||||
if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
|
||||
$obj[$key] = $val;
|
||||
} else {
|
||||
$obj->$key = $val;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} elseif ((($chrs{$c} == '"') || ($chrs{$c} == "'")) && ($top['what'] != SERVICES_JSON_IN_STR)) {
|
||||
// found a quote, and we are not inside a string
|
||||
array_push($stk, array('what' => SERVICES_JSON_IN_STR, 'where' => $c, 'delim' => $chrs{$c}));
|
||||
//print("Found start of string at {$c}\n");
|
||||
|
||||
} elseif (($chrs{$c} == $top['delim']) &&
|
||||
($top['what'] == SERVICES_JSON_IN_STR) &&
|
||||
((strlen(substr($chrs, 0, $c)) - strlen(rtrim(substr($chrs, 0, $c), '\\'))) % 2 != 1)) {
|
||||
// found a quote, we're in a string, and it's not escaped
|
||||
// we know that it's not escaped becase there is _not_ an
|
||||
// odd number of backslashes at the end of the string so far
|
||||
array_pop($stk);
|
||||
//print("Found end of string at {$c}: ".substr($chrs, $top['where'], (1 + 1 + $c - $top['where']))."\n");
|
||||
|
||||
} elseif (($chrs{$c} == '[') &&
|
||||
in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
|
||||
// found a left-bracket, and we are in an array, object, or slice
|
||||
array_push($stk, array('what' => SERVICES_JSON_IN_ARR, 'where' => $c, 'delim' => false));
|
||||
//print("Found start of array at {$c}\n");
|
||||
|
||||
} elseif (($chrs{$c} == ']') && ($top['what'] == SERVICES_JSON_IN_ARR)) {
|
||||
// found a right-bracket, and we're in an array
|
||||
array_pop($stk);
|
||||
//print("Found end of array at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
|
||||
|
||||
} elseif (($chrs{$c} == '{') &&
|
||||
in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
|
||||
// found a left-brace, and we are in an array, object, or slice
|
||||
array_push($stk, array('what' => SERVICES_JSON_IN_OBJ, 'where' => $c, 'delim' => false));
|
||||
//print("Found start of object at {$c}\n");
|
||||
|
||||
} elseif (($chrs{$c} == '}') && ($top['what'] == SERVICES_JSON_IN_OBJ)) {
|
||||
// found a right-brace, and we're in an object
|
||||
array_pop($stk);
|
||||
//print("Found end of object at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
|
||||
|
||||
} elseif (($substr_chrs_c_2 == '/*') &&
|
||||
in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
|
||||
// found a comment start, and we are in an array, object, or slice
|
||||
array_push($stk, array('what' => SERVICES_JSON_IN_CMT, 'where' => $c, 'delim' => false));
|
||||
$c++;
|
||||
//print("Found start of comment at {$c}\n");
|
||||
|
||||
} elseif (($substr_chrs_c_2 == '*/') && ($top['what'] == SERVICES_JSON_IN_CMT)) {
|
||||
// found a comment end, and we're in one now
|
||||
array_pop($stk);
|
||||
$c++;
|
||||
|
||||
for ($i = $top['where']; $i <= $c; ++$i)
|
||||
$chrs = substr_replace($chrs, ' ', $i, 1);
|
||||
|
||||
//print("Found end of comment at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (reset($stk) == SERVICES_JSON_IN_ARR) {
|
||||
return $arr;
|
||||
|
||||
} elseif (reset($stk) == SERVICES_JSON_IN_OBJ) {
|
||||
return $obj;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Ultimately, this should just call PEAR::isError()
|
||||
*/
|
||||
function isError($data, $code = null)
|
||||
{
|
||||
if (class_exists('pear')) {
|
||||
return PEAR::isError($data, $code);
|
||||
} elseif (is_object($data) && (get_class($data) == 'services_json_error' ||
|
||||
is_subclass_of($data, 'services_json_error'))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (class_exists('PEAR_Error')) {
|
||||
|
||||
class Services_JSON_Error extends PEAR_Error
|
||||
{
|
||||
function Services_JSON_Error($message = 'unknown error', $code = null,
|
||||
$mode = null, $options = null, $userinfo = null)
|
||||
{
|
||||
parent::PEAR_Error($message, $code, $mode, $options, $userinfo);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
/**
|
||||
* @todo Ultimately, this class shall be descended from PEAR_Error
|
||||
*/
|
||||
class Services_JSON_Error
|
||||
{
|
||||
function Services_JSON_Error($message = 'unknown error', $code = null,
|
||||
$mode = null, $options = null, $userinfo = null)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
326
onyx2/include/applications/GSM/main.php
Normal file
326
onyx2/include/applications/GSM/main.php
Normal file
|
|
@ -0,0 +1,326 @@
|
|||
<?php
|
||||
//Fichier appelé pour afficher l'application
|
||||
|
||||
$p = strtolower(gpc("p"));
|
||||
$titre = ucfirst(trim(gpc("titre", "post")));
|
||||
$auteur = ucwords(trim(gpc("auteur", "post")));
|
||||
|
||||
if ($p == "liste")
|
||||
{
|
||||
$bdd = new BDD();
|
||||
$req = $bdd->query("SELECT id, titre, chanteur, CDDeca, CDChanteur, CDAnnee FROM gsm ORDER BY id;");
|
||||
$req["nombre"] = $bdd->num_rows;
|
||||
$reqCDA = $bdd->query("SELECT id, nom FROM gsm_cdannee;");
|
||||
$reqCDC = $bdd->query("SELECT id, nom FROM gsm_cdchant;");
|
||||
$reqCDD = $bdd->query("SELECT id, nom FROM gsm_cddece;");
|
||||
$bdd->deconnexion();
|
||||
|
||||
$xml_cds = $xml->createElement("liste");
|
||||
if (!empty($req))
|
||||
foreach($req as $ligne)
|
||||
{
|
||||
if (!empty($ligne["id"]))
|
||||
{
|
||||
$chan = $xml->createElement("chanson");
|
||||
$chan->setAttribute("id", $ligne["id"]);
|
||||
$chan->setAttribute("titre", $ligne["titre"]);
|
||||
$chan->setAttribute("chanteur", $ligne["chanteur"]);
|
||||
$chan->setAttribute("CD_decenie", $ligne["CDDeca"]);
|
||||
$chan->setAttribute("CD_annee", $ligne["CDAnnee"]);
|
||||
$chan->setAttribute("CD_interprete", $ligne["CDChanteur"]);
|
||||
$xml_cds->appendChild($chan);
|
||||
}
|
||||
}
|
||||
if (!empty($reqCDA))
|
||||
foreach($reqCDA as $cd)
|
||||
{
|
||||
$chan = $xml->createElement("cdannee");
|
||||
$chan->setAttribute("id", $cd["id"]);
|
||||
$chan->setAttribute("nom", $cd["nom"]);
|
||||
$xml_cds->appendChild($chan);
|
||||
}
|
||||
if (!empty($reqCDC))
|
||||
foreach($reqCDC as $cd)
|
||||
{
|
||||
$chan = $xml->createElement("cdchant");
|
||||
$chan->setAttribute("id", $cd["id"]);
|
||||
$chan->setAttribute("nom", $cd["nom"]);
|
||||
$xml_cds->appendChild($chan);
|
||||
}
|
||||
if (!empty($reqCDD))
|
||||
foreach($reqCDD as $cd)
|
||||
{
|
||||
$chan = $xml->createElement("cddece");
|
||||
$chan->setAttribute("id", $cd["id"]);
|
||||
$chan->setAttribute("nom", $cd["nom"]);
|
||||
$xml_cds->appendChild($chan);
|
||||
}
|
||||
$xml_root->appendChild($xml_cds);
|
||||
}
|
||||
elseif ($p == "add" && ($type = intval(gpc("type", "post"))) && ($title = gpc("title", "post")))
|
||||
{
|
||||
$color = hexdec(gpc("color", "post"));
|
||||
|
||||
if ($type == 1)
|
||||
$table = "gsm_cdannee";
|
||||
else if ($type == 2)
|
||||
$table = "gsm_cdchant";
|
||||
else
|
||||
$table = "gsm_cddece";
|
||||
|
||||
$bdd = new BDD();
|
||||
$bdd->escape($title);
|
||||
$bdd->query("INSERT INTO `$table` (nom, color) VALUES ('$title', $color);");
|
||||
$id = $bdd->insert_id();
|
||||
$req = $bdd->unique_query("SELECT COUNT(id) AS nombre FROM gsm");
|
||||
$bdd->deconnexion();
|
||||
|
||||
$xml_root->appendChild($xml->createElement("id", $id));
|
||||
}
|
||||
elseif ($p == "del" && $id = intval(gpc("id", "post")))
|
||||
{
|
||||
$bdd = new BDD();
|
||||
$bdd->query("DELETE FROM `gsm` WHERE id = $id;");
|
||||
$req = $bdd->unique_query("SELECT COUNT(id) AS nombre FROM gsm");
|
||||
$bdd->deconnexion();
|
||||
}
|
||||
elseif ($p == "color" && ($type = intval(gpc("type", "get"))) && ($idAlbum = intval(gpc("id", "get"))))
|
||||
{
|
||||
if ($type == 1)
|
||||
$table = "gsm_cdannee";
|
||||
else if ($type == 2)
|
||||
$table = "gsm_cdchant";
|
||||
else
|
||||
$table = "gsm_cddece";
|
||||
|
||||
$bdd = new BDD();
|
||||
$res = $bdd->unique_query("SELECT color FROM `$table` WHERE id = $idAlbum;");
|
||||
$req = $bdd->unique_query("SELECT COUNT(id) AS nombre FROM gsm");
|
||||
$bdd->deconnexion();
|
||||
|
||||
$xml_root->appendChild($xml->createElement("color", sprintf("#%06X", $res["color"])));
|
||||
|
||||
$color2R = ($res["color"] >> 16) & 255;
|
||||
if ($color2R >= 25)
|
||||
$color2R -= 25;
|
||||
$color2G = ($res["color"] >> 8) & 255;
|
||||
if ($color2G >= 25)
|
||||
$color2G -= 25;
|
||||
$color2B = ($res["color"]) & 255;
|
||||
if ($color2B >= 25)
|
||||
$color2B -= 25;
|
||||
$xml_root->appendChild($xml->createElement("color", sprintf("#%02X%02X%02X", $color2R, $color2G, $color2B)));
|
||||
}
|
||||
elseif ($p == "rech")
|
||||
{
|
||||
$type = substr(gpc("type", "post"), 0, 1);
|
||||
$id = intval(gpc("id", "post"));
|
||||
|
||||
if ($type == "d")
|
||||
{
|
||||
$bdd = new BDD();
|
||||
$rech = $bdd->query("SELECT * FROM gsm WHERE CDDeca = $id;");
|
||||
$req = $bdd->unique_query("SELECT COUNT(id) AS nombre FROM gsm");
|
||||
$bdd->deconnexion();
|
||||
}
|
||||
elseif ($type == "a")
|
||||
{
|
||||
$bdd = new BDD();
|
||||
$rech = $bdd->query("SELECT * FROM gsm WHERE CDAnnee = $id;");
|
||||
$req = $bdd->unique_query("SELECT COUNT(id) AS nombre FROM gsm");
|
||||
$bdd->deconnexion();
|
||||
}
|
||||
elseif ($type == "i")
|
||||
{
|
||||
$bdd = new BDD();
|
||||
$rech = $bdd->query("SELECT * FROM gsm WHERE CDChanteur = $id;");
|
||||
$req = $bdd->unique_query("SELECT COUNT(id) AS nombre FROM gsm");
|
||||
$bdd->deconnexion();
|
||||
}
|
||||
|
||||
$xml_cds = $xml->createElement("album");
|
||||
if (!empty($rech))
|
||||
{
|
||||
foreach($rech as $ligne)
|
||||
{
|
||||
$chan = $xml->createElement("chanson");
|
||||
$chan->setAttribute("id", $ligne["id"]);
|
||||
$chan->setAttribute("titre", $ligne["titre"]);
|
||||
$chan->setAttribute("chanteur", $ligne["chanteur"]);
|
||||
$chan->setAttribute("CD_decenie", $ligne["CDDeca"]);
|
||||
$chan->setAttribute("CD_annee", $ligne["CDAnnee"]);
|
||||
$chan->setAttribute("CD_interprete", $ligne["CDChanteur"]);
|
||||
$xml_cds->appendChild($chan);
|
||||
}
|
||||
}
|
||||
$xml_root->appendChild($xml_cds);
|
||||
}
|
||||
elseif ($p == "stats")
|
||||
{
|
||||
$cds = array();
|
||||
|
||||
$bdd = new BDD();
|
||||
$cds["annees"] = $bdd->query("SELECT A.id, A.nom, COUNT(T.id) AS nombre FROM gsm_cdannee A LEFT OUTER JOIN gsm T ON A.id = T.CDAnnee GROUP BY A.id ORDER BY A.nom;");
|
||||
$cds["interpretes"] = $bdd->query("SELECT A.id, A.nom, COUNT(T.id) AS nombre FROM gsm_cdchant A LEFT OUTER JOIN gsm T ON A.id = T.CDChanteur GROUP BY A.id ORDER BY A.nom;");
|
||||
$cds["decenies"] = $bdd->query("SELECT A.id, A.nom, COUNT(T.id) AS nombre FROM gsm_cddece A LEFT OUTER JOIN gsm T ON A.id = T.CDDeca GROUP BY A.id ORDER BY A.nom;");
|
||||
$req = $bdd->unique_query("SELECT COUNT(id) AS nombre FROM gsm");
|
||||
$bdd->deconnexion();
|
||||
|
||||
if (!empty($cds["annees"]))
|
||||
{
|
||||
foreach($cds["annees"] as $ligne)
|
||||
{
|
||||
$cd = $xml->createElement("annee");
|
||||
$cd->setAttribute("id", $ligne["id"]);
|
||||
$cd->setAttribute("nbTitles", $ligne["nombre"]);
|
||||
$xml_root->appendChild($cd);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($cds["interpretes"]))
|
||||
{
|
||||
foreach($cds["interpretes"] as $ligne)
|
||||
{
|
||||
$cd = $xml->createElement("interprete");
|
||||
$cd->setAttribute("id", $ligne["id"]);
|
||||
$cd->setAttribute("nbTitles", $ligne["nombre"]);
|
||||
$xml_root->appendChild($cd);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($cds["decenies"]))
|
||||
{
|
||||
foreach($cds["decenies"] as $ligne)
|
||||
{
|
||||
$cd = $xml->createElement("decenie");
|
||||
$cd->setAttribute("id", $ligne["id"]);
|
||||
$cd->setAttribute("nbTitles", $ligne["nombre"]);
|
||||
$xml_root->appendChild($cd);
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif ($p == "cds")
|
||||
{
|
||||
$bdd = new BDD();
|
||||
$cds["decenies"] = $bdd->query("SELECT A.*, COUNT(T.id) AS nombre FROM gsm_cddece A LEFT OUTER JOIN gsm T ON A.id = T.CDDeca GROUP BY A.nom;");
|
||||
$cds["interpretes"] = $bdd->query("SELECT A.*, COUNT(T.id) AS nombre FROM gsm_cdchant A LEFT OUTER JOIN gsm T ON A.id = T.CDChanteur GROUP BY A.nom;");
|
||||
$cds["annees"] = $bdd->query("SELECT A.*, COUNT(T.id) AS nombre FROM gsm_cdannee A LEFT OUTER JOIN gsm T ON A.id = T.CDAnnee GROUP BY A.nom;");
|
||||
$req = $bdd->unique_query("SELECT COUNT(id) AS nombre FROM gsm");
|
||||
$bdd->deconnexion();
|
||||
|
||||
$xml_cds = $xml->createElement("decenies");
|
||||
if (!empty($cds["decenies"]))
|
||||
{
|
||||
foreach($cds["decenies"] as $ligne)
|
||||
{
|
||||
$cd = $xml->createElement("cd");
|
||||
$cd->setAttribute("id", $ligne["id"]);
|
||||
$cd->setAttribute("nom", $ligne["nom"]);
|
||||
$cd->setAttribute("nombre_titres", $ligne["nombre"]);
|
||||
$xml_cds->appendChild($cd);
|
||||
}
|
||||
}
|
||||
$xml_root->appendChild($xml_cds);
|
||||
|
||||
$xml_cds = $xml->createElement("interpretes");
|
||||
if (!empty($cds["interpretes"]))
|
||||
{
|
||||
foreach($cds["interpretes"] as $ligne)
|
||||
{
|
||||
$cd = $xml->createElement("cd");
|
||||
$cd->setAttribute("id", $ligne["id"]);
|
||||
$cd->setAttribute("nom", $ligne["nom"]);
|
||||
$cd->setAttribute("nombre_titres", $ligne["nombre"]);
|
||||
$xml_cds->appendChild($cd);
|
||||
}
|
||||
}
|
||||
$xml_root->appendChild($xml_cds);
|
||||
|
||||
$xml_cds = $xml->createElement("annees");
|
||||
if (!empty($cds["annees"]))
|
||||
{
|
||||
foreach($cds["annees"] as $ligne)
|
||||
{
|
||||
$cd = $xml->createElement("cd");
|
||||
$cd->setAttribute("id", $ligne["id"]);
|
||||
$cd->setAttribute("nom", $ligne["nom"]);
|
||||
$cd->setAttribute("nombre_titres", $ligne["nombre"]);
|
||||
$xml_cds->appendChild($cd);
|
||||
}
|
||||
}
|
||||
$xml_root->appendChild($xml_cds);
|
||||
}
|
||||
elseif (!empty($titre) && !empty($auteur))
|
||||
{
|
||||
$alb = intval(gpc("alb", "post"));
|
||||
$type = intval(gpc("type", "post"));
|
||||
$id = intval(gpc("id"));
|
||||
|
||||
$bdd = new BDD();
|
||||
$bdd->escape($titre);
|
||||
$bdd->escape($auteur);
|
||||
if ($id)
|
||||
$bdd->query("UPDATE gsm SET titre = '$titre', chanteur = '$auteur' WHERE id = $id;");
|
||||
else
|
||||
{
|
||||
//On recherche la chanson pour tester si elle n'existe pas déjà
|
||||
$chanson = $bdd->unique_query("SELECT id, CDDeca, CDAnnee, CDChanteur FROM gsm WHERE titre LIKE '$titre' AND chanteur LIKE '$auteur' LIMIT 1;");
|
||||
$update = "";
|
||||
if (!empty($chanson))
|
||||
{
|
||||
if (isset($update) && !empty($type) && $type == 3)
|
||||
{
|
||||
if (empty($chanson["CDDeca"]))
|
||||
$update .= "CDDeca = ".$alb.", ";
|
||||
else
|
||||
$update = null;
|
||||
}
|
||||
if (isset($update) && !empty($type) && $type == 1)
|
||||
{
|
||||
if (empty($chanson["CDAnnee"]))
|
||||
$update .= "CDAnnee = ".$alb.", ";
|
||||
else
|
||||
$update = null;
|
||||
}
|
||||
if (isset($update) && !empty($type) && $type == 2)
|
||||
{
|
||||
if (empty($chanson["CDChanteur"]))
|
||||
$update .= "CDChanteur = ".$alb.", ";
|
||||
else
|
||||
$update = null;
|
||||
}
|
||||
}
|
||||
if (!empty($update))
|
||||
{
|
||||
$bdd->query("UPDATE gsm SET $update titre = titre WHERE id = ".$chanson["id"].";");
|
||||
$res = $chanson["id"];
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($type == 1)
|
||||
$disc = array("annee" => $alb, "interprete" => 0, "decenie" => 0);
|
||||
else if ($type == 2)
|
||||
$disc = array("annee" => 0, "interprete" => $alb, "decenie" => 0);
|
||||
else if ($type == 3)
|
||||
$disc = array("annee" => 0, "interprete" => 0, "decenie" => $alb);
|
||||
else
|
||||
$disc = array("annee" => 0, "interprete" => 0, "decenie" => 0);
|
||||
|
||||
$bdd->query("INSERT INTO gsm (titre, chanteur, CDDeca, CDAnnee, CDChanteur) VALUES ('$titre', '$auteur', ".$disc["decenie"].", ".$disc["annee"].", ".$disc["interprete"].");");
|
||||
$res = $bdd->insert_id();
|
||||
}
|
||||
}
|
||||
$req = $bdd->unique_query("SELECT COUNT(id) AS nombre FROM gsm");
|
||||
$bdd->deconnexion();
|
||||
|
||||
$xml_root->appendChild($xml->createElement("id", $res));
|
||||
}
|
||||
else
|
||||
{
|
||||
$bdd = new BDD();
|
||||
$req = $bdd->unique_query("SELECT COUNT(id) AS nombre FROM gsm");
|
||||
$bdd->deconnexion();
|
||||
}
|
||||
|
||||
$json["nombre"] = $req["nombre"];
|
||||
?>
|
||||
50
onyx2/include/applications/GSM/property.xml
Normal file
50
onyx2/include/applications/GSM/property.xml
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<application active="1">
|
||||
<property value="name">Gérer sa musique</property>
|
||||
<property value="description">Cette application vous permet de gérer facilement votre discothèque.</property>
|
||||
<property value="etatAvancement">beta</property>
|
||||
<property value="version">1.1</property>
|
||||
<property value="lang">fr_FR</property>
|
||||
<property value="developpeur"><![CDATA[<span style="font-variant: small-caps">Mercier</span> Pierre-Olivier]]></property>
|
||||
<property value="corps">contenu</property>
|
||||
|
||||
<security type="users" default="restricted">
|
||||
<user>1</user>
|
||||
<user>2</user>
|
||||
</security>
|
||||
|
||||
<display value="logo">0</display>
|
||||
<display value="css" media="all">main.css</display>
|
||||
<display value="css" media="screen">style.css</display>
|
||||
<display value="css" media="print">print.css</display>
|
||||
<display value="script">app.js</display>
|
||||
<display value="body">
|
||||
<![CDATA[
|
||||
<h1>Bienvenue dans la gestion d'une discothèque</h1>
|
||||
<ul id="GSM_menu">
|
||||
<li><h2>Discothèque</h2></li>
|
||||
<li onclick="GSM_add();">Ajouter un album</li>
|
||||
<li onclick="GSM_listAlbums();">Liste des albums</li>
|
||||
<li onclick="GSM_listTitres();">Liste des titres</li>
|
||||
<li>Nombre de titres enregistrés : <span id="nbpc"></span></li>
|
||||
</ul>
|
||||
<div id="contenu"></div>
|
||||
]]>
|
||||
</display>
|
||||
<display value="js">
|
||||
<![CDATA[
|
||||
function runApplication(property, display, json)
|
||||
{
|
||||
$('logo').style.display = 'none';
|
||||
|
||||
$('contenu').innerHTML = "";
|
||||
news = document.createElement("div");
|
||||
news.className = "news";
|
||||
news.innerHTML = "<h3>Bienvenue dans la version béta de GSM pour Pommultimédia For Home !</h3>Cette nouvelle version est plus rapide que la version précédente et a une meilleur intégration avec Pommultimédia For Home.<br />N'hésitez pas à nous faire part de vos commentaires ;)";
|
||||
$('contenu').appendChild(news);
|
||||
}
|
||||
]]>
|
||||
</display>
|
||||
|
||||
<config value="table_bdd">gsm</config>
|
||||
</application>
|
||||
81
onyx2/include/applications/GSPC/main.php
Normal file
81
onyx2/include/applications/GSPC/main.php
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
//Fichier appelé pour afficher l'application
|
||||
|
||||
$p = strtolower(gpc("p"));
|
||||
$nom = trim(utf8_decode(utf8_encode(strtolower(gpc("nom", "post")))));
|
||||
$ligne = trim(utf8_decode(utf8_encode(strtoupper(gpc("ligne", "post")))));
|
||||
|
||||
//sleep(5);
|
||||
|
||||
if ($p == "liste")
|
||||
{
|
||||
$bdd = new BDD();
|
||||
$req = $bdd->query("SELECT * FROM gspc;");
|
||||
$req["nombre"] = $bdd->num_rows;
|
||||
$bdd->deconnexion();
|
||||
|
||||
$xml_pc = $xml->createElement("liste");
|
||||
foreach($req as $ligne)
|
||||
{
|
||||
if (!empty($ligne["reftable"]))
|
||||
{
|
||||
$portecle = $xml->createElement("porteclef");
|
||||
$portecle->setAttribute("id", $ligne["reftable"]);
|
||||
$portecle->setAttribute("nom", $ligne["nom"]);
|
||||
$portecle->setAttribute("caracteristique", ucfirst($ligne["caracteristique"]));
|
||||
$portecle->setAttribute("ligne", $ligne["ligne"]);
|
||||
$portecle->setAttribute("special", $ligne["special"]);
|
||||
$xml_pc->appendChild($portecle);
|
||||
}
|
||||
}
|
||||
$xml_root->appendChild($xml_pc);
|
||||
}
|
||||
elseif ($p == "stats")
|
||||
{
|
||||
$bdd = new BDD();
|
||||
$req = $bdd->query("SELECT ligne, COUNT(reftable) AS nombre FROM `gspc` GROUP BY ligne ORDER BY ligne ASC;");
|
||||
$bdd->deconnexion();
|
||||
|
||||
$xml_pc = $xml->createElement("statistiques");
|
||||
foreach($req as $ligne)
|
||||
{
|
||||
$portecle = $xml->createElement("ligne");
|
||||
$portecle->setAttribute("nom", $ligne["ligne"]);
|
||||
$portecle->setAttribute("nombre", $ligne["nombre"]);
|
||||
$xml_pc->appendChild($portecle);
|
||||
}
|
||||
$xml_root->appendChild($xml_pc);
|
||||
}
|
||||
elseif ($p == "del" && $id = intval(gpc("id", "post")))
|
||||
{
|
||||
$bdd = new BDD();
|
||||
$bdd->query("DELETE FROM `gspc` WHERE reftable = $id;");
|
||||
$req = $bdd->unique_query("SELECT COUNT(reftable) AS nombre FROM gspc");
|
||||
$bdd->deconnexion();
|
||||
}
|
||||
elseif (!empty($nom) && !empty($ligne))
|
||||
{
|
||||
$carac = trim(utf8_decode(utf8_encode(gpc("caracteristique", "post"))));
|
||||
$quantite = intval(gpc("quantite", "post"));
|
||||
$id = intval(gpc("id"));
|
||||
|
||||
$bdd = new BDD();
|
||||
$bdd->escape($nom);
|
||||
$bdd->escape($carac);
|
||||
$bdd->escape($ligne);
|
||||
if ($id)
|
||||
$bdd->query("UPDATE gspc SET nom = '$nom', caracteristique = '$carac', ligne = '$ligne', special = $quantite WHERE reftable = $id;");
|
||||
else
|
||||
$bdd->query("INSERT INTO gspc (nom, caracteristique, ligne, special) VALUES ('$nom', '$carac', '$ligne', $quantite);");
|
||||
$req = $bdd->unique_query("SELECT COUNT(reftable) AS nombre FROM gspc");
|
||||
$bdd->deconnexion();
|
||||
}
|
||||
else
|
||||
{
|
||||
$bdd = new BDD();
|
||||
$req = $bdd->unique_query("SELECT COUNT(reftable) AS nombre FROM gspc");
|
||||
$bdd->deconnexion();
|
||||
}
|
||||
|
||||
$json["nombre"] = $req["nombre"];
|
||||
?>
|
||||
51
onyx2/include/applications/GSPC/property.xml
Normal file
51
onyx2/include/applications/GSPC/property.xml
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<application active="1">
|
||||
<property value="name">Gérer ses porte-clefs</property>
|
||||
<property value="description">Cette application vous permet de gérer facilement une collection de porte-clefs.</property>
|
||||
<property value="etatAvancement">final</property>
|
||||
<property value="version">1.1</property>
|
||||
<property value="lang">fr_FR</property>
|
||||
<property value="developpeur"><![CDATA[<span style="font-variant: small-caps">Mercier</span> Pierre-Olivier]]></property>
|
||||
<property value="corps">contenu</property>
|
||||
|
||||
<security type="users" default="restricted">
|
||||
<user>1</user>
|
||||
<user>2</user>
|
||||
</security>
|
||||
<!--
|
||||
<menu text="Test pommes" eventClick="alert('Alerte aux pommes !');" />
|
||||
<menu text="Test abricot" eventClick="alert('Alerte aux abricots !');" />
|
||||
-->
|
||||
<display value="logo">0</display>
|
||||
<display value="css">style.css</display>
|
||||
<display value="script">app.js</display>
|
||||
<display value="body">
|
||||
<![CDATA[
|
||||
<h1>Bienvenue dans la gestion de collection de porte-clefs</h1>
|
||||
<ul id="GSPC_menu">
|
||||
<li><h2>Porte-clefs</h2></li>
|
||||
<li onclick="GSPC_add();">Ajouter un porte-clef</li>
|
||||
<li onclick="GSPC_list();">Liste des porte-clefs</li>
|
||||
<li onclick="GSPC_stats();">Liste des lignes</li>
|
||||
<li>Nombre de porte-clefs enregistrés : <span id="nbpc"></span></li>
|
||||
</ul>
|
||||
<div id="contenu"></div>
|
||||
]]>
|
||||
</display>
|
||||
<display value="js">
|
||||
<![CDATA[
|
||||
function runApplication(property, display, json)
|
||||
{
|
||||
$('logo').style.display = 'none';
|
||||
|
||||
$('contenu').innerHTML = "";
|
||||
news = document.createElement("div");
|
||||
news.className = "news";
|
||||
news.innerHTML = "<h3>Bienvenue dans la version finale de GSPC pour Pommultimédia For Home !</h3>Cette nouvelle version a été encore plus simplifiée et réduit les temps d'attente en préchargeant les données de manière asynchrone.<br />N'hésitez pas à nous faire part de vos commentaires. Bonne utilisation ;)";
|
||||
$('contenu').appendChild(news);
|
||||
}
|
||||
]]>
|
||||
</display>
|
||||
|
||||
<config value="table_bdd">gspc</config>
|
||||
</application>
|
||||
3
onyx2/include/applications/UDload/main.php
Normal file
3
onyx2/include/applications/UDload/main.php
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
<?php
|
||||
//Fichier appelé pour afficher l'application
|
||||
?>
|
||||
32
onyx2/include/applications/UDload/property.xml
Normal file
32
onyx2/include/applications/UDload/property.xml
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<application active="1">
|
||||
<property value="name">Transfert de fichiers</property>
|
||||
<property value="description">Cette application vous permet de transférer rapidement de petits fichiers et de les partager sur Internet.</property>
|
||||
<property value="dir">UDload</property>
|
||||
<property value="etatAvancement">final</property>
|
||||
<property value="version">1.0</property>
|
||||
<property value="lang">fr_FR</property>
|
||||
<property value="developpeur"><![CDATA[<span style="font-variant: small-caps">Mercier</span> Pierre-Olivier]]></property>
|
||||
<property value="js">
|
||||
<![CDATA[
|
||||
function runApplication(property, display, json)
|
||||
{
|
||||
formulaire = document.createElement("form");
|
||||
formfield = document.createElement("fieldset");
|
||||
labelfile = document.createElement("label");
|
||||
labelfile.innerHTML = "Fichier à uploader : ";
|
||||
formfield.appendChild(labelfile);
|
||||
inputfile = document.createElement("input");
|
||||
inputfile.name = "upfile";
|
||||
formulaire.appendChild(formfield);
|
||||
$('corps').appendChild(formulaire);
|
||||
}
|
||||
]]>
|
||||
</property>
|
||||
|
||||
<security default="connected" />
|
||||
|
||||
<display value="titre">download.png</display>
|
||||
|
||||
<config value="table_bdd">udload</config>
|
||||
</application>
|
||||
72
onyx2/include/applications/chat/main.php
Normal file
72
onyx2/include/applications/chat/main.php
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
//Fichier appelé pour afficher l'application
|
||||
if (isset($_POST['message']))
|
||||
{
|
||||
$message = strip_tags(trim(gpc("message", "post")));
|
||||
if (!empty($message) || $message == "0")
|
||||
{
|
||||
$bdd = new BDD();
|
||||
$bdd->escape($message);
|
||||
$bdd->query("INSERT INTO chat (id_membre, timestamp, message) VALUES (".$SESS->values['id_user'].", ".time().", '$message');");
|
||||
$bdd->deconnexion();
|
||||
}
|
||||
}
|
||||
elseif (isset($_POST['comm']))
|
||||
{
|
||||
$commande = strip_tags(trim(gpc("comm", "post")));
|
||||
if ($commande == "!clear")
|
||||
{
|
||||
if ($SESS->values["id_user"] == 1)
|
||||
{
|
||||
$bdd = new BDD();
|
||||
$bdd->query("DELETE FROM chat;");
|
||||
$bdd->deconnexion();
|
||||
$json["confirm"] = "Tous les messages ont été supprimés";
|
||||
}
|
||||
else
|
||||
$json["confirm"] = "Vous n'avez pas les autorisations nécessaires pour effacer les messages.";
|
||||
}
|
||||
elseif ($commande == "!online")
|
||||
{
|
||||
$users = Cache::read('chat_online');
|
||||
$json["confirm"] = "Actuellement en ligne :<ul>";
|
||||
foreach($users as $username => $time)
|
||||
{
|
||||
if (time()-30 < $time)
|
||||
$json["confirm"] .= "<li>$username</li>";
|
||||
}
|
||||
$json["confirm"] .= "</ul>";
|
||||
}
|
||||
elseif ($commande == "!help" || $commande == "!hlp" || $commande == "!aide")
|
||||
{
|
||||
$json["confirm"] = "<table><tr><th>Commande</th><th>Description</th></tr>
|
||||
<tr><td>!changeRefreshTime <ins>int</ins></td><td>Change le temps de rafraîchissement à <ins>int</ins> (milli)secondes</td></tr>
|
||||
<tr><td>!cls</td><td>Nettoie l'écran</td></tr>
|
||||
<tr><td>!clear</td><td>Supprime tous les messages enregistrés dans la base de données</td></tr>
|
||||
<tr><td>!help</td><td>Affiche cet aide</td></tr>
|
||||
<tr><td>!maj</td><td>Actualise les messages du chat</td></tr>
|
||||
<tr><td>!online</td><td>Montre les utilisateurs en ligne (ces 30 dernières secondes)</td></tr>
|
||||
<tr><td>!quit</td><td>Quitte le chat et affiche l'accueil</td></tr>
|
||||
<tr><td>!reset</td><td>Réaffiche les 15 derniers messages envoyés</td></tr>
|
||||
</table>";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Met à jour la liste des personnes en ligne
|
||||
$users = Cache::read('chat_online');
|
||||
$users[$SESS->values["username"]] = time();
|
||||
Cache::set('chat_online', $users);
|
||||
|
||||
if (!empty($_GET['time']))
|
||||
$time = intval(gpc("time"))." ORDER BY timestamp DESC";
|
||||
else
|
||||
$time = "0 ORDER BY timestamp DESC LIMIT 15";
|
||||
|
||||
$bdd = new BDD();
|
||||
$messages = $bdd->query("SELECT C.*, U.pseudo FROM chat C INNER JOIN users U ON U.id = C.id_membre WHERE C.timestamp > $time;");
|
||||
$bdd->deconnexion();
|
||||
|
||||
$json["messages"] = $messages;
|
||||
}
|
||||
?>
|
||||
121
onyx2/include/applications/chat/property.xml
Normal file
121
onyx2/include/applications/chat/property.xml
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<application active="1">
|
||||
<property value="name">Chat</property>
|
||||
<property value="description">Cette application vous permet de dialoguer facilement avec les autres personnes connectées.</property>
|
||||
<property value="dir">chat</property>
|
||||
<property value="etatAvancement">beta</property>
|
||||
<property value="version">1.0</property>
|
||||
<property value="lang">fr_FR</property>
|
||||
<property value="developpeur"><![CDATA[<span style="font-variant: small-caps">Mercier</span> Pierre-Olivier]]></property>
|
||||
<property value="js">
|
||||
<![CDATA[
|
||||
function runApplication(property, display, json)
|
||||
{
|
||||
formulaire = document.createElement("form");
|
||||
formulaire.onsubmit = sendMessage;
|
||||
formfield = document.createElement("fieldset");
|
||||
formfield.style.margin = "auto";
|
||||
labelmess = document.createElement("label");
|
||||
labelmess.innerHTML = "Message : ";
|
||||
labelmess.setAttribute("for", "message");
|
||||
formfield.appendChild(labelmess);
|
||||
inputmessage = document.createElement("input");
|
||||
inputmessage.name = "message";
|
||||
inputmessage.id = "message";
|
||||
inputmessage.size = "40";
|
||||
formfield.appendChild(inputmessage);
|
||||
formulaire.appendChild(formfield);
|
||||
$('corps').appendChild(formulaire);
|
||||
tableMessages = document.createElement("table");
|
||||
tableMessages.style.margin = "auto";
|
||||
tableMessages.style.width = "90%";
|
||||
theMess = document.createElement("thead");
|
||||
trMess = document.createElement("tr");
|
||||
thMess = document.createElement("th");
|
||||
thMess.innerHTML = "Date et heure";
|
||||
trMess.appendChild(thMess);
|
||||
thMess = document.createElement("th");
|
||||
thMess.innerHTML = "Message";
|
||||
trMess.appendChild(thMess);
|
||||
theMess.appendChild(trMess);
|
||||
tableMessages.appendChild(theMess);
|
||||
tboMess = document.createElement("tbody");
|
||||
tboMess.style.textAlign = "left";
|
||||
tboMess.id = "chat";
|
||||
tableMessages.appendChild(tboMess);
|
||||
$('corps').appendChild(tableMessages);
|
||||
|
||||
printEtat(0);
|
||||
chat_MAJ();
|
||||
}
|
||||
|
||||
function sendMessage()
|
||||
{
|
||||
if ($('message').value == "!cls")
|
||||
{
|
||||
chat_clearScreen();
|
||||
$('message').value = "";
|
||||
}
|
||||
else if ($('message').value == "!maj")
|
||||
{
|
||||
chat_refreshScreen();
|
||||
$('message').value = "";
|
||||
}
|
||||
else if ($('message').value == "!reset")
|
||||
{
|
||||
chat_reset();
|
||||
$('message').value = "";
|
||||
}
|
||||
else if ($('message').value == "!quit" || $('message').value == "!exit" || $('message').value == "!deco" || $('message').value == "!deconnexion")
|
||||
{
|
||||
first_page();
|
||||
}
|
||||
else if ($('message').value.toString().indexOf("!changerefreshtime ") == 0 || $('message').value.toString().indexOf("!changeRefreshtime ") == 0 || $('message').value.toString().indexOf("!changerefreshTime ") == 0 || $('message').value.toString().indexOf("!changeRefreshTime ") == 0)
|
||||
{
|
||||
split = $('message').value.toString().split(" ");
|
||||
$('message').value = "";
|
||||
chat_changeRefreshTime(split[1]);
|
||||
}
|
||||
else if ($('message').value == "!clear" || $('message').value == "!online" || $('message').value == "!help" || $('message').value == "!hlp" || $('message').value == "!aide")
|
||||
{
|
||||
chat_sendCommande($('message').value);
|
||||
$('message').value = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
new Ajax.Request(
|
||||
'ajax.php?d=action&a=chat',
|
||||
{
|
||||
method: 'post',
|
||||
parameters: {message: $('message').value},
|
||||
onSuccess: function(transport, json) {
|
||||
$('message').value = "";
|
||||
},
|
||||
onFailure: function() { if (confirm("La requête a échouée, voulez-vous réessayer de renvoyer votre message ?")) sendMessage(); }
|
||||
}
|
||||
);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function chat_MAJ()
|
||||
{
|
||||
var date = new Date();
|
||||
var newRow = $('chat').insertRow(0);
|
||||
var newCell = newRow.insertCell(0);
|
||||
newCell.innerHTML = '<em>JS</em> ' + (date.getHours()<10?"0"+date.getHours():date.getHours()) + ":" + (date.getMinutes()<10?"0"+date.getMinutes():date.getMinutes()) + ":" + (date.getSeconds()<10?"0"+date.getSeconds():date.getSeconds());
|
||||
newCell = newRow.insertCell(1);
|
||||
newCell.innerHTML = "<em>Connexion au chat</em>";
|
||||
$('message').focus();
|
||||
chat_refresh = setTimeout("chat_MAJ()", 150);
|
||||
}
|
||||
]]>
|
||||
</property>
|
||||
|
||||
<security default="connected" />
|
||||
|
||||
<display value="titre">chat.png</display>
|
||||
<display value="js">app.js</display>
|
||||
|
||||
<config value="table_bdd">chat</config>
|
||||
</application>
|
||||
13
onyx2/include/applications/users/main.php
Normal file
13
onyx2/include/applications/users/main.php
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
//Fichier appelé pour afficher l'application
|
||||
if (isset($_POST['message']))
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
$bdd = new BDD();
|
||||
$json["users"] = $bdd->query("SELECT * FROM users ORDER BY last_visite DESC;");
|
||||
$bdd->deconnexion();
|
||||
}
|
||||
?>
|
||||
36
onyx2/include/applications/users/property.xml
Normal file
36
onyx2/include/applications/users/property.xml
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<application active="1">
|
||||
<property value="name">Gestion des utilisateurs</property>
|
||||
<property value="description">Cette application permet de gérer les utilisateurs et les accès aux applications.</property>
|
||||
<property value="dir">users</property>
|
||||
<property value="etatAvancement">enconstruction</property>
|
||||
<property value="version">1.0</property>
|
||||
<property value="lang">fr_FR</property>
|
||||
<property value="developpeur"><![CDATA[<span style="font-variant: small-caps">Mercier</span> Pierre-Olivier]]></property>
|
||||
<property value="js">
|
||||
<![CDATA[
|
||||
function runApplication(property, display, json)
|
||||
{
|
||||
alert('pom');
|
||||
USERS_display("main", json)
|
||||
printEtat(0);
|
||||
}
|
||||
|
||||
function USERS_display(page, plus)
|
||||
{
|
||||
alert("USERS_display('" + page + "', " + plus + ");");
|
||||
USERS_liste = plus.users;
|
||||
setTimeout("USERS_display('" + page + "', false);", 100);
|
||||
}
|
||||
]]>
|
||||
</property>
|
||||
|
||||
<security type="users" default="restricted">
|
||||
<user>1</user>
|
||||
</security>
|
||||
|
||||
<display value="titre">utilisateurs.png</display>
|
||||
<display value="js">app.js</display>
|
||||
|
||||
<config value="table_bdd">users</config>
|
||||
</application>
|
||||
85
onyx2/include/functions.php
Normal file
85
onyx2/include/functions.php
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
if (!defined("ONYX"))
|
||||
exit;
|
||||
|
||||
define("APPSDIR", ONYX."include/applications/");
|
||||
define("PAGESDIR", ONYX."include/pages/");
|
||||
|
||||
function acces_application($application, $applicationXML = null)
|
||||
{
|
||||
global $SESS;
|
||||
|
||||
$autoriser = false;
|
||||
|
||||
if (empty($applicationXML))
|
||||
{
|
||||
$applicationXML = new DOMDocument();
|
||||
$applicationXML->load(APPSDIR.$application.'/property.xml');
|
||||
}
|
||||
|
||||
if ($applicationXML->documentElement->getAttribute('active') && ($applicationXML->getElementsByTagName('application') || $applicationXML->getElementsByTagName('page')))
|
||||
{
|
||||
foreach($applicationXML->getElementsByTagName('security') as $security)
|
||||
{
|
||||
//Autorisation par défaut
|
||||
if ($security->getAttribute('default') == "connected")
|
||||
$autoriser = !empty($SESS->values["connecte"]);
|
||||
elseif ($security->getAttribute('default') == "authorized")
|
||||
$autoriser = true;
|
||||
|
||||
//Méthode(s) d'autorisation(s)
|
||||
if (ereg("users", $security->getAttribute('type')) && !empty($SESS->values["username"]))
|
||||
{
|
||||
foreach($applicationXML->getElementsByTagName('user') as $user)
|
||||
{
|
||||
if (strtolower($user->textContent) == strtolower($SESS->values["id_user"]))
|
||||
return !$autoriser;
|
||||
}
|
||||
}
|
||||
if (ereg("usernames", $security->getAttribute('type')) && !empty($SESS->values["username"]))
|
||||
{
|
||||
foreach($applicationXML->getElementsByTagName('username') as $user)
|
||||
{
|
||||
if (strtolower($user->textContent) == strtolower($SESS->values["username"]))
|
||||
return !$autoriser;
|
||||
}
|
||||
}
|
||||
if (ereg("ips", $security->getAttribute('type')))
|
||||
{
|
||||
foreach($applicationXML->getElementsByTagName('ip') as $ip)
|
||||
{
|
||||
if ($ip->textContent == $_SERVER["REMOTE_ADDR"])
|
||||
return !$autoriser;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $autoriser;
|
||||
}
|
||||
|
||||
function send404(&$xml_root)
|
||||
{
|
||||
global $xml;
|
||||
|
||||
$xml_root->appendChild($xml->createElement("titre", "404.png"));
|
||||
$xml_root->appendChild($xml->createElement("body", "Page introuvable"));
|
||||
}
|
||||
|
||||
function send403(&$xml_root)
|
||||
{
|
||||
global $xml;
|
||||
|
||||
$xml_root->appendChild($xml->createElement("titre", "avertissements.png"));
|
||||
$xml_root->appendChild($xml->createElement("body", "<h2>Erreur 403</h2><h3>Vous n'êtes pas autorisé à accéder à cette page.</h3>Si vous êtes sur d'avoir le droit d'accèder à cette page et que le problème perciste, contacter l'administrateur."));
|
||||
}
|
||||
|
||||
if (!function_exists("json_encode"))
|
||||
{
|
||||
include_once(ONYX.'include/JSON.php');
|
||||
function json_encode($value, $option = 0)
|
||||
{
|
||||
$json = new Services_JSON();
|
||||
return $json->encode($value);
|
||||
}
|
||||
}
|
||||
?>
|
||||
30
onyx2/include/pages/aproposdusite.xml
Normal file
30
onyx2/include/pages/aproposdusite.xml
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<page active="1">
|
||||
<display value="titre">aproposdusite.png</display>
|
||||
<display value="body">
|
||||
<![CDATA[
|
||||
<h2>A propos de Pommultimedia for Home</h2>
|
||||
<h3>Pommultimedia for Home<br />
|
||||
Version 0.2 du 22/04/2011</h3>
|
||||
<h3>Ce site a été développé avec Emacs et Eclipse (plug-in Aptana) sur un serveur utilisant la technologie <a href="http://www.php.net/">PHP</a>.</h3>
|
||||
<br />
|
||||
<h3>Navigateurs conseillés : <a href="www.mozilla.org/firefox/">Mozilla Firefox</a> et <a href="http://www.google.com/chrome/">Google Chrome</a>.</h3>
|
||||
<br />
|
||||
<h3>Historique des versions :</h3>
|
||||
<h4>Version 0.2 du 22/04/2011</h4>
|
||||
<ul>
|
||||
<li>Factorisation du code JavaScript du framework</li>
|
||||
<li>La page connexion est maintenant une page à part entière</li>
|
||||
<li>Ajout du JavaScript aux pages</li>
|
||||
<li>Les items du menu font maintenant parti du fichier XML de chaque application, ce n'est plus dans le JavaScript</li>
|
||||
<li>Régénération de toutes les images d'en-tête : utilisation de la police du cahier des charges et toutes ont été générés</li>
|
||||
<li>Le JavaScript évalué ne fait plus parti des propriétés de l'application, il est dans l'affichage (d'où : accélération du chargement de la liste des applications sur la page d'accueil)</li>
|
||||
<li>Il peut y avoir plusieurs fichiers de scripts et de style par app, ils sont mieux déchargé à la fermeture de l'app</li>
|
||||
</ul>
|
||||
<h4>Version 0.1 du 04/08/2009</h4>
|
||||
Version initiale
|
||||
]]>
|
||||
</display>
|
||||
|
||||
<security default="authorized" />
|
||||
</page>
|
||||
63
onyx2/include/pages/connexion.xml
Normal file
63
onyx2/include/pages/connexion.xml
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<page active="1">
|
||||
<display value="titre">identification.png</display>
|
||||
<display value="body">
|
||||
<![CDATA[
|
||||
<h1>Bienvenue sur le serveur <em>Pommultimédia for home</em> !</h1>
|
||||
<h2>Pour vous connecter au serveur, veuillez indiquer votre nom d'utilisateur ainsi que votre mot de passe.</h2>
|
||||
<form action="#" method="post">
|
||||
<fieldset class="connexion">
|
||||
<label for="pseudo">Nom d'utilisateur :</label>
|
||||
<input type="text" id="pseudo" maxlength="32"><br>
|
||||
<label for="mdp">Mot de passe :</label>
|
||||
<input type="password" id="mdp" maxlength="32"><br>
|
||||
<input type="submit" value="Connexion">
|
||||
</fieldset>
|
||||
</form>
|
||||
<p id="erreur"></p>
|
||||
]]>
|
||||
</display>
|
||||
<display value="js">
|
||||
<![CDATA[
|
||||
function connexion(nom, pass)
|
||||
{
|
||||
printEtat(4);
|
||||
$('pseudo').disabled = "disabled";
|
||||
$('mdp').disabled = "disabled";
|
||||
new Ajax.Request(
|
||||
'ajax.php?d=connecte',
|
||||
{
|
||||
method: 'post',
|
||||
parameters: {name: nom, mdp: pass},
|
||||
onSuccess: function(transport, json)
|
||||
{
|
||||
if (json.statut == 1)
|
||||
{
|
||||
printEtat(2);
|
||||
username = nom.toLowerCase();
|
||||
page_accueil();
|
||||
}
|
||||
else
|
||||
{
|
||||
$('pseudo').disabled = "";
|
||||
$('mdp').disabled = "";
|
||||
$('pseudo').className = "erreur";
|
||||
$('mdp').className = "erreur";
|
||||
$('erreur').innerHTML = "Nom d'utilisateur ou mot de passe incorrect !";
|
||||
$('pseudo').focus();
|
||||
$('pseudo').select();
|
||||
printEtat(0);
|
||||
}
|
||||
},
|
||||
onFailure: function() { printEtat(3); }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
$('corps').getElementsByTagName("form")[0].onsubmit = function() { connexion($('pseudo').value, $('mdp').value); return false; };
|
||||
$('pseudo').focus();
|
||||
]]>
|
||||
</display>
|
||||
|
||||
<security default="authorized" />
|
||||
</page>
|
||||
Reference in a new issue