示例#1
0
        /// <summary>
        /// Re-tweets 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()
                                  ? $"@{this.Get<YafBoardSettings>().TwitterUserName} "
                                  : string.Empty;

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

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

            // Send Re-tweet Directly 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 auth = new OAuthTwitter
                {
                    ConsumerKey    = Config.TwitterConsumerKey,
                    ConsumerSecret = Config.TwitterConsumerSecret,
                    Token          = this.Get <IYafSession>().TwitterToken,
                    TokenSecret    = this.Get <IYafSession>().TwitterTokenSecret
                };

                var tweets = new TweetAPI(auth);

                tweets.UpdateStatus(
                    TweetAPI.ResponseFormat.json,
                    this.Server.UrlEncode(
                        string.Format("RT {1}: {0} {2}", twitterMsg.Truncate(100), twitterName, topicUrl)),
                    string.Empty);
            }
            else
            {
                this.Get <HttpResponseBase>().Redirect(
                    $"http://twitter.com/share?url={this.Server.UrlEncode(topicUrl)}&text={this.Server.UrlEncode(s: $"RT {twitterName}: {twitterMsg.Truncate(100)}")}");
            }
示例#2
0
        /// <summary>
        /// Gets the twitter user info as JSON string for the hover cards
        /// </summary>
        /// <param name="context">The context.</param>
        public void GetTwitterUserInfo([NotNull] HttpContext context)
        {
            try
            {
                var twitterName = context.Request.QueryString.GetFirstOrDefault("twitterinfo");

                if (!Config.IsTwitterEnabled)
                {
                    context.Response.Write(
                        "Error: Resource has been moved or is unavailable. Please contact the forum admin.");

                    return;
                }

                var authTwitter = new OAuthTwitter
                {
                    ConsumerKey    = Config.TwitterConsumerKey,
                    ConsumerSecret = Config.TwitterConsumerSecret,
                    Token          = Config.TwitterToken,
                    TokenSecret    = Config.TwitterTokenSecret
                };

                var tweetApi = new TweetAPI(authTwitter);

                context.Response.Write(tweetApi.UsersLookupJson(twitterName));

                HttpContext.Current.ApplicationInstance.CompleteRequest();
            }
            catch (Exception x)
            {
                this.Get <ILogger>().Log(BoardContext.Current.PageUserID, this, x, EventLogTypes.Information);

                context.Response.Write(
                    "Error: Resource has been moved or is unavailable. Please contact the forum admin.");
            }
        }