Esempio n. 1
0
        /// <summary>
        /// Informs the core journal that the user has provided an answer.
        /// </summary>
        /// <param name="objPost"></param>
        /// <param name="questionTitle"></param>
        /// <param name="portalId"></param>
        /// <param name="journalUserId"></param>
        /// <param name="url"></param>
        internal void AddAnswerToJournal(AlbumInfo objPost, string questionTitle, int portalId, int journalUserId, string url)
        {
            var objectKey = Constants.ContentTypeName + "_" + Constants.JournalAnswerTypeName + "_" + string.Format("{0}:{1}", objPost.AlbumID, objPost.AlbumID);
            var ji = JournalController.Instance.GetJournalItemByKey(portalId, objectKey);

            if ((ji != null))
            {
                JournalController.Instance.DeleteJournalItemByKey(portalId, objectKey);
            }

            ji = new JournalItem
            {
                PortalId = portalId,
                ProfileId = journalUserId,
                UserId = journalUserId,
                ContentItemId = objPost.ContentItemId,
                Title = questionTitle,
                ItemData = new ItemData { Url = url },
                Summary = "", //objPost.Body,
                Body = null,
                JournalTypeId = GetAnswerJournalTypeID(portalId),
                ObjectKey = objectKey,
                SecuritySet = "E,"
            };

            JournalController.Instance.SaveJournalItem(ji, objPost.TabID);
        }
Esempio n. 2
0
        /// <summary>
        /// This is used to update the content in the ContentItems table. Should be called when a question is updated.
        /// </summary>
        internal void UpdateContentItem(JournalItem objJournalItem, int tabId, int moduleId)
        {
            var objContent = Util.GetContentController().GetContentItem(objJournalItem.ContentItemId);

            if (objContent == null)
            {
                return;
            }
            //Only update content the contentitem if it was created by the journal
            if ((objContent.ContentTypeId == GetContentTypeID("DNNCorp_JournalProfile") && objJournalItem.ProfileId > 0) ||
                (objContent.ContentTypeId == GetContentTypeID("DNNCorp_JournalGroup") && objJournalItem.SocialGroupId > 0))
            {
                objContent.Content    = GetContentBody(objJournalItem);
                objContent.TabID      = tabId;
                objContent.ModuleID   = moduleId;
                objContent.ContentKey = "journalid=" + objJournalItem.JournalId; // we reset this just in case the page changed.

                Util.GetContentController().UpdateContentItem(objContent);
            }


            // Update Terms
            //var cntTerm = new Terms();
            //cntTerm.ManageQuestionTerms(objPost, objContent);
        }
Esempio n. 3
0
        public static void CreateJournalEntry(RoleInfo roleInfo, UserInfo createdBy)
        {
            var journalController = JournalController.Instance;
            var journalItem = new JournalItem();
            
            string url = "";
            
            if (roleInfo.Settings.ContainsKey("URL"))
            {
                url = roleInfo.Settings["URL"];
            }

            journalItem.PortalId = roleInfo.PortalID;
            journalItem.ProfileId = createdBy.UserID;
            journalItem.UserId = createdBy.UserID;
            journalItem.Title = roleInfo.RoleName;
            journalItem.ItemData = new ItemData {Url = url};
            journalItem.SocialGroupId = roleInfo.RoleID;
            journalItem.Summary = roleInfo.Description;
            journalItem.Body = null;
            journalItem.JournalTypeId = journalController.GetJournalType("groupcreate").JournalTypeId;
            journalItem.ObjectKey = string.Format("groupcreate:{0}:{1}", roleInfo.RoleID.ToString(CultureInfo.InvariantCulture), createdBy.UserID.ToString(CultureInfo.InvariantCulture));
            
            if (journalController.GetJournalItemByKey(roleInfo.PortalID, journalItem.ObjectKey) != null)
                journalController.DeleteJournalItemByKey(roleInfo.PortalID, journalItem.ObjectKey);
            
            
            journalItem.SecuritySet = string.Empty;
            
            if (roleInfo.IsPublic)
                journalItem.SecuritySet += "E,";
            
            
            journalController.SaveJournalItem(journalItem, -1);
        }
        /// <summary>
        /// Informs the core journal that the user has created an item
        /// </summary>
        /// <param name="objEntity"></param>
        /// <param name="tabId"></param>
        /// <param name="title"></param>
        /// <param name="portalId"></param>
        /// <param name="journalUserId"></param>
        /// <param name="url"></param>
        /// <remarks>This may need to be updated based on what you intent to send to the jorunal.</remarks>
        internal void AddItemToJournal(EntityInfo objEntity, int tabId, string title, int portalId, int journalUserId, string url)
        {
            var objectKey = Constants.ContentTypeName + "_" + Constants.JournalSocialModuleTypeName + "_" + string.Format("{0}:{1}", objEntity.Id, portalId);
            var ji = JournalController.Instance.GetJournalItemByKey(portalId, objectKey);

            if ((ji != null))
            {
                JournalController.Instance.DeleteJournalItemByKey(portalId, objectKey);
            }

            ji = new JournalItem
            {
                PortalId = portalId,
                ProfileId = journalUserId,
                UserId = journalUserId,
                //SocialGroupId = objEntity.GroupId,
                //ContentItemId = objEntity.ContentItemId,
                Title = title,
                ItemData = new ItemData { Url = url },
                //Summary = objEntity.Details,
                Body = null,
                JournalTypeId = GetCreateEventJournalType(portalId),
                ObjectKey = objectKey,
                SecuritySet = "E,"
            };

            //if (objEntity.GroupId > Null.NullInteger) ji.SocialGroupId = objEntity.GroupId;

            JournalController.Instance.SaveJournalItem(ji, tabId);
        }
Esempio n. 5
0
        /// <summary>
        /// This should only run after the Post exists in the data store. 
        /// </summary>
        /// <returns>The newly created ContentItemID from the data store.</returns>
        /// <remarks>This is for the first question in the thread. Not for replies or items with ParentID > 0.</remarks>
        internal ContentItem CreateContentItem(JournalItem objJournalItem, int tabId) {
            var typeController = new ContentTypeController();
            string contentTypeName = "DNNCorp_JournalProfile";
            if (objJournalItem.SocialGroupId > 0) {
                contentTypeName = "DNNCorp_JournalGroup";
            }
            var colContentTypes = (from t in typeController.GetContentTypes() where t.ContentType == contentTypeName select t);
            int contentTypeID;

            if (colContentTypes.Count() > 0) {
                var contentType = colContentTypes.Single();
                contentTypeID = contentType == null ? CreateContentType(contentTypeName) : contentType.ContentTypeId;
            } else {
                contentTypeID = CreateContentType(contentTypeName);
            }
            
            var objContent = new ContentItem {
                Content = GetContentBody(objJournalItem),                
                ContentTypeId = contentTypeID,
                Indexed = false,
                ContentKey = "journalid=" + objJournalItem.JournalId,
                ModuleID = -1,
                TabID = tabId
            };

            objContent.ContentItemId = Util.GetContentController().AddContentItem(objContent);

            // Add Terms
            //var cntTerm = new Terms();
            //cntTerm.ManageQuestionTerms(objPost, objContent);

            return objContent;
        }
Esempio n. 6
0
        public void UpdateJournalItem(JournalItem journalItem, ModuleInfo module)
        {
            var tabId       = module == null ? Null.NullInteger : module.TabID;
            var tabModuleId = module == null ? Null.NullInteger : module.TabModuleID;

            UpdateJournalItem(journalItem, tabId, tabModuleId);
        }
Esempio n. 7
0
        public void DeleteJournalItem(int portalId, int currentUserId, int journalId)
        {
            JournalItem ji      = GetJournalItem(portalId, currentUserId, journalId);
            int         groupId = ji.SocialGroupId;

            _dataService.Journal_Delete(journalId);
            if (groupId > 0)
            {
                UpdateGroupStats(portalId, groupId);
            }
        }
        public JournalItemTokenReplace(JournalItem journalItem, JournalControl journalControl) {
            PropertySource["journalitem"] = journalItem;
            PropertySource["journalcontrol"] = journalControl;
            if (journalItem.ItemData != null) {
                PropertySource["journaldata"] = journalItem.ItemData;
            }
            if (journalItem.JournalAuthor != null) {
                PropertySource["journalauthor"] = journalItem.JournalAuthor;
            }
           
            
            

        }
Esempio n. 9
0
 /// <summary>
 /// Creates the content text
 /// </summary>
 /// <param name="objJournalItem"></param>
 /// <returns></returns>
 private static string GetContentBody(JournalItem objJournalItem)
 {
     if (!string.IsNullOrEmpty(objJournalItem.Title))
     {
         return(objJournalItem.Title);
     }
     else if (!string.IsNullOrEmpty(objJournalItem.Summary))
     {
         return(objJournalItem.Summary);
     }
     else if (!string.IsNullOrEmpty(objJournalItem.Body))
     {
         return(objJournalItem.Body);
     }
     else
     {
         return(null);
     }
 }
Esempio n. 10
0
        /// <summary>
        /// This is used to update the content in the ContentItems table. Should be called when a question is updated.
        /// </summary>
        internal void UpdateContentItem(JournalItem objJournalItem, int tabId) {
            var objContent = Util.GetContentController().GetContentItem(objJournalItem.ContentItemId);

            if (objContent == null) return;
            //Only update content the contentitem if it was created by the journal
            if ((objContent.ContentTypeId == GetContentTypeID("DNNCorp_JournalProfile") && objJournalItem.ProfileId > 0)
                    || (objContent.ContentTypeId == GetContentTypeID("DNNCorp_JournalGroup") && objJournalItem.SocialGroupId > 0))
            {
                objContent.Content = GetContentBody(objJournalItem);
                objContent.TabID = tabId;
                objContent.ContentKey = "journalid=" + objJournalItem.JournalId; // we reset this just in case the page changed.

                Util.GetContentController().UpdateContentItem(objContent);
            }
            

            // Update Terms
            //var cntTerm = new Terms();
            //cntTerm.ManageQuestionTerms(objPost, objContent);
        }
Esempio n. 11
0
        /// <summary>
        /// Posts the topic comment to DNN journal.
        /// </summary>
        /// <param name="summary">The summary.</param>
        /// <param name="title">The title.</param>
        /// <param name="description">The description.</param>
        /// <param name="linkToTopic">The link to topic.</param>
        /// <param name="currentTab">The current tab.</param>
        /// <param name="topicName">Name of the topic.</param>
        /// <param name="journalType">Type of the journal.</param>
        public static void PostTopicCommentToJournal(
            string summary,
            string title,
            string description,
            string linkToTopic,
            int currentTab,
            string topicName,
            SharedEnum.DNNJournalType journalType)
        {
            if (HttpContext.Current != null && HttpContext.Current.User.Identity.IsAuthenticated)
            {
                UserInfo user = UserController.GetCurrentUserInfo();
                if (user != null)
                {
                    // Post to DotnetNuke Journal
                    var journalController = JournalController.Instance;
                    var journalItem = new JournalItem();
                    journalItem.Summary = summary;
                    journalItem.PortalId = PortalSettings.Current.PortalId;
                    journalItem.ProfileId = user.UserID;
                    journalItem.SocialGroupId = Null.NullInteger;
                    journalItem.UserId = user.UserID;

                    journalItem.ItemData = new ItemData()
                    {
                        Description = description,
                        Title = title,
                        Url = linkToTopic
                    };

                    journalItem.JournalTypeId = (int)journalType;
                    journalItem.ObjectKey = string.Empty;
                    journalItem.SecuritySet = "F,";
                    //// http: //www.dnnsoftware.com/wiki/loc/history/Page/Journal/Revision/11

                    journalItem.Title = topicName;
                    journalController.SaveJournalItem(journalItem, currentTab); // saving
                }
            }
        }
Esempio n. 12
0
        /// <summary>
        /// This should only run after the Post exists in the data store.
        /// </summary>
        /// <returns>The newly created ContentItemID from the data store.</returns>
        /// <remarks>This is for the first question in the thread. Not for replies or items with ParentID > 0.</remarks>
        internal ContentItem CreateContentItem(JournalItem objJournalItem, int tabId, int moduleId)
        {
            var    typeController  = new ContentTypeController();
            string contentTypeName = "DNNCorp_JournalProfile";

            if (objJournalItem.SocialGroupId > 0)
            {
                contentTypeName = "DNNCorp_JournalGroup";
            }

            var colContentTypes = from t in typeController.GetContentTypes() where t.ContentType == contentTypeName select t;
            int contentTypeID;

            if (colContentTypes.Count() > 0)
            {
                var contentType = colContentTypes.Single();
                contentTypeID = contentType == null?CreateContentType(contentTypeName) : contentType.ContentTypeId;
            }
            else
            {
                contentTypeID = CreateContentType(contentTypeName);
            }

            var objContent = new ContentItem
            {
                Content       = GetContentBody(objJournalItem),
                ContentTypeId = contentTypeID,
                Indexed       = false,
                ContentKey    = "journalid=" + objJournalItem.JournalId,
                ModuleID      = moduleId,
                TabID         = tabId,
            };

            objContent.ContentItemId = Util.GetContentController().AddContentItem(objContent);

            // Add Terms
            // var cntTerm = new Terms();
            // cntTerm.ManageQuestionTerms(objPost, objContent);
            return(objContent);
        }
