A critical vulnerability was discovered in React Server Components (Next.js). Our systems remain protected but we advise to update packages to newest version. Learn More

Anders Hattestad
Oct 27, 2011
  2888
(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

Please login to comment.
Latest blogs
A day in the life of an Optimizely OMVP: Learning Optimizely Just Got Easier: Introducing the Optimizely Learning Centre

On the back of my last post about the Opti Graph Learning Centre, I am now happy to announce a revamped interactive learning platform that makes...

Graham Carr | Jan 31, 2026

Scheduled job for deleting content types and all related content

In my previous blog post which was about getting an overview of your sites content https://world.optimizely.com/blogs/Per-Nergard/Dates/2026/1/sche...

Per Nergård (MVP) | Jan 30, 2026

Working With Applications in Optimizely CMS 13

💡 Note:  The following content has been written based on Optimizely CMS 13 Preview 2 and may not accurately reflect the final release version. As...

Mark Stott | Jan 30, 2026

Experimentation at Speed Using Optimizely Opal and Web Experimentation

If you are working in experimentation, you will know that speed matters. The quicker you can go from idea to implementation, the faster you can...

Minesh Shah (Netcel) | Jan 30, 2026

How to run Optimizely CMS on VS Code Dev Containers

VS Code Dev Containers is an extension that allows you to use a Docker container as a full-featured development environment. Instead of installing...

Daniel Halse | Jan 30, 2026

A day in the life of an Optimizely OMVP: Introducing Optimizely Graph Learning Centre Beta: Master GraphQL for Content Delivery

GraphQL is transforming how developers query and deliver content from Optimizely CMS. But let's be honest—there's a learning curve. Between...

Graham Carr | Jan 30, 2026