From 6411a4f462fcd039ce4d233aaf28a5186b20eeea Mon Sep 17 00:00:00 2001
From: Jacek Kowalski <Jacek@jacekk.info>
Date: Fri, 12 Feb 2016 23:26:39 +0000
Subject: [PATCH] [mod_pogoda] Podbicie wersji API yr.no
---
class/BotAPIGG.php | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 58 insertions(+), 1 deletions(-)
diff --git a/class/BotAPIGG.php b/class/BotAPIGG.php
index ff52117..90981dd 100644
--- a/class/BotAPIGG.php
+++ b/class/BotAPIGG.php
@@ -233,9 +233,21 @@
* array( 'SendToOffline' => (bool)TRUE/FALSE )
*/
function sendMessage($toURL, BotMsg $msg, $params = array()) {
+ if(is_string($toURL)) {
+ $toURL = array($toURL);
+ }
+
+ if(!is_array($toURL)) {
+ throw new Exception('Lista adresatów przekazywanych do funkcji BotAPIGG::sendMessage() winna być tablicą.');
+ }
+
$to = array();
foreach($toURL as $url) {
$url = parse_url($url);
+ if($url === FALSE) {
+ continue;
+ }
+
if($url['scheme'] != 'Gadu-Gadu') {
continue;
}
@@ -274,8 +286,9 @@
),
));
+ // Brak obrazka w cache BotMastera...
if((string)$tok->status == '18') {
- $tok = $this->httpQuery('https://'.$token['host'].'/sendMessage/'.$auth['numer'], FALSE, array(
+ $tok = $this->httpQuery('https://'.$token['host'].'/sendMessage/'.$auth['numer'], array(
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POST => TRUE,
CURLOPT_POSTFIELDS => array(
@@ -292,5 +305,49 @@
return TRUE;
}
+
+ /**
+ * Pobiera dane użytkownika z katalogu publicznego.
+ * @param string|BotUser Numer użytkownika
+ * @return array|false Tablica z danymi.
+ */
+ function getPublicData($number) {
+ if($number instanceof BotUser) {
+ if($number->network != 'gadu-gadu.pl') {
+ return FALSE;
+ }
+
+ $number = $number->uid;
+ }
+
+ if(!ctype_digit($number)) {
+ throw new Exception('Numer użytkownika przekazany do funkcji BotAPIGG::getPublicData() jest niepoprawny.');
+ }
+
+ try {
+ $data = file_get_contents('http://api.gadu-gadu.pl/users/'.$number.'.xml');
+ if(!$data) {
+ throw new Exception('Nie udało się pobrać danych użytkownika z katalogu publicznego.');
+ }
+ }
+ catch(Exception $e) {
+ throw new Exception('Nie udało się pobrać danych użytkownika z katalogu publicznego.');
+ }
+
+ libxml_use_internal_errors();
+ $data = simplexml_load_string($data);
+ libxml_clear_errors();
+
+ if(!$data) {
+ throw new Exception('Dane użytkownika otrzymane z API Gadu-Gadu mają niepoprawny format.');
+ }
+
+ if(!$data) {
+ throw new Exception('Dane użytkownika otrzymane z API Gadu-Gadu mają niepoprawny format.');
+ }
+
+
+ return (array)$data->users->user;
+ }
}
?>
\ No newline at end of file
--
Gitblit v1.9.1