November Happy Hour will be moved to Thursday December 5th.

Anders Hattestad
Oct 27, 2011
  4915
(0 votes)

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.

image

The front end code is like this (some Norwegian thou)

Code Snippet
  1. <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="EditUserVarslingsMail.ascx.cs" Inherits="Custom.Plugins.EditUserVarslingsMail" %>
  2. <h2>Varslinger på ulike deler av siten</h2>
  3. <fieldset>
  4.     <div>
  5.         <asp:Label ID="Label2" Text="<%$ Resources: EPiServer, subscription.interval %>" CssClass="topLabel" AssociatedControlID="Interval" runat="server" />
  6.         <asp:DropDownList ID="Interval" runat="Server">
  7.             <asp:ListItem Value="0" Text="<%$ Resources: EPiServer, subscription.fastaspossible %>" />
  8.             <asp:ListItem Value="1" Text="<%$ Resources: EPiServer, subscription.daily %>" />
  9.             <asp:ListItem Value="7" Text="<%$ Resources: EPiServer, subscription.weekly %>" />
  10.             <asp:ListItem Value="30" Text="<%$ Resources: EPiServer, subscription.monthly %>" />
  11.         </asp:DropDownList>
  12.     </div>
  13.     <div class="subscriptionListArea">
  14.         <asp:CheckBoxList ID="SubscriptonOn" runat="server" />
  15.     </div>
  16. </fieldset>

and the backend code is this

Code Snippet
  1. [GuiPlugIn(
  2.      DisplayName = "Varslings mail",
  3.      Description = "More information about the user",
  4.      Url = "~/Custom/Plugins/EditUserVarslingsMail.ascx",
  5.      Area = PlugInArea.SidSettingsArea)]
  6.     public partial class EditUserVarslingsMail : System.Web.UI.UserControl, IUserSettings
  7.     {
  8.         protected void Page_Load(object sender, EventArgs e)
  9.         {
  10.         }
  11.         #region IUserSettings Members
  12.         public void LoadSettings(string userName, EPiServer.Personalization.EPiServerProfile data)
  13.         {
  14.             SetUp();
  15.             if (SubscriptonOn.Items.Count == 0)
  16.             {
  17.                 foreach (ListItem item in Interval.Items)
  18.                     item.Selected = Int32.Parse(item.Value) == data.SubscriptionInfo.Interval;
  19.                 foreach (PageData page in GetSubscriptionPages(null))
  20.                 {
  21.                     ListItem item = new ListItem();
  22.                     item.Attributes.Add("title", GetPath(page));
  23.                     item.Text = page.PageName + " [" + page.LanguageID + "]";
  24.                     if (data.SubscriptionInfo.IsSubscribingTo(page.PageLink, page.LanguageID))
  25.                         item.Selected = true;
  26.                     item.Value = page.PageLink.ID + "|" + page.LanguageID;
  27.                     SubscriptonOn.Items.Add(item);
  28.                 }
  29.             }
  30.         }
  31.  
  32.         public bool SaveRequiresUIReload
  33.         {
  34.             get
  35.             {
  36.                 return false;
  37.             }
  38.             set
  39.             {
  40.  
  41.             }
  42.         }
  43.         public string GetID(object o)
  44.         {
  45.             return (o as PageData).PageLink.ID.ToString();
  46.         }
  47.         public static string GetPath(object o)
  48.         {
  49.             PageData page = o as PageData;
  50.             string result = "";
  51.             while (page != null)
  52.             {
  53.                 if (result != "")
  54.                     result = " / " + result;
  55.                 result = page.PageName + result;
  56.                 if (PageReference.IsNullOrEmpty(page.ParentLink) || page.ParentLink.CompareToIgnoreWorkID(PageReference.RootPage))
  57.                     page = null;
  58.                
  59.                 else
  60.                     page = EPiServer.DataFactory.Instance.GetPage(page.ParentLink);
  61.  
  62.             }
  63.             return result;
  64.         }
  65.         public void SaveSettings(string userName, EPiServer.Personalization.EPiServerProfile data)
  66.         {
  67.            
  68.  
  69.             data.SubscriptionInfo.Interval = Int32.Parse(Interval.SelectedItem.Value);
  70.             foreach (ListItem item in SubscriptonOn.Items)
  71.             {
  72.                 string[] parts = item.Value.Split("|".ToCharArray());
  73.                 int pageID = int.Parse(parts[0]);
  74.  
  75.  
  76.                 if (item.Selected)
  77.                 {
  78.                     if (!data.SubscriptionInfo.IsSubscribingTo(PageReference.Parse(parts[0]), parts[1]))
  79.                     {
  80.                         data.SubscriptionInfo.SubscribeTo(PageReference.Parse(parts[0]), parts[1]);
  81.                     }
  82.                 }
  83.                 else
  84.                 {
  85.                     if (data.SubscriptionInfo.IsSubscribingTo(PageReference.Parse(parts[0]), parts[1]))
  86.                     {
  87.                         data.SubscriptionInfo.UnSubscribe(PageReference.Parse(parts[0]), parts[1]);
  88.                     }
  89.                 }
  90.             }
  91.         }
  92.  
  93.         #endregion
  94.  
  95.         void SetUp()
  96.         {
  97.         }
  98.  
  99.         public static PageDataCollection GetSubscriptionPages(string lang)
  100.         {
  101.             PageDataCollection pages = new PageDataCollection();
  102.             PropertySearchDB hdb = new PropertySearchDB();
  103.             foreach (PageReference reference in hdb.FindPagesWithProperty(PageReference.RootPage.ID, "EPSUBSCRIBE", "EPSUBSCRIBEHIDDEN", lang))
  104.             {
  105.                 try
  106.                 {
  107.                     pages.Add(DataFactory.Instance.GetPage(reference));
  108.                 }
  109.                 catch (AccessDeniedException)
  110.                 {
  111.                 }
  112.             }
  113.             PageDataCollection sortedPages = new PageDataCollection();
  114.             foreach (var page in pages)
  115.             {
  116.                 if (!page.IsDeleted && ((PropertyBoolean)page.Property["EPSUBSCRIBE"]).Boolean)
  117.                     sortedPages.Add(page);
  118.             }
  119.  
  120.             return sortedPages;
  121.         }
  122.     }

