Retrieve Component parameters in plugin

Filed Under (Joomla! 1.5) by khawaib on 18-08-2010

Tagged Under : , , , ,

Using following code component parameters can be retrieved in plugins and modules.

If component has parameters in its Global Configurations use following:

$params = &JComponentHelper::getParams( 'component_name' );
$parammeter = $usersConfig->get( 'parameter_name' );

Use following if component have configurations inside component page:

$params = $mainframe->getParams('component_name');
parammeter  = $params->get('parameter_name');

Permissions for Joomla using Plesk and Virtuozzo

Filed Under (Joomla! 1.0, Joomla! 1.5, Plesk/Virtuozzo, Ubuntu) by khawaib on 15-08-2010

Tagged Under : , , , , , , , , , ,

Change the umask in ‘/etc/proftpd.conf’ from ’022′ to ’002′.

Then, update the directory permissions by running the following at the command line:

cd /var/www/vhosts/[domain.com]
chown -R [username]:psacln httpdocs
chmod -R g+w httpdocs
find httpdocs -type d -exec chmod g+s {} \;

Add the ‘apache’ user to the ‘psacln’ group by editing ‘/etc/group’.

psacln:x:2524:apache

Calling a plugin from a Component or another Plugin

Filed Under (Joomla! 1.5) by khawaib on 03-08-2010

Tagged Under : , , ,

You can use a plugins functions from another plugin or component using following codes.
These are for Joomla 1.5

$Plugin =& JPluginHelper::getPlugin('system', 'saleslogix');
$dispatcher =& JDispatcher::getInstance();
$plg = array("type"=>"system","name"=>"saleslogix","params"=>$Plugin->params);
$saleslogixPlg = new plgSystemSaleslogix( $dispatcher, $plg );
//$resultHere = $saleslogixPlg->myFunction();

OR

JPluginHelper::importPlugin('system');
$app = &JFactory::getApplication();
$app->triggerEvent('onAfterInitialise');

www or no www in urls

Filed Under (Facebook, Joomla! 1.0, Joomla! 1.5, Ubuntu) by khawaib on 01-08-2010

Tagged Under : , , , , , , , ,

You can enter your website urls with a www or with no www. Which is better I leave for you to google and find out yourself. Using both is not a good idea as search engines and Facebook will not treat them same and will cause problems.

Solution is to force one of them to be used and not both. So if a users enters http://www.youtsite.com gets to http://yoursite.com and vice versa.

Solutions 1: Using Mod Rewrite
Following code should be placed in htaccess file in root directory of your website.

If your want to http://www.yoursite.com use following code:

<IfModule mod_rewrite.c>
   Options +FollowSymLinks
   Options +Indexes
   RewriteEngine On
   RewriteBase /
   RewriteCond %{HTTP_HOST} ^domain\.com$
   RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
</IfModule>

If your want to http://yoursite.com use following code:

<IfModule mod_rewrite.c>
   Options +FollowSymLinks
   Options +Indexes
   RewriteEngine On
   RewriteBase /
   RewriteCond %{HTTP_HOST} ^www\.domain\.com$
   RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]
</IfModule>

Joomla website users:
You can use following free plugin from JED
http://extensions.joomla.org/extensions/site-management/url-redirection/10527

Create New user in Joomla

Filed Under (Joomla! 1.5) by khawaib on 30-07-2010

Tagged Under : , , , , , , , ,

