diff options
author | Adam <adam@sigterm.info> | 2015-04-04 09:50:57 -0400 |
---|---|---|
committer | Adam <adam@sigterm.info> | 2015-04-04 09:50:57 -0400 |
commit | 5efaa5b206f37d32bf14e21e05696a27f10e523f (patch) | |
tree | 4ebfadd0a431dec58dfd7ef157c9315ecfa2f93b /docs | |
parent | abc4851287166a8b4365dd3da406cea15d8374bb (diff) | |
parent | 41f4c7dab66765e4e759559b97b4a37317a32090 (diff) |
Merge pull request #117 from aFreshMelon/fix-xmlrpc-php
Fix xmlrpc php
Diffstat (limited to 'docs')
-rw-r--r-- | docs/XMLRPC/xmlrpc.php | 183 |
1 files changed, 111 insertions, 72 deletions
diff --git a/docs/XMLRPC/xmlrpc.php b/docs/XMLRPC/xmlrpc.php index c469ab05a..2b5645ca7 100644 --- a/docs/XMLRPC/xmlrpc.php +++ b/docs/XMLRPC/xmlrpc.php @@ -1,90 +1,129 @@ <?php -/* XMLRPC Functions + +/** + * XMLRPC Functions * - * (C) 2003-2014 Anope Team + * (C) 2003-2015 Anope Team * Contact us at team@anope.org - * */ - class AnopeXMLRPC { - private $Host; + /** + * The XMLRPC host + * + * @var string + */ + private $host; - function __construct($Host) - { - $this->Host = $Host; - } + /** + * Initiate a new AnopeXMLRPC instance + * + * @param $host + */ + public function __construct($host) + { + $this->host = $host; + } - /** Run an XMLRPC command. Name should be a query name and params an array of parameters, eg: - * $this->RunXMLRPC("checkAuthentication", array("adam", "qwerty")); - * If successful returns back an array of useful information. - * - * Note that $params["id"] is reserved for query ID, you may set it to something if you wish. - * If you do, the same ID will be passed back with the reply from Anope. - */ - function RunXMLRPC($name, $params) - { - $xmlquery = xmlrpc_encode_request($name, $params); - $context = stream_context_create(array("http" => array( - "method" => "POST", - "header" => "Content-Type: text/xml", - "content" => $xmlquery))); + /** + * Run an XMLRPC command. Name should be a query name and params an array of parameters, eg: + * $this->raw("checkAuthentication", ["adam", "qwerty"]); + * If successful returns back an array of useful information. + * + * Note that $params["id"] is reserved for query ID, you may set it to something if you wish. + * If you do, the same ID will be passed back with the reply from Anope. + * + * @param $name + * @param $params + * @return array|null + */ + public function run($name, $params) + { + $xmlquery = xmlrpc_encode_request($name, $params); + $context = stream_context_create(["http" => [ + "method" => "POST", + "header" => "Content-Type: text/xml", + "content" => $xmlquery]]); - $inbuf = file_get_contents($this->Host, false, $context); - $response = xmlrpc_decode($inbuf); + $inbuf = file_get_contents($this->host, false, $context); + $response = xmlrpc_decode($inbuf); - if (isset($response[0])) - return $response[0]; - return NULL; - } + if ($response) { + return $response; + } - /** Do Command on Service as User, eg: - * $anope->DoCommand("ChanServ", "Adam", "REGISTER #adam"); - * Returns an array of information regarding the command execution, if - * If 'online' is set to yes, then the reply to the command was sent to the user on IRC. - * If 'online' is set to no, then the reply to the command is in the array member 'return' - */ - function DoCommand($Service, $User, $Command) - { - return $this->RunXMLRPC("command", array($Service, $User, $Command)); - } + return null; + } - /** Check an account/nick name and password to see if they are valid - * Returns the account display name if valid - */ - function CheckAuthentication($Account, $Pass) - { - $ret = $this->RunXMLRPC("checkAuthentication", array($Account, $Pass)); + /** + * Do Command on Service as User, eg: + * $anope->command("ChanServ", "Adam", "REGISTER #adam"); + * Returns an array of information regarding the command execution, if + * If 'online' is set to yes, then the reply to the command was sent to the user on IRC. + * If 'online' is set to no, then the reply to the command is in the array member 'return' + * + * @param $service + * @param $user + * @param $command + * @return array|null + */ + public function command($service, $user, $command) + { + return $this->run("command", [$service, $user, $command]); + } - if ($ret && $ret["result"] == "Success") - return $ret["account"]; - return NULL; - } + /** + * Check an account/nick name and password to see if they are valid + * Returns the account display name if valid + * + * @param $account + * @param $pass + * @return string|null + */ + public function auth($account, $pass) + { + $ret = $this->run("checkAuthentication", [$account, $pass]); - /* Returns an array of misc stats regarding Anope - */ - function DoStats() - { - return $this->RunXMLRPC("stats", NULL); - } + if ($ret && $ret["result"] == "Success") { + return $ret["account"]; + } - /* Look up data for a channel - * Returns an array containing channel information, or an array of size one - * (just containing the name) if the channel does not exist - */ - function DoChannel($Channel) - { - return $this->RunXMLRPC("channel", array($Channel)); - } + return null; + } - /* Like DoChannel(), but different. - */ - function DoUser($User) - { - return $this->RunXMLRPC("user", array($User)); - } -} + /** + * Returns an array of misc stats regarding Anope + * + * @return array|null + */ + public function stats() + { + return $this->run("stats", null); + } + + /** + * Look up data for a channel + * Returns an array containing channel information, or an array of size one + * (just containing the name) if the channel does not exist + * + * @param $channel + * @return array|null + */ + public function channel($channel) + { + return $this->run("channel", [$channel]); + } -$anopexmlrpc = new AnopeXMLRPC("http://127.0.0.1:8080/xmlrpc"); + /** + * Like channel(), but different. + * + * @param $user + * @return array|null + */ + public function user($user) + { + return $this->run("user", [$user]); + } +} -?> +$anope = new AnopeXMLRPC("http://127.0.0.1:8080/xmlrpc"); |