Moved methods which wrapped UmbracoHelper
This commit is contained in:
@@ -1,231 +1,233 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Web;
|
||||
using System.Xml;
|
||||
using StackExchange.Profiling;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Core.Profiling;
|
||||
using Umbraco.Core.Strings;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Web.Macros;
|
||||
|
||||
namespace umbraco
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class item
|
||||
{
|
||||
private string _fieldContent = "";
|
||||
private readonly string _fieldName;
|
||||
|
||||
public string FieldContent
|
||||
{
|
||||
get { return _fieldContent; }
|
||||
}
|
||||
|
||||
public item(string itemValue, IDictionary attributes)
|
||||
{
|
||||
_fieldContent = itemValue;
|
||||
ParseItem(attributes);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new Legacy item
|
||||
/// </summary>
|
||||
/// <param name="elements"></param>
|
||||
/// <param name="attributes"></param>
|
||||
public item(IDictionary elements, IDictionary attributes)
|
||||
: this(null, elements, attributes)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an Item with a publishedContent item in order to properly recurse and return the value.
|
||||
/// </summary>
|
||||
/// <param name="publishedContent"></param>
|
||||
/// <param name="elements"></param>
|
||||
/// <param name="attributes"></param>
|
||||
/// <remarks>
|
||||
/// THIS ENTIRE CLASS WILL BECOME LEGACY, THE FIELD RENDERING NEEDS TO BE REPLACES SO THAT IS WHY THIS
|
||||
/// CTOR IS INTERNAL.
|
||||
/// </remarks>
|
||||
internal item(IPublishedContent publishedContent, IDictionary elements, IDictionary attributes)
|
||||
{
|
||||
_fieldName = FindAttribute(attributes, "field");
|
||||
|
||||
if (_fieldName.StartsWith("#"))
|
||||
{
|
||||
_fieldContent = library.GetDictionaryItem(_fieldName.Substring(1, _fieldName.Length - 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Loop through XML children we need to find the fields recursive
|
||||
var recursive = FindAttribute(attributes, "recursive") == "true";
|
||||
|
||||
if (publishedContent == null)
|
||||
{
|
||||
var recursiveVal = GetRecursiveValueLegacy(elements);
|
||||
_fieldContent = recursiveVal.IsNullOrWhiteSpace() ? _fieldContent : recursiveVal;
|
||||
}
|
||||
|
||||
//check for published content and get its value using that
|
||||
if (publishedContent != null && (publishedContent.HasProperty(_fieldName) || recursive))
|
||||
{
|
||||
var pval = publishedContent.Value(_fieldName, recurse: recursive);
|
||||
var rval = pval == null ? string.Empty : pval.ToString();
|
||||
_fieldContent = rval.IsNullOrWhiteSpace() ? _fieldContent : rval;
|
||||
}
|
||||
else
|
||||
{
|
||||
//get the vaue the legacy way (this will not parse locallinks, etc... since that is handled with ipublishedcontent)
|
||||
var elt = elements[_fieldName];
|
||||
if (elt != null && string.IsNullOrEmpty(elt.ToString()) == false)
|
||||
_fieldContent = elt.ToString().Trim();
|
||||
}
|
||||
|
||||
//now we check if the value is still empty and if so we'll check useIfEmpty
|
||||
if (string.IsNullOrEmpty(_fieldContent))
|
||||
{
|
||||
var altFieldName = FindAttribute(attributes, "useIfEmpty");
|
||||
if (string.IsNullOrEmpty(altFieldName) == false)
|
||||
{
|
||||
if (publishedContent != null && (publishedContent.HasProperty(altFieldName) || recursive))
|
||||
{
|
||||
var pval = publishedContent.Value(altFieldName, recurse: recursive);
|
||||
var rval = pval == null ? string.Empty : pval.ToString();
|
||||
_fieldContent = rval.IsNullOrWhiteSpace() ? _fieldContent : rval;
|
||||
}
|
||||
else
|
||||
{
|
||||
//get the vaue the legacy way (this will not parse locallinks, etc... since that is handled with ipublishedcontent)
|
||||
var elt = elements[altFieldName];
|
||||
if (elt != null && string.IsNullOrEmpty(elt.ToString()) == false)
|
||||
_fieldContent = elt.ToString().Trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ParseItem(attributes);
|
||||
}
|
||||
|
||||
static string FindAttribute(IDictionary attributes, string key)
|
||||
{
|
||||
key = key.ToLowerInvariant();
|
||||
var attributeValue = attributes.Contains(key) ? attributes[key].ToString() : string.Empty;
|
||||
return MacroRenderer.ParseAttribute(null, attributeValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the recursive value using a legacy strategy of looking at the xml cache and the splitPath in the elements collection
|
||||
/// </summary>
|
||||
/// <param name="elements"></param>
|
||||
/// <returns></returns>
|
||||
private string GetRecursiveValueLegacy(IDictionary elements)
|
||||
{
|
||||
using (Current.ProfilingLogger.DebugDuration<item>("Checking recusively"))
|
||||
{
|
||||
var content = "";
|
||||
|
||||
var umbracoContext = UmbracoContext.Current;
|
||||
var cache = umbracoContext.ContentCache as Umbraco.Web.PublishedCache.XmlPublishedCache.PublishedContentCache;
|
||||
if (cache == null)
|
||||
throw new InvalidOperationException("Unsupported IPublishedContentCache, only the Xml one is supported.");
|
||||
var umbracoXml = cache.GetXml(umbracoContext.InPreviewMode);
|
||||
|
||||
var splitpath = (string[])elements["splitpath"];
|
||||
for (int i = 0; i < splitpath.Length - 1; i++)
|
||||
{
|
||||
XmlNode element = umbracoXml.GetElementById(splitpath[splitpath.Length - i - 1]);
|
||||
|
||||
if (element == null)
|
||||
continue;
|
||||
|
||||
var xpath = "./{0}";
|
||||
var currentNode = element.SelectSingleNode(string.Format(xpath, _fieldName));
|
||||
|
||||
//continue if all is null
|
||||
if (currentNode == null || currentNode.FirstChild == null || string.IsNullOrEmpty(currentNode.FirstChild.Value) || string.IsNullOrEmpty(currentNode.FirstChild.Value.Trim()))
|
||||
continue;
|
||||
|
||||
HttpContext.Current.Trace.Write("item.recursive", "Item loaded from " + splitpath[splitpath.Length - i - 1]);
|
||||
content = currentNode.FirstChild.Value;
|
||||
break;
|
||||
}
|
||||
|
||||
return content;
|
||||
}
|
||||
}
|
||||
|
||||
private void ParseItem(IDictionary attributes)
|
||||
{
|
||||
using (Current.ProfilingLogger.DebugDuration<item>("Start parsing " + _fieldName))
|
||||
{
|
||||
HttpContext.Current.Trace.Write("item", "Start parsing '" + _fieldName + "'");
|
||||
if (FindAttribute(attributes, "textIfEmpty") != "" && _fieldContent == "")
|
||||
_fieldContent = FindAttribute(attributes, "textIfEmpty");
|
||||
|
||||
_fieldContent = _fieldContent.Trim();
|
||||
|
||||
// DATE FORMATTING FUNCTIONS
|
||||
if (FindAttribute(attributes, "formatAsDateWithTime") == "true")
|
||||
{
|
||||
if (_fieldContent == "")
|
||||
_fieldContent = DateTime.Now.ToString();
|
||||
_fieldContent = Convert.ToDateTime(_fieldContent).ToLongDateString() +
|
||||
FindAttribute(attributes, "formatAsDateWithTimeSeparator") +
|
||||
Convert.ToDateTime(_fieldContent).ToShortTimeString();
|
||||
}
|
||||
else if (FindAttribute(attributes, "formatAsDate") == "true")
|
||||
{
|
||||
if (_fieldContent == "")
|
||||
_fieldContent = DateTime.Now.ToString();
|
||||
_fieldContent = Convert.ToDateTime(_fieldContent).ToLongDateString();
|
||||
}
|
||||
|
||||
|
||||
// TODO: Needs revision to check if parameter-tags has attributes
|
||||
if (FindAttribute(attributes, "stripParagraph") == "true" && _fieldContent.Length > 5)
|
||||
{
|
||||
_fieldContent = _fieldContent.Trim();
|
||||
string fieldContentLower = _fieldContent.ToLower();
|
||||
|
||||
// the field starts with an opening p tag
|
||||
if (fieldContentLower.Substring(0, 3) == "<p>"
|
||||
// it ends with a closing p tag
|
||||
&& fieldContentLower.Substring(_fieldContent.Length - 4, 4) == "</p>"
|
||||
// it doesn't contain multiple p-tags
|
||||
&& fieldContentLower.IndexOf("<p>", 1) < 0)
|
||||
{
|
||||
_fieldContent = _fieldContent.Substring(3, _fieldContent.Length - 7);
|
||||
}
|
||||
}
|
||||
|
||||
// CASING
|
||||
if (FindAttribute(attributes, "case") == "lower")
|
||||
_fieldContent = _fieldContent.ToLower();
|
||||
else if (FindAttribute(attributes, "case") == "upper")
|
||||
_fieldContent = _fieldContent.ToUpper();
|
||||
else if (FindAttribute(attributes, "case") == "title")
|
||||
_fieldContent = _fieldContent.ToCleanString(CleanStringType.Ascii | CleanStringType.Alias | CleanStringType.PascalCase);
|
||||
|
||||
// OTHER FORMATTING FUNCTIONS
|
||||
|
||||
if (FindAttribute(attributes, "urlEncode") == "true")
|
||||
_fieldContent = HttpUtility.UrlEncode(_fieldContent);
|
||||
if (FindAttribute(attributes, "htmlEncode") == "true")
|
||||
_fieldContent = HttpUtility.HtmlEncode(_fieldContent);
|
||||
if (FindAttribute(attributes, "convertLineBreaks") == "true")
|
||||
_fieldContent = _fieldContent.Replace("\n", "<br/>\n");
|
||||
|
||||
HttpContext.Current.Trace.Write("item", "Done parsing '" + _fieldName + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Web;
|
||||
using System.Xml;
|
||||
using StackExchange.Profiling;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Core.Profiling;
|
||||
using Umbraco.Core.Strings;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Web.Macros;
|
||||
|
||||
namespace umbraco
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class item
|
||||
{
|
||||
private string _fieldContent = "";
|
||||
private readonly string _fieldName;
|
||||
|
||||
public string FieldContent
|
||||
{
|
||||
get { return _fieldContent; }
|
||||
}
|
||||
|
||||
public item(string itemValue, IDictionary attributes)
|
||||
{
|
||||
_fieldContent = itemValue;
|
||||
ParseItem(attributes);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new Legacy item
|
||||
/// </summary>
|
||||
/// <param name="elements"></param>
|
||||
/// <param name="attributes"></param>
|
||||
public item(IDictionary elements, IDictionary attributes)
|
||||
: this(null, elements, attributes)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an Item with a publishedContent item in order to properly recurse and return the value.
|
||||
/// </summary>
|
||||
/// <param name="publishedContent"></param>
|
||||
/// <param name="elements"></param>
|
||||
/// <param name="attributes"></param>
|
||||
/// <remarks>
|
||||
/// THIS ENTIRE CLASS WILL BECOME LEGACY, THE FIELD RENDERING NEEDS TO BE REPLACES SO THAT IS WHY THIS
|
||||
/// CTOR IS INTERNAL.
|
||||
/// </remarks>
|
||||
internal item(IPublishedContent publishedContent, IDictionary elements, IDictionary attributes)
|
||||
{
|
||||
_fieldName = FindAttribute(attributes, "field");
|
||||
|
||||
if (_fieldName.StartsWith("#"))
|
||||
{
|
||||
var umbHelper = new UmbracoHelper(Current.UmbracoContext, Current.Services, Current.ApplicationCache);
|
||||
|
||||
_fieldContent = umbHelper.GetDictionaryValue(_fieldName.Substring(1, _fieldName.Length - 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Loop through XML children we need to find the fields recursive
|
||||
var recursive = FindAttribute(attributes, "recursive") == "true";
|
||||
|
||||
if (publishedContent == null)
|
||||
{
|
||||
var recursiveVal = GetRecursiveValueLegacy(elements);
|
||||
_fieldContent = recursiveVal.IsNullOrWhiteSpace() ? _fieldContent : recursiveVal;
|
||||
}
|
||||
|
||||
//check for published content and get its value using that
|
||||
if (publishedContent != null && (publishedContent.HasProperty(_fieldName) || recursive))
|
||||
{
|
||||
var pval = publishedContent.Value(_fieldName, recurse: recursive);
|
||||
var rval = pval == null ? string.Empty : pval.ToString();
|
||||
_fieldContent = rval.IsNullOrWhiteSpace() ? _fieldContent : rval;
|
||||
}
|
||||
else
|
||||
{
|
||||
//get the vaue the legacy way (this will not parse locallinks, etc... since that is handled with ipublishedcontent)
|
||||
var elt = elements[_fieldName];
|
||||
if (elt != null && string.IsNullOrEmpty(elt.ToString()) == false)
|
||||
_fieldContent = elt.ToString().Trim();
|
||||
}
|
||||
|
||||
//now we check if the value is still empty and if so we'll check useIfEmpty
|
||||
if (string.IsNullOrEmpty(_fieldContent))
|
||||
{
|
||||
var altFieldName = FindAttribute(attributes, "useIfEmpty");
|
||||
if (string.IsNullOrEmpty(altFieldName) == false)
|
||||
{
|
||||
if (publishedContent != null && (publishedContent.HasProperty(altFieldName) || recursive))
|
||||
{
|
||||
var pval = publishedContent.Value(altFieldName, recurse: recursive);
|
||||
var rval = pval == null ? string.Empty : pval.ToString();
|
||||
_fieldContent = rval.IsNullOrWhiteSpace() ? _fieldContent : rval;
|
||||
}
|
||||
else
|
||||
{
|
||||
//get the vaue the legacy way (this will not parse locallinks, etc... since that is handled with ipublishedcontent)
|
||||
var elt = elements[altFieldName];
|
||||
if (elt != null && string.IsNullOrEmpty(elt.ToString()) == false)
|
||||
_fieldContent = elt.ToString().Trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ParseItem(attributes);
|
||||
}
|
||||
|
||||
static string FindAttribute(IDictionary attributes, string key)
|
||||
{
|
||||
key = key.ToLowerInvariant();
|
||||
var attributeValue = attributes.Contains(key) ? attributes[key].ToString() : string.Empty;
|
||||
return MacroRenderer.ParseAttribute(null, attributeValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the recursive value using a legacy strategy of looking at the xml cache and the splitPath in the elements collection
|
||||
/// </summary>
|
||||
/// <param name="elements"></param>
|
||||
/// <returns></returns>
|
||||
private string GetRecursiveValueLegacy(IDictionary elements)
|
||||
{
|
||||
using (Current.ProfilingLogger.DebugDuration<item>("Checking recusively"))
|
||||
{
|
||||
var content = "";
|
||||
|
||||
var umbracoContext = UmbracoContext.Current;
|
||||
var cache = umbracoContext.ContentCache as Umbraco.Web.PublishedCache.XmlPublishedCache.PublishedContentCache;
|
||||
if (cache == null)
|
||||
throw new InvalidOperationException("Unsupported IPublishedContentCache, only the Xml one is supported.");
|
||||
var umbracoXml = cache.GetXml(umbracoContext.InPreviewMode);
|
||||
|
||||
var splitpath = (string[])elements["splitpath"];
|
||||
for (int i = 0; i < splitpath.Length - 1; i++)
|
||||
{
|
||||
XmlNode element = umbracoXml.GetElementById(splitpath[splitpath.Length - i - 1]);
|
||||
|
||||
if (element == null)
|
||||
continue;
|
||||
|
||||
var xpath = "./{0}";
|
||||
var currentNode = element.SelectSingleNode(string.Format(xpath, _fieldName));
|
||||
|
||||
//continue if all is null
|
||||
if (currentNode == null || currentNode.FirstChild == null || string.IsNullOrEmpty(currentNode.FirstChild.Value) || string.IsNullOrEmpty(currentNode.FirstChild.Value.Trim()))
|
||||
continue;
|
||||
|
||||
HttpContext.Current.Trace.Write("item.recursive", "Item loaded from " + splitpath[splitpath.Length - i - 1]);
|
||||
content = currentNode.FirstChild.Value;
|
||||
break;
|
||||
}
|
||||
|
||||
return content;
|
||||
}
|
||||
}
|
||||
|
||||
private void ParseItem(IDictionary attributes)
|
||||
{
|
||||
using (Current.ProfilingLogger.DebugDuration<item>("Start parsing " + _fieldName))
|
||||
{
|
||||
HttpContext.Current.Trace.Write("item", "Start parsing '" + _fieldName + "'");
|
||||
if (FindAttribute(attributes, "textIfEmpty") != "" && _fieldContent == "")
|
||||
_fieldContent = FindAttribute(attributes, "textIfEmpty");
|
||||
|
||||
_fieldContent = _fieldContent.Trim();
|
||||
|
||||
// DATE FORMATTING FUNCTIONS
|
||||
if (FindAttribute(attributes, "formatAsDateWithTime") == "true")
|
||||
{
|
||||
if (_fieldContent == "")
|
||||
_fieldContent = DateTime.Now.ToString();
|
||||
_fieldContent = Convert.ToDateTime(_fieldContent).ToLongDateString() +
|
||||
FindAttribute(attributes, "formatAsDateWithTimeSeparator") +
|
||||
Convert.ToDateTime(_fieldContent).ToShortTimeString();
|
||||
}
|
||||
else if (FindAttribute(attributes, "formatAsDate") == "true")
|
||||
{
|
||||
if (_fieldContent == "")
|
||||
_fieldContent = DateTime.Now.ToString();
|
||||
_fieldContent = Convert.ToDateTime(_fieldContent).ToLongDateString();
|
||||
}
|
||||
|
||||
|
||||
// TODO: Needs revision to check if parameter-tags has attributes
|
||||
if (FindAttribute(attributes, "stripParagraph") == "true" && _fieldContent.Length > 5)
|
||||
{
|
||||
_fieldContent = _fieldContent.Trim();
|
||||
string fieldContentLower = _fieldContent.ToLower();
|
||||
|
||||
// the field starts with an opening p tag
|
||||
if (fieldContentLower.Substring(0, 3) == "<p>"
|
||||
// it ends with a closing p tag
|
||||
&& fieldContentLower.Substring(_fieldContent.Length - 4, 4) == "</p>"
|
||||
// it doesn't contain multiple p-tags
|
||||
&& fieldContentLower.IndexOf("<p>", 1) < 0)
|
||||
{
|
||||
_fieldContent = _fieldContent.Substring(3, _fieldContent.Length - 7);
|
||||
}
|
||||
}
|
||||
|
||||
// CASING
|
||||
if (FindAttribute(attributes, "case") == "lower")
|
||||
_fieldContent = _fieldContent.ToLower();
|
||||
else if (FindAttribute(attributes, "case") == "upper")
|
||||
_fieldContent = _fieldContent.ToUpper();
|
||||
else if (FindAttribute(attributes, "case") == "title")
|
||||
_fieldContent = _fieldContent.ToCleanString(CleanStringType.Ascii | CleanStringType.Alias | CleanStringType.PascalCase);
|
||||
|
||||
// OTHER FORMATTING FUNCTIONS
|
||||
|
||||
if (FindAttribute(attributes, "urlEncode") == "true")
|
||||
_fieldContent = HttpUtility.UrlEncode(_fieldContent);
|
||||
if (FindAttribute(attributes, "htmlEncode") == "true")
|
||||
_fieldContent = HttpUtility.HtmlEncode(_fieldContent);
|
||||
if (FindAttribute(attributes, "convertLineBreaks") == "true")
|
||||
_fieldContent = _fieldContent.Replace("\n", "<br/>\n");
|
||||
|
||||
HttpContext.Current.Trace.Write("item", "Done parsing '" + _fieldName + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.Composing;
|
||||
|
||||
namespace umbraco
|
||||
@@ -20,33 +19,6 @@ namespace umbraco
|
||||
[Obsolete("v8.kill.kill")]
|
||||
public class library
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns a new UmbracoHelper so that we can start moving the logic from some of these methods to it
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private static UmbracoHelper GetUmbracoHelper()
|
||||
{
|
||||
return new UmbracoHelper(Current.UmbracoContext, Current.Services, Current.ApplicationCache);
|
||||
}
|
||||
|
||||
private page _page;
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Returns a string with a friendly url from a node.
|
||||
/// IE.: Instead of having /482 (id) as an url, you can have
|
||||
/// /screenshots/developer/macros (spoken url)
|
||||
/// </summary>
|
||||
/// <param name="nodeID">Identifier for the node that should be returned</param>
|
||||
/// <returns>String with a friendly url from a node</returns>
|
||||
public static string NiceUrl(int nodeID)
|
||||
{
|
||||
return GetUmbracoHelper().Url(nodeID);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get a media object as an xml object
|
||||
/// </summary>
|
||||
@@ -106,28 +78,5 @@ namespace umbraco
|
||||
deep);
|
||||
return Tuple.Create(serialized, media.Path);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Replaces text line breaks with html line breaks
|
||||
/// </summary>
|
||||
/// <param name="text">The text.</param>
|
||||
/// <returns>The text with text line breaks replaced with html linebreaks (<br/>)</returns>
|
||||
public static string ReplaceLineBreaks(string text)
|
||||
{
|
||||
return GetUmbracoHelper().ReplaceLineBreaksForHtml(text);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the dictionary item with the specified key.
|
||||
/// </summary>
|
||||
/// <param name="Key">The key.</param>
|
||||
/// <returns>A dictionary items value as a string.</returns>
|
||||
public static string GetDictionaryItem(string Key)
|
||||
{
|
||||
return GetUmbracoHelper().GetDictionaryValue(Key);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,101 +1,107 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Web.UI.WebControls;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Web._Legacy.BusinessLogic;
|
||||
namespace umbraco.presentation.umbraco.translation {
|
||||
public partial class details : Umbraco.Web.UI.Pages.UmbracoEnsuredPage {
|
||||
|
||||
public details()
|
||||
{
|
||||
CurrentApp = Constants.Applications.Translation.ToString();
|
||||
|
||||
}
|
||||
protected void closeTask(object sender, EventArgs e) {
|
||||
int translationId = int.Parse(Request["id"]);
|
||||
Task t = new Task(translationId);
|
||||
|
||||
if (t != null && (t.ParentUser.Id == Security.CurrentUser.Id || t.User.Id == Security.CurrentUser.Id)) {
|
||||
t.Closed = true;
|
||||
t.Save();
|
||||
Response.Redirect("default.aspx");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void Page_Load(object sender, EventArgs e) {
|
||||
int translationId = int.Parse(Request["id"]);
|
||||
Task t = new Task(translationId);
|
||||
//Document page = new Document(t.Node.Id);
|
||||
var page = Current.Services.ContentService.GetById(t.TaskEntity.EntityId);
|
||||
|
||||
//Bind meta data and language...
|
||||
Literal lt = new Literal();
|
||||
lt.Text = t.Date.ToLongDateString() + " " + t.Date.ToLongTimeString();
|
||||
pp_date.Controls.Add(lt);
|
||||
pp_date.Text = Services.TextService.Localize("translation/taskOpened");
|
||||
|
||||
lt = new Literal();
|
||||
lt.Text = t.ParentUser.Name;
|
||||
pp_owner.Controls.Add(lt);
|
||||
pp_owner.Text = Services.TextService.Localize("translation/taskAssignedBy");
|
||||
|
||||
//TODO: Make this work again with correct APIs and angularized - so none of this code will exist anymore
|
||||
//lt = new Literal();
|
||||
//lt.Text = Translation.CountWords(t.Node.Id).ToString();
|
||||
//pp_totalWords.Controls.Add(lt);
|
||||
//pp_totalWords.Text = Services.TextService.Localize("translation/totalWords");
|
||||
|
||||
lt = new Literal();
|
||||
lt.Text = library.ReplaceLineBreaks(t.Comment);
|
||||
pp_comment.Controls.Add(lt);
|
||||
pp_comment.Text = Services.TextService.Localize("comment");
|
||||
|
||||
lt = new Literal();
|
||||
lt.Text = "<a target=\"_blank\" href=\"xml.aspx?id=" + t.Id + "\">" + Services.TextService.Localize("download") + "</a>";
|
||||
pp_xml.Controls.Add(lt);
|
||||
pp_xml.Text = Services.TextService.Localize("translation/downloadTaskAsXml");
|
||||
|
||||
pane_details.Text = Services.TextService.Localize("translation/details");
|
||||
panel1.Text = Services.TextService.Localize("translation/details");
|
||||
|
||||
pane_fields.Text = Services.TextService.Localize("translation/fields");
|
||||
pane_tasks.Text = Services.TextService.Localize("translation/translationOptions");
|
||||
lt = new Literal();
|
||||
lt.Text = "<a href=\"default.aspx?id=" + t.Id + "\">" + Services.TextService.Localize("upload") + "</a>";
|
||||
pp_upload.Controls.Add(lt);
|
||||
pp_upload.Text = Services.TextService.Localize("translation/uploadTranslationXml");
|
||||
|
||||
if (t.Closed)
|
||||
pp_closeTask.Visible = false;
|
||||
else {
|
||||
pp_closeTask.Text = Services.TextService.Localize("translation/closeTask");
|
||||
bt_close.Text = Services.TextService.Localize("close");
|
||||
}
|
||||
|
||||
|
||||
//Bind page fields
|
||||
DataTable pageTable = new DataTable();
|
||||
pageTable.Columns.Add(Services.TextService.Localize("name"));
|
||||
pageTable.Columns.Add(Services.TextService.Localize("value"));
|
||||
|
||||
DataRow pageRow = pageTable.NewRow();
|
||||
pageRow[Services.TextService.Localize("name")] = Services.TextService.Localize("nodeName");
|
||||
pageRow[Services.TextService.Localize("value")] = page.Name;
|
||||
pageTable.Rows.Add(pageRow);
|
||||
|
||||
//TODO: Make this work again with correct APIs and angularized - so none of this code will exist anymore
|
||||
//foreach (PropertyType pt in page.ContentType.PropertyTypes) {
|
||||
// pageRow = pageTable.NewRow();
|
||||
// pageRow[Services.TextService.Localize("name")] = pt.Name;
|
||||
// pageRow[Services.TextService.Localize("value")] = page.getProperty(pt.Alias).Value;
|
||||
// pageTable.Rows.Add(pageRow);
|
||||
//}
|
||||
|
||||
dg_fields.DataSource = pageTable;
|
||||
dg_fields.DataBind();
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Web.UI.WebControls;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Web._Legacy.BusinessLogic;
|
||||
using Umbraco.Web;
|
||||
|
||||
namespace umbraco.presentation.umbraco.translation {
|
||||
public partial class details : Umbraco.Web.UI.Pages.UmbracoEnsuredPage {
|
||||
|
||||
public details()
|
||||
{
|
||||
CurrentApp = Constants.Applications.Translation.ToString();
|
||||
|
||||
}
|
||||
protected void closeTask(object sender, EventArgs e) {
|
||||
int translationId = int.Parse(Request["id"]);
|
||||
Task t = new Task(translationId);
|
||||
|
||||
if (t != null && (t.ParentUser.Id == Security.CurrentUser.Id || t.User.Id == Security.CurrentUser.Id)) {
|
||||
t.Closed = true;
|
||||
t.Save();
|
||||
Response.Redirect("default.aspx");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void Page_Load(object sender, EventArgs e) {
|
||||
int translationId = int.Parse(Request["id"]);
|
||||
Task t = new Task(translationId);
|
||||
//Document page = new Document(t.Node.Id);
|
||||
var page = Current.Services.ContentService.GetById(t.TaskEntity.EntityId);
|
||||
|
||||
//Bind meta data and language...
|
||||
Literal lt = new Literal();
|
||||
lt.Text = t.Date.ToLongDateString() + " " + t.Date.ToLongTimeString();
|
||||
pp_date.Controls.Add(lt);
|
||||
pp_date.Text = Services.TextService.Localize("translation/taskOpened");
|
||||
|
||||
lt = new Literal();
|
||||
lt.Text = t.ParentUser.Name;
|
||||
pp_owner.Controls.Add(lt);
|
||||
pp_owner.Text = Services.TextService.Localize("translation/taskAssignedBy");
|
||||
|
||||
//TODO: Make this work again with correct APIs and angularized - so none of this code will exist anymore
|
||||
//lt = new Literal();
|
||||
//lt.Text = Translation.CountWords(t.Node.Id).ToString();
|
||||
//pp_totalWords.Controls.Add(lt);
|
||||
//pp_totalWords.Text = Services.TextService.Localize("translation/totalWords");
|
||||
|
||||
lt = new Literal();
|
||||
|
||||
|
||||
var umbHelper = new UmbracoHelper(Current.UmbracoContext, Current.Services, Current.ApplicationCache);
|
||||
lt.Text = umbHelper.ReplaceLineBreaksForHtml(t.Comment);
|
||||
|
||||
pp_comment.Controls.Add(lt);
|
||||
pp_comment.Text = Services.TextService.Localize("comment");
|
||||
|
||||
lt = new Literal();
|
||||
lt.Text = "<a target=\"_blank\" href=\"xml.aspx?id=" + t.Id + "\">" + Services.TextService.Localize("download") + "</a>";
|
||||
pp_xml.Controls.Add(lt);
|
||||
pp_xml.Text = Services.TextService.Localize("translation/downloadTaskAsXml");
|
||||
|
||||
pane_details.Text = Services.TextService.Localize("translation/details");
|
||||
panel1.Text = Services.TextService.Localize("translation/details");
|
||||
|
||||
pane_fields.Text = Services.TextService.Localize("translation/fields");
|
||||
pane_tasks.Text = Services.TextService.Localize("translation/translationOptions");
|
||||
lt = new Literal();
|
||||
lt.Text = "<a href=\"default.aspx?id=" + t.Id + "\">" + Services.TextService.Localize("upload") + "</a>";
|
||||
pp_upload.Controls.Add(lt);
|
||||
pp_upload.Text = Services.TextService.Localize("translation/uploadTranslationXml");
|
||||
|
||||
if (t.Closed)
|
||||
pp_closeTask.Visible = false;
|
||||
else {
|
||||
pp_closeTask.Text = Services.TextService.Localize("translation/closeTask");
|
||||
bt_close.Text = Services.TextService.Localize("close");
|
||||
}
|
||||
|
||||
|
||||
//Bind page fields
|
||||
DataTable pageTable = new DataTable();
|
||||
pageTable.Columns.Add(Services.TextService.Localize("name"));
|
||||
pageTable.Columns.Add(Services.TextService.Localize("value"));
|
||||
|
||||
DataRow pageRow = pageTable.NewRow();
|
||||
pageRow[Services.TextService.Localize("name")] = Services.TextService.Localize("nodeName");
|
||||
pageRow[Services.TextService.Localize("value")] = page.Name;
|
||||
pageTable.Rows.Add(pageRow);
|
||||
|
||||
//TODO: Make this work again with correct APIs and angularized - so none of this code will exist anymore
|
||||
//foreach (PropertyType pt in page.ContentType.PropertyTypes) {
|
||||
// pageRow = pageTable.NewRow();
|
||||
// pageRow[Services.TextService.Localize("name")] = pt.Name;
|
||||
// pageRow[Services.TextService.Localize("value")] = page.getProperty(pt.Alias).Value;
|
||||
// pageTable.Rows.Add(pageRow);
|
||||
//}
|
||||
|
||||
dg_fields.DataSource = pageTable;
|
||||
dg_fields.DataBind();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,138 +1,140 @@
|
||||
using System;
|
||||
using System.Web;
|
||||
using System.Web.Services;
|
||||
using System.ComponentModel;
|
||||
using System.Web.Script.Services;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.WebServices;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Web._Legacy.UI;
|
||||
|
||||
namespace umbraco.presentation.webservices
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for legacyAjaxCalls
|
||||
/// </summary>
|
||||
[WebService(Namespace = "http://umbraco.org/webservices")]
|
||||
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
|
||||
[ToolboxItem(false)]
|
||||
[ScriptService]
|
||||
public class legacyAjaxCalls : UmbracoAuthorizedWebService
|
||||
{
|
||||
/// <summary>
|
||||
/// method to accept a string value for the node id. Used for tree's such as python
|
||||
/// and xslt since the file names are the node IDs
|
||||
/// </summary>
|
||||
/// <param name="nodeId"></param>
|
||||
/// <param name="alias"></param>
|
||||
/// <param name="nodeType"></param>
|
||||
[WebMethod]
|
||||
[ScriptMethod]
|
||||
public void Delete(string nodeId, string alias, string nodeType)
|
||||
{
|
||||
if (!AuthorizeRequest())
|
||||
return;
|
||||
|
||||
//U4-2686 - alias is html encoded, make sure to decode
|
||||
alias = HttpUtility.HtmlDecode(alias);
|
||||
|
||||
//check which parameters to pass depending on the types passed in
|
||||
int intNodeId;
|
||||
if (nodeType == "memberGroups")
|
||||
{
|
||||
LegacyDialogHandler.Delete(
|
||||
new HttpContextWrapper(HttpContext.Current),
|
||||
Security.CurrentUser,
|
||||
nodeType, 0, nodeId);
|
||||
}
|
||||
else if (int.TryParse(nodeId, out intNodeId) && nodeType != "member") // Fix for #26965 - numeric member login gets parsed as nodeId
|
||||
{
|
||||
LegacyDialogHandler.Delete(
|
||||
new HttpContextWrapper(HttpContext.Current),
|
||||
Security.CurrentUser,
|
||||
nodeType, intNodeId, alias);
|
||||
}
|
||||
else
|
||||
{
|
||||
LegacyDialogHandler.Delete(
|
||||
new HttpContextWrapper(HttpContext.Current),
|
||||
Security.CurrentUser,
|
||||
nodeType, 0, nodeId);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Permanently deletes a document/media object.
|
||||
/// Used to remove an item from the recycle bin.
|
||||
/// </summary>
|
||||
/// <param name="nodeId"></param>
|
||||
/// <param name="nodeType"></param>
|
||||
[WebMethod]
|
||||
[ScriptMethod]
|
||||
public void DeleteContentPermanently(string nodeId, string nodeType)
|
||||
{
|
||||
int intNodeId;
|
||||
if (int.TryParse(nodeId, out intNodeId))
|
||||
{
|
||||
switch (nodeType)
|
||||
{
|
||||
case "media":
|
||||
case "mediaRecycleBin":
|
||||
//ensure user has access to media
|
||||
AuthorizeRequest(Constants.Applications.Media.ToString(), true);
|
||||
var media = Current.Services.MediaService.GetById(intNodeId);
|
||||
if (media != null)
|
||||
Current.Services.MediaService.Delete(media);
|
||||
break;
|
||||
case "content":
|
||||
case "contentRecycleBin":
|
||||
default:
|
||||
//ensure user has access to content
|
||||
AuthorizeRequest(Constants.Applications.Content.ToString(), true);
|
||||
var content = Current.Services.ContentService.GetById(intNodeId);
|
||||
if (content != null)
|
||||
Current.Services.ContentService.Delete(content);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException("The nodeId argument could not be parsed to an integer");
|
||||
}
|
||||
}
|
||||
|
||||
[WebMethod]
|
||||
[ScriptMethod]
|
||||
public void DisableUser(int userId)
|
||||
{
|
||||
AuthorizeRequest(Constants.Applications.Users.ToString(), true);
|
||||
|
||||
var user = Services.UserService.GetUserById(userId);
|
||||
if (user == null) return;
|
||||
|
||||
user.IsApproved = false;
|
||||
Services.UserService.Save(user);
|
||||
}
|
||||
|
||||
[WebMethod]
|
||||
[ScriptMethod]
|
||||
public string NiceUrl(int nodeId)
|
||||
{
|
||||
|
||||
AuthorizeRequest(true);
|
||||
|
||||
return library.NiceUrl(nodeId);
|
||||
}
|
||||
|
||||
[WebMethod]
|
||||
[ScriptMethod]
|
||||
public string ProgressStatus(string Key)
|
||||
{
|
||||
AuthorizeRequest(true);
|
||||
|
||||
return Application[Context.Request.GetItemAsString("key")].ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Web;
|
||||
using System.Web.Services;
|
||||
using System.ComponentModel;
|
||||
using System.Web.Script.Services;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.WebServices;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Web._Legacy.UI;
|
||||
|
||||
namespace umbraco.presentation.webservices
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for legacyAjaxCalls
|
||||
/// </summary>
|
||||
[WebService(Namespace = "http://umbraco.org/webservices")]
|
||||
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
|
||||
[ToolboxItem(false)]
|
||||
[ScriptService]
|
||||
public class legacyAjaxCalls : UmbracoAuthorizedWebService
|
||||
{
|
||||
/// <summary>
|
||||
/// method to accept a string value for the node id. Used for tree's such as python
|
||||
/// and xslt since the file names are the node IDs
|
||||
/// </summary>
|
||||
/// <param name="nodeId"></param>
|
||||
/// <param name="alias"></param>
|
||||
/// <param name="nodeType"></param>
|
||||
[WebMethod]
|
||||
[ScriptMethod]
|
||||
public void Delete(string nodeId, string alias, string nodeType)
|
||||
{
|
||||
if (!AuthorizeRequest())
|
||||
return;
|
||||
|
||||
//U4-2686 - alias is html encoded, make sure to decode
|
||||
alias = HttpUtility.HtmlDecode(alias);
|
||||
|
||||
//check which parameters to pass depending on the types passed in
|
||||
int intNodeId;
|
||||
if (nodeType == "memberGroups")
|
||||
{
|
||||
LegacyDialogHandler.Delete(
|
||||
new HttpContextWrapper(HttpContext.Current),
|
||||
Security.CurrentUser,
|
||||
nodeType, 0, nodeId);
|
||||
}
|
||||
else if (int.TryParse(nodeId, out intNodeId) && nodeType != "member") // Fix for #26965 - numeric member login gets parsed as nodeId
|
||||
{
|
||||
LegacyDialogHandler.Delete(
|
||||
new HttpContextWrapper(HttpContext.Current),
|
||||
Security.CurrentUser,
|
||||
nodeType, intNodeId, alias);
|
||||
}
|
||||
else
|
||||
{
|
||||
LegacyDialogHandler.Delete(
|
||||
new HttpContextWrapper(HttpContext.Current),
|
||||
Security.CurrentUser,
|
||||
nodeType, 0, nodeId);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Permanently deletes a document/media object.
|
||||
/// Used to remove an item from the recycle bin.
|
||||
/// </summary>
|
||||
/// <param name="nodeId"></param>
|
||||
/// <param name="nodeType"></param>
|
||||
[WebMethod]
|
||||
[ScriptMethod]
|
||||
public void DeleteContentPermanently(string nodeId, string nodeType)
|
||||
{
|
||||
int intNodeId;
|
||||
if (int.TryParse(nodeId, out intNodeId))
|
||||
{
|
||||
switch (nodeType)
|
||||
{
|
||||
case "media":
|
||||
case "mediaRecycleBin":
|
||||
//ensure user has access to media
|
||||
AuthorizeRequest(Constants.Applications.Media.ToString(), true);
|
||||
var media = Current.Services.MediaService.GetById(intNodeId);
|
||||
if (media != null)
|
||||
Current.Services.MediaService.Delete(media);
|
||||
break;
|
||||
case "content":
|
||||
case "contentRecycleBin":
|
||||
default:
|
||||
//ensure user has access to content
|
||||
AuthorizeRequest(Constants.Applications.Content.ToString(), true);
|
||||
var content = Current.Services.ContentService.GetById(intNodeId);
|
||||
if (content != null)
|
||||
Current.Services.ContentService.Delete(content);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException("The nodeId argument could not be parsed to an integer");
|
||||
}
|
||||
}
|
||||
|
||||
[WebMethod]
|
||||
[ScriptMethod]
|
||||
public void DisableUser(int userId)
|
||||
{
|
||||
AuthorizeRequest(Constants.Applications.Users.ToString(), true);
|
||||
|
||||
var user = Services.UserService.GetUserById(userId);
|
||||
if (user == null) return;
|
||||
|
||||
user.IsApproved = false;
|
||||
Services.UserService.Save(user);
|
||||
}
|
||||
|
||||
[WebMethod]
|
||||
[ScriptMethod]
|
||||
public string NiceUrl(int nodeId)
|
||||
{
|
||||
|
||||
AuthorizeRequest(true);
|
||||
|
||||
var umbHelper = new UmbracoHelper(Current.UmbracoContext, Current.Services, Current.ApplicationCache);
|
||||
|
||||
return umbHelper.Url(nodeId);
|
||||
}
|
||||
|
||||
[WebMethod]
|
||||
[ScriptMethod]
|
||||
public string ProgressStatus(string Key)
|
||||
{
|
||||
AuthorizeRequest(true);
|
||||
|
||||
return Application[Context.Request.GetItemAsString("key")].ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user