Internationalized in CFMX

Folks,.. As you know, getprofilestring doesn't support unicode format. That's why we don't have to create our projects for multi-language. Because, I'm doing project for Vietnamese, which is unicode format. That's why I need to solve this problem. I stuck on this solution for 5 hours. Finally, I gotcha..!!

You can use my coding, but please don't forget to credit to me.

udf_Translate.cfm

view plain print about
1<cfscript>
2function udf_Translate(Name, Filename) {
3infile = FileOpen(Filename, "read", "UTF-8");
4i = 0;
5flag = 0;
6while (! FileIsEOF(infile)) {
7i++;
8x = FileReadLine(infile);
9Org = trim(listFirst(x,"="));
10Lang = trim(listRest(x,"="));
11MyArray.array[i][1] = Org;
12MyArray.array[i][2] = Lang;
13if (MyArray.array[i][1] == Name)
14{
15WriteOutput(MyArray.array[i][2]);
16flag = 1;
17}
18}
19if (flag == 0) WriteOutput(Name);
20FileClose(infile);
21MyArray = StructNew();
22MyArray.array = ArrayNew(2);
23}
24
</cfscript>

Client.cfm

view plain print about
1<cfoutput>
2    #udf_translate("User Name", "D:\GREEK.properties"")#
3</cfoutput>

How? It's easy, isn't it?

Coldfusion Force Download

Don't you wanna display image file on client browsers when users downloading? It's kinda simple, use following code :

 

view plain print about
1<cfheader name="Content-Type" value="unknown">
2<cfheader name="Content-Disposition" value="attachment; filename=FileName.jpg">
3<cfcontent type="Application/Unknown" file="http://downloads/FileName.jpg" deletefile="No">

Site Encryption with CFML

You're so far to use command prompt for encrypting CFML files? Here is tutorial for you to encrypt with CFM file. Here you go..

view plain print about
1<cfparam name="encryptFile" default="">
2<!---
3The purpose of this file is to provide a method to recursively encrypt all ColdFusion files with a folder.
4The script first goes through all the folders starting from a set point and builds up a query of all the folders and file locations
5Finally it will either encrypt the file, or copy it if it is a non-cfm file, to a new location.
6
7CAVEAT:
8There does appear to be a bug in CF MX6.1 when using a combination of the version number in cfencode and stating a header in the command line.
9Basically if you want a header in the encrypted file you must use v1 encrypting otherwise use v2
10--->

11
12<!---set the root folder for the site you want to encrypt--->
13<cfset startDir="D:\sites\pathtosite">
14<!---set a root folder for where you want to save the encrypted/non-encrypted files--->
15<cfset newDir="D:\sites\pathtoencrypted site">
16<!---set the cfm file type (cfm or cfml)--->
17<cfset fileExt="cfm">
18<!---set the path to the cfencode.exe file--->
19<cfset pathtoexe="c:\cfusionmx\bin\cfencode.exe">
20<!---set the cfencode version--->
21<cfset encVer="2">
22<!---if you set the encVer to 1 you can set a header (see caveat above)--->
23<cfset encHeader="This file has been encrypted. Unauthorised decryption attempts strictly forbidden">
24
25<!---
26Mimics the cfdirectory, action=&amp;quot;list&amp;quot; command.
27Updated with final CFMX var code.
28Fixed a bug where the filter wouldn't show dirs.
29
30@param directory      The directory to list. (Required)
31@param filter      Optional filter to apply. (Optional)
32@param sort      Sort to apply. (Optional)
33@param recurse      Recursive directory list. Defaults to false. (Optional)
34@return Returns a query.
35@author Raymond Camden (ray@camdenfamily.com)
36@version 2, April 8, 2004
37@modified by Philip Williams (contact@openmindedsolutions.co.uk)
38@version 2.1, May 3rd 2006
39<strong>
40Revisions:
41</strong> Removed extraneous information for the directory query
42--->

43<cffunction name="directoryList" output="false" returnType="query">
44<cfargument name="directory" type="string" required="true">
45<cfargument name="filter" type="string" required="false" default="">
46<cfargument name="sort" type="string" required="false" default="">
47<cfargument name="recurse" type="boolean" required="false" default="true">
48<!--- temp vars --->
49<cfargument name="dirInfo" type="query" required="false">
50<cfargument name="thisDir" type="query" required="false">
51<cfset var path="">
52<cfset var temp="">
53
54<cfif not recurse>
55<cfdirectory name="temp" directory="#directory#" filter="#filter#" sort="#sort#">
56<cfreturn temp>
57<cfelse>
58<!--- We loop through until done recursing drive --->
59<cfif not isDefined("dirInfo")>
60<cfset dirInfo = queryNew("name,type,directory")>
61</cfif>
62
63<cfset thisDir = directoryList(directory,filter,sort,false)>
64<cfif server.os.name contains "Windows">
65<cfset path = "\">
66<cfelse>
67<cfset path = "/">
68</cfif>
69<cfloop query="thisDir">
70<cfset queryAddRow(dirInfo)>
71<cfset querySetCell(dirInfo,"name",name)>
72<cfset querySetCell(dirInfo,"type",type)>
73<cfset querySetCell(dirInfo,"directory",directory)>
74<cfif type is "dir">
75<!--- go deep! --->
76<cfset directoryList(directory &amp; path &amp; name,filter,sort,true,dirInfo)>
77</cfif>
78</cfloop>
79<cfreturn dirInfo>
80</cfif>
81</cffunction>
82<!---ceate the dirList query--->
83<cfscript>
84dirList = directoryList("#startDir#","","name desc");
85
</cfscript>
86<cfoutput query="dirList">
87<cfset currFold=directory>
88<cfset newFold=ReplaceNocase(directory, startDir, newDir)>
89currfold:#currfold#
90newfold:#newfold#
91<!---if the new directory does not exist, we create it--->
92<cftry>
93<cfdirectory action="create" directory="#newFold#">
94newfold created
95<cfcatch>newfold exists<!---do nothing as the folder exists---></cfcatch>
96</cftry>
97<!---if the file is a cfm file then we encode it here--->
98<cfif type EQ "file" AND ListLast(name, '.') EQ "#fileExt#">
99<cfset inputFile="#currFold#\#name#">
100<cfset outputFile="#newFold#\#name#">
101#inputfile#
102#outputfile#
103<!---dependent on the encryption version, we set the command line arguments--->
104<cfswitch expression="#encVer#">
105<cfcase value="1">
106<cfscript>
107ArgumentLine=inputFile;
108ArgumentLine=ArgumentLine&amp;" ";
109ArgumentLine=ArgumentLine&amp;outputFile;
110ArgumentLine=ArgumentLine&amp;" ";
111ArgumentLine=ArgumentLine&amp;" /q /h ";
112ArgumentLine=ArgumentLine&amp;chr(34);
113ArgumentLine=ArgumentLine&amp;encHeader;
114ArgumentLine=ArgumentLine&amp;chr(34);
115ArgumentLine=ArgumentLine&amp;" ";
116ArgumentLine=ArgumentLine&amp;" /v 1";
117
</cfscript>
118</cfcase>
119<cfcase value="2">
120<cfscript>
121ArgumentLine=inputFile;
122ArgumentLine=ArgumentLine&amp;" ";
123ArgumentLine=ArgumentLine&amp;outputFile;
124ArgumentLine=ArgumentLine&amp;" ";
125ArgumentLine=ArgumentLine&amp;" /q /v 2";
126
</cfscript>
127</cfcase>
128</cfswitch>
129argumentline:#argumentline#
130<cfexecute
131name="#PathToExe#"
132arguments="#argumentLine#"
133timeout="10">

134</cfexecute>
135encrypt complete
136<!---the file is not a cfm file so we just copy it to the new location--->
137<cfelseif type EQ "file" AND ListLast(name, '.') NEQ "#fileExt#">
138<cftry>
139<cffile action="copy" source="#currFold#\#name#" destination="#newFold#\#name#">
140copy:#currFold#\#name#
141<cfcatch>nocopy:#currFold#\#name#<!---do nothing, file already exists---></cfcatch>
142</cftry>
143<cfelse>
144</cfif>
145
146</cfoutput>
Site encryption complete!

Integrate Crystal Reports into CFreport

Wanna reduce server load cos of reporting so many data? Getting sick of designing HTML coding for report? You don't need to worry of above 2 questions. CFreport is there for you to fulfill your desire.

First of all, you need to draw your report in crystal report on-click action. Then, save these report. Here you need to embed this report in CFML.

view plain print about
1<CFREPORT REPORT="myreport.rpt"></CFREPORT>

Wanna to pass parameters into this crystal reports? Here you go:

view plain print about
1<CFREPORT REPORT="myreport.rpt">
2{Table_name.field_name} = "ppshein"
3</CFREPORT>

CFML integrate with Facebook

Last weekend, I've spent most of my time by researching how to integrate facebook with CFML. That's why, I kept searching ideas and technology around blogs and forums. At that time, I saw Raymond Camden's work in Adobe, featuring about how to create simple application in facebook with Coldfusion. So, I kept reading his tutorial and explanation and created simple news application by myself.

Here you go :

http://apps.facebook.com/planetnews/

my Creation

When I started working in Singapore, I was about to manipulate cfchart and jQuery. Cos of that, I've got a lot of new knowledge and experiences on it. That's why I'm proud of myself that I can do so. I've created these four features what I created for my job.

setInterval Javascript

Like gmail, you can use auto fresh your page with setInterval funtion of javascript.

view plain print about
1intervalID = window.setInterval("alert('Hi')", 1000)

Check mouse pointer location

Do you want to check your mouse pointer location? It's kinda simple. Check it out.

 

view plain print about
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2<html>
3<head>
4<title>Browser Coordinate Computation Demo</title>
5<invalidTag type="text/javascript">
6function move(e)
7{
8if (!e) e= event;
9var docX,docY;
10
11if (e.pageX == null)
12{
13// IE case
14var d= (document.documentElement &amp;&amp;
15document.documentElement.scrollLeft != null) ?
16document.documentElement : document.body;
17docX= e.clientX + d.scrollLeft;
18docY= e.clientY + d.scrollTop;
19}
20else
21{
22// all other browsers
23docX= e.pageX;
24docY= e.pageY;
25}
26
27var coord= document.getElementById('coord');
28while (coord.firstChild) coord.removeChild(coord.firstChild);
29coord.appendChild(document.createTextNode(docX+', 1, '+docY));
30
31var xhair= document.getElementById('crosshair');
32xhair.style.left= docX-8+'px';
33xhair.style.top= docY-8+'px';
34
35return false;
36}
37
38if (document.addEventListener)
39{
40document.addEventListener("mousedown",move, false);
41}
42else if (document.attachEvent)
43{
44document.attachEvent("onmousedown",move);
45}
46</script>
47</head>
48<body>
49<h3>Click to Move Crosshairs</h3>
50Shrink screen so you can get scroll bars and test this in a scrolled window.
51<p>
52X,Y=(<span id="coord">?,?</span>);
53<img id="crosshair" src="crosshair.gif" style="position: absolute; left: 90px; top: 150px">
54
55<p>&amp;nbsp; <p>&amp;nbsp; <p>&amp;nbsp; <p>&amp;nbsp;<p>
56<pre>
57if (e.pageX == null)
58{
59// IE case
60var d= (document.documentElement &amp;&amp;
61document.documentElement.scrollLeft != null) ?
62document.documentElement : document.body;
63docX= e.clientX + d.scrollLeft;
64docY= e.clientY + d.scrollTop;
65}
66else
67{
68// all other browsers
69docX= e.pageX;
70docY= e.pageY;
71}
72</pre>
73</body>
74</html>

 

Best credit : http://unixpapa.com/js/mouse.html

 

Compress Javascript coding

As we all know, some javascript file is messy coding and let us not to change or edit their coding. Because, the owner compressed his/her file. The best way of compressing javascript file led to reduce file size. If you want to compress your javascript file, here you go : http://jscompress.com

Increase and decrease count by clicking with Javascript

Today, my supervisor wants me to do simple javascript program. It seems, it's kinda simple but complicated when I implement it. This program is, to increase or decrease count by clicking on button. I took 1 hour to implement this program. Voilà..!!

view plain print about
1<form name="myform">
2<input type="Hidden" name="init" value="3">
3<input type="Button" name="actoin" value="+" onclick="increase()">
4<input type="Button" name="actoin" value="-" onclick="decrease()">
5</form>
6
7<invalidTag>
8<!--
9var x = document.myform.init.value;
10
11function increase()
12{
13x++;
14document.getElementById("mynumber").innerHTML = x;
15}
16
17function decrease()
18{
19x--;
20document.getElementById("mynumber").innerHTML = x;
21}
22-->

23</script>
24
25<p id="mynumber">3</p>

Top of Page