Example #1
0
        public static void ApplyRestrictions(Core core, Classifications classification)
        {
            if (core == null)
            {
                throw new NullCoreException();
            }

            switch (classification)
            {
                case Classifications.Restricted:
                    if (core.Session.LoggedInMember.Profile.Age < 18)
                    {
                        // TODO: Restricted content notice
                        core.Functions.Generate403();
                        return;
                    }
                    break;
                case Classifications.Mature:
                    if (core.Session.LoggedInMember.Profile.Age < 13)
                    {
                        // TODO: Restricted content notice
                        core.Functions.Generate403();
                        return;
                    }
                    else if (core.Session.LoggedInMember.Profile.Age < 15)
                    {
                        // TODO: click-through message for 13/14 year olds
                        // TODO: Restricted content notice
                        core.Functions.Generate403();
                        return;
                    }
                    break;
            }
        }
Example #2
0
        public Category(Core core, DataRow categoryRow)
            : base(core)
        {
            ItemLoad += new ItemLoadHandler(Category_ItemLoad);

            loadItemInfo(categoryRow);
        }
Example #3
0
        public HelpTopic(Core core, DataRow helpRow)
            : base(core)
        {
            ItemLoad += new ItemLoadHandler(HelpTopic_ItemLoad);

            loadItemInfo(helpRow);
        }
Example #4
0
        public static void Show(Core core, UPage page)
        {
            core.Template.SetTemplate("GuestBook", "viewguestbook");

            page.User.LoadProfileInfo();

            if (!page.User.Access.Can("VIEW"))
            {
                core.Functions.Generate403();
                return;
            }

            /* pages */
            core.Display.ParsePageList(page.Owner, true);

            core.Template.Parse("PAGE_TITLE", string.Format(core.Prose.GetString("USERS_GUEST_BOOK"), page.Owner.DisplayNameOwnership));

            if (core.Session.IsLoggedIn)
            {
                if (page.User.Access.Can("COMMENT"))
                {
                    core.Template.Parse("CAN_COMMENT", "TRUE");
                }
            }

            core.Template.Parse("IS_USER_GUESTBOOK", "TRUE");

            List<string[]> breadCrumbParts = new List<string[]>();
            breadCrumbParts.Add(new string[] { "profile", core.Prose.GetString("PROFILE") });
            breadCrumbParts.Add(new string[] { "comments", core.Prose.GetString("GUEST_BOOK") });

            core.Display.DisplayComments(core.Template, page.User, page.User, UserGuestBookHook);
            core.Display.ParsePagination("COMMENT_PAGINATION", core.Hyperlink.BuildGuestBookUri(page.User), 10, page.User.Comments);
            page.User.ParseBreadCrumbs(breadCrumbParts);
        }
Example #5
0
        public ApplicationError(Core core, DataRow errorRow)
            : base(core)
        {
            ItemLoad += new ItemLoadHandler(ApplicationError_ItemLoad);

            loadItemInfo(errorRow);
        }
Example #6
0
        public SpamReport(Core core, DataRow reportRow)
            : base(core)
        {
            ItemLoad += new ItemLoadHandler(SpamReport_ItemLoad);

            loadItemInfo(reportRow);
        }
Example #7
0
        public ReferralKey(Core core, DataRow referralRow)
            : base(core)
        {
            ItemLoad += new ItemLoadHandler(ReferralKey_ItemLoad);

            loadItemInfo(referralRow);
        }
Example #8
0
        public EventEmailInvite(Core core, System.Data.Common.DbDataReader eventInviteDataRow)
            : base(core)
        {
            ItemLoad += new ItemLoadHandler(EventEmailInvite_ItemLoad);

            loadItemInfo(eventInviteDataRow);
        }
        public NumberedItemsCache(Core core)
        {
            this.core = core;
            this.db = core.Db;

            if (itemsPersisted == null)
            {
                object o = core.Cache.GetCached("NumberedItems");

                if (o != null && o is Dictionary<NumberedItemId, NumberedItem>)
                {
                    itemsPersisted = (Dictionary<NumberedItemId, NumberedItem>)o;
                }
                else
                {
                    itemsPersisted = new Dictionary<NumberedItemId, NumberedItem>(32);
                }
            }

            if (itemsPersisted != null)
            {
                foreach (NumberedItemId nii in itemsPersisted.Keys)
                {
                    itemsCached.Add(nii, itemsPersisted[nii]);
                }
            }
        }
        public PrimitiveApplicationInfo(Core core, Primitive owner, long applicationId)
            : base(core)
        {
            this.owner = owner;
            ItemLoad += new ItemLoadHandler(PrimitiveApplicationInfo_ItemLoad);

            SelectQuery query = new SelectQuery(PrimitiveApplicationInfo.GetTable(typeof(PrimitiveApplicationInfo)));
            query.AddFields(PrimitiveApplicationInfo.GetFieldsPrefixed(core, typeof(PrimitiveApplicationInfo)));
            query.AddCondition("application_id", applicationId);
            query.AddCondition("item_id", owner.Id);
            query.AddCondition("item_type_id", owner.TypeId);

            DataTable appDataTable = db.Query(query);

            if (appDataTable.Rows.Count == 1)
            {
                DataRow appRow = appDataTable.Rows[0];
                try
                {
                    loadItemInfo(appRow);
                }
                catch (InvalidItemException)
                {
                    throw new InvalidPrimitiveAppInfoException();
                }
            }
            else
            {
                throw new InvalidPrimitiveAppInfoException();
            }
        }
