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

External Service Providers the use of the {ip} variable

Discussion in 'XenForo Development Discussions' started by AndyB, May 5, 2014.

  1. AndyB

    AndyB Well-Known Member

    I would like to use the {ip} found in this Option:

    pic001.jpg

    In my template I have the following:

    Code:
    <xen:foreach loop="$results" value="$result">
    <tr class="dataRow">
        <td>{$result.username}</td>   
        <td><a href="{$xenOptions.ipInfoUrl}{$result.ip}">{$result.ip}</a></td>
        <td>{$result.user_agent}</td>
        <td>{xen:datetime $result.view_date}</td>
    </tr>
    </xen:foreach>
    
    When I hover my mouse over the IP link, I get the following:

    pic002.jpg

    Notice the {ip} is still in the URL and not being converted.

    What is the proper template code?

    Thank you.
     
    Last edited: May 5, 2014
  2. AndyB

    AndyB Well-Known Member

    According to the instructions:

    How do we pass our variable to the curly brackets {ip} in the URL?
     
  3. Nobita.Kun

    Nobita.Kun Well-Known Member

    You should replace {ip} to your value. Maybe helpful:
    PHP:
    strtr(
    {
    $xenOptions.ipInfoUrl}, array(
    '{ip}' => {$result.ip}
    )
    );
     
  4. AndyB

    AndyB Well-Known Member

    Hello Nobita.Kun,

    Thank you for you help with this.

    Does this code go into the PHP file or template?
     
  5. Nobita.Kun

    Nobita.Kun Well-Known Member

    Should be in PHP file. :)
     
  6. AndyB

    AndyB Well-Known Member

    My PHP file looks something like this:

    PHP:
    // prepare viewParams
    $viewParams = array(
        
    'results' => $results
    );        

    // send to template
    return $this->responseView('Andy_UserAgent_ViewPublic_UserAgent''andy_useragent'$viewParams);
    I don't understand where your code would fit in.
     
  7. Nobita.Kun

    Nobita.Kun Well-Known Member

    PHP:
    // prepare viewParams

    foreach ($results as $key => $result)
    {
        
    $result['linktoIP'] = strtr(XenForo_Application::getOptions()->ipInfoUrl, array(
            
    '{ip}' => $result['ip']
        ));
    }

    $viewParams = array(
        
    'results' => $results
    );       

    // send to template
    return $this->responseView('Andy_UserAgent_ViewPublic_UserAgent''andy_useragent'$viewParams);
    Then in template you can using $result.linktoIP :) Didn't test but should work ;)
     
  8. AndyB

    AndyB Well-Known Member

    Hi Nobita.Kun,

    I tried your code, but unfortunately it doesn't work. However you have shown me how it could be done through PHP by adding to the $results variable, I can do that.

    I was hoping that this could be done all through the template syntax, which would have been very good. Perhaps Mike will take a look at this and confirm if there is a template only solution. Otherwise I can add data to the $results array through PHP.

    Again, than you very much for your time it has been a great help as always.
     
  9. Nobita.Kun

    Nobita.Kun Well-Known Member

    Its should work.
    Code:
    <xen:foreach loop="$results" value="$result">
    <tr class="dataRow">
        <td>{$result.username}</td>
    {xen:helper dump, $result.linktoIP}
        <td><a href="{$result.linktoIP}">{$result.ip}</a></td>
        <td>{$result.user_agent}</td>
        <td>{xen:datetime $result.view_date}</td>
    </tr>
    </xen:foreach>
    What's the result return from that code :)
     
  10. Milano

    Milano Well-Known Member

    Why you don't use {xen:link misc/ip-info ..} just like spam_cleaner template, it will validate your IP and forward to the chosen provider site
     
    AndyB likes this.
  11. AndyB

    AndyB Well-Known Member

    That's exactly the information I was looking for! :)

    Thank you very much, Milano.

    Code:
    <xen:foreach loop="$results" value="$result">
    <tr class="dataRow">
        <td>{$result.username}</td>      
        <td><a href="{xen:link misc/ip-info, '', 'ip={$result.ip}'}" target="_blank">{$result.ip}</a></td>
        <td>{$result.user_agent}</td>
        <td>{xen:datetime $result.view_date}</td>
    </tr>
    </xen:foreach>
    
     

Share This Page