/ Published in: PHP
Expand |
Embed | Plain Text
<?php require_once('HTTP/Client.php'); class HttpBot { $c = __CLASS__; self::$singleton = new $c; } return self::$singleton; } private $http; private function __construct() { $shell = Shell::singleton(); $this->http = new HTTP_Client; $this->signature_purge(2); // debug codes, enabled for debug $this->signature_purge(0); } public function __clone() { } public function signature_exists($html) { $shell = Shell::singleton(); } public function signature_save($html) { $shell = Shell::singleton(); } public function signature_purge($days_old) { $shell = Shell::singleton(); $path = $shell->temp($file); } } } } } } private function assert_response($code, $text = false) { if ($code != 200) { return false; } return true; } private function assert_text($body, $chk, $text = false) { return false; } return true; } public function normalize_string($text) { } } public function response($encoding = false) { $shell = Shell::singleton(); $resp = $this->http->currentResponse(); $raw = $resp['body']; if ($encoding !== false) { $raw = $shell->concmd_utf8($raw, $encoding); } $dom = new DOMDocument; $dom->preserveWhiteSpace = false; @$dom->loadHTML($body); $xpath = new DOMXPath($dom); } public function geta($url, $error = false) { return $this->assert_response($this->http->get($url), $error); } public function posta($url, $data, $error = false) { return $this->assert_response($this->http->post($url, $data), $error); } public function contenta($chk, $text = false) { $resp = $this->http->currentResponse(); return $this->assert_text($resp['body'], $chk, $text); } } ?>
Comments
Subscribe to comments
You need to login to post a comment.

What does this bot do?
i have never thought there is someone comments on my codes, as i am just putting some of my frequently used snippets online ;)
in short, it does nothing. This class basically is a wrapper of the HTTPClient PEAR package. it just groups several functions of the HTTPClient which i used very frequently together. and it's needed to be used in conjunction of my other class "Shell.class.php" (http://snipplr.com/view/6648/a-shell-access-wrapper-for-windows-in-php/)
let's say, I want to write a script that log me into facebook and write something on someone's else wall.... I would simply do:
$http = HttpBot::singleton(); $http->geta('http://www.facebook.com', 'Unable to connect to Facebook'); if ($http->contenta('logout') === false) { // Login required, login now!
}
i used this script to create several scheduled tasks in windows to collect / poll different contents from internet, summarize and email to me on a daily basis. it may not be a very elegant solution, but it just gives me some shorthand, while dealing with the HTTP_Client class.