Welcome Guest, Not a member yet? Register   Sign In
OpenInviter.com library wrapper
#1

[eluser]tkyy[/eluser]
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.

Code:
<?php
/* [email protected] 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);
        }
    }
}
?>
#2

[eluser]Dam1an[/eluser]
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
#3

[eluser]tkyy[/eluser]
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
#4

[eluser]hikari[/eluser]
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.
#5

[eluser]R. Oerlemans[/eluser]
Thanks for this! Love it.
#6

[eluser]coding_hero[/eluser]
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.
#7

[eluser]R. Oerlemans[/eluser]
I am integrate it right now, I'll share it with you all when it works.
#8

[eluser]Twisted1919[/eluser]
Hi , this wrapper works with the following changes :

The inviter Class

Code:
<?php
/* [email protected] 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
Code:
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:&lt;input type="text" name="password" /&gt;
        <br />
        &lt;input type="submit" name="submit" value="send"/&gt;
        &lt;/form&gt;';
        }
    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
#9

[eluser]hikari[/eluser]
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
#10

[eluser]Steven Richards[/eluser]
[quote author="hikari" date="1248798760"]Got a little problem here I used the Twisted1919 mods but I get a fatal error. any Idea what the problem is?[/quote]

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.




Theme © iAndrew 2016 - Forum software by © MyBB