Created
September 6, 2016 14:49
-
-
Save jameslkingsley/50e4803f2b553fad2d04cdfa5a4fb81a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfcomponent displayname="core"> | |
<cffunction name="BlackListApp" access="public" returntype="void"> | |
<cfargument name="appID" type="numeric" required="yes"> | |
<cfset var loc = {}> | |
<cfquery name="loc.getAppIP" datasource="#GetDatasource()#"> | |
SELECT appIP | |
FROM apps | |
WHERE appID = #val(appID)# | |
LIMIT 1 | |
</cfquery> | |
<cfquery name="loc.removeOther" datasource="#GetDatasource()#"> | |
DELETE FROM blacklist | |
WHERE blAddress = '#loc.getAppIP.appIP#' | |
</cfquery> | |
<cfquery name="loc.addNew" datasource="#GetDatasource()#"> | |
INSERT INTO blacklist ( | |
blAddress | |
) VALUES ( | |
'#loc.getAppIP.appIP#' | |
) | |
</cfquery> | |
<cfquery name="loc.updateStatus" datasource="#GetDatasource()#"> | |
UPDATE apps | |
SET appStatus = 'Blacklisted' | |
WHERE appID = #val(appID)# | |
</cfquery> | |
</cffunction> | |
<cffunction name="WhiteListApp" access="public" returntype="void"> | |
<cfargument name="appID" type="numeric" required="yes"> | |
<cfset var loc = {}> | |
<cfquery name="loc.getAppIP" datasource="#GetDatasource()#"> | |
SELECT appIP | |
FROM apps | |
WHERE appID = #val(appID)# | |
LIMIT 1 | |
</cfquery> | |
<cfquery name="loc.removeOther" datasource="#GetDatasource()#"> | |
DELETE FROM blacklist | |
WHERE blAddress = '#loc.getAppIP.appIP#' | |
</cfquery> | |
<cfquery name="loc.updateStatus" datasource="#GetDatasource()#"> | |
UPDATE apps | |
SET appStatus = 'Pending' | |
WHERE appID = #val(appID)# | |
</cfquery> | |
</cffunction> | |
<cffunction name="LoadEmailForApp" access="public" returntype="array"> | |
<cfargument name="appID" type="numeric" required="yes"> | |
<cfset var loc = {}> | |
<cfquery name="loc.emails" datasource="#GetDatasource()#"> | |
SELECT * | |
FROM apps_emails | |
WHERE aeParent = #val(appID)# | |
ORDER BY aeTimestamp ASC | |
</cfquery> | |
<cfreturn QueryToArrayOfStruct(loc.emails)> | |
</cffunction> | |
<cffunction name="DeletePreset" access="public" returntype="void"> | |
<cfargument name="presetID" type="numeric" required="yes"> | |
<cfset var loc = {}> | |
<cfquery name="loc.del" datasource="#GetDatasource()#"> | |
DELETE FROM email_presets | |
WHERE epID = #val(presetID)# | |
</cfquery> | |
</cffunction> | |
<cffunction name="AddEmailPreset" access="public" returntype="void"> | |
<cfargument name="args" type="struct" required="yes"> | |
<cfset var loc = {}> | |
<cfquery name="loc.add" datasource="#GetDatasource()#"> | |
INSERT INTO email_presets ( | |
epSubject, | |
epContent | |
) VALUES ( | |
'#args.subject#', | |
'#args.content#' | |
) | |
</cfquery> | |
</cffunction> | |
<cffunction name="SaveEmailPreset" access="public" returntype="void"> | |
<cfargument name="args" type="struct" required="yes"> | |
<cfset var loc = {}> | |
<cfquery name="loc.update" datasource="#GetDatasource()#"> | |
UPDATE email_presets | |
SET epSubject = '#args.subject#', | |
epContent = '#args.content#' | |
WHERE epID = #val(args.presetID)# | |
</cfquery> | |
</cffunction> | |
<cffunction name="AddEmailToApp" access="public" returntype="void"> | |
<cfargument name="args" type="struct" required="yes"> | |
<cfset var loc = {}> | |
<cfquery name="loc.newEmail" datasource="#GetDatasource()#"> | |
INSERT INTO apps_emails ( | |
aeParent, | |
aeSubject, | |
aeContent<cfif session.steam.loggedin>, | |
aeSenderID, | |
aeSenderName, | |
aeSenderImage</cfif> | |
) VALUES ( | |
#val(args.appID)#, | |
'#args.subject#', | |
'#ParagraphFormat(args.content)#'<cfif session.steam.loggedin>, | |
'#session.steam.id#', | |
'#session.steam.user.steamID#', | |
'#session.steam.user.avatarFull#'</cfif> | |
) | |
</cfquery> | |
</cffunction> | |
<cffunction name="LoadEmailPreset" access="public" returntype="struct"> | |
<cfargument name="presetID" type="numeric" required="yes"> | |
<cfset var loc = {}> | |
<cfquery name="loc.preset" datasource="#GetDatasource()#"> | |
SELECT * | |
FROM email_presets | |
WHERE epID = #val(presetID)# | |
</cfquery> | |
<cfreturn QueryToStruct(loc.preset)> | |
</cffunction> | |
<cffunction name="LoadEmailPresets" access="public" returntype="array"> | |
<cfset var loc = {}> | |
<cfquery name="loc.presets" datasource="#GetDatasource()#"> | |
SELECT * | |
FROM email_presets | |
</cfquery> | |
<cfreturn QueryToArrayOfStruct(loc.presets)> | |
</cffunction> | |
<cffunction name="LoadPendingMediaCounts" access="public" returntype="numeric"> | |
<cfset var loc = {}> | |
<cfquery name="loc.photos" datasource="#GetDatasource()#"> | |
SELECT COUNT(phID) AS PhotoCount | |
FROM photos | |
WHERE phActive = 0 | |
</cfquery> | |
<cfquery name="loc.videos" datasource="#GetDatasource()#"> | |
SELECT COUNT(vidID) AS VideoCount | |
FROM videos | |
WHERE vidActive = 0 | |
</cfquery> | |
<cfreturn val(loc.photos.PhotoCount + loc.videos.VideoCount)> | |
</cffunction> | |
<cffunction name="SendTemplatedEmail" access="public" returntype="void"> | |
<cfargument name="args" type="struct" required="yes"> | |
<cfset var loc = {}> | |
<cftry> | |
<cfmail | |
from="#application.mail.from#" | |
to="#args.recipient#" | |
password="#application.mail.password#" | |
server="#application.mail.server#" | |
subject="#args.subject#" | |
username="#application.mail.username#" | |
type="html"> | |
<cfoutput> | |
<cffile action="read" file="#application.directory#\wwwroot\css\email.css" variable="emailStyles"> | |
<style>#emailStyles#</style> | |
<div class="arcomm-email"> | |
<div class="arc_header"> | |
<center> | |
<img src="#request.url#images/logo_white.png" class="arc_logo"> | |
</center> | |
<!---<div class="arc_logo" style="background-image:url(#request.url#images/logo_white.png);"></div>---> | |
<div class="arc_subject">#args.subject#</div> | |
</div> | |
<div class="arc_content"> | |
<center> | |
<div class="arc_innerContent">#args.content#</div> | |
</center> | |
</div> | |
<div class="arc_footer"> | |
<div class="arc_innerFooter"> | |
<a href="#request.url#">© ARCOMM #Year(Now())#</a> | |
</div> | |
</div> | |
</div> | |
</cfoutput> | |
</cfmail> | |
<cfcatch type="any"> | |
<cfdump var="#cfcatch#" output="#application.directory#\data\logs\E#DateFormat(Now(), 'yyyymmdd')##TimeFormat(Now(), 'HHmmss')#.html" format="html"> | |
</cfcatch> | |
</cftry> | |
</cffunction> | |
<cffunction name="LoadSource" access="public" returntype="struct"> | |
<cfargument name="srcID" type="numeric" required="yes"> | |
<cfset var loc = {}> | |
<cfquery name="loc.source" datasource="#GetDatasource()#"> | |
SELECT * | |
FROM sources | |
WHERE srcID = #val(srcID)# | |
LIMIT 1 | |
</cfquery> | |
<cfreturn QueryToStruct(loc.source)> | |
</cffunction> | |
<cffunction name="LoadSources" access="public" returntype="array"> | |
<cfset var loc = {}> | |
<cfquery name="loc.sources" datasource="#GetDatasource()#"> | |
SELECT * | |
FROM sources | |
ORDER BY srcTitle ASC | |
</cfquery> | |
<cfreturn QueryToArrayOfStruct(loc.sources)> | |
</cffunction> | |
<cffunction name="LoadAppData" access="public" returntype="struct"> | |
<cfargument name="refYear" type="numeric" required="yes" default="-1"> | |
<cfargument name="refMonth" type="numeric" required="yes" default="-1"> | |
<cfset var loc = {}> | |
<cfset loc.result = { | |
keys = [], | |
values = {} | |
}> | |
<cfquery name="loc.apps" datasource="#GetDatasource()#"> | |
SELECT * | |
FROM apps | |
WHERE appID = appID | |
<cfif refYear gt -1> | |
AND YEAR(appTimestamp) = #val(refYear)# | |
</cfif> | |
<cfif refMonth gt -1> | |
AND MONTH(appTimestamp) = #val(refMonth)# | |
</cfif> | |
</cfquery> | |
<cfset loc.query = QueryToArrayOfStruct(loc.apps)> | |
<cfloop array="#loc.query#" index="loc.item"> | |
<cfif NOT StructKeyExists(loc.result.values, loc.item.appSource)> | |
<cfset ArrayAppend(loc.result.keys, LCase(loc.item.appSource))> | |
<cfset StructInsert(loc.result.values, LCase(loc.item.appSource), { | |
name = loc.item.appSource, | |
count = 1 | |
})> | |
<cfelse> | |
<cfset loc.result.values[LCase(loc.item.appSource)].count++> | |
</cfif> | |
</cfloop> | |
<cfreturn loc.result> | |
</cffunction> | |
<cffunction name="DeleteAppComment" access="public" returntype="void"> | |
<cfargument name="comID" type="numeric" required="yes"> | |
<cfset var loc = {}> | |
<cfquery name="loc.del" datasource="#GetDatasource()#"> | |
DELETE FROM apps_comments | |
WHERE acID = #val(comID)# | |
AND acOwnerID = '#session.steam.id#' | |
</cfquery> | |
</cffunction> | |
<cffunction name="AddAppComment" access="public" returntype="void"> | |
<cfargument name="args" type="struct" required="yes"> | |
<cfset var loc = {}> | |
<cfquery name="loc.add" datasource="#GetDatasource()#"> | |
INSERT INTO apps_comments ( | |
acParent, | |
acOwnerID, | |
acOwnerName, | |
acOwnerAvatar, | |
acComment | |
) VALUES ( | |
#val(args.appID)#, | |
'#session.steam.id#', | |
'#session.steam.user.steamID#', | |
'#session.steam.user.avatarFull#', | |
'#args.comment#' | |
) | |
</cfquery> | |
</cffunction> | |
<cffunction name="LoadAppComments" access="public" returntype="array"> | |
<cfargument name="appID" type="numeric" required="yes"> | |
<cfset var loc = {}> | |
<cfset loc.result = []> | |
<cfquery name="loc.comments" datasource="#GetDatasource()#"> | |
SELECT *, | |
(SELECT acsSeen FROM apps_comments_seen WHERE acsCommentID = acID) AS CommentSeen | |
FROM apps_comments | |
WHERE acParent = #val(appID)# | |
ORDER BY acTimestamp ASC | |
</cfquery> | |
<cfset loc.result = QueryToArrayOfStruct(loc.comments)> | |
<cfset loc.shouldSee = false> | |
<cfloop array="#loc.result#" index="loc.item"> | |
<cfif loc.item.CommentSeen neq 1> | |
<cfset loc.shouldSee = true> | |
</cfif> | |
</cfloop> | |
<cfif loc.shouldSee> | |
<cfquery name="loc.updateSeen" datasource="#GetDatasource()#"> | |
INSERT INTO apps_comments_seen ( | |
acsUserID, | |
acsCommentID | |
) VALUES | |
<cfset loc.counter = 0> | |
<cfloop array="#loc.result#" index="loc.item"> | |
<cfset loc.counter++> | |
<cfif loc.item.CommentSeen neq 1> | |
( | |
'#session.steam.id#', | |
#val(loc.item.acID)# | |
)<cfif loc.counter neq ArrayLen(loc.result)>,</cfif> | |
</cfif> | |
</cfloop> | |
</cfquery> | |
</cfif> | |
<cfreturn loc.result> | |
</cffunction> | |
<cfscript> | |
/* | |
* Sorts an array of structures based on a key in the structures. | |
* | |
* @param aofS Array of structures. (Required) | |
* @param key Key to sort by. (Required) | |
* @param sortOrder Order to sort by, asc or desc. (Optional) | |
* @param sortType Text, textnocase, or numeric. (Optional) | |
* @param delim Delimiter used for temporary data storage. Must not exist in data. Defaults to a period. (Optional) | |
* @return Returns a sorted array. | |
* @author Nathan Dintenfass ([email protected]) | |
* @version 1, April 4, 2013 | |
*/ | |
function arrayOfStructsSort(aOfS,key){ | |
var sortOrder = "asc"; | |
var sortType = "textnocase"; | |
var delim = "."; | |
var sortArray = arraynew(1); | |
var returnArray = arraynew(1); | |
var count = arrayLen(aOfS); | |
var ii = 1; | |
if (arraylen(arguments) GT 2) | |
sortOrder = arguments[3]; | |
if (arraylen(arguments) GT 3) | |
sortType = arguments[4]; | |
if (arraylen(arguments) GT 4) | |
delim = arguments[5]; | |
for (ii = 1; ii lte count; ii = ii + 1) | |
sortArray[ii] = aOfS[ii][key] & delim & ii; | |
arraySort(sortArray,sortType,sortOrder); | |
for (ii = 1; ii lte count; ii = ii + 1) | |
returnArray[ii] = aOfS[listLast(sortArray[ii],delim)]; | |
return returnArray; | |
} | |
</cfscript> | |
<cffunction name="ArchiveMod" access="public" returntype="void"> | |
<cfargument name="modID" type="numeric" required="yes"> | |
<cfset var loc = {}> | |
<cfquery name="loc.update" datasource="#GetDatasource()#"> | |
UPDATE mods | |
SET modStatus = 'Archived' | |
WHERE modID = #val(modID)# | |
</cfquery> | |
</cffunction> | |
<cffunction name="DeleteMod" access="public" returntype="void"> | |
<cfargument name="modID" type="numeric" required="yes"> | |
<cfset var loc = {}> | |
<cfquery name="loc.check" datasource="#GetDatasource()#"> | |
SELECT modOwner | |
FROM mods | |
WHERE modID = #val(modID)# | |
LIMIT 1 | |
</cfquery> | |
<cfif loc.check.recordcount gt 0> | |
<cfif loc.check.modOwner eq session.steam.id> | |
<cfquery name="loc.delete" datasource="#GetDatasource()#"> | |
DELETE FROM mods | |
WHERE modID = #val(modID)# | |
</cfquery> | |
</cfif> | |
</cfif> | |
</cffunction> | |
<cffunction name="AddMod" access="public" returntype="void"> | |
<cfargument name="args" type="struct" required="yes"> | |
<cfset var loc = {}> | |
<cfquery name="loc.add" datasource="#GetDatasource()#"> | |
INSERT INTO mods ( | |
modOwner, | |
modOwnerName, | |
modName, | |
modLink, | |
modSummary | |
) VALUES ( | |
'#session.steam.id#', | |
'#session.steam.user.steamID#', | |
'#args.title#', | |
'#args.link#', | |
'#args.summary#' | |
) | |
</cfquery> | |
</cffunction> | |
<cffunction name="UserModVote" access="public" returntype="string"> | |
<cfargument name="modID" type="numeric" required="yes"> | |
<cfset var loc = {}> | |
<cfquery name="loc.check" datasource="#GetDatasource()#"> | |
SELECT mvValue | |
FROM mods_votes | |
WHERE mvParent = #val(modID)# | |
AND mvOwner = '#session.steam.id#' | |
LIMIT 1 | |
</cfquery> | |
<cfif loc.check.recordcount is 1> | |
<cfif loc.check.mvValue gt 0> | |
<cfreturn "up"> | |
<cfelse> | |
<cfreturn "down"> | |
</cfif> | |
<cfelse> | |
<cfreturn "none"> | |
</cfif> | |
</cffunction> | |
<cffunction name="DownVoteMod" access="public" returntype="void"> | |
<cfargument name="modID" type="numeric" required="yes"> | |
<cfset var loc = {}> | |
<cfquery name="loc.del" datasource="#GetDatasource()#"> | |
DELETE FROM mods_votes | |
WHERE mvParent = #val(modID)# | |
AND mvOwner = '#session.steam.id#' | |
</cfquery> | |
<cfquery name="loc.new" datasource="#GetDatasource()#"> | |
INSERT INTO mods_votes ( | |
mvParent, | |
mvOwner, | |
mvValue | |
) VALUES ( | |
#val(modID)#, | |
'#session.steam.id#', | |
-1 | |
) | |
</cfquery> | |
</cffunction> | |
<cffunction name="UpVoteMod" access="public" returntype="void"> | |
<cfargument name="modID" type="numeric" required="yes"> | |
<cfset var loc = {}> | |
<cfquery name="loc.del" datasource="#GetDatasource()#"> | |
DELETE FROM mods_votes | |
WHERE mvParent = #val(modID)# | |
AND mvOwner = '#session.steam.id#' | |
</cfquery> | |
<cfquery name="loc.new" datasource="#GetDatasource()#"> | |
INSERT INTO mods_votes ( | |
mvParent, | |
mvOwner, | |
mvValue | |
) VALUES ( | |
#val(modID)#, | |
'#session.steam.id#', | |
1 | |
) | |
</cfquery> | |
</cffunction> | |
<cffunction name="LoadModPoints" access="public" returntype="numeric"> | |
<cfargument name="modID" type="numeric" required="yes"> | |
<cfset var loc = {}> | |
<cfquery name="loc.points" datasource="#GetDatasource()#"> | |
SELECT SUM(mvValue) AS modVotes | |
FROM mods_votes | |
WHERE mvParent = #val(modID)# | |
</cfquery> | |
<cfreturn val(loc.points.modVotes)> | |
</cffunction> | |
<cffunction name="LoadModSuggestions" access="public" returntype="array"> | |
<cfargument name="status" type="string" required="no" default="Active"> | |
<cfargument name="order" type="string" required="no" default="votes"> | |
<cfargument name="count" type="numeric" required="no" default="10"> | |
<cfset var loc = {}> | |
<cfquery name="loc.suggestions" datasource="#GetDatasource()#"> | |
SELECT *, | |
( SELECT SUM(mvValue) FROM mods_votes WHERE mvParent = modID ) AS modVotes | |
FROM mods | |
WHERE modStatus = '#status#' | |
<cfswitch expression="#order#"> | |
<cfcase value="votes"> | |
ORDER BY modVotes DESC | |
</cfcase> | |
<cfcase value="timestamp"> | |
ORDER BY modTimestamp DESC | |
</cfcase> | |
</cfswitch> | |
LIMIT #val(count)# | |
</cfquery> | |
<cfreturn QueryToArrayOfStruct(loc.suggestions)> | |
</cffunction> | |
<cffunction name="LoadNavByName" access="public" returntype="struct"> | |
<cfargument name="navName" type="string" required="yes"> | |
<cfset var loc = {}> | |
<cfquery name="loc.navGet" datasource="#GetDatasource()#"> | |
SELECT * | |
FROM nav | |
WHERE navTitle = '#navName#' | |
LIMIT 1 | |
</cfquery> | |
<cfset loc.nav = QueryToStruct(loc.navGet)> | |
<cfquery name="loc.items" datasource="#GetDatasource()#"> | |
SELECT navItems.*, pages.* | |
FROM navItems, pages | |
WHERE niNav = #val(loc.nav.navID)# | |
AND niPage = pgID | |
AND pgActive = 'Yes' | |
ORDER BY niOrder ASC | |
</cfquery> | |
<cfset loc.nav.items = QueryToArrayOfStruct(loc.items)> | |
<cfreturn loc.nav> | |
</cffunction> | |
<cffunction name="IsBlacklisted" access="public" returntype="boolean"> | |
<cfargument name="IP" type="string" required="yes"> | |
<cfset var loc = {}> | |
<cfquery name="loc.check" datasource="#GetDatasource()#"> | |
SELECT * | |
FROM blacklist | |
WHERE blAddress = '#IP#' | |
LIMIT 1 | |
</cfquery> | |
<cfif loc.check.recordcount is 1> | |
<cfreturn true> | |
<cfelse> | |
<cfreturn false> | |
</cfif> | |
</cffunction> | |
<cffunction name="ApproveApp" access="public" returntype="void"> | |
<cfargument name="appID" type="numeric" required="yes"> | |
<cfset var loc = {}> | |
<cfset loc.app = LoadAppByID(appID)> | |
<cfobject component="code/steam" name="loc.steam"> | |
<cfif loc.steam.IsUserAdmin()> | |
<cfquery name="loc.update" datasource="#GetDatasource()#"> | |
UPDATE apps | |
SET appStatus = 'Approved' | |
WHERE appID = #val(appID)# | |
</cfquery> | |
<cfset loc.approvedPreset = LoadEmailPreset(7)> | |
<cfmail | |
from="#application.mail.from#" | |
to="#loc.app.appEmail#" | |
password="#application.mail.password#" | |
server="#application.mail.server#" | |
subject="[ARCOMM] #loc.approvedPreset.epSubject#" | |
username="#application.mail.username#" | |
type="html"> | |
<cfoutput> | |
#loc.approvedPreset.epContent# | |
</cfoutput> | |
</cfmail> | |
<cfset AddEmailToApp({ | |
"appID" = val(appID), | |
"subject" = "#loc.approvedPreset.epSubject#", | |
"content" = "#loc.approvedPreset.epContent#" | |
})> | |
</cfif> | |
</cffunction> | |
<cffunction name="PendingApp" access="public" returntype="void"> | |
<cfargument name="appID" type="numeric" required="yes"> | |
<cfset var loc = {}> | |
<cfobject component="code/steam" name="loc.steam"> | |
<cfif loc.steam.IsUserAdmin()> | |
<cfquery name="loc.update" datasource="#GetDatasource()#"> | |
UPDATE apps | |
SET appStatus = 'Pending' | |
WHERE appID = #val(appID)# | |
</cfquery> | |
</cfif> | |
</cffunction> | |
<cffunction name="DeclineApp" access="public" returntype="void"> | |
<cfargument name="appID" type="numeric" required="yes"> | |
<cfset var loc = {}> | |
<cfset loc.app = LoadAppByID(appID)> | |
<cfobject component="code/steam" name="loc.steam"> | |
<cfif loc.steam.IsUserAdmin()> | |
<cfquery name="loc.update" datasource="#GetDatasource()#"> | |
UPDATE apps | |
SET appStatus = 'Declined' | |
WHERE appID = #val(appID)# | |
</cfquery> | |
<cfset loc.declinedPreset = LoadEmailPreset(8)> | |
<cfmail | |
from="#application.mail.from#" | |
to="#loc.app.appEmail#" | |
password="#application.mail.password#" | |
server="#application.mail.server#" | |
subject="[ARCOMM] #loc.declinedPreset.epSubject#" | |
username="#application.mail.username#" | |
type="html"> | |
<cfoutput> | |
#loc.declinedPreset.epContent# | |
</cfoutput> | |
</cfmail> | |
<cfset AddEmailToApp({ | |
"appID" = val(appID), | |
"subject" = "#loc.declinedPreset.epSubject#", | |
"content" = "#loc.declinedPreset.epContent#" | |
})> | |
</cfif> | |
</cffunction> | |
<cffunction name="LoadAppByPublicToken" access="public" returntype="struct"> | |
<cfargument name="appID" type="string" required="yes"> | |
<cfset var loc = {}> | |
<cfquery name="loc.app" datasource="#GetDatasource()#"> | |
SELECT * | |
FROM apps | |
WHERE appPublicToken = '#appID#' | |
LIMIT 1 | |
</cfquery> | |
<cfreturn QueryToStruct(loc.app)> | |
</cffunction> | |
<cffunction name="LoadAppByID" access="public" returntype="struct"> | |
<cfargument name="appID" type="numeric" required="yes"> | |
<cfset var loc = {}> | |
<cfquery name="loc.app" datasource="#GetDatasource()#"> | |
SELECT * | |
FROM apps | |
WHERE appID = #val(appID)# | |
LIMIT 1 | |
</cfquery> | |
<cfreturn QueryToStruct(loc.app)> | |
</cffunction> | |
<cffunction name="LoadApp" access="public" returntype="struct"> | |
<cfargument name="appID" type="string" required="yes"> | |
<cfset var loc = {}> | |
<cfquery name="loc.app" datasource="#GetDatasource()#"> | |
SELECT * | |
FROM apps | |
WHERE appToken = '#appID#' | |
LIMIT 1 | |
</cfquery> | |
<cfreturn QueryToStruct(loc.app)> | |
</cffunction> | |
<cffunction name="LoadApplicationCounts" access="public" returntype="struct"> | |
<cfset var loc = {}> | |
<cfset loc.pending = 0> | |
<cfset loc.approved = 0> | |
<cfset loc.declined = 0> | |
<cfquery name="loc.pending" datasource="#GetDatasource()#"> | |
SELECT COUNT(*) AS appCount | |
FROM apps | |
WHERE appStatus = 'Pending' | |
</cfquery> | |
<cfset loc.pending = val(loc.pending.appCount)> | |
<cfquery name="loc.approved" datasource="#GetDatasource()#"> | |
SELECT COUNT(*) AS appCount | |
FROM apps | |
WHERE appStatus = 'Approved' | |
</cfquery> | |
<cfset loc.approved = val(loc.approved.appCount)> | |
<cfquery name="loc.declined" datasource="#GetDatasource()#"> | |
SELECT COUNT(*) AS appCount | |
FROM apps | |
WHERE appStatus = 'Declined' | |
</cfquery> | |
<cfset loc.declined = val(loc.declined.appCount)> | |
<cfquery name="loc.blacklisted" datasource="#GetDatasource()#"> | |
SELECT COUNT(*) AS ipCount | |
FROM blacklist | |
</cfquery> | |
<cfset loc.blacklisted = val(loc.blacklisted.ipCount)> | |
<cfreturn { | |
"pending" = loc.pending, | |
"approved" = loc.approved, | |
"declined" = loc.declined, | |
"blacklisted" = loc.blacklisted | |
}> | |
</cffunction> | |
<cffunction name="LoadNewCommentCount" access="public" returntype="numeric"> | |
<cfargument name="appID" type="numeric" required="yes"> | |
<cfset var loc = {}> | |
<cfquery name="loc.comments" datasource="#GetDatasource()#"> | |
SELECT acID | |
FROM apps_comments | |
WHERE acParent = #val(appID)# | |
AND NOT EXISTS (SELECT acsCommentID FROM apps_comments_seen WHERE acsUserID = '#session.steam.id#' AND acsCommentID = acID) | |
</cfquery> | |
<cfreturn val(loc.comments.recordcount)> | |
</cffunction> | |
<cffunction name="LoadApplications" access="public" returntype="struct"> | |
<cfargument name="order" type="string" required="no" default="oldest"> | |
<cfset var loc = {}> | |
<cfset loc.pending = []> | |
<cfset loc.approved = []> | |
<cfset loc.declined = []> | |
<cfset loc.blacklisted = []> | |
<cfquery name="loc.pending" datasource="#GetDatasource()#"> | |
SELECT * | |
FROM apps | |
WHERE appStatus = 'Pending' | |
ORDER BY appTimestamp <cfif order eq "oldest">ASC<cfelse>DESC</cfif> | |
</cfquery> | |
<cfset loc.pending = QueryToArrayOfStruct(loc.pending)> | |
<cfquery name="loc.approved" datasource="#GetDatasource()#"> | |
SELECT * | |
FROM apps | |
WHERE appStatus = 'Approved' | |
ORDER BY appTimestamp <cfif order eq "oldest">ASC<cfelse>DESC</cfif> | |
</cfquery> | |
<cfset loc.approved = QueryToArrayOfStruct(loc.approved)> | |
<cfquery name="loc.declined" datasource="#GetDatasource()#"> | |
SELECT * | |
FROM apps | |
WHERE appStatus = 'Declined' | |
ORDER BY appTimestamp <cfif order eq "oldest">ASC<cfelse>DESC</cfif> | |
</cfquery> | |
<cfset loc.declined = QueryToArrayOfStruct(loc.declined)> | |
<cfquery name="loc.blacklisted" datasource="#GetDatasource()#"> | |
SELECT * | |
FROM apps, blacklist | |
WHERE appIP = blAddress | |
ORDER BY appTimestamp <cfif order eq "oldest">ASC<cfelse>DESC</cfif> | |
</cfquery> | |
<cfset loc.blacklisted = QueryToArrayOfStruct(loc.blacklisted)> | |
<cfreturn { | |
"pending" = loc.pending, | |
"approved" = loc.approved, | |
"declined" = loc.declined, | |
"blacklisted" = loc.blacklisted | |
}> | |
</cffunction> | |
<cffunction name="AddApplication" access="public" returntype="string"> | |
<cfargument name="args" type="struct" required="yes"> | |
<cfset var loc = {}> | |
<cfset loc.token = CreateUUID()> | |
<cfset loc.pubtoken = CreateUUID()> | |
<cfquery name="loc.addApp" datasource="#GetDatasource()#" result="loc.addApp_result"> | |
INSERT INTO apps ( | |
appIP, | |
appName, | |
appAge, | |
appCountry, | |
appEmail, | |
appSteam, | |
appAvailable, | |
appExperience, | |
appGroups, | |
appApex, | |
appBio, | |
appToken, | |
appPublicToken, | |
appSource<cfif Len(args.sourceData)>, | |
appSourceData</cfif> | |
) VALUES ( | |
'#args.ip#', | |
<cfqueryparam value="#args.userName#" cfsqltype="cf_sql_varchar">, | |
<cfqueryparam value="#args.userAge#" cfsqltype="cf_sql_varchar">, | |
<cfqueryparam value="#args.country#" cfsqltype="cf_sql_varchar">, | |
<cfqueryparam value="#args.emailAddress#" cfsqltype="cf_sql_varchar">, | |
<cfqueryparam value="#args.steamAccount#" cfsqltype="cf_sql_varchar">, | |
<cfqueryparam value="#args.available#" cfsqltype="cf_sql_varchar">, | |
<cfqueryparam value="#ParagraphFormat(args.armaExperience)#" cfsqltype="CF_SQL_LONGVARCHAR">, | |
<cfqueryparam value="#args.otherGroups#" cfsqltype="cf_sql_varchar">, | |
<cfqueryparam value="#args.apex#" cfsqltype="cf_sql_varchar">, | |
<cfqueryparam value="#ParagraphFormat(args.bio)#" cfsqltype="CF_SQL_LONGVARCHAR">, | |
'#loc.token#', | |
'#loc.pubtoken#', | |
<cfqueryparam value="#LoadSource(args.source).srcID#" cfsqltype="cf_sql_varchar"><cfif Len(args.sourceData)>, | |
<cfqueryparam value="#args.sourceData#" cfsqltype="cf_sql_varchar"></cfif> | |
) | |
</cfquery> | |
<cfset loc.approvedPreset = LoadEmailPreset(10)> | |
<cfmail | |
from="#application.mail.from#" | |
to="#args.emailAddress#" | |
password="#application.mail.password#" | |
server="#application.mail.server#" | |
subject="[ARCOMM] #loc.approvedPreset.epSubject#" | |
username="#application.mail.username#" | |
type="html"> | |
<cfoutput> | |
#loc.approvedPreset.epContent# | |
</cfoutput> | |
</cfmail> | |
<cfset AddEmailToApp({ | |
appID = loc.addApp_result.generatedKey, | |
subject = "#loc.approvedPreset.epSubject#", | |
content = "#loc.approvedPreset.epContent#" | |
})> | |
<cfreturn loc.token> | |
</cffunction> | |
<cffunction name="LoadNav" access="public" returntype="array"> | |
<cfset var loc = {}> | |
<cfset loc.result = []> | |
<cfquery name="loc.nav" datasource="#GetDatasource()#"> | |
SELECT * | |
FROM nav | |
</cfquery> | |
<cfloop query="loc.nav"> | |
<cfset loc.header = {}> | |
<cfset loc.header.id = navID> | |
<cfset loc.header.title = navTitle> | |
<cfquery name="loc.items" datasource="#GetDatasource()#"> | |
SELECT navItems.*, pages.* | |
FROM navItems, pages | |
WHERE niNav = #val(loc.header.id)# | |
AND niPage = pgID | |
AND pgActive = 'Yes' | |
ORDER BY niOrder ASC | |
</cfquery> | |
<cfset loc.header.items = QueryToArrayOfStruct(loc.items)> | |
<cfset ArrayAppend(loc.result, loc.header)> | |
</cfloop> | |
<cfreturn loc.result> | |
</cffunction> | |
<cffunction name="LoadPage" access="public" returntype="struct"> | |
<cfargument name="pageUrl" type="string" required="yes"> | |
<cfset var loc = {}> | |
<cfquery name="loc.page" datasource="#GetDatasource()#"> | |
SELECT * | |
FROM pages | |
WHERE pgUrl = <cfqueryparam value="#arguments.pageUrl#" cfsqltype="cf_sql_varchar"> | |
AND pgActive = 'Yes' | |
AND pgLevel >= <cfqueryparam value="#session.visitor.user.level#" cfsqltype="cf_sql_integer"> | |
</cfquery> | |
<cfif loc.page.recordcount gt 0> | |
<cfobject component="code/steam" name="loc.steam"> | |
<cfif loc.page.pgMemberOnly AND NOT loc.steam.IsUserInGroup()> | |
<cflocation url="#request.url#" addtoken="no"> | |
<cfreturn {}> | |
<cfelse> | |
<cfreturn QueryToStruct(loc.page)> | |
</cfif> | |
<cfelse> | |
<cflocation url="#request.url#" addtoken="no"> | |
<cfreturn {}> | |
</cfif> | |
</cffunction> | |
<cffunction name="QueryToStruct" access="public" returntype="struct"> | |
<cfargument name="queryname" type="query" required="yes"> | |
<cfset var loc = {}> | |
<cfset loc.qStruct = {}> | |
<cfset loc.columns = queryname.columnlist> | |
<cfloop query="queryname"> | |
<cfset loc.qStruct = {}> | |
<cfloop list="#loc.columns#" index="colName"> | |
<cfset StructInsert(loc.qStruct, colName, StructFind(queryname, colName))> | |
</cfloop> | |
</cfloop> | |
<cfreturn loc.qStruct> | |
</cffunction> | |
<cffunction name="QueryToArrayOfStruct" access="public" returntype="array"> | |
<cfargument name="queryname" type="query" required="yes"> | |
<cfset var loc = {}> | |
<cfset loc.qArray = []> | |
<cfset loc.columns = queryname.columnlist> | |
<cfloop query="queryname"> | |
<cfset loc.qStruct = {}> | |
<cfloop list="#loc.columns#" index="colName"> | |
<cfset loc.fndValue = StructFind(queryname,colName)> | |
<cfset StructInsert(loc.qStruct, colName, loc.fndValue)> | |
</cfloop> | |
<cfset ArrayAppend(loc.qArray, StructCopy(loc.qStruct))> | |
</cfloop> | |
<cfreturn loc.qArray> | |
</cffunction> | |
<cffunction name="VerifyEncryptedString" access="public" returntype="boolean"> | |
<cfargument name="stringToTest" type="string" required="yes"> | |
<cfargument name="originalString" type="binary" required="yes"> | |
<cfset var loc = {}> | |
<cfquery name="loc.Encrypt" datasource="#GetDatasource()#"> | |
SELECT (DES_ENCRYPT("#stringToTest#")) AS EncryptedString | |
</cfquery> | |
<cfif toString(loc.Encrypt.EncryptedString) eq toString(originalString)> | |
<cfreturn true> | |
<cfelse> | |
<cfreturn false> | |
</cfif> | |
</cffunction> | |
<cffunction name="GetDatasource" access="public" returntype="any"> | |
<cfreturn application.site.datasource> | |
</cffunction> | |
<cffunction name="ConvertXmlToStruct" access="public" returntype="struct" output="true" | |
hint="Parse raw XML response body into ColdFusion structs and arrays and return it."> | |
<cfargument name="xmlNode" type="string" required="true" /> | |
<cfargument name="str" type="struct" required="true" /> | |
<!---Setup local variables for recurse: ---> | |
<cfset var i = 0 /> | |
<cfset var axml = arguments.xmlNode /> | |
<cfset var astr = arguments.str /> | |
<cfset var n = "" /> | |
<cfset var tmpContainer = "" /> | |
<cfset axml = XmlSearch(XmlParse(arguments.xmlNode),"/node()")> | |
<cfset axml = axml[1] /> | |
<!--- For each children of context node: ---> | |
<cfloop from="1" to="#arrayLen(axml.XmlChildren)#" index="i"> | |
<!--- Read XML node name without namespace: ---> | |
<cfset n = replace(axml.XmlChildren[i].XmlName, axml.XmlChildren[i].XmlNsPrefix&":", "") /> | |
<!--- If key with that name exists within output struct ... ---> | |
<cfif structKeyExists(astr, n)> | |
<!--- ... and is not an array... ---> | |
<cfif not isArray(astr[n])> | |
<!--- ... get this item into temp variable, ... ---> | |
<cfset tmpContainer = astr[n] /> | |
<!--- ... setup array for this item beacuse we have multiple items with same name, ... ---> | |
<cfset astr[n] = arrayNew(1) /> | |
<!--- ... and reassing temp item as a first element of new array: ---> | |
<cfset astr[n][1] = tmpContainer /> | |
<cfelse> | |
<!--- Item is already an array: ---> | |
</cfif> | |
<cfif arrayLen(axml.XmlChildren[i].XmlChildren) gt 0> | |
<!--- recurse call: get complex item: ---> | |
<cfset astr[n][arrayLen(astr[n])+1] = ConvertXmlToStruct(axml.XmlChildren[i], structNew()) /> | |
<cfelse> | |
<!--- else: assign node value as last element of array: ---> | |
<cfset astr[n][arrayLen(astr[n])+1] = axml.XmlChildren[i].XmlText /> | |
</cfif> | |
<cfelse> | |
<!--- | |
This is not a struct. This may be first tag with some name. | |
This may also be one and only tag with this name. | |
---> | |
<!--- | |
If context child node has child nodes (which means it will be complex type): ---> | |
<cfif arrayLen(axml.XmlChildren[i].XmlChildren) gt 0> | |
<!--- recurse call: get complex item: ---> | |
<cfset astr[n] = ConvertXmlToStruct(axml.XmlChildren[i], structNew()) /> | |
<cfelse> | |
<cfif IsStruct(aXml.XmlAttributes) AND StructCount(aXml.XmlAttributes)> | |
<cfset at_list = StructKeyList(aXml.XmlAttributes)> | |
<cfloop from="1" to="#listLen(at_list)#" index="atr"> | |
<cfif ListgetAt(at_list,atr) CONTAINS "xmlns:"> | |
<!--- remove any namespace attributes---> | |
<cfset Structdelete(axml.XmlAttributes, listgetAt(at_list,atr))> | |
</cfif> | |
</cfloop> | |
<!--- if there are any atributes left, append them to the response---> | |
<cfif StructCount(axml.XmlAttributes) GT 0> | |
<cfset astr['_attributes'] = axml.XmlAttributes /> | |
</cfif> | |
</cfif> | |
<!--- else: assign node value as last element of array: ---> | |
<!--- if there are any attributes on this element---> | |
<cfif IsStruct(aXml.XmlChildren[i].XmlAttributes) AND StructCount(aXml.XmlChildren[i].XmlAttributes) GT 0> | |
<!--- assign the text ---> | |
<cfset astr[n] = axml.XmlChildren[i].XmlText /> | |
<!--- check if there are no attributes with xmlns: , we dont want namespaces to be in the response---> | |
<cfset attrib_list = StructKeylist(axml.XmlChildren[i].XmlAttributes) /> | |
<cfloop from="1" to="#listLen(attrib_list)#" index="attrib"> | |
<cfif ListgetAt(attrib_list,attrib) CONTAINS "xmlns:"> | |
<!--- remove any namespace attributes---> | |
<cfset Structdelete(axml.XmlChildren[i].XmlAttributes, listgetAt(attrib_list,attrib))> | |
</cfif> | |
</cfloop> | |
<!--- if there are any atributes left, append them to the response---> | |
<cfif StructCount(axml.XmlChildren[i].XmlAttributes) GT 0> | |
<cfset astr[n&'_attributes'] = axml.XmlChildren[i].XmlAttributes /> | |
</cfif> | |
<cfelse> | |
<cfset astr[n] = axml.XmlChildren[i].XmlText /> | |
</cfif> | |
</cfif> | |
</cfif> | |
</cfloop> | |
<!--- return struct: ---> | |
<cfreturn astr /> | |
</cffunction> | |
<cffunction name="CalculateEasyDateTime" access="public" returntype="string"> | |
<cfargument name="testDateTime" type="string" required="yes"> | |
<cfset var result="Just now"> | |
<cfset var currentDateTime=now()> | |
<cfset var difference=DateDiff("s", testDateTime, currentDateTime)> | |
<cfif difference gt 0> | |
<cfset result="Just now"> | |
</cfif> | |
<cfif difference gt 1> | |
<cfset result="1 second ago"> | |
</cfif> | |
<!---SECONDS---> | |
<cfif difference gte 2 and difference lte 59> | |
<cfset result="#difference# seconds ago"> | |
</cfif> | |
<!---MINUTES---> | |
<cfif difference gte 60> | |
<cfset result="1 minute ago"> | |
</cfif> | |
<cfif difference gte 120 and difference lte 3599> | |
<cfset result="#NumberFormat(difference/60)# minutes ago"> | |
</cfif> | |
<!---HOURS---> | |
<cfif difference gte 3600> | |
<cfset result="1 hour ago"> | |
</cfif> | |
<cfif difference gte 7200 and difference lte 86399> | |
<cfset result="#NumberFormat(difference/3600)# hours ago"> | |
</cfif> | |
<!---DAYS---> | |
<cfif difference gte 86400> | |
<cfset result="1 day ago"> | |
</cfif> | |
<cfif difference gte 172800 and difference lte 604799> | |
<cfset result="#NumberFormat(difference/86400)# days ago"> | |
</cfif> | |
<!---WEEKS---> | |
<cfif difference gte 604800> | |
<cfset result="1 week ago"> | |
</cfif> | |
<cfif difference gte 1209600 and difference lte 2419199> | |
<cfset result="#NumberFormat(difference/604800)# weeks ago"> | |
</cfif> | |
<!---TOO LONG---> | |
<cfif difference gte 2419200> | |
<cfset result="#DateFormat(testDateTime, 'd mmm YYYY')#"> | |
</cfif> | |
<cfreturn result> | |
</cffunction> | |
</cfcomponent> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment