public static List <TagCloudItem> GetTagCloud(int numberTagClasses, QuickParametersTag quickParameters) { List <TagCloudItem> tagCloud = new List <TagCloudItem>(); DataObjectList <DataObjectTag> tags = DataObjects.Load <DataObjectTag>(quickParameters); if (tags.Count > 0) { decimal relevanceGap = tags[0].Relevance - tags[tags.Count - 1].Relevance; decimal minRelevance = tags[tags.Count - 1].Relevance; decimal ratio = relevanceGap / (decimal)numberTagClasses; if (ratio == 0) { ratio = 1; } foreach (DataObjectTag tag in tags) { int tagClass = Math.Max(1, (int)((tag.Relevance - minRelevance) / ratio + 0.5m)); tagCloud.Add(new TagCloudItem(tag, tagClass)); } tagCloud.Sort(new TitleSorterTag()); } return(tagCloud); }
public new void Delete(bool showStateOnly) { DataObjectList <DataObject> relatedObjects = DataObjects.Load <DataObject>(new QuickParameters() { RelationParams = new RelationParams() { ParentObjectID = this.ObjectID }, Udc = this.userDataContext, DisablePaging = true, Amount = 999999 }); foreach (var relatedObject in relatedObjects) { relatedObject.Delete(showStateOnly); } base.Delete(showStateOnly); }
public static void SetPictureRelationsFromContent(string content, DataObject dataObject, string relationType, bool copyFirstImage) { DataObject.RelDelete(new RelationParams() { ParentObjectID = dataObject.ObjectID, ParentObjectType = Helper.GetObjectTypeNumericID("Article"), ChildObjectType = Helper.GetObjectTypeNumericID("Picture") }); MatchCollection images = Regex.Matches(content, @"<img(.*?)>", RegexOptions.IgnoreCase | RegexOptions.Multiline); int insertNumber = 0; foreach (Match match in images) { Match idMatch = Regex.Match(match.Groups[1].Value, @"id="".*?_(.*?)""", RegexOptions.IgnoreCase | RegexOptions.Multiline); //Match pvMatch = Regex.Match(match.Groups[1].Value, @"pv=""(.*?)""", RegexOptions.IgnoreCase | RegexOptions.Multiline); //Match pvpMatch = Regex.Match(match.Groups[1].Value, @"pvp=""(.*?)""", RegexOptions.IgnoreCase | RegexOptions.Multiline); if (idMatch.Success) { Guid objectId = idMatch.Groups[1].Value.ToGuid(); //PictureVersion pictureVersion = (PictureVersion)Enum.Parse(typeof(PictureVersion), pvMatch.Groups[1].Value); //string popupVersion = pvpMatch.Groups[1].Value; DataObject.RelInsert(new RelationParams() { ParentObjectID = dataObject.ObjectID, ParentObjectType = Helper.GetObjectTypeNumericID("Article"), ChildObjectID = objectId, ChildObjectType = Helper.GetObjectTypeNumericID("Picture"), RelationType = relationType }, insertNumber++); } } if (copyFirstImage) { DataObjectList <DataObjectPicture> pictures = DataObjects.Load <DataObjectPicture>(new QuickParameters { Udc = UserDataContext.GetUserDataContext(), ShowState = null, RelationParams = new RelationParams { ParentObjectID = dataObject.ObjectID.Value } } ); if (pictures.Count > 0) { string mediaSource = string.Format(@"{0}\{1}\P\{{0}}\{2}.jpg", ConfigurationManager.AppSettings["ConverterRootPathMedia"], pictures[0].UserID, pictures[0].ObjectID); string mediaTarget = string.Format(@"{0}\{1}\P\{{0}}\{2}.jpg", ConfigurationManager.AppSettings["ConverterRootPathMedia"], dataObject.UserID, dataObject.ObjectID); foreach (var pictureFormat in pictures[0].PictureFormats) { if (!string.IsNullOrEmpty(pictureFormat.Value)) { dataObject.SetImageType(pictureFormat.Key, (PictureFormat)Enum.Parse(typeof(PictureFormat), pictureFormat.Value)); File.Copy(string.Format(mediaSource, pictureFormat.Key), string.Format(mediaTarget, pictureFormat.Key), true); } } dataObject.Image = dataObject.ObjectID.Value.ToString(); } } }
public static string GetFeed(QuickParameters quickParameters, string type) { string urlPrefix = System.Configuration.ConfigurationManager.AppSettings["HostName"] + HttpContext.Current.Request.ApplicationPath; UserDataContext udc = UserDataContext.GetUserDataContext(); quickParameters.Udc = udc; quickParameters.ObjectTypes = QuickParameters.GetDelimitedObjectTypeIDs(rssEngineConfig.ObjectTypes, ','); quickParameters.SortBy = QuickSort.StartDate; //quickParameters.FromStartDate = DateTime.Now - new TimeSpan(rssEngineConfig.Days, 0, 0, 0); quickParameters.Amount = rssEngineConfig.MaxItems; quickParameters.PageSize = rssEngineConfig.MaxItems; StringBuilder sb; List <string> titleSegments = new List <string>(); SyndicationFeed feed = new SyndicationFeed(); if (quickParameters.CommunityID.HasValue) { DataObjectCommunity channelCommunity = DataObject.Load <DataObjectCommunity>(quickParameters.CommunityID); if (channelCommunity.State != ObjectState.Added) { if (channelCommunity.ObjectType == Helper.GetObjectTypeNumericID("ProfileCommunity")) { titleSegments.Add(string.Format("Von {0}", channelCommunity.Nickname)); } else { titleSegments.Add(string.Format("Von {0}", channelCommunity.Title)); } } } else if (quickParameters.UserID.HasValue) { Business.DataObjectUser channelUser = DataObject.Load <DataObjectUser>(quickParameters.UserID); if (channelUser.State != ObjectState.Added) { titleSegments.Add(string.Format("Von {0}", channelUser.Nickname)); } } if (!string.IsNullOrEmpty(quickParameters.RawTags1) || !string.IsNullOrEmpty(quickParameters.RawTags2) || !string.IsNullOrEmpty(quickParameters.RawTags3)) { titleSegments.Add(string.Format("Tags {0}", Helper.GetTagWordString(new List <string>() { quickParameters.RawTags1, quickParameters.RawTags2, quickParameters.RawTags3 }))); } sb = new StringBuilder(); if (titleSegments.Count > 0) { for (int i = 0; i < titleSegments.Count; i++) { sb.Append(titleSegments[i]); if (i < titleSegments.Count - 1) { sb.Append(", "); } } } else { sb.Append("Alles"); } string title = string.Format("{0} Feed - {1}", siteName, sb.ToString()); string description = "RSS Feed von " + siteName; feed.Title = TextSyndicationContent.CreatePlaintextContent(title); feed.Description = TextSyndicationContent.CreatePlaintextContent(description); feed.Links.Add(new SyndicationLink(new Uri(urlPrefix))); feed.Language = "de-CH"; List <SyndicationItem> items = new List <SyndicationItem>(); DataObjectList <DataObject> rssItems = DataObjects.Load <DataObject>(quickParameters); foreach (DataObject rssItem in rssItems) { SyndicationItem item = new SyndicationItem(); // Add prefix to title item.Title = TextSyndicationContent.CreatePlaintextContent("[" + Helper.GetObjectName(rssItem.ObjectType, true) + "] " + rssItem.Title); // Set owner as author SyndicationPerson author = new SyndicationPerson(); author.Name = rssItem.Nickname; item.Authors.Add(author); // Set object's guid item.Id = rssItem.objectID.Value.ToString(); // Link to the object string itemUrl = urlPrefix + Helper.GetDetailLink(rssItem.ObjectType, rssItem.objectID.Value.ToString()); item.AddPermalink(new Uri(itemUrl)); // Take start date as publish date item.PublishDate = rssItem.StartDate; // Image if available if (!string.IsNullOrEmpty(rssItem.GetImage(PictureVersion.S)) && rssItem.GetImage(PictureVersion.S).ToLower() != Helper.GetDefaultURLImageSmall(rssItem.ObjectType).ToLower()) { item.Content = SyndicationContent.CreateXhtmlContent("<div><a href=\"" + itemUrl + "\"><img src=\"" + System.Configuration.ConfigurationManager.AppSettings["MediaDomainName"] + rssItem.GetImage(PictureVersion.S) + "\"></a></div><div>" + rssItem.Description.StripHTMLTags().CropString(rssEngineConfig.MaxDescriptionLength) + "</div>"); } else { item.Content = TextSyndicationContent.CreatePlaintextContent(rssItem.Description.StripHTMLTags().CropString(rssEngineConfig.MaxDescriptionLength)); } items.Add(item); } feed.Items = items; sb = new StringBuilder(); XmlWriter xmlWriter = XmlWriter.Create(sb); if (type == "rss") { feed.SaveAsRss20(xmlWriter); } else if (type == "atom") { feed.SaveAsAtom10(xmlWriter); } xmlWriter.Close(); string feedXml = sb.ToString(); feedXml = Regex.Replace(feedXml, @"^<.*?xml.*?>\s*", ""); return(feedXml); }
public static string GetPlaylistFeed(Guid?objectId, VideoFormat videoFormat, VideoVersion videoVersion) { UserDataContext udc = UserDataContext.GetUserDataContext(); DataObjectVideo dataObjectVideo = DataObject.Load <DataObjectVideo>(objectId); DataObjectCommunity community = DataObject.Load <DataObjectCommunity>(dataObjectVideo.CommunityID); QuickParameters quickParameters = new QuickParameters(); quickParameters.Udc = udc; quickParameters.ObjectType = Helper.GetObjectTypeNumericID("Video"); quickParameters.SortBy = QuickSort.StartDate; quickParameters.Amount = 100; quickParameters.PageSize = 100; quickParameters.PageNumber = 1; quickParameters.ShowState = ObjectShowState.Published; if (community.ObjectType == Helper.GetObjectTypeNumericID("Community")) { quickParameters.CommunityID = community.ObjectID; } else if (community.ObjectType == Helper.GetObjectTypeNumericID("ProfileCommunity")) { quickParameters.UserID = community.UserID; } MediaSyndicationFeed feed = new MediaSyndicationFeed(); string title = string.Empty; if (community.ObjectType == Helper.GetObjectTypeNumericID("Community")) { title = "Video aus " + community.Title; } else if (community.ObjectType == Helper.GetObjectTypeNumericID("ProfileCommunity")) { title = "Videos von " + community.Nickname; } feed.Title = TextSyndicationContent.CreatePlaintextContent(title); //feed.Description = TextSyndicationContent.CreatePlaintextContent(""); string feedUrl = SiteConfig.SiteURL + Helper.GetDetailLink(community.ObjectType, community.ObjectID.Value.ToString()); feed.Links.Add(new SyndicationLink(new Uri(feedUrl))); feed.Language = "de-CH"; List <SyndicationItem> items = new List <SyndicationItem>(); DataObjectList <DataObjectVideo> videos = DataObjects.Load <DataObjectVideo>(quickParameters); foreach (DataObjectVideo video in videos) { MediaSyndicationItem item = new MediaSyndicationItem(); item.MediaContentUrl = new Uri(string.Format("{0}{1}", Helper.GetVideoBaseURL(), video.GetLocation(videoFormat, videoVersion))); item.MediaContentDuration = video.DurationSecond; item.MediaContentType = "video/x-flv"; item.MediaThumbnailUrl = new Uri(string.Format("{0}{1}", SiteConfig.MediaDomainName, video.GetImage(PictureVersion.S))); item.MediaKeywords = video.TagList.Replace(Constants.TAG_DELIMITER.ToString(), ", "); item.MediaCredit = video.Nickname; item.Title = TextSyndicationContent.CreatePlaintextContent(video.Title.StripHTMLTags()); item.Id = video.ObjectID.Value.ToString(); string itemUrl = SiteConfig.SiteURL + Helper.GetDetailLink(video.ObjectType, video.ObjectID.Value.ToString()); item.AddPermalink(new Uri(itemUrl)); item.PublishDate = video.StartDate; items.Add(item); } feed.Items = items; StringBuilder sb = new StringBuilder(); XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; XmlWriter xmlWriter = XmlWriter.Create(sb, settings); feed.SaveAsRss20(xmlWriter); xmlWriter.Close(); string feedXml = sb.ToString(); feedXml = Regex.Replace(feedXml, @"^<.*?xml.*?>\s*", ""); return(feedXml); }