forked from sachatrauwaen/OpenBlocks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTemplate_Preview.ascx.cs
106 lines (84 loc) · 2.91 KB
/
Template_Preview.ascx.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#region Copyright
//
// Copyright (c) 2014
// by SatraBel
//
#endregion
#region Using Statements
using System;
using DotNetNuke.Entities.Modules;
using System.Web.Hosting;
using System.Collections.Generic;
using System.IO;
using Satrabel.OpenBlocks.Token;
using DotNetNuke.UI.Skins.Controls;
#endregion
namespace SatraBel.OpenBlocks
{
public partial class Template_Preview : PortalModuleBase
{
#region Event Handlers
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
}
string Template = "";
string Mode = "preview";
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (Request.QueryString["template"] != null)
{
Template = Request.QueryString["template"];
}
if (Request.QueryString["mode"] != null)
{
Mode = Request.QueryString["mode"];
}
if (!Page.IsPostBack)
{
try
{
string realfilename = HostingEnvironment.MapPath(Template);
Dictionary<string, string> parameters = new Dictionary<string, string>();
string dsFileName = Path.ChangeExtension(realfilename, ".datasource");
if (File.Exists(dsFileName))
{
string[] lines = File.ReadAllLines(dsFileName);
foreach (var item in lines)
{
string[] par = item.Split(new char[]{'='},2);
parameters.Add(par[0], par[1]);
}
}
if (Mode != "data")
{
parameters.Add("templatefile", Template);
}
if (Mode == "widget")
{
string Output = "{{widget ";
foreach (var item in parameters)
{
Output += item.Key + "=\"" + item.Value + "\" ";
}
Output += "}}";
lContent.Text = Output;
hlThis.NavigateUrl = Request.RawUrl.Replace("&mode=widget", "");
hlThis.Text = hlThis.NavigateUrl;
//hlThis.Visible = true;
}
else
{
lContent.Text = WidgetTokenProvider.ExecuteWidget(parameters);
}
}
catch (Exception ex)
{
DotNetNuke.UI.Skins.Skin.AddModuleMessage(this, Template + "/" + ex.Message, ModuleMessage.ModuleMessageType.RedError);
}
}
}
#endregion
}
}