<?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>The Coloured Keyboard &#187; PHP</title>
	<atom:link href="http://www.morgadinho.org/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.morgadinho.org</link>
	<description>Great Throughput, Less Waste</description>
	<lastBuildDate>Thu, 26 Jan 2012 14:42:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>PHP with gettext support on Mac OS X</title>
		<link>http://www.morgadinho.org/2011/11/05/php-with-gettext-support-on-mac-os-x/</link>
		<comments>http://www.morgadinho.org/2011/11/05/php-with-gettext-support-on-mac-os-x/#comments</comments>
		<pubDate>Sat, 05 Nov 2011 15:21:30 +0000</pubDate>
		<dc:creator>Nuno Morgadinho</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.morgadinho.org/?p=3044</guid>
		<description><![CDATA[PHP comes installed on OS X by default but it doesn&#8217;t come compiled with gettext support. So once you try to do something with gettext you will likely see something like this error message: Fatal error: Call to undefined function &#8230; <a href="http://www.morgadinho.org/2011/11/05/php-with-gettext-support-on-mac-os-x/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>PHP comes installed on OS X by default but it doesn&#8217;t come compiled with gettext support. So once you try to do something with gettext you will likely see something like this error message:</p>
<p><strong>Fatal error: Call to undefined function bindtextdomain()</strong></p>
<p>At this point you might be tempted to recompile PHP to add gettext but in fact there&#8217;s a better way, you can simply add it as a dynamically loaded library.</p>
<p>To do that download your version of php and do the following:<br />
<code><br />
(inside the php directory)<br />
cd ext/gettext<br />
phpize<br />
MACOSXDEPLOYMENTTARGET=10.6 CFLAGS="-arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp" CCFLAGS="-arch i386 -arch x86_64 -g -Os -pipe" CXXFLAGS="-arch i386 -arch x86_64 -g -Os -pipe" LDFLAGS="-arch i386 -arch x86_64 -bindatload" ./configure<br />
make<br />
sudo make install<br />
</code></p>
<p>When done, edit your php.ini (normally located in /etc) and add:<br />
<code><br />
extension=/usr/lib/php/extensions/no-debug-non-zts-20090626/gettext.so<br />
</code></p>
<p>Next just restart apache and you should be all done.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.morgadinho.org/2011/11/05/php-with-gettext-support-on-mac-os-x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress Development Course and stuff</title>
		<link>http://www.morgadinho.org/2011/01/14/wordpress-development-course-and-stuff/</link>
		<comments>http://www.morgadinho.org/2011/01/14/wordpress-development-course-and-stuff/#comments</comments>
		<pubDate>Fri, 14 Jan 2011 23:57:03 +0000</pubDate>
		<dc:creator>Nuno Morgadinho</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.morgadinho.org/?p=2742</guid>
		<description><![CDATA[I will be running a WordPress Development course of P2PU, starting from the 26th of January 2010. For more information visit the course page. As a sign-up task for this course I thought that it would be fun for people &#8230; <a href="http://www.morgadinho.org/2011/01/14/wordpress-development-course-and-stuff/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I will be running a WordPress Development course of P2PU, starting from the 26th of January 2010. For more information visit the course page.</p>
<p>As a sign-up task for this course I thought that it would be fun for people to modify the Hello Dolly plugin with their favorite quotes. One of the plugins that resulted from this exercise is one with quotes from Da Vinci, which I find to be brilliant. </p>
<p><a href="http://p2pu.org/webcraft/wordpress-development">http://p2pu.org/webcraft/wordpress-development</a></p>
<p><a href="http://wordpress.org/extend/plugins/hello-da-vinci/">http://wordpress.org/extend/plugins/hello-da-vinci/</a></p>
<p>Thanks to all of you that signed up for this course, I was really suprissed to see so many people interested and now I&#8217;m really looking forward to it and I intend to do my best. Thanks!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.morgadinho.org/2011/01/14/wordpress-development-course-and-stuff/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WPMU posts return 404 not found</title>
		<link>http://www.morgadinho.org/2010/01/12/wpmu-posts-return-404-not-found/</link>
		<comments>http://www.morgadinho.org/2010/01/12/wpmu-posts-return-404-not-found/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 16:53:38 +0000</pubDate>
		<dc:creator>Nuno Morgadinho</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.morgadinho.org/?p=2234</guid>
		<description><![CDATA[I&#8217;ve installed WordPress MU on a fresh Apache httpd and I go to try it out. I start by clicking on the &#8216;hello world&#8217; post that comes as default and the page returns a 404 &#8220;not found&#8221; message. What is &#8230; <a href="http://www.morgadinho.org/2010/01/12/wpmu-posts-return-404-not-found/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve installed WordPress MU on a fresh Apache httpd and I go to try it out. I start by clicking on the &#8216;hello world&#8217; post that comes as default and the page returns a 404<span> &#8220;not found&#8221; message. What is happening? This keeps happening to me all the time so I might as well share it here for others.<br />
</span></p>
<p>This can be fixed this by setting &#8220;AllowOverride to All&#8221; in the httpd.conf file, in the relevant Directory directive section where MU is installed.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.morgadinho.org/2010/01/12/wpmu-posts-return-404-not-found/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Authentication by POST/GET in WordPress</title>
		<link>http://www.morgadinho.org/2009/11/25/authentication-by-postget-in-wordpress/</link>
		<comments>http://www.morgadinho.org/2009/11/25/authentication-by-postget-in-wordpress/#comments</comments>
		<pubDate>Wed, 25 Nov 2009 18:07:10 +0000</pubDate>
		<dc:creator>Nuno Morgadinho</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://evolreverse.wordpress.com/?p=2053</guid>
		<description><![CDATA[For a project I&#8217;m working on I needed to trigger an action in a remote WordPress installation. I had a bit of trouble understanding how I could authenticate myself against the remote site. Eventually I found a clean and nice &#8230; <a href="http://www.morgadinho.org/2009/11/25/authentication-by-postget-in-wordpress/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>For a project I&#8217;m working on I needed to trigger an action in a remote WordPress installation. I had a bit of trouble understanding how I could authenticate myself against the remote site. Eventually I found a clean and nice way and I want to share it here with you. Of course, if you&#8217;re not into WordPress you can safely skip this post.</p>
<p><strong>The Problem</strong></p>
<p>Where I first stumbled was when from my plugin I tried to access directly the other plugin in the remote site. The code I was using for doing this was something like:</p>
<p><code><br />
	// create curl resource<br />
	$ch = curl_init();<br />
	// set url<br />
	curl_setopt($ch, CURLOPT_URL, "http://wordpress.mu/wp-admin/admin.php?page=myplugin");<br />
	//return the transfer as a string<br />
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);<br />
	// $output contains the output string<br />
	$output = curl_exec($ch);<br />
	// close curl resource to free up system resources<br />
	curl_close($ch);<br />
	// print the result of the whole request:<br />
	print "CONTENT = ".$output;<br />
</code></p>
<p>And this wouldn&#8217;t work because although I was authenticated in the remote site via the browser, the session that the curl request creates is not, and so this request results in us being redirected to the login page.</p>
<p><strong>What to do?</strong></p>
<p>Ideally we want to do a POST request that we execute before and that authenticates us. I searched around on how to do this but couldn&#8217;t find anything. What I found was one of the many third-party applications that allow talking to WordPress remotely. I then looked at how they work and how they authenticate themselves.</p>
<p>Instead of doing a POST request to the plugin page like before, they do a POST request to the site&#8217;s index.php. A plugin is registered to catch a particular POST request. Then you simple use the WordPress function user_pass_ok(), that authenticates the user against the database.</p>
<p>Here I demonstrate how to do this using a GET request, because its simpler, but the same thing would work with a POST request.<br />
<code><br />
add_action('plugins_loaded', 'unpackimport_createblog', -1);<br />
function unpackimport_createblog() {<br />
	if(isset($_GET['myplugin'])) {<br />
			if(user_pass_ok($_REQUEST['username'], $_REQUEST['password']))<br />
				echo 'Authentication successful';<br />
}<br />
</code></p>
<p>And the client request:<br />
<code><br />
curl_setopt($ch, CURLOPT_URL, "http://wordpress.mu/index.php?myplugin=true&amp;username=test&amp;password=testpass");<br />
</code></p>
<p><strong>Screencast</strong></p>
<p>I wanted to show a working example rather than just saying this works so I did this screencast. You can also download the plugins yourself and try them out.</p>
<p><a href="http://www.youtube.com/watch?v=Ort-IMmpo4s">http://www.youtube.com/watch?v=Ort-IMmpo4s</a></p>
<p><strong>Download</strong></p>
<p><a href="http://www.morgadinho.org/static/unpack_import_demo.tar.gz">unpack_import_demo.tar.gz</a><br />
<a href="http://www.morgadinho.org/static/dump_pack_demo.tar.gz">dump_pack_demo.tar.gz</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.morgadinho.org/2009/11/25/authentication-by-postget-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress Media Buttons</title>
		<link>http://www.morgadinho.org/2009/10/16/wordpress-media-buttons/</link>
		<comments>http://www.morgadinho.org/2009/10/16/wordpress-media-buttons/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 21:30:45 +0000</pubDate>
		<dc:creator>Nuno Morgadinho</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.morgadinho.org/?p=1912</guid>
		<description><![CDATA[<p>
If you know Wordpress, you know it is a great publishing platform. For a particular plugin I wanted to build I started looking at how to add one of those little icons you have access while writing a post, e.g. &#8216;Add an Image&#8217;, etc.
</p>
<p>
I was looking at how other plugins do this and found this code:
</p>

<pre class="code">
function wp_myplugin_media_button() {
	$context = __('Add media: %s');
	$wp_myplugin_media_button_image = '/path/media_button.gif';
	$wp_myplugin_media_button = '&lt;a href=&quot;media-upload.php?type=wp_myplugin&amp;amp;TB_iframe=true&quot; class=&quot;thickbox&quot;&gt;
  &lt;img src='&quot;.$wp_myplugin_media_button_image.&quot;' /&gt;&lt;/a&gt;&quot;.' %s';
	return sprintf($context, $wp_myplugin_media_button);
}
add_filter('media_buttons_context', 'wp_myplugin_media_button');
</pre>

<p>
But when I tried this in my plugin something weird happened. If both my plugin and the one from where I took this code were active, then only the button from the other plugin would appear. If I disabled the second one then it worked. Why, oh why? After struggling a bit I found the answer.
</p>
<p>
The way the function is receiving the context is not correct. Both functions are asking for the default &#8220;context&#8221; (this is the media buttons themselves) and then adding something to it. The correct way to receive the context is to have it as an argument of the function. In that way it can be updated without a problem. Example follows:
</p>

<pre class="code">
function wp_myplugin_media_button($context) {
	$wp_myplugin_media_button_image = '/path/media_button.gif';
	$wp_myplugin_media_button = '&lt;a href=&quot;media-upload.php?type=wp_myplugin&amp;amp;TB_iframe=true&quot; class=&quot;thickbox&quot;&gt;
  &lt;img src='&quot;.$wp_myplugin_media_button_image.&quot;' /&gt;&lt;/a&gt;&quot;.' %s';
	return sprintf($context, $wp_myplugin_media_button);
}
add_filter('media_buttons_context', 'wp_myplugin_media_button');
</pre>

<p>
Update: if you want to add the button to the end of the media button list just append the %s first, e.g.:
</p>

<pre class="code">
function wp_myplugin_media_button($context) {
	$wp_myplugin_media_button_image = '/path/media_button.gif';
	$wp_myplugin_media_button = ' %s' . '&lt;a href=&quot;media-upload.php?type=wp_myplugin&amp;amp;TB_iframe=true&quot; class=&quot;thickbox&quot;&gt;
  &lt;img src='&quot;.$wp_myplugin_media_button_image.&quot;' /&gt;&lt;/a&gt;&quot;;
	return sprintf($context, $wp_myplugin_media_button);
}
add_filter('media_buttons_context', 'wp_myplugin_media_button');
</pre>

<p>
Hope it helps someone. Cheers.
</p>]]></description>
			<content:encoded><![CDATA[<p>
If you know Wordpress, you know it is a great publishing platform. For a particular plugin I wanted to build I started looking at how to add one of those little icons you have access while writing a post, e.g. &#8216;Add an Image&#8217;, etc.
</p>
<p>
I was looking at how other plugins do this and found this code:
</p>

<pre class="code">
function wp_myplugin_media_button() {
	$context = __('Add media: %s');
	$wp_myplugin_media_button_image = '/path/media_button.gif';
	$wp_myplugin_media_button = '&lt;a href=&quot;media-upload.php?type=wp_myplugin&amp;amp;TB_iframe=true&quot; class=&quot;thickbox&quot;&gt;
  &lt;img src='&quot;.$wp_myplugin_media_button_image.&quot;' /&gt;&lt;/a&gt;&quot;.' %s';
	return sprintf($context, $wp_myplugin_media_button);
}
add_filter('media_buttons_context', 'wp_myplugin_media_button');
</pre>

<p>
But when I tried this in my plugin something weird happened. If both my plugin and the one from where I took this code were active, then only the button from the other plugin would appear. If I disabled the second one then it worked. Why, oh why? After struggling a bit I found the answer.
</p>
<p>
The way the function is receiving the context is not correct. Both functions are asking for the default &#8220;context&#8221; (this is the media buttons themselves) and then adding something to it. The correct way to receive the context is to have it as an argument of the function. In that way it can be updated without a problem. Example follows:
</p>

<pre class="code">
function wp_myplugin_media_button($context) {
	$wp_myplugin_media_button_image = '/path/media_button.gif';
	$wp_myplugin_media_button = '&lt;a href=&quot;media-upload.php?type=wp_myplugin&amp;amp;TB_iframe=true&quot; class=&quot;thickbox&quot;&gt;
  &lt;img src='&quot;.$wp_myplugin_media_button_image.&quot;' /&gt;&lt;/a&gt;&quot;.' %s';
	return sprintf($context, $wp_myplugin_media_button);
}
add_filter('media_buttons_context', 'wp_myplugin_media_button');
</pre>

<p>
Update: if you want to add the button to the end of the media button list just append the %s first, e.g.:
</p>

<pre class="code">
function wp_myplugin_media_button($context) {
	$wp_myplugin_media_button_image = '/path/media_button.gif';
	$wp_myplugin_media_button = ' %s' . '&lt;a href=&quot;media-upload.php?type=wp_myplugin&amp;amp;TB_iframe=true&quot; class=&quot;thickbox&quot;&gt;
  &lt;img src='&quot;.$wp_myplugin_media_button_image.&quot;' /&gt;&lt;/a&gt;&quot;;
	return sprintf($context, $wp_myplugin_media_button);
}
add_filter('media_buttons_context', 'wp_myplugin_media_button');
</pre>

<p>
Hope it helps someone. Cheers.
</p>]]></content:encoded>
			<wfw:commentRss>http://www.morgadinho.org/2009/10/16/wordpress-media-buttons/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

