-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.cs
57 lines (52 loc) · 1.73 KB
/
content.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using umbraco.presentation.umbracobase;
using System.Web.Helpers;
[RestExtension("content")]
public class ContentClass
{
[RestExtensionMethod(returnXml = false)]
public static string node(int nodeId)
{
var node = new umbraco.NodeFactory.Node(nodeId);
// I think getting template name requires a database hit
/*var template = new umbraco.cms.businesslogic.template.Template(node.template); */
return Json.Encode(
new
{
node.Name,
node.UrlName,
node.NodeTypeAlias,
node.CreatorName,
node.template,
/*Template = template.Alias,*/
Properties = node.PropertiesAsList.Select(p => new { p.Alias, Value=replacemedia(p.Value) }).ToDictionary(k => k.Alias, k => k.Value),
node.CreateDate,
node.UpdateDate,
node.SortOrder,
node.Url,
ParentId = (node.Parent != null) ? node.Parent.Id : -1,
ChildIds = node.ChildrenAsList.Select(n => n.Id)
});
}
[RestExtensionMethod(returnXml = false)]
public static string nodeByUrl()
{
var url = System.Web.HttpContext.Current.Request["url"] ?? "";
try
{
var findNode = umbraco.content.Instance.XmlContent.SelectSingleNode(umbraco.requestHandler.CreateXPathQuery(url, true));
if (findNode != null) return node(Convert.ToInt32(findNode.Attributes["id"].Value));
}
catch (Exception)
{
}
return "";
}
private static string replacemedia(string html)
{
return html.Replace("/media","http://mysite.com/media");
}
}