| 1 | <!--- |
|---|
| 2 | Name : message.cfc |
|---|
| 3 | Author : Raymond Camden |
|---|
| 4 | Created : October 21, 2004 |
|---|
| 5 | Last Updated : May 1, 2007 |
|---|
| 6 | History : We now check sendonpost to see if we notify admin on posts (rkc 10/21/04) |
|---|
| 7 | The email sent to admins now cotain forum/conference name. (rkc 2/11/05) |
|---|
| 8 | Was calling util.throw, not utils (rkc 3/31/05) |
|---|
| 9 | We needed settings, so now I just pass them all in. (rkc 7/14/05) |
|---|
| 10 | Subscriptions are different now (rkc 7/29/05) |
|---|
| 11 | New init, tableprefix (rkc 8/27/05) |
|---|
| 12 | getmessages returns forum+conference (rkc 9/9/05) |
|---|
| 13 | limit search string (rkc 10/30/05) |
|---|
| 14 | make title in subjects dynamic, fix SaveMessage for moderators (rkc 7/12/06) |
|---|
| 15 | Simple size change + new email support (rkc 7/27/06) |
|---|
| 16 | Render moved in here - attachment support (rkc 11/3/06) |
|---|
| 17 | Swaped render around (rkc 11/6/06) |
|---|
| 18 | Don't send email twice to admin, slight email tweaks (rkc 11/9/06) |
|---|
| 19 | Fix up the deletion of attachments (rkc 11/16/06) |
|---|
| 20 | Slight change to emails sent out - send the username as well (rkc 12/5/6) |
|---|
| 21 | Changed calls to isUserInAnyRole to isTheUserInAnyRole (rkc 5/1/07) |
|---|
| 22 | Support for [img] (rkc 12/8/06) |
|---|
| 23 | Purpose : |
|---|
| 24 | ---> |
|---|
| 25 | <cfcomponent displayName="Message" hint="Handles Messages."> |
|---|
| 26 | |
|---|
| 27 | <cfset variables.dsn = ""> |
|---|
| 28 | <cfset variables.dbtype = ""> |
|---|
| 29 | <cfset variables.tableprefix = ""> |
|---|
| 30 | |
|---|
| 31 | <cffunction name="init" access="public" returnType="message" output="false" |
|---|
| 32 | hint="Returns an instance of the CFC initialized with the correct DSN."> |
|---|
| 33 | <cfreturn this> |
|---|
| 34 | |
|---|
| 35 | </cffunction> |
|---|
| 36 | |
|---|
| 37 | <cffunction name="addMessage" access="remote" returnType="uuid" output="false" |
|---|
| 38 | hint="Adds a message, and potentially a new thread."> |
|---|
| 39 | |
|---|
| 40 | <cfargument name="message" type="struct" required="true"> |
|---|
| 41 | <cfargument name="forumid" type="uuid" required="true"> |
|---|
| 42 | <cfargument name="username" type="string" required="false" default="#getAuthUser()#"> |
|---|
| 43 | <cfargument name="threadid" type="uuid" required="false"> |
|---|
| 44 | <cfset var badForum = false> |
|---|
| 45 | <cfset var forum = ""> |
|---|
| 46 | <cfset var badThread = false> |
|---|
| 47 | <cfset var tmpThread = ""> |
|---|
| 48 | <cfset var tmpConference = ""> |
|---|
| 49 | <cfset var newmessage = ""> |
|---|
| 50 | <cfset var getInterestedFolks = ""> |
|---|
| 51 | <cfset var thread = ""> |
|---|
| 52 | <cfset var newid = createUUID()> |
|---|
| 53 | <cfset var notifiedList = ""> |
|---|
| 54 | <cfset var body = ""> |
|---|
| 55 | |
|---|
| 56 | <!--- First see if we can add a message. Because roles= doesn't allow for OR, we use a UDF ---> |
|---|
| 57 | <cfif not variables.utils.isTheUserInAnyRole("forumsadmin,forumsmoderator,forumsmember")> |
|---|
| 58 | <cfset variables.utils.throw("Message CFC","Unauthorized execution of addMessage.")> |
|---|
| 59 | </cfif> |
|---|
| 60 | |
|---|
| 61 | <!--- Another security check - if arguments.username neq getAuthUser, throw ---> |
|---|
| 62 | <cfif arguments.username neq getAuthUser() and not isUserInRole("forumsadmin")> |
|---|
| 63 | <cfset variables.utils.throw("Message CFC","Unauthorized execution of addMessage.")> |
|---|
| 64 | </cfif> |
|---|
| 65 | |
|---|
| 66 | <cfif not validmessage(arguments.message)> |
|---|
| 67 | <cfset variables.utils.throw("Message CFC","Invalid data passed to addMessage.")> |
|---|
| 68 | </cfif> |
|---|
| 69 | |
|---|
| 70 | <!--- is the forum readonly, or non existent? ---> |
|---|
| 71 | <cftry> |
|---|
| 72 | <cfset forum = variables.forum.getForum(arguments.forumid)> |
|---|
| 73 | <cfif forum.readonly and not isUserInRole("forumsadmin")> |
|---|
| 74 | <cfset badForum = true> |
|---|
| 75 | <cfelse> |
|---|
| 76 | <cfset tmpConference = variables.conference.getConference(forum.conferenceidfk)> |
|---|
| 77 | </cfif> |
|---|
| 78 | <cfcatch type="forumcfc"> |
|---|
| 79 | <!--- don't really care which it is - it is bad ---> |
|---|
| 80 | <cfset badForum = true> |
|---|
| 81 | </cfcatch> |
|---|
| 82 | </cftry> |
|---|
| 83 | |
|---|
| 84 | <cfif badForum> |
|---|
| 85 | <cfset variables.utils.throw("MessageCFC","Invalid or Protected Forum")> |
|---|
| 86 | </cfif> |
|---|
| 87 | |
|---|
| 88 | <!--- is the thread readonly, or nonexistent? ---> |
|---|
| 89 | <cfif isDefined("arguments.threadid")> |
|---|
| 90 | <cftry> |
|---|
| 91 | <cfset tmpThread = variables.thread.getThread(arguments.threadid)> |
|---|
| 92 | <cfif tmpThread.readonly and not isUserInRole("forumsadmin")> |
|---|
| 93 | <cfset badThread = true> |
|---|
| 94 | </cfif> |
|---|
| 95 | <cfcatch type="threadcfc"> |
|---|
| 96 | <!--- don't really care which it is - it is bad ---> |
|---|
| 97 | <cfset badThread = true> |
|---|
| 98 | </cfcatch> |
|---|
| 99 | </cftry> |
|---|
| 100 | |
|---|
| 101 | <cfif badThread> |
|---|
| 102 | <cfset variables.utils.throw("MessageCFC","Invalid or Protected Thread")> |
|---|
| 103 | </cfif> |
|---|
| 104 | <cfelse> |
|---|
| 105 | <!--- We need to create a new thread ---> |
|---|
| 106 | <cfset tmpThread = structNew()> |
|---|
| 107 | <cfset tmpThread.name = message.title> |
|---|
| 108 | <cfset tmpThread.readonly = false> |
|---|
| 109 | <cfset tmpThread.active = true> |
|---|
| 110 | <cfset tmpThread.forumidfk = arguments.forumid> |
|---|
| 111 | <cfset tmpThread.useridfk = variables.user.getUserID(arguments.username)> |
|---|
| 112 | <cfset tmpThread.dateCreated = now()> |
|---|
| 113 | <cfset tmpThread.sticky = false> |
|---|
| 114 | <cfset arguments.threadid = variables.thread.addThread(tmpThread)> |
|---|
| 115 | </cfif> |
|---|
| 116 | |
|---|
| 117 | <cfquery name="newmessage" datasource="#variables.dsn#"> |
|---|
| 118 | insert into #variables.tableprefix#messages(id,title,body,useridfk,threadidfk,posted,attachment,filename) |
|---|
| 119 | values(<cfqueryparam value="#newid#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">, |
|---|
| 120 | <cfqueryparam value="#arguments.message.title#" cfsqltype="CF_SQL_VARCHAR" maxlength="255">, |
|---|
| 121 | <cfqueryparam value="#arguments.message.body#" cfsqltype="CF_SQL_LONGVARCHAR">, |
|---|
| 122 | <cfqueryparam value="#variables.user.getUserID(arguments.username)#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">, |
|---|
| 123 | <cfqueryparam value="#arguments.threadid#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">, |
|---|
| 124 | <cfqueryparam value="#now()#" cfsqltype="CF_SQL_TIMESTAMP">, |
|---|
| 125 | <cfqueryparam value="#arguments.message.attachment#" cfsqltype="CF_SQL_VARCHAR" maxlength="255">, |
|---|
| 126 | <cfqueryparam value="#arguments.message.filename#" cfsqltype="CF_SQL_VARCHAR" maxlength="255"> |
|---|
| 127 | ) |
|---|
| 128 | </cfquery> |
|---|
| 129 | |
|---|
| 130 | <!--- Do clean up of special layout. I may need to abstract this later. ---> |
|---|
| 131 | <cfset body = reReplaceNoCase(arguments.message.body, "\[/{0,1}code\]", "", "all")> |
|---|
| 132 | <cfset body = reReplaceNoCase(body, "\[/{0,1}img\]", "", "all")> |
|---|
| 133 | <cfset body = reReplaceNoCase(body, "\[/{0,1}quote.*?\]", "", "all")> |
|---|
| 134 | |
|---|
| 135 | <!--- get everyone in the thread who wants posts ---> |
|---|
| 136 | <cfset notifiedList = notifySubscribers(arguments.threadid, tmpThread.name, arguments.forumid, variables.user.getUserID(arguments.username),body)> |
|---|
| 137 | |
|---|
| 138 | <cfif structKeyExists(variables.settings,"sendonpost") and len(variables.settings.sendonpost) and not listFindNoCase(notifiedList, variables.settings.sendOnPost)> |
|---|
| 139 | |
|---|
| 140 | <cfmail to="#variables.settings.sendonpost#" from="#variables.settings.fromAddress#" |
|---|
| 141 | subject="#variables.settings.title# Notification: Post to #tmpThread.name#"> |
|---|
| 142 | Title: #arguments.message.title# |
|---|
| 143 | Thread: #tmpThread.name# |
|---|
| 144 | Forum: #forum.name# |
|---|
| 145 | Conference: #tmpConference.name# |
|---|
| 146 | User: #arguments.username# |
|---|
| 147 | |
|---|
| 148 | #wrap(body,80)# |
|---|
| 149 | |
|---|
| 150 | #variables.settings.rootURL#messages.cfm?threadid=#arguments.threadid# |
|---|
| 151 | </cfmail> |
|---|
| 152 | |
|---|
| 153 | </cfif> |
|---|
| 154 | |
|---|
| 155 | <cfreturn newid> |
|---|
| 156 | |
|---|
| 157 | </cffunction> |
|---|
| 158 | |
|---|
| 159 | <cffunction name="deleteMessage" access="public" returnType="void" output="false" |
|---|
| 160 | hint="Deletes a message."> |
|---|
| 161 | |
|---|
| 162 | <cfargument name="id" type="uuid" required="true"> |
|---|
| 163 | <cfset var q = ""> |
|---|
| 164 | |
|---|
| 165 | <!--- First see if we can delete a message. Because roles= doesn't allow for OR, we use a UDF ---> |
|---|
| 166 | <cfif not variables.utils.isTheUserInAnyRole("forumsadmin,forumsmoderator")> |
|---|
| 167 | <cfset variables.utils.throw("Message CFC","Unauthorized execution of deleteMessage.")> |
|---|
| 168 | </cfif> |
|---|
| 169 | |
|---|
| 170 | <cfquery name="q" datasource="#variables.dsn#"> |
|---|
| 171 | select filename |
|---|
| 172 | from #variables.tableprefix#messages |
|---|
| 173 | where id = <cfqueryparam value="#arguments.id#" cfsqltype="CF_SQL_VARCHAR" maxlength="35"> |
|---|
| 174 | </cfquery> |
|---|
| 175 | |
|---|
| 176 | <cfquery datasource="#variables.dsn#"> |
|---|
| 177 | delete from #variables.tableprefix#messages |
|---|
| 178 | where id = <cfqueryparam value="#arguments.id#" cfsqltype="CF_SQL_VARCHAR" maxlength="35"> |
|---|
| 179 | </cfquery> |
|---|
| 180 | |
|---|
| 181 | <cfif len(q.filename) and fileExists("#variables.attachmentdir#/#q.filename#")> |
|---|
| 182 | <cffile action="delete" file="#variables.attachmentdir#/#q.filename#"> |
|---|
| 183 | </cfif> |
|---|
| 184 | |
|---|
| 185 | </cffunction> |
|---|
| 186 | |
|---|
| 187 | <cffunction name="getMessage" access="remote" returnType="struct" output="false" |
|---|
| 188 | hint="Returns a struct copy of the message."> |
|---|
| 189 | <cfargument name="id" type="uuid" required="true"> |
|---|
| 190 | <cfset var qGetMessage = ""> |
|---|
| 191 | |
|---|
| 192 | <cfquery name="qGetMessage" datasource="#variables.dsn#"> |
|---|
| 193 | select id, title, body, posted, useridfk, threadidfk, attachment, filename |
|---|
| 194 | from #variables.tableprefix#messages |
|---|
| 195 | where id = <cfqueryparam value="#arguments.id#" cfsqltype="CF_SQL_VARCHAR" maxlength="35"> |
|---|
| 196 | </cfquery> |
|---|
| 197 | |
|---|
| 198 | <!--- Throw if invalid id passed ---> |
|---|
| 199 | <cfif not qGetMessage.recordCount> |
|---|
| 200 | <cfset variables.utils.throw("MessageCFC","Invalid ID")> |
|---|
| 201 | </cfif> |
|---|
| 202 | |
|---|
| 203 | <cfreturn variables.utils.queryToStruct(qGetMessage)> |
|---|
| 204 | |
|---|
| 205 | </cffunction> |
|---|
| 206 | |
|---|
| 207 | <cffunction name="getMessages" access="remote" returnType="query" output="false" |
|---|
| 208 | hint="Returns a list of messages."> |
|---|
| 209 | |
|---|
| 210 | <cfargument name="threadid" type="uuid" required="false"> |
|---|
| 211 | |
|---|
| 212 | <cfset var qGetMessages = ""> |
|---|
| 213 | |
|---|
| 214 | <cfquery name="qGetMessages" datasource="#variables.dsn#"> |
|---|
| 215 | select #variables.tableprefix#messages.id, #variables.tableprefix#messages.title, #variables.tableprefix#messages.body, #variables.tableprefix#messages.attachment, #variables.tableprefix#messages.filename, |
|---|
| 216 | #variables.tableprefix#messages.posted, #variables.tableprefix#messages.threadidfk, #variables.tableprefix#messages.useridfk, |
|---|
| 217 | #variables.tableprefix#threads.name as threadname, #variables.tableprefix#users.username, |
|---|
| 218 | #variables.tableprefix#forums.name as forumname, #variables.tableprefix#conferences.name as conferencename |
|---|
| 219 | |
|---|
| 220 | from (((#variables.tableprefix#messages left join #variables.tableprefix#threads on #variables.tableprefix#messages.threadidfk = #variables.tableprefix#threads.id) |
|---|
| 221 | left join #variables.tableprefix#forums on #variables.tableprefix#threads.forumidfk = #variables.tableprefix#forums.id) |
|---|
| 222 | left join #variables.tableprefix#conferences on #variables.tableprefix#forums.conferenceidfk = #variables.tableprefix#conferences.id) |
|---|
| 223 | left join #variables.tableprefix#users on #variables.tableprefix#messages.useridfk = #variables.tableprefix#users.id |
|---|
| 224 | |
|---|
| 225 | |
|---|
| 226 | <cfif isDefined("arguments.threadid")> |
|---|
| 227 | where #variables.tableprefix#messages.threadidfk = <cfqueryparam value="#arguments.threadid#" cfsqltype="CF_SQL_VARCHAR" maxlength="35"> |
|---|
| 228 | </cfif> |
|---|
| 229 | order by posted asc |
|---|
| 230 | </cfquery> |
|---|
| 231 | |
|---|
| 232 | <cfreturn qGetMessages> |
|---|
| 233 | |
|---|
| 234 | </cffunction> |
|---|
| 235 | |
|---|
| 236 | <cffunction name="notifySubscribers" access="private" returnType="string" output="false" |
|---|
| 237 | hint="Emails subscribers about a new post."> |
|---|
| 238 | <cfargument name="threadid" type="uuid" required="true"> |
|---|
| 239 | <cfargument name="threadname" type="string" required="true"> |
|---|
| 240 | <cfargument name="forumid" type="uuid" required="true"> |
|---|
| 241 | <cfargument name="userid" type="uuid" required="true"> |
|---|
| 242 | <cfargument name="body" type="string" required="true"> |
|---|
| 243 | <cfset var forum = variables.forum.getForum(arguments.forumid)> |
|---|
| 244 | <cfset var conference = variables.conference.getConference(forum.conferenceidfk)> |
|---|
| 245 | <cfset var subscribers = ""> |
|---|
| 246 | |
|---|
| 247 | <cfset var username = variables.user.getUser(variables.user.getUsernameFromId(arguments.userid)).username> |
|---|
| 248 | |
|---|
| 249 | <!--- |
|---|
| 250 | In order to get our subscribers, we need to get the forum and conference for the thread. |
|---|
| 251 | Then - anyone who is subscribed to ANY of those guys will get notified, unless the person |
|---|
| 252 | is #userid#, the originator of the post. |
|---|
| 253 | ---> |
|---|
| 254 | <cfquery name="subscribers" datasource="#variables.dsn#"> |
|---|
| 255 | select distinct #variables.tableprefix#subscriptions.useridfk, #variables.tableprefix#users.emailaddress |
|---|
| 256 | from #variables.tableprefix#subscriptions, #variables.tableprefix#users |
|---|
| 257 | where (#variables.tableprefix#subscriptions.threadidfk = <cfqueryparam value="#arguments.threadid#" cfsqltype="CF_SQL_VARCHAR" maxlength="35"> |
|---|
| 258 | or #variables.tableprefix#subscriptions.forumidfk = <cfqueryparam value="#arguments.forumid#" cfsqltype="CF_SQL_VARCHAR" maxlength="35"> |
|---|
| 259 | or #variables.tableprefix#subscriptions.conferenceidfk = <cfqueryparam value="#conference.id#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">) |
|---|
| 260 | and #variables.tableprefix#subscriptions.useridfk <> <cfqueryparam value="#arguments.userid#" cfsqltype="CF_SQL_VARCHAR" maxlength="35"> |
|---|
| 261 | and #variables.tableprefix#subscriptions.useridfk = #variables.tableprefix#users.id |
|---|
| 262 | </cfquery> |
|---|
| 263 | |
|---|
| 264 | <cfif subscribers.recordCount> |
|---|
| 265 | <cfmail query="subscribers" subject="#variables.settings.title# Notification: Post to #arguments.threadname#" from="#variables.settings.fromAddress#" to="#emailaddress#"> |
|---|
| 266 | A post has been made to a thread, forum, or conference that you are subscribed to. |
|---|
| 267 | You can change your subscription preferences by updating your profile. |
|---|
| 268 | You can visit the thread here: |
|---|
| 269 | |
|---|
| 270 | #variables.settings.rootURL#messages.cfm?threadid=#arguments.threadid# |
|---|
| 271 | |
|---|
| 272 | Conference: #conference.name# |
|---|
| 273 | Forum: #forum.name# |
|---|
| 274 | Thread: #arguments.threadname# |
|---|
| 275 | User: #username# |
|---|
| 276 | <cfif variables.settings.fullemails> |
|---|
| 277 | Message: |
|---|
| 278 | #wrap(arguments.body,80)# |
|---|
| 279 | </cfif> |
|---|
| 280 | |
|---|
| 281 | |
|---|
| 282 | </cfmail> |
|---|
| 283 | |
|---|
| 284 | </cfif> |
|---|
| 285 | |
|---|
| 286 | <cfreturn valueList(subscribers.emailaddress)> |
|---|
| 287 | </cffunction> |
|---|
| 288 | |
|---|
| 289 | <cffunction name="renderMessage" access="public" returnType="string" roles="" output="false" |
|---|
| 290 | hint="This is used to render messages. Handles all string manipulations."> |
|---|
| 291 | <cfargument name="message" type="string" required="true"> |
|---|
| 292 | <cfset var counter = ""> |
|---|
| 293 | <cfset var codeblock = ""> |
|---|
| 294 | <cfset var codeportion = ""> |
|---|
| 295 | <cfset var style = "code"> |
|---|
| 296 | <cfset var result = ""> |
|---|
| 297 | <cfset var newbody = ""> |
|---|
| 298 | <cfset var codeBlocks = arrayNew(1)> |
|---|
| 299 | <cfset var imgBlocks = arrayNew(1)> |
|---|
| 300 | <cfset var quoteBlocks = arrayNew(1)> |
|---|
| 301 | <cfset var quoteportion = ""> |
|---|
| 302 | <cfset var quotename = ""> |
|---|
| 303 | <cfset var quotetag = ""> |
|---|
| 304 | |
|---|
| 305 | <cfset var imgblock = ""> |
|---|
| 306 | <cfset var imgportion = ""> |
|---|
| 307 | |
|---|
| 308 | <!--- Add Code Support ---> |
|---|
| 309 | <cfif findNoCase("[code]",arguments.message) and findNoCase("[/code]",arguments.message)> |
|---|
| 310 | <cfset counter = findNoCase("[code]",arguments.message)> |
|---|
| 311 | <cfloop condition="counter gte 1"> |
|---|
| 312 | <cfset codeblock = reFindNoCase("(?s)(.*)(\[code\])(.*)(\[/code\])(.*)",arguments.message,1,1)> |
|---|
| 313 | <cfif arrayLen(codeblock.len) gte 6> |
|---|
| 314 | <cfset codeportion = mid(arguments.message, codeblock.pos[4], codeblock.len[4])> |
|---|
| 315 | <cfif len(trim(codeportion))> |
|---|
| 316 | <cfset result = variables.utils.coloredcode(codeportion, style)> |
|---|
| 317 | <cfelse> |
|---|
| 318 | <cfset result = ""> |
|---|
| 319 | </cfif> |
|---|
| 320 | |
|---|
| 321 | <cfset arrayAppend(codeBlocks,result)> |
|---|
| 322 | <cfset newbody = mid(arguments.message, 1, codeblock.len[2]) & "****CODEBLOCK:#arrayLen(codeBlocks)#:KCOLBEDOC****" & mid(arguments.message,codeblock.pos[6],codeblock.len[6])> |
|---|
| 323 | <cfset arguments.message = newbody> |
|---|
| 324 | <cfset counter = findNoCase("[code]",arguments.message,counter)> |
|---|
| 325 | <cfelse> |
|---|
| 326 | <!--- bad crap, maybe <code> and no ender, or maybe </code><code> ---> |
|---|
| 327 | <cfset counter = 0> |
|---|
| 328 | </cfif> |
|---|
| 329 | </cfloop> |
|---|
| 330 | </cfif> |
|---|
| 331 | |
|---|
| 332 | <cfif findNoCase("[img]",arguments.message) and findNoCase("[/img]",arguments.message)> |
|---|
| 333 | <cfset counter = findNoCase("[img]",arguments.message)> |
|---|
| 334 | <cfloop condition="counter gte 1"> |
|---|
| 335 | <cfset imgblock = reFindNoCase("(?s)(.*)(\[img\])(.*)(\[/img\])(.*)",arguments.message,1,1)> |
|---|
| 336 | <cfif arrayLen(imgblock.len) gte 6> |
|---|
| 337 | <cfset imgportion = mid(arguments.message, imgblock.pos[4], imgblock.len[4])> |
|---|
| 338 | <cfif len(trim(imgportion))> |
|---|
| 339 | <cfset result = "<img src=""#imgportion#"">"> |
|---|
| 340 | <cfelse> |
|---|
| 341 | <cfset result = ""> |
|---|
| 342 | </cfif> |
|---|
| 343 | |
|---|
| 344 | <cfset arrayAppend(imgBlocks,result)> |
|---|
| 345 | <cfset newbody = mid(arguments.message, 1, imgblock.len[2]) & "****IMGBLOCK:#arrayLen(imgBlocks)#:KCOLBGMI****" & mid(arguments.message,imgblock.pos[6],imgblock.len[6])> |
|---|
| 346 | <cfset arguments.message = newbody> |
|---|
| 347 | <cfset counter = findNoCase("[img]",arguments.message,counter)> |
|---|
| 348 | <cfelse> |
|---|
| 349 | <!--- bad crap, maybe <code> and no ender, or maybe </code><code> ---> |
|---|
| 350 | <cfset counter = 0> |
|---|
| 351 | </cfif> |
|---|
| 352 | </cfloop> |
|---|
| 353 | </cfif> |
|---|
| 354 | |
|---|
| 355 | <cfif reFindNoCase("[quote.*?]",arguments.message) and findNoCase("[/quote]",arguments.message)> |
|---|
| 356 | <cfset counter = reFindNoCase("[quote.*?]",arguments.message)> |
|---|
| 357 | <cfloop condition="counter gte 1"> |
|---|
| 358 | <cfset quoteblock = reFindNoCase("(?s)(.*)(\[quote.*?\])(.*)(\[/quote\])(.*)",arguments.message,1,1)> |
|---|
| 359 | <cfif arrayLen(quoteblock.len) gte 6> |
|---|
| 360 | <!--- look for name="" in the tag ---> |
|---|
| 361 | <!--- so the tag is pos 3 ---> |
|---|
| 362 | <cfset quotetag = mid(arguments.message, quoteblock.pos[3], quoteblock.len[3])> |
|---|
| 363 | <cfif findNoCase("name=", quotetag)> |
|---|
| 364 | <cfset quotename = rereplace(quotetag, ".*?name=""(.+?)"".*\]", "\1")> |
|---|
| 365 | </cfif> |
|---|
| 366 | <cfset quoteportion = mid(arguments.message, quoteblock.pos[4], quoteblock.len[4])> |
|---|
| 367 | <cfif len(trim(quoteportion))> |
|---|
| 368 | <cfif len(quotename)> |
|---|
| 369 | <cfset result = "<blockquote><div class=""bqheader"">#quotename# said:</div>#quoteportion#</blockquote>"> |
|---|
| 370 | <cfelse> |
|---|
| 371 | <cfset result = "<blockquote>#quoteportion#</blockquote>"> |
|---|
| 372 | </cfif> |
|---|
| 373 | <cfelse> |
|---|
| 374 | <cfset result = ""> |
|---|
| 375 | </cfif> |
|---|
| 376 | |
|---|
| 377 | <cfset arrayAppend(quoteBlocks,result)> |
|---|
| 378 | <cfset newbody = mid(arguments.message, 1, quoteblock.len[2]) & "****QUOTEBLOCK:#arrayLen(quoteBlocks)#:KCOLBETOUQ****" & mid(arguments.message,quoteblock.pos[6],quoteblock.len[6])> |
|---|
| 379 | <cfset arguments.message = newbody> |
|---|
| 380 | <cfset counter = reFindNoCase("[quote.*?]",arguments.message,counter)> |
|---|
| 381 | <cfelse> |
|---|
| 382 | <!--- bad crap, maybe <code> and no ender, or maybe </code><code> ---> |
|---|
| 383 | <cfset counter = 0> |
|---|
| 384 | </cfif> |
|---|
| 385 | </cfloop> |
|---|
| 386 | </cfif> |
|---|
| 387 | |
|---|
| 388 | <!--- now htmlecode ---> |
|---|
| 389 | <cfset arguments.message = htmlEditFormat(arguments.message)> |
|---|
| 390 | |
|---|
| 391 | <!--- turn on URLs ---> |
|---|
| 392 | <cfset arguments.message = variables.utils.activeURL(arguments.message)> |
|---|
| 393 | |
|---|
| 394 | <!--- now put those blocks back in ---> |
|---|
| 395 | <cfloop index="counter" from="1" to="#arrayLen(codeBlocks)#"> |
|---|
| 396 | <cfset arguments.message = replace(arguments.message,"****CODEBLOCK:#counter#:KCOLBEDOC****", codeBlocks[counter])> |
|---|
| 397 | </cfloop> |
|---|
| 398 | <cfloop index="counter" from="1" to="#arrayLen(imgBlocks)#"> |
|---|
| 399 | <cfset arguments.message = replace(arguments.message,"****IMGBLOCK:#counter#:KCOLBGMI****", imgBlocks[counter])> |
|---|
| 400 | </cfloop> |
|---|
| 401 | <cfloop index="counter" from="1" to="#arrayLen(quoteBlocks)#"> |
|---|
| 402 | <cfset arguments.message = replace(arguments.message,"****QUOTEBLOCK:#counter#:KCOLBETOUQ****", quoteBlocks[counter])> |
|---|
| 403 | </cfloop> |
|---|
| 404 | |
|---|
| 405 | <!--- add Ps ---> |
|---|
| 406 | <cfset arguments.message = variables.utils.paragraphFormat2(arguments.message)> |
|---|
| 407 | |
|---|
| 408 | <cfreturn arguments.message> |
|---|
| 409 | </cffunction> |
|---|
| 410 | |
|---|
| 411 | <cffunction name="renderHelp" access="public" returnType="string" roles="" output="false" |
|---|
| 412 | hint="This is used to return help for message editing."> |
|---|
| 413 | <cfset var msg = ""> |
|---|
| 414 | |
|---|
| 415 | <cfsavecontent variable="msg"> |
|---|
| 416 | All URLs will be automatically linked. No HTML is allowed in your message.<br /> |
|---|
| 417 | You may include code in your message like so: [code]...[/code].<br /> |
|---|
| 418 | You may include an image in your message like so: [img]url[/img].<br /> |
|---|
| 419 | To add a quote, use [quote]...[/quote].<br /> |
|---|
| 420 | To annotate the quote, use [quote name="foo"]...[/quote]. |
|---|
| 421 | </cfsavecontent> |
|---|
| 422 | |
|---|
| 423 | <cfreturn msg> |
|---|
| 424 | </cffunction> |
|---|
| 425 | |
|---|
| 426 | <cffunction name="saveMessage" access="remote" returnType="void" roles="" output="false" |
|---|
| 427 | hint="Saves an existing message."> |
|---|
| 428 | |
|---|
| 429 | <cfargument name="id" type="uuid" required="true"> |
|---|
| 430 | <cfargument name="message" type="struct" required="true"> |
|---|
| 431 | |
|---|
| 432 | <cfif not variables.utils.isTheUserInAnyRole("forumsadmin,forumsmoderator")> |
|---|
| 433 | <cfset variables.utils.throw("Message CFC","Unauthorized execution of saveMessage.")> |
|---|
| 434 | </cfif> |
|---|
| 435 | |
|---|
| 436 | <cfif not validMessage(arguments.message)> |
|---|
| 437 | <cfset variables.utils.throw("Message CFC","Invalid data passed to saveMessage.")> |
|---|
| 438 | </cfif> |
|---|
| 439 | |
|---|
| 440 | <cfquery datasource="#variables.dsn#"> |
|---|
| 441 | update #variables.tableprefix#messages |
|---|
| 442 | set title = <cfqueryparam value="#arguments.message.title#" cfsqltype="CF_SQL_VARCHAR" maxlength="255">, |
|---|
| 443 | body = <cfqueryparam value="#arguments.message.body#" cfsqltype="CF_SQL_LONGVARCHAR">, |
|---|
| 444 | threadidfk = <cfqueryparam value="#arguments.message.threadidfk#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">, |
|---|
| 445 | useridfk = <cfqueryparam value="#arguments.message.useridfk#" cfsqltype="CF_SQL_VARCHAR" maxlength="35">, |
|---|
| 446 | posted = <cfqueryparam value="#arguments.message.posted#" cfsqltype="CF_SQL_TIMESTAMP">, |
|---|
| 447 | attachment = <cfqueryparam value="#arguments.message.attachment#" cfsqltype="CF_SQL_VARCHAR" maxlength="255">, |
|---|
| 448 | filename = <cfqueryparam value="#arguments.message.filename#" cfsqltype="CF_SQL_VARCHAR" maxlength="255"> |
|---|
| 449 | where id = <cfqueryparam value="#arguments.id#" cfsqltype="CF_SQL_VARCHAR" maxlength="35"> |
|---|
| 450 | </cfquery> |
|---|
| 451 | |
|---|
| 452 | </cffunction> |
|---|
| 453 | |
|---|
| 454 | <cffunction name="search" access="remote" returnType="query" output="false" |
|---|
| 455 | hint="Allows you to search messages."> |
|---|
| 456 | <cfargument name="searchterms" type="string" required="true"> |
|---|
| 457 | <cfargument name="searchtype" type="string" required="false" default="phrase" hint="Must be: phrase,any,all"> |
|---|
| 458 | |
|---|
| 459 | <cfset var results = ""> |
|---|
| 460 | <cfset var x = ""> |
|---|
| 461 | <cfset var joiner = ""> |
|---|
| 462 | <cfset var aTerms = ""> |
|---|
| 463 | |
|---|
| 464 | <cfset arguments.searchTerms = variables.utils.searchSafe(arguments.searchTerms)> |
|---|
| 465 | |
|---|
| 466 | <!--- massage search terms into an array ---> |
|---|
| 467 | <cfset aTerms = listToArray(arguments.searchTerms," ")> |
|---|
| 468 | |
|---|
| 469 | |
|---|
| 470 | <!--- confirm searchtype is ok ---> |
|---|
| 471 | <cfif not listFindNoCase("phrase,any,all", arguments.searchtype)> |
|---|
| 472 | <cfset arguments.searchtype = "phrase"> |
|---|
| 473 | <cfelseif arguments.searchtype is "any"> |
|---|
| 474 | <cfset joiner = "OR"> |
|---|
| 475 | <cfelseif arguments.searchtype is "all"> |
|---|
| 476 | <cfset joiner = "AND"> |
|---|
| 477 | </cfif> |
|---|
| 478 | |
|---|
| 479 | <cfquery name="results" datasource="#variables.dsn#"> |
|---|
| 480 | select id, title, threadidfk |
|---|
| 481 | from #variables.tableprefix#messages |
|---|
| 482 | where 1 = 1 |
|---|
| 483 | and ( |
|---|
| 484 | <cfif arguments.searchtype is not "phrase"> |
|---|
| 485 | <cfloop index="x" from=1 to="#arrayLen(aTerms)#"> |
|---|
| 486 | (title like <cfqueryparam cfsqltype="CF_SQL_VARCHAR" maxlength="255" value="%#left(aTerms[x],255)#%"> |
|---|
| 487 | or |
|---|
| 488 | body like '%#aTerms[x]#%' |
|---|
| 489 | ) |
|---|
| 490 | <cfif x is not arrayLen(aTerms)>#joiner#</cfif> |
|---|
| 491 | </cfloop> |
|---|
| 492 | <cfelse> |
|---|
| 493 | title like <cfqueryparam cfsqltype="CF_SQL_VARCHAR" maxlength="255" value="%#left(arguments.searchTerms,255)#%"> |
|---|
| 494 | or |
|---|
| 495 | body like '%#arguments.searchTerms#%' |
|---|
| 496 | </cfif> |
|---|
| 497 | ) |
|---|
| 498 | </cfquery> |
|---|
| 499 | |
|---|
| 500 | <cfreturn results> |
|---|
| 501 | </cffunction> |
|---|
| 502 | |
|---|
| 503 | <cffunction name="validMessage" access="private" returnType="boolean" output="false" |
|---|
| 504 | hint="Checks a structure to see if it contains all the proper keys/values for a forum."> |
|---|
| 505 | |
|---|
| 506 | <cfargument name="cData" type="struct" required="true"> |
|---|
| 507 | <cfset var rList = "title,body"> |
|---|
| 508 | <cfset var x = ""> |
|---|
| 509 | |
|---|
| 510 | <cfloop index="x" list="#rList#"> |
|---|
| 511 | <cfif not structKeyExists(cData,x)> |
|---|
| 512 | <cfreturn false> |
|---|
| 513 | </cfif> |
|---|
| 514 | </cfloop> |
|---|
| 515 | |
|---|
| 516 | <cfreturn true> |
|---|
| 517 | |
|---|
| 518 | </cffunction> |
|---|
| 519 | |
|---|
| 520 | <cffunction name="setSettings" access="public" output="No" returntype="void"> |
|---|
| 521 | <cfargument name="settings" required="true" hint="Setting"> |
|---|
| 522 | <cfset variables.dsn = arguments.settings.getSettings().dsn> |
|---|
| 523 | <cfset variables.dbtype = arguments.settings.getSettings().dbtype> |
|---|
| 524 | <cfset variables.tableprefix = arguments.settings.getSettings().tableprefix> |
|---|
| 525 | <cfset variables.settings = arguments.settings.getSettings()> |
|---|
| 526 | </cffunction> |
|---|
| 527 | |
|---|
| 528 | <cffunction name="setUtils" access="public" output="No" returntype="void"> |
|---|
| 529 | <cfargument name="utils" required="true" hint="utils"> |
|---|
| 530 | <cfset variables.utils = arguments.utils /> |
|---|
| 531 | </cffunction> |
|---|
| 532 | |
|---|
| 533 | <cffunction name="setThread" access="public" output="No" returntype="void"> |
|---|
| 534 | <cfargument name="thread" required="true" hint="thread"> |
|---|
| 535 | <cfset variables.thread = arguments.thread /> |
|---|
| 536 | </cffunction> |
|---|
| 537 | |
|---|
| 538 | <cffunction name="setForum" access="public" output="No" returntype="void"> |
|---|
| 539 | <cfargument name="forum" required="true" hint="forum"> |
|---|
| 540 | <cfset variables.forum = arguments.forum /> |
|---|
| 541 | </cffunction> |
|---|
| 542 | |
|---|
| 543 | <cffunction name="setUser" access="public" output="No" returntype="void"> |
|---|
| 544 | <cfargument name="user" required="true" hint="user" /> |
|---|
| 545 | <cfset variables.user = arguments.user /> |
|---|
| 546 | </cffunction> |
|---|
| 547 | |
|---|
| 548 | <cffunction name="setConference" access="public" output="No" returntype="void"> |
|---|
| 549 | <cfargument name="conference" required="true" hint="conference" /> |
|---|
| 550 | <cfset variables.conference = arguments.conference /> |
|---|
| 551 | </cffunction> |
|---|
| 552 | |
|---|
| 553 | </cfcomponent> |
|---|