File: D:/HostingSpaces/RMourik/bassol.nl/CMS/CMSWebParts/General/EditDocumentLink.ascx.cs
using System;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CMS.DataEngine;
using CMS.Helpers;
using CMS.Membership;
using CMS.PortalControls;
using CMS.DocumentEngine;
using CMS.SiteProvider;
using CMS.UIControls;
using CMS.URLRewritingEngine;
using CMS.PortalEngine;
using TreeNode = CMS.DocumentEngine.TreeNode;
public partial class CMSWebParts_General_EditDocumentLink : CMSAbstractWebPart
{
#region "Web part properties"
/// <summary>
/// Indicates whether on-site editing is preferred for document editing if is available
/// </summary>
public bool PreferOnSiteEdit
{
get
{
return ValidationHelper.GetBoolean(GetValue("PreferOnSiteEdit"), true);
}
set
{
SetValue("PreferOnSiteEdit", value);
}
}
/// <summary>
/// URL to the image
/// </summary>
public string ImageURL
{
get
{
return ValidationHelper.GetString(GetValue("ImageURL"), String.Empty);
}
set
{
SetValue("ImageURL", value);
}
}
/// <summary>
/// Text of the link.
/// </summary>
public string LinkText
{
get
{
return ValidationHelper.GetString(GetValue("LinkText"), String.Empty);
}
set
{
SetValue("LinkText", value);
}
}
/// <summary>
/// Indicates if the link should be available only for users who have the access to the CMS Desk and rights to edit the current document.
/// </summary>
public bool ShowOnlyWhenAuthorized
{
get
{
return ValidationHelper.GetBoolean(GetValue("ShowOnlyWhenAuthorized"), false);
}
set
{
SetValue("ShowOnlyWhenAuthorized", value);
}
}
#endregion
#region "Web part methods"
/// <summary>
/// Content loaded event handler.
/// </summary>
public override void OnContentLoaded()
{
base.OnContentLoaded();
SetupControl();
}
/// <summary>
/// Initializes the control properties.
/// </summary>
protected void SetupControl()
{
if (!StopProcessing)
{
bool show = true;
TreeNode curDoc = DocumentContext.CurrentDocument;
// Check if permissions should be checked
if (ShowOnlyWhenAuthorized)
{
// Check permissions
if (!((MembershipContext.AuthenticatedUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Editor, SiteContext.CurrentSiteName)) && CMSPage.IsUserAuthorizedPerContent() && (MembershipContext.AuthenticatedUser.IsAuthorizedPerDocument(curDoc, NodePermissionsEnum.Modify) == AuthorizationResultEnum.Allowed)))
{
show = false;
Visible = false;
}
}
if (show)
{
// Create edit link
StringBuilder sb = new StringBuilder("<a class=\"EditDocumentLink\" href=\"");
// On-Site edit
if (PreferOnSiteEdit && PortalHelper.IsOnSiteEditingEnabled(CurrentSiteName))
{
string onsiteEditUrl = URLHelper.ResolveUrl(PortalHelper.OnSiteEditRelativeURL);
string retUrl = RequestContext.CurrentURL;
// handle default alias path
if ((ViewMode == CMS.PortalEngine.ViewModeEnum.LiveSite) && (URLRewritingContext.CurrentPageInfoSource == PageInfoSource.DefaultAliasPath))
{
string aliasPath = PageInfoProvider.GetDefaultAliasPath(RequestContext.CurrentDomain, SiteContext.CurrentSiteName);
if (!String.IsNullOrEmpty(aliasPath))
{
string query = URLHelper.GetQuery(retUrl);
retUrl = URLHelper.ResolveUrl(DocumentURLProvider.GetUrl(aliasPath));
retUrl = URLHelper.AppendQuery(retUrl, query);
}
}
onsiteEditUrl = URLHelper.UpdateParameterInUrl(onsiteEditUrl, "returnurl", HTMLHelper.HTMLEncode(HttpUtility.UrlEncode(retUrl)));
sb.Append(onsiteEditUrl);
}
// CMSDesk edit
else
{
sb.Append("~/Admin/cmsadministration.aspx?action=edit&nodeid=");
sb.Append(curDoc.NodeID);
sb.Append("&culture=");
sb.Append(curDoc.DocumentCulture);
sb.Append(UIContextHelper.GetApplicationHash("cms.content", "content"));
}
sb.Append("\">");
// Text link
if (String.IsNullOrEmpty(ImageURL))
{
sb.Append(LinkText);
}
// Image link
else
{
sb.Append("<img src=\"");
sb.Append(URLHelper.ResolveUrl(ImageURL));
sb.Append("\" alt=\"");
sb.Append(HTMLHelper.HTMLEncode(LinkText));
sb.Append("\" title=\"");
sb.Append(HTMLHelper.HTMLEncode(LinkText));
sb.Append("\" />");
}
sb.Append("</a>");
ltlEditLink.Text = sb.ToString();
}
}
}
#endregion
}