Просмотр файла FreeWeatherInformers/queryApi.php

Размер файла: 2.1Kb
<?php

/*
 *       Copyright (C) W@P Labs Group
 *       Product name: Free Informers
 *        Web Site: http://waplabs.ru
 *       Web Site: http://x-engine.net
 *
 *  This script is redistributed to the free
 *     conditions, observe copyright and
 *    appreciate the work of programmers.
 *       Sincerely Michael aka Sklep
 *
 *  Founder of the project Michael aka Sklep
 *      (Jabber id: [email protected])
 */

/**
 * Connections to api.x-engine.net
 *
 * @author Michael aka Sklep
 */
class queryApi {

    static $Username = null;
    static $Password = null;

    static public function setAuth($username, $password) {
        self::$Username = $username;
        self::$Password = $password;
    }

    static public function send($value='') {
        if (is_array($value)) {
            if (function_exists('curl_init')) {
                $c = curl_init('https://api.x-engine.net/');
                curl_setopt($c, CURLOPT_RETURNTRANSFER, TRUE);
                curl_setopt($c, CURLOPT_TIMEOUT, 15);
                curl_setopt($c, CURLOPT_SSL_VERIFYPEER, FALSE);
                curl_setopt($c, CURLOPT_SSL_VERIFYHOST, FALSE);
                curl_setopt($c, CURLOPT_USERAGENT, 'X-Engine Mobile CMS (net client v0.1)');
                curl_setopt($c, CURLOPT_POST, TRUE);
                curl_setopt($c, CURLOPT_POSTFIELDS, array('ini' => base64_encode(json_encode($value)),
                    'Username' => self::$Username,
                    'Password' => md5(self::$Password)
                ));

                $ext = curl_exec($c);
                curl_close($c);

                if (($result = @json_decode($ext))) {
                    return $result;
                } else {
                    return array('error_text' => 'Правильного ответа от API сервера не полученно.',
                        'error_code' => 'API_SERVER_NOTANSWER',
                        'result' => 'error',
                        'data_answer' => $ext);
                }
            } else {
                exit('Библиотека cUrl не найдена.');
            }
        }
    }

}

?>