From 1a5b215058b94af0a90df2c6c2f87960429e6aaf Mon Sep 17 00:00:00 2001
From: Jacek Kowalski <Jacek@jacekk.info>
Date: Mon, 27 Aug 2012 14:53:50 +0000
Subject: [PATCH] 1. Uzupełnienie instrukcji aktualizacji w zawiązku ze zmianami w bocie, 2. Poprawienie błędnego wywołania metody httpQuery() w pliku ./class/BotAPIGG.php, 3. Dodanie metody getPublicData() do klasy BotAPIGG, 4. Poprawienie błędnego warunku w pliku ./test.php, 5. Dodanie wywołania libxml_use_internal_errors() do ./class/std.php
---
class/BotAPIGG.php | 59 +++++++++++++++++++++++++++++
UPGRADE | 9 ++++
class/std.php | 1
test.php | 6 +-
4 files changed, 71 insertions(+), 4 deletions(-)
diff --git a/UPGRADE b/UPGRADE
index d7b7ff4..7dabaeb 100644
--- a/UPGRADE
+++ b/UPGRADE
@@ -1,4 +1,13 @@
===========================
+ AKTUALIZACJA Z WERSJI 2.3
+===========================
+
+* usuń wszystkie pliki i katalogi (za wyjątkiem własnych modułów)
+ z katalogu ./modules
+* nadpisz wszystkie pliki w katalogach ./class i ./modules,
+ za wyjątkiem ./class/config.php
+
+===========================
AKTUALIZACJA Z WERSJI 2.2
===========================
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
diff --git a/class/std.php b/class/std.php
index 26ebbd0..2f98c9f 100644
--- a/class/std.php
+++ b/class/std.php
@@ -34,6 +34,7 @@
setlocale(LC_CTYPE, 'pl_PL.utf8', 'pl_PL', 'polish', 'plk');
mb_internal_encoding('UTF-8');
+libxml_use_internal_errors();
spl_autoload_register('botAutoload');
set_error_handler('errorToException', E_ALL & ~E_NOTICE);
?>
\ No newline at end of file
diff --git a/test.php b/test.php
index 3f846ea..3af958d 100644
--- a/test.php
+++ b/test.php
@@ -51,10 +51,10 @@
testdir('./data/rss');
testdir('./data/tv');
testdir('./data/tv/cache');
-test('./db', !is_dir('./db') || is_writable('./db'));
-if(is_dir('./database')) {
- testdir('./database');
+if(is_dir($db)) {
+ testdir('./db');
}
+testdir('./database');
echo '</table>';
?>
--
Gitblit v1.9.1