Exemplo n.º 1
0
        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);
                    }
                }
            }
        }
Exemplo n.º 2
0
        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
                {
                    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.FacebookAuthenticated) // are we still authenticated
                {
                    string postDescription = job.Body;

                    Facebook fb = new Facebook(core.Settings.FacebookApiAppid, core.Settings.FacebookApiSecret);

                    FacebookAccessToken token = fb.OAuthAppAccessToken(core, owner.UserInfo.FacebookUserId);
                    FacebookPost post = fb.StatusesUpdate(token, postDescription, sharedItem.Info.ShareUri, owner.UserInfo.FacebookSharePermissions);

                    if (post != null)
                    {
                        uQuery.AddField("info_facebook_post_id", post.PostId);
                    }

                    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
                }
                return false; // Failed for other reasons, retry
            }

            return true; // success
        }
Exemplo n.º 3
0
        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;
            }
        }