From 69d1f4e0cd9d9cfba482cdb6500eda0a14d79ba2 Mon Sep 17 00:00:00 2001 From: Anthony Date: Fri, 29 Jun 2018 13:41:47 +0100 Subject: [PATCH] Moved methods which wrapped UmbracoHelper --- src/Umbraco.Web/umbraco.presentation/item.cs | 464 +++++++++--------- .../umbraco.presentation/library.cs | 51 -- .../umbraco/translation/details.aspx.cs | 208 ++++---- .../webservices/legacyAjaxCalls.asmx.cs | 278 +++++------ 4 files changed, 480 insertions(+), 521 deletions(-) diff --git a/src/Umbraco.Web/umbraco.presentation/item.cs b/src/Umbraco.Web/umbraco.presentation/item.cs index c183e3833e..226db9bf90 100644 --- a/src/Umbraco.Web/umbraco.presentation/item.cs +++ b/src/Umbraco.Web/umbraco.presentation/item.cs @@ -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 -{ - /// - /// - /// - 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); - } - - /// - /// Creates a new Legacy item - /// - /// - /// - public item(IDictionary elements, IDictionary attributes) - : this(null, elements, attributes) - { - } - - /// - /// Creates an Item with a publishedContent item in order to properly recurse and return the value. - /// - /// - /// - /// - /// - /// THIS ENTIRE CLASS WILL BECOME LEGACY, THE FIELD RENDERING NEEDS TO BE REPLACES SO THAT IS WHY THIS - /// CTOR IS INTERNAL. - /// - 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); - } - - /// - /// Returns the recursive value using a legacy strategy of looking at the xml cache and the splitPath in the elements collection - /// - /// - /// - private string GetRecursiveValueLegacy(IDictionary elements) - { - using (Current.ProfilingLogger.DebugDuration("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("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) == "

" - // it ends with a closing p tag - && fieldContentLower.Substring(_fieldContent.Length - 4, 4) == "

" - // it doesn't contain multiple p-tags - && fieldContentLower.IndexOf("

", 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", "
\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 +{ + ///

+ /// + /// + 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); + } + + /// + /// Creates a new Legacy item + /// + /// + /// + public item(IDictionary elements, IDictionary attributes) + : this(null, elements, attributes) + { + } + + /// + /// Creates an Item with a publishedContent item in order to properly recurse and return the value. + /// + /// + /// + /// + /// + /// THIS ENTIRE CLASS WILL BECOME LEGACY, THE FIELD RENDERING NEEDS TO BE REPLACES SO THAT IS WHY THIS + /// CTOR IS INTERNAL. + /// + 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); + } + + /// + /// Returns the recursive value using a legacy strategy of looking at the xml cache and the splitPath in the elements collection + /// + /// + /// + private string GetRecursiveValueLegacy(IDictionary elements) + { + using (Current.ProfilingLogger.DebugDuration("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("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) == "

" + // it ends with a closing p tag + && fieldContentLower.Substring(_fieldContent.Length - 4, 4) == "

" + // it doesn't contain multiple p-tags + && fieldContentLower.IndexOf("

", 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", "
\n"); + + HttpContext.Current.Trace.Write("item", "Done parsing '" + _fieldName + "'"); + } + } + } +} diff --git a/src/Umbraco.Web/umbraco.presentation/library.cs b/src/Umbraco.Web/umbraco.presentation/library.cs index 1c2d746086..d76b4066f6 100644 --- a/src/Umbraco.Web/umbraco.presentation/library.cs +++ b/src/Umbraco.Web/umbraco.presentation/library.cs @@ -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 { - ///

- /// Returns a new UmbracoHelper so that we can start moving the logic from some of these methods to it - /// - /// - private static UmbracoHelper GetUmbracoHelper() - { - return new UmbracoHelper(Current.UmbracoContext, Current.Services, Current.ApplicationCache); - } - - private page _page; - - - - /// - /// 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) - /// - /// Identifier for the node that should be returned - /// String with a friendly url from a node - public static string NiceUrl(int nodeID) - { - return GetUmbracoHelper().Url(nodeID); - } - - - /// /// Get a media object as an xml object /// @@ -106,28 +78,5 @@ namespace umbraco deep); return Tuple.Create(serialized, media.Path); } - - - /// - /// Replaces text line breaks with html line breaks - /// - /// The text. - /// The text with text line breaks replaced with html linebreaks (
)
- public static string ReplaceLineBreaks(string text) - { - return GetUmbracoHelper().ReplaceLineBreaksForHtml(text); - } - - - /// - /// Gets the dictionary item with the specified key. - /// - /// The key. - /// A dictionary items value as a string. - public static string GetDictionaryItem(string Key) - { - return GetUmbracoHelper().GetDictionaryValue(Key); - } - } } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/translation/details.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/translation/details.aspx.cs index 79c22c3c08..a73094d871 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/translation/details.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/translation/details.aspx.cs @@ -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 = "" + Services.TextService.Localize("download") + ""; - 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 = "" + Services.TextService.Localize("upload") + ""; - 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 = "" + Services.TextService.Localize("download") + ""; + 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 = "" + Services.TextService.Localize("upload") + ""; + 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(); + } + } +} diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/legacyAjaxCalls.asmx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/legacyAjaxCalls.asmx.cs index 13b37b21e8..f4fc07f71c 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/legacyAjaxCalls.asmx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/webservices/legacyAjaxCalls.asmx.cs @@ -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 description for legacyAjaxCalls - /// - [WebService(Namespace = "http://umbraco.org/webservices")] - [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] - [ToolboxItem(false)] - [ScriptService] - public class legacyAjaxCalls : UmbracoAuthorizedWebService - { - /// - /// 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 - /// - /// - /// - /// - [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); - } - } - - /// - /// Permanently deletes a document/media object. - /// Used to remove an item from the recycle bin. - /// - /// - /// - [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 description for legacyAjaxCalls + /// + [WebService(Namespace = "http://umbraco.org/webservices")] + [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] + [ToolboxItem(false)] + [ScriptService] + public class legacyAjaxCalls : UmbracoAuthorizedWebService + { + /// + /// 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 + /// + /// + /// + /// + [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); + } + } + + /// + /// Permanently deletes a document/media object. + /// Used to remove an item from the recycle bin. + /// + /// + /// + [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(); + } + } +}