Index: twitter_pull.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/twitter_pull/twitter_pull.module,v
retrieving revision 1.1
diff -u -r1.1 twitter_pull.module
--- twitter_pull.module	7 Jan 2010 04:25:46 -0000	1.1
+++ twitter_pull.module	2 Mar 2010 03:49:23 -0000
@@ -39,7 +39,7 @@
 * function with $themekey key passing tweets array along. 
 
 * <p>The rest of this module needs to make sure that corresponding theming
-* functions exist, exist tweets array and perform desired theming.
+* functions exist, exist tweets array and perform desired theming.</p>
 *
 * @param $twitkey
 *     Twitter key, which can be a username (prepended with @) or hashtag (prepended with #)
@@ -73,7 +73,8 @@
       $puller->get_items();
       $tweets = $puller->tweets;    
       
-    } catch (Exception $e) {
+    }
+    catch (Exception $e) {
       watchdog('Twitter Pull', $e->getMessage(), array(), WATCHDOG_WARNING);
       return twitter_pull_empty_message();
     }
@@ -125,6 +126,15 @@
   );
 }
 
+/**
+ * Implementation of hook_help().
+ */
+function twitter_pull_help($section) {
+  switch ($section) {
+    case 'admin/modules#description':
+      return t('Twitter Pull is a small module, the only purpose of which is to allow super-easy embedding of public twitter data like: a user timeline or twitter search results by hashtag or a search term.');
+  }
+}
 
 
 
@@ -147,4 +157,90 @@
 function twitter_pull_test() {
   return twitter_pull_render('@inadarei');  
 }
-*/
\ No newline at end of file
+*/
+/**
+ * Implementation of hook_filter().
+ */
+function twitter_pull_filter($op, $delta = 0, $format = -1, $text = '', $cache_id = 0) {
+  switch ($op) {
+    case 'list':
+      return array(
+        0 => t('Embed Twitter feed'),
+      );
+
+    case 'no cache':
+      switch ($delta) {
+        case 0:
+          return TRUE;
+      }
+
+    case 'description':
+      switch ($delta) {
+        case 0:
+          // $twitkey, $title = NULL, $num_items = NULL, $themekey = NULL.
+          return t('Embed Twitter feed using [twitter-pull:URL] or [twitter-pull:URL,TITLE,NUM,THEMEKEY] type tags.  Disables filter caching so not recommended for all input formats.');
+      }
+
+    case "process":
+      switch ($delta) {
+        case 0:
+          $text = preg_replace_callback('/\[twitter\-pull:?([^\]]*)\]/', '_twitter_pull_feed_filter_replacer', $text);
+          return $text;
+      }
+      return $text;
+
+    default:
+      return $text;
+  }
+}
+
+/**
+ * Implementation of hook_filter_tips().
+ */
+function twitter_pull_filter_tips($delta, $format, $long = FALSE) {
+  switch ($delta) {
+    case 0:
+      return t('[twitter-pull:URL] or [twitter-pull:URL,TITLE,NUM,THEMEKEY] - inserts a Twitter feed content based on the URL, (e.g. @username or #hashtag) and optional title (TITLE), feed number (NUM), and theme key (THEMEKEY) properties.');
+  }
+}
+
+/**
+ * Helper function for twitter_pull input filter.
+ */
+function _twitter_pull_feed_filter_replacer($matches) {
+  if (drupal_strlen($matches[1])) {
+    list ($twitkey, $title, $num_items, $themekey) = twitter_pull_explode_tags($matches[1]);
+
+    // Test the ThemeKey, ignore if not valid.
+    if (!empty($themekey)) {
+      init_theme();
+      $registry = theme_get_registry();
+      if (!isset($themekey)) {
+        $themekey = NULL;
+      }
+    }
+    else {
+      $themekey = NULL;
+    }
+    return twitter_pull_render($twitkey, $title, $num_items, $themekey);
+  }
+  else {
+    return '';
+  }
+}
+
+/**
+ * Custom clone of drupal_explode_tags() that does not filter duplicates and
+ * does not remove empty values.
+ */
+function twitter_pull_explode_tags($tags) {
+  $regexp = '%(?:^|,\ *)("(?>[^"]*)(?>""[^"]* )*"|(?: [^",]*))%x';
+  preg_match_all($regexp, $tags, $matches);
+  $typed_tags = $matches[1];
+  $tags = array();
+  foreach ($typed_tags as $tag) {
+    $tag = trim(str_replace('""', '"', preg_replace('/^"(.*)"$/', '\1', $tag)));
+    $tags[] = $tag;
+  }
+  return $tags;
+}
