void AccountPreferences_LinkTumblr(object sender, EventArgs e) { AuthoriseRequestSid(); Tumblr t = new Tumblr(core.Settings.TumblrApiKey, core.Settings.TumblrApiSecret); TumblrAuthToken auth = t.OAuthRequestToken(); LoggedInMember.UserInfo.TumblrToken = auth.Token; LoggedInMember.UserInfo.TumblrTokenSecret = auth.Secret; LoggedInMember.UserInfo.TumblrAuthenticated = false; LoggedInMember.UserInfo.TumblrSyndicate = false; LoggedInMember.UserInfo.Update(); core.Http.Redirect("https://www.tumblr.com/oauth/authorize?oauth_token=" + auth.Token); }
void AccountPreferences_Show(object sender, EventArgs e) { Save(new EventHandler(AccountPreferences_Save)); //User loggedInMember = (User)loggedInMember; template.SetTemplate("account_preferences.html"); TextBox customDomainTextBox = new TextBox("custom-domain"); customDomainTextBox.Value = LoggedInMember.UserDomain; TextBox analyticsCodeTextBox = new TextBox("analytics-code"); analyticsCodeTextBox.Value = LoggedInMember.UserInfo.AnalyticsCode; TextBox twitterUserNameTextBox = new TextBox("twitter-user-name"); twitterUserNameTextBox.Value = LoggedInMember.UserInfo.TwitterUserName; CheckBox twitterSyndicateCheckBox = new CheckBox("twitter-syndicate"); twitterSyndicateCheckBox.IsChecked = LoggedInMember.UserInfo.TwitterSyndicate; twitterSyndicateCheckBox.Width.Length = 0; CheckBox tumblrSyndicateCheckBox = new CheckBox("tumblr-syndicate"); tumblrSyndicateCheckBox.IsChecked = LoggedInMember.UserInfo.TumblrSyndicate; tumblrSyndicateCheckBox.Width.Length = 0; CheckBox facebookSyndicateCheckBox = new CheckBox("facebook-syndicate"); facebookSyndicateCheckBox.IsChecked = LoggedInMember.UserInfo.FacebookSyndicate; facebookSyndicateCheckBox.Width.Length = 0; SelectBox facebookSharePermissionSelectBox = new SelectBox("facebook-share-permissions"); facebookSharePermissionSelectBox.Add(new SelectBoxItem("", core.Prose.GetString("TIMELINE_DEFAULT"))); facebookSharePermissionSelectBox.Add(new SelectBoxItem("EVERYONE", core.Prose.GetString("PUBLIC"))); facebookSharePermissionSelectBox.Add(new SelectBoxItem("FRIENDS_OF_FRIENDS", core.Prose.GetString("FRIENDS_OF_FACEBOOK_FRIENDS"))); facebookSharePermissionSelectBox.Add(new SelectBoxItem("ALL_FRIENDS", core.Prose.GetString("FACEBOOK_FRIENDS"))); SelectBox tumblrBlogsSelectBox = new SelectBox("tumblr-blogs"); if (LoggedInMember.UserInfo.TumblrAuthenticated) { Tumblr t = new Tumblr(core.Settings.TumblrApiKey, core.Settings.TumblrApiSecret); List<Dictionary<string, string>> blogs = t.GetUserInfo(new TumblrAccessToken(LoggedInMember.UserInfo.TumblrToken, LoggedInMember.UserInfo.TumblrTokenSecret)).Blogs; foreach (Dictionary<string, string> blog in blogs) { string hostname = (new Uri(blog["url"])).Host; tumblrBlogsSelectBox.Add(new SelectBoxItem(hostname, blog["title"])); if (hostname == LoggedInMember.UserInfo.TumblrHostname) { tumblrBlogsSelectBox.SelectedKey = LoggedInMember.UserInfo.TumblrHostname; } } } if (LoggedInMember.UserInfo.FacebookSharePermissions != null) { facebookSharePermissionSelectBox.SelectedKey = LoggedInMember.UserInfo.FacebookSharePermissions; } string radioChecked = " checked=\"checked\""; if (LoggedInMember.UserInfo.EmailNotifications) { template.Parse("S_EMAIL_NOTIFICATIONS_YES", radioChecked); } else { template.Parse("S_EMAIL_NOTIFICATIONS_NO", radioChecked); } if (LoggedInMember.UserInfo.ShowCustomStyles) { template.Parse("S_SHOW_STYLES_YES", radioChecked); } else { template.Parse("S_SHOW_STYLES_NO", radioChecked); } if (LoggedInMember.UserInfo.BbcodeShowImages) { template.Parse("S_DISPLAY_IMAGES_YES", radioChecked); } else { template.Parse("S_DISPLAY_IMAGES_NO", radioChecked); } if (LoggedInMember.UserInfo.BbcodeShowFlash) { template.Parse("S_DISPLAY_FLASH_YES", radioChecked); } else { template.Parse("S_DISPLAY_FLASH_NO", radioChecked); } if (LoggedInMember.UserInfo.BbcodeShowVideos) { template.Parse("S_DISPLAY_VIDEOS_YES", radioChecked); } else { template.Parse("S_DISPLAY_VIDEOS_NO", radioChecked); } template.Parse("S_CUSTOM_DOMAIN", customDomainTextBox); template.Parse("S_ANALYTICS_CODE", analyticsCodeTextBox); if (!string.IsNullOrEmpty(core.Settings.TwitterApiKey)) { template.Parse("S_TWITTER_INTEGRATION", "TRUE"); } if (!string.IsNullOrEmpty(core.Settings.TumblrApiKey)) { template.Parse("S_TUMBLR_INTEGRATION", "TRUE"); } if (core.Settings.FacebookEnabled || ((!string.IsNullOrEmpty(core.Settings.FacebookApiAppid)) && LoggedInMember.UserInfo.FacebookAuthenticated)) { template.Parse("S_FACEBOOK_INTEGRATION", "TRUE"); } if (string.IsNullOrEmpty(LoggedInMember.UserInfo.TwitterUserName)) { template.Parse("S_TWITTER_USER_NAME", twitterUserNameTextBox); } else { template.Parse("TWITTER_USER_NAME", LoggedInMember.UserInfo.TwitterUserName); template.Parse("S_SYDNDICATE_TWITTER", twitterSyndicateCheckBox); template.Parse("U_UNLINK_TWITTER", core.Hyperlink.AppendSid(BuildUri("preferences", "unlink-twitter"), true)); } if (string.IsNullOrEmpty(LoggedInMember.UserInfo.TumblrUserName)) { template.Parse("U_LINK_TUMBLR", core.Hyperlink.AppendSid(BuildUri("preferences", "link-tumblr"), true)); } else { /* TODO: get list of tumblr blogs */ template.Parse("TUMBLR_USER_NAME", LoggedInMember.UserInfo.TumblrUserName); template.Parse("S_TUMBLR_BLOGS", tumblrBlogsSelectBox); template.Parse("S_SYDNDICATE_TUMBLR", tumblrSyndicateCheckBox); template.Parse("U_UNLINK_TUMBLR", core.Hyperlink.AppendSid(BuildUri("preferences", "unlink-tumblr"), true)); } if (string.IsNullOrEmpty(LoggedInMember.UserInfo.FacebookUserId)) { string appId = core.Settings.FacebookApiAppid; string redirectTo = (core.Settings.UseSecureCookies ? "https://" : "http://") + Hyperlink.Domain + "/api/facebook/callback"; template.Parse("U_LINK_FACEBOOK", string.Format("https://www.facebook.com/dialog/oauth?client_id={0}&redirect_uri={1}&scope={2}", appId, System.Web.HttpUtility.UrlEncode(redirectTo), "publish_actions")); } else { template.Parse("S_SYDNDICATE_FACEBOOK", facebookSyndicateCheckBox); template.Parse("S_FACEBOOK_SHARE_PERMISSIONS", facebookSharePermissionSelectBox); template.Parse("U_UNLINK_FACEBOOK", core.Hyperlink.AppendSid(BuildUri("preferences", "unlink-facebook"), true)); } DataTable pagesTable = db.Query(string.Format("SELECT page_id, page_slug, page_parent_path FROM user_pages WHERE page_item_id = {0} AND page_item_type_id = {1} ORDER BY page_order ASC;", LoggedInMember.UserId, ItemKey.GetTypeId(core, typeof(User)))); SelectBox pagesSelectBox = new SelectBox("homepage"); foreach (DataRow pageRow in pagesTable.Rows) { if (string.IsNullOrEmpty((string)pageRow["page_parent_path"])) { pagesSelectBox.Add(new SelectBoxItem("/" + (string)pageRow["page_slug"], "/" + (string)pageRow["page_slug"])); } else { pagesSelectBox.Add(new SelectBoxItem("/" + (string)pageRow["page_parent_path"] + "/" + (string)pageRow["page_slug"], "/" + (string)pageRow["page_parent_path"] + "/" + (string)pageRow["page_slug"])); } } SelectBox timezoneSelectBox = UnixTime.BuildTimeZoneSelectBox("timezone"); timezoneSelectBox.SelectedKey = LoggedInMember.UserInfo.TimeZoneCode.ToString(); pagesSelectBox.SelectedKey = LoggedInMember.UserInfo.ProfileHomepage; template.Parse("S_HOMEPAGE", pagesSelectBox); template.Parse("S_TIMEZONE", timezoneSelectBox); //core.Display.ParseTimeZoneBox(template, "S_TIMEZONE", LoggedInMember.TimeZoneCode.ToString()); if (core.Http.Query["status"] == "facebook-auth-failed") { DisplayError("Failed to link your Facebook profile"); } }
public static void CleanUp(Core core, IActionableItem item) { if (item.Owner is User) { User owner = (User)item.Owner; if (owner.UserInfo.TwitterSyndicate && owner.UserInfo.TwitterAuthenticated) { if (item.Info.TweetId > 0) { Twitter t = new Twitter(core.Settings.TwitterApiKey, core.Settings.TwitterApiSecret); t.DeleteStatus(new TwitterAccessToken(owner.UserInfo.TwitterToken, owner.UserInfo.TwitterTokenSecret), item.Info.TweetId); } } if (owner.UserInfo.TumblrSyndicate && owner.UserInfo.TumblrAuthenticated) { if (item.Info.TumblrPostId > 0) { Tumblr t = new Tumblr(core.Settings.TumblrApiKey, core.Settings.TumblrApiSecret); t.DeleteStatus(new TumblrAccessToken(owner.UserInfo.TumblrToken, owner.UserInfo.TumblrTokenSecret), owner.UserInfo.TumblrHostname, item.Info.TumblrPostId); } } if (owner.UserInfo.FacebookSyndicate && owner.UserInfo.FacebookAuthenticated) { if (!string.IsNullOrEmpty(item.Info.FacebookPostId)) { Facebook fb = new Facebook(core.Settings.FacebookApiAppid, core.Settings.FacebookApiSecret); FacebookAccessToken token = fb.OAuthAppAccessToken(core, owner.UserInfo.FacebookUserId); fb.DeleteStatus(token, item.Info.FacebookPostId); } } } }
public static bool PublishPost(Core core, Job job) { core.LoadUserProfile(job.UserId); User owner = core.PrimitiveCache[job.UserId]; ItemKey sharedItemKey = new ItemKey(job.ItemId, job.ItemTypeId); IActionableItem sharedItem = null; core.ItemCache.RequestItem(sharedItemKey); try { sharedItem = (IActionableItem)core.ItemCache[sharedItemKey]; } catch { try { sharedItem = (IActionableItem)NumberedItem.Reflect(core, sharedItemKey); HttpContext.Current.Response.Write("<br />Fallback, had to reflect: " + sharedItemKey.ToString()); } catch { job.Cancel = true; return true; // Item is probably deleted, report success to delete from queue } } UpdateQuery uQuery = new UpdateQuery(typeof(ItemInfo)); uQuery.AddCondition("info_item_id", sharedItemKey.Id); uQuery.AddCondition("info_item_type_id", sharedItemKey.TypeId); try { if (owner.UserInfo.TumblrAuthenticated) // are we still authenticated { string postDescription = job.Body; Tumblr t = new Tumblr(core.Settings.TumblrApiKey, core.Settings.TumblrApiSecret); TumblrPost post = t.StatusesUpdate(new TumblrAccessToken(owner.UserInfo.TumblrToken, owner.UserInfo.TumblrTokenSecret), owner.UserInfo.TumblrHostname, sharedItem.PostType, string.Empty, postDescription, sharedItem.Info.ShareUri, sharedItem.Data, sharedItem.DataContentType); if (post != null) { uQuery.AddField("info_tumblr_post_id", post.Id); } core.Db.Query(uQuery); } } catch (System.Net.WebException ex) { HttpWebResponse response = (HttpWebResponse)ex.Response; if (response.StatusCode == HttpStatusCode.Forbidden) { return true; // This request cannot succeed, so remove it from the queue } job.Error = ex.ToString(); return false; // Failed for other reasons, retry } return true; // success }
protected void Page_Load(object sender, EventArgs e) { string function = core.Http["fun"]; string oAuthToken; string oAuthVerifier; switch (function) { case "form": break; case "date": string date = core.Functions.InterpretDate(core.Http.Form["date"], (DisplayMedium)int.Parse(core.Http.Form["Medium"])); core.Response.SendRawText("date", date); return; case "time": string time = core.Functions.InterpretTime(core.Http.Form["time"]); core.Response.SendRawText("time", time); return; case "friend-list": ReturnFriendList(); return; case "tag-list": ReturnTagList(); return; case "search-list": return; case "contact-card": ReturnContactCard(); return; case "feed": if (core.Http.Form["view-mode"] == "tick") { long viewId = 0; viewId = core.Functions.FormLong("vid", core.Functions.RequestLong("vid", 0)); if (viewId > 0) { ItemView.UpdateView(core, false); } } CheckNewFeedItems(); return; case "permission-groups-list": core.Functions.ReturnPermissionGroupList(ResponseFormats.Xml); return; case "embed": ReturnItemEmbedCode(); return; case "twitter": Twitter t = new Twitter(core.Settings.TwitterApiKey, core.Settings.TwitterApiSecret); oAuthToken = core.Http.Query["oauth_token"]; oAuthVerifier = core.Http.Query["oauth_verifier"]; t.SaveTwitterAccess(core, oAuthToken, oAuthVerifier); return; case "tumblr": Tumblr tr = new Tumblr(core.Settings.TumblrApiKey, core.Settings.TumblrApiSecret); oAuthToken = core.Http.Query["oauth_token"]; oAuthVerifier = core.Http.Query["oauth_verifier"]; // + "#_=_"; tr.SaveTumblrAccess(core, oAuthToken, oAuthVerifier); return; case "googleplus": /*Google g = new Google(core.Settings.GoogleApiKey, core.Settings.GoogleApiSecret); string oAuthCode = core.Http.Query["code"]; g.SaveGoogleAccess(core, oAuthToken, oAuthCode);*/ return; case "facebook": Facebook fb = new Facebook(core.Settings.FacebookApiAppid, core.Settings.FacebookApiSecret); string errorReason = core.Http.Query["error_reason"]; string code = core.Http.Query["code"]; if (!(errorReason == "user_denied")) { fb.SaveFacebookAccess(core, code); } else { core.Http.Redirect(core.Hyperlink.BuildAccountSubModuleUri("dashboard", "preferences") + "?status=facebook-auth-failed"); } return; case "boxsocial": NameValueCollection response = new NameValueCollection(); core.Http.WriteAndEndResponse(response); break; case "oauth": string method = core.Http.Query["method"]; switch (method) { case "authorize": OAuthAuthorize(false); return; case "approve": OAuthApprove(); return; case "authenticate": return; } break; case "sms": break; case "log-view": ItemView.UpdateView(core); break; } }