<?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>HagelBlog&#187; Tags</title>
	<atom:link href="http://www.hagelnx.com/tag/plugin/feed" rel="self" type="application/rss+xml" />
	<link>http://www.hagelnx.com</link>
	<description>An American in Bulgaria</description>
	<lastBuildDate>Mon, 17 May 2010 11:37:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>WordPress plugins don&#8217;t commonly use classes, why?</title>
		<link>http://www.hagelnx.com/prog/wordpress/658</link>
		<comments>http://www.hagelnx.com/prog/wordpress/658#comments</comments>
		<pubDate>Fri, 11 Dec 2009 14:59:45 +0000</pubDate>
		<dc:creator>Kevin  Hagel</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://www.hagelnx.com/?p=658</guid>
		<description><![CDATA[I&#8217;m learning how to write wordpress plugins, I&#8217;ve said that before here in my blog.  One of the ways I&#8217;m doing it is by downloading/installing existing plugins I see out there which may be interesting to me &#8211; they provide actions and capabilities to do things I want my plugin(s) to do &#8230; on a [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m learning how to write wordpress plugins, I&#8217;ve said that before here in my blog.  One of the ways I&#8217;m doing it is by downloading/installing existing plugins I see out there which may be interesting to me &#8211; they provide actions and capabilities to do things I want my plugin(s) to do &#8230; on a more general scale.</p>
<p>One thing I have noticed &#8211; almost all of these plugin authors do NOT use classes in their design.  Their .php files are full of functions, most of the time written without the</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'my_function'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">function</span> my_function<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// and so on</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>or</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'my_function'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">function</span> my_function<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// and so on</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span></div></div>
<p>How do they expect to avoid naming collisions?  If they <em>have</em> to have a function by a certain name which probably exist in some other plugin developer&#8217;s file somewhere, then even if they use this <em>!function_exists</em> business they&#8217;ll end up getting the other author&#8217;s behavior for that function.</p>
<p>Why don&#8217;t these people just use classes!  I know I&#8217;m coming at this from the java world where you <em>have to</em> use classes for everything, and there&#8217;s packaging to avoid naming collisions, but still &#8211; this seems like an obvious question to me.  Do the modern php programmers have <strong><em>no</em></strong> experience with a real class-oriented language?</p>
<p>Here&#8217;s a silly example I&#8217;m doing.  I have a plugin I&#8217;m developing to allow Zlatina&#8217;s web administrators to deal with their database of students and contacts.  It&#8217;s called Bcc DBManager.<br />
I created a subdirectory  wp-content/plugins/bcc-dbmanager, with a file named bcc-dbmanager.php &#8230; duh.  I want to hook into the activate_${plugin} (<a href="http://adambrown.info/p/wp_hooks/hook/activate_%7B$plugin%7D" target="_blank">see this link for an explanation of that</a>).  Here&#8217;s a partial &#8230;</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <br />
<span style="color: #666666; font-style: italic;">/* <br />
Plugin Name: Bcc DBManager <br />
Description: Blah blah <br />
*/</span> <br />
<span style="color: #000088;">$bccDBManager</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> BCC_DBmanager<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'activate_bcc-dbmanager/bcc-dbmanager.php'</span><span style="color: #339933;">,</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$bccDBManager</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'_activate'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
<br />
<span style="color: #000000; font-weight: bold;">class</span> BCC_DBmanager <span style="color: #009900;">&#123;</span> &nbsp; <br />
&nbsp; <span style="color: #000000; font-weight: bold;">function</span> _activate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> &nbsp;<span style="color: #009900;">&#123;</span> &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// do stuff &nbsp; &nbsp; </span><br />
&nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">very_common_function_name</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// or this way</span><br />
&nbsp; &nbsp; BCC_DBmanager<span style="color: #339933;">::</span><span style="color: #004000;">very_common_function_name</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">## function with a very common name<br />
</span> &nbsp;<span style="color: #000000; font-weight: bold;">function</span> very_common_function_name<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// do stuff</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></div>
<p>How hard is that?  I certainly don&#8217;t know much about plugin development at this point.  But I would have to describe the use of functions rather than class instances and methods as Code Smell.</p>
<p>[Edit] Since I wrote this post I found this link on Nerdaphernalia:<a rel="nofollow" target="_blank" href="http://striderweb.com/nerdaphernalia/2008/07/use-classes-in-your-wordpress-plugins/"> Use Classes in your WordPress plugins to increase code portability and reduce name conflicts</a></p>
<p><a href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fwww.hagelnx.com%2Fprog%2Fwordpress%2F658&amp;linkname=WordPress%20plugins%20don%26%238217%3Bt%20commonly%20use%20classes%2C%20why%3F" title="Facebook" rel="nofollow" target="_blank"><img src="http://www.hagelnx.com/wordpress/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a> <a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.hagelnx.com%2Fprog%2Fwordpress%2F658&amp;linkname=WordPress%20plugins%20don%26%238217%3Bt%20commonly%20use%20classes%2C%20why%3F"><img src="http://www.hagelnx.com/wordpress/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.hagelnx.com/prog/wordpress/658/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Comment translation</title>
		<link>http://www.hagelnx.com/prog/450</link>
		<comments>http://www.hagelnx.com/prog/450#comments</comments>
		<pubDate>Fri, 13 Nov 2009 13:43:31 +0000</pubDate>
		<dc:creator>Kevin  Hagel</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[comments]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Language]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[plugin review]]></category>

		<guid isPermaLink="false">http://www.hagelnx.com/?p=450</guid>
		<description><![CDATA[I&#8217;ve been getting an amazing number of comments on some of my blog entries coming from Russia &#8211; and they&#8217;re in the Russian language in Cyrillic.  I expect there&#8217;s some kind of rss-feed going on, I do have several subscribers to this blog who&#8217;s personal data indicates their home page is in .ru domain or [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been getting an amazing number of comments on some of my blog entries coming from Russia &#8211; and they&#8217;re in the Russian language in Cyrillic.  I expect there&#8217;s some kind of rss-feed going on, I do have several subscribers to this blog who&#8217;s personal data indicates their home page is in .ru domain or their email address comes from a .ru domain.<br />
Using the <a href="http://wordpress.org/extend/plugins/visitor-maps/" target="_blank">Vistor Maps and Who is Online</a> plugin I&#8217;m able to see where my visitors are coming from, at least the country where their IP address is located.  Most of the .ru commentors are actually coming from Latvia &#8230; from Preili Latvia in particular.<span style="color: green;"><br />
</span></p>
<p>Maybe they&#8217;ve put my site on some social networking location in Russia?  How is it they&#8217;re able to write comments to my blog without appearing in my google analytics report?  Why aren&#8217;t they writing comments in english, my language?  Are my blog entries being translated to Russian where these people are reading them, and if so how good a translation is it?</p>
<p>Since so many of the comments coming from Russia are spam I&#8217;ve had to place the .ru domain in my Aksimet filter, but just as many seem to be honest comments coming from regular people.  So I go through the comments flagged as spam this way, and on occasion will approve them for the post.  I go to translate.google.com to see what they are saying, and to have a look at the website they claim as home page.<br />
Often some innocuous comment such as &#8220;good post&#8221; comes with a link to some porno or warez site, so I just delete those.</p>
<p>But a they are in Russian, I have to translate all of them this way.  So I&#8217;m going to try something new.  I&#8217;ve done a google search for &#8220;<a href="http://www.google.bg/search?q=wordpress+google+translate+plugin&amp;ie=utf-8&amp;oe=utf-8" target="_blank">wordpress google translate plugin</a>&#8220;, and have arrived at the following two plugins (links open in new window):</p>
<ul>
<li><a href="http://wordpress.org/extend/plugins/google-ajax-translation/" target="_blank">Google Ajax Translation</a></li>
<li><a href="http://wordpress.org/extend/plugins/global-translator/" target="_blank">Global Translator</a></li>
</ul>
<p>It looks like the Global Translator is more fully developed, and able to use 4 different translator engines (at least claimed on the plugin site), so this is the one I&#8217;m going to try.<br />
There is a pro version available, but let&#8217;s see how well this plugin works on a site such as mine, with these Russian-language and cyrillic charset comments.<br />
&#8230;.<br />
Ok, I&#8217;ve installed the global translator and I have to admit, it doesn&#8217;t do what I want in this case.  I only want to be able to translate the comments, not the entire website.  The Global Translator has lots of nice options, and it might be useful for my readers who come from those various countries to get a translation of my website in their language, but hey &#8211; than can do what I&#8217;ve been doing, go to translate.google.com and enter the URL and see the translation.<br />
So I&#8217;m going to deactivate that plugin for now, and try the Google Ajax Translator.<br />
&#8230;.<br />
Very nice.  This does what I want.  I&#8217;m not offering translation of entire pages or posts, I only want to see for myself what these Russian comments are saying.  So we&#8217;ll see how it works.</p>
<p>And if any of you commenting on my blog entries would like to tell me &#8211; where are you seeing my blog?  Are my entries translated into your language, is this why you&#8217;re writing comments in Russian?  I&#8217;d like to read your comments about these questions.</p>
<p><a href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fwww.hagelnx.com%2Fprog%2F450&amp;linkname=Comment%20translation" title="Facebook" rel="nofollow" target="_blank"><img src="http://www.hagelnx.com/wordpress/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a> <a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.hagelnx.com%2Fprog%2F450&amp;linkname=Comment%20translation"><img src="http://www.hagelnx.com/wordpress/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.hagelnx.com/prog/450/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Visitor Maps and Who&#8217;s Online</title>
		<link>http://www.hagelnx.com/prog/wordpress/391</link>
		<comments>http://www.hagelnx.com/prog/wordpress/391#comments</comments>
		<pubDate>Fri, 06 Nov 2009 12:23:19 +0000</pubDate>
		<dc:creator>Kevin  Hagel</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://www.hagelnx.com/?p=391</guid>
		<description><![CDATA[I just installed this wordpress plugin: Visitor Maps and Who&#8217;s Online.  Free, and informative.  Find out who&#8217;s online at any one moment, including bots and crawlers if you want. It&#8217;s easy to install.  It downloads a database of geolocation information, see www.maxmind.com for that. Informative &#8211; shows visitor IP address, country, which url they were [...]]]></description>
			<content:encoded><![CDATA[<p>I just installed this wordpress plugin: <a href="http://wordpress.org/extend/plugins/visitor-maps/" target="_blank">Visitor Maps and Who&#8217;s Online</a>.  Free, and informative.  Find out who&#8217;s online at any one moment, including bots and crawlers if you want.</p>
<p>It&#8217;s easy to install.  It downloads a database of geolocation information, see <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a> for that.</p>
<p>Informative &#8211; shows visitor IP address, country, which url they were visiting.  A map is provided.  Very nice.</p>
<p><a href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fwww.hagelnx.com%2Fprog%2Fwordpress%2F391&amp;linkname=Visitor%20Maps%20and%20Who%26%238217%3Bs%20Online" title="Facebook" rel="nofollow" target="_blank"><img src="http://www.hagelnx.com/wordpress/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a> <a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.hagelnx.com%2Fprog%2Fwordpress%2F391&amp;linkname=Visitor%20Maps%20and%20Who%26%238217%3Bs%20Online"><img src="http://www.hagelnx.com/wordpress/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.hagelnx.com/prog/wordpress/391/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
