<?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>3DN Technology Blog</title>
	<atom:link href="http://wordpress.3dn.nl/feed/" rel="self" type="application/rss+xml" />
	<link>http://wordpress.3dn.nl</link>
	<description>Just another 3DN Site</description>
	<lastBuildDate>Mon, 17 May 2010 10:06:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0-beta2-14576</generator>
		<item>
		<title>New 3DN Techblog</title>
		<link>http://wordpress.3dn.nl/2010/05/12/migrating-wordpress/</link>
		<comments>http://wordpress.3dn.nl/2010/05/12/migrating-wordpress/#comments</comments>
		<pubDate>Wed, 12 May 2010 14:33:09 +0000</pubDate>
		<dc:creator>wordpress</dc:creator>
				<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://wordpress.3dn.nl/?p=1</guid>
		<description><![CDATA[This is the first post on the Wordpress 3.0 MU server. http://wordpress.3dn.nl has now become a &#8216;site&#8217; under the main blog http://3dn.nl. This is possible since 3.0 which now has the multi user functionality built in. First there will be some transitioning stage where plugins I used on the old http://wordpress.3dn.nl will be enabled on [...]]]></description>
			<content:encoded><![CDATA[<p>This is the first post on the Wordpress 3.0 MU server. http://wordpress.3dn.nl has now become a &#8216;site&#8217; under the main blog http://3dn.nl. This is possible since 3.0 which now has the multi user functionality built in.</p>
<p>First there will be some transitioning stage where plugins I used on the old http://wordpress.3dn.nl will be enabled on this site, so it&#8217;s possible that this site will look off for a while. Please bear with me, I&#8217;m still trying to figure this out.</p>
<p>The migration was fairly simple. I probably could have done it even simpler by just starting with the old database and migrating that to 3.0 but I decided to have 3.0 running in parallel with 2.9 for a while when I tackle the Debian way. I first created a MU site called http://wordpress.3dn.nl and tested that to work. Then I went on to export (using Tools -&gt; Export) in the wp-admin screen, which gave me an XML file. Then I imported this into wordpress.3dn.nl and checked the box to import attachments as well. The latter tries to fetch the attachments using the URL; since this has http://wordpress&#8230; in it, I had to temporarily leave the old server running. After it imported I renamed wordpress.3dn.nl and disabled the old wordpress.3dn.nl</p>
<p>I fully expect some plugins not to work. The first one I found not to work properly is the linkedin resume plugin. Peculiarly it failed at updating the settings. I also found EHT graphviz not to work, in fact it messed up the whole admin section.</p>
<p>There are still some major glitches on the site but I&#8217;ve decided to go for it as some problems may be related to having a different site name.</p>


<div class="shr-bookmarks shr-bookmarks-expand">
<ul class="socials">
		<li class="sexy-delicious">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-digg">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-facebook">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-twitter">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-linkedin">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-googlebuzz">
			<a href="" rel="nofollow" title=""></a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://wordpress.3dn.nl/2010/05/12/migrating-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Add Ajax to Expertise Plugin</title>
		<link>http://wordpress.3dn.nl/2010/02/28/add-ajax-to-expertise-plugin/</link>
		<comments>http://wordpress.3dn.nl/2010/02/28/add-ajax-to-expertise-plugin/#comments</comments>
		<pubDate>Sun, 28 Feb 2010 07:43:32 +0000</pubDate>
		<dc:creator>fred leeflang</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[expertise]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[thickbox]]></category>

		<guid isPermaLink="false">http://wordpress.3dn.nl/?p=1508</guid>
		<description><![CDATA[The Expertise plugin is nearing completion now. We still need to give experts a method to sign up as experts for the 3DN expertise areas (or to sign out should they no longer want to act as expert). We will be using some Wordpress specific Ajax constructs for this.]]></description>
			<content:encoded><![CDATA[ 
 
<h1>Add Ajax to Expertise Plugin</h1>
<p>The Expertise plugin is nearing completion now. We still need to give experts a method to sign up as experts for the 3DN expertise areas (or to sign out should they no longer want to act as expert). We will be using some Wordpress specific Ajax constructs for this.</p>
<p>One of the reasons we would like users to sign up and be logged in when they look at the expertise pages is so we can see right away if somebody who&#8217;s visiting the pages is an expert himself or not. This way we can decide what button to show and what action to attach to the button. We have two different buttons to choose from:</p>
<p><a href="http://wordpress.3dn.nl/files/2010/02/expert1.png"><img class="alignnone size-full wp-image-1512" src="http://wordpress.3dn.nl/files/2010/02/expert1.png" alt="" width="105" height="34" /></a> <a href="http://wordpress.3dn.nl/files/2010/02/noexpert.png"><img class="alignnone size-full wp-image-1513" src="http://wordpress.3dn.nl/files/2010/02/noexpert.png" alt="" width="128" height="35" /></a></p>
<p>These are opt-in / opt-out buttons where a visitor can indicate whether he is or isn&#8217;t an expert on the expertise being viewed.</p>
<p>These buttons have a simple onclick javascript that gets executed when the user clicks on them; when the opt-in button is clicked a simple thickbox dialog asking for the user&#8217;s expertise level is displayed while the opt-out button simply shows an &#8216;are you sure&#8217; question. In this article I&#8217;ll assume the reader is familiar with thicbox and how to pop-up a dialog.</p>
<h2>Using SACK</h2>
<p>SACK is the Simple Ajax Code Kit. We don&#8217;t want clicking the button on the popup dialog to cause a reload of the whole page so we&#8217;re using SACK to send an asynchronous page request to the server to handle the opt-in / opt-out.</p>
<p>To do this, we first need to tell Wordpress to include the SACK library javascript:</p>
<pre class="brush: php;">
// Add SACK requirement to head
add_action ('wp_head', 'expertise_js_header');

function expertise_js_header () {
 wp_print_scripts ( array ('sack') );
</pre>
<p><script type="text/javascript"><!--
google_ad_client = "pub-6394625565386592";
/* 468x60, gemaakt 3-2-10 */
google_ad_slot = "0905523941";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p>The only thing somewhat complicated for using SACK is that we need to figure out what page to post the AJAX requests to; Wordpress comes with a <em>/wp-admin/admin-ajax.php</em> script for this. It&#8217;s a unified Ajax handler script that can be used for all AJAX requests. We only need to tell it about a <em>callback</em> function to use depending on which <em>action</em> the page receives. First we define our own actions, <em>handle_signup</em> and <em>handle_signout</em>:</p>
<pre class="brush: php;">
// Configure AJAX callback
add_action ('wp_ajax_handle_signup', &quot;signup_callback&quot;);
add_action ('wp_ajax_nopriv_handle_signup', &quot;signup_callback&quot;);
add_action ('wp_ajax_handle_signout', &quot;signout_callback&quot;);
add_action ('wp_ajax_nopriv_handle_signout', &quot;signout_callback&quot;);
</pre>
<p>Then in our button javascript we use these action names in the SACK initialization:</p>
<pre class="brush: php;">
// Define custom Javascript function
?&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
//&lt;![CDATA[
function expertise_signup () {
 for (var i=0; i &lt; document.lvlfrm.lvlval.length; i++) {
 if (document.lvlfrm.lvlval[i].checked) {
 var expertise_level = document.lvlfrm.lvlval[i].value;
 }
 }
 var mysack = new sack (
 &quot;&lt;?php bloginfo ('wpurl'); ?&gt;/wp-admin/admin-ajax.php&quot; );

 mysack.execute = 1;
 mysack.method = 'POST';
 mysack.setVar (&quot;action&quot;, &quot;handle_signup&quot;);
 mysack.setVar (&quot;expertise_level&quot;, expertise_level);
 mysack.runAJAX();

 parent.tb_remove();
}
</pre>
<p>And finally we add the actual callback function:</p>
<pre class="brush: php;">
function signup_callback () {
 $level = $_POST['expertise_level'];
 $levels = array( 'junior', 'medior', 'senior' );
 $thelevel = $levels[$level - 1];
 $error = &quot;&quot;;
 $results = &quot;You have signed up as a $thelevel expert!&quot;;
 if ($error ) {
 die ( &quot;alert('$error')&quot; );
 }
 die( &quot;document.getElementById('$results_id').innerHTML = '$results'&quot; );
}
</pre>
<p>The callback function itself is not completely finished here but you&#8217;ll probably get the idea from this sample code.</p>
<h2>Read More</h2>
<p>If  you liked reading this article you might want to read some more articles in 3DN&#8217;s Wordpress category:</p>
<ul class="lcp_catlist"><li><a href="http://wordpress.3dn.nl/2010/05/12/migrating-wordpress/">New 3DN Techblog</a></li><li><a href="http://wordpress.3dn.nl/2010/02/28/add-ajax-to-expertise-plugin/">Add Ajax to Expertise Plugin</a></li><li><a href="http://wordpress.3dn.nl/2010/02/20/disqus-wordpres/">Checking Comments for Requests</a></li><li><a href="http://wordpress.3dn.nl/2010/02/17/adding-sendmailsmtp-to-experts-plugin/">Adding sendmail/SMTP to experts plugin</a></li><li><a href="http://wordpress.3dn.nl/2010/02/16/periodic-expertise-events/">Periodic Expertise Events</a></li></ul>
<p>Or in the Coding category:</p>
<ul class="lcp_catlist"><li><a href="http://wordpress.3dn.nl/2010/02/28/add-ajax-to-expertise-plugin/">Add Ajax to Expertise Plugin</a></li><li><a href="http://wordpress.3dn.nl/2010/02/20/disqus-wordpres/">Checking Comments for Requests</a></li><li><a href="http://wordpress.3dn.nl/2010/02/17/adding-sendmailsmtp-to-experts-plugin/">Adding sendmail/SMTP to experts plugin</a></li><li><a href="http://wordpress.3dn.nl/2010/02/16/periodic-expertise-events/">Periodic Expertise Events</a></li><li><a href="http://wordpress.3dn.nl/2010/02/15/expertise-shortcode/">Expertise Shortcode</a></li></ul>


<div class="shr-bookmarks shr-bookmarks-expand">
<ul class="socials">
		<li class="sexy-delicious">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-digg">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-facebook">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-twitter">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-linkedin">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-googlebuzz">
			<a href="" rel="nofollow" title=""></a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://wordpress.3dn.nl/2010/02/28/add-ajax-to-expertise-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Downloading from Trac</title>
		<link>http://wordpress.3dn.nl/2010/02/22/downloading-from-trac/</link>
		<comments>http://wordpress.3dn.nl/2010/02/22/downloading-from-trac/#comments</comments>
		<pubDate>Mon, 22 Feb 2010 07:44:59 +0000</pubDate>
		<dc:creator>fred leeflang</dc:creator>
				<category><![CDATA[sccm]]></category>
		<category><![CDATA[subversion]]></category>
		<category><![CDATA[tar file]]></category>
		<category><![CDATA[trac]]></category>

		<guid isPermaLink="false">http://wordpress.3dn.nl/?p=1480</guid>
		<description><![CDATA[I would like to know if it's possible to download a dynamically generated tar file from Trac.]]></description>
			<content:encoded><![CDATA[<h1>Downloading from Trac</h1>
<p>I would like to know if it&#8217;s possible to download a dynamically generated tar file from Trac. In an <a title="Wordpress Expertise Plugin" href="http://wordpress.3dn.nl/expertise/expertise-plugin/" target="_blank">expertise page </a>on this site I would like to be able to link to the source of the Expertise plugin from within the article itself. When a user clicks on this link, either Trac, Subversion or Wordpress should generate the tar file and send it as a download.</p>


<div class="shr-bookmarks shr-bookmarks-expand">
<ul class="socials">
		<li class="sexy-delicious">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-digg">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-facebook">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-twitter">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-linkedin">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-googlebuzz">
			<a href="" rel="nofollow" title=""></a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://wordpress.3dn.nl/2010/02/22/downloading-from-trac/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Checking Comments for Requests</title>
		<link>http://wordpress.3dn.nl/2010/02/20/disqus-wordpres/</link>
		<comments>http://wordpress.3dn.nl/2010/02/20/disqus-wordpres/#comments</comments>
		<pubDate>Sat, 20 Feb 2010 14:38:32 +0000</pubDate>
		<dc:creator>fred leeflang</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[disqus]]></category>
		<category><![CDATA[expertise]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://wordpress.3dn.nl/?p=1429</guid>
		<description><![CDATA[Disqus comments are no different from regular Wordpress comments. This means that checking the comments on an expertise page will be no different for Disqus comments as it is for standard Wordpress comments. Can we still find something special to do with Disqus comments?]]></description>
			<content:encoded><![CDATA[<h1>Checking Comments for Requests</h1>
<p>Disqus comments are no different from regular Wordpress comments. This means that checking the comments on an expertise page will be no different for Disqus comments as it is for standard Wordpress comments. Can we still find something special to do with Disqus comments?</p>
<p>The Disqus comment system is a really well thought out commenting system. I had imagined I would need to use the Disqus API to check for new comments on our expertise pages but no such thing; When users submit a comment through Disqus, a local copy is kept as well according to a comment by avinash on <a title="MattFlies" href="http://mattflies.com/tech/why-and-how-to-use-disqus-with-wordpress/" target="_blank">MattFlies&#8217; blog</a>. Ofcourse I verified this before believing it by posting a comment:</p>
<pre class="brush: sql;">
mysql&gt; select count(*) from wp_comments;
+----------+
| count(*) |
+----------+
|       84 |
+----------+
</pre>
<p>Then I posted a comment:</p>
<pre class="brush: sql;">
mysql&gt; select count(*) from wp_comments;
+----------+
| count(*) |
+----------+
|       84 |
+----------+
</pre>
<p>So alas, it looks like it&#8217;s not true what&#8217;s being said! I checked into this with the Disqus support and they recommended that I try their beta version. I installed it but the same issue remained. However at some point, &#8216;magically&#8217; the Disqus posts would indeed show up in my wp_comments. I guess I had assumed that the update in wp_comments would be immediate after somebody posts a message. This is not quite true; I inspected the code for the Disqus plugin:</p>
<pre class="brush: php;">
add_filter('comments_template', 'dsq_comments_template');

function dsq_comments_template($value) {
...
// Sync comments with database.
 dsq_sync_comments($post, $dsq_response['posts']);
...
}
</pre>
<p>This implies that the <em>dsq_sync_comments()</em> function only gets called when the comments_template hook is triggered. I tried this theory simply by reloading the page after I posted a comment and indeed, the counter on wp_comments increased! Well you could call this a bug or a feature I guess but for my purposes it means that I cannot rely on the Wordpress comment functions to work properly under all circumstances. So I decided to mimic the <em>dsq_sync_comments()</em> behaviour in the Expertise plugin&#8217;s hourly message check instead:</p>
<pre class="brush: php;">
// Require this in case we use Disqus on our site.
$expert_settings = get_option(&quot;expert_settings&quot;);
$disqusactive = 0;
if ($expert_settings['commentsmethod'] == 'disqus') {
 define ('DISQUS_API_FILE', WP_PLUGIN_DIR . '/disqus-comment-system/lib/api.php');
 // Check if API file exists and if plugin is activated
 if (file_exists(DISQUS_API_FILE) &amp;&amp; function_exists('dsq_sync_comments')) {
 require_once(WP_PLUGIN_DIR . '/disqus-comment-system/lib/api.php');
 $dsq_api = new DisqusAPI(get_option('disqus_forum_url'), get_option('disqus_api_key'));
 $disqusactive = 1;
 }
}

function hourly_msgcheck () {
 global $disqusactive;
 global $dsq_api;

 if ($disqusactive) {
 $args = array (
 'post_type' =&gt; 'page',
 'numberposts' =&gt; -1
 );
 $expert_posts = get_posts ($args);
 if ($expert_posts) {
 foreach ($expert_posts as $post) {
 setup_postdata($post);
 $permalink = get_permalink($post);
 $title = get_the_title($post);
 $excerpt = get_the_excerpt($post);

 // Call &quot;get_thread&quot; API method.
 $dsq_response = $dsq_api-&gt;get_thread($post, $permalink, $title, $excerpt);
 if( $dsq_response &lt; 0 ) {
 return false;
 }

 // Sync comments with database.
 dsq_sync_comments($post, $dsq_response['posts']);
 }
 }
 }
}
</pre>
<p>This seems to work rather well so far, now it&#8217;s off to actually using the Wordpress API again and checking for new messages to we can finally get to sending the new messages to the experts!</p>


<div class="shr-bookmarks shr-bookmarks-expand">
<ul class="socials">
		<li class="sexy-delicious">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-digg">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-facebook">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-twitter">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-linkedin">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-googlebuzz">
			<a href="" rel="nofollow" title=""></a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://wordpress.3dn.nl/2010/02/20/disqus-wordpres/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding sendmail/SMTP to experts plugin</title>
		<link>http://wordpress.3dn.nl/2010/02/17/adding-sendmailsmtp-to-experts-plugin/</link>
		<comments>http://wordpress.3dn.nl/2010/02/17/adding-sendmailsmtp-to-experts-plugin/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 15:26:47 +0000</pubDate>
		<dc:creator>fred leeflang</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[encryption]]></category>
		<category><![CDATA[expertise]]></category>
		<category><![CDATA[gmail]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[google apps]]></category>
		<category><![CDATA[mta postfix]]></category>
		<category><![CDATA[smtp servers]]></category>
		<category><![CDATA[smtp service]]></category>

		<guid isPermaLink="false">http://wordpress.3dn.nl/?p=1414</guid>
		<description><![CDATA[The expertise plugin I'm writing and have been publishing about needs a selector in the admin screen to allow sending mail through SMTP or through sendmail. This article will include some javascript to do just that.]]></description>
			<content:encoded><![CDATA[ 
 
<h1>Adding sendmail/SMTP to experts plugin</h1>
<p>The expertise plugin I&#8217;m writing and have been publishing about needs a selector in the admin screen to allow sending mail through SMTP or through sendmail. This article will include some javascript to do just that.</p>
<h2>GMAIL</h2>
<p>Because of my local setup at first I decided to let the experts plugin use GMAIL&#8217;s SMTP service for mailing the Experts when new expertise requests are posted. GMAIL has a great free service to allow people to use their SMTP servers to send mail through. I&#8217;m also a Google Apps user to host my own domain&#8217;s emails on GMAIL so it seemed like a natural thing to do at first. GMAIL&#8217;s setup is a little bit tricky however as not only do you need to use TLS (encryption) and authentication to use it, there are also some complications with properly setting the sender of the email.</p>
<p>I&#8217;ve long ago been able to configure my local MTA (postfix) to do all of the above but it&#8217;s apparently not so trivial to do this directly from PHP. I tried doing this using the Wordpress supplied PHPMailer class but so far I have not been able to get it to send email succesfully using SMTP.</p>
<h2>Sendmail</h2>
<p>The PHPMailer class can also send email using the sendmail method. While the sendmail name is reminiscent of the good old sendmail, it basically means to use the local MTA on the server Wordpress is running on. As I&#8217;ve configured my local MTA properly it was easy enough to get PHPMailer to send email through the sendmail method.</p>
<p>So while the experts plugin is now able to send email using the sendmail method, I&#8217;m starting to think that the plugin I&#8217;m developing may be useful to others as well down the line and I decided to keep the broken SMTP part in order to fix it later on. This means I need to have a mail method selector in the admin menu and some code in the plugin to decide what method to use based on the selector value.</p>
<h2>Adding the Selector</h2>
<p>Now that I have the <em>register_settings()</em> understood, it was fairly easy to add a selector. All that it required was to add a <em>mailmethod</em> field to the expert_settings array:</p>
<pre class="brush: php;">
add_option('expert_settings', array(
 'onpost' =&gt; 1,
 'mailmethod' =&gt; 'sendmail',
 'smtp_user' =&gt; '',
 'smtp_password' =&gt; '',
 'smtp_server' =&gt; 'smtp.gmail.com'));
</pre>
<p>As well as a select field to the admin form:</p>
<pre class="brush: xml;">
&lt;tr&gt;
 &lt;td&gt;Mail Method&lt;/td&gt;
 &lt;td&gt;&lt;select name=&quot;expert_settings[mailmethod]&quot;&gt;
 &lt;option value=&quot;smtp&quot; &lt;?php selected(&quot;smtp&quot;,$expert_settings[mailmethod]); ?&gt;&gt;SMTP&lt;/option&gt;
 &lt;option value=&quot;sendmail&quot; &lt;?php selected(&quot;sendmail&quot;,$expert_settings[mailmethod]); ?&gt;&gt;Sendmail&lt;/option&gt;
 &lt;/select&gt;&lt;/td&gt;
 &lt;tr&gt;
</pre>
<p>This literally took me like 5 minutes to do after having spent considerable time on learning the <em>register_settings()</em> stuff.</p>
<h2>Make it look Pretty</h2>
<p>Since it was so easy to add the above I figured I might as well spend some time I saved on making it look pretty; When the admin chooses to use the <em>sendmail</em> method for sending mail, the SMTP settings (eg. user/password/servername etc.) are irrelevant so we could add some Javascript to enable/disable those fields when either mail method gets selected by the user. The best way to dynamically change form fields is still by using Javascript so let&#8217;s go ahead and add a scripts directory to our project:</p>
<pre class="brush: bash;">
fredl@omega:/web/prd/wordpress.3dn.nl/wp-content/plugins/experts$ mkdir scripts
fredl@omega:/web/prd/wordpress.3dn.nl/wp-content/plugins/experts$ svn add scripts/
A         scripts
</pre>
<p>And a bit of Javascript in it&#8217;s own file:</p>
<pre class="brush: bash;">
fredl@omega:/web/prd/wordpress.3dn.nl/wp-content/plugins/experts/scripts$ svn add admin.js
A         admin.js
</pre>
<p>We need to include this inside our admin form. To do this we first need to take a step back and look at our admin menu definition again. So far we&#8217;ve only told Wordpress to add an action to the admin_menu using</p>
<pre class="brush: php;">
// Add page name, then scripts and styles
 if (function_exists('add_options_page')) {
 add_action(&quot;admin_print_scripts&quot;, 'expertise_admin_scripts');
 add_action(&quot;admin_print_styles&quot;, 'expertise_admin_styles');
 }

function expertise_admin_scripts () {
 wp_enqueue_script('expertise-js', EXPERTISE_PLUGPATH.'scripts/admin.js');
}

function expertise_admin_styles () {
  wp_enqueue_style('expertise-css', EXPERTISE_PLUGPATH.'style/admin.css');
}
</pre>
<p>This should now include our still empty piece of Javascript in our admin menu. This is not nearly perfect as the <em>add_action(&#8220;admin_print_scripts&#8221;&#8230;</em> should really have a page name like <em>add_action(&#8220;admin_print_scripts-$pagename&#8221;&#8230;.</em> to limit which admin pages the script gets enqueued in but at the time of writing this I&#8217;m not really sure how to do this. I also added a constant <em>EXPERTISE_PLUGPATH</em> to the plugin as well as a CSS file that may come in handy when we implement our JS to dynamically disable elements.</p>
<p>So now we have the JS script and the CSS in place, we need to add some action to the mailmethod select:</p>
<pre class="brush: xml;">
&lt;select name=&quot;expert_settings[mailmethod]&quot; onChange=&quot;toggleSMTP()&quot;&gt;
</pre>
<p>Remember, we want to toggle the visibility of our SMTP settings when the Sendmail or SMTP mailmethod is chosen. So in scripts/admin.js we create the Javascript function toggleSMTP():</p>
<pre class="brush: jscript;">
function toggleSMTP () {
 alert(&quot;Toggling&quot;);
}
</pre>
<p>And indeed we get a nice popup saying &#8216;Toggling&#8217; when we toggle the mailmethod in the admin screen. While the popup is a good test to see if things work so far, ofcourse it needs some real functionality now so we wrap our SMTP settings into a div. We define the div style first in admin.css, calling it simply &#8216;#smtpsettings&#8217; and wrapping our SMTP settings in it. The problem with this is that tables, which I used to layout the settings menu initially, don&#8217;t behave very nicely with CSS, so since I added some custom CSS file to the menu anyway I decided to make the settings menu a CSS based layout instead. I also decided to disable the SMTP inputs instead of making them invisible. So in <em>toggleSMTP()</em> we first want to get the selected value of the mailmethod select and based on that we want to enable/disable the three SMTP inputs:</p>
<pre class="brush: jscript;">
function toggleSMTP () {
 var dropdownIndex = document.getElementById('mailmethod').selectedIndex;
 var dropdownValue = document.getElementById('mailmethod')[dropdownIndex].value;
 if (dropdownValue == &quot;smtp&quot;) {
 document.settingsform.smtp_user.disabled = false;
 document.settingsform.smtp_password.disabled = false;
 document.settingsform.smtp_server.disabled = false;
 } else {
 document.settingsform.smtp_user.disabled = true;
 document.settingsform.smtp_password.disabled = true;
 document.settingsform.smtp_server.disabled = true;
 }
}
</pre>
<p>So now we end up with an admin menu that looks like:</p>
<p><a href="http://wordpress.3dn.nl/files/2010/02/settings.png"><img class="alignnone size-medium wp-image-1423" src="http://wordpress.3dn.nl/wp-content/uploads/2010/02/settings-300x129.png" alt="" width="300" height="129" /></a></p>
<p>Not looking bad I think!</p>
<h2>Read More</h2>
<p>If you find this article interesting you might want to read some more articles in the Wordpress category:</p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-6394625565386592";
/* 468x60, gemaakt 3-2-10 */
google_ad_slot = "0905523941";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<ul class="lcp_catlist"><li><a href="http://wordpress.3dn.nl/2010/05/12/migrating-wordpress/">New 3DN Techblog</a></li><li><a href="http://wordpress.3dn.nl/2010/02/28/add-ajax-to-expertise-plugin/">Add Ajax to Expertise Plugin</a></li><li><a href="http://wordpress.3dn.nl/2010/02/20/disqus-wordpres/">Checking Comments for Requests</a></li><li><a href="http://wordpress.3dn.nl/2010/02/17/adding-sendmailsmtp-to-experts-plugin/">Adding sendmail/SMTP to experts plugin</a></li><li><a href="http://wordpress.3dn.nl/2010/02/16/periodic-expertise-events/">Periodic Expertise Events</a></li></ul>
<p>Or in the Coding category:</p>
<ul class="lcp_catlist"><li><a href="http://wordpress.3dn.nl/2010/02/28/add-ajax-to-expertise-plugin/">Add Ajax to Expertise Plugin</a></li><li><a href="http://wordpress.3dn.nl/2010/02/20/disqus-wordpres/">Checking Comments for Requests</a></li><li><a href="http://wordpress.3dn.nl/2010/02/17/adding-sendmailsmtp-to-experts-plugin/">Adding sendmail/SMTP to experts plugin</a></li><li><a href="http://wordpress.3dn.nl/2010/02/16/periodic-expertise-events/">Periodic Expertise Events</a></li><li><a href="http://wordpress.3dn.nl/2010/02/15/expertise-shortcode/">Expertise Shortcode</a></li></ul>
<p>If you have any questions regarding Wordpress, check out our         <a href="http://wordpress.3dn.nl/expertise/wordpress-expertise/" title="Expertise area for Wordpress">Wordpress</a> page or our         <a href="http://wordpress.3dn.nl/expertise/programming/" title="Expertise area for Programming">Programming</a> page. <strong>Note: </strong>The code I&#8217;m writing about is constantly under development. I can&#8217;t write about every little change I make but I try. I&#8217;m learning as I go because this is my first Wordpress plugin. If you&#8217;re interested in the latest code you can always look in SVN through my <a title="Dutchie Trac" href="http://trac.dutchie.org/browser/trunk/experts" target="_blank">public Trac server</a>.</p>


<div class="shr-bookmarks shr-bookmarks-expand">
<ul class="socials">
		<li class="sexy-delicious">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-digg">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-facebook">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-twitter">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-linkedin">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-googlebuzz">
			<a href="" rel="nofollow" title=""></a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://wordpress.3dn.nl/2010/02/17/adding-sendmailsmtp-to-experts-plugin/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Periodic Expertise Events</title>
		<link>http://wordpress.3dn.nl/2010/02/16/periodic-expertise-events/</link>
		<comments>http://wordpress.3dn.nl/2010/02/16/periodic-expertise-events/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 11:37:21 +0000</pubDate>
		<dc:creator>fred leeflang</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[activation code]]></category>
		<category><![CDATA[database tables]]></category>
		<category><![CDATA[deactivation]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[expertise]]></category>
		<category><![CDATA[hook function]]></category>
		<category><![CDATA[hooks]]></category>
		<category><![CDATA[notifications]]></category>

		<guid isPermaLink="false">http://wordpress.3dn.nl/?p=1393</guid>
		<description><![CDATA[Earlier I wrote a few articles on creating the expertise plugin and how to add shortcodes to it. Today I want to add scheduled events to the plugin. When somebody posts a question to the expertise page, we could probably write a trigger that checks immediately who's the expert for the section and send a notice in an email. However, I think it's also nice to illustrate making a timed even that will check all expertise pages at once for new messages and send out all notifications right away.]]></description>
			<content:encoded><![CDATA[ 
 
<h1>Periodic Expertise Events</h1>
<p>Earlier I wrote a few articles on creating the expertise plugin and how to add shortcodes to it. Today I want to add scheduled events to the plugin. When somebody posts a question to the expertise page, we could probably write a trigger that checks immediately who&#8217;s the expert for the section and send a notice in an email. However, I think it&#8217;s also nice to illustrate making a timed even that will check all expertise pages at once for new messages and send out all notifications right away.</p>
<h2>Activation Code</h2>
<p>One thing we have not yet added to the plugin is a decent activation/deactivation section. We should do this first, we&#8217;ll see why later on. In Wordpress, a plugin can be activated and deactivated through the administrative plugin menu. These events can be trapped with the <em>register_activation_hook()</em> and <em>register_deactivation_hook() </em>functions. Typically these hooks get used to create extra database tables needed by a plugin, set default values for the plugin etc.</p>
<p>Another thing that can be done in an activation/deactivation section for a plugin is to create / remove a timed event for the plugin:</p>
<pre class="brush: php;">
register_activation_hook(__FILE__, 'expert_activate');
add_action ('expert_msgcheck', 'hourly_msgcheck');

register_deactivation_hook(__FILE__, 'expert_deactivate');

function expert_activate () {
 wp_schedule_event(time(), 'hourly', 'expert_msgcheck');
}

function expert_deactivate () {
 wp_clear_scheduled_hook('expert_msgcheck');
}

function hourly_msgcheck () {
}
</pre>
<p>The above code snippet sets this all up; The <em>add_action()</em> call at first seems kind of pointless here as there&#8217;s no point in time where the Wordpress core will execute this action. This all changed when an administrator chooses to activate the Expertise plugin. Through the register_activation_hook function <em>expert_activate() </em>will be called. This function in turn calls <em>wp_schedule_event()</em> which schedules the action expert_msgcheck (and thus the function <em>hourly_msgcheck()</em>) to be executed hourly, starting immediately.</p>
<h2>Work with Me</h2>
<p>Let&#8217;s add some code to the <em>hourly_msgcheck()</em> function. We know that we want it to send email eventually, so to check if the mechanism works we&#8217;ll simply let the function send us an email every hour. On my setup I need to use an SMTP mailer as I&#8217;m using Google Apps for email. This requires some settings we might as well initialize on activation of the plugin:</p>
<pre class="brush: php;">
function expert_activate () {
 wp_schedule_event(time(), 'hourly', 'expert_msgcheck');
 add_option('expert_settings', array(
 'onpost' =&gt; 1,
 'smtp_user' =&gt; '',
 'smtp_password' =&gt; '',
 'smtp_server' =&gt; 'smtp.gmail.com'));
}

function expert_deactivate () {
 wp_clear_scheduled_hook('expert_msgcheck');
 unregister_setting('experts-settings-group', 'expert_settings');
 delete_option('expert_settings');
}
</pre>
<p>I&#8217;ve changed my earlier approach here from a variable <em>expert_onpost</em> to adding all related options into an array. Just learning as I go, and reading over <a title="Permanent link : Handling Plugins Options in WordPress 2.8 with register_setting()" rel="bookmark" href="http://planetozh.com/blog/2009/05/handling-plugins-options-in-wordpress-28-with-register_setting/" target="_blank">Handling Plugins Options in WordPress 2.8 with register_setting()</a> many times to see if I could figure out what&#8217;s going on there.</p>
<p>Remember we used the new API&#8217;s <em>register_setting()</em> call in a previous article? Well that&#8217;s still compatible with <em>add_option()</em> so it&#8217;s safe to set default values for the options with this. I have included the deactivation code though, just to show that you still need to use <em>delete_option()</em> as <em>unregister_setting()</em> does not take care of this for you.</p>
<p>I also added a parameter validation function:</p>
<pre class="brush: php;">
register_setting( 'experts-settings-group', 'expert_settings','expert_onpost_validate');

function expert_onpost_validate ($input) {
 // Our first value is either 0 or 1
 $input['onpost'] = ($input['onpost'] == 1 ? 1 : 0);
 return $input;
}
</pre>
<p>This simply checks whether the variable onpost is actually a boolean. I haven&#8217;t included any validation checks on the other variables yet.</p>
<p>So with the registered variables in place it becomes really very easy to do the actual form building / handling:</p>
<pre class="brush: php;">
function expert_settings_page() {
?&gt;
&lt;div&gt;
&lt;h2&gt;Experts&lt;/h2&gt;
&lt;form method=&quot;post&quot; action=&quot;options.php&quot;&gt;
 &lt;?php settings_fields( 'experts-settings-group' ); ?&gt;
 &lt;?php $expert_settings = get_option(&quot;expert_settings&quot;); ?&gt;
 &lt;table&gt;
 &lt;tr valign=&quot;top&quot;&gt;
 &lt;td scope=&quot;row&quot;&gt;On Post in Expertise Section&lt;/td&gt;
 &lt;td&gt;
 &lt;input name=&quot;expert_settings[onpost]&quot; type=&quot;radio&quot; value=&quot;0&quot; &lt;? checked(0,$expert_settings['onpost']); ?&gt; /&gt; Do Nothing &lt;input name=&quot;expert_settings[onpost]&quot; type=&quot;radio&quot; value=&quot;1&quot; &lt;?php checked(1,$expert_settings['onpost']); ?&gt; /&gt; Send Email
 &lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;SMTP username&lt;/td&gt;
 &lt;td&gt;
 &lt;input name=&quot;expert_settings[smtp_user]&quot; type=&quot;text&quot; value=&quot;&lt;?php echo $expert_settings['smtp_user']; ?&gt;&quot; /&gt;
 &lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;SMTP password&lt;/td&gt;
 &lt;td&gt;
 &lt;input name=&quot;expert_settings[smtp_password]&quot; type=&quot;password&quot; value=&quot;&lt;?php echo $expert_settings['smtp_password']; ?&gt;&quot; /&gt;
 &lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
 &lt;td&gt;SMTP server&lt;/td&gt;
 &lt;td&gt;

&lt;input name=&quot;expert_settings[smtp_server]&quot; type=&quot;text&quot; value=&quot;&lt;?php echo $expert_settings['smtp_server']; ?&gt;&quot; /&gt;
 &lt;/td&gt;
 &lt;/tr&gt;
 &lt;/table&gt;

 &lt;p&gt;
 &lt;input type=&quot;submit&quot; value=&quot;&lt;?php _e('Save Changes') ?&gt;&quot; /&gt;
 &lt;/p&gt;

&lt;/form&gt;
&lt;/div&gt;
&lt;?php } ?&gt;
</pre>
<p>Notice that there is no form handling in the plugin itself anymore! That&#8217;s all done by Wordpress itself.</p>
<p>So now that we can actually set some required options, let&#8217;s add this <em>send_email()</em> function:</p>
<pre class="brush: php;">
function send_email () {
 // PHP Mailer Variables
 if (!class_exists(&quot;phpmailer&quot;)) {
 require_once(ABSPATH.'wp-includes/class-phpmailer.php');
 }
 $expert_settings = get_option(&quot;expert_settings&quot;);
 $mail = new PHPMailer();
 $mail-&gt;Mailer   = &quot;smtp&quot;;
 $mail-&gt;Username = $expert_settings['smtp_user'];
 $mail-&gt;Password = $expert_settings['smtp_password'];
 $mail-&gt;Host     = $expert_settings['smtp_server']
 $mail-&gt;SMTPSecurity = &quot;tls&quot;;
 $mail-&gt;Post     = 465;
 $mail-&gt;SMTPAuth = true;
 $mail-&gt;CharSet  = &quot;utf-8&quot;;
 $mail-&gt;Encoding = &quot;quoted-printable&quot;;
 $mail-&gt;FromName = &quot;3DN Techblog &lt;3dn@3dn.nl&gt;&quot;;
 $mail-&gt;AddReplyTo = &quot;Fred Leeflang &lt;fredl@3dn.nl&gt;&quot;;
 $mail-&gt;Subject  = &quot;Test Email&quot;;
 $mail-&gt;Body     = &quot;Testing gmail functionality&quot;;
 $mail-&gt;AddAddress(&quot;fredl@dutchie.org&quot;);
 if ($mail-&gt;Send()) {
 return 1;
 } else {
 return 0;
 }
}
</pre>
<p>And add a call to this function in the <em>hourly_msgcheck() </em>function just to see if it works:</p>
<pre class="brush: php;">
function hourly_msgcheck () {
 send_email();
}
</pre>
<h2>Read More</h2>
<p>If you find this article interesting you might want to read some more articles in the Wordpress category:</p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-6394625565386592";
/* 468x60, gemaakt 3-2-10 */
google_ad_slot = "0905523941";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<ul class="lcp_catlist"><li><a href="http://wordpress.3dn.nl/2010/05/12/migrating-wordpress/">New 3DN Techblog</a></li><li><a href="http://wordpress.3dn.nl/2010/02/28/add-ajax-to-expertise-plugin/">Add Ajax to Expertise Plugin</a></li><li><a href="http://wordpress.3dn.nl/2010/02/20/disqus-wordpres/">Checking Comments for Requests</a></li><li><a href="http://wordpress.3dn.nl/2010/02/17/adding-sendmailsmtp-to-experts-plugin/">Adding sendmail/SMTP to experts plugin</a></li><li><a href="http://wordpress.3dn.nl/2010/02/16/periodic-expertise-events/">Periodic Expertise Events</a></li></ul>
<p>Or in the Coding category:</p>
<ul class="lcp_catlist"><li><a href="http://wordpress.3dn.nl/2010/02/28/add-ajax-to-expertise-plugin/">Add Ajax to Expertise Plugin</a></li><li><a href="http://wordpress.3dn.nl/2010/02/20/disqus-wordpres/">Checking Comments for Requests</a></li><li><a href="http://wordpress.3dn.nl/2010/02/17/adding-sendmailsmtp-to-experts-plugin/">Adding sendmail/SMTP to experts plugin</a></li><li><a href="http://wordpress.3dn.nl/2010/02/16/periodic-expertise-events/">Periodic Expertise Events</a></li><li><a href="http://wordpress.3dn.nl/2010/02/15/expertise-shortcode/">Expertise Shortcode</a></li></ul>
<p>If you have any questions regarding Wordpress, check out our         <a href="http://wordpress.3dn.nl/expertise/wordpress-expertise/" title="Expertise area for Wordpress">Wordpress</a> page or our         <a href="http://wordpress.3dn.nl/expertise/programming/" title="Expertise area for Programming">Programming</a> page. <strong>Note: </strong>The code I&#8217;m writing about is constantly under development. I can&#8217;t write about every little change I make but I try. I&#8217;m learning as I go because this is my first Wordpress plugin. If you&#8217;re interested in the latest code you can always look in SVN through my <a title="Dutchie Trac" href="http://trac.dutchie.org/browser/trunk/experts" target="_blank">public Trac server</a> or simply <a title="Download Development Code" href="http://trac.dutchie.org/changeset/103/trunk/expertise?old_path=%2F&amp;format=zip" target="_blank">download the latest development copy</a>.</p>


<div class="shr-bookmarks shr-bookmarks-expand">
<ul class="socials">
		<li class="sexy-delicious">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-digg">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-facebook">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-twitter">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-linkedin">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-googlebuzz">
			<a href="" rel="nofollow" title=""></a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://wordpress.3dn.nl/2010/02/16/periodic-expertise-events/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Expertise Shortcode</title>
		<link>http://wordpress.3dn.nl/2010/02/15/expertise-shortcode/</link>
		<comments>http://wordpress.3dn.nl/2010/02/15/expertise-shortcode/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 13:25:35 +0000</pubDate>
		<dc:creator>fred leeflang</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[attributes]]></category>
		<category><![CDATA[expertise]]></category>
		<category><![CDATA[expertise level]]></category>
		<category><![CDATA[hyperlinks]]></category>
		<category><![CDATA[wordpress plugins]]></category>

		<guid isPermaLink="false">http://wordpress.3dn.nl/?p=1377</guid>
		<description><![CDATA[Wordpress has a mechanism for adding 'shortcodes' authors can use in their articles through a plugin. In an earlier article I described how to get started with writing your own Wordpress plugins. In this article I'll show how to add a handy shortcode to the plugin that generates code in the expert pages which allows people to register as experts in a certain area of expertise.]]></description>
			<content:encoded><![CDATA[ 
<h1>Expertise Shortcode</h1>
<p>Wordpress has a mechanism for adding &#8216;shortcodes&#8217; authors can use in their articles through a plugin. In an earlier article I described how to get started with writing your own Wordpress plugins. In this article I&#8217;ll show how to add a handy shortcode to the plugin that generates code in the expert pages which allows people to register as experts in a certain area of expertise.</p>
<h2>Functionality</h2>
<p>Every time I create a new expertise page I try to write a brief introduction to the subject. I also want to add a button to this page. When people click on the button they should get a little popup window where they&#8217;re asked to indicate their expertise level. This button is mostly repetitive code which only differs in a few parameters (like &#8216;which expertise page are we on right now&#8217;)</p>
<p>Wordpress&#8217; shortcode mechanism is not the best mechanism to get this done but I want to add it this way mostly for educative purposes.</p>
<h2>Adding the Shortcode</h2>
<p>It&#8217;s real simple to add the shortcode to our plugin:</p>
<pre class="brush: php;">
add_shortcode('expertise', 'expertise_shortcode');
</pre>
<p>That&#8217;s really all there is to adding the shortcode. Ofcourse we still need some code to implement <em>expert_shortcode()</em>:</p>
<pre class="brush: php;">
function expertise_shortcode ($att) {
 $expert = &lt;&lt;&lt;EOM
 &lt;input type=&quot;button&quot; value=&quot;I'm an expert!&quot;&gt;
EOM;
 return $expert;
}
</pre>
<p>After we added this code to our Expertise plugin, inserting <em>[expertise]</em> into our articles/pages should display a very basic button. Why you still see [expertise] in this article even though the plugin is currently active is because I used double [['s in the article.</p>
<p>The above is ofcourse the easiest thing I could think of to make an introduction from.</p>
<h2>Hyperlinks</h2>
<p>Besides adding a button on the expertise page, we could also use this shortcode to link to the expertise page from withing an article. We could ofcourse make an entirely new shortcode for that but it's not neccesary at all; We can add attributes to the shortcode. Let's agree first that we'll give every expertise page it's own 'expertise' custom field which holds the name of the expertise. Custom fields are easy to add in the 'Edit Page' screen. As the value for this 'expertise' field we choose a simple name like 'Linux'.</p>
<p>Now we'll add an attribute <em>link</em> to the expert shortcode so we can use it like <em>[expertise link=Linux]</em>. The expertiselink attribute is optional so if we don&#8217;t add it we&#8217;ll still get the ugly button but if we do add it, the plugin will look in Wordpress&#8217; database to find the URL of the page that has custom field &#8216;expertise&#8217; set to &#8216;Linux&#8217; and display code for a hyperlink to that page with all the titles etc.</p>
<pre class="brush: php;">
function expertise_shortcode ($atts) {
 global $wpdb;

 // Extract attributes and set defaults if not present.
 extract(shortcode_atts(array(
 'link' =&gt; 0,
 ), $atts));

 if ($link) {
 $expertpost = $wpdb-&gt;get_row(&quot;
 SELECT wposts.*
 FROM $wpdb-&gt;posts wposts, $wpdb-&gt;postmeta wpostmeta
 WHERE wposts.ID = wpostmeta.post_id
 AND wpostmeta.meta_key='expertise'
 AND wpostmeta.meta_value='$link'
 AND wposts.post_status='publish'
 AND wposts.post_type='page'
 &quot;, ARRAY_A);
 $url = get_permalink ($expertpost['ID']);
 $expert = &lt;&lt;&lt;EOM
 &lt;a href=&quot;$url&quot; title=&quot;{$expertpost['post_title']}&quot;&gt;{$expertpost['post_title']}&lt;/a&gt;
EOM;
 } else {
 $expert = &lt;&lt;&lt;EOM
 &lt;input type=&quot;button&quot; value=&quot;I'm an expert!&quot;&gt;
EOM;
 }
 return $expert;
}
</pre>
<p>That code looks a bit more complex already. First of all we&#8217;re using the <em>shortcode_atts()</em> function to check if the attribute <em>link</em> is set in <em>$atts</em>. If it&#8217;s not set, it gets the default value of 0. So whether <em>link</em> is set or not becomes an if-then-else construct that determines whether to show the ugly button or an equally ugly link. When $link is set it will be set to &#8216;Linux&#8217; or something along those lines. We should also do some filtering on this later as it&#8217;s value is put into a SQL query and we don&#8217;t really want to encourage SQL-injection.</p>
<p>The SQL query uses $wpdb, hence the <em>global $wpdb</em> declaration at the top of the function. If everything works well the query should return a row with all the wp_posts columns set. This sample code doesn&#8217;t have error checking yet, which it really should have as the query could also return 0 rows (if the author made a typo, or the expertise page administrator has forgotten to add the expertise custom field).</p>
<p>Finally here&#8217;s an example using [expertise link=Wordpress], please go see our         <a href="http://wordpress.3dn.nl/expertise/wordpress-expertise/" title="Expertise area for Wordpress">Wordpress</a> page!</p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-6394625565386592";
/* 468x60, gemaakt 3-2-10 */
google_ad_slot = "0905523941";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<h2>Read More</h2>
<p>If you liked this article, maybe you want to read more in the Wordpress category:</p>
<ul class="lcp_catlist"><li><a href="http://wordpress.3dn.nl/2010/05/12/migrating-wordpress/">New 3DN Techblog</a></li><li><a href="http://wordpress.3dn.nl/2010/02/28/add-ajax-to-expertise-plugin/">Add Ajax to Expertise Plugin</a></li><li><a href="http://wordpress.3dn.nl/2010/02/20/disqus-wordpres/">Checking Comments for Requests</a></li><li><a href="http://wordpress.3dn.nl/2010/02/17/adding-sendmailsmtp-to-experts-plugin/">Adding sendmail/SMTP to experts plugin</a></li><li><a href="http://wordpress.3dn.nl/2010/02/16/periodic-expertise-events/">Periodic Expertise Events</a></li></ul>
<p>Or if you have any questions about this article or Wordpress in general you might want to visit our         <a href="http://wordpress.3dn.nl/expertise/wordpress-expertise/" title="Expertise area for Wordpress">Wordpress</a> page.</p>


<div class="shr-bookmarks shr-bookmarks-expand">
<ul class="socials">
		<li class="sexy-delicious">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-digg">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-facebook">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-twitter">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-linkedin">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-googlebuzz">
			<a href="" rel="nofollow" title=""></a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://wordpress.3dn.nl/2010/02/15/expertise-shortcode/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding an Expertise Section to Wordpress</title>
		<link>http://wordpress.3dn.nl/2010/02/15/expertise-wordpress/</link>
		<comments>http://wordpress.3dn.nl/2010/02/15/expertise-wordpress/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 07:16:55 +0000</pubDate>
		<dc:creator>fred leeflang</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[expertise]]></category>
		<category><![CDATA[expertise section]]></category>
		<category><![CDATA[ipv6]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[section maintainer]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://wordpress.3dn.nl/?p=1334</guid>
		<description><![CDATA[I've been thinking about a way to get people to add links to our blog on their site. A friendly way to do this is by adding an 'expertise' section to the site where people can go after they sign up. Here people can ask questions which will be emailed to the section maintainer(s) so they can answer any questions involving their expertise as timely as possible.]]></description>
			<content:encoded><![CDATA[ 
 
<h1>Adding an Expertise Section to Wordpress</h1>
<p>I&#8217;ve been thinking about a way to get people to add links to our blog on their site. A friendly way to do this is by adding an &#8216;expertise&#8217; section to the site where people can go after they sign up. Here people can ask questions which will be emailed to the section maintainer(s) so they can answer any questions involving their expertise as timely as possible.</p>
<p>This is not a standard Wordpress functionality however so I&#8217;m going to write my own Wordpress plugin for this.</p>
<h2>Requirements</h2>
<p>I first created an &#8216;Expertise&#8217; page to the blog. This page is freely accessible without having to log in. Then I created some pages with the Expertise page as it&#8217;s parent page. We need to have the &#8216;<a title="Member Access" href="http://www.chrisabernethy.com/wordpress-plugins/member-access/" target="_blank">Member Access</a>&#8216; plugin installed on the blog in order to make the separate expertises member-only. The first three expertise pages I set up were for &#8216;Linux/Unix&#8217; (maintainers: FredLeeflang, TigerP), &#8216;Programming&#8217; (maintainers: FredLeeflang, TigerP) and &#8216;IPv6&#8242; (maintainers: TigerP).</p>
<p>I manually added the &#8216;maintainers&#8217; custom field to each of the separate expertise pages to get started. When the plugin is done this field should be added automatically.</p>
<h2>Getting Started with the Plugin</h2>
<p>Creating a plugin for Wordpress is easy. Simply go inside the wp-contents/plugin directory, create a new directory there and some files and you&#8217;re on your merry way. I also took some effort to import the directory into my public subversion server:</p>
<pre class="brush: bash;">
svn import experts https://secure.dutchie.org:444/svn/trunk/experts
</pre>
<p>So  you should also be able to check out the source while I&#8217;m developing it by:</p>
<pre class="brush: bash;">
cd wp-contents/plugins
svn co https://secure.dutchie.org:444/svn/trunk/experts
</pre>
<p>So all I did to get the plugin to show up with some meaningfull information was to add a file <em>experts.php</em> and a <em>readme.txt</em>. The expert.php has a header in it:</p>
<pre class="brush: php;">
/*
Plugin Name:    Experts
Plugin URI:     http://wordpress.3dn.nl/experts/
Description:    This plugin allows you to add experts to several pages on your site. Experts will get notified when a comment on the page is posted, allowing them to quickly respond even though they don't check the site every day.
Author:         Fred Leeflang
Version:        0.1
Author URI:     http://wordpress.3dn.nl/

Setup:
 1) Install the plugin.
 2) Go to the admin menus, and in the &quot;Options&quot; panel, select &quot;Expers&quot;.
 4) Configure the plugin if you need.

*/
</pre>
<p>Which by itself is sufficient to make the plugin show up like this in the admin -&gt; Plugins section:</p>
<p><a href="http://wordpress.3dn.nl/files/2010/02/experts2.png"><img class="size-medium wp-image-1347 alignnone" src="http://wordpress.3dn.nl/wp-content/uploads/2010/02/experts2-300x90.png" alt="" width="300" height="90" /></a></p>
<p style="text-align: left">Obviously this doesn&#8217;t make the plugin do anything yet but it just goes to show that having a header in a file makes the plugin show up with the correct description etc. in the plugin admin screen, ready to be activated!</p>
<h2 style="text-align: left">Got Admin Options?</h2>
<p>First we want to make a basic admin page. This is easily done with:</p>
<pre class="brush: php;">
add_action('admin_menu', 'expert_ap');

function expert_ap() {
 //create new submenu under 'Settings'
 add_submenu_page('options-general.php', 'Expertise Settings','Expertise Settings', 'administrator', __FILE__, 'expert_settings_page');

 //call register settings function
 add_action( 'admin_init', 'register_expertsettings' );
}

function register_expertsettings() {
 //register our settings
 register_setting( 'experts-settings-group', 'onpost', 'intval' );
}
</pre>
<p>This is not complete yet but this shows two important mechanism; adding a submenu to an existing (eg. &#8216;Settings&#8217;) menu and registering settings for our plugin.</p>
<p>The <em>add_submenu_page()</em> function links our settings menu under Wordpress&#8217; settings (through using <em>options-general.php</em>), gives it a label, sets which <em>capability</em> is required and sets which PHP function must be called when the user selects the menu (<em>expert_settings_page()</em> which we have not added yet).</p>
<p>The <em>add_action() </em>function adds the function <em>register_expertsettings() </em>to the admin_init section of the page. There&#8217;s actually some pretty tricky stuff going on in <em>register_expertsettings()</em>, people who have coded plugins &#8216;the good old way&#8217; will find out what I mean later. Essentially the <em>register_setting() </em>call adds a variable and a variable validation to a pulldown we&#8217;ll design later on. There will be no $_POST processing, HTML filtering etc, Wordpress will do all that for us. We just need to make sure that the form POST&#8217;s to options.php and make sure that the variables we want to get from the form get registered with <em>register_setting().</em></p>
<h2>The Form</h2>
<p>Because of letting Wordpress handle our variables, we only need to build the form itself in <em>expert_settings_page().</em></p>
<pre class="brush: php;">
function expert_settings_page() {
?&gt;
&lt;div&gt;
&lt;h2&gt;Experts&lt;/h2&gt;

&lt;form method=&quot;post&quot; action=&quot;options.php&quot;&gt;
 &lt;?php settings_fields( 'experts-settings-group' ); ?&gt;
 &lt;table&gt;
 &lt;tr valign=&quot;top&quot;&gt;
 &lt;th scope=&quot;row&quot;&gt;On Post in Expertise Section&lt;/th&gt;
 &lt;td&gt;
 &lt;select name='onpost'&gt;
 &lt;option value=&quot;1&quot;&gt;Send Email&lt;/option&gt;
 &lt;option value=&quot;0&quot;&gt;Do Nothing&lt;/option&gt;
 &lt;/select&gt;
 &lt;/td&gt;
 &lt;/tr&gt;

 &lt;/table&gt;

 &lt;p&gt;
 &lt;input type=&quot;submit&quot; value=&quot;&lt;?php _e('Save Changes') ?&gt;&quot; /&gt;
 &lt;/p&gt;

&lt;/form&gt;
&lt;/div&gt;
&lt;?php } ?&gt;
</pre>
<h2>Sample Expertise Area</h2>
<p>I&#8217;ve set up a sample expertise area for <a title="Wordpress Expertise Area" href="http://wordpress.3dn.nl/expertise/wordpress-expertise/" target="_blank">Wordpress Expertise</a>. While I&#8217;m developing this plugin further I&#8217;ll post some more followup in there and probably later on I&#8217;ll add one or more articles about the development so stay tuned!</p>
<h2>Read More</h2>
<p>If you enjoyed reading this article you might also like other articles in the Coding category:</p>
<ul class="lcp_catlist"><li><a href="http://wordpress.3dn.nl/2010/02/28/add-ajax-to-expertise-plugin/">Add Ajax to Expertise Plugin</a></li><li><a href="http://wordpress.3dn.nl/2010/02/20/disqus-wordpres/">Checking Comments for Requests</a></li><li><a href="http://wordpress.3dn.nl/2010/02/17/adding-sendmailsmtp-to-experts-plugin/">Adding sendmail/SMTP to experts plugin</a></li><li><a href="http://wordpress.3dn.nl/2010/02/16/periodic-expertise-events/">Periodic Expertise Events</a></li><li><a href="http://wordpress.3dn.nl/2010/02/15/expertise-shortcode/">Expertise Shortcode</a></li></ul>
<p>Or in the Wordpress category:</p>
<ul class="lcp_catlist"><li><a href="http://wordpress.3dn.nl/2010/05/12/migrating-wordpress/">New 3DN Techblog</a></li><li><a href="http://wordpress.3dn.nl/2010/02/28/add-ajax-to-expertise-plugin/">Add Ajax to Expertise Plugin</a></li><li><a href="http://wordpress.3dn.nl/2010/02/20/disqus-wordpres/">Checking Comments for Requests</a></li><li><a href="http://wordpress.3dn.nl/2010/02/17/adding-sendmailsmtp-to-experts-plugin/">Adding sendmail/SMTP to experts plugin</a></li><li><a href="http://wordpress.3dn.nl/2010/02/16/periodic-expertise-events/">Periodic Expertise Events</a></li></ul>
<p>Both older and newer articles in the Coding category will be listed here. Should you need (free!) Wordpress Expertise, please feel free to check out our <a title="Wordpress Expertise Area" href="http://wordpress.3dn.nl/expertise/wordpress-expertise/" target="_blank">Wordpress Expertise area</a>.</p>


<div class="shr-bookmarks shr-bookmarks-expand">
<ul class="socials">
		<li class="sexy-delicious">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-digg">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-facebook">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-twitter">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-linkedin">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-googlebuzz">
			<a href="" rel="nofollow" title=""></a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://wordpress.3dn.nl/2010/02/15/expertise-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Robot Desktop Vacuum</title>
		<link>http://wordpress.3dn.nl/2010/02/14/robot-desktop-vacuum/</link>
		<comments>http://wordpress.3dn.nl/2010/02/14/robot-desktop-vacuum/#comments</comments>
		<pubDate>Sun, 14 Feb 2010 17:38:13 +0000</pubDate>
		<dc:creator>tracy leeflang</dc:creator>
				<category><![CDATA[gadgets]]></category>
		<category><![CDATA[gadget guide]]></category>
		<category><![CDATA[robot]]></category>

		<guid isPermaLink="false">http://wordpress.3dn.nl/?p=1359</guid>
		<description><![CDATA[If you've got messy eaters in the house, cleaning up the kitchen table after every meal can be a real pain.]]></description>
			<content:encoded><![CDATA[ 
<p>If you&#8217;ve got messy eaters in the house, cleaning up the kitchen table after every meal can be a real pain. But with this cute little guy, that chore can become a pleasure. Available in different cheery colors at a reasonable price of $18.99, the Robot Desktop Vacuum may just make your day a little bit brighter.</p>
<p><img src="http://www.boystomengifts.com/images/D/Grey%20Robo%20Vacuum.jpg" alt="robot desktop vacuum" width="458" height="350" /></p>
<p style="text-align: left"><script type="text/javascript"><!--
google_ad_client = "pub-6394625565386592";
/* 468x60, gemaakt 20-2-10 */
google_ad_slot = "8107466664";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p><img src="http://www.boystomengifts.com/images/D/Robo-Vaccume-3-Colours%20copy.jpg" alt="robot desktop vacuum" width="458" height="350" /></p>
<p>Grab yours here at <a href="http://www.boystomengifts.com/Robot-Desktop-Vacuum-Boys-To-Men-Gifts.html">boystomengifts.com</a></p>
<p>If you want to see some more awesome 3DN gadget finds:</p>
<ul class="lcp_catlist"><li><a href="http://wordpress.3dn.nl/2010/02/14/robot-desktop-vacuum/">Robot Desktop Vacuum</a></li><li><a href="http://wordpress.3dn.nl/2010/02/07/charging-and-storage-solutions/">Charging and Storage Solutions</a></li><li><a href="http://wordpress.3dn.nl/2010/02/06/multitouch-skin-that-transforms-surfaces-into-interactive-screens/">Multitouch "Skin" that Transforms Surfaces into Interactive Screens</a></li><li><a href="http://wordpress.3dn.nl/2010/02/04/no-strings-attached/">No Strings Attached</a></li><li><a href="http://wordpress.3dn.nl/2010/02/02/hands-free-smart-phone-options/">Hands-Free Smart Phone Options</a></li></ul>


<div class="shr-bookmarks shr-bookmarks-expand">
<ul class="socials">
		<li class="sexy-delicious">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-digg">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-facebook">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-twitter">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-linkedin">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-googlebuzz">
			<a href="" rel="nofollow" title=""></a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://wordpress.3dn.nl/2010/02/14/robot-desktop-vacuum/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding Facebook Detail</title>
		<link>http://wordpress.3dn.nl/2010/02/10/facebook-application-contest-detail/</link>
		<comments>http://wordpress.3dn.nl/2010/02/10/facebook-application-contest-detail/#comments</comments>
		<pubDate>Wed, 10 Feb 2010 19:18:31 +0000</pubDate>
		<dc:creator>fred leeflang</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[social]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[initial setup]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php application]]></category>
		<category><![CDATA[vote]]></category>

		<guid isPermaLink="false">http://wordpress.3dn.nl/?p=1312</guid>
		<description><![CDATA[Recently I published a short article on how to create your own Facebook application and a somewhat longer article on implementing some basic code into it. Today I'll tell you how to get some more Facebook gadgets in the application to make it more enticing for people to share it with others.]]></description>
			<content:encoded><![CDATA[ 
<h1>Adding Facebook Detail</h1>
<p>Recently I published a short article on how to create your own Facebook application and a somewhat longer article on implementing some basic code into it. Today I&#8217;ll tell you how to get some more Facebook gadgets in the application to make it more enticing for people to share it with others. I&#8217;ve touched up the HTML and added to the functionality since the most recent article and won&#8217;t be describing much about that process as I assume that most people reading this will be familiar with PHP but are more eager to learn about embedding Facebook functionality in their own PHP application.</p>
<h2>Facebook Hooks</h2>
<p>So we now have a contest that allows people to enter project names, change their suggestions, vote on suggestions or change their votes. All of these events are potentially interesting to people who participate in the contest. Additionally, when people suggest a projectname, they may want to let their friends know they did and invite their friends to vote for their suggested project name. While it&#8217;s very easy to develop an application that does these things on a facebook server itself I&#8217;ve chosen to let my application to run in an <em>iframe.</em> This makes it considerably more difficult to get it to work as we need to enable something called <a title="XFBML" href="http://wiki.developers.facebook.com/index.php/XFBML" target="_blank">XFBML</a> for this.</p>
<p>Setting up XFBML is not very hard to do as there&#8217;s an excellent writeup on the Facebook Wiki called &#8216;<a title="Facebook XFBML Connect" href="Adding Facebook Detail  Recently I published a short article on how to create your own Facebook application and a somewhat longer article on implementing some basic code into it. Today I'll tell you how to get some more Facebook gadgets in the application to make it more enticing for people to share it with others. I've touched up the HTML and added to the functionality since the most recent article and won't be describing much about that process as I assume that most people reading this will be familiar with PHP but are more eager to learn about embedding Facebook functionality in their own PHP application. Facebook Hooks  So we now have a contest that allows people to enter project names, change their suggestions, vote on suggestions or change their votes. All of these events are potentially interesting to people who participate in the contest. Additionally, when people suggest a projectname, they may want to let their friends know they did and invite their friends to vote for their suggested project name. While it's very easy to develop an application that does these things on a facebook server itself I've chosen to let my application to run in an iframe. This makes it considerably more difficult to get it to work as we need to enable something called XFBML for this.  Setting up XFBML is not very hard to do as there's an excellent writeup on the Facebook Wiki called 'Connect/Setting up your Site'" target="_blank">Connect/Setting up your Site</a>&#8216; but I still found it somewhat tricky to do so I&#8217;ll describe the initial setup in some more detail in this article such that it&#8217;s very specific for this application instead of the general setup on the Wiki page. After we&#8217;ve setup Facebook Connect it gets much more comprehensible to do things with it.</p>
<h2>Modify Your Application</h2>
<p><a href="http://wordpress.3dn.nl/files/2010/02/appsettings.png"><img class="alignright size-full wp-image-1315" style="margin-top: 10px;margin-bottom: 10px" src="http://wordpress.3dn.nl/files/2010/02/appsettings.png" alt="" width="285" height="204" /></a>First, the Facebook application I created on Facebook Developer needs to be configured to use XFBML. You need to go into &#8216;Application Settings&#8217; -&gt; &#8216;Edit&#8217; for this. By default you will be shown the &#8216;Basic&#8217; tab but you need to go to the &#8216;Connect&#8217; tab. The most important thing to set there is the &#8216;Connect URL&#8217; which I set to <em>http://wordpress.3dn.nl</em>.</p>
<p>To be quite honest I&#8217;m not sure what it&#8217;s intended for! Something that needs to be set up after this is an <em>xd_receiver.htm</em> file and at first I thought it would need to be in the &#8216;Connect URL&#8217;, however this is not the case as the location of the xd_receiver.htm file gets specified elsewhere later on.</p>
<p>So the xd_receiver.htm file is just a small file that has these contents:</p>
<pre class="brush: xml;">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt; &lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; &gt; &lt;body&gt; &lt;script src=&quot;http://static.ak.connect.facebook.com/js/api_lib/v0.4/XdCommReceiver.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt; &lt;/body&gt; &lt;/html&gt;
</pre>
<p>There&#8217;s nothing site specific about this file as you can probably tell. The next thing to do is to modify the HTML header. As you may have noticed if you checked out my sources from Subversion (https://secure.dutchie.org:444/svn/trunk/idmcontest) I set up my HTML header for all the files I serve in a single file called <em>head.inc.php</em> so this was fairly easy to do and it&#8217;s all in here:</p>
<pre class="brush: php;">
$page = &lt;&lt;&lt;EOM
&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot;
 &quot;http://www.w3.org/TR/html4/strict.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xmlns:fb=&quot;http://www.facebook.com/2008/fbml&quot;&gt;
</pre>
<p>The next thing that needs to be done is equally simply done in the head.inc.php file, which is including Facebook&#8217;s API library&#8217;s feature loader script:</p>
<pre class="brush: php;">
$page .= &quot;&lt;body&gt;&quot;;
 $page .= &lt;&lt;&lt;EOM
 &lt;script src=&quot;http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php/en_US&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;

EOM;
</pre>
<p>Finally we get to the point where we tell Facebook where out xd_receiver.htm really sits by running a function from the above mentioned API library. This call needs to be made from the bottom of the page and it will render the XFBML code in the body of the document to have actual contents instead of just the markup. As you may have guessed from me using a head.inc.php there&#8217;s also a foot.inc.php from which I will run this function call:</p>
<pre class="brush: php;">
$page .= &lt;&lt;&lt;EOM
 &lt;/div&gt;
 &lt;/div&gt;
 &lt;script type=&quot;text/javascript&quot;&gt;
 FB.init(&quot;6082487783cacb849db9e382f1ef92bb&quot;, &quot;/idmcontest/xd_receiver.htm&quot;);
 &lt;/script&gt;
 &lt;/body&gt;
</pre>
<p>So that&#8217;s quite a bit of stuff to do to get this all to work! However, after this it&#8217;s easy to do some really nice things with the quite powerfull XFBML.</p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-6394625565386592";
/* 468x60, gemaakt 3-2-10 */
google_ad_slot = "0905523941";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<h2>Adding an Invite</h2>
<p>So one of the reasons for me to try and rewrite this application as a Facebook application is the potential that people will ask their friends to vote on their suggestion. As long as the method to vote is easy enough, most people will be likely to do so.</p>
<p>This is actually relatively simple to do with the XFBML configured, it almost looks exactly like FBML:</p>
<pre class="brush: php;">
if ($addinvitefriends) {
 // Retrieve array of friends who've already authorized the app.
 $fql = 'SELECT uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1='.$user_id.') AND is_app_user = 1';
 $_friends = $facebook-&gt;api_client-&gt;fql_query($fql);

 // Extract the user ID's returned in the FQL request into a new array.
 $friends = array();
 if (is_array($_friends) &amp;&amp; count($_friends)) {
   foreach ($_friends as $friend) {
     $friends[] = $friend['uid'];
   }
 }

 // Convert the array of friends into a comma-delimeted string.
 $friends = implode(',', $friends);

 // Prepare the invitation text that all invited users will receive.
 $content =
   &quot;&lt;fb:name uid=\&quot;&quot;.$user_id.&quot;\&quot; firstnameonly=\&quot;true\&quot; shownetwork=\&quot;false\&quot;/&gt; has started using &lt;a href=\&quot;http://apps.facebook.com/idmcontest/\&quot;&gt;3DN IdM Contest&lt;/a&gt; and &quot; . $invitemsg .
   &quot;&lt;fb:req-choice url=\&quot;&quot;.$facebook-&gt;get_add_url().&quot;\&quot; label=\&quot;Put 3DN IdM Contest on your profile\&quot;/&gt;&quot;;
 $page .= &lt;&lt;&lt;EOM
 &lt;fb:serverFbml style=&quot;width: 640px;&quot;&gt;
   &lt;script type=&quot;text/fbml&quot;&gt;
     &lt;fb:fbml&gt;
       &lt;fb:request-form
         action=&quot;invite.php&quot;
         method=&quot;POST&quot;
         type=&quot;XFBML&quot;
         content=&quot;
EOM;
 $page .= htmlentities($content,ENT_COMPAT,'UTF-8') . &quot;\&quot;&gt;\n&quot;;
 $page .= &lt;&lt;&lt;EOM
         &lt;fb:multi-friend-selector
           actiontext=&quot;Invite your friends to vote:&quot;
           exclude_ids=&quot;$friends&quot;&gt;
       &lt;/fb:request-form&gt;
     &lt;/fb:fbml&gt;
   &lt;/script&gt;
 &lt;/fb:serverFbml&gt;

EOM;
}
</pre>
<p>The <em>$addinvitefriends</em> variable is set when a new project name is suggested so that&#8217;s when we want to display the invite box. Line 2 through 15 actually connect to Facebook&#8217;s database using the fql_query() method, so it does a SQL select to find out which friends are already using the application so as to prevent invites to be send repeatedly. Frequently Facebook itself will impose a maximum on the number of friends you can invite but it&#8217;s possible to invite more people the next day.</p>
<h2>Posting Updates on somebody&#8217;s Wall</h2>
<p>In the next and last article in this series I&#8217;ll describe how posting a vote or a new contest leader on somebody&#8217;s wall could entice people to ask more of their friends to vote.</p>
<h2>Read More</h2>
<p>If you enjoyed reading this article you might enjoy reading the following articles in the Coding section as well:</p>
<ul class="lcp_catlist"><li><a href="http://wordpress.3dn.nl/2010/02/28/add-ajax-to-expertise-plugin/">Add Ajax to Expertise Plugin</a> - February 28, 2010</li><li><a href="http://wordpress.3dn.nl/2010/02/20/disqus-wordpres/">Checking Comments for Requests</a> - February 20, 2010</li><li><a href="http://wordpress.3dn.nl/2010/02/17/adding-sendmailsmtp-to-experts-plugin/">Adding sendmail/SMTP to experts plugin</a> - February 17, 2010</li><li><a href="http://wordpress.3dn.nl/2010/02/16/periodic-expertise-events/">Periodic Expertise Events</a> - February 16, 2010</li><li><a href="http://wordpress.3dn.nl/2010/02/15/expertise-shortcode/">Expertise Shortcode</a> - February 15, 2010</li></ul>


<div class="shr-bookmarks shr-bookmarks-expand">
<ul class="socials">
		<li class="sexy-delicious">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-digg">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-facebook">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-twitter">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-linkedin">
			<a href="" rel="nofollow" title=""></a>
		</li>
		<li class="sexy-googlebuzz">
			<a href="" rel="nofollow" title=""></a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://wordpress.3dn.nl/2010/02/10/facebook-application-contest-detail/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
