BlogCFC ColdFish Code Block Print Function Update

Normally I pay quite a bit of attention to my site after I do any major updates or changes but I've been quite a slacker lately and I seemed to have missed a few issues that happened after I updated my blog core ... Bad me.

Something interesting that I truly thought would be an isolated incident - and my problem - actually wasn't. It seems that there was a bug where Gecko based browsers - Firefox - don't seem to like the window.frames[] syntax ... So, for those that are using BlogCFC and want to be able to print code blocks from Firefox ... You may need to update the formatter.cfc with the new syntax ... Here's the link for the formatter.cfc ... on RIAForge ... or you can simply copy the update from here ...

view plain print about
1<!---
2    Copyright 2009 Jason Delmore
3    All rights reserved.
4    jason@cfinsider.com
5    
6    This program is free software: you can redistribute it and/or modify
7    it under the terms of the GNU Lesser General Public License (LGPL) as published by
8    the Free Software Foundation, either version 3 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU Lesser General Public License for more details.
15
16    You should have received a copy of the GNU Lesser General Public License    
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18    --->

19<cfcomponent output="false">
20    <cffunction name="init" access="public" hint="This function initializes all of the variables needed for the component." output="false">
21        <cfscript>
22            //initialize a buffer
23
                
24            // If you're using JDK 1.5 or later and want some extra performance this can be a StringBuilder
25
            //variables.buffer=createObject("java","java.lang.StringBuilder").init();
26
            variables.buffer=createObject("java","java.lang.StringBuffer").init();
27            
28            // initialize private variables
29
            // TODO : Change the parser state to be a struct rather than individual variables.
30
            variables.isCommented=false;
31            variables.isTag=false;
32            variables.isValue=false;
33            variables.isCFSETTag=false;
34            variables.isCFScript=false;
35            variables.isCFQueryTag=false;
36            variables.isOneLineComment=false;
37            variables.isMXML=false;
38            variables.isActionscript=false;
39            variables.isSQL=false;
40            variables.isSQLValue=false;
41            variables.initialparser="";
42            variables.spansOpened = 0;
43            variables.spansClosed = 0;
44        
</cfscript>
45        <cfreturn this/>
46    </cffunction>
47    
48    <cffunction name="getHTMLOutput" access="public" hint="This function accepts a block of code and formats it into syntax highlighted HTML." output="false">
49        <cfargument name="code" type="string"/>
50        <cfargument name="parser" type="string"/>
51        <cfargument name="codesig" type="string"/>
52        <cfscript>
53            var BIstream = createObject("java","java.io.StringBufferInputStream").init(arguments.code);
54            var IStream = createObject("java","java.io.InputStreamReader").init(BIstream);
55            var reader = createObject("java","java.io.BufferedReader").init(IStream);
56            var line = reader.readLine();
57            var linenumber = 0;
58            
59            if (arguments.parser neq ""{
60                "variables.is#arguments.parser#" = true;
61            }
62            
63            if (getConfig().getShowToolbar()) {
64                variables.buffer.append(getToolbarHTML(arguments.code,arguments.codesig));            
65            }
66            
67            variables.buffer.append("<span id='formatted_code_" & arguments.codesig & "' style='" & getStyle("TEXT") & "'>");
68            while isdefinedd("line")) {
69                if (getConfig().getShowLineNumbers()) {
70                    linenumber = linenumber + 1;
71                    variables.buffer.append("<span style='" & getStyle("LINENUMBER") & "'>" & linenumber & "</span>");
72                }
73                formatLine(line);
74                line = reader.readLine();
75            }
76            // there appears to be more spans created than cleaned up... closing up any extras... will need to review to see what is keeping extra spans
77
            while (variables.spansOpened gt variables.spansClosed) {
78                variables.spansClosed = variables.spansClosed + 1;
79                variables.buffer.append("</span>");
80            }
81            variables.buffer.append("</span>");
82            reader.close();
83
84            return variables.buffer;
85        
</cfscript>
86    </cffunction>
87    
88    <cffunction name="getToolbarHTML" access="private" output="true">
89        <cfargument name="code" type="string"/>
90        <cfargument name="codesig" type="string"/>
91        <cfset var toolbarHTML = ""/>
92        <cfsavecontent variable="toolbarHTML">
93            <iframe id='print_frame_#arguments.codesig#' style='display:inline;height:0px;width:0px;' frameborder='0'></iframe>
94            <script type='text/javascript'>
95                function toggle_view_#arguments.codesig#() {
96                    var temp = document.getElementById('htmlencoded_plain_#arguments.codesig#').style.display;
97                    document.getElementById('htmlencoded_plain_#arguments.codesig#').style.display=document.getElementById('formatted_code_#arguments.codesig#').style.display;
98                    document.getElementById('formatted_code_#arguments.codesig#').style.display=temp;
99                    if (temp=='none') {
100                        document.getElementById('view_#arguments.codesig#').innerHTML='view formatted';
101                    } else {
102                        document.getElementById('view_#arguments.codesig#').innerHTML='view plain';
103                    }
104                }
105                function copy_to_clipboard_#arguments.codesig#() {
106                    var code=unescape(document.getElementById('htmlencoded_plain_#arguments.codesig#').innerHTML).replace(/&lt;/g, '\x3C').replace(/&gt;/g, '\x3E').replace(/&amp;/g, '\x26').replace(/\x3Cbr\x3E/gi, '\r\n').replace(new RegExp('&nbsp;&nbsp;&nbsp;&nbsp;', 'gi'), '\t');
107                    window.clipboardData.setData('text',code);
108                }
109                function print_#arguments.codesig#() {
110                    document.getElementById("print_frame_#arguments.codesig#").contentWindow.document.body.innerHTML = document.getElementById('formatted_code_#arguments.codesig#').innerHTML;
111                    document.getElementById("print_frame_#arguments.codesig#").contentWindow.focus();
112                    document.getElementById("print_frame_#arguments.codesig#").contentWindow.print();
113                }
114                function show_about_#arguments.codesig#() {
115                    document.getElementById('about_#arguments.codesig#').style.display='inline';
116                    window.setTimeout('hide_about_#arguments.codesig#();', 4000);
117                }
118                function hide_about_#arguments.codesig#() {
119                    document.getElementById('about_#arguments.codesig#').style.display='none';
120                }
121            </script>
122            <div style='#getStyle("TOOLBAR")#'>
123                <span style='margin:0 0 0 2em'/>
124                <!--- Toggle code view --->
125                <a href='javascript:toggle_view_#arguments.codesig#()' style='#getStyle("TOOLBARLINK")#' id='view_#arguments.codesig#'>view plain</a>
126                
127                <!--- Copy to clipboard --->
128                <a href='javascript:copy_to_clipboard_#arguments.codesig#()' style='display:none;#getStyle("TOOLBARLINK")#' id='view_copy_to_clipboard_link_#arguments.codesig#'>copy to clipboard</a>
129                <!--- The cross-browser copy to clipboard methods out there are hacky and only work on certain browsers... if the browser handles it, then the link show up... --->
130                <script type='text/javascript'>if(window.clipboardData) { document.getElementById('view_copy_to_clipboard_link_#arguments.codesig#').style.display='inline';}</script>
131                
132                <!--- Print --->
133                <a href='javascript:print_#arguments.codesig#()' style='#getStyle("TOOLBARLINK")#'>print</a>
134                
135                <!--- About --->
136                <a href='javascript:show_about_#arguments.codesig#()' style='#getStyle("TOOLBARLINK")#'>about</a>
137                
138            </div>
139            <span id='about_#arguments.codesig#' style='display:none;#getStyle("TEXT")#'><span style='#getStyle("LINENUMBER")#'>&nbsp;</span>&nbsp;ColdFISH is developed by Jason Delmore.  Source code and license information available at <a href='http://coldfish.riaforge.org/'>coldfish.riaforge.org</a><br/></span>
140            <span id='htmlencoded_plain_#arguments.codesig#' style='display:none;#getStyle("TEXT")#'>#REReplace(REReplace(htmleditformat(arguments.code), "\n", "<br />", "ALL"),"\t","&nbsp;&nbsp;&nbsp;&nbsp;","ALL")#</span>
141        </cfsavecontent>
142        <cfreturn toolbarHTML/>
143    </cffunction>
144    
145    <cffunction name="formatLine" access="private" hint="This function takes a single line of code and formats it into syntax highlighted HTML." output="false">
146        <cfargument name="line" type="any"/>
147        <cfscript>
148            var character = "";
149            var thisLine=arguments.line;
150            var i = 0;
151            var endtagPos = 0;
152            var startAttributePos = 0;
153            var keywordskip = 0;
154
155            
156            if (variables.isOneLineComment) endOneLineComment();
157            
158            for (i=0; i LT thisLine.length(); i=i+1)
159            {
160                character=thisLine.charAt(javacast('int',i));
161                if (character EQ '
<')
162                {
163                    if (variables.isCFScript AND NOT variables.isValue)
164                        endCFScript();
165                    if (regionMatches(thisLine, 1, i+1, "!--", 0, 3))
166                    {
167                        if (regionMatches(thisLine, 1, i+4, "-", 0, 1))
168                        {
169                            startComment("CF");
170                        } else {
171                            startComment("HTML");
172                        }
173                    } else {
174                        if (regionMatches(thisLine, 1, i+1, "CF", 0, 2) OR regionMatches(thisLine, 1, i+1, "/CF", 0, 3))
175                        {
176                            startTag("CF");
177                            if (regionMatches(thisLine, 1, i+3, "SET", 0, 3) AND NOT regionMatches(thisLine, 1, i+6, "T", 0, 1)) // CFSET Tag
178                            {
179                                variables.buffer.append(thisLine.substring(javacast('int',i+1), javacast('int',i+6)));
180                                i=i+5;
181                                startCFSET();
182                            }
183                            else if (regionMatches(thisLine, 1, i+3, "SCRIPT>", 0, 6)) // CFSCRIPT TAG
184                            {
185                                variables.buffer.append(thisLine.substring(javacast('int',i+1), javacast('int',i+9)) & "&gt;");
186                                i=i+9;
187                                startCFScript();
188                            }
189                            else if (regionMatches(thisLine, 1, i+3, "QUERY", 0, 5)) // START CFQUERY TAG
190                            {    // TODO: This sets the value color immediately to match SQL values including the CFQuery tag...
191                                variables.isCFQueryTag = true;
192                            } else if (regionMatches(thisLine, 1, i+4, "QUERY", 0, 5)) // END CFQUERY TAG
193                            {
194                                variables.isCFQueryTag = false;
195                                endSQL();
196                            }
197                        }
198                        else if    (
199                                     regionMatches(thisLine, 1, i+1, "TA", 0, 2) OR
200                                    regionMatches(thisLine, 1, i+1, "/TA", 0, 3) OR
201                                    regionMatches(thisLine, 1, i+1, "TB", 0, 2) OR
202                                    regionMatches(thisLine, 1, i+1, "/TB", 0, 3) OR
203                                    regionMatches(thisLine, 1, i+1, "TD", 0, 2) OR
204                                    regionMatches(thisLine, 1, i+1, "/TD", 0, 3) OR
205                                    regionMatches(thisLine, 1, i+1, "TF", 0, 2) OR
206                                    regionMatches(thisLine, 1, i+1, "/TF", 0, 3) OR
207                                    regionMatches(thisLine, 1, i+1, "TH", 0, 2) OR
208                                    regionMatches(thisLine, 1, i+1, "/TH", 0, 3) OR
209                                    regionMatches(thisLine, 1, i+1, "TR", 0, 2) OR
210                                    regionMatches(thisLine, 1, i+1, "/TR", 0, 3)
211                                ) // HTML TABLE
212                        {
213                            startTag("HTMLTABLES");
214                        }
215                        else if (regionMatches(thisLine, 1, i+1, "IMG", 0, 3) OR regionMatches(thisLine, 1, i+1, "STY", 0, 3) OR regionMatches(thisLine, 1, i+1, "/STY", 0, 4)) //IMG or STYLE Tag
216                        // TODO: Do separate syntax highlighting for stuff inside style
217                        {
218                            startTag("HTMLSTYLES");
219                        }
220                        else if (
221                                    regionMatches(thisLine, 1, i+1, "FORM", 0, 4) OR
222                                    regionMatches(thisLine, 1, i+1, "/FORM", 0, 5) OR
223                                    regionMatches(thisLine, 1, i+1, "INPUT", 0, 5) OR
224                                    regionMatches(thisLine, 1, i+1, "/INPUT", 0, 5) OR
225                                    regionMatches(thisLine, 1, i+1, "TEXT", 0, 4) OR
226                                    regionMatches(thisLine, 1, i+1, "/TEXT", 0, 5) OR
227                                    regionMatches(thisLine, 1, i+1, "SELECT", 0, 6) OR
228                                    regionMatches(thisLine, 1, i+1, "/SELECT", 0, 7) OR
229                                    regionMatches(thisLine, 1, i+1, "OPT", 0, 3) OR
230                                    regionMatches(thisLine, 1, i+1, "/OPT", 0, 3)
231                                )
232                        {
233                            startTag("HTMLFORMS");
234                        }
235                        else if (
236                                     regionMatches(thisLine, 1, i+1, "MX:", 0, 3) OR
237                                    regionMatches(thisLine, 1, i+1, "/MX:", 0, 4)
238                                )
239                        {
240                            if (regionMatches(thisLine, 1, i+4, "SCRIPT>", 0, 6)) // MX:SCRIPT TAG
241                            {
242                                startTag("ACTIONSCRIPTTAG");
243                                variables.buffer.append(thisLine.substring(javacast('int',i+1), javacast('int',i+10)) & "&gt;");
244                                i=i+10;
245                                startActionscript();
246                            } else if (regionMatches(thisLine, 1, i+5, "SCRIPT>", 0, 6)) // END MX:SCRIPT TAG
247                            {
248                                endActionscript();
249                                startTag("ACTIONSCRIPTTAG");
250                                variables.buffer.append(thisLine.substring(javacast('int',i+1), javacast('int',i+11)));
251                                i=i+12;
252                                endTag();
253                            } else {
254                                startTag("MXML");
255                                startAttributePos=find(' ',thisLine,i+1); //start finding the next space from current position
256                                endtagPos=find('>
',thisLine,i+1); //start finding the end tag from current position
257                                if (startAttributePos neq 0) {  // start attribute colors
258                                    variables.buffer.append(thisLine.substring(javacast('int',i+1), javacast('int',startAttributePos)));
259                                    i=startAttributePos-1;
260                                    startMXMLTag();
261                                } else {
262                                    if (endtagPos neq 0) { // found >

263                                        variables.buffer.append(thisLine.substring(javacast('int',i+1), javacast('int',endtagPos-1)));
264                                        i=i+endtagPos;
265                                        variables.buffer.append("&gt;");
266                                        endHighlight();
267                                    }
268                                }    
269                            }
270                        } else {
271                            if (variables.isActionscript or variables.isSQL) {
272                                variables.buffer.append("&lt;");
273                            } else {
274                                startTag("HTML");
275                            }
276                        }
277                    }
278                }
279                else if (character EQ '>')
280                {
281                    if (variables.isCommented AND regionMatches(thisLine, 1, i-2, "--", 0, 2))
282                    {
283                        if (regionMatches(thisLine, 1, i-3, "-", 0, 1))
284                        {
285                            endComment("CF");
286                        } else {
287                            endComment("HTML");
288                        }
289                    } else {
290                        if (variables.isCFSETTag) {
291                            endCFSET();
292                        } else if (variables.isActionscript) {
293                            //This is where a CDATA for AS ends
294                            variables.buffer.append("&gt;");
295                        } else if (variables.isSQL) {
296                            variables.buffer.append("&gt;");
297                        } else if (variables.isCFQueryTag) {
298                            endTag();
299                            startSQL();
300                        } else if (variables.isMXML) {
301                            endMXMLTag();
302                        } else {
303                            endTag();
304                        }
305                    }
306                }
307                else if (character EQ '"')
308                {
309                    if (variables.isTag OR variables.isCFScript OR variables.isActionscript)
310                    {
311                        if (NOT variables.isValue) {
312                            startValue();
313                            variables.buffer.append('"');
314                        } else {
315                            variables.buffer.append('"');
316                            endValue();
317                        }
318                    } else {
319                        variables.buffer.append('"');
320                    }
321                }
322                else if (character EQ '{')
323                {
324                    startBind();
325                    variables.buffer.append("{");
326                    endBind();
327                }
328                else if (character EQ '}')
329                {
330                    startBind();
331                    variables.buffer.append("}");
332                    endBind();
333                }
334                else if (character EQ '/')
335                {
336                    if ((variables.isCFScript OR variables.isActionscript) AND regionMatches(thisLine, 1, i+1, "/", 0, 1) AND NOT variables.isCommented)
337                    {
338                        if (variables.isActionscript) {
339                            startOneLineComment("MXMLCOMMENT");
340                            variables.buffer.append("/");
341                        } else {
342                            startOneLineComment("HTMLCOMMENT");
343                            variables.buffer.append("/");
344                        }
345                    }
346                    else if (variables.isCommented)
347                    {
348                        if (regionMatches(thisLine, 1, i-1, "*", 0, 1))
349                        {
350                            endComment("SCRIPT");
351                        } else {
352                            variables.buffer.append("/");
353                        }
354                    } else {
355                        if (regionMatches(thisLine, 1, i+1, "*", 0, 1))
356                        {
357                            startComment("SCRIPT");
358                        } else {
359                            variables.buffer.append("/");
360                        }
361                    }
362                }
363                else if (variables.isSQL AND character EQ '-')
364                {
365                    if (regionMatches(thisLine, 1, i+1, "-", 0, 1) AND NOT variables.isCommented)
366                    {
367                        startOneLineComment("SQLCOMMENT");
368                        variables.buffer.append("-");
369                    } else {
370                        variables.buffer.append("-");
371                    }
372                }
373                else if (variables.isSQL AND character EQ "'" AND NOT variables.isCommented)
374                {
375                    if (NOT variables.isValue) {
376                        startValue();
377                        variables.buffer.append("'");
378                    } else {
379                        variables.buffer.append("'");
380                        endValue();
381                    }
382                }
383
384                // straight up replacements
385                else if (character EQ '\t' OR character EQ '    ')
386                {
387                    variables.buffer.append("&nbsp;&nbsp;&nbsp;&nbsp;");
388                }
389                else if (character EQ ' ')
390                {
391                    variables.buffer.append("&nbsp;");
392                }
393                else if (character EQ '&')
394                {
395                    if (regionMatches(thisLine, 1, i+1, "##", 0, 1)) {
396                        variables.buffer.append("&");
397                    } else {
398                        variables.buffer.append("&amp;");
399                    }
400                } else {
401                    if (not variables.isCommented AND not variables.isValue and (i eq 0 OR NOT listcontainsnocase('a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,@', thisLine.substring(javacast('int',i-1),javacast('int',i))))) {
402                        keywordskip = 0;
403                        // would like this to be much more generic rather than checking "is"
404                        if (variables.isActionscript) {
405                            keywordskip = keywordsearch(thisLine,i,"Actionscript");
406                        } else if (variables.isCFscript or variables.isCFSetTag) {
407                            keywordskip = keywordsearch(thisLine,i,"CFscript");
408                        } else if (variables.isSQL) {
409                            keywordskip = keywordsearch(thisLine,i,"sql");
410                        }
411                        if (keywordskip) {
412                            i = i + keywordskip;
413                        } else {
414                            variables.buffer.append(character.toString());
415                        }
416                    } else {
417                        variables.buffer.append(character.toString());
418                    }
419                }
420            }
421            variables.buffer.append("<br />");
422        </cfscript>
423    </cffunction>
424    <cffunction name="keywordsearch" access="private" hint="This function searches for keywords." output="false">
425        <cfargument name="thisLine" type="any"/>
426        <cfargument name="i" type="numeric"/>
427        <cfargument name="parser" type="string"/>
428        <cfset var keywordmap = getConfig().getKeywordmap()/>
429        <cfset var keyword = listfirst(thisLine.substring(javacast('int',i)),' (')/> <!--- search starting from current position --->
430        <cfset var findkey = StructFindKey(keywordmap[parser], keyword)/>
431        <cfset var keywordtype = ""/>
432        
433        <cfif arraylen(findkey)>
434            <cfset keywordtype = findkey[1].value/>
435            <cfset variables.buffer.append("<span style='" & getStyle(keywordtype) & "'>" & keyword & "</span>")/>
436             <cfreturn keyword.length()-1/>
437        </cfif>
438        <cfreturn 0/>
439    </cffunction>
440    <cffunction name="regionMatches" access="private" hint="This function checks if a regionMatches." output="false">
441        <cfargument name="string1" type="any"/>
442        <cfargument name="caseInsensitive" type="boolean" default="true"/>
443        <cfargument name="startPosition1" type="numeric"/>
444        <cfargument name="string2" type="any"/>
445        <cfargument name="startPosition2" type="numeric"/>
446        <cfargument name="endPosition2" type="numeric"/>
447        <cfreturn arguments.string1.regionMatches(arguments.caseInsensitive, javacast('int',arguments.startPosition1), arguments.string2, javacast('int',arguments.startPosition2), javacast('int',arguments.endPosition2))/>
448    </cffunction>
449    <cffunction name="startHighlight" access="private" hint="" output="false">
450        <cfargument name="element" type="string"/>
451        <cfset variables.spansOpened = variables.spansOpened + 1/>
452        <cfset variables.buffer.append("<span style='" & getStyle(arguments.element) & "'>")/>
453    </cffunction>
454    <cffunction name="endHighlight" access="private" hint="" output="false">
455        <cfargument name="line" type="any"/>
456        <cfset variables.spansClosed = variables.spansClosed + 1/>
457        <cfset variables.buffer.append("</span>")/>
458    </cffunction>
459    <cffunction name="startOneLineComment" access="private" output="false">
460        <cfargument name="type" type="string"/>
461        <cfscript>
462        startHighlight(type);
463        variables.isOneLineComment=true;
464        variables.isCommented=true;
465        
</cfscript>    
466    </cffunction>
467    <cffunction name="endOneLineComment" access="private" output="false">
468        <cfscript>
469        endHighlight();
470        variables.isOneLineComment=false;
471        variables.isCommented=false;
472        
</cfscript>    
473    </cffunction>
474    <cffunction name="startComment" access="private" output="false">
475        <cfargument name="type" type="string"/>
476        <cfscript>
477        if (type  EQ  "CF"{
478            startHighlight("CFCOMMENT");
479            variables.buffer.append("&lt;");
480        } else if (type  EQ  "HTML"{
481            if (variables.isMXML) {
482                startHighlight("MXMLCOMMENT");
483            } else {
484                startHighlight("HTMLCOMMENT");
485            }
486            variables.buffer.append("&lt;");
487        } else {
488            if (variables.isActionscript) {
489                startHighlight("ACTIONSCRIPTCOMMENT");
490            } else if (variables.isSQL) {
491                startHighlight("SQLCOMMENT");
492            } else {
493                startHighlight("CFSCRIPTCOMMENT");
494            }
495            variables.buffer.append("/");
496        }
497        variables.isCommented=true;
498        
</cfscript>
499    </cffunction>
500    <cffunction name="endComment" access="private" output="false">
501        <cfargument name="type" type="string"/>
502        <cfscript>
503        if (type  EQ  "SCRIPT"{
504            variables.buffer.append("/");
505        } else {
506            variables.buffer.append("&gt;");
507        }
508        endHighlight();
509        variables.isCommented=false;
510        
</cfscript>
511    </cffunction>
512    <cffunction name="startTag" access="private" output="false">
513        <cfargument name="type" type="string"/>
514        <cfscript>
515        if NOTT variables.isCommented AND NOT variables.isValue) {
516            if (type  EQ  "CF"{
517                startHighlight("CFTAG");
518            } else if (type  EQ  "HTMLSTYLES"{
519                startHighlight("HTMLSTYLES");
520            } else if (type  EQ  "HTMLTABLES"{
521                startHighlight("HTMLTABLES");
522            } else if (type  EQ  "HTMLFORMS"{
523                startHighlight("HTMLFORMS");
524            } else if (type EQ "MXML"{
525                startHighlight("MXML");
526            } else if (type EQ "ACTIONSCRIPTTAG"{
527                startHighlight("ACTIONSCRIPTTAG");
528            } else { // type is HTML
529
                startHighlight("HTML");
530            }
531            variables.isTag=true;
532        }
533        variables.buffer.append("&lt;");
534        
</cfscript>
535    </cffunction>
536    <cffunction name="endTag" access="private" output="false">
537        <cfscript>
538        variables.buffer.append("&gt;");
539        if NOTT variables.isCommented AND NOT variables.isValue) {
540            endHighlight();
541            variables.isTag=false;
542        }
543        
</cfscript>
544    </cffunction>
545    <cffunction name="startValue" access="private" output="false">
546        <cfscript>
547        if NOTT variables.isCommented) {
548            if (variables.isCFSETTag OR variables.isCFScript) {
549                startHighlight("CFSCRIPTVALUE");
550            } else if (variables.isActionscript) {
551                startHighlight("ACTIONSCRIPTVALUE");
552            } else if (variables.isMXML) {
553                startHighlight("MXMLVALUE");
554            } else if (variables.isSQL) {
555                startHighlight("SQLVALUE");
556            } else {
557                startHighlight("VALUE");
558            }
559            variables.isValue=true;
560        }
561        
</cfscript>
562    </cffunction>
563    <cffunction name="endValue" access="private" output="false">
564        <cfscript>
565        if NOTT variables.isCommented) {
566            endHighlight();
567            variables.isValue=false;
568        }
569        
</cfscript>
570    </cffunction>
571    <cffunction name="startBind" access="private" output="false">
572        <cfscript>
573        if NOTT variables.isCommented) {
574            startHighlight("BIND");
575        }
576        
</cfscript>
577    </cffunction>
578    <cffunction name="endBind" access="private" output="false">
579        <cfscript>
580        if NOTT variables.isCommented) {
581            endHighlight();
582        }
583        
</cfscript>
584    </cffunction>
585    <cffunction name="startCFSET" access="private" output="false">
586        <cfscript>
587        if NOTT variables.isCommented) {
588            startHighlight("CFSET");
589            variables.isCFSETTag=true;
590        }
591        
</cfscript>
592    </cffunction>
593    <cffunction name="endCFSET" access="private" output="false">
594        <cfscript>
595        if NOTT variables.isCommented) {
596            endHighlight();
597            variables.buffer.append("&gt;");
598            endHighlight();
599            variables.isCFSETTag=false;
600        } else {
601            variables.buffer.append("&gt;");
602        }
603        
</cfscript>
604    </cffunction>
605    <cffunction name="startMXMLTag" access="private" output="false">
606        <cfscript>
607        if NOTT variables.isCommented) {
608            startHighlight("MXMLATTRIBUTES");
609            // TODO: Add in MXML Value colors.
610
            // setStyle("VALUE","color:##900");
611
            variables.isMXML=true;
612        }
613        
</cfscript>
614    </cffunction>
615    <cffunction name="endMXMLTag" access="private" output="false">
616        <cfscript>
617        if NOTT variables.isCommented) {
618            endHighlight();
619            variables.buffer.append("&gt;");
620            endHighlight();
621            // TODO: Add in MXML Value colors.
622
            // setStyle("VALUE","color:##0000CC");
623
            variables.isMXML=false;
624        } else {
625            variables.buffer.append("&gt;");
626        }
627        
</cfscript>
628    </cffunction>
629    <cffunction name="startCFScript" access="private" output="false">
630        <cfscript>
631        if NOTT variables.isCommented) {
632            endHighlight();
633            startHighlight("CFSCRIPT");
634            variables.isCFScript=true;
635        }
636        
</cfscript>
637    </cffunction>
638    <cffunction name="endCFScript" access="private" output="false">
639        <cfscript>
640        if NOTT variables.isCommented) {
641            endHighlight();
642            variables.isCFScript=false;
643        }
644        
</cfscript>
645    </cffunction>
646    <cffunction name="startActionscript" access="private" output="false">
647        <cfscript>
648        if NOTT variables.isCommented) {
649            endHighlight();
650            startHighlight("ACTIONSCRIPT");
651            variables.isActionscript=true;
652        }
653        
</cfscript>
654    </cffunction>
655    <cffunction name="endActionscript" access="private" output="false">
656        <cfscript>
657        if NOTT variables.isCommented) {
658            variables.isActionscript=false;
659        }
660        
</cfscript>
661    </cffunction>
662    <cffunction name="startSQL" access="private" output="false">
663        <cfscript>
664        if NOTT variables.isCommented) {
665            variables.isSQL=true;
666        }
667        
</cfscript>
668    </cffunction>
669    <cffunction name="endSQL" access="private" output="false">
670        <cfscript>
671        if NOTT variables.isCommented) {
672            variables.isSQL=false;
673        }
674        
</cfscript>
675    </cffunction>
676    
677    <!--- configuration methods --->
678    <cffunction name="setConfig" access="public" hint="This sets the coldfish configuration object for the parser to use." output="false">
679        <cfargument name="config" type="any"/>
680        <cfset variables.coldfishconfig = config/>
681    </cffunction>
682    <cffunction name="getConfig" access="public" hint="This sets the coldfish configuration object for the parser to use." output="false">
683        <cfargument name="config" type="any"/>
684        <cfreturn variables.coldfishconfig/>
685    </cffunction>
686    <cffunction name="getStyle" access="private" hint="This function can be used to get the style used in conjunction with a type of language element." output="false">
687        <cfargument name="element" type="string"/>
688        <cfreturn getConfig().getStyle(element)/>
689    </cffunction>
690    <cffunction name="getInitialParser" access="private" hint="You can set the initial parser state with this.  This is helpful for scripts that make initial parsing impossible (ie. Script, Actionscript)" output="false">
691        <cfreturn getConfig().getInitialParser()/>
692    </cffunction>
693    <cffunction name="getKeywordmap" access="private" hint="You can set the keywordmap with this." output="false">
694        <cfreturn getConfig().getKeywordMap()/>
695    </cffunction>
696</cfcomponent>

