<?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>Helion-Prime Solutions blog &#187; CMS general</title>
	<atom:link href="http://blogs.helion-prime.com/category/cms-general/feed" rel="self" type="application/rss+xml" />
	<link>http://blogs.helion-prime.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Mon, 10 May 2010 17:51:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Battle N2: Typo3, Joomla!, and Drupal CMSs performance testing</title>
		<link>http://blogs.helion-prime.com/2008/07/02/battle-n2-typo3-joomla-and-drupal-cmss-performance-testing.html</link>
		<comments>http://blogs.helion-prime.com/2008/07/02/battle-n2-typo3-joomla-and-drupal-cmss-performance-testing.html#comments</comments>
		<pubDate>Wed, 02 Jul 2008 08:34:55 +0000</pubDate>
		<dc:creator>alex.shapovalov</dc:creator>
				<category><![CDATA[drupal]]></category>
		<category><![CDATA[joomla]]></category>
		<category><![CDATA[typo3]]></category>

		<guid isPermaLink="false">http://blogs.helion-prime.com/?p=39</guid>
		<description><![CDATA[“More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason &#8211; including blind stupidity.”
William A. Wulf
preamble
Since my last article about performance comparison of popular CMSs: Typo3, Joomla!, and Drupal [typo3-joomla-and-drupal-cmss-performance-testing.html] I got enormous amount of messages, emails and notes.
Most discussed question is:
*What the hell you [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>“More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason &#8211; including blind stupidity.”<br />
William A. Wulf</p></blockquote>
<h2>preamble</h2>
<p>Since my last article about performance comparison of popular CMSs: Typo3, Joomla!, and Drupal [<a href="http://blogs.helion-prime.com/alexshapovalov/2008/05/19/typo3-joomla-and-drupal-cmss-performance-testing.html">typo3-joomla-and-drupal-cmss-performance-testing.html</a>] I got enormous amount of messages, emails and notes.</p>
<p>Most discussed question is:<br />
<span style="color: #3366ff;">*</span>What the hell you didn&#8217;t turn cache on, and forgot about optimization?</p>
<p><strong>And comments like:</strong><br />
In case of optimization zzz will take first place.<br />
No one runs systems like that in real life. Every real web server is optimized for performance ..</p>
<p><strong>I answered several times with:</strong><br />
I make tests to test effectiveness of pure systems rather then caching sub-system or optimization methods.<br />
Developers should think about effectiveness of their components and don’t pass care about performance entirely to caching or other technics.<br />
Surely cache is good as well as better CPU, bandwidth, and cluster when solution is already got all benefits of good software design.</p>
<p><em>But if you want OK.<br />
I will turn ON everything I know on all CMSs, and will make all environment optimizations. I hope you will be glad.</em></p>
<p>Surely if you are hacker that want to tune all the daylights you will beat any system.<br />
Let&#8217;s think that this environment presents common set of optimizations on general production system.</p>
<h2>Prepared configuration</h2>
<p>architecture: x86<br />
CPU: 3.0Ghz<br />
RAM: 512Mb<br />
OS: Debian GNU/Linux lenny/sid (testing)<br />
kernel: 2.6.22, optimized for current computer configuration</p>
<p><strong>software versions:</strong><br />
apache: 2.2.8<br />
php: 5.2.5-3<br />
mysql: 5.0.51a-3</p>
<p>joomla!: 1.5.3<br />
drupal: 6.2<br />
typo3: 4.2.1</p>
<p><strong>apache:</strong><br />
web-server API: apache2.0 handler<br />
processing model: mpm-prefork [http://httpd.apache.org/docs/2.0/mod/prefork.html]<br />
MaxClient  adapted for load<br />
excessive login disabled<br />
HostNameLookups dissabled</p>
<p><strong>PHP:</strong><br />
XCache PHP opcode cacher installed [http://xcache.lighttpd.net/]</p>
<p>xcache.cacher = On<br />
xcache.optimizer = On<br />
xcache.coverager = Off</p>
<p>xcache.size=64M # cache size<br />
xcache.count=2 # cpu count</p>
<p>xcache.var_size = 64M # variable data cache size<br />
xcache.var_count = 2 # cpu count</p>
<p><strong>MySQL:</strong><br />
mysqli database adapter used  where appropriate<br />
bin log disabled<br />
query_cache_limit = 2M # default was 1M<br />
query_cache_size = 64M # default was 16M<br />
table_cache = 256 # default was 64<br />
key_buffer_size = 64M # default was 16M</p>
<p>CMSs returned specially prepared page contains:<br />
menu, login form, 2 articles with overall size 40Kb<br />
Testing series contains results for 10, and 20 simultaneous users.</p>
<h2>comparison results</h2>
<p><strong>note: </strong><br />
results in the tables are presented in milliseconds per page request<br />
and surely smaller result is better.</p>
<p><strong>10 users</strong></p>
<table style="border-color: gray; border-style: dotted; width:450px;" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td></td>
<td><strong>joomla</strong></td>
<td><strong>drupal</strong></td>
<td><strong>typo3</strong></td>
</tr>
<tr>
<td><strong>average</strong></td>
<td>101</td>
<td>19</td>
<td>71</td>
</tr>
<tr>
<td><strong>median</strong></td>
<td>100</td>
<td>18</td>
<td>71</td>
</tr>
<tr>
<td><strong>90% results line</strong></td>
<td>145</td>
<td>30</td>
<td>103</td>
</tr>
<tr>
<td><strong>min</strong></td>
<td>19</td>
<td>8</td>
<td>16</td>
</tr>
<tr>
<td><strong>max</strong></td>
<td>289</td>
<td>60</td>
<td>570</td>
</tr>
</tbody>
</table>
<p><img class="alignnone size-full wp-image-42" title="results_10u1" src="http://blogs.helion-prime.com/wp-content/uploads/2008/07/results_10u1.jpg" alt="" width="370" height="276" /></p>
<p><strong>20 users</strong></p>
<table style="border-color: gray; border-style: dotted; width:450px;" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td></td>
<td><strong>joomla</strong></td>
<td><strong>drupal</strong></td>
<td><strong>typo3</strong></td>
</tr>
<tr>
<td><strong>average</strong></td>
<td>237</td>
<td>47</td>
<td>187</td>
</tr>
<tr>
<td><strong>median</strong></td>
<td>196</td>
<td>41</td>
<td>146</td>
</tr>
<tr>
<td><strong>90% results line</strong></td>
<td>357</td>
<td>72</td>
<td>318</td>
</tr>
<tr>
<td><strong>min</strong></td>
<td>18</td>
<td>8</td>
<td>16</td>
</tr>
<tr>
<td><strong>max</strong></td>
<td>7323</td>
<td>356</td>
<td>4378</td>
</tr>
</tbody>
</table>
<p><img class="alignnone size-full wp-image-43" title="results_20u1" src="http://blogs.helion-prime.com/wp-content/uploads/2008/07/results_20u1.jpg" alt="" width="371" height="277" /></p>
<p><strong>fast conclusion:</strong><br />
Drupal uses caching mechanism more effectively that explains such lag of others.<br />
Numbers, and graphs are very loud, and so I think you don&#8217;t need any additional descriptions.</p>
<p>You can always compare this result with result without optimization techniques using my previous article [<a href="http://blogs.helion-prime.com/alexshapovalov/2008/05/19/typo3-joomla-and-drupal-cmss-performance-testing.html">typo3-joomla-and-drupal-cmss-performance-testing.html</a>].</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.helion-prime.com/2008/07/02/battle-n2-typo3-joomla-and-drupal-cmss-performance-testing.html/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Typo3, Joomla!, and Drupal CMSs performance testing</title>
		<link>http://blogs.helion-prime.com/2008/05/19/typo3-joomla-and-drupal-cmss-performance-testing.html</link>
		<comments>http://blogs.helion-prime.com/2008/05/19/typo3-joomla-and-drupal-cmss-performance-testing.html#comments</comments>
		<pubDate>Mon, 19 May 2008 11:16:09 +0000</pubDate>
		<dc:creator>alex.shapovalov</dc:creator>
				<category><![CDATA[drupal]]></category>
		<category><![CDATA[joomla]]></category>
		<category><![CDATA[typo3]]></category>

		<guid isPermaLink="false">http://blogs.helion-prime.com/?p=12</guid>
		<description><![CDATA[preamble
Our company above all uses 3 CMSs [http://en.wikipedia.org/wiki/Content_management_system]
Typo3, Joomla!, and Drupal since we find them the most appropriate for most of our tasks.
Check this our article to find more about it [cms-based-web-applications-fast-way-for-creation-of-web-based-solutions.html]
Sometimes our customers asks what is faster, trying to find fair answer I made a short research
in order to compare them and provide our [...]]]></description>
			<content:encoded><![CDATA[<h2>preamble</h2>
<p>Our company above all uses 3 CMSs [<a href="http://en.wikipedia.org/wiki/Content_management_system">http://en.wikipedia.org/wiki/Content_management_system</a>]<br />
Typo3, Joomla!, and Drupal since we find them the most appropriate for most of our tasks.<br />
Check this our article to find more about it [<a href="http://blogs.helion-prime.com/vasiliykiryanov/2008/05/07/cms-based-web-applications-fast-way-for-creation-of-web-based-solutions.html">cms-based-web-applications-fast-way-for-creation-of-web-based-solutions.html</a>]</p>
<p>Sometimes our customers asks what is faster, trying to find fair answer I made a short research<br />
in order to compare them and provide our customer as well as you with pretty graphs.</p>
<h2>testing conditions</h2>
<p>I have created virtual dedicated server with following configuration within our server<br />
to have a picture of average hosting providers.</p>
<p><strong>configuration:</strong><br />
architecture: 	x86<br />
CPU:		3.0Ghz<br />
RAM:		512Mb<br />
OS:		Debian GNU/Linux lenny/sid (testing)<br />
kernel:		2.6.22-3-686</p>
<p>On all CMS returned page contains:<br />
menu, login form, 2 articles with overall size 40Kb</p>
<p>As Joomla! doesn&#8217;t have built-in internationalization functionality I made tests with JoomFish 2.0beta extension<br />
that provide that functionality and without it.</p>
<p>Every testing series contains results for 1, 10, and 20 simultaneous users.<br />
Caching functionally:<br />
turned off for Drupal, Joomla!, and Typo3;</p>
<p><strong>apache configuration:</strong><br />
apache web-server API: apache2.0 handler<br />
processing model: mpm-prefork [http://httpd.apache.org/docs/2.0/mod/prefork.html]</p>
<p><strong>software versions:</strong><br />
apache: 2.2.8<br />
php: 5.2.5-3<br />
mysql: 5.0.51a-3</p>
<p>joomla!: 1.5.2<br />
typo3: 4.1.6<br />
drupal:6.2</p>
<h2>comparison results</h2>
<p>So it&#8217;s time to see some results. Keep your eyes widely opened..</p>
<p><em>note: </em><br />
results in the tables are presented in milliseconds per page request<br />
and surely smaller result is better</p>
<p><strong>1 user</strong></p>
<table style="border-color: lightgrey; border-style: dotted; width:450px;" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td></td>
<td><strong>joomla+joomfish</strong></td>
<td><strong>joomla</strong></td>
<td><strong>drupal</strong></td>
<td><strong>typo3</strong></td>
</tr>
<tr>
<td><strong>average</strong></td>
<td>261</td>
<td>185</td>
<td>130</td>
<td>233</td>
</tr>
<tr>
<td><strong>median</strong></td>
<td>260</td>
<td>184</td>
<td>129</td>
<td>232</td>
</tr>
<tr>
<td><strong>min</strong></td>
<td>253</td>
<td>180</td>
<td>127</td>
<td>225</td>
</tr>
<tr>
<td><strong>max</strong></td>
<td>311</td>
<td>209</td>
<td>144</td>
<td>248</td>
</tr>
</tbody>
</table>
<p><img class="alignnone size-full wp-image-13" title="1user" src="http://blogs.helion-prime.com/wp-content/uploads/2008/05/1user.jpg" alt="" width="460" height="265" /></p>
<p><strong>10 users</strong></p>
<table style="border-color: lightgrey; border-style: dotted; width:450px;"  cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td></td>
<td><strong>joomla+joomfish</strong></td>
<td><strong>joomla</strong></td>
<td><strong>drupal</strong></td>
<td><strong>typo3</strong></td>
</tr>
<tr>
<td><strong>average</strong></td>
<td>2093</td>
<td>1510</td>
<td>1118</td>
<td>2039</td>
</tr>
<tr>
<td><strong>median</strong></td>
<td>1965.5</td>
<td>1416</td>
<td>1040</td>
<td>1247.5</td>
</tr>
<tr>
<td><strong>min</strong></td>
<td>253</td>
<td>181</td>
<td>126</td>
<td>226</td>
</tr>
<tr>
<td><strong>max</strong></td>
<td>36422</td>
<td>31591</td>
<td>30999</td>
<td>29138</td>
</tr>
</tbody>
</table>
<p><img class="alignnone size-full wp-image-15" title="10users" src="http://blogs.helion-prime.com/wp-content/uploads/2008/05/10users.jpg" alt="" width="460" height="265" /></p>
<p><strong>20 users</strong></p>
<table style="border-color: lightgrey; border-style: dotted; width:450px;" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td></td>
<td><strong>joomla+joomfish</strong></td>
<td><strong>joomla</strong></td>
<td><strong>drupal</strong></td>
<td><strong>typo3</strong></td>
</tr>
<tr>
<td><strong>average</strong></td>
<td>4106</td>
<td>2908</td>
<td>2123</td>
<td>3886</td>
</tr>
<tr>
<td><strong>median</strong></td>
<td>3689</td>
<td>2306</td>
<td>1552</td>
<td>2075</td>
</tr>
<tr>
<td><strong>min</strong></td>
<td>254</td>
<td>182</td>
<td>128</td>
<td>233</td>
</tr>
<tr>
<td><strong>max</strong></td>
<td>119187</td>
<td>112612</td>
<td>83831</td>
<td>105285</td>
</tr>
</tbody>
</table>
<p><img class="alignnone size-full wp-image-16" title="20users" src="http://blogs.helion-prime.com/wp-content/uploads/2008/05/20users.jpg" alt="" width="460" height="265" /></p>
<h2>fast conclusions:</h2>
<p>as you see in the tables and on graphs</p>
<p><span style="color: #3366ff;">**</span>Drupal is noticeably faster then competitors<br />
<span style="color: #3366ff;">**</span>joomfish is a break for Joomla but it is very important extension and very likely it is installed on your system<br />
<span style="color: #3366ff;">**</span>without JoomFish Joomla! can be even faster then Typo3</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.helion-prime.com/2008/05/19/typo3-joomla-and-drupal-cmss-performance-testing.html/feed</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>Joomla! 1.5 extensions development hints</title>
		<link>http://blogs.helion-prime.com/2008/05/12/joomla-15-extensions-development-hints.html</link>
		<comments>http://blogs.helion-prime.com/2008/05/12/joomla-15-extensions-development-hints.html#comments</comments>
		<pubDate>Mon, 12 May 2008 13:38:10 +0000</pubDate>
		<dc:creator>henadiy.atroshko</dc:creator>
				<category><![CDATA[joomla]]></category>
		<category><![CDATA[joomla development]]></category>

		<guid isPermaLink="false">http://blogs.helion-prime.com/?p=11</guid>
		<description><![CDATA[0. go through basic Joomla! documentation
Joomla! Beginners guide: [http://docs.joomla.org/Beginners]
Joomla developer network: [http://dev.joomla.org/]
which includes very useful:
Joomla framework API: [http://api.joomla.org/]
Joomla! tutorials on Wiki: [http://dev.joomla.org/component/option,com_jd-wiki/Itemid,32/]
Joomla! forum: [http://forum.joomla.org]
1. project structure
It is useful during development to keep the code in only one place. You can easy use this structure with your IDEs [http://en.wikipedia.org/wiki/Integrated_development_environment] and VCS [http://en.wikipedia.org/wiki/Version_control_system]
It is recommended to use [...]]]></description>
			<content:encoded><![CDATA[<h2>0. go through basic Joomla! documentation</h2>
<p>Joomla! Beginners guide: [<a href="http://docs.joomla.org/Beginners">http://docs.joomla.org/Beginners</a>]</p>
<p>Joomla developer network: [<a href="http://dev.joomla.org/">http://dev.joomla.org/</a>]<br />
which includes very useful:<br />
Joomla framework API: [http://api.joomla.org/]<br />
Joomla! tutorials on Wiki: [http://dev.joomla.org/component/option,com_jd-wiki/Itemid,32/]</p>
<p>Joomla! forum: [<a href="http://forum.joomla.org">http://forum.joomla.org</a>]</p>
<h2>1. project structure</h2>
<p>It is useful during development to keep the code in only one place. You can easy use this structure with your IDEs [<a href="http://en.wikipedia.org/wiki/Integrated_development_environment">http://en.wikipedia.org/wiki/Integrated_development_environment</a>] and VCS [<a href="http://en.wikipedia.org/wiki/Version_control_system">http://en.wikipedia.org/wiki/Version_control_system</a>]</p>
<p>It is recommended to use next structure:</p>
<pre>project-root
	com_component
		site
			...
			lang
				...
				en-GB.com_component.ini
				de-DE.com_component.ini
			component.php
		admin
			...
			lang
				...
				en-GB.com_component.ini
				de-DE.com_component.ini
			admin.component.php
			install.sql
			uninstall.sql
		component.xml
	mod_module
		...
		lang
			...
			en-GB.mod_module.ini
			de-DE.mod_module.ini
		module.php
		module.xml
	plg_plugin
		...
		lang
			...
			en-GB.plg_group_plugin.ini
			de-DE.plg_group_plugin.ini
		plugin.php
		plugin.xml
	tpl_temlate
		template.xml
	...
</pre>
<p>After creation of project structure prepare installation packages with help of Joomla! tutorials and install them to Joomla!. We will work with local installation (or dedicated server in your LAN) because another variants decries performance of developers.</p>
<p>After extensions installation process change files of extensions installed to Joomla! with GNU/Linux symbolic links [<a href="http://en.wikipedia.org/wiki/Symbolic_link">http://en.wikipedia.org/wiki/Symbolic_link</a>] or Windows Vista symbolic links [<a href="http://en.wikipedia.org/wiki/NTFS_symbolic_link">http://en.wikipedia.org/wiki/NTFS_symbolic_link</a>] of your project files.<br />
Note: Don&#8217;t forget to use option “Options +FollowSymLinks” for Apache web-server for directory where your Joomla! installed to use symbolic links.</p>
<p>In Joomla! filenames of extensions has special structure. In mentioned structure names of corresponding extensions in filenames  and directories replaced with words component, module, and plug-in. The word group in files of plugin replaces name of group to which plug-in relate to [content, editors, search, system, user].<br />
Every group defines set of events on which plug-in will be triggered.</p>
<p>Ready to use project has following structure of relations: (&lt;== symbol means symbolic link)</p>
<pre>PRJ-ROOT/COM_COMPONENT/SITE &lt;== J_ROOT/COMPONENTS/COM_COMPONET
PRJ-ROOT/COM_COMPONENT/SITE/LANG/en-GB.com_component.ini
&lt;== J_ROOT/LANGUAGE/en-GB/en-GB.com_component.ini
PRJ-ROOT/COM_COMPONENT/SITE/LANG/de-DE.com_component.ini
&lt;== J_ROOT/LANGUAGE/de-DE/de-DE.com_component.ini

PRJ-ROOT/COM_COMPONENT/ADMIN &lt;== J_ROOT/ADMINISTRATOR/COMPONENTS/COM_COMPONET
PRJ-ROOT/COM_COMPONENT/ADMIN/LANG/en-GB.com_component.ini
&lt;== J_ROOT/ADMINISTRATOR/LANGUAGE/en-GB/en-GB.com_component.ini
PRJ-ROOT/COM_COMPONENT/ADMIN/LANG/de-DE.com_component.ini
&lt;== J_ROOT/ADMINISTRATOR/LANGUAGE/de-DE/de-DE.com_component.ini

PRJ-ROOT/MOD_MODULE &lt;== J_ROOT/MODULES/MOD_MODULE
PRJ-ROOT/MOD_MODULE/LANG/en-GB.mod_module.ini
&lt;== J_ROOT/LANGUAGE/en-GB/en-GB.mod_module.ini
PRJ-ROOT/MOD_MODULE/LANG/de-DE.mod_module.ini
&lt;== J_ROOT/LANGUAGE/de-DE/de-DE.mod_module.ini

PRJ-ROOT/PLG_PLUGIN/plugin.php &lt;== J_ROOT/PLUGINS/GROUP/plugin.php
PRJ-ROOT/PLG_PLUGIN/LANG/en-GB.plg_group_plugin.ini
&lt;== J_ROOT/ADMINISTRATOR/LANGUAGE/en-GB/en-GB.plg_group_plugin.ini
PRJ-ROOT/PLG_PLUGIN/LANG/de-DE.plg_group_plugin.ini
&lt;== J_ROOT/ADMINISTRATOR/LANGUAGE/de-DE/de-DE.plg_group_plugin.ini
</pre>
<p>As you see languages files of plug-ins installed to administration part of Joomla!. Why so, ask Joomla! developers.</p>
<h2>2. internationalization (i18n)</h2>
<p>Most of extensions require internationalization. This mechanism is simple to use in Joomla!, but it has some ambiguous decisions.</p>
<p>To use internationalization support of text messages in the code of extensions instead of output of simple strings we should use next construction:  JText::_(&#8216;text message&#8217;); This call check current locale and using appropriate localization file returns required string.</p>
<p>For instance if current locale is &#8216;en-GB&#8217; then it seek for appropriate file:<br />
for “site part” of Joomla!:  joomla-root/language/en-GB/en-GB.com_component.ini<br />
and in that file I look for sting with id &#8216;TEXT MESSAGE&#8217;</p>
<p>If it can&#8217;t find appropriate file then it returns passed string.</p>
<p><strong>Structure of localization file:</strong><br />
identifier=value</p>
<p>identifier – is a string, it should be written in UPPER CASE.<br />
Value – is a localized value.</p>
<p><strong>Example:</strong><br />
We need to output 2 internationalized strings<br />
echo JText::_(&#8216;This is test message.&#8217;);<br />
echo JText::_(&#8216;Hello world.&#8217;);</p>
<p>Then we create localization file for appropriate locale en-EN.com_component.ini:<br />
THIS IS TEST MESSAGE=This is test message.<br />
HELLO WORLD.=Hello all.</p>
<p>de-DE.com_component.ini:<br />
THIS IS TEST MESSAGE=Das ist testen Meldung.<br />
HELLO WORLD.=Halo eine Welt.</p>
<p>I want to note that in order to use that mechanism for plug-ins you should invoke method  loadLanguage of class Jplugin:</p>
<p>loadLanguage(<br />
[name of localization file],<br />
[path to root directory of site part of admin part of Joomla!]</p>
<p>name of localization file, by default plg_group_plugin.ini path to root directory, can be: “j_root/administrator” or  “j_root” (by default)</p>
<h2>3. layouts</h2>
<p>Layouts is a handy mechanism which let us to avoid using of  “if construction”  in “view” of the MVC model [<a href="http://en.wikipedia.org/wiki/Model-view-controller">http://en.wikipedia.org/wiki/Model-view-controller</a>] which Joomla! 1.5 began to use actively for extensions development.</p>
<p>By default structure of extensions presentation in Joomla (for modules, and components) has next structure:</p>
<pre>EXTENSION-ROOT
	VIEWS
	   VIEW
               TMPL
		 default.php
	     view.html.php
</pre>
<p>Here “view.html.php” file is a  common part of presentation which can commonly contains invocations of “model” (MVC) or in other words where we extract data that necessary for data output, and some simple logic.<br />
There is a rule to place mature logic to model or controller(MVC). In the “TMPL” directory we keep different presentations. They contain markup or in other words exact presentation of data. An file “default.php “ is a default layout, so it will be used if we wasn&#8217;t selected another one. You can easily create additional layouts adding them to &#8216;TMPL&#8217; directory files with name “layoutname.php”. In order to select specific layout you should in the controller(MVC) before invocation of display() function<br />
select its name with command: JRequest::setVar(&#8216;layout&#8217;, &#8216;layoutname&#8217;);</p>
<h2>4. using of AJAX</h2>
<p>It is hardy to imagine an application that can be developed nowadays without AJAX. [<a href="http://en.wikipedia.org/wiki/Ajax_%28programming%29">http://en.wikipedia.org/wiki/Ajax_%28programming%29</a>]</p>
<p>It is much easier to use some javascript library like jquery, mootols, dojo, etc.. to invoke Ajax-based methods. I like jquery [http://jquery.com]. However Joomla! Developers have selected another Javascript library – mootols [http://mootools.net] and so I earnestly recommend to you to use for ajax methods invocations Mootools library. If you anyway want to use your favorite JavaScript library you must switch your library to the compatibility mode.</p>
<p>For instance for Jquery it can be do it with:<br />
var jq = jQuery.noConflict();<br />
then instead of &#8216;$&#8217; you should use  &#8216;jq&#8217; but anyway keep in mind that most of extensions for JavaScript libraries don&#8217;t use that mode and so you will have Javascript error because of name collisions.</p>
<p>Example of MVC flow using Ajax invocation:<br />
- Create task in the controller, ex.: getAjaxData</p>
<pre>	“controller.php”:
	function getAjaxData() {
		JRequest::setVar('view', 'viewname');
		JRequest::setVar('layout', 'ajaxlayout');

		parent::display();
	}
</pre>
<p>- Create layout, ex: ajaxlayout</p>
<pre>	“viewname/tmpl/ajaxlayout.php”:
	&lt;?php defined('_JEXEC') or die('Restricted access');

	global $mainframe;
	echo &lt;ajax data&gt;;

	$mainframe-&gt;close();
	?&gt;
</pre>
<p><strong>Important note:</strong><br />
You should add invocation: $mainframe-&gt;close();<br />
in order to create output flow or it will add Joomla! standard page after result of you Ajax method. Thus creating concrete layout you can pass any data, don&#8217;t forget to setup appropriate header. For XML [<a href="http://en.wikipedia.org/wiki/Xml">http://en.wikipedia.org/wiki/Xml</a>] it can be: header(&#8220;Content-type: text/xml;charset=utf-8&#8243;);</p>
<p>On client-side yous should make invoke defined method using Ajax call, using URL like:<br />
JURI::root().&#8217;index.php?option=com_component&amp;task=getajaxdata&#8217;;</p>
<h2>5. mapping of tables to the Database</h2>
<p>Joomla! using simple ORM system [<a href="http://en.wikipedia.org/wiki/Object-relational_mapping">http://en.wikipedia.org/wiki/Object-relational_mapping</a>].<br />
In order to use this mechanism you should describe your DB structure with sets of objects that inherit JTable.</p>
<p>For example:<br />
foo.php:</p>
<pre>&lt;?php
defined('_JEXEC') or die('Restricted access');

class TableFoo extends JTable {
	var $id = null;
	var $bar = null;

	function TableFoo(&amp; $db) {
		parent::__construct('#__foo', 'id', $db);
	}

	function bind( $from, $ignore=array() ) {
		$from['bar'] = strtoupper($from['bar']);
		return parent::bind($from, $ignore);
	}

	function check() {
		if (empty($this-&gt;bar)) {
			$this-&gt;setError( 'Error message');
			return false;
        		}
		return true;
	}

	function delete( $oid=null ) {
		$res = parent::delete($oid);

		// here if you need you can define mechanism
		// to delete linked tables
		return $res;
    	}
}
?&gt;
</pre>
<p>First of all it is necessary to define public variables that corresponding to fields names of table. Then you should pass name of the table and name of primary key to the constructor.</p>
<p><strong>key methods:</strong></p>
<p>Bind() method using in order to transfer data from external sources (ex.: requst) into object. Overriding that method you can execute specific data transformations of data before adding to the fields of the object.<br />
Check() method make checking of data in the fields, for example it can check that fields not empty or filled with required range of values, etc.<br />
Delete() method  can add specific behavior during deletion of  records. For example deleting of linked records.</p>
<p>Also JTable class contains set of other handy methods  overriding which you can add appropriate specific behavior.<br />
<em> See Joomla! documentation for details.</em></p>
<p><strong>possible use:</strong></p>
<p>You can get object in the model (MVC) with following: $row =&amp; $this-&gt;getTable(&#8216;foo&#8217;);</p>
<p>to delete record you invoke: $row-&gt;delete($id)</p>
<p>to store record to db:<br />
$row-&gt;bind($data);<br />
$row-&gt;check();<br />
$row-&gt;store();</p>
<p>If then you need  get value of primary key you can simply take the value from the object: $row-&gt;id;</p>
<p>Surely it is better to add to described calls check of result of methods executions.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.helion-prime.com/2008/05/12/joomla-15-extensions-development-hints.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Simple wordpress sidebar widget step-by-step development</title>
		<link>http://blogs.helion-prime.com/2008/04/14/simple-wordpress-sidebar-widget-step-by-step-development.html</link>
		<comments>http://blogs.helion-prime.com/2008/04/14/simple-wordpress-sidebar-widget-step-by-step-development.html#comments</comments>
		<pubDate>Mon, 14 Apr 2008 16:04:39 +0000</pubDate>
		<dc:creator>henadiy.atroshko</dc:creator>
				<category><![CDATA[wordpress]]></category>
		<category><![CDATA[cms]]></category>
		<category><![CDATA[plug-in]]></category>
		<category><![CDATA[widget]]></category>

		<guid isPermaLink="false">http://blogs.helion-prime.com/?p=9</guid>
		<description><![CDATA[sidebar and widgets
Sidebar – is an area that take place on the left or on the right from main area. Usually on sidebar placed blog common or quick access elements. This elements called widgets.
Common examples:   authors, tags, categories, etc.
In the world of WordPress widget is a plugin subtype. That is activation/deactivation of widgets [...]]]></description>
			<content:encoded><![CDATA[<h2>sidebar and widgets</h2>
<p>Sidebar – is an area that take place on the left or on the right from main area. Usually on sidebar placed blog common or quick access elements. This elements called widgets.<br />
Common examples:   authors, tags, categories, etc.</p>
<p>In the world of WordPress widget is a plugin subtype. That is activation/deactivation of widgets realized thru the control panel of plug-ins.</p>
<p>Status control of widgets managed  in the  Design/Widgets panel. There you can add/remove widgets from/to sidebar and change their parameters.</p>
<h2>1. How to add new widget</h2>
<p>Since widget is plug-in it is behavior like common plug-in in WordPress. In other words it is php-script which placed in directory/subdirectories  “/wp-content/plugins”. For correct information representation widget(plug-in) should has header like above:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">/*<br />
Plugin Name: Simple Wordpress Sidebar Widget<br />
Plugin URI: http://open.helion-prime.com/Simple-Wordpress-Sidebar-Widget<br />
Description: Simple wordpress sidebar widget.<br />
Version: 1.0<br />
Author: Helion-Prime Solutions Ltd.<br />
Author URI: http://helion-prime.com/<br />
*/</span></div></td></tr></tbody></table></div>
<p>&#8216;Plugin Name&#8217; field described symbolic plug-in name in the system.<br />
&#8216;Plugin URI &#8216; contains link to plug-in description.<br />
&#8216;description&#8217;  description.<br />
&#8216;version&#8217; version<br />
&#8216;Author&#8217; author name<br />
&#8216;Author URI&#8217; uniform resource identifier</p>
<p>In the upshot in order to add new widget to the system we should:<br />
create file “simple-sidebar-widget.php”<br />
add to file described header<br />
copy file to directory “/wp-content/plugins”</p>
<p>Then in the plug-in control panel we have new plug-in with our name:<br />
&#8216;Simple Wordpress Sidebar Widget&#8217;</p>
<p>simple-sidebar-widget.php</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><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: Simple Sidebar Widget<br />
Plugin URI: http://open.helion-prime.com/Simple-Wordpress-Sidebar-Widget<br />
Description: Simple wordpress sidebar widget.<br />
Version: 1.0<br />
Author: Helion-Prime Solutions Ltd.<br />
Author URI: http://helion-prime.com/<br />
*/</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<h2>2. Plug-in registration</h2>
<p>In the first step we have added simplest plug-in (but not widget yet)<br />
In order to transform it to the widget, we should register it.</p>
<p>Code for sidebar registration:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br /></div></td><td><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;">function</span> simple_sidebar_widget_content_gen<span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">function</span> simple_sidebar_widget_register<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp;<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;">'register_sidebar_widget'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #b1b100;">return</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp;register_sidebar_widget<span style="color: #009900;">&#40;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Simple Sidebar Widget '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'simple-sidebar-widget'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'simple_sidebar_widget_content_gen'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'init'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'simple_sidebar_widget_register'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>To work widget should contain at least 2 functions:<br />
*initialization (here simple_sidebar_widget_register)<br />
*content generation (here simple_sidebar_widget_content_gen)</p>
<p>To get control in the our code we should create hook on some event. We have 2 events to select from. In our case I have selected &#8216;init event&#8217; (raised when system loaded and initialized).<br />
Hook created with help of  add_action function, as parameter to it passed &#8216;name of event&#8217; (init) and name of handler function (simple_sidebar_widget_register).</p>
<p>If event raised function simple_sidebar_widget_register receive control and perform following actions:<br />
*check possibility to create widget with help of  accessibility of widget registration function – function_exists(&#8216;register_sidebar_widget&#8217;).<br />
* if required function is accessible it register widget</p>
<p>As you see register_sidebar_widget function receive 2 parameters:<br />
first contain localized name of widget in the widget control panel.<br />
second link to functionality of content-generator (&#8217;simple_sidebar_widget_content_gen&#8217;).</p>
<p>Now we have full-fledged widget that can be viewed in the widget control panel, it can be added to sidebar (don&#8217;t forget to activate it in the plug-in control panel).</p>
<h2>3. Representation</h2>
<p>If you add our widget to the sidebar it will not show anything. To find any result you should add function of content generation in the following way:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><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;">function</span> simple_sidebar_widget_content_gen<span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #990000;">extract</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #000088;">$title</span> <span style="color: #339933;">=</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Simple Sidebar Widget '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'simple-sidebar-widget'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #000088;">$widget_content</span> <span style="color: #339933;">=</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'This is simple sidebar widget'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'simple-sidebar-widget'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$before_widget</span> <span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$before_title</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$title</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$after_title</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;p&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$widget_content</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/p&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$after_widget</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>First thing that we do is from array of arguments of function that extract variables we create set of variables.</p>
<p>Mainly it is special variables that should be  used. Then we create content of widget: in fixed order we output values of special(which contain basic widget markup) and defined variables.</p>
<p>Now we can see our widget on sidebar.</p>
<h2>4. Widget setup</h2>
<p>If you want to have possibility to setup widget you should change code to the following:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">function simple_sidebar_widget_control_gen($widget_content, $show_content) {<br />
&lt;p&gt;<br />
&nbsp; &nbsp;&lt;label for=&quot;widget-content&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> _e<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content:'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'simple-sidebar-widget'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><br />
&nbsp; &nbsp; &nbsp; &lt;input class=&quot;widefat&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;id=&quot;widget-content&quot; name=&quot;widget-content&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;type=&quot;text&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> attribute_escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$widget_content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;<br />
&nbsp; &nbsp; &nbsp; /&gt;<br />
&nbsp; &nbsp;&lt;/label&gt;<br />
&lt;/p&gt;<br />
&lt;p&gt;<br />
&nbsp; &nbsp;&lt;label for=&quot;show-content&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &lt;input class=&quot;checkbox&quot; type=&quot;checkbox&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;id=&quot;show-content&quot; name=&quot;show-content&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$show_content</span> ? <span style="color: #0000ff;">'checked=&quot;checked&quot;'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><br />
&nbsp; &nbsp; &nbsp; /&gt;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;?php</span> _e<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Show content.'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'simple-sidebar-widget'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><br />
&nbsp; &nbsp;&lt;/label&gt;<br />
&lt;/p&gt;<br />
&lt;input type=&quot;hidden&quot;<br />
&nbsp; &nbsp; &nbsp; id=&quot;simple-sidebar-widget-submit&quot; name=&quot;simple-sidebar-widget-submit&quot;<br />
&nbsp; &nbsp; &nbsp; value=&quot;1&quot;/&gt;<br />
<span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #000000; font-weight: bold;">function</span> simple_sidebar_widget_control<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$newoptions</span> <span style="color: #339933;">=</span> get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'simple_sidebar_widget'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'simple-sidebar-widget-submit'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000088;">$newoptions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'widget-content'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strip_tags</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">stripslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'widget-content'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000088;">$newoptions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'show-content'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'show-content'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span> <span style="color: #339933;">!=</span> <span style="color: #000088;">$newoptions</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$newoptions</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; update_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'simple_sidebar_widget'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp;simple_sidebar_widget_control_gen<span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'widget-content'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'show-content'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">function</span> simple_sidebar_widget_content_gen<span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #990000;">extract</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #000088;">$title</span> <span style="color: #339933;">=</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Simple Sidebar Widget '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'simple-sidebar-widget'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'simple_sidebar_widget'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #000088;">$show_content</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'show-content'</span><span style="color: #009900;">&#93;</span> ? <span style="color: #009900; font-weight: bold;">true</span> <span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #000088;">$widget_content</span> <span style="color: #339933;">=</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'widget-content'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ?<br />
&nbsp; &nbsp; &nbsp; __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'This is simple sidebar widget'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'simple-sidebar-widget'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'widget-content'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$before_widget</span> <span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$before_title</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$title</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$after_title</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$show_content</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&amp;lt;p&amp;gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$widget_content</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&amp;lt;/p&amp;gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$after_widget</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">function</span> simple_sidebar_widget_register<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp;<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;">'register_sidebar_widget'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #b1b100;">return</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp;register_sidebar_widget<span style="color: #009900;">&#40;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Simple Sidebar Widget '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'simple-sidebar-widget'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'simple_sidebar_widget_content_gen'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;register_widget_control<span style="color: #009900;">&#40;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Simple Sidebar Widget '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'simple-sidebar-widget'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'simple_sidebar_widget_control'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p><strong>What changed in our code:</strong></p>
<p>In function &#8217;simple_sidebar_widget_register&#8217; one invocation added (&#8216;register_widget_control&#8217;), it register function which catch widget configuration change event (&#8217;simple_sidebar_widget_control&#8217;).</p>
<p>In the generator of widget content additional code added that receives current configuration of widget get_option(&#8217;simple_sidebar_widget&#8217;).<br />
Here parameter &#8217;simple_sidebar_widget&#8217; is identifier of parameters set that used in our widget.<br />
Then into variables $show_content and $widget_content extracted current values of parameters.</p>
<p>As I already noted for event processing of configuration changes we should add appropriate event-handler function (&#8217;simple_sidebar_widget_control&#8217;). In this function we extract parameters from request  and analyze changes, also this function create content of configuration form (this functionality moved to &#8217;simple_sidebar_widget_control_gen&#8217;).</p>
<p>After we added above code in the parameters of widget we have 2 fields.<br />
One field contains content that should be outputted.<br />
Second field is a switch which allow/forbid output of content.</p>
<p>In closing I want to note that widgets work only with themes that support sidebar.<br />
Described methodology work for WordPress >=2.5, although  it is almost the same for previous versions.</p>
<p><strong>related links:</strong><br />
plug-in development &#8211; http://codex.wordpress.org/Writing_a_Plugin<br />
list of actions &#8211; http://codex.wordpress.org/Plugin_API/Action_Reference<br />
localization: http://codex.wordpress.org/Translating_WordPress</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.helion-prime.com/2008/04/14/simple-wordpress-sidebar-widget-step-by-step-development.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
