Ejemplo n.º 1
0
        /// <summary>
        /// Retweets Message thru the Twitter API
        /// </summary>
        /// <param name="sender">
        /// The source of the event. 
        /// </param>
        /// <param name="e">
        /// The <see cref="System.EventArgs"/> instance containing the event data. 
        /// </param>
        protected void Retweet_Click(object sender, EventArgs e)
        {
            var twitterName = this.Get<YafBoardSettings>().TwitterUserName.IsSet()
                                  ? "@{0} ".FormatWith(this.Get<YafBoardSettings>().TwitterUserName)
                                  : string.Empty;

            // process message... clean html, strip html, remove bbcode, etc...
            var twitterMsg =
                StringExtensions.RemoveMultipleWhitespace(
                    BBCodeHelper.StripBBCode(
                        HtmlHelper.StripHtml(HtmlHelper.CleanHtmlString((string)this.DataRow["Message"]))));

            var topicUrl = YafBuildLink.GetLinkNotEscaped(ForumPages.posts, true, "m={0}#post{0}", this.DataRow["MessageID"]);

            // Send Retweet Directlly thru the Twitter API if User is Twitter User
            if (Config.TwitterConsumerKey.IsSet() && Config.TwitterConsumerSecret.IsSet() &&
                this.Get<IYafSession>().TwitterToken.IsSet() && this.Get<IYafSession>().TwitterTokenSecret.IsSet() &&
                this.Get<IYafSession>().TwitterTokenSecret.IsSet() && this.PageContext.IsTwitterUser)
            {
                var oAuth = new OAuthTwitter
                {
                    ConsumerKey = Config.TwitterConsumerKey,
                    ConsumerSecret = Config.TwitterConsumerSecret,
                    Token = this.Get<IYafSession>().TwitterToken,
                    TokenSecret = this.Get<IYafSession>().TwitterTokenSecret
                };

                var tweets = new TweetAPI(oAuth);

                tweets.UpdateStatus(
                    TweetAPI.ResponseFormat.json,
                    this.Server.UrlEncode("RT {1}: {0} {2}".FormatWith(twitterMsg.Truncate(100), twitterName, topicUrl)),
                    string.Empty);
            }
            else
            {
                this.Get<HttpResponseBase>().Redirect(
                    "http://twitter.com/share?url={0}&text={1}".FormatWith(
                        this.Server.UrlEncode(this.Get<HttpRequestBase>().Url.ToString()),
                        this.Server.UrlEncode(
                            "RT {1}: {0} {2}".FormatWith(twitterMsg.Truncate(100), twitterName, topicUrl))));
            }
        }
Ejemplo n.º 2
0
		/// <summary>
		/// The options menu_ item click.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">
		/// The Pop Event Arguments.
		/// </param>
		private void ShareMenu_ItemClick([NotNull] object sender, [NotNull] PopEventArgs e)
		{
			var topicUrl = YafBuildLink.GetLinkNotEscaped(ForumPages.posts, true, "t={0}", this.PageContext.PageTopicID);
			switch (e.Item.ToLower())
			{
				case "email":
					this.EmailTopic_Click(sender, e);
					break;
				case "tumblr":
					{
						// process message... clean html, strip html, remove bbcode, etc...
						var tumblrMsg =
								StringExtensions.RemoveMultipleWhitespace(
										BBCodeHelper.StripBBCode(
												HtmlHelper.StripHtml(HtmlHelper.CleanHtmlString((string)this._topic["Topic"]))));

						var meta = this.Page.Header.FindControlType<HtmlMeta>();

						string description = string.Empty;

						if (meta.Any(x => x.Name.Equals("description")))
						{
							var descriptionMeta = meta.FirstOrDefault(x => x.Name.Equals("description"));
							if (descriptionMeta != null)
							{
								description = "&description={0}".FormatWith(descriptionMeta.Content);
							}
						}

						var tumblrUrl =
								"http://www.tumblr.com/share/link?url={0}&name={1}{2}".FormatWith(
										this.Server.UrlEncode(topicUrl), tumblrMsg, description);

						this.Get<HttpResponseBase>().Redirect(tumblrUrl);
					}

					break;
				case "retweet":
					{
						var twitterName = this.Get<YafBoardSettings>().TwitterUserName.IsSet()
																	? "@{0} ".FormatWith(this.Get<YafBoardSettings>().TwitterUserName)
																	: string.Empty;

						// process message... clean html, strip html, remove bbcode, etc...
						var twitterMsg =
								StringExtensions.RemoveMultipleWhitespace(
										BBCodeHelper.StripBBCode(
												HtmlHelper.StripHtml(HtmlHelper.CleanHtmlString((string)this._topic["Topic"]))));

						var tweetUrl =
								"http://twitter.com/share?url={0}&text={1}".FormatWith(
										this.Server.UrlEncode(topicUrl),
										this.Server.UrlEncode(
												"RT {1}Thread: {0}".FormatWith(twitterMsg.Truncate(100), twitterName)));

						// Send Retweet Directlly thru the Twitter API if User is Twitter User
						if (Config.TwitterConsumerKey.IsSet() && Config.TwitterConsumerSecret.IsSet() &&
								this.Get<IYafSession>().TwitterToken.IsSet() &&
								this.Get<IYafSession>().TwitterTokenSecret.IsSet() && this.PageContext.IsTwitterUser)
						{
							var oAuth = new OAuthTwitter
									{
										ConsumerKey = Config.TwitterConsumerKey,
										ConsumerSecret = Config.TwitterConsumerSecret,
										Token = this.Get<IYafSession>().TwitterToken,
										TokenSecret = this.Get<IYafSession>().TwitterTokenSecret
									};

							var tweets = new TweetAPI(oAuth);

							tweets.UpdateStatus(
									TweetAPI.ResponseFormat.json,
									this.Server.UrlEncode(
											"RT {1}: {0} {2}".FormatWith(twitterMsg.Truncate(100), twitterName, topicUrl)),
									string.Empty);
						}
						else
						{
							this.Get<HttpResponseBase>().Redirect(tweetUrl);
						}
					}

					break;
				case "digg":
					{
						var diggUrl =
								"http://digg.com/submit?url={0}&title={1}".FormatWith(
										this.Server.UrlEncode(topicUrl), this.Server.UrlEncode((string)this._topic["Topic"]));

						this.Get<HttpResponseBase>().Redirect(diggUrl);
					}

					break;
				case "reddit":
					{
						var redditUrl =
								"http://www.reddit.com/submit?url={0}&title={1}".FormatWith(
										this.Server.UrlEncode(topicUrl), this.Server.UrlEncode((string)this._topic["Topic"]));

						this.Get<HttpResponseBase>().Redirect(redditUrl);
					}

					break;
				case "googleplus":
					{
						var googlePlusUrl =
								"https://plusone.google.com/_/+1/confirm?hl=en&url={0}".FormatWith(
										this.Server.UrlEncode(topicUrl));

						this.Get<HttpResponseBase>().Redirect(googlePlusUrl);
					}

					break;
				default:
					throw new ApplicationException(e.Item);
			}
		}