<?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>Myatu&#039;s</title>
	<atom:link href="http://myatus.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://myatus.com</link>
	<description>Wasting bits and bytes daily</description>
	<lastBuildDate>Fri, 12 Apr 2013 13:41:08 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Watching TV on your Android via a Raspberry Pi</title>
		<link>http://myatus.com/p/watching-tv-on-your-android-via-a-raspberry-pi/</link>
		<comments>http://myatus.com/p/watching-tv-on-your-android-via-a-raspberry-pi/#comments</comments>
		<pubDate>Tue, 02 Apr 2013 20:04:30 +0000</pubDate>
		<dc:creator>Myatu</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[raspberrypi]]></category>
		<category><![CDATA[tv]]></category>

		<guid isPermaLink="false">http://myatus.com/?p=4614</guid>
		<description><![CDATA[During the long Easter holiday I&#8217;ve kept myself busy with a little pet project for my Raspberry Pi. So far I&#8217;ve been using the RPI as a small intranet server, DNS server and Proxy server. But it had plenty of &#8230; <a href="http://myatus.com/p/watching-tv-on-your-android-via-a-raspberry-pi/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><a href="http://myatus.com/wp-content/uploads/2013/04/TV-Screenshot.png"><img class="alignright size-thumbnail wp-image-4624" style="margin: 10px; display: block;" alt="Screenshot of XBMC Live TV" src="http://myatus.com/wp-content/uploads/2013/04/TV-Screenshot-150x150.png" width="150" height="150" /></a>During the long Easter holiday I&#8217;ve kept myself busy with a little pet project for my Raspberry Pi. So far I&#8217;ve been using the RPI as a small intranet server, DNS server and Proxy server. But it had plenty of room, both in RAM and storage, to do other things. As I had recently acquired a (dirt-cheap!) Android-based tablet, I was wondering if it would be possible to stream live TV directly to it.</p>
<p>There are plenty of commercial solutions available, as well as some apps, that stream directly over the Internet. But, as I had mentioned, the tablet was dirt cheap and so it should be indicative of the amount of money I was willing to spend.<span id="more-4614"></span></p>
<p>I already owned a USB TV stick, which I used on my laptop, and wanted to use this as the receiver. It&#8217;s a <a title="PCTV Nanostick T2" href="http://www.pctvsystems.com/Products/ProductsEuropeAsia/DVBTT2products/PCTVnanoStickT2/tabid/248/language/en-GB/Default.aspx" target="_blank">PCTV Nanostick T2</a>, based on the Sony CXD2820R demodulator, which is (or was?) the only device to support the UK&#8217;s DVB-T2 format for HD reception.</p>
<p>The USB TV stick is directly supported by the 3.x kernel (as an em28xx device), and naturally, the RPI did too. So it was a matter of finding what software would stream from the TV source over the network, and what software that would be able to accept and display this stream &#8211; particularly on an Android device.</p>
<p><span class="label label-info">Heads up!</span> While the Raspberry Pi will detect the USB TV stick that is directly connected to it, it cannot provide enough power to it. This means it will not be able to tune into any channels. So the USB TV stick <strong>must</strong> be attached to a self-powered USB hub (which in turn is connected to the RPI, of course).</p>
<p>This is where <a title="XBMC" href="http://xbmc.org/" target="_blank">XBMC</a> comes into play. Since version 12 of XBMC (&#8220;Frodo&#8221;), it is now possible to watch live TV via a PVR back-end. What&#8217;s great too, is that XBMC runs on a plethora of operating systems and devices, including Android. The app is not yet available in the Google Play store, so you need to <a title="XBMC Downloads" href="http://xbmc.org/download/" target="_blank">manually download</a> and install it. Just note, that before you install it on your Android, you may need to enable the <em>Unknown sources</em> option found under the Android&#8217;s system settings (under the <em>Security</em> tab).</p>
<h2>Tvheadend</h2>
<p>So with the &#8220;front-end&#8221; sorted, all I needed was the back-end for the Raspberry Pi. I settled on using <a title="Tvheadend" href="https://tvheadend.org/projects/tvheadend" target="_blank">Tvheadend</a>, because it is very lightweight and runs on the ARM device just fine. However, I didn&#8217;t install it from binary as, well, there wasn&#8217;t one available &#8211; at least not in individual form. Compiling is a breeze though, and the developers already have everything available for a .DEB package. I skipped building a .DEB package, simply for sake of simplicity, but used their init script, config files, etc.</p>
<p>To compile Tvheadend, you start by getting the necessary packages. Some I will list here are optional, but I prefer to cram as much &#8220;optional&#8221; stuff into a build, so I won&#8217;t need to recompile everything it when I do need it at one point.</p>
<pre class="prettyprint linenums">sudo apt-get install git build-essential \
  libavcodec-dev libavformat-dev libssl-dev \
  libavutil-dev libavahi-client-dev libcurl3 \
  w-scan</pre>
<p>After the packages have been installed, proceed to clone the source code of Tvheadend using git. This will create a directory called <em>tvheadend</em> based on the location where you are, generally <em>/home/pi/</em> if you&#8217;ve logged in via SSH.</p>
<pre class="prettyprint linenums">git clone git://github.com/tvheadend/tvheadend.git</pre>
<p>Now proceed to the directory and run the initial configuration. Running the configuration will check if you have the required packages installed, and fetch DVB scan data from a remote server.</p>
<pre class="prettyprint linenums">cd tvheadend
./configure</pre>
<p>If everything went well, you should not have received any fatal errors. You may see a few &#8220;fail&#8221; messages, but these are benign.</p>
<p>As I live in the London area, the Freeview transmitter is Crystal Palace. However, the source from which the configuration obtains the DVB scan data appears to be slightly outdated and may cause some hiccups. In my case, I&#8217;ve simply provided my own scan data using the previously installed <em>w_scan</em> application. You may skip this, if it doesn&#8217;t apply to you.</p>
<pre class="prettyprint linenums">w_scan -cGB -x &gt; ./data/dvb-scan/dvb-t/uk-CrystalPalace</pre>
<p>This will directly replace the file in <em>tvheadend/data/dvb-scan/dvb-t/uk-CrystalPalace</em>, so if you&#8217;re concerned, you may wish to make a copy first.</p>
<p>Then proceed to compile Tvheadend, which for obvious reasons will take a little longer on a Raspberry Pi than a conventional computer:</p>
<pre class="prettyprint linenums">make clean &amp;&amp; make</pre>
<h3>Installation</h3>
<p>Once it has been completed, you&#8217;re ready to install it. As mentioned earlier, Tvheadend already contains everything needed to build a .DEB package from which you could install it. However, I chose not to, and simply used some of the existing files to install it manually:</p>
<pre class="prettyprint linenums">sudo su
make install
ln -s /usr/local/bin/tvheadend /usr/bin/tvheadend
cp ./debian/tvheadend.init /etc/init.d/tvheadend
chmod +x /etc/init.d/tvheadend
update-rc.d tvheadend defaults

cp ./debian/tvheadend.default /etc/default/tvheadend
adduser --quiet --system --group --shell /bin/bash hts
mkdir -p "/home/hts/.hts/tvheadend"
cat &gt; /home/hts/.hts/tvheadend/superuser &lt;&lt;EOF
{
"username": "superadmin",
"password": "MySuperSecretPassword"
}
EOF
chmod 600 /home/hts/.hts/tvheadend/superuser
chown -R hts:hts "/home/hts/.hts"
exit</pre>
<p><span class="label label-info">Heads up!</span> The one thing that you should pay attention to, is the portion here it creates the <em>/home/hts/.hts/tvheadend/superuser</em> file. The username and password provided here are only for sample purposes, and you should change this to something you&#8217;ve thought up yourself.</p>
<p>If you have a firewall setup on your RPI (and you should!), remember to open up the TCP ports 9981 and 9982 for the appropriate network. UDP is not required.</p>
<h3>Configuration</h3>
<p>Now that you have installed it, fire up Tvheadend:</p>
<pre class="prettyprint linenums">sudo service tvheadend start</pre>
<p>And configure it further at <em>http://(ip address or domain name of your PI):9981</em>. You will be prompted for a username and password, which was provided earlier in the <em>superuser</em> file.</p>
<p>Some guidance for configuration can be found in <a title="XBMC Quick Install Guide" href="http://wiki.xbmc.org/index.php?title=PVR/Backend/Tvheadend#Tvheadend_quick_start_guide" target="_blank">XBMC&#8217;s Wiki</a> - it does not mention that after you&#8217;ve selected DVB input, you should tick the box <em>Enabled</em> found in the <em>Adapter Configuration</em> box, and then save the settings before it will perform an initial scan. You can follow its progress by expanding the window at the bottom (click the chevrons pointing upwards in the bottom-right corner).</p>
<p>Additionally, you need to setup the <em>Access Control</em> list, also found in the <em>Configuration</em> area, to allow/restrict access from devices. This is explained in more detail in the <a title="Tvheadend - Access configuation" href="https://tvheadend.org/projects/tvheadend/wiki/Access_configuration" target="_blank">Tvheadend Wiki</a>.</p>
<p>After this, you can configure XBMC, by going into its system settings, and enabling the <em>Tvheadend HTSP Client</em> add-on. Once that has been enabled, click <em>Configure</em> for it, and provide the necessary details, which at minimum is the IP or domain name for the Raspberry Pi. Finally, still within XBMC&#8217;s system settings, enable Live TV. You are now able to watch live TV! Unless &#8230;</p>
<h2>Bugs!</h2>
<p>There&#8217;s a bug with the Raspberry Pi firmware related to its USB. Or, there&#8217;s a problem with the USB itself. Either way, it affects many video streaming devices, such as webcams and TV USB sticks (like the em28xx devices). The result is that you may find yourself rather annoyed by the fact that live TV is barely &#8220;live&#8221;, and mostly consists of black screens or what appears to be a very bad signal. Looking at the logs for Tvheadend, you may notice many lines similar to this:</p>
<pre>Apr 1 21:45:02 raspberrypi tvheadend[13259]: TS: Sony CXD2820R/London: 490,000 kHz/BBC ONE: MPEG2AUDIO @ #102: Continuity counter error, 533 duplicate log lines suppressed
Apr 1 21:45:03 raspberrypi tvheadend[13259]: TS: Sony CXD2820R/London: 490,000 kHz/BBC ONE: MPEG2VIDEO @ #101: Continuity counter error, 5777 duplicate log lines suppressed
Apr 1 21:45:03 raspberrypi tvheadend[13259]: TS: Sony CXD2820R/London: 490,000 kHz/BBC ONE: MPEG2AUDIO @ #106: Continuity counter error, 121 duplicate log lines suppressed
Apr 1 21:45:03 raspberrypi tvheadend[13259]: TS: Sony CXD2820R/London: 490,000 kHz/BBC ONE: MPEG2AUDIO @ #102: Continuity counter error, 534 duplicate log lines suppressed</pre>
<p>Thankfully, this problem has been addressed by the Raspbian teams, and requires that you update your kernel (firmware). You can double-check the current version, which will likely produce something similar to this:</p>
<pre class="prettyprint linenums"># uname -a
Linux raspberrypi 3.6.11+ #371 PREEMPT Thu Feb 7 16:31:35 GMT 2013 armv6l GNU/Linux</pre>
<p>The important bit is the <em>#371</em> part here, which is the one that has the above described issue. Updating the kernel/firmware is slightly different than what you&#8217;d expect from most Debian distributions (which is simply apt-get a linux image), but <a title="rpi-update" href="https://github.com/Hexxeh/rpi-update" target="_blank">Liam McLoughlin has created a simple script</a> to help you with that. Here&#8217;s a quick how-to:</p>
<pre class="prettyprint linenums">sudo wget http://goo.gl/1BOfJ -O /usr/bin/rpi-update &amp;&amp; sudo chmod +x /usr/bin/rpi-update
sudo rpi-update</pre>
<p>Just let it run its course, which involves updating itself and then obtaining the latest firmware. If this is the first time you&#8217;ve run it, it will download about 42 Megabytes worth of files. After it has successfully completed downloading and installing, you need to reboot the Raspberry Pi. Once back up, the kernel/firmware version should have been updated to at least the following:</p>
<pre class="prettyprint linenums"># uname -a
Linux raspberrypi 3.6.11+ #401 PREEMPT Fri Mar 29 22:59:09 GMT 2013 armv6l GNU/Linux</pre>
<p>Again, the important part here is the <em>#401</em>, changed from the previous <em>#371</em>.</p>
<p>&nbsp;</p>
<div class="alert alert-info"><strong>NOTE:</strong> If you still have all the original Raspbian bells and whistles installed, such as X-server/Gnome, then before you reboot the RPI, double check your available disk space.</div>
]]></content:encoded>
			<wfw:commentRss>http://myatus.com/p/watching-tv-on-your-android-via-a-raspberry-pi/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Background Manager screencast by Untame</title>
		<link>http://myatus.com/p/background-manager-screencast-by-untame/</link>
		<comments>http://myatus.com/p/background-manager-screencast-by-untame/#comments</comments>
		<pubDate>Sat, 09 Mar 2013 09:17:22 +0000</pubDate>
		<dc:creator>Myatu</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[background-manager]]></category>

		<guid isPermaLink="false">http://myatus.com/?p=4603</guid>
		<description><![CDATA[Brock Nunn of Untame has written a great article about Background Manager, which includes a screen cast on how to get started with the plugin &#8211; shown above.]]></description>
				<content:encoded><![CDATA[<p>Brock Nunn of <a title="Untame" href="http://www.untame.net/" target="_blank">Untame</a> has written <a title="How To Create Full Screen Background Images In WordPress" href="http://untame.net/2013/02/wordpress-easy-full-screen-background-images/" target="_blank">a great article</a> about <a title="Background Manager" href="http://myatus.com/projects/background-manager/">Background Manager</a>, which includes a screen cast on how to get started with the plugin &#8211; shown above.</p>
]]></content:encoded>
			<wfw:commentRss>http://myatus.com/p/background-manager-screencast-by-untame/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cookie law: To opt in or to opt out</title>
		<link>http://myatus.com/p/cookie-law-to-opt-in-or-to-opt-out/</link>
		<comments>http://myatus.com/p/cookie-law-to-opt-in-or-to-opt-out/#comments</comments>
		<pubDate>Sun, 08 Jul 2012 17:23:14 +0000</pubDate>
		<dc:creator>Myatu</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[cookies]]></category>

		<guid isPermaLink="false">http://myatus.com/?p=4586</guid>
		<description><![CDATA[Since May 26 of 2012, the infamous &#8220;cookie law&#8221; has been in effect in the United Kingdom. While there have been many questions regarding its implementation on websites, most have settled on the &#8220;implied consent&#8221; method, as it was easiest &#8230; <a href="http://myatus.com/p/cookie-law-to-opt-in-or-to-opt-out/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Since May 26 of 2012, the infamous &#8220;<a title="Cookie Regulations and the new EU Law - ICO" href="http://www.ico.gov.uk/for_organisations/privacy_and_electronic_communications/the_guide/cookies.aspx" target="_blank">cookie law</a>&#8221; has been in effect in the United Kingdom. While there have been many questions regarding its implementation on websites, most have settled on the &#8220;implied consent&#8221; method, as it was easiest to implement and had the least amount of impact on the visitors.</p>
<p>Using <a title="Cookillian" href="http://myatus.com/projects/cookillian/" target="_blank">Cookillian</a> on my own website, I had initially decided on using the strict method. It barred cookies outright and required the visitor to make an explicit decision about cookies. With this method, the average between opt in and out was nearly 50:50 down the middle. For June, I decided to change from explicit to implied consent, and as seen in the statistics below this changed the numbers significantly:<span id="more-4586"></span></p>
<p><img class="aligncenter size-full wp-image-4592" title="June 2012 Opt In vs. Opt Out" src="http://myatus.com/wp-content/uploads/2012/07/June2012optinvsoptout.png" alt="" width="640" height="459" /></p>
<p>These numbers were taken from Cookillian&#8217;s statistics for the specified month, and takes into account those that ignored the alert. As you can see, at most 20% of the visitors (for the Czech Republic) had decided not to receive cookies. A combined average of 15.92% visitors decided not to receive cookies, which is certainly a significant difference between the near 50:50 split when using explicit consent.</p>
<p>I&#8217;m wondering whether this is simply a matter of convenience outweighing matters of e-privacy (as the EC has nicely named it). And while I do think it is important to let a visitor decide about cookies, was the law in itself really worth the effort &#8211; and aggravation? Time will tell.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://myatus.com/p/cookie-law-to-opt-in-or-to-opt-out/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Background Manager 1.1.6 released</title>
		<link>http://myatus.com/p/background-manager-1-1-6-released/</link>
		<comments>http://myatus.com/p/background-manager-1-1-6-released/#comments</comments>
		<pubDate>Sat, 30 Jun 2012 04:12:29 +0000</pubDate>
		<dc:creator>Myatu</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[background-manager]]></category>

		<guid isPermaLink="false">http://myatus.com/?p=4579</guid>
		<description><![CDATA[Another update for Background Manager has been released today, which fixes a number of bugs and introduces a new option. Based on a suggestion in the WordPress Support forum, the new option provides a method for remembering the last shown &#8230; <a href="http://myatus.com/p/background-manager-1-1-6-released/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Another update for <a title="Background Manager" href="http://myatus.com/projects/background-manager/">Background Manager</a> has been released today, which fixes a number of bugs and introduces a new option.</p>
<p>Based on <a title="Background reloads on every page - WordPress Support Forum" href="http://wordpress.org/support/topic/plugin-background-manager-background-reloads-on-every-page?replies=3" target="_blank">a suggestion in the WordPress Support forum</a>, the new option provides a method for remembering the last shown background image. This allows Background Manager to continue with that image on another page, provided that page uses the same Image Set (no override).<span id="more-4579"></span></p>
<p>A bug related to click-able background images has been fixed. Previously, the option to open a link in a new window did not work as intended, opening the link in the same browser window instead.</p>
<p>Another minor bug was related to the Pinterest &#8220;Pin it&#8221; button. The way Background Manager handled it, with each new image shown as the background, an entry was added to the browser&#8217;s history affecting the back-button functionality. This was fixed in time for the release of 1.1.6.</p>
<p>A lingering issue was related to Full Screen background images, which hopefully has been resolved. Depending on the theme, the background images could potentially be moved &#8220;out of sight&#8221;, and thus give the impression Background Manager did not work. This was due to a positioning error.</p>
<p>Also, under certain circumstances, the natural image width and height could not be obtained. This was required to calculate the image ratio and positioning, which at times resulted in a width or height of zero, thus invisible. A different method for obtaining the natural width and heigh has been implemented, based on the browser&#8217;s capabilities.</p>
<p>Finally, a bug corrected as part of the development process, was a related to how Background Manager filtered the Media Library functions. It caused some issues with adding new images to the Image Set.</p>
<p>On to the next version!</p>
<p><span class="label label-info">Edit 14:25 BST</span> Version 1.1.6.1 has been released as a hot-fix to some reported issues of screen elements &#8220;missing&#8221;.</p>
]]></content:encoded>
			<wfw:commentRss>http://myatus.com/p/background-manager-1-1-6-released/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>Cookillian 1.1.18 released</title>
		<link>http://myatus.com/p/cookillian-1-1-18-released/</link>
		<comments>http://myatus.com/p/cookillian-1-1-18-released/#comments</comments>
		<pubDate>Mon, 25 Jun 2012 18:53:32 +0000</pubDate>
		<dc:creator>Myatu</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[cookillian]]></category>

		<guid isPermaLink="false">http://myatus.com/?p=4574</guid>
		<description><![CDATA[Today brings the release of Cookillian version 1.1.18, which adds the option of periodically &#8220;scrubbing&#8221; cookies as first described in the Cookillian and Javascript post. Coincidentally, that post also revealed an issue with Google AdSense, which has now been resolved. &#8230; <a href="http://myatus.com/p/cookillian-1-1-18-released/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Today brings the release of <a title="Cookillian" href="http://myatus.com/projects/cookillian/">Cookillian</a> version 1.1.18, which adds the option of periodically &#8220;scrubbing&#8221; cookies as first described in the <a title="Cookillian and JavaScript" href="http://myatus.com/p/cookillian-and-javascript/">Cookillian and Javascript</a> post. Coincidentally, that post also revealed an issue with Google AdSense, which has now been resolved.<span id="more-4574"></span></p>
<p>Furthermore, the JavaScript header/footer was only loaded when cookies were permitted. This behaviour has been changed in version 1.1.18, where it will also load if cookies are not deleted &#8212; this keeps it in sync with the &#8220;delete cookies before/after&#8221; option.</p>
<p>Also in 1.1.18, the default alert now uses the AJAX API to opt a user in, or out, depending on the availability of JavaScript. If JavaScript is not available, it will use the convential method instead.</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://myatus.com/p/cookillian-1-1-18-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Infographic: World IPv6 Launch by the numbers</title>
		<link>http://myatus.com/p/infographic-world-ipv6-launch-by-the-numbers/</link>
		<comments>http://myatus.com/p/infographic-world-ipv6-launch-by-the-numbers/#comments</comments>
		<pubDate>Tue, 19 Jun 2012 00:12:25 +0000</pubDate>
		<dc:creator>Myatu</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[ipv6]]></category>

		<guid isPermaLink="false">http://myatus.com/?p=4567</guid>
		<description><![CDATA[As found at http://www.worldipv6launch.org/infographic/]]></description>
				<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-4568" title="Wolrd IPv6 Launch - Infographic" src="http://myatus.com/wp-content/uploads/2012/06/worldipv6launch-infographic.jpg" alt="" width="720" height="4680" /></p>
<p>As found at <a href="http://www.worldipv6launch.org/infographic/">http://www.worldipv6launch.org/infographic/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://myatus.com/p/infographic-world-ipv6-launch-by-the-numbers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress caching and nonce lifespan</title>
		<link>http://myatus.com/p/wordpress-caching-and-nonce-lifespan/</link>
		<comments>http://myatus.com/p/wordpress-caching-and-nonce-lifespan/#comments</comments>
		<pubDate>Mon, 18 Jun 2012 19:43:49 +0000</pubDate>
		<dc:creator>Myatu</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[nonce]]></category>

		<guid isPermaLink="false">http://myatus.com/?p=4558</guid>
		<description><![CDATA[A security feature available in WordPress is a &#8220;nonce&#8221;. Generally, a &#8220;nonce&#8221; is a token that can only be used once and are often used to prevent unauthorised people  from submitting data on behalf of another person. Let&#8217;s simplify that: &#8230; <a href="http://myatus.com/p/wordpress-caching-and-nonce-lifespan/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>A <a title="WordPress Nonces" href="http://codex.wordpress.org/WordPress_Nonces" target="_blank">security feature available in WordPress</a> is a &#8220;nonce&#8221;. Generally, a &#8220;nonce&#8221; is a token that can only be used once and are often used to prevent unauthorised people  from submitting data on behalf of another person. Let&#8217;s simplify that:</p>
<ul>
<li>Person A is given nonce &#8220;A&#8221;</li>
<li>Person B is given nonce &#8220;B&#8221;</li>
<li>Person B attempts to submit data to the server on behalf of person A</li>
<li>The server reads the submitted data from person B as &#8220;Person A with nonce  &#8217;B&#8217; is submitting data&#8221;. Knowing that Person A does not have nonce &#8216;B&#8217;, it ignores/denies the submitted data.</li>
</ul>
<p>WordPress differs by giving it a lifespan and allowing the nonce to be used more than once within that lifespan by the same person. And by the &#8216;same person&#8217; it is meant a logged in WordPress user, or an anonymous user (visitor not logged in).<span id="more-4558"></span></p>
<p>The benefit is that the server does not need to keep track what nonce it has given to any particular user. It just needs to know the user returning the nonce and the current time; based on that information, it creates another nonce and checks if it matches the one returned.</p>
<h2>Using time as part of a nonce</h2>
<p>As time varies, WordPress needs to allow for a nonce generated at 10:01 AM to be valid at 10:02 AM. It does this by using a time &#8220;tick&#8221; instead of the actual time, which is generated in two steps:</p>
<ol>
<li>First divide the lifespan of a nonce, in seconds, by two</li>
<li>Divide the <a title="Unix timestamp - WikiPedia" href="http://en.wikipedia.org/wiki/Unix_timestamp" target="_blank">Unix timestamp</a> by the above value, and round it up using <em>ceil()</em></li>
</ol>
<p>By default, the lifespan is 86400 seconds, or 24 hours (and can be adjusted with the <em>nonce_life</em> filter). Half this, 12 hours, is 43200.</p>
<p>So at 10:01 AM on 18/06/2012, the Unix timestamp is 1340031660. Dividing that by 43200, rounded we get 31019. A minute later (10:02 AM), the timestamp is 1340031720. Dividing and rounding, we also end up with 31019. In fact, for the first 12 hours of the day this value will be the resulting &#8220;tick&#8221;.</p>
<p>The reason WordPress divides the timespan in two, is that it can determine if a nonce was created in the first or second half of its full lifespan, simply by incrementing a &#8220;tick&#8221; by one.</p>
<h2>Nonce time caveat</h2>
<p>Based on a 24-hour lifespan, a &#8220;tick&#8221; as calculated above is the same for each 12-hour span of a day. At 07:45 AM the &#8220;tick&#8221; is the same as 9:30 AM and 11:59 AM. But it will be one less than a &#8220;tick&#8221; created at 12:01 PM (a new 12-hour span within the day) or 15:30 PM.</p>
<p>Because of this, a WordPress nonce is not valid for <em>exactly</em> 24-hours from the moment that it was created, but <em>up to</em> 24 hours, depending how far into a 12-hour period a nonce was created.</p>
<h2>Nonces and WordPress Cache</h2>
<p>Nonces can also be used on the &#8220;public&#8221; side of WordPress, and can help reduce abuse of data submissions. My WordPress plugins use this, as do some others like <a title="Contact Form 7" href="http://wordpress.org/extend/plugins/contact-form-7/" target="_blank">Contact Form 7</a>.</p>
<p>As a nonce is often added as a (hidden) form element or using JavaScript, this means that it will also end up being cached by a WordPress plugin such as <a title="WP Super Cache" href="http://wordpress.org/extend/plugins/wp-super-cache/" target="_blank">WP Super Cache</a> or <a title="W3 Total Cache" href="http://wordpress.org/extend/plugins/w3-total-cache/" target="_blank">W3 Total Cache</a>. This can cause some issues with nonce verification.</p>
<p>The main issue is how long a page is cached and <em>how</em> most caching plugins determine the age of a cached page. As mentioned earlier, a nonce &#8220;tick&#8221; is not valid for exactly 24 hours. On the other hand, the age of a cached page is determined from when it was first cached. So if a page is cached for 24 hours (or more), it allows the possibility for a nonce to expire and thus become invalid.</p>
<p>For example: a page is cached at 10:01 AM on 18/06/2012. The &#8220;tick&#8221; of used for the nonce at this time was 31019. 24 hours from that time, at 10:01 AM on 19/06/2012, the server calculates a &#8220;tick&#8221; to be 31021. But as the cached nonce was based on a &#8220;tick&#8221; of 31019, any attempt to use it for data submission would fail.</p>
<p>To avoid this, a page should be cached for at most 12 hours, provided the life-span for a nonce has not been changed from its default 24 hours. The author of WP Super Cache also provides <a title="Forms not sending with Super Cache enabled - Contact Form 7 - WordPress" href="http://wordpress.org/support/topic/plugin-contact-form-7-forms-not-sending-with-super-cache-enabled">an alternative solution</a>, though that may not be a suitable solution in all cases (ie., in AJAX that uses nonce on all pages).</p>
<h2>Cache garbage collection</h2>
<p>In WP Super Cache&#8217;s case, by default a cached page becomes stale after an hour, which is well less than the 12 hours. But for the stale page to be refreshed using its <em>Garbage Collection</em> feature (see the <em>Advanced</em> tab), the collection has to be done in time as well. For instance, if the cached page has become stale after an hour, but garbage collection is done every 24 hours, the stale page will still be used for up to 23 hours.</p>
<p>This is further complicated because the WordPress Cron (the scheduler for performing tasks) usually checks its schedule whenever a visitor accesses the website. On low-traffic websites, this could give large variations between the scheduled time versus actual time a task is performed (such as the garbage collection). In these instances, it would make better sense to use a UNIX Cron Job to call <em>wp-cron.php</em>, or to reduce the garbage collection time as much as possible.</p>
]]></content:encoded>
			<wfw:commentRss>http://myatus.com/p/wordpress-caching-and-nonce-lifespan/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Background Manager 1.1.1 released</title>
		<link>http://myatus.com/p/background-manager-1-1-released/</link>
		<comments>http://myatus.com/p/background-manager-1-1-released/#comments</comments>
		<pubDate>Thu, 14 Jun 2012 03:03:19 +0000</pubDate>
		<dc:creator>Myatu</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[background-manager]]></category>

		<guid isPermaLink="false">http://myatus.com/?p=4521</guid>
		<description><![CDATA[Finally! After 3 months of hard work, Background Manager version 1.1 1.1.1 has been released, coinciding with the release of WordPress 3.4. (Update: A rather annoying bug was introduced in version 1.1, which has been remedied in 1.1.1. If something can go &#8230; <a href="http://myatus.com/p/background-manager-1-1-released/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Finally! After 3 months of hard work, <a title="Background Manager" href="http://myatus.com/projects/background-manager/">Background Manager</a> version <del>1.1</del> 1.1.1 has been released, coinciding with the <a title="WordPress 3.4 &quot;Green&quot; released" href="http://wordpress.org/news/2012/06/green/" target="_blank">release of WordPress 3.4</a>.</p>
<p>(Update: A rather annoying bug was introduced in version 1.1, which has been remedied in 1.1.1. If something can go wrong, it most certainly will).</p>
<p>It includes a large number of new features, which I will outline below. Please note that there are a few changes that could potentially affect the layout of the background, so keep these in mind before upgrading.</p>
<p><span id="more-4521"></span></p>
<h2>Theme Customizer</h2>
<p><a href="http://myatus.com/wp-content/uploads/2012/06/ss_wpbgm_1.1_theme_customizer.png"><img class="alignleft size-thumbnail thumbnail wp-image-4522" style="margin: 10px;" title="Background Manager and WordPress Theme Customizer" src="http://myatus.com/wp-content/uploads/2012/06/ss_wpbgm_1.1_theme_customizer-150x150.png" alt="" width="150" height="150" /></a>WordPress 3.4 introduces a <em>theme customizer</em>, allowing you make adjustments to your theme and see them in a preview. It&#8217;s a welcome addition to WordPress, making it a lot easier to customise a website and Background Manager takes full advantage new feature.</p>
<p>All the visual options found in the Background <em>Manager&#8217;s Settings</em> screen can be accesses directly from the theme customizer, allowing you to change image sets, background colors and overlays, select between full-screen and normal display modes and more.</p>
<p>All these changes are non-permanent until you save the settings, allowing you to test various options, like the new image transitions, to see which ones work best for your website.</p>
<h2>New image transitions</h2>
<p>Version 1.1.1 increases the number of available transitions to 19 with the introduction of <em>Fade-in and Zoom</em> transition and 8 CSS3 transitions based on the hard work of <a title="Flux Slider - Joe Lambert" href="http://www.joelambert.co.uk/flux/" target="_blank">Joe Lambert&#8217;s Flux Slider</a>.</p>
<p><span class="label label-info">Heads up!</span> The new transitions required a few changes in how the background images are displayed. Prior to version 1.1, it used an <code>&lt;img&gt;</code> element to display the background. Now it will us a <code>&lt;div&gt;</code> element with a background image, unless the browser does not support the <em>&#8220;background-size&#8221;</em> element (Microsoft Internet Explorer 8 and below) &#8212; such browser will still use the <code>&lt;img&gt;</code> element, and fall back to the &#8220;Crossfade&#8221; transition.</p>
<h2>Better full screen images</h2>
<p>Previously Background Manager relied upon CSS to adjust the background image size according to the browser window. This worked well for images that were smaller than the browser window, but larger images were not resized and this lead to some confusion, particularly in what size the background image to use.</p>
<p>In version 1.1 this is now managed with JavaScript, which allows you to use any size image. Large, and small, images will be resized to fit the entire background, whilst maintaining the ratio (preventing stretching or squishing). If after resizing the image is larger than the width or height of the browser (due to maintaining its ratio), it can optionally be centred.</p>
<p><span class="label label-info">Heads up!</span> Because large images are now resized too, make sure that this is okay for your website before upgrading.</p>
<h2>Sequential image selection</h2>
<p><a href="http://myatus.com/wp-content/uploads/2012/06/ss_bgmwp_1.1_reorder.png"><img class="alignright size-thumbnail thumbnail wp-image-4529" style="margin: 10px;" title="Image Set, re-order and remove options" src="http://myatus.com/wp-content/uploads/2012/06/ss_bgmwp_1.1_reorder-150x150.png" alt="" width="150" height="150" /></a>One of the most requested features was the ability to display images in the order they appear in an Image Set, as well as the ability to re-order those images.</p>
<p>This feature has been added to version 1.1, and allows you to display the images in random, ascending or descending order. When editing an Image Set, highlighting an image will provide to option to move it left or right. You can also double-click to select images, and move them in one go.</p>
<h2>Additional Image Set improvements</h2>
<p>Another improvement when editing Image Sets, is the ability to remove an image from an Image Set. This differs from deleting an image, as it will remain in the Media Library for later re-use.</p>
<p>The window showing the images within an Image Set can now also be resized (and it will remember the size for next time).</p>
<h2>Background Impression and Click tracking</h2>
<p>The ability to make backgrounds click-able since version 1.0.6 has proven rather popular, and another frequently requested feature is the ability to track the impressions and clicks of such click-able background images.</p>
<p>Version 1.1 introduces the option to do so with the help of Google Analytics and will trigger Events whenever a click-able image is shown or clicked on. These events can also be used as part of Goals.</p>
<h2>And More!</h2>
<p>In addition to the above, version 1.1 also introduces the following new features:</p>
<ul>
<li>Detects 3rd party category taxonomies, such as those created by <a title="WP e-Commerce" href="http://wordpress.org/extend/plugins/wp-e-commerce/" target="_blank">WP e-Commerce</a>, and override the background image based on those categories.</li>
<li>The option to override the link for the [ + ] icon</li>
<li>Override the background color per post, page, category or tag</li>
<li>Select which WordPress Roles are permitted to override the background for a post or page</li>
<li>Optionally disable the ease-in of the first image</li>
<li>Longer transition times and faster background change frequencies (down to 1 second)</li>
</ul>
<p>As well as numerous bug fixes, including the &#8220;blocking&#8221; during a background change as well as the &#8220;flicker&#8221; noticeable on certain browser.</p>
<p>&nbsp;</p>
<h6><a title="&quot;Untitled&quot; by cessemi" href="http://www.flickr.com/photos/cessemi/2079977086/" target="_blank">Photo</a> by <a title="cessemi at Flickr" href="http://www.flickr.com/photos/cessemi/" target="_blank">cessemi</a></h6>
]]></content:encoded>
			<wfw:commentRss>http://myatus.com/p/background-manager-1-1-released/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Cookillian Alert styling: Simple Implied Consent</title>
		<link>http://myatus.com/p/cookillian-alert-styling-simple-implied-consent/</link>
		<comments>http://myatus.com/p/cookillian-alert-styling-simple-implied-consent/#comments</comments>
		<pubDate>Wed, 13 Jun 2012 17:57:33 +0000</pubDate>
		<dc:creator>Myatu</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[cookillian]]></category>
		<category><![CDATA[cookillian-extend]]></category>

		<guid isPermaLink="false">http://myatus.com/?p=4509</guid>
		<description><![CDATA[Cookillian is very flexible and allows you to fully customize the alert that will be displayed as well as how it handles consent. Here I will provide an example for a simple, unobtrusive alert at the bottom (or top) of &#8230; <a href="http://myatus.com/p/cookillian-alert-styling-simple-implied-consent/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><a href="http://myatus.com/wp-content/uploads/2012/06/Subtle_Implied_Consent.png"><img class="alignleft size-thumbnail wp-image-4510" style="margin: 10px;" title="Simple Implied Consent" src="http://myatus.com/wp-content/uploads/2012/06/Subtle_Implied_Consent-150x150.png" alt="" width="150" height="150" /></a> <a title="Cookillian" href="http://myatus.com/projects/cookillian/">Cookillian</a> is very flexible and allows you to fully customize the alert that will be displayed as well as how it handles consent.</p>
<p>Here I will provide an example for a simple, unobtrusive alert at the bottom (or top) of a page, with an option to opt out of receiving cookies. This is a commonly used method for <em>implied consent</em> across major websites in the United Kingdom.</p>
<p>It also shows how to use Cookillian&#8217;s API to make an AJAX call, yet provide backward compatibility with browsers that do not use JavaScript.</p>
<p><span id="more-4509"></span></p>
<h2>Setup</h2>
<p>This styling is divided in two parts, one that provides the HTML code, and another the CSS styling. We first need to access the <em>Settings</em> screen (<strong>Settings -&gt; Cookies</strong>) and set both <em>Alert Content</em> and <em>Alert Styling</em> options to <em>Custom</em>. This will provide us with two new large fields where we can add the code necessary.</p>
<p>As this alert style is geared towards implied consent, you may also want to tick the box <em>Implied Consent</em>, which will hide the alert if the visitor accesses any other page (by opting the user in). And under the heading <em>Advanced Options</em>, you have the option to delete cookies if the visitor specifically opts <span style="text-decoration: underline;">out</span>.</p>
<h2>CSS Code</h2>
<p>For the <em>Custom Alert Style</em> we use the following code:</p>
<pre class="prettyprint linenums">.cookillian-alert {
  position: fixed;
  bottom:0;
  left:0;
  z-index:10000;
  width:100%;
  border-top:1px solid #000;
  color: #000;
  background-color: #eee;
}
.cookillian-alert-inside {
  padding: 5px;
  text-align: center;
}</pre>
<p>This will ensure that the alert will &#8220;stick&#8221; to the bottom of the screen, above all other content. If you find that the alert is still covered, you need to increase the <em>z-index</em> value. And if you&#8217;d rather wish to have the alert appear at the top of the screen, replace <em>&#8220;bottom: 0;&#8221;</em> with <em>&#8220;top: 0;&#8221;</em> and <em>&#8220;border-top&#8221;</em> with <em>&#8220;border-bottom&#8221;</em>.</p>
<p><span class="label label-info">Heads up!</span> Cookillian always wraps the HTML code inside a <code>&lt;div&gt;</code> element with the class <code>cookillian-alert</code>.</p>
<h2>HTML Code</h2>
<p>Under the heading <em>Content</em>, you can add the following HTML code in the large <em>Custom Alert Code</em> field:</p>
<pre class="prettyprint linenums">&lt;div class="cookillian-alert-inside"&gt;
Just to let you know, this website uses cookies and you can read more about them &lt;a href="#"&gt;here&lt;/a&gt;. If you'd rather not want this, &lt;a href="?cookillian_resp=0" onclick="try{cookillian.optOut();jQuery('.cookillian-alert').fadeOut('slow');return false;}catch(e){}"&gt;Click here&lt;/a&gt;.
&lt;/div&gt;</pre>
<p>Obviously you are free to change the text to meet your needs. Just be sure to change the link to the information about the cookies (currently a hash [#] sign).</p>
<p>The &#8220;<em>Click Here&#8221;</em> linke contains an <em>onclick</em> attribute that executes a little JavaScript if its available:</p>
<ol>
<li>In the background, it first opts the user out of receiving cookies &#8211; so that the visited page does not need to be refreshed.</li>
<li>It hides the alert in a fading motion.</li>
</ol>
<p>If JavaScript is not available, then it will use Cookillian&#8217;s ability to opt a visitor out by URL. This will ensure that anyone can opt out, regardless of their browser capability.</p>
]]></content:encoded>
			<wfw:commentRss>http://myatus.com/p/cookillian-alert-styling-simple-implied-consent/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cookillian and JavaScript</title>
		<link>http://myatus.com/p/cookillian-and-javascript/</link>
		<comments>http://myatus.com/p/cookillian-and-javascript/#comments</comments>
		<pubDate>Tue, 12 Jun 2012 01:35:22 +0000</pubDate>
		<dc:creator>Myatu</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[cookies]]></category>
		<category><![CDATA[cookillian]]></category>
		<category><![CDATA[cookillian-extend]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://myatus.com/?p=4462</guid>
		<description><![CDATA[By default, Cookillian will delete cookies that are set by WordPress (ie., wp-settings-*) and other WordPress plugins. As JavaScript generally lies outside the realm of WordPress, the idea is that certain scripts, such as Google Analytics, are removed from the &#8230; <a href="http://myatus.com/p/cookillian-and-javascript/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>By default, <a title="Cookillian" href="http://myatus.com/projects/cookillian/">Cookillian</a> will delete cookies that are set by WordPress (ie., wp-settings-*) and other WordPress plugins. As JavaScript generally lies outside the realm of WordPress, the idea is that certain scripts, such as <a title="Google Analytics" href="http://www.google.com/analytics" target="_blank">Google Analytics</a>, are removed from the website and into the <em>Header</em> or <em>Footer</em> fields of Cookillian&#8217;s <em>JavaScript</em> section. This prevents the script from loading when the visitor has not (yet) given permission to receive cookies.</p>
<p>This is the preferred method, as it gives greater control over the cookies set by third party scripts. As mentioned, Google Analytics is one such script that should be moved, and is probably easiest to accomplish. But there are some that require a bit more work, like the Twitter Tweet button and Google AdSense, which I will explain next.</p>
<p>I will also provide a sample code that with the help of Cookillian will delete local cookies set by existing JavaScript, to help ease the transition.</p>
<p><span id="more-4462"></span></p>
<h2>Tweet Button</h2>
<p>The original code provided by Twitter for the <a title="Tweet Button - Twitter Developers" href="https://dev.twitter.com/docs/tweet-button" target="_blank">Tweet button</a> is the following:</p>
<pre class="prettyprint linenums">&lt;a href="https://twitter.com/share" data-lang="en"&gt;Tweet&lt;/a&gt;
&lt;script&gt;!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");&lt;/script&gt;</pre>
<p>This bit of code is in fact two parts: a regular link with the word <em>&#8220;Tweet&#8221;</em> to share a URL on Twitter, and a script that replaces this link with a pretty button and a share counter.</p>
<p>Because the JavaScript only needs to be called once for all such links, we can simply remove the <code>&lt;script&gt;</code> portion from the code above, and place it in the <em>Footer</em> field of Cookillian&#8217;s <em>JavaScript</em> section. It should not be placed in the <em>Header</em> field though, as it would otherwise be run too soon by the browser.</p>
<p>When cookies are blocked, the script by Twitter is not permitted to run and the regular <em>&#8220;Tweet&#8221;</em> link will remain as-is. When cookies are permitted, the script <em>is</em> allowed to run, and the simple links are transformed into the more familiar buttons with counters.</p>
<p>This also works for other scripts that replace a simple link with buttons, such as <a title="Like Button - Facebook Developers" href="https://developers.facebook.com/docs/reference/plugins/like/" target="_blank">Facebook&#8217;s &#8220;Like&#8221; button</a>. However, some scripts must be run at certain locations. Google AdSense is one such example, and will require a bit more work still.</p>
<h2>Google AdSense</h2>
<p>The following is a sample of the code provided by Google AdSense. It is to be placed where the advertisement should be displayed:</p>
<pre class="prettyprint linenums">&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "ca-pub-xxxxxxxxxxxxxxxx";
/* 160x600, created 11/1/08 */
google_ad_slot = "000000000000";
google_ad_width = 160;
google_ad_height = 600;
//--&gt;
&lt;/script&gt;
&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;</pre>
<p>When this code is run by the browser, it will add the advertisement where this code is located. For this reason, it cannot be moved into the <em>Footer</em> or <em>Header</em> fields of Cookillian&#8217;s <em>JavaScript</em> section. Instead, one needs to use one of Cookillian&#8217;s API methods to accomplish this.</p>
<h3>Selective text insertion</h3>
<p>One API method available in Cookillian is <code>cookillian.insertString()</code>, and can be used to insert text, including JavaScript, at a specified location. It takes 4 parameters:</p>
<ul>
<li><code>where</code> - the CSS selector where to insert the string,</li>
<li><code>true_string</code> - The string (text) to use when the 4th parameter (<code>tf_value</code>) is <code>true</code>,</li>
<li><code>false_string</code> - The string to use when the 4th parameter is <code>false</code>,</li>
<li><code>tf_value</code> - An optional boolean value (<code>true</code> or <code>false</code>) or name of a Cookillian variable, used to indicate which string to use. If this is omitted, it will use Cookillian&#8217;s <code>blocked_cookies</code> variable by default.</li>
</ul>
<p>Using it is very simple, and it automatically handles any asynchronous AJAX calls made by Cookillian. Here&#8217;s an example:</p>
<pre class="prettyprint linenums">Cookies are currently &lt;span id="insert_here"&gt;&lt;/span&gt;.
&lt;script type="text/javascript"&gt;cookillian.insertString("#insert_here", "disabled", "enabled", "blocked_cookies");&lt;/script&gt;</pre>
<p>This will check the <code>cookillian.blocked_cookies</code> variable when it is ready, and add will <em>&#8220;disabled&#8221;</em> to the text if cookies are blocked (true), or <em>&#8220;enabled&#8221;</em> if they are not (false). As the text can also include JavaScript, we can use this function to add the Google AdSense code when cookies are permitted.</p>
<p><span class="label label-info">Heads up!</span> Any text needs to be enclosed in a single or double quote. The JavaScript code may already contain single or double quotes, and therefore need to be &#8220;escaped&#8221;.  <a title="JavaScript escaping at freeformatter.com" href="http://www.freeformatter.com/javascript-escape.html" target="_blank">Freeformatter.com</a> provides a quick and easy to use tool to perform the escaping.</p>
<p>The following is what the code will look like for Google AdSense:</p>
<pre class="prettyprint linenums">&lt;span id="google_ad_1"&gt;&lt;/span&gt;
&lt;script type="text/javascript"&gt;
cookillian.insertString(
"#google_ad_1", // Where
"",
"&lt;script type=\"text\/javascript\"&gt;&lt;!--
google_ad_client = \"ca-pub-xxxxxxxxxxxxxxxx\";
\/* 160x600, created 11\/1\/08 *\/
google_ad_slot = \"000000000000\";
google_ad_width = 160;
google_ad_height = 600;
\/\/--&gt;
&lt;\/script&gt;
&lt;script type=\"text\/javascript\"
src=\"http:\/\/pagead2.googlesyndication.com\/pagead\/show_ads.js\"&gt;
&lt;\/script&gt;"
);</pre>
<p>This code will insert nothing if cookies are blocked. You could perhaps use that to display an alternative advertisement. If cookies are not blocked, it will run the provided Google AdSense code as usual. As you may have noticed, I left out the 4th parameter, as this is the <code>cookillian.blocked_cookies</code> variable by default.</p>
<div class="alert alert-info">Important! It is important to note that according to the <a title="Google AdSense program policies" href="https://support.google.com/adsense/bin/answer.py?hl=en&amp;utm_medium=link&amp;utm_campaign=ww-ww-et-asfe_&amp;utm_source=aso&amp;answer=48182" target="_blank">Google AdSense program policies</a>, their provided code should not be altered to behave in a different way.</div>
<p><span class="label label-info">Heads up!</span> An ID attribute, as seen in the <code>&lt;span&gt;</code> tag, can only be used once on a page. For each ad, you should use a different ID (you could increment the last number, for example).</p>
<h2>Periodic Clean-up</h2>
<p>The following is an example using the Cookillian API, which periodically checks if new local cookies have been set and delete them (unless they&#8217;re required). It will also skip this periodic clean-up if cookies are permitted.</p>
<pre class="prettyprint linenums">(function($){
    $(document).on('cookillian_ready', function() {
        function cookiesSqueakyClean() {
            // Check if cookies aren't allowed but present
            if (cookillian.blocked_cookies &amp;&amp; document.cookie) {
                // If we haven't "seen" these cookies before, try delete them
                if (typeof document.last_seen_cookies === "undefined" ||
                    document.last_seen_cookies !== document.cookie) {
                    cookillian.deleteCookies();
                }

                // Anything left is likely to be "required",
                // and we save these for the next check
                document.last_seen_cookies = document.cookie;
            }
            setTimeout(cookiesSqueakyClean, 1000);
        }
        cookiesSqueakyClean();
    });
}(jQuery));</pre>
<p>The periodic clean-up will handle cookies that are &#8220;local&#8221; only, that is, cookies that belong to the same domain as the visiting website. Cookies for other domains cannot be handled (and is not a limitation, but a security feature implemented by browsers).</p>
<p>Again, the preferred method is to use the selective insertion of Javascript using the API or in the provided fields, as this gives greater control over 3rd party cookies.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://myatus.com/p/cookillian-and-javascript/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
