Serialised Example : API

 

Serialised PHP Class Example

The following example is for wGET it will work with any PHP Class library, you may need to install the JSON library for PHP or use the PEAR class:

<?php

define
('XORTIFY_JSON_API''http://xortify.chronolabs.coop/serial/');

define('XOOPS_SERIALIZE_LIB''PHPSERIALIZE');

if (!
function_exists("xortify_obj2array")) {
    function 
xortify_obj2array($objects) {
        
$ret = array();
        foreach(
$objects as $key => $value) {
            if (
is_a($value'stdClass')) {
                
$ret[$key] = xortify_obj2array((array)$value);
            } elseif (
is_array($value)) {
                
$ret[$key] = xortify_obj2array($value);
            } else {
                
$ret[$key] = $value;
            }
        }
        return 
$ret;
    }
}

if (!
function_exists("getIPData")) {
    function 
getIPData($ip=false){
        
$ret = array();
        if (
is_object($GLOBALS['xoopsUser'])) {
            
$ret['uid'] = $GLOBALS['xoopsUser']->getVar('uid');
            
$ret['uname'] = $GLOBALS['xoopsUser']->getVar('uname');
            
$ret['email'] = $GLOBALS['xoopsUser']->getVar('email');
        } else {
            
$ret['uid'] = 0;
            
$ret['uname'] = $_REQUEST['uname'];
            
$ret['email'] = $_REQUEST['email'];
        }
        if (!
$ip) {
            if (
$_SERVER["HTTP_X_FORWARDED_FOR"] != ""){ 
                
$ip = (string)$_SERVER["HTTP_X_FORWARDED_FOR"]; 
                
$ret['is_proxied'] = true;
                
$proxy_ip $_SERVER["REMOTE_ADDR"]; 
                
$ret['network-addy'] = @gethostbyaddr($ip); 
                
$ret['long'] = @ip2long($ip);
                if (
is_ipv6($ip)) {
                    
$ret['ip6'] = $ip;
                    
$ret['proxy-ip6'] = $proxy_ip;
                } else {
                    
$ret['ip4'] = $ip;
                    
$ret['proxy-ip4'] = $proxy_ip;
                }
            }else{ 
                
$ret['is_proxied'] = false;
                
$ip = (string)$_SERVER["REMOTE_ADDR"]; 
                
$ret['network-addy'] = @gethostbyaddr($ip); 
                
$ret['long'] = @ip2long($ip);
                if (
is_ipv6($ip)) {
                    
$ret['ip6'] = $ip;
                } else {
                    
$ret['ip4'] = $ip;
                }
            } 
        } else {
            
$ret['is_proxied'] = false;
            
$ret['network-addy'] = @gethostbyaddr($ip); 
            
$ret['long'] = @ip2long($ip);
            if (
is_ipv6($ip)) {
                
$ret['ip6'] = $ip;
            } else {
                
$ret['ip4'] = $ip;
            }
        }
        
$ret['made'] = time();                
        return 
$ret;
    }
}

if (!
function_exists("is_ipv6")) {
    function 
is_ipv6($ip ""
    { 
        if (
$ip == ""
            return 
false;
            
        if (
substr_count($ip,":") > 0){ 
            return 
true
        } else { 
            return 
false
        } 
    } 
}

class 
JSONXortifyExchange {

    var 
$json_client;
    var 
$json_xoops_username '';
    var 
$json_xoops_password '';
    var 
$refresh 600;
    var 
$json '';
    
    function 
__construct()
    {
        
$this->JSONXortifyExchange ();
    }
    
    function 
JSONXortifyExchange () {
    
        
$configs['xortify_username'] = 'user';
        
$configs['xortify_password'] = 'pass';
        
$configs['xortify_records'] = 1200;

        
$this->json_xoops_username $configs['xortify_username'];
        
$this->json_xoops_password md5($configs['xortify_password']);
        
$this->refresh $configs['xortify_records'];
            
    }

    function 
sendBan($comment$category_id 2$ip=false) {

        
$ipData getIPData($ip);
        
        switch (
XOOPS_SERIALIZE_LIB){
        default:
        case 
"PHPSERIALIZE":
            
$data file_get_contents(XORTIFY_JSON_API.'?ban='.urlencode(serialize( array(      "username"    =>     $this->json_xoops_username
                            
"password"    =>     $this->json_xoops_password
                            
"bans"         =>     array(    0     =>     array_merge(
                                                                        
$ipData
                                                                        array(
'category_id' => $category_id)
                                                                        )
                                            ),
                            
"comments"     =>     array(    0    =>    array(    'uname'        =>        $this->json_xoops_username
                                                                    
"comment"     =>         $comment
                                                            
)
                                             ) 
                    ))));
            
$result xortify_obj2array(unserialize($data));
            break;
        }            
        return 
$result;    
    }

    function 
checkBans($ipdata) {
        
        switch (
XOOPS_SERIALIZE_LIB){
        default:
        case 
"PHPSERIALIZE":
            
$data file_get_contents(XORTIFY_JSON_API.'?banned='.urlencode(serialize
                    array(  
"username"    =>     $this->json_xoops_username
                            
"password"    =>     $this->json_xoops_password
                            
"ipdata"     =>     $ipdata)
                    ))));
            
$result xortify_obj2array(unserialize($data));
            break;
        }            
        return 
$result;    
    }
    
    function 
checkUnbans($ipdata) {
        
        switch (
XOOPS_SERIALIZE_LIB){
        default:
        case 
"PHPSERIALIZE":
            
$data file_get_contents(XORTIFY_JSON_API.'?unbanned='.urlencode(serialize
                    array(  
"username"    =>     $this->json_xoops_username
                            
"password"    =>     $this->json_xoops_password
                            
"ipdata"     =>     $ipdata)
                    ))));
            
$result xortify_obj2array(unserialize($data));
            break;
        }            
        return 
