Find this useful? Enter your email to receive occasional updates for securing PHP code.
Signing you up...
Thank you for signing up!
PHP Decode
<?php namespace Swoole; /** * * HTML * @author Tianfeng.Han * @package SwooleSystem ..
Decoded Output download
<?php
namespace Swoole;
/**
*
* HTML
* @author Tianfeng.Han
* @package SwooleSystem
* @subpackage HTML
* @link http://www.swoole.com/
*
*/
class Form
{
static $checkbox_value_split = ',';
static $default_help_option = '';
/**
*
* @param $form_array
* @return unknown_type
*/
static function autoform($form_array)
{
$forms = array();
foreach($form_array as $k=>$v)
{
//
$func = $v['type'];
//
$value = '';
if(isset($v['value'])) $value = $v['value'];
unset($v['type'],$v['value']);
if($func=='input' or $func=='password' or $func=='text' or $func=='htmltext')
{
$forms[$k] = self::$func($k,$value,$v);
}
else
{
$option = $v['option'];
$self = $v['self'];
$label_class = $v['label_class'];
unset($v['option'],$v['self'],$v['label_class']);
$forms[$k] = self::$func($k,$option,$value,$self,$v,$label_class);
if($func=='radio' and isset($v['empty']))
$forms[$k].= "
<script language='javascript'>add_filter('{$k}','{$v['empty']}',function(){return getRadioValue('{$k}');});</script>";
elseif($func=='checkbox' and isset($v['empty']))
$forms[$k].= "
<script language='javascript'>add_filter('{$k}[]','{$v['empty']}',function(){return getCheckboxValue('{$k}[]');});</script>";
}
}
return $forms;
}
static function checkInput($input,$form,&$error)
{
foreach($form as $name=>$f)
{
$value = $input[$name];
// -empty
if(isset($f['empty']) and empty($value))
{
$error = $f['empty'];
return false;
}
//
if(isset($f['maxlen']))
{
$qs = explode('|',$f['maxlen']);
if(mb_strlen($value)>$qs[0])
{
$error = $qs[1];
return false;
}
}
//
if(isset($f['minlen']))
{
$qs = explode('|',$f['maxlen']);
if(mb_strlen($value)>$qs[0])
{
$error = $qs[1];
return false;
}
}
// -equal
if(isset($f['equal']))
{
$qs = explode('|',$f['equal']);
if($value!=$qs[0])
{
$error = $qs[1];
return false;
}
}
// -noequal
if(isset($f['noequal']))
{
$qs = explode('|',$f['noequal']);
if($value==$qs[0])
{
$error = $qs[1];
return false;
}
}
// -equalo
if(isset($f['equalo']))
{
$qs = explode('|',$f['equalo']);
if($value==$input[$qs[0]])
{
$error = $qs[1];
return false;
}
}
// -equalo
if(isset($f['ctype']))
{
$qs = explode('|',$f['ctype']);
if(!Validate::check($qs[0],$value))
{
$error = $qs[1];
return false;
}
}
// -regx
if(isset($f['regx']))
{
$qs = explode('|',$f['regx']);
if(!Validate::regx($qs[0],$value))
{
$error = $qs[1];
return false;
}
}
}
return true;
}
/**
*
* @param $attr
* @return unknown_type
*/
static function input_attr(&$attr)
{
$str = " ";
if(!empty($attr) && is_array($attr))
{
foreach($attr as $key=>$value)
{
$str .= "$key=\"$value\" ";
}
}
return $str;
}
/**
*
* $name select name
* $array select
* $default
* $self trueoption$value
* $attrArray html select class="x1"
* $add_help
* $force
*/
static function select($name, $option, $default = null, $self = null, $attrArray = null, $add_help = true, $force = false)
{
$htmlStr = "<select name=\"$name\" id=\"$name\"";
$htmlStr .= self::input_attr($attrArray) . ">
";
if ($add_help) {
if ($add_help === true) {
$htmlStr .= "<option value=\"\">" . self::$default_help_option . "</option>
";
} else {
$htmlStr .= "<option value=\"\">$add_help</option>
";
}
}
foreach ($option as $key => $value) {
if ($self) {
$key = $value;
}
if (!$force and $key == $default) {
$htmlStr .= "<option value=\"{$key}\" selected=\"selected\">{$value}</option>
";
} elseif ($force and $key === $default) {
$htmlStr .= "<option value=\"{$key}\" selected=\"selected\">{$value}</option>
";
} else {
$htmlStr .= "<option value=\"{$key}\">{$value}</option>
";
}
}
$htmlStr .= "</select>
";
return $htmlStr;
}
/**
*
* $name select name
* $array select
* $default
* $self tureoption$value
* $attrArray html select class="x1"
* $add_help
*/
static function muti_select($name,$option,$default=array(),$self=null,$attrArray=null,$add_help=true)
{
$htmlStr = "<select name=\"$name\" id=\"$name\"";
$htmlStr .= self::input_attr($attrArray) . ">
";
if($add_help)
{
if($add_help===true)
$htmlStr .= "<option value=\"\">".self::$default_help_option."</option>
";
else $htmlStr .= "<option value=\"\">$add_help</option>
";
}
foreach($option as $key => $value)
{
if($self) $key=$value;
if (in_array($key,$default))
{
$htmlStr .= "<option value=\"{$key}\" selected=\"selected\">{$value}</option>
";
}
else
{
$htmlStr .= "<option value=\"{$key}\">{$value}</option>
";
}
}
$htmlStr .= "</select>
";
return $htmlStr;
}
/**
*
* $name radio name
* $array radio
* $default
* $self tureoption$value
* $attrArray html class="x1"
**/
static function radio($name, $option, $default = null, $self = false, $attrArray = null, $label_class = '')
{
$htmlStr = "";
$attrStr = self::input_attr($attrArray);
foreach($option as $key => $value)
{
if($self) $key=$value;
if ($key == $default)
{
$htmlStr .= "<label class='$label_class'><input type=\"radio\" name=\"$name\" id=\"{$name}_{$key}\" value=\"$key\" checked=\"checked\" {$attrStr} />".$value."</label>";
}
else
{
$htmlStr .= "<label class='$label_class'><input type=\"radio\" name=\"$name\" id=\"{$name}_{$key}\" value=\"$key\" {$attrStr} /> ".$value."</label>";
}
}
return $htmlStr;
}
/**
*
* @param string $name radio name
* @param array $option radio
* @param string $default
* @param bool $self tureoption$value
* @param array $attrArray html class="x1"
* @param string $label_class
* @return string
*/
static function checkbox($name, $option, $default = null, $self = false, $attrArray = null, $label_class = '')
{
$htmlStr = "";
$attrStr = self::input_attr($attrArray);
$default = array_flip(explode(self::$checkbox_value_split, $default));
foreach ($option as $key => $value)
{
if ($self)
{
$key = $value;
}
if (isset($default[$key]))
{
$htmlStr
.=
"<label class='$label_class'><input type=\"checkbox\" name=\"{$name}[]\" id=\"{$name}_$key\" value=\"$key\" checked=\"checked\" {$attrStr} />"
. $value . '</label>';
}
else
{
$htmlStr
.=
"<label class='$label_class'><input type=\"checkbox\" name=\"{$name}[]\" id=\"{$name}_$key\" value=\"$key\" {$attrStr} />"
. $value . '</label>';
}
}
return $htmlStr;
}
/**
*
* @param $name
* @param $value
* @param $attrArray html class="x1"
* @return unknown_type
*/
static function upload($name, $value = '', $attrArray = null)
{
$attrStr = self::input_attr($attrArray);
$form = '';
if(!empty($value))
$form = " <a href='$value' target='_blank'></a><br />
";
return $form."<input type='file' name='$name' id='{$name}' {$attrStr} />";
}
/**
*
* @param $name
* @param $value
* @param $attrArray
* @return string
*/
static function input($name, $value = '', $attrArray = null)
{
$attrStr = self::input_attr($attrArray);
return "<input type='text' name='{$name}' id='{$name}' value='{$value}' {$attrStr} />";
}
/**
*
* @param $name
* @param $value
* @param $attrArray
* @return unknown_type
*/
static function button($name,$value='',$attrArray=null)
{
if(empty($attrArray['type'])) $attrArray['type'] = 'button';
$attrStr = self::input_attr($attrArray);
return "<input name='{$name}' id='{$name}' value='{$value}' {$attrStr} />";
}
/**
*
* @param $name
* @param $value
* @param $attrArray
* @return unknown_type
*/
static function password($name,$value='',$attrArray=null)
{
$attrStr = self::input_attr($attrArray);
return "<input type='password' name='{$name}' id='{$name}' value='{$value}' {$attrStr} />";
}
/**
*
* @param $name
* @param $value
* @param $attrArray
* @return string
*/
static function text($name,$value='',$attrArray=null)
{
if(!isset($attrArray['cols'])) $attrArray['cols'] = 60;
if(!isset($attrArray['rows'])) $attrArray['rows'] = 3;
$attrStr = self::input_attr($attrArray);
$forms = "<textarea name='{$name}' id='{$name}' $attrStr>$value</textarea>";
return $forms;
}
/**
*
* @param $name
* @param $value
* @param $attrArray
* @return string
*/
static function hidden($name,$value='',$attrArray=null)
{
$attrStr = self::input_attr($attrArray);
return "<input type='hidden' name='{$name}' id='{$name}' value='{$value}' {$attrStr} />";
}
/**
*
* @param $form_name
* @param $method
* @param $action
* @param $if_upload
* @param $attrArray
* @return string
*/
static function head($form_name,$method='post',$action='',$if_upload=false,$attrArray=null)
{
if($if_upload) $attrArray['enctype'] = "multipart/form-data";
$attrStr = self::input_attr($attrArray);
return "action='$action' method='$method' name='$form_name' id='$form_name' $attrStr";
}
/**
* Form Secret
* @param $page_name
* @param $return
* @return string
*/
static function secret($page_name = '', $length = 32, $return = false)
{
$secret = uniqid(RandomKey::string($length));
if ($return)
{
return $secret;
}
else
{
$k = 'form_' . $page_name;
setcookie($k, $secret, 0, '/');
if (!isset($_SESSION))
{
session();
}
$_SESSION[$k] = $secret;
}
}
}
?>
Did this file decode correctly?
Original Code
<?php
namespace Swoole;
/**
*
* HTML
* @author Tianfeng.Han
* @package SwooleSystem
* @subpackage HTML
* @link http://www.swoole.com/
*
*/
class Form
{
static $checkbox_value_split = ',';
static $default_help_option = '';
/**
*
* @param $form_array
* @return unknown_type
*/
static function autoform($form_array)
{
$forms = array();
foreach($form_array as $k=>$v)
{
//
$func = $v['type'];
//
$value = '';
if(isset($v['value'])) $value = $v['value'];
unset($v['type'],$v['value']);
if($func=='input' or $func=='password' or $func=='text' or $func=='htmltext')
{
$forms[$k] = self::$func($k,$value,$v);
}
else
{
$option = $v['option'];
$self = $v['self'];
$label_class = $v['label_class'];
unset($v['option'],$v['self'],$v['label_class']);
$forms[$k] = self::$func($k,$option,$value,$self,$v,$label_class);
if($func=='radio' and isset($v['empty']))
$forms[$k].= "\n<script language='javascript'>add_filter('{$k}','{$v['empty']}',function(){return getRadioValue('{$k}');});</script>";
elseif($func=='checkbox' and isset($v['empty']))
$forms[$k].= "\n<script language='javascript'>add_filter('{$k}[]','{$v['empty']}',function(){return getCheckboxValue('{$k}[]');});</script>";
}
}
return $forms;
}
static function checkInput($input,$form,&$error)
{
foreach($form as $name=>$f)
{
$value = $input[$name];
// -empty
if(isset($f['empty']) and empty($value))
{
$error = $f['empty'];
return false;
}
//
if(isset($f['maxlen']))
{
$qs = explode('|',$f['maxlen']);
if(mb_strlen($value)>$qs[0])
{
$error = $qs[1];
return false;
}
}
//
if(isset($f['minlen']))
{
$qs = explode('|',$f['maxlen']);
if(mb_strlen($value)>$qs[0])
{
$error = $qs[1];
return false;
}
}
// -equal
if(isset($f['equal']))
{
$qs = explode('|',$f['equal']);
if($value!=$qs[0])
{
$error = $qs[1];
return false;
}
}
// -noequal
if(isset($f['noequal']))
{
$qs = explode('|',$f['noequal']);
if($value==$qs[0])
{
$error = $qs[1];
return false;
}
}
// -equalo
if(isset($f['equalo']))
{
$qs = explode('|',$f['equalo']);
if($value==$input[$qs[0]])
{
$error = $qs[1];
return false;
}
}
// -equalo
if(isset($f['ctype']))
{
$qs = explode('|',$f['ctype']);
if(!Validate::check($qs[0],$value))
{
$error = $qs[1];
return false;
}
}
// -regx
if(isset($f['regx']))
{
$qs = explode('|',$f['regx']);
if(!Validate::regx($qs[0],$value))
{
$error = $qs[1];
return false;
}
}
}
return true;
}
/**
*
* @param $attr
* @return unknown_type
*/
static function input_attr(&$attr)
{
$str = " ";
if(!empty($attr) && is_array($attr))
{
foreach($attr as $key=>$value)
{
$str .= "$key=\"$value\" ";
}
}
return $str;
}
/**
*
* $name select name
* $array select
* $default
* $self trueoption$value
* $attrArray html select class="x1"
* $add_help
* $force
*/
static function select($name, $option, $default = null, $self = null, $attrArray = null, $add_help = true, $force = false)
{
$htmlStr = "<select name=\"$name\" id=\"$name\"";
$htmlStr .= self::input_attr($attrArray) . ">\n";
if ($add_help) {
if ($add_help === true) {
$htmlStr .= "<option value=\"\">" . self::$default_help_option . "</option>\n";
} else {
$htmlStr .= "<option value=\"\">$add_help</option>\n";
}
}
foreach ($option as $key => $value) {
if ($self) {
$key = $value;
}
if (!$force and $key == $default) {
$htmlStr .= "<option value=\"{$key}\" selected=\"selected\">{$value}</option>\n";
} elseif ($force and $key === $default) {
$htmlStr .= "<option value=\"{$key}\" selected=\"selected\">{$value}</option>\n";
} else {
$htmlStr .= "<option value=\"{$key}\">{$value}</option>\n";
}
}
$htmlStr .= "</select>\n";
return $htmlStr;
}
/**
*
* $name select name
* $array select
* $default
* $self tureoption$value
* $attrArray html select class="x1"
* $add_help
*/
static function muti_select($name,$option,$default=array(),$self=null,$attrArray=null,$add_help=true)
{
$htmlStr = "<select name=\"$name\" id=\"$name\"";
$htmlStr .= self::input_attr($attrArray) . ">\n";
if($add_help)
{
if($add_help===true)
$htmlStr .= "<option value=\"\">".self::$default_help_option."</option>\n";
else $htmlStr .= "<option value=\"\">$add_help</option>\n";
}
foreach($option as $key => $value)
{
if($self) $key=$value;
if (in_array($key,$default))
{
$htmlStr .= "<option value=\"{$key}\" selected=\"selected\">{$value}</option>\n";
}
else
{
$htmlStr .= "<option value=\"{$key}\">{$value}</option>\n";
}
}
$htmlStr .= "</select>\n";
return $htmlStr;
}
/**
*
* $name radio name
* $array radio
* $default
* $self tureoption$value
* $attrArray html class="x1"
**/
static function radio($name, $option, $default = null, $self = false, $attrArray = null, $label_class = '')
{
$htmlStr = "";
$attrStr = self::input_attr($attrArray);
foreach($option as $key => $value)
{
if($self) $key=$value;
if ($key == $default)
{
$htmlStr .= "<label class='$label_class'><input type=\"radio\" name=\"$name\" id=\"{$name}_{$key}\" value=\"$key\" checked=\"checked\" {$attrStr} />".$value."</label>";
}
else
{
$htmlStr .= "<label class='$label_class'><input type=\"radio\" name=\"$name\" id=\"{$name}_{$key}\" value=\"$key\" {$attrStr} /> ".$value."</label>";
}
}
return $htmlStr;
}
/**
*
* @param string $name radio name
* @param array $option radio
* @param string $default
* @param bool $self tureoption$value
* @param array $attrArray html class="x1"
* @param string $label_class
* @return string
*/
static function checkbox($name, $option, $default = null, $self = false, $attrArray = null, $label_class = '')
{
$htmlStr = "";
$attrStr = self::input_attr($attrArray);
$default = array_flip(explode(self::$checkbox_value_split, $default));
foreach ($option as $key => $value)
{
if ($self)
{
$key = $value;
}
if (isset($default[$key]))
{
$htmlStr
.=
"<label class='$label_class'><input type=\"checkbox\" name=\"{$name}[]\" id=\"{$name}_$key\" value=\"$key\" checked=\"checked\" {$attrStr} />"
. $value . '</label>';
}
else
{
$htmlStr
.=
"<label class='$label_class'><input type=\"checkbox\" name=\"{$name}[]\" id=\"{$name}_$key\" value=\"$key\" {$attrStr} />"
. $value . '</label>';
}
}
return $htmlStr;
}
/**
*
* @param $name
* @param $value
* @param $attrArray html class="x1"
* @return unknown_type
*/
static function upload($name, $value = '', $attrArray = null)
{
$attrStr = self::input_attr($attrArray);
$form = '';
if(!empty($value))
$form = " <a href='$value' target='_blank'></a><br />\n";
return $form."<input type='file' name='$name' id='{$name}' {$attrStr} />";
}
/**
*
* @param $name
* @param $value
* @param $attrArray
* @return string
*/
static function input($name, $value = '', $attrArray = null)
{
$attrStr = self::input_attr($attrArray);
return "<input type='text' name='{$name}' id='{$name}' value='{$value}' {$attrStr} />";
}
/**
*
* @param $name
* @param $value
* @param $attrArray
* @return unknown_type
*/
static function button($name,$value='',$attrArray=null)
{
if(empty($attrArray['type'])) $attrArray['type'] = 'button';
$attrStr = self::input_attr($attrArray);
return "<input name='{$name}' id='{$name}' value='{$value}' {$attrStr} />";
}
/**
*
* @param $name
* @param $value
* @param $attrArray
* @return unknown_type
*/
static function password($name,$value='',$attrArray=null)
{
$attrStr = self::input_attr($attrArray);
return "<input type='password' name='{$name}' id='{$name}' value='{$value}' {$attrStr} />";
}
/**
*
* @param $name
* @param $value
* @param $attrArray
* @return string
*/
static function text($name,$value='',$attrArray=null)
{
if(!isset($attrArray['cols'])) $attrArray['cols'] = 60;
if(!isset($attrArray['rows'])) $attrArray['rows'] = 3;
$attrStr = self::input_attr($attrArray);
$forms = "<textarea name='{$name}' id='{$name}' $attrStr>$value</textarea>";
return $forms;
}
/**
*
* @param $name
* @param $value
* @param $attrArray
* @return string
*/
static function hidden($name,$value='',$attrArray=null)
{
$attrStr = self::input_attr($attrArray);
return "<input type='hidden' name='{$name}' id='{$name}' value='{$value}' {$attrStr} />";
}
/**
*
* @param $form_name
* @param $method
* @param $action
* @param $if_upload
* @param $attrArray
* @return string
*/
static function head($form_name,$method='post',$action='',$if_upload=false,$attrArray=null)
{
if($if_upload) $attrArray['enctype'] = "multipart/form-data";
$attrStr = self::input_attr($attrArray);
return "action='$action' method='$method' name='$form_name' id='$form_name' $attrStr";
}
/**
* Form Secret
* @param $page_name
* @param $return
* @return string
*/
static function secret($page_name = '', $length = 32, $return = false)
{
$secret = uniqid(RandomKey::string($length));
if ($return)
{
return $secret;
}
else
{
$k = 'form_' . $page_name;
setcookie($k, $secret, 0, '/');
if (!isset($_SESSION))
{
session();
}
$_SESSION[$k] = $secret;
}
}
}
Function Calls
None |
Stats
MD5 | 5202ff3a07d994f955e53dfa3e77a3a3 |
Eval Count | 0 |
Decode Time | 140 ms |