Added support for Twitter feed.

This commit is contained in:
Dario Solera 2010-01-09 13:41:01 +00:00
parent 788bf708e2
commit 0519c46baf
2 changed files with 35 additions and 21 deletions

View file

@ -16,5 +16,5 @@ using System.Reflection;
// //
// You can specify all the values or you can default the Revision and Build Numbers // You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
[assembly: AssemblyVersion("3.0.1.453")] [assembly: AssemblyVersion("3.0.1.454")]
[assembly: AssemblyFileVersion("3.0.1.453")] [assembly: AssemblyFileVersion("3.0.1.454")]

View file

@ -18,10 +18,10 @@ namespace ScrewTurn.Wiki.Plugins.PluginPack {
private IHostV30 _host; private IHostV30 _host;
private string _config; private string _config;
private bool _enableLogging = true; private bool _enableLogging = true;
private static readonly ComponentInformation Info = new ComponentInformation("RSS Feed Display Plugin", "ScrewTurn Software", "3.0.1.453", "http://www.screwturn.eu", "http://www.screwturn.eu/Version/PluginPack/RssFeedDisplay.txt"); private static readonly ComponentInformation Info = new ComponentInformation("RSS Feed Display Plugin", "ScrewTurn Software", "3.0.1.454", "http://www.screwturn.eu", "http://www.screwturn.eu/Version/PluginPack/RssFeedDisplay.txt");
private static readonly Regex RssRegex = new Regex(@"{RSS:http://(.+?)}", private static readonly Regex RssRegex = new Regex(@"{(RSS|Twitter):(.+?)}",
RegexOptions.Compiled | RegexOptions.Singleline | RegexOptions.IgnoreCase | RegexOptions.CultureInvariant); RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
/// <summary> /// <summary>
/// Specifies whether or not to execute Phase 1. /// Specifies whether or not to execute Phase 1.
@ -66,7 +66,7 @@ namespace ScrewTurn.Wiki.Plugins.PluginPack {
try { try {
KeyValuePair<int, string> block = FindAndRemoveFirstOccurrence(buffer); KeyValuePair<int, Match> block = FindAndRemoveFirstOccurrence(buffer);
while(block.Key != -1) { while(block.Key != -1) {
string blockHash = block.Value.ToString(); string blockHash = block.Value.ToString();
@ -78,13 +78,26 @@ namespace ScrewTurn.Wiki.Plugins.PluginPack {
} }
if(result == null) { if(result == null) {
XmlDocument feedXml = GetXml(block.Value.ToString().Substring(5, block.Value.ToString().Length - 6)); bool isTwitter = block.Value.Groups[1].Value.ToLowerInvariant() == "twitter";
XmlDocument feedXml = GetXml(block.Value.Groups[2].Value);
XmlNode node = feedXml.DocumentElement; XmlNode node = feedXml.DocumentElement;
XmlNode itemTitle = node.SelectNodes("/rss/channel/item/title")[0]; XmlNode itemTitle = node.SelectNodes("/rss/channel/item/title")[0];
XmlNode itemLink = node.SelectNodes("/rss/channel/item/link")[0]; XmlNode itemLink = node.SelectNodes("/rss/channel/item/link")[0];
XmlNode itemContent = node.SelectNodes("/rss/channel/item/description")[0]; XmlNode itemContent = node.SelectNodes("/rss/channel/item/description")[0];
string itemContentStr = StripHtml(itemContent.InnerText); string itemContentStr = StripHtml(itemContent.InnerText);
itemContentStr = (itemContentStr.Length > 350 && itemContentStr.Substring(347, 5) != "[...]") ? itemContentStr.Substring(0, itemContentStr.IndexOf(" ", 345)) + " [...]" : itemContentStr; itemContentStr = (itemContentStr.Length > 350 && itemContentStr.Substring(347, 5) != "[...]") ? itemContentStr.Substring(0, itemContentStr.IndexOf(" ", 345) + 1) + " [...]" : itemContentStr;
if(itemContentStr.Length <= 1) itemContentStr = StripHtml(itemContent.InnerText);
if(isTwitter) {
string tweet = itemTitle.InnerText;
tweet = tweet.Substring(tweet.IndexOf(":") + 2);
result = @"<div class=""twitterfeed"">
<span class=""tweet"">
<a href=""" + itemLink.InnerText + @""" title=""Go to this Tweet"">" + tweet + @"</a>
</span>
</div>";
}
else {
result = @"<div class=""rssfeed""> result = @"<div class=""rssfeed"">
<span class=""rsstitle""> <span class=""rsstitle"">
<a href=""" + itemLink.InnerText + @""" title=""" + itemTitle.InnerText + @""">" + itemTitle.InnerText + @"</a> <a href=""" + itemLink.InnerText + @""" title=""" + itemTitle.InnerText + @""">" + itemTitle.InnerText + @"</a>
@ -92,6 +105,8 @@ namespace ScrewTurn.Wiki.Plugins.PluginPack {
<br /> <br />
<span class=""rsscontent"">" + itemContentStr + @"</span> <span class=""rsscontent"">" + itemContentStr + @"</span>
</div>"; </div>";
}
if(System.Web.HttpContext.Current != null) { if(System.Web.HttpContext.Current != null) {
System.Web.HttpContext.Current.Cache.Add(blockHash, result, null, DateTime.Now.AddMinutes(60), System.Web.HttpContext.Current.Cache.Add(blockHash, result, null, DateTime.Now.AddMinutes(60),
System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Normal, null); System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Normal, null);
@ -105,7 +120,6 @@ namespace ScrewTurn.Wiki.Plugins.PluginPack {
} }
catch(Exception ex) { catch(Exception ex) {
LogWarning(string.Format("Exception occurred: {0}", ex.Message)); LogWarning(string.Format("Exception occurred: {0}", ex.Message));
return null;
} }
return buffer.ToString(); return buffer.ToString();
} }
@ -127,7 +141,7 @@ namespace ScrewTurn.Wiki.Plugins.PluginPack {
results.LoadXml(xmlString); results.LoadXml(xmlString);
} }
catch { catch {
LogWarning("Received Unexpected Response from Unfuddle Server."); LogWarning("Received Unexpected Response from server.");
} }
} }
return results; return results;
@ -143,16 +157,16 @@ namespace ScrewTurn.Wiki.Plugins.PluginPack {
/// </summary> /// </summary>
/// <param name="buffer">The buffer.</param> /// <param name="buffer">The buffer.</param>
/// <returns>The index->content data.</returns> /// <returns>The index->content data.</returns>
private static KeyValuePair<int, string> FindAndRemoveFirstOccurrence(StringBuilder buffer) { private static KeyValuePair<int, Match> FindAndRemoveFirstOccurrence(StringBuilder buffer) {
Match match = RssRegex.Match(buffer.ToString()); Match match = RssRegex.Match(buffer.ToString());
if(match.Success) { if(match.Success) {
buffer.Remove(match.Index, match.Length); buffer.Remove(match.Index, match.Length);
return new KeyValuePair<int, string>(match.Index, match.Value); return new KeyValuePair<int, Match>(match.Index, match);
} }
return new KeyValuePair<int, string>(-1, null); return new KeyValuePair<int, Match>(-1, null);
} }
/// <summary> /// <summary>
@ -221,7 +235,7 @@ namespace ScrewTurn.Wiki.Plugins.PluginPack {
/// Gets a brief summary of the configuration string format, in HTML. Returns <c>null</c> if no configuration is needed. /// Gets a brief summary of the configuration string format, in HTML. Returns <c>null</c> if no configuration is needed.
/// </summary> /// </summary>
public string ConfigHelpHtml { public string ConfigHelpHtml {
get { return null; } get { return "Specify <i>nolog</i> for disabling warning log messages."; }
} }
} }