Esempio n. 13
0
        public void SaveJournalItem(JournalItem journalItem, int tabId)
        {
            if (journalItem.UserId < 1)
            {
                throw new ArgumentException("journalItem.UserId must be for a real user");
            }
            UserInfo currentUser = UserController.GetUserById(journalItem.PortalId, journalItem.UserId);

            if (currentUser == null)
            {
                throw new Exception("Unable to locate the current user");
            }

            string xml            = null;
            var    portalSecurity = new PortalSecurity();

            if (!String.IsNullOrEmpty(journalItem.Title))
            {
                journalItem.Title = portalSecurity.InputFilter(journalItem.Title, PortalSecurity.FilterFlag.NoMarkup);
            }
            if (!String.IsNullOrEmpty(journalItem.Summary))
            {
                journalItem.Summary = HttpUtility.HtmlDecode(portalSecurity.InputFilter(journalItem.Summary, PortalSecurity.FilterFlag.NoScripting));
            }
            if (!String.IsNullOrEmpty(journalItem.Body))
            {
                journalItem.Body = HttpUtility.HtmlDecode(portalSecurity.InputFilter(journalItem.Body, PortalSecurity.FilterFlag.NoScripting));
            }

            if (!String.IsNullOrEmpty(journalItem.Body))
            {
                var        xDoc   = new XmlDocument();
                XmlElement xnode  = xDoc.CreateElement("items");
                XmlElement xnode2 = xDoc.CreateElement("item");
                xnode2.AppendChild(CreateElement(xDoc, "id", "-1"));
                xnode2.AppendChild(CreateCDataElement(xDoc, "body", journalItem.Body));
                xnode.AppendChild(xnode2);
                xDoc.AppendChild(xnode);
                XmlDeclaration xDec = xDoc.CreateXmlDeclaration("1.0", null, null);
                xDec.Encoding   = "UTF-16";
                xDec.Standalone = "yes";
                XmlElement root = xDoc.DocumentElement;
                xDoc.InsertBefore(xDec, root);
                journalItem.JournalXML = xDoc;
                xml = journalItem.JournalXML.OuterXml;
            }
            if (journalItem.ItemData != null)
            {
                if (!String.IsNullOrEmpty(journalItem.ItemData.Title))
                {
                    journalItem.ItemData.Title = portalSecurity.InputFilter(journalItem.ItemData.Title, PortalSecurity.FilterFlag.NoMarkup);
                }
                if (!String.IsNullOrEmpty(journalItem.ItemData.Description))
                {
                    journalItem.ItemData.Description = HttpUtility.HtmlDecode(portalSecurity.InputFilter(journalItem.ItemData.Description, PortalSecurity.FilterFlag.NoScripting));
                }
                if (!String.IsNullOrEmpty(journalItem.ItemData.Url))
                {
                    journalItem.ItemData.Url = portalSecurity.InputFilter(journalItem.ItemData.Url, PortalSecurity.FilterFlag.NoScripting);
                }
                if (!String.IsNullOrEmpty(journalItem.ItemData.ImageUrl))
                {
                    journalItem.ItemData.ImageUrl = portalSecurity.InputFilter(journalItem.ItemData.ImageUrl, PortalSecurity.FilterFlag.NoScripting);
                }
            }
            string journalData = journalItem.ItemData.ToJson();

            if (journalData == "null")
            {
                journalData = null;
            }
            if (String.IsNullOrEmpty(journalItem.SecuritySet))
            {
                journalItem.SecuritySet = "E,";
            }
            else if (!journalItem.SecuritySet.EndsWith(","))
            {
                journalItem.SecuritySet += ",";
            }
            if (journalItem.SecuritySet == "F,")
            {
                journalItem.SecuritySet  = "F" + journalItem.UserId.ToString(CultureInfo.InvariantCulture) + ",";
                journalItem.SecuritySet += "P" + journalItem.ProfileId.ToString(CultureInfo.InvariantCulture) + ",";
            }
            if (journalItem.SecuritySet == "U,")
            {
                journalItem.SecuritySet += "U" + journalItem.UserId.ToString(CultureInfo.InvariantCulture) + ",";
            }
            if (journalItem.ProfileId > 0 && journalItem.UserId != journalItem.ProfileId)
            {
                journalItem.SecuritySet += "P" + journalItem.ProfileId.ToString(CultureInfo.InvariantCulture) + ",";
                journalItem.SecuritySet += "U" + journalItem.UserId.ToString(CultureInfo.InvariantCulture) + ",";
            }
            if (!journalItem.SecuritySet.Contains("U" + journalItem.UserId.ToString(CultureInfo.InvariantCulture)))
            {
                journalItem.SecuritySet += "U" + journalItem.UserId.ToString(CultureInfo.InvariantCulture) + ",";
            }
            if (journalItem.SocialGroupId > 0)
            {
                JournalItem item = journalItem;
                RoleInfo    role = TestableRoleController.Instance.GetRole(journalItem.PortalId, r => r.SecurityMode != SecurityMode.SecurityRole && r.RoleID == item.SocialGroupId);
                if (role != null)
                {
                    if (currentUser.IsInRole(role.RoleName))
                    {
                        journalItem.SecuritySet += "R" + journalItem.SocialGroupId.ToString(CultureInfo.InvariantCulture) + ",";
                        if (!role.IsPublic)
                        {
                            journalItem.SecuritySet = journalItem.SecuritySet.Replace("E,", String.Empty);
                        }
                    }
                }
            }
            journalItem.JournalId = _dataService.Journal_Save(journalItem.PortalId,
                                                              journalItem.UserId,
                                                              journalItem.ProfileId,
                                                              journalItem.SocialGroupId,
                                                              journalItem.JournalId,
                                                              journalItem.JournalTypeId,
                                                              journalItem.Title,
                                                              journalItem.Summary,
                                                              journalItem.Body,
                                                              journalData,
                                                              xml,
                                                              journalItem.ObjectKey,
                                                              journalItem.AccessKey,
                                                              journalItem.SecuritySet);

            var updatedJournalItem = GetJournalItem(journalItem.PortalId, journalItem.UserId, journalItem.JournalId);

            journalItem.DateCreated = updatedJournalItem.DateCreated;
            journalItem.DateUpdated = updatedJournalItem.DateUpdated;

            var cnt = new Content();

            if (journalItem.ContentItemId > 0)
            {
                cnt.UpdateContentItem(journalItem, tabId);
                _dataService.Journal_UpdateContentItemId(journalItem.JournalId, journalItem.ContentItemId);
            }
            else
            {
                ContentItem ci = cnt.CreateContentItem(journalItem, tabId);
                _dataService.Journal_UpdateContentItemId(journalItem.JournalId, ci.ContentItemId);
                journalItem.ContentItemId = ci.ContentItemId;
            }
            if (journalItem.SocialGroupId > 0)
            {
                try
                {
                    UpdateGroupStats(journalItem.PortalId, journalItem.SocialGroupId);
                }
                catch (Exception exc)
                {
                    Exceptions.Exceptions.LogException(exc);
                }
            }
        }
Esempio n. 14
0
        // none of the parameters should be null; checked before calling this method
        private void PrepareSecuritySet(JournalItem journalItem, UserInfo currentUser)
        {
            var originalSecuritySet =
                journalItem.SecuritySet = (journalItem.SecuritySet ?? string.Empty).ToUpperInvariant();

            if (string.IsNullOrEmpty(journalItem.SecuritySet))
            {
                journalItem.SecuritySet = "E,";
            }
            else if (!journalItem.SecuritySet.EndsWith(","))
            {
                journalItem.SecuritySet += ",";
                originalSecuritySet      = journalItem.SecuritySet;
            }

            if (journalItem.SecuritySet == "F,")
            {
                journalItem.SecuritySet = "F" + journalItem.UserId + ",";
                if (journalItem.ProfileId > 0)
                {
                    journalItem.SecuritySet += "P" + journalItem.ProfileId + ",";
                }
            }
            else if (journalItem.SecuritySet == "U,")
            {
                journalItem.SecuritySet += "U" + journalItem.UserId + ",";
            }
            else if (journalItem.SecuritySet == "R,")
            {
                if (journalItem.SocialGroupId > 0)
                {
                    journalItem.SecuritySet += "R" + journalItem.SocialGroupId + ",";
                }
            }

            if (journalItem.ProfileId > 0 && journalItem.UserId != journalItem.ProfileId)
            {
                if (!journalItem.SecuritySet.Contains("P" + journalItem.ProfileId + ","))
                {
                    journalItem.SecuritySet += "P" + journalItem.ProfileId + ",";
                }

                if (!journalItem.SecuritySet.Contains("U" + journalItem.UserId + ","))
                {
                    journalItem.SecuritySet += "U" + journalItem.UserId + ",";
                }
            }

            if (!journalItem.SecuritySet.Contains("U" + journalItem.UserId + ","))
            {
                journalItem.SecuritySet += "U" + journalItem.UserId + ",";
            }

            // if the post is marked as private, we shouldn't make it visible to the group.
            if (journalItem.SocialGroupId > 0 && originalSecuritySet.Contains("U,"))
            {
                var item = journalItem;
                var role = RoleController.Instance.GetRole(
                    journalItem.PortalId,
                    r => r.SecurityMode != SecurityMode.SecurityRole && r.RoleID == item.SocialGroupId);

                if (role != null && !role.IsPublic)
                {
                    journalItem.SecuritySet = journalItem.SecuritySet.Replace("E,", string.Empty).Replace("C,", string.Empty);
                }
            }

            // clean up and remove duplicates
            var parts = journalItem.SecuritySet
                        .Replace(" ", string.Empty)
                        .Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)
                        .Distinct()
                        .Except(InvalidSecuritySetsWithoutId)
                        .Where(p => p.IndexOfAny(ValidSecurityDescriptors) >= 0);

            // TODO: validate existence and visibility/accessability of all Roles added to the set (if any)
            journalItem.SecuritySet = string.Join(",", parts);
        }
Esempio n. 15
0
        internal string GetCommentRow(JournalItem journal, CommentInfo comment) {
            var sb = new StringBuilder();
            string pic = string.Format(Globals.UserProfilePicRelativeUrl(), comment.UserId, 32, 32);
            sb.AppendFormat("<li id=\"cmt-{0}\">", comment.CommentId);
            if (comment.UserId == CurrentUser.UserID || journal.UserId == CurrentUser.UserID || isAdmin) {
                sb.Append("<div class=\"miniclose\"></div>");
            }
            sb.AppendFormat("<img src=\"{0}\" />", pic);
            sb.Append("<p>");
            string userUrl = Globals.NavigateURL(PortalSettings.UserTabId, string.Empty, new[] { "userId=" + comment.UserId });
            sb.AppendFormat("<a href=\"{1}\">{0}</a>", comment.DisplayName, userUrl);
            
            if (comment.CommentXML != null && comment.CommentXML.SelectSingleNode("/root/comment") != null)
            {
                string text;
                var regex = new Regex(@"\<\!\[CDATA\[(?<text>[^\]]*)\]\]\>");
                if (regex.IsMatch(comment.CommentXML.SelectSingleNode("/root/comment").InnerText))
                {
                    var match = regex.Match(comment.CommentXML.SelectSingleNode("/root/comment").InnerText);
                    text = match.Groups["text"].Value;                
                }
                else
                {
                    text = comment.CommentXML.SelectSingleNode("/root/comment").InnerText;
                }
                sb.Append(text.Replace("\n", "<br />"));
            }
            else
            {
                sb.Append(comment.Comment.Replace("\n", "<br />"));
            }           

            var timeFrame = DateUtils.CalculateDateForDisplay(comment.DateCreated);
            comment.DateCreated = CurrentUser.LocalTime(comment.DateCreated);
            sb.AppendFormat("<abbr title=\"{0}\">{1}</abbr>", comment.DateCreated, timeFrame);
  
            sb.Append("</p>");
            sb.Append("</li>");
            return sb.ToString();
        }
