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.";
}