<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Kevin Dubois &#187; Uncategorized</title>
	<atom:link href="http://kevindubois.com/blog/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>http://kevindubois.com/blog</link>
	<description>A LAMP consultant in the greater Salt Lake City Area</description>
	<lastBuildDate>Mon, 16 Nov 2009 17:52:49 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Creating an advertisement widget for external websites using JavaScript</title>
		<link>http://kevindubois.com/blog/2009/11/16/creating-advertisement-widgets-for-3rd-party-websites/</link>
		<comments>http://kevindubois.com/blog/2009/11/16/creating-advertisement-widgets-for-3rd-party-websites/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 17:42:58 +0000</pubDate>
		<dc:creator>Kevin Dubois</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[advertisement]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[widget]]></category>

		<guid isPermaLink="false">http://kevindubois.com/blog/?p=41</guid>
		<description><![CDATA[If you work with Google Analytics or Google Adsense, you&#039;ve undoubtedly worked with the little code bits they ask you to include in your website.  This tutorial will teach you how to create your own widget that people can include on their website by pasting a similar piece of javascript.
First off, you&#039;ll need to create [...]]]></description>
			<content:encoded><![CDATA[<p>If you work with Google Analytics or Google Adsense, you&#039;ve undoubtedly worked with the little code bits they ask you to include in your website.  This tutorial will teach you how to create your own widget that people can include on their website by pasting a similar piece of javascript.</p>
<p>First off, you&#039;ll need to create a javascript file, accessible from 3rd party systems.  Typically you won&#039;t have to do anything for this &#8211; just make sure you can access the file from any browser and host with the http protocol.</p>
<h2>1) The simple and easy (but limited) solution</h2>
<p>So let&#039;s go ahead and create mywidget1.js, and tell it to output the string &#039;Hello World&#039;.</p>
<blockquote>
<pre>document.write("hello world!");</pre>
</blockquote>
<p>Now, we&#039;ll write the code bit that will be included on the 3rd party sites:</p>
<blockquote>
<pre>&lt;script type="text/javascript" src="http://www.kevindubois.com/demos/js/mywidget1.js"&gt;&lt;/script&gt;</pre>
</blockquote>
<p>Simple, right?  If that satisfieds your needs, all the better, but most people will want a little more functionality.</p>
<p>Either way, you can see a demo for this one at <a title="widget1" href="http://www.kevindubois.com/demos/widget1.html" target="_blank">http://www.kevindubois.com/demos/widget1.html</a> (the js code is at <a title="widget1 javascript" href="http://www.kevindubois.com/demos/js/mywidget1.js" target="_blank">http://www.kevindubois.com/demos/js/mywidget1.js</a>)</p>
<p>There are ways to pass variables and there are ways to handle secure servers, so if that&#039;s what you&#039;re interested in, please continue to read!</p>
<h2>2) The more advanced (but still pretty easy) solution:</h2>
<p>The files stay the same, only the code within will get a little more chunky.  My sample will be based on the assumption that you&#039;re sending an advertisement widget to the 3rd party sites &#8211; but it really could be anything you want, just change the parameters in whatever you want.</p>
<p>Let&#039;s start with the 3rd party code this time.  We&#039;ll write the javascript tags again,  but this time we&#039;re not going to include the location to the js file in the tag but rather, we&#039;re going to tell the browser to write another javascript codebit from within the first javascript tag.  This is necessary to pass some parameters to the js file; and to write some code around secure sites (or not) issues:</p>
<blockquote>
<pre>&lt;script type="text/javascript"&gt;
 referral_code = "MQI74";
 ad_code = "aa";
 ad_width = "200"; // optional
 var myHost = (("https:" == document.location.protocol) ? "https://www." : "http://www.");
 document.write(unescape("%3Cscript src='" + myHost + "kevindubois.com/demos/js/mywidget2.js' type='text/javascript'%3E%3C/script%3E"));
&lt;/script&gt;</pre>
</blockquote>
<p>referral_code, ad_code and ad_width are parameters that are being sent to the js file.  myHost detects whether we&#039;re on a secure site or not, and will change the path to reflect that.  Note that this will only work if you have a secure certificate on your end too.  The reason why I included this, is because some browsers will return a warning on the 3rd party secure site if your js file is not secure, saying that some items on the site are not secure.  The html tags are being escaped ( &lt; = %3C and &gt; = %3E ) and then unescaped, because otherwise the browser will interpret these tags incorrectly.</p>
<p>Let&#039;s go back to the js file and add some more code to handle the parameters and the security:</p>
<p>Start the js file by figuring out the security again:</p>
<blockquote>
<pre>var myHost = (("https:" == document.location.protocol) ? "https://www." : "http://www.");</pre>
</blockquote>
<p>The parameters you passed are directly available, so you can start using them immediately. In my case, I added a switch statement to show different ads (sort of like google adsense, where you can show different ad sizes and types by changing the ad code).  Make sure you escape opening and closing tags because you will get problems with the browser interpreting things incorrectly.</p>
<pre>var ad_code = ad_code ? ad_code : '1a';
var referral_code = referral_code ? referral_code : '000';
var ad_width = ad_width ? ad_width : 200;

// switch code to see what we want to serve up
switch(ad_code){

   case '1a':
     document.write(unescape("%3Cdiv style='width:"+ad_width+"px; font-family: verdana, arial, helvetica, sans-serif; cursor:pointer; font-size:11px;'%3E"));
     document.write(unescape("%3Ca href='" + myHost + "kevindubois.com/index.php?referral="+referral_code+"' style='text-decoration:none;color:white'%3E"));

     document.write(unescape("%3Cdiv style='border-top:5px solid #0F0442; width:"+ad_width+"px; background-color:#FF6204; color:#FFF; padding-bottom:10px '%3E"));
     document.write(unescape("%3Cul%3E"));    
     document.write(unescape("%3Cli style='margin-left:-15px'%3EThis is a demo for %3Ca href='http://kevindubois.com/blog/2009/11/16/creating-advertisement-widgets-for-3rd-party-websites'%3Ehttp://kevindubois.com/blog/2009/11/16/creating-advertisement-widgets-for-3rd-party-websites%3C/a%3E%3C/li%3E"));    
     document.write(unescape("%3Cli style='margin-left:-15px'%3bla bla bla%3C/li%3E"));    
     document.write(unescape("%3Cli style='margin-left:-15px'%3Ebla bla bla%3C/li%3E"));    
     document.write(unescape("%3Cli style='margin-left:-15px'%3Ebla bla bla%3C/li%3E"));    
     document.write(unescape("%3C/ul%3E  "));    
     document.write(unescape("%3Cdiv style='text-align:center;font-weight:bold; font-size:12px; '%3E LEARN MORE %3C/div%3E"));    
     document.write(unescape("%3C/div%3E"));    
     document.write(unescape("%3C/a%3E"));    
     document.write(unescape("%3C/div%3E"));
   break;

   case '2a':
     document.write(unescape("%3Cdiv style='width:"+ad_width+"px; font-family: verdana, arial, helvetica, sans-serif; cursor:pointer; font-size:11px;'%3E"));
     document.write(unescape("%3Ca href='" + myHost + "kevindubois.com/index.php?referral="+referral_code+"' style='text-decoration:none;color:white'%3E"));

     document.write(unescape("%3Cdiv style='border-top:5px solid #0F0442; width:"+ad_width+"px; background-color:#FF6204; color:#FFF; padding-bottom:10px '%3E"));
     document.write(unescape("%3Cul%3E"));    
     document.write(unescape("%3Cli style='margin-left:-15px'%3EThis is a demo for %3Ca href='http://kevindubois.com/blog/2009/11/16/creating-advertisement-widgets-for-3rd-party-websites'%3Ehttp://kevindubois.com/blog/2009/11/16/creating-advertisement-widgets-for-3rd-party-websites%3C/a%3E%3C/li%3E"));    
     document.write(unescape("%3Cli style='margin-left:-15px'%3bla bla bla%3C/li%3E"));    
     document.write(unescape("%3Cli style='margin-left:-15px'%3Ebla bla bla%3C/li%3E"));    
     document.write(unescape("%3Cli style='margin-left:-15px'%3Ebla bla bla%3C/li%3E"));    
     document.write(unescape("%3C/ul%3E  "));    
     document.write(unescape("%3Cdiv style='text-align:center;font-weight:bold; font-size:12px; '%3E LEARN MORE %3C/div%3E"));    
     document.write(unescape("%3C/div%3E"));    
     document.write(unescape("%3C/a%3E"));    
     document.write(unescape("%3C/div%3E"));
   break;

   // and so on ...
}</pre>
<p>The only thing I haven&#039;t mentioned is the links and the referral code: you can track widgets and clicks from each 3rd party by supplying a referral code.  The link within the widget has this referral code and in the linked page you can then write some code to track/count/whatever you want.<br />
From here on, I think you should have all the tools to start customizing your own widget.  You can make everything even more dynamic by using some ajax; you can add more parameters or really any content you want.</p>
<p>You can find a demo for the 2nd widget at <a title="widget2" href="http://www.kevindubois.com/demos/widget2.html" target="_blank">http://www.kevindubois.com/demos/widget2.html</a> (the js code is at <a title="widget1 javascript" href="http://www.kevindubois.com/demos/js/mywidget2.js" target="_blank">http://www.kevindubois.com/demos/js/mywidget2.js</a>)</p>
<p class="buymebeer"><form action="https://www.paypal.com/cgi-bin/webscr" target="paypal" method="post"><input type="hidden" name="cmd" value="_xclick" /><input type="hidden" name="business" value="kevin.dubois@gmail.com" /><input type="hidden" name="return" value="" /><input type="hidden" name="item_name" value="Buy Me a Beer for Creating an advertisement widget for external websites using JavaScript" /><input type="hidden" name="currency_code" value="USD" /><input type="hidden" name="amount" value="3" /><input type="image" src="http://kevindubois.com/blog/wp-content/plugins/buy-me-beer/icon_beer.gif" align="left" alt="" title="" hspace="3" /></form><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&amp;business=kevin.dubois@gmail.com&amp;currency_code=USD&amp;amount=3&amp;return=&amp;item_name=Buy+Me+a+Beer+for+Creating+an+advertisement+widget+for+external+websites+using+JavaScript" target="paypal">Was this post helpful? You can help me by buying me a beer :-)</a></p>]]></content:encoded>
			<wfw:commentRss>http://kevindubois.com/blog/2009/11/16/creating-advertisement-widgets-for-3rd-party-websites/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Curly Quote / Apostrophe in Wordpress</title>
		<link>http://kevindubois.com/blog/2009/03/16/curly-quote-apostrophe-in-wordpress/</link>
		<comments>http://kevindubois.com/blog/2009/03/16/curly-quote-apostrophe-in-wordpress/#comments</comments>
		<pubDate>Mon, 16 Mar 2009 23:53:09 +0000</pubDate>
		<dc:creator>Kevin Dubois</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[apostrophes]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[quotes]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://kevindubois.com/blog/2009/03/16/curly-quote-apostrophe-in-wordpress/</guid>
		<description><![CDATA[When a user reported that some of my code snippets didn&#039;t work I noticed that the apostrophes in Wordpress are automatically changed to curly quotes.  That obviously brakes the code when php tries to parse it.  I did some googling and found a simple solution: The &#034;Unfancy Quotes&#034; plugin which can be found [...]]]></description>
			<content:encoded><![CDATA[<p>When a user reported that some of my code snippets didn&#039;t work I noticed that the apostrophes in Wordpress are automatically changed to curly quotes.  That obviously brakes the code when php tries to parse it.  I did some googling and found a simple solution: The &#034;Unfancy Quotes&#034; plugin which can be found here: <a title="here" href="http://www.semiologic.com/software/wp-tweaks/unfancy-quote/" target="_blank">http://www.semiologic.com/software/wp-tweaks/unfancy-quote/</a></p>
<p class="buymebeer"><form action="https://www.paypal.com/cgi-bin/webscr" target="paypal" method="post"><input type="hidden" name="cmd" value="_xclick" /><input type="hidden" name="business" value="kevin.dubois@gmail.com" /><input type="hidden" name="return" value="" /><input type="hidden" name="item_name" value="Buy Me a Beer for Curly Quote / Apostrophe in Wordpress" /><input type="hidden" name="currency_code" value="USD" /><input type="hidden" name="amount" value="3" /><input type="image" src="http://kevindubois.com/blog/wp-content/plugins/buy-me-beer/icon_beer.gif" align="left" alt="" title="" hspace="3" /></form><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&amp;business=kevin.dubois@gmail.com&amp;currency_code=USD&amp;amount=3&amp;return=&amp;item_name=Buy+Me+a+Beer+for+Curly+Quote+/+Apostrophe+in+Wordpress" target="paypal">Was this post helpful? You can help me by buying me a beer :-)</a></p>]]></content:encoded>
			<wfw:commentRss>http://kevindubois.com/blog/2009/03/16/curly-quote-apostrophe-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Group TD (table data) without using rowspan when left joining in mySQL</title>
		<link>http://kevindubois.com/blog/2008/10/30/group-td-table-data-without-using-rowspan-when-left-joining-in-mysql/</link>
		<comments>http://kevindubois.com/blog/2008/10/30/group-td-table-data-without-using-rowspan-when-left-joining-in-mysql/#comments</comments>
		<pubDate>Thu, 30 Oct 2008 15:43:59 +0000</pubDate>
		<dc:creator>Kevin Dubois</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[group]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[left join]]></category>
		<category><![CDATA[linkedin]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[td]]></category>
		<category><![CDATA[tr]]></category>

		<guid isPermaLink="false">http://kevindubois.com/blog/?p=6</guid>
		<description><![CDATA[When outputting data from a database using left joins you often get redundant data in your output.  Say you have a table with vendor information, and a second table containing the customers for each vendor.  If you want to display a table with the vendor names and their customers, you&#039;ll most likely want to use [...]]]></description>
			<content:encoded><![CDATA[<p>When outputting data from a database using left joins you often get redundant data in your output.  Say you have a table with vendor information, and a second table containing the customers for each vendor.  If you want to display a table with the vendor names and their customers, you&#039;ll most likely want to use a left join.</p>
<p>The problem is, when you output your data you&#039;ll repeat the vendor name for each customer they have.  It makes the table look cluttered and hard to read.  Not to worry though, there is an easy solution!</p>
<p>All you have to do is create 2 classes:</p>
<blockquote><p><span style="color: #800080;">.noblanktd{color:inherit; border-top:1px solid #000; border-top:1px solid #000}<br />
.blanktd{color:white; }</span></p></blockquote>
<p>and here&#039;s the php code:</p>
<blockquote><p><span style="color: #800080;">function outputmystuff(){<br />
// get your data here eg<br />
$query = &#034;SELECT v.id, v.name as vendorname, c.name as customername FROM vendors as v LEFT JOIN customers as c ON v.id = c.vendor_id&#034;;<br />
$result = mysql_query($query);<br />
</span></p>
<p><span style="color: #800080;">$oldID = false;<br />
while($row = mysql_fetch_assoc($result)){<br />
$ID = $row['id'];<br />
if($oldID == $ID){<br />
$class = &#039;blanktd&#039;;<br />
} else{<br />
$class = &#034;noblanktd&#034;;<br />
}<br />
$returnval .= &lt;&lt;&lt;EOD<br />
&lt;tr&gt;<br />
&lt;td class=&#034;{$class}&#034;&gt;{$row['vendorname']}&lt;/td&gt;<br />
&lt;td class=&#034;noblanktd&#034;&gt;{$row['customername']}&lt;/td&gt;<br />
&lt;/tr&gt;<br />
EOD;<br />
$oldID = $ID;</span></p>
<p><span style="color: #800080;">}</span></p>
<p><span style="color: #800080;">return $returnval;</span></p>
<p><span style="color: #800080;">}</span></p></blockquote>
<p>and last but not least the html</p>
<blockquote><p><span style="color: #800080;">&lt;table class=&#034;repTable&#034;&gt;<br />
&lt;tr&gt;<br />
&lt;th&gt;Vendor Name&lt;/th&gt;<br />
&lt;th&gt;Customer Name&lt;/th&gt;<br />
&lt;/tr&gt;<br />
&lt;?=outputmystuff()?&gt;<br />
&lt;/table&gt;</span></p></blockquote>
<p class="buymebeer"><form action="https://www.paypal.com/cgi-bin/webscr" target="paypal" method="post"><input type="hidden" name="cmd" value="_xclick" /><input type="hidden" name="business" value="kevin.dubois@gmail.com" /><input type="hidden" name="return" value="" /><input type="hidden" name="item_name" value="Buy Me a Beer for Group TD (table data) without using rowspan when left joining in mySQL" /><input type="hidden" name="currency_code" value="USD" /><input type="hidden" name="amount" value="3" /><input type="image" src="http://kevindubois.com/blog/wp-content/plugins/buy-me-beer/icon_beer.gif" align="left" alt="" title="" hspace="3" /></form><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&amp;business=kevin.dubois@gmail.com&amp;currency_code=USD&amp;amount=3&amp;return=&amp;item_name=Buy+Me+a+Beer+for+Group+TD+(table+data)+without+using+rowspan+when+left+joining+in+mySQL" target="paypal">Was this post helpful? You can help me by buying me a beer :-)</a></p>]]></content:encoded>
			<wfw:commentRss>http://kevindubois.com/blog/2008/10/30/group-td-table-data-without-using-rowspan-when-left-joining-in-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