Esempio n. 16
0
        internal string GetJournalTemplate(string journalType, JournalItem ji) {
            string template = Services.Localization.Localization.GetString("journal_" + journalType, resxPath);
            if (String.IsNullOrEmpty(template))
            {
                template = Services.Localization.Localization.GetString("journal_generic", resxPath);
            }

            template = Regex.Replace(template, "\\[BaseUrl\\]", url, RegexOptions.IgnoreCase);
            template = template.Replace("[journalitem:action]", Services.Localization.Localization.GetString(journalType + ".Action", resxPath));
            string pattern = "{CanComment}(.*?){/CanComment}";
            string replacement = string.Empty;
            if (CurrentUser.UserID > 0 && SocialGroupId <= 0) {
                replacement = "$1";
            }
            if (CurrentUser.UserID > 0 && ji.SocialGroupId > 0) {
                if (CurrentUser.IsInRole(ji.JournalOwner.Name)) {
                    replacement = "$1";
                } else {
                    replacement = string.Empty;
                }
            }
            template = Regex.Replace(template, pattern, replacement, RegexOptions.IgnoreCase);

            return template;
        }
        public void AddAnnouncementToJournal(AnnouncementInfo announcement, int tabId, String journalType)
        {

            var objJournalType = JournalController.Instance.GetJournalType(journalType);

            var journalItem = new JournalItem
            {
                PortalId = announcement.PortalID,
                ProfileId = announcement.LastModifiedByUserID,
                UserId = announcement.LastModifiedByUserID,
                ContentItemId = announcement.ContentItemID,
                Title = announcement.Title
            };
            var data = new ItemData
            {
                Url = announcement.Permalink()
            };
            journalItem.ItemData = data;
            journalItem.Summary = HtmlUtils.Shorten(HtmlUtils.Clean(System.Web.HttpUtility.HtmlDecode(announcement.Description), false), 250, "...");
            journalItem.Body = announcement.Description;
            journalItem.JournalTypeId = objJournalType.JournalTypeId;
            journalItem.SecuritySet = "E,";

            JournalController.Instance.SaveJournalItem(journalItem, tabId);

        }
Esempio n. 18
0
        /// <summary>
        /// Informs the core journal that the user has earned a new privilege.
        /// </summary>
        /// <param name="objPrivilege"></param>
        /// <param name="title"></param>
        /// <param name="summary"></param>
        /// <param name="portalId"></param>
        /// <param name="tabId"></param>
        /// <param name="journalUserId"></param>
        /// <param name="url"></param>
        internal void AddPrivilegeToJournal(QaSettingInfo objPrivilege, string title, string summary, int portalId, int tabId, int journalUserId, string url)
        {
            var objectKey = Constants.ContentTypeName + "_" + Constants.JournalPrivilegeTypeName + "_" + objPrivilege.Key;
            var ji = JournalController.Instance.GetJournalItemByKey(portalId, objectKey);

            if ((ji != null))
            {
                JournalController.Instance.DeleteJournalItemByKey(portalId, objectKey);
            }

            ji = new JournalItem
            {
                PortalId = portalId,
                ProfileId = journalUserId,
                UserId = journalUserId,
                Title = title,
                ItemData = new ItemData { Url = url },
                Summary = "", // summary,
                Body = null,
                JournalTypeId = GetPrivilegeJournalTypeID(portalId),
                ObjectKey = objectKey,
                SecuritySet = "E,"
            };

            JournalController.Instance.SaveJournalItem(ji, tabId);
        }
Esempio n. 19
0
 private string GetStringReplacement(JournalItem journalItem)
 {
     string replacement = string.Empty;
     if (CurrentUser.UserID > 0 && SocialGroupId <= 0 && !isUnverifiedUser)
     {
         replacement = "$1";
     }
     if (CurrentUser.UserID > 0 && journalItem.SocialGroupId > 0 && !isUnverifiedUser)
     {
         replacement = CurrentUser.IsInRole(journalItem.JournalOwner.Name) ? "$1" : string.Empty;
     }
     return replacement;
 }
Esempio n. 20
0
        public void AddTopicToJournal(int PortalId, int ModuleId, int ForumId, int TopicId, int UserId, string URL, string Subject, string Summary, string Body, int SecurityOption, string ReadRoles, int SocialGroupId)
        {

            var ji = new JournalItem
                         {
                             PortalId = PortalId,
                             ProfileId = UserId,
                             UserId = UserId,
                             Title = Subject,
                             ItemData = new ItemData { Url = URL }
                         };
            if (string.IsNullOrEmpty(Summary))
            {
                Summary = Utilities.StripHTMLTag(Body);
                if (Summary.Length > 150)
                {
                    Summary = Summary.Substring(0, 150) + "...";
                }
            }
            ji.Summary = Summary;
            ji.Body = Utilities.StripHTMLTag(Body);
            ji.JournalTypeId = 5;
            ji.ObjectKey = string.Format("{0}:{1}", ForumId.ToString(), TopicId.ToString());
            if (JournalController.Instance.GetJournalItemByKey(PortalId, ji.ObjectKey) != null)
            {
                JournalController.Instance.DeleteJournalItemByKey(PortalId, ji.ObjectKey);
            }
            string roles = string.Empty;
            if (!(string.IsNullOrEmpty(ReadRoles)))
            {
                if (ReadRoles.Contains("|"))
                {
                    roles = ReadRoles.Substring(0, ReadRoles.IndexOf("|", StringComparison.Ordinal) - 1);
                }
            }

            foreach (string s in roles.Split(';'))
            {
                if ((s == "-1") | (s == "-3"))
                {
                    /* cjh - securityset was null and throwing an error, thus journal items weren't added */
                    if ((ji.SecuritySet != null) && !(ji.SecuritySet.Contains("E,")))
                    {
                        ji.SecuritySet += "E,";
                    }
                }
                else
                {
                    ji.SecuritySet += "R" + s + ",";
                }

            }
            if (SocialGroupId > 0)
            {

                ji.SocialGroupId = SocialGroupId;

            }
            JournalController.Instance.SaveJournalItem(ji, -1);


           
        }
Esempio n. 21
0
        public HttpResponseMessage Create(CreateDTO postData)
        {
            try
            {
                var journalTypeId = 1;
                switch (postData.JournalType)
                {
                    case "link":
                        journalTypeId = 2;
                        break;
                    case "photo":
                        journalTypeId = 3;
                        break;
                    case "file":
                        journalTypeId = 4;
                        break;
                }

                if (postData.ProfileId == -1)
                {
                    postData.ProfileId = UserInfo.UserID;
                }

                if (postData.GroupId > 0)
                {
                    postData.ProfileId = -1;
                }
                
                var ji = new JournalItem
                {
                    JournalId = -1,
                    JournalTypeId = journalTypeId,
                    PortalId = ActiveModule.OwnerPortalID,
                    UserId = UserInfo.UserID,
                    SocialGroupId = postData.GroupId,
                    ProfileId = postData.ProfileId,
                    Summary = postData.Text,
                    SecuritySet = postData.SecuritySet
                };
                ji.Title = HttpUtility.HtmlDecode(HttpUtility.UrlDecode(ji.Title));
                ji.Summary = HttpUtility.HtmlDecode(HttpUtility.UrlDecode(ji.Summary));

                var ps = new PortalSecurity();

                ji.Title = ps.InputFilter(ji.Title, PortalSecurity.FilterFlag.NoScripting);
                ji.Title = Utilities.RemoveHTML(ji.Title);
                ji.Title = ps.InputFilter(ji.Title, PortalSecurity.FilterFlag.NoMarkup);

                ji.Summary = ps.InputFilter(ji.Summary, PortalSecurity.FilterFlag.NoScripting);
                ji.Summary = Utilities.RemoveHTML(ji.Summary);
                ji.Summary = ps.InputFilter(ji.Summary, PortalSecurity.FilterFlag.NoMarkup);

                if (ji.Summary.Length > 2000)
                {
                    ji.Body = ji.Summary;
                    ji.Summary = null;
                }

                if (!string.IsNullOrEmpty(postData.ItemData))
                {
                    ji.ItemData = postData.ItemData.FromJson<ItemData>();
                    ji.ItemData.Description = HttpUtility.UrlDecode(ji.ItemData.Description);

                    if (!string.IsNullOrEmpty(ji.ItemData.Url) && ji.ItemData.Url.StartsWith("fileid="))
                    {
                        var fileId = Convert.ToInt32(ji.ItemData.Url.Replace("fileid=", string.Empty).Trim());
                        var file = FileManager.Instance.GetFile(fileId);
                        ji.ItemData.Title = file.FileName;
						ji.ItemData.Url = Globals.LinkClick(ji.ItemData.Url, Null.NullInteger, Null.NullInteger);
                    }
                }

                JournalController.Instance.SaveJournalItem(ji, 1);

                return Request.CreateResponse(HttpStatusCode.OK, ji);
            }
            catch (Exception exc)
            {
                Logger.Error(exc);
                return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc);
            }
        }
Esempio n. 22
0
        public ActionResult Create(string text, int profileId, string journalType, string itemData, string securitySet, int groupId)
        {
            try
            {
                var journalTypeId = 1;
                switch (journalType)
                {
                    case "link":
                        journalTypeId = 2;
                        break;
                    case "photo":
                        journalTypeId = 3;
                        break;
                    case "file":
                        journalTypeId = 4;
                        break;
                }

                if (profileId == -1)
                {
                    profileId = UserInfo.UserID;
                }

                if (groupId > 0)
                {
                    profileId = -1;
                }
                
                var ji = new JournalItem
                {
                    JournalId = -1,
                    JournalTypeId = journalTypeId,
                    PortalId = PortalSettings.PortalId,
                    UserId = UserInfo.UserID,
                    SocialGroupId = groupId,
                    ProfileId = profileId,
                    Summary = text,
                    SecuritySet = securitySet
                };
                ji.Title = HttpUtility.HtmlDecode(HttpUtility.UrlDecode(ji.Title));
                ji.Summary = HttpUtility.HtmlDecode(HttpUtility.UrlDecode(ji.Summary));

                Security.PortalSecurity ps = new Security.PortalSecurity();

                ji.Title = ps.InputFilter(ji.Title, Security.PortalSecurity.FilterFlag.NoScripting);
                ji.Title = Utilities.RemoveHTML(ji.Title);
                ji.Title = ps.InputFilter(ji.Title, Security.PortalSecurity.FilterFlag.NoMarkup);

                ji.Summary = ps.InputFilter(ji.Summary, Security.PortalSecurity.FilterFlag.NoScripting);
                ji.Summary = Utilities.RemoveHTML(ji.Summary);
                ji.Summary = ps.InputFilter(ji.Summary, Security.PortalSecurity.FilterFlag.NoMarkup);

                if (ji.Summary.Length > 2000)
                {
                    ji.Body = ji.Summary;
                    ji.Summary = null;
                }

                if (!string.IsNullOrEmpty(itemData))
                {
                    ji.ItemData = itemData.FromJson<ItemData>();
                    ji.ItemData.Description = HttpUtility.UrlDecode(ji.ItemData.Description);

                    if (!string.IsNullOrEmpty(ji.ItemData.Url) && ji.ItemData.Url.StartsWith("fileid="))
                    {
                        var fileId = Convert.ToInt32(ji.ItemData.Url.Replace("fileid=", string.Empty).Trim());
                        var file = FileManager.Instance.GetFile(fileId);
                        ji.ItemData.Title = file.FileName;
                        ji.ItemData.Url = string.Format("{0}/LinkClick.aspx?fileticket={1}", Globals.ApplicationPath, UrlUtils.EncryptParameter(UrlUtils.GetParameterValue(ji.ItemData.Url)));
                    }
                }

                JournalController.Instance.SaveJournalItem(ji, 1);

                return Json(ji);
            }
            catch (Exception exc)
            {
                DnnLog.Error(exc);
                return Json(new { Result = "error" });
            }
        }
Esempio n. 23
0
 public void UpdateJournalItem(JournalItem journalItem, int tabId)
 {
     UpdateJournalItem(journalItem, tabId, Null.NullInteger);
 }
Esempio n. 24
0
 public void SaveJournalItem(JournalItem journalItem, int tabId)
 {
     SaveJournalItem(journalItem, tabId, Null.NullInteger);
 }
Esempio n. 25
0
        private void SendMentionNotifications(IDictionary<string, UserInfo> mentionedUsers, JournalItem item, string originalSummary, string type = "Post")
        {
            //send notification to the mention users
            var subjectTemplate = Utilities.GetSharedResource("Notification_Mention.Subject");
            var bodyTemplate = Utilities.GetSharedResource("Notification_Mention.Body");
            var mentionType = Utilities.GetSharedResource("Notification_MentionType_" + type);
            var notificationType = DotNetNuke.Services.Social.Notifications.NotificationsController.Instance.GetNotificationType("JournalMention");

            foreach (var key in mentionedUsers.Keys)
            {
                var mentionUser = mentionedUsers[key];
                var mentionText = originalSummary.Substring(originalSummary.IndexOf(MentionIdentityChar + key, StringComparison.InvariantCultureIgnoreCase));
                if (mentionText.Length > MentionNotificationLength)
                {
                    mentionText = mentionText.Substring(0, MentionNotificationLength) + MentionNotificationSuffix;
                }
                var notification = new Notification
                {
                    Subject = string.Format(subjectTemplate, UserInfo.DisplayName, mentionType),
                    Body = string.Format(bodyTemplate, mentionText),
                    NotificationTypeID = notificationType.NotificationTypeId,
                    SenderUserID = UserInfo.UserID,
                    IncludeDismissAction = true,
                    Context = string.Format("{0}_{1}", UserInfo.UserID, item.JournalId)
                };

                Services.Social.Notifications.NotificationsController.Instance.SendNotification(notification, PortalSettings.PortalId, null, new List<UserInfo> { mentionUser });
            }
        }
Esempio n. 26
0
        internal string GetJournalTemplate(string journalType, JournalItem ji) 
        {
            string template = Localization.GetString("journal_" + journalType, ResxPath);
            if (String.IsNullOrEmpty(template))
            {
                template = Localization.GetString("journal_generic", ResxPath);
            }

            template = Regex.Replace(template, "\\[BaseUrl\\]", url, RegexOptions.IgnoreCase);
            template = template.Replace("[journalitem:action]", Localization.GetString(journalType + ".Action", ResxPath));

            const string pattern = "{CanComment}(.*?){/CanComment}";
            string replacement = GetStringReplacement(ji);

            template = Regex.Replace(template, pattern, replacement, RegexOptions.IgnoreCase);

            return template;
        }
Esempio n. 27
0
		internal string GetLikeListHTML(JournalItem ji, ref bool isLiked) 
        {
			var sb = new StringBuilder();
            isLiked = false;
			if (ji.JournalXML == null) {
				return string.Empty;
			}
			XmlNodeList xLikes = ji.JournalXML.DocumentElement.SelectNodes("//likes/u");
			if (xLikes == null){
				return string.Empty;
			}
			 foreach(XmlNode xLike in xLikes) {
				if (Convert.ToInt32(xLike.Attributes["uid"].Value) == CurrentUser.UserID){
					ji.CurrentUserLikes = true;
                    isLiked = true;
					break;
				}

			}
			 int xc = 0;
			sb.Append("<div class=\"likes\">");
			if (xLikes.Count == 1 && ji.CurrentUserLikes) {
				sb.Append("{resx:youlikethis}");
			} else if (xLikes.Count > 1) {
				if (ji.CurrentUserLikes) {
					sb.Append("{resx:you}");
					xc += 1;
				}
				foreach (XmlNode l in xLikes) {
					int userId = Convert.ToInt32(l.Attributes["uid"].Value);
					string name = l.Attributes["un"].Value;
					if (userId != CurrentUser.UserID) {
						if (xc < xLikes.Count - 1 && xc > 0 && xc < 3) {
							sb.Append(", ");
						} else if (xc > 0 & xc < xLikes.Count & xc < 3) {
							sb.Append(" {resx:and} ");
						} else if (xc >= 3) {
							int diff = (xLikes.Count - xc);
							sb.Append(" {resx:and} " + (xLikes.Count - xc).ToString(CultureInfo.InvariantCulture));
							if (diff > 1) {
								sb.Append(" {resx:others}");
							} else {
								sb.Append(" {resx:other}");
							}
							break; // TODO: might not be correct. Was : Exit For
						}
						sb.AppendFormat("<span id=\"user-{0}\" class=\"juser\">{1}</span>", userId, name);
						xc += 1;
					}
				}
				if (xc == 1) {
					sb.Append(" {resx:likesthis}");
				} else if (xc>1) {
					sb.Append(" {resx:likethis}");
				}

		} else {
			foreach (XmlNode l in xLikes) {
				int userId = Convert.ToInt32(l.Attributes["uid"].Value);
				string name = l.Attributes["un"].Value;
				sb.AppendFormat("<span id=\"user-{0}\" class=\"juser\">{1}</span>", userId, name);
				xc += 1;
				if (xc == xLikes.Count - 1) {
					sb.Append(" {resx:and} ");
				} else if (xc < xLikes.Count - 1) {
					sb.Append(", ");
				}
			}
			if (xc == 1) {
				sb.Append(" {resx:likesthis}");
			} else if (xc>1) {
				sb.Append(" {resx:likethis}");
			}
		}

		   
			sb.Append("</div>");
			return sb.ToString();
		}
        // Journal Items
        public void SaveJournalItem(JournalItem journalItem, int tabId, int moduleId)
        {
            if (journalItem.UserId < 1)
            {
                throw new ArgumentException("journalItem.UserId must be for a real user");
            }
            UserInfo currentUser = UserController.GetUserById(journalItem.PortalId, journalItem.UserId);
            if (currentUser == null)
            {
                throw new Exception("Unable to locate the current user");
            }

            string xml = null;
            var portalSecurity = new PortalSecurity();
            if (!String.IsNullOrEmpty(journalItem.Title))
            {
                journalItem.Title = portalSecurity.InputFilter(journalItem.Title, PortalSecurity.FilterFlag.NoMarkup);
            }
            if (!String.IsNullOrEmpty(journalItem.Summary))
            {
                journalItem.Summary = HttpUtility.HtmlDecode(portalSecurity.InputFilter(journalItem.Summary, PortalSecurity.FilterFlag.NoScripting));
            }
            if (!String.IsNullOrEmpty(journalItem.Body))
            {
                journalItem.Body = HttpUtility.HtmlDecode(portalSecurity.InputFilter(journalItem.Body, PortalSecurity.FilterFlag.NoScripting));
            }

            if (!String.IsNullOrEmpty(journalItem.Body))
            {
                var xDoc = new XmlDocument();
                XmlElement xnode = xDoc.CreateElement("items");
                XmlElement xnode2 = xDoc.CreateElement("item");
                xnode2.AppendChild(CreateElement(xDoc, "id", "-1"));
                xnode2.AppendChild(CreateCDataElement(xDoc, "body", journalItem.Body));
                xnode.AppendChild(xnode2);
                xDoc.AppendChild(xnode);
                XmlDeclaration xDec = xDoc.CreateXmlDeclaration("1.0", null, null);
                xDec.Encoding = "UTF-16";
                xDec.Standalone = "yes";
                XmlElement root = xDoc.DocumentElement;
                xDoc.InsertBefore(xDec, root);
                journalItem.JournalXML = xDoc;
                xml = journalItem.JournalXML.OuterXml;
            }
            if (journalItem.ItemData != null)
            {
                if (!String.IsNullOrEmpty(journalItem.ItemData.Title))
                {
                    journalItem.ItemData.Title = portalSecurity.InputFilter(journalItem.ItemData.Title, PortalSecurity.FilterFlag.NoMarkup);
                }
                if (!String.IsNullOrEmpty(journalItem.ItemData.Description))
                {
                    journalItem.ItemData.Description = HttpUtility.HtmlDecode(portalSecurity.InputFilter(journalItem.ItemData.Description, PortalSecurity.FilterFlag.NoScripting));
                }
                if (!String.IsNullOrEmpty(journalItem.ItemData.Url))
                {
                    journalItem.ItemData.Url = portalSecurity.InputFilter(journalItem.ItemData.Url, PortalSecurity.FilterFlag.NoScripting);
                }
                if (!String.IsNullOrEmpty(journalItem.ItemData.ImageUrl))
                {
                    journalItem.ItemData.ImageUrl = portalSecurity.InputFilter(journalItem.ItemData.ImageUrl, PortalSecurity.FilterFlag.NoScripting);
                }
            }
            string journalData = journalItem.ItemData.ToJson();
            if (journalData == "null")
            {
                journalData = null;
            }

            PrepareSecuritySet(journalItem, currentUser);

            journalItem.JournalId = _dataService.Journal_Save(journalItem.PortalId,
                                                     journalItem.UserId,
                                                     journalItem.ProfileId,
                                                     journalItem.SocialGroupId,
                                                     journalItem.JournalId,
                                                     journalItem.JournalTypeId,
                                                     journalItem.Title,
                                                     journalItem.Summary,
                                                     journalItem.Body,
                                                     journalData,
                                                     xml,
                                                     journalItem.ObjectKey,
                                                     journalItem.AccessKey,
                                                     journalItem.SecuritySet,
                                                     journalItem.CommentsDisabled,
                                                     journalItem.CommentsHidden);

            var updatedJournalItem = GetJournalItem(journalItem.PortalId, journalItem.UserId, journalItem.JournalId);
            journalItem.DateCreated = updatedJournalItem.DateCreated;
            journalItem.DateUpdated = updatedJournalItem.DateUpdated;
            var cnt = new Content();

            if (journalItem.ContentItemId > 0)
            {
                cnt.UpdateContentItem(journalItem, tabId, moduleId);
                _dataService.Journal_UpdateContentItemId(journalItem.JournalId, journalItem.ContentItemId);
            }
            else
            {
                ContentItem ci = cnt.CreateContentItem(journalItem, tabId, moduleId);
                _dataService.Journal_UpdateContentItemId(journalItem.JournalId, ci.ContentItemId);
                journalItem.ContentItemId = ci.ContentItemId;
            }
            if (journalItem.SocialGroupId > 0)
            {
                try
                {
                    UpdateGroupStats(journalItem.PortalId, journalItem.SocialGroupId);
                }
                catch (Exception exc)
                {
                    Exceptions.Exceptions.LogException(exc);
                }
            }
        }
Esempio n. 29
0
        // Journal Items
        public void SaveJournalItem(JournalItem journalItem, int tabId, int moduleId)
        {
            if (journalItem.UserId < 1)
            {
                throw new ArgumentException("journalItem.UserId must be for a real user");
            }

            UserInfo currentUser = UserController.GetUserById(journalItem.PortalId, journalItem.UserId);

            if (currentUser == null)
            {
                throw new Exception("Unable to locate the current user");
            }

            string xml            = null;
            var    portalSecurity = PortalSecurity.Instance;

            if (!string.IsNullOrEmpty(journalItem.Title))
            {
                journalItem.Title = portalSecurity.InputFilter(journalItem.Title, PortalSecurity.FilterFlag.NoMarkup);
            }

            if (!string.IsNullOrEmpty(journalItem.Summary))
            {
                journalItem.Summary = portalSecurity.InputFilter(journalItem.Summary, PortalSecurity.FilterFlag.NoScripting);
            }

            if (!string.IsNullOrEmpty(journalItem.Body))
            {
                journalItem.Body = portalSecurity.InputFilter(journalItem.Body, PortalSecurity.FilterFlag.NoScripting);
            }

            if (!string.IsNullOrEmpty(journalItem.Body))
            {
                var xDoc = new XmlDocument {
                    XmlResolver = null
                };
                XmlElement xnode  = xDoc.CreateElement("items");
                XmlElement xnode2 = xDoc.CreateElement("item");
                xnode2.AppendChild(this.CreateElement(xDoc, "id", "-1"));
                xnode2.AppendChild(this.CreateCDataElement(xDoc, "body", journalItem.Body));
                xnode.AppendChild(xnode2);
                xDoc.AppendChild(xnode);
                XmlDeclaration xDec = xDoc.CreateXmlDeclaration("1.0", null, null);
                xDec.Encoding   = "UTF-16";
                xDec.Standalone = "yes";
                XmlElement root = xDoc.DocumentElement;
                xDoc.InsertBefore(xDec, root);
                journalItem.JournalXML = xDoc;
                xml = journalItem.JournalXML.OuterXml;
            }

            if (journalItem.ItemData != null)
            {
                if (!string.IsNullOrEmpty(journalItem.ItemData.Title))
                {
                    journalItem.ItemData.Title = portalSecurity.InputFilter(journalItem.ItemData.Title, PortalSecurity.FilterFlag.NoMarkup);
                }

                if (!string.IsNullOrEmpty(journalItem.ItemData.Description))
                {
                    journalItem.ItemData.Description = portalSecurity.InputFilter(journalItem.ItemData.Description, PortalSecurity.FilterFlag.NoScripting);
                }

                if (!string.IsNullOrEmpty(journalItem.ItemData.Url))
                {
                    journalItem.ItemData.Url = portalSecurity.InputFilter(journalItem.ItemData.Url, PortalSecurity.FilterFlag.NoScripting);
                }

                if (!string.IsNullOrEmpty(journalItem.ItemData.ImageUrl))
                {
                    journalItem.ItemData.ImageUrl = portalSecurity.InputFilter(journalItem.ItemData.ImageUrl, PortalSecurity.FilterFlag.NoScripting);
                }
            }

            string journalData = journalItem.ItemData.ToJson();

            if (journalData == "null")
            {
                journalData = null;
            }

            this.PrepareSecuritySet(journalItem, currentUser);

            journalItem.JournalId = this._dataService.Journal_Save(
                journalItem.PortalId,
                journalItem.UserId,
                journalItem.ProfileId,
                journalItem.SocialGroupId,
                journalItem.JournalId,
                journalItem.JournalTypeId,
                journalItem.Title,
                journalItem.Summary,
                journalItem.Body,
                journalData,
                xml,
                journalItem.ObjectKey,
                journalItem.AccessKey,
                journalItem.SecuritySet,
                journalItem.CommentsDisabled,
                journalItem.CommentsHidden);

            var updatedJournalItem = this.GetJournalItem(journalItem.PortalId, journalItem.UserId, journalItem.JournalId);

            journalItem.DateCreated = updatedJournalItem.DateCreated;
            journalItem.DateUpdated = updatedJournalItem.DateUpdated;
            var cnt = new Content();

            if (journalItem.ContentItemId > 0)
            {
                cnt.UpdateContentItem(journalItem, tabId, moduleId);
                this._dataService.Journal_UpdateContentItemId(journalItem.JournalId, journalItem.ContentItemId);
            }
            else
            {
                ContentItem ci = cnt.CreateContentItem(journalItem, tabId, moduleId);
                this._dataService.Journal_UpdateContentItemId(journalItem.JournalId, ci.ContentItemId);
                journalItem.ContentItemId = ci.ContentItemId;
            }

            if (journalItem.SocialGroupId > 0)
            {
                try
                {
                    this.UpdateGroupStats(journalItem.PortalId, journalItem.SocialGroupId);
                }
                catch (Exception exc)
                {
                    Exceptions.Exceptions.LogException(exc);
                }
            }
        }
        public void UpdateJournalItem(JournalItem journalItem, int tabId, int moduleId)
        {
            if (journalItem.UserId < 1)
            {
                throw new ArgumentException("journalItem.UserId must be for a real user");
            }
            UserInfo currentUser = UserController.GetUserById(journalItem.PortalId, journalItem.UserId);
            if (currentUser == null)
            {
                throw new Exception("Unable to locate the current user");
            }
            string xml = null;
            var portalSecurity = new PortalSecurity();
            if (!String.IsNullOrEmpty(journalItem.Title))
            {
                journalItem.Title = portalSecurity.InputFilter(journalItem.Title, PortalSecurity.FilterFlag.NoMarkup);
            }
            if (!String.IsNullOrEmpty(journalItem.Summary))
            {
                journalItem.Summary = HttpUtility.HtmlDecode(portalSecurity.InputFilter(journalItem.Summary, PortalSecurity.FilterFlag.NoScripting));
            }
            if (!String.IsNullOrEmpty(journalItem.Body))
            {
                journalItem.Body = HttpUtility.HtmlDecode(portalSecurity.InputFilter(journalItem.Body, PortalSecurity.FilterFlag.NoScripting));
            }
            if (!String.IsNullOrEmpty(journalItem.Body))
            {
                var xDoc = new XmlDocument();
                XmlElement xnode = xDoc.CreateElement("items");
                XmlElement xnode2 = xDoc.CreateElement("item");
                xnode2.AppendChild(CreateElement(xDoc, "id", "-1"));
                xnode2.AppendChild(CreateCDataElement(xDoc, "body", journalItem.Body));
                xnode.AppendChild(xnode2);
                xDoc.AppendChild(xnode);
                XmlDeclaration xDec = xDoc.CreateXmlDeclaration("1.0", null, null);
                xDec.Encoding = "UTF-16";
                xDec.Standalone = "yes";
                XmlElement root = xDoc.DocumentElement;
                xDoc.InsertBefore(xDec, root);
                journalItem.JournalXML = xDoc;
                xml = journalItem.JournalXML.OuterXml;
            }
            if (journalItem.ItemData != null)
            {
                if (!String.IsNullOrEmpty(journalItem.ItemData.Title))
                {
                    journalItem.ItemData.Title = portalSecurity.InputFilter(journalItem.ItemData.Title, PortalSecurity.FilterFlag.NoMarkup);
                }
                if (!String.IsNullOrEmpty(journalItem.ItemData.Description))
                {
                    journalItem.ItemData.Description = HttpUtility.HtmlDecode(portalSecurity.InputFilter(journalItem.ItemData.Description, PortalSecurity.FilterFlag.NoScripting));
                }
                if (!String.IsNullOrEmpty(journalItem.ItemData.Url))
                {
                    journalItem.ItemData.Url = portalSecurity.InputFilter(journalItem.ItemData.Url, PortalSecurity.FilterFlag.NoScripting);
                }
                if (!String.IsNullOrEmpty(journalItem.ItemData.ImageUrl))
                {
                    journalItem.ItemData.ImageUrl = portalSecurity.InputFilter(journalItem.ItemData.ImageUrl, PortalSecurity.FilterFlag.NoScripting);
                }
            }
            string journalData = journalItem.ItemData.ToJson();
            if (journalData == "null")
            {
                journalData = null;
            }
            if (String.IsNullOrEmpty(journalItem.SecuritySet))
            {
                journalItem.SecuritySet = "E,";
            }
            else if (!journalItem.SecuritySet.EndsWith(","))
            {
                journalItem.SecuritySet += ",";
            }
            if (journalItem.SecuritySet == "F,")
            {
                journalItem.SecuritySet = "F" + journalItem.UserId.ToString(CultureInfo.InvariantCulture) + ",";
                journalItem.SecuritySet += "P" + journalItem.ProfileId.ToString(CultureInfo.InvariantCulture) + ",";
            }
            if (journalItem.SecuritySet == "U,")
            {
                journalItem.SecuritySet += "U" + journalItem.UserId.ToString(CultureInfo.InvariantCulture) + ",";
            }
            if (journalItem.ProfileId > 0 && journalItem.UserId != journalItem.ProfileId)
            {
                journalItem.SecuritySet += "P" + journalItem.ProfileId.ToString(CultureInfo.InvariantCulture) + ",";
                journalItem.SecuritySet += "U" + journalItem.UserId.ToString(CultureInfo.InvariantCulture) + ",";
            }
            if (!journalItem.SecuritySet.Contains("U" + journalItem.UserId.ToString(CultureInfo.InvariantCulture)))
            {
                journalItem.SecuritySet += "U" + journalItem.UserId.ToString(CultureInfo.InvariantCulture) + ",";
            }
            if (journalItem.SocialGroupId > 0)
            {
                JournalItem item = journalItem;
                RoleInfo role = RoleController.Instance.GetRole(journalItem.PortalId, r => r.SecurityMode != SecurityMode.SecurityRole && r.RoleID == item.SocialGroupId);
                if (role != null)
                {
                    if (currentUser.IsInRole(role.RoleName))
                    {
                        journalItem.SecuritySet += "R" + journalItem.SocialGroupId.ToString(CultureInfo.InvariantCulture) + ",";
                        if (!role.IsPublic)
                        {
                            journalItem.SecuritySet = journalItem.SecuritySet.Replace("E,", String.Empty);
                        }
                    }
                }
            }
            journalItem.JournalId = _dataService.Journal_Update(journalItem.PortalId,
                                                     journalItem.UserId,
                                                     journalItem.ProfileId,
                                                     journalItem.SocialGroupId,
                                                     journalItem.JournalId,
                                                     journalItem.JournalTypeId,
                                                     journalItem.Title,
                                                     journalItem.Summary,
                                                     journalItem.Body,
                                                     journalData,
                                                     xml,
                                                     journalItem.ObjectKey,
                                                     journalItem.AccessKey,
                                                     journalItem.SecuritySet,
                                                     journalItem.CommentsDisabled,
                                                     journalItem.CommentsHidden);

            var updatedJournalItem = GetJournalItem(journalItem.PortalId, journalItem.UserId, journalItem.JournalId);
            journalItem.DateCreated = updatedJournalItem.DateCreated;
            journalItem.DateUpdated = updatedJournalItem.DateUpdated;

            var cnt = new Content();
            if (journalItem.ContentItemId > 0)
            {
                cnt.UpdateContentItem(journalItem, tabId, moduleId);
                _dataService.Journal_UpdateContentItemId(journalItem.JournalId, journalItem.ContentItemId);
            }
            else
            {
                ContentItem ci = cnt.CreateContentItem(journalItem, tabId, moduleId);
                _dataService.Journal_UpdateContentItemId(journalItem.JournalId, ci.ContentItemId);
                journalItem.ContentItemId = ci.ContentItemId;
            }
            if (journalItem.SocialGroupId > 0)
            {
                try
                {
                    UpdateGroupStats(journalItem.PortalId, journalItem.SocialGroupId);
                }
                catch (Exception exc)
                {
                    Exceptions.Exceptions.LogException(exc);
                }
            }
        }
        public void UpdateJournalItem(JournalItem journalItem, ModuleInfo module)
        {
            var tabId = module == null ? Null.NullInteger : module.TabID;
            var tabModuleId = module == null ? Null.NullInteger : module.TabModuleID;

            UpdateJournalItem(journalItem, tabId, tabModuleId);
        }
 public void SaveJournalItem(JournalItem journalItem, int tabId)
 {
     SaveJournalItem(journalItem, tabId, Null.NullInteger);
 }
Esempio n. 33
0
 /// <summary>
 /// Creates the content text
 /// </summary>
 /// <param name="objJournalItem"></param>
 /// <returns></returns>
 private static string GetContentBody(JournalItem objJournalItem) {
     if (!string.IsNullOrEmpty(objJournalItem.Title)) {
         return objJournalItem.Title;
     } else if (!string.IsNullOrEmpty(objJournalItem.Summary)) {
         return objJournalItem.Summary;
     } else if (!string.IsNullOrEmpty(objJournalItem.Body)) {
         return objJournalItem.Body;
     } else {
         return null;
     }
 }
 public void UpdateJournalItem(JournalItem journalItem, int tabId)
 {
     UpdateJournalItem(journalItem, tabId, Null.NullInteger);
 }
        // none of the parameters should be null; checked before calling this method
        private void PrepareSecuritySet(JournalItem journalItem, UserInfo currentUser)
        {
            var originalSecuritySet =
                journalItem.SecuritySet = (journalItem.SecuritySet ??string.Empty).ToUpperInvariant();

            if (String.IsNullOrEmpty(journalItem.SecuritySet))
            {
                journalItem.SecuritySet = "E,";
            }
            else if (!journalItem.SecuritySet.EndsWith(","))
            {
                journalItem.SecuritySet += ",";
                originalSecuritySet = journalItem.SecuritySet;
            }

            if (journalItem.SecuritySet == "F,")
            {
                journalItem.SecuritySet = "F" + journalItem.UserId + ",";
                if (journalItem.ProfileId > 0)
                    journalItem.SecuritySet += "P" + journalItem.ProfileId + ",";
            }
            else if (journalItem.SecuritySet == "U,")
            {
                journalItem.SecuritySet += "U" + journalItem.UserId + ",";
            }
            else if (journalItem.SecuritySet == "R,")
            {
                if (journalItem.SocialGroupId > 0)
                    journalItem.SecuritySet += "R" + journalItem.SocialGroupId + ",";
            }

            if (journalItem.ProfileId > 0 && journalItem.UserId != journalItem.ProfileId)
            {
                if (!journalItem.SecuritySet.Contains("P" + journalItem.ProfileId + ","))
                {
                    journalItem.SecuritySet += "P" + journalItem.ProfileId + ",";
                }

                if (!journalItem.SecuritySet.Contains("U" + journalItem.UserId + ","))
                {
                    journalItem.SecuritySet += "U" + journalItem.UserId + ",";
                }
            }

            if (!journalItem.SecuritySet.Contains("U" + journalItem.UserId + ","))
            {
                journalItem.SecuritySet += "U" + journalItem.UserId + ",";
            }

            //if the post is marked as private, we shouldn't make it visible to the group.
            if (journalItem.SocialGroupId > 0 && originalSecuritySet.Contains("U,"))
            {
                var item = journalItem;
                var role = RoleController.Instance.GetRole(journalItem.PortalId,
                    r => r.SecurityMode != SecurityMode.SecurityRole && r.RoleID == item.SocialGroupId);

                if (role != null && !role.IsPublic)
                {
                    journalItem.SecuritySet = journalItem.SecuritySet.Replace("E,", String.Empty).Replace("C,", String.Empty);
                }
            }

            // clean up and remove duplicates
            var parts = journalItem.SecuritySet
                .Replace(" ", "")
                .Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)
                .Distinct()
                .Except(InvalidSecuritySetsWithoutId)
                .Where(p => p.IndexOfAny(ValidSecurityDescriptors) >= 0);

            //TODO: validate existence and visibility/accessability of all Roles added to the set (if any)

            journalItem.SecuritySet = string.Join(",", parts);
        }
Esempio n. 36
0
        internal string GetCommentAreaHTML(JournalItem journal, IList<CommentInfo> comments) {
            if (journal.CommentsHidden)
            {
                return string.Empty;
            }
            var sb = new StringBuilder();
			sb.AppendFormat("<ul class=\"jcmt\" id=\"jcmt-{0}\">", journal.JournalId);
            foreach(CommentInfo ci in comments) {
				if (ci.JournalId == journal.JournalId)
				{
					sb.Append(GetCommentRow(journal, ci));
                }
            }
			if (CurrentUser.UserID > 0 && !journal.CommentsDisabled)
			{
				sb.AppendFormat("<li id=\"jcmt-{0}-txtrow\" class=\"cmteditarea\">", journal.JournalId);
				sb.AppendFormat("<textarea id=\"jcmt-{0}-txt\" class=\"cmteditor\"></textarea>", journal.JournalId);
                sb.Append("<div class=\"editorPlaceholder\">{resx:leavecomment}</div></li>");
                sb.Append("<li class=\"cmtbtn\">");
                sb.Append("<a href=\"#\">{resx:comment}</a></li>");
            }
            
            sb.Append("</ul>");
            return sb.ToString();
        }