Skip to content

Commit

Permalink
Tentative 'Version 6' from Scott, possibly the start of a rewrite ini…
Browse files Browse the repository at this point in the history
…tiated by Matt Gifford
  • Loading branch information
seancorfield committed May 28, 2014
1 parent 34470cc commit 29b8fb8
Show file tree
Hide file tree
Showing 28 changed files with 4,281 additions and 0 deletions.
90 changes: 90 additions & 0 deletions blogCFC6/Application.cfc
@@ -0,0 +1,90 @@
<cfcomponent output="false">

<cfset this.name = "Utopia" & right(reReplace(hash(getCurrentTemplatePath()),"[^a-zA-Z0-9]","","all"),50)>

<cfset this.applicationTimeout = createTimeSpan(0,2,0,0)>
<cfset this.sessionManagement = true>
<cfset this.scriptProtect = false>
<cfset this.mappings["/org"] = getDirectoryFromPath(getCurrentTemplatePath()) & "org">
<cfset this.mappings["/root"] = getDirectoryFromPath(getCurrentTemplatePath())>
<cfset this.customtagpaths = getDirectoryFromPath(getCurrentTemplatePath()) & "tags">

<cffunction name="loadSettings" returnType="struct" output="false">
<cfset var settings = "">
<cfset var settingsxml = "">
<cfset var myxmlfile = "">
<cfset var setting = "">
<cfset var result = structNew()>
<cfset var getSettings = "">
<cfset var col = "">

<!--- todo: are we overwriting at runtime? --->
<!--- what is my setting file? --->
<cfset myxmlfile = expandPath("./settings.xml.cfm")>

<!--- read it in --->
<cffile action="read" file="#myxmlfile#" variable="settings">

<!--- remove comments --->
<cfset settings = replace(settings, "<!---","")>
<cfset settings = trim(replace(settings, "--->",""))>

<!--- parse to xml --->
<cfset settingsxml = xmlParse(settings)>
<cfloop item="setting" collection="#settingsxml.settings#">
<!--- for now we assume simple strings, todo: support complex --->
<cfset result[setting] = settingsxml.settings[setting].xmltext>
</cfloop>

<!--- get root folder --->
<cfset result.rootfolder = getDirectoryFromPath(getCurrentTemplatePath())>

<!--- Some defaults for virgin installs --->
<cfif not structKeyExists(result, "reloadKey")>
<cfset result.reloadkey = "init">
</cfif>

<!--- This is where we hit the DB for it's settings - To Be Done Better --->
<cfquery name="getSettings" datasource="#result.dsn#" username="#result.username#" password="#result.password#">
select *
from tblblogsettings
where blog = <cfqueryparam cfsqltype="cf_sql_varchar" maxlength="255" value="#result.blog#">
</cfquery>
<cfloop index="col" list="#getSettings.columnList#">
<cfset result[col] = getSettings[col][1]>
</cfloop>

<cfreturn result>
</cffunction>

<cffunction name="onApplicationStart" returnType="boolean" output="false">
<cfset application.settings = loadSettings()>

<!--- begin to load components --->
<cfset application.factory = createObject("component", "org.camden.blog.factory").init(application.settings)>
<cfset application.entryService = application.factory.get("entryService")>
<cfset application.themeService = application.factory.get("themeService")>
<cfset application.pageService = application.factory.get("page")>

<cfreturn true>
</cffunction>

<cffunction name="onRequestStart" returnType="boolean" output="false">
<cfargument name="thePage" type="string" required="true">

<cfif structKeyExists(url, application.settings.reloadkey) or 1>
<cfset onApplicationStart()>
</cfif>
<cfreturn true>
</cffunction>

<cffunction name="onError" returnType="void" output="false">
<cfargument name="exception" required="true">
<cfargument name="eventname" type="string" required="true">
<cfdump var="#arguments#"><cfabort>
</cffunction>

<cffunction name="onSessionStart" returnType="void" output="false">
</cffunction>

</cfcomponent>
52 changes: 52 additions & 0 deletions blogCFC6/index.cfm
@@ -0,0 +1,52 @@

<!--- Logic here determines what we are doing - getting entries, a entry, page, etc --->
<cf_getmode r_params="params">

<cfif not structKeyExists(params, "byalias")>

<cfset entryData = application.entryService.getEntries(params)>
<cfset previousLink = "">
<cfset nextLink = "">

<cfif (url.startRow gt 1) or (entryData.totalEntries gte url.startRow + application.settings.maxEntries)>

<!--- get path if not /index.cfm --->
<cfset path = rereplace(cgi.path_info, "(.*?)/index.cfm", "")>

<!--- clean out startrow from query string --->
<cfset qs = cgi.query_string>
<!--- handle: http://www.coldfusionjedi.com/forums/messages.cfm?threadid=4DF1ED1F-19B9-E658-9D12DBFBCA680CC6 --->
<cfset qs = reReplace(qs, "<.*?>", "", "all")>
<cfset qs = reReplace(qs, "[\<\>]", "", "all")>

<cfset qs = reReplaceNoCase(qs, "&*startrow=[\-0-9]+", "")>
<cfif isDefined("form.search") and len(trim(form.search)) and not structKeyExists(url, "search")>
<cfset qs = qs & "&amp;search=#htmlEditFormat(form.search)#">
</cfif>

<cfif url.startRow gt 1>

<cfset prevqs = qs & "&amp;startRow=" & (url.startRow - application.settings..maxEntries)>
<cfset previousLink = "#application.settings.blogurl#/#path#?#prevqs#">

</cfif>

<cfif entryData.totalEntries gte url.startRow + application.settings.maxEntries>

<cfset nextqs = qs & "&amp;startRow=" & (url.startRow + application.settings.maxEntries)>
<cfset nextLink = "#application.settings.blogurl#/#path#?#nextqs#">
</cfif>

</cfif>
<cfset content = application.themeService.renderEntries(entryData,params.startrow,previousLink,nextLink)>

<cfelse>

<cfset entryData = application.entryService.getEntries(params)>
<cfset content = application.themeService.renderEntry(entryData)>

</cfif>

<cfset title = application.settings.blogtitle>

<cfoutput>#application.themeService.renderLayout(title,content)#</cfoutput>

3 comments on commit 29b8fb8

@busches
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be a branch instead of a folder? Don't want to end up with Mach II's awkward repo structure.

@seancorfield
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I said on the mailing list, it's not clear yet whether this really is a replacement or an add-on. I don't know whether it has an admin, for example. So it's better to have it alongside the full V5 code so we can look at what functionality is present and what is missing and decide how to move forward. It may ultimately replace some of the V5 code, in which case it can do so on a branch. I don't anticipate the "V6" folder staying around for long once we have a test suite and start to move the core code forward.

@busches
Copy link

@busches busches commented on 29b8fb8 May 29, 2014 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.