Kuba MiszczOTS
Member
- Joined
- Jun 29, 2010
- Messages
- 151
- Reaction score
- 7
We need some news!
[JOKE]Tibia flash on website?
Nice.No, PHP tibia text client. You write:
STEP "LEFT
and it moves your character one tile left.. of course
--------------------
Enough tidy?
Do you really think it will be safe? :huh:
[JOKE]
No, PHP tibia text client. You write:
STEP "LEFT
and it moves your character one tile left.. of course
[/JOKE]
--------------------
Enough tidy?
<?PHP
$loginForm = new Form();
$field = new FormField_Password();
$field->setName('loginAccount');
$loginForm->addField($field);
$field = new FormField_Password();
$field->setName('loginPassword');
$loginForm->addField($field);
$field = new FormField_Hidden();
$field->setName('loadDataAfterLogin');
if(isset($_REQUEST['loadDataAfterLogin']))
$field->setValue($_REQUEST['loadDataAfterLogin']);
elseif(isset($_PARAM[0]))
$field->setValue($_PARAM[0]);
$loginForm->addField($field);
$field = new FormField_Submit();
$field->setName('send');
$field->setValue('Send');
$loginForm->addField($field);
if($loginForm->isSetFieldValue('loginAccount') && $loginForm->isSetFieldValue('loginPassword'))
{
$VISITOR->setAccount($loginForm->getFieldValue('loginAccount'));
$VISITOR->setPassword($loginForm->getFieldValue('loginPassword'));
$VISITOR->login(); // this set account and password from code above as login and password to next login attempt
$VISITOR->loadAccount(); // this is required to force reload account and get status of user
$isTryingToLogin = true;
}
if($VISITOR->isLogged())
{
if(!isset($_REQUEST['loadDataAfterLogin']))
Website::redirect('', 'account', array('view'));
else
Website::redirect('', 'redirect', array((int) $_REQUEST['loadDataAfterLogin']));
}
elseif(isset($isTryingToLogin))
{
switch($VISITOR->getLoginState())
{
case Visitor::LOGINSTATE_NO_ACCOUNT:
$WEB->addNotice('', 'Account with that name doesn\'t exist.');
break;
case Visitor::LOGINSTATE_WRONG_PASSWORD:
$WEB->addNotice('', 'Wrong password to account.');
break;
}
}
echo $loginForm->getString_Form();
echo $loginForm->getField('loadDataAfterLogin');
echo 'Login: ' . $loginForm->getField('loginAccount') . '<br />';
echo 'Password: ' . $loginForm->getField('loginPassword') . '<br />';
echo $loginForm->getField('send');
echo $loginForm->getString_FormEnd();
?>
<?PHP
class Form extends Errors
{
const FIELD_NONE = 0;
const FIELD_TEXT = 1;
const FIELD_TEXTAREA = 2;
const FIELD_PASSWORD = 3;
const FIELD_HIDDEN = 4;
const FIELD_CHECKBOX = 5;
const FIELD_RADIO = 6;
const FIELD_SELECT = 7;
const FIELD_SELECTOPTION = 8;
const FIELD_SUBMIT = 9;
const FIELD_IMAGE = 10;
public $actionPage;
public $actionParam;
public $actionParamCustom;
public $actionUseString = false;
/*
* '' by default send data to 'self', but only on pages that don't use custom_params
* if you use custom params you must use function:
* setAction(PAGE, $_PARAMS, array(here your custom params))
* they will be added as hidden data or added to URI [rewrite mode on]
*/
public $action = '';
/*
* you can use: 'POST', 'GET'
*/
public $method = 'POST';
public $style = '';
public $class = '';
public $name = '';
public $id = '';
/*
* you can use: 'multipart/form-data', 'application/x-www-form-urlencoded', 'text/plain'
*/
public $enctype = 'multipart/form-data';
public $onSubmit = '';
public $onMouseOver = '';
public $onMouseOut = '';
public $fields = array();
public function getString_Form()
{
$ret = '<form';
$action = $this->getAction();
$ret .= ' action="' . $action['URI'] . '"';
$ret .= ' method="' . $this->method . '"';
$ret .= ' enctype="' . $this->enctype . '"';
$ret .= ' />';
if(count($action['hiddenFields']) > 0)
foreach($action['hiddenFields'] as $key => $value)
$ret .= '<input type="hidden" name="' . $key . '" value="' . $value . '" />';
return $ret;
}
public function getString_FormEnd()
{
return '</form>';
}
public function getAction()
{
// finish, fix
$uri = '';
$hiddenFields = array();
if($this->actionUseString)
$uri .= $this->action;
else
{
$_web = Website::getInstance();
if($this->actionPage == '') // move to self
{
$this->actionPage = $_web->getPage();
$_tmp_param = $_web->getRealFolders();
if(count($_web->getParams()) > 0)
foreach($_web->getParams() as $value)
$_tmp_param[] = $value;
$this->actionParam = $_tmp_param;
$this->actionParamCustom = array();
}
if($_web->getWebsiteConfig()->getValue('useRewrite'))
{
$uri .= $_web->getURI();
$uri .= $this->actionPage . '/';
if(count($this->actionParam) > 0)
$uri .= implode('/', $this->actionParam) . '/';
if(count($this->actionParamCustom) > 0)
$hiddenFields = $this->actionParamCustom;
}
else
{ // fix
$uri .= $_web->getURI();
$i = 0;
if(count($this->actionParam) > 0)
foreach($this->actionParam as $value)
$hiddenFields['amp' . $i++] = $value;
if(count($this->actionParamCustom) > 0)
foreach($this->actionParam as $key => $value)
$hiddenFields[$key] = $value;
$hiddenFields['page'] = $this->actionPage;
}
}
return array('URI' => $uri, 'hiddenFields' => $hiddenFields);
}
public function setAction($page, $param = array(), $custom_param = array())
{
$this->actionPage = $page;
$this->actionParam = $param;
$this->actionParamCustom = $custom_param;
$this->actionUseString = false;
}
public function setActionString($value)
{
$this->action = $value;
$this->actionUseString = true;
}
public function getMethod()
{
return $this->method;
}
public function setMethod($value)
{
$this->method = $value;
}
public function getStyle()
{
return $this->style;
}
public function setStyle($value)
{
$this->style = $value;
}
public function getClass()
{
return $this->class;
}
public function setClass($value)
{
$this->class = $value;
}
public function getName()
{
return $this->name;
}
public function setName($value)
{
$this->name = $value;
}
public function getId()
{
return $this->id;
}
public function setId($value)
{
$this->id = $value;
}
public function getEnctype()
{
return $this->enctype;
}
public function setEnctype($value)
{
$this->enctype = $value;
}
public function getOnSubmit()
{
return $this->onSubmit;
}
public function setOnSubmit($value)
{
$this->onSubmit = $value;
}
public function getOnMouseOver()
{
return $this->onMouseOver;
}
public function setOnMouseOver($value)
{
$this->onMouseOver = $value;
}
public function getOnMouseOut()
{
return $this->onMouseOut;
}
public function setOnMouseOut($value)
{
$this->onMouseOut = $value;
}
public function addField(&$field, $id = null)
{
$field->setForm(&$this);
if($field->getLoadUserValue())
$field->loadUserValue();
if($field->getType() == self::FIELD_RADIO || $field->getType() == self::FIELD_CHECKBOX)
if($id == null)
$this->fields[$field->getName()][] = $field;
else
$this->fields[$field->getName()][$id] = $field;
else
$this->fields[$field->getName()] = $field;
}
public function removeField($name, $id = null)
{
if(isset($this->fields[$name]))
if($id != null)
unset($this->fields[$field->getName()][$id]);
else
unset($this->fields[$field->getName()]);
}
public function getField($name, $id = null)
{
if(isset($this->fields[$name]))
if($id == null)
return $this->fields[$name];
elseif(isset($this->fields[$name][$id]))
return $this->fields[$name][$id];
else
return false;
else
return false;
}
public function getFields()
{
return $this->fields;
}
public function setFields($value)
{
$this->fields = $value;
}
public function getFieldValue($name)
{
return $GLOBALS['_' . $this->getMethod()][$name];
}
public function isSetFieldValue($name)
{
return isset($GLOBALS['_' . $this->getMethod()][$name]);
}
}
class FormField extends Errors
{
public $style = '';
public $class = '';
public $name = '';
public $id = '';
public $value = '';
public $disabled = false;
public $onFocus = '';
public $onBlur = '';
public $onMouseOver = '';
public $onMouseOut = '';
public $onClick = '';
public $type = Form::FIELD_NONE;
public $loadUserValue = false;
public $form;
public function getStyle()
{
return $this->style;
}
public function setStyle($value)
{
$this->style = $value;
}
public function getClass()
{
return $this->class;
}
public function setClass($value)
{
$this->class = $value;
}
public function getName()
{
return $this->name;
}
public function setName($value)
{
$this->name = $value;
}
public function getId()
{
return $this->id;
}
public function setId($value)
{
$this->id = $value;
}
public function getValue()
{
return $this->value;
}
public function setValue($value)
{
$this->value = $value;
}
public function getDisabled()
{
return $this->disabled;
}
public function setDisabled($value)
{
$this->disabled = $value;
}
public function getOnFocus()
{
return $this->onFocus;
}
public function setOnFocus($value)
{
$this->onFocus = $value;
}
public function getOnBlur()
{
return $this->onBlur;
}
public function setOnBlur($value)
{
$this->onBlur = $value;
}
public function getOnMouseOver()
{
return $this->onMouseOver;
}
public function setOnMouseOver($value)
{
$this->onMouseOver = $value;
}
public function getOnMouseOut()
{
return $this->onMouseOut;
}
public function setOnMouseOut($value)
{
$this->onMouseOut = $value;
}
public function getOnClick()
{
return $this->onClick;
}
public function setOnClick($value)
{
$this->onClick = $value;
}
public function getType()
{
return $this->type;
}
public function getLoadUserValue()
{
return $this->loadUserValue;
}
public function setLoadUserValue($value)
{
$this->loadUserValue = $value;
}
public function getForm()
{
return $this->form;
}
public function setForm($value)
{
$this->form = $value;
}
public function isSetUserValue()
{
return isset($GLOBALS['_' . $this->getForm()->getMethod()][$this->getName()]);
}
public function loadUserValue()
{
if($this->isSetUserValue())
$this->setValue($GLOBALS['_' . $this->getForm()->getMethod()][$this->getName()]);
$this->setValue('');
}
public function __toString()
{
$_all_form = '';
if($this->getId() != '')
$_all_form .= 'id="' . $this->getId() . '" ';
if($this->getName() != '')
$_all_form .= 'name="' . $this->getName() . '" ';
if($this->getClass() != '')
$_all_form .= 'class="' . $this->getClass() . '" ';
if($this->getStyle() != '')
$_all_form .= 'style="' . $this->getStyle() . '" ';
switch ($this->getType())
{
case Form::FIELD_TEXT:
$ret = '<input ';
$ret .= 'type="text" ';
$ret .= 'size="' . $this->getSize() . '" ';
if($this->getMaxLenght() > 0)
$ret .= 'maxlenght="' . $this->getMaxLenght() . '" ';
if($this->getReadOnly())
$ret .= 'readonly="readonly" ';
$ret .= 'value="' . htmlspecialchars($this->getValue()) . '" ';
$ret .= $_all_form . '/>';
break;
case Form::FIELD_TEXTAREA:
$ret .= '<textarea ';
$ret .= 'cols="' . $this->getCols() . '" ';
$ret .= 'rows="' . $this->getRows() . '" ';
if($this->getWrap() != '')
$ret .= 'wrap="' . $this->getWrap() . '" ';
if($this->getReadOnly())
$ret .= 'readonly="readonly" ';
$ret .= $_all_form . '>';
$ret .= htmlspecialchars($this->getValue());
$ret .= '</textarea>';
break;
case Form::FIELD_PASSWORD:
$ret = '<input ';
$ret .= 'type="password" ';
$ret .= 'size="' . $this->getSize() . '" ';
if($this->getMaxLenght() > 0)
$ret .= 'maxlenght="' . $this->getMaxLenght() . '" ';
if($this->getReadOnly())
$ret .= 'readonly="readonly" ';
$ret .= 'value="' . htmlspecialchars($this->getValue()) . '" ';
$ret .= $_all_form . '/>';
break;
case Form::FIELD_HIDDEN:
$ret = '<input ';
$ret .= 'type="hidden" ';
$ret .= 'value="' . htmlspecialchars($this->getValue()) . '" ';
$ret .= $_all_form . '/>';
break;
case Form::FIELD_SUBMIT:
$ret = '<input ';
$ret .= 'type="submit" ';
$ret .= 'value="' . htmlspecialchars($this->getValue()) . '" ';
$ret .= $_all_form . '/>';
break;
}
return $ret;
}
}
class FormField_Text extends FormField
{
public $type = Form::FIELD_TEXT;
public $size = 10;
public $maxlenght = 0;
public $readonly = false;
public function getSize()
{
return $this->size;
}
public function setSize($value)
{
$this->size = $value;
}
public function getMaxLenght()
{
return $this->maxlenght;
}
public function setMaxLenght($value)
{
$this->maxlenght = $value;
}
public function getReadOnly()
{
return $this->readonly;
}
public function setReadOnly($value)
{
$this->readonly = $value;
}
}
class FormField_Textarea extends FormField
{
public $type = Form::FIELD_TEXTAREA;
public $rows = 1;
public $cols = 3;
public $wrap = ''; // off, physical, virtual - it's not valid HTML!
public $readonly = false;
public function getRows()
{
return $this->rows;
}
public function setRows($value)
{
$this->rows = $value;
}
public function getCols()
{
return $this->cols;
}
public function setCols($value)
{
$this->cols = $value;
}
public function getWrap()
{
return $this->wrap;
}
public function setWrap($value)
{
$this->wrap = $value;
}
public function getReadOnly()
{
return $this->readonly;
}
public function setReadOnly($value)
{
$this->readonly = $value;
}
}
class FormField_Password extends FormField
{
public $type = Form::FIELD_PASSWORD;
public $size = 10;
public $maxlenght = 0;
public $readonly = false;
public function getSize()
{
return $this->size;
}
public function setSize($value)
{
$this->size = $value;
}
public function getMaxLenght()
{
return $this->maxlenght;
}
public function setMaxLenght($value)
{
$this->maxlenght = $value;
}
public function getReadOnly()
{
return $this->readonly;
}
public function setReadOnly($value)
{
$this->readonly = $value;
}
}
class FormField_Hidden extends FormField
{
public $type = Form::FIELD_HIDDEN;
}
class FormField_Checkbox extends FormField
{
public $type = Form::FIELD_CHECKBOX;
public $checked = false;
public function getChecked()
{
return $this->checked;
}
public function setChecked($value)
{
$this->checked = $value;
}
public function isSetUserValue()
{
if(isset($GLOBALS['_' . $this->getForm()->getMethod()][$this->getName()]));
}
public function loadUserValue()
{
if($this->isSetUserValue())
$this->setValue($GLOBALS['_' . $this->getForm()->getMethod()][$this->getName()]);
}
}
class FormField_Radio extends FormField
{
public $type = Form::FIELD_RADIO;
public $checked = false;
public function getChecked()
{
return $this->checked;
}
public function setChecked($value)
{
$this->checked = $value;
}
public function isSetUserValue()
{
return isset($GLOBALS['_' . $this->getForm()->getMethod()][$this->getName()]);
}
public function loadUserValue()
{
if($this->isSetUserValue())
$this->setValue($GLOBALS['_' . $this->getForm()->getMethod()][$this->getName()]);
$this->setValue('');
}
}
class FormField_Select extends FormField
{
public $type = Form::FIELD_SELECT;
public $multiple = false;
public $size = 0;
public $onChange = '';
public $selected;
public function getSelected()
{
return $this->selected;
}
public function setSelected($value)
{
$this->selected = $value;
}
public function getMultiple()
{
return $this->multiple;
}
public function setMultiple($value)
{
$this->multiple = $value;
}
public function getSize()
{
return $this->size;
}
public function setSize($value)
{
$this->size = $value;
}
public function getOnChange()
{
return $this->onChange;
}
public function setOnChange($value)
{
$this->onChange = $value;
}
public function isSetUserValue()
{
return isset($GLOBALS['_' . $this->getForm()->getMethod()][$this->getName()]);
}
public function loadUserValue()
{
if($this->isSetUserValue())
$this->setValue($GLOBALS['_' . $this->getForm()->getMethod()][$this->getName()]);
$this->setValue('');
}
}
class FormField_SelectOption extends FormField
{
public $type = Form::FIELD_SELECTOPTION;
}
class FormField_Submit extends FormField
{
public $type = Form::FIELD_SUBMIT;
}
class FormField_Image extends FormField
{
public $type = Form::FIELD_IMAGE;
public $src = '';
public $alt = '';
public function getSrc()
{
return $this->src;
}
public function setSrc($value)
{
$this->src = $value;
}
public function getAlt()
{
return $this->alt;
}
public function setAlt($value)
{
$this->alt = $value;
}
}
?>
[JOKE]
No, PHP tibia text client. You write:
STEP "LEFT
and it moves your character one tile left.. of course
[/JOKE]
--------------------
Enough tidy?
I'd like to see some sort of live support system within the AAC. The GM should be logged in, as well as players to chat. This could be beneficial to any community. Not all GM's want to be in game as the only option to assist people.
Good luck,
J.Dre
aha, add a staff chat in the site, everyone with access2 and higher got mod in chat and write in orange and other can chat there and such, and u can disable this chat or enable this chat xD
I see nothing "more complicated" = \