Example #11
0
        public EventEmailInvite(Core core, DataRow eventInviteDataRow)
            : base(core)
        {
            ItemLoad += new ItemLoadHandler(EventEmailInvite_ItemLoad);

            loadItemInfo(eventInviteDataRow);
        }
Example #12
0
        public InviteKey(Core core, DataRow inviteRow)
            : base(core)
        {
            ItemLoad += new ItemLoadHandler(InviteKey_ItemLoad);

            loadItemInfo(inviteRow);
        }
Example #13
0
        public RateLimit(Core core, System.Data.Common.DbDataReader rateLimitRow)
            : base(core)
        {
            ItemLoad += new ItemLoadHandler(RateLimit_ItemLoad);

            loadItemInfo(rateLimitRow);
        }
Example #14
0
        public GroupMember(Core core, UserGroup group, long userId)
            : base(core)
        {
            this.db = db;

            SelectQuery query = GetSelectQueryStub(core, UserLoadOptions.All);
            query.AddCondition("user_keys.user_id", userId);
            query.AddCondition("group_members.group_id", group.GroupId);

            System.Data.Common.DbDataReader memberReader = db.ReaderQuery(query);

            if (memberReader.HasRows)
            {
                memberReader.Read();

                loadItemInfo(memberReader);
                loadUserInfo(memberReader);
                loadUserIcon(memberReader);

                memberReader.Close();
                memberReader.Dispose();
            }
            else
            {
                memberReader.Close();
                memberReader.Dispose();

                throw new InvalidUserException();
            }
        }
        public ItemViewCountByHour(Core core, DataRow viewRow)
            : base(core)
        {
            ItemLoad += new ItemLoadHandler(ItemViewCountByHour_ItemLoad);

            loadItemInfo(viewRow);
        }
Example #16
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
                {
                    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
        }
Example #17
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
        }
        public GuestBookCommentCount(Core core, DataRow countRow)
            : base(core)
        {
            ItemLoad += new ItemLoadHandler(GuestBookCommentCount_ItemLoad);

            loadItemInfo(countRow);
        }
Example #19
0
        public static void Show(Core core)
        {
            string path = core.Http.Query["path"];
            long ownerId = core.Functions.RequestLong("owner_id", 0);
            long ownerTypeId = core.Functions.RequestLong("owner_type_id", 0);
            ItemKey ownerKey = new ItemKey(ownerId, ownerTypeId);

            try
            {
                core.PrimitiveCache.LoadPrimitiveProfile(ownerKey);
                Primitive owner = core.PrimitiveCache[ownerKey];

                Page thePage = new Page(core, owner, path);

                JsonSerializer js;
                StringWriter jstw;
                JsonTextWriter jtw;

                js = new JsonSerializer();
                jstw = new StringWriter();
                jtw = new JsonTextWriter(jstw);

                js.NullValueHandling = NullValueHandling.Ignore;

                core.Http.WriteJson(js, thePage);
            }
            catch (PageNotFoundException)
            {

            }
            catch
            {
            }
        }
Example #20
0
        public ListType(Core core, DataRow typeRow)
            : base(core)
        {
            ItemLoad += new ItemLoadHandler(ListType_ItemLoad);

            loadItemInfo(typeRow);
        }
Example #21
0
        public ActionItem(Core core, long actionId, long itemId, long itemTypeId)
            : base(core)
        {
            ItemLoad += new ItemLoadHandler(ActionItem_ItemLoad);

            SelectQuery query = ActionItem.GetSelectQueryStub(core, typeof(ActionItem));
            query.AddCondition("action_id", actionId);
            query.AddCondition("item_id", itemId);
            query.AddCondition("item_type_id", itemTypeId);

            System.Data.Common.DbDataReader actionReader = db.ReaderQuery(query);

            if (actionReader.HasRows)
            {
                actionReader.Read();

                loadItemInfo(actionReader);

                actionReader.Close();
                actionReader.Dispose();
            }
            else
            {
                actionReader.Close();
                actionReader.Dispose();

                throw new InvalidActionItemException();
            }
        }
