<?php if ($_SERVER['argc'] < 3) { echo "Specify your Twitter account name and the password\n"; exit; } $user = $_SERVER['argv'][1]; $passwd = $_SERVER['argv'][2]; require_once dirname(__FILE__) . '/Tuitter.php'; try { $tuitter = new Tuitter($user, $passwd); $user = $tuitter->getUser('nao58'); if (!$user->isFollowing()) { $user->follow(); $tuitter->sendMessage('This is my first tweet by Tuitter, @nao58 !'); } else { $tl = $tuitter->getHomeTL(); foreach ($tl as $tweet) { echo $tweet->user->screen_name . "\n"; echo $tweet->text . "\n\n"; } } } catch (Exception $e) { echo "Error: " . $e->getMessage() . "\n"; }
<?php Tuitter::load('Cache/Interface.php'); class Tuitter_Cache_File implements Tuitter_Cache_Interface { private $_dir; public function __construct($dir) { $this->_dir = realpath($dir); if (!$this->_dir) { throw new Exception("The cache directory '{$dir}' does not exists."); } } public function get($key) { $file = $this->_dir . DIRECTORY_SEPARATOR . $key; if (file_exists($file)) { return gzinflate(file_get_contents($file)); } } public function put($key, $data) { $file = $this->_dir . DIRECTORY_SEPARATOR . $key; return file_put_contents($file, gzdeflate($data)); } }
<?php /** * Tuitter - Twitter Client Class for PHP 5 * * PHP versions 5 * * @author Naohiko MORI <*****@*****.**> * @copyright 2009 Naohiko MORI <*****@*****.**> * @license Dual licensed under the MIT and GPL licenses. */ Tuitter::init(); /** * Tuitter Main Class */ class Tuitter { /** * protected members */ protected $_user; protected $_pass; protected $_cache; protected $_client_name; protected $_client_version; protected $_client_url; protected $_retry = 3; protected $_retryInterval = 1; /** * Load modules Tuitter uses *
<?php Tuitter::load('Filter/Interface.php'); class Tuitter_Filter_HashTag implements Tuitter_Filter_Interface { private $_exp; public function __construct() { $tags = func_get_args(); if (!$tags) { trigger_error('Missing arguments.'); } $esc = array(); foreach ($tags as $tag) { $esc[] = preg_quote($tag); } $this->_exp = '/#(' . implode('|', $esc) . ')\\W/i'; } public function check(Tuitter_Tweet $tweet) { return preg_match($this->_exp, $tweet->text . ' ') ? true : false; } }
/** * Constructor * * @access public * @param string $config config file name */ public function __construct($config) { if (!class_exists('Tuitter')) { @(require_once 'Tuitter.php'); } self::load('Events.php'); $config_file = realpath($config); if (file_exists($config_file)) { if (!defined('TUIBOTTER_CONF_DIR')) { define('TUIBOTTER_CONF_DIR', dirname($config_file)); } $this->_config = parse_ini_file($config_file, true); } else { throw new Exception('Config file "' . $config_file . '" does not exists.'); } $account = $this->_config['Account']; $authType = isset($account['authType']) ? $account['authType'] : 'Basic'; if ($authType == 'Basic') { $user = $account['user']; $pass = $account['pass']; $this->_tuitter = new Tuitter($user, $pass); } else { if ($authType == 'OAuth') { if (!class_exists('TuitterOAuth')) { require_once 'TuitterOAuth'; } $this->_tuitter = new TuitterOAuth($account['consumerKey'], $account['consumerSec'], $account['accessKey'], $account['accessSec']); } } if ($env = $this->_config['Environment']) { if ($env['cache']) { if ($cacheDir = $env['cacheDir']) { Tuitter::load('Cache/File.php'); $this->_tuitter->setCache(new Tuitter_Cache_File($cacheDir)); } } if ($env['cacheHttp']) { if ($cacheDir = $env['cacheHttpDir']) { Tuitter::load('Cache/File.php'); $this->_tuitter->setHttpCache(new Tuitter_Cache_File($cacheDir)); } } } if (isset($this->_config['Behaviours']) and $bhs = $this->_config['Behaviours']) { foreach ($bhs as $class => $class_file) { require_once $class_file; self::applyBehaviour(new $class()); } } }