<?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>Plyplemadesign.com.au &#187; programming</title>
	<atom:link href="http://plyplemadesign.com.au/blog/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://plyplemadesign.com.au/blog</link>
	<description>Website design, software programming and development, AMX control system programming, photography, graphics design, internet marketing</description>
	<lastBuildDate>Wed, 23 Feb 2011 04:48:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.3</generator>
		<item>
		<title>How to Add Google AdSense Under Post Titles</title>
		<link>http://plyplemadesign.com.au/blog/programming/how-to-add-google-adsense-under-post-titles/</link>
		<comments>http://plyplemadesign.com.au/blog/programming/how-to-add-google-adsense-under-post-titles/#comments</comments>
		<pubDate>Wed, 06 May 2009 12:59:18 +0000</pubDate>
		<dc:creator>Troy</dc:creator>
				<category><![CDATA[Blogging]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Adsense]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[sem]]></category>
		<category><![CDATA[seo]]></category>

		<guid isPermaLink="false">http://plyplemadesign.com.au/blog/?p=55</guid>
		<description><![CDATA[In several of my blogs I have created for search engine optimization and marketing experimentation I have monetized them using the popular Google Adsense. One of Adsense&#8217;s limitations is that it is limited to only 3 ad units per page. These units need to be strategically positioned for maximum exposure and highest click through rate. [...]]]></description>
			<content:encoded><![CDATA[<p>In several of my blogs I have created for search engine optimization and marketing experimentation I have monetized them using the popular Google Adsense.  One of Adsense&#8217;s limitations is that it is limited to only 3 ad units per page.  These units need to be strategically positioned for maximum exposure and highest click through rate.  The position I choose is to have a letterbox unit positioned directly under the title of individual posts.  This means that a reader will have to view the ad before moving onto the content.  I also see a lot of questions on how to actually get the ads onto the site.</p>
<p>There are many plugins available to display Google Adsense on a WordPress blog but the one I choose to use is Simple Adsense Insertion (SAI).  To use this plugin you simply insert your Adsense campaign code into one of the SAI campaigns and then use the provided tags (<!- - wp_ad_camp_1 - -> or &#8220;echo show_ad_camp_1();&#8221;) to position them throughout your site.</p>
<p>To display an ad unit under the title of each post you will need to edit your themes template:<br />
<span id="more-55"></span><br />
1.  Go to you WordPress Admin page.<br />
2.  Download and install Simple Adsense Insertion using the built in plugin browser.</p>
<div id="attachment_56" class="wp-caption aligncenter" style="width: 596px"><a href="http://plyplemadesign.com.au/blog/wp-content/uploads/2009/05/sai.png"><img class="size-full wp-image-56" title="Simple Adsense Insertion Settings" src="http://plyplemadesign.com.au/blog/wp-content/uploads/2009/05/sai.png" alt="Simple Adsense Insertion Settings" width="586" height="125" /></a><p class="wp-caption-text">Simple Adsense Insertion Settings</p></div>
<p>3.  Go to the plugin settings for Simple Adsense Insertion and add in your Google Adsense code and copy down the tag for your campaign &#8220;echo show_ad_camp_1();&#8221; for example.</p>
<div id="attachment_57" class="wp-caption aligncenter" style="width: 176px"><a href="http://plyplemadesign.com.au/blog/wp-content/uploads/2009/05/editor.png"><img class="size-full wp-image-57" title="Theme Template Editor" src="http://plyplemadesign.com.au/blog/wp-content/uploads/2009/05/editor.png" alt="Theme Template Editor" width="166" height="366" /></a><p class="wp-caption-text">Theme Template Editor</p></div>
<p>4.  You now need to modify the templates to insert your campaign onto your site.  Browse to &#8220;Appearance &gt; Editor&#8221;</p>
<div id="attachment_58" class="wp-caption aligncenter" style="width: 207px"><a href="http://plyplemadesign.com.au/blog/wp-content/uploads/2009/05/templates.png"><img class="size-full wp-image-58" title="Theme Template List" src="http://plyplemadesign.com.au/blog/wp-content/uploads/2009/05/templates.png" alt="Theme Template List" width="197" height="346" /></a><p class="wp-caption-text">Theme Template List</p></div>
<p>5.  On the right hand side of the page you need to select the Main Index Template (index.php).  This is the main file for your public site so be careful not to modify the wrong thing.  If you are unsure on how to backup the file off an FTP then I recommend copying all of the text from the text-area into notepad and saving it for safe keeping.  If things go wrong you can always copy the text back.</p>
<p>6. The next step will vary slightly depending on the theme that you use and the way it outputs the posts.  You need to browse through the index.php file and find where the content of a post is sent to the browser.  The easiest to find this is use your browsers find function and look for &#8220;<em><span style="color: #3366ff;">the_content(</span></em>&#8220;.   This should be positioned in between a &lt;div&gt; tag with an id of something like &#8220;content&#8221;, &#8220;entry&#8221;, or &#8220;story&#8221;.  This is all theme dependant.</p>
<p>To display your ad unit before the post&#8217;s content  simply add &#8220;<em><span style="color: #3366ff;">&lt;?php echo show_ad_camp_1(); ?&gt;</span></em>&#8221; before &#8220;<em><span style="color: #3366ff;">the_content(</span></em>&#8221; but after the opening <em><span style="color: #3366ff;">&lt;div id=&#8221;content&#8221;&gt;</span></em>.<br />
7.  You can now save the changes to the file and have a look at the result on your home page.  There should be a Google Ad Unit displayed before the content of each post now.</p>
<p>One of the problems of adding the ad unit to each post is that Google only lets you display three units per page.  If you look at posts after the top 3 you will either have a large chunk of space or a non paying ad in its place, depending on your Google AdSense settings.</p>
<p>To get around this problem a counter can be added to the index.php inside the loop that makes the posts.  When this counter is less than 4 display a Google Ad, when it is equal or greater display nothing (without the large blank space) or display an ad from another affiliate.</p>
<p>Adding a counter is quite simple.  Firstly find the start of the loop used to display posts.  For most themes it will look something like</p>
<p><em><span style="color: #3366ff;">&lt;?php while (have_posts()) : the_post(); ?&gt;</span></em></p>
<p>Directly above  this line add the following code so it looks like this:</p>
<p><em><span style="color: #3366ff;">&lt;?php $totalPosts = 0; ?&gt;</span><br />
&lt;?php while (have_posts()) : the_post(); ?&gt;</em></p>
<p>To increment the totalPosts  counter add the following code directly under the opening of the while loop:</p>
<p><em>&lt;?php $totalPosts = 0; ?&gt;<br />
&lt;?php while (have_posts()) : the_post(); ?&gt;</em><br />
<em><span style="color: #3366ff;">&lt;?php $totalPosts++; ?&gt;</span></em></p>
<p>Now go down to where you added &#8220;<em>&lt;?php echo show_ad_camp_1();  ?&gt;</em>&#8220;.  Change this to:</p>
<p><em><span style="color: #3366ff;">&lt;?php<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if( $totalPosts &lt;= 3 )<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo show_ad_camp_1();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//add other ad campaigns here<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
?&gt;</span></em></p>
<p>If you have other ads to display that use php code then simply place that code inside the else statement {}.</p>
<p>Save these changes and go and look at your home page now.  It will no longer have blank spots or ugly unwanted ads on post four and after.</p>
]]></content:encoded>
			<wfw:commentRss>http://plyplemadesign.com.au/blog/programming/how-to-add-google-adsense-under-post-titles/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Base64&#8242;ing in AMX NetLinx &#8211; Part 1 &#8211; Encoding</title>
		<link>http://plyplemadesign.com.au/blog/programming/base64ing-in-amx-netlinx-part-1-encoding/</link>
		<comments>http://plyplemadesign.com.au/blog/programming/base64ing-in-amx-netlinx-part-1-encoding/#comments</comments>
		<pubDate>Wed, 29 Apr 2009 12:08:09 +0000</pubDate>
		<dc:creator>Troy</dc:creator>
				<category><![CDATA[AMX]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://plyplemadesign.com.au/blog/?p=31</guid>
		<description><![CDATA[While working on an AMX project involving a lot of HTTP requests I came across some methods that required Basic Authentication. In regards to HTTP, Basic Authentication allows for a web client, such as a browser, to provider user credentials to the server when making a request. A colon &#8216;:&#8217; is appended to the user [...]]]></description>
			<content:encoded><![CDATA[<p>While working on an AMX project involving a lot of HTTP requests I came across some methods that required Basic Authentication.  In regards to HTTP, Basic Authentication allows for a web client, such as a browser, to provider user credentials to the server when making a request.  A colon &#8216;:&#8217; is appended to the user name and concatenated with the password before having Base64 encoding applied and sent off in the HTTP header to the server.  The server then receives and decodes the message to retrieve the original user name and password.</p>
<p>Most browsers natively support Base64 encoding and a lot of programming languages either support or have libraries already built to add the support to make Base64 encoding a simple hurdle to jump while programming on a PC.  Unfortunately, AMX NetLinx has no such libraries or modules so the encoding needs to be added to each project.</p>
<p>This article will give you the functions required to add Base64 encoding to your next HTTP project.  Also stay tuned for Part 2 which will give you the functions required to decode a Base64 string.<br />
<span id="more-31"></span><br />
Base64 was created from the problems caused when binary files were needed to be encapsulated in other documents.  A binary file can contain many zeroes and as we know from various issues with NetLinx, zeroes represent the end of strings or end of files for many different documents and programs.  The binary bytes also have the chance of representing reserved or special characters that may cause misrepresentation in the document.</p>
<p>Base64 solved this problem by representing the data as one of a 64 character alphabet ( 0-9, a-z, A-Z, +, / ).  Base64 works by converting the binary data into 6-bit long chunks which then gives you a value between 0 and 63 when represented as a decimal.  This value represents one of the letters in the Base64 alphabet.  It also compresses the original data 6:1.</p>
<p>This works really efficiently when the binary data being encoded is divisible by 3 bytes but when not problems can occur.  Diving any number by 3 will always results in 3 different scenarios.  There will either be no remainder, a remainder of 1 and a remainder of 2.  The problems occur  in the last 2 situations.  The solution is rather simple and might appear as common sense to some but to turn the 1 byte with 2 remainders to a 3 byte sequence simply pad an extra two bytes of zeroes onto the end.  This 3 byte sequence can now be divided into 4 Base64 characters.  The character used to represent the 0000&#8242;s is an &#8216;=&#8217;.  The same is done when there is one byte remaining.  Add one byte of zeroes and divided the new sequence by 4.</p>
<p>Another requirement of Base64 implementation is that specifies a maximum line length of 76 characters.  Lines can be delimited by a carriage return and line feed to encode long data.</p>
<p>The NetLinx code for encoding is broken up into two different functions.  The first function is used to encode a byte into its Base64 equivalent.  Each byte is offset by a different printable char to put it within the printable range.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">define_function char fnBase64_helperEncode( char c )
{
     if (c &lt; 26)
     {
          return 'A' + c
     }
     if (c &lt; 52)
     {
          return 'a' + (c - 26)
     }
     if (c &lt; 62)
     {
          return '0' + (c - 52)
     }
     if (c == 62)
     {
          return '+'
     }
     return '/'
}</pre></td></tr></table></div>

<p>The following function is the main process used to encode the inputted string into its Base64 representation.  The function takes 3 bytes of the string and converts it using bit shifting to four 6 bit chunks.  These 6 bit chunks are then converted to Base64 and appended to the return string.  The string is checked to see if the length has reached 76 characters and if so a carriage return and line feed is appended as specified.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">define_function char[1024] fnBase64_encode( char strIn[1024] )
{
     stack_var char strReturn[1024]
     stack_var integer i
     stack_var integer len
     stack_var char by1,by2,by3,by4,by5,by6,by7
&nbsp;
     len = length_string(strIn)
     if( len == 0 )
     {
          return strReturn;
     }
     for( i = 1; i &lt;= len; i = i + 3 )
     {
          by1 = 0
          by2 = 0
          by3 = 0
          by4 = 0
          by5 = 0
          by6 = 0
          by7 = 0
          by1 = strIn[i]
&nbsp;
          if( i + 1 &lt;= len )
          {
               by2 = strIn[i+1]
          }
          if( i + 2 &lt;= len )
          {
               by3 = strIn[i+2]
          }
&nbsp;
          by4 = type_cast( by1 &gt;&gt; 2 )
          by5 = type_cast( (( by1 &amp; $03) &lt;&lt; 4) | (by2 &gt;&gt; 4) )
          by6 = type_cast( (( by2 &amp; $0F) &lt;&lt; 2) | (by3 &gt;&gt; 6) )
          by7 = type_cast( by3 &amp; $3F )
&nbsp;
          strReturn = &quot;strReturn, fnBase64_helperEncode(by4)&quot;
          strReturn = &quot;strReturn, fnBase64_helperEncode(by5)&quot;
          if( i+1 &lt;= len)
          {
               strReturn = &quot;strReturn, fnBase64_helperEncode(by6)&quot;
          }
          else
          {
               strReturn = &quot;strReturn, '='&quot;
          }
&nbsp;
          if( i+2 &lt;= len)
          {
               strReturn = &quot;strReturn, fnBase64_helperEncode(by7)&quot;
          }
          else
          {
               strReturn = &quot;strReturn, '='&quot;
          }
          if ((len % 76) == 0)
          {
               strReturn = &quot;strReturn, $0D, $0A&quot;
          }
     }
     return strReturn
}</pre></td></tr></table></div>

<p><span style="color: #808080;"><br />
</span>These functions can be now used for Basic Authorisation in HTTP headers or for more advanced features such as emailing binary files over the AMX NetLinx platform.  This article will be followed up with the functions required to reverse the process and decode a Base64 string into its original form.</p>
<p>If you have any questions or requests about other HTTP features you need clarifying for your AMX project then feel free to send me an email or post a comment here and I will look to covering it in the future.</p>
]]></content:encoded>
			<wfw:commentRss>http://plyplemadesign.com.au/blog/programming/base64ing-in-amx-netlinx-part-1-encoding/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