<?php
function CreateNewUser($name, $username, $email, $password, $registerDate = NULL, $usertype = 'Registered', $block = '0', $sendEmail = '1', $gid = '18') {
        global $db;

        $db = & JFactory::getDBO();
        jimport('joomla.user.helper');

        //Make the joomla password hash
        $salt = JUserHelper::genRandomPassword(32);
        $crypt = JUserHelper::getCryptedPassword($password, $salt);
        $joomlapassword = $crypt . ':' . $salt;

        //Table #__users
        //Informations about the user
        $user = new stdClass;
        $user->id = NULL;
        $user->name = $name;
        $user->username = $username;
        $user->email = $email;
        $user->password = $joomlapassword;
        $user->registerDate = registerDate;
        $user->usertype = $usertype;
        $user->block = $block;
        $user->sendEmail = $sendEmail;
        $user->gid = $gid;

        if (!$db->insertObject('#__users', $user, 'id')) {
            echo $db->stderr();
            return false;
        }

        //Table #__core_acl_aro
        //Discover what is the last value of value in #__core_acl_aro
        $query = "SELECT value FROM #__core_acl_aro ORDER BY id DESC LIMIT 1";
        $db->setQuery($query);
        $coreaclarolastvalue = $db->loadResult();

        $coreaclaro = new stdClass;
        $coreaclaro->id = NULL;
        $coreaclaro->section_value = 'users';
        $coreaclaro->value = $coreaclarolastvalue + 1;
        $coreaclaro->order_value = NULL;
        $coreaclaro->name = $name;
        $coreaclaro->hidden = NULL;

        if (!$db->insertObject('#__core_acl_aro', $coreaclaro, 'id')) {
            echo $db->stderr();
            return false;
        }

        //Table #__core_acl_groups_aro_map
        $coreaclmap = new stdClass;
        $coreaclmap->group_id = $gid;
        $coreaclmap->section_value = NULL;
        $coreaclmap->aro_id = $coreaclaro->id; // maybe just $user->id ?

        if (!$db->insertObject('#__core_acl_groups_aro_map', $coreaclmap)) {
            echo $db->stderr();
            return false;
        }

        $CreateNewUserInfo = array($user->id, $user->name, $user->username, $user->email);
        return $CreateNewUserInfo;
}

Implementation


//This exemple will take data from one post, for example
$username = JRequest::getVar('username');
$name = JRequest::getvar('name');
$email = JRequest::getVar('email');
$password = JRequest::getVar('password');

//This code will call your funcion, then register with your data
$NewUserInfo = CreateNewUser($name, $username, $email, $password, $registerDate);

Menu Item Properties

Filed Under (Joomla! 1.5) by khawaib on 07-06-2010

Tagged Under : , , ,

Gives current menu:

$currentMenuName = JSite::getMenu()->getActive()->name ;

Current Menu ID:

$currentMenuId = JSite::getMenu()->getActive()->id ;

Gives menu status, published (1) and unpublished (0)

$currentMenuStatus = JSite::getMenu()->getActive()->published ;

Non SEO URL of current menu:

$currentMenuLink = JSite::getMenu()->getActive()->link ;

Current menus parent ID:

$currentMenuParent = JSite::getMenu()->getActive()->parent ;

Current Menu’s Access Level Value.(Public = 0, Registered = 1, Special= 2)

$currentMenuAccess = JSite::getMenu()->getActive()->access ;
[/php]

[php]

Breezing form data vairiables

Filed Under (Joomla! 1.5) by khawaib on 29-04-2010

Tagged Under : , ,

Joomla’s Breezing Form data variables:

// fallback if no template exists

if ($this->record_id != '')
$body .= BFText::_('PROCESS_RECORDSAVEDID')." ".$this->record_id.nl().nl();
$body .=
BFText::_('PROCESS_FORMID').": ".$this->form.nl().
BFText::_('PROCESS_FORMTITLE').": ".$this->formrow->title.nl().
BFText::_('PROCESS_FORMNAME').": ".$this->formrow->name.nl().nl().
BFText::_('PROCESS_SUBMITTEDAT').": ".$this->submitted.nl().
BFText::_('PROCESS_SUBMITTERIP').": ".$this->ip.nl().
BFText::_('PROCESS_PROVIDER').": ".$this->provider.nl().
BFText::_('PROCESS_BROWSER').": ".$this->browser.nl().
BFText::_('PROCESS_OPSYS').": ".$this->opsys.nl().nl();
if (count($this->maildata)) foreach ($this->maildata as $data)
$body .= $data[_FF_DATA_TITLE].": ".$data[_FF_DATA_VALUE].nl();
}

$attachment = NULL;
if ($this->formrow->emailxml>0) {
$attachment = $this->expxml();
if ($this->status != _FF_STATUS_OK) return;
} // if

