Initial commit
This commit is contained in:
commit
998d011cd3
233 changed files with 36893 additions and 0 deletions
35
onyx/require/cache.php
Normal file
35
onyx/require/cache.php
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
class Cache
|
||||
{
|
||||
|
||||
static function set($id,$var)
|
||||
{
|
||||
$file = '<?php $cache = '.var_export($var,TRUE).'; ?>';
|
||||
|
||||
file_put_contents(ONYX.'cache/'.md5($id).'.cache.php',$file) or trigger_error('dossier cache inaccessible en écriture.',E_USER_ERROR);
|
||||
}
|
||||
|
||||
static function read($id)
|
||||
{
|
||||
if(!is_readable(ONYX.'cache/'.md5($id).'.cache.php')) return FALSE;
|
||||
|
||||
include(ONYX.'cache/'.md5($id).'.cache.php');
|
||||
if(!$cache) return FALSE;
|
||||
return $cache;
|
||||
}
|
||||
|
||||
static function del($id)
|
||||
{
|
||||
if(!is_file(ONYX.'cache/'.md5($id).'.cache.php')) return FALSE;
|
||||
return unlink(ONYX.'cache/'.md5($id).'.cache.php');
|
||||
}
|
||||
|
||||
static function flush()
|
||||
{
|
||||
foreach(glob(ONYX.'cache/*.cache.php') as $file) unlink($file);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
49
onyx/require/env.php
Normal file
49
onyx/require/env.php
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
function elog($message,$level = 0,$dir = NULL,$file = NULL)
|
||||
{
|
||||
$dir = empty($dir) ? ONYX."log" : $dir;
|
||||
$file = empty($file) ? strftime('%d-%m-%y').".log" : $file;
|
||||
|
||||
if($fichier = fopen("$dir/$file",'a+'))
|
||||
{
|
||||
switch($level)
|
||||
{
|
||||
default:
|
||||
case 0: $level = 'MESSAGE'; break;
|
||||
case 1: $level = 'AVERTISSEMENT'; break;
|
||||
case 2: $level = 'ERREUR'; break;
|
||||
}
|
||||
$time = strftime('%d/%m/%y %H:%M:%S');
|
||||
$req = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD']: '';
|
||||
$arg = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI']: '';
|
||||
$remote = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR']: '';
|
||||
$ua = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT']: '';
|
||||
$referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER']: '';
|
||||
$line = "[$time] $level : $message [$remote] [$req] [$arg] [$ua] [$referer]\r\n";
|
||||
fwrite($fichier,$line);
|
||||
fclose($fichier);
|
||||
}
|
||||
else trigger_error('Log non accessible en ecriture',E_USER_ERROR);
|
||||
}
|
||||
|
||||
function gpc($name,$method='get',$default=NULL)
|
||||
{
|
||||
switch($method)
|
||||
{
|
||||
default:
|
||||
case 'get': $var = isset($_GET[$name]) ? $_GET[$name] : $default; break;
|
||||
case 'post': $var = isset($_POST[$name]) ? $_POST[$name] : $default; break;
|
||||
case 'cookie': $var = isset($_COOKIE[$name]) ? $_COOKIE[$name] : $default; break;
|
||||
}
|
||||
|
||||
if(get_magic_quotes_gpc()) $var = stripslashes($var);
|
||||
return $var;
|
||||
}
|
||||
|
||||
/*function cookie($name,$value,$time = 3600)
|
||||
{
|
||||
setcookie($name,$value,$time);
|
||||
}*/
|
||||
|
||||
?>
|
||||
73
onyx/require/parse.php
Normal file
73
onyx/require/parse.php
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
|
||||
function parse_config($node,$name = 'var',$attribut = 'name')
|
||||
{
|
||||
@$configs = $node->childNodes;
|
||||
if($configs)
|
||||
{
|
||||
$array = array();
|
||||
|
||||
foreach($configs as $value)
|
||||
{
|
||||
if($value->nodeName == $name)
|
||||
{
|
||||
if($value->getElementsByTagName($name)->length == 0)
|
||||
{
|
||||
$array[$value->getAttribute($attribut)] = trim($value->textContent);
|
||||
}
|
||||
else $array[$value->getAttribute($attribut)] = parse_config($value,$name,$attribut);
|
||||
}
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
else return array();
|
||||
}
|
||||
|
||||
/*function parse($file)
|
||||
{
|
||||
$xml = new DOMDocument();
|
||||
|
||||
$xml->load($file);
|
||||
#$xml->validate();
|
||||
|
||||
if($root = $xml->documentElement->getAttribute('root'))
|
||||
{
|
||||
if($root == substr(FILE,0,strlen($root)))
|
||||
{
|
||||
$search = substr(FILE,strlen($root));
|
||||
|
||||
$paths = explode('/',$search);
|
||||
$paths2 = $paths;
|
||||
foreach($paths as $key => $path)
|
||||
{
|
||||
for($i = $key - 1; $i >= 0; $i--)
|
||||
{
|
||||
$paths2[$key] = $paths[$i] . '/' . $paths2[$key];
|
||||
}
|
||||
if($key != count($paths) - 1) $paths2[$key] .= '/';
|
||||
}
|
||||
|
||||
foreach($xml->getElementsByTagName('config') as $value)
|
||||
{
|
||||
$config[$value->getAttribute('match')] = $value;
|
||||
}
|
||||
|
||||
$parsed = array();
|
||||
array_unshift($paths2,'*');
|
||||
|
||||
foreach($paths2 as $path)
|
||||
{
|
||||
if($config[$path]) $parsed = array_merge($parsed,parse_config($config[$path]));
|
||||
}
|
||||
|
||||
return $parsed;
|
||||
}
|
||||
}
|
||||
else return FALSE;
|
||||
}
|
||||
|
||||
define('FILE','/var/www/site/test/test.php');
|
||||
|
||||
print_r(parse('../config/root.xml'));*/
|
||||
|
||||
?>
|
||||
109
onyx/require/str.php
Normal file
109
onyx/require/str.php
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
<?php
|
||||
function hexstr($var)
|
||||
{
|
||||
return pack('H*',$var);
|
||||
}
|
||||
|
||||
function strhex($var)
|
||||
{
|
||||
$tab = unpack('H*',$var);
|
||||
return $tab[1];
|
||||
}
|
||||
|
||||
function bitstr($var)
|
||||
{
|
||||
$r = NULL;
|
||||
for($i = 0; $i < strlen($var); $i += 8) $r .= chr(bindec(substr($var,$i,8)));
|
||||
return $r;
|
||||
}
|
||||
|
||||
function bithex($var)
|
||||
{
|
||||
$r = NULL;
|
||||
for($i = 0; $i < strlen($var); $i += 4) $r .= base_convert(substr($var,$i,4),2,16);
|
||||
return $r;
|
||||
}
|
||||
|
||||
|
||||
if (!function_exists('hex2bin'))
|
||||
{
|
||||
function hex2bin($str)
|
||||
{
|
||||
$bin = "";
|
||||
$i = 0;
|
||||
do
|
||||
{
|
||||
$bin .= chr(hexdec($str{$i}.$str{($i + 1)}));
|
||||
$i += 2;
|
||||
}
|
||||
while ($i < strlen($str));
|
||||
return $bin;
|
||||
}
|
||||
}
|
||||
function cxor($msg,$cle)
|
||||
{
|
||||
$xor = NULL;
|
||||
for($i = 0; $i < strlen($msg);$i++) $xor .= substr($msg,$i,1) ^ substr($cle,$i % strlen($cle),1);
|
||||
return $xor;
|
||||
}
|
||||
|
||||
function random($l=128)
|
||||
{
|
||||
$r = NULL;
|
||||
for($i = 1;$i <= $l/128 && $l/128 <= 32; $i++)
|
||||
{
|
||||
$var = time().microtime().mt_rand().md5(time()).md5(microtime()).md5(mt_rand()).sha1(time()).sha1(microtime()).sha1(mt_rand());
|
||||
$r .= md5(cxor(md5($var,TRUE),sha1($var,TRUE)));
|
||||
}
|
||||
return $r;
|
||||
}
|
||||
|
||||
function uniquehash($var,$length=128,$raw=FALSE)
|
||||
{
|
||||
$hashs = array('tiger192,4','haval256,5','md5','snefru','gost','ripemd160','whirlpool');
|
||||
$r = hash('sha512',$var,TRUE);
|
||||
|
||||
foreach($hashs as $algo) $r = cxor(strrev($r),hash($algo,strrev($r),TRUE));
|
||||
|
||||
if($length % 8 == 0 && $length >=128 && $length <= 512) $r = substr($r,0,$length/8);
|
||||
if(!$raw) $r = strhex($r);
|
||||
|
||||
return $r;
|
||||
}
|
||||
|
||||
function temphash($var,$length=128,$raw=FALSE)
|
||||
{
|
||||
if(!$val = Cache::read('_temphash')) Cache::set('_temphash',$val = hexstr(random()));
|
||||
|
||||
return uniquehash(cxor($var,$val),$length,$raw);
|
||||
}
|
||||
|
||||
function decode_ip($int_ip)
|
||||
{
|
||||
return inet_ntop(hex2bin($int_ip));
|
||||
}
|
||||
|
||||
function encode_ip($ip=FALSE)
|
||||
{
|
||||
if(!$ip)
|
||||
$ip = $_SERVER['REMOTE_ADDR'];
|
||||
|
||||
return bin2hex(inet_pton($ip));
|
||||
}
|
||||
|
||||
function url($string,$external=FALSE)
|
||||
{
|
||||
if($external) return htmlspecialchars($string);
|
||||
|
||||
global $VAR;
|
||||
|
||||
if(!empty($VAR['rewrite_url']))
|
||||
{
|
||||
$masque = $VAR['rewrite_url']['masque'];
|
||||
$replace = $VAR['rewrite_url']['replace'];
|
||||
$var = preg_replace($masque,$replace,$string);
|
||||
return htmlspecialchars($var);
|
||||
}
|
||||
else return htmlspecialchars($string);
|
||||
}
|
||||
?>
|
||||
Reference in a new issue