-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.cfm
executable file
·173 lines (134 loc) · 3.51 KB
/
index.cfm
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<cfinclude template="plugin/config.cfm">
<cfset local = StructNew() />
<cfparam name="FORM.sitetree" default="">
<cfparam name="FORM.display_items" default="0">
<cfscript>
//Helper functions
function listPopAt(list, index){
var i = "";
for(var i=ListLen(list); i >= index; i--){
list = ListDeleteAt(list, i);
}
return list;
}
function createPages(node, parentid){
var k = "";
var sortedNodes = StructSort(node, "numeric", "asc", "order");
var OrderID = 1 ;
for(var k=1; k LTE ArrayLen(sortedNodes); k++){
//Get the struct here:
var item = sortedNodes[k];
var bean = man.getBean();
bean.setTitle(item);
bean.setSiteId(session.siteid);
bean.setParentID(arguments.parentid);
bean.setType('Page');
bean.setDisplay(FORM.display_items);
bean.setOrderNo(OrderID);
bean.save();
if(!StructIsEmpty(node[item].children)){
createPages(node[item].children, bean.getContentID());
}
OrderID++;
}
}
</cfscript>
<cfsavecontent variable="local.newBody">
<cfoutput>
<h2>#variables.pluginConfig.getName()#</h2>
<cfif Len(FORM.sitetree)>
<cfset aToParse = ListToArray(FORM.sitetree, Chr(13) & Chr(10))>
<cfset parsed = []>
<cfset depthCounter = 1>
<cfset stack = "">
<cfscript>
//Parse the tab into an array
for(a in aToParse){
depth = ListLen(a, Chr(9), true);
//if the depth changes we need to remove all the items from the depth specified.
if(depthCounter >= depth){
//pop the items from the list
stack = listPopAt(stack, depth);
}
stack = ListAppend(stack, a);
ArrayAppend(parsed,stack);
depthCounter = depth;
}
//Now create this into a Struct
stParsed = {};
currentNode = stParsed;
ordercounter = 1;
for(l in parsed){
items = ListToArray(l);
for(i in items){
if(!StructKeyExists(currentNode, i)){
currentNode[i] = {
order = ordercounter,
children = {}
};
currentNode = stParsed;
}
else {
currentNode = currentNode[i]['children'];
}
}
ordercounter++;
}
//Now we can go and create the items
man = $.getServiceFactory().getBean("ContentManager");
rootpageList = man.getlist({siteid=session.siteid, moduleid=00000000000000000000000000000000000});
rootID = rootPageList.contentID;
createPages(stParsed, rootID);
</cfscript>
<h3>Site Created!</h3>
</cfif>
<p>Just paste a tab delimited site structure and submit, this will then generate your site for you.
<br>
As an example, you can create a site outline as follows using tabs at the start of each item:
<pre>
About
Team
History
Vision
Mission
Products
Product 1
Product 2
Technical Specs
Features 2
Services
Service 1
Service 2
Features
Contact
Map
</pre>
<br>
The site generator will then create the list of pages as you have defined.
</p>
<form action="" method="post" accept-charset="utf-8">
<label for="site_tree:">Site Tree:</label>
<textarea name="sitetree" rows="20">
About
Team
History
Vision
Mission
Products
Product 1
Product 2
Technical Specs
Features 2
Services
Service 1
Service 2
Features
Contact
Map
</textarea>
<label for="display_items?">Display Items?<input type="checkbox" name="display_items" value="1" id="display_items"></label>
<p><input type="submit" value="Continue →"></p>
</form>
</cfoutput>
</cfsavecontent>
<cfoutput>#$.getBean('pluginManager').renderAdminTemplate(body=local.newBody,pageTitle=variables.pluginConfig.getName())#</cfoutput>