So when you go into admin and find a user your admin user plugin is there an gives you the opportunity to get alerts.

Oct 27, 2011

Comments

Sandor Voordes
Sandor Voordes Oct 10, 2012 05:06 PM

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


Jonathan Roberts
Jonathan Roberts Apr 16, 2013 01:58 PM

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

Please login to comment.
Latest blogs
Optimizely SaaS CMS + Coveo Search Page

Short on time but need a listing feature with filters, pagination, and sorting? Create a fully functional Coveo-powered search page driven by data...

Damian Smutek | Nov 21, 2024 | Syndicated blog

Optimizely SaaS CMS DAM Picker (Interim)

Simplify your Optimizely SaaS CMS workflow with the Interim DAM Picker Chrome extension. Seamlessly integrate your DAM system, streamlining asset...

Andy Blyth | Nov 21, 2024 | Syndicated blog

Optimizely CMS Roadmap

Explore Optimizely CMS's latest roadmap, packed with developer-focused updates. From SaaS speed to Visual Builder enhancements, developer tooling...

Andy Blyth | Nov 21, 2024 | Syndicated blog

Set Default Culture in Optimizely CMS 12

Take control over culture-specific operations like date and time formatting.

Tomas Hensrud Gulla | Nov 15, 2024 | Syndicated blog

I'm running Optimizely CMS on .NET 9!

It works 🎉

Tomas Hensrud Gulla | Nov 12, 2024 | Syndicated blog

Recraft's image generation with AI-Assistant for Optimizely

Recraft V3 model is outperforming all other models in the image generation space and we are happy to share: Recraft's new model is now available fo...

Luc Gosso (MVP) | Nov 8, 2024 | Syndicated blog