#1470 updated API & achievements tracker to latest live version
--HG-- branch : gsoc2012-achievementshg/feature/gsoc2013-dfighter
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/* Copyright (C) 2009 Winch Gate Property Limited
|
||||
*
|
||||
* This file is part of ryzom_api.
|
||||
* ryzom_api is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* ryzom_api is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with ryzom_api. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
$tick_cache_timeout = 60;
|
||||
|
||||
function ryzom_time_tick() {
|
||||
$fn = RYAPI_URL.'data/cache/game_cycle.ticks';
|
||||
$handle = fopen($fn, "r");
|
||||
$version = fread($handle, 1);
|
||||
$raw_tick = fread($handle, 4);
|
||||
fclose($handle);
|
||||
$arr = unpack("V", $raw_tick);
|
||||
$tick = $arr[1];
|
||||
return sprintf("%u", $tick & 0xffffffff);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Takes a computed ryzom time array and returns a SimpleXMLElement
|
||||
*/
|
||||
function ryzom_time_xml($rytime) {
|
||||
global $tick_cache_timeout;
|
||||
$out = ryzom_time_xml_without_cache($rytime);
|
||||
$filename = RYAPI_URL.'data/cache/game_cycle.ticks';
|
||||
$cache = $out->addChild('cache');
|
||||
$cache->addAttribute('created', filemtime($filename));
|
||||
$cache->addAttribute('expire', (filemtime($filename)+$tick_cache_timeout));
|
||||
return $out;
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,158 @@
|
||||
<?php
|
||||
|
||||
/* Copyright (C) 2012 Winch Gate Property Limited
|
||||
*
|
||||
* This file is part of ryzom_api.
|
||||
* ryzom_api is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* ryzom_api is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with ryzom_app. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
class ryActionClass {
|
||||
public $classname;
|
||||
public $instance;
|
||||
public $args;
|
||||
public $requires;
|
||||
|
||||
function __construct($classname, $instance, $args, $requires) {
|
||||
$this->classname = $classname;
|
||||
$this->instance = $instance;
|
||||
$this->args = $args;
|
||||
$this->requires = $requires;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class ryActionPage {
|
||||
|
||||
private static $classesArgs = array();
|
||||
private static $myClasses = array();
|
||||
private static $aliases = array();
|
||||
private static $messages;
|
||||
private static $haveMessage;
|
||||
protected static $id;
|
||||
|
||||
public $instanceName;
|
||||
public $myMethods = array();
|
||||
|
||||
function __construct() {
|
||||
}
|
||||
|
||||
function addMethods($child_class) {
|
||||
if (is_array($child_class)) {
|
||||
foreach ($child_class as $c_class)
|
||||
$this->myMethods = array_merge($this->myMethods, get_class_methods($c_class));
|
||||
} else {
|
||||
$this->myMethods = get_class_methods($child_class);
|
||||
}
|
||||
}
|
||||
|
||||
static function addClass($name, $classname, $args=array(), $requires=NULL) {
|
||||
self::$myClasses[$name] = new ryActionClass($classname, NULL, $args, $requires);
|
||||
}
|
||||
|
||||
static function addAlias($aliasname, $name) {
|
||||
self::$aliases[$aliasname] = $name;
|
||||
}
|
||||
|
||||
static function initInstance($listener) {
|
||||
$i = self::$myClasses[$listener];
|
||||
if (!$i->instance) {
|
||||
// requires
|
||||
if ($i->requires) {
|
||||
self::initInstance($i->requires);
|
||||
}
|
||||
if ($i->args)
|
||||
$i->instance = new $i->classname($listener, $i->args);
|
||||
else
|
||||
$i->instance = new $i->classname($listener);
|
||||
$i->instance->addMethods($i->classname);
|
||||
$i->instance->instanceName = $listener;
|
||||
|
||||
}
|
||||
return $i->instance;
|
||||
}
|
||||
|
||||
static function getInstance($listener) {
|
||||
return self::initInstance($listener);
|
||||
}
|
||||
|
||||
static function _addMSG($type='OK', $message='') {
|
||||
self::$messages[] = array($type, $message);
|
||||
return '';
|
||||
}
|
||||
|
||||
function addMSG($type='OK', $action='', $message='') {
|
||||
self::$messages[] = array($type, $message);
|
||||
$this->haveMessage = $action;
|
||||
return '';
|
||||
}
|
||||
|
||||
static function getMSGs() {
|
||||
return self::$messages;
|
||||
}
|
||||
|
||||
static function call($action, $url_params) {
|
||||
$action_params = explode('_', $action);
|
||||
|
||||
if (count($action_params) != 2)
|
||||
return self::_addMSG('ERR', 'Action call error : bad params of ['.$action.']');
|
||||
|
||||
list($listener, $call) = $action_params;
|
||||
if (array_key_exists($listener,self::$aliases))
|
||||
$listener = self::$aliases[$listener];
|
||||
|
||||
if (!array_key_exists($listener, self::$myClasses))
|
||||
return self::_addMSG('ERR', 'Action call error : class ['. $listener .'] not found');
|
||||
|
||||
$i = self::initInstance($listener);
|
||||
|
||||
if (in_array('action'.$call, $i->myMethods)) {
|
||||
$i->haveMessage = NULL;
|
||||
$ret = call_user_func(array($i, 'action'.$call), $url_params);
|
||||
if (!isset($_SESSION['last_action']) or $action != $_SESSION['last_action'])
|
||||
$_SESSION['last_action'] = $action;
|
||||
$msg = $i->haveMessage;
|
||||
if ($msg and ($msg != $action)) {
|
||||
$ret = self::call($msg, $url_params);
|
||||
return self::_addMSG('OK', $ret);
|
||||
}
|
||||
return self::_addMSG('OK', $ret);
|
||||
} else
|
||||
return self::_addMSG('ERR', 'Action call error : action ['. $call .'] of ['. $listener .'] not found');
|
||||
}
|
||||
}
|
||||
|
||||
function callAction($action) {
|
||||
$c = '';
|
||||
ryActionPage::call($action, ryzom_get_params());
|
||||
$msgs = ryActionPage::getMSGs();
|
||||
|
||||
foreach ($msgs as $msg) {
|
||||
if ($msg[0] == 'HEADER')
|
||||
$c .= $msg[1];
|
||||
}
|
||||
|
||||
foreach ($msgs as $msg) {
|
||||
if ($msg[0] == 'ERR')
|
||||
$c .= _s('message error', $msg[1]);
|
||||
else if ($msg[0] == 'MSG')
|
||||
$c .= _s('message', $msg[1]);
|
||||
else if ($msg[0] == 'WARNING')
|
||||
$c .= _s('message warning', $msg[1]);
|
||||
else if ($msg[0] != 'HEADER')
|
||||
$c .= $msg[1];
|
||||
}
|
||||
return $c;
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,998 @@
|
||||
<?php
|
||||
|
||||
/* Copyright (C) 2009 Winch Gate Property Limited
|
||||
*
|
||||
* This file is part of ryzom_api.
|
||||
* ryzom_api is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* ryzom_api is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with ryzom_api. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// setup bbCode formatter
|
||||
|
||||
bbCode::$ig = RYZOM_IG;
|
||||
|
||||
/**
|
||||
* Image proxy
|
||||
*/
|
||||
if(!defined('IMG_PROXY')){
|
||||
$url = 'http://'.$_SERVER['HTTP_HOST'].'/app_forum/tools/imageproxy.php';
|
||||
define('IMG_PROXY', $url);
|
||||
}
|
||||
if (!function_exists('proxy_image_url')) {
|
||||
function proxy_image_url($href, $attrs=''){
|
||||
return IMG_PROXY.'?'.($attrs != '' ? $attrs.'&' : '').'url='.urlencode($href);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
abstract class bbCodeParser {
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $_ig;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $tags_ignore;
|
||||
private $tags_block_open;
|
||||
private $tags_block_close;
|
||||
private $tags_ignore_depth;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $open_tags;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $last_closed_tag;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $current_tag;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $state;
|
||||
|
||||
/**
|
||||
* @param bool $ig if true, use ingame markup
|
||||
*/
|
||||
function __construct($ig) {
|
||||
$this->_ig = $ig;
|
||||
|
||||
// ignore bbcode between these tags
|
||||
$this->tags_ignore = array(
|
||||
'noparse', 'code',
|
||||
'url', 'img', 'mail', 'page', 'forum', 'topic', 'post', 'wiki', 'time', 'date'
|
||||
);
|
||||
|
||||
// these create block level html code, so '\n' or ' ' or '\t' around them needs to be cleared
|
||||
$this->tags_block_open = array('h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'quote', 'list', 'p');
|
||||
$this->tags_block_close = $this->tags_block_open;
|
||||
if ($this->_ig) {
|
||||
// ingame <p> is not block level when closing, so dont strip there
|
||||
$key = array_search('p', $this->tags_block_close, true);
|
||||
unset($this->tags_block_close[$key]);
|
||||
}
|
||||
|
||||
$this->state = array();
|
||||
|
||||
// reset internals
|
||||
$this->reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Format bbcode tag
|
||||
*
|
||||
* @param string $tag tag name
|
||||
* @param string $open open markup
|
||||
* @param string $close close markup
|
||||
* @param string $attr tag attributes
|
||||
* @param string $text text between tags
|
||||
*/
|
||||
abstract function format($tag, $open, $close, $attr, $text);
|
||||
|
||||
/**
|
||||
* Wrapper to call Child->format(...)
|
||||
*
|
||||
* @param array $tag assoc array with tag info
|
||||
* @return string
|
||||
*/
|
||||
function handle_tag($tag) {
|
||||
return $this->format($tag['tag'], $tag['open'], $tag['close'], $tag['attr'], $tag['text']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset internals
|
||||
*/
|
||||
function reset() {
|
||||
$this->current_tag = 0;
|
||||
$this->tags_ignore_depth = 0;
|
||||
|
||||
// 0'th position is used as result
|
||||
$this->open_tags = array(
|
||||
0 => array('tag' => '', 'open' => '', 'close' => '', 'attr' => '', 'text' => '')
|
||||
);
|
||||
|
||||
$this->last_closed_tag = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save working state
|
||||
*/
|
||||
private function _state_save() {
|
||||
$this->state[] = array($this->current_tag, $this->tags_ignore_depth, $this->open_tags, $this->last_closed_tag);
|
||||
$this->reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore working state
|
||||
*/
|
||||
private function _state_restore() {
|
||||
if (!empty($this->state)) {
|
||||
list($this->current_tag, $this->tags_ignore_depth, $this->open_tags, $this->last_closed_tag) = array_pop($this->state);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Main worker. Parse $text for bbCode tags
|
||||
*
|
||||
* NOTE: Text must already be safe for HTML, ie. treated with htmlspecialchars()
|
||||
*
|
||||
* @param string $text
|
||||
* @return string formatted string
|
||||
*/
|
||||
function bbcode($text) {
|
||||
$text = str_replace("\r\n", "\n", $text);
|
||||
|
||||
$split = preg_split('/(\[[a-zA-Z0-9_\/]*?(?:[= ].*?)?\])/', $text, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
|
||||
|
||||
foreach ($split as $chunk) {
|
||||
if (substr($chunk, 0, 1) == '[' && substr($chunk, -1, 1) == ']') {
|
||||
if (substr($chunk, 0, 2) == '[/') {
|
||||
$this->close($chunk);
|
||||
} else {
|
||||
$this->open($chunk);
|
||||
}
|
||||
} else {
|
||||
$this->text($chunk);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->result();
|
||||
}
|
||||
|
||||
/**
|
||||
* Push tag with args to stack
|
||||
* Do not strip whitespace because tag might be invalid
|
||||
*
|
||||
* @param string $chunk full tag string, eg. [tag=attr]
|
||||
*/
|
||||
function open($chunk) {
|
||||
list($tag, $attr) = $this->split_params($chunk);
|
||||
|
||||
// test for [noparse]
|
||||
if ($this->tags_ignore_depth > 0) {
|
||||
$this->text($chunk);
|
||||
} else {
|
||||
$this->current_tag++;
|
||||
// remember tag, attributes and complete string that was used in markup
|
||||
$this->open_tags[$this->current_tag] = array('tag' => $tag, 'attr' => $attr, 'open' => $chunk, 'close' => '', 'text' => '');
|
||||
}
|
||||
|
||||
if (in_array($tag, $this->tags_ignore)) {
|
||||
$this->tags_ignore_depth++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Close tag and call tag handler to format output
|
||||
*
|
||||
* @param $chunk full tag string, eg. [/tag]
|
||||
*/
|
||||
function close($chunk) {
|
||||
// extract tag name from [/name]
|
||||
$tag = strtolower(substr($chunk, 2, -1));
|
||||
|
||||
if ($this->tags_ignore_depth > 0 && in_array($tag, $this->tags_ignore)) {
|
||||
$this->tags_ignore_depth--;
|
||||
}
|
||||
|
||||
// stack underrun
|
||||
if ($this->current_tag < 0) {
|
||||
$this->text($chunk);
|
||||
return;
|
||||
}
|
||||
|
||||
// ignore block
|
||||
if ($this->tags_ignore_depth > 0) {
|
||||
$this->text($chunk);
|
||||
return;
|
||||
}
|
||||
|
||||
// tag mismatch
|
||||
if ($this->open_tags[$this->current_tag]['tag'] !== $tag) {
|
||||
// try to find first open tag for this
|
||||
$key = false;
|
||||
for ($i = $this->current_tag - 1; $i > 0; $i--) {
|
||||
if (isset($this->open_tags[$i]['tag']) && $this->open_tags[$i]['tag'] === $tag) {
|
||||
$key = $i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($key === false) {
|
||||
$this->text($chunk);
|
||||
return;
|
||||
}
|
||||
|
||||
// tag is open so we need to 'rewind' a bit
|
||||
for ($i = $this->current_tag; $i > $key; $i--) {
|
||||
$tmp_tag = $this->pop_stack();
|
||||
$this->text($tmp_tag['open'] . $tmp_tag['text']);
|
||||
}
|
||||
}
|
||||
|
||||
// close tag
|
||||
$open = $this->pop_stack();
|
||||
|
||||
// handle bbcode
|
||||
$open['close'] = $chunk;
|
||||
|
||||
$block_level = false;
|
||||
if (in_array($tag, $this->tags_block_open)) {
|
||||
$block_level = true;
|
||||
// for block level element, trim whitespace from inside tag
|
||||
// [tag]<ws>...text...<ws>[/tag]
|
||||
$open['text'] = $this->trim_ws($open['text']);
|
||||
}
|
||||
$result = $this->handle_tag($open);
|
||||
|
||||
// strip whitespace from text before tag 'text...<ws>[tag]'
|
||||
if ($block_level) {
|
||||
$ts = $this->rtrim_ws($this->open_tags[$this->current_tag]['text']);
|
||||
$this->open_tags[$this->current_tag]['text'] = $ts;
|
||||
}
|
||||
|
||||
$this->text($result);
|
||||
|
||||
$this->last_closed_tag = $open['tag'];
|
||||
}
|
||||
|
||||
function text($text) {
|
||||
// strip whitespace after closing '[/tag]<ws>...text'
|
||||
if (in_array($this->last_closed_tag, $this->tags_block_close)) {
|
||||
$text = $this->ltrim_ws($text);
|
||||
}
|
||||
$this->open_tags[$this->current_tag]['text'] .= $text;
|
||||
|
||||
$this->last_closed_tag = false;
|
||||
}
|
||||
|
||||
function result() {
|
||||
// close tags that are still open
|
||||
while ($this->current_tag > 0) {
|
||||
$open = $this->pop_stack();
|
||||
|
||||
if ($this->tags_ignore_depth > 0) {
|
||||
$this->tags_ignore_depth--;
|
||||
// need to reparse text that's after ignore tag
|
||||
$this->_state_save();
|
||||
$text = $open['open'] . $this->bbcode($open['text']);
|
||||
$this->_state_restore();
|
||||
} else {
|
||||
// tag was not closed proprely, include start tag with result
|
||||
$text = $open['open'] . $open['text'];
|
||||
}
|
||||
|
||||
$this->text($text);
|
||||
};
|
||||
|
||||
return $this->open_tags[0]['text'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Pop tag and text from stack and return them
|
||||
*
|
||||
* @return array [0] = tag, [1] = text
|
||||
*/
|
||||
function pop_stack() {
|
||||
// remove from stack
|
||||
$open = $this->open_tags[$this->current_tag];
|
||||
unset($this->open_tags[$this->current_tag]);
|
||||
$this->current_tag--;
|
||||
|
||||
return $open;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trim from end of string
|
||||
* 'text...\s{0,}\n{1}\s{0,}'
|
||||
*
|
||||
* @param string $ts
|
||||
* @return string
|
||||
*/
|
||||
function rtrim_ws($ts){
|
||||
// we want to get rid of all spaces/tabs, but only single \n, so rtrim($ts, " \t\n\r") would not work
|
||||
$ts = rtrim($ts, " \t");
|
||||
if (substr($ts, -1, 1) === "\n") {
|
||||
$ts = substr($ts, 0, -1);
|
||||
$ts = rtrim($ts, " \t");
|
||||
}
|
||||
return $ts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trim from start of string
|
||||
* '\s{0,}\n{1}...text'
|
||||
*
|
||||
* @param string $ts
|
||||
* @return string
|
||||
*/
|
||||
function ltrim_ws($ts){
|
||||
// we want to get rid of all spaces/tabs, but only single \n, so ltrim($ts, " \t\n\r") would not work
|
||||
$ts = ltrim($ts, " \t");
|
||||
if (substr($ts, 0, 1) === "\n") {
|
||||
$ts = substr($ts, 1);
|
||||
}
|
||||
return $ts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trim from both sides
|
||||
* '\s{0,}\n{1}...text...\s{0,}\n{1}\s{0,}
|
||||
*
|
||||
* @param string $ts
|
||||
* @return string
|
||||
*/
|
||||
function trim_ws($ts){
|
||||
$ts = $this->ltrim_ws($ts);
|
||||
$ts = $this->rtrim_ws($ts);
|
||||
return $ts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract tag parameters from [tag=params] or [tag key1=val1 key2=val2]
|
||||
*
|
||||
* @param type $tag
|
||||
* @return type
|
||||
*/
|
||||
function split_params($chunk) {
|
||||
if (substr($chunk, 0, 1) == '[') {
|
||||
$b = '\[';
|
||||
$e = '\]';
|
||||
} else {
|
||||
$b = '';
|
||||
$e = '';
|
||||
}
|
||||
// [1] [2] [3]
|
||||
if (preg_match('/^' . $b . '([\*a-zA-Z0-9]*?)' . '(=| )' . '(.*?)' . $e . '$/', $chunk, $match)) {
|
||||
$tagName = strtolower($match[1]);
|
||||
if ($match[2] == '=') {
|
||||
// = means single parameter
|
||||
$tagParam = $match[3];
|
||||
} else {
|
||||
// <space> means multiple parameters
|
||||
$tagParam = array();
|
||||
$args = preg_split('/[ ]/', $match[3], null, PREG_SPLIT_NO_EMPTY);
|
||||
foreach ($args as $arg) {
|
||||
$pairs = explode('=', $arg);
|
||||
// preg_replace will remove possible quotes around value
|
||||
if (isset($pairs[1])) {
|
||||
$tagParam[strtolower($pairs[0])] = preg_replace('@("|\'|)(.*?)\\1@', '$2', $pairs[1]);
|
||||
} else {
|
||||
$tagParam[] = preg_replace('@("|\'|)(.*?)\\1@', '$2', $pairs[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (substr($chunk, 0, 1) == '[' && substr($chunk, -1, 1) == ']') {
|
||||
$chunk = substr($chunk, 1, -1);
|
||||
}
|
||||
$tagName = strtolower($chunk);
|
||||
$tagParam = '';
|
||||
}
|
||||
return array($tagName, $tagParam);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class bbCode extends bbCodeParser {
|
||||
static $legacy_sync = 1348956841;
|
||||
static $legacy_shard = array(
|
||||
'ani' => 2363920179,
|
||||
'lea' => 2437578274,
|
||||
'ari' => 2358620001,
|
||||
);
|
||||
|
||||
static $ig = false;
|
||||
static $timezone = 'UTC';
|
||||
static $clock12h = false;
|
||||
static $shardid = false;
|
||||
static $lang = 'en';
|
||||
static $disabledTags = array();
|
||||
//
|
||||
const COLOR_P = '#d0d0d0'; // normal text
|
||||
//
|
||||
const COLOR_BBCODE_TAG = '#444444';
|
||||
|
||||
static function bbDisabled($tag) {
|
||||
return in_array(strtolower($tag), self::$disabledTags);
|
||||
}
|
||||
|
||||
static function getFontSize($value) {
|
||||
$size = 16;
|
||||
switch (strtolower($value)) {
|
||||
case '1': case 'xx-small': $size = 9; break;
|
||||
case '2': case 'x-small' : $size = 10; break;
|
||||
case '3': case 'small' : $size = 13; break;
|
||||
case '4': case 'medium' : $size = 16; break;
|
||||
case '5': case 'large' : $size = 18; break;
|
||||
case '6': case 'x-large' : $size = 24; break;
|
||||
case '7': case 'xx-large': $size = 32; break;
|
||||
//case '8': case 'smaller' : break;
|
||||
//case '9': case 'larger' : break;
|
||||
}
|
||||
return $size;
|
||||
}
|
||||
|
||||
static function bb_noparse($code) {
|
||||
return preg_replace(array('/\[/', '/\]/'), array('[', ']'), $code);
|
||||
}
|
||||
|
||||
static function bb_code($code) {
|
||||
return '<pre>' . self::bb_noparse($code) . '</pre>';
|
||||
}
|
||||
|
||||
static function bb_list($list) {
|
||||
$result = '';
|
||||
$list = str_replace("\n[", '[', $list);
|
||||
$result = '<ul>' . preg_replace('/\s*\[\*\]\s*/is', "</li><li>", $list) . '</li></ul>';
|
||||
return preg_replace('#<ul>\s*</li>#is', '<ul>', $result);
|
||||
}
|
||||
|
||||
static function bb_quote($author, $text) {
|
||||
if (self::$ig) {
|
||||
// prevents [color] tag to take over color
|
||||
$author = self::bb_color(self::COLOR_P, $author);
|
||||
$text = self::bb_color(self::COLOR_P, $text);
|
||||
// left/right border, top/bottom border height
|
||||
$l = '<td width="1" bgcolor="#888888" height="1"></td>';
|
||||
$r = '<td width="1" bgcolor="#888888" height="1"></td>';
|
||||
return // 98% gives bit padding on the right
|
||||
'<table width="98%" cellpadding="0" cellspacing="0" border="0">' .
|
||||
'<tr><td width="1" height="5"></td><td></td><td></td></tr>' . // top padding - no border
|
||||
'<tr>' . $l . '<td bgcolor="#888888"></td>' . $r . '</tr>' . // top border
|
||||
'<tr>' . $l . '<td bgcolor="#000000" l_margin="5" height="3"></td>' . $r . '</tr>' . // author top padding
|
||||
'<tr>' . $l . '<td bgcolor="#000000" l_margin="5">' . $author . '</td>' . $r . '</tr>' . // author
|
||||
'<tr>' . $l . '<td bgcolor="#000000" l_margin="5" height="2"></td>' . $r . '</tr>' . // author bottom padding
|
||||
'<tr>' . $l . '<td bgcolor="#555555" l_margin="10" height="3"></td>' . $r . '</tr>' . // quote top padding
|
||||
'<tr>' . $l . '<td bgcolor="#555555" l_margin="10">' . $text . '</td>' . $r . '</tr>' . // quote
|
||||
'<tr>' . $l . '<td bgcolor="#555555" l_margin="10" height="2"></td>' . $r . '</tr>' . // quote bottom padding
|
||||
'<tr>' . $l . '<td bgcolor="#888888"></td>' . $r . '</tr>' . // bottom border
|
||||
'<tr><td width="1" height="8"></td><td></td><td></td></tr>' . // bottom padding - no border
|
||||
'</table>';
|
||||
} else {
|
||||
return '' .
|
||||
'<div class="post-quote">' .
|
||||
'<cite>' . $author . '</cite>' .
|
||||
'<blockquote>' . $text . '</blockquote>' .
|
||||
'</div>';
|
||||
}
|
||||
}
|
||||
|
||||
static function bb_h($nr, $color, $text) {
|
||||
$tag = 'h' . $nr;
|
||||
|
||||
if (self::$ig) {
|
||||
if ($color != '') {
|
||||
$text = '<font color="' . $color . '">' . $text . '</font>';
|
||||
}
|
||||
return '<' . $tag . '>' . $text . '</' . $tag . '>';
|
||||
} else {
|
||||
if ($color != '') {
|
||||
$style = ' style="color: ' . $color . ';"';
|
||||
} else {
|
||||
$style = '';
|
||||
}
|
||||
return '<' . $tag . $style . '>' . $text . '</' . $tag . '>';
|
||||
}
|
||||
}
|
||||
|
||||
static function bb_url($href, $text) {
|
||||
// "http://..../" remove " if present
|
||||
if (substr($href, 0, 6) == '"') {
|
||||
if (substr($href, -6) == '"') {
|
||||
$href = substr($href, 6, -6);
|
||||
} else {
|
||||
$href = substr($href, 6);
|
||||
}
|
||||
}
|
||||
|
||||
if ($href == '')
|
||||
$href = $text;
|
||||
if ($text == '') {
|
||||
$text = $href;
|
||||
$text = wordwrap($text, 65, ' ', true);
|
||||
}
|
||||
|
||||
$disable = self::bbDisabled('url');
|
||||
// if not disabled and in ryzom and is proper url (<scheme>://<host>/)
|
||||
if (!$disable && self::$ig) {
|
||||
$url = @parse_url(strtolower($href));
|
||||
$disable = true;
|
||||
if (!empty($url['scheme']) && !empty($url['host'])) {
|
||||
if (in_array($url['scheme'], array('http', 'https'))) {
|
||||
if (in_array($url['host'], array('app.ryzom.com'))) {
|
||||
if (empty($url['query']) || stripos($url['query'], 'redirect') === false) {
|
||||
// http://atys.ryzom.com/
|
||||
// and does not contain redirect
|
||||
// - allow url in game browser
|
||||
$disable = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // !empty
|
||||
}// isRYZOM
|
||||
|
||||
if ($disable) {
|
||||
// empty href will give proper link color without 'underline' - perfect for 'disabled' links
|
||||
if ($href == '') {
|
||||
$text = '<a href="">' . $text . '</a>';
|
||||
} else {
|
||||
$href = wordwrap($href, 65, ' ', true);
|
||||
$text = wordwrap($text, 65, ' ', true);
|
||||
$text = '<a href="">' . $text . '</a> ' . self::bb_color(self::COLOR_BBCODE_TAG, '(' . $href . ')');
|
||||
}
|
||||
return $text;
|
||||
}
|
||||
|
||||
// make sure http:// (or ftp:// or mailto:// etc is present), if not, add it
|
||||
if (!preg_match('#://#', $href)) {
|
||||
$href = 'http://' . $href;
|
||||
}
|
||||
|
||||
return sprintf('<a href="%s"' . (self::$ig ? '' : ' target="_blank"') . '>%s</a>', $href, $text);
|
||||
}
|
||||
|
||||
static function bb_img($attr, $href) {
|
||||
if (self::bbDisabled('img')) {
|
||||
return self::bb_noparse('[img]' . $href . '[/img]');
|
||||
}
|
||||
// $href is treated with htmlspecialchars() so any & in url is &
|
||||
$href = str_replace('&', '&', $href);
|
||||
|
||||
// images from current server directly
|
||||
if ($attr=='src' || strstr($href, $_SERVER['HTTP_HOST']) !== false){
|
||||
return '<img src="' . $href . '" />';
|
||||
}
|
||||
$url = proxy_image_url($href);
|
||||
return '<a href="' . $url . '&no_proxy=1"><img src="' . $url . '" /></a>';
|
||||
}
|
||||
|
||||
static function bb_banner($lang, $ckey) {
|
||||
// $lang and $ckey should already be escaped for HTML, so urlencode() in here would double escape them
|
||||
// - channel it thru image proxy. proxy does caching better and uses '304 Not Modified' status
|
||||
$src = 'http://atys.ryzom.com/api/banner.php?ckey=' . $ckey . '&langid=' . $lang . '&size=500';
|
||||
return self::bb_img('', $src);
|
||||
}
|
||||
|
||||
static function bb_mail($user) {
|
||||
$url = 'http://' . $_SERVER['HTTP_HOST'] . '/app_mail/?page=compose/to/' . urlencode($user);
|
||||
return '<a href="' . $url . '">' . $user . '</a>';
|
||||
}
|
||||
|
||||
static function bb_profile($ptype, $pname) {
|
||||
// types from app_profile
|
||||
$types = array('user', 'player', 'npc', 'fauna', 'entity', 'source');
|
||||
$ptype = array_search($ptype, $types, true);
|
||||
// if type not found, then fall back to player
|
||||
if ($ptype === false)
|
||||
$ptype = 1;
|
||||
|
||||
$url = 'http://' . $_SERVER['HTTP_HOST'] . '/app_profile/?ptype=' . intval($ptype) . '&pname=' . urlencode($pname);
|
||||
return '<a href="' . $url . '">' . $pname . '</a>';
|
||||
}
|
||||
|
||||
static function bb_color($color, $str) {
|
||||
if ($color == '') {
|
||||
return $str;
|
||||
}
|
||||
|
||||
if (self::$ig) {
|
||||
return '<font color="' . $color . '">' . $str . '</font>';
|
||||
} else {
|
||||
return '<span style="color: ' . $color . ';">' . $str . '</span>';
|
||||
}
|
||||
}
|
||||
|
||||
static function bb_size($size, $str) {
|
||||
$size = self::getFontSize($size);
|
||||
|
||||
if (self::$ig) {
|
||||
return '<font size="' . $size . 'px">' . $str . '</font>';
|
||||
} else {
|
||||
return '<span style="font-size: ' . $size . 'px;">' . $str . '</span>';
|
||||
}
|
||||
}
|
||||
|
||||
static function bb_pre($str) {
|
||||
return '<pre>' . $str . '</pre>';
|
||||
}
|
||||
|
||||
static function bb_p($str) {
|
||||
return '<p>' . $str . '</p>';
|
||||
}
|
||||
|
||||
// Added by ulukyn. WebIg compatibility.
|
||||
static function bb_center($str) {
|
||||
if (self::$ig) {
|
||||
return '<table width="100%" cellpadding="0" cellspacing="0"><tr><td align="center" valign="middle">' . $str . '</td></tr></table>';
|
||||
} else {
|
||||
return '<div style="text-align: center;">' . $str . '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
/** Table format : (added by ulukyn)
|
||||
* A1| A2|A3
|
||||
* B1| B2 |B3
|
||||
* C1|C2 |C3
|
||||
*/
|
||||
static function bb_table($attr, $content) {
|
||||
$width = isset($attr['width'])?$attr['width']:'100%';
|
||||
$border = isset($attr['border'])?$attr['border']:'0';
|
||||
$bgcolor = isset($attr['bgcolor'])?' bgcolor="'.$attr['bgcolor'].'" ':'';
|
||||
$ret = '<table width="'.$width.'" border="'.$border.'" cellpadding="0" cellspacing="0" '.$bgcolor.' >';
|
||||
$lines = explode("\n", $content);
|
||||
foreach ($lines as $line) {
|
||||
if ($line) {
|
||||
$ret .= '<tr>';
|
||||
$cols = explode('|', $line);
|
||||
foreach ($cols as $text) {
|
||||
if (!$text)
|
||||
continue;
|
||||
$params = array('valign' => 'middle');
|
||||
if ($text[0] == '#') {
|
||||
$paramsdef = explode(' ', $text);
|
||||
$paramlist = substr(array_shift($paramsdef), 1);
|
||||
$paramlist = explode(',', $paramlist);
|
||||
foreach ($paramlist as $p) {
|
||||
list($name, $value) = explode('=', $p);
|
||||
$params[ _h(str_replace('"', '', $name))] = _h(str_replace('"', '', $value));
|
||||
}
|
||||
if ($paramsdef)
|
||||
$text = implode(' ', $paramsdef);
|
||||
}
|
||||
$param_html = '';
|
||||
foreach ($params as $name => $value)
|
||||
$param_html .= $name.'="'.$value.'" ';
|
||||
|
||||
if ($text && $text[0] == ' ' && $text[strlen($text)-1] == ' ')
|
||||
$align = 'center';
|
||||
else if ($text && $text[0] == ' ')
|
||||
$align = 'right';
|
||||
else
|
||||
$align = 'left';
|
||||
|
||||
$ret .= '<td '.$param_html.' align="'.$align.'">'.$text.'</td>';
|
||||
}
|
||||
$ret .= '</tr>';
|
||||
}
|
||||
}
|
||||
|
||||
$ret .= '</table>';
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
static function bb_page_link($page, $txt) {
|
||||
if ($page == '') {
|
||||
$page = $txt;
|
||||
}
|
||||
$tmp = explode('/', $page);
|
||||
foreach ($tmp as $k => $v) {
|
||||
$tmp[$k] = urlencode($v);
|
||||
}
|
||||
$url = 'http://' . $_SERVER['HTTP_HOST'] . '/app_forum/?page=' . join('/', $tmp);
|
||||
return '<a href="' . $url . '">' . $txt . '</a>';
|
||||
}
|
||||
|
||||
static function bb_forum_link($page, $id, $txt) {
|
||||
$page = $page . '/view/' . $id;
|
||||
if ($id == '') {
|
||||
$page.= $txt;
|
||||
}
|
||||
return self::bb_page_link($page, $txt);
|
||||
}
|
||||
|
||||
// Added by Ulukyn
|
||||
static function bb_wiki_link($page, $txt) {
|
||||
$need_new_txt = false;
|
||||
if ($page == '') {
|
||||
$page = $txt;
|
||||
$need_new_txt = true;
|
||||
}
|
||||
|
||||
if (substr($page, 0, 22) == 'http://atys.ryzom.com/')
|
||||
$url = 'http://atys.ryzom.com/start/app_wiki.php?page=' . substr($page, 21);
|
||||
else {
|
||||
$tmp = explode('/', $page);
|
||||
if (count($tmp) != 2) {
|
||||
return 'Syntax: [wiki]/[page], ex: en/Chronicles';
|
||||
} else {
|
||||
$wiki = $tmp[0];
|
||||
$page = $tmp[1];
|
||||
}
|
||||
if (self::$ig) {
|
||||
$url = 'http://atys.ryzom.com/start/app_wiki.php?page=/projects/pub' . $wiki . '/wiki/' . $page;
|
||||
}
|
||||
else
|
||||
$url = 'http://atys.ryzom.com/projects/pub' . $wiki . '/wiki/' . $page;
|
||||
if ($need_new_txt)
|
||||
$txt = 'WIKI [' . $page . ']';
|
||||
}
|
||||
return '<a href="' . $url . '"' . (self::$ig ? '' : ' target="_blank"') . '>' . $txt . '</a>';
|
||||
}
|
||||
|
||||
static function bb_biu($tag, $txt) {
|
||||
$tag = strtolower($tag);
|
||||
if (self::$ig) {
|
||||
switch ($tag) {
|
||||
// FIXME: darken/lighter or tint current color
|
||||
case 'b': $txt = self::bb_color('white', $txt);
|
||||
break;
|
||||
case 'i': $txt = self::bb_color('#ffffd0', $txt);
|
||||
break;
|
||||
case 'u': $txt = '<a href="ah:">' . self::bb_color(self::COLOR_P, $txt) . '</a>';
|
||||
break;
|
||||
default : $txt = self::bb_color(self::COLOR_BBCODE_TAG, $txt);
|
||||
break; // fallback
|
||||
}
|
||||
return $txt;
|
||||
}
|
||||
|
||||
switch ($tag) {
|
||||
case 'b': $tag = 'strong';
|
||||
break;
|
||||
case 'i': $tag = 'em';
|
||||
break;
|
||||
case 'u': $tag = 'u';
|
||||
break;
|
||||
default: $tag = 'span'; // fallback
|
||||
}
|
||||
return '<' . $tag . '>' . $txt . '</' . $tag . '>';
|
||||
}
|
||||
|
||||
static function bb_date($attr, $txt) {
|
||||
$time = strtotime($txt);
|
||||
|
||||
$shardid = isset($attr['shard']) ? $attr['shard'] : self::$shardid;
|
||||
if ($time === false || $shardid === false)
|
||||
return 'ERR:[' . $txt . ']';
|
||||
|
||||
if (isset(self::$legacy_shard[$shardid])) {
|
||||
$tick = self::$legacy_shard[$shardid];
|
||||
if (self::$legacy_sync > $time) {
|
||||
// only modify game cycle when asked time is before sync
|
||||
$tick = ($time - self::$legacy_sync) * 10 + $tick;
|
||||
}
|
||||
} else {
|
||||
$tick = ryzom_time_tick($shardid);
|
||||
// tick is for NOW, adjust it to match time given
|
||||
$now = time();
|
||||
$tick = ($time - $now) * 10 + $tick;
|
||||
}
|
||||
|
||||
$rytime = ryzom_time_array($tick, $shardid);
|
||||
$txt = ryzom_time_txt($rytime, self::$lang);
|
||||
|
||||
return $txt;
|
||||
}
|
||||
|
||||
static function bb_lang($attr, $txt) {
|
||||
if (_user()->lang == $attr)
|
||||
return $txt;
|
||||
else
|
||||
return '';
|
||||
}
|
||||
|
||||
static function bb_time($options, $txt) {
|
||||
$time = strtotime($txt);
|
||||
|
||||
if ($time == 0) {
|
||||
return $txt;
|
||||
}
|
||||
|
||||
$timezone = self::$timezone;
|
||||
|
||||
$show_time = '';
|
||||
$show_date = '';
|
||||
$show_timer = '';
|
||||
|
||||
if (is_array($options)) {
|
||||
foreach ($options as $key => $val) {
|
||||
switch ($key) {
|
||||
case 'timezone':
|
||||
// fix some timezones for php
|
||||
switch ($val) {
|
||||
case 'pst': // fall thru
|
||||
case 'pdt': $val = 'US/Pacific';
|
||||
break;
|
||||
}
|
||||
$timezone = $val;
|
||||
break;
|
||||
case 'date' :
|
||||
$show_date = $val == 'off' ? false : $val;
|
||||
break;
|
||||
case 'time' :
|
||||
$show_time = $val == 'off' ? false : $val;
|
||||
break;
|
||||
case 'timer':
|
||||
$show_timer = $val == 'off' ? false : $val;
|
||||
break;
|
||||
}//switch
|
||||
}//foreach
|
||||
}
|
||||
|
||||
$ret = array();
|
||||
|
||||
$old_timezone = date_default_timezone_get();
|
||||
@date_default_timezone_set($timezone);
|
||||
if ($show_date !== false) {
|
||||
$date = ryzom_absolute_time($time);
|
||||
//ryzom_absolute_time does not have year, so we need to add it
|
||||
$current_y = date('Y', time());
|
||||
$y = date('Y', $time);
|
||||
if ($y != $current_y) {
|
||||
$date.= ' ' . $y;
|
||||
}
|
||||
$ret[] = self::bb_color($show_date, $date);
|
||||
}
|
||||
if ($show_time !== false) {
|
||||
$fmtTime = self::$clock12h ? 'g:i:s a T' : 'H:i:s T';
|
||||
$ret[] = self::bb_color($show_time, date($fmtTime, $time));
|
||||
}
|
||||
date_default_timezone_set($old_timezone);
|
||||
|
||||
if ($show_timer !== false) {
|
||||
if ($show_time === false && $show_date === false) {
|
||||
$f = '%s';
|
||||
} else {
|
||||
$f = '(%s)';
|
||||
}
|
||||
$ret[] = self::bb_color($show_timer, sprintf($f, ryzom_relative_time($time)));
|
||||
}
|
||||
|
||||
return join(' ', $ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is called by bbCodeParser class
|
||||
*
|
||||
* @see bbCodeParser::format
|
||||
*/
|
||||
public function format($tag, $open, $close, $attr, $text) {
|
||||
// silly functions all have different parameters
|
||||
switch ($tag) {
|
||||
case 'noparse' :
|
||||
$result = self::bb_noparse($text);
|
||||
break;
|
||||
case 'code' :
|
||||
$result = self::bb_code($text);
|
||||
break;
|
||||
case 'quote' :
|
||||
$result = self::bb_quote($attr, $text);
|
||||
break;
|
||||
case 'h1' : // fall thru
|
||||
case 'h2' : // fall thru
|
||||
case 'h3' : // fall thru
|
||||
case 'h4' : // fall thru
|
||||
case 'h5' : // fall thru
|
||||
case 'h6' :
|
||||
$nr = (int) substr($tag, -1);
|
||||
$color = isset($attr['color']) ? $attr['color'] : '';
|
||||
$result = self::bb_h($nr, $color, $text);
|
||||
break;
|
||||
case 'color' :
|
||||
$result = self::bb_color($attr, $text);
|
||||
break;
|
||||
case 'size' :
|
||||
$result = self::bb_size($attr, $text);
|
||||
break;
|
||||
case 'list' :
|
||||
$result = self::bb_list($text);
|
||||
break;
|
||||
case 'img' :
|
||||
$result = self::bb_img($attr, $text);
|
||||
break;
|
||||
case 'banner' :
|
||||
$result = self::bb_banner($attr, $text);
|
||||
break;
|
||||
case 'pre' :
|
||||
$result = self::bb_pre($text);
|
||||
break;
|
||||
case 'p' :
|
||||
$result = self::bb_p($text);
|
||||
break;
|
||||
case 'table' :
|
||||
$result = self::bb_table($attr, $text);
|
||||
break;
|
||||
case 'center' :
|
||||
$result = self::bb_center($text);
|
||||
break;
|
||||
case 'url' :
|
||||
$result = self::bb_url($attr, $text);
|
||||
break;
|
||||
case 'mail' :
|
||||
$result = self::bb_mail($text);
|
||||
break;
|
||||
case 'profile' :
|
||||
$result = self::bb_profile($attr, $text);
|
||||
break;
|
||||
case 'page' :
|
||||
$result = self::bb_page_link($attr, $text);
|
||||
break;
|
||||
case 'forum' : // fall thru
|
||||
case 'topic' : // fall thru
|
||||
case 'post' :
|
||||
$result = self::bb_forum_link($tag, $attr, $text);
|
||||
break;
|
||||
case 'wiki' :
|
||||
$result = self::bb_wiki_link($attr, $text);
|
||||
break;
|
||||
case 'b' : // fall thru
|
||||
case 'i' : // fall thru
|
||||
case 'u' :
|
||||
$result = self::bb_biu($tag, $text);
|
||||
break;
|
||||
case 'time' :
|
||||
$result = self::bb_time($attr, $text);
|
||||
break;
|
||||
case 'date' :
|
||||
$result = self::bb_date($attr, $text);
|
||||
break;
|
||||
case 'lang' :
|
||||
$result = self::bb_lang($attr, $text);
|
||||
break;
|
||||
default :
|
||||
$result = $open . $text . $close;
|
||||
break;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces some BBcode with HTML code
|
||||
*
|
||||
* NOTE: $text should be already escaped for HTML
|
||||
*
|
||||
* @param string $text html escaped input text
|
||||
* @param array $disabledTags
|
||||
*/
|
||||
static function parse($text, $disabledTags = array()) {
|
||||
static $parser = null;
|
||||
if ($parser === null) {
|
||||
$parser = new self(self::$ig);
|
||||
}
|
||||
$parser->reset();
|
||||
|
||||
self::$disabledTags = $disabledTags;
|
||||
return $parser->bbcode($text);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
/* Copyright (C) 2012 Winch Gate Property Limited
|
||||
*
|
||||
* This file is part of ryzom_api.
|
||||
* ryzom_api is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* ryzom_api is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with ryzom_api. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// init database table used by webig
|
||||
$db = ryDB::getInstance('webig');
|
||||
$db->setDbDefs('players', array('id' => SQL_DEF_INT, 'cid' => SQL_DEF_INT, 'name' => SQL_DEF_TEXT, 'gender' => SQL_DEF_INT, 'creation_date' => SQL_DEF_DATE, 'deleted' => SQL_DEF_BOOLEAN, 'last_login' => SQL_DEF_TEXT, 'dev_shard' => SQL_DEF_BOOLEAN));
|
||||
$db->setDbDefs('accounts', array('uid' => SQL_DEF_INT, 'web_privs' => SQL_DEF_TEXT));
|
||||
|
||||
?>
|
@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
/* Copyright (C) 2009 Winch Gate Property Limited
|
||||
*
|
||||
* This file is part of ryzom_api.
|
||||
* ryzom_api is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* ryzom_api is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with ryzom_api. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
function getDirLinks($url_params, $path, $getvar, $home) {
|
||||
$ret = '';
|
||||
$dirs = explode('/', $path);
|
||||
$dirpath = '';
|
||||
$ret .= _l($home, $url_params, array($getvar => ''));
|
||||
foreach($dirs as $dirname) {
|
||||
if ($dirname) {
|
||||
$ret .= ' » '._l($dirname, $url_params, array($getvar => '/'.$dirpath.$dirname));
|
||||
$dirpath .= $dirname.'/';
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function isEmptyDir($dir)
|
||||
{
|
||||
if (($files = scandir($dir)) && count($files) <= 2) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
class ryDataFileManager {
|
||||
|
||||
public $id;
|
||||
public $log_dir;
|
||||
public $data_dir;
|
||||
public $user_dir;
|
||||
public $app_name;
|
||||
|
||||
function __construct($id, $app_name=APP_NAME) {
|
||||
$this->app_name = $app_name;
|
||||
$id = (strlen($id) == 0?'0':'').$id;
|
||||
$id = (strlen($id) == 1?'0':'').$id;
|
||||
$this->id = $id;
|
||||
$this->log_dir = RYAPP_PATH.$app_name.'/data/logs/';
|
||||
$this->data_dir = RYAPP_PATH.$app_name.'/data/app/';
|
||||
$this->user_dir = RYAPP_PATH.$app_name.'/data/chars/'.$id[0].'/'.$id[1].'/'.$id.'/';
|
||||
|
||||
if (!is_dir($this->user_dir))
|
||||
@mkdir($this->user_dir, 0777, true);
|
||||
|
||||
if (!is_dir($this->log_dir)) {
|
||||
@mkdir($this->log_dir, 0777, true);
|
||||
@mkdir($this->data_dir, 0777, true);
|
||||
}
|
||||
}
|
||||
|
||||
/*** Generic datafiles access methods ***/
|
||||
|
||||
function getData($name, $default=null) {
|
||||
if (file_exists($name))
|
||||
return unserialize(file_get_contents($name));
|
||||
if ($default !== NULL) {
|
||||
@file_put_contents($name, serialize($default));
|
||||
return $default;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
function saveData($name, $datas, $create_folders=true) {
|
||||
if ($create_folders) {
|
||||
if (!is_dir(dirname($name)))
|
||||
@mkdir(dirname($name), 0777, true);
|
||||
}
|
||||
if ($datas !== NULL)
|
||||
@file_put_contents($name, serialize($datas));
|
||||
else
|
||||
@unlink($name);
|
||||
}
|
||||
|
||||
function listDataFiles($dir) {
|
||||
$ret = array();
|
||||
if ($handle = @opendir($dir)) {
|
||||
while (false !== ($file = readdir($handle))) {
|
||||
if ($file != '.' && $file != '..' && $file[0] != '.')
|
||||
$ret[] = $file;
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/*** App Datas ***/
|
||||
|
||||
function loadAppData($name, $default=null) {
|
||||
return $this->getData($this->data_dir.$name, $default);
|
||||
}
|
||||
|
||||
function saveAppData($name, $datas, $create_folders=true) {
|
||||
return $this->saveData($this->data_dir.$name, $datas, $create_folders);
|
||||
}
|
||||
|
||||
function listAppDataFiles($basedir='') {
|
||||
return $this->listDataFiles($this->data_dir.$basedir);
|
||||
}
|
||||
|
||||
|
||||
/*** User Datas ***/
|
||||
|
||||
function loadUserData($name, $default=null) {
|
||||
return $this->getData($this->user_dir.$name, $default);
|
||||
}
|
||||
|
||||
function saveUserData($name, $datas, $create_folders=true) {
|
||||
return $this->saveData($this->user_dir.$name, $datas, $create_folders);
|
||||
}
|
||||
|
||||
function listUserDataFiles($basedir='') {
|
||||
return $this->listDataFiles($this->user_dir.$basedir);
|
||||
}
|
||||
|
||||
function loadUserDataFromApp($name, $app, $default=null) {
|
||||
$id = $this->id;
|
||||
$file = RYAPP_PATH.$app.'/data/chars/'.$id[0].'/'.$id[1].'/'.$id.'/'.$name;
|
||||
if (file_exists($file))
|
||||
return unserialize(file_get_contents($file));
|
||||
if ($default !== null)
|
||||
return $default;
|
||||
return null;
|
||||
}
|
||||
|
||||
function saveUserDataFromApp($name, $app, $datas) {
|
||||
$id = $this->id;
|
||||
$dir = RYAPP_PATH.$app.'/data/chars/'.$id[0].'/'.$id[1].'/'.$id.'/';
|
||||
if (!is_dir($dir))
|
||||
@mkdir($dir, 0777, true);
|
||||
file_put_contents($dir.$name, serialize($datas));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
@ -0,0 +1,680 @@
|
||||
<?php
|
||||
|
||||
/* Copyright (C) 2009 Winch Gate Property Limited
|
||||
*
|
||||
* This file is part of ryzom_api.
|
||||
* ryzom_api is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* ryzom_api is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with ryzom_api. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
include_once (RYAPI_PATH.'/common/ryformBases.php');
|
||||
|
||||
class ryVar extends basicRyForm {
|
||||
public $formName = '';
|
||||
public $varName = '';
|
||||
public $varValue = '';
|
||||
|
||||
function getFormDefs() {
|
||||
return array(
|
||||
new ryFormDef('varName', DEF_TYPE_TEXT),
|
||||
new ryFormDef('varValue', DEF_TYPE_TEXT),
|
||||
);
|
||||
}
|
||||
|
||||
function getHtmlRepr() {
|
||||
return $this->varName.' => '.$this->varValue;
|
||||
}
|
||||
}
|
||||
|
||||
class ryForm {
|
||||
|
||||
private $name = '';
|
||||
private $defines = array();
|
||||
private $template = '';
|
||||
|
||||
static private $forms;
|
||||
static private $ryformsIcons = array();
|
||||
|
||||
function __construct($dir, $name) {
|
||||
$this->name = $name;
|
||||
self::$forms[$dir.'/'.$name] = $this;
|
||||
}
|
||||
|
||||
static function addRyFormIcon($ryform_name, $icon) {
|
||||
self::$ryformsIcons[$ryform_name] = $icon;
|
||||
}
|
||||
|
||||
function addDefine($def) {
|
||||
$this->defines[$def->name] = $def;
|
||||
}
|
||||
|
||||
function setTemplate($template) {
|
||||
$this->template = $template;
|
||||
}
|
||||
|
||||
function getTemplate() {
|
||||
return $this->template;
|
||||
}
|
||||
|
||||
function addValue($name, $value) {
|
||||
if (array_key_exists($name, $this->defines))
|
||||
$this->defines[$name]->value = $value;
|
||||
else
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
function addExtraValues($name, $value) {
|
||||
if (array_key_exists($name, $this->defines))
|
||||
$this->defines[$name]->extraValues = $value;
|
||||
else
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
function getForm($params) {
|
||||
|
||||
if (isset($params['ryform_action']) && $params['ryform_action']) {
|
||||
$res = $this->doAction($params);
|
||||
return $res;
|
||||
}
|
||||
|
||||
if (@$params['validate'] == $this->name)
|
||||
return array(DATA_FORM_VALUES, $_POST);
|
||||
|
||||
if (isset($params['ryform_parent']))
|
||||
$parent_ryform_name = $params['ryform_parent'].'/';
|
||||
else
|
||||
$parent_ryform_name = '';
|
||||
|
||||
$action =_url(ryzom_get_params(), array('validate' => $this->name));
|
||||
$ret = '';
|
||||
$ret .= '<form action="'.$action.'" method="POST">'."\n";
|
||||
|
||||
if (!$this->getTemplate()) {
|
||||
$ret .= ' <table width="100%" cellpadding="0" cellspacing="0">'."\n";
|
||||
$ret .= ' '._s('t header', '<td height="24px">'._t('parameter').'</td><td>'._t('value').'</td><td></td>')."\n";
|
||||
$tmpl = '';
|
||||
} else {
|
||||
$tmpl = $this->getTemplate();
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
|
||||
foreach ($this->defines as $def_id => $def) {
|
||||
if ($def->name == 'name')
|
||||
$def->name = '_name';
|
||||
|
||||
$deffullname = $def->name;
|
||||
$url_params = ryzom_get_params();
|
||||
$type = $def->type;
|
||||
$infos = $def->infos;
|
||||
$value = ($def->value !== NULL)?$def->value:$def->defaultValue;
|
||||
|
||||
if (!is_object($value) && !is_array($value))
|
||||
$str_value = _h(strval($value));
|
||||
else
|
||||
$str_value = '';
|
||||
|
||||
if ($def->hidden)
|
||||
$type = DEF_TYPE_HIDDEN;
|
||||
|
||||
$hidden = false;
|
||||
$input = '';
|
||||
switch ($type) {
|
||||
|
||||
case DEF_TYPE_HIDDEN:
|
||||
$input = '<input type="hidden" name="'.$def->name.'" value="'.$str_value.'" />'."\n";
|
||||
$hidden = true;
|
||||
break;
|
||||
|
||||
case DEF_TYPE_TEXT:
|
||||
$input = '<input style="width:250px" type="text" name="'.$def->name.'" value="'.$str_value.'" size="25'.(_user()->ig?'0':'').'" />';
|
||||
break;
|
||||
case DEF_TYPE_NAMEID:
|
||||
$input = '<input style="width:250px" type="text" name="'.$def->name.'" value="'.getNameId($str_value).'" size="25'.(_user()->ig?'0':'').'" />';
|
||||
break;
|
||||
|
||||
case DEF_TYPE_ID:
|
||||
case DEF_TYPE_INT:
|
||||
case DEF_TYPE_FLOAT:
|
||||
$input = '<input style="width:100px" type="text" name="'.$def->name.'" value="'.$str_value.'" size="10'.(_user()->ig?'0':'').'" />';
|
||||
break;
|
||||
|
||||
case DEF_TYPE_BOOL:
|
||||
$input = '<select name="'.$def->name.'">'."\n";
|
||||
if ($value)
|
||||
$input .= '<option selected="selected" value="on">'._t('yes').'</option>'."\n".'<option value="off">'._t('no').'</option>';
|
||||
else
|
||||
$input .= '<option value="on">'._t('yes').'</option>'."\n".'<option selected="selected" value="off">'._t('no').'</option>';
|
||||
$input .= '</select>';
|
||||
break;
|
||||
|
||||
case DEF_TYPE_OPTION_FUNCTION:
|
||||
case DEF_TYPE_OPTION:
|
||||
if ($type == DEF_TYPE_OPTION)
|
||||
$options = $def->params;
|
||||
else {
|
||||
if (is_array($def->defaultValue))
|
||||
$options = call_user_func_array($def->params, $def->defaultValue);
|
||||
else
|
||||
$options = call_user_func($def->params);
|
||||
}
|
||||
$input = '<select name="'.$def->name.'">'."\n";
|
||||
$options_html = '';
|
||||
foreach ($options as $option => $text) {
|
||||
$option = strval($option);
|
||||
if ($option && $option[0] === '<' && $option[1] === '/')
|
||||
$options_html .= '</optgroup>';
|
||||
else if ($option && $option[0] === '<')
|
||||
$options_html .= '<optgroup label="'.$text.'">';
|
||||
else {
|
||||
if ($value !== NULL and (strval($value) == $option))
|
||||
$options_html .= '<option selected="selected" value="'.$option.'">'.$text.'</option>'."\n";
|
||||
else
|
||||
$options_html .= '<option value="'.$option.'">'.$text.'</option>'."\n";
|
||||
}
|
||||
}
|
||||
$input .= $options_html;
|
||||
$input .= '</select>';
|
||||
break;
|
||||
|
||||
case DEF_TYPE_COMBO_FUNCTION:
|
||||
case DEF_TYPE_COMBO:
|
||||
if ($type == DEF_TYPE_COMBO)
|
||||
$options = $def->params;
|
||||
else {
|
||||
if (is_array($def->defaultValue))
|
||||
$options = call_user_func_array($def->params, $def->defaultValue);
|
||||
else
|
||||
$options = call_user_func($def->params);
|
||||
}
|
||||
if (_user()->ig) {
|
||||
// TODO : try to do it with lua
|
||||
} else { // HTML 4
|
||||
$input .= '<input style="width:400px" type="text" id="'.$def->name.'" name="'.$def->name.'" value="'.$str_value.'" />
|
||||
<select onChange="combo(this, \''.$def->name.'\')" onMouseOut="comboInit(this, \''.$def->name.'\')" >';
|
||||
$options_html = '';
|
||||
$have_selected = false;
|
||||
foreach ($options as $option => $text) {
|
||||
if ($option && $option[0] === '<' && $option[1] === '/')
|
||||
$options_html .= '</optgroup>';
|
||||
else if ($option && $option[0] === '<')
|
||||
$options_html .= '<optgroup label="'.$text.'">';
|
||||
else {
|
||||
|
||||
if ($value and ($value == $option)) {
|
||||
$have_selected = true;
|
||||
$options_html .= '<option selected="selected" value="'.$option.'">'.$text.'</option>'."\n";
|
||||
} else
|
||||
$options_html .= '<option value="'.$option.'">'.$text.'</option>'."\n";
|
||||
}
|
||||
}
|
||||
if ($have_selected)
|
||||
$input .= '<option value=""></option>';
|
||||
else
|
||||
$input .= '<option selected="selected" value=""></option>';
|
||||
$input .= $options_html;
|
||||
$input .= '</select>';
|
||||
}
|
||||
break;
|
||||
|
||||
case DEF_TYPE_TEXTAREA:
|
||||
if (!$value)
|
||||
$value = "";
|
||||
$input = '<pre>'.($type == DEF_TYPE_BBCODE?'<font color="orange">- BBCode -</font><br />':'').'<textarea name="'.$def->name.'" rows="3">'._h($value).'</textarea></pre>';
|
||||
break;
|
||||
|
||||
case DEF_TYPE_TRAD:
|
||||
$base = '';
|
||||
$param = $def->name;
|
||||
$value = array_merge(array('en' => '', 'fr' => '', 'de' => '', 'ru' => '', 'es' => ''), $value);
|
||||
$base = ryzom_get_param('select_base', '');
|
||||
$edit = $display = $input_header = '';
|
||||
foreach (array('en', 'fr', 'de', 'ru', 'es') as $lang) {
|
||||
if (_user()->lang == $lang)
|
||||
$edit = _i($lang == 'en'?API_URL.'data/img/lang/us.png':API_URL.'data/img/lang/'.$lang.'.png').' <textarea style="width: 90%" rows="3" name="'.$param.'['.$lang.']">'._h($value[$lang]).'</textarea>';
|
||||
if ((!$base && $value[$lang]) || $base == $lang) {
|
||||
$base = $lang;
|
||||
$display = strtoupper($lang).' = <font color="orange">'.str_replace("\n", '<br />', _h($value[$lang])).'</font>';
|
||||
}
|
||||
$input .= '<input type="hidden" name="'.$param.'['.$lang.']" value="'.$value[$lang].'" />';
|
||||
$input_header .= _l(_i($lang == 'en'?API_URL.'data/img/lang/us.png':API_URL.'data/img/lang/'.$lang.'.png'), $url_params, array('select_base' => $lang)).' ';
|
||||
}
|
||||
|
||||
$input = $input_header.$input.' '.$display.'<br />'.$edit;
|
||||
break;
|
||||
|
||||
case DEF_TYPE_RYFORM:
|
||||
case DEF_TYPE_RYFORMS_ARRAY:
|
||||
$savedRyform = $value;
|
||||
if (is_array($savedRyform)) {
|
||||
$to_clean = array();
|
||||
foreach ($savedRyform as $id => $ryform) {
|
||||
if (!is_object($ryform))
|
||||
$to_clean[] = $id;
|
||||
}
|
||||
foreach ($to_clean as $id)
|
||||
unset($savedRyform[$id]);
|
||||
$savedRyform = array_values($savedRyform);
|
||||
} else if (is_object($savedRyform)) {
|
||||
$savedRyform = array($savedRyform);
|
||||
} else
|
||||
$savedRyform = array();
|
||||
|
||||
$input .= '<table width="100%" cellspacing="0" cellpadding="0" >';
|
||||
if ($savedRyform) {
|
||||
foreach ($savedRyform as $id => $ryform) {
|
||||
if (!is_object($ryform)) {
|
||||
p('!!! ERROR !!!', $ryform);
|
||||
continue;
|
||||
}
|
||||
$ryform->id = $id+1;
|
||||
if (!isset($ryform->formName) || !$ryform->formName)
|
||||
$ryform->formName = 'Element '.$id;
|
||||
if (count($savedRyform) > 1)
|
||||
$display_id = '<font size="12px" style="font-weight: bold; font-size: 14px" color="#FFAA55">'.strval(intval($id)+1).'</font>';
|
||||
else
|
||||
$display_id = '';
|
||||
|
||||
$script_up = ($id != 0)?_l(_i('16/arrow_up', _t('up')), $url_params, array('ryform_name' => $parent_ryform_name.$deffullname.':'.$id, 'ryform_action' => 'up')).' ':'';
|
||||
$script_down = ($id != count($savedRyform)-1)?_l(_i('16/arrow_down', _t('down')), $url_params, array('ryform_name' => $parent_ryform_name.$deffullname.':'.$id, 'ryform_action' => 'down')).' ':'';
|
||||
|
||||
$icon = (isset(self::$ryformsIcons[get_class($ryform)]))?self::$ryformsIcons[get_class($ryform)]:_i('32/brick');
|
||||
$input .= _s('t row '.($id%2),
|
||||
'<td width="36px">'._l(($def->type == DEF_TYPE_RYFORM?_i('16/arrow_redo', _t('change')):_i('16/add', _t('add'))), $url_params, array('ryform_name' => $parent_ryform_name.$deffullname.':'.strval(intval($id)+1), 'ryform_action' => 'list')).' '.$display_id.'</td>'.
|
||||
'<td width="10px">'.$script_up.$script_down.'</td>'.
|
||||
'<td ><table width="100%"><tr>
|
||||
<td width="40px">'.$icon.'</td>
|
||||
<td valign="middle" width="300px"><font size="12px" style="font-size: 13px;font-weight: bold;" color="#FFAA55">'.
|
||||
_l($ryform->formName, $url_params, array('ryform_name' => $parent_ryform_name.$deffullname.':'.$id, 'ryform_action' => 'edit')).' '.
|
||||
'</font><br />'._t(get_class($ryform).'_short_description').'</td>
|
||||
<td align="left" valign="middle" bgcolor="#000000">'.$ryform->getHtmlRepr().'</td>
|
||||
</tr></table><td width="70px" align="right">'.
|
||||
_l(_i('16/script_edit', _t('edit')), $url_params, array('ryform_name' => $parent_ryform_name.$deffullname.':'.$id, 'ryform_action' => 'edit')).' '.
|
||||
_l(_i('16/script_code', _t('edit_source')), $url_params, array('ryform_name' => $parent_ryform_name.$deffullname.':'.$id, 'ryform_action' => 'source')).' '.
|
||||
_l(_i('16/script_delete', _t('del')), $url_params, array('ryform_name' => $parent_ryform_name.$deffullname.':'.$id, 'ryform_action' => 'del')).'</td><td> </td>');
|
||||
}
|
||||
}
|
||||
$input .= '</table>';
|
||||
if (count($savedRyform) == 0 || $def->type != DEF_TYPE_RYFORM) {
|
||||
if (is_string($def->params))
|
||||
$infos = _l(_i('16/add', _t('add')), $url_params, array('new_ryform' => $def->params, 'ryform_name' => $parent_ryform_name.$deffullname.':0', 'ryform_action' => 'add'));
|
||||
else if (count($def->params) == 1)
|
||||
$infos = _l(_i('16/add', _t('add')), $url_params, array('new_ryform' => $def->params[0], 'ryform_name' => $parent_ryform_name.$deffullname.':0', 'ryform_action' => 'add'));
|
||||
else
|
||||
|
||||
$infos = _l(_i('16/add', _t('add')), $url_params, array('ryform_name' => $parent_ryform_name.$deffullname.':0', 'ryform_action' => 'list'));
|
||||
|
||||
if ($type == DEF_TYPE_RYFORMS_ARRAY)
|
||||
$infos .= ' '._l(_i('16/application_form_add', _t('multiadd')), $url_params, array('ryform_name' => $deffullname, 'ryform_action' => 'list_multiadd'));
|
||||
}
|
||||
break;
|
||||
|
||||
case DEF_TYPE_FUNCTION:
|
||||
if (is_array($def->defaultValue))
|
||||
list($result_type, $value) = call_user_func_array($def->params, $def->defaultValue);
|
||||
else
|
||||
list($result_type, $value) = call_user_func($def->params);
|
||||
if ($result_type == DATA_HTML_FORM) {
|
||||
return array(DATA_HTML_FORM, $value);
|
||||
} else {
|
||||
unset($url_params[$deffullname.'_action']);
|
||||
$input = $value;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
$input = '<input type="hidden" name="'.$def->name.'" value="'.$value.'" />'.$value."\n";
|
||||
$hidden = true;
|
||||
|
||||
}
|
||||
|
||||
if ($hidden)
|
||||
$ret .= $input;
|
||||
else
|
||||
{
|
||||
if ($tmpl) {
|
||||
$tmpl = str_replace('{'.$def->name.'}', '<font '.(_user()->ig?'color="orange" size="11"':'style="color:orange;"').'>'._t($def->prefixTrad.$def->name).'</font>', $tmpl);
|
||||
$tmpl = str_replace('{'.$def->name.'.input}', $input, $tmpl);
|
||||
$tmpl = str_replace('{'.$def->name.'.infos}', $infos, $tmpl);
|
||||
} else
|
||||
$ret .= _s('t row '.strval($i % 2), '<td height="32px" width="200px"> '.(!$def->optional?'*':'').($def->superAdmin?'##':'').($def->admin?'#':'')._t($def->prefixTrad.$def->name).'</td><td valign="center">'.$input.'</td><td>'.$infos.'</td>')."\n";
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($tmpl) {
|
||||
$tmpl = str_replace('{submit.input}', '<input type="submit" value="'._t('submit').'" />', $tmpl);
|
||||
$ret .= $tmpl;
|
||||
$ret .= '<table width="100%" cellspacing="0" cellpadding="0" ><tr>'._s('t row '.strval($i % 2), '<td height="32px"> '._t('required_fields').'</td><td></td><td align="middle"><input type="submit" value="'._t('submit').'" /></td>').'</tr></table>';
|
||||
} else {
|
||||
$ret .= _s('t row '.strval($i % 2), '<td height="32px"> '._t('required_fields').'</td><td></td><td><input type="submit" value="'._t('submit').'" /></td>');
|
||||
$ret .= '</table>';
|
||||
}
|
||||
$ret .= '</form><br />';
|
||||
return array(DATA_HTML_FORM, $ret."\n");
|
||||
}
|
||||
|
||||
|
||||
function doAction($url_params) {
|
||||
if (!$url_params['ryform_name'])
|
||||
return array(DATA_RYFORM_VALUE, array());
|
||||
$ret = '';
|
||||
$ryforms = explode('/', $url_params['ryform_name']);
|
||||
$this_ryform_name = array_shift($ryforms);
|
||||
list($ryform_name,$ryform_pos) = explode(':', $this_ryform_name);
|
||||
if (!isset($this->defines[$ryform_name]))
|
||||
return 'Bad ryform name';
|
||||
$def = $this->defines[$ryform_name];
|
||||
|
||||
if ($ryforms) {
|
||||
$action = 'edit';
|
||||
$next_action = $url_params['ryform_action'];
|
||||
} else {
|
||||
$action = $url_params['ryform_action'];
|
||||
$next_action = '';
|
||||
}
|
||||
|
||||
switch ($action) {
|
||||
case 'list':
|
||||
if (isset($url_params['ryform_parent']) && $url_params['ryform_parent'])
|
||||
$ryform_parent = $url_params['ryform_parent'].'/';
|
||||
else
|
||||
$ryform_parent = '';
|
||||
$ret .= '<table cellpadding="0" cellspacing="0" width="100%">';
|
||||
foreach ($def->params as $id => $ryform) {
|
||||
if (is_array($ryform)) {
|
||||
$ret .= _s('t row 1', '<td height="28px" width="22px" bgcolor='.ryzom_get_color_style('section').'></td><td bgcolor='.ryzom_get_color_style('section').'>'.ryzom_font(_t('ryform_cat_'.$id), '', '12').'</td><td bgcolor='.ryzom_get_color_style('section').'></td>');
|
||||
foreach ($ryform as $subid => $subryform) {
|
||||
$ret .= _s('t row '.($subid%2), '<td width="22px" height="34px">'.self::$ryformsIcons[$subryform].'</td><td> '.
|
||||
_l(_t($subryform.'_short_description'), $url_params, array('ryform_name' => $ryform_parent.$url_params['ryform_name'], 'ryform_action' => 'add', 'new_ryform' => $subryform)).'</td><td>'.$subryform.'</td>');
|
||||
}
|
||||
} else
|
||||
$ret .= _s('t row '.($id%2), '<td width="22px" height="34px">'.self::$ryformsIcons[$ryform].'</td><td> '.
|
||||
_l(_t($ryform.'_short_description'), $url_params, array('ryform_name' => $ryform_parent.$url_params['ryform_name'], 'ryform_action' => 'add', 'new_ryform' => $ryform)).'</td><td>'.$ryform.'</td>');
|
||||
}
|
||||
$ret .= '</table>';
|
||||
return array(DATA_HTML_FORM, $ret);
|
||||
break;
|
||||
|
||||
case 'list_multiadd':
|
||||
// TODO
|
||||
/*
|
||||
unset($url_params[$deffullname.'_action']);
|
||||
$ret .= '<table cellpadding="5"><tr>';
|
||||
foreach ($def->params as $ryform) {
|
||||
$ret .= '<td bgcolor="#000000">'._l($ryform, $url_params, array('ryform_action' => 'multiadd', 'new_ryform' => $ryform)).'</td>';
|
||||
}
|
||||
$ret .= '</tr></table>';
|
||||
return array(DATA_HTML_FORM, $ret);*/
|
||||
break;
|
||||
|
||||
case 'add':
|
||||
$new_ryform = ryzom_get_param('new_ryform');
|
||||
$valid_ryform = false;
|
||||
if ($new_ryform) {
|
||||
|
||||
if ((is_string($def->params) && $new_ryform == $def->params) || in_array($new_ryform, $def->params))
|
||||
$valid_ryform = true;
|
||||
else {
|
||||
foreach ($def->params as $param) {
|
||||
if (is_array($param) && in_array($new_ryform, $param))
|
||||
$valid_ryform = true;
|
||||
}
|
||||
}
|
||||
if (!$valid_ryform)
|
||||
return array(DATA_HTML_FORM, 'Bad ryform');
|
||||
|
||||
} else {
|
||||
$new_ryform = $def->params;
|
||||
}
|
||||
$ryform = new $new_ryform($new_ryform, '');
|
||||
$ryform->preSerialization();
|
||||
if ($def->type != DEF_TYPE_RYFORM) {
|
||||
p($def->value);
|
||||
if (!is_array($def->value))
|
||||
$savedRyform = array($def->value);
|
||||
else
|
||||
$savedRyform = $def->value;
|
||||
if ($ryform_pos === 0) {
|
||||
$value = array_values(array_merge(array($ryform), $savedRyform));
|
||||
} else if ($ryform_pos !== NULL) {
|
||||
$begin = array_slice($savedRyform, 0, $ryform_pos);
|
||||
$end = array_slice($savedRyform, $ryform_pos, count($savedRyform)-$ryform_pos);
|
||||
$value = array_values(array_merge($begin, array($ryform), $end));
|
||||
} else
|
||||
$value[] = $ryform;
|
||||
p($ryform_name, $value);
|
||||
//return array(DATA_RYFORM_VALUE, array('stages' => array()));
|
||||
return array(DATA_RYFORM_VALUE, array($ryform_name => $value));
|
||||
} else {
|
||||
p($ryform_name, $ryform);
|
||||
return array(DATA_RYFORM_VALUE, array($ryform_name => $ryform));
|
||||
}
|
||||
break;
|
||||
|
||||
case 'edit':
|
||||
$a_ryforms = $def->value;
|
||||
if (is_array($a_ryforms))
|
||||
$ryform = $a_ryforms[$ryform_pos];
|
||||
else
|
||||
$ryform = $a_ryforms;
|
||||
$ryform->postSerialization();
|
||||
$validate = isset($url_params['validate']) && $url_params['validate'];
|
||||
|
||||
$form = new ryForm('', $def->name);
|
||||
foreach ($ryform->getFormDefs() as $form_def) {
|
||||
$form->addDefine($form_def);
|
||||
$name = $form_def->name;
|
||||
// Init form with ryfom values
|
||||
if (property_exists($ryform, $name)) {
|
||||
$form->addValue($form_def->name, $ryform->$name);
|
||||
}
|
||||
}
|
||||
foreach ($ryform->getFormDefsExtraValues() as $def_name => $extra_values)
|
||||
$form->addExtraValues($def_name, $extra_values);
|
||||
$form->setTemplate($ryform->getTemplate());
|
||||
|
||||
list($result_type, $value) = $form->getForm(array('action' => $url_params['action'], 'script' => $url_params['script'], 'ryform_action' => $next_action, 'ryform_parent' => $this_ryform_name, 'ryform_name' => implode('/', $ryforms), 'validate' => $validate));
|
||||
if ($result_type == DATA_HTML_FORM) {
|
||||
return array(DATA_HTML_FORM, $value);
|
||||
} else {
|
||||
if ($result_type == DATA_FORM_VALUES)
|
||||
$value = $form->validateFormPost($value);
|
||||
$ryform->setFormParams($value);
|
||||
$ryform->preSerialization();
|
||||
|
||||
}
|
||||
if (is_array($a_ryforms))
|
||||
$a_ryforms[$ryform_pos] = $ryform;
|
||||
else
|
||||
$a_ryforms = $ryform;
|
||||
|
||||
$value = array($ryform_name => $a_ryforms);
|
||||
return array(DATA_RYFORM_VALUE, $value);
|
||||
break;
|
||||
|
||||
|
||||
case 'del':
|
||||
$id = $ryform_pos;
|
||||
p($def->value);
|
||||
if (!is_array($def->value))
|
||||
$def->value = array();
|
||||
else
|
||||
unset($def->value[$id]);
|
||||
$value = array_values($def->value);
|
||||
return array(DATA_RYFORM_VALUE, array($ryform_name => $value));
|
||||
break;
|
||||
|
||||
case 'up':
|
||||
$a_ryforms = $def->value;
|
||||
if (!is_array($a_ryforms))
|
||||
ryzom_redirect(_url($url_params, array('ryform_action' => '')));
|
||||
|
||||
$temp_ryform = $a_ryforms[$ryform_pos-1];
|
||||
$a_ryforms[$ryform_pos-1] = $a_ryforms[$ryform_pos];
|
||||
$a_ryforms[$ryform_pos] = $temp_ryform;
|
||||
$a_ryforms = array_values($a_ryforms);
|
||||
p($ryform_name, $a_ryforms);
|
||||
return array(DATA_RYFORM_VALUE, array($ryform_name => $a_ryforms));
|
||||
break;
|
||||
|
||||
case 'down':
|
||||
$a_ryforms = $def->value;
|
||||
if (!is_array($a_ryforms))
|
||||
ryzom_redirect(_url($url_params, array('ryform_action' => '')));
|
||||
|
||||
$temp_ryform = $a_ryforms[$ryform_pos+1];
|
||||
$a_ryforms[$ryform_pos+1] = $a_ryforms[$ryform_pos];
|
||||
$a_ryforms[$ryform_pos] = $temp_ryform;
|
||||
$a_ryforms = array_values($a_ryforms);
|
||||
return array(DATA_RYFORM_VALUE, array($ryform_name => $a_ryforms));
|
||||
break;
|
||||
|
||||
case 'source':
|
||||
$a_ryforms = $def->value;
|
||||
if (is_array($a_ryforms))
|
||||
$ryform = $a_ryforms[$ryform_pos];
|
||||
else
|
||||
$ryform = $a_ryforms;
|
||||
$ryform->postSerialization();
|
||||
|
||||
$form = new ryForm('', $def->name);
|
||||
$form->addDefine(new ryFormDef('ryform_source', DEF_TYPE_TEXTAREA, '', base64_encode(serialize($ryform))));
|
||||
$validate = isset($url_params['validate']) && $url_params['validate'];
|
||||
list($result_type, $value) = $form->getForm(array('ryform_action' => $next_action, 'ryform_parent' => $this_ryform_name, 'ryform_name' => implode('/', $ryforms), 'validate' => $validate));
|
||||
if ($result_type == DATA_HTML_FORM) {
|
||||
return array(DATA_HTML_FORM, $value);
|
||||
} else {
|
||||
if ($result_type == DATA_FORM_VALUES)
|
||||
$params = $form->validateFormPost($value);
|
||||
else
|
||||
$params = $value;
|
||||
$ryform = unserialize(base64_decode($params['ryform_source']));
|
||||
if (!is_object($ryform)) {
|
||||
unset($url_params['validate']);
|
||||
ryzom_redirect(_url($url_params, array('ryform_action' => '', 'message' => 'bad_paste')));
|
||||
}
|
||||
|
||||
$is_valid = false;
|
||||
p($def->params);
|
||||
foreach ($def->params as $id => $ryform_class) {
|
||||
if (is_array($ryform_class)) {
|
||||
if (in_array(get_class($ryform), array_values($ryform_class)))
|
||||
$is_valid = true;
|
||||
} else if (get_class($ryform) == $ryform_class)
|
||||
$is_valid = true;
|
||||
}
|
||||
if (!$is_valid) {
|
||||
p(get_class($ryform), $def->params);
|
||||
ryzom_redirect(_url($url_params, array($deffullname.'_action' => '', 'message' => 'not_valid_stage')));
|
||||
return;
|
||||
}
|
||||
if (is_array($a_ryforms))
|
||||
$a_ryforms[$ryform_pos] = $ryform;
|
||||
else
|
||||
$a_ryforms = $ryform;
|
||||
$value = array($ryform_name => $a_ryforms);
|
||||
return array(DATA_RYFORM_VALUE, $value);
|
||||
}
|
||||
return;
|
||||
break;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function validateFormPost($params, $use_default=true) {
|
||||
$final = array();
|
||||
foreach ($this->defines as $def) {
|
||||
$name = $def->name;
|
||||
if ($def->name == 'name')
|
||||
$def->name = '_name';
|
||||
|
||||
$type = $def->type;
|
||||
if ($def->hidden)
|
||||
$type = DEF_TYPE_HIDDEN;
|
||||
|
||||
if (isset($params[$def->name])) {
|
||||
$value = $params[$def->name];
|
||||
} else if (!$use_default) {
|
||||
continue;
|
||||
} else {
|
||||
$value = '';
|
||||
}
|
||||
|
||||
|
||||
switch ($type) {
|
||||
|
||||
case DEF_TYPE_HIDDEN:
|
||||
case DEF_TYPE_TEXT:
|
||||
case DEF_TYPE_OPTION:
|
||||
case DEF_TYPE_TEXTAREA:
|
||||
$final[$name] = $value;
|
||||
break;
|
||||
|
||||
case DEF_TYPE_TRAD:
|
||||
if (!$value[_user()->lang] && $value['europeanunion'])
|
||||
$value[_user()->lang] = $value['europeanunion'];
|
||||
$final[$name] = $value;
|
||||
break;
|
||||
|
||||
case DEF_TYPE_NAMEID:
|
||||
$final[$name] = cleanNameID($value);
|
||||
break;
|
||||
|
||||
case DEF_TYPE_COMBO:
|
||||
$final[$name] = $value;
|
||||
break;
|
||||
|
||||
case DEF_TYPE_ID:
|
||||
case DEF_TYPE_INT: // TODO
|
||||
$final[$name] = intval($value);
|
||||
break;
|
||||
case DEF_TYPE_FLOAT: // TODO
|
||||
$final[$name] = floatval($value);
|
||||
break;
|
||||
|
||||
case DEF_TYPE_BOOL:
|
||||
$final[$name] = $value == 'on';
|
||||
break;
|
||||
|
||||
case DEF_TYPE_RYFORM:
|
||||
if (is_array($value))
|
||||
$final[$name] = $value[0];
|
||||
break;
|
||||
case DEF_TYPE_RYFORMS_ARRAY:
|
||||
break;
|
||||
|
||||
default:
|
||||
$final[$name] = $value;
|
||||
|
||||
}
|
||||
}
|
||||
return $final;
|
||||
}
|
||||
|
||||
/*
|
||||
function reset() {
|
||||
|
||||
// Clean all temp files
|
||||
$userDatas = _tools()->listAppDataFiles($this->dir);
|
||||
foreach ($userDatas as $userData) {
|
||||
if (substr($userData, 0, strlen($this->name)) == $this->name)
|
||||
_tools()->saveAppData($this->dir.'/'.$userData, NULL);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,304 @@
|
||||
<?php
|
||||
|
||||
/* Copyright (C) 2012 Winch Gate Property Limited
|
||||
*
|
||||
* This file is part of ryzom_api.
|
||||
* ryzom_api is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* ryzom_api is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with ryzom_app. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
define('DEF_TYPE_UNKNOWN', 0);
|
||||
define('DEF_TYPE_HIDDEN', 1);
|
||||
define('DEF_TYPE_TEXT', 2);
|
||||
define('DEF_TYPE_ID', 3);
|
||||
define('DEF_TYPE_INT', 4);
|
||||
define('DEF_TYPE_FLOAT', 5);
|
||||
define('DEF_TYPE_BOOL', 6);
|
||||
define('DEF_TYPE_OPTION', 7);
|
||||
define('DEF_TYPE_TEXTAREA', 8);
|
||||
define('DEF_TYPE_TRAD', 9);
|
||||
define('DEF_TYPE_FORM', 10);
|
||||
define('DEF_TYPE_ICON', 11);
|
||||
define('DEF_TYPE_RYFORM', 12);
|
||||
define('DEF_TYPE_RYFORMS_ARRAY', 13);
|
||||
define('DEF_TYPE_BBCODE', 14);
|
||||
define('DEF_TYPE_FUNCTION', 15);
|
||||
define('DEF_TYPE_COMBO', 16);
|
||||
define('DEF_TYPE_OPTION_FUNCTION', 17);
|
||||
define('DEF_TYPE_NAMEID', 18);
|
||||
define('DEF_TYPE_COMBO_FUNCTION', 19);
|
||||
define('DEF_TYPE_DATE', 20);
|
||||
|
||||
|
||||
define('DEF_TYPE_ICON_UNKNOWN', 0);
|
||||
define('DEF_TYPE_ICON_SHARED', 1);
|
||||
define('DEF_TYPE_ICON_RYZITEM', 2);
|
||||
define('DEF_TYPE_ICON_URL', 3);
|
||||
|
||||
define('DATA_HTML_FORM', 0);
|
||||
define('DATA_FORM_VALUES', 1);
|
||||
define('DATA_FORM_VALID_VALUES', 2);
|
||||
define('DATA_RYFORM_VALUE', 3);
|
||||
|
||||
function cleanFormName($name) {
|
||||
$final_name = '';
|
||||
for ($i=0; $i<strlen($name); $i++) {
|
||||
$c = substr($name, $i, 1);
|
||||
if ( ((ord(strtolower($c)) >= ord('a')) && (ord(strtolower($c)) <= ord('z'))) ||
|
||||
(in_array($c, array('-', '.', '_'))) ||
|
||||
(ord(strtolower($c)) >= ord('0')) && (ord(strtolower($c)) <= ord('9')) )
|
||||
$final_name .= $c;
|
||||
}
|
||||
return $final_name;
|
||||
}
|
||||
|
||||
function cleanNameID($name) {
|
||||
$final_name = '';
|
||||
for ($i=0; $i<strlen($name); $i++) {
|
||||
$c = substr($name, $i, 1);
|
||||
if ($c == ' ' || $c == '_')
|
||||
$final_name .= '_';
|
||||
else if ( ((ord(strtolower($c)) >= ord('a')) && (ord(strtolower($c)) <= ord('z'))) ||
|
||||
(ord($c) >= ord('0')) && (ord($c) <= ord('9')) )
|
||||
$final_name .= $c;
|
||||
}
|
||||
return $final_name;
|
||||
}
|
||||
|
||||
function getNameId($name) {
|
||||
return str_replace('_', ' ', $name);
|
||||
}
|
||||
|
||||
function getTrad($value) {
|
||||
if ($value[_user()->lang])
|
||||
$trad = $value[_user()->lang];
|
||||
foreach (array('en', 'fr', 'de', 'ru', 'es') as $lang) {
|
||||
if ($value[$lang]) {
|
||||
$trad = $value[$lang];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (substr($trad, 0, 2) == '//')
|
||||
$trad = strstr(str_replace("\r", '', $trad), "\n");
|
||||
return substr($trad, 1);
|
||||
}
|
||||
|
||||
function setRyformSource($object, $src, $indent=0, $protecteds=array()) {
|
||||
$c = '';
|
||||
$src = str_replace("\r", '', $src);
|
||||
$ssrc = explode("\n", $src);
|
||||
$mode = 'var';
|
||||
$cache = '';
|
||||
$current_ryform = NULL;
|
||||
foreach ($ssrc as $line) {
|
||||
if (!$line)
|
||||
continue;
|
||||
if ($mode != 'ryform')
|
||||
$c .= str_repeat("\t", $indent);
|
||||
switch ($mode) {
|
||||
case 'ryform':
|
||||
if ($line[0] == "\t") {
|
||||
$cache .= substr($line, 1)."\n";
|
||||
break;
|
||||
} else {
|
||||
$mode = 'array';
|
||||
}
|
||||
|
||||
case 'array':
|
||||
if ($line == ')' || $line == '}') {
|
||||
if ($cache && $current_ryform) {
|
||||
$c .= $current_ryform->setSource($cache, $indent+1);
|
||||
$c .= 'SET SOURCE ';
|
||||
if ($line == ')')
|
||||
$array[] = $current_ryform;
|
||||
else
|
||||
$array = $current_ryform;
|
||||
}
|
||||
if (array_key_exists($var_name, $protecteds))
|
||||
call_user_func(array($object, $protecteds[$var_name]), $array);
|
||||
else
|
||||
$object->$var_name = $array;
|
||||
$mode = 'var';
|
||||
$cache = '';
|
||||
continue;
|
||||
} else if ($line[0] == '[') {
|
||||
if ($cache && $current_ryform) {
|
||||
$c .= $current_ryform->setSource($cache, $indent+1);
|
||||
$array[] = $current_ryform;
|
||||
$c .= 'SET SOURCE ';
|
||||
}
|
||||
$ryform_name = substr($line, 1, strlen($line)-2);
|
||||
$c .= 'New Ryform: '.$ryform_name."\n";
|
||||
$cache = '';
|
||||
$current_ryform = new $ryform_name();
|
||||
$mode = 'ryform';
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
$sep = strpos($line, '=');
|
||||
if ($sep) {
|
||||
$var_name = substr($line, 0, $sep-1);
|
||||
$value = substr($line, $sep+2);
|
||||
if ($value == '(' || $value == '{') {
|
||||
$c .= $var_name.' is ARRAY'."\n";
|
||||
$mode = 'array';
|
||||
$array = array();
|
||||
} else {
|
||||
$c .= $var_name .' = '.$value."\n";
|
||||
if ($value[0] == '\'' && $value[strlen($value)-1] == '\'')
|
||||
$object->$var_name = str_replace('\n', "\n", substr($value, 1, -1));
|
||||
else {
|
||||
if (is_numeric($value))
|
||||
$object->$var_name = eval('return '.$value.';');
|
||||
else if ($value == 'false')
|
||||
$object->$var_name = false;
|
||||
else if ($value == 'true')
|
||||
$object->$var_name = true;
|
||||
else if ($value == 'NULL')
|
||||
$object->$var_name = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $c;
|
||||
}
|
||||
|
||||
interface iRyForm {
|
||||
function getForm($url_params);
|
||||
function setFormParams($params);
|
||||
function getHtmlRepr();
|
||||
function getFormDefs();
|
||||
function getFormDefsExtraValues();
|
||||
function preSerialization();
|
||||
function postSerialization($vars=array());
|
||||
function getTemplate();
|
||||
}
|
||||
|
||||
class ryFormDef {
|
||||
|
||||
public $name = '';
|
||||
public $type = DEF_TYPE_UNKNOWN;
|
||||
public $params = array();
|
||||
public $infos = '';
|
||||
public $defaultValue = NULL;
|
||||
public $value = NULL;
|
||||
public $extraValues = array();
|
||||
public $hidden = false;
|
||||
public $optional = false;
|
||||
public $admin = false;
|
||||
public $superAdmin = false;
|
||||
public $prefixTrad = '';
|
||||
|
||||
function __construct($name, $type, $params=array(), $defaultValue=NULL, $optional=false, $infos='') {
|
||||
$this->name = $name;
|
||||
$this->type = $type;
|
||||
$this->params = $params;
|
||||
$this->defaultValue = $defaultValue;
|
||||
$this->optional = $optional;
|
||||
$this->infos = $infos;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class basicRyForm implements iRyForm {
|
||||
public $formName = ''; // Used by Form
|
||||
public $id = 0;
|
||||
|
||||
function __construct($name='', $title='') {
|
||||
}
|
||||
|
||||
function getForm($url_params) {
|
||||
$form = new ryForm($this->formName);
|
||||
$form_defs = $this->getFormDefs();
|
||||
foreach ($form_defs as $def)
|
||||
$form->addDefine($def);
|
||||
return $form->getForm(_s('section', $this->formName.' ('.get_class($this).')'));
|
||||
}
|
||||
|
||||
function setFormParams($params) {
|
||||
foreach ($params as $name => $value) {
|
||||
if (property_exists($this, $name))
|
||||
$this->$name = $value;
|
||||
}
|
||||
}
|
||||
|
||||
function getHtmlRepr() {
|
||||
return $this->formName.' ('.get_class($this).')';
|
||||
}
|
||||
|
||||
function getFormDefs() {
|
||||
return array();
|
||||
}
|
||||
|
||||
function getFormDefsExtraValues() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/*function preSerialization() {
|
||||
unset($this->tools);
|
||||
}*/
|
||||
|
||||
function preSerialization() {
|
||||
$all_defs = array('class_name');
|
||||
$this->author = _user()->id;
|
||||
foreach ($this->getFormDefs() as $def)
|
||||
$all_defs[] = $def->name;
|
||||
|
||||
foreach (get_object_vars($this) as $name => $value) {
|
||||
if (!in_array($name, $all_defs))
|
||||
unset($this->$name);
|
||||
}
|
||||
}
|
||||
|
||||
function postSerialization($vars=array()) {
|
||||
}
|
||||
|
||||
function getTemplate() {
|
||||
return '';
|
||||
}
|
||||
|
||||
function getSource($indent=0) {
|
||||
$attrs = $this->getFormDefs();
|
||||
$c = str_repeat("\t", $indent-1).'['.get_class($this).']'."\n";
|
||||
foreach ($attrs as $attr) {
|
||||
$c .= str_repeat("\t", $indent).$attr->name.' ';
|
||||
$var = $this->{$attr->name};
|
||||
if (is_object($var)) {
|
||||
$c .= "= {\n".substr($var->getSource($indent+1), 0, -1)."\n".str_repeat("\t", $indent).'}';
|
||||
} else if (is_array($var)) {
|
||||
$c .= '= ('."\n";
|
||||
foreach ($var as $element) {
|
||||
if (is_object($element))
|
||||
$c .= $element->getSource($indent+1);
|
||||
else if ($element)
|
||||
$c .= '#'.str_replace("\r", '', str_replace("\n", '\\\\n', var_export($element, true)));
|
||||
}
|
||||
$c .= str_repeat("\t", $indent).")";
|
||||
} else
|
||||
$c .= '= '.str_replace("\r", '', str_replace("\n", '\\\\n', var_export($var, true)));
|
||||
$c .= "\n";
|
||||
}
|
||||
return $c;
|
||||
}
|
||||
|
||||
function setSource($src, $indent=0) {
|
||||
$this->preSerialization();
|
||||
return setRyformSource($this, $src, $indent);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,130 @@
|
||||
<?php
|
||||
/* Copyright (C) 2009 Winch Gate Property Limited
|
||||
*
|
||||
* This file is part of ryzom_api.
|
||||
* ryzom_api is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* ryzom_api is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with ryzom_api. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* Basic constants */
|
||||
/* 1 IG hour = 3 IRL minutes = 1800 ticks */
|
||||
define('RYTIME_HOUR_TICKS', 1800);
|
||||
define('RYTIME_DAY_HOURS', 24);
|
||||
define('RYTIME_SEASON_DAYS', 90);
|
||||
define('RYTIME_MONTH_DAYS', 30);
|
||||
define('RYTIME_CYCLE_MONTHS', 12);
|
||||
define('RYTIME_JY_CYCLES', 4);
|
||||
define('RYTIME_WEEK_DAYS', 6);
|
||||
/* 0 = spring, 1 = summer, 2 = automn, 3 = winter */
|
||||
define('RYTIME_CYCLE_SEASONS', 4);
|
||||
/* Tick is offset on server of 61 days. */
|
||||
define('RYTIME_TICK_OFFSET', 61 * RYTIME_DAY_HOURS * RYTIME_HOUR_TICKS);
|
||||
|
||||
define('RYTIME_START_JY', 2568);
|
||||
|
||||
/* Helpers */
|
||||
define('RYTIME_CYCLE_DAYS',RYTIME_CYCLE_MONTHS * RYTIME_MONTH_DAYS);
|
||||
define('RYTIME_JY_DAYS', RYTIME_CYCLE_DAYS * RYTIME_JY_CYCLES);
|
||||
define('RYTIME_JY_MONTHS', RYTIME_CYCLE_MONTHS * RYTIME_JY_CYCLES);
|
||||
|
||||
// Takes a server tick and returns a computed array
|
||||
function ryzom_time_array($tick) {
|
||||
$out = array();
|
||||
$out["server_tick"] = $tick;
|
||||
|
||||
$time_in_hours = ($tick-RYTIME_TICK_OFFSET) / RYTIME_HOUR_TICKS;
|
||||
$day = $time_in_hours / RYTIME_DAY_HOURS;
|
||||
|
||||
$out["jena_year"] = floor($day / RYTIME_JY_DAYS) + RYTIME_START_JY;
|
||||
if ($day < 0) $day = RYTIME_JY_DAYS - abs($day) % RYTIME_JY_DAYS;
|
||||
$out["day_of_jy"] = $day % RYTIME_JY_DAYS;
|
||||
$out["month_of_jy"] = floor($out["day_of_jy"] / RYTIME_MONTH_DAYS);
|
||||
|
||||
$out["cycle"] = floor($out["day_of_jy"] / RYTIME_CYCLE_DAYS);
|
||||
$out["day_of_cycle"] = $day % RYTIME_CYCLE_DAYS;
|
||||
$out["month_of_cycle"] = $out["month_of_jy"] % RYTIME_CYCLE_MONTHS;
|
||||
|
||||
$out["day_of_month"] = $out["day_of_jy"] % RYTIME_MONTH_DAYS;
|
||||
$out["day_of_week"] = $day % RYTIME_WEEK_DAYS;
|
||||
|
||||
$out["season"] = ($day / RYTIME_SEASON_DAYS) % RYTIME_CYCLE_SEASONS;
|
||||
$out["day_of_season"] = $day % RYTIME_SEASON_DAYS;
|
||||
|
||||
$out["time_of_day"] = abs($time_in_hours) % RYTIME_DAY_HOURS;
|
||||
if ($time_in_hours < 0 && $out["time_of_day"]) $out["time_of_day"] = RYTIME_DAY_HOURS - $out["time_of_day"];
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
function ryzom_time_xml_without_cache($rytime) {
|
||||
$out = new SimpleXMLElement('<shard_time/>');
|
||||
foreach($rytime as $key => $value) {
|
||||
$out->addChild($key, $value);
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Take number of the month (0-11) and returns its name
|
||||
*/
|
||||
function ryzom_month_name($month_number) {
|
||||
if ($month_number < 0 || $month_number > 11) return "bad month";
|
||||
|
||||
$RYTIME_MONTHS = array(
|
||||
'Winderly', 'Germinally', 'Folially', 'Floris',
|
||||
'Medis', 'Thermis', 'Harvestor', 'Frutor',
|
||||
'Fallenor', 'Pluvia', 'Mystia', 'Nivia'
|
||||
);
|
||||
|
||||
return $RYTIME_MONTHS[(int)$month_number];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Take number of the day of week (0-5) and returns its name
|
||||
*/
|
||||
function ryzom_day_name($day_number) {
|
||||
if ($day_number < 0 || $day_number > 5) return "bad day of week";
|
||||
|
||||
$RYTIME_DAYS = array(
|
||||
'Prima', 'Dua', 'Tria',
|
||||
'Quarta', 'Quinteth', 'Holeth'
|
||||
);
|
||||
|
||||
return $RYTIME_DAYS[(int)$day_number];
|
||||
}
|
||||
|
||||
/**
|
||||
* Take a computed ryzom time array and returns the formatted date
|
||||
* (Official 2004 Format without trailing JY)
|
||||
*/
|
||||
function ryzom_time_txt($rytime, $lang = "en") {
|
||||
if ($lang != "en" && $lang != "fr" && $lang != "de") $lang = "en";
|
||||
|
||||
$RYTIME_AC = array(
|
||||
"de" => array("1. AZ", "2. AZ", "3. AZ", "4. AZ"),
|
||||
"en" => array("1st AC", "2nd AC", "3rd AC", "4th AC"),
|
||||
"fr" => array("1er CA", "2e CA", "3e CA", "4e CA")
|
||||
);
|
||||
|
||||
# Day, Month DayOfMonth, CycleNth AC JY
|
||||
return sprintf("%sh - %s, %s %d, %s %d",
|
||||
$rytime["time_of_day"],
|
||||
ryzom_day_name($rytime["day_of_week"]),
|
||||
ryzom_month_name($rytime["month_of_cycle"]),
|
||||
$rytime["day_of_month"] + 1,
|
||||
$RYTIME_AC[$lang][$rytime["cycle"]],
|
||||
$rytime["jena_year"]);
|
||||
}
|
||||
|
||||
?>
|
@ -1,3 +1,69 @@
|
||||
<?php
|
||||
|
||||
/* Copyright (C) 2009 Winch Gate Property Limited
|
||||
*
|
||||
* This file is part of ryzom_api.
|
||||
* ryzom_api is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* ryzom_api is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with ryzom_api. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
class ryUser {
|
||||
private $infos;
|
||||
|
||||
function __construct($infos) {
|
||||
$this->infos = $infos;
|
||||
}
|
||||
|
||||
function __get($name)
|
||||
{
|
||||
if (array_key_exists($name, $this->infos)) {
|
||||
return $this->infos[$name];
|
||||
} else {
|
||||
/** TODO **/
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
function inGroup($groups) {
|
||||
$groups = explode(':', $groups);
|
||||
foreach ($groups as $group) {
|
||||
if ($group != '') {
|
||||
if (in_array($group, $this->groups))
|
||||
return true;
|
||||
if ('P_'.$this->id == $group)
|
||||
return true;
|
||||
if ('G_'.$this->guild_id == $group)
|
||||
return true;
|
||||
if ($group == '*')
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function ryzom_auth_user($ask_login=true, $welcome_message='') {
|
||||
global $user, $_USER;
|
||||
|
||||
$result = ryzom_app_authenticate($user, $ask_login, $welcome_message, true);
|
||||
$_USER = new RyUser($user);
|
||||
return $result;
|
||||
}
|
||||
|
||||
function _user() {
|
||||
global $_USER;
|
||||
return $_USER;
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
/* Copyright (C) 2009 Winch Gate Property Limited
|
||||
*
|
||||
* This file is part of ryzom_api.
|
||||
* ryzom_api is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* ryzom_api is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with ryzom_api. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
function ryzom_display_xml_header() {
|
||||
header('Content-Type: application/xml; charset=UTF-8');
|
||||
}
|
||||
|
||||
?>
|
After Width: | Height: | Size: 2.5 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 732 B |
After Width: | Height: | Size: 566 B |
After Width: | Height: | Size: 369 KiB |
After Width: | Height: | Size: 3.8 KiB |
Before Width: | Height: | Size: 229 B After Width: | Height: | Size: 736 B |
Before Width: | Height: | Size: 396 B After Width: | Height: | Size: 725 B |
After Width: | Height: | Size: 649 B |
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 675 B |
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 646 B |
@ -0,0 +1,17 @@
|
||||
|
||||
function comboInit(thelist)
|
||||
{
|
||||
theinput = document.getElementById(theinput);
|
||||
var idx = thelist.selectedIndex;
|
||||
var content = thelist.options[idx].value;
|
||||
if(theinput.value == "")
|
||||
theinput.value = content;
|
||||
}
|
||||
|
||||
function combo(thelist, theinput)
|
||||
{
|
||||
theinput = document.getElementById(theinput);
|
||||
var idx = thelist.selectedIndex;
|
||||
var content = thelist.options[idx].value;
|
||||
theinput.value = content;
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
|
||||
if(window.addEventListener)
|
||||
window.addEventListener("load", tabulation, false);
|
||||
else
|
||||
window.attachEvent("onload", tabulation);
|
||||
|
||||
function tabulation(){
|
||||
var textareas = document.getElementsByTagName("textarea");
|
||||
for(var i = 0, t = textareas.length; i < t; i++){
|
||||
textareas[i].onkeydown = function(e){
|
||||
var tab = (e || window.event).keyCode == 9;
|
||||
if(tab){
|
||||
var tabString = String.fromCharCode(9);
|
||||
var scroll = this.scrollTop;
|
||||
|
||||
if(window.ActiveXObject){
|
||||
var textR = document.selection.createRange();
|
||||
var selection = textR.text;
|
||||
textR.text = tabString + selection;
|
||||
textR.moveStart("character",-selection.length);
|
||||
textR.moveEnd("character", 0);
|
||||
textR.select();
|
||||
}
|
||||
else {
|
||||
var beforeSelection = this.value.substring(0, this.selectionStart);
|
||||
var selection = this.value.substring(this.selectionStart, this.selectionEnd);
|
||||
var afterSelection = this.value.substring(this.selectionEnd);
|
||||
this.value = beforeSelection + tabString + selection + afterSelection;
|
||||
this.setSelectionRange(beforeSelection.length + tabString.length, beforeSelection.length + tabString.length + selection.length);
|
||||
}
|
||||
this.focus();
|
||||
this.scrollTop = scroll;
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
deny from all
|
After Width: | Height: | Size: 3.3 KiB |
After Width: | Height: | Size: 3.3 KiB |
After Width: | Height: | Size: 3.4 KiB |
After Width: | Height: | Size: 3.3 KiB |
After Width: | Height: | Size: 3.3 KiB |
After Width: | Height: | Size: 3.2 KiB |
After Width: | Height: | Size: 3.2 KiB |
After Width: | Height: | Size: 3.2 KiB |
After Width: | Height: | Size: 3.0 KiB |
After Width: | Height: | Size: 3.0 KiB |
After Width: | Height: | Size: 3.7 KiB |
After Width: | Height: | Size: 3.5 KiB |
After Width: | Height: | Size: 3.8 KiB |
After Width: | Height: | Size: 3.6 KiB |
After Width: | Height: | Size: 3.7 KiB |
After Width: | Height: | Size: 3.6 KiB |
After Width: | Height: | Size: 3.6 KiB |
After Width: | Height: | Size: 3.5 KiB |
After Width: | Height: | Size: 3.3 KiB |
After Width: | Height: | Size: 3.4 KiB |
After Width: | Height: | Size: 3.4 KiB |
After Width: | Height: | Size: 3.1 KiB |
After Width: | Height: | Size: 3.5 KiB |
After Width: | Height: | Size: 3.1 KiB |
After Width: | Height: | Size: 3.5 KiB |
After Width: | Height: | Size: 3.1 KiB |
After Width: | Height: | Size: 3.4 KiB |
After Width: | Height: | Size: 3.0 KiB |
After Width: | Height: | Size: 3.1 KiB |
After Width: | Height: | Size: 2.9 KiB |
After Width: | Height: | Size: 536 B |
After Width: | Height: | Size: 517 B |
After Width: | Height: | Size: 543 B |
After Width: | Height: | Size: 498 B |
After Width: | Height: | Size: 539 B |
After Width: | Height: | Size: 502 B |
After Width: | Height: | Size: 434 B |
After Width: | Height: | Size: 419 B |
After Width: | Height: | Size: 387 B |
After Width: | Height: | Size: 363 B |
After Width: | Height: | Size: 561 B |
After Width: | Height: | Size: 457 B |
After Width: | Height: | Size: 622 B |
After Width: | Height: | Size: 484 B |
After Width: | Height: | Size: 625 B |
After Width: | Height: | Size: 494 B |
After Width: | Height: | Size: 513 B |
After Width: | Height: | Size: 366 B |
After Width: | Height: | Size: 388 B |
After Width: | Height: | Size: 416 B |
After Width: | Height: | Size: 543 B |
After Width: | Height: | Size: 397 B |
After Width: | Height: | Size: 584 B |
After Width: | Height: | Size: 405 B |
After Width: | Height: | Size: 623 B |
After Width: | Height: | Size: 394 B |
After Width: | Height: | Size: 528 B |
After Width: | Height: | Size: 351 B |
After Width: | Height: | Size: 431 B |
After Width: | Height: | Size: 238 B |
After Width: | Height: | Size: 2.8 KiB |
After Width: | Height: | Size: 2.0 KiB |
After Width: | Height: | Size: 3.0 KiB |
After Width: | Height: | Size: 1.8 KiB |
After Width: | Height: | Size: 2.4 KiB |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 2.1 KiB |