Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace YetAnotherPanel;
- final class Engine extends Core implements i_Engine
- {
- private $mySQL_Server = '',
- $mySQL_Username = '',
- $mySQL_Password = '',
- $mySQL_Database = '',
- $mySQL_Link = '',
- $mySQL_Connected = false;
- protected static $params = array(), $queryCount = 0, $rawQuery = '';
- final public function __construct( array $dbArray )
- {
- $this->mySQL_Server = $dbArray['Server'];
- $this->mySQL_Username = $dbArray['Username'];
- $this->mySQL_Password = $dbArray['Password'];
- $this->mySQL_Database = $dbArray['Database'];
- try
- {
- $this->connect();
- }
- catch( Error $e ){}
- }
- public function randomChars( $len = 20, $isNumeric = false, $withSpecials = true )
- {
- if( $isNumeric )
- {
- $poss = '1234567890';
- }
- else
- {
- $poss = '1234567890QWERTYUIOASDFGHJKLZXCVBNMqwertyuioasdfghjklzxcvbnm';
- if( $withSpecials )
- {
- $poss .= '!£$%^&*';
- }
- }
- for( $i = 1; $i <= $len; $i++ )
- {
- $randomChars .= substr($poss, rand( 1, strlen( $poss ) - 1 ), 1 );
- }
- return $randomChars;
- }
- final public function connect()
- {
- if( !$this->mySQL_Link = @$this->functions['connect']( $this->mySQL_Server, $this->mySQL_Username, $this->mySQL_Password ) )
- {
- throw new Error('Can not connect to mySQL server. <br /><br />'. $this->functions['error'] );
- }
- if( !@$this->functions['select_db']( $this->mySQL_Database, $this->mySQL_Link ) )
- {
- throw new Error('Can not connect to database. <br /><br />'. $this->functions['error'] );
- }
- unset( $mySQL_Server, $mySQL_Username, $mySQL_Password, $mySQL_Database );
- $this->mySQL_Connected = true;
- }
- final public static function rawQuery($Query, $params = array() )
- {
- $find = '/\{([0-9]+)(,)?( )?([ibds]{1})?\}/s';
- if( preg_match( $find, $Query ) )
- {
- self::$params = $params;
- while( (bool) (int) preg_match( $find, $Query ) )
- {
- $Query = preg_replace_callback(
- $find,
- create_function('$ma', 'return YetAnotherPanel\Engine::returnParam( $ma[ 1 ], $ma[ 4 ] );' ),
- $Query
- );
- }
- }
- self::$rawQuery = self::filterPreParams( $Query );
- try
- {
- $Query = @mysql_query( self::$rawQuery );
- if( @mysql_error() )
- {
- throw new Error('Could not execute mySQL query. <br /><br /><strong>Raw Query</strong>: <br /><br />'.self::$rawQuery . ' <br /><br /><strong>Error</strong>: <br /><br />' . mysql_error() );
- }
- }
- catch( Error $e ){}
- return $Query;
- }
- final private static function filterPreParams( $query )
- {
- $find = array( '{prefix}', '{now}' );
- $replace = array( 'yap_', 'UNIX_TIMESTAMP()' );
- return str_replace( $find, $replace, $query );
- }
- final public static function returnParam( $arrayNumber = '', $arrayType = 's' )
- {
- $param = self::$params[ $arrayNumber ];
- switch( $arrayType )
- {
- default:
- case 's':
- $param = mysql_real_escape_string( $param );
- $param = htmlentities( $param );
- break;
- case 'i':
- if( !is_numeric( $param ) )
- {
- return '"0"';
- }
- break;
- case 'b':
- if( !is_bool( $param ) )
- {
- return '"0"';
- }
- break;
- case 'd':
- if( !is_double( $param ) )
- {
- return '"0"';
- }
- break;
- }
- return '"'. self::$params[ $arrayNumber ] . '"';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement