root/trunk/website/org/camden/blog/blog.cfc @ 5

Revision 5, 130.8 kB (checked in by DanWilson, 17 years ago)

Initial Commit Of ModelGlue? Website (upgrade to blogcfc 511)

Line 
1<!---
2        Name         : blog
3        Author       : Raymond Camden
4        Created      : February 10, 2003
5        Last Updated : 1/14/08
6        History      : Reset history for version 5.7
7                                 : delete enclosure on delete entry
8                                 : generateRSS fix for utc strings
9                                 : hide future/unreleased entries based on argument
10                                 : notifyentry has filters now to suppress email
11                                 : oracle fix in savecomment
12                                 : saveEntry will correctly schedule task
13                                 : approveComment, category can be list, version (rkc 5/18/07)
14                                 : some additional xmlformtting (rkc 1/14/08)
15        Purpose          : Blog CFC
16--->
17<cfcomponent displayName="Blog" output="false" hint="BlogCFC by Raymond Camden">
18
19        <!--- Load utils immidiately. --->
20        <cfset variables.utils = createObject("component", "utils")>           
21
22        <!--- Require 6.1 or higher --->
23        <cfset majorVersion = listFirst(server.coldfusion.productversion)>
24        <cfset minorVersion = listGetAt(server.coldfusion.productversion,2,".,")>
25        <cfset cfversion = majorVersion & "." & minorVersion>
26        <cfif (server.coldfusion.productname is "ColdFusion Server" and cfversion lte 6)
27                  or
28                  (server.coldfusion.productname is "BlueDragon" and cfversion lte 6.1)>
29                <cfset variables.utils.throw("Blog must be run under ColdFusion 6.1, BlueDragon 6.2, or higher.")>
30        </cfif>
31        <cfset variables.isColdFusionMX8 = server.coldfusion.productname is "ColdFusion Server" and cfversion gte 8>
32
33        <!--- Valid database types --->
34        <cfset validDBTypes = "MSACCESS,MYSQL,MSSQL,ORACLE">
35
36        <!--- current version --->
37        <cfset version = "5.9.3.006" />
38       
39        <!--- cfg file --->
40        <cfset variables.cfgFile = "#getDirectoryFromPath(GetCurrentTemplatePath())#/blog.ini.cfm">
41       
42        <!--- used for rendering --->
43        <cfset variables.renderMethods = structNew()>
44       
45        <!--- used for settings --->
46        <cfset variables.instance = "">
47       
48        <cffunction name="init" access="public" returnType="blog" output="false"
49                                hint="Initialize the blog engine">
50
51                <cfargument name="name" type="string" required="false" default="default" hint="Blog name, defaults to default in blog.ini">
52                <cfargument name="instanceData" type="struct" required="false" hint="Allows you to specify BlogCFC info at runtime.">
53
54                <cfset var renderDir = "">
55                <cfset var renderCFCs = "">
56                <cfset var cfcName = "">
57                <cfset var md = "">
58               
59                <cfif isDefined("arguments.instanceData")>
60                        <cfset instance = duplicate(arguments.instanceData)>
61                <cfelse>
62                        <cfif not listFindNoCase(structKeyList(getProfileSections(variables.cfgFile)),name)>
63                                <cfset variables.utils.throw("#arguments.name# isn't registered as a valid blog.")>
64                        </cfif>
65                        <cfset instance = structNew()>
66                        <cfset instance.dsn = variables.utils.configParam(variables.cfgFile,arguments.name,"dsn")>     
67                        <cfset instance.username = variables.utils.configParam(variables.cfgFile,arguments.name,"username")>   
68                        <cfset instance.password = variables.utils.configParam(variables.cfgFile,arguments.name,"password")>   
69                        <cfset instance.ownerEmail = variables.utils.configParam(variables.cfgFile, arguments.name, "owneremail")>
70                        <cfset instance.blogURL = variables.utils.configParam(variables.cfgFile, arguments.name, "blogURL")>
71                        <cfset instance.blogTitle = variables.utils.configParam(variables.cfgFile, arguments.name, "blogTitle")>
72                        <cfset instance.blogDescription = variables.utils.configParam(variables.cfgFile, arguments.name, "blogDescription")>
73                        <cfset instance.blogDBType = variables.utils.configParam(variables.cfgFile, arguments.name, "blogDBType")>
74                        <cfset instance.locale = variables.utils.configParam(variables.cfgFile, arguments.name, "locale")>
75                        <cfset instance.users = variables.utils.configParam(variables.cfgFile,arguments.name,"users")>
76                        <cfset instance.commentsFrom = variables.utils.configParam(variables.cfgFile,arguments.name,"commentsFrom")>
77                        <cfset instance.mailServer = variables.utils.configParam(variables.cfgFile,arguments.name,"mailserver")>
78                        <cfset instance.mailusername = variables.utils.configParam(variables.cfgFile,arguments.name,"mailusername")>
79                        <cfset instance.mailpassword = variables.utils.configParam(variables.cfgFile,arguments.name,"mailpassword")>
80                        <cfset instance.pingurls = variables.utils.configParam(variables.cfgFile,arguments.name,"pingurls")>
81                        <cfset instance.offset = variables.utils.configParam(variables.cfgFile, arguments.name, "offset")>
82                        <cfset instance.allowtrackbacks = variables.utils.configParam(variables.cfgFile, arguments.name, "allowtrackbacks")>
83                        <cfset instance.trackbackspamlist = variables.utils.configParam(variables.cfgFile, arguments.name, "trackbackspamlist")>
84                        <cfset instance.blogkeywords = variables.utils.configParam(variables.cfgFile, arguments.name, "blogkeywords")>
85                        <cfset instance.ipblocklist = variables.utils.configParam(variables.cfgFile, arguments.name, "ipblocklist")>
86                        <cfset instance.maxentries = variables.utils.configParam(variables.cfgFile, arguments.name, "maxentries")>
87                        <cfset instance.moderate = variables.utils.configParam(variables.cfgFile, arguments.name, "moderate")>
88                        <cfset instance.usecaptcha = variables.utils.configParam(variables.cfgFile, arguments.name, "usecaptcha")>
89                        <cfset instance.usecfp = variables.utils.configParam(variables.cfgFile, arguments.name, "usecfp")>                     
90                        <cfset instance.allowgravatars = variables.utils.configParam(variables.cfgFile, arguments.name, "allowgravatars")>                     
91                        <cfset instance.filebrowse = variables.utils.configParam(variables.cfgFile, arguments.name, "filebrowse")>
92                        <cfset instance.settings = variables.utils.configParam(variables.cfgFile, arguments.name, "settings")>
93                        <cfset instance.imageroot = variables.utils.configParam(variables.cfgFile, arguments.name, "imageroot")>                                                                       
94                        <cfset instance.itunesSubtitle = variables.utils.configParam(variables.cfgFile, arguments.name, "itunesSubtitle")>
95                        <cfset instance.itunesSummary = variables.utils.configParam(variables.cfgFile, arguments.name, "itunesSummary")>
96                        <cfset instance.itunesKeywords = variables.utils.configParam(variables.cfgFile, arguments.name, "itunesKeywords")>
97                        <cfset instance.itunesAuthor = variables.utils.configParam(variables.cfgFile, arguments.name, "itunesAuthor")>
98                        <cfset instance.itunesImage = variables.utils.configParam(variables.cfgFile, arguments.name, "itunesImage")>
99                        <cfset instance.itunesExplicit = variables.utils.configParam(variables.cfgFile, arguments.name, "itunesExplicit")>
100                        <cfset instance.usetweetbacks = variables.utils.configParam(variables.cfgFile, arguments.name, "usetweetbacks")>
101
102                </cfif>
103                               
104                <!--- Name the blog --->
105                <cfset instance.name = arguments.name>
106                               
107                <!--- Only real validation we do on instance data. --->                                         
108                <cfif not isValidDBType(instance.blogDBType)>
109                        <cfset variables.utils.throw("#instance.blogDBType# is not a supported value (#getValidDBTypes()#)")>
110                </cfif>
111
112                <!--- get a copy of ping --->
113                <cfif variables.isColdFusionMX8>
114                <cfset variables.ping = createObject("component", "ping8")>
115       
116                <cfelse>
117                        <cfset variables.ping = createObject("component", "ping7")>
118                </cfif>
119                       
120                <!--- get a copy of textblock --->
121                <cfset variables.textblock = createObject("component","textblock").init(dsn=instance.dsn, username=instance.username, password=instance.password, blog=instance.name)>
122
123                <!--- prepare rendering --->
124                <cfset renderDir = getDirectoryFromPath(GetCurrentTemplatePath()) & "/render/">
125                <!--- get my kids --->
126                <cfdirectory action="list" name="renderCFCs" directory="#renderDir#" filter="*.cfc">
127               
128                <cfloop query="renderCFCs">
129                        <cfset cfcName = listDeleteAt(renderCFCs.name, listLen(renderCFCs.name, "."), ".")>
130
131                        <cfif cfcName is not "render">
132                                <!--- store the name --->
133                                <cfset variables.renderMethods[cfcName] = structNew()>
134                                <!--- create an instance of the CFC. It better have a render method! --->
135                                <cfset variables.renderMethods[cfcName].cfc = createObject("component", "render.#cfcName#")>
136                                <cfset md = getMetaData(variables.renderMethods[cfcName].cfc)>
137                                <cfif structKeyExists(md, "instructions")>
138                                        <cfset variables.renderMethods[cfcName].instructions = md.instructions>
139                                </cfif>
140                        </cfif>
141                                               
142                </cfloop>
143
144                <cfreturn this>
145               
146        </cffunction>
147
148        <cffunction name="addCategory" access="remote" returnType="uuid" roles="admin" output="false"
149                                hint="Adds a category.">
150                <cfargument name="name" type="string" required="true"> 
151                <cfargument name="alias" type="string" required="true">
152               
153                <cfset var checkC = "">
154                <cfset var id = createUUID()>
155               
156                <cflock name="blogcfc.addCategory" type="exclusive" timeout=30>
157               
158                        <cfif categoryExists(name="#arguments.name#")>
159                                <cfset variables.utils.throw("#arguments.name# already exists as a category.")>
160                        </cfif>
161                       
162                        <cfquery datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
163                                insert into tblblogcategories(categoryid,categoryname,categoryalias,blog)
164                                values(
165                                        <cfqueryparam value="#id#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">,
166                                        <cfqueryparam value="#arguments.name#" cfsqltype="CF_SQL_VARCHAR" maxlength="50">,
167                                        <cfqueryparam value="#arguments.alias#" cfsqltype="CF_SQL_VARCHAR" maxlength="50">,
168                                        <cfqueryparam value="#instance.name#" cfsqltype="CF_SQL_VARCHAR" maxlength="50">)
169                        </cfquery>
170                                               
171                </cflock>
172               
173                <cfreturn id>
174        </cffunction>
175       
176        <cffunction name="addComment" access="remote" returnType="uuid" output="false"
177                                hint="Adds a comment.">
178                <cfargument name="entryid" type="uuid" required="true">
179                <cfargument name="name" type="string" required="true">
180                <cfargument name="email" type="string" required="true">
181                <!--- RBB 11/02/2005:  Added website argument --->
182                <cfargument name="website" type="string" required="true">
183                <cfargument name="comments" type="string" required="true">
184                <cfargument name="subscribe" type="boolean" required="true">
185                <cfargument name="subscribeonly" type="boolean" required="false" default="false">
186               
187                <cfset var newID = createUUID()>
188                <cfset var entry = "">
189                <cfset var spam = "">
190                <cfset var kill = createUUID()>
191               
192                <cfset arguments.comments = htmleditformat(arguments.comments)>
193                <cfset arguments.name = left(htmlEditFormat(arguments.name),50)>
194                <cfset arguments.email = left(htmlEditFormat(arguments.email),50)>
195                <!--- RBB 11/02/2005:  Added website element --->
196                <cfset arguments.website = left(htmlEditFormat(arguments.website),255)>
197                               
198                <cfif not entryExists(arguments.entryid)>
199                        <cfset variables.utils.throw("#arguments.entryid# is not a valid entry.")>
200                </cfif>
201               
202                <!--- get the entry so we can check for allowcomments --->
203                <cfset entry = getEntry(arguments.entryid,true)>
204                <cfif not entry.allowcomments>
205                        <cfset variables.utils.throw("#arguments.entryid# does not allow for comments.")>
206                </cfif>
207               
208                <!--- only check spam if not a sub --->
209                <cfif not arguments.subscribeonly>
210                        <!--- check spam and IPs --->
211                        <cfloop index="spam" list="#instance.trackbackspamlist#">
212                                <cfif findNoCase(spam, arguments.comments) or
213                                          findNoCase(spam, arguments.name) or
214                                          findNoCase(spam, arguments.website) or
215                                          findNoCase(spam, arguments.email)>
216                                        <cfset variables.utils.throw("Comment blocked for spam.")>
217                                </cfif>
218                        </cfloop>
219                        <cfloop list="#instance.ipblocklist#" index="spam">
220                                <cfif spam contains "*" and reFindNoCase(replaceNoCase(spam, '.', '\.','all'), cgi.REMOTE_ADDR)>
221                                        <cfset variables.utils.throw("Comment blocked for spam.")>
222                                <cfelseif spam is cgi.REMOTE_ADDR>             
223                                        <cfset variables.utils.throw("Comment blocked for spam.")>
224                                </cfif>
225                </cfloop>
226                </cfif>
227                                       
228                <cfquery datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
229                <!--- RBB 11/02/2005:  Added website element --->
230                insert into tblblogcomments(id,entryidfk,name,email,website,comment<cfif instance.blogDBTYPE is "ORACLE">s</cfif>,posted,subscribe,moderated,killcomment,subscribeonly)
231                values(<cfqueryparam value="#newID#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">,
232                           <cfqueryparam value="#arguments.entryid#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">,
233                           <cfqueryparam value="#arguments.name#" maxlength="50">,
234                           <cfqueryparam value="#arguments.email#" maxlength="50">,
235                                 <!--- RBB 11/02/2005:  Added website element --->
236         <cfqueryparam value="#arguments.website#" maxlength="255">,
237                        <cfif instance.blogDBType is "ORACLE">
238                                <cfqueryparam value="#arguments.comments#" cfsqltype="CF_SQL_CLOB">,
239                        <cfelse>
240                           <cfqueryparam value="#arguments.comments#" cfsqltype="CF_SQL_LONGVARCHAR">,
241                        </cfif> 
242                         <cfqueryparam value="#blogNow()#" cfsqltype="CF_SQL_TIMESTAMP">,
243                           <cfif instance.blogDBType is "MSSQL" or instance.blogDBType is "MSACCESS">
244                                   <cfqueryparam value="#arguments.subscribe#" cfsqltype="CF_SQL_BIT">
245                           <cfelse>
246                                        <!--- convert yes/no to 1 or 0 --->
247                                        <cfif arguments.subscribe>
248                                                <cfset arguments.subscribe = 1>
249                                        <cfelse>
250                                                <cfset arguments.subscribe = 0>
251                                        </cfif>
252                                   <cfqueryparam value="#arguments.subscribe#" cfsqltype="CF_SQL_TINYINT">
253                           </cfif>
254                           ,<cfif instance.moderate>0<cfelse>1</cfif>,
255                           <cfqueryparam value="#kill#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">,
256                           <cfqueryparam value="#arguments.subscribeonly#" cfsqltype="CF_SQL_TINYINT">
257                           )
258                </cfquery>
259               
260                <!--- If subscribe is no, auto set older posts in thread by this author to no --->
261                <cfif not arguments.subscribe>
262
263                        <cfquery datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
264                        update  tblblogcomments
265                        set             subscribe = 0
266                        where   entryidfk = <cfqueryparam value="#arguments.entryid#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">
267                        and             email = <cfqueryparam value="#arguments.email#" cfsqltype="cf_sql_varchar" maxlength="100">
268                        </cfquery>
269
270                </cfif>
271               
272                <cfreturn newID>
273        </cffunction>
274       
275        <cffunction name="addEntry" access="remote" returnType="uuid" roles="admin" output="true"
276                                hint="Adds an entry.">
277                <cfargument name="title" type="string" required="true">
278                <cfargument name="body" type="string" required="true">
279                <cfargument name="morebody" type="string" required="false" default="">
280                <cfargument name="alias" type="string" required="false" default="">
281                <cfargument name="posted" type="date" required="false" default="#blogNow()#">
282                <cfargument name="allowcomments" type="boolean" required="false" default="true">
283                <cfargument name="enclosure" type="string" required="false" default="">
284                <cfargument name="filesize" type="numeric" required="false" default="0">
285                <cfargument name="mimetype" type="string" required="false" default="">
286                <cfargument name="released" type="boolean" required="false" default="true">
287                <cfargument name="relatedEntries" type="string" required="false" default="">
288                <cfargument name="sendemail" type="boolean" required="false" default="true">
289                <cfargument name="duration" type="string" required="false" default="">
290                <cfargument name="subtitle" type="string" required="false" default="">
291                <cfargument name="summary" type="string" required="false" default="">
292                <cfargument name="keywords" type="string" required="false" default="">
293               
294                <cfset var id = createUUID()>
295                <cfset var theURL = "">
296                               
297                <cfquery datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
298                        insert into tblblogentries(id,title,body,posted
299                                <cfif len(arguments.morebody)>,morebody</cfif>
300                                <cfif len(arguments.alias)>,alias</cfif>
301                                ,username,blog,allowcomments,enclosure,summary,subtitle,keywords,duration,filesize,mimetype,released,views,mailed)
302                        values(
303                                <cfqueryparam value="#id#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">,
304                                <cfqueryparam value="#arguments.title#" cfsqltype="CF_SQL_VARCHAR" maxlength="100">,
305                                <cfif instance.blogDBTYPE is "ORACLE">
306                                        <cfqueryparam cfsqltype="cf_sql_clob" value="#arguments.body#">,
307                                <cfelse>
308                                        <cfqueryparam value="#arguments.body#" cfsqltype="CF_SQL_LONGVARCHAR">,
309                                </cfif>
310                               
311                                <cfqueryparam value="#arguments.posted#" cfsqltype="CF_SQL_TIMESTAMP">
312                                <cfif len(arguments.morebody)>
313                                        <cfif instance.blogDBType is "ORACLE">
314                                                ,<cfqueryparam cfsqltype="cf_sql_clob" value="#arguments.morebody#">
315                                        <cfelse>
316                                                ,<cfqueryparam value="#arguments.morebody#" cfsqltype="CF_SQL_LONGVARCHAR">
317                                        </cfif>
318                                </cfif>
319                                <cfif len(arguments.alias)>
320                                        ,<cfqueryparam value="#arguments.alias#" cfsqltype="CF_SQL_VARCHAR" maxlength="100">
321                                </cfif>
322                                ,<cfqueryparam value="#getAuthUser()#" cfsqltype="CF_SQL_VARCHAR" maxlength="50">,
323                                <cfqueryparam value="#instance.name#" cfsqltype="CF_SQL_VARCHAR" maxlength="50">,
324                            <cfif instance.blogDBType is not "MYSQL" AND instance.blogDBType is not "ORACLE">
325                                        <cfqueryparam value="#arguments.allowcomments#" cfsqltype="CF_SQL_BIT">
326                           <cfelse>
327                                        <!--- convert yes/no to 1 or 0 --->
328                                        <cfif arguments.allowcomments>
329                                                <cfset arguments.allowcomments = 1>
330                                        <cfelse>
331                                                <cfset arguments.allowcomments = 0>
332                                        </cfif>
333                                        <cfqueryparam value="#arguments.allowcomments#" cfsqltype="CF_SQL_TINYINT">
334                           </cfif>                 
335                                ,<cfqueryparam value="#arguments.enclosure#" cfsqltype="CF_SQL_VARCHAR" maxlength="255">
336                                ,<cfqueryparam value="#arguments.summary#" cfsqltype="CF_SQL_VARCHAR" maxlength="255">
337                                ,<cfqueryparam value="#arguments.subtitle#" cfsqltype="CF_SQL_VARCHAR" maxlength="100">
338                                ,<cfqueryparam value="#arguments.keywords#" cfsqltype="CF_SQL_VARCHAR" maxlength="100">
339                                ,<cfqueryparam value="#arguments.duration#" cfsqltype="CF_SQL_VARCHAR" maxlength="10"> 
340                                ,<cfqueryparam value="#arguments.filesize#" cfsqltype="CF_SQL_NUMERIC">
341                                ,<cfqueryparam value="#arguments.mimetype#" cfsqltype="CF_SQL_VARCHAR" maxlength="255">
342                                ,<cfif instance.blogDBType is not "MYSQL" and instance.blogDBType is not "ORACLE">
343                                        <cfqueryparam value="#arguments.released#" cfsqltype="CF_SQL_BIT">
344                           <cfelse>
345                                        <!--- convert yes/no to 1 or 0 --->
346                                        <cfif arguments.released>
347                                                <cfset arguments.released = 1>
348                                        <cfelse>
349                                                <cfset arguments.released = 0>
350                                        </cfif>
351                                        <cfqueryparam value="#arguments.released#" cfsqltype="CF_SQL_TINYINT">
352                           </cfif>                 
353                                ,0
354                                ,<cfif instance.blogDBType is not "MYSQL" AND instance.blogDBType is not "ORACLE">
355                                        <cfqueryparam value="false" cfsqltype="CF_SQL_BIT">
356                           <cfelse>
357                                        <cfqueryparam value="0" cfsqltype="CF_SQL_TINYINT">
358                           </cfif>                 
359                                )
360                </cfquery>
361
362                <cfif len(trim(arguments.relatedEntries)) GT 0>
363                        <cfset saveRelatedEntries(id, arguments.relatedEntries) />
364                </cfif>                 
365               
366                <!---
367                          Only mail if released = true, and posted not in the future
368                --->
369                <cfif arguments.sendEmail and arguments.released and dateCompare(dateAdd("h", instance.offset,arguments.posted), blogNow()) lte 0>
370
371                        <cfset mailEntry(id)>
372                       
373                </cfif>
374               
375                <cfif arguments.released>
376               
377                        <cfif arguments.sendEmail and dateCompare(dateAdd("h", instance.offset,arguments.posted), blogNow()) is 1>
378                                <!--- Handle delayed posting --->
379                                <cfset theURL = getRootURL()>
380                                <cfset theURL = theURL & "admin/notify.cfm?id=#id#">
381                                <cfschedule action="update" task="BlogCFC Notifier #id#" operation="HTTPRequest"
382                                                        startDate="#arguments.posted#" startTime="#arguments.posted#" url="#theURL#" interval="once">   
383                        <cfelse>
384                                <cfset variables.ping.pingAggregators(instance.pingurls, instance.blogtitle, instance.blogurl)>
385                        </cfif>
386
387                </cfif>         
388               
389               
390                <cfreturn id>
391               
392        </cffunction>
393
394        <cffunction name="addSubscriber" access="remote" returnType="string" output="false"
395                                hint="Adds a subscriber to the blog.">
396                <cfargument name="email" type="string" required="true">
397                <cfset var token = createUUID()>
398                <cfset var getMe = "">
399               
400                <!--- First, lets see if this guy is already subscribed. --->
401                <cfquery name="getMe" datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
402                select  email
403                from    tblblogsubscribers
404                where   email = <cfqueryparam value="#arguments.email#" cfsqltype="cf_sql_varchar" maxlength="50">
405                and             blog = <cfqueryparam value="#instance.name#" cfsqltype="cf_sql_varchar" maxlength="50">
406                </cfquery>
407               
408                <cfif getMe.recordCount is 0>
409                        <cfquery datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
410                        insert into tblblogsubscribers(email,
411                        token,
412                        blog,
413                        verified)
414                        values(<cfqueryparam value="#arguments.email#" cfsqltype="cf_sql_varchar" maxlength="50">,
415                        <cfqueryparam value="#token#" cfsqltype="cf_sql_varchar" maxlength="35">,
416                        <cfqueryparam value="#instance.name#" cfsqltype="cf_sql_varchar" maxlength="50">,
417                        0
418                        )
419                        </cfquery>
420
421                        <cfreturn token>               
422
423                <cfelse>
424               
425                        <cfreturn "">
426                       
427                </cfif>
428
429        </cffunction>
430
431        <cffunction name="addTrackBack" returnType="string" access="public" output="false"
432                                hint="Adds a trackback entry for a blog post.">
433                <cfargument name="title" type="string" required="true" hint="The title of the remote blog entry.">
434                <cfargument name="url" type="string" required="true" hint="The url of the remote blog entry.">
435                <cfargument name="blogName" type="string" required="true" hint="The name of the remote blog.">
436                <cfargument name="excerpt" type="string" required="true" hint="The excerpt from the remote blog entry.">
437                <cfargument name="id" type="string" required="true" hint="The id of the local blog entry.">
438
439                <cfset var checkTrackBack = "">
440                <cfset var newID = createUUID()>
441                <cfset var spam = "">
442               
443                <cfset arguments.title = left(htmlEditFormat(arguments.title),255)>
444                <cfset arguments.blogName = left(htmlEditFormat(arguments.blogName),255)>
445                <cfset arguments.blogurl = left(arguments.url,255)>
446               
447                <cfset arguments.excerpt = htmlEditFormat(arguments.excerpt)>
448               
449                <!--- look for spam in title, blogname, and except --->
450                <cfloop index="spam" list="#instance.trackbackspamlist#">
451                        <cfif findNoCase(spam, arguments.title) or
452                                  findNoCase(spam, arguments.blogName) or
453                                  findNoCase(spam, arguments.excerpt) or
454                                  findNoCase(spam, arguments.url)>
455                                <!--- silently fail --->
456                                <cfreturn "">
457                        </cfif>
458                </cfloop>
459
460                <cfif len(cgi.http_referer) and listFind(instance.ipblocklist, cgi.http_referer)>
461                        <cfreturn "">
462                </cfif>
463               
464                <!---
465                New security. Do not allow 2 TBs with same name+title+url. In theory you could beat this
466                by adding random chars to a postURL. It would be more secure to just check Name+Title,
467                but I'm starting with this for now.
468                --->           
469                <cfquery name="checkTrackBack" datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
470                        select  id
471                        from    tblblogtrackbacks
472                        where   blogName = <cfqueryparam value="#arguments.blogName#" cfsqltype="CF_SQL_VARCHAR" maxlength="255">
473                        and             title = <cfqueryparam value="#arguments.title#" cfsqltype="CF_SQL_VARCHAR" maxlength="255">
474                        and             postURL = <cfqueryparam value="#arguments.url#" cfsqltype="CF_SQL_VARCHAR" maxlength="255">
475                </cfquery>
476               
477                <cfif not checkTrackBack.recordcount>
478                        <cfquery datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
479                                insert  into tblblogtrackbacks (id, title, posturl, blogname, excerpt, created, entryid, blog)
480                                                values (
481                                                <cfqueryparam value="#newID#" cfsqltype="CF_SQL_VARCHAR">,
482                                                <cfqueryparam value="#arguments.title#" cfsqltype="CF_SQL_VARCHAR" maxlength="255">,
483                                                <cfqueryparam value="#arguments.url#" cfsqltype="CF_SQL_VARCHAR" maxlength="255">,
484                                                <cfqueryparam value="#arguments.blogName#" cfsqltype="CF_SQL_VARCHAR" maxlength="255">,
485                                                <cfif instance.blogDBType is not "ORACLE">
486                                                        <cfqueryparam cfsqltype="cf_sql_clob" value="#arguments.excerpt#">,
487                                                <cfelse>
488                                                        <cfqueryparam value="#arguments.excerpt#" cfsqltype="CF_SQL_LONGVARCHAR">,
489                                                </cfif>
490                                                <cfqueryparam value="#now()#" cfsqltype="CF_SQL_TIMESTAMP">,
491                                                <cfqueryparam value="#arguments.id#" cfsqltype="CF_SQL_VARCHAR">,
492                                                <cfqueryparam value="#instance.name#" cfsqltype="CF_SQL_VARCHAR">
493                                                )
494                        </cfquery>
495                <cfelse>
496                        <cfreturn "">
497                </cfif>
498               
499                <cfreturn newID>
500        </cffunction>
501       
502        <cffunction name="approveComment" access="public" returnType="void" output="false"
503                                hint="Approves a comment.">
504                <cfargument name="commentid" type="uuid" required="true">
505               
506                <cfquery datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
507                update tblblogcomments
508                set        moderated =
509                        <cfif instance.blogDBType is "MSSQL" or instance.blogDBType is "MSACCESS">
510                                <cfqueryparam value="true" cfsqltype="CF_SQL_BIT">
511                        <cfelse>
512                                <cfqueryparam value="1" cfsqltype="CF_SQL_TINYINT">
513                        </cfif>
514                where   id = <cfqueryparam value="#arguments.commentid#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">
515                </cfquery>
516                               
517        </cffunction>
518
519               
520        <cffunction name="assignCategory" access="remote" returnType="void" roles="admin" output="false"
521                                hint="Assigns entry ID to category X">
522                <cfargument name="entryid" type="uuid" required="true">
523                <cfargument name="categoryid" type="uuid" required="true">
524                <cfset var checkEC = "">
525                                               
526                <cfquery name="checkEC" datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
527                        select  categoryidfk
528                        from    tblblogentriescategories
529                        where   categoryidfk = <cfqueryparam value="#arguments.categoryid#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">
530                        and             entryidfk = <cfqueryparam value="#arguments.entryid#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">
531                </cfquery>
532
533                <cfif entryExists(arguments.entryid) and categoryExists(id=arguments.categoryID) and not checkEC.recordCount>
534                        <cfquery datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
535                                insert into tblblogentriescategories(categoryidfk,entryidfk)
536                                values(<cfqueryparam value="#arguments.categoryid#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">,<cfqueryparam value="#arguments.entryid#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">)
537                        </cfquery>
538                </cfif>
539               
540        </cffunction>
541
542        <cffunction name="assignCategories" access="remote" returnType="void" roles="admin" output="false"
543                                hint="Assigns entry ID to multiple categories">
544                <cfargument name="entryid" type="uuid" required="true">
545                <cfargument name="categoryids" type="string" required="true">
546
547                <cfset var i=0>
548               
549                <!--- Loop through categories --->
550                <cfloop index="i" from="1" to="#listLen(arguments.categoryids)#">
551                        <cfset assignCategory(arguments.entryid,listGetAt(categoryids,i))>
552                </cfloop>
553       
554        </cffunction>   
555       
556        <cffunction name="authenticate" access="public" returnType="boolean" output="false">
557                <cfargument name="username" type="string" required="true">
558                <cfargument name="password" type="string" required="true">
559               
560                <cfset var q = "">
561               
562                <cfquery name="q" datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
563                        select  username
564                        from    tblusers
565                        where   username = <cfqueryparam value="#arguments.username#" cfsqltype="CF_SQL_VARCHAR" maxlength="50">
566                        and             password = <cfqueryparam value="#arguments.password#" cfsqltype="CF_SQL_VARCHAR" maxlength="50">
567                        <!--- check for restricted users --->
568                        <cfif instance.users is not "">
569                        and             username in (<cfqueryparam value="#instance.users#" cfsqltype="CF_SQL_VARCHAR" list="Yes">)
570                        </cfif>
571                </cfquery>
572               
573                <cfreturn q.recordCount is 1>
574       
575        </cffunction>
576
577        <cffunction name="blogNow" access="public" returntype="date" output="false"
578                                hint="Returns now() with the offset.">
579                <cfreturn dateAdd("h", instance.offset, now())>
580        </cffunction>
581       
582        <cffunction name="categoryExists" access="private" returnType="boolean" output="false"
583                                hint="Returns true or false if an entry exists.">
584                <cfargument name="id" type="uuid" required="false">
585                <cfargument name="name" type="string" required="false">
586                <cfset var checkC = "">
587
588                <!--- must pass either ID or name, but not obth --->
589                <cfif (not isDefined("arguments.id") and not isDefined("arguments.name")) or (isDefined("arguments.id") and isDefined("arguments.name"))>
590                        <cfset variables.utils.throw("categoryExists method must be passed id or name, but not both.")>
591                </cfif>
592               
593                <cfquery name="checkC" datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
594                        select  categoryid
595                        from    tblblogcategories
596                        where   
597                                <cfif isDefined("arguments.id")>
598                                categoryid = <cfqueryparam value="#arguments.id#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">
599                                </cfif>
600                                <cfif isDefined("arguments.name")>
601                                categoryname = <cfqueryparam value="#arguments.name#" cfsqltype="CF_SQL_VARCHAR" maxlength="100">
602                                </cfif>
603                                and blog = <cfqueryparam value="#instance.name#" cfsqltype="CF_SQL_VARCHAR" maxlength="50">
604                               
605                </cfquery>
606       
607                <cfreturn checkC.recordCount gte 1>
608                       
609        </cffunction>
610       
611        <cffunction name="confirmSubscription" access="public" returnType="void" output="false"
612                                hint="Confirms a user's subscription to the blog.">
613                <cfargument name="token" type="uuid" required="false">
614                <cfargument name="email" type="string" required="false">
615               
616                <cfquery datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
617                update  tblblogsubscribers
618                set             verified = 1
619                <cfif structKeyExists(arguments, "token")>
620                where   token = <cfqueryparam cfsqltype="cf_sql_varchar" maxlength="35" value="#arguments.token#">
621                <cfelseif structKeyExists(arguments, "email")>
622                where   email = <cfqueryparam cfsqltype="cf_sql_varchar" maxlength="255" value="#arguments.email#">
623                <cfelse>
624                        <cfthrow message="Invalid call to confirmSubscription. Must pass token or email.">
625                </cfif>
626                </cfquery>
627               
628        </cffunction>
629       
630        <cffunction name="deleteCategory" access="public" returnType="void" roles="admin" output="false"
631                                hint="Deletes a category.">
632                <cfargument name="id" type="uuid" required="true">
633
634                <cfquery datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
635                        delete from tblblogentriescategories
636                        where categoryidfk = <cfqueryparam value="#arguments.id#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">
637                </cfquery>
638               
639                <cfquery datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
640                        delete from tblblogcategories
641                        where categoryid = <cfqueryparam value="#arguments.id#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">
642                </cfquery>
643
644        </cffunction>
645
646        <cffunction name="deleteComment" access="public" returnType="void" roles="admin" output="false"
647                                hint="Deletes a comment.">
648                <cfargument name="id" type="uuid" required="true">
649               
650                <cfquery datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
651                        delete from tblblogcomments
652                        where id = <cfqueryparam value="#arguments.id#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">
653                </cfquery>
654               
655        </cffunction>
656       
657        <cffunction name="deleteEntry" access="remote" returnType="void" roles="admin" output="false"
658                                hint="Deletes an entry, plus all comments.">
659                <cfargument name="id" type="uuid" required="true">
660                <cfset var entry = "">
661                <cfset var enclosure = "">
662               
663                <cfif entryExists(arguments.id)>
664               
665                        <!--- get the entry. we need it to clean up enclosure --->
666                        <cfset entry = getEntry(arguments.id)>
667                       
668                        <cfif entry.enclosure neq "">
669                                <cfif fileExists(entry.enclosure)>
670                                        <cffile action="delete" file="#entry.enclosure#">
671                                </cfif>
672                        </cfif>
673                       
674                        <cfquery datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
675                                delete from tblblogentries
676                                where id = <cfqueryparam value="#arguments.id#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">
677                                and       blog = <cfqueryparam value="#instance.name#" cfsqltype="CF_SQL_VARCHAR" maxlength="50">
678                        </cfquery>
679
680                        <cfquery datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">     
681                                delete from tblblogentriescategories
682                                where entryidfk = <cfqueryparam value="#arguments.id#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">
683                        </cfquery>
684                       
685                        <cfquery datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">     
686                                delete from tblblogcomments
687                                where entryidfk = <cfqueryparam value="#arguments.id#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">
688                        </cfquery>
689                                               
690                </cfif>
691                               
692        </cffunction>
693
694        <cffunction name="deleteTrackback" access="public" returnType="void" roles="" output="false"
695                                hint="Deletes a TB.">
696                <cfargument name="id" type="uuid" required="true">
697               
698                <cfquery datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
699                        delete from tblblogtrackbacks
700                        where id = <cfqueryparam value="#arguments.id#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">
701                </cfquery>
702               
703        </cffunction>
704       
705        <cffunction name="entryExists" access="private" returnType="boolean" output="false"
706                                hint="Returns true or false if an entry exists.">
707                <cfargument name="id" type="uuid" required="true">             
708                <cfset var getIt = "">
709               
710                <cfquery name="getIt" datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
711                        select          tblblogentries.id
712                        from            tblblogentries
713                        where           tblblogentries.id = <cfqueryparam value="#arguments.id#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">
714                        and                     tblblogentries.blog = <cfqueryparam value="#instance.name#" cfsqltype="CF_SQL_VARCHAR" maxlength="50">
715                        <cfif not isUserInRole("admin")>
716                        and                     posted < <cfqueryparam cfsqltype="cf_sql_timestamp" value="#now()#">
717                        and                     released = 1
718                        </cfif>
719                </cfquery>
720
721                <cfreturn getIt.recordCount gte 1>
722               
723        </cffunction>
724
725       
726        <cffunction name="generateRSS" access="remote" returnType="string" output="false"
727                                hint="Attempts to generate RSS 1.0">
728                <cfargument name="mode" type="string" required="false" default="short" hint="If mode=short, show EXCERPT chars of entries. Otherwise, show all.">
729                <cfargument name="excerpt" type="numeric" required="false" default="250" hint="If mode=short, this how many chars to show.">
730                <cfargument name="params" type="struct" required="false" default="#structNew()#" hint="Passed to getEntries. Note, maxEntries can't be bigger than 15.">
731                <cfargument name="version" type="numeric" required="false" default="2" hint="RSS verison, Options are 1 or 2">         
732                <cfargument name="additionalTitle" type="string" required="false" default="" hint="Adds a title to the end of your blog title. Used mainly by the cat view.">
733               
734                <cfset var articles = "">
735                <cfset var z = getTimeZoneInfo()>
736                <cfset var header = "">
737                <cfset var channel = "">
738                <cfset var items = "">
739                <cfset var dateStr = "">
740                <cfset var rssStr = "">
741                <cfset var utcPrefix = "">
742                <cfset var rootURL = "">
743                <cfset var cat = "">
744                <cfset var lastid = "">
745                <cfset var catid = "">
746                <cfset var catlist = "">
747               
748                <!--- Right now, we force this in. Useful to limit throughput of RSS feed. I may remove this later. --->
749                <cfif (structKeyExists(arguments.params,"maxEntries") and arguments.params.maxEntries gt 15) or not structKeyExists(arguments.params,"maxEntries")>
750                        <cfset arguments.params.maxEntries = 15>
751                </cfif>
752               
753                <cfset articles = getEntries(arguments.params)>
754                <!--- copy over just the actual query --->
755                <cfset articles = articles.entries>
756               
757                <cfif not find("-", z.utcHourOffset)>
758                        <cfset utcPrefix = " -">
759                <cfelse>
760                        <cfset z.utcHourOffset = right(z.utcHourOffset, len(z.utcHourOffset) -1 )>
761                        <cfset utcPrefix = " +">
762                </cfif>
763               
764               
765                <cfif arguments.version is 1>
766       
767                        <cfsavecontent variable="header">
768                        <cfoutput>
769                        <?xml version="1.0" encoding="utf-8"?>
770                       
771                        <rdf:RDF
772                                xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns##"
773                                xmlns:dc="http://purl.org/dc/elements/1.1/"
774                                xmlns="http://purl.org/rss/1.0/"
775                        >
776                        </cfoutput>
777                        </cfsavecontent>
778       
779                        <cfsavecontent variable="channel">
780                        <cfoutput>
781                        <channel rdf:about="#xmlFormat(instance.blogURL)#">
782                        <title>#xmlFormat(instance.blogTitle)##xmlFormat(arguments.additionalTitle)#</title>
783                        <description>#xmlFormat(instance.blogDescription)#</description>
784                        <link>#xmlFormat(instance.blogURL)#</link>
785               
786                        <items>
787                                <rdf:Seq>
788                                        <cfloop query="articles">
789                                        <rdf:li rdf:resource="#xmlFormat(makeLink(id))#" />
790                                        </cfloop>
791                                </rdf:Seq>
792                        </items>
793                       
794                        </channel>
795                        </cfoutput>
796                        </cfsavecontent>
797       
798                        <cfsavecontent variable="items">
799                        <cfloop query="articles">
800                        <cfset dateStr = dateFormat(posted,"yyyy-mm-dd")>
801                        <cfset dateStr = dateStr & "T" & timeFormat(posted,"HH:mm:ss") & utcPrefix & numberFormat(z.utcHourOffset,"00") & ":00">
802                        <cfoutput>
803                        <item rdf:about="#xmlFormat(makeLink(id))#">
804                        <title>#xmlFormat(title)#</title>
805                        <description><cfif arguments.mode is "short" and len(REReplaceNoCase(body,"<[^>]*>","","ALL")) gte arguments.excerpt>#xmlFormat(left(REReplaceNoCase(body,"<[^>]*>","","ALL"),arguments.excerpt))#...<cfelse>#xmlFormat(body)#</cfif><cfif len(morebody)> [More]</cfif></description>
806                        <link>#xmlFormat(makeLink(id))#</link>
807                        <dc:date>#dateStr#</dc:date>
808                        <cfloop item="catid" collection="#categories#">
809                                <cfset catlist = listAppend(catlist, xmlFormat(categories[currentRow][catid]))>
810                        </cfloop>
811                        <dc:subject>#xmlFormat(catlist)#</dc:subject>
812                        </item>
813                        </cfoutput>
814                        </cfloop>
815                        </cfsavecontent>
816       
817                        <cfset rssStr = trim(header & channel & items & "</rdf:RDF>")>
818       
819                <cfelseif arguments.version eq "2">
820               
821                        <cfset rootURL = reReplace(instance.blogURL, "(.*)/index.cfm", "\1")>
822
823                        <cfsavecontent variable="header">
824                        <cfoutput>
825                        <?xml version="1.0" encoding="utf-8"?>
826                       
827                        <rss version="2.0" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns##" xmlns:cc="http://web.resource.org/cc/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
828
829                        <channel>
830                        <title>#xmlFormat(instance.blogTitle)##xmlFormat(arguments.additionalTitle)#</title>
831                        <link>#xmlFormat(instance.blogURL)#</link>
832                        <description>#xmlFormat(instance.blogDescription)#</description>
833                        <language>#replace(lcase(instance.locale),'_','-','one')#</language>
834                        <pubDate>#dateFormat(blogNow(),"ddd, dd mmm yyyy") & " " & timeFormat(blogNow(),"HH:mm:ss") & utcPrefix & numberFormat(z.utcHourOffset,"00") & "00"#</pubDate>
835                        <lastBuildDate>{LAST_BUILD_DATE}</lastBuildDate>
836                        <generator>BlogCFC</generator>
837                        <docs>http://blogs.law.harvard.edu/tech/rss</docs>
838                        <managingEditor>#xmlFormat(instance.owneremail)#</managingEditor>
839                        <webMaster>#xmlFormat(instance.owneremail)#</webMaster>
840                        <itunes:subtitle>#xmlFormat(instance.itunesSubtitle)#</itunes:subtitle>
841                        <itunes:summary>#xmlFormat(instance.itunesSummary)#</itunes:summary>
842                        <itunes:category text="Technology" />
843                        <itunes:category text="Technology">
844                                <itunes:category text="Podcasting" />
845                        </itunes:category>
846                        <itunes:category text="Technology">
847                                <itunes:category text="Tech News" />
848                        </itunes:category>
849                        <itunes:keywords>#xmlFormat(instance.itunesKeywords)#</itunes:keywords>
850                        <itunes:author>#xmlFormat(instance.itunesAuthor)#</itunes:author>
851                        <itunes:owner>
852                                <itunes:email>#xmlFormat(instance.owneremail)#</itunes:email>
853                                <itunes:name>#xmlFormat(instance.itunesAuthor)#</itunes:name>
854                        </itunes:owner>
855                        <itunes:image href="#xmlFormat(instance.itunesImage)#" />
856                        <image>
857                                <url>#xmlFormat(instance.itunesImage)#</url>
858                                <title>#xmlFormat(instance.blogTitle)#</title>
859                                <link>#xmlFormat(instance.blogURL)#</link>
860                        </image>
861                        <itunes:explicit>#xmlFormat(instance.itunesExplicit)#</itunes:explicit>
862                        </cfoutput>
863                        </cfsavecontent>
864               
865                        <cfsavecontent variable="items">
866                        <cfloop query="articles">
867                        <cfset dateStr = dateFormat(posted,"ddd, dd mmm yyyy") & " " & timeFormat(posted,"HH:mm:ss") & utcPrefix & numberFormat(z.utcHourOffset,"00") & "00">
868                        <cfoutput>
869                        <item>
870                                <title>#xmlFormat(title)#</title>
871                                <link>#xmlFormat(makeLink(id))#</link>
872                                <description>
873                                <!--- Regex operation removes HTML code from blog body output --->
874                                <cfif arguments.mode is "short" and len(REReplaceNoCase(body,"<[^>]*>","","ALL")) gte arguments.excerpt>
875                                #xmlFormat(left(REReplace(body,"<[^>]*>","","All"),arguments.excerpt))#...
876                                <cfelse>#xmlFormat(body)#</cfif>
877                                <cfif len(morebody)> [More]</cfif>
878                                </description>
879                                <cfset lastid = listLast(structKeyList(categories))>           
880                                <cfloop item="catid" collection="#categories#">
881                                <category>#xmlFormat(categories[currentRow][catid])#</category>                         
882                                </cfloop>
883                                <pubDate>#dateStr#</pubDate>
884                                <guid>#xmlFormat(makeLink(id))#</guid>
885                                <!---
886                                <author>
887                                <name>#xmlFormat(name)#</name>
888                                </author>
889                                --->
890                                <cfif len(enclosure)>
891                                <enclosure url="#xmlFormat("#rootURL#/enclosures/#getFileFromPath(enclosure)#")#" length="#filesize#" type="#mimetype#"/>
892                                <cfif mimetype IS "audio/mpeg">
893                                <itunes:author>#xmlFormat(instance.itunesAuthor)#</itunes:author>
894                                <itunes:explicit>#xmlFormat(instance.itunesExplicit)#</itunes:explicit>
895                                <itunes:duration>#xmlFormat(duration)#</itunes:duration>
896                                <itunes:keywords>#xmlFormat(keywords)#</itunes:keywords>
897                                <itunes:subtitle>#xmlFormat(subtitle)#</itunes:subtitle>
898                                <itunes:summary>#xmlFormat(summary)#</itunes:summary>
899                                <itunes:image href="#xmlFormat(instance.itunesImage)#" />
900                                </cfif>
901                                </cfif>
902                        </item>
903                        </cfoutput>
904                        </cfloop>
905                        </cfsavecontent>
906               
907                        <cfset header = replace(header,'{LAST_BUILD_DATE}','#dateFormat(articles.posted[1],"ddd, dd mmm yyyy") & " " & timeFormat(articles.posted[1],"HH:mm:ss") & utcPrefix & numberFormat(z.utcHourOffset,"00") & "00"#','one')>
908                        <cfset rssStr = trim(header & items & "</channel></rss>")>
909               
910                </cfif>
911                                                       
912                <cfreturn rssStr>
913               
914        </cffunction>
915       
916        <cffunction name="getActiveDays" returnType="string" output="false" hint="Returns a list of days with Entries.">
917                <cfargument name="year" type="numeric" required="true">
918                <cfargument name="month" type="numeric" required="true">
919               
920                <cfset var dtMonth = createDateTime(arguments.year,arguments.month,1,0,0,0)>
921                <cfset var dtEndOfMonth = createDateTime(arguments.year,arguments.month,daysInMonth(dtMonth),23,59,59)>
922                <cfset var days = "">
923                <cfset var posted = "">         
924
925                <cfif instance.blogDBType is "MSSQL">
926                        <cfset posted = "dateAdd(hh, #instance.offset#, tblblogentries.posted)">
927                <cfelseif instance.blogDBType is "MSACCESS">
928                        <cfset posted = "dateAdd('h', #instance.offset#, tblblogentries.posted)">
929                <cfelseif instance.blogDBType is "MYSQL">
930                        <cfset posted = "date_add(posted, interval #instance.offset# hour)">
931                <cfelseif instance.blogDBType is "ORACLE">
932                        <cfset posted = "tblblogentries.posted + (#instance.offset#/24)">
933                </cfif>                         
934               
935                <cfquery datasource="#instance.dsn#" name="days" username="#instance.username#" password="#instance.password#">
936                        select distinct
937                                <cfif instance.blogDBType is "MSSQL">
938                                        datepart(dd, #preserveSingleQuotes(posted)#)
939                                <cfelseif instance.blogDBType is "MYSQL">
940                                        extract(day from #preserveSingleQuotes(posted)#)
941                                <cfelseif instance.blogDBType is "MSACCESS">
942                                        datepart('d', #preserveSingleQuotes(posted)#)
943                                <cfelseif instance.blogDBType is "ORACLE">
944                                        to_char(#preserveSingleQuotes(posted)#, 'dd')   
945                                </cfif> as posted_day
946                        from tblblogentries
947                        where
948                                #preserveSingleQuotes(posted)# >= <cfqueryparam value="#dtMonth#" cfsqltype="CF_SQL_TIMESTAMP">
949                                and
950                                #preserveSingleQuotes(posted)# <= <cfqueryparam value="#dtEndOfMonth#" cfsqltype="CF_SQL_TIMESTAMP">
951                                and blog = <cfqueryparam value="#instance.name#" cfsqltype="CF_SQL_VARCHAR" maxlength="50">
952                                and     #preserveSingleQuotes(posted)# < <cfqueryparam cfsqltype="cf_sql_timestamp" value="#blogNow()#">
953                                and     released = 1
954                </cfquery>
955
956                <cfreturn valueList(days.posted_day)>
957
958        </cffunction>
959       
960        <cffunction name="getCategories" access="remote" returnType="query" output="false">
961                <cfset var getC = "">
962                <cfset var getTotal = "">
963               
964                <!---
965                Update on May 10, 2006
966                So I wanted to update the code to handle cats with 0 entries. This proved difficult.
967                My friend Tai sent code that he said would work on both mssql and mysql,
968                but it only worked on mssql for me.
969               
970                So for now I'm going to use the "nice" method for mssql, and the "hack" method
971                for the others. The hack method will be slower, but it should not be terrible.
972                --->
973               
974                <cfif instance.blogDBType is "mssql">
975
976                        <cfquery name="getC" datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
977                                select  tblblogcategories.categoryid, tblblogcategories.categoryname, tblblogcategories.categoryalias, count(tblblogentriescategories.entryidfk) as entryCount
978                                from    (tblblogcategories
979                                left outer join
980                                tblblogentriescategories ON tblblogcategories.categoryid = tblblogentriescategories.categoryidfk)
981                                left join tblblogentries on tblblogentriescategories.entryidfk = tblblogentries.id
982                                where   tblblogcategories.blog = <cfqueryparam value="#instance.name#" cfsqltype="CF_SQL_VARCHAR" maxlength="50">
983                                <!--- Don't allow future posts unless logged in. --->
984                                <cfif not isUserInRole("admin")>
985                                                and isNull(tblblogentries.posted, '1/1/1900') < <cfqueryparam cfsqltype="cf_sql_timestamp" value="#blogNow()#">
986                                                and isNull(tblblogentries.released, 1) = 1
987                                </cfif>
988                                group by tblblogcategories.categoryid, tblblogcategories.categoryname, tblblogcategories.categoryalias
989                                order by tblblogcategories.categoryname
990                        </cfquery>
991
992                <cfelse>
993               
994                        <cfquery name="getC" datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
995                        select  tblblogcategories.categoryid, tblblogcategories.categoryname, tblblogcategories.categoryalias
996                        from    tblblogcategories
997                        where   tblblogcategories.blog = <cfqueryparam value="#instance.name#" cfsqltype="CF_SQL_VARCHAR" maxlength="50">
998                        order by tblblogcategories.categoryname
999                        </cfquery>
1000
1001                        <cfset queryAddColumn(getC, "entrycount", arrayNew(1))>
1002                       
1003                        <cfloop query="getC">
1004                                <cfquery name="getTotal" datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
1005                                select  count(tblblogentriescategories.entryidfk) as total
1006                                from    tblblogentriescategories, tblblogentries
1007                                where   tblblogentriescategories.categoryidfk = <cfqueryparam value="#categoryid#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">
1008                                and    tblblogentriescategories.entryidfk = tblblogentries.id
1009                                and    tblblogentries.released = 1                             
1010                                </cfquery>
1011                                <cfif getTotal.recordCount>
1012                                        <cfset querySetCell(getC, "entrycount", getTotal.total, currentRow)>
1013                                <cfelse>
1014                                        <cfset querySetCell(getC, "entrycount", 0, currentRow)>
1015                                </cfif>
1016                        </cfloop>
1017                </cfif>
1018               
1019                <cfreturn getC>
1020        </cffunction>
1021       
1022        <cffunction name="getCategoriesForEntry" access="remote" returnType="query" output="false">
1023                <cfargument name="id" type="uuid" required="true">
1024                <cfset var getC = "">
1025               
1026                <cfif not entryExists(arguments.id)>
1027                        <cfset variables.utils.throw("#arguments.id# does not exist.")>
1028                </cfif>
1029               
1030                <!--- updated "variables.dsn" to "instance.dsn" (DS 8/22/06) --->
1031                <cfquery name="getC" datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
1032                        select  tblblogcategories.categoryID, tblblogcategories.categoryname
1033                        from    tblblogcategories, tblblogentriescategories
1034                        where   tblblogcategories.categoryID = tblblogentriescategories.categoryidfk
1035                        and             tblblogentriescategories.entryidfk = <cfqueryparam value="#arguments.id#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">
1036                </cfquery>
1037                <cfreturn getC>
1038
1039        </cffunction>
1040
1041        <cffunction name="getCategory" access="remote" returnType="query" output="false">
1042                <cfargument name="id" type="uuid" required="true">
1043                <cfset var getC = "">
1044               
1045                <cfif not categoryExists(id="#arguments.id#")>
1046                        <cfset variables.utils.throw("#arguments.id# is not a valid category.")>
1047                </cfif>
1048               
1049                <cfquery name="getC" datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
1050                        select  categoryname, categoryalias
1051                        from    tblblogcategories
1052                        where   categoryid = <cfqueryparam value="#arguments.id#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">
1053                        and             blog = <cfqueryparam value="#instance.name#" cfsqltype="CF_SQL_VARCHAR" maxlength="50">
1054                </cfquery>
1055               
1056                <cfreturn getC>
1057               
1058        </cffunction>
1059
1060        <cffunction name="getCategoryByAlias" access="remote" returnType="string" output="false">
1061                <cfargument name="alias" type="string" required="true">
1062                <cfset var getC = "">
1063                               
1064                <cfquery name="getC" datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
1065                        select  categoryid
1066                        from    tblblogcategories
1067                        where   categoryalias = <cfqueryparam value="#arguments.alias#" cfsqltype="CF_SQL_VARCHAR" maxlength="50">
1068                        and             blog = <cfqueryparam value="#instance.name#" cfsqltype="CF_SQL_VARCHAR" maxlength="50">
1069                </cfquery>
1070               
1071                <cfreturn getC.categoryid>
1072               
1073        </cffunction>
1074
1075        <!--- This method originally written for parseses, but is not used. Keeping it around though. --->
1076        <cffunction name="getCategoryByName" access="remote" returnType="string" output="false">
1077                <cfargument name="name" type="string" required="true">
1078                <cfset var getC = "">
1079                               
1080                <cfquery name="getC" datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
1081                        select  categoryid
1082                        from    tblblogcategories
1083                        where   categoryname = <cfqueryparam value="#arguments.name#" cfsqltype="CF_SQL_VARCHAR" maxlength="50">
1084                        and             blog = <cfqueryparam value="#instance.name#" cfsqltype="CF_SQL_VARCHAR" maxlength="50">
1085                </cfquery>
1086               
1087                <cfreturn getC.categoryid>
1088               
1089        </cffunction>
1090
1091        <cffunction name="getComment" access="remote" returnType="query" output="false"
1092                                hint="Gets a comment.">
1093                <cfargument name="id" type="uuid" required="true">
1094                <cfset var getC = "">
1095               
1096                <cfquery name="getC" datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
1097                        select          id, entryidfk, name, email, website, comment<cfif instance.blogDBTYPE is "ORACLE">s</cfif>, posted, subscribe, moderated, killcomment
1098                        from            tblblogcomments
1099                        where           id = <cfqueryparam value="#arguments.id#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">
1100                </cfquery>
1101               
1102                <!--- DS 8/22/06: if this is oracle, do a q of q to return the data with column named "comment" --->
1103                <cfif instance.blogDBType is "ORACLE">
1104                        <cfquery name="getC" dbtype="query">
1105                                select          id, entryidfk, name, email, website, comments AS comment, posted, subscribe, moderated, killcomment
1106                                from            getC
1107                        </cfquery>
1108                </cfif>
1109                <cfreturn getC>
1110
1111        </cffunction>
1112       
1113        <cffunction name="getComments" access="remote" returnType="query" output="false"
1114                                hint="Gets comments for an entry.">
1115                <cfargument name="id" type="uuid" required="false">
1116                <cfargument name="sortdir" type="string" required="false" default="asc">
1117                <cfargument name="includesubscribers" type="boolean" required="false" default="false">
1118                <cfargument name="search" type="string" required="false">
1119               
1120                <cfset var getC = "">
1121                <cfset var getO = "">
1122               
1123                <cfif structKeyExists(arguments, "id") and not entryExists(arguments.id)>
1124                        <cfset variables.utils.throw("#arguments.id# does not exist.")>
1125                </cfif>
1126               
1127                <cfif arguments.sortDir is not "asc" and arguments.sortDir is not "desc">
1128                        <cfset arguments.sortDir = "asc">
1129                </cfif>
1130               
1131                <!--- RBB 11/02/2005: Added website to query --->
1132                <cfquery name="getC" datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
1133                        select          tblblogcomments.id, tblblogcomments.name, tblblogcomments.email, tblblogcomments.website,
1134                                                <cfif instance.blogDBTYPE is NOT "ORACLE">tblblogcomments.comment<cfelse>to_char(tblblogcomments.comments) as comments</cfif>, tblblogcomments.posted, tblblogcomments.subscribe, tblblogentries.title as entrytitle, tblblogcomments.entryidfk
1135                        from            tblblogcomments, tblblogentries
1136                        where           tblblogcomments.entryidfk = tblblogentries.id
1137                        <cfif structKeyExists(arguments, "search")>
1138                        and                     
1139                                                (
1140                                                <cfif instance.blogDBTYpe is not "ORACLE">
1141                                                tblblogcomments.comment
1142                                                <cfelse>
1143                                                comments
1144                                                </cfif> like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#arguments.search#%">
1145                                                or
1146                                                tblblogcomments.name like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#arguments.search#%">
1147                                                )
1148                        </cfif>
1149                        <cfif structKeyExists(arguments, "id")>
1150                        and                     tblblogcomments.entryidfk = <cfqueryparam value="#arguments.id#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">
1151                        </cfif>
1152                        and                     tblblogentries.blog = <cfqueryparam value="#instance.name#" cfsqltype="CF_SQL_VARCHAR" maxlength="50">
1153                        <!--- added 12/5/2006 by Trent Richardson --->
1154                        <cfif instance.moderate>
1155                                and tblblogcomments.moderated = 1
1156                        </cfif>
1157                        <cfif not arguments.includesubscribers>
1158                        and (subscribeonly = 0 or subscribeonly is null)               
1159                        </cfif>
1160                        order by        tblblogcomments.posted #arguments.sortdir#
1161                </cfquery>
1162
1163                <!--- DS 8/22/06: if this is oracle, do a q of q to return the data with column named "comment" --->
1164                <cfif instance.blogDBType is "ORACLE">
1165                        <cfquery name="getO" dbtype="query">
1166                        select          id, name, email, website,
1167                                                comments AS comment, posted, subscribe, entrytitle, entryidfk
1168                        from            getC
1169                        order by        posted #arguments.sortdir#
1170                        </cfquery>
1171                       
1172                        <cfreturn getO>
1173                </cfif>
1174               
1175                <cfreturn getC>
1176               
1177        </cffunction>
1178       
1179        <cffunction name="getEntry" access="remote" returnType="struct" output="false"
1180                                hint="Returns one particular entry.">
1181                <cfargument name="id" type="uuid" required="true">
1182                <cfargument name="dontlog" type="boolean" required="false" default="false">
1183                <cfset var getIt = "">
1184                <cfset var s = structNew()>
1185                <cfset var col = "">
1186                <cfset var getCategories = "">
1187               
1188                <cfif not entryExists(arguments.id)>
1189                        <cfset variables.utils.throw("#arguments.id# does not exist.")>
1190                </cfif>
1191       
1192                <cfquery name="getIt" datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
1193                        select          tblblogentries.id, tblblogentries.title,
1194                                                <!--- Handle offset --->
1195                                                <cfif instance.blogDBType is "MSACCESS">
1196                                                dateAdd('h', #instance.offset#, tblblogentries.posted) as posted,
1197                                                <cfelseif instance.blogDBType is "MSSQL">
1198                                                dateAdd(hh, #instance.offset#, tblblogentries.posted) as posted,
1199                                                <cfelseif instance.blogDBType is "ORACLE">
1200                                                tblblogentries.posted + (#instance.offset#/24) as posted,
1201                                                <cfelse>
1202                                                date_add(posted, interval #instance.offset# hour) as posted,
1203                                                </cfif>
1204                                                tblblogentries.body,
1205                                                tblblogentries.morebody, tblblogentries.alias, tblusers.name, tblblogentries.allowcomments,
1206                                                tblblogentries.enclosure, tblblogentries.filesize, tblblogentries.mimetype, tblblogentries.released, tblblogentries.mailed,
1207                                                tblblogentries.summary, tblblogentries.keywords, tblblogentries.subtitle, tblblogentries.duration
1208                        from            tblblogentries, tblusers
1209                        where           tblblogentries.id = <cfqueryparam value="#arguments.id#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">
1210                        and                     tblblogentries.blog = <cfqueryparam value="#instance.name#" cfsqltype="CF_SQL_VARCHAR" maxlength="50">
1211                        and                     tblblogentries.username = tblusers.username
1212                </cfquery>
1213
1214                <cfquery name="getCategories" datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
1215                        select  categoryid,categoryname
1216                        from    tblblogcategories, tblblogentriescategories
1217                        where   tblblogentriescategories.entryidfk = <cfqueryparam value="#arguments.id#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">
1218                        and             tblblogentriescategories.categoryidfk = tblblogcategories.categoryid
1219                </cfquery>
1220                               
1221                <cfloop index="col" list="#getIt.columnList#">
1222                        <cfset s[col] = getIt[col][1]>
1223                </cfloop>
1224
1225                <cfset s.categories = structNew()>
1226                <cfloop query="getCategories">
1227                        <cfset s.categories[categoryid] = categoryname>
1228                </cfloop>
1229               
1230                <!--- Handle view --->
1231                <cfif not arguments.dontlog>
1232                        <cfquery datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
1233                        update  tblblogentries
1234                        set             views = views + 1
1235                        where   id = <cfqueryparam value="#arguments.id#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">
1236                        </cfquery>
1237                </cfif>
1238                               
1239                <cfreturn s>
1240               
1241        </cffunction>
1242       
1243        <cffunction name="getEntriesOld" access="remote" returnType="query" output="false"
1244                                hint="Returns entries. Allows for a params structure to configure what entries are returned.">
1245                <cfargument name="params" type="struct" required="false" default="#structNew()#">
1246                <cfset var getEm = "">
1247                <cfset var getComments = "">
1248                <cfset var getCategories = "">
1249                <cfset var getTrackbacks = "">
1250                <cfset var validOrderBy = "posted,title">
1251                <cfset var validOrderByDir = "asc,desc">
1252                <cfset var validMode = "short,full">
1253                <cfset var pos = "">
1254                <cfset var id = "">
1255                <cfset var catdata = "">
1256
1257                <!--- By default, order the results by posted col --->
1258                <cfif not structKeyExists(arguments.params,"orderBy") or not listFindNoCase(validOrderBy,arguments.params.orderBy)>
1259                        <cfset arguments.params.orderBy = "posted">
1260                </cfif>
1261                <!--- By default, order the results direction desc --->
1262                <cfif not structKeyExists(arguments.params,"orderByDir") or not listFindNoCase(validOrderByDir,arguments.params.orderByDir)>
1263                        <cfset arguments.params.orderByDir = "desc">
1264                </cfif>
1265                <!--- If lastXDays is passed, verify X is int between 1 and 365 --->
1266                <cfif structKeyExists(arguments.params,"lastXDays")>
1267                        <cfif not val(arguments.params.lastXDays) or val(arguments.params.lastXDays) lt 1 or val(arguments.params.lastXDays) gt 365>
1268                                <cfset structDelete(arguments.params,"lastXDays")>
1269                        <cfelse>
1270                                <cfset arguments.params.lastXDays = val(arguments.params.lastXDays)>
1271                        </cfif>
1272                </cfif>
1273                <!--- If byDay is passed, verify X is int between 1 and 31 --->
1274                <cfif structKeyExists(arguments.params,"byDay")>
1275                        <cfif not val(arguments.params.byDay) or val(arguments.params.byDay) lt 1 or val(arguments.params.byDay) gt 31>
1276                                <cfset structDelete(arguments.params,"byDay")>
1277                        <cfelse>
1278                                <cfset arguments.params.byDay = val(arguments.params.byDay)>
1279                        </cfif>
1280                </cfif>
1281                <!--- If byMonth is passed, verify X is int between 1 and 12 --->
1282                <cfif structKeyExists(arguments.params,"byMonth")>
1283                        <cfif not val(arguments.params.byMonth) or val(arguments.params.byMonth) lt 1 or val(arguments.params.byMonth) gt 12>
1284                                <cfset structDelete(arguments.params,"byMonth")>
1285                        <cfelse>
1286                                <cfset arguments.params.byMonth = val(arguments.params.byMonth)>
1287                        </cfif>
1288                </cfif>
1289                <!--- If byYear is passed, verify X is int  --->
1290                <cfif structKeyExists(arguments.params,"byYear")>
1291                        <cfif not val(arguments.params.byYear)>
1292                                <cfset structDelete(arguments.params,"byYear")>
1293                        <cfelse>
1294                                <cfset arguments.params.byYear = val(arguments.params.byYear)>
1295                        </cfif>
1296                </cfif>
1297                <!--- If byTitle is passed, verify we have a length  --->
1298                <cfif structKeyExists(arguments.params,"byTitle")>
1299                        <cfif not len(trim(arguments.params.byTitle))>
1300                                <cfset structDelete(arguments.params,"byTitle")>
1301                        <cfelse>
1302                                <cfset arguments.params.byTitle = trim(arguments.params.byTitle)>
1303                        </cfif>
1304                </cfif>
1305
1306                <!--- By default, get body, commentCount and categories as well, requires additional lookup --->
1307                <cfif not structKeyExists(arguments.params,"mode") or not listFindNoCase(validMode,arguments.params.mode)>
1308                        <cfset arguments.params.mode = "full">
1309                </cfif>
1310                <!--- handle searching --->
1311                <cfif structKeyExists(arguments.params,"searchTerms") and not len(trim(arguments.params.searchTerms))>
1312                        <cfset structDelete(arguments.params,"searchTerms")>
1313                </cfif>
1314                <!--- Limit number returned. Thanks to Rob Brooks-Bilson --->
1315                <cfif structKeyExists(arguments.params,"maxEntries") and not val(arguments.params.maxEntries)>
1316                        <cfset structDelete(arguments.params,"maxEntries")>
1317                </cfif>
1318               
1319                <cfquery name="getEm" datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
1320                <!--- DS 8/22/06: added Oracle pseudo top n code --->
1321                <cfif instance.blogDBType is "ORACLE" AND structKeyExists(arguments.params, "maxEntries")>
1322                SELECT * FROM (
1323                </cfif>
1324                        select         
1325                                <cfif structKeyExists(arguments.params,"maxEntries") and
1326                                          instance.blogDBType is not "MYSQL" AND instance.blogDBType is not "ORACLE">
1327                                        top #arguments.params.maxEntries#
1328                                </cfif>
1329                                        tblblogentries.id, tblblogentries.title,
1330                                        tblblogentries.alias,
1331                                        <!--- Handle offset --->
1332                                        <cfif instance.blogDBType is "MSACCESS">
1333                                                dateAdd('h', #instance.offset#, tblblogentries.posted) as posted,
1334                                        <cfelseif instance.blogDBType is "MSSQL">
1335                                                dateAdd(hh, #instance.offset#, tblblogentries.posted) as posted,
1336                                        <cfelseif instance.blogDBType is "ORACLE">
1337                                                tblblogentries.posted + (#instance.offset#/24) as posted,       
1338                                        <cfelse>
1339                                        date_add(posted, interval #instance.offset# hour) as posted,
1340                                        </cfif>
1341                                        tblusers.name, tblblogentries.allowcomments,
1342                                        tblblogentries.enclosure, tblblogentries.filesize, tblblogentries.mimetype, tblblogentries.released, tblblogentries.views,
1343                                        tblblogentries.summary, tblblogentries.subtitle, tblblogentries.keywords, tblblogentries.duration
1344                                <cfif arguments.params.mode is "full">, tblblogentries.body, tblblogentries.morebody</cfif>
1345                        from    tblblogentries, tblusers
1346                        <cfif structKeyExists(arguments.params,"byCat")>,tblblogentriescategories</cfif>
1347                        where           1=1
1348                                                and blog = <cfqueryparam value="#instance.name#" cfsqltype="CF_SQL_VARCHAR" maxlength="50">
1349                                                and tblblogentries.username = tblusers.username
1350                        <cfif structKeyExists(arguments.params,"lastXDays")>
1351                                and tblblogentries.posted >= <cfqueryparam value="#dateAdd("d",-1*arguments.params.lastXDays,blogNow())#" cfsqltype="CF_SQL_DATE">
1352                        </cfif>
1353                        <cfif structKeyExists(arguments.params,"byDay")>
1354                                <cfif instance.blogDBType is "MSSQL">
1355                                        and day(dateAdd(hh, #instance.offset#, tblblogentries.posted))
1356                                <cfelseif  instance.blogDBType is "MSACCESS">
1357                                        and day(dateAdd('h', #instance.offset#, tblblogentries.posted))
1358                                <cfelseif instance.blogDBType is "MYSQL">
1359                                        and dayOfMonth(date_add(posted, interval #instance.offset# hour))
1360                                <cfelseif instance.blogDBType is "ORACLE">
1361                                        and to_number(to_char(tblblogentries.posted + (#instance.offset#/24), 'dd'))   
1362                                </cfif>
1363                                        <cfif instance.blogDBType is not "ORACLE">
1364                                        = <cfqueryparam value="#arguments.params.byDay#" cfsqltype="CF_SQL_NUMERIC">
1365                                        <cfelse>
1366                                        = <cfqueryparam value="#arguments.params.byDay#" cfsqltype="CF_SQL_integer">
1367                                        </cfif>
1368                               
1369                        </cfif>
1370                        <cfif structKeyExists(arguments.params,"byMonth")>
1371                                <cfif instance.blogDBType is "MSSQL">
1372                                        and month(dateAdd(hh, #instance.offset#, tblblogentries.posted)) = <cfqueryparam value="#arguments.params.byMonth#" cfsqltype="CF_SQL_NUMERIC">
1373                                <cfelseif instance.blogDBType is "MSACCESS">
1374                                        and month(dateAdd('h', #instance.offset#, tblblogentries.posted)) = <cfqueryparam value="#arguments.params.byMonth#" cfsqltype="CF_SQL_NUMERIC">
1375                                <cfelseif instance.blogDBType is "MYSQL">
1376                                        and month(date_add(posted, interval #instance.offset# hour)) = <cfqueryparam value="#arguments.params.byMonth#" cfsqltype="CF_SQL_NUMERIC">
1377                                <cfelseif instance.blogDBType is "ORACLE">
1378                                        and to_number(to_char(tblblogentries.posted + (#instance.offset#/24), 'MM')) = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.params.byMonth#">     
1379                                </cfif>
1380                        </cfif>
1381                        <cfif structKeyExists(arguments.params,"byYear")>
1382                                <cfif instance.blogDBType is "MSSQL">
1383                                        and year(dateAdd(hh, #instance.offset#, tblblogentries.posted)) = <cfqueryparam value="#arguments.params.byYear#" cfsqltype="CF_SQL_NUMERIC">
1384                                <cfelseif instance.blogDBType is "MSACCESS">
1385                                        and year(dateAdd('h', #instance.offset#, tblblogentries.posted)) = <cfqueryparam value="#arguments.params.byYear#" cfsqltype="CF_SQL_NUMERIC">
1386                                <cfelseif instance.blogDBType is "MYSQL">
1387                                        and year(date_add(posted, interval #instance.offset# hour)) = <cfqueryparam value="#arguments.params.byYear#" cfsqltype="CF_SQL_NUMERIC">
1388                                <cfelseif instance.blogDBType is "ORACLE">
1389                                        and to_number(to_char(tblblogentries.posted + (#instance.offset#/24), 'YYYY')) = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.params.byYear#">   
1390                                </cfif>                                 
1391                        </cfif>
1392                        <cfif structKeyExists(arguments.params,"byTitle")>
1393                                and tblblogentries.title = <cfqueryparam value="#arguments.params.byTitle#" cfsqltype="CF_SQL_VARCHAR" maxlength="100">
1394                        </cfif>
1395                        <cfif structKeyExists(arguments.params,"byCat")>
1396                                and tblblogentriescategories.entryidfk = tblblogentries.id
1397                                and tblblogentriescategories.categoryidfk in (<cfqueryparam value="#arguments.params.byCat#" cfsqltype="CF_SQL_VARCHAR" maxlength="35" list=true>)
1398                        </cfif>
1399                        <cfif structKeyExists(arguments.params,"searchTerms")>
1400                                <cfif not structKeyExists(arguments.params, "dontlogsearch")>
1401                                        <cfset logSearch(arguments.params.searchTerms)>
1402                                </cfif>
1403                                <cfif instance.blogDBType is not "ORACLE">
1404                                        and (tblblogentries.title like '%#arguments.params.searchTerms#%' OR tblblogentries.body like '%#arguments.params.searchTerms#%' or tblblogentries.morebody like '%#arguments.params.searchTerms#%')
1405                                <cfelse>
1406                                and (lower(tblblogentries.title) like '%#lcase(arguments.params.searchTerms)#%' OR lower(tblblogentries.body) like '%#lcase(arguments.params.searchTerms)#%' or lower(tblblogentries.morebody) like '%#lcase(arguments.params.searchTerms)#%')
1407                                </cfif>
1408                        </cfif>
1409                        <cfif structKeyExists(arguments.params,"byEntry")>
1410                                and tblblogentries.id = <cfqueryparam value="#arguments.params.byEntry#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">
1411                        </cfif>
1412                        <cfif structKeyExists(arguments.params,"byAlias")>
1413                                and tblblogentries.alias = <cfqueryparam value="#arguments.params.byAlias#" cfsqltype="CF_SQL_VARCHAR" maxlength="100">
1414                        </cfif>
1415                        <!--- Don't allow future posts unless logged in. --->
1416                        <cfif not isUserInRole("admin") or (structKeyExists(arguments.params, "releasedonly") and arguments.params.releasedonly)>
1417                                <cfif instance.blogDBType IS "ORACLE">
1418                                         and                    to_char(tblblogentries.posted + (#instance.offset#/24), 'YYYY-MM-DD HH24:MI:SS') <= <cfqueryparam cfsqltype="cf_sql_varchar" value="#dateformat(now(), 'YYYY-MM-DD')# #timeformat(now(), 'HH:mm:ss')#">
1419                                <cfelse>
1420                                        and                     posted < <cfqueryparam cfsqltype="cf_sql_timestamp" value="#now()#">
1421                                </cfif>
1422                                and                     released = 1
1423                        </cfif>
1424                        order by        tblblogentries.#arguments.params.orderBy# #arguments.params.orderByDir#
1425                        <cfif structKeyExists(arguments.params,"maxEntries") and instance.blogDBType is "MYSQL">limit #arguments.params.maxEntries#</cfif>
1426                <cfif instance.blogDBType is "ORACLE" and structKeyExists(arguments.params,"maxEntries")>
1427                        )
1428                        WHERE rownum <= #arguments.params.maxEntries#
1429                </cfif>
1430                </cfquery>
1431               
1432                <cfif arguments.params.mode is "full" and getEm.recordCount>
1433                        <cfset queryAddColumn(getEm,"commentCount",arrayNew(1))>
1434                        <cfquery name="getComments" datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
1435                                select count(id) as commentCount, entryidfk
1436                                from    tblblogcomments
1437                                where   entryidfk in (<cfqueryparam value="#valueList(getEm.id)#" cfsqltype="CF_SQL_VARCHAR" list="Yes">)       
1438                                <!--- added 12/5/2006 by Trent Richardson --->
1439                                <cfif instance.moderate>
1440                                        and moderated = 1
1441                                </cfif>
1442                                and (subscribeonly = 0 or subscribeonly is null)
1443                                group by entryidfk
1444                        </cfquery>
1445                        <cfif getComments.recordCount>
1446                                <!--- for each row, need to find in getEm --->
1447                                <cfloop query="getComments">
1448                                        <cfset pos = listFindNoCase(valueList(getEm.id),entryidfk)>
1449                                        <cfif pos>
1450                                                <cfset querySetCell(getEm,"commentCount",commentCount,pos)>
1451                                        </cfif>
1452                                </cfloop>
1453                        </cfif>
1454                        <cfset queryAddColumn(getEm,"categories",arrayNew(1))>
1455                        <cfloop query="getEm">
1456                                <cfquery name="getCategories" datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
1457                                        select  categoryid,categoryname
1458                                        from    tblblogcategories, tblblogentriescategories
1459                                        where   tblblogentriescategories.entryidfk = <cfqueryparam value="#getEm.id#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">
1460                                        and             tblblogentriescategories.categoryidfk = tblblogcategories.categoryid
1461                                </cfquery>
1462                                <!---
1463                                <cfset querySetCell(getEm,"categoryids",valueList(getCategories.categoryID),currentRow)>
1464                                <cfset querySetCell(getEm,"categorynames",valueList(getCategories.categoryname),currentRow)>
1465                                --->
1466                                <cfset catData = structNew()>
1467                                <cfloop query="getCategories">
1468                                        <cfset catData[categoryID] = categoryName>
1469                                </cfloop>
1470                                <cfset querySetCell(getEm,"categories",catData,currentRow)>
1471                        </cfloop>
1472                       
1473                        <cfset queryAddColumn(getEm,"trackbackCount",arrayNew(1))>
1474                        <cfquery name="getTrackbacks" datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
1475                                select count(id) as trackbackCount, entryid
1476                                from    tblblogtrackbacks
1477                                where   entryid in (<cfqueryparam value="#valueList(getEm.id)#" cfsqltype="CF_SQL_VARCHAR" list="Yes">)
1478                                group by entryid
1479                        </cfquery>
1480                        <cfif getTrackbacks.recordCount>
1481                                <!--- for each row, need to find in getEm --->
1482                                <cfloop query="getTrackbacks">
1483                                        <cfset pos = listFindNoCase(valueList(getEm.id),entryid)>
1484                                        <cfif pos>
1485                                                <cfset querySetCell(getEm,"trackbackCount",trackbackCount,pos)>
1486                                        </cfif>
1487                                </cfloop>
1488                        </cfif>
1489                       
1490                </cfif>
1491               
1492                <cfreturn getEm>
1493               
1494        </cffunction>
1495
1496        <cffunction name="getEntries" access="remote" returnType="struct" output="false"
1497                                hint="Returns entries. Allows for a params structure to configure what entries are returned.">
1498                <cfargument name="params" type="struct" required="false" default="#structNew()#">
1499                <cfset var getEm = "">
1500                <cfset var getComments = "">
1501                <cfset var getCategories = "">
1502                <cfset var getTrackbacks = "">
1503                <cfset var validOrderBy = "posted,title">
1504                <cfset var validOrderByDir = "asc,desc">
1505                <cfset var validMode = "short,full">
1506                <cfset var pos = "">
1507                <cfset var id = "">
1508                <cfset var catdata = "">
1509                <cfset var getIds = "">
1510                <cfset var idList = "">
1511                <cfset var pageIdList = "">
1512                <cfset var x = "">
1513                <cfset var r = structNew()>
1514                       
1515                <!--- By default, order the results by posted col --->
1516                <cfif not structKeyExists(arguments.params,"orderBy") or not listFindNoCase(validOrderBy,arguments.params.orderBy)>
1517                        <cfset arguments.params.orderBy = "posted">
1518                </cfif>
1519                <!--- By default, order the results direction desc --->
1520                <cfif not structKeyExists(arguments.params,"orderByDir") or not listFindNoCase(validOrderByDir,arguments.params.orderByDir)>
1521                        <cfset arguments.params.orderByDir = "desc">
1522                </cfif>
1523                <!--- If lastXDays is passed, verify X is int between 1 and 365 --->
1524                <cfif structKeyExists(arguments.params,"lastXDays")>
1525                        <cfif not val(arguments.params.lastXDays) or val(arguments.params.lastXDays) lt 1 or val(arguments.params.lastXDays) gt 365>
1526                                <cfset structDelete(arguments.params,"lastXDays")>
1527                        <cfelse>
1528                                <cfset arguments.params.lastXDays = val(arguments.params.lastXDays)>
1529                        </cfif>
1530                </cfif>
1531                <!--- If byDay is passed, verify X is int between 1 and 31 --->
1532                <cfif structKeyExists(arguments.params,"byDay")>
1533                        <cfif not val(arguments.params.byDay) or val(arguments.params.byDay) lt 1 or val(arguments.params.byDay) gt 31>
1534                                <cfset structDelete(arguments.params,"byDay")>
1535                        <cfelse>
1536                                <cfset arguments.params.byDay = val(arguments.params.byDay)>
1537                        </cfif>
1538                </cfif>
1539                <!--- If byMonth is passed, verify X is int between 1 and 12 --->
1540                <cfif structKeyExists(arguments.params,"byMonth")>
1541                        <cfif not val(arguments.params.byMonth) or val(arguments.params.byMonth) lt 1 or val(arguments.params.byMonth) gt 12>
1542                                <cfset structDelete(arguments.params,"byMonth")>
1543                        <cfelse>
1544                                <cfset arguments.params.byMonth = val(arguments.params.byMonth)>
1545                        </cfif>
1546                </cfif>
1547                <!--- If byYear is passed, verify X is int  --->
1548                <cfif structKeyExists(arguments.params,"byYear")>
1549                        <cfif not val(arguments.params.byYear)>
1550                                <cfset structDelete(arguments.params,"byYear")>
1551                        <cfelse>
1552                                <cfset arguments.params.byYear = val(arguments.params.byYear)>
1553                        </cfif>
1554                </cfif>
1555                <!--- If byTitle is passed, verify we have a length  --->
1556                <cfif structKeyExists(arguments.params,"byTitle")>
1557                        <cfif not len(trim(arguments.params.byTitle))>
1558                                <cfset structDelete(arguments.params,"byTitle")>
1559                        <cfelse>
1560                                <cfset arguments.params.byTitle = trim(arguments.params.byTitle)>
1561                        </cfif>
1562                </cfif>
1563
1564                <!--- By default, get body, commentCount and categories as well, requires additional lookup --->
1565                <cfif not structKeyExists(arguments.params,"mode") or not listFindNoCase(validMode,arguments.params.mode)>
1566                        <cfset arguments.params.mode = "full">
1567                </cfif>
1568                <!--- handle searching --->
1569                <cfif structKeyExists(arguments.params,"searchTerms") and not len(trim(arguments.params.searchTerms))>
1570                        <cfset structDelete(arguments.params,"searchTerms")>
1571                </cfif>
1572                <!--- Limit number returned. Thanks to Rob Brooks-Bilson --->
1573                <cfif not structKeyExists(arguments.params,"maxEntries") or (structKeyExists(arguments.params,"maxEntries") and not val(arguments.params.maxEntries))>
1574                        <cfset arguments.params.maxEntries = 10>
1575                </cfif>
1576               
1577                <cfif not structKeyExists(arguments.params,"startRow") or (structKeyExists(arguments.params,"startRow") and not val(arguments.params.startRow))>
1578                        <cfset arguments.params.startRow = 1>
1579                </cfif>
1580
1581                <!--- I get JUST the ids --->
1582                <cfquery name="getIds" datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
1583                select  tblblogentries.id
1584                from    tblblogentries, tblusers
1585                        <cfif structKeyExists(arguments.params,"byCat")>,tblblogentriescategories</cfif>
1586                        where           1=1
1587                                                and blog = <cfqueryparam value="#instance.name#" cfsqltype="CF_SQL_VARCHAR" maxlength="50">
1588                                                and tblblogentries.username = tblusers.username
1589                        <cfif structKeyExists(arguments.params,"lastXDays")>
1590                                and tblblogentries.posted >= <cfqueryparam value="#dateAdd("d",-1*arguments.params.lastXDays,blogNow())#" cfsqltype="CF_SQL_DATE">
1591                        </cfif>
1592                        <cfif structKeyExists(arguments.params,"byDay")>
1593                                <cfif instance.blogDBType is "MSSQL">
1594                                        and day(dateAdd(hh, #instance.offset#, tblblogentries.posted))
1595                                <cfelseif  instance.blogDBType is "MSACCESS">
1596                                        and day(dateAdd('h', #instance.offset#, tblblogentries.posted))
1597                                <cfelseif instance.blogDBType is "MYSQL">
1598                                        and dayOfMonth(date_add(posted, interval #instance.offset# hour))
1599                                <cfelseif instance.blogDBType is "ORACLE">
1600                                        and to_number(to_char(tblblogentries.posted + (#instance.offset#/24), 'dd'))   
1601                                </cfif>
1602                                        <cfif instance.blogDBType is not "ORACLE">
1603                                        = <cfqueryparam value="#arguments.params.byDay#" cfsqltype="CF_SQL_NUMERIC">
1604                                        <cfelse>
1605                                        = <cfqueryparam value="#arguments.params.byDay#" cfsqltype="CF_SQL_integer">
1606                                        </cfif>
1607                               
1608                        </cfif>
1609                        <cfif structKeyExists(arguments.params,"byMonth")>
1610                                <cfif instance.blogDBType is "MSSQL">
1611                                        and month(dateAdd(hh, #instance.offset#, tblblogentries.posted)) = <cfqueryparam value="#arguments.params.byMonth#" cfsqltype="CF_SQL_NUMERIC">
1612                                <cfelseif instance.blogDBType is "MSACCESS">
1613                                        and month(dateAdd('h', #instance.offset#, tblblogentries.posted)) = <cfqueryparam value="#arguments.params.byMonth#" cfsqltype="CF_SQL_NUMERIC">
1614                                <cfelseif instance.blogDBType is "MYSQL">
1615                                        and month(date_add(posted, interval #instance.offset# hour)) = <cfqueryparam value="#arguments.params.byMonth#" cfsqltype="CF_SQL_NUMERIC">
1616                                <cfelseif instance.blogDBType is "ORACLE">
1617                                        and to_number(to_char(tblblogentries.posted + (#instance.offset#/24), 'MM')) = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.params.byMonth#">     
1618                                </cfif>
1619                        </cfif>
1620                        <cfif structKeyExists(arguments.params,"byYear")>
1621                                <cfif instance.blogDBType is "MSSQL">
1622                                        and year(dateAdd(hh, #instance.offset#, tblblogentries.posted)) = <cfqueryparam value="#arguments.params.byYear#" cfsqltype="CF_SQL_NUMERIC">
1623                                <cfelseif instance.blogDBType is "MSACCESS">
1624                                        and year(dateAdd('h', #instance.offset#, tblblogentries.posted)) = <cfqueryparam value="#arguments.params.byYear#" cfsqltype="CF_SQL_NUMERIC">
1625                                <cfelseif instance.blogDBType is "MYSQL">
1626                                        and year(date_add(posted, interval #instance.offset# hour)) = <cfqueryparam value="#arguments.params.byYear#" cfsqltype="CF_SQL_NUMERIC">
1627                                <cfelseif instance.blogDBType is "ORACLE">
1628                                        and to_number(to_char(tblblogentries.posted + (#instance.offset#/24), 'YYYY')) = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.params.byYear#">   
1629                                </cfif>                                 
1630                        </cfif>
1631                        <cfif structKeyExists(arguments.params,"byTitle")>
1632                                and tblblogentries.title = <cfqueryparam value="#arguments.params.byTitle#" cfsqltype="CF_SQL_VARCHAR" maxlength="100">
1633                        </cfif>
1634                        <cfif structKeyExists(arguments.params,"byCat")>
1635                                and tblblogentriescategories.entryidfk = tblblogentries.id
1636                                and tblblogentriescategories.categoryidfk in (<cfqueryparam value="#arguments.params.byCat#" cfsqltype="CF_SQL_VARCHAR" maxlength="35" list=true>)
1637                        </cfif>
1638                        <cfif structKeyExists(arguments.params,"searchTerms")>
1639                                <cfif not structKeyExists(arguments.params, "dontlogsearch")>
1640                                        <cfset logSearch(arguments.params.searchTerms)>
1641                                </cfif>
1642                                <cfif instance.blogDBType is not "ORACLE">
1643                                        and (tblblogentries.title like '%#arguments.params.searchTerms#%' OR tblblogentries.body like '%#arguments.params.searchTerms#%' or tblblogentries.morebody like '%#arguments.params.searchTerms#%')
1644                                <cfelse>
1645                                and (lower(tblblogentries.title) like '%#lcase(arguments.params.searchTerms)#%' OR lower(tblblogentries.body) like '%#lcase(arguments.params.searchTerms)#%' or lower(tblblogentries.morebody) like '%#lcase(arguments.params.searchTerms)#%')
1646                                </cfif>
1647                        </cfif>
1648                        <cfif structKeyExists(arguments.params,"byEntry")>
1649                                and tblblogentries.id = <cfqueryparam value="#arguments.params.byEntry#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">
1650                        </cfif>
1651                        <cfif structKeyExists(arguments.params,"byAlias")>
1652                                and tblblogentries.alias = <cfqueryparam value="#arguments.params.byAlias#" cfsqltype="CF_SQL_VARCHAR" maxlength="100">
1653                        </cfif>
1654                        <!--- Don't allow future posts unless logged in. --->
1655                        <cfif not isUserInRole("admin") or (structKeyExists(arguments.params, "releasedonly") and arguments.params.releasedonly)>
1656                                <cfif instance.blogDBType IS "ORACLE">
1657                                         and                    to_char(tblblogentries.posted + (#instance.offset#/24), 'YYYY-MM-DD HH24:MI:SS') <= <cfqueryparam cfsqltype="cf_sql_varchar" value="#dateformat(now(), 'YYYY-MM-DD')# #timeformat(now(), 'HH:mm:ss')#">
1658                                <cfelse>
1659                                        and                     posted < <cfqueryparam cfsqltype="cf_sql_timestamp" value="#now()#">
1660                                </cfif>
1661                                and                     released = 1
1662                        </cfif>
1663                        order by        tblblogentries.#arguments.params.orderBy# #arguments.params.orderByDir#         
1664                </cfquery>
1665
1666                <!--- we now have a query from row 1 to our max, we need to get a 'page' of IDs --->
1667                <cfset idList = valueList(getIds.id)>
1668                <cfif idList eq "">
1669                        <!---// the we need the "title" column for the spryproxy.cfm //--->
1670                        <cfset r.entries = queryNew("id, title, posted")>
1671                        <cfset r.totalEntries = 0>
1672                        <cfreturn r>
1673                </cfif>
1674               
1675                <cfloop index="x" from="#arguments.params.startRow#" to="#min(arguments.params.startRow+arguments.params.maxEntries-1,getIds.recordCount)#">
1676                        <cfset pageIdList = listAppend(pageIdList, listGetAt(idlist,x))>
1677                </cfloop>
1678
1679                <!--- I now get the full info --->
1680                <cfquery name="getEm" datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#" maxrows="#arguments.params.maxEntries+arguments.params.startRow-1#">
1681                <!--- DS 8/22/06: added Oracle pseudo top n code --->
1682                        select         
1683                                        tblblogentries.id, tblblogentries.title,
1684                                        tblblogentries.alias,
1685                                        <!--- Handle offset --->
1686                                        <cfif instance.blogDBType is "MSACCESS">
1687                                                dateAdd('h', #instance.offset#, tblblogentries.posted) as posted,
1688                                        <cfelseif instance.blogDBType is "MSSQL">
1689                                                dateAdd(hh, #instance.offset#, tblblogentries.posted) as posted,
1690                                        <cfelseif instance.blogDBType is "ORACLE">
1691                                                tblblogentries.posted + (#instance.offset#/24) as posted,       
1692                                        <cfelse>
1693                                        date_add(posted, interval #instance.offset# hour) as posted,
1694                                        </cfif>
1695                                        tblusers.name, tblblogentries.allowcomments,
1696                                        tblblogentries.enclosure, tblblogentries.filesize, tblblogentries.mimetype, tblblogentries.released, tblblogentries.views,
1697                                        tblblogentries.summary, tblblogentries.subtitle, tblblogentries.keywords, tblblogentries.duration
1698                                <cfif arguments.params.mode is "full">, tblblogentries.body, tblblogentries.morebody</cfif>
1699                        from    tblblogentries, tblusers
1700                        where           
1701                                tblblogentries.id in (<cfqueryparam cfsqltype="cf_sql_varchar" list="true" value="#pageIdList#">)
1702                                                and blog = <cfqueryparam value="#instance.name#" cfsqltype="CF_SQL_VARCHAR" maxlength="50">
1703                                                and tblblogentries.username = tblusers.username
1704                        order by        tblblogentries.#arguments.params.orderBy# #arguments.params.orderByDir#
1705                </cfquery>
1706
1707                <cfif arguments.params.mode is "full" and getEm.recordCount>
1708                        <cfset queryAddColumn(getEm,"commentCount",arrayNew(1))>
1709                        <cfquery name="getComments" datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
1710                                select count(id) as commentCount, entryidfk
1711                                from    tblblogcomments
1712                                where   entryidfk in (<cfqueryparam value="#valueList(getEm.id)#" cfsqltype="CF_SQL_VARCHAR" list="Yes">)       
1713                                <!--- added 12/5/2006 by Trent Richardson --->
1714                                <cfif instance.moderate>
1715                                        and moderated = 1
1716                                </cfif>
1717                                and (subscribeonly = 0 or subscribeonly is null)
1718                                group by entryidfk
1719                        </cfquery>
1720                        <cfif getComments.recordCount>
1721                                <!--- for each row, need to find in getEm --->
1722                                <cfloop query="getComments">
1723                                        <cfset pos = listFindNoCase(valueList(getEm.id),entryidfk)>
1724                                        <cfif pos>
1725                                                <cfset querySetCell(getEm,"commentCount",commentCount,pos)>
1726                                        </cfif>
1727                                </cfloop>
1728                        </cfif>
1729                        <cfset queryAddColumn(getEm,"categories",arrayNew(1))>
1730                        <cfloop query="getEm">
1731                                <cfquery name="getCategories" datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
1732                                        select  categoryid,categoryname
1733                                        from    tblblogcategories, tblblogentriescategories
1734                                        where   tblblogentriescategories.entryidfk = <cfqueryparam value="#getEm.id#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">
1735                                        and             tblblogentriescategories.categoryidfk = tblblogcategories.categoryid
1736                                </cfquery>
1737                                <!---
1738                                <cfset querySetCell(getEm,"categoryids",valueList(getCategories.categoryID),currentRow)>
1739                                <cfset querySetCell(getEm,"categorynames",valueList(getCategories.categoryname),currentRow)>
1740                                --->
1741                                <cfset catData = structNew()>
1742                                <cfloop query="getCategories">
1743                                        <cfset catData[categoryID] = categoryName>
1744                                </cfloop>
1745                                <cfset querySetCell(getEm,"categories",catData,currentRow)>
1746                        </cfloop>
1747                       
1748                        <cfset queryAddColumn(getEm,"trackbackCount",arrayNew(1))>
1749                        <cfquery name="getTrackbacks" datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
1750                                select count(id) as trackbackCount, entryid
1751                                from    tblblogtrackbacks
1752                                where   entryid in (<cfqueryparam value="#valueList(getEm.id)#" cfsqltype="CF_SQL_VARCHAR" list="Yes">)
1753                                group by entryid
1754                        </cfquery>
1755                        <cfif getTrackbacks.recordCount>
1756                                <!--- for each row, need to find in getEm --->
1757                                <cfloop query="getTrackbacks">
1758                                        <cfset pos = listFindNoCase(valueList(getEm.id),entryid)>
1759                                        <cfif pos>
1760                                                <cfset querySetCell(getEm,"trackbackCount",trackbackCount,pos)>
1761                                        </cfif>
1762                                </cfloop>
1763                        </cfif>
1764                       
1765                </cfif>
1766                <cfset r.entries = getEm>
1767                <cfset r.totalEntries = getIds.recordCount>
1768
1769                <cfreturn r>
1770               
1771        </cffunction>   
1772
1773        <cffunction name="getNameForUser" access="public" returnType="string" output="false">
1774                <cfargument name="username" type="string" required="true">
1775                <cfset var q = "">
1776               
1777                <cfquery name="q" datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
1778                select  name
1779                from    tblusers
1780                where   username = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.username#" maxlength="50">
1781                </cfquery>
1782               
1783                <cfreturn q.name>
1784        </cffunction>
1785       
1786        <cffunction name="getNumberUnmoderated" access="public" returntype="numeric" output="false">
1787                <cfset var getUnmoderated = "">
1788                <cfquery name="getUnmoderated" datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
1789                        select count(c.moderated) as unmoderated
1790                        from tblblogcomments c, tblblogentries e
1791                        where c.moderated=0
1792                        and      e.blog = <cfqueryparam value="#instance.name#" cfsqltype="CF_SQL_VARCHAR" maxlength="50">
1793                        and c.entryidfk = e.id
1794                </cfquery>
1795               
1796                <cfreturn getUnmoderated.unmoderated>
1797        </cffunction>
1798
1799        <cffunction name="getProperties" access="public" returnType="struct" output="false">
1800                <cfreturn duplicate(instance)>
1801        </cffunction>
1802       
1803        <cffunction name="getProperty" access="public" returnType="any" output="false">
1804                <cfargument name="property" type="string" required="true">
1805               
1806                <cfif not structKeyExists(instance,arguments.property)>
1807                        <cfset variables.utils.throw("#arguments.property# is not a valid property.")>
1808                </cfif>
1809               
1810                <cfreturn instance[arguments.property]>
1811               
1812        </cffunction>
1813
1814        <cffunction name="getRecentComments" access="remote" returnType="query" output="false"
1815                hint="Returns the last N comments.">
1816        <cfargument name="maxEntries" type="numeric" required="false" default="10">
1817        <cfset var getRecentComments = "">
1818                <cfset var getO = "">
1819       
1820                <cfquery datasource="#instance.dsn#" name="getRecentComments" username="#instance.username#" password="#instance.password#">
1821                <!--- DS 8/22/06: Added Oracle pseudo "top n" code --->
1822                <cfif instance.blogDBTYPE is "ORACLE">
1823                SELECT  * FROM (
1824                </cfif>
1825               
1826                select <cfif instance.blogDBType is not "MYSQL" AND instance.blogDBType is not "ORACLE">
1827                    top #arguments.maxEntries#
1828                </cfif>
1829                e.id as entryID,
1830                e.title,
1831                c.id,
1832                c.entryidfk,
1833                c.name,
1834                <cfif instance.blogDBType is NOT "ORACLE">c.comment<cfelse>to_char(c.comments) as comments</cfif>,
1835                <!--- Handle offset --->
1836                <cfif instance.blogDBType is "MSACCESS">
1837                    dateAdd('h', #instance.offset#, c.posted) as posted
1838                <cfelseif instance.blogDBType is "MSSQL">
1839                    dateAdd(hh, #instance.offset#, c.posted) as posted
1840                <cfelseif instance.blogDBType is "ORACLE">
1841                        c.posted + (#instance.offset#/24) as posted
1842                <cfelse>
1843                    date_add(c.posted, interval #instance.offset# hour) as posted
1844                </cfif>
1845                from tblblogcomments c
1846                inner join tblblogentries e on c.entryidfk = e.id
1847                where    blog = <cfqueryparam value="#instance.name#" cfsqltype="CF_SQL_VARCHAR" maxlength="50">
1848                <!--- added 12/5/2006 by Trent Richardson --->
1849                <cfif instance.moderate>
1850                        and c.moderated = 1
1851                </cfif>
1852                order by c.posted desc
1853                <cfif instance.blogDBType is "MYSQL">limit #arguments.maxEntries#</cfif>
1854               
1855                <cfif instance.blogDBType is "ORACLE">
1856                )
1857                WHERE   rownum <= #arguments.maxEntries#
1858                </cfif>
1859                </cfquery>
1860               
1861                <cfif instance.blogDBType is "ORACLE">
1862                        <cfquery name="getO" dbtype="query">
1863                        SELECT  entryID, title, id, entryidfk, name, comments AS comment, posted
1864                        FROM    getRecentComments
1865                        ORDER BY posted desc
1866                        </cfquery>
1867                       
1868                        <cfreturn getO>
1869                </cfif>
1870               
1871               
1872        <cfreturn getRecentComments>
1873               
1874    </cffunction>
1875
1876        <!--- TODO: Take a look at this, something seems wrong. --->
1877        <cffunction name="getRelatedBlogEntries" access="remote" returntype="query" output="true" hint="returns related entries">
1878            <cfargument name="entryId" type="uuid" required="true" />
1879            <cfargument name="bDislayBackwardRelations" type="boolean" hint="Displays related entries that set from another entry" default="true" />
1880            <cfargument name="bDislayFutureLinks" type="boolean" hint="Displays related entries that occur after the posted date of THIS entry" default="true" />
1881       
1882            <cfset var qEntries = "" />
1883
1884                <!--- BEGIN : added categoryID to related blog entry query : cjg : 31 december 2005 --->
1885                <!--- <cfset var qRelatedEntries = queryNew("id,title,posted,alias") /> --->
1886                <cfset var qRelatedEntries = queryNew("id,title,posted,alias,categoryName") />
1887                <!--- END : added categoryID to related blog entry query : cjg : 31 december 2005 --->
1888               
1889            <cfset var qThisEntry = "" />
1890            <cfset var getRelatedIds = "" />
1891                <cfset var getThisRelatedEntry = "" />
1892               
1893            <cfquery name="qThisEntry" datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
1894              select posted
1895              from tblblogentries
1896              where id = <cfqueryparam value="#arguments.entryId#" cfsqltype="CF_SQL_VARCHAR" maxlength="35" />
1897            </cfquery>
1898            <cfquery name="getRelatedIds" datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
1899              select distinct relatedid
1900              from tblblogentriesrelated
1901              where entryid = <cfqueryparam value="#arguments.entryId#" cfsqltype="CF_SQL_VARCHAR" maxlength="35" />
1902             
1903              <cfif bDislayBackwardRelations>
1904              union
1905             
1906              select distinct entryid as relatedid
1907              from tblblogentriesrelated
1908              where relatedid = <cfqueryparam value="#arguments.entryId#" cfsqltype="CF_SQL_VARCHAR" maxlength="35" />
1909              </cfif>
1910            </cfquery>
1911            <cfloop query="getRelatedIds">
1912                  <cfquery name="getThisRelatedEntry" datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
1913                        select
1914                                tblblogentries.id,
1915                                tblblogentries.title,
1916                                tblblogentries.posted,
1917                                tblblogentries.alias,
1918                                tblblogcategories.categoryname
1919                        from
1920                                (tblblogcategories
1921                                inner join tblblogentriescategories on
1922                                        tblblogcategories.categoryid = tblblogentriescategories.categoryidfk)
1923                                inner join tblblogentries on
1924                                        tblblogentriescategories.entryidfk = tblblogentries.id
1925                where tblblogentries.id = <cfqueryparam value="#getrelatedids.relatedid#" cfsqltype="cf_sql_varchar" maxlength="35" />
1926                and   tblblogentries.blog = <cfqueryparam value="#instance.name#" cfsqltype="cf_sql_varchar" maxlength="255">
1927                <cfif bdislayfuturelinks is false>
1928                                <cfif instance.blogDBType is not "ORACLE">
1929                                and tblblogentries.posted <= #createodbcdatetime(qthisentry.posted)#
1930                                <cfelse>
1931                                and tblblogentries.posted <= <cfqueryparam cfsqltype="cf_sql_timestamp" value="#qthisentry.posted#">
1932                                </cfif>
1933                </cfif>
1934                        <!--- END : added categoryName to query : cjg : 31 december 2005 --->
1935              </cfquery>
1936                 
1937              <cfif getThisRelatedEntry.recordCount>
1938                <cfset queryAddRow(qRelatedEntries, 1) />
1939                <cfset querySetCell(qRelatedEntries, "id", getThisRelatedEntry.id) />
1940                <cfset querySetCell(qRelatedEntries, "title", getThisRelatedEntry.title) />
1941                <cfset querySetCell(qRelatedEntries, "posted", getThisRelatedEntry.posted) />
1942                <cfset querySetCell(qRelatedEntries, "alias", getThisRelatedEntry.alias) />
1943                        <!--- BEGIN : added categoryName to query : cjg : 31 december 2005 --->
1944                        <cfset querySetCell(qRelatedEntries, "categoryName", getThisRelatedEntry.categoryName) />
1945                        <!--- END : added categoryName to query : cjg : 31 december 2005 --->
1946              </cfif>
1947            </cfloop>
1948            <cfif qRelatedEntries.recordCount>
1949              <!--- Order By --->
1950              <cfquery name="qRelatedEntries" dbtype="query">
1951                select *
1952                from qrelatedentries
1953                order by posted desc
1954              </cfquery>
1955            </cfif>
1956       
1957                <cfreturn qRelatedEntries />
1958        </cffunction>
1959        <!--- END : get related entries method : cjg  --->
1960
1961        <cffunction name="getRelatedEntriesSelects" access="remote" returntype="query" output="false">
1962                <cfset var getRelatedP = "" />
1963               
1964                <cfquery name="getRelatedP" datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
1965                        select
1966                                tblblogcategories.categoryname,
1967                                tblblogentries.id,
1968                                tblblogentries.title,
1969                                tblblogentries.posted
1970                        from
1971                                tblblogentries inner join
1972                                        (tblblogcategories inner join tblblogentriescategories on tblblogcategories.categoryid = tblblogentriescategories.categoryidfk) on
1973                                                tblblogentries.id = tblblogentriescategories.entryidfk
1974
1975                        where tblblogcategories.blog = <cfqueryparam value="#instance.name#" cfsqltype="CF_SQL_VARCHAR" maxlength="50">                                         
1976                        order by
1977                                tblblogcategories.categoryname,
1978                                tblblogentries.posted,
1979                                tblblogentries.title
1980                </cfquery>
1981               
1982                <cfreturn getRelatedP />
1983        </cffunction>
1984
1985        <cffunction name="getRootURL" access="public" returnType="string" output="false"
1986                                hint="Simple helper function to get root url.">
1987               
1988                <cfset var theURL = replace(instance.blogurl, "index.cfm", "")>
1989                <cfreturn theURL>
1990
1991        </cffunction>
1992               
1993        <cffunction name="getSubscribers" access="public" returnType="query" output="false"
1994                                hint="Returns all people subscribed to the blog.">
1995                <cfargument name="verifiedonly" type="boolean" required="false" default="false">
1996                <cfset var getPeople = "">
1997               
1998                <cfquery name="getPeople" datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
1999                select          email, token, verified
2000                from            tblblogsubscribers
2001                where           blog = <cfqueryparam value="#instance.name#" cfsqltype="cf_sql_varchar" maxlength="50">
2002                <cfif           arguments.verifiedonly>
2003                and                     verified = 1
2004                </cfif>
2005                order by        email asc
2006                </cfquery>
2007               
2008                <cfreturn getPeople>
2009        </cffunction>
2010
2011        <cffunction name="getTrackBack" returnType="struct" access="remote" output="false"
2012                                hint="Returns one trackback entry.">
2013                <cfargument name="id" type="string" required="true" hint="The id of the trackback.">
2014                <cfset var trackback = "">
2015                <cfset var result = structNew()>
2016                               
2017                <cfquery name="trackback" datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
2018                        select          id, title, posturl, excerpt, created, entryid, blogname
2019                        from            tblblogtrackbacks
2020                        where           id = <cfqueryparam value="#arguments.id#" cfsqltype="CF_SQL_VARCHAR">
2021                </cfquery>
2022
2023                <cfif trackback.recordcount>
2024                        <cfset result.id = trackback.id>
2025                        <cfset result.title = trackback.title>
2026                        <cfset result.posturl = trackback.posturl>
2027                        <cfset result.excerpt = trackback.excerpt>
2028                        <cfset result.created = trackback.created>
2029                        <cfset result.entryid = trackback.entryid>
2030                        <cfset result.blogname = trackback.blogname>
2031                </cfif>
2032               
2033                <cfreturn result>
2034               
2035        </cffunction>
2036
2037        <cffunction name="getTrackBacks" returnType="query" access="remote" output="false"
2038                                hint="Returns trackback entries for a blog post.">
2039                <cfargument name="id" type="string" required="false" hint="The id of the blog entry.">
2040                <cfargument name="sortdir" type="string" required="false" default="asc">
2041       
2042                <cfset var trackbacks = "">
2043
2044                <cfif arguments.sortDir is not "asc" and arguments.sortDir is not "desc">
2045                        <cfset arguments.sortDir = "asc">
2046                </cfif>
2047               
2048                <cfquery name="trackbacks" datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
2049                        select          id, title, posturl, excerpt, created, blogname
2050                        from            tblblogtrackbacks
2051                        where           blog = <cfqueryparam value="#instance.name#" cfsqltype="CF_SQL_VARCHAR" maxlength="255">
2052                        <cfif structKeyExists(arguments, "id")>
2053                        and             entryid = <cfqueryparam value="#arguments.id#" cfsqltype="CF_SQL_VARCHAR">
2054                        </cfif>
2055                        order by        created #arguments.sortdir#
2056                </cfquery>
2057
2058                <cfreturn trackbacks>
2059               
2060        </cffunction>
2061
2062        <cffunction name="getUnmoderatedComments" access="remote" returnType="query" output="false"
2063                                hint="Gets unmoderated comments for an entry.">
2064                <cfargument name="id" type="uuid" required="false">
2065                <cfargument name="sortdir" type="string" required="false" default="asc">
2066
2067                <cfset var getC = "">
2068                <cfset var getO = "">
2069               
2070                <cfif structKeyExists(arguments, "id") and not entryExists(arguments.id)>
2071                        <cfset variables.utils.throw("#arguments.id# does not exist.")>
2072                </cfif>
2073               
2074                <cfif arguments.sortDir is not "asc" and arguments.sortDir is not "desc">
2075                        <cfset arguments.sortDir = "asc">
2076                </cfif>
2077               
2078                <!--- RBB 11/02/2005: Added website to query --->
2079                <cfquery name="getC" datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
2080                        select          tblblogcomments.id, tblblogcomments.name, tblblogcomments.email, tblblogcomments.website,
2081                                                <cfif instance.blogDBTYPE is NOT "ORACLE">tblblogcomments.comment<cfelse>to_char(tblblogcomments.comments) as comments</cfif>, tblblogcomments.posted, tblblogcomments.subscribe, tblblogentries.title as entrytitle, tblblogcomments.entryidfk
2082                        from            tblblogcomments, tblblogentries
2083                        where           tblblogcomments.entryidfk = tblblogentries.id
2084                        <cfif structKeyExists(arguments, "id")>
2085                        and                     tblblogcomments.entryidfk = <cfqueryparam value="#arguments.id#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">
2086                        </cfif>
2087                        and                     tblblogentries.blog = <cfqueryparam value="#instance.name#" cfsqltype="CF_SQL_VARCHAR" maxlength="50">
2088                        <!--- added 12/5/2006 by Trent Richardson --->
2089                        and tblblogcomments.moderated = 0
2090                       
2091                        order by        tblblogcomments.posted #arguments.sortdir#
2092                </cfquery>
2093               
2094                <!--- DS 8/22/06: if this is oracle, do a q of q to return the data with column named "comment" --->
2095                <cfif instance.blogDBType is "ORACLE">
2096                        <cfquery name="getO" dbtype="query">
2097                        select          id, name, email, website,
2098                                                comments AS comment, posted, subscribe, entrytitle, entryidfk
2099                        from            getC
2100                        order by        posted #arguments.sortdir#
2101                        </cfquery>
2102                       
2103                        <cfreturn getO>
2104                </cfif>
2105               
2106                <cfreturn getC>
2107               
2108        </cffunction>
2109       
2110        <cffunction name="getValidDBTypes" access="public" returnType="string" output="false"
2111                                hint="Returns the valid database types.">
2112                <cfreturn variables.validDBTypes>
2113        </cffunction>
2114
2115        <cffunction name="getVersion" access="remote" returnType="string" output="false"
2116                                hint="Returns the version of the blog.">
2117                <cfreturn variables.version>
2118        </cffunction>
2119       
2120        <cffunction name="isValidDBType" access="private" returnType="boolean" output="false"
2121                                hint="Checks to see if a db type is valid for the blog.">
2122                <cfargument name="dbtype" type="string" required="true">
2123               
2124                <cfreturn listFindNoCase(getValidDBTypes(), arguments.dbType) gte 1>
2125               
2126        </cffunction>
2127
2128        <cffunction name="killComment" access="public" returnType="void" output="false">
2129                <cfargument name="kid" type="uuid" required="true">
2130                <cfset var q = "">
2131
2132                <!--- delete comment based on kill --->
2133                <cfquery name="q" datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
2134                        delete from tblblogcomments
2135                        where killcomment = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.kid#" maxlength="35">           
2136                </cfquery>
2137
2138        </cffunction>
2139       
2140        <cffunction name="logSearch" access="private" returnType="void" output="false"
2141                                hint="Logs the search.">
2142                <cfargument name="searchterm" type="string" required="true">
2143               
2144                <cfquery datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
2145                insert into tblblogsearchstats(searchterm, searched, blog)
2146                values(
2147                        <cfqueryparam value="#arguments.searchterm#" cfsqltype="cf_sql_varchar" maxlength="255">,
2148                        <cfqueryparam value="#blogNow()#" cfsqltype="cf_sql_timestamp">,
2149                        <cfqueryparam value="#instance.name#" cfsqltype="cf_sql_varchar" maxlength="50">
2150                )
2151                </cfquery>
2152               
2153        </cffunction>
2154
2155        <cffunction name="mailEntry" access="public" returnType="void" output="false"
2156                                hint="Handles email for the blog.">
2157                <cfargument name="entryid" type="uuid" required="true">
2158                <cfset var entry = getEntry(arguments.entryid,true)>
2159                <cfset var subscribers = getSubscribers(true)>
2160                <cfset var theMessage = "">
2161                <cfset var mailBody = "">
2162
2163                <cfloop query="subscribers">
2164               
2165                        <cfsavecontent variable="theMessage">
2166                        <cfoutput>
2167<h2>#entry.title#</h2>
2168<b>URL:</b> <a href="#makeLink(entry.id)#">#makeLink(entry.id)#</a><br />
2169<b>Author:</b> #entry.name#<br />
2170
2171#renderEntry(entry.body,false,entry.enclosure)#<cfif len(entry.morebody)>
2172<a href="#makeLink(entry.id)#">[Continued at Blog]</a></cfif>
2173                               
2174<p>
2175You are receiving this email because you have subscribed to this blog.<br />
2176To unsubscribe, please go to this URL:
2177<a href="#getRootURL()#unsubscribe.cfm?email=#email#&token=#token#">#getRootURL()#unsubscribe.cfm?email=#email#&token=#token#</a>
2178</p>
2179                        </cfoutput>
2180                        </cfsavecontent>
2181                       
2182                        <cfif instance.mailserver is "">
2183                                <cfmail to="#email#" from="#instance.owneremail#" subject="#variables.utils.htmlToPlainText(htmlEditFormat(instance.blogtitle))# / #variables.utils.htmlToPlainText(entry.title)#" type="html">#theMessage#</cfmail>
2184                        <cfelse>
2185                                <cfmail to="#email#" from="#instance.owneremail#" subject="#variables.utils.htmlToPlainText(htmlEditFormat(instance.blogtitle))# / #variables.utils.htmlToPlainText(entry.title)#"
2186                                                server="#instance.mailserver#" username="#instance.mailusername#" password="#instance.mailpassword#" type="html">#theMessage#</cfmail>
2187                        </cfif>
2188                </cfloop>
2189                       
2190                <!---
2191                        update the record to mark it mailed.
2192                        note: it is possible that an entry will never be marked mailed if your blog has
2193                        no subscribers. I don't think this is an issue though.
2194                --->
2195                <cfquery datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
2196                update tblblogentries
2197                set             mailed =
2198                                <cfif instance.blogDBType is not "MYSQL">
2199                                        <cfqueryparam value="true" cfsqltype="CF_SQL_BIT">
2200                           <cfelse>
2201                                                <cfqueryparam value="1" cfsqltype="CF_SQL_TINYINT">
2202                           </cfif>                 
2203                where   id = <cfqueryparam value="#arguments.entryid#" cfsqltype="CF_SQL_VARCHAR">
2204                </cfquery>
2205               
2206               
2207        </cffunction>
2208       
2209        <cffunction name="makeCategoryLink" access="public" returnType="string" output="false"
2210                                hint="Generates links for a category.">
2211                <cfargument name="catid" type="uuid" required="true">
2212                <cfset var q = "">
2213
2214                <cfquery name="q" datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
2215                select  categoryalias
2216                from    tblblogcategories
2217                where   categoryid = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.catid#" maxlength="35">
2218                </cfquery>
2219
2220                <cfif q.categoryalias is not "">
2221                        <cfreturn "#instance.blogURL#/#q.categoryalias#">
2222                <cfelse>
2223                        <cfreturn "#instance.blogURL#?mode=cat&catid=#arguments.catid#">
2224                </cfif>
2225
2226        </cffunction>
2227       
2228        <cffunction name="cacheLink" access="public" returnType="struct" output="false"
2229                                hint="Caches a link.">
2230                <cfargument name="entryid" type="uuid" required="true" />
2231                <cfargument name="alias" type="string" required="true" />
2232                <cfargument name="posted" type="date" required="true" />
2233               
2234                <!---// make sure the cache exists //--->
2235                <cfif not structKeyExists(variables, "lCache")>
2236                        <cfset variables.lCache = structNew() />
2237                </cfif>
2238
2239                <cfset variables.lCache[arguments.entryid] = structNew() />
2240                <cfset variables.lCache[arguments.entryid].alias = arguments.alias />
2241                <cfset variables.lCache[arguments.entryid].posted = arguments.posted />
2242               
2243                <cfreturn arguments />
2244        </cffunction>
2245
2246        <cffunction name="makeLink" access="public" returnType="string" output="false"
2247                                hint="Generates links for an entry.">
2248                <cfargument name="entryid" type="uuid" required="true" />
2249                <cfargument name="updateCache" type="boolean" required="false" default="false" />
2250                <cfset var q = "">
2251                <cfset var realdate = "">
2252               
2253                <cfif not structKeyExists(variables, "lCache")>
2254                        <cfset variables.lCache = structNew()>
2255                </cfif>
2256               
2257                <!---// if forcing the cache to be updated, remove the key //--->
2258                <cfif arguments.updateCache>
2259                        <cfset structDelete(variables.lCache, arguments.entryid, true) />
2260                </cfif>
2261               
2262                <cfif not structKeyExists(variables.lCache, arguments.entryid)>
2263                        <cflock name="variablesLCache_#instance.name#" timeout="30" type="exclusive">
2264                                <cfif not structKeyExists(variables.lCache, arguments.entryid)>
2265                                        <cfquery name="q" datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
2266                                        select  posted, alias
2267                                        from    tblblogentries
2268                                        where   id = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.entryid#" maxlength="35">
2269                                        </cfquery>
2270                                        <!---// cache the link //--->
2271                                        <cfset realdate = dateAdd("h", instance.offset, q.posted)>
2272                                        <cfset cacheLink(entryid=arguments.entryid, alias=q.alias, posted=realdate) />
2273                                <cfelse>
2274                                        <cfset q = structNew()>
2275                                        <cfset q.alias = variables.lCache[arguments.entryid].alias>
2276                                        <cfset q.posted = variables.lCache[arguments.entryid].posted>
2277                                </cfif>
2278                                </cflock>
2279                <cfelse>
2280                        <cfset q = structNew()>
2281                        <cfset q.alias = variables.lCache[arguments.entryid].alias>
2282                        <cfset q.posted = variables.lCache[arguments.entryid].posted>
2283                </cfif>
2284               
2285                <cfif q.alias is not "">
2286                        <cfreturn "#instance.blogURL#/#year(q.posted)#/#month(q.posted)#/#day(q.posted)#/#q.alias#">
2287                <cfelse>
2288                        <cfreturn "#instance.blogURL#?mode=entry&entry=#arguments.entryid#">
2289                </cfif>
2290        </cffunction>
2291
2292        <cffunction name="makeTitle" access="public" returnType="string" output="false"
2293                                hint="Formats the title.">
2294                <cfargument name="title" type="string" required="true">
2295               
2296                <!--- Remove non alphanumeric but keep spaces. --->
2297                <!--- Changed to be more strict - Martin Baur noticed foreign chars getting through. THey
2298                ARE valid alphanumeric chars, but we don't want them. --->
2299                <!---
2300                <cfset arguments.title = reReplace(arguments.title,"[^[:alnum:] ]","","all")>
2301                --->
2302                <!---// replace the & symbol with the word "and" //--->
2303                <cfset arguments.title = replace(arguments.title, "&amp;", "and", "all") />
2304                <!---// remove html entities //--->
2305                <cfset arguments.title = reReplace(arguments.title, "&[^;]+;", "", "all") />
2306                <cfset arguments.title = reReplace(arguments.title,"[^0-9a-zA-Z ]","","all")>
2307                <!--- change spaces to - --->
2308                <cfset arguments.title = replace(arguments.title," ","-","all")>
2309               
2310                <cfreturn arguments.title>
2311        </cffunction>
2312       
2313        <cffunction name="notifyEntry" access="public" returnType="void" output="false"
2314                                hint="Sends a message to everyone in an entry.">
2315                <cfargument name="entryid" type="uuid" required="true">
2316                <cfargument name="message" type="string" required="true">
2317                <cfargument name="subject" type="string" required="true">
2318                <cfargument name="from" type="string" required="true">
2319
2320                <!--- Both of these are related to comment moderation. --->             
2321                <cfargument name="adminonly" type="boolean" required="false">
2322                <cfargument name="noadmin" type="boolean" required="false">
2323
2324                <!--- used so we can get the kill switch --->
2325                <cfargument name="commentid" type="string" required="false">
2326               
2327                <cfset var emailAddresses = structNew()>
2328                <cfset var folks = "">
2329                <cfset var folk = "">
2330                <cfset var comments = "">
2331                <cfset var address = "">
2332                <cfset var ulink = "">
2333                <cfset var theMessage = "">
2334                <cfset var comment = getComment(arguments.commentid)>
2335
2336                <!--- is it a valid entry? --->
2337                <cfif not entryExists(arguments.entryid)>
2338                        <cfset variables.utils.throw("#entryid# isn't a valid entry.")>
2339                </cfif>
2340               
2341                <!--- argument allows us to only send to the admin. --->
2342                <cfif not structKeyExists(arguments, "adminonly") or not arguments.adminonly>
2343                               
2344                        <!--- First, get everyone in the thread --->
2345                        <cfinvoke method="getComments" returnVariable="comments">
2346                                <cfinvokeargument name="id" value="#arguments.entryid#">
2347                                <cfinvokeargument name="includesubscribers" value="true">
2348                        </cfinvoke>
2349
2350                        <cfloop query="comments">
2351                                <cfif isBoolean(subscribe) and subscribe and not structKeyExists(emailAddresses, email)>
2352                                        <!--- We store the id of the comment, this is used in unsub  notices --->
2353                                        <cfset emailAddresses[email] = id>
2354                                </cfif>
2355                        </cfloop>
2356                       
2357
2358                </cfif>
2359
2360                <!--- Send email to admin --->
2361                <cfif not structKeyExists(arguments, "noadmin") or not arguments.noadmin>
2362                        <cfset emailAddresses[instance.ownerEmail] = "">
2363                </cfif>
2364                               
2365                <!--- Don't send email to from --->
2366                <cfset structDelete(emailAddresses, arguments.from)>
2367               
2368                <cfif not structIsEmpty(emailAddresses)>
2369                        <!---
2370                                Determine if we have a commentsFrom property. If so, it overrides this setting.
2371                        --->
2372                        <cfif getProperty("commentsFrom") neq "">
2373                                <cfset arguments.from = getProperty("commentsFrom")>
2374                        </cfif>
2375
2376                        <cfloop item="address" collection="#emailAddresses#">
2377                                <!--- determine if msg has an unsub token, if so, prepare the link --->
2378                                <!---
2379                                        Note, right now, the email sent to the admin will have a blank
2380                                        commentID. Since the admin can't unsub anyway I don't think it
2381                                        is a huge deal.
2382                                --->
2383                                <cfif findNoCase("%unsubscribe%", arguments.message)>
2384                                        <cfif address is not instance.ownerEmail>
2385                                                <cfset ulink = getRootURL() & "unsubscribe.cfm" &
2386                                                "?commentID=#emailAddresses[address]#&email=#address#">
2387                                        <cfelse>
2388                                                <cfset ulink = "Not available for owner.">
2389                                                <!--- We get a bit fancier now as well as we will be allowing for kill switches --->
2390                                                <cfset ulink = ulink & "#chr(10)#Delete this comment: #getRootURL()#index.cfm?killcomment=#comment.killcomment#">
2391                                                <!--- also allow for approving --->
2392                                                <cfif instance.moderate>
2393                                                        <cfset ulink = ulink & "#chr(10)#Approve this comment: #getRootURL()#index.cfm?approvecomment=#comment.id#">
2394                                                </cfif>
2395                                        </cfif>
2396                                        <cfset theMessage = replaceNoCase(arguments.message, "%unsubscribe%", ulink, "all")>
2397                                <cfelse>
2398                                        <cfset theMessage = arguments.message>
2399                                </cfif>
2400                                                               
2401                                <!--- switch depending on server --->
2402                                <cfif instance.mailserver is "">
2403                                        <cfmail to="#address#" from="#arguments.from#" subject="#variables.utils.htmlToPlainText(arguments.subject)#">#theMessage#</cfmail>
2404                                <cfelse>
2405                                        <cfmail to="#address#" from="#arguments.from#" subject="#variables.utils.htmlToPlainText(arguments.subject)#"
2406                                                        server="#instance.mailserver#" username="#instance.mailusername#" password="#instance.mailpassword#">#theMessage#</cfmail>
2407                                </cfif>
2408                        </cfloop>
2409                </cfif>
2410               
2411        </cffunction>
2412
2413        <cffunction name="removeCategory" access="remote" returnType="void" roles="admin" output="false"
2414                                hint="remove entry ID from category X">
2415                <cfargument name="entryid" type="uuid" required="true">
2416                <cfargument name="categoryid" type="uuid" required="true">
2417               
2418                <cfquery datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
2419                        delete from tblblogentriescategories
2420                        where categoryidfk = <cfqueryparam value="#arguments.categoryid#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">
2421                        and entryidfk = <cfqueryparam value="#arguments.entryid#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">
2422                </cfquery>
2423               
2424        </cffunction>
2425
2426        <cffunction name="removeCategories" access="remote" returnType="void" roles="admin" output="false"
2427                                hint="Remove all categories from an entry.">
2428                <cfargument name="entryid" type="uuid" required="true">
2429
2430                <cfquery datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
2431                        delete from tblblogentriescategories
2432                        where   entryidfk = <cfqueryparam value="#arguments.entryid#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">
2433                </cfquery>
2434        </cffunction>
2435
2436        <cffunction name="removeSubscriber" access="remote" returnType="boolean" output="false"
2437                                hint="Removes a subscriber user.">
2438                <cfargument name="email" type="string" required="true">
2439                <cfargument name="token" type="uuid" required="false">
2440                <cfset var getMe = "">
2441               
2442                <cfif not isUserInRole("admin") and not structKeyExists(arguments,"token")>
2443                        <cfset variables.utils.throw("Unauthorized removal.")>
2444                </cfif>
2445               
2446                <!--- First, lets see if this guy is already subscribed. --->
2447                <cfquery name="getMe" datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
2448                select  email
2449                from    tblblogsubscribers
2450                where   email = <cfqueryparam value="#arguments.email#" cfsqltype="cf_sql_varchar" maxlength="50">
2451                <cfif structKeyExists(arguments, "token")>
2452                and             token = <cfqueryparam value="#arguments.token#" cfsqltype="cf_sql_varchar" maxlength="35">
2453                </cfif>
2454                </cfquery>
2455               
2456                <cfif getMe.recordCount is 1>
2457                        <cfquery datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
2458                        delete  from tblblogsubscribers
2459                        where   email = <cfqueryparam value="#arguments.email#" cfsqltype="cf_sql_varchar" maxlength="50">
2460                        <cfif structKeyExists(arguments, "token")>
2461                        and             token = <cfqueryparam value="#arguments.token#" cfsqltype="cf_sql_varchar" maxlength="35">
2462                        </cfif>
2463                        and             blog = <cfqueryparam value="#instance.name#" cfsqltype="cf_sql_varchar" maxlength="50">
2464                        </cfquery>
2465
2466                        <cfreturn true>
2467                <cfelse>
2468                        <cfreturn false>
2469                </cfif>
2470
2471        </cffunction>
2472
2473        <cffunction name="removeUnverifiedSubscribers" access="remote" returnType="void" output="false" roles="admin"
2474                                hint="Removes all subscribers who are not verified.">
2475                                               
2476                <cfquery datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
2477                delete  from tblblogsubscribers
2478                where   blog = <cfqueryparam value="#instance.name#" cfsqltype="cf_sql_varchar" maxlength="50">
2479                and             verified = 0
2480                </cfquery>
2481
2482        </cffunction>
2483
2484        <cffunction name="renderEntry" access="public" returnType="string" output="false"
2485                                hint="Handles rendering the blog entry.">
2486                <cfargument name="string" type="string" required="true">
2487                <cfargument name="printformat" type="boolean" required="false" default="false">
2488                <cfargument name="enclosure" type="string" required="false" default="">
2489                <cfargument name="ignoreParagraphFormat" type="boolean" required="false" default="#yesNoFormat(reFindNoCase('<p[^>]*>', arguments.string, 0, false))#" />
2490                <cfset var counter = "">
2491                <cfset var codeblock = "">
2492                <cfset var codeportion = "">
2493                <cfset var result = "">
2494                <cfset var newbody = "">
2495                <cfset var style = "">
2496                <cfset var imgURL = "">
2497                <cfset var rootURL = "">
2498                <cfset var textblock = "">
2499                <cfset var tbRegex = "">
2500                <cfset var textblockLabel = "">
2501                <cfset var textblockTag = "">
2502                <cfset var newContent = "">
2503               
2504                <cfset var cfc = "">
2505                <cfset var newstring = "">
2506                                               
2507                <!--- Check for code blocks --->
2508                <cfif findNoCase("<code>",arguments.string) and findNoCase("</code>",arguments.string)>
2509                        <cfset counter = findNoCase("<code>",arguments.string)>
2510                        <cfloop condition="counter gte 1">
2511                <cfset codeblock = reFindNoCase("(?s)(.*)(<code>)(.*)(</code>)(.*)",arguments.string,1,1)>
2512                                <cfif arrayLen(codeblock.len) gte 6>
2513                    <cfset codeportion = mid(arguments.string, codeblock.pos[4], codeblock.len[4])>
2514                    <cfif len(trim(codeportion))>
2515                                                <cfset result = variables.codeRenderer.formatString(trim(codeportion))>
2516                                                <cfif arguments.printformat>
2517                                                        <cfset result = "<div class='codePrint'>#result#</div>">
2518                                                <cfelse>
2519                                                        <cfset result = "<div class='code'>#result#</div>">
2520                                                </cfif>
2521                                        <cfelse>
2522                                                <cfset result = "">
2523                                        </cfif>
2524                                        <cfset newbody = mid(arguments.string, 1, codeblock.len[2]) & result & mid(arguments.string,codeblock.pos[6],codeblock.len[6])>
2525       
2526                    <cfset arguments.string = newbody>
2527                                        <cfset counter = findNoCase("<code>",arguments.string,counter)>
2528                                <cfelse>
2529                                        <!--- bad crap, maybe <code> and no ender, or maybe </code><code> --->
2530                                        <cfset counter = 0>
2531                                </cfif>
2532                        </cfloop>
2533                </cfif>
2534               
2535                <!--- call our render funcs --->
2536                <cfloop item="cfc" collection="#variables.renderMethods#">
2537                        <cfinvoke component="#variables.renderMethods[cfc].cfc#" method="renderDisplay" argumentCollection="#arguments#" returnVariable="newstring" />
2538                        <cfset arguments.string = newstring>
2539                </cfloop>       
2540
2541                <!--- New enclosure support. If enclose if a jpg, png, or gif, put it on top, aligned left. --->
2542                <cfif len(arguments.enclosure) and listFindNoCase("gif,jpg,png", listLast(arguments.enclosure, "."))>
2543                        <cfset rootURL = replace(instance.blogURL, "index.cfm", "")>
2544                        <cfset imgURL = "#rootURL#enclosures/#urlEncodedFormat(getFileFromPath(enclosure))#">
2545                        <cfset arguments.string = "<div class=""autoImage""><img src=""#imgURL#""></div>" & arguments.string>
2546                <!--- bmeloche - 06/13/2008 - Adding podcast support. --->
2547                <cfelseif len(arguments.enclosure) and listFindNoCase("mp3", listLast(arguments.enclosure, "."))>
2548                        <cfset rootURL = replace(instance.blogURL, "index.cfm", "")>
2549                        <cfset imgURL = "#rootURL#enclosures/#urlEncodedFormat(getFileFromPath(enclosure))#">
2550                        <cfset arguments.string = "<div id=""#urlEncodedFormat(getFileFromPath(enclosure))#""></div>" & arguments.string>
2551                </cfif>
2552               
2553                <!--- textblock support --->
2554                <cfset tbRegex = "<textblock[[:space:]]+label[[:space:]]*=[[:space:]]*""(.*?)"">">
2555                <cfif reFindNoCase(tbRegex,arguments.string)>
2556                        <cfset counter = reFindNoCase(tbRegex,arguments.string)>
2557                        <cfloop condition="counter gte 1">
2558                                <cfset textblock = reFindNoCase(tbRegex,arguments.string,1,1)>
2559                                <cfif arrayLen(textblock.pos) is 2>
2560                                        <cfset textblockTag = mid(arguments.string, textblock.pos[1], textblock.len[1])>
2561                                        <cfset textblockLabel = mid(arguments.string, textblock.pos[2], textblock.len[2])>
2562                                        <cfset newContent = variables.textblock.getTextBlockContent(textblockLabel)>
2563                                        <cfset arguments.string = replaceNoCase(arguments.string, textblockTag, newContent)>
2564                                </cfif>         
2565                                <cfset counter = reFindNoCase(tbRegex,arguments.string, counter)>
2566                        </cfloop>
2567                </cfif>
2568               
2569                <!---// check to see if we should paragraph format this string //--->
2570                <cfif not arguments.ignoreParagraphFormat>
2571                        <cfset arguments.string = xhtmlParagraphFormat(arguments.string) />
2572                </cfif>
2573
2574                <cfreturn arguments.string />
2575        </cffunction>
2576       
2577        <cffunction name="saveCategory" access="remote" returnType="void" roles="admin" output="false"
2578                                hint="Saves an category.">
2579                <cfargument name="id" type="uuid" required="true">
2580                <cfargument name="name" type="string" required="true">
2581                <cfargument name="alias" type="string" required="true">
2582                <cfset var oldName = getCategory(arguments.id).categoryname>
2583               
2584                <cflock name="blogcfc.addCategory" type="exclusive" timeout=30>
2585               
2586                        <!--- new name? --->
2587                        <cfif oldName neq arguments.name>
2588                                <cfif categoryExists(name="#arguments.name#")>
2589                                        <cfset variables.utils.throw("#arguments.name# already exists as a category.")>
2590                                </cfif>
2591                        </cfif>
2592       
2593                        <cfquery datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
2594                        update  tblblogcategories
2595                        set             categoryname = <cfqueryparam value="#arguments.name#" cfsqltype="cf_sql_varchar" maxlength="50">,
2596                                        categoryalias = <cfqueryparam value="#arguments.alias#" cfsqltype="cf_sql_varchar" maxlength="50">
2597                        where   categoryid = <cfqueryparam value="#arguments.id#" cfsqltype="cf_sql_varchar" maxlength="35">
2598                        </cfquery>
2599
2600                </cflock>
2601                               
2602        </cffunction>
2603       
2604        <cffunction name="saveComment" access="public" returnType="uuid" output="false"
2605                                hint="Saves a comment.">
2606                <cfargument name="commentid" type="uuid" required="true">
2607                <cfargument name="name" type="string" required="true">
2608                <cfargument name="email" type="string" required="true">
2609                <cfargument name="website" type="string" required="true">
2610                <cfargument name="comments" type="string" required="true">
2611                <cfargument name="subscribe" type="boolean" required="true">
2612                <cfargument name="moderated" type="boolean" required="true">
2613                               
2614                <cfset arguments.comments = htmleditformat(arguments.comments)>
2615                <cfset arguments.name = left(htmlEditFormat(arguments.name),50)>
2616                <cfset arguments.email = left(htmlEditFormat(arguments.email),50)>
2617                <cfset arguments.website = left(htmlEditFormat(arguments.website),255)>
2618                                               
2619               
2620                <cfquery datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
2621                update tblblogcomments
2622                set name = <cfqueryparam value="#arguments.name#" maxlength="50">,
2623                email = <cfqueryparam value="#arguments.email#" maxlength="50">,
2624                website = <cfqueryparam value="#arguments.website#" maxlength="255">,
2625                <cfif instance.blogDBType is not "ORACLE">
2626                comment = <cfqueryparam value="#arguments.comments#" cfsqltype="CF_SQL_LONGVARCHAR">,
2627                <cfelse>
2628                comments = <cfqueryparam cfsqltype="cf_sql_clob" value="#arguments.comments#">,
2629                </cfif>
2630                subscribe =
2631                           <cfif instance.blogDBType is "MSSQL" or instance.blogDBType is "MSACCESS">
2632                                   <cfqueryparam value="#arguments.subscribe#" cfsqltype="CF_SQL_BIT">
2633                           <cfelse>
2634                                        <!--- convert yes/no to 1 or 0 --->
2635                                        <cfif arguments.subscribe>
2636                                                <cfset arguments.subscribe = 1>
2637                                        <cfelse>
2638                                                <cfset arguments.subscribe = 0>
2639                                        </cfif>
2640                                   <cfqueryparam value="#arguments.subscribe#" cfsqltype="CF_SQL_TINYINT">
2641                           </cfif>,               
2642                moderated=
2643                        <cfif instance.blogDBType is "MSSQL" or instance.blogDBType is "MSACCESS">
2644                                <cfqueryparam value="#arguments.moderated#" cfsqltype="CF_SQL_BIT">
2645                        <cfelse>
2646                                <cfqueryparam value="#arguments.moderated#" cfsqltype="CF_SQL_TINYINT">
2647                        </cfif>
2648                where   id = <cfqueryparam value="#arguments.commentid#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">
2649                </cfquery>
2650                               
2651                <cfreturn arguments.commentid>
2652        </cffunction>
2653       
2654        <cffunction name="saveEntry" access="remote" returnType="void" roles="admin" output="false"
2655                                hint="Saves an entry.">
2656                <cfargument name="id" type="uuid" required="true">
2657                <cfargument name="title" type="string" required="true">
2658                <cfargument name="body" type="string" required="true">
2659                <cfargument name="morebody" type="string" required="false" default="">
2660                <cfargument name="alias" type="string" required="false" default="">
2661                <!--- I use "any" so I can default to a blank string --->               
2662                <cfargument name="posted" type="any" required="false" default="">       
2663                <cfargument name="allowcomments" type="boolean" required="false" default="true">       
2664                <cfargument name="enclosure" type="string" required="false" default="">
2665                <cfargument name="filesize" type="numeric" required="false" default="0">
2666                <cfargument name="mimetype" type="string" required="false" default="">
2667                <cfargument name="released" type="boolean" required="false" default="true">
2668                <cfargument name="relatedPPosts" type="string" required="true" default="">
2669                <cfargument name="sendemail" type="boolean" required="false" default="true">
2670                <cfargument name="duration" type="string" required="false" default="">
2671                <cfargument name="subtitle" type="string" required="false" default="">
2672                <cfargument name="summary" type="string" required="false" default="">
2673                <cfargument name="keywords" type="string" required="false" default="">
2674
2675                <cfset var theURL = "" />
2676                <cfset var entry = "" />
2677               
2678                <cfif not entryExists(arguments.id)>
2679                        <cfset variables.utils.throw("#arguments.id# does not exist as an entry.")>
2680                </cfif>
2681               
2682                <cfquery datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
2683                        update tblblogentries
2684                        set             title = <cfqueryparam value="#arguments.title#" cfsqltype="CF_SQL_CHAR" maxlength="100">,
2685                                        <cfif instance.blogDBType is not "ORACLE">
2686                                        body = <cfqueryparam value="#arguments.body#" cfsqltype="CF_SQL_LONGVARCHAR">
2687                                        <cfelse>
2688                                        body = <cfqueryparam value="#arguments.body#" cfsqltype="CF_SQL_CLOB">
2689                                        </cfif>
2690                                        <cfif len(arguments.morebody)>
2691                                                <cfif instance.blogDBType is not "ORACLE">
2692                                                ,morebody = <cfqueryparam value="#arguments.morebody#" cfsqltype="CF_SQL_LONGVARCHAR">
2693                                                <cfelse>
2694                                                ,morebody = <cfqueryparam value="#arguments.morebody#" cfsqltype="CF_SQL_CLOB">
2695                                                </cfif>
2696                                        <!--- ME - 04/27/2005 - fix this to overwrite more/ on edit --->
2697                                    <cfelse>
2698                                                <cfif instance.blogDBType is not "ORACLE">
2699                                        ,morebody = <cfqueryparam null="yes" cfsqltype="CF_SQL_LONGVARCHAR">
2700                                                <cfelse>
2701                                                ,morebody = <cfqueryparam null="yes" cfsqltype="CF_SQL_CLOB">
2702                                                </cfif>
2703                                        </cfif>
2704                                        <cfif len(arguments.alias)>
2705                                                ,alias = <cfqueryparam value="#arguments.alias#" cfsqltype="CF_SQL_VARCHAR" maxlength="100">
2706                                        </cfif>
2707                                        <cfif (len(trim(arguments.posted)) gt 0) and isDate(arguments.posted)>
2708                                                ,posted = <cfqueryparam value="#arguments.posted#" cfsqltype="CF_SQL_TIMESTAMP">
2709                                        </cfif>
2710                                    <cfif instance.blogDBType is not "MYSQL" AND instance.blogDBType is not "ORACLE">
2711                                        ,allowcomments = <cfqueryparam value="#arguments.allowcomments#" cfsqltype="CF_SQL_BIT">
2712                                        <cfelse>
2713                                                <!--- convert yes/no to 1 or 0 --->
2714                                                <cfif arguments.allowcomments>
2715                                                        <cfset arguments.allowcomments = 1>
2716                                                <cfelse>
2717                                                        <cfset arguments.allowcomments = 0>
2718                                                </cfif>
2719                                                ,allowcomments = <cfqueryparam value="#arguments.allowcomments#" cfsqltype="CF_SQL_TINYINT">   
2720                                        </cfif>           
2721                                        ,enclosure = <cfqueryparam value="#arguments.enclosure#" cfsqltype="CF_SQL_CHAR" maxlength="255">
2722                                        ,summary = <cfqueryparam value="#arguments.summary#" cfsqltype="CF_SQL_VARCHAR" maxlength="255">
2723                                        ,subtitle = <cfqueryparam value="#arguments.subtitle#" cfsqltype="CF_SQL_VARCHAR" maxlength="100">
2724                                        ,keywords = <cfqueryparam value="#arguments.keywords#" cfsqltype="CF_SQL_VARCHAR" maxlength="100">
2725                                        ,duration = <cfqueryparam value="#arguments.duration#" cfsqltype="CF_SQL_VARCHAR" maxlength="10">                                       
2726                                        ,filesize = <cfqueryparam value="#arguments.filesize#" cfsqltype="CF_SQL_NUMERIC">
2727                                        ,mimetype = <cfqueryparam value="#arguments.mimetype#" cfsqltype="CF_SQL_VARCHAR" maxlength="255">
2728                                        <cfif instance.blogDBType is not "MYSQL" AND instance.blogDBType is not "ORACLE">
2729                                        ,released = <cfqueryparam value="#arguments.released#" cfsqltype="CF_SQL_BIT">
2730                                        <cfelse>
2731                                                <!--- convert yes/no to 1 or 0 --->
2732                                                <cfif arguments.released>
2733                                                        <cfset arguments.released = 1>
2734                                                <cfelse>
2735                                                        <cfset arguments.released = 0>
2736                                                </cfif>
2737                                                ,released = <cfqueryparam value="#arguments.released#" cfsqltype="CF_SQL_TINYINT">     
2738                                        </cfif>           
2739
2740                        where   id = <cfqueryparam value="#arguments.id#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">
2741                        and             blog = <cfqueryparam value="#instance.name#" cfsqltype="CF_SQL_VARCHAR" maxlength="50">
2742                </cfquery>
2743               
2744                <cfset saveRelatedEntries(arguments.ID, arguments.relatedpposts) />
2745               
2746                <!---// get the entry //--->
2747                <cfset entry = getEntry(arguments.id, true) />
2748
2749                <!---// update the link cache //--->
2750                <cfset cacheLink(entryid=arguments.id, alias=entry.alias, posted=entry.posted) />
2751
2752                <cfif arguments.released>
2753               
2754                        <cfif arguments.sendEmail>                     
2755                                <cfif dateCompare(dateAdd("h", instance.offset, entry.posted), blogNow()) is 1>
2756                                        <!--- Handle delayed posting --->
2757                                        <cfset theURL = getRootURL()>
2758                                        <cfset theURL = theURL & "admin/notify.cfm?id=#id#">
2759                                        <cfschedule action="update" task="BlogCFC Notifier #id#" operation="HTTPRequest"
2760                                                                startDate="#entry.posted#" startTime="#entry.posted#" url="#theURL#" interval="once">   
2761                                <cfelse>
2762                                        <cfset mailEntry(arguments.id)>         
2763                                </cfif>
2764                        </cfif>
2765                               
2766                        <cfif dateCompare(dateAdd("h", instance.offset, entry.posted), blogNow()) is not 1>
2767                                <cfset variables.ping.pingAggregators(instance.pingurls, instance.blogtitle, instance.blogurl)>
2768                        </cfif>
2769
2770                </cfif>         
2771               
2772        </cffunction>
2773
2774        <cffunction name="saveRelatedEntries" access="public" returntype="void" roles="admin" output="false"
2775                hint="I add/update related blog entries">
2776                <cfargument name="ID" type="UUID" required="true" />
2777                <cfargument name="relatedpposts" type="string" required="true" />
2778               
2779                <cfset var ppost = "" />
2780               
2781                <cfquery datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
2782                        delete from
2783                                tblblogentriesrelated
2784                        where
2785                                entryid = <cfqueryparam value="#arguments.id#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">
2786                </cfquery>
2787               
2788                <cfloop list="#arguments.relatedpposts#" index="ppost">
2789                        <cfquery datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
2790                                insert into
2791                                        tblblogentriesrelated(
2792                                                entryid,
2793                                                relatedid
2794                                        ) values (
2795                                                <cfqueryparam value="#arguments.id#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">,
2796                                                <cfqueryparam value="#ppost#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">
2797                                        )
2798                        </cfquery>
2799                </cfloop>
2800               
2801        </cffunction>
2802
2803        <cffunction name="setCodeRenderer" access="public" returnType="void" output="false" hint="Injector for coldfish">
2804                <cfargument name="renderer" type="any" required="true">
2805                <cfset variables.coderenderer = arguments.renderer>
2806        </cffunction>
2807       
2808        <cffunction name="setProperty" access="public" returnType="void" output="false" roles="admin">
2809                <cfargument name="property" type="string" required="true">
2810                <cfargument name="value" type="string" required="true">
2811               
2812                <cfset instance[arguments.property] = arguments.value>
2813                <cfset setProfileString(variables.cfgFile, instance.name, arguments.property, arguments.value)>
2814               
2815        </cffunction>
2816       
2817        <cffunction name="setModeratedComment" access="public" returnType="void" output="false" roles="admin" hint="Sets a comment to approved">
2818                <cfargument name="id" type="string" required="true">
2819               
2820                <cfquery datasource="#instance.dsn#">
2821                        update tblblogcomments set moderated=1 where id=<cfqueryparam value="#arguments.id#" cfsqltype="cf_sql_varchar">
2822                </cfquery>
2823               
2824        </cffunction>
2825       
2826        <cffunction name="unsubscribeThread" access="public" returnType="boolean" output="false"
2827                                hint="Removes a user from a thread.">
2828                <cfargument name="commentID" type="UUID" required="true">
2829                <cfargument name="email" type="string" required="true">
2830                <cfset var verifySubscribe = "">
2831               
2832                <!--- First ensure that the commentID equals the email --->
2833                <cfquery name="verifySubscribe" datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
2834                        select  entryidfk
2835                        from    tblblogcomments
2836                        where   id = <cfqueryparam value="#arguments.commentID#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">
2837                        and             email = <cfqueryparam value="#arguments.email#" cfsqltype="CF_SQL_VARCHAR" maxlength="100">
2838                </cfquery>
2839               
2840                <!--- If we have a result, then set subscribe=0 for this user for ALL comments in the thread --->
2841                <cfif verifySubscribe.recordCount>
2842               
2843                        <cfquery datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
2844                                update  tblblogcomments
2845                                set             subscribe = 0
2846                                where   entryidfk = <cfqueryparam value="#verifySubscribe.entryidfk#"
2847                                                                        cfsqltype="CF_SQL_VARCHAR" maxlength="35">
2848                                and             email = <cfqueryparam value="#arguments.email#" cfsqltype="CF_SQL_VARCHAR" maxlength="100">
2849                        </cfquery>
2850                       
2851                        <cfreturn true>
2852                </cfif>
2853               
2854                <cfreturn false>
2855        </cffunction>
2856       
2857        <cffunction name="updatePassword" access="public" returnType="boolean" output="false"
2858                                hint="Updates the current user's password.">
2859                <cfargument name="oldpassword" type="string" required="true">
2860                <cfargument name="newpassword" type="string" required="true">
2861                <cfset var checkit = "">
2862               
2863                <cfquery name="checkit" datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
2864                select  password
2865                from    tblusers
2866                where   username = <cfqueryparam value="#getAuthUser()#" cfsqltype="cf_sql_varchar" maxlength="50">
2867                and             password = <cfqueryparam value="#arguments.oldpassword#" cfsqltype="cf_sql_varchar" maxlength="50">
2868                </cfquery>
2869               
2870                <cfif checkit.recordCount is 0>
2871                        <cfreturn false>
2872                <cfelse>
2873                        <cfquery datasource="#instance.dsn#" username="#instance.username#" password="#instance.password#">
2874                        update  tblusers
2875                        set             password = <cfqueryparam value="#arguments.newpassword#" cfsqltype="cf_sql_varchar" maxlength="50">
2876                        where   username = <cfqueryparam value="#getAuthUser()#" cfsqltype="cf_sql_varchar" maxlength="50">
2877                        </cfquery>
2878                        <cfreturn true>
2879                </cfif>         
2880        </cffunction>
2881
2882        <cffunction name="XHTMLParagraphFormat" returntype="string" output="false">
2883                <cfargument name="strTextBlock" required="true" type="string" />
2884                <cfreturn REReplace("<p>" & arguments.strTextBlock & "</p>", "\r+\n\r+\n", "</p><p>", "ALL") />
2885        </cffunction>
2886                               
2887</cfcomponent>
Note: See TracBrowser for help on using the browser.