Part of the EllisLab Network
   
1 of 3
1
OpenInviter.com library wrapper
Posted: 22 May 2009 05:25 PM   [ Ignore ]  
Grad Student
Rank
Total Posts:  81
Joined  05-16-2009

I was Googling for this and saw a couple people needed it, this is just a small library wrapper for the OpenInviter.com tool that will return contacts as an array for you to work with.

<?php
/* tky@tmo.blackberry.net inviter.php Fri May 22 04:00:19 GMT 2009 */

class importer
{
    
var $ci;
    var 
$imported;
    
    public function 
__construct()
    
{
        $this
->ci=&get;_instance();
    
}

    
public function grab_contacts($plugin,$username,$password)
    
{
        
require_once($this->ci->config->item('absolute_url').'include/openinviter/openinviter.php');
        
        
$oi    = new OpenInviter();
        
        
$oi->startPlugin($plugin);
        
$oi->login($username,$password);
        
        
$array        =     $oi->getMyContacts();
        
        if(
is_array($array) && count($array)>=1)
        
{
            $this
->imported        =    $array;
            
            
$this->_store_invited();
            
            return(
$this->imported);
        
}else{
            
return;
        
}
    }
    
    
private function _store_invited()
    
{
        
foreach($this->imported as $mail=>$name)
        
{
            $a    
=    array(    'user_id'        =>    ospc_user_id(),
                            
'name'            =>    $name,
                            
'email_address'    =>    $mail,
                            
'status'        =>    0,
                            
'time_imported'    =>    time()    );
                            
            
$this->ci->db->insert('ospc_imported',$a);
            
            unset(
$a);
        
}
    }
}
?> 
 Signature 

sr web applications developer
ci, mysql driven, jquery powered (mostly social web applications)

taky.bz, blackhat

