-
-
Save jrivero/738532 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class GenericVariable | |
{ | |
private $var; | |
function __construct($variable) | |
{ | |
$this->var = $variable; | |
} | |
function __get($var) | |
{ | |
return $this->{$var}; | |
} | |
} | |
class String extends GenericVariable | |
{ | |
const TEXT = 1; // Normal Text (Will make XML & SQL "Safe") | |
const HTML = 2; // HTML (Will make SQL "Safe") | |
const XML = 2; // XML "Ditto" | |
const SQL = 4; // SQL (Won't SQL Escape) | |
const BBCODE = 8; // BBCODE | |
private $var; | |
private $sql; | |
private $html; | |
private $text; | |
private $bbcode; | |
private $html_attr; | |
private $type; | |
function __construct($string,$type = 1) | |
{ | |
global $bbcodeparser; | |
$this->type = $type; | |
$string = trim($string); // Trim It | |
$this->var = $string; | |
if($type & self::HTML) | |
{ | |
$this->var = html_entity_decode($this->var); | |
$this->html = $string; // Oh, you're giving us HTML? | |
} | |
else | |
{ | |
$this->html = htmlspecialchars($string); | |
} | |
if($type & self::SQL) | |
{ | |
$this->var = stripslashes($this->var); | |
$this->html = stripslashes($this->html); | |
$this->sql = $string; | |
} | |
elseif(mysql_ping()) | |
{ | |
$this->sql = mysql_real_escape_string($this->var); | |
} | |
if($type & self::BBCODE && $bbcodeparser) | |
{ | |
if($type & self::HTML) { $this->bbcode = $bbcodeparser->parse($this->var); } | |
else { $this->bbcode = $bbcodeparser->parse($this->var,false); } | |
} else { | |
$this->bbcode = $this->var; | |
} | |
$this->html_attr = htmlspecialchars($this->var,ENT_QUOTES); | |
$this->text = $this->var; | |
} | |
function __invoke($string,$type = 0) | |
{ | |
if($type == 0) | |
{ | |
$type = $this->type; | |
} | |
$this->__construct($string,$type); | |
} | |
function __get($var) | |
{ | |
return $this->{$var}; | |
} | |
function __set($var,$val) | |
{ | |
if($var == "var") | |
{ | |
$this->__construct($val); | |
} | |
} | |
function __toString() | |
{ | |
return $this->var; | |
} | |
} | |
class Number extends GenericVariable | |
{ | |
private $var; | |
private $int; | |
private $float; | |
function __construct($int) | |
{ | |
if(is_numeric($int)) { $this->var = $int; } | |
else { $this->var = 0;$int = 0; } | |
$this->int = &$this->var; | |
$this->float = floatval($int); | |
} | |
function __get($var) | |
{ | |
return $this->{$var}; | |
} | |
function __set($var,$val) | |
{ | |
if($var == "var") | |
{ | |
$this->__construct($val); | |
} | |
} | |
function __invoke($int) | |
{ | |
$this->__construct($int); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment