Calling all developers! We invite you to provide your input on Feature Experimentation by completing this brief survey.

 

Anders Hattestad
Oct 27, 2011
  4938
(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 CMS easy RSS feed integration library

As I've mentioned in my  previous blog post , while I was developing the Optimizely version of my blog, I tried to look for a library that could...

David Drouin-Prince | Jan 25, 2025 | Syndicated blog

Decimal numbers in Optimizely Graph

Storing prices as decimal numbers on a commerce website and planning to expose them through Optimizely Graph? It might not be as straightforward as...

Damian Smutek | Jan 23, 2025 | Syndicated blog

Find and delete non used media and blocks

On my new quest to play around with Blazor and MudBlazor I'm going back memory lane and porting some previously plugins. So this time up is my plug...

Per Nergård (MVP) | Jan 21, 2025

Optimizely Content Graph on mobile application

CG everywhere! I pull schema from our default index https://cg.optimizely.com/app/graphiql?auth=eBrGunULiC5TziTCtiOLEmov2LijBf30obh0KmhcBlyTktGZ in...

Cuong Nguyen Dinh | Jan 20, 2025

Image Analyzer with AI Assistant for Optimizely

The Smart Image Analyzer is a new feature in the Epicweb AI Assistant for Optimizely CMS that automates the management of image metadata, such as...

Luc Gosso (MVP) | Jan 16, 2025 | Syndicated blog

How to: create Decimal metafield with custom precision

If you are using catalog system, the way of creating metafields are easy – in fact, you can forget about “metafields”, all you should be using is t...

Quan Mai | Jan 16, 2025 | Syndicated blog