1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

What am I doing wrong? Not able to using variables from php in template.

Discussion in 'XenForo Development Discussions' started by arcaneex, Sep 1, 2012.

  1. arcaneex

    arcaneex Active Member

    Long story short , here's my listener:
    PHP:
    <?php
    class Steamrep_Rep_Rep {
    public static function 
    includePhpFile($hookName, &$contents, array $hookParamsXenForo_Template_Abstract $template)
        {
            if(
    $hookName == 'message_user_info_avatar')
            {
                
    ob_start();
                require_once(
    'repchecker.php');
                
    $contents .= ob_get_contents();
                
    ob_end_clean();
                            
    $hookParams['rep'] = $rep;
                            
    $params $template->getParams();
                            
    $params += $hookParams;
            }
        }
    }
    ?>
    My PHP file:
    PHP:
    <?php
    class Steam_Rep_Rep {
     
        
    // cURL Variable
        
    private $ch null;
     
        public function 
    __construct() {
            
    // Setup cURL
            
    $this->ch curl_init();
            
    curl_setopt($this->chCURLOPT_RETURNTRANSFER1);
            
    curl_setopt($this->chCURLOPT_TIMEOUT4);
        }   
        public function 
    getUserInfo($steamrep_id) {
            
    // cURL
            
    curl_setopt($this->chCURLOPT_URL"http://steamrep.com/api/beta/reputation/76561197971691194?json=1");
            
    $result curl_exec($this->ch);
            
    $xml json_decode($result);
            if(!empty(
    $xml->steamrep->reputation)) {
                return array(
                    
    'rep' => $xml->steamrep->reputation,
                );
            } else {
                return array(
                    
    'rep' => "No reputation found",
                );
            }
        }
    }
    $steam = new Steam_Rep_Rep();
    $rep $steam->getUserInfo('76561197971691194');
    ?>
    Basically , what I need to do is output the content of this link: http://steamrep.com/api/beta/reputation/76561197971691194?json=1 in message_user_info.
    Can anyone help?
     
  2. arcaneex

    arcaneex Active Member

    Okay I got it to work but instead of getting the contents , it just says NULL.
    Help?
     
  3. arcaneex

    arcaneex Active Member

    Can anyone help? Sorry if it seems I'm being rude but without this my forum can't be functioning :I
     
  4. Chris D

    Chris D XenForo Developer Staff Member

    As per my post yesterday, you have something missing.

    Ideally you need to create your own template that is inserted into the hook, and pass along with that the paramters. Right now the parameters you're defining aren't being passed to anything.

    Your Listener needs to look like this:


    PHP:
    <?php
    class Steamrep_Rep_Rep {
    public static function 
    includePhpFile($hookName, &$contents, array $hookParamsXenForo_Template_Abstract $template)
        {
            if(
    $hookName == 'message_user_info_avatar')
            {
                
    ob_start();
                require_once(
    'repchecker.php');
                
    ob_end_clean();
                            
    $hookParams['rep'] = $rep;
                            
    $params $template->getParams();
                            
    $params += $hookParams;
                
    $contents .= $template->create('steam_rep'$params);
            }
        }
    }
    ?>
    Then in your steam_rep template you can now use:

    {$rep.rep}

    For me, that looks like this:

    steam_rep.PNG
     
    bousaid likes this.
  5. arcaneex

    arcaneex Active Member

    Thank you so much but it doesn't show what you have.
    http://prntscr.com/es9nq
    I didn't have steam_rep , I suppose it needs to be created by the listener but it didn't so I manually created it and it still doesn't work.
     
  6. Chris D

    Chris D XenForo Developer Staff Member

    Looks like you've missed the dollar. The output says {rep.rep}

    My post says: {$rep.rep}
     
  7. arcaneex

    arcaneex Active Member

    It works! Thank you so much!
    One last question , how can I set an user group if the output is lets say SCAMMER it puts into user group 3 , and if DONATOR user group 4.
     

Share This Page