/** * @param BotMsg $msg Wiadomość do przekonwertowania */ function __construct(BotMsg $msg) { $msg->a('<reset />'); $parser = $msg->getParser(); $this->html = $parser->saveXML($parser->getElementsByTagName('body')->item(0)); $this->html = (string) substr($this->html, 6, -7); }
function testAppend() { $text = ''; $substring = 'abc'; $msg = new BotMsg($substring); $text .= $substring; $substring = 'cba'; $msg->a($substring); $text .= $substring; $substring = 'cba'; $msg->append($substring); $text .= $substring; $this->assertEquals($text, $msg->getRaw()); }
function miasto($msg, $params) { $msg->session->setClass('pogoda'); if (strlen($params) > 0) { $arg = trim($params); } else { $arg = trim($msg->args); } $out = new BotMsg(); if (empty($arg)) { if (isset($msg->session->miasto)) { return new BotMsg('Aktualnie ustawione miejsce to: ' . htmlspecialchars($this->session->miasto) . ', ' . htmlspecialchars($this->session->countryName)); } try { $api = new BotAPIGG(); $dane = $api->getPublicData($msg->user); if (!isset($arg['city']) || empty($arg['city'])) { throw new Exception('Brak miasta w danych w katalogu publicznym.'); } $arg = trim($arg['city']); } catch (Exception $e) { return new BotMsg('Nie podano wymaganego argumentu <i>miasto</i>.'); } $out->a('<p>Na podstawie danych z katalogu publicznego wybieram miasto: ' . htmlspecialchars($arg) . '</p>' . "\n\n"); } else { } $api = new api_geonames(); $dane = $api->search($arg); if ($dane === FALSE) { return new BotMsg('Wystąpił błąd przy wyszukiwaniu miasta. Spróbuj ponownie później.'); } elseif ($dane === NULL) { return new BotMsg('Nie udało się zlokalizować podanego miejsca. Spróbuj wpisać inną nazwę.'); } $msg->session->miasto = $dane['name']; $msg->session->kraj = $dane['countryName']; $msg->session->cc = $dane['countryCode']; $msg->session->geo = array('lat' => $dane['lat'], 'lon' => $dane['lng']); $out->a('<p>Ustawiono miejsce: ' . htmlspecialchars($this->session->miasto) . ', ' . htmlspecialchars($this->session->countryName) . '</p>'); return $out; }
<?php require_once './class/std.php'; try { $msg = new BotMsg('<p>To jest tekst!</p>'); $msg->a('<p>A to tekst <b>pogrubiony</b> oraz <i>pochylony</i>.</p>'); $api = new BotAPIGG(); var_dump($api->sendMessage(array('Gadu-Gadu://NUMER_GG@gadu-gadu.pl'), $msg)); } catch (Exception $e) { echo $e; }