Skip to content

Commit

Permalink
Working on #2972 Template Conversion to Twig Format (modcp_ipsearch) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Starpaul20 authored and euantorano committed Jun 2, 2019
1 parent 697167d commit b81ad69
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 58 deletions.
1 change: 1 addition & 0 deletions inc/languages/english/modcp.lang.php
Expand Up @@ -78,6 +78,7 @@
$l['number_awaiting'] = "Number Awaiting";
$l['latest'] = "Latest";
$l['ipsearch'] = "IP Search";
$l['iplookup'] = "IP Lookup";
$l['ipsearch_results'] = "IP Search Results for '{1}'";
$l['ipaddress_search'] = "IP Address Search";
$l['ipaddress_misc_info'] = "Misc. Information for '{1}'";
Expand Down
30 changes: 30 additions & 0 deletions inc/views/base/modcp/iplookup.twig
@@ -0,0 +1,30 @@
{% extends 'layouts/master.twig' %}

{% block head %}
<title>{{ mybb.settings.bbname }} - {{ lang.iplookup }}</title>
{% endblock head %}

{% block body %}
<table width="100%" border="0" align="center">
<tr>
{# To do: modcp_nav #}
<td valign="top">
<table border="0" cellspacing="{{ theme.borderwidth }}" cellpadding="{{ theme.tablespace }}" class="tborder">
<tr>
<td class="thead" align="center" colspan="2">
<strong>{{ trans('ipaddress_misc_info', ipaddress.ipaddress) }}</strong>
</td>
</tr>
<tr>
<td class="trow1" width="25%" align="center">{{ lang.ipaddress_host_name }}</td>
<td class="trow1">{{ ipaddress.host_name }}</td>
</tr>
<tr>
<td class="trow2" width="25%" align="center">{{ lang.ipaddress_location }}</td>
<td class="trow2">{{ ipaddress.location }}</td>
</tr>
</table>
</td>
</tr>
</table>
{% endblock body %}
19 changes: 19 additions & 0 deletions inc/views/base/modcp/iplookup_modal.twig
@@ -0,0 +1,19 @@
<div class="modal">
<div style="overflow-y: auto; max-height: 400px;">
<table border="0" cellspacing="{{ theme.borderwidth }}" cellpadding="{{ theme.tablespace }}" class="tborder">
<tr>
<td class="thead" align="center" colspan="2">
<strong>{{ trans('ipaddress_misc_info', ipaddress.ipaddress) }}</strong>
</td>
</tr>
<tr>
<td class="trow1" width="25%" align="center">{{ lang.ipaddress_host_name }}</td>
<td class="trow1">{{ ipaddress.host_name }}</td>
</tr>
<tr>
<td class="trow2" width="25%" align="center">{{ lang.ipaddress_location }}</td>
<td class="trow2">{{ ipaddress.location }}</td>
</tr>
</table>
</div>
</div>
83 changes: 83 additions & 0 deletions inc/views/base/modcp/ipsearch.twig
@@ -0,0 +1,83 @@
{% extends 'layouts/master.twig' %}

{% block head %}
<title>{{ mybb.settings.bbname }} - {{ lang.ipsearch }}</title>
{% endblock head %}

{% block body %}
<table width="100%" border="0" align="center">
<tr>
{# To do: modcp_nav #}
<td valign="top">
{% if ipsearch.results %}
<table border="0" cellspacing="{{ theme.borderwidth }}" cellpadding="{{ theme.tablespace }}" class="tborder">
<tr>
<td class="thead" align="center" colspan="2">
{% if ipsearch.info_link %}
<div class="float_right">
(<a href="modcp.php?action=iplookup&amp;ipaddress={{ ipsearch.ipaddress }}" onclick="MyBB.popupWindow('/modcp.php?action=iplookup&ipaddress={{ ipsearch.ipaddress_url }}&modal=1'); return false;">{{ lang.info_on_ip }}</a>
| <a href="http://www.stopforumspam.com/ipcheck/{{ ipsearch.ipaddress }}" target="_blank" rel="noopener">{{ lang.search_ip_sfs }}</a>)
</div>
{% endif %}
<div><strong>
{% if ipsearch.ipaddress %}
{{ trans('ipsearch_results', ipsearch.ipaddress) }}
{% else %}
{{ lang.ipsearch }}
{% endif %}
</strong></div>
</td>
</tr>
<tr>
<td class="tcat" width="15%" align="center"><span class="smalltext"><strong>{{ lang.ipaddress }}</strong></span></td>
<td class="tcat"><span class="smalltext"><strong>{{ lang.result }}</strong></span></td>
</tr>
{% for ipaddress in ipresults %}
{% set row = alt_trow() %}
<tr>
<td class="{{ row }}" align="center">{{ ipaddress.ip }}</td>
<td class="{{ row }}">
{% if ipaddress.type == 'regip' %}
<strong>{{ lang.ipresult_regip }}</strong> {{ ipaddress.profile_link|raw }}
{% elseif ipaddress.type == 'lastip' %}
<strong>{{ lang.ipresult_lastip }}</strong> {{ ipaddress.profile_link|raw }}
{% else %}
<strong>{{ lang.ipresult_post }}</strong> <a href="{{ ipaddress.postlink|raw }}">{{ ipaddress.subject }}</a> {{ lang.by }} {{ ipaddress.profilelink|raw }}
{% endif %}
</td>
</tr>
{% else %}
<tr>
<td class="trow1" align="center" colspan="2">{{ lang.error_no_results }}</td>
</tr>
{% endfor %}
</table>
{{ multipage|raw }}
<br />
{% endif %}
<form action="modcp.php?action=ipsearch" method="post">
<table border="0" cellspacing="{{ theme.borderwidth }}" cellpadding="{{ theme.tablespace }}" class="tborder">
<tr>
<td class="thead" colspan="2"><strong>{{ lang.ipaddress_search }}</strong></td>
</tr>
<tr>
<td class="trow1" width="25%"><strong>{{ lang.ip_address }}</strong></td>
<td class="trow1" width="75%"><input type="text" class="textbox" name="ipaddress" value="{{ ipsearch.ipaddress }}" size="30" /></td>
</tr>
<tr>
<td class="trow1" width="25%" valign="top"><strong>{{ lang.options }}</strong></td>
<td class="trow1" width="75%">
<label><input type="checkbox" class="checkbox" name="search_users" value="1"{% if ipsearch.usersearch %} checked="checked"{% endif %} />{{ lang.search_users }}</label><br />
<label><input type="checkbox" class="checkbox" name="search_posts" value="1"{% if ipsearch.postsearch %} checked="checked"{% endif %} />{{ lang.search_posts }}</label>
</td>
</tr>
</table>
<br />
<div align="center">
<input type="submit" class="button" value="{{ lang.find }}" />
</div>
</form>
</td>
</tr>
</table>
{% endblock body %}
118 changes: 60 additions & 58 deletions modcp.php
Expand Up @@ -2857,13 +2857,15 @@

add_breadcrumb($lang->mcp_nav_ipsearch, "modcp.php?action=ipsearch");

$ipsearch['results'] = false;
$mybb->input['ipaddress'] = $mybb->get_input('ipaddress');
if ($mybb->input['ipaddress']) {
$ipsearch['results'] = true;
if (!is_array($groupscache)) {
$groupscache = $cache->read("usergroups");
}

$ipaddressvalue = htmlspecialchars_uni($mybb->input['ipaddress']);
$ipsearch['ipaddress'] = $mybb->input['ipaddress'];

$ip_range = fetch_ip_range($mybb->input['ipaddress']);

Expand Down Expand Up @@ -3007,36 +3009,36 @@
$multipage = multipage($total_results, $perpage, $page, $page_url);

$post_limit = $perpage;
$results = '';
$ipresults = [];
if (isset($mybb->input['search_users']) && $user_results && $start <= $user_results) {
$query = $db->simple_select('users', 'username, uid, regip, lastip', $user_ip_sql,
array('order_by' => 'regdate', 'order_dir' => 'DESC', 'limit_start' => $start, 'limit' => $perpage));

while ($ipaddress = $db->fetch_array($query)) {
$result = false;
$ipaddress['username'] = htmlspecialchars_uni($ipaddress['username']);
$profile_link = build_profile_link($ipaddress['username'], $ipaddress['uid']);
$trow = alt_trow();
$ip = false;
$ipaddress['profile_link'] = build_profile_link($ipaddress['username'], $ipaddress['uid']);
$ipaddress['type'] = $ipaddress['ip'] = false;
if (is_array($ip_range)) {
if (strcmp($ip_range[0], $ipaddress['regip']) <= 0 && strcmp($ip_range[1], $ipaddress['regip']) >= 0) {
eval("\$subject = \"".$templates->get("modcp_ipsearch_result_regip")."\";");
$ip = my_inet_ntop($db->unescape_binary($ipaddress['regip']));
$ipaddress['type'] = 'regip';
$ipaddress['ip'] = my_inet_ntop($db->unescape_binary($ipaddress['regip']));
} elseif (strcmp($ip_range[0], $ipaddress['lastip']) <= 0 && strcmp($ip_range[1], $ipaddress['lastip']) >= 0) {
eval("\$subject = \"".$templates->get("modcp_ipsearch_result_lastip")."\";");
$ip = my_inet_ntop($db->unescape_binary($ipaddress['lastip']));
$ipaddress['type'] = 'lastip';
$ipaddress['ip'] = my_inet_ntop($db->unescape_binary($ipaddress['lastip']));
}
} elseif ($ipaddress['regip'] == $ip_range) {
eval("\$subject = \"".$templates->get("modcp_ipsearch_result_regip")."\";");
$ip = my_inet_ntop($db->unescape_binary($ipaddress['regip']));
$ipaddress['type'] = 'regip';
$ipaddress['ip'] = my_inet_ntop($db->unescape_binary($ipaddress['regip']));
} elseif ($ipaddress['lastip'] == $ip_range) {
eval("\$subject = \"".$templates->get("modcp_ipsearch_result_lastip")."\";");
$ip = my_inet_ntop($db->unescape_binary($ipaddress['lastip']));
$ipaddress['type'] = 'lastip';
$ipaddress['ip'] = my_inet_ntop($db->unescape_binary($ipaddress['lastip']));
}
if ($ip) {
eval("\$results .= \"".$templates->get("modcp_ipsearch_result")."\";");

if ($ipaddress['ip']) {
$ipresults[] = $ipaddress;
$result = true;
}

if ($result) {
--$post_limit;
}
Expand Down Expand Up @@ -3080,100 +3082,100 @@
unset($uids);

foreach ($ipaddresses as $ipaddress) {
$ip = my_inet_ntop($db->unescape_binary($ipaddress['ipaddress']));
$ipaddress['ip'] = my_inet_ntop($db->unescape_binary($ipaddress['ipaddress']));
if (!$ipaddress['username']) {
$ipaddress['username'] = $ipaddress['postusername']; // Guest username support
}
$ipaddress['username'] = htmlspecialchars_uni($ipaddress['username']);
$trow = alt_trow();

if (!$ipaddress['subject']) {
$ipaddress['subject'] = "RE: {$ipaddress['threadsubject']}";
}

$ipaddress['postlink'] = get_post_link($ipaddress['pid'], $ipaddress['tid']);
$ipaddress['subject'] = htmlspecialchars_uni($parser->parse_badwords($ipaddress['subject']));
$ipaddress['subject'] = $parser->parse_badwords($ipaddress['subject']);
$ipaddress['profilelink'] = build_profile_link($ipaddress['username'], $ipaddress['uid']);

eval("\$subject = \"".$templates->get("modcp_ipsearch_result_post")."\";");
eval("\$results .= \"".$templates->get("modcp_ipsearch_result")."\";");
$ipresults[] = $ipaddress;
}
}
}

if (!$results) {
eval("\$results = \"".$templates->get("modcp_ipsearch_noresults")."\";");
}

if ($ipaddressvalue) {
$lang->ipsearch_results = $lang->sprintf($lang->ipsearch_results, $ipaddressvalue);
} else {
$lang->ipsearch_results = $lang->ipsearch;
}

$ipaddress = $ipaddress_url = $misc_info_link = '';
$ipsearch['info_link'] = false;
if (!strstr($mybb->input['ipaddress'], "*") && !strstr($mybb->input['ipaddress'], "/")) {
$ipaddress = htmlspecialchars_uni($mybb->input['ipaddress']);
$ipaddress_url = urlencode($mybb->input['ipaddress']);
eval("\$misc_info_link = \"".$templates->get("modcp_ipsearch_results_information")."\";");
$ipsearch['info_link'] = true;
$ipsearch['ipaddress_url'] = urlencode($mybb->input['ipaddress']);
}

eval("\$ipsearch_results = \"".$templates->get("modcp_ipsearch_results")."\";");
}

// Fetch filter options
if (!$mybb->input['ipaddress']) {
$mybb->input['search_posts'] = 1;
$mybb->input['search_users'] = 1;
}
$usersearchselect = $postsearchselect = '';

$ipsearch['usersearch'] = $ipsearch['postsearch'] = false;
if (isset($mybb->input['search_posts'])) {
$postsearchselect = "checked=\"checked\"";
$ipsearch['postsearch'] = true;
}
if (isset($mybb->input['search_users'])) {
$usersearchselect = "checked=\"checked\"";
$ipsearch['usersearch'] = true;
}

$plugins->run_hooks('modcp_ipsearch_end');

eval("\$ipsearch = \"".$templates->get("modcp_ipsearch")."\";");
output_page($ipsearch);
output_page(\MyBB\template('modcp/ipsearch.twig', [
'ipsearch' => $ipsearch,
'multipage' => $multipage,
'ipresults' => $ipresults,
]));
}

if ($mybb->input['action'] == "iplookup") {
if ($mybb->usergroup['canuseipsearch'] == 0) {
error_no_permission();
}

$mybb->input['ipaddress'] = $mybb->get_input('ipaddress');
$lang->ipaddress_misc_info = $lang->sprintf($lang->ipaddress_misc_info, htmlspecialchars_uni($mybb->input['ipaddress']));
$ipaddress_location = $lang->na;
$ipaddress_host_name = $lang->na;
$modcp_ipsearch_misc_info = '';
if (!strstr($mybb->input['ipaddress'], "*")) {
$modal = $mybb->get_input('modal', MyBB::INPUT_INT);
$ipaddress['ipaddress'] = $mybb->get_input('ipaddress');
$ipaddress['location'] = $ipaddress['host_name'] = $lang->na;

if(!$ipaddress['ipaddress'])
{
error($lang->error_missing_ipaddress);
}

if (!strstr($ipaddress['ipaddress'], "*")) {
// Return GeoIP information if it is available to us
if (function_exists('geoip_record_by_name')) {
$ip_record = @geoip_record_by_name($mybb->input['ipaddress']);
$ip_record = @geoip_record_by_name($ipaddress['ipaddress']);
if ($ip_record) {
$ipaddress_location = htmlspecialchars_uni(utf8_encode($ip_record['country_name']));
$ipaddress['location'] = utf8_encode($ip_record['country_name']);
if ($ip_record['city']) {
$ipaddress_location .= $lang->comma.htmlspecialchars_uni(utf8_encode($ip_record['city']));
$ipaddress['location'] .= $lang->comma.utf8_encode($ip_record['city']);
}
}
}

$ipaddress_host_name = htmlspecialchars_uni(@gethostbyaddr($mybb->input['ipaddress']));
$ipaddress['host_name'] = @gethostbyaddr($ipaddress['ipaddress']);

// gethostbyaddr returns the same ip on failure
if ($ipaddress_host_name == $mybb->input['ipaddress']) {
$ipaddress_host_name = $lang->na;
if ($ipaddress['host_name'] == $ipaddress['ipaddress']) {
$ipaddress['host_name'] = $lang->na;
}
}

$plugins->run_hooks('modcp_iplookup_end');

eval("\$iplookup = \"".$templates->get('modcp_ipsearch_misc_info', 1, 0)."\";");
echo($iplookup);
exit;
if ($modal) {
output_page(\MyBB\template('modcp/iplookup_modal.twig', [
'ipaddress' => $ipaddress,
]));
exit;
} else {
output_page(\MyBB\template('modcp/iplookup.twig', [
'ipaddress' => $ipaddress,
]));
}
}

if ($mybb->input['action'] == "banning") {
Expand Down

0 comments on commit b81ad69

Please sign in to comment.