Add Files To WordPress SVN Repository
If you have developed a wordpress plugin on Windows and want to host the files on WordPress.org, you need this step by step tutorial about how to commit files into WordPress SVN Repository on Windows using TortoiseSVN:
wp_footer hook not working
After I installed WordPress Plugin for Omniture Site Catalyst and activated it from WordPress Admin panel. It did not appear to insert the markup it was supposed to add just before the </body> tag as it was using the following hook to do that:
add_action(‘wp_footer’, ‘omniture_tag’);
After searching the internet for a solution, I figured that the theme I was using needed to have the following missing statement in the footer.php just before the </body> tag to make it work:
<?php wp_footer(); ?>
Enjoy…
Protect your website from spam bots using ASP.NET CAPTCHA Library
reCAPTCHA ASP.NET Library gives you an easy way to integrate spam bot protection into your ASP.net website which is the most accessible CAPTCHA implementation due to listening option it provides for visually impaired people. Below is the link for the Server Control download and the sample code to implement it:
ASP.NET CAPTCHA Library for reCAPTCHA
On September 16, 2009, Google announced acquisition of reCAPTCHA in a bid to digitize old time books and newspapers and support Google’s on going OCR research.
Custom URL Rewriting in WordPress
It looks like I will have to override url rewrites in WordPress soon and the following link appears to offer some useful info about implementing custom URL rewriting in WP:
Disable automatic line breaks in WordPress
I found a simple hack to disable automatic line break (<p> and <br> tags inserted by WordPress wp_autop filter) filtering on all line breaks that was too annoying for my technical web development team busy transforming ColdFusion websites to WordPress Blogs. Here’s the solution:
Comment the following line in /wp-includes/default-filters.php:
add_filter($filter, ‘wpautop’)
How to remove index.cfm from url to make it Search Engine friendly
All ColdFusion websites run the risk of having two links for a single page when the file name is index.cfm. For example, http://www.example.com and http://www.example.com/index.cfm. Although ColdFusion provides elegant way of Permanent redirection from http://www.example.com/index.cfm to http://www.example.com, but there’s no server side path variable that could tell you the exact URL requested. Even CGI.PATH_INFO and CGI.SCRIPT_NAME provide the same path that includes /index.cfm.
Solution
<cfif cgi.CONTENT_LENGTH eq “”>
<cfset redirect_url = “http://” & CGI.SERVER_NAME & left(CGI.SCRIPT_NAME, len(CGI.SCRIPT_NAME) – 10)>
<cfheader statuscode=”301″ statustext=”Moved permanently”>
<cfheader name=”Location” value=”#redirect_url#”>
</cfif>
The above code works perfect for me although I don’t understand why Content_length is different for both URLs. I found the solution by cfdumping CGI variable using one url without index.cfm and another with index.cfm and observed that content-length was empty when url included index.cfm.
I hope it works for other CF folks as well.
Google Custom Search Web Services in ColdFusion
Google Custom Search Engine lets website managers and developers easily integrate site search functionality into their websites with most of the required features. However, there are situations when you might have to control the display of search results (custom style guides), add more restrictions (search specific filetypes) or report meta data to web analytics software. I have covered this topic in two posts. This post covers querying , extracting, parsing and looping through the search results while the next part includes posting information (not easily available using iframe approach) to web analytics.
Calling Google Custom Search (CSE) Web Services
<cfhttp result=”cseresult” url=”http://www.google.com/cse?cx=#googleAPIKey#&client=google-csbe&output=xml_no_dtd&q=#q#&start=#start#&filter=0″ method=”get” resolveurl=”yes” />
In the above statement, googleAPIKey=key of the custom search engine; q=search query; start=Zero based paging index, use start=10 for page 2; filter=0= Don’t filter similar result, use 1 to filter results.
Extracting Metadata and Results
<cfscript>
resultsxml = XMLParse(cseresult.FileContent);
RES = XMLSearch(resultsxml, “GSP/RES”);
if (ArrayLen(RES) gt 0)
{
totalResults = XMLSearch(RES[1], “M”);
searchResults = XMLSearch(RES[1], “R”);
iTotalResults = totalResults[1].XmlText;
iStartNumber = RES[1].XmlAttributes.SN;
iEndNumber = RES[1].XmlAttributes.EN;
}
</cfscript>
All XPath queries in above code return Arrays of Structures. RES element in the xml contains all the results information. SN is the index of the first result on the page while EN is the index of the last result on a page. For example, if page 2 has 4 results, then SN=11 and EN=14 while START remains 10.
Displaying Results and Pager
<div id=”google-cse”>
<cfif ArrayLen(RES) gt 0><!— If more than zero results returned —>
<!—Results Pager Header —>
<cfoutput><p>Results <b>#iStartNumber#</b> – <b>#iEndNumber#</b> of about <b>#iTotalResults#</b> for <b>#q#</b></p></cfoutput>
<cfloop index=”i” from=”1″ to=”#ArrayLen(searchResults)#”>
<cfset current_result = searchResults[i]>
<!—Unique Result —>
<div>
<h2><a <cfif isdefined(‘current_result.XmlAttributes.MIME’) AND current_result.XmlAttributes.MIME eq ‘application/pdf’>class=”mime_pdf”</cfif> href=”<cfoutput>#current_result.U.XmlText#</cfoutput>”><cfoutput>#current_result.T.XmlText#</cfoutput></a></h2>
<p><cfoutput>#current_result.S.XmlText#</cfoutput></p>
<p><cfoutput>#current_result.UE.XmlText#</cfoutput></p>
</div>
</cfloop>
<cfif iTotalResults gt numresults>
<cfset num_of_pages = Ceiling(iTotalResults/numresults) >
<cfset current_page = (iStartNumber – 1) / numresults + 1 >
<!—Pager Navigation —>
<div id=”cse-pager”>
<cfif current_page gt 1>
<cfset startnew = (current_page-2)* numresults>
<cfoutput><a href=”#CGI.SCRIPT_NAME#?q=#q#&start=#startnew#”>Previous</a></cfoutput>
</cfif>
<cfloop index=”i” from=”1″ to=”#num_of_pages#”>
<cfset startnew = (i-1)* numresults>
<cfoutput><a <cfif current_page eq i >class=”active” <cfelse>href=”#CGI.SCRIPT_NAME#?q=#q#&start=#startnew#”</cfif>>#i#</a></cfoutput>
</cfloop>
<cfif current_page lt num_of_pages>
<cfset startnew = (current_page)* numresults>
<cfoutput><a href=”#CGI.SCRIPT_NAME#?q=#q#&start=#startnew#”>Next</a></cfoutput>
</cfif>
</div>
</cfif>
</cfif>
The above code will show specific icon for PDF files and a basic pager that includes all the links according to the number of results found.
Complete Implementation (Code Listing)
<div id=”middle_content”>
<cfset numresults = 10>
<cfset iTotalResults = 0>
<cfif not IsDefined(’start’)>
<cfset start = 0>
</cfif>
<cfif not IsDefined(‘q’)>
<cfset q = ”>
</cfif>
<cfif q eq ”>
<p>Please use the search box above to find the information you need.</p>
<p>Thank you</p>
<cfelse>
<cfhttp result=”cseresult” url=”http://www.google.com/cse?cx=#googleAPIKey#&client=google-csbe&output=xml_no_dtd&q=#q#&start=#start#&filter=0” method=”get” resolveurl=”yes” />
<cfscript>
resultsxml = XMLParse(cseresult.FileContent);
RES = XMLSearch(resultsxml, “GSP/RES”);
if (ArrayLen(RES) gt 0)
{
totalResults = XMLSearch(RES[1], “M”);
searchResults = XMLSearch(RES[1], “R”);
iTotalResults = totalResults[1].XmlText;
iStartNumber = RES[1].XmlAttributes.SN;
iEndNumber = RES[1].XmlAttributes.EN;
}
</cfscript>
<div id=”google-cse”>
<cfif ArrayLen(RES) gt 0><!— If more than zero results returned —>
<!—Results Pager Header —>
<cfoutput><p>Results <b>#iStartNumber#</b> – <b>#iEndNumber#</b> of about <b>#iTotalResults#</b> for <b>#q#</b></p></cfoutput>
<cfloop index=”i” from=”1″ to=”#ArrayLen(searchResults)#”>
<cfset current_result = searchResults[i]>
<!—Unique Result —>
<div>
<h2><a <cfif isdefined(‘current_result.XmlAttributes.MIME’) AND current_result.XmlAttributes.MIME eq ‘application/pdf’>class=”mime_pdf”</cfif> href=”<cfoutput>#current_result.U.XmlText#</cfoutput>”><cfoutput>#current_result.T.XmlText#</cfoutput></a></h2>
<p><cfoutput>#current_result.S.XmlText#</cfoutput></p>
<p><cfoutput>#current_result.UE.XmlText#</cfoutput></p>
</div>
</cfloop>
<cfif iTotalResults gt numresults>
<cfset num_of_pages = Ceiling(iTotalResults/numresults) >
<cfset current_page = (iStartNumber – 1) / numresults + 1 >
<!—Pager Navigation —>
<div id=”cse-pager”>
<cfif current_page gt 1>
<cfset startnew = (current_page-2)* numresults>
<cfoutput><a href=”#CGI.SCRIPT_NAME#?q=#q#&start=#startnew#”>Previous</a></cfoutput>
</cfif>
<cfloop index=”i” from=”1″ to=”#num_of_pages#”>
<cfset startnew = (i-1)* numresults>
<cfoutput><a <cfif current_page eq i >class=”active” <cfelse>href=”#CGI.SCRIPT_NAME#?q=#q#&start=#startnew#”</cfif>>#i#</a></cfoutput>
</cfloop>
<cfif current_page lt num_of_pages>
<cfset startnew = (current_page)* numresults>
<cfoutput><a href=”#CGI.SCRIPT_NAME#?q=#q#&start=#startnew#”>Next</a></cfoutput>
</cfif>
</div>
</cfif>
<cfelse><!— If no results returned —>
<p>Your search – <b><cfoutput>#q#</cfoutput></b> – did not match any documents.<br /><br />
Suggestions:<br /></p>
<ul>
<li>Make sure all words are spelled correctly</li>
<li>Try different keywords</li>
<li>Try more general keywords</li>
<li>Try fewer keywords</li>
</ul>
</cfif>
</div>
</cfif>
</div><!—End of middle_content—>
Above code integrates everything and handles manages output when provided with empty search query or getting zero results from Google. To see the implementation of the above code, Take a look at OSHACampus.com
Browser Compatible AJAX Applications in JAVA
Google Web Toolkit – GWT provides JAVA developers a framework to easily write, reuse, maintain and debug AJAX front end applications. GWT automatically generates optimized JavaScript that works across all major browsers by choosing the JavaScript purely targetted to the requesting browser, thus providing localization features as configured in the browsers. Using GWT allows debugging AJAX applications using any JAVA debugger and the code will only compile to JavaScript when it’s instructed to do so. During development, the code changes can be viewed immediately without a need to recompile.
GWT, however, does not eliminate the need to learn JavaScript or CSS and even provides ways to insert hand written JavaScript based on the complexity of the situation.
Links:
http://code.google.com/webtoolkit/download.html
http://qasimalikhawaja.wordpress.com/2008/03/29/putting-urself-into-gwt-googlewebtoolkit/
Drop Script for Full-text Catalog in Sql Server 2005
Sql Server 2005 Management Studio provides Drop Script generation for different database objects like Table, Views, Stored Procedures, Functions etc. using the right click option. These scripts are very useful for build promotion and replicating database structure on different database servers. However, this facility is not available for full-text catalogs probably because of the possible dependency over a full-text index. Below is the script (specifically for Sql Server 2005+) that checks system catalogs for existence of full-text catalog and index and then proceeds with drop/delete.
IF EXISTS(select 1 from sys.fulltext_catalogs where [name]=’fulltextcatalog’)
BEGIN
IF EXISTS (select 1 from sys.fulltext_indexes where object_id = object_id(‘[db-owner].[view/table name]‘))
DROP FULLTEXT INDEX ON dbo.[view/table name]
DROP FULLTEXT Catalog fulltextcatalog
END
GO


Recent Comments