Ejemplo n.º 1
0
        internal static void RenderMessage(Core core, Template template, Message message)
        {
            MessageRecipient recipient = new MessageRecipient(core, core.Session.LoggedInMember, message.Id);

            VariableCollection messageVariableCollection = template.CreateChild("post_list");

            messageVariableCollection.Parse("SUBJECT", message.Subject);
            messageVariableCollection.Parse("POST_TIME", core.Tz.DateTimeToString(message.GetSentDate(core.Tz)));
            messageVariableCollection.Parse("URI", message.Uri);
            messageVariableCollection.Parse("ID", message.Id.ToString());
            core.Display.ParseBbcode(messageVariableCollection, "MESSAGE", message.Text);
            if (message.Sender != null)
            {
                messageVariableCollection.Parse("U_USER", message.Sender.Uri);
                messageVariableCollection.Parse("USER_DISPLAY_NAME", message.Sender.UserInfo.DisplayName);
                messageVariableCollection.Parse("USER_TILE", message.Sender.Tile);
                messageVariableCollection.Parse("USER_ICON", message.Sender.Icon);
                messageVariableCollection.Parse("USER_JOINED", core.Tz.DateTimeToString(message.Sender.UserInfo.GetRegistrationDate(core.Tz)));
                messageVariableCollection.Parse("USER_COUNTRY", message.Sender.Profile.Country);
                //core.Display.ParseBbcode(messageVariableCollection, "SIGNATURE", postersList[post.UserId].ForumSignature);

                if (message.Sender.Id == core.LoggedInMemberId)
                {
                    messageVariableCollection.Parse("OWNER", "TRUE");
                }
            }
            else
            {
                messageVariableCollection.Parse("USER_DISPLAY_NAME", "Anonymous");
            }

            if (recipient.IsRead)
            {
                messageVariableCollection.Parse("IS_READ", "TRUE");
            }
            else
            {
                messageVariableCollection.Parse("IS_READ", "FALSE");
            }

            recipient.MarkRead();
        }
Ejemplo n.º 2
0
        public Template RenderPreview()
        {
            Template template = new Template(Assembly.GetExecutingAssembly(), "topicpost");
            template.Medium = core.Template.Medium;
            template.SetProse(core.Prose);

            VariableCollection postVariableCollection = template.CreateChild("post_list");

            Dictionary<long, ForumMember> postersList = ForumMember.GetMembers(core, Forum.Owner, new List<long> { UserId });

            postVariableCollection.Parse("SUBJECT", Title);
            postVariableCollection.Parse("POST_TIME", core.Tz.DateTimeToString(GetCreatedDate(core.Tz)));
            postVariableCollection.Parse("URI", Uri);
            //postVariableCollection.Parse("POST_MODIFIED", core.tz.DateTimeToString(post.GetModifiedDate(core.tz)));
            postVariableCollection.Parse("ID", Id.ToString());
            core.Display.ParseBbcode(postVariableCollection, "TEXT", Text);
            if (postersList.ContainsKey(UserId))
            {
                postVariableCollection.Parse("U_USER", postersList[UserId].Uri);
                postVariableCollection.Parse("USER_DISPLAY_NAME", postersList[UserId].UserInfo.DisplayName);
                postVariableCollection.Parse("USER_TILE", postersList[UserId].Tile);
                postVariableCollection.Parse("USER_ICON", postersList[UserId].Icon);
                postVariableCollection.Parse("USER_JOINED", core.Tz.DateTimeToString(postersList[UserId].UserInfo.GetRegistrationDate(core.Tz)));
                postVariableCollection.Parse("USER_COUNTRY", postersList[UserId].Profile.Country);
                postVariableCollection.Parse("USER_POSTS", postersList[UserId].ForumPosts.ToString());
                core.Display.ParseBbcode(postVariableCollection, "SIGNATURE", postersList[UserId].ForumSignature);

                /*if (ranksList.ContainsKey(postersList[post.UserId].ForumRankId))
                {
                    postVariableCollection.Parse("USER_RANK", ranksList[postersList[UserId].ForumRankId].RankTitleText);
                }*/
            }
            else
            {
                postVariableCollection.Parse("USER_DISPLAY_NAME", "Anonymous");
            }

            /*if (thisTopic.ReadStatus == null)
            {*/
                postVariableCollection.Parse("IS_READ", "FALSE");
            /*}
            else
            {
                if (thisTopic.ReadStatus.ReadTimeRaw < post.TimeCreatedRaw)
                {
                    postVariableCollection.Parse("IS_READ", "FALSE");
                }
                else
                {
                    postVariableCollection.Parse("IS_READ", "TRUE");
                }
            }*/

            return template;
        }
Ejemplo n.º 3
0
        public void ShowGroupNews(HookEventArgs e)
        {
            Template template = new Template(Assembly.GetExecutingAssembly(), "viewprofilenews");
            template.Medium = core.Template.Medium;
            template.SetProse(core.Prose);

            if (e.Owner is UserGroup)
            {
                News news = new News(e.core, (UserGroup)e.Owner);

                List<Article> articles = news.GetArticles(1, 5);

                foreach (Article article in articles)
                {
                    VariableCollection articleVariableCollection = template.CreateChild("news_list");

                    articleVariableCollection.Parse("TITLE", article.ArticleSubject);
                }
            }

            e.core.AddSidePanel(template);
        }
Ejemplo n.º 4
0
        public static void Show(Core core, TPage page, User owner)
        {
            if (core == null)
            {
                throw new NullCoreException();
            }

            if (core.ResponseFormat == ResponseFormats.Xml)
            {
                ShowMore(core, page, owner);
                return;
            }

            Template template = new Template(core.Http.TemplatePath, "viewfeed.html");
            template.Medium = core.Template.Medium;
            template.SetProse(core.Prose);

            PermissionGroupSelectBox permissionSelectBox = new PermissionGroupSelectBox(core, "permissions", owner.ItemKey);

            template.Parse("S_STATUS_PERMISSIONS", permissionSelectBox);

            bool moreContent = false;
            long lastId = 0;
            bool first = true;

            List<Action> feedActions = Feed.GetItems(core, owner, page.TopLevelPageNumber, 20, page.TopLevelPageOffset, out moreContent);

            if (feedActions.Count > 0)
            {
                template.Parse("HAS_FEED_ITEMS", "TRUE");
                VariableCollection feedDateVariableCollection = null;
                string lastDay = core.Tz.ToStringPast(core.Tz.Now);

                foreach (Action feedAction in feedActions)
                {
                    DateTime feedItemDay = feedAction.GetTime(core.Tz);

                    if (feedDateVariableCollection == null || lastDay != core.Tz.ToStringPast(feedItemDay))
                    {
                        lastDay = core.Tz.ToStringPast(feedItemDay);
                        feedDateVariableCollection = template.CreateChild("feed_days_list");

                        feedDateVariableCollection.Parse("DAY", lastDay);
                    }

                    if (first)
                    {
                        first = false;
                        template.Parse("NEWEST_ID", feedAction.Id.ToString());
                    }

                    VariableCollection feedItemVariableCollection = feedDateVariableCollection.CreateChild("feed_item");

                    core.Display.ParseBbcode(feedItemVariableCollection, "TITLE", feedAction.FormattedTitle);
                    /*if ((!core.IsMobile) && (!string.IsNullOrEmpty(feedAction.BodyCache)))
                    {
                        core.Display.ParseBbcodeCache(feedItemVariableCollection, "TEXT", feedAction.BodyCache);
                    }
                    else*/
                    {
                        Primitive itemOwner = core.PrimitiveCache[feedAction.OwnerId];
                        if (feedAction.InteractItem is IActionableItem)
                        {
                            itemOwner = ((IActionableItem)feedAction.InteractItem).Owner;

                            if (((IActionableItem)feedAction.InteractItem).ApplicationId > 0)
                            {
                                try
                                {
                                    ApplicationEntry ae = new ApplicationEntry(core, ((IActionableItem)feedAction.InteractItem).ApplicationId);

                                    if (ae.ApplicationType == ApplicationType.OAuth)
                                    {
                                        OAuthApplication oae = new OAuthApplication(core, ae);

                                        feedItemVariableCollection.Parse("VIA_APP_TITLE", oae.DisplayTitle);
                                        feedItemVariableCollection.Parse("U_VIA_APP", oae.Uri);
                                    }
                                }
                                catch (InvalidApplicationException)
                                {
                                }
                            }
                        }
                        else if (feedAction.ActionedItem is IActionableItem)
                        {
                            itemOwner = ((IActionableItem)feedAction.ActionedItem).Owner;

                            if (((IActionableItem)feedAction.ActionedItem).ApplicationId > 0)
                            {
                                try
                                {
                                    ApplicationEntry ae = new ApplicationEntry(core, ((IActionableItem)feedAction.ActionedItem).ApplicationId);

                                    if (ae.ApplicationType == ApplicationType.OAuth)
                                    {
                                        OAuthApplication oae = new OAuthApplication(core, ae);

                                        feedItemVariableCollection.Parse("VIA_APP_TITLE", oae.DisplayTitle);
                                        feedItemVariableCollection.Parse("U_VIA_APP", oae.Uri);
                                    }
                                }
                                catch (InvalidApplicationException)
                                {
                                }
                            }
                        }
                        core.Display.ParseBbcode(feedItemVariableCollection, "TEXT", feedAction.Body, itemOwner, true, string.Empty, string.Empty);
                    }

                    feedItemVariableCollection.Parse("USER_DISPLAY_NAME", feedAction.Owner.DisplayName);

                    ItemKey interactItemKey = null;

                    if (feedAction.InteractItemKey.Id > 0)
                    {
                        interactItemKey = feedAction.InteractItemKey;
                        feedItemVariableCollection.Parse("ID", feedAction.InteractItemKey.Id);
                        feedItemVariableCollection.Parse("TYPE_ID", feedAction.InteractItemKey.TypeId);
                    }
                    else
                    {
                        interactItemKey = feedAction.ActionItemKey;
                        feedItemVariableCollection.Parse("ID", feedAction.ActionItemKey.Id);
                        feedItemVariableCollection.Parse("TYPE_ID", feedAction.ActionItemKey.TypeId);
                    }

                    if (interactItemKey.GetType(core).Likeable)
                    {
                        feedItemVariableCollection.Parse("LIKEABLE", "TRUE");

                        if (feedAction.Info.Likes > 0)
                        {
                            feedItemVariableCollection.Parse("LIKES", string.Format(" {0:d}", feedAction.Info.Likes));
                            feedItemVariableCollection.Parse("DISLIKES", string.Format(" {0:d}", feedAction.Info.Dislikes));
                        }
                    }

                    if (interactItemKey.GetType(core).Commentable)
                    {
                        feedItemVariableCollection.Parse("COMMENTABLE", "TRUE");

                        if (feedAction.Info.Comments > 0)
                        {
                            feedItemVariableCollection.Parse("COMMENTS", string.Format(" ({0:d})", feedAction.Info.Comments));
                        }
                    }

                    //Access access = new Access(core, feedAction.ActionItemKey, true);
                    if (feedAction.PermissiveParent.Access.IsPublic())
                    {
                        feedItemVariableCollection.Parse("IS_PUBLIC", "TRUE");
                        if (interactItemKey.GetType(core).Shareable)
                        {
                            feedItemVariableCollection.Parse("SHAREABLE", "TRUE");
                            //feedItemVariableCollection.Parse("U_SHARE", feedAction.ShareUri);

                            if (feedAction.Info.SharedTimes > 0)
                            {
                                feedItemVariableCollection.Parse("SHARES", string.Format(" {0:d}", feedAction.Info.SharedTimes));
                            }
                        }
                    }
                    else
                    {
                        feedItemVariableCollection.Parse("IS_PUBLIC", "FALSE");
                        feedItemVariableCollection.Parse("SHAREABLE", "FALSE");
                    }

                    if (feedAction.Owner is User)
                    {
                        feedItemVariableCollection.Parse("USER_TILE", ((User)feedAction.Owner).Tile);
                        feedItemVariableCollection.Parse("USER_ICON", ((User)feedAction.Owner).Icon);
                    }

                    lastId = feedAction.Id;
                }
            }

            core.Display.ParseBlogPagination(template, "PAGINATION", core.Hyperlink.BuildHomeUri(), 0, moreContent ? lastId : 0);
            template.Parse("U_NEXT_PAGE", core.Hyperlink.BuildHomeUri() + "?p=" + (core.TopLevelPageNumber + 1) + "&o=" + lastId);

            core.AddMainPanel(template);
        }
Ejemplo n.º 5
0
        public Template RenderPreview()
        {
            Template template = new Template(Assembly.GetExecutingAssembly(), "blogentry");
            template.SetProse(core.Prose);

            VariableCollection blogPostVariableCollection = template.CreateChild("blog_list");

            blogPostVariableCollection.Parse("TITLE", Title);

            DateTime postDateTime = GetPublishedDate(core.Tz);

            string postUrl = HttpUtility.HtmlEncode(string.Format("{0}blog/{1}/{2:00}/{3}",
                    Owner.UriStub, postDateTime.Year, postDateTime.Month, PostId));

            blogPostVariableCollection.Parse("DATE", core.Tz.DateTimeToString(postDateTime));
            blogPostVariableCollection.Parse("URL", postUrl);
            blogPostVariableCollection.Parse("ID", Id);
            blogPostVariableCollection.Parse("TYPE_ID", ItemKey.TypeId);

            blogPostVariableCollection.Parse("POST", Functions.TrimStringToWord(HttpUtility.HtmlDecode(core.Bbcode.StripTags(HttpUtility.HtmlEncode(Body))), 256, true));

            if (core.Session.IsLoggedIn)
            {
                if (Owner.IsItemOwner(core.Session.LoggedInMember))
                {
                    blogPostVariableCollection.Parse("IS_OWNER", "TRUE");
                    blogPostVariableCollection.Parse("U_DELETE", DeleteUri);
                }
            }

            if (Info.Likes > 0)
            {
                blogPostVariableCollection.Parse("LIKES", string.Format(" {0:d}", Info.Likes));
                blogPostVariableCollection.Parse("DISLIKES", string.Format(" {0:d}", Info.Dislikes));
            }

            if (Info.Comments > 0)
            {
                blogPostVariableCollection.Parse("COMMENTS", string.Format(" ({0:d})", Info.Comments));
            }

            return template;
        }
