using System; using CMS.CMSHelper; using CMS.Controls; using CMS.GlobalHelper; using CMS.PortalControls; public partial class CMSWebParts_Syndication_Basic_AtomFeed : CMSAbstractWebPart { #region "Variables" private CMSBaseDataSource mDataSourceControl = null; private Guid mFeedGUID = Guid.Empty; #endregion #region "Atom Feed Properties" /// /// Querystring key which is used for Atom feed identification on a page with multiple Atom feeds. /// public string QueryStringKey { get { return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("QueryStringKey"), null), atomFeed.QueryStringKey); } set { SetValue("QueryStringKey", value); atomFeed.QueryStringKey = value; } } /// /// Feed name to identify this feed on a page with multiple feeds. If the value is empty the GUID of the web part instance will be used by default. /// public string FeedName { get { return DataHelper.GetNotEmpty(ValidationHelper.GetString(GetValue("FeedName"), null), GetIdentifier()); } set { string valueToSet = value; // If no feed name was specified if (string.IsNullOrEmpty(valueToSet)) { // Set default name valueToSet = GetIdentifier(); } SetValue("FeedName", valueToSet); atomFeed.FeedName = valueToSet; } } /// /// Text for the feed link. /// public string LinkText { get { return ValidationHelper.GetString(GetValue("LinkText"), string.Empty); } set { SetValue("LinkText", value); atomFeed.LinkText = value; } } /// /// Icon which will be displayed in the feed link. /// public string LinkIcon { get { return ValidationHelper.GetString(GetValue("LinkIcon"), string.Empty); } set { SetValue("LinkIcon", value); atomFeed.LinkIcon = value; } } /// /// Indicates if the Atom feed is automatically discovered by the browser. /// public bool EnableAtomAutodiscovery { get { return ValidationHelper.GetBoolean(GetValue("EnableAtomAutodiscovery"), true); } set { SetValue("EnableAtomAutodiscovery", value); atomFeed.EnableAutodiscovery = value; } } #endregion #region "Atom Repeater properties" /// /// URL title of the feed. /// public string FeedTitle { get { return ValidationHelper.GetString(GetValue("FeedTitle"), string.Empty); } set { SetValue("FeedTitle", value); atomFeed.FeedTitle = value; } } /// /// Subtitle/Description of the feed. /// public string FeedSubtitle { get { return ValidationHelper.GetString(GetValue("FeedSubtitle"), string.Empty); } set { SetValue("FeedSubtitle", value); atomFeed.FeedSubtitle = value; } } /// /// Language of the feed. If the value is empty the content culture will be used. /// public string FeedLanguage { get { string cultureCode = ValidationHelper.GetString(GetValue("FeedLanguage"), null); if (string.IsNullOrEmpty(cultureCode)) { cultureCode = CMSContext.PreferredCultureCode; } return cultureCode; } set { SetValue("FeedLanguage", value); atomFeed.FeedLanguage = value; } } /// /// The unique identifier of the feed. If the value is empty, Guid.Empty will be used. /// public Guid FeedGUID { get { if (mFeedGUID == Guid.Empty) { return InstanceGUID; } else { return mFeedGUID; } } set { Guid valueToSet = value; // If no feed GUID was specified if (valueToSet == Guid.Empty) { // Set default GUID valueToSet = InstanceGUID; } mFeedGUID = valueToSet; atomFeed.FeedGUID = valueToSet; } } /// /// Last significant modification date of the feed. /// public DateTime FeedUpdated { get { return ValidationHelper.GetDateTimeSystem(GetValue("FeedUpdated"), DateTimeHelper.ZERO_TIME); } set { SetValue("FeedUpdated", value); atomFeed.FeedUpdated = value; } } /// /// Author name of the feed. /// public string FeedAuthorName { get { return ValidationHelper.GetString(GetValue("FeedAuthorName"), string.Empty); } set { SetValue("FeedAuthorName", value); atomFeed.FeedAuthorName = value; } } /// /// Custom feed header XML which is generated before feed items. If the value is empty default header for Atom feed is generated. /// public string HeaderXML { get { return ValidationHelper.GetString(GetValue("HeaderXML"), null); } set { SetValue("HeaderXML", value); atomFeed.HeaderXML = value; } } /// /// Custom feed footer XML which is generated after feed items. If the value is empty default footer for Atom feed is generated. /// public string FooterXML { get { return ValidationHelper.GetString(GetValue("FooterXML"), null); } set { SetValue("FooterXML", value); atomFeed.FooterXML = value; } } #endregion #region "Datasource properties" /// /// Gets or sets name of source. /// public string DataSourceName { get { return ValidationHelper.GetString(GetValue("DataSourceName"), string.Empty); } set { SetValue("DataSourceName", value); atomFeed.DataSourceName = value; } } /// /// Control with data source. /// public CMSBaseDataSource DataSourceControl { get { return mDataSourceControl; } set { mDataSourceControl = value; atomFeed.DataSourceControl = value; } } /// /// Related data object. /// public override object RelatedData { get { if (atomFeed.DataSourceControl != null) { return atomFeed.DataSourceControl.RelatedData; } return base.RelatedData; } } #endregion #region "Cache properties" /// /// Gets or sets the cache item name. /// public override string CacheItemName { get { return ValidationHelper.GetString(base.CacheItemName, atomFeed.CacheItemName); } set { base.CacheItemName = value; atomFeed.CacheItemName = value; } } /// /// Cache dependencies, each cache dependency on a new line. /// public override string CacheDependencies { get { return ValidationHelper.GetString(base.CacheDependencies, atomFeed.CacheDependencies); } set { base.CacheDependencies = value; atomFeed.CacheDependencies = value; } } /// /// Gets or sets the cache minutes. /// public override int CacheMinutes { get { return base.CacheMinutes; } set { base.CacheMinutes = value; atomFeed.CacheMinutes = value; } } #endregion #region "Transformation properties" /// /// Gets or sets ItemTemplate property. /// public string TransformationName { get { return ValidationHelper.GetString(GetValue("TransformationName"), string.Empty); } set { SetValue("TransformationName", value); atomFeed.TransformationName = value; } } #endregion #region "Stop processing" /// /// Returns true if the control processing should be stopped. /// public override bool StopProcessing { get { return base.StopProcessing; } set { base.StopProcessing = value; atomFeed.StopProcessing = value; } } #endregion #region "Overidden methods" /// /// Content loaded event handler. /// public override void OnContentLoaded() { base.OnContentLoaded(); SetupControl(); } /// /// Reloads data. /// public override void ReloadData() { base.ReloadData(); SetupControl(); } #endregion #region "Setup control" /// /// Initializes the control properties. /// protected void SetupControl() { if (StopProcessing) { atomFeed.StopProcessing = true; } else { // Atom feed properties atomFeed.FeedName = FeedName; atomFeed.FeedLink = URLHelper.GetAbsoluteUrl(URLHelper.AddParameterToUrl(URLHelper.CurrentURL, QueryStringKey, FeedName)); atomFeed.LinkText = LinkText; atomFeed.LinkIcon = LinkIcon; atomFeed.FeedTitle = FeedTitle; atomFeed.FeedSubtitle = FeedSubtitle; atomFeed.FeedLanguage = FeedLanguage; atomFeed.FeedAuthorName = FeedAuthorName; atomFeed.FeedGUID = FeedGUID; atomFeed.FeedUpdated = FeedUpdated; atomFeed.EnableAutodiscovery = EnableAtomAutodiscovery; atomFeed.QueryStringKey = QueryStringKey; atomFeed.HeaderXML = HeaderXML; atomFeed.FooterXML = FooterXML; // Cache properties atomFeed.CacheItemName = CacheItemName; atomFeed.CacheDependencies = CacheDependencies; atomFeed.CacheMinutes = CacheMinutes; // Transformation properties atomFeed.TransformationName = TransformationName; // Datasource properties atomFeed.DataSourceName = DataSourceName; } } #endregion }