$result;    
    }
    
    function 
checkSFSBans($ipdata) {
        
        switch (
XOOPS_SERIALIZE_LIB){
        default:
        case 
"PHPSERIALIZE":
            
$data file_get_contents(XORTIFY_JSON_API.'?checksfsbans='.urlencode(serialize
                    array(  
"username"    =>     $this->json_xoops_username
                            
"password"    =>     $this->json_xoops_password
                            
"ipdata"     =>     array_merge($ipdata, array('category_id' => $category_id))
                    ))));
            
$result xortify_obj2array(unserialize($data));
            break;
        }            
        return 
$result;    
    }

    function 
checkPHPBans($ipdata) {
        
        switch (
XOOPS_SERIALIZE_LIB){
        default:
        case 
"PHPSERIALIZE":
            
$data file_get_contents(XORTIFY_JSON_API.'?checkphpbans='.urlencode(serialize
                    array(  
"username"    =>     $this->json_xoops_username
                            
"password"    =>     $this->json_xoops_password
                            
"ipdata"     =>     $ipdata
                    
))));
            
$result xortify_obj2array(unserialize($data));
            break;
        }            
        return 
$result;    
    }    

    function 
retrieveBans() {
        switch (
XOOPS_SERIALIZE_LIB){
        default:
        case 
"PHPSERIALIZE":
            
$data file_get_contents(XORTIFY_JSON_API.'?bans='.urlencode(serialize(array("username"=> $this->json_xoops_username"password"=> $this->json_xoops_password,  "records"=> $this->refresh))));
            
$result xortify_obj2array(unserialize($data));
            break;
        }
        return 
$result;
    }

    function 
retrieveUnbans() {
        switch (
XOOPS_SERIALIZE_LIB){
        default:
        case 
"PHPSERIALIZE":
            
$data file_get_contents(XORTIFY_JSON_API.'?unbans='.urlencode(serialize(array("username"=> $this->json_xoops_username"password"=> $this->json_xoops_password,  "records"=> $this->refresh))));
            
$result xortify_obj2array(unserialize($data));
            break;
        }
        return 
$result;
    }

    function 
sendSpider($spider) {
        switch (
XOOPS_SERIALIZE_LIB){
        case 
"PHPSERIALIZE":
            
$data file_get_contents(XORTIFY_JSON_API.'?spider='.urlencode(serialize(array("username" => $this->json_xoops_username"password"    => $this->json_xoops_password"spider" => $spider ))));
            
$result xortify_obj2array(unserialize($data));
            break;
        }
            
        return 
$result;    
    }
    
    function 
sendStatistic($statistic) {
        switch (
XOOPS_SERIALIZE_LIB){
        case 
"PHPSERIALIZE":
            
$data file_get_contents(XORTIFY_JSON_API.'?spiderstat='.urlencode(serialize(array("username" => $this->json_xoops_username"password"    => $this->json_xoops_password"statistic" => $statistic ))));
            
$result xortify_obj2array(unserialize($data));
            break;
        }
            
        return 
$result;    
    }
    
    function 
getSpiders() {
        switch (
XOOPS_SERIALIZE_LIB){
        case 
"PHPSERIALIZE":
            
$data file_get_contents(XORTIFY_JSON_API.'?spiders='.urlencode(serialize(array( "username" => $this->json_xoops_username"password"    =>     $this->json_xoops_password ))));
            
$result xortify_obj2array(unserialize($data));
            break;
        }
        return 
$result['robots'];
    }
    
    function 
getSEOLinks() {
        switch (
XOOPS_SERIALIZE_LIB){
        case 
"PHPSERIALIZE":
            
$data file_get_contents(XORTIFY_JSON_API.'?seolinks='.urlencode(serialize(array( "username" => $this->json_xoops_username"password"    =>     $this->json_xoops_password ))));
            
$result xortify_obj2array(unserialize($data));;
            break;
        }
        return 
$result['seolinks'];    
    }
}

?>
Written by: System Overlord 2011/4/21