Skip to content

Instantly share code, notes, and snippets.

@bennadel
Created March 25, 2014 12:04
Show Gist options
  • Save bennadel/9760440 to your computer and use it in GitHub Desktop.
Save bennadel/9760440 to your computer and use it in GitHub Desktop.
Building A Branded Jing Image Viewer Using ColdFusion
<!---
Param the incoming URL parameters. These are the properties
that are available in the JING automated code snippet.
NOTE: Rather than waste time computing the image dimensions in
ColdFusion, we're just going to use the values that JING sends
to use. This will remove some headache.
--->
<cfparam name="url.filename" type="string" default="" />
<cfparam name="url.width" type="numeric" default="0" />
<cfparam name="url.height" type="numeric" default="0" />
<!---
Set the root url for the blog - since this is a *branded* JING
page, we will be linked back to the root of the blog when
necessary. Rather than calculating the link each time, just set
it here.
--->
<cfset brandUrl = "http://www.bennadel.com/" />
<!---
Sanitize the file name to make sure that no one is trying
to gain access about the server file system.
--->
<cfset url.filename = getFileFromPath( url.filename ) />
<!---
Check to see if the given file exists. If it doesn't then we
are going to send people back to the blog root.
--->
<cfif !fileExists( expandPath( "./images/#url.filename#" ) )>
<!---
Something went wrong - the file name could not be found.
Relocate the user.
--->
<cflocation
url="#brandUrl#"
addtoken="false"
/>
</cfif>
<!---
ASSERT: If we made it this far then the image exists and can
be displayed for the user.
--->
<!--- Reset the output buffer and set the mime type. --->
<cfcontent type="text/html" />
<cfoutput>
<!DOCTYPE html>
<html>
<head>
<title>The Blog of Ben Nadel</title>
<meta name="description" content="Images uploaded by Ben Nadel." />
<link rel="stylesheet" type="text/css" href="./linked/styles.css"></link>
</head>
<body>
<div class="header">
<a href="#brandUrl#">
The Blog of Ben Nadel - Recent Blog Entries
</a>
</div>
<div class="body">
<div class="content" style="width: #url.width#px ;">
<!--- Output the uploaded image. --->
<img
src="./images/#url.filename#"
width="#url.width#"
height="#url.height#"
/>
</div>
</div>
<div class="footer">
Ben Nadel &copy; #year( now() )#. All content is the property of Ben Nadel and <a href="#brandUrl#">BenNadel.com</a>.
</div>
</body>
</html>
</cfoutput>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment