<?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>Diadem Tech Weblogs &#187; Joomla</title>
	<atom:link href="http://www.diademblogs.com/category/content-management-systems/joomla/feed" rel="self" type="application/rss+xml" />
	<link>http://www.diademblogs.com</link>
	<description>Tutorials, tips and howtos for web hosting and open source web development</description>
	<lastBuildDate>Mon, 17 Oct 2011 12:28:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Keep Joomla 1.0.x compatible after upgrading PHP 5.2 to 5.3 in Plesk</title>
		<link>http://www.diademblogs.com/content-management-systems/keep-joomla-1-0-x-compatible-after-upgrading-php-5-2-to-5-3-in-plesk</link>
		<comments>http://www.diademblogs.com/content-management-systems/keep-joomla-1-0-x-compatible-after-upgrading-php-5-2-to-5-3-in-plesk#comments</comments>
		<pubDate>Sat, 04 Jun 2011 11:08:57 +0000</pubDate>
		<dc:creator>hriday</dc:creator>
				<category><![CDATA[CMS]]></category>
		<category><![CDATA[Joomla]]></category>

		<guid isPermaLink="false">http://www.diademblogs.com/?p=1268</guid>
		<description><![CDATA[PHP 5.3 introduces various new tags and deprecated certain PHP functions which were being supported till ver 5.2. We recently upgraded the PHP version on one of our servers to 5.3 and found that it broke one site which was built on ver Joomla 1.0.x. Following is a simple update to ensure that the site [...]]]></description>
			<content:encoded><![CDATA[<p>PHP 5.3 introduces various new tags and deprecated certain PHP functions which were being supported till ver 5.2. We recently upgraded the PHP version on one of our servers to 5.3 and found that it broke one site which was built on ver Joomla 1.0.x. Following is a simple update to ensure that the site still works on the new version of PHP 5.3.x.</p>
<p>Edit the Function.php file under  your Joomla directory on /public_html/includes/Cache/Lite.<br />
Replace:<br />
$arguments = func_get_args();</p>
<p>with</p>
<p>$arguments = func_get_args();<br />
$numargs = func_num_args();<br />
for($i=1; $i &lt; $numargs; $i++){<br />
$arguments[$i] = &amp;$arguments[$i];<br />
}</p>
<p>in includes/Cache/Lite/Function.php. It will fix compatibility view issues for joomla 1.0.x on php 5.3.x and this resolved the issue for us.</p>
Note: There is a rating embedded within this post, please visit this post to rate it.
]]></content:encoded>
			<wfw:commentRss>http://www.diademblogs.com/content-management-systems/keep-joomla-1-0-x-compatible-after-upgrading-php-5-2-to-5-3-in-plesk/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Two ways to add Joomla users using your custom code</title>
		<link>http://www.diademblogs.com/content-management-systems/two-ways-to-add-joomla-users-using-your-custom-code</link>
		<comments>http://www.diademblogs.com/content-management-systems/two-ways-to-add-joomla-users-using-your-custom-code#comments</comments>
		<pubDate>Sun, 07 Jun 2009 12:36:45 +0000</pubDate>
		<dc:creator>amitabh</dc:creator>
				<category><![CDATA[CMS]]></category>
		<category><![CDATA[Joomla]]></category>
		<category><![CDATA[add joomla users]]></category>
		<category><![CDATA[joomla users]]></category>

		<guid isPermaLink="false">http://www.diademblogs.com/?p=430</guid>
		<description><![CDATA[The task of adding Joomla users, login/logout, activating/deactivating of users and password reset tasks etc are handled by the component com_users. In this post I will show how to add a joomla user from an external page. Adding users externally can be done in two ways: 1. Create an html form with correct fields and [...]]]></description>
			<content:encoded><![CDATA[<p>The task of adding <a href="http://www.joomla.org" target="_blank">Joomla</a> users, login/logout, activating/deactivating of users and password reset tasks etc are handled by the component <em>com_users</em>. In this post I will show how to add a joomla user from an external page.</p>
<p>Adding users externally can be done in two ways:<br />
1.	Create an html form with correct fields and submit it the correct Joomla url so that Joomla handles the registration, or<br />
2.	If you want to do it in your custom method, you need to create both the html form and the and the script that will add the user to the Joomla.</p>
<p><strong>First, the regular way:</strong></p>
<p>We create an html form with the correct field names and place the form in the joomla root. The field names should match with that of the general joomla registration form.</p>
<p>If we view the source of a Joomla registration form then we can see that the form has text fields named name, username, Email, password, password2 and hidden fields task, id, gid. There is another hidden field whose name is generated by JUtility::getToken() and the value of the field is 1. This field value is checked at the time of submitting the registration information. More about this in a moment. On submitting the registration form the registration information is processed by the register_save method of the UserController in com_user, which has been specified by the hidden field named task in the registration form.</p>
<p>Now we come to the UserController in the com_user. In the register_save method there is a line which checks the token value from the submitted form. As we are using a static html form we either need to generate the token name on the html form or if we don’t want to include the token in the form then we need to bypass the line of code which checks for the token.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">JRequest<span style="color: #339933;">::</span><span style="color: #004000;">checkToken</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> or jexit<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Invalid Token'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>In the register_save method of the UserController in the com_user. Since we will be using a html form commonly so we go for the second option and comment the line for checking token</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// JRequest::checkToken() or jexit( 'Invalid Token' );</span></pre></div></div>

<p>The submitted registration information is then processed by the register_save method. The data is actually saved in the save method of the UserController.</p>
<p><strong>Now, the Other way:</strong></p>
<p>Here we use the previously created form and submit it to the custom script that we create. This approach is basically to copy the functionality of the register_save() method in the UserController in com_user to an external script and submit the html registration form to that script.</p>
<p>Now onto the script:<br />
To access the joomla environment in an external script, the following snippet is added to the start of the script:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'_JEXEC'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'JPATH_BASE'</span><span style="color: #339933;">,</span> <span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//this is when we are in the root</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'DS'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">DIRECTORY_SEPARATOR</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">require_once</span> <span style="color: #009900;">&#40;</span> JPATH_BASE <span style="color: #339933;">.</span>DS<span style="color: #339933;">.</span><span style="color: #0000ff;">'includes'</span><span style="color: #339933;">.</span>DS<span style="color: #339933;">.</span><span style="color: #0000ff;">'defines.php'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span> <span style="color: #009900;">&#40;</span> JPATH_BASE <span style="color: #339933;">.</span>DS<span style="color: #339933;">.</span><span style="color: #0000ff;">'includes'</span><span style="color: #339933;">.</span>DS<span style="color: #339933;">.</span><span style="color: #0000ff;">'framework.php'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$mainframe</span> <span style="color: #339933;">=&amp;</span> JFactory<span style="color: #339933;">::</span><span style="color: #004000;">getApplication</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'site'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$mainframe</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">initialise</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This snippet basically makes available the joomla framework available in the script. The code snippet is found in the index.php of the joomla root.</p>
<p>Now we import the functionality of the register_save() method in the script.</p>
<p>#1. Check for request forgeries, we comment this out since tokens are not generated in the html  page</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//JRequest::checkToken() or jexit( 'Invalid Token' );</span></pre></div></div>

<p>#2. Get required system objects</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$user</span> 	      <span style="color: #339933;">=</span> clone<span style="color: #009900;">&#40;</span>JFactory<span style="color: #339933;">::</span><span style="color: #004000;">getUser</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pathway</span> 	      <span style="color: #339933;">=</span> <span style="color: #339933;">&amp;</span> <span style="color: #000088;">$mainframe</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getPathway</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$config</span>	      <span style="color: #339933;">=</span> <span style="color: #339933;">&amp;</span> JFactory<span style="color: #339933;">::</span><span style="color: #004000;">getConfig</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$authorize</span>	      <span style="color: #339933;">=</span> <span style="color: #339933;">&amp;</span> JFactory<span style="color: #339933;">::</span><span style="color: #004000;">getACL</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$document</span>       <span style="color: #339933;">=</span> <span style="color: #339933;">&amp;</span> JFactory<span style="color: #339933;">::</span><span style="color: #004000;">getDocument</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>#3. If user registration is not allowed, show 403 not authorized(Not needed)</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$usersConfig</span> <span style="color: #339933;">=</span> <span style="color: #339933;">&amp;</span>JComponentHelper<span style="color: #339933;">::</span><span style="color: #004000;">getParams</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'com_users'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$usersConfig</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'allowUserRegistration'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'0'</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		JError<span style="color: #339933;">::</span><span style="color: #004000;">raiseError</span><span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">403</span><span style="color: #339933;">,</span> JText<span style="color: #339933;">::</span>_<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Access Forbidden'</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span></pre></div></div>

<p>#4. Initialize new usertype setting</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$newUsertype</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$usersConfig</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'new_usertype'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$newUsertype</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$newUsertype</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Registered'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span></pre></div></div>

<p>#5. Bind the post array to the user object</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bind</span><span style="color: #009900;">&#40;</span> JRequest<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'post'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'usertype'</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		JError<span style="color: #339933;">::</span><span style="color: #004000;">raiseError</span><span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">500</span><span style="color: #339933;">,</span> <span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getError</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span></pre></div></div>

<p>#6. Set some initial user values</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'usertype'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'gid'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$authorize</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_group_id</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$newUsertype</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'ARO'</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$date</span> <span style="color: #339933;">=&amp;</span> JFactory<span style="color: #339933;">::</span><span style="color: #990000;">getDate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'registerDate'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$date</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">toMySQL</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>#7. If user activation is turned on, we need to set the activation information(Not needed)</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$useractivation</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$usersConfig</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'useractivation'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$useractivation</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'1'</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		jimport<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'joomla.user.helper'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'activation'</span><span style="color: #339933;">,</span> <span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span> JUserHelper<span style="color: #339933;">::</span><span style="color: #004000;">genRandomPassword</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'block'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'1'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span></pre></div></div>

<p>#8. Save the details of the user</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>After this we can use the php header function to redirect the user to the desired location.</p>
<p>That&#8217;s it! I hope Joomla developers find this helpful and please feel to post your views and comments to this post.</p>
Note: There is a rating embedded within this post, please visit this post to rate it.
]]></content:encoded>
			<wfw:commentRss>http://www.diademblogs.com/content-management-systems/two-ways-to-add-joomla-users-using-your-custom-code/feed</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
	</channel>
</rss>

