<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Michele Campeotto: Tag technorati</title>
    <link>http://blog.micampe.it/articles/tag/technorati?tag=technorati</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>I'm not Winston Wolfe.</description>
    <item>
      <title>PHP ain’t that funny after all</title>
      <description>&lt;p&gt;I don&amp;#8217;t like PHP. I use it on the web because it&amp;#8217;s everywhere and you can find a busload of code to do pretty much whatever you want. But I really dislike how it&amp;#8217;s designed. It&amp;#8217;s inconsistent, you&amp;#8217;ll never know what might happen when you call that new function you just found.&lt;/p&gt;

&lt;p&gt;Take my &lt;a href="http://micampe.it/2005/04/11/technorati-cosmos-in-textpattern"&gt;Technorati Cosmos Textpattern plugin&lt;/a&gt; for example. Sometimes Technorati returns duplicated results and I wanted to filter them: when looping over the list of links received from the Cosmos API call, I added them to an array and then looked there before printing the other links.&lt;/p&gt;

&lt;p&gt;I looked PHP documentation and found the nice &lt;code&gt;array_search()&lt;/code&gt; function. The &lt;a href="http://www.php.net/array_search"&gt;documentation&lt;/a&gt; says:&lt;/p&gt;

&lt;blockquote&gt;
    &lt;p&gt;mixed &lt;strong&gt;array_search&lt;/strong&gt; (mixed needle, array haystack [, bool strict])&lt;/p&gt;
    
    &lt;p&gt;Searches &lt;em&gt;haystack&lt;/em&gt; for &lt;em&gt;needle&lt;/em&gt; and returns the key if it is found in the array, &lt;code&gt;FALSE&lt;/code&gt; otherwise. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;nice, the function returns &lt;code&gt;FALSE&lt;/code&gt; if the item is not in the array, so I went and wrote my check:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;if (!empty($cosmo-&amp;gt;permalink) and array_search($cosmo-&amp;gt;permalink, $items)) {
    // Skip the item if we have already seen it
    continue;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;where&amp;#8217;s the problem with that? Let&amp;#8217;s see some examples.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$a = array(1, 2, 3, 4, 5);

var_dump(array_search(3, $a));
var_dump(array_search(1, $a));
var_dump(array_search(8, $a));
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;this prints, as expected:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;int(2)
int(0)
bool(false)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;but what happens if we put this in an &lt;code&gt;if&lt;/code&gt; statement?&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;if (array_search(3, $a))
    echo "3 found\n";
else
    echo "3 not found\n";
if (array_search(1, $a))
    echo "1 found\n";
else
    echo "1 not found\n";
if (array_search(8, $a))
    echo "8 found\n";
else
    echo "8 not found\n";
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;the result is:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;3 found
1 not found
8 not found
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Why? Because &lt;code&gt;0 == FALSE&lt;/code&gt; and the second test doesn&amp;#8217;t pass. Ok, let&amp;#8217;s make it more specific.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;if (array_search(1, $a) != FALSE)
    echo "1 found\n";
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Wrong again, because &lt;code&gt;0&lt;/code&gt; is still the same as &lt;code&gt;FALSE&lt;/code&gt;. Don&amp;#8217;t despair, a solution isn&amp;#8217;t that far, any of these will work:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;if (array_search(1, $a) !== FALSE)
    echo "1 found\n";
if (array_search(1, $a) &amp;gt;= 0)
    echo "1 found\n";
if (is_int(array_search(1, $a)))
    echo "1 found\n";
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Functions that returns different data types are just &lt;strong&gt;evil&lt;/strong&gt;, and they are &lt;em&gt;everywhere&lt;/em&gt; in PHP. In this case, for example, they force you to use and grasp datatypes in a language which shouldn&amp;#8217;t care much about them.&lt;/p&gt;

&lt;p&gt;I just uploaded a new release of the &lt;a href="http://micampe.it/2005/04/11/technorati-cosmos-in-textpattern"&gt;Cosmos plugin&lt;/a&gt; to fix the duplicates detection.&lt;/p&gt;

&lt;p&gt;PHP &lt;a href="http://claudio.cicali.org/article/37/php-is--funny"&gt;ain&amp;#8217;t that funny&lt;/a&gt;, after all.&lt;/p&gt;</description>
      <pubDate>Thu, 14 Apr 2005 04:17:00 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:f2b90430-638d-40d8-b146-95e2fa32275c</guid>
      <author>micampe</author>
      <link>http://blog.micampe.it/articles/2005/04/14/php-ain%E2%80%99t-that-funny-after-all</link>
      <category>English</category>
      <category>php</category>
      <category>stupid</category>
      <category>programming</category>
      <category>technorati</category>
      <category>textpattern</category>
      <category>plugin</category>
      <trackback:ping>http://blog.micampe.it/articles/trackback/181</trackback:ping>
    </item>
    <item>
      <title>Technorati Cosmos in Textpattern</title>
      <description>&lt;p&gt;How do you get trackbacks without the spam and at the same time routing around your &lt;a href="http://textpattern.com"&gt;blogging software&lt;/a&gt; lack of that functionality?&lt;/p&gt;

&lt;p&gt;Answer: you use some other tool, wich requires an even lower effort both on your and on other people&amp;#8217;s side: &lt;a href="http://developers.technorati.com/wiki/CosmosQuery"&gt;Technorati Cosmos&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I started with a simple piece of code from &lt;a href="http://weblogtoolscollection.com/archives/2004/02/08/technorati-link-cosmos-using-php/"&gt;Weblog Tools Collection&lt;/a&gt;, kept only the clever XML parsing trick and expanded it to a full Textpattern plugin. There was no license attached to that code, so I hope they are fine with me redistributing this.&lt;/p&gt;

&lt;p&gt;So here is my &lt;a href="http://micampe.it/files/txp/mic_technorati_cosmos.php"&gt;Texpattern Technorati Cosmos plugin&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The plugin needs some easy configuration, in form of a &lt;a href="http://www.technorati.com/developers/apikey.html"&gt;Technorati Key&lt;/a&gt; and a cache directory wich must be writable by the web server.&lt;/p&gt;

&lt;p&gt;To use it just place the tag &lt;code&gt;&amp;lt;txp:mic_technorati_cosmos /&amp;gt;&lt;/code&gt; in your article form and you&amp;#8217;re mostly done. With the default settings, the generated code will be like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;!-- Technorati Cosmos for http://currenturl --&amp;gt;
&amp;lt;h3 class="cosmos_label"&amp;gt;Technorati Cosmos &amp;lt;a href=""&amp;gt;&amp;lt;img src="bubble"&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;/h3&amp;gt;
&amp;lt;ul class="cosmos_list"&amp;gt;
    &amp;lt;li&amp;gt;&amp;lt;a href="" title=""&amp;gt;Cosmo title&amp;lt;/a&amp;gt; &amp;amp;mdash; Cosmo excerpt&amp;lt;/li&amp;gt;
    &amp;lt;li&amp;gt;&amp;lt;a href="" title=""&amp;gt;Cosmo title&amp;lt;/a&amp;gt; &amp;amp;mdash; Cosmo excerpt&amp;lt;/li&amp;gt;
&amp;lt;/ul&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The label, the image and the excerpt can be customized and completely removed, please refer to the plugin&amp;#8217;s help for more information. &lt;code&gt;rel="nofollow"&lt;/code&gt; support is an attribute away, too.&lt;/p&gt;

&lt;p&gt;You can see it at work in some of my &lt;a href="http://micampe.it/2005/03/28/textpattern-wysiwyg-editor"&gt;articles&lt;/a&gt; and &lt;a href="http://micampe.it/things/flickrclient"&gt;projects&lt;/a&gt; pages. Enjoy.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;: New version with better duplicates detection&lt;/p&gt;</description>
      <pubDate>Mon, 11 Apr 2005 06:04:00 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:564ab76e-f688-4e3a-ac74-74a79dfb2247</guid>
      <author>micampe</author>
      <link>http://blog.micampe.it/articles/2005/04/11/technorati-cosmos-in-textpattern</link>
      <category>English</category>
      <category>textpattern</category>
      <category>technorati</category>
      <category>cosmos</category>
      <category>plugin</category>
      <category>php</category>
      <category>blogging</category>
      <trackback:ping>http://blog.micampe.it/articles/trackback/176</trackback:ping>
    </item>
  </channel>
</rss>
