=====Twitter Feed===== This is my first attempt at an action... hopefully things will work out ok. **Note:** This is mostly re-tooled from the default rss action. I added in some additional features as specified below =====Features===== ---- **Current Features** - Takes twitter rss feed and... - Strips the "Username: " portion from the feed - Only posts the description (the Title and description are identical, one is just a link back to the individual twitter post) - Optionally displays @ replies (providing one-sided conversations) - Optionally limits results to specified number (helpful for fitting the feed into a portion of your layout) - Automatically converts twittered links to clickable links. - Automatically converts @username to a clickable link to www.twitter.com/username - Automatically converts #hashes to a clickable link to search.twitter.com =====Source Code===== ---- **Current Version:** 0.8 %%(php;1) htmlspecialchars_ent($vars['maxitems'])); if (!$twitter_max_items) { $max_items = 5; // this is the default number of items to display } else { $max_items = $twitter_max_items; // set max items to passed variable } // Are we displaying replies $twitter_replies = (bool)trim($this->htmlspecialchars_ent($vars['replies'])); if (!$twitter_replies) { $replies = 0; // defaults to not showing replies } else { $replies = $twitter_replies; // set replies to passed variable } // What cache time are we using $twitter_cache_time = (int)trim($this->htmlspecialchars_ent($vars['cachetime'])); if (!$twitter_cache_time) { $twitter_cache_time = 30; // set this for default cache time } elseif ($twitter_cache_time < $lowest_cache_time_allowed) { $twitter_cache_time = $lowest_cache_time_allowed; } $twitter_cache_file = ""; // initial value, no need to ever change // End dealing with action variables // Action configuration $twitter_path = $this->htmlspecialchars_ent($vars['url']); if ((!$twitter_path) && $wikka_vars) $twitter_path = $wikka_vars; $twitter_path = $this->cleanUrl(trim($twitter_path)); // override - Added by pezhore: not sure what this does... if (preg_match("/^(http|https):\/\/([^\\s\"<>]+)$/i", $twitter_path)) { $onyx_classpath = $this->GetConfigValue('onyx_path').DIRECTORY_SEPARATOR.'onyx-rss.php'; /** * 3rdParty plugin; implements feed aggregation. */ #include_once('3rdparty'.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.'onyx-rss'.DIRECTORY_SEPARATOR.'onyx-rss.php'); include_once $onyx_classpath; if (!class_exists('Wikka_Onyx')) { /** * Extension to plugin; implements error handling. * * @package Actions */ class Wikka_Onyx extends ONYX_RSS { //private function raiseError($line, $err) function raiseError($line, $err) { if ($this->debugMode) { $errortext = sprintf($this->error, $line, $err); echo ''."\n"; } } } } } if (preg_match("/^(http|https):\/\/([^\\s\"<>]+)$/i", $twitter_path)) { if ($caching) { // Create unique cache file name based on URL $twitter_cache_file = md5($twitter_path).".xml"; } //Load the RSS Feed: workaround to hide error messages within HTML comments: #$twitter =& new Wikka_Onyx(); $twitter = instantiate('Wikka_Onyx'); $twitter->setCachePath($twitter_cache_path); $twitter->parse($twitter_path, $twitter_cache_file, $twitter_cache_time); $meta = $twitter->getData(ONYX_META); $nick = ": "; //List the feed's items $cached_output = "\n"; echo $this->ReturnSafeHTML($cached_output); } else // If this was called improperly, display usage { echo 'Error: Invalid Twitter action syntax.
Proper usage: {{twitter http://twitter.com/statuses/user_timeline/[uid]}} or
{{twitter url="http://twitter.com/statuses/user_timeline/[uid]" cachetime="30"}} or
{{twitter url="http://twitter.com/statuses/user_timeline/[uid]" cachetime="30" replies=true}} or
{{twitter url="http://twitter.com/statuses/user_timeline/[uid]" cachetime="30" replies="1" maxitems="5"}}}}
'; # i18n } ?> %% =====Installation===== ---- - Save the code above as twitter.php in your actions folder (for trunk, you have to first create an actions/twitter folder, then save as actions/twitter/twitter.php) - Use as ""{{twitter}}"" according to the usage stated above =====Known Bugs===== ---- - The coding for dropping "Username: " isn't quite up to par. Change line #133 to $str_desc = substr($str_desc, #); where # is the number of characters from of your twitter name + 2 (for ':' and ' '). Working on the fix. - Fixed in Version 0.5 and above Thoughts? Questions? Let me know. I'm on [[http://wikkawiki.org/TheLounge | IRC]] as Pezhore. ---- CategoryUserContributions