diff --git a/twitter_pull.class.inc b/twitter_pull.class.inc index 5ea3ff2..da288ab 100644 --- a/twitter_pull.class.inc +++ b/twitter_pull.class.inc @@ -11,6 +11,8 @@ class twitter_puller { var $twitkey; var $num_items; var $tweets; + var $langcode; + var $geoloc; /** * @param $twitkey @@ -18,11 +20,12 @@ class twitter_puller { * @param $num_items * maximum number of tweets to pull from Twitter. */ - function __construct($twitkey, $num_items) { + function __construct($twitkey, $num_items, $langcode, $geoloc) { $this->twitkey = $twitkey; $this->num_items = $num_items; - + $this->langcode = $langcode; + $this->geoloc = $geoloc; $this->check_arguments(); } @@ -37,7 +40,10 @@ class twitter_puller { if ($num <= 0 || $num > 200) { throw new Exception(t('Number of Twitter items to pull must be a positive integer less than or equal to 200.')); } - + + //@TODO: check $langcode argument + + //@TODO: check $geoloc argument } function get_items() { @@ -45,6 +51,8 @@ class twitter_puller { $prefix = drupal_substr($this->twitkey, 0, 1); $slash = strpos($this->twitkey, '/', 1); $num = intval($this->num_items); + $lang = $this->langcode; + $geoloc = $this->geoloc; // lists have the format @username/listname if ($prefix == '@' && $slash !== FALSE) { @@ -62,7 +70,9 @@ class twitter_puller { if ($num > 100) { $num = 100; } - $url = 'http://search.twitter.com/search.json?q='. urlencode($this->twitkey) .'&rpp='. $num; + //@TODO: check for a better way of handling $geocode (e.g. empty arrays) + $geocode = isset($geoloc) ? implode(',', $geoloc): NULL; //@TODO: remove this -> ['latitude'] . ',' . $geoloc['longitude'] . ',' . $geoloc['radius']; + $url = 'http://search.twitter.com/search.json?q='. urlencode($this->twitkey) .'&rpp='. $num . '&lang=' . $lang . (isset($geocode) ? '&geocode=' . $geocode: ''); } $ret = drupal_http_request($url); diff --git a/twitter_pull.module b/twitter_pull.module index 7683261..d52825a 100644 --- a/twitter_pull.module +++ b/twitter_pull.module @@ -58,13 +58,15 @@ function twitter_pull_init() { * @param $themekey * Theme key name to use for theming the output of Twitter API. */ -function twitter_pull_render($twitkey, $title = NULL, $num_items = NULL, $themekey = NULL) { +function twitter_pull_render($twitkey, $title = NULL, $num_items = NULL, $themekey = NULL, $langcode = 'EN', $geoloc = NULL) { //-- Set defaults if empty arguments were passed $title = (empty($title) && $title != FALSE ) ? t('Related Tweets') : $title; $themekey = empty($themekey) ? 'twitter_pull_listing' : $themekey; $num_items = empty($num_items) ? twitter_pull_num_items() : $num_items; + //@TODO: set defaults for $langcode? + //@TODO: set defaults for $geoloc? - $tweets = twitter_pull_retrieve($twitkey, $num_items); + $tweets = twitter_pull_retrieve($twitkey, $num_items, $langcode, $geoloc); $ret = theme($themekey, $tweets, $twitkey, $title); @@ -86,7 +88,7 @@ function twitter_pull_render($twitkey, $title = NULL, $num_items = NULL, $themek * @param $num_items * Number of tweets to retrieve from Twitter. Can't be more than 200. */ -function twitter_pull_retrieve($twitkey, $num_items = NULL) { +function twitter_pull_retrieve($twitkey, $num_items = NULL, $langcode = 'EN', $geoloc = NULL) { // If $num_items is not set, use the default value. // This value is checked more rigorously in twitter_puller->check_arguments(). $num_items = (intval($num_items) > 0) ? intval($num_items) : twitter_pull_num_items(); @@ -102,7 +104,7 @@ function twitter_pull_retrieve($twitkey, $num_items = NULL) { } else { try { - $puller = new twitter_puller($twitkey, $num_items); + $puller = new twitter_puller($twitkey, $num_items, $langcode, $geoloc); $puller->get_items(); $tweets = $puller->tweets; }