Anders Hattestad
Oct 27, 2011
  4867
(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
Opti ID overview

Opti ID allows you to log in once and switch between Optimizely products using Okta, Entra ID, or a local account. You can also manage all your use...

K Khan | Jul 26, 2024

Getting Started with Optimizely SaaS using Next.js Starter App - Extend a component - Part 3

This is the final part of our Optimizely SaaS CMS proof-of-concept (POC) blog series. In this post, we'll dive into extending a component within th...

Raghavendra Murthy | Jul 23, 2024 | Syndicated blog

Optimizely Graph – Faceting with Geta Categories

Overview As Optimizely Graph (and Content Cloud SaaS) makes its global debut, it is known that there are going to be some bugs and quirks. One of t...

Eric Markson | Jul 22, 2024 | Syndicated blog

Integration Bynder (DAM) with Optimizely

Bynder is a comprehensive digital asset management (DAM) platform that enables businesses to efficiently manage, store, organize, and share their...

Sanjay Kumar | Jul 22, 2024

Frontend Hosting for SaaS CMS Solutions

Introduction Now that CMS SaaS Core has gone into general availability, it is a good time to start discussing where to host the head. SaaS Core is...

Minesh Shah (Netcel) | Jul 20, 2024

Optimizely London Dev Meetup 11th July 2024

On 11th July 2024 in London Niteco and Netcel along with Optimizely ran the London Developer meetup. There was an great agenda of talks that we put...

Scott Reed | Jul 19, 2024