Blog CFC customization

I don’t know if any of you have used Blog CFC but it’s a great little app. I have been implementing it into our CMS. I have found a few problems with it though, for example if you want the admin completely seperate in a different folder structure it’s very hard to get the links to work.
I also didnt really like the calendar aspect of the tool so I have written my own “pod” for just showing the months and years with posts.

in the blog.cfc i have written the following function:

<cffunction name="getActiveMonths" returnType="query" output="false" hint="Returns a query of months and years with Entries.">
  <cfargument name=”year” type=”numeric” required=”false”>
  
 <cfset var months = “”>
<cfset var posted = “”>  
  <cfif instance.blogDBType is "MSSQL">
   <cfset posted = “dateAdd(hh, #instance.offset#, tblblogentries.posted)”>
  <cfelseif instance.blogDBType is “MSACCESS”>
   <cfset posted = “dateAdd(’h', #instance.offset#, tblblogentries.posted)”>
  <cfelseif instance.blogDBType is “MYSQL”>
   <cfset posted = “date_add(posted, interval #instance.offset# hour)”>
  <cfelseif instance.blogDBType is “ORACLE”>
   <cfset posted = “tblblogentries.posted + (#instance.offset#/24)”>
  </cfif>    
  
  <cfquery datasource=”#instance.dsn#” name=”months” username=”#instance.username#” password=”#instance.password#”>
   select distinct
    <cfif instance.blogDBType is “MSSQL”>
     datepart(mm, #preserveSingleQuotes(posted)#)
    <cfelseif instance.blogDBType is “MYSQL”>
     extract(month from #preserveSingleQuotes(posted)#)
    <cfelseif instance.blogDBType is “MSACCESS”>
     datepart(’m', #preserveSingleQuotes(posted)#)
    <cfelseif instance.blogDBType is “ORACLE”>
     to_char(#preserveSingleQuotes(posted)#, ‘mm’) 
    </cfif> as posted_month,
    <cfif instance.blogDBType is “MSSQL”>
     datepart(yyyy, #preserveSingleQuotes(posted)#)
    <cfelseif instance.blogDBType is “MYSQL”>
     extract(year from #preserveSingleQuotes(posted)#)
    <cfelseif instance.blogDBType is “MSACCESS”>
     datepart(’y', #preserveSingleQuotes(posted)#)
    <cfelseif instance.blogDBType is “ORACLE”>
     to_char(#preserveSingleQuotes(posted)#, ‘yyyy’) 
    </cfif> as posted_year
   from tblblogentries
   where
    
    blog = <cfqueryparam value=”#instance.name#” cfsqltype=”CF_SQL_VARCHAR” maxlength=”50″>
    and #preserveSingleQuotes(posted)# < <cfqueryparam cfsqltype=”cf_sql_timestamp” value=”#blogNow()#”>
    and released = 1
    ORDER BY posted DESC
  </cfquery> <cfreturn months>

 </cffunction>

Then in the front end in the calendar.cfm pod I commented out the calendar and put in the following code:

<cfscript>
monthsQuery=application.blog.getActiveMonths();
</cfscript>
<ol>
<cfoutput query=”monthsQuery”>
<li><a href=”#application.rooturl##posted_year#/#posted_month#” mce_href=”#application.rooturl##posted_year#/#posted_month#”>#monthAsString(posted_month)# #posted_year#</a></li>
</cfoutput>
</ol>

It seems to work a treat!

July 5, 2007. coldfusion.

No Comments

Be the first to comment!

Leave a Reply

Trackback URI