Custome filters

Tuitter_Filter is used for filtering Tweets. It’s convenience to prepare custome filters.

Custome filters have to implement Tuitter_Filter_Interface.

Implements just one method

The filters should implement just one method, “check”.

Tuitter_Tweet object is given to this method. Return FALSE when you want to take out the Tweet.

HashTag filtering example

See the example of Tuitter_Filter_HashTag.

The class constructor generate regular expression, then Tweet text is matched in check method.

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);
  }
}