-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpost.cfm
More file actions
97 lines (72 loc) · 4.08 KB
/
post.cfm
File metadata and controls
97 lines (72 loc) · 4.08 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<!---Set defaults --->
<cfparam name="form.id" default="" />
<cfparam name="form.content" default="" />
<cfparam name="form.pageurl" default="" />
<cfparam name="form.myCheckbox" default="" />
<!--- Only if content, id and url were passed --->
<cfif isdefined("form.content") and form.content neq "">
<cfif isdefined("form.pageurl") and form.pageurl neq "">
<cfif isdefined("form.id") and form.id neq "">
<cfset postTitle = trim(form.id) />
<cfset postName = replace(postTitle," ","-","ALL") />
<cfset AtSign = Left(postTitle,1) />
<!--- If data is coming from index.cfm ie homepage --->
<cfif form.pageurl eq "index.cfm">
<!--- Get the data via the attributed name --->
<cfset qry = model("page").findAll(select="id, pageUrl,attributes,value", where="attributes='#postName#' AND pageUrl='#form.pageurl#'")>
<!--- If there is no data, go ahead and insert into the page table --->
<cfif qry.recordcount eq 0>
<cfset newPage = model("page").new()>
<cfset newPage.attributes = "#postName#">
<cfset newPage.value = "#form.content#">
<cfset newPage.pageUrl = "#form.pageurl#">
<cfset newPage.save()>
<cfelse>
<!--- Update the record --->
<cfset attr = model("page").findOne(where="attributes='#postName#' AND pageUrl='#form.pageurl#'")>
<cfset attr.update(value="#form.content#")>
</cfif>
<!--- if the page is not a homepage --->
<cfelse>
<!---If the @ is present, remove the @ sign --->
<cfif AtSign eq "@">
<cfset postName = Right(postTitle,len(postTitle) - 1) />
<cfif isdefined("form.myCheckbox") and form.myCheckbox eq "true">
<cfset postNameUpdate = replace(form.content," ","-","ALL") />
<cfset postNameUpdate = replace(postNameUpdate,"<p>","","ALL") />
<cfset postNameUpdate = replace(postNameUpdate,"</p>","","ALL") />
<cfelse>
<cfset postNameUpdate = postName />
</cfif>
<cfelse>
<cfset postNameUpdate = postName />
</cfif>
<!--- Get the data via the post_name --->
<cfset qry = model("wp_post").findOne(select="id,post_name, post_title, post_excerpt, post_content", where="post_name='#postName#' AND post_status='publish'", returnAs="query")>
<!--- If there is no data, go ahead and insert into the page table --->
<cfif qry.recordcount eq 0>
<cfquery name="qry" datasource="longrun" result="qryResult">
Insert into wp_posts (post_title,post_name,post_content,post_excerpt)
Values(<cfqueryparam value="#postName#" cfsqltype="CF_SQL_VARCHAR">,
<cfqueryparam value="#form.content#" cfsqltype="CF_SQL_VARCHAR">);
</cfquery>
<cfelse>
<cfset post = model("wp_post").findOne(select="id,post_name, post_title, post_excerpt, post_content", where="post_name='#postName#' AND post_status='publish'")>
<cfset post.update(post_name="#LCase(trim(postNameUpdate))#")>
<cfif AtSign eq "@">
<cfset postTitle = "#form.content#">
<cfset postTitle = replace(postTitle,"<p>","","ALL") />
<cfset postTitle = replace(postTitle,"</p>","","ALL") />
<cfset post.update(post_title="#postTitle#")>
<cfelse>
<cfset post.update(post_content="#form.content#")>
</cfif>
<cfquery name="qry" datasource="longrun" result="qryResult">
update wp_posts set post_title = 'sophek' where id = 3338;
</cfquery>
<!---Redirect to new page if the pageName was changed --->
</cfif>
</cfif>
</cfif>
</cfif>
</cfif>