Profile
 
 
Posted: 22 May 2009 05:37 PM   [ Ignore ]   [ # 1 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  2674
Joined  05-18-2008

smile I can see this being very useful very soon
I’m building a large multi user site, so something lie this to make it easier to get other users in will be a great help

Thanks for sharing

 Signature 

I’m building a Project Management System for my 3rd year Uni project, Sign up to the beta
Track my progress | Post of the day: UI Designs
Get full auto complete support for CodeIgniter in Eclipse

Profile
 
 
Posted: 22 May 2009 05:40 PM   [ Ignore ]   [ # 2 ]  
Grad Student
Rank
Total Posts:  81
Joined  05-16-2009

no problem, its a great tool to have for a social networking site. usually i would just write out the curl sequence and parse the page myself with regex, but this api auto-updates and its free so why the hell not, just as long as i dont have to see any of their ugly coding-style in my project smile

 Signature 

sr web applications developer
ci, mysql driven, jquery powered (mostly social web applications)

taky.bz, blackhat

Profile
 
 
Posted: 24 June 2009 07:33 AM   [ Ignore ]   [ # 3 ]  
Summer Student
Total Posts:  12
Joined  06-24-2009

is there any documentation with your wrapper? Even if it seems very easy to understand some documentation and examples wouldn’t hurt. Thank you very much tkyy. btw I can’t stand their coding-style too.

Profile
 
 
Posted: 03 July 2009 08:34 AM   [ Ignore ]   [ # 4 ]  
Grad Student
Rank
Total Posts:  38
Joined  06-27-2009

Thanks for this! Love it.

Profile
 
 
Posted: 06 July 2009 02:32 AM   [ Ignore ]   [ # 5 ]  
Summer Student
Total Posts:  25
Joined  02-06-2009

I’m working with this right now.  I’ve got most of it working, but I don’t get where ospc_user_id() is supposed to come from.  It is late, though, so perhaps I should look at it when I’m more fresh.

Profile
 
 
Posted: 10 July 2009 03:44 PM   [ Ignore ]   [ # 6 ]  
Grad Student
Rank
Total Posts:  38
Joined  06-27-2009

I am integrate it right now, I’ll share it with you all when it works.

Profile
 
 
Posted: 13 July 2009 04:25 PM   [ Ignore ]   [ # 7 ]  
Research Assistant
RankRankRank
Total Posts:  550
Joined  12-14-2008

Hi , this wrapper works with the following changes :

The inviter Class

<?php
/* tky@tmo.blackberry.net inviter.php Fri May 22 04:00:19 GMT 2009 */

class inviter
{
    
var $ci;
    var 
$imported;
    
    public function 
__construct()
    
{
        $this
->ci=& get_instance();
    
}

    
public function grab_contacts($plugin,$username,$password)
    
{
        
require_once($this->ci->config->item('absolute_url').'OpenInviter/openinviter.php');
        
        
$oi    = new OpenInviter();
        
        
$oi->startPlugin($plugin);
        
//First modification , added the if clause
        
if($oi->login($username,$password))
        
{
            $array        
=     $oi->getMyContacts();
            
            if(
is_array($array) && count($array)>=1)
            
{
                $this
->imported        =    $array;
                
                
$this->_store_invited();
                
                return(
$this->imported);
            
}else{
                
return;
            
}
        }
        
else
        
{
        
return 'ERROR on login.';
        
}
    }
    
    
private function _store_invited()
    
{
        
foreach($this->imported as $mail=>$name)
        
{
            
//Second modification , commented out the user_id /

            
$a    =    array(   /* 'user_id'        =>    ospc_user_id(),*/
                            
'name'            =>    $name,
                            
'email_address'    =>    $mail,
                            
'status'        =>    0,
                            
'time_imported'    =>    time()    );
                            
            
$this->ci->db->insert('ospc_imported',$a);
            
            unset(
$a);
        
}
    }
}
?> 

Notice that i commented out the user_id key from $a array , just because it showed errors when was not commented .
Also i added an if clause for login , because previously , when the login failed there where some nasty errors but now, when login fails , it shows “ERROR on login.” ans the script stops .

I tried as follows , in one of my controllers

function openinviter()
    
{
    ini_set
('display_errors',1);
    
error_reporting(E_ALL);    
    
$this->load->library('Inviter');    
    
$plugin 'yahoo';
    
$username $this->input->post('username');
    
$password $this->input->post('password');
    if(empty(
$username) || empty($password))
        
{
        
echo '<form action="" method="post">
        Username :<input type="text" name="username" />
        <br />
        Password:<input type="text" name="password" />
        <br />
        <input type="submit" name="submit" value="send"/>
        </form>'
;
        
}
    
else
        
{
        $users 
$this->inviter->grab_contacts($plugin,$username,$password)   ;
        echo 
'<pre>';
        
print_r($users);
        echo 
'</pre>';
        
}    
    } 

And everything went ok ,it printed the array with the needed values .

Hope that helps someone smile

Profile
 
 
Posted: 28 July 2009 07:32 AM   [ Ignore ]   [ # 8 ]  
Summer Student
Total Posts:  12
Joined  06-24-2009

Got a little problem here I used the Twisted1919 mods but I get a fatal error. any Idea what the problem is?


A PHP Error was encountered

Severity: Notice

Message: Undefined property: OpenInviter::$plugin

Filename: OpenInviter/openinviter.php

Line Number: 391

Fatal error: Call to a member function isEmail() on a non-object in /home/advancg6/public_html/taiwanoutlet/ci/OpenInviter/openinviter.php on line 391

Profile
 
 
Posted: 30 July 2009 02:26 AM   [ Ignore ]   [ # 9 ]  
Summer Student
Avatar
Total Posts:  3
Joined  04-22-2009
hikari - 28 July 2009 11:32 AM

Got a little problem here I used the Twisted1919 mods but I get a fatal error. any Idea what the problem is?

I ran into the same problem. The issue turned out to be a configuration problem. I had stats enabled in my config file but my install didn’t support stats. Disabling stats fixed the issue.

For future reference, if you’re having weird problems like this, you can retrieve the internal message from the OI object. I just used print_r() on the OI object to see if the plugin was loaded (it wasn’t) and if any error had been set.

Profile
 
 
Posted: 31 July 2009 01:33 AM   [ Ignore ]   [ # 10 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  109
Joined  03-27-2009

Hi,
I am creating one like this.
Thanks for the inspiration smile

Thanks
DesignFellow

 Signature 

Download CodeIgniter 2.0 Cheat Sheet http://www.mmyo.me/30

More CodeIgniter Related Resources : www.memeyo.com/groups/codeigniter

Profile
 
 
   
1 of 3
1