<?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>triptic techblog</title>
	<atom:link href="http://techblog.triptic.nl/feed/" rel="self" type="application/rss+xml" />
	<link>http://techblog.triptic.nl</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Fri, 23 Mar 2012 20:55:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>HybridAuth: OAuth and OpenID made easy</title>
		<link>http://techblog.triptic.nl/hybridauth-oauth-and-openid-made-easy/</link>
		<comments>http://techblog.triptic.nl/hybridauth-oauth-and-openid-made-easy/#comments</comments>
		<pubDate>Fri, 23 Mar 2012 20:42:38 +0000</pubDate>
		<dc:creator>tbeijers</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://techblog.triptic.nl/?p=176</guid>
		<description><![CDATA[Social media integration is becoming more and more common on websites these days. Visitors want to be able to log in using their Facebook, Google and Twitter accounts and site owners want to give their visitors the possibility to tell other people about their site on these social media. Implementing these possibilities on your website [...]]]></description>
			<content:encoded><![CDATA[<p>Social media integration is becoming more and more common on websites these days. Visitors want to be able to log in using their Facebook, Google and Twitter accounts and site owners want to give their visitors the possibility to tell other people about their site on these social media.</p>
<p>Implementing these possibilities on your website requires knowledge of the OpenID and OAuth protocols, as well as specifics each site might have done differently than the standard. Once you start programming it, the code has a tendency to be a lot of copy-paste work with just small differences, and that isn&#8217;t making your code very clear.</p>
<p>As with a lot of programming problems there is a free, open-source solution: HybridAuth. HybridAuth tries to take away all specifics for the seperate social media sites and gives you a generic way of authenticating users to these sites while also providing API-access where applicable.</p>
<p>I think things like this are usually better explained with a piece of code(the code is inspired by examples from the HybridAuth website):</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="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$config</span> <span style="color: #339933;">=</span> <span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/library/config.php'</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// this config contains things like tokens and what providers are enabled</span>
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'./library/Hybrid/Auth.php'</span><span style="color: #339933;">;</span>
try <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$hybridauth</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Hybrid_Auth<span style="color: #009900;">&#40;</span><span style="color: #000088;">$config</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">/*
    * When the user is not authenticated this redirects that user to the twitter authentication page.
    * Twitter then sends the user back to this page
    * If the user is already authenticated it simply goes on to the next line of code.
    */</span>
    <span style="color: #000088;">$provider</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$hybridauth</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">authenticate</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Twitter'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$user_profile</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$provider</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUserProfile</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// getUserProfile() is available for every &quot;provider&quot; and contains basic information like the displayName and where allowed by the user: the e-mail address</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Hi there! '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$user_profile</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">displayName</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$provider</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setUserStatus</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Hello world!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// This is an example of API-access, this specific function(getUserStatus()) is available in more providers    </span>
    <span style="color: #000088;">$account_totals</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$provider</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">api</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'account/totals.json'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// You can also directly call the api of a provider by using $provider-&gt;api()</span>
    <span style="color: #000088;">$user_contacts</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$provider</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUserContacts</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// getUserContacts() is available in most providers, and does what it says: it gets the users friends/contacts</span>
<span style="color: #009900;">&#125;</span> catch<span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Ooops, we got an error: '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$e</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>
Now what if we want to do exactly the same, but for Facebook? That&#8217;s actually quite simple: the ONLY line we have to edit is the line that says:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$provider</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$hybridauth</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">authenticate</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Twitter'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>and change it to</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$provider</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$hybridauth</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">authenticate</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Facebook'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>It really is that simple.
</p>
<p>But does HybridAuth only support Facebook, Twitter and Google then? No, it supports way more, a list of all supported providers as of 23 march 2012:</p>
<ul>
<li>OpenID</li>
<li>Facebook</li>
<li>Twitter</li>
<li>Yahoo</li>
<li>Google</li>
<li>MySpace</li>
<li>Windows Live</li>
<li>LinkedIn</li>
<li>Foursquare</li>
<li>AOL</li>
</ul>
<p>And there is even an additional providers package available for download which adds support for:</p>
<ul>
<li>Github</li>
<li>Gowalla</li>
<li>LastFM</li>
<li>Vimeo</li>
<li>Viadeo</li>
<li>Identica</li>
<li>Tumblr</li>
<li>Goodreads</li>
<li>QQ</li>
<li>Sina</li>
<li>Murmur</li>
<li>Pixnet</li>
<li>Plurk</li>
</ul>
<p>That is 23 different providers(counting OpenID as only 1 provider, even though multiple sites supports that). And even if you want your visitors to be able to login using another provider, it&#8217;s quite simple to add support for that, especially if that provider has OAuth support.</p>
<p>So does this HybridAuth library also have disadvantages?</p>
<p>The answer to that is: yes. But that doesn&#8217;t mean the library is useless. The biggest disadvantages I&#8217;ve found are:</p>
<ol>
<li>If you plan to use it in a framework or CMS that abstracts for example the $_SESSION variable, it requires more fiddling than it seems at first sight to get it working. Even though there is a Storage class which you can easily edit to use something else than $_SESSION, the Storage class is not always used for storage, sometimes $_SESSION is hardcoded.</li>
<li>There are some small bugs that can still be quite annoying, and since the library seems to be largely maintained by one person it can take some time before the bug is solved in the main release.</li>
</ol>
<p>For me these disadvantages don&#8217;t weigh up to the advantages. And if they don&#8217;t for you: just make a pull request at the <a href="https://github.com/hybridauth/hybridauth">Github page</a> and fix it.</p>
<p>If you want to know more about HybridAuth you can visit the website: <a href="http://hybridauth.sourceforge.net/">http://hybridauth.sourceforge.net/</a>, which also has some documentation on how to use it.</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.triptic.nl/hybridauth-oauth-and-openid-made-easy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL performance nightmares: Solr to the rescue</title>
		<link>http://techblog.triptic.nl/mysql-performance-nightmares-solr-to-the-rescue/</link>
		<comments>http://techblog.triptic.nl/mysql-performance-nightmares-solr-to-the-rescue/#comments</comments>
		<pubDate>Wed, 11 May 2011 14:04:02 +0000</pubDate>
		<dc:creator>Onno Marsman</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[solr]]></category>

		<guid isPermaLink="false">http://techblog.triptic.nl/?p=117</guid>
		<description><![CDATA[For almost a year we have worked very hard on a huge project: Oneindig Noord-Holland. In case you were wondering why it&#8217;s been a bit quiet from my side: That&#8217;s why. One of the key features of this website was its search feature. It&#8217;s going to be a huge collection of items of different types: [...]]]></description>
			<content:encoded><![CDATA[<p>For almost a year we have worked very hard on a huge project: <a href="http://www.oneindignoordholland.nl">Oneindig Noord-Holland</a>. In case you were wondering why it&#8217;s been a bit quiet from my side: That&#8217;s why.</p>
<p>One of the key features of this website was its search feature. It&#8217;s going to be a huge collection of items of different types: stories, events, news, profiles, images, videos and a lot more&#8230; All these types of  items can have the same properties: title, author, description, tags, dates, date ranges, specific locations, location areas and links to other items. These items can also have content which contains text, images, videos, links to other items and more. As a visitor you need to be able to work your way through all these items and that&#8217;s where the search comes in.</p>
<p><span id="more-117"></span>We wanted everything in the search we could think of and we wanted it to filter on most of the properties:</p>
<ul>
<li>Text: in text, tags, title, subtitle, description etc.</li>
<li>Tag</li>
<li>Location: both by region and within a certain distance from a specified location</li>
<li>Time: both by a period in time and by a specific point in time</li>
<li>Author</li>
<li>State: published or not</li>
<li>Used: used in other items</li>
<li>etc.</li>
</ul>
<p>I thought everything through and looked at each type of search option separately and concluded most properties weren&#8217;t a problem with the queries in our database MySQL. There were some that did pose some problems, but I found solutions for this in advance:</p>
<ul>
<li>Filter by a region: There are only 8 regions. When an item is added or edited we can just calculate to which regions it belongs and save that too.</li>
<li>Filter by a specific location: Not filter by radius but filter by a box. We now have minimum and maximum longitudes and latitudes to filter by.</li>
<li>Filter by text: Easy enough: just use a lot of LIKE &#8216;%word%&#8217; and that&#8217;s it. When this would prove to be a performance issue we could always create a shadow table in MyISAM with a <a href="http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html">fulltext</a> index and that&#8217;s it.</li>
</ul>
<p>With a potential number of 20 tables involved with this query this wasn&#8217;t going to be an easy task and performance was going to be an issue. But I&#8217;ve read the book <a href="http://oreilly.com/catalog/9780596003067">High Performance MySQL</a> and a lot of articles on the <a href="http://www.mysqlperformanceblog.com/">MySQL Perfomance Blog</a>. So I know the <a href="http://dev.mysql.com/doc/refman/5.0/en/explain.html">explain</a> statement, I know MySQL can&#8217;t use more than one index from a table in a specific query, so I have to choose my indexes carefully and I know a large UNION statement performs better than a simple OR. I know everything I know to get the job done. What could go wrong?</p>
<p>The answer to this question is as simple as it is frustrating:<br />
A lot!</p>
<p>The problems began when we started some test imports of images from external sources into our development environment. These were literally tens of thousands of images. Suddenly the site didn&#8217;t perform very well on our development environment: Our search query was taking 2 minutes to run when we hadn&#8217;t even used all the filtering options. No problem: we would locate the bottlenecks and fix them! We did and performance improved&#8230; a bit. We did it again and performance improved&#8230; a bit. So now we were really digging into the endless possibilities of queries and we were trying to find out which indexes were wrong and how we could tempt MySQL into using the right indexes. Until we ran into a bit of a problem: dependent subqueries, which really didn&#8217;t really seem that dependent at all&#8230; A bit of googling taught me this is a known problem in MySQL and there are workarounds. These workarounds involve writing stored procedures or clientside code to collect the data from the subquery in a separate query and feed the results to the main query. Because our subqueries can potentially produce thousands of results and they need to be combined with other subqueries, I didn&#8217;t think these workarounds were gonna give the performance benefits we were aiming for. It was time to sound the alarms&#8230;</p>
<h3><strong>Solr</strong></h3>
<p>It didn&#8217;t take very long to find the tool we needed. I attended a workshop about <a href="http://www.slideshare.net/IanBarber/in-search-of">integrating site search</a> at the dutch phpconference in 2010 where the speaker tried to &#8211; but couldn&#8217;t really &#8211; hide the fact that <a href="http://lucene.apache.org/solr/">Solr</a> was his favorite tool to use for site searching. With only a few weeks until the deadline we didn&#8217;t really have time to obtain knowledge about using a to us completely new tool like Solr. Luckily <a href="http://blog.raspberry.nl/">Bas de Nooijer</a> was able to lend us a helping hand and we got Solr up and running and integrated in our site in just a few days! The performance benefits were amazing, though we did have some issues adding multiple locations and date ranges to the items in Solr. Without getting to much into the technical details I&#8217;ll try to explain what happened.</p>
<h4>Multiple locations and areas</h4>
<p>The newest beta versions of Solr do have support for multiple locations,  but we didn&#8217;t want to take the risk of using a beta version. On top of  that we still had the problem of multiple dates and dateranges. The problem of filtering on multiple locations and areas was solved by storing location and area ids in Solr so we could make a query in MySQL of which the resulting ids would be passed to the Solr query. If we would have a lot of locations this would still pose a problem but fortunately this was not the case.</p>
<h4>Multiple dates and dateranges</h4>
<p>Bas and I found a, what I think, clever solution for this part of the problem. We first thought we could store all days as a number within an item. Because we had items with ranges from 3000 B.C. until 1000 A.D. it turned out that an item like this really had to much days in it to be able to store it in any convenient way. This was solved by taking the full years out of these date ranges and store them in a separate field. The number of days was now small enough to be stored and we could filter by a custom date range by splitting it up into years and days and find the related items with a simple OR in the Solr query.</p>
<p>Thanks to Solr and Bas de Nooijer we could launch the site as scheduled with a very nice and fast search feature. Check it out at <a href="http://www.oneindignoordholland.nl/">Oneindig Noord-Holland</a> (site is in dutch).<a href="http://www.oneindignoordholland.nl/"><br />
</a></p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.triptic.nl/mysql-performance-nightmares-solr-to-the-rescue/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Betatest: Beating formspam with brandnew SpamBeetle</title>
		<link>http://techblog.triptic.nl/beating-formspam-with-spambeetle/</link>
		<comments>http://techblog.triptic.nl/beating-formspam-with-spambeetle/#comments</comments>
		<pubDate>Tue, 18 Jan 2011 12:42:38 +0000</pubDate>
		<dc:creator>Rick Cuijpers</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[formspam]]></category>
		<category><![CDATA[onlinespamfilter]]></category>
		<category><![CDATA[spam]]></category>
		<category><![CDATA[spambeetle]]></category>
		<category><![CDATA[triptic]]></category>

		<guid isPermaLink="false">http://techblog.triptic.nl/?p=123</guid>
		<description><![CDATA[Brandnew formspamkiller is ready for Bètatesting. Since a few years triptic has been acquainted with the guys of onlinespamfilter.nl. Onlinespamfilter.nl promises their clients to get rid of e-mail spam within 24-hours. The guys at onlinespamfilter.nl have built an ingenious filtering systeem that will recognise well over 99% of all spam. And it works! So when [...]]]></description>
			<content:encoded><![CDATA[<p><em><strong>Brandnew formspamkiller is ready for Bètatesting.</strong></em></p>
<p>Since a few years triptic  has been acquainted<em> </em>with the guys of <a href="http://www.onlinespamfilter.nl/">onlinespamfilter.nl</a>. Onlinespamfilter.nl promises their clients to get rid of e-mail spam within 24-hours. The guys at onlinespamfilter.nl have built an ingenious filtering systeem that will recognise well over 99% of all spam. And it works! So when the developers at <a title="triptic" href="http://www.triptic.nl">triptic</a> were working on some of our clients&#8217; weblogs, trying to get rid of form spam, we discussed this issue with Gerard and Jasper at onlinespamfilter.nl. We talked about using the powerful spamfilter combined with an API, in order to get rid of formspam in much the same way as getting rid of e-mailspam.</p>
<p>As you might know -when you&#8217;re a blogger for instance- that formspam can be a drag. Your blog makes it possible for people to post comments. That&#8217;s what makes your blog lively. Yeah! Sadly, spambots can also find their way to your commentbox. Result: you have to work your way through hundreds of irrelevant comments before you get to that one intelligent comment made by a designated reader. There is a &#8220;solution&#8221;. Of course! Just let readers type an unidentifiable series of letters, numbers and dollarsigns in a small box and all will be fine. &lt;Not&gt;.</p>
<p>So, the task before us seemed easy enough. Together we had to come up with someting clever. And we did! As a result <strong>you now can bèta-test our formspam killer</strong>. We lovingly call her SpamBeetle. SpamBeetle is available as a WordPress plugin. Little as she may be, she will beat the hell out of spam. Want to try it for your self? <a href="mailto:spambeetle@triptic.nl">Send an e-mail to let us know that you want to be one of our béta-testers</a>. We&#8217;ll send you al the information and API&#8217;s you need.</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.triptic.nl/beating-formspam-with-spambeetle/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Moving wordpress using the ezmigrate plugin</title>
		<link>http://techblog.triptic.nl/moving-wordpress-using-the-ezmigrate-plugin/</link>
		<comments>http://techblog.triptic.nl/moving-wordpress-using-the-ezmigrate-plugin/#comments</comments>
		<pubDate>Mon, 29 Mar 2010 19:07:41 +0000</pubDate>
		<dc:creator>Onno Marsman</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ezmigrate]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://techblog.triptic.nl/?p=81</guid>
		<description><![CDATA[Following up on my rather complex post about how the ezmigrate plugin came to life, this will be a simpler tutorial style post in which I will explain how to actually use the ezmigrate plugin to move or migrate your wordpress installation. Keep in mind that some plugins might not work and need additional configuration changes [...]]]></description>
			<content:encoded><![CDATA[<p>Following up on my rather complex <a href="/ezmigrate-plugin-for-wordpress/">post</a> about how the <a href="http://wordpress.org/extend/plugins/ezmigrate/" target="_self">ezmigrate plugin</a> came to life, this will be a simpler tutorial style post in which I will explain how to actually use the ezmigrate plugin to move or migrate your wordpress installation.</p>
<p><span id="more-81"></span>Keep in mind that some plugins might not work and need additional configuration changes after you have moved your blog. Please let me know about them.</p>
<p>I will distinguish between two types of migration: Only changing the url and moving to a new server.</p>
<h3><strong>Changing the url</strong></h3>
<p>You will only change the url to your wordpress installation. The code and database will stay on the same server. If you&#8217;re moving to a new server, please scroll down to &#8220;Moving to a new server&#8221;.</p>
<ol>
<li><a href="http://wordpress.org/extend/plugins/ezmigrate/installation/" target="_blank">Install the ezmigrate plugin</a> (when it&#8217;s not already installed).</li>
<li>Make the url change. For example by moving or renaming the wordpress directory or creating the new domain name and point it to your installation.</li>
<li>If you are using a caching plugin: empty or delete the cache folder(s).</li>
<li>If you are using <a title="Using Permalinks" href="http://codex.wordpress.org/Using_Permalinks">Permalinks</a>: go to the <a title="Administration Panels" href="http://codex.wordpress.org/Administration_Panels">Administration</a> &gt; <a title="Administration Panels" href="http://codex.wordpress.org/Administration_Panels#Options_-_Configuration_Settings">Settings</a> &gt; <a title="Settings Permalinks SubPanel" href="http://codex.wordpress.org/Settings_Permalinks_SubPanel">Permalinks</a> panel and update  your Permalink structure to your <a title="Glossary" href="http://codex.wordpress.org/Glossary#.htaccess">.htaccess</a> file, which should be in the same directory as the main <tt>index.php</tt> file. (Text copied from the <a href="http://codex.wordpress.org/Moving_WordPress">wordpress codex</a>).</li>
</ol>
<p>That&#8217;s it. There is no need to change any settings or do a search and replace in your database.</p>
<p>When you&#8217;ve moved to a new domain name and you don&#8217;t use any caching tool you will find that your wordpress installation still works on your old domain name as long as it still exists.</p>
<p>When you do use a caching tool and still expect visitors on your old domain you will need to make sure your old domain name will redirect to your new domain to prevent the cache from filling with pages containing old urls. This can be achieved for example by placing the following code at the top of the file wp-config.php:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_HOST'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">!=</span><span style="color: #0000ff;">'www.newdomain.com'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'HTTP/1.1 301 Moved Permanently'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Location: http://www.newdomain.com'</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>Moving to a new server</h3>
<ol>
<li><a href="http://wordpress.org/extend/plugins/ezmigrate/installation/" target="_blank">Install the ezmigrate plugin</a> (when it&#8217;s not already installed).</li>
<li>Get a backup of your database by using any of the methods described at: <a href="http://codex.wordpress.org/Backing_Up_Your_Database" target="_blank">http://codex.wordpress.org/Backing_Up_Your_Database</a></li>
<li>Download all of the wordpress files to your local computer.</li>
<li>Edit wp-config.php and change the database settings for the new server.</li>
<li>Upload all of the wordpress files from your local computer to the new server.</li>
<li>Place your database backup into the new database by using any of the method described at: <a href="http://codex.wordpress.org/Restoring_Your_Database_From_Backup" target="_blank">http://codex.wordpress.org/Restoring_Your_Database_From_Backup</a></li>
<li>If you are using a caching plugin: empty or delete the cache folder(s).</li>
<li>If you are using <a title="Using Permalinks" href="http://codex.wordpress.org/Using_Permalinks">Permalinks</a>: go to the <a title="Administration Panels" href="http://codex.wordpress.org/Administration_Panels">Administration</a> &gt; <a title="Administration Panels" href="http://codex.wordpress.org/Administration_Panels#Options_-_Configuration_Settings">Settings</a> &gt; <a title="Settings Permalinks SubPanel" href="http://codex.wordpress.org/Settings_Permalinks_SubPanel">Permalinks</a> panel and update your Permalink structure to your <a title="Glossary" href="http://codex.wordpress.org/Glossary#.htaccess">.htaccess</a> file, which should be in the same directory as the main <tt>index.php</tt> file. (Text copied from the <a href="http://codex.wordpress.org/Moving_WordPress">wordpress codex</a>)</li>
</ol>
<p>Again:  There is no need to change any settings or do a search and replace in your database.</p>
<p>Related articles:</p>
<ul>
<li><a href="/ezmigrate-plugin-for-wordpress/">ezMigrate plugin for  WordPress</a></li>
<li><a href="http://codex.wordpress.org/Moving_WordPress">http://codex.wordpress.org/Moving_WordPress</a></li>
<li><a href="http://codex.wordpress.org/Changing_The_Site_URL">http://codex.wordpress.org/Changing_The_Site_URL</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://techblog.triptic.nl/moving-wordpress-using-the-ezmigrate-plugin/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>Simulating closures in php versions prior to php 5.3</title>
		<link>http://techblog.triptic.nl/simulating-closures-in-php-versions-prior-to-php-5-3/</link>
		<comments>http://techblog.triptic.nl/simulating-closures-in-php-versions-prior-to-php-5-3/#comments</comments>
		<pubDate>Sun, 28 Mar 2010 13:17:48 +0000</pubDate>
		<dc:creator>Onno Marsman</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[closure]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://techblog.triptic.nl/?p=70</guid>
		<description><![CDATA[<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/techblog/domains/techblog.triptic.nl/public_html/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>1904</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/techblog/domains/techblog.triptic.nl/public_html/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>1904</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/techblog/domains/techblog.triptic.nl/public_html/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>2257</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/techblog/domains/techblog.triptic.nl/public_html/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3206</b><br />
<br />
<b>Warning</b>:  implode() [<a href='function.implode'>function.implode</a>]: Argument must be an array in <b>/home/techblog/domains/techblog.triptic.nl/public_html/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3258</b><br />
<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/techblog/domains/techblog.triptic.nl/public_html/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3289</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/techblog/domains/techblog.triptic.nl/public_html/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3289</b><br />
<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/techblog/domains/techblog.triptic.nl/public_html/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3332</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/techblog/domains/techblog.triptic.nl/public_html/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3332</b><br />
<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/techblog/domains/techblog.triptic.nl/public_html/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3477</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/techblog/domains/techblog.triptic.nl/public_html/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3477</b><br />
Now that PHP 5.3 has closure and lambda function support, we all would like to use it. However, not all of us are able to do so because we are still stuck with hosting providers not able or willing to upgrade to PHP 5.3. Wanting to use closures myself on servers that only support PHP [...]]]></description>
			<content:encoded><![CDATA[<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/techblog/domains/techblog.triptic.nl/public_html/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>1904</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/techblog/domains/techblog.triptic.nl/public_html/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>1904</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/techblog/domains/techblog.triptic.nl/public_html/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>2257</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/techblog/domains/techblog.triptic.nl/public_html/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3206</b><br />
<br />
<b>Warning</b>:  implode() [<a href='function.implode'>function.implode</a>]: Argument must be an array in <b>/home/techblog/domains/techblog.triptic.nl/public_html/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3258</b><br />
<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/techblog/domains/techblog.triptic.nl/public_html/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3289</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/techblog/domains/techblog.triptic.nl/public_html/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3289</b><br />
<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/techblog/domains/techblog.triptic.nl/public_html/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3332</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/techblog/domains/techblog.triptic.nl/public_html/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3332</b><br />
<br />
<b>Warning</b>:  array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in <b>/home/techblog/domains/techblog.triptic.nl/public_html/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3477</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/techblog/domains/techblog.triptic.nl/public_html/wp-content/plugins/wp-syntax/geshi/geshi.php</b> on line <b>3477</b><br />
<p>Now that PHP 5.3 has closure and lambda function support, we all would like to use it. However, not all of us are able to do so because we are still stuck with hosting providers not able or willing to upgrade to PHP 5.3. Wanting to use closures myself on servers that only support PHP 5.2 I came up with a solution to be able to use closures in PHP 5 versions prior to 5.3:</p>
<p><span id="more-70"></span></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
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>
<span style="color: #000000; font-weight: bold;">class</span> PhpClosure
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$variables</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$callback</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span> <span style="color: #000088;">$variables</span><span style="color: #339933;">,</span> <span style="color: #000088;">$callback</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">variables</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$variables</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">callback</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$callback</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    static <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> get<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span> <span style="color: #000088;">$variables</span><span style="color: #339933;">,</span> <span style="color: #000088;">$callback</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$closure</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$variables</span><span style="color: #339933;">,</span> <span style="color: #000088;">$callback</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$closure</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'call'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #339933;">&amp;</span>__get<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">variables</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __set<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">variables</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> call<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$arguments</span> <span style="color: #339933;">=</span> <span style="color: #990000;">func_get_args</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">array_unshift</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$arguments</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #990000;">call_user_func_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">callback</span><span style="color: #339933;">,</span> <span style="color: #000088;">$arguments</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Before we take a look at some usage examples, let&#8217;s first take a look at some code that uses a closure in PHP 5.3:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>
<span style="color: #000088;">$var</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$f</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span> use <span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$var</span> <span style="color: #339933;">+=</span> <span style="color: #000088;">$i</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$var</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;br /&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$f</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$var</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;br /&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$f</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$var</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;br /&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>This produces the following output:</p>

<div class="wp_syntax"><div class="code"><pre class="" style="font-family:monospace;"><span style="">1</span>
<span style="">3</span>
<span style="">6</span></pre></div></div>

<p>All following code snippets use the PhpClosure class to do exactly the same thing and produce the same output without PHP 5.3:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>
<span style="color: #000088;">$var</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$f</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PhpClosure<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'var'</span><span style="color: #339933;">=&gt;&amp;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">create_function</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'$closure,$i'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'
    $closure-&gt;var += $i;
'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$var</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;br /&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$f</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">call</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$var</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;br /&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$f</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">call</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$var</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;br /&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>This looks a lot like the PHP5.3 code snippet! Of course, if you don&#8217;t like the way <code>$closure-&gt;var</code> needs to be called you can always add an extra <code>$var =&amp; $closure-&gt;var;</code>.</p>
<p>Personally I don&#8217;t like the way create_function works. In my opinion the way you need to provide code inside a string makes it just as <a href="http://www.google.com/search?q=evil+eval" target="_blank">evil as eval</a>. Also, your editor won&#8217;t show syntax highlighting or code completion for code inside a string. To overcome this I&#8217;ll give a name to my anonymous function. Now it&#8217;s not an anonymous function anymore, but the closure still works:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>
<span style="color: #000088;">$var</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">function</span> increase<span style="color: #009900;">&#40;</span><span style="color: #000088;">$closure</span><span style="color: #339933;">,</span> <span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$closure</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">var</span> <span style="color: #339933;">+=</span> <span style="color: #000088;">$i</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$f</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PhpClosure<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'var'</span><span style="color: #339933;">=&gt;&amp;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'increase'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$var</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;br /&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$f</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">call</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$var</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;br /&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$f</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">call</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$var</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;br /&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>This is also possible using methods within objects by passing <code>array($this, 'methodName')</code> instead of <code>'increase'</code>.</p>
<p>The last code snippet shows how to get a variable of the callback type to be able to use it with functions like <a href="http://www.php.net/call_user_func" target="_blank">call_user_func</a>, <a href="http://www.php.net/usort" target="_blank">usort</a> or <a href="http://www.php.net/array_map" target="_blank">array_map</a>:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>
<span style="color: #000088;">$var</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">function</span> increase<span style="color: #009900;">&#40;</span><span style="color: #000088;">$closure</span><span style="color: #339933;">,</span> <span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$closure</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">var</span> <span style="color: #339933;">+=</span> <span style="color: #000088;">$i</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$f</span> <span style="color: #339933;">=</span> PhpClosure<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'var'</span><span style="color: #339933;">=&gt;&amp;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'increase'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$var</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;br /&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #990000;">call_user_func</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$var</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;br /&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #990000;">call_user_func</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$var</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;br /&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Related articles:</p>
<ul>
<li><a href="http://www.steike.com/code/php-closures/">http://www.steike.com/code/php-closures/</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://techblog.triptic.nl/simulating-closures-in-php-versions-prior-to-php-5-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ezMigrate plugin for WordPress</title>
		<link>http://techblog.triptic.nl/ezmigrate-plugin-for-wordpress/</link>
		<comments>http://techblog.triptic.nl/ezmigrate-plugin-for-wordpress/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 09:22:02 +0000</pubDate>
		<dc:creator>Onno Marsman</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ezmigrate]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://dev2.triptic.net/~onno/projects/triptic_techblog/?p=6</guid>
		<description><![CDATA[While setting up a development environment last month for an extensive blog using WordPress I once more encountered a problem which I ran up against every single time I had worked with WordPress. The absolute urls stored in constants, options and post contents got in my way again. Now it was the time to find [...]]]></description>
			<content:encoded><![CDATA[<p>While setting up a development environment last month for an extensive blog using WordPress I once more encountered a problem which I ran up against every single time I had worked with WordPress. The absolute urls stored in constants, options and post contents got in my way again. Now it was the time to find a solution for this and take matters into my own hands.</p>
<p><span id="more-6"></span><strong>Introduction<br />
</strong>At triptic we like to develop our projects on a development server using a Version Control System. That way we can work with multiple people on the same project and test it before putting it on a production server. We all have our own checkout of a project and our own url through which we can view our checkout of the project so we can test our code before committing it to the repository. We also like to use the same single database for all developers so we can look at the same content and the same settings. I know there are reasons not to do this, but for smaller projects it&#8217;s just a fast way of getting things done. When a project is finished we migrate everything to a test server so the customer can have a look at it before we move it to the production server. Because development on a project is never finished we need to be able to make code changes on the development server. We also need to be able to test it with the newest content, so we often move the production database back to the development database before putting the newest code onto the production server.</p>
<p>Short version:</p>
<ul>
<li>Our projects need to migrate <em><strong>a lot</strong></em></li>
<li>On a development server our projects need to be available through multiple urls at the same time</li>
</ul>
<p><strong>Our own solution</strong><br />
This is why our home grown Content Management System determines its location on the fly and puts a &lt;base href=&#8221;"&gt; in the header of every page. Additionally the current directory within PHP is always set to the root location of the CMS. This way we can use relative urls and relative locations everywhere in the code and we can move projects anywhere without the need to change anything. But sometimes our own CMS is just not the right tool for the job and we need to use some other framework or CMS.</p>
<p><strong>The problem with WordPress</strong><br />
When we need to create a blog the obvious choice is to use WordPress. Unfortunately it doesn&#8217;t have the same characteristics  as our own CMS that allow it to migrate so easily. Absolute paths our stored in the database which need to be changed every time the project changes location. There are ways to do search and replaces and there even are plugins that help you to do this, but I really don&#8217;t like doing this every single time the project switches location. It also isn&#8217;t possible to view the project through multiple urls at the same time which doesn&#8217;t allow for development the way we&#8217;d like to.</p>
<p>So&#8230;, I went on a mission to fix this.</p>
<p>The result:<br />
the ezMigrate plugin for WordPress</p>
<p><strong>ezMigrate plugin</strong></p>
<p>The ezMigrate plugin does the following things:</p>
<ul>
<li>It determines the root url of the blog.</li>
<li>It replaces the options &#8220;siteurl&#8221;, &#8220;home&#8221;, &#8220;upload_path&#8221; and &#8220;fileupload_url&#8221; to the correct values, independent of their values stored inside the database.</li>
<li>When not already set in wp-config.php it sets the constants WP_CONTENT_URL, COOKIEPATH and SITECOOKIEPATH to the correct values.</li>
<li>When a post is saved into the database it replaces all root urls in href and src attributes with a placeholder. (This is also done for all posts when the plugin is activated).</li>
<li>When a post is retrieved from the database it replaces all placeholders with the current calculated root url. (This is also done for all posts when the plugin is deactivated).</li>
</ul>
<p>This way you don&#8217;t need to do anything when you migrate your blog and you can even make your blog accessible through multiple urls. It made life for me and the other developers at triptic a lot easier when we need to develop blogs using wordpress.</p>
<p>What this plugin doesn&#8217;t do (but might do in the future):</p>
<ul>
<li>Put a &lt;base href=&#8221;"&gt; in the header of your template. You can easily do this yourself by placing  <code>&lt;base href="&lt;?php echo ezMigrate_getFullUrl();?&gt;/" /&gt; </code>right after the &lt;head&gt; tag in the header.php file of your theme.</li>
<li>Replace urls outside of the four mentioned options or outside of href and src attributes in posts. But so far it has been sufficient for my projects.</li>
<li>Make changes that might be necessary in the .htaccess file.</li>
</ul>
<p>This plugin is a step towards setting up a development environment with a VCS and multiple developers but there are still some problems to overcome. The contents of the .htaccess file are still dependent on the location and you might not wish to leave the .htaccess file sitting outside of the repository. I will write more about how to solve this in a future post, as well as what to do with the wp-content directory.</p>
<p><a href="http://wordpress.org/extend/plugins/ezmigrate/">Download the ezMigrate plugin for WordPress</a> and follow the <a href="http://wordpress.org/extend/plugins/ezmigrate/installation/">installation instructions</a>.</p>
<p>Comments on the usage of this plugin and suggestions are greatly appreciated.</p>
<p>Related articles:</p>
<ul>
<li><a href="/moving-wordpress-using-the-ezmigrate-plugin/"></a><a href="/moving-wordpress-using-the-ezmigrate-plugin/">Moving wordpress using the ezMigrate plugin</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://techblog.triptic.nl/ezmigrate-plugin-for-wordpress/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
	</channel>
</rss>

