/** * @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); }
private function getHelp() { if (is_file(BOT_TOPDIR . self::BOT_HELP_FILE)) { return unserialize(file_get_contents(BOT_TOPDIR . self::BOT_HELP_FILE)); } $st = $this->PDO->prepare('SELECT DISTINCT dir, init FROM functions ORDER BY dir ASC'); $st->execute(); $data = $st->fetchAll(); $help = new BotMsg(); foreach ($data as $element) { $dir = $element['dir']; if (!is_file(BOT_TOPDIR . $dir . '/init.php')) { continue; } $class = (include_once BOT_TOPDIR . $dir . '/init.php'); if ($class === TRUE) { $class = $element['init']; } if (!$class || !class_exists($class, FALSE)) { continue; } $init = new $class(); if (!$init instanceof BotModuleInit) { continue; } $row = $init->help(); if (!$row instanceof BotMsg) { continue; } $help->append($row); } $help->append('Objaśnienie:<br />' . "\n" . ' <i>argument</i> jest wymagany<br />' . "\n" . ' <i>[argument]</i> jest opcjonalny'); file_put_contents(BOT_TOPDIR . self::BOT_HELP_FILE, serialize($help)); return $help; }
/** * @param BotMsg $msg Wiadomość do przekonwertowania */ function __construct(BotMsg $msg) { $parser = $msg->getParser(); unset($msg); $this->parser = new DOMDocument('1.0', 'utf-8'); $this->parser->loadHTML('<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body></body></html>'); $this->rewrite($parser->getElementsByTagName('body')->item(0), $this->parser->getElementsByTagName('body')->item(0)); unset($parser); $this->parse($this->parser->getElementsByTagName('body')->item(0)); $this->html = strtr((string) substr($this->parser->saveXML($this->parser->getElementsByTagName('body')->item(0)), 6, -7), array('/>' => '>')); }
function testSleep() { $msg = new BotMsg('<h1>Test</h1><p><u><i>This.</i></u></p><p><b>That!</b></p>'); $raw = $msg->getRaw(); $text = $msg->getText(); $html = $msg->getHTML(); $serialized = serialize($msg); $msg = unserialize($serialized); $this->assertEquals($raw, $msg->getRaw()); $this->assertEquals($text, $msg->getText()); $this->assertEquals($html, $msg->getHTML()); }
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; }
/** * @param BotMsg $msg Wiadomość do przekonwertowania */ function __construct(BotMsg $msg) { $this->html = $msg->getHTML(); }
<?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; }