Example #22
0
        public EventInvite(Core core, long eventId, Primitive invitee)
            : base(core)
        {
            this.ItemLoad += new ItemLoadHandler(EventInvite_ItemLoad);

            SelectQuery query = EventInvite.GetSelectQueryStub(core, typeof(EventInvite));
            query.AddCondition("event_id", eventId);
            query.AddCondition("item_id", invitee.Id);
            query.AddCondition("item_type_id", invitee.TypeId);

            System.Data.Common.DbDataReader inviteReader = db.ReaderQuery(query);

            try
            {
                if (inviteReader.HasRows)
                {
                    inviteReader.Read();

                    loadItemInfo(inviteReader);
                }

                inviteReader.Close();
                inviteReader.Dispose();
            }
            catch (InvalidItemException)
            {
                inviteReader.Close();
                inviteReader.Dispose();

                throw new InvalidEventInviteException();
            }
        }
Example #23
0
        public UserGuestBook(Core core, User owner)
            : base(core)
        {
            this.db = core.Db;

            this.owner = owner;
        }
Example #24
0
        public BirthdayEvent(Core core, User owner, User user, int year)
            : base(core)
        {
            this.owner = owner;
            this.user = user;

            if (!user.IsFriend(owner.ItemKey))
            {
                throw new InvalidEventException();
            }

            UnixTime tz = new UnixTime(core, user.UserInfo.TimeZoneCode);

            this.eventId = ~user.Id;
            this.subject = user.TitleNameOwnership + " birthday";
            this.description = string.Empty;
            this.views = 0;
            this.attendeeCount = 0;
            this.ownerKey = new ItemKey(owner.Id, owner.TypeId);
            this.userId = user.Id;
            this.startTimeRaw =  tz.GetUnixTimeStamp(new DateTime(year, user.Profile.DateOfBirth.Month, user.Profile.DateOfBirth.Day, 0, 0, 0));
            this.endTimeRaw = tz.GetUnixTimeStamp(new DateTime(year, user.Profile.DateOfBirth.Month, user.Profile.DateOfBirth.Day, 23, 59, 59));
            this.allDay = true;
            this.invitees = 0;
            this.category = 0;
            this.location = string.Empty;
        }
Example #25
0
        public ApplicationError(Core core, System.Data.Common.DbDataReader errorRow)
            : base(core)
        {
            ItemLoad += new ItemLoadHandler(ApplicationError_ItemLoad);

            loadItemInfo(errorRow);
        }
Example #26
0
        public OAuthApplication(Core core, string apiKey)
            : base(core, false)
        {
            this.db = db;

            SelectQuery query = GetSelectQueryStub(core);
            query.AddCondition(new DataField(typeof(OAuthApplication), "application_api_key"), apiKey);

            System.Data.Common.DbDataReader applicationReader = db.ReaderQuery(query);

            if (applicationReader.HasRows)
            {
                applicationReader.Read();

                loadItemInfo(applicationReader);
                loadApplication(applicationReader);

                applicationReader.Close();
                applicationReader.Dispose();
            }
            else
            {
                applicationReader.Close();
                applicationReader.Dispose();

                throw new InvalidApplicationException();
            }
        }
Example #27
0
        public Category(Core core, System.Data.Common.DbDataReader categoryRow)
            : base(core)
        {
            ItemLoad += new ItemLoadHandler(Category_ItemLoad);

            loadItemInfo(categoryRow);
        }
Example #28
0
        public ItemHashtag(Core core, DataRow itemHashtagRow)
            : base(core)
        {
            ItemLoad += new ItemLoadHandler(ItemHashtag_ItemLoad);

            loadItemInfo(itemHashtagRow);
        }
Example #29
0
        public Calendar(Core core, Primitive owner)
            : base(core)
        {
            if (core == null)
            {
                throw new NullCoreException();
            }

            if (owner == null)
            {
                throw new InvalidUserException();
            }

            this.owner = owner;
            ItemLoad += new ItemLoadHandler(Calendar_ItemLoad);

            try
            {
                LoadItem("calendar_item_id", "calendar_item_type_id", owner);
            }
            catch (InvalidItemException)
            {
                throw new InvalidCalendarException();
            }
        }
Example #30
0
        internal GroupOperator(Core core, DataRow operatorRow)
            : base(core, operatorRow)
        {
            ItemLoad += new ItemLoadHandler(GroupOperator_ItemLoad);

            loadItemInfo(operatorRow);
        }