11. September 2009 17:13 by Markus Wollny

ColdFusion UDF to test if a Java Class implements a method

11
Sep/09
0

I recently started implementing a couple of our full text search requirements using Sphinx. I am extremely happy with this search engine, as it’s lightning fast and provides some quite easy integration with the data we store in our PostgreSQL databases, is highly scalable and fairly easy to implement in ColdFusion via the Sphinx Client API. 

4. September 2009 11:59 by Markus Wollny

UDF to grab a frame from an FLV to JPG

4
Sep/09
0

This requires FFMPEG to be installed on your server. Here’s the UDF:

<cffunction name="flvgrabber" access="public" output="no" returntype="void" hint="grabs a frame from an FLV at a specified second and renders it as a JPG">
	<cfargument name="strPathToFLV" type="string" required="yes" hint="absolute path to the source flv">
	<cfargument name="strPathToJPG" type="string" required="yes" hint="absolute path to the target JPG; if file exists and is writeable, it will be overwritten">
	<cfargument name="strFrameAtTime" type="string" required="no" default="00:00:05" hint="time at which frame should be grabbed in format hh:mm:ss">
	<cfscript>
		var strTMPPath = '/tmp/';
		var strUniqueFname = CreateUUID();
		var strPathToFFMPEG = '/usr/bin/ffmpeg';
		var strArguments = '';
		var qTempFile = '';
	</cfscript>
 
	<cfif not DirectoryExists(getDirectoryFromPath(arguments.strPathToJPG))>
		<cfthrow message="target directory does not exist">
	</cfif>
	<cfif not FileExists(arguments.strPathToFLV)>
		<cfthrow message="source FLV does not exist">
	</cfif>
	<cfif not RefindNoCase('\.flv$',arguments.strPathToFLV)>
		<cfthrow message="source file must be an .flv">
	</cfif>
	<cfif not RefindNoCase('\.jpg$',arguments.strPathToJPG)>
		<cfthrow message="target file must be a .jpg">
	</cfif>		
	<cfif not RefindNoCase('^\d\d:\d\d:\d\d$',arguments.strFrameAtTime)>
		<cfthrow message="time must be set as hh:mm:ss">
	</cfif>
	<cfset strArguments = "-i ""#arguments.strPathToFLV#"" -an -ss #arguments.strFrameAtTime# -an -r 1 -vframes 1 -y #strTMPPath##strUniqueFname#-%d.jpg">		
 
	<cfexecute name="#strPathToFFMPEG#" arguments="#strArguments#" timeout="30"></cfexecute>
	<cfdirectory name="qTempFile" action="list" directory="#strTMPPath#" filter="#strUniqueFname#-*.jpg" listinfo="name" recurse="no" type="file">
	<cffile action="move" source="#strTMPPath##qTempFile.name#" destination="#arguments.strPathToJPG#">		
</cffunction>

And here’s how to use it:

<cfscript>
flvgrabber(strPathToFLV='/some/path/some.flv',strPathToJPG='/some/path/some.jpg',strFrameAtTime='00:00:03');
</cfscript>

Have fun!

Tagged as: , , , ,
21. July 2009 14:06 by Markus Wollny

UDF to strip certain chars, but leave UBB tags alone

21
Jul/09
1

We are developing a commenting system which is supposed to discourage comment spam by making comments more or less unreadable when they crossed a certain threshold of negative ratings. We decided that we’d like to strip all vowels from the text, though we’d like to keep the UBB-style tags inside the comment unchanged.
You’ll find that this last bit makes the whole task a little more complicated than just a simple Regex-Replace. We’ll need to use a negative lookbehind, then mark the characters we do not wish to strip, then remove any “unmarked” characters and finally remove our marker.

15. June 2009 9:57 by Markus Wollny

ColdFusion-UDF Wrapper for JTidy to clean up HTML

15
Jun/09
17

JTidy is a Java port of HTML Tidy, which allows you to clean up messy HTML. This comes in useful when you need to output some Code which has been created by users. I’ll show in some later post how to allow users to actually enter HTML without compromising the security of your site, today I’ll just show how to clean up this user-generated code. JTidy will not only generate XHTML-valid code from incomplete code by correctly closing opened tags, it will also do a couple of “prettifying” operations to increase quality of the result.