コード例 #1
0
ファイル: api.php プロジェクト: osuisumi/OS.js
                    }
                }
            }
            if ($ch = curl_init()) {
                curl_setopt($ch, CURLOPT_URL, $url);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                if ($timeout) {
                    curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
                }
                if ($data) {
                    curl_setopt($ch, CURLOPT_POST, true);
                    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
                }
                $response = curl_exec($ch);
                $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
                if ($binary && $response) {
                    $response = "data:{$mime};base64," . base64_encode($response);
                }
                $result = array("httpCode" => $httpcode, "body" => $response);
                curl_close($ch);
            } else {
                $error = "Failed to initialize cURL";
            }
        }
        return array($error, $result);
    }
}
API::AddHandler('application', array('CoreAPIHandler', 'application'));
API::AddHandler('fs', array('CoreAPIHandler', 'fs'));
API::AddHandler('curl', array('CoreAPIHandler', 'curl'));
コード例 #2
0
ファイル: php.php プロジェクト: genecyber/OS.js-v2
 * @licence Simplified BSD License
 */
/**
 * This is your handler class
 *
 * Out-of-the-box support for permissions! You just have to make sure your
 * login method returns the right groups.
 *
 * @link http://os.js.org/doc/tutorials/create-handler.html
 */
class EXAMPLEAPIHandler extends APIHandler
{
    public static function login(array $arguments)
    {
        $user = APIUser::login(array("id" => 0, "username" => "test", "name" => "EXAMPLE handler user", "groups" => array("admin")));
        return array(false, $user->getData());
    }
    public static function logout(array $arguments)
    {
        APIUser::logout();
        return array(false, true);
    }
    public static function settings(array $arguments)
    {
        return array(false, true);
    }
}
API::AddHandler('login', array('EXAMPLEAPIHandler', 'login'));
API::AddHandler('logout', array('EXAMPLEAPIHandler', 'logout'));
API::AddHandler('settings', array('EXAMPLEAPIHandler', 'settings'));
API::SetHandler('EXAMPLEAPIHandler');
コード例 #3
0
ファイル: handler.php プロジェクト: MicroBlocks/OS.js
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * @author  Anders Evenrud <*****@*****.**>
 * @licence Simplified BSD License
 */
/**
 * DemoAPIHandler for demoing
 */
class DemoAPIHandler extends APIHandler
{
    public static function login(array $arguments)
    {
        $user = APIUser::login(array("id" => 0, "username" => "demo", "name" => "Demo User", "groups" => array("admin")));
        return array(false, $user->getData());
    }
    public static function logout(array $arguments)
    {
        APIUser::logout();
        return array(false, true);
    }
    /**
     * Demo handler allows EVERYTHING
     */
    public static function checkPrivilege($requires = null)
    {
        APIHandler::checkPrivilege(true);
    }
}
API::AddHandler('login', array('DemoAPIHandler', 'login'));
API::AddHandler('logout', array('DemoAPIHandler', 'logout'));
API::SetHandler('DemoAPIHandler');
コード例 #4
0
ファイル: handler.php プロジェクト: AlexanderBrevig/OS.js-v2
        $db = self::_initDB();
        APIUser::logout();
        return array(false, true);
    }
    public static function settings(array $arguments)
    {
        $db = self::_initDB();
        $result = false;
        if (!isset($_SESSION['user'])) {
            throw new Exception("Cannot set settings without user session");
        }
        $q = "UPDATE `users` SET `settings` = ? WHERE `id` = ?;";
        $a = array(json_encode($arguments['settings']), $_SESSION['user']['id']);
        if ($stmt = $db->prepare($q)) {
            $result = $stmt->execute($a);
        }
        return array(false, $result);
    }
    /**
     * This enables full privileges for all users. Simply remove to make use of the groups
     * @see APIUser
     */
    public static function checkPrivilege($requires = null)
    {
        APIHandler::checkPrivilege(true);
    }
}
API::AddHandler('login', array('ExampleAPIHandler', 'login'));
API::AddHandler('logout', array('ExampleAPIHandler', 'logout'));
API::AddHandler('settings', array('ExampleAPIHandler', 'settings'));
API::SetHandler('ExampleAPIHandler');
コード例 #5
0
ファイル: handler.php プロジェクト: genecyber/OS.js-v2
        $db = self::_initDB();
        APIUser::logout();
        return array(false, true);
    }
    public static function settings(array $arguments)
    {
        $db = self::_initDB();
        $result = false;
        if (!isset($_SESSION['user'])) {
            throw new Exception("Cannot set settings without user session");
        }
        $q = "UPDATE `users` SET `settings` = ? WHERE `id` = ?;";
        $a = array(json_encode($arguments['settings']), $_SESSION['user']['id']);
        if ($stmt = $db->prepare($q)) {
            $result = $stmt->execute($a);
        }
        return array(false, $result);
    }
    /**
     * This enables full privileges for all users. Simply remove to make use of the groups
     * @see APIUser
     */
    public static function checkPrivilege($requires = null)
    {
        APIHandler::checkPrivilege(true);
    }
}
API::AddHandler('login', array('MysqlAPIHandler', 'login'));
API::AddHandler('logout', array('MysqlAPIHandler', 'logout'));
API::AddHandler('settings', array('MysqlAPIHandler', 'settings'));
API::SetHandler('MysqlAPIHandler');
コード例 #6
0
ファイル: api.php プロジェクト: AlexanderBrevig/OS.js-v2
<?php

class BroadwayAPIHandler
{
    public static function broadway(array $arguments)
    {
        return array(false, false);
    }
}
API::AddHandler('broadway', array('BroadwayAPIHandler', 'broadway'));