Esempio n. 1
0
<?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;
    }
}
Esempio n. 2
0
<?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));
    }
}
Esempio n. 3
0
 /**
  * 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());
         }
     }
 }