Commit 494b351f authored by Alex Ne's avatar Alex Ne

Обнова от проекта SW-Ranks

parent 11d5e29e
......@@ -71,7 +71,9 @@ class X_DB_MySQLi
public function Connect()
{
if(!isset(X_DB_MySQLi::$LINK[$this->DBLN]) || !X_DB_MySQLi::$LINK[$this->DBLN]->ping() )
if(!isset(X_DB_MySQLi::$LINK[$this->DBLN])
|| !(X_DB_MySQLi::$LINK[$this->DBLN] instanceof mysqli)
|| !X_DB_MySQLi::$LINK[$this->DBLN]->ping() )
{
X_DB_MySQLi::$LINK[$this->DBLN] = new mysqli( $this->DBHOST, $this->DBUSER, $this->DBPASS, $this->DBNAME );
X_DB_MySQLi::$LINK[$this->DBLN]->set_charset( $this->DBCHARSET );
......@@ -93,17 +95,58 @@ class X_DB_MySQLi
return $this->insert($type.' INTO `'.$tableName.'` (`'.implode('`,`', $keys).'`) VALUES (\''.implode('\',\'', $values).'\')');
}
public function update($tableName, $arrayParams, $whereParams = null)
{
if( !is_array($arrayParams) || count($arrayParams) == 0 ) return false;
$params = "";
foreach ($arrayParams as $key => $value) {
$params .= "`".$key."` = '".$this->esc($value)."',";
}
$params = trim($params, ",");
$WHERE = "";
if($whereParams != null)
{
if(is_array($whereParams) && count($whereParams)>0 && is_string($whereParams[0]))
{
$WHERE = "WHERE ".$this->construct_where_param($whereParams);
}
else if(is_array($whereParams) && count($whereParams)>0 && is_array($whereParams[0]) && count($whereParams[0])>0 )
{
foreach ($whereParams as $value)
{
if(strlen($WHERE) == 0 ) $WHERE = "WHERE "; else $WHERE .= " AND ";
$WHERE .= $this->construct_where_param($value);
}
}
}
return $this->rq('UPDATE `'.$tableName.'` SET '.$params.' '.$WHERE);
}
private function construct_where_param($whereParams)
{
if(count($whereParams) == 2 )
return "`".$whereParams[0]."`='".$this->esc($whereParams[1])."'";
if(count($whereParams) == 3 )
return "`".$whereParams[0]."`".$whereParams[1]."'".$this->esc($whereParams[2])."'";
}
public function insert($SQL)
{
if( X_DB_MySQLi::$LINK[$this->Connect()->DBLN]->real_query($SQL) ) return X_DB_MySQLi::$LINK[$this->DBLN]->insert_id;
else throw new Exception(X_DB_MySQLi::$LINK[$this->DBLN]->error, X_DB_MySQLi::$LINK[$this->DBLN]->errno);
}
public function esc( $value )
{
return X_DB_MySQLi::$LINK[$this->Connect()->DBLN]->real_escape_string( $value );
}
public function rq( $SQL )
{
if( X_DB_MySQLi::$LINK[$this->Connect()->DBLN]->real_query($SQL) ) return true;
else throw new Exception(X_DB_MySQLi::$LINK[$this->DBLN]->error, X_DB_MySQLi::$LINK[$this->DBLN]->errno);
}
public function get($SQL,$ID_COL=false,$ID_COL2=false,$ID_COL3=false)
{
if($this->rq($SQL))
......@@ -141,10 +184,28 @@ class X_DB_MySQLi
else return false;
}
public function delete_in($table, $column, $data)
{
if(!(count($data)>0)) return false;
$SQL = "DELETE FROM";
$SQL .= " `".$table."` ";
$SQL .= "WHERE";
$SQL .= " `".$column."` in('";
$SQL .= implode("','", $data);
$SQL .= "')";
return $this->rq($SQL);
}
function __destruct()
{
if ( isset( X_DB_MySQLi::$LINK[$this->DBLN] ) && X_DB_MySQLi::$LINK[$this->DBLN]->ping() )
if ( isset( X_DB_MySQLi::$LINK[$this->DBLN] )
&& X_DB_MySQLi::$LINK[$this->DBLN] instanceof mysqli
&& X_DB_MySQLi::$LINK[$this->DBLN]->ping()
)
{
X_DB_MySQLi::$LINK[$this->DBLN]->close();
unset(X_DB_MySQLi::$LINK[$this->DBLN]);
}
}
}
?>
\ No newline at end of file
......@@ -6,12 +6,12 @@ class X_ErrorWriter
{
static $AllErrorList = [];
public $ErrorList = [];
function __construct($Type, $Message, $File, $Line, $StackTrace=false)
function __construct($Type, $Message, $File, $Line, $StackTrace=false, $vars = "")
{
$this->fixError($Type, $Message, $File, $Line, $StackTrace);
$this->fixError($Type, $Message, $File, $Line, $StackTrace, $vars);
}
public function fixError($Type, $Message, $File, $Line, $StackTrace=false)
public function fixError($Type, $Message, $File, $Line, $StackTrace=false, $vars = "")
{
$File = str_replace(ROOT_DIR, "", $File);
$Message = str_replace(ROOT_DIR, "", $Message);
......@@ -28,6 +28,7 @@ class X_ErrorWriter
$this->ErrorList[$ErrorIndex]['message'] = $StackTrace?$Message."\n".$StackTrace:$Message;
$this->ErrorList[$ErrorIndex]['file'] = $File;
$this->ErrorList[$ErrorIndex]['line'] = $Line;
$this->ErrorList[$ErrorIndex]['vars'] = $vars;
$this->ErrorList[$ErrorIndex]['time'] = time();
}
X_ErrorWriter::$AllErrorList[$ErrorIndex] = $this->ErrorList[$ErrorIndex];
......
<?php
/**
*
*/
class X_Input
{
protected $Value;
protected $Default = false;
function __construct()
{
}
public function lower_string()
{
return strtolower($this->string());
}
public function bool()
{
if (!is_string($this->Value)) return (bool) $this->Value;
switch ( strtolower( trim( $this->Value ) ) )
{
case 'true':
case 'on':
case 'yes':
case 'y':
case '1':
return true;
break;
default:
return false;
break;
}
}
public function str_replace($search, $replace)
{
return (is_string($this->Value))?str_replace($search, $replace, $this->Value):"";
}
public function explode($delimiter)
{
return (is_string($this->Value))?explode($delimiter, $this->Value):[];
}
public function int()
{
if($this->Default === false) $this->Default = 0;
return intval($this->Value);
}
public function numeric()
{
return (is_numeric($this->Value)) ? $this->Value : 0;
}
public function string()
{
return strval($this->Value);
}
public function json_decode()
{
if($this->Value == null) return null;
if($this->Value == false) return false;
return json_decode($this->Value,true);
}
public function RequestValue( $Name, $Default=false )
{
return $this->Request( $Name, $Default )->Value;
}
public function Request( $Name, $Default=false )
{
return (new X_Input_RequestItem($Name, $Default));
}
public function PostValue( $Name, $Default=false )
{
return $this->Request( $Name, $Default )->Value;
}
public function Post( $Name, $Default=false )
{
return (new X_Input_MethodPostItem($Name, $Default));
}
public function GetValue( $Name, $Default=false )
{
return $this->Get( $Name, $Default )->Value;
}
public function Get( $Name, $Default=false )
{
return (new X_Input_MethodGetItem($Name, $Default));
}
public function CookieValue( $Name, $Default=false )
{
return $this->Cookie( $Name, $Default )->Value;
}
public function Cookie( $Name, $Default=false )
{
return (new X_Input_MethodCookieItem($Name, $Default));
}
}
?>
\ No newline at end of file
<?php
/**
*
*/
class X_Input_MethodCookieItem extends X_Input
{
public $Name;
public $Value;
protected $Default = false;
function __construct( $Name, $Default=false )
{
$this->Name = $Name;
$this->get_value( $Name, $Default );
}
public function is_set()
{
return isset($_COOKIE[ $this->Name ]);
}
public function DefaultValue($Default)
{
$this->get_value( $this->Name, $Default );
return $this;
}
private function get_value( $name, $default=false )
{
$this->Default = $default;
if ( isset( $_COOKIE[ $name ] ) )
$this->Value = $_COOKIE[ $name ];
else
$this->Value = $this->Default;
}
}
?>
\ No newline at end of file
<?php
/**
*
*/
class X_Input_MethodGetItem extends X_Input
{
public $Name;
public $Value;
protected $Default = false;
function __construct( $Name, $Default=false )
{
$this->Name = $Name;
$this->get_value( $Name, $Default );
}
public function is_set()
{
return isset($_GET[ $this->Name ]);
}
public function DefaultValue($Default)
{
$this->get_value( $this->Name, $Default );
return $this;
}
private function get_value( $name, $default=false )
{
$this->Default = $default;
if ( isset( $_GET[ $name ] ) )
$this->Value = $_GET[ $name ];
else
$this->Value = $this->Default;
}
}
?>
\ No newline at end of file
<?php
/**
*
*/
class X_Input_MethodPostItem extends X_Input
{
public $Name;
public $Value;
protected $Default = false;
function __construct( $Name, $Default=false )
{
$this->Name = $Name;
$this->get_value( $Name, $Default );
}
public function is_set()
{
return isset($_POST[ $this->Name ]);
}
public function DefaultValue($Default)
{
$this->get_value( $this->Name, $Default );
return $this;
}
private function get_value( $name, $default=false )
{
$this->Default = $default;
if ( isset( $_POST[ $name ] ) )
$this->Value = $_POST[ $name ];
else
$this->Value = $this->Default;
}
}
?>
\ No newline at end of file
<?php
/**
*
*/
class X_Input_RequestItem extends X_Input
{
public $Name;
public $Value;
protected $Default = false;
function __construct( $Name, $Default=false )
{
$this->Name = $Name;
$this->get_value( $Name, $Default );
}
public function is_set()
{
return isset($_REQUEST[ $this->Name ]);
}
public function DefaultValue($Default)
{
$this->get_value( $this->Name, $Default );
return $this;
}
private function get_value( $name, $default=false )
{
$this->Default = $default;
if ( isset( $_REQUEST[ $name ] ) )
$this->Value = $_REQUEST[ $name ];
else
$this->Value = $this->Default;
}
}
?>
\ No newline at end of file
<?php
if (!defined('DS')) define('DS', DIRECTORY_SEPARATOR);
spl_autoload_register(
function ($className) {
$classPath = explode('_', $className);
if ( array_shift( $classPath ) != 'X') return;
if ( ctype_digit( end( $classPath ) ) ) $V = "_" . array_pop($classPath); else $V = ""; // Version Control
$filePath = dirname(__FILE__) . DS . implode(DS, $classPath) . $V . '.php';
if ( count($classPath) == 0 ) $classPath[] = "X";
if ( file_exists($filePath) ) require_once($filePath);
}
);
?>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment