From ec4a44453776265d73c887d144c96191bdfba51f Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Fri, 23 Jul 2010 18:11:54 -0700 Subject: [PATCH] The Gallery Feeds get their title from the feed --HG-- branch : dev --- .../Controllers/GalleryController.cs | 28 +++++++++++++++---- .../ViewModels/PackagingAddSourceViewModel.cs | 3 -- .../Views/Gallery/AddSource.ascx | 2 -- .../Services/FeedStorage.cs | 4 ++- .../Web.config | 4 ++- 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Packaging/Controllers/GalleryController.cs b/src/Orchard.Web/Modules/Orchard.Packaging/Controllers/GalleryController.cs index ab66160b6..806806ad5 100644 --- a/src/Orchard.Web/Modules/Orchard.Packaging/Controllers/GalleryController.cs +++ b/src/Orchard.Web/Modules/Orchard.Packaging/Controllers/GalleryController.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using System.Web.Mvc; +using System.Xml.Linq; using Orchard.Environment.Extensions; using Orchard.Localization; using Orchard.Packaging.Services; @@ -8,6 +9,7 @@ using Orchard.Packaging.ViewModels; using Orchard.Themes; using Orchard.UI.Admin; using Orchard.UI.Notify; +using System.Xml.XPath; namespace Orchard.Packaging.Controllers { [OrchardFeature("Gallery")] @@ -58,23 +60,37 @@ namespace Orchard.Packaging.Controllers { } [HttpPost] - public ActionResult AddSource(string title, string url) { + public ActionResult AddSource(string url) { try { if ( !String.IsNullOrEmpty(url) ) { if (!url.StartsWith("http")) { - ModelState.AddModelError("Url", T("The Url is a valid").Text); + ModelState.AddModelError("Url", T("The Url is not valid").Text); } } else if ( String.IsNullOrWhiteSpace(url)) { ModelState.AddModelError("Url", T("Url is required").Text); } - if ( String.IsNullOrWhiteSpace(title) ) { - ModelState.AddModelError("Url", T("Title is required").Text); + string title = null; + // try to load the feed + try { + + XNamespace atomns = "http://www.w3.org/2005/Atom" ; + var feed = XDocument.Load(url, LoadOptions.PreserveWhitespace); + var titleNode = feed.Descendants(atomns + "title").FirstOrDefault(); + if ( titleNode != null ) + title = titleNode.Value; + + if(String.IsNullOrWhiteSpace(title)) { + ModelState.AddModelError("Url", T("The feed has no title.").Text); + } + } + catch { + ModelState.AddModelError("Url", T("The url of the feed or its content is not valid.").Text); } if ( !ModelState.IsValid ) - return AddSourceViewResult(new PackagingAddSourceViewModel(){Title = title, Url = url}); + return AddSourceViewResult(new PackagingAddSourceViewModel(){ Url = url }); _packagingSourceManager.AddSource(new PackagingSource { Id = Guid.NewGuid(), FeedUrl = url, FeedTitle = title }); _notifier.Information(T("The feed has been added successfully.")); @@ -83,7 +99,7 @@ namespace Orchard.Packaging.Controllers { } catch ( Exception exception ) { _notifier.Error(T("Adding feed failed: {0}", exception.Message)); - return AddSourceViewResult(new PackagingAddSourceViewModel() { Title = title, Url = url }); + return AddSourceViewResult(new PackagingAddSourceViewModel() { Url = url }); } } diff --git a/src/Orchard.Web/Modules/Orchard.Packaging/ViewModels/PackagingAddSourceViewModel.cs b/src/Orchard.Web/Modules/Orchard.Packaging/ViewModels/PackagingAddSourceViewModel.cs index 1b19a6774..4a4f326ad 100644 --- a/src/Orchard.Web/Modules/Orchard.Packaging/ViewModels/PackagingAddSourceViewModel.cs +++ b/src/Orchard.Web/Modules/Orchard.Packaging/ViewModels/PackagingAddSourceViewModel.cs @@ -5,8 +5,5 @@ namespace Orchard.Packaging.ViewModels { [Required] public string Url { get; set; } - - [Required] - public string Title { get; set; } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Packaging/Views/Gallery/AddSource.ascx b/src/Orchard.Web/Modules/Orchard.Packaging/Views/Gallery/AddSource.ascx index 1b139ba6e..f30548aba 100644 --- a/src/Orchard.Web/Modules/Orchard.Packaging/Views/Gallery/AddSource.ascx +++ b/src/Orchard.Web/Modules/Orchard.Packaging/Views/Gallery/AddSource.ascx @@ -5,8 +5,6 @@ <%using ( Html.BeginFormAntiForgeryPost(Url.Action("AddSource")) ) { %> <%: Html.ValidationSummary() %>
- -
diff --git a/src/Tools/PackageIndexReferenceImplementation/Services/FeedStorage.cs b/src/Tools/PackageIndexReferenceImplementation/Services/FeedStorage.cs index e226be531..584334967 100644 --- a/src/Tools/PackageIndexReferenceImplementation/Services/FeedStorage.cs +++ b/src/Tools/PackageIndexReferenceImplementation/Services/FeedStorage.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Configuration; using System.IO; using System.Linq; using System.ServiceModel.Syndication; @@ -14,7 +15,8 @@ namespace PackageIndexReferenceImplementation.Services { var formatter = new Atom10FeedFormatter(); var feedPath = HostingEnvironment.MapPath("~/App_Data/Feed.xml"); if (!File.Exists(feedPath)) { - return new SyndicationFeed(); + string title = ConfigurationManager.AppSettings["Title"]; + return new SyndicationFeed() { Title = new TextSyndicationContent(title)}; } using (var reader = XmlReader.Create(feedPath)) { formatter.ReadFrom(reader); diff --git a/src/Tools/PackageIndexReferenceImplementation/Web.config b/src/Tools/PackageIndexReferenceImplementation/Web.config index aca1cb27a..4bacee924 100644 --- a/src/Tools/PackageIndexReferenceImplementation/Web.config +++ b/src/Tools/PackageIndexReferenceImplementation/Web.config @@ -12,9 +12,11 @@ providerName="System.Data.SqlClient" /> + + + -