Skip to content

Instantly share code, notes, and snippets.

@jrivero
Forked from navarr/class_typesetting.php
Created December 13, 2010 01:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrivero/738532 to your computer and use it in GitHub Desktop.
Save jrivero/738532 to your computer and use it in GitHub Desktop.
<?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