Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Anders Hattestad
Oct 27, 2011
  4829
(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
Solving the mystery of high memory usage

Sometimes, my work is easy, the problem could be resolved with one look (when I’m lucky enough to look at where it needs to be looked, just like th...

Quan Mai | Apr 22, 2024 | Syndicated blog

Search & Navigation reporting improvements

From version 16.1.0 there are some updates on the statistics pages: Add pagination to search phrase list Allows choosing a custom date range to get...

Phong | Apr 22, 2024

Optimizely and the never-ending story of the missing globe!

I've worked with Optimizely CMS for 14 years, and there are two things I'm obsessed with: Link validation and the globe that keeps disappearing on...

Tomas Hensrud Gulla | Apr 18, 2024 | Syndicated blog

Visitor Groups Usage Report For Optimizely CMS 12

This add-on offers detailed information on how visitor groups are used and how effective they are within Optimizely CMS. Editors can monitor and...

Adnan Zameer | Apr 18, 2024 | Syndicated blog

Azure AI Language – Abstractive Summarisation in Optimizely CMS

In this article, I show how the abstraction summarisation feature provided by the Azure AI Language platform, can be used within Optimizely CMS to...

Anil Patel | Apr 18, 2024 | Syndicated blog

Fix your Search & Navigation (Find) indexing job, please

Once upon a time, a colleague asked me to look into a customer database with weird spikes in database log usage. (You might start to wonder why I a...

Quan Mai | Apr 17, 2024 | Syndicated blog