Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Arrowchat and vanilla integration

JoneJone New
edited April 2013 in Vanilla 2.0 - 2.8

I was trying to add arrowchat into my vanilla forum following this doc http://www.arrowchat.com/documentation/?p=custom-website But since i'm not PHP expert the doc cofused me. What to use Session or cookie?

If i use session the function will be like this:

 function get_user_id() 
{
    $userid = NULL;

    if (!empty($_SESSION['userid']))
    {
        $userid = $_SESSION['userid'];
    }

    return $userid;
}

so, what the name of vanilla session?

Thank you!

Comments

  • lifeisfoolifeisfoo ✭✭✭

    You can get the current vanilla userID using:

    //return the current session object
    $Session = Gdn::Session();
    //return true if this session is not a guest session
    $Valid = $Session->IsValid();
    //if you want only the userid
    $UserID = $Session->UserID;
    //user name
    $UserName = $Session->User->Name;
    

    There was an error rendering this rich post.

  • JoneJone New
    edited April 2013

    @lifeisfoo Thank you very much!!!

    So, do you think this looks good

    function get_user_id() 
        {
            $userid = NULL;
    
            if (isset($_SESSION['Gdn::Session()']['user']['UserID']))
            {
                $userid = $_SESSION['$Session->UserID']['user']['UserID'];
            }
    
            return $userid;
        }
    
  • lifeisfoolifeisfoo ✭✭✭
     function get_user_id() 
        {
            $Session = Gdn::Session();
            if ( $Session->IsValid() )
            {
                return $Session->UserID;
            }else{
                return NULL;
            }
        }
    

    Keep in mind that this must be executed in a scope where Garden is present. E.g. in a plugin or in a theme class (via hooks).

    There was an error rendering this rich post.

  • That's not working, I don't know why. I will keep trying anyway.

    Thanks,

  • lifeisfoolifeisfoo ✭✭✭

    If you post here all the code you are using for the integration somebody can help you.

    There was an error rendering this rich post.

  • JoneJone New
    edited April 2013

    Ok good here the whole integration.php file

    <?php
    
        session_start();
     /** The orginal integration function   
     *      function get_user_id()
     *      {
     *          $userid = NULL;
     *    
     *          if (isset($_SESSION['Gdn::Sessiion']['user']['UserID']))
     *          {
     *              $userid = $_SESSION['Gdn::Sessiion']['user']['UserID'];
     *          }
     *   
     *          return $userid; }
     *      
     */
    
     function get_user_id() 
        {
            $Session = Gdn::Session();
            if ( $Session->IsValid() )
            {
                return $Session->UserID;
            }else{
                return NULL;
            }
        }    
            function get_friend_list($userid, $time)
            {
                global $db;
                global $online_timeout;
    
                $sql = ("
                    SELECT DISTINCT " . TABLE_PREFIX . DB_USERTABLE . "." . DB_USERTABLE_USERID . " userid, " . TABLE_PREFIX . DB_USERTABLE . "." . DB_USERTABLE_NAME . " username, arrowchat_status.session_time lastactivity, " . TABLE_PREFIX . DB_USERTABLE . "." . DB_USERTABLE_AVATAR . " avatar, " . TABLE_PREFIX . DB_USERTABLE . "." . DB_USERTABLE_NAME . " link, arrowchat_status.is_admin, arrowchat_status.status
                    FROM " . TABLE_PREFIX . DB_FRIENDSTABLE . "
                    JOIN " . TABLE_PREFIX . DB_USERTABLE . "
                        ON  " . TABLE_PREFIX . DB_FRIENDSTABLE . "." . DB_FRIENDSTABLE_FRIENDID . " = " . TABLE_PREFIX . DB_USERTABLE . "." . DB_USERTABLE_USERID . "
                    LEFT JOIN arrowchat_status
                        ON " . TABLE_PREFIX . DB_USERTABLE . "." . DB_USERTABLE_USERID . " = arrowchat_status.userid
                    WHERE " . TABLE_PREFIX . DB_FRIENDSTABLE . "." . DB_FRIENDSTABLE_USERID . " = '" . $db->escape_string($userid) . "'
                        AND (arrowchat_status.session_time + 60 + " . $online_timeout . ") > " . time() . "
                    ORDER BY " . TABLE_PREFIX . DB_USERTABLE . "." . DB_USERTABLE_NAME . " ASC
                ");
    
                return $sql;
            }
    
            function get_online_list($userid, $time)
            {
                global $db;
                global $online_timeout;
    
                $sql = ("
                    SELECT DISTINCT " . TABLE_PREFIX . DB_USERTABLE . "." . DB_USERTABLE_USERID . " userid, " . TABLE_PREFIX . DB_USERTABLE . "." . DB_USERTABLE_NAME . " username, arrowchat_status.session_time lastactivity, " . TABLE_PREFIX . DB_USERTABLE . "." . DB_USERTABLE_AVATAR . " avatar, " . TABLE_PREFIX . DB_USERTABLE . "." . DB_USERTABLE_NAME . " link, arrowchat_status.is_admin, arrowchat_status.status
                    FROM " . TABLE_PREFIX . DB_USERTABLE . "
                    JOIN arrowchat_status
                        ON " . TABLE_PREFIX . DB_USERTABLE . "." . DB_USERTABLE_USERID . " = arrowchat_status.userid
                    WHERE ('" . time() . "' - arrowchat_status.session_time - 60 < '" . $online_timeout . "')
                        AND " . TABLE_PREFIX . DB_USERTABLE . "." . DB_USERTABLE_USERID . " != '" . $db->escape_string($userid) . "'
                    ORDER BY " . TABLE_PREFIX . DB_USERTABLE . "." . DB_USERTABLE_NAME . " ASC
                ");
    
                return $sql;
            }
    
            function get_user_details($userid)
            {
                global $db;
    
                $sql = ("
                    SELECT " . TABLE_PREFIX . DB_USERTABLE . "." . DB_USERTABLE_USERID . " userid, " . TABLE_PREFIX . DB_USERTABLE . "." . DB_USERTABLE_NAME . " username, arrowchat_status.session_time lastactivity,  " . TABLE_PREFIX . DB_USERTABLE . "." . DB_USERTABLE_NAME . " link,  " . TABLE_PREFIX . DB_USERTABLE . "." . DB_USERTABLE_AVATAR . " avatar, arrowchat_status.is_admin, arrowchat_status.status
                    FROM " . TABLE_PREFIX . DB_USERTABLE . "
                    LEFT JOIN arrowchat_status
                        ON " . TABLE_PREFIX . DB_USERTABLE . "." . DB_USERTABLE_USERID . " = arrowchat_status.userid
                    WHERE " . TABLE_PREFIX . DB_USERTABLE . "." . DB_USERTABLE_USERID . " = '" . $db->escape_string($userid) . "'
                ");
    
                return $sql;
            }
    
            /**
             * This function returns the profile link of the specified user ID.
             *
             * @param userid the user ID to get the profile link of
             * @return the link of the user ID's profile
             */
            function get_link($link, $user_id)
            {
                global $base_url;
    
                return $base_url . '../' . $link;
            }
    
    
            function get_avatar($image, $user_id)
            {
                global $base_url;
    
                if (is_file(dirname(dirname(dirname(__FILE__))) . '/uploads/' . $image))
                {
                    return $base_url . '../uploads/' . $image;
                }
                else
                {
                    return $base_url . AC_FOLDER_ADMIN . "/images/img-no-avatar.gif";
                }
            }
    
            /**
             * This function returns the name of the logged in user.  You should not need to
             * change this function.
             *
             * @param userid the user ID of the user
             * @return the name of the user
             */
            function get_username($userid)
            {
                global $db;
                global $language;
                global $show_full_username;
    
                $users_name = $language[83];
    
                $result = $db->execute("
                    SELECT " . DB_USERTABLE_NAME . " name
                    FROM " . TABLE_PREFIX . DB_USERTABLE . "
                    WHERE " . DB_USERTABLE_USERID . " = '" . $db->escape_string($userid) . "'
                ");
    
                if ($result AND $db->count_select() > 0)
                {
                    $row = $db->fetch_array($result);
                    $users_name = $row['name'];
                }
    
                $pieces = explode(" ", $users_name);
    
                if ($show_full_username == 1)
                {
                    return $users_name;
                }
                else
                {
                    return $pieces[0];
                }
            }
    
        ?>
    

    Thanks,

  • lifeisfoolifeisfoo ✭✭✭

    You need to setup db tables, syncronize them with vanilla user data, overwrite functions according to the arrowchat expected format, etc.
    Seems a not so little work.
    You can do this on your own or ask for a custom paid development here in the forum.

    There was an error rendering this rich post.

Sign In or Register to comment.