Monday, February 25, 2013

Connect to facebook using localhost


Steps to connect to facebook from localhost

1. We need to trick facebook in believing we are from that we are from actual domain instead of localhost.

So what we need to do is create a host 

So go to /etc/hosts on ubuntu one can go in windows apache/hosts file and add the following

/etc/hosts

127.0.0.1       localhost
127.0.1.1       your local ip address or whatever
127.0.0.1       abo.mysite
127.0.1.1       abo.mysite

2. Now go to apache config
/etc/apache2/sites enabled/000-default and add the following

<VirtualHost abo.mysite:80>
 DocumentRoot /var/www/
    <Directory /var/www>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>
</VirtualHost>

 Now restart apache sudo /etc/init.d/apache2 restart and test the new locahost
http://abo.mysite this should resolve now.

3. No go to http://apps.facebook.com and create a new app after you create a app you should have settings as showin in the image below.






File index.php

require_once("library/facebook.php");

$facebook= new Facebook(array(
                'appId'  => '$appid',
                'secret' => '#appsecretkey'
            ));


$me = null;
// some random permissions
$permissions = 'publish_stream, create_event, rsvp_event, manage_pages, ads_management, user_photos';

// Session based API call.

    try {
        $uid = $facebook->getUser();
        echo $uid;
        $me = $facebook->api('/' . $uid);

    } catch (FacebookApiException $e) {
        var_dump($e);
    }

// here, check if the user has the application added
if ($me == null) {
    $loginUrl = $facebook->getLoginUrl(array(
        'canvas' => 1,
        'fbconnect' => 0,
        'req_perms' => $permissions,
        'next' => CALLBACK_URL . '?installed=1', // will be redirected to this URL after pressing "allow"
        'cancel_url' => CALLBACK_URL . '?cancel', // will be redirected here if app is not allowed
    )
    ); // end of array
    // redirect the user to the $loginUrl, you can place a button if you want
  
}
$user_profile = $facebook->api('/me');
var_dump($user_profile);   
exit;

Tuesday, February 14, 2012

Change default Shell to Bash in Ubuntu

1. Edit /etc/passwd and find the user whose shell you want to change and replace
/bin/sh to /bin/bash
2. Login as root and fire the command  chsh -s /bin/bash {username}

Now log out and login as the username

The newbash should appear.

Tuesday, December 6, 2011

Database Module in Joomla 1.7




Create a folder mod_userdatas above
1. Helper.php

<?php

defined('_JEXEC') or die;

class modUserDataHelper
{
  function getData( &$params )
  {
  
   // Database query  
   $list = array();   
   $query = " SELECT id, name, username "    
   ." FROM #__users "
   ." WHERE block=0 "    
   ." ORDER BY id DESC "
   ." LIMIT " . $params->get( 'limit' );    
   $db =& JFactory::getDBO();
   $db->setQuery( $query );  
   $rows = $db->loadObjectList();
     
   // Get list items
   if ($rows!=null)
   {
    $i=0;
    foreach ($rows as $row) 
    {    
     $list["users"][$i]["id"]=$row->id;
     $list["users"][$i]["name"]=$row->name;
     $list["users"][$i]["username"]=$row->username;
     $i++;  
    }
    return $list;
   }
     
  }
}

2. mod_userdata.xml
<?xml version="1.0" encoding="UTF-8"?>
<extension type="module" version="1.7" client="site" method="upgrade">
 <name>User Data Module</name>
 <author>Minitek.gr</author>
 <creationDate>03/08/2011</creationDate>
 <copyright>Copyright (C) 2011. All rights reserved.</copyright>
 <license>http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL</license>
 <authorEmail>your_email</authorEmail>
 <authorUrl>www.minitek.gr</authorUrl>
 <version>1.7.1</version>
 <description>Users Data Module</description>
 <languages>
 </languages>
 <files>
  <filename module="mod_userdata">mod_userdata.php</filename>
  <filename>mod_userdata.xml</filename>
  <filename>helper.php</filename>
  <filename>index.html</filename>
  <folder>tmpl</folder>
 </files>
 <config>
  <fields name="params">
   <fieldset name="basic">
    <field name="moduleclass_sfx" type="text" 
     default="" label="Module Class Suffix" 
     description="Suffix for individual css styling" />
    <field name="limit" type="text" default="10" 
       label="Limit Displayed Users" description="Limit Displayed Users" />
    <field name="user_id" type="radio" default="1" 
      label="Display user ID" description="Display user ID">
     <option value="0">JNO</option>
     <option value="1">JYES</option>
    </field>
    <field name="user_name" type="radio" default="1" 
      label="Display Name" description="Display Name">
     <option value="0">JNO</option>
     <option value="1">JYES</option>
    </field>
    <field name="user_username" type="radio" default="1" 
     label="Display Username" description="Display Username">
     <option value="0">JNO</option>
     <option value="1">JYES</option>
    </field>
   </fieldset>
  </fields>
 </config>
</extension>

3.mod_userdata.php
<?php

defined('_JEXEC') or die;

// Include the syndicate functions only once
require_once dirname(__FILE__).'/helper.php';

// Get the user data
$list = modUserDataHelper::getData($params);

// Get the layout
require JModuleHelper::getLayoutPath('mod_userdata', $params->get('layout', 'default'));
 
4. tmpl/default.php place the default.php in tmpl folder
 
<?php
s
defined('_JEXEC') or die; ?>

<div class="moduletable<?php echo $params->get( 'moduleclass_sfx' ) ?>">

 <ul>
  <?php for ($i=0;$i< sizeof($list["users"]); $i++) { ?> 
 
  <li>
   <?php if ($params->get( 'user_id' )) { ?>
   <span><?php echo $list["users"][$i]["id"];?></span>
  <?php } ?>
  <?php if ($params->get( 'user_name' )) { ?>
   <span><?php echo $list["users"][$i]["name"];?></span>
  <?php } ?>
  <?php if ($params->get( 'user_username' )) { ?>
   <span><?php echo $list["users"][$i]["username"];?></span>
  <?php } ?>
  </li>
 
 <?php } ?>
 </ul>

</div>
 
5. Place index.html under tmpl folder
 
<html><body bgcolor="#FFFFFF"></body></html>
 
Now zip the mod_userdata folder  and upload the module from 
adminstrator/extension and upload 
Activate and place the module