Ejemplo n.º 6
0
        void AccountGalleriesUpload_Save(object sender, EventArgs e)
        {
            ControlPanelSubModule.AuthoriseRequestSid(core);

            long galleryId = core.Functions.FormLong("gallery-id", 0);
            string title = core.Http.Form["title"];
            string galleryTitle = core.Http.Form["gallery-title"];
            string description = core.Http.Form["description"];
            bool publishToFeed = (core.Http.Form["publish-feed"] != null);
            bool highQualitySave = (core.Http.Form["high-quality"] != null);
            bool submittedTitle = true;

            if (string.IsNullOrEmpty(galleryTitle))
            {
                submittedTitle = false;
                galleryTitle = "Uploaded " + core.Tz.Now.ToString("MMMM dd, yyyy");
            }

            bool newGallery = core.Http.Form["album"] == "create";

            int filesUploaded = 0;
            for (int i = 0; i < core.Http.Files.Count; i++)
            {
                if (core.Http.Files.GetKey(i).StartsWith("photo-file", StringComparison.Ordinal))
                {
                    filesUploaded++;
                    if (core.Http.Files[i] == null || core.Http.Files[i].ContentLength == 0)
                    {
                        core.Response.ShowMessage("error", "No files selected", "You need to select some files to upload");
                    }
                }
            }

            if (filesUploaded == 0)
            {
                core.Response.ShowMessage("error", "No files selected", "You need to select some files to upload");
                return;
            }

            try
            {
                Gallery parent = null;

                if (newGallery)
                {
                    Gallery grandParent = null;

                    if (!submittedTitle)
                    {
                        string grandParentSlug = "photos-from-posts";
                        try
                        {
                            grandParent = new Gallery(core, Owner, grandParentSlug);
                        }
                        catch (InvalidGalleryException)
                        {
                            Gallery root = new Gallery(core, Owner);
                            grandParent = Gallery.Create(core, Owner, root, "Photos From Posts", ref grandParentSlug, "All my unsorted uploads");
                        }
                    }
                    else
                    {
                        grandParent = new Gallery(core, Owner);
                    }

                    string gallerySlug = string.Empty;

                    if (!submittedTitle)
                    {
                        gallerySlug = "photos-" + UnixTime.UnixTimeStamp().ToString();
                    }
                    else
                    {
                        gallerySlug = Gallery.GetSlugFromTitle(galleryTitle, "");
                    }

                    try
                    {
                        parent = Gallery.Create(core, LoggedInMember, grandParent, galleryTitle, ref gallerySlug, string.Empty);
                    }
                    catch (GallerySlugNotUniqueException)
                    {
                        core.Response.ShowMessage("error", "Gallery not unique", "Please give a different name to the gallery");
                    }

                    AccessControlLists acl = new AccessControlLists(core, parent);
                    acl.SaveNewItemPermissions();
                }
                else
                {
                    parent = new Gallery(core, Owner, galleryId);
                }

                string slug = string.Empty;
                try
                {
                    for (int i = 0; i < core.Http.Files.Count; i++)
                    {
                        if (!core.Http.Files.GetKey(i).StartsWith("photo-file", StringComparison.Ordinal))
                        {
                            continue;
                        }

                        slug = core.Http.Files[i].FileName;

                        MemoryStream stream = new MemoryStream();
                        core.Http.Files[i].InputStream.CopyTo(stream);

                        db.BeginTransaction();

                        GalleryItem newGalleryItem = GalleryItem.Create(core, Owner, parent, title, ref slug, core.Http.Files[i].FileName, core.Http.Files[i].ContentType, (ulong)core.Http.Files[i].ContentLength, description, core.Functions.GetLicenseId(), core.Functions.GetClassification(), stream, highQualitySave /*, width, height*/);
                        stream.Close();

                        if (publishToFeed && i < 3)
                        {
                            core.CallingApplication.PublishToFeed(core, LoggedInMember, parent, newGalleryItem, Functions.SingleLine(core.Bbcode.Flatten(newGalleryItem.ItemAbstract)));
                        }
                    }

                    //db.CommitTransaction();

                    if (core.ResponseFormat == ResponseFormats.Xml)
                    {
                        long newestId = core.Functions.FormLong("newest-id", 0);
                        long newerId = 0;

                        List<BoxSocial.Internals.Action> feedActions = Feed.GetNewerItems(core, LoggedInMember, newestId);

                        Template template = new Template("pane.feeditem.html");
                        template.Medium = core.Template.Medium;
                        template.SetProse(core.Prose);

                        foreach (BoxSocial.Internals.Action feedAction in feedActions)
                        {
                            VariableCollection feedItemVariableCollection = template.CreateChild("feed_days_list.feed_item");

                            if (feedAction.Id > newerId)
                            {
                                newerId = feedAction.Id;
                            }

                            core.Display.ParseBbcode(feedItemVariableCollection, "TITLE", feedAction.FormattedTitle);
                            core.Display.ParseBbcode(feedItemVariableCollection, "TEXT", feedAction.Body, core.PrimitiveCache[feedAction.OwnerId], true, string.Empty, string.Empty);

                            feedItemVariableCollection.Parse("USER_DISPLAY_NAME", feedAction.Owner.DisplayName);

                            feedItemVariableCollection.Parse("ID", feedAction.ActionItemKey.Id);
                            feedItemVariableCollection.Parse("TYPE_ID", feedAction.ActionItemKey.TypeId);

                            if (feedAction.ActionItemKey.GetType(core).Likeable)
                            {
                                feedItemVariableCollection.Parse("LIKEABLE", "TRUE");

                                if (feedAction.Info.Likes > 0)
                                {
                                    feedItemVariableCollection.Parse("LIKES", string.Format(" {0:d}", feedAction.Info.Likes));
                                    feedItemVariableCollection.Parse("DISLIKES", string.Format(" {0:d}", feedAction.Info.Dislikes));
                                }
                            }

                            if (feedAction.ActionItemKey.GetType(core).Commentable)
                            {
                                feedItemVariableCollection.Parse("COMMENTABLE", "TRUE");

                                if (feedAction.Info.Comments > 0)
                                {
                                    feedItemVariableCollection.Parse("COMMENTS", string.Format(" ({0:d})", feedAction.Info.Comments));
                                }
                            }

                            //Access access = new Access(core, feedAction.ActionItemKey, true);
                            if (feedAction.PermissiveParent.Access.IsPublic())
                            {
                                feedItemVariableCollection.Parse("IS_PUBLIC", "TRUE");
                                if (feedAction.ActionItemKey.GetType(core).Shareable)
                                {
                                    feedItemVariableCollection.Parse("SHAREABLE", "TRUE");
                                    //feedItemVariableCollection.Parse("U_SHARE", feedAction.ShareUri);

                                    if (feedAction.Info.SharedTimes > 0)
                                    {
                                        feedItemVariableCollection.Parse("SHARES", string.Format(" {0:d}", feedAction.Info.SharedTimes));
                                    }
                                }
                            }

                            if (feedAction.Owner is User)
                            {
                                feedItemVariableCollection.Parse("USER_TILE", ((User)feedAction.Owner).Tile);
                                feedItemVariableCollection.Parse("USER_ICON", ((User)feedAction.Owner).Icon);
                            }
                        }

                        // Check for new messages and upload
                        Dictionary<string, string> returnValues = new Dictionary<string, string>();

                        returnValues.Add("update", "true");
                        returnValues.Add("message", description);
                        returnValues.Add("template", template.ToString());
                        returnValues.Add("newest-id", newerId.ToString());

                        core.Response.SendDictionary("statusPosted", returnValues);
                    }
                    else
                    {
                        if (filesUploaded == 1)
                        {
                            template.Parse("REDIRECT_URI", Gallery.BuildPhotoUri(core, Owner, parent.FullPath, slug));
                        }
                        else
                        {
                            template.Parse("REDIRECT_URI", parent.Uri);
                        }
                        core.Display.ShowMessage("Photo Uploaded", "You have successfully uploaded a photo.");
                    }

                    return;
                }
                catch (GalleryItemTooLargeException)
                {
                    db.RollBackTransaction();
                    core.Response.ShowMessage("error", "Photo too big", "The photo you have attempted to upload is too big, you can upload photos up to " + Functions.BytesToString(core.Settings.MaxFileSize) + " in size.");
                    return;
                }
                catch (GalleryQuotaExceededException)
                {
                    db.RollBackTransaction();
                    core.Response.ShowMessage("error", "Not Enough Quota", "You do not have enough quota to upload this photo. Try resizing the image before uploading or deleting images you no-longer need. Smaller images use less quota.");
                    return;
                }
                catch (InvalidGalleryItemTypeException)
                {
                    db.RollBackTransaction();
                    core.Response.ShowMessage("error", "Invalid image uploaded", "You have tried to upload a file type that is not a picture. You are allowed to upload PNG and JPEG images.");
                    return;
                }
                catch (InvalidGalleryFileNameException)
                {
                    db.RollBackTransaction();
                    core.Response.ShowMessage("error", "Submission failed", "Submission failed, try uploading with a different file name.");
                    return;
                }
            }
            catch (InvalidGalleryException)
            {
                db.RollBackTransaction();
                core.Response.ShowMessage("error", "Submission failed", "Submission failed, Invalid Gallery.");
                return;

            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Hook showing gallery items on a network profile.
        /// </summary>
        /// <param name="e">Hook event arguments</param>
        public void ShowNetworkGallery(HookEventArgs e)
        {
            Network theNetwork = (Network)e.Owner;

            Template template = new Template(Assembly.GetExecutingAssembly(), "viewprofilegallery");
            template.Medium = core.Template.Medium;
            template.SetProse(core.Prose);

            Gallery gallery = new Gallery(e.core, theNetwork);

            List<GalleryItem> galleryItems = gallery.GetItems(e.core, 1, 6, 0);

            template.Parse("PHOTOS", theNetwork.GalleryItems.ToString());

            foreach (GalleryItem galleryItem in galleryItems)
            {
                VariableCollection galleryVariableCollection = template.CreateChild("photo_list");

                galleryVariableCollection.Parse("TITLE", galleryItem.ItemTitle);
                galleryVariableCollection.Parse("PHOTO_URI", Gallery.BuildPhotoUri(core, theNetwork, galleryItem.Path));

                string thumbUri = string.Format("/network/{0}/images/_tiny/{1}",
                    theNetwork.NetworkNetwork, galleryItem.Path);
                galleryVariableCollection.Parse("THUMBNAIL", thumbUri);
            }

            template.Parse("U_NETWORK_GALLERY", Gallery.BuildGalleryUri(core, theNetwork));

            e.core.AddMainPanel(template);
        }
Ejemplo n.º 8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string comment;
            long itemId;
            long itemTypeId;
            ItemKey itemKey = null;
            ICommentableItem thisItem = null;
            long commentId = -1;
            bool isAjax = false;
            ApplicationEntry ae = null;

            if (Request["ajax"] == "true")
            {
                isAjax = true;
            }

            string mode = Request.QueryString["mode"];

            if (mode == "quote")
            {
                template.SetTemplate("posting.comment.html");

                try
                {
                    itemId = long.Parse((string)Request.QueryString["item"]);
                }
                catch
                {
                    core.Response.SendRawText("errorFetchingComment", "");
                    return;
                }

                DataTable commentsTable = db.Query(string.Format("SELECT ui.user_name, c.comment_text FROM comments c LEFT JOIN user_info ui ON c.user_id = ui.user_id WHERE comment_id = {0}",
                    itemId));

                if (commentsTable.Rows.Count == 1)
                {
                    string quotedComment = string.Format("\n\n[quote=\"{0}\"]{1}[/quote]",
                        (string)commentsTable.Rows[0]["user_name"], (string)commentsTable.Rows[0]["comment_text"]);

                    template.Parse("COMMENT_TEXT", quotedComment);
                }
                else
                {
                    core.Response.SendRawText("errorFetchingComment", "");
                }

                return;
            }

            if (mode == "fetch")
            {
                try
                {
                    itemId = long.Parse((string)Request.QueryString["item"]);
                }
                catch
                {
                    core.Response.SendRawText("errorFetchingComment", "");
                    return;
                }

                DataTable commentsTable = db.Query(string.Format("SELECT ui.user_name, c.comment_text FROM comments c LEFT JOIN user_info ui ON c.user_id = ui.user_id WHERE comment_id = {0}",
                    itemId));

                if (commentsTable.Rows.Count == 1)
                {
                    core.Response.SendRawText("commentFetched", (string.Format("\n\n[quote=\"{0}\"]{1}[/quote]",
                        (string)commentsTable.Rows[0]["user_name"], (string)commentsTable.Rows[0]["comment_text"])));
                }
                else
                {
                    core.Response.SendRawText("errorFetchingComment", "");
                }

                return;
            }

            if (mode == "load")
            {
                try
                {
                    itemId = long.Parse((string)core.Http.Query["item"]);
                    itemTypeId = long.Parse((string)core.Http.Query["type"]);
                }
                catch
                {
                    core.Response.SendRawText("errorFetchingComment", "");
                    return;
                }

                try
                {
                    // This isn't the most elegant fix, but it works
                    if (core.IsPrimitiveType(itemTypeId))
                    {
                        ae = core.GetApplication("GuestBook");
                    }
                    else
                    {
                        ItemType itemType = new ItemType(core, itemTypeId);
                        if (itemType.ApplicationId == 0)
                        {
                            ae = core.GetApplication("GuestBook");
                        }
                        else
                        {
                            ae = new ApplicationEntry(core, itemType.ApplicationId);
                        }
                    }

                    BoxSocial.Internals.Application.LoadApplication(core, AppPrimitives.Any, ae);
                }
                catch (InvalidApplicationException)
                {
                    core.Response.ShowMessage("invalidComment", "Invalid Comment", "The comments you have attempted to fetch are invalid. (0x01)");
                    return;
                }

                try
                {
                    thisItem = (ICommentableItem)NumberedItem.Reflect(core, new ItemKey(itemId, itemTypeId));
                }
                catch (Exception ex)
                {
                    // Only catch genuine InvalidItemException throws
                    if ((ex.GetType() == typeof(TargetInvocationException) && ex.InnerException.GetType().IsSubclassOf(typeof(InvalidItemException))) || ex.GetType().IsSubclassOf(typeof(InvalidItemException)))
                    {
                        core.Response.ShowMessage("invalidItem", "Item no longer exists", "Cannot load the comments as the item no longer exists.");
                    }
                    throw ex;
                }

                Template template = new Template("pane.comments.html");
                template.Medium = core.Template.Medium;
                template.SetProse(core.Prose);

                template.Parse("U_SIGNIN", Core.Hyperlink.BuildLoginUri());

                if (thisItem is IPermissibleItem)
                {
                    if (!((IPermissibleItem)thisItem).Access.Can("VIEW"))
                    {
                        core.Response.ShowMessage("accessDenied", "Access Denied", "The you do not have access to these comments");
                        return;
                    }

                    if (((IPermissibleItem)thisItem).Access.Can("COMMENT"))
                    {
                        template.Parse("CAN_COMMENT", "TRUE");
                    }
                }

                if (thisItem is IPermissibleSubItem)
                {
                    if (!((IPermissibleSubItem)thisItem).PermissiveParent.Access.Can("VIEW"))
                    {
                        core.Response.ShowMessage("accessDenied", "Access Denied", "The you do not have access to these comments");
                        return;
                    }

                    if (((IPermissibleSubItem)thisItem).PermissiveParent.Access.Can("COMMENT"))
                    {
                        template.Parse("CAN_COMMENT", "TRUE");
                    }
                }

                if (thisItem is ICommentableItem)
                {
                    core.Display.DisplayComments(template, ((ICommentableItem)thisItem).Owner, 1, (ICommentableItem)thisItem);
                    //List<Comment> comments = Comment.GetComments(core, new ItemKey(itemId, itemTypeId), SortOrder.Ascending, 1, 10, null);

                    core.Response.SendRawText("fetchSuccess", template.ToString());
                }
                else
                {
                    core.Response.ShowMessage("invalidComment", "Invalid Comment", "The comments you have attempted to fetch are invalid. (0x07)");
                }
                return;
            }

            if (mode == "report")
            {
                try
                {
                    itemId = long.Parse((string)Request.QueryString["item"]);
                }
                catch
                {
                    core.Response.ShowMessage("errorReportingComment", "Error", "The comment you have reported is invalid.");
                    return;
                }

                // only logged in members can report comment spam
                if (session.IsLoggedIn)
                {
                    // has the user reported the comment before?
                    DataTable reportsTable = db.Query(string.Format("SELECT report_id FROM spam_reports WHERE comment_id = {0} AND user_id = {1};",
                        itemId, loggedInMember.UserId));

                    if (reportsTable.Rows.Count == 0)
                    {
                        db.BeginTransaction();
                        db.UpdateQuery(string.Format("UPDATE comments SET comment_spam_score = comment_spam_score + 2 WHERE comment_id = {0}",
                            itemId));

                        // add a log entry that the user reported this comment
                        db.UpdateQuery(string.Format("INSERT INTO spam_reports (comment_id, user_id, report_time_ut) VALUES ({0}, {1}, UNIX_TIMESTAMP());",
                            itemId, loggedInMember.UserId));
                    }
                    else
                    {
                        core.Response.ShowMessage("alreadyReported", "Already Reported", "You have already reported this comment as SPAM.");
                    }
                }
                core.Response.ShowMessage("commentReported", "Reported Comment", "You have successfully reported a comment.");
                return;
            }

            if (mode == "delete")
            {
                // select the comment
                try
                {
                    Comment.Delete(core);
                }
                catch (InvalidCommentException)
                {
                    core.Response.ShowMessage("errorDeletingComment", "Error", "An error was encountered while deleting the comment, the comment has not been deleted.");
                }
                catch (PermissionDeniedException)
                {
                    core.Response.ShowMessage("permissionDenied", "Permission Denied", "You do not have the permissions to delete this comment.");
                }

                if (core.ResponseFormat == ResponseFormats.Xml)
                {
                    core.Response.SendRawText("commentDeleted", "You have successfully deleted the comment.");
                }
                else
                {
                    core.Response.ShowMessage("commentDeleted", "Comment Deleted", "You have successfully deleted the comment");
                }
                return;
            }

            // else we post a comment
            {
                try
                {
                    comment = (string)Request.Form["comment"];
                    itemId = core.Functions.RequestLong("item_id", 0);
                    itemTypeId = core.Functions.RequestLong("item_type_id", 0);
                    itemKey = new ItemKey(itemId, itemTypeId);
                }
                catch
                {
                    core.Response.ShowMessage("invalidComment", "Invalid Comment", "The comment you have attempted to post is invalid. (0x02)");
                    return;
                }

                if (itemId == 0 || itemTypeId == 0)
                {
                    core.Response.ShowMessage("invalidComment", "Invalid Comment", "The comment you have attempted to post is invalid. (0x08)");
                    return;
                }

                try
                {
                    // This isn't the most elegant fix, but it works
                    if (core.IsPrimitiveType(itemTypeId))
                    {
                        ae = core.GetApplication("GuestBook");
                    }
                    else
                    {
                        ItemType itemType = new ItemType(core, itemTypeId);
                        if (itemType.ApplicationId == 0)
                        {
                            ae = core.GetApplication("GuestBook");
                        }
                        else
                        {
                            ae = new ApplicationEntry(core, itemType.ApplicationId);
                        }
                    }

                    BoxSocial.Internals.Application.LoadApplication(core, AppPrimitives.Any, ae);
                }
                catch (InvalidApplicationException)
                {
                    core.Response.ShowMessage("invalidComment", "Invalid Comment", "The comment you have attempted to post is invalid. (0x03)");
                    return;
                }

                /* save comment in the database */

                NumberedItem item = null;
                try
                {
                    item = NumberedItem.Reflect(core, new ItemKey(itemId, itemTypeId));
                    if (item is ICommentableItem)
                    {
                        thisItem = (ICommentableItem)item;

                        IPermissibleItem pItem = null;
                        if (item is IPermissibleItem)
                        {
                            pItem = (IPermissibleItem)item;
                        }
                        else if (item is IPermissibleSubItem)
                        {
                            pItem = ((IPermissibleSubItem)item).PermissiveParent;
                        }
                        else
                        {
                            pItem = thisItem.Owner;
                        }

                        if (!pItem.Access.Can("COMMENT"))
                        {
                            core.Response.ShowMessage("notLoggedIn", "Permission Denied", "You do not have the permissions to post a comment to this item.");
                        }
                    }
                    else
                    {
                        core.Response.ShowMessage("invalidComment", "Invalid Item", "The comment you have attempted to post is invalid. (0x07)");
                    }
                }
                catch (InvalidItemException)
                {
                    core.Response.ShowMessage("invalidComment", "Invalid Comment", "The comment you have attempted to post is invalid. (0x04)");
                }

                Comment commentObject = null;
                try
                {
                    commentObject = Comment.Create(Core, itemKey, comment);
                    commentId = commentObject.CommentId;

                    if (item != null)
                    {
                        if (item is IActionableItem || item is IActionableSubItem)
                        {
                            //ae.TouchFeed(core.Session.LoggedInMember, item);
                        }
                        else
                        {
                            ae.PublishToFeed(core, core.Session.LoggedInMember, commentObject, item, Functions.SingleLine(core.Bbcode.Flatten(commentObject.Body)));
                        }
                        ICommentableItem citem = (ICommentableItem)item;

                        citem.CommentPosted(new CommentPostedEventArgs(commentObject, core.Session.LoggedInMember, new ItemKey(itemId, itemTypeId)));
                    }

                    Comment.Commented(core, itemKey);

                    // Notify everyone who comments on the item by default, track this so people can unsubscribe later
                    //NotificationSubscription.Create(core, loggedInMember, itemKey);
                    try
                    {
                        Subscription.SubscribeToItem(core, itemKey);
                    }
                    catch (AlreadySubscribedException)
                    {
                        // not a problem
                    }

                }
                catch (NotLoggedInException)
                {
                    core.Response.ShowMessage("notLoggedIn", "Not Logged In", "You must be logged in to post a comment.");
                }
                catch (CommentFloodException)
                {
                    core.Response.ShowMessage("rejectedByFloodControl", "Posting Too Fast", "You are posting too fast. Please wait a minute and try again.");
                }
                catch (CommentTooLongException)
                {
                    core.Response.ShowMessage("commentTooLong", "Comment Too Long", "The comment you have attempted to post is too long, maximum size is 511 characters.");
                }
                catch (CommentTooShortException)
                {
                    core.Response.ShowMessage("commentTooShort", "Comment Too Short", "The comment you have attempted to post is too short, must be longer than two characters.");
                }
                catch (InvalidCommentException)
                {
                    core.Response.ShowMessage("invalidComment", "Invalid Comment", "The comment you have attempted to post is invalid. (0x05)");
                }
                catch (Exception ex)
                {
                    core.Response.ShowMessage("invalidComment", "Invalid Comment", "The comment you have attempted to post is invalid. (0x06) " + ex.ToString());
                }

                if (core.ResponseFormat == ResponseFormats.Xml)
                {
                    Template ct = new Template(Server.MapPath("./templates"), "pane.comment.html");
                    template.Medium = core.Template.Medium;
                    ct.SetProse(core.Prose);

                    if (core.Session.IsLoggedIn && loggedInMember != null)
                    {
                        ct.Parse("LOGGED_IN", "TRUE");
                        ct.Parse("USER_DISPLAY_NAME", core.Session.LoggedInMember.DisplayName);
                        ct.Parse("USER_TILE", core.Session.LoggedInMember.Tile);
                        ct.Parse("USER_ICON", core.Session.LoggedInMember.Icon);
                    }

                    if (item != null)
                    {
                        template.Parse("ITEM_ID", item.Id.ToString());
                        template.Parse("ITEM_TYPE", item.ItemKey.TypeId.ToString());
                    }

                    VariableCollection commentsVariableCollection = ct.CreateChild("comment-list");

                    //commentsVariableCollection.ParseRaw("COMMENT", Bbcode.Parse(HttpUtility.HtmlEncode(comment), core.session.LoggedInMember));
                    core.Display.ParseBbcode(commentsVariableCollection, "COMMENT", comment);
                    // TODO: finish comments this
                    commentsVariableCollection.Parse("ID", commentId.ToString());
                    commentsVariableCollection.Parse("TYPE_ID", ItemKey.GetTypeId(core, typeof(Comment)));
                    commentsVariableCollection.Parse("USERNAME", loggedInMember.DisplayName);
                    commentsVariableCollection.Parse("USER_ID", loggedInMember.Id.ToString());
                    commentsVariableCollection.Parse("U_PROFILE", loggedInMember.ProfileUri);
                    commentsVariableCollection.Parse("U_QUOTE", core.Hyperlink.BuildCommentQuoteUri(commentId));
                    commentsVariableCollection.Parse("U_REPORT", core.Hyperlink.BuildCommentReportUri(commentId));
                    commentsVariableCollection.Parse("U_DELETE", core.Hyperlink.BuildCommentDeleteUri(commentId));
                    commentsVariableCollection.Parse("TIME", tz.DateTimeToString(tz.Now));
                    commentsVariableCollection.Parse("USER_TILE", loggedInMember.Tile);
                    commentsVariableCollection.Parse("USER_ICON", loggedInMember.Icon);

                    try
                    {
                        if (core.Session.IsLoggedIn)
                        {
                            if (thisItem.Owner.CanModerateComments(loggedInMember))
                            {
                                commentsVariableCollection.Parse("MODERATE", "TRUE");
                            }

                            if (thisItem.Owner.IsItemOwner(loggedInMember))
                            {
                                commentsVariableCollection.Parse("OWNER", "TRUE");
                                commentsVariableCollection.Parse("NORMAL", "FALSE");
                            }
                            else
                            {
                                commentsVariableCollection.Parse("OWNER", "FALSE");
                                commentsVariableCollection.Parse("NORMAL", "TRUE");
                            }
                        }
                        else
                        {
                            commentsVariableCollection.Parse("OWNER", "FALSE");
                            commentsVariableCollection.Parse("NORMAL", "TRUE");
                        }
                    }
                    catch (Exception ex)
                    {
                        commentsVariableCollection.Parse("NORMAL", "FALSE");
                    }

                    core.Response.SendRawText("comment", ct.ToString());

                    if (db != null)
                    {
                        db.CloseConnection();
                    }
                    Response.End();
                    return;
                }
                else
                {
                    string redirect = Request["redirect"];
                    if (!string.IsNullOrEmpty(redirect))
                    {
                        template.Parse("REDIRECT_URI", redirect);
                    }
                    core.Display.ShowMessage("Comment Posted", "Your comment has been successfully posted.");
                }
            }
        }
Ejemplo n.º 9
0
        public Template RenderPreview()
        {
            Template template = new Template(Assembly.GetExecutingAssembly(), "search_result_galleryitem");
            template.Medium = core.Template.Medium;
            template.SetProse(core.Prose);

            VariableCollection statusMessageVariableCollection = template.CreateChild("status_messages");

            //statusMessageVariableCollection.Parse("STATUS_MESSAGE", item.Message);
            core.Display.ParseBbcode(statusMessageVariableCollection, "STATUS_MESSAGE", core.Bbcode.FromStatusCode(GetActionBody(new List<ItemKey>())), owner, true, string.Empty, string.Empty);
            statusMessageVariableCollection.Parse("STATUS_UPDATED", core.Tz.DateTimeToString(GetCreatedDate(core.Tz)));

            statusMessageVariableCollection.Parse("ID", Id.ToString());
            statusMessageVariableCollection.Parse("TYPE_ID", ItemKey.TypeId.ToString());
            statusMessageVariableCollection.Parse("USERNAME", Owner.DisplayName);
            statusMessageVariableCollection.Parse("USER_ID", Owner.Id);
            statusMessageVariableCollection.Parse("U_PROFILE", Owner.Uri); // TODO: ProfileUri for primitive
            statusMessageVariableCollection.Parse("U_PERMISSIONS", Parent.Access.AclUri);
            statusMessageVariableCollection.Parse("USER_TILE", Owner.Tile);
            statusMessageVariableCollection.Parse("USER_ICON", Owner.Icon);
            statusMessageVariableCollection.Parse("URI", Uri);

            if (core.Session.IsLoggedIn)
            {
                if (Owner is User && Owner.Id == core.Session.LoggedInMember.Id)
                {
                    statusMessageVariableCollection.Parse("IS_OWNER", "TRUE");
                }
            }

            if (Info.Likes > 0)
            {
                statusMessageVariableCollection.Parse("LIKES", string.Format(" {0:d}", Info.Likes));
                statusMessageVariableCollection.Parse("DISLIKES", string.Format(" {0:d}", Info.Dislikes));
            }

            if (Info.Comments > 0)
            {
                statusMessageVariableCollection.Parse("COMMENTS", string.Format(" ({0:d})", Info.Comments));
            }

            return template;
        }
Ejemplo n.º 10
0
        protected void Page_Load(object sender, EventArgs e)
        {
            bool isAjax = false;
            long itemId;
            long itemTypeId;
            ItemKey itemKey = null;
            IShareableItem item = null;

            if (Request["ajax"] == "true")
            {
                isAjax = true;
            }

            if (!core.Session.IsLoggedIn)
            {
                core.Response.ShowMessage("notLoggedIn", "Not Logged In", "Sign in to share this item.");
            }

            string mode = Request.QueryString["mode"];

            if (mode == "post")
            {
                template.SetTemplate("pane.share.post.html");

                try
                {
                    itemId = long.Parse((string)core.Http.Query["item"]);
                    itemTypeId = long.Parse((string)core.Http.Query["type"]);

                    itemKey = new ItemKey(itemId, itemTypeId);
                    item = (IShareableItem)NumberedItem.Reflect(core, itemKey);

                    TextBox messageTextBox = new TextBox("share-message");
                    PermissionGroupSelectBox permissionSelectBox = new PermissionGroupSelectBox(core, "share-permissions", core.Session.LoggedInMember.ItemKey);

                    template.Parse("S_SHARE_MESSAGE", messageTextBox);
                    template.Parse("S_SHARE_PERMISSIONS", permissionSelectBox);
                    template.Parse("S_SHARED_URI", item.Info.ShareUri);
                    core.Display.ParseBbcode(template, "S_SHARED_STRING", core.Functions.Tldr("[share=\"[iurl=\"" + item.Uri + "\"]" + item.Owner.DisplayName + "[/iurl]\"]" + item.ShareString + "[/share]"), item.Owner);
                }
                catch
                {
                    core.Response.SendRawText("errorFetchingItem", "");
                    return;
                }

                core.Response.SendRawText("sharingForm", template.ToString());
                return;
            }

            // Save the Share
            try
            {
                itemId = long.Parse((string)core.Http.Form["item"]);
                itemTypeId = long.Parse((string)core.Http.Form["type"]);
            }
            catch
            {
                core.Response.SendRawText("errorFetchingItem", "");
                return;
            }

            itemKey = new ItemKey(itemId, itemTypeId);
            item = (IShareableItem)NumberedItem.Reflect(core, itemKey);

            if (item is IPermissibleItem)
            {
                IPermissibleItem pitem = (IPermissibleItem)item;

                if (!pitem.Access.IsPublic())
                {
                    core.Response.ShowMessage("cannotShare", "Cannot Share", "You can only share public items.");
                    return;
                }
            }

            string message = (string)core.Http.Form["share-message"] + "\n\n" + core.Functions.Tldr("[share=\"[iurl=\"" + item.Uri + "\"]" + item.Owner.DisplayName + "[/iurl]\"]" + item.ShareString + "[/share]");

            StatusMessage newStatus = StatusMessage.Create(core, core.Session.LoggedInMember, message);

            AccessControlLists acl = new AccessControlLists(core, newStatus);
            acl.SaveNewItemPermissions("share-permissions");

            core.Search.Index(newStatus);

            ApplicationEntry ae = core.GetApplication("Profile");
            ae.PublishToFeed(core, core.Session.LoggedInMember, newStatus, Functions.SingleLine(core.Bbcode.Flatten(newStatus.Message)));

            Share.ShareItem(core, itemKey);

            if (Request.Form["ajax"] == "true")
            {
                Template template = new Template("pane.statusmessage.html");
                template.Medium = core.Template.Medium;
                template.SetProse(core.Prose);

                VariableCollection statusMessageVariableCollection = template.CreateChild("status_messages");

                core.Display.ParseBbcode(statusMessageVariableCollection, "STATUS_MESSAGE", core.Bbcode.FromStatusCode(newStatus.Message), core.Session.LoggedInMember, true, string.Empty, string.Empty);
                statusMessageVariableCollection.Parse("STATUS_UPDATED", core.Tz.DateTimeToString(newStatus.GetTime(core.Tz)));

                statusMessageVariableCollection.Parse("ID", newStatus.Id.ToString());
                statusMessageVariableCollection.Parse("TYPE_ID", newStatus.ItemKey.TypeId.ToString());
                statusMessageVariableCollection.Parse("USERNAME", newStatus.Poster.DisplayName);
                statusMessageVariableCollection.Parse("U_PROFILE", newStatus.Poster.ProfileUri);
                statusMessageVariableCollection.Parse("U_QUOTE", string.Empty /*core.Hyperlink.BuildCommentQuoteUri(newStatus.Id)*/);
                statusMessageVariableCollection.Parse("U_REPORT", string.Empty /*core.Hyperlink.BuildCommentReportUri(newStatus.Id)*/);
                statusMessageVariableCollection.Parse("U_DELETE", string.Empty /*core.Hyperlink.BuildCommentDeleteUri(newStatus.Id)*/);
                statusMessageVariableCollection.Parse("U_PERMISSIONS", newStatus.Access.AclUri);
                statusMessageVariableCollection.Parse("USER_TILE", newStatus.Poster.Tile);
                statusMessageVariableCollection.Parse("USER_ICON", newStatus.Poster.Icon);
                statusMessageVariableCollection.Parse("URI", newStatus.Uri);

                statusMessageVariableCollection.Parse("IS_OWNER", "TRUE");

                if (newStatus.Access.IsPublic())
                {
                    statusMessageVariableCollection.Parse("IS_PUBLIC", "TRUE");
                    statusMessageVariableCollection.Parse("SHAREABLE", "TRUE");
                    statusMessageVariableCollection.Parse("U_SHARE", newStatus.ShareUri);
                }

                Dictionary<string, string> returnValues = new Dictionary<string, string>(StringComparer.Ordinal);

                returnValues.Add("update", item.OwnerKey.Equals(newStatus.Owner.ItemKey) ? "true" : "false");
                returnValues.Add("message", message);
                returnValues.Add("template", template.ToString());

                core.Response.SendDictionary("statusPosted", returnValues);
                return;
            }
            else
            {
                string redirect = Request["redirect"];
                if (!string.IsNullOrEmpty(redirect))
                {
                    template.Parse("REDIRECT_URI", redirect);
                }
                core.Display.ShowMessage("Shared", "You have shared this item to your status feed.");
            }
        }
Ejemplo n.º 11
0
        void ShowFriends(HookEventArgs e)
        {
            Template template = new Template(Assembly.GetExecutingAssembly(), "todayfriendpanel");
            template.Medium = core.Template.Medium;
            template.SetProse(core.Prose);

            List<Friend> friends = e.core.Session.LoggedInMember.GetFriends(1, 10, true);

            foreach (UserRelation friend in friends)
            {
                VariableCollection friendVariableCollection = template.CreateChild("friend_list");

                friendVariableCollection.Parse("USER_DISPLAY_NAME", friend.DisplayName);
                friendVariableCollection.Parse("U_PROFILE", friend.Uri);
                friendVariableCollection.Parse("ICON", friend.Icon);
                friendVariableCollection.Parse("TILE", friend.Tile);
                friendVariableCollection.Parse("SQUARE", friend.Square);
                friendVariableCollection.Parse("SUBSCRIBERS", friend.Info.Subscribers);
                friendVariableCollection.Parse("IS_ONLINE", friend.IsOnline ? "TRUE" : "FALSE");
            }

            e.core.AddSidePanel(template);
        }
Ejemplo n.º 12
0
        public static void ShowMore(object sender, ShowPPageEventArgs e)
        {
            char[] trimStartChars = { '.', '/' };

            string galleryPath = e.Slug;

            if (galleryPath != null)
            {
                galleryPath = galleryPath.TrimEnd('/').TrimStart(trimStartChars);
            }
            else
            {
                galleryPath = "";
            }

            Gallery gallery;
            if (galleryPath != "")
            {
                try
                {
                    gallery = new Gallery(e.Core, e.Page.Owner, galleryPath);

                    if (!gallery.Access.Can("VIEW"))
                    {
                        e.Core.Functions.Generate403();
                        return;
                    }
                }
                catch (InvalidGalleryException)
                {
                    return;
                }
            }
            else
            {
                gallery = new Gallery(e.Core, e.Page.Owner);
            }

            Template template = new Template(Assembly.GetExecutingAssembly(), "pane_photo");
            template.Medium = e.Core.Template.Medium;
            template.SetProse(e.Core.Prose);

            bool moreContent = false;
            long lastId = 0;

            List<GalleryItem> galleryItems = gallery.GetItems(e.Core, e.Page.TopLevelPageNumber, 12, e.Page.TopLevelPageOffset);

            int i = 0;
            foreach (GalleryItem galleryItem in galleryItems)
            {
                VariableCollection galleryVariableCollection = template.CreateChild("photo_list");

                galleryVariableCollection.Parse("TITLE", galleryItem.ItemTitle);
                galleryVariableCollection.Parse("PHOTO_URI", Gallery.BuildPhotoUri(e.Core, e.Page.Owner, galleryItem.ParentPath, galleryItem.Path));
                galleryVariableCollection.Parse("COMMENTS", e.Core.Functions.LargeIntegerToString(galleryItem.Comments));
                galleryVariableCollection.Parse("VIEWS", e.Core.Functions.LargeIntegerToString(galleryItem.ItemViews));
                galleryVariableCollection.Parse("INDEX", i.ToString());
                galleryVariableCollection.Parse("ID", galleryItem.Id.ToString());
                galleryVariableCollection.Parse("TYPE_ID", galleryItem.ItemKey.TypeId.ToString());

                galleryVariableCollection.Parse("ICON", galleryItem.IconUri);
                galleryVariableCollection.Parse("TILE", galleryItem.TileUri);
                galleryVariableCollection.Parse("SQUARE", galleryItem.SquareUri);

                galleryVariableCollection.Parse("TINY", galleryItem.TinyUri);
                galleryVariableCollection.Parse("THUMBNAIL", galleryItem.ThumbnailUri);

                Display.RatingBlock(galleryItem.ItemRating, galleryVariableCollection, galleryItem.ItemKey);

                if (galleryItem.Info.Likes > 0)
                {
                    galleryVariableCollection.Parse("LIKES", string.Format(" {0:d}", galleryItem.Info.Likes));
                    galleryVariableCollection.Parse("DISLIKES", string.Format(" {0:d}", galleryItem.Info.Dislikes));
                }

                switch (i % 3)
                {
                    case 0:
                        galleryVariableCollection.Parse("ABC", "a");
                        break;
                    case 1:
                        galleryVariableCollection.Parse("ABC", "b");
                        break;
                    case 2:
                        galleryVariableCollection.Parse("ABC", "c");
                        break;
                }

                switch (i % 4)
                {
                    case 0:
                        galleryVariableCollection.Parse("ABCD", "a");
                        break;
                    case 1:
                        galleryVariableCollection.Parse("ABCD", "b");
                        break;
                    case 2:
                        galleryVariableCollection.Parse("ABCD", "c");
                        break;
                    case 3:
                        galleryVariableCollection.Parse("ABCD", "d");
                        break;
                }

                lastId = galleryItem.Id;
                i++;
            }

            if (e.Core.TopLevelPageNumber * 12 < gallery.Items)
            {
                moreContent = true;
            }

            string loadMoreUri = Gallery.BuildGalleryUri(e.Core, e.Page.Owner, galleryPath) + "?p=" + (e.Core.TopLevelPageNumber + 1) + "&o=" + lastId;
            e.Core.Response.SendRawText(moreContent ? loadMoreUri : "noMoreContent", template.ToString());
        }
Ejemplo n.º 13
0
        private void CheckNewFeedItems()
        {
            string mode = core.Http["mode"];
            long newestId = core.Functions.RequestLong("newest-id", 0);
            long newerId = 0;

            if (!core.Session.IsLoggedIn)
            {
                Dictionary<string, string> returnValues = new Dictionary<string, string>();
                core.Response.SendDictionary("noNewContent", returnValues);
            }

            if (mode == "query")
            {
                int count = Feed.GetNewerItemCount(core, core.Session.LoggedInMember, newestId);

                Dictionary<string, string> returnValues = new Dictionary<string, string>();

                returnValues.Add("notifications", session.LoggedInMember.UserInfo.UnreadNotifications.ToString());
                returnValues.Add("mail", session.LoggedInMember.UserInfo.UnseenMail.ToString());

                if (count > 0)
                {
                    returnValues.Add("feed-count", count.ToString());

                    core.Response.SendDictionary("newContent", returnValues);
                }
                else
                {
                    core.Response.SendDictionary("noNewContent", returnValues);
                }
            }
            else if (mode == "fetch")
            {
                List<BoxSocial.Internals.Action> feedActions = Feed.GetNewerItems(core, core.Session.LoggedInMember, newestId);

                Template template = new Template("pane.feeditem.html");
                template.Medium = core.Template.Medium;
                template.SetProse(core.Prose);

                foreach (BoxSocial.Internals.Action feedAction in feedActions)
                {
                    VariableCollection feedItemVariableCollection = template.CreateChild("feed_days_list.feed_item");

                    if (feedAction.Id > newerId)
                    {
                        newerId = feedAction.Id;
                    }

                    core.Display.ParseBbcode(feedItemVariableCollection, "TITLE", feedAction.FormattedTitle);
                    core.Display.ParseBbcode(feedItemVariableCollection, "TEXT", feedAction.Body, core.PrimitiveCache[feedAction.OwnerId], true, string.Empty, string.Empty);

                    feedItemVariableCollection.Parse("USER_DISPLAY_NAME", feedAction.Owner.DisplayName);

                    feedItemVariableCollection.Parse("ID", feedAction.ActionItemKey.Id);
                    feedItemVariableCollection.Parse("TYPE_ID", feedAction.ActionItemKey.TypeId);

                    if (feedAction.ActionItemKey.GetType(core).Likeable)
                    {
                        feedItemVariableCollection.Parse("LIKEABLE", "TRUE");

                        if (feedAction.Info.Likes > 0)
                        {
                            feedItemVariableCollection.Parse("LIKES", string.Format(" {0:d}", feedAction.Info.Likes));
                            feedItemVariableCollection.Parse("DISLIKES", string.Format(" {0:d}", feedAction.Info.Dislikes));
                        }
                    }

                    if (feedAction.ActionItemKey.GetType(core).Commentable)
                    {
                        feedItemVariableCollection.Parse("COMMENTABLE", "TRUE");

                        if (feedAction.Info.Comments > 0)
                        {
                            feedItemVariableCollection.Parse("COMMENTS", string.Format(" ({0:d})", feedAction.Info.Comments));
                        }
                    }

                    //Access access = new Access(core, feedAction.ActionItemKey, true);
                    if (feedAction.PermissiveParent.Access.IsPublic())
                    {
                        feedItemVariableCollection.Parse("IS_PUBLIC", "TRUE");
                        if (feedAction.ActionItemKey.GetType(core).Shareable)
                        {
                            feedItemVariableCollection.Parse("SHAREABLE", "TRUE");
                            //feedItemVariableCollection.Parse("U_SHARE", feedAction.ShareUri);

                            if (feedAction.Info.SharedTimes > 0)
                            {
                                feedItemVariableCollection.Parse("SHARES", string.Format(" {0:d}", feedAction.Info.SharedTimes));
                            }
                        }
                    }

                    if (feedAction.Owner is User)
                    {
                        feedItemVariableCollection.Parse("USER_TILE", ((User)feedAction.Owner).Tile);
                        feedItemVariableCollection.Parse("USER_ICON", ((User)feedAction.Owner).Icon);
                    }
                }

                // Check for new messages and upload
                Dictionary<string, string> returnValues = new Dictionary<string, string>();

                returnValues.Add("update", "true");
                returnValues.Add("template", template.ToString());
                returnValues.Add("newest-id", newerId.ToString());

                returnValues.Add("notifications", session.LoggedInMember.UserInfo.UnreadNotifications.ToString());
                returnValues.Add("mail", session.LoggedInMember.UserInfo.UnseenMail.ToString());

                core.Response.SendDictionary("newFeedItems", returnValues);
            }
            else
            {
                Dictionary<string, string> returnValues = new Dictionary<string, string>();

                returnValues.Add("notifications", session.LoggedInMember.UserInfo.UnreadNotifications.ToString());
                returnValues.Add("mail", session.LoggedInMember.UserInfo.UnseenMail.ToString());

                core.Response.SendDictionary("unreadItems", returnValues);
            }
        }
Ejemplo n.º 14
0
        public void ShowMemberGroups(HookEventArgs e)
        {
            User profileOwner = (User)e.Owner;
            Template template = new Template(Assembly.GetExecutingAssembly(), "viewprofilegroups");
            template.Medium = core.Template.Medium;
            template.SetProse(core.Prose);

            List<UserGroup> groups = UserGroup.GetUserGroups(e.core, profileOwner, 1, 4);
            if (groups.Count > 0)
            {
                template.Parse("HAS_GROUPS", "TRUE");
            }

            foreach(UserGroup group in groups)
            {
                VariableCollection groupVariableCollection = template.CreateChild("groups_list");

                groupVariableCollection.Parse("TITLE", group.DisplayName);
                groupVariableCollection.Parse("U_GROUP", group.Uri);
                groupVariableCollection.Parse("ICON", group.Icon);
                groupVariableCollection.Parse("TILE", group.Tile);
                groupVariableCollection.Parse("SQUARE", group.Square);
            }

            e.core.AddSidePanel(template);
        }
Ejemplo n.º 15
0
        void ShowToday(HookEventArgs e)
        {
            Template template = new Template(Assembly.GetExecutingAssembly(), "todayupcommingevents");
            template.Medium = core.Template.Medium;
            template.SetProse(core.Prose);

            long startTime = e.core.Tz.GetUnixTimeStamp(new DateTime(e.core.Tz.Now.Year, e.core.Tz.Now.Month, e.core.Tz.Now.Day, 0, 0, 0));
            long endTime = startTime + 60 * 60 * 24 * 7; // skip ahead one week into the future

            Calendar cal = null;
            try
            {
                cal = new Calendar(core, core.Session.LoggedInMember);
            }
            catch (InvalidCalendarException)
            {
                cal = Calendar.Create(core, core.Session.LoggedInMember);
            }

            List<Event> events = cal.GetEvents(core, e.core.Session.LoggedInMember, startTime, endTime);

            template.Parse("U_NEW_EVENT", core.Hyperlink.AppendSid(string.Format("{0}calendar/new-event",
                e.core.Session.LoggedInMember.AccountUriStub)));

            template.Parse("U_CALENDAR", core.Hyperlink.AppendSid(string.Format("{0}calendar",
                e.core.Session.LoggedInMember.UriStub)));

            VariableCollection appointmentDaysVariableCollection = null;
            DateTime lastDay = e.core.Tz.Now;

            if (events.Count > 0)
            {
                template.Parse("HAS_EVENTS", "TRUE");
            }

            foreach(Event calendarEvent in events)
            {
                DateTime eventDay = calendarEvent.GetStartTime(e.core.Tz);
                DateTime eventEnd = calendarEvent.GetEndTime(e.core.Tz);

                if (appointmentDaysVariableCollection == null || lastDay.Day != eventDay.Day)
                {
                    lastDay = eventDay;
                    appointmentDaysVariableCollection = template.CreateChild("appointment_days_list");

                    appointmentDaysVariableCollection.Parse("DAY", core.Tz.DateTimeToDateString(eventDay));
                }

                VariableCollection appointmentVariableCollection = appointmentDaysVariableCollection.CreateChild("appointments_list");

                appointmentVariableCollection.Parse("TIME", eventDay.ToShortTimeString() + " - " + eventEnd.ToShortTimeString());
                appointmentVariableCollection.Parse("SUBJECT", calendarEvent.Subject);
                appointmentVariableCollection.Parse("LOCATION", calendarEvent.Location);
                appointmentVariableCollection.Parse("URI", Event.BuildEventUri(core, calendarEvent));
            }

            e.core.AddMainPanel(template);

            //
            // Tasks panel
            //

            template = new Template(Assembly.GetExecutingAssembly(), "todaytaskspanel");
            template.SetProse(core.Prose);
            List<Task> tasks = cal.GetTasks(core, e.core.Session.LoggedInMember, startTime, endTime, true);

            VariableCollection taskDaysVariableCollection = null;
            lastDay = e.core.Tz.Now;

            if (tasks.Count > 0)
            {
                template.Parse("HAS_TASKS", "TRUE");
            }

            template.Parse("U_TASKS", Task.BuildTasksUri(e.core, e.core.Session.LoggedInMember));

            foreach (Task calendarTask in tasks)
            {
                DateTime taskDue = calendarTask.GetDueTime(e.core.Tz);

                if (taskDaysVariableCollection == null || lastDay.Day != taskDue.Day)
                {
                    lastDay = taskDue;
                    taskDaysVariableCollection = template.CreateChild("task_days");

                    taskDaysVariableCollection.Parse("DAY", taskDue.DayOfWeek.ToString());
                }

                VariableCollection taskVariableCollection = taskDaysVariableCollection.CreateChild("task_list");

                taskVariableCollection.Parse("DATE", taskDue.ToShortDateString() + " (" + taskDue.ToShortTimeString() + ")");
                taskVariableCollection.Parse("TOPIC", calendarTask.Topic);
                taskVariableCollection.Parse("ID", calendarTask.Id.ToString());
                taskVariableCollection.Parse("URI", Task.BuildTaskUri(core, calendarTask));
                taskVariableCollection.Parse("U_MARK_COMPLETE", Task.BuildTaskMarkCompleteUri(core, calendarTask));

                if (calendarTask.Status == TaskStatus.Overdue)
                {
                    taskVariableCollection.Parse("OVERDUE", "TRUE");
                    taskVariableCollection.Parse("CLASS", "overdue-task");
                }
                else if (calendarTask.Status == TaskStatus.Completed)
                {
                    taskVariableCollection.Parse("COMPLETE", "TRUE");
                    taskVariableCollection.Parse("CLASS", "complete-task");
                }
                else
                {
                    taskVariableCollection.Parse("CLASS", "task");
                }

                if (calendarTask.Priority == TaskPriority.High)
                {
                    taskDaysVariableCollection.Parse("HIGH_PRIORITY", "TRUE");
                }
                else if (calendarTask.Priority == TaskPriority.Low)
                {
                    taskDaysVariableCollection.Parse("LOW_PRIORITY", "TRUE");
                }
            }

            e.core.AddSidePanel(template);
        }
Ejemplo n.º 16
0
        void ShowGroups(HookEventArgs e)
        {
            Template template = new Template(Assembly.GetExecutingAssembly(), "todaygrouppanel");
            template.Medium = core.Template.Medium;
            template.SetProse(core.Prose);

            List<UserGroup> groups = UserGroup.GetUserGroups(e.core, e.core.Session.LoggedInMember, 1, 4);

            foreach (UserGroup group in groups)
            {
                VariableCollection groupVariableCollection = template.CreateChild("groups_list");

                groupVariableCollection.Parse("TITLE", group.DisplayName);
                groupVariableCollection.Parse("MEMBERS", core.Functions.LargeIntegerToString(group.Members));
                groupVariableCollection.Parse("U_GROUP", group.Uri);
                groupVariableCollection.Parse("ICON", group.Icon);
                groupVariableCollection.Parse("TILE", group.Tile);
                groupVariableCollection.Parse("SQUARE", group.Square);
            }

            e.core.AddSidePanel(template);
        }
Ejemplo n.º 17
0
        public static void ShowMore(Core core, ShowUPageEventArgs e)
        {
            if (core == null)
            {
                throw new NullCoreException();
            }

            if (!e.Page.Owner.Access.Can("VIEW"))
            {
                core.Functions.Generate403();
                return;
            }

            Template template = new Template("pane.statusmessage.html");
            template.Medium = core.Template.Medium;
            template.SetProse(core.Prose);

            bool moreContent = false;
            long lastId = 0;
            List<StatusMessage> items = StatusFeed.GetItems(core, (User)e.Page.Owner, e.Page.TopLevelPageNumber, 20, e.Page.TopLevelPageOffset, out moreContent);

            foreach (StatusMessage item in items)
            {
                VariableCollection statusMessageVariableCollection = template.CreateChild("status_messages");

                core.Display.ParseBbcode(statusMessageVariableCollection, "STATUS_MESSAGE", core.Bbcode.FromStatusCode(item.Message), e.Page.Owner, true, string.Empty, string.Empty);
                statusMessageVariableCollection.Parse("STATUS_UPDATED", core.Tz.DateTimeToString(item.GetTime(core.Tz)));

                statusMessageVariableCollection.Parse("ID", item.Id.ToString());
                statusMessageVariableCollection.Parse("TYPE_ID", item.ItemKey.TypeId.ToString());
                statusMessageVariableCollection.Parse("USERNAME", item.Poster.DisplayName);
                statusMessageVariableCollection.Parse("USER_ID", item.Poster.Id);
                statusMessageVariableCollection.Parse("U_PROFILE", item.Poster.ProfileUri);
                statusMessageVariableCollection.Parse("U_QUOTE", string.Empty /*core.Hyperlink.BuildCommentQuoteUri(item.Id)*/);
                statusMessageVariableCollection.Parse("U_REPORT", string.Empty /*core.Hyperlink.BuildCommentReportUri(item.Id)*/);
                statusMessageVariableCollection.Parse("U_DELETE", string.Empty /*core.Hyperlink.BuildCommentDeleteUri(item.Id)*/);
                statusMessageVariableCollection.Parse("U_PERMISSIONS", item.Access.AclUri);
                statusMessageVariableCollection.Parse("USER_TILE", item.Poster.Tile);
                statusMessageVariableCollection.Parse("USER_ICON", item.Poster.Icon);
                statusMessageVariableCollection.Parse("URI", item.Uri);

                if (core.Session.IsLoggedIn)
                {
                    if (item.Owner.Id == core.Session.LoggedInMember.Id)
                    {
                        statusMessageVariableCollection.Parse("IS_OWNER", "TRUE");
                    }
                }

                if (item.Info.Likes > 0)
                {
                    statusMessageVariableCollection.Parse("LIKES", string.Format(" {0:d}", item.Info.Likes));
                    statusMessageVariableCollection.Parse("DISLIKES", string.Format(" {0:d}", item.Info.Dislikes));
                }

                if (item.Info.Comments > 0)
                {
                    statusMessageVariableCollection.Parse("COMMENTS", string.Format(" ({0:d})", item.Info.Comments));
                }

                if (item.Access.IsPublic())
                {
                    statusMessageVariableCollection.Parse("IS_PUBLIC", "TRUE");
                    if (item.ItemKey.GetType(core).Shareable)
                    {
                        statusMessageVariableCollection.Parse("SHAREABLE", "TRUE");
                        statusMessageVariableCollection.Parse("U_SHARE", item.ShareUri);

                        if (item.Info.SharedTimes > 0)
                        {
                            statusMessageVariableCollection.Parse("SHARES", string.Format(" {0:d}", item.Info.SharedTimes));
                        }
                    }
                }
                lastId = item.Id;
            }

            string loadMoreUri = core.Hyperlink.BuildStatusUri((User)e.Page.Owner) + "?p=" + (core.TopLevelPageNumber + 1) + "&o=" + lastId;
            core.Response.SendRawText(moreContent ? loadMoreUri : "noMoreContent", template.ToString());
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Hook showing gallery items on a group profile.
        /// </summary>
        /// <param name="e">Hook event arguments</param>
        public void ShowGroupGallery(HookEventArgs e)
        {
            UserGroup thisGroup = (UserGroup)e.Owner;

            if (!(!thisGroup.IsGroupMember(e.core.LoggedInMemberItemKey) && thisGroup.GroupType == "CLOSED"))
            {
                Template template = new Template(Assembly.GetExecutingAssembly(), "viewprofilegallery");
                template.Medium = core.Template.Medium;
                template.SetProse(core.Prose);

                // show recent photographs in the gallery
                Gallery gallery = new Gallery(e.core, thisGroup);

                List<GalleryItem> galleryItems = gallery.GetItems(e.core, 1, 6, 0);

                template.Parse("PHOTOS", thisGroup.GalleryItems.ToString());

                foreach (GalleryItem galleryItem in galleryItems)
                {
                    VariableCollection galleryVariableCollection = template.CreateChild("photo_list");

                    galleryVariableCollection.Parse("TITLE", galleryItem.ItemTitle);
                    galleryVariableCollection.Parse("PHOTO_URI", galleryItem.Uri);

                    galleryVariableCollection.Parse("THUMBNAIL", galleryItem.ThumbnailUri);
                }

                template.Parse("U_GROUP_GALLERY", Gallery.BuildGalleryUri(core, thisGroup));

                e.core.AddMainPanel(template);
            }
        }
Ejemplo n.º 19
0
        public void DisplayComments(Template template, Primitive owner, ICommentableItem item, List<User> commenters, int page, long commentCount, DisplayCommentHookHandler hook)
        {
            Mysql db = core.Db;

            long c = core.Functions.RequestLong("c", 0);

            if (c > 0)
            {
                SelectQuery query = new SelectQuery("comments");
                query.AddFields("COUNT(*) AS total");
                query.AddCondition("comment_item_id", item.Id);
                query.AddCondition("comment_item_type_id", item.ItemKey.TypeId);
                query.AddCondition("comment_id", ConditionEquality.LessThanEqual, c);

                if (commenters != null)
                {
                    if (commenters.Count == 2)
                    {
                        if (item.Namespace == "USER")
                        {
                            QueryCondition qc1 = query.AddCondition("c.comment_item_id", commenters[0].Id);
                            qc1.AddCondition("user_id", commenters[1].Id);

                            QueryCondition qc2 = query.AddCondition(ConditionRelations.Or, "c.comment_item_id", commenters[1].Id);
                            qc2.AddCondition("user_id", commenters[0].Id);

                            query.AddCondition("c.comment_item_type_id", item.ItemKey.TypeId);
                        }
                        else
                        {
                            query.AddCondition("comment_item_id", item.Id);
                            query.AddCondition("comment_item_type_id", item.ItemKey.TypeId);
                        }
                    }
                    else
                    {
                        query.AddCondition("comment_item_id", item.Id);
                        query.AddCondition("comment_item_type_id", item.ItemKey.TypeId);
                    }
                }
                else
                {
                    query.AddCondition("comment_item_id", item.Id);
                    query.AddCondition("comment_item_type_id", item.ItemKey.TypeId);
                }

                query.AddSort(SortOrder.Ascending, "comment_time_ut");

                DataRow commentsRow = db.Query(query).Rows[0];

                long before = (long)commentsRow["total"];
                long after = item.Comments - before - 1;

                if (item.CommentSortOrder == SortOrder.Ascending)
                {
                    page = (int)(before / item.CommentsPerPage + 1);
                }
                else
                {
                    page = (int)(after / item.CommentsPerPage + 1);
                }
            }

            if (core.Session.IsLoggedIn && core.Session.LoggedInMember != null)
            {
                template.Parse("LOGGED_IN", "TRUE");
                template.Parse("LOGGED_IN_USER_DISPLAY_NAME", core.Session.LoggedInMember.DisplayName);
                template.Parse("LOGGED_IN_USER_ICON", core.Session.LoggedInMember.Icon);
                template.Parse("LOGGED_IN_USER_TILE", core.Session.LoggedInMember.Tile);
                template.Parse("LOGGED_IN_USER_SQUARE", core.Session.LoggedInMember.Square);
            }

            List<Comment> comments = Comment.GetComments(core, item.ItemKey, item.CommentSortOrder, page, item.CommentsPerPage, commenters);
            Comment.LoadUserInfoCache(core, comments);

            if (commentCount >= 0)
            {
                template.Parse("COMMENTS", commentCount.ToString());
            }
            else if (((NumberedItem)item).Info.Comments >= 0)
            {
                template.Parse("COMMENTS", ((NumberedItem)item).Info.Comments.ToString());
            }
            else
            {
                template.Parse("COMMENTS", comments.Count.ToString());
            }

            template.Parse("ITEM_ID", item.Id.ToString());
            template.Parse("ITEM_TYPE", item.ItemKey.TypeId.ToString());

            if (item.CommentSortOrder == SortOrder.Ascending)
            {
                template.Parse("COMMENTS_ASC", "TRUE");
                template.Parse("COMMENT_SORT", "asc");
            }
            else
            {
                template.Parse("COMMENTS_DESC", "TRUE");
                template.Parse("COMMENT_SORT", "desc");
            }

            foreach (Comment comment in comments)
            {
                core.PrimitiveCache.LoadUserProfile(comment.UserId);
            }

            long lastId = 0;

            foreach (Comment comment in comments)
            {
                VariableCollection commentsVariableCollection = template.CreateChild("comment-list");

                //commentsVariableCollection.ParseRaw("COMMENT", Bbcode.Parse(HttpUtility.HtmlEncode(comment.Body), core.session.LoggedInMember));
                /*if ((!core.IsMobile) && (!string.IsNullOrEmpty(comment.BodyCache)))
                {
                    core.Display.ParseBbcodeCache(commentsVariableCollection, "COMMENT", comment.BodyCache);
                }
                else*/
                {
                    core.Display.ParseBbcode(commentsVariableCollection, "COMMENT", comment.Body, true, null, null);
                }

                try
                {
                    User commentPoster = core.PrimitiveCache[comment.UserId];

                    lastId = comment.Id;

                    commentsVariableCollection.Parse("ID", comment.Id.ToString());
                    commentsVariableCollection.Parse("TYPE_ID", ItemKey.GetTypeId(core, typeof(Comment)));
                    commentsVariableCollection.Parse("USERNAME", commentPoster.DisplayName);
                    commentsVariableCollection.Parse("USER_ID", commentPoster.Id.ToString());
                    commentsVariableCollection.Parse("USER_DISPLAY_NAME", commentPoster.DisplayName);
                    commentsVariableCollection.Parse("U_PROFILE", commentPoster.ProfileUri);
                    commentsVariableCollection.Parse("U_QUOTE", core.Hyperlink.BuildCommentQuoteUri(comment.Id));
                    commentsVariableCollection.Parse("U_REPORT", core.Hyperlink.BuildCommentReportUri(comment.Id));
                    commentsVariableCollection.Parse("U_DELETE", core.Hyperlink.BuildCommentDeleteUri(comment.Id));
                    commentsVariableCollection.Parse("U_LIKE", core.Hyperlink.BuildLikeItemUri(comment.ItemTypeId, comment.Id));
                    commentsVariableCollection.Parse("TIME", core.Tz.DateTimeToString(comment.GetTime(core.Tz)));
                    commentsVariableCollection.Parse("USER_ICON", commentPoster.Icon);
                    commentsVariableCollection.Parse("USER_TILE", commentPoster.Tile);
                    commentsVariableCollection.Parse("USER_SQUARE", commentPoster.Square);

                    if (comment.Info.Likes > 0)
                    {
                        commentsVariableCollection.Parse("LIKES", string.Format("{0:d} ", comment.Info.Likes));
                    }

                    if (comment.Info.Dislikes > 0)
                    {
                        commentsVariableCollection.Parse("DISLIKES", string.Format(" {0:d}", comment.Info.Dislikes));
                    }

                    if (comment.Info.SharedTimes > 0)
                    {
                        commentsVariableCollection.Parse("SHARES", string.Format(" ({0:d})", comment.Info.SharedTimes));
                    }

                    if (hook != null)
                    {
                        hook(new DisplayCommentHookEventArgs(core, owner, commentPoster, commentsVariableCollection));
                    }

                    if (core.Session.IsLoggedIn)
                    {
                        if (owner.CanModerateComments(core.Session.LoggedInMember))
                        {
                            commentsVariableCollection.Parse("MODERATE", "TRUE");
                        }
                    }

                    if (owner.IsItemOwner(commentPoster))
                    {
                        commentsVariableCollection.Parse("OWNER", "TRUE");
                        commentsVariableCollection.Parse("NORMAL", "FALSE");
                    }
                    else
                    {
                        commentsVariableCollection.Parse("OWNER", "FALSE");
                        commentsVariableCollection.Parse("NORMAL", "TRUE");
                    }

                    if (comment.SpamScore >= 10)
                    {
                        commentsVariableCollection.Parse("IS_SPAM", "TRUE");
                    }
                }
                catch
                {
                    // if userid is 0, anonymous
                    commentsVariableCollection.Parse("USERNAME", "Anonymous");
                    commentsVariableCollection.Parse("TIME", core.Tz.DateTimeToString(comment.GetTime(core.Tz)));

                    commentsVariableCollection.Parse("OWNER", "FALSE");
                    commentsVariableCollection.Parse("NORMAL", "TRUE");
                }
            }

            template.Parse("LAST_ID", "lastId");
        }
Ejemplo n.º 20
0
        public void ParseACL(Template template, Primitive owner, string variable)
        {
            Template aclTemplate = new Template("std.acl.html");
            aclTemplate.Medium = core.Template.Medium;
            aclTemplate.SetProse(core.Prose);

            if (itemPermissions == null)
            {
                itemPermissions = GetPermissions(core, item);
            }
            if (itemGrants == null)
            {
                itemGrants = AccessControlGrant.GetGrants(core, item);
            }
            if (unsavedGrants == null)
            {
                unsavedGrants = new List<UnsavedAccessControlGrant>();
            }

            if (itemGrants != null)
            {
                foreach (AccessControlGrant itemGrant in itemGrants)
                {
                    core.PrimitiveCache.LoadPrimitiveProfile(itemGrant.PrimitiveKey);
                }
            }

            bool simple = item.IsSimplePermissions;

            string mode = core.Http["aclmode"];
            switch (mode)
            {
                case "simple":
                    simple = true;
                    break;
                case "detailed":
                    simple = false;
                    break;
            }

            bool first = true;
            PermissionTypes lastType = PermissionTypes.View;
            VariableCollection permissionTypeVariableCollection = null;

            PermissionGroupSelectBox typeGroupSelectBox = null;
            List<PrimitivePermissionGroup> ownerGroups = null;

            if (itemPermissions != null)
            {
                foreach (AccessControlPermission itemPermission in itemPermissions)
                {
                    if (first || itemPermission.PermissionType != lastType)
                    {
                        if (typeGroupSelectBox != null)
                        {
                            permissionTypeVariableCollection.Parse("S_SIMPLE_SELECT", typeGroupSelectBox);
                        }

                        permissionTypeVariableCollection = aclTemplate.CreateChild("permision_types");
                        typeGroupSelectBox = new PermissionGroupSelectBox(core, "group-select-" + itemPermission.PermissionType.ToString(), item.ItemKey);

                        permissionTypeVariableCollection.Parse("TITLE", AccessControlLists.PermissionTypeToString(itemPermission.PermissionType));

                        first = false;
                        lastType = itemPermission.PermissionType;
                    }

                    if (simple)
                    {
                        if (ownerGroups == null)
                        {
                            ownerGroups = new List<PrimitivePermissionGroup>();
                            int itemGroups = 0;

                            Type type = item.GetType();
                            if (type.GetMethod(type.Name + "_GetItemGroups", new Type[] { typeof(Core) }) != null)
                            {
                                ownerGroups.AddRange((List<PrimitivePermissionGroup>)type.InvokeMember(type.Name + "_GetItemGroups", BindingFlags.Public | BindingFlags.Static | BindingFlags.InvokeMethod, null, null, new object[] { core }));
                                itemGroups = ownerGroups.Count;
                            }

                            ownerGroups.AddRange(core.GetPrimitivePermissionGroups(owner));
                        }

                        VariableCollection permissionVariableCollection = permissionTypeVariableCollection.CreateChild("permission_desc");
                        permissionVariableCollection.Parse("ID", itemPermission.Id.ToString());
                        permissionVariableCollection.Parse("TITLE", itemPermission.Name);
                        permissionVariableCollection.Parse("DESCRIPTION", itemPermission.Description);

                        if (itemGrants != null)
                        {
                            foreach (AccessControlGrant itemGrant in itemGrants)
                            {
                                if (itemGrant.PermissionId == itemPermission.Id)
                                {
                                    switch (itemGrant.Allow)
                                    {
                                        case AccessControlGrants.Allow:
                                            PrimitivePermissionGroup ppg = null;

                                            ppg = new PrimitivePermissionGroup(itemGrant.PrimitiveKey, string.Empty, string.Empty);
                                            foreach (PrimitivePermissionGroup p in ownerGroups)
                                            {
                                                if (ppg.ItemKey.Equals(p.ItemKey))
                                                {
                                                    ppg = p;
                                                    break;
                                                }
                                            }

                                            if (!typeGroupSelectBox.ItemKeys.Contains(ppg))
                                            {
                                                typeGroupSelectBox.ItemKeys.Add(ppg);
                                            }
                                            break;
                                        default:
                                            break;
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        VariableCollection permissionVariableCollection = permissionTypeVariableCollection.CreateChild("permission");
                        permissionVariableCollection.Parse("ID", itemPermission.Id.ToString());
                        permissionVariableCollection.Parse("TITLE", itemPermission.Name);
                        permissionVariableCollection.Parse("DESCRIPTION", itemPermission.Description);

                        SelectBox groupsSelectBox = BuildGroupsSelectBox(string.Format("new-permission-group[{0}]", itemPermission.Id), owner);

                        if (itemGrants != null)
                        {
                            foreach (AccessControlGrant itemGrant in itemGrants)
                            {
                                if (itemGrant.PermissionId == itemPermission.Id)
                                {
                                    string gsbk = string.Format("{0},{1}", itemGrant.PrimitiveKey.TypeId, itemGrant.PrimitiveKey.Id);
                                    if (groupsSelectBox.ContainsKey(gsbk))
                                    {
                                        groupsSelectBox[gsbk].Selectable = false;
                                    }

                                    VariableCollection grantVariableCollection = permissionVariableCollection.CreateChild("grant");

                                    if (groupsSelectBox.ContainsKey(gsbk))
                                    {
                                        string text = groupsSelectBox[gsbk].Text;
                                        if (text.StartsWith(" -- ", StringComparison.Ordinal))
                                        {
                                            text = text.Substring(4);
                                        }
                                        grantVariableCollection.Parse("DISPLAY_NAME", text);
                                        groupsSelectBox[gsbk].Selectable = false;
                                    }
                                    else
                                    {
                                        try
                                        {
                                            grantVariableCollection.Parse("DISPLAY_NAME", core.PrimitiveCache[itemGrant.PrimitiveKey].DisplayName);
                                        }
                                        catch
                                        {
                                            grantVariableCollection.Parse("DISPLAY_NAME", "{{ERROR LOADING PRIMITIVE(" + itemGrant.PrimitiveKey.TypeId.ToString() + "," + itemGrant.PrimitiveKey.Id.ToString() + ":" + (new ItemType(core, itemGrant.PrimitiveKey.TypeId)).Namespace + ")}}");
                                        }
                                    }

                                    RadioList allowrl = new RadioList("allow[" + itemGrant.PermissionId.ToString() + "," + itemGrant.PrimitiveKey.TypeId.ToString() + "," + itemGrant.PrimitiveKey.Id.ToString() + "]");
                                    SelectBox allowsb = new SelectBox("allow[" + itemGrant.PermissionId.ToString() + "," + itemGrant.PrimitiveKey.TypeId.ToString() + "," + itemGrant.PrimitiveKey.Id.ToString() + "]");
                                    Button deleteButton = new Button("delete", "Delete", itemGrant.PermissionId.ToString() + "," + itemGrant.PrimitiveKey.TypeId.ToString() + "," + itemGrant.PrimitiveKey.Id.ToString());

                                    allowrl.Add(new RadioListItem(allowrl.Name, "allow", "Allow"));
                                    allowrl.Add(new RadioListItem(allowrl.Name, "deny", "Deny"));
                                    allowrl.Add(new RadioListItem(allowrl.Name, "inherit", "Inherit"));

                                    allowsb.Add(new SelectBoxItem("allow", "Allow"));
                                    allowsb.Add(new SelectBoxItem("deny", "Deny"));
                                    allowsb.Add(new SelectBoxItem("inherit", "Inherit"));

                                    switch (itemGrant.Allow)
                                    {
                                        case AccessControlGrants.Allow:
                                            allowrl.SelectedKey = "allow";
                                            allowsb.SelectedKey = "allow";
                                            break;
                                        case AccessControlGrants.Deny:
                                            allowrl.SelectedKey = "deny";
                                            allowsb.SelectedKey = "deny";
                                            break;
                                        case AccessControlGrants.Inherit:
                                            allowrl.SelectedKey = "inherit";
                                            allowsb.SelectedKey = "inherit";
                                            break;
                                    }

                                    if (core.Http.Form["allow[" + itemPermission.Id.ToString() + "," + itemGrant.PrimitiveKey.TypeId.ToString() + "," + itemGrant.PrimitiveKey.Id.ToString() + "]"] != null)
                                    {
                                        allowrl.SelectedKey = core.Http.Form["allow[" + itemPermission.Id.ToString() + "," + itemGrant.PrimitiveKey.TypeId.ToString() + "," + itemGrant.PrimitiveKey.Id.ToString() + "]"];
                                    }

                                    grantVariableCollection.Parse("S_GRANT", allowsb);

                                    grantVariableCollection.Parse("S_ALLOW", allowrl["allow"]);
                                    grantVariableCollection.Parse("S_DENY", allowrl["deny"]);
                                    grantVariableCollection.Parse("S_INHERIT", allowrl["inherit"]);

                                    grantVariableCollection.Parse("S_DELETE", deleteButton);

                                    grantVariableCollection.Parse("ID", string.Format("{0},{1}", itemGrant.PrimitiveKey.TypeId, itemGrant.PrimitiveKey.Id));
                                    grantVariableCollection.Parse("PERMISSION_ID", itemPermission.Id.ToString());
                                    grantVariableCollection.Parse("IS_NEW", "FALSE");
                                }
                            }

                            foreach (AccessControlGrant itemGrant in itemGrants)
                            {
                                VariableCollection grantsVariableCollection = template.CreateChild("grants");
                            }
                        }

                        if (core.Http.Form["save"] == null)
                        {
                            foreach (SelectBoxItem gsbi in groupsSelectBox)
                            {
                                if (core.Http.Form[string.Format("new-grant[{0},{1}]", itemPermission.Id, gsbi.Key)] != null)
                                {
                                    ItemKey ik = new ItemKey(gsbi.Key);

                                    UnsavedAccessControlGrant uacg = new UnsavedAccessControlGrant(core, ik, item.ItemKey, itemPermission.Id, AccessControlGrants.Inherit);

                                    VariableCollection grantVariableCollection = permissionVariableCollection.CreateChild("grant");

                                    grantVariableCollection.Parse("DISPLAY_NAME", gsbi.Text);

                                    RadioList allowrl = new RadioList("allow[" + itemPermission.Id.ToString() + "," + ik.TypeId.ToString() + "," + ik.Id.ToString() + "]");
                                    SelectBox allowsb = new SelectBox("allow[" + itemPermission.Id.ToString() + "," + ik.TypeId.ToString() + "," + ik.Id.ToString() + "]");

                                    allowrl.Add(new RadioListItem(allowrl.Name, "allow", "Allow"));
                                    allowrl.Add(new RadioListItem(allowrl.Name, "deny", "Deny"));
                                    allowrl.Add(new RadioListItem(allowrl.Name, "inherit", "Inherit"));

                                    allowsb.Add(new SelectBoxItem("allow", "Allow"));
                                    allowsb.Add(new SelectBoxItem("deny", "Deny"));
                                    allowsb.Add(new SelectBoxItem("inherit", "Inherit"));

                                    if (core.Http.Form["allow[" + itemPermission.Id.ToString() + "," + ik.TypeId.ToString() + "," + ik.Id.ToString() + "]"] != null)
                                    {
                                        allowrl.SelectedKey = core.Http.Form["allow[" + itemPermission.Id.ToString() + "," + ik.TypeId.ToString() + "," + ik.Id.ToString() + "]"];
                                    }
                                    else
                                    {
                                        switch (uacg.Allow)
                                        {
                                            case AccessControlGrants.Allow:
                                                allowrl.SelectedKey = "allow";
                                                allowsb.SelectedKey = "allow";
                                                break;
                                            case AccessControlGrants.Deny:
                                                allowrl.SelectedKey = "deny";
                                                allowsb.SelectedKey = "deny";
                                                break;
                                            case AccessControlGrants.Inherit:
                                                allowrl.SelectedKey = "inherit";
                                                allowsb.SelectedKey = "inherit";
                                                break;
                                        }
                                    }

                                    grantVariableCollection.Parse("S_GRANT", allowsb);

                                    grantVariableCollection.Parse("S_ALLOW", allowrl["allow"]);
                                    grantVariableCollection.Parse("S_DENY", allowrl["deny"]);
                                    grantVariableCollection.Parse("S_INHERIT", allowrl["inherit"]);

                                    grantVariableCollection.Parse("ID", string.Format("{0},{1}", ik.TypeId, ik.Id));
                                    grantVariableCollection.Parse("PERMISSION_ID", itemPermission.Id.ToString());
                                    grantVariableCollection.Parse("IS_NEW", "TRUE");

                                    gsbi.Selectable = false;
                                }
                            }
                        }

                        if (core.Http.Form[string.Format("add-permission[{0}]", itemPermission.Id)] != null)
                        {
                            string groupSelectBoxId = core.Http.Form[string.Format("new-permission-group[{0}]", itemPermission.Id)];

                            ItemKey ik = new ItemKey(groupSelectBoxId);

                            UnsavedAccessControlGrant uacg = new UnsavedAccessControlGrant(core, ik, item.ItemKey, itemPermission.Id, AccessControlGrants.Inherit);

                            VariableCollection grantVariableCollection = permissionVariableCollection.CreateChild("grant");

                            grantVariableCollection.Parse("DISPLAY_NAME", groupsSelectBox[groupSelectBoxId].Text);

                            RadioList allowrl = new RadioList("allow[" + itemPermission.Id.ToString() + "," + ik.TypeId.ToString() + "," + ik.Id.ToString() + "]");
                            SelectBox allowsb = new SelectBox("allow[" + itemPermission.Id.ToString() + "," + ik.TypeId.ToString() + "," + ik.Id.ToString() + "]");

                            allowrl.Add(new RadioListItem(allowrl.Name, "allow", "Allow"));
                            allowrl.Add(new RadioListItem(allowrl.Name, "deny", "Deny"));
                            allowrl.Add(new RadioListItem(allowrl.Name, "inherit", "Inherit"));

                            allowsb.Add(new SelectBoxItem("allow", "Allow"));
                            allowsb.Add(new SelectBoxItem("deny", "Deny"));
                            allowsb.Add(new SelectBoxItem("inherit", "Inherit"));

                            switch (uacg.Allow)
                            {
                                case AccessControlGrants.Allow:
                                    allowrl.SelectedKey = "allow";
                                    allowsb.SelectedKey = "allow";
                                    break;
                                case AccessControlGrants.Deny:
                                    allowrl.SelectedKey = "deny";
                                    allowsb.SelectedKey = "deny";
                                    break;
                                case AccessControlGrants.Inherit:
                                    allowrl.SelectedKey = "inherit";
                                    allowsb.SelectedKey = "inherit";
                                    break;
                            }

                            grantVariableCollection.Parse("S_GRANT", allowsb);

                            grantVariableCollection.Parse("S_ALLOW", allowrl["allow"]);
                            grantVariableCollection.Parse("S_DENY", allowrl["deny"]);
                            grantVariableCollection.Parse("S_INHERIT", allowrl["inherit"]);

                            grantVariableCollection.Parse("ID", string.Format("{0},{1}", ik.TypeId, ik.Id));
                            grantVariableCollection.Parse("PERMISSION_ID", itemPermission.Id.ToString());
                            grantVariableCollection.Parse("IS_NEW", "TRUE");

                            groupsSelectBox[groupSelectBoxId].Selectable = false;
                        }

                        permissionVariableCollection.Parse("S_PERMISSION_GROUPS", groupsSelectBox);

                        RadioList allowNewrl = new RadioList("new-permission-group-allow");
                        SelectBox allowNewsb = new SelectBox("new-permission-group-allow");

                        allowNewrl.Add(new RadioListItem(allowNewrl.Name, "allow", "Allow"));
                        allowNewrl.Add(new RadioListItem(allowNewrl.Name, "deny", "Deny"));
                        allowNewrl.Add(new RadioListItem(allowNewrl.Name, "inherit", "Inherit"));

                        allowNewsb.Add(new SelectBoxItem("allow", "Allow"));
                        allowNewsb.Add(new SelectBoxItem("deny", "Deny"));
                        allowNewsb.Add(new SelectBoxItem("inherit", "Inherit"));

                        allowNewrl.SelectedKey = "inherit";
                        allowNewsb.SelectedKey = "inherit";

                        permissionVariableCollection.Parse("S_GRANT", allowNewsb);

                        permissionVariableCollection.Parse("S_ALLOW", allowNewrl["allow"].ToString());
                        permissionVariableCollection.Parse("S_DENY", allowNewrl["deny"].ToString());
                        permissionVariableCollection.Parse("S_INHERIT", allowNewrl["inherit"].ToString());
                    }
                }

                if (typeGroupSelectBox != null)
                {
                    permissionTypeVariableCollection.Parse("S_SIMPLE_SELECT", typeGroupSelectBox);
                }
            }

            if (string.IsNullOrEmpty(variable))
            {
                variable = "S_PERMISSIONS";
            }

            /*PermissionGroupSelectBox groupSelectBox = new PermissionGroupSelectBox(core, "group-select", item.ItemKey);
            groupSelectBox.SelectMultiple = true;

            aclTemplate.Parse("S_SIMPLE_SELECT", groupSelectBox);*/

            if (simple)
            {
                aclTemplate.Parse("IS_SIMPLE", "TRUE");
            }

            aclTemplate.Parse("U_DETAILED", Access.BuildAclUri(core, item, false));
            aclTemplate.Parse("U_SIMPLE", Access.BuildAclUri(core, item, true));

            HiddenField modeField = new HiddenField("aclmode");
            if (simple)
            {
                modeField.Value = "simple";
            }
            else
            {
                modeField.Value = "detailed";
            }

            aclTemplate.Parse("S_ACLMODE", modeField);

            template.ParseRaw(variable, aclTemplate.ToString());
        }
Ejemplo n.º 21
0
        void core_PrimitiveHeadHooks(HookEventArgs e)
        {
            if (e.PageType == AppPrimitives.Group)
            {
                core.Template.Parse("TAB_LIST", "TRUE");
                Template template = new Template(Assembly.GetExecutingAssembly(), "header_navigation_tabs");
                template.Medium = core.Template.Medium;
                template.SetProse(core.Prose);

                List<NagivationTab> tabs = NagivationTab.GetTabs(core, e.Owner);

                {
                    VariableCollection tabVariableCollection = template.CreateChild("tab_list");

                    tabVariableCollection.Parse("TITLE", "Home");
                    tabVariableCollection.Parse("U_TAB", e.Owner.Uri);
                }

                foreach (NagivationTab tab in tabs)
                {
                    VariableCollection tabVariableCollection = template.CreateChild("tab_list");

                    tabVariableCollection.Parse("TITLE", tab.Page.Title);
                    tabVariableCollection.Parse("U_TAB", tab.Page.Uri);
                }

                if (tabs.Count > 0)
                {
                    e.core.AddPrimitiveHeadPanel(template);
                }
            }
        }
Ejemplo n.º 22
0
        public static void ShowMore(Core core, TPage page, User owner)
        {
            if (core == null)
            {
                throw new NullCoreException();
            }

            Template template = new Template("pane.feeditem.html");
            template.Medium = core.Template.Medium;
            template.SetProse(core.Prose);

            bool moreContent = false;
            long lastId = 0;
            List<Action> feedActions = CombinedFeed.GetItems(core, owner, page.TopLevelPageNumber, 20, page.TopLevelPageOffset, out moreContent);

            foreach (Action feedAction in feedActions)
            {
                VariableCollection feedItemVariableCollection = template.CreateChild("feed_days_list.feed_item");

                core.Display.ParseBbcode(feedItemVariableCollection, "TITLE", feedAction.FormattedTitle);
                core.Display.ParseBbcode(feedItemVariableCollection, "TEXT", feedAction.Body, core.PrimitiveCache[feedAction.OwnerId], true, string.Empty, string.Empty);

                feedItemVariableCollection.Parse("USER_DISPLAY_NAME", feedAction.Owner.DisplayName);

                feedItemVariableCollection.Parse("ID", feedAction.ActionItemKey.Id);
                feedItemVariableCollection.Parse("TYPE_ID", feedAction.ActionItemKey.TypeId);

                if (feedAction.ActionItemKey.GetType(core).Likeable)
                {
                    feedItemVariableCollection.Parse("LIKEABLE", "TRUE");

                    if (feedAction.Info.Likes > 0)
                    {
                        feedItemVariableCollection.Parse("LIKES", string.Format(" {0:d}", feedAction.Info.Likes));
                        feedItemVariableCollection.Parse("DISLIKES", string.Format(" {0:d}", feedAction.Info.Dislikes));
                    }
                }

                if (feedAction.ActionItemKey.GetType(core).Commentable)
                {
                    feedItemVariableCollection.Parse("COMMENTABLE", "TRUE");

                    if (feedAction.Info.Comments > 0)
                    {
                        feedItemVariableCollection.Parse("COMMENTS", string.Format(" ({0:d})", feedAction.Info.Comments));
                    }
                }

                //Access access = new Access(core, feedAction.ActionItemKey, true);
                if (feedAction.PermissiveParent.Access.IsPublic())
                {
                    feedItemVariableCollection.Parse("IS_PUBLIC", "TRUE");
                    if (feedAction.ActionItemKey.GetType(core).Shareable)
                    {
                        feedItemVariableCollection.Parse("SHAREABLE", "TRUE");
                        //feedItemVariableCollection.Parse("U_SHARE", feedAction.ShareUri);

                        if (feedAction.Info.SharedTimes > 0)
                        {
                            feedItemVariableCollection.Parse("SHARES", string.Format(" {0:d}", feedAction.Info.SharedTimes));
                        }
                    }
                }

                if (feedAction.Owner is User)
                {
                    feedItemVariableCollection.Parse("USER_TILE", ((User)feedAction.Owner).Tile);
                    feedItemVariableCollection.Parse("USER_ICON", ((User)feedAction.Owner).Icon);
                }

                lastId = feedAction.Id;
            }

            string loadMoreUri = core.Hyperlink.BuildHomeUri() + "?p=" + (core.TopLevelPageNumber + 1) + "&o=" + lastId;
            core.Response.SendRawText(moreContent ? loadMoreUri : "noMoreContent", template.ToString());
        }
Ejemplo n.º 23
0
        public void ShowGroupForum(HookEventArgs e)
        {
            Template template = new Template(Assembly.GetExecutingAssembly(), "viewprofileforum");
            template.Medium = core.Template.Medium;
            template.SetProse(core.Prose);

            Forum forum = new Forum(core, (UserGroup)e.Owner);
            template.Parse("U_FORUM", forum.Uri);

            List<ForumTopic> recentTopics = forum.GetTopicsFlat(0, 10);

            // PostId, TopicPost
            Dictionary<long, TopicPost> topicLastPosts;

            topicLastPosts = TopicPost.GetTopicLastPosts(core, recentTopics);

            template.Parse("TOPICS", recentTopics.Count.ToString());

            foreach (ForumTopic topic in recentTopics)
            {
                core.LoadUserProfile(topic.PosterId);
            }

            foreach (ForumTopic topic in recentTopics)
            {
                VariableCollection topicVariableCollection = template.CreateChild("topic_list");

                topicVariableCollection.Parse("TITLE", topic.Title);
                topicVariableCollection.Parse("URI", topic.Uri);
                topicVariableCollection.Parse("VIEWS", topic.Views.ToString());
                topicVariableCollection.Parse("REPLIES", topic.Posts.ToString());
                topicVariableCollection.Parse("DATE", core.Tz.DateTimeToString(topic.GetCreatedDate(core.Tz)));
                topicVariableCollection.Parse("USERNAME", core.PrimitiveCache[topic.PosterId].DisplayName);
                topicVariableCollection.Parse("U_POSTER", core.PrimitiveCache[topic.PosterId].Uri);

                if (topicLastPosts.ContainsKey(topic.LastPostId))
                {
                    topicVariableCollection.Parse("LAST_POST_URI", topicLastPosts[topic.LastPostId].Uri);
                    topicVariableCollection.Parse("LAST_POST_TITLE", topicLastPosts[topic.LastPostId].Title);
                    core.Display.ParseBbcode(topicVariableCollection, "LAST_POST", string.Format("[iurl={0}]{1}[/iurl]\n{2}",
                        topicLastPosts[topic.LastPostId].Uri, Functions.TrimStringToWord(topicLastPosts[topic.LastPostId].Title, 20), core.Tz.DateTimeToString(topicLastPosts[topic.LastPostId].GetCreatedDate(core.Tz))));
                }
                else
                {
                    topicVariableCollection.Parse("LAST_POST", "No posts");
                }

                switch (topic.Status)
                {
                    case TopicStates.Normal:
                        if (topic.IsRead)
                        {
                            if (topic.IsLocked)
                            {
                                topicVariableCollection.Parse("IS_NORMAL_READ_LOCKED", "TRUE");
                            }
                            else
                            {
                                topicVariableCollection.Parse("IS_NORMAL_READ_UNLOCKED", "TRUE");
                            }
                        }
                        else
                        {
                            if (topic.IsLocked)
                            {
                                topicVariableCollection.Parse("IS_NORMAL_UNREAD_LOCKED", "TRUE");
                            }
                            else
                            {
                                topicVariableCollection.Parse("IS_NORMAL_UNREAD_UNLOCKED", "TRUE");
                            }
                        }
                        break;
                    case TopicStates.Sticky:
                        if (topic.IsRead)
                        {
                            if (topic.IsLocked)
                            {
                                topicVariableCollection.Parse("IS_STICKY_READ_LOCKED", "TRUE");
                            }
                            else
                            {
                                topicVariableCollection.Parse("IS_STICKY_READ_UNLOCKED", "TRUE");
                            }
                        }
                        else
                        {
                            if (topic.IsLocked)
                            {
                                topicVariableCollection.Parse("IS_STICKY_UNREAD_LOCKED", "TRUE");
                            }
                            else
                            {
                                topicVariableCollection.Parse("IS_STICKY_UNREAD_UNLOCKED", "TRUE");
                            }
                        }

                        break;
                    case TopicStates.Announcement:
                    case TopicStates.Global:
                        if (topic.IsRead)
                        {
                            if (topic.IsLocked)
                            {
                                topicVariableCollection.Parse("IS_ANNOUNCEMENT_READ_LOCKED", "TRUE");
                            }
                            else
                            {
                                topicVariableCollection.Parse("IS_ANNOUNCEMENT_READ_UNLOCKED", "TRUE");
                            }
                        }
                        else
                        {
                            if (topic.IsLocked)
                            {
                                topicVariableCollection.Parse("IS_ANNOUNCEMENT_UNREAD_LOCKED", "TRUE");
                            }
                            else
                            {
                                topicVariableCollection.Parse("IS_ANNOUNCEMENT_UNREAD_UNLOCKED", "TRUE");
                            }
                        }

                        break;
                }
            }

            e.core.AddMainPanel(template);
        }
Ejemplo n.º 24
0
        private static void DisplayMiniCalendar(Core core, Template template, VariableCollection vc1, Primitive owner, int year, int month)
        {
            int days = DateTime.DaysInMonth(year, month);
            DayOfWeek firstDay = new DateTime(year, month, 1).DayOfWeek;
            int offset = Calendar.GetFirstDayOfMonthOffset(firstDay);
            int weeks = (int)Math.Ceiling((days + offset) / 7.0);

            if (template != null)
            {
                template.Parse("CURRENT_MONTH", core.Functions.IntToMonth(month));
                template.Parse("CURRENT_YEAR", year.ToString());
            }
            else
            {
                vc1.Parse("MONTH", core.Functions.IntToMonth(month));
                vc1.Parse("U_MONTH", BuildMonthUri(core, owner, year, month));
            }

            for (int week = 0; week < weeks; week++)
            {
                VariableCollection weekVariableCollection;
                if (template != null)
                {
                    weekVariableCollection = template.CreateChild("week");
                }
                else
                {
                    weekVariableCollection = vc1.CreateChild("week");
                }

                weekVariableCollection.Parse("WEEK", (week + 1).ToString());

                if (week + 1 == 1)
                {
                    int daysPrev = DateTime.DaysInMonth(year - (month - 1) / 12, (month - 1) % 12 + 1);
                    for (int i = offset - 1; i >= 0; i--)
                    {
                        int day = daysPrev - i;

                        VariableCollection dayVariableCollection = weekVariableCollection.CreateChild("day");
                        dayVariableCollection.Parse("DATE", day.ToString());
                        dayVariableCollection.Parse("URI", Calendar.BuildDateUri(core, owner, year - (month - 2) / 12, (month - 2) % 12 + 1, day));
                    }
                    for (int i = offset; i < 7; i++)
                    {
                        int day = i - offset + 1;

                        VariableCollection dayVariableCollection = weekVariableCollection.CreateChild("day");
                        dayVariableCollection.Parse("DATE", day.ToString());
                        dayVariableCollection.Parse("URI", Calendar.BuildDateUri(core, owner, year, month, day));
                    }
                }
                else if (week + 1 == weeks)
                {
                    for (int i = week * 7 - offset; i < days; i++)
                    {
                        int day = i + 1;

                        VariableCollection dayVariableCollection = weekVariableCollection.CreateChild("day");
                        dayVariableCollection.Parse("DATE", day.ToString());
                        dayVariableCollection.Parse("URI", Calendar.BuildDateUri(core, owner, year, month, day));
                    }
                    for (int i = 0; i < weeks * 7 - days - offset; i++)
                    {
                        int day = i + 1;

                        VariableCollection dayVariableCollection = weekVariableCollection.CreateChild("day");
                        dayVariableCollection.Parse("DATE", day.ToString());
                        dayVariableCollection.Parse("URI", Calendar.BuildDateUri(core, owner, year + (month) / 12, (month) % 12 + 1, day));
                    }
                }
                else
                {
                    for (int i = 0; i < 7; i++)
                    {
                        int day = week * 7 + i + 1 - offset;

                        VariableCollection dayVariableCollection = weekVariableCollection.CreateChild("day");
                        dayVariableCollection.Parse("DATE", day.ToString());
                        dayVariableCollection.Parse("URI", Calendar.BuildDateUri(core, owner, year, month, day));
                    }
                }
            }
        }
Ejemplo n.º 25
0
        public void SendNotification(Core core, User actionBy, User receiver, ItemKey itemOwnerKey, ItemKey itemKey, string verb, string url, string action)
        {
            if (canNotify(core, receiver))
            {
                Notification notification = Notification.Create(core, this, actionBy, receiver, itemOwnerKey, itemKey, verb, url, action);

                if (receiver.UserInfo.EmailNotifications)
                {
                    // Header so we can use the same emailBody for multiple subscribers
                    Template emailTemplate = new Template(core.TemplateEmailPath, "notification.html");

                    emailTemplate.Parse("SITE_TITLE", core.Settings.SiteTitle);
                    emailTemplate.Parse("U_SITE", core.Hyperlink.StripSid(core.Hyperlink.AppendAbsoluteSid(core.Hyperlink.BuildHomeUri())));
                    emailTemplate.Parse("TO_NAME", receiver.DisplayName);
                    core.Display.ParseBbcode(emailTemplate, "NOTIFICATION_MESSAGE", notification.NotificationString, receiver, false, string.Empty, string.Empty, true);

                    // TODO parse action links
                    if (itemKey.GetType(core).Notifiable)
                    {
                        Dictionary<string, string> actions = notification.NotifiedItem.GetNotificationActions(action);

                        foreach (string a in actions.Keys)
                        {
                            VariableCollection actionsVariableCollection = emailTemplate.CreateChild("actions_list");

                            actionsVariableCollection.Parse("ACTION", actions[a]);
                            actionsVariableCollection.Parse("U_ACTION", core.Hyperlink.AppendAbsoluteSid(core.Hyperlink.AppendNvid(notification.NotifiedItem.GetNotificationActionUrl(a), notification.VerificationString)));
                        }
                    }

                    core.Email.SendEmail(receiver.UserInfo.PrimaryEmail, HttpUtility.HtmlDecode(core.Bbcode.Flatten(HttpUtility.HtmlEncode(notification.NotificationString))), emailTemplate);
                }
            }
        }