I'd like to extend a special thanks to Ray Camden & Jason Delmore for their prompt replies and expeditious changes ... Much Appreciated.

Business Getting Slow? Invest in SEO

Search Engine Optimization Increases Business ยป Any Questions?

Sometimes I'm baffled by the lack of understanding most business owners have in the value of online visiblity. Even some of the clients I have worked with which have seen and realized fantastic results still fail to recognize the benefits. In this desperate economy isn't an increase in revenue a good thing?

I recently went through the effort of creating a detailed analytics presentation on the performance of one of my clients sites since signing with Florida Search Engine Optimization. Self promotion aside - their site is performing and producing phenomenally well, which in turn evaluates to a significant increase in revenue. However, shortly after giving the successful presentation and discussing moving forward with increasing their search marketing efforts - their focus and committment waned and they haven't moved forward since.

Not trying to brag here ... but I feel it's important to mention that I hardly ever market for new clients - Almost all of the business that I get is through my own optimization efforts. When I first started out I did have to grab the 50 pound phone to get things kicked off, but I haven't had to do "hard marketing" in a long time ...

I feel partially responsible in not being able to effectively communicate the value of SEO to the "C Suite" ... I guess I just consider an increase in conversions and revenue a no brainer.

That's it.

ColdFusion Ajax & JQuery ... Learn to Earn

Recently I decided that it's time to start paying a bit more attention to improving the visual presentation of one of my sites. The site's built in ColdFusion with lot's of nifty CF Ajax stuff thrown in. CFDiv's, CFWindows, and Pods here and there too. So, I figured since I'm not too bad at coding in CF - at least I can usually Google my way through most of the snags I run in to - I wanted to try challenging myself a bit by taking on something fairly foreign to me. Ajax.

I know the basics of Ajax. Asynchronous JavaScript with XML - Sending and receiving Http requests and responses to a server to return data to a site without refreshing the documents. However, I had little experience actually taking on an Ajax project. But if that wasn't difficult enough, I wanted to get really frustrated, so I decided to use a JavaScript library that I had little if any experience with - Entrance JQuery.

Now I've seen a lot of very groovy examples of the nifty UI tricks that can be done with JQuery. They are cool. But I really wanted to learn how to use JQuery for my specific needs. So, I did. I choose to launch my campaign with a real world example. So for my project, I mapped out what I wanted to do with ColdFusion, JQuery, and Some CFAjax stuff. Here's what I planned out ... First, I wanted to add a US database to my site, SEOMasterList.com, to build out some dynamic pages. The reasons for that should be quite apparent. I'm planning to obtain rankings and possibly monetize the site.

Next, I wanted to add some cool visual effects while providing improved functionality to the site, and possibly give visitors a better experience.

And finally, I just wanted to see if I could actually do it - two weeks in to it, I finished it. I have got to admit I spent a hell of a lot of time learning while trying to get the site done - someone with experience could have probably launched it in a matter of no time. But, I learned a lot.

Once I modified, installed, and built out the components to accommodate the addition of the database, I set up another component to dynamically bind the results from the database to two selects in a form. This was very challenging - I spent the better part of two days just trying to get the bindings to work. Luckily, I found a cool ColdFusion script and modified it to output my database queries to XML. That came in really handy. The first go at trying to output 80,000+ records to a single flat XML file didn't work out to well. I ended up rebuilding the data CFC's several times in order to get what I needed. I ended up with a 1.4 MB XML file that I'm now using to bind to the data in the selects.

After tackling that part of the project, I wanted to introduce some visually appealing effects to the site so I picked up the latest JQuery code and sent it up to my site. After some effort, I was successful in creating a pretty slick interface for my Ajax loaded form. Through the use of some nifty ('#div').show(),('#div').hide () functionality on the form page, I was able to add and remove elements of the page which weren't necessary at every stage of the form submission process. This proved to be tougher to implement than I had expected. Up to this point I have a form bound by CFC's to data, an asynchronous form handler to process a form submission, and some nifty JQuery going on to assist in dressing up my application modifications. All in all. I think it went really well - and I learned a whole hell of a lot doing it. If you want to see what I did ... have a heart ... I'm an Ajax nOOb. Check it out on SEOMasterList ...

Florida SEO » CFC Problem » Solved

In my last post, I was ranting about a frustrating situation with CFC's on shared hosting over at HostMySite. Several months ago, I installed a rather cool CFC that only had a life span of three days - it worked fine - then all of a sudden - it stopped working.

A few weeks ago the same scenario took place - I installed a component on another one of my CF sites, SEO Master List - It ran fine for three weeks and the all of a sudden - it stopped working.

After many hours of confusion with the guys over at HostMySite, it turns out that occasionally during server resets the security permissions are changed. I really don't know whether there's someone to blame for it, but at least I know the why of it if not the how.

So, if you have a CF site on shared hosting over at HMS and find your CFC's stop working and your pretty certain that they should be, make sure to take a look at the security settings - That's it.

CFC Madness » Where's The Damned Component?

Okay, So I might be a bit frustrated here ... I have had ongoing issues with CFC's at HostMySite, and I can't for the life of me find the root cause to my dilemma. If someone could give me a clue ... I would really appreciate it. My problem follows ...

I have shared hosting accounts with HostMySite for my CF sites. A few months back I attempted to work with the CFlickr CFC on my blog ... However, after a few days of being in operation, I started to receive errors stating that ...

" The value of the Function Foo is not of type components.someComponent. "

After working with tech support for a few days, our first guess was that there was a mapping issue with the CFC, and that we just needed to update the mappings ... after checking the mappings several times, reinstalling the component several times, and having support finally tell me that "there must be something wrong with the code", I abandoned the project feeling a bit ... beaten.

Recently I created a feed aggregator based on the same code from ColdFusionBloggers ... For several weeks the site ran fine ... no problems. But recently, I tried to login to the admin area ... and I started to receive errors by email that were strikingly similar to the errors I had with the CFlikr CFC. This time I'm getting ...

" The value returned from the getComponent function is not of type components.entries "

So, I contacted tech support, only to hear the familiar lines ... "We'll create a ticket ... and call you when we know something ... " Which usually means I'll have to figure it out for myself. Now, I don't quite understand why a component would just stop working without any changes to it ... but I'm starting to think that this issue is not something that I caused. If there's a CFer out there that has had a similar experience and found a solution ... could you please throw me a rope?

That's it.

Florida SEO Try Catch Application.CFC

Okay, so I am only a year in to CF development now, and I still feeling about as confident with my skills as well, the first month I started ... don't ask me why, but I always seem to find a problem that baffles me. This time is not an exception.

I recently moved to Application.CFC ... (Don't know what that is? Don't worry, I know as much as you. Want to find out more? ... Ray "Raymond" has info on his site ... )

So, this move came about since I had no idea how to manage error handling for 404 pages in CF ... for instance, if a link to a page on my site was missing, or broken ... the 404 page would get returned. However, if someone requested a .cfm page that did not exist whatsoever ... then the "IIS" template would kick in ... Not Good ...

So, I wanted my 404 template to kick in even when someone requested a specific ColdFusion page as well as broken links, moved pages, anything else ...

The only way to get what I really needed ... a default error handler in CF for all pages ... was not going to be available on a shared hosting platform ... which my site is on ... Good thing that ColdFusion 8, has the functionality available by way of the onMissingTemplate function through Application.CFC ...

Now, I saw a few references regarding the cflocation tag ...

view plain print about
1<cffunction name="onMissingTemplate" returnType="boolean" output="false">
2    <cfargument name="thePage" type="string" required="true">
3    <cflog file="somefiles" text="#arguments.thePage#">
4    <cflocation url="404.cfm?thepage=#urlEncodedFormat(arguments.thePage)#" addToken="false">
5</cffunction>

But this was a problem due to redirecting from a 404 page ... The search engines would definitely have a problem with a 404 page returning a "page moved temporarily" or a "page moved permanently" flag when in fact it didn't exist at all ... That would Not be good for the rankings ...

So, the answer it seems was to try a bit of a different solution ... similar, yet a bit different ... here's the next shot ...

view plain print about
1<cffunction name="onMissingTemplate" returnType="boolean" output="true">
2    <cfargument name="targetPage" type="string" required="true" />
3    <cflog file="somefile" type="error" text="Missing template: #Arguments.targetPage#">
4    <cfinclude template="404.cfm" />
5    <cfreturn true />
6</cffunction>

Generally it's not a real smart idea for a newbie coder such as myself to go playing around with really important functions on a production site ... but, then again I can't have problems with 404 pages either ... So, I chanced fate ... and came up with the solution above ...

I also created a custom 404 page which I am rather fond of ... if an event fires my 404 template ... I have an include of my site map so search engine robots can give me a some credit by crawling the sitemap ... and at the same time, I can offer my visitors a useful way to navigate a page that they might have been looking for ...

You have been warned! If, you decide to use a 404 page ... make sure that you don't include it either in your .xml site map ... and that you implement a header status 404 ...

view plain print about
1<cfheader statuscode="404" statustext="Not Found" />

Furthermore, pay attention to your Meta Robots Tag ...

view plain print about
1<meta name="robots" content="noindex, follow" />

If not ... you are basically telling the search engines that your pages exist ... (status 200 ยป okay ) ... and that will kill your search engine optimization efforts ... fast.

Florida SEO Bringing on Visuals - CFlickr CFC

I recently decided that it was about time to start adding some imagery to my Blog. I am the first person to go to bat for Content being the King on the web, but straight text content can at times be a little boring to look at. So I went on the hunt for a simple way to add life to my blog.

I found an API called CFlickr, that is written in ColdFusion and provides the ability to work with Flickr's REST API. There are some really cool examples of the things that you can do with the API over at SixFive.

CFlickr's developer, (Chris Blackwell), gives some very good examples of how the API can be used to develop dynamic pages through working with the API. He has even gone through the trouble of setting up the CFC's Documentation.

If you haven't ever worked with ColdFusion Components, there are a few things that you have to do to make sure that the component works correctly. If you are in a shared hosting environment, you will have to ask your host to provide a mapping to the directory where CFlickr is under your web root. Make sure you are careful to get the mapping right ... if you aren't ... you will find out really fast.

I'm not going to try to go in to a tutorial on using the API just yet, but if you are interested in learning more about it, you can get more at the CFlickr Site.

ColdFusion Components and OO Java - Closely Related - Not the Same

Recently I have been reviewing ColdFusion 8 - Beyond the Basics by David Gassner and I have ventured into the world of ColdFusion Components (CFC's). I am starting to get a better understanding of how ColdFusion, or CFML Pages, are processed in the JRun server and how CFC's relate somewhat to Object Oriented Java. First of all I had to find out that the CFML alone is not related to Java. However, there is an ability in ColdFusion to integrate in a hybrid environment with Java through the use of CFC's.

Since I am very new to CFC's, I will not attempt to explain the complex architecture that is involved in relating ColdFusion to Java, but rather what it is that I came to realize from the Beyond the Basics series and by doing a little research on CFC's and Java.

[More]

BlogCFC was created by Raymond Camden. This blog is running version 5.9.7. Contact Florida Search Engine Optimization L.L.C.
Search Engine Optimization Specialist || Web Designer || Web Developer || Edward J Beckett ||
Search Engine Optimization Company  || SEO Services || Internet Marketing Company || Search Engine Optimization Expert || Florida Search Engine Optimization LLC
Florida Search Engine Optimization || Search Engine Optimization || SEO Services || Florida SEO Blog
Florida Search Engine Optimization
Search Engine Optimization
SEO Services
Florida SEO Blog
February-04-2012
3:58 PM EST