From 6e7958d91fcb949ac27e3fc6d1b67833e013f725 Mon Sep 17 00:00:00 2001
From: Jacek Kowalski <Jacek@jacekk.info>
Date: Sat, 29 Jun 2013 16:21:31 +0000
Subject: [PATCH] Poprawka pobierania wyników Multi Multi z 21:40
---
class/BotAPIGG.php | 77 +++++++++++++++++++++++++++++++++-----
1 files changed, 66 insertions(+), 11 deletions(-)
diff --git a/class/BotAPIGG.php b/class/BotAPIGG.php
index 2a96367..90981dd 100644
--- a/class/BotAPIGG.php
+++ b/class/BotAPIGG.php
@@ -181,7 +181,7 @@
$auth = $this->APIs['Gadu-Gadu'];
$token = $this->getToken();
- $tok = $this->httpQuery('https://'.$token['host'].'/botmaster/getImage/'.$auth['numer'], array(
+ $tok = $this->httpQuery('https://botapi.gadu-gadu.pl/botmaster/getImage/'.$auth['numer'], array(
CURLOPT_POST => TRUE,
CURLOPT_POSTFIELDS => http_build_query(array('hash' => $hash), '', '&'),
), TRUE, FALSE);
@@ -193,7 +193,7 @@
$auth = $this->APIs['Gadu-Gadu'];
$token = $this->getToken();
- $tok = $this->httpQuery('https://'.$token['host'].'/botmaster/existsImage/'.$auth['numer'], array(
+ $tok = $this->httpQuery('https://botapi.gadu-gadu.pl/botmaster/existsImage/'.$auth['numer'], array(
CURLOPT_POST => TRUE,
CURLOPT_POSTFIELDS => http_build_query(array('hash' => $hash), '', '&'),
));
@@ -206,18 +206,16 @@
}
function putImage($path) {
- $fp = fopen($path, 'r');
- if(!$fp) {
- return FALSE;
- }
-
$auth = $this->APIs['Gadu-Gadu'];
$token = $this->getToken();
- $tok = $this->httpQuery('https://'.$token['host'].'/botmaster/putImage/'.$auth['numer'], array(
- CURLOPT_HTTPHEADER => array('Content-Type: image/x-any'),
+ $tok = $this->httpQuery('https://botapi.gadu-gadu.pl/botmaster/putImage/'.$auth['numer'], array(
+ CURLOPT_HTTPHEADER => array(
+ 'Content-Type: image/x-any',
+ 'Expect: ',
+ ),
CURLOPT_POST => TRUE,
- CURLOPT_INFILE => $fp,
+ CURLOPT_POSTFIELDS => file_get_contents($path),
));
if( (string)$tok->status != '0') {
@@ -235,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;
}
@@ -276,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(
@@ -294,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