for($i = 0; $i < $recipientsSize;$i++){
$this->sendMail($from, $fromname, $recipients[$i], $subject, $body, $attachment, $isHtml);
}
echo "test";
} // sendEmailNotification

Joomla plugin to insert codes in head section

Filed Under (Joomla! 1.5) by khawaib on 20-04-2010

Tagged Under : , , , , , , , , ,

Following is a template that can be used to develop plugins to inert code into Joomla head section.

<?xml version="1.0" encoding="utf-8"?>
<install version="1.5" type="plugin" group="system">
	<name>System - Name of Plugin</name>
	<author>Name of  author</author>
	<creationDate>19th April 2010</creationDate>
	<authorEmail>email@email.com</authorEmail>
	<authorUrl>http://www.khawaib.co.uk</authorUrl>
	<version>1.0</version>
        <copyright>Copyright (c) 2010 Khawaib Ahmed. All rights reserved.</copyright>
	<license>http://www.gnu.org/copyleft/gpl.html GNU/GPL</license>
	<description> Plugin description.</description>
	<files>
		<filename plugin="phpFileName">phpFileName.php</filename>
	</files>
	<params>
		<param name="code" type="text" default="[DEFAULT VALUE]" label="[LABEL]" description=" [DESCRIPTION]"  />
	</params>
</install>
<?php
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

jimport( 'joomla.plugin.plugin');

class plgSystemAsynGoogleAnalytics extends JPlugin {
	function plgAsynGoogleAnalytics(&$subject, $config) 	{
		parent::__construct($subject, $config);
		$this->_plugin = JPluginHelper::getPlugin( 'system', 'AsynGoogleAnalytics' );
		$this->_params = new JParameter( $this->_plugin->params );
	}

	function onAfterRender() {
		global $mainframe;

		// skip if admin page
		if($mainframe->isAdmin()) {
			return;
		}

		// get params
		$trackerCode = $this->params->get( 'code', '' );

		//getting body code and storing as buffer
		$buffer = JResponse::getBody();

		//embed Google Analytics code
		$javascript = "<script type=\"text/javascript\">
					  var _gaq = _gaq || [];

					  _gaq.push(['_setAccount', '".$trackerCode."']);
						_gaq.push(['_trackPageview']);

					  (function() {
						var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
						ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
						var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
					  })();
					</script>";

		// adding the Google Analytics code in the header before the ending </head> tag and then replacing the buffer
		$buffer = preg_replace ("/<\/head>/", "\n\n".$javascript."\n\n</head>", $buffer); 

		//output the buffer
		JResponse::setBody($buffer);

		return true;
	}
}
?>

GPL issues for Joomla extensions

Filed Under (Joomla! 1.5) by khawaib on 19-04-2010

Tagged Under : , , , , ,

GPL guidelines for submitting extensions to Joomla Extensions Directory(JED).

1- PHP files:
1A- Notice at the top of each php file stating that it is distributed under the terms of the GPL
(see http://www.fsf.org/licensing/licenses/gpl-howto.html for details)
1B- Copyright notice at the top of each php file,
as in:

/**
* @Copyright Copyright (C) 2010- ... author-name
* @license GNU/GPL http://www.gnu.org/copyleft/gpl.html
**/

2- XML File
2A- a tag in your extension’s XML file stating that it is GPL,
as in:

<license>GNU/GPL http://www.gnu.org/copyleft/gpl.html</license>

2B- a copy of the GPL license with your package
(note: this does not need to be installed with the extension, just included with the package as a text file)

Turn off/Remove Mootools in Joomla template on frontend

Filed Under (Joomla! 1.5) by khawaib on 13-04-2010

Tagged Under : , , ,

Use following code to turn off/remove Mootools in Joomla template on frontend.

$user =& JFactory::getUser();
if($user->get('guest') == 1) {
	$search = array('mootools', 'caption.js');
	// remove the js files
	foreach($this->_scripts as $key => $script) {
		foreach($search as $findme) {
			if(stristr($key, $findme) !== false) {
				unset($this->_scripts[$key]);
			}
		}
	}
}