-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathp.cshtml
More file actions
77 lines (72 loc) · 2.79 KB
/
p.cshtml
File metadata and controls
77 lines (72 loc) · 2.79 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
@using System.Xml.Linq
@using System.Xml
@using WebMatrix.WebData
@{
// set the name of the file
string filename = "~/content/xml/content/webpages.xml";
string filePath = "";
var load = new Comic();
var webpageXml = load.LoadComic(filename);
var pageId = UrlData[0];
bool include = false;
var settings = load.LoadComic("~/App_Data/WebcomicX.xml");
@load.ManageSite();
var webpage = (from xml in webpageXml.Descendants("Page")
where xml.Element("Id").Value == pageId
select xml).FirstOrDefault();
try {
include = webpage.Element("Include").Value.AsBool();
} catch {
include = false;
}
try {
var theme = settings.Descendants("Settings").Descendants("Theme").ElementAt(0).Value;
if (HttpContext.Current.Request.Cookies["previewTheme"] != null && WebSecurity.IsAuthenticated) {
theme = HttpContext.Current.Request.Cookies["previewTheme"].Value;
}
if (HttpContext.Current.Session["previewTheme"] != null) {
HttpContext.Current.Session.Remove("previewTheme");
}
filePath = "~/content/themes/" + theme + "/layouts/_main.cshtml";
} catch {
}
Layout = filePath;
}
@if (include || WebSecurity.IsAuthenticated && webpage != null) {
if (webpage.Element("External").Value.AsBool()) {
Response.Redirect(webpage.Element("PermaLink").Value);
} else {
var redirectUrl = Request.Url.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped) + "/p/" + pageId + "/" + webpage.Element("PermaLink").Value;
if (UrlData[1] != webpage.Element("PermaLink").Value) {
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location", redirectUrl);
}
Page.PreppendTitle = webpage.Element("Title").Value + " - ";
@section head{
<meta name="description" content="@webpage.Element("Description").Value">
}
@section heading{
<h1>
@webpage.Element("Title").Value
@if (WebSecurity.IsAuthenticated) {
<a class="edit" href="/webcomicx/admin/edit-webpage/@pageId">Edit</a>
if (!include) {
<span class="subheading">This blog post has not been published yet so only you can see it</span>
}
}
</h1>
}
@section article{
@Html.Raw(webpage.Element("Content").Value)
}
}
} else {
Page.PreppendTitle = "404";
Response.Status = "404 Not Found";
@section heading{
<h1 itemprop="headline">404!</h1>
}
@section article{
<h2>Sorry, the page you were looking for does not exist.</h2>
}
}