External Service Providers the use of the {ip} variable

AndyB

Well-known member
I would like to use the {ip} found in this Option:

pic001.webp

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.webp

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

What is the proper template code?

Thank you.
 
Last edited:
According to the instructions:

Specify a URL to be used for requesting more information about an IPv4 address. The URL must include {ip}, which will be replaced with the actual IP address.

How do we pass our variable to the curly brackets {ip} in the URL?
 
You should replace {ip} to your value. Maybe helpful:
PHP:
strtr(
{$xenOptions.ipInfoUrl}, array(
'{ip}' => {$result.ip}
)
);
 
Hello Nobita.Kun,

Thank you for you help with this.

Does this code go into the PHP file or template?
 
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.
 
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 ;)
 
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.
 
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 :)
 
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
 
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

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>
 
Top Bottom