• 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

AndyB

Well-known member
#1
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:

AndyB

Well-known member
#2
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?
 

truonglv

Formerly Nobita.Kun
#3
You should replace {ip} to your value. Maybe helpful:
PHP:
strtr(
{$xenOptions.ipInfoUrl}, array(
'{ip}' => {$result.ip}
)
);
 

AndyB

Well-known member
#6
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.
 

truonglv

Formerly Nobita.Kun
#7
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 ;)
 

AndyB

Well-known member
#8
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.
 

truonglv

Formerly Nobita.Kun
#9
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 :)
 

Milano

Well-known member
#10
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

Well-known member
#11
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>