User subscribe plugin
Often the editors need to get alerts when other editors publish new articles in one area of the site. This can subscribes template in EPiServer take care of. Even if you are not using the subscribes template you can make a user plugin that enables you to active subscription on certain areas.
Like this plugin that will list all pages that have EPSUBSCRIBE set to true and allow the selected user to subscribe.
The front end code is like this (some Norwegian thou)
- <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="EditUserVarslingsMail.ascx.cs" Inherits="Custom.Plugins.EditUserVarslingsMail" %>
- <h2>Varslinger på ulike deler av siten</h2>
- <fieldset>
- <div>
- <asp:Label ID="Label2" Text="<%$ Resources: EPiServer, subscription.interval %>" CssClass="topLabel" AssociatedControlID="Interval" runat="server" />
- <asp:DropDownList ID="Interval" runat="Server">
- <asp:ListItem Value="0" Text="<%$ Resources: EPiServer, subscription.fastaspossible %>" />
- <asp:ListItem Value="1" Text="<%$ Resources: EPiServer, subscription.daily %>" />
- <asp:ListItem Value="7" Text="<%$ Resources: EPiServer, subscription.weekly %>" />
- <asp:ListItem Value="30" Text="<%$ Resources: EPiServer, subscription.monthly %>" />
- </asp:DropDownList>
- </div>
- <div class="subscriptionListArea">
- <asp:CheckBoxList ID="SubscriptonOn" runat="server" />
- </div>
- </fieldset>
and the backend code is this
- [GuiPlugIn(
- DisplayName = "Varslings mail",
- Description = "More information about the user",
- Url = "~/Custom/Plugins/EditUserVarslingsMail.ascx",
- Area = PlugInArea.SidSettingsArea)]
- public partial class EditUserVarslingsMail : System.Web.UI.UserControl, IUserSettings
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- #region IUserSettings Members
- public void LoadSettings(string userName, EPiServer.Personalization.EPiServerProfile data)
- {
- SetUp();
- if (SubscriptonOn.Items.Count == 0)
- {
- foreach (ListItem item in Interval.Items)
- item.Selected = Int32.Parse(item.Value) == data.SubscriptionInfo.Interval;
- foreach (PageData page in GetSubscriptionPages(null))
- {
- ListItem item = new ListItem();
- item.Attributes.Add("title", GetPath(page));
- item.Text = page.PageName + " [" + page.LanguageID + "]";
- if (data.SubscriptionInfo.IsSubscribingTo(page.PageLink, page.LanguageID))
- item.Selected = true;
- item.Value = page.PageLink.ID + "|" + page.LanguageID;
- SubscriptonOn.Items.Add(item);
- }
- }
- }
- public bool SaveRequiresUIReload
- {
- get
- {
- return false;
- }
- set
- {
- }
- }
- public string GetID(object o)
- {
- return (o as PageData).PageLink.ID.ToString();
- }
- public static string GetPath(object o)
- {
- PageData page = o as PageData;
- string result = "";
- while (page != null)
- {
- if (result != "")
- result = " / " + result;
- result = page.PageName + result;
- if (PageReference.IsNullOrEmpty(page.ParentLink) || page.ParentLink.CompareToIgnoreWorkID(PageReference.RootPage))
- page = null;
- else
- page = EPiServer.DataFactory.Instance.GetPage(page.ParentLink);
- }
- return result;
- }
- public void SaveSettings(string userName, EPiServer.Personalization.EPiServerProfile data)
- {
- data.SubscriptionInfo.Interval = Int32.Parse(Interval.SelectedItem.Value);
- foreach (ListItem item in SubscriptonOn.Items)
- {
- string[] parts = item.Value.Split("|".ToCharArray());
- int pageID = int.Parse(parts[0]);
- if (item.Selected)
- {
- if (!data.SubscriptionInfo.IsSubscribingTo(PageReference.Parse(parts[0]), parts[1]))
- {
- data.SubscriptionInfo.SubscribeTo(PageReference.Parse(parts[0]), parts[1]);
- }
- }
- else
- {
- if (data.SubscriptionInfo.IsSubscribingTo(PageReference.Parse(parts[0]), parts[1]))
- {
- data.SubscriptionInfo.UnSubscribe(PageReference.Parse(parts[0]), parts[1]);
- }
- }
- }
- }
- #endregion
- void SetUp()
- {
- }
- public static PageDataCollection GetSubscriptionPages(string lang)
- {
- PageDataCollection pages = new PageDataCollection();
- PropertySearchDB hdb = new PropertySearchDB();
- foreach (PageReference reference in hdb.FindPagesWithProperty(PageReference.RootPage.ID, "EPSUBSCRIBE", "EPSUBSCRIBEHIDDEN", lang))
- {
- try
- {
- pages.Add(DataFactory.Instance.GetPage(reference));
- }
- catch (AccessDeniedException)
- {
- }
- }
- PageDataCollection sortedPages = new PageDataCollection();
- foreach (var page in pages)
- {
- if (!page.IsDeleted && ((PropertyBoolean)page.Property["EPSUBSCRIBE"]).Boolean)
- sortedPages.Add(page);
- }
- return sortedPages;
- }
- }
So when you go into admin and find a user your admin user plugin is there an gives you the opportunity to get alerts.
Hi Anders,
Before I dive intro you solution I hope you can point me into a descent article emplaining how to setup subscriptions in the first place. I can't seem to find anything when I search for EPiServer subscriptions or EPSUBSCRIBE. However I do see the service available in the Admin section. How can something so trivial be so hard? What am I missing?
Regards,
Sandor
Hi, I was wondering if Sandor has found anything regarding Subscriptions. Im in the same boat - I cant find any information on Subscriptions.
I have EPiserver 6 R2.
Jonathan