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);

How To Create a Facebook Page

Filed Under (Facebook) by khawaib on 21-07-2010

How to access Faceboo Pages?

You can find Facebook Pages in left column on your Facebook home page when you are logged in. If it is not showing you can click on More link to find it.

Then click on create page link as shown in screenshot.

If you still can not find it Click Here to go directly to Facebook Create Page Screen (Make sure you are signed in Facebook).

Creating a Facebook Page

On Create a Page screen you will be asked to enter various categories of information to input.

You can choose between Official Page or Community Page.

When you create a page you will see URL in Browser address bar for that page. For example

Customized Facebook Profile URL

If you have customised Facebook Page URL then your ID will not show in URL and your URL will be like http://www.facebook.com/USER_NAME instead.

To find your Facebook Page ID from a Customised URL simply click on your profile picture and it will take you to your profile pictures. On profile pictures area you will see your Facebook Page ID in browser address bar.

PHP String Functions

Filed Under (PHP) by khawaib on 12-07-2010

To search a string in a text:

$string = "Ahmed";
$text = "My name is Ahmed.";

if(strstr($text, $string)) {
   echo "found it.";
} else {
   echo "not found.";
}

Useful Regular Expressions

Filed Under (Regex) by khawaib on 12-06-2010

Strips tags won’t remove the actual jscript

$text = preg_replace( "'<script[^>]*>.*?</script>'si", "", $text );

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]

chmod directories/files using command line

Filed Under (Ubuntu) by khawaib on 21-05-2010

Tagged Under : , , ,

//Following command will set the permission for all directories only:
find . -type d -exec chmod 755 {} \;
//Following command will set the permission for all files only:
find . -type f -exec chmod 644 {} \;
//To only apply chmod to files with names matching a specified pattern:
find . -type f -name '*.htm*' -exec chmod 644 {} \;
//To restrict to an owner you can also do:
find . -type d -user fileowner -exec chmod 0755 {} \;
//Changing files of only a specific type/extension is:
find ./ -name *.pdf -exec chmod 755 {} \;