Skip to content

Commit

Permalink
Working on #2972 Template Conversion to Twig Format (modcp_warninglog…
Browse files Browse the repository at this point in the history
…s) (#3213)

* Working on #2972 Template Conversion to Twig Format (modcp_warninglogs)

* Nested template into folder
  • Loading branch information
Starpaul20 authored and euantorano committed Jun 2, 2019
1 parent b81ad69 commit 8b6b055
Show file tree
Hide file tree
Showing 3 changed files with 177 additions and 33 deletions.
119 changes: 119 additions & 0 deletions inc/views/base/modcp/warninglogs.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
{% extends 'layouts/master.twig' %}

{% block head %}
<title>{{ mybb.settings.bbname }} - {{ lang.warning_logs }}</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="6"><strong>{{ lang.warning_logs }}</strong></td>
</tr>
<tr>
<td class="tcat" width="15%"><span class="smalltext"><strong>{{ lang.warned_user }}</strong></span></td>
<td class="tcat" width="25%"><span class="smalltext"><strong>{{ lang.warning }}</strong></span></td>
<td class="tcat" width="20%" align="center"><span class="smalltext"><strong>{{ lang.date_issued }}</strong></span></td>
<td class="tcat" width="20%" align="center"><span class="smalltext"><strong>{{ lang.expires }}</strong></span></td>
<td class="tcat" width="15%"><span class="smalltext"><strong>{{ lang.issued_by }}</strong></span></td>
<td class="tcat" width="1%" align="center"><span class="smalltext"><strong>{{ lang.details }}</strong></span></td>
</tr>
{% for warning in warning_list %}
{% include 'modcp/warninglogs/item.twig' %}
{% else %}
<tr>
<td class="trow1" align="center" colspan="6">{{ lang.no_warning_logs }}</td>
</tr>
{% endfor %}
</table>
{{ multipage|raw }}
<br />
<form action="modcp.php" method="get">
<input type="hidden" name="action" value="warninglogs" />
<table border="0" cellspacing="{{ theme.borderwidth }}" cellpadding="{{ theme.tablespace }}" class="tborder">
<tr>
<td class="thead" colspan="2"><strong>{{ lang.filter_warning_logs }}</strong></td>
</tr>
<tr>
<td class="trow1" width="25%"><strong>{{ lang.filter_warned_user }}</strong></td>
<td class="trow1" width="75%"><input type="text" name="filter[username]" id="username" value="{{ select.username }}" class="textbox" /></td>
</tr>
<tr>
<td class="trow2" width="25%"><strong>{{ lang.filter_issued_by }}</strong></td>
<td class="trow2" width="75%"><input type="text" name="filter[mod_username]" value="{{ select.mod_username }}" class="textbox" /></td>
</tr>
<tr>
<td class="trow1" width="25%"><strong>{{ lang.filter_reason }}</strong></td>
<td class="trow1" width="75%"><input type="text" name="filter[reason]" value="{{ select.reason }}" class="textbox" /></td>
</tr>
<tr>
<td class="trow2" width="25%"><strong>{{ lang.sort_by }}</strong></td>
<td class="trow2" width="75%">
<select name="filter[sortby]">
<option value="username"{% if select.sortby.username %} selected="selected"{% endif %}>{{ lang.username }}</option>
<option value="issuedby"{% if select.sortby.issuedby %} selected="selected"{% endif %}>{{ lang.issued_by }}</option>
<option value="dateline"{% if select.sortby.dateline %} selected="selected"{% endif %}>{{ lang.issued_date }}</option>
<option value="expires"{% if select.sortby.expires %} selected="selected"{% endif %}>{{ lang.expiry_date }}</option>
</select>
{{ lang.in }}
<select name="filter[order]">
<option value="asc"{% if select.order.asc %} selected="selected"{% endif %}>{{ lang.asc }}</option>
<option value="desc"{% if select.order.desc %} selected="selected"{% endif %}>{{ lang.desc }}</option>
</select>
{{ lang.order }}
</td>
</tr>
<tr>
<td class="trow1" width="25%"><strong>{{ lang.per_page }}</strong></td>
<td class="trow1" width="75%"><input type="text" name="filter[per_page]" value="{{ select.per_page }}" class="textbox" /></td>
</tr>
</table>
<br />
<div align="center">
<input type="submit" class="button" value="{{ lang.filter_warning_logs }}" />
</div>
</form>
</td>
</tr>
</table>
<link rel="stylesheet" href="{{ asset_url('jscripts/select2/select2.css') }}">
<script type="text/javascript" src="{{ asset_url('jscripts/select2/select2.min.js') }}"></script>
<script type="text/javascript">
<!--
if({{ mybb.settings.use_xmlhttprequest }})
{
MyBB.select2();
$("#username").select2({
placeholder: "{{ lang.search_user }}",
minimumInputLength: 2,
multiple: false,
ajax: { // instead of writing the function to execute the request we use Select2's convenient helper
url: "xmlhttp.php?action=get_users",
dataType: 'json',
data: function (term, page) {
return {
query: term, // search term
};
},
results: function (data, page) { // parse the results into the format expected by Select2.
// since we are using custom formatting functions we do not need to alter remote JSON data
return {results: data};
}
},
initSelection: function(element, callback) {
var value = $(element).val();
if (value !== "") {
callback({
id: value,
text: value
});
}
},
});
}
// -->
</script>
{% endblock body %}
14 changes: 14 additions & 0 deletions inc/views/base/modcp/warninglogs/item.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% set row = alt_trow() %}
<tr>
<td class="{{ row }}">{{ warning.username_link|raw }}</td>
<td class="{{ row }}">{{ warning.title }} ({{ warning.points }})</td>
<td class="{{ row }}" align="center">{{ warning.issued_date }}</td>
<td class="{{ row }}" align="center">
{{ warning.expire_date }}
{% if warning.daterevoked %}
<br /><span class="smalltext"><strong>{{ lang.revoked }}</strong> {{ warning.revoked_date }}</span>
{% endif %}
</td>
<td class="{{ row }}">{{ warning.mod_username_link|raw }}</td>
<td class="{{ row }}" align="center"><a href="warnings.php?action=view&amp;wid={{ warning.wid }}">{{ lang.view }}</a></td>
</tr>
77 changes: 44 additions & 33 deletions modcp.php
Original file line number Diff line number Diff line change
Expand Up @@ -2690,6 +2690,7 @@
} else {
$mybb->input['filter']['username'] = '';
}

if (!empty($mybb->input['filter']['uid'])) {
$search['uid'] = (int)$mybb->input['filter']['uid'];
$where_sql .= " AND w.uid='{$search['uid']}'";
Expand All @@ -2700,6 +2701,7 @@
} else {
$mybb->input['filter']['uid'] = '';
}

if (!empty($mybb->input['filter']['mod_username'])) {
$mod_user = get_user_by_username($mybb->input['filter']['mod_username']);

Expand All @@ -2708,6 +2710,7 @@
} else {
$mybb->input['filter']['mod_username'] = '';
}

if (!empty($mybb->input['filter']['mod_uid'])) {
$search['mod_uid'] = (int)$mybb->input['filter']['mod_uid'];
$where_sql .= " AND w.issuedby='{$search['mod_uid']}'";
Expand All @@ -2718,44 +2721,46 @@
} else {
$mybb->input['filter']['mod_uid'] = '';
}

if (!empty($mybb->input['filter']['reason'])) {
$search['reason'] = $db->escape_string_like($mybb->input['filter']['reason']);
$where_sql .= " AND (w.notes LIKE '%{$search['reason']}%' OR t.title LIKE '%{$search['reason']}%' OR w.title LIKE '%{$search['reason']}%')";
$mybb->input['filter']['reason'] = htmlspecialchars_uni($mybb->input['filter']['reason']);
} else {
$mybb->input['filter']['reason'] = '';
}
$sortbysel = array('username' => '', 'expires' => '', 'issuedby' => '', 'dateline' => '');

$select['sortby'] = array('username' => false, 'expires' => false, 'issuedby' => false, 'dateline' => false);
if (!isset($mybb->input['filter']['sortby'])) {
$mybb->input['filter']['sortby'] = '';
}
switch ($mybb->input['filter']['sortby']) {
case "username":
$sortby = "u.username";
$sortbysel['username'] = ' selected="selected"';
$select['sortby']['username'] = true;
break;
case "expires":
$sortby = "w.expires";
$sortbysel['expires'] = ' selected="selected"';
$select['sortby']['expires'] = true;
break;
case "issuedby":
$sortby = "i.username";
$sortbysel['issuedby'] = ' selected="selected"';
$select['sortby']['issuedby'] = true;
break;
default: // "dateline"
$sortby = "w.dateline";
$sortbysel['dateline'] = ' selected="selected"';
$select['sortby']['dateline'] = true;
}

if (!isset($mybb->input['filter']['order'])) {
$mybb->input['filter']['order'] = '';
}
$order = $mybb->input['filter']['order'];
$ordersel = array('asc' => '', 'desc' => '');
$select['order'] = array('asc' => false, 'desc' => false);
if ($order != "asc") {
$order = "desc";
$ordersel['desc'] = ' selected="selected"';
$select['order']['desc'] = true;
} else {
$ordersel['asc'] = ' selected="selected"';
$select['order']['asc'] = true;
}

$plugins->run_hooks('modcp_warninglogs_start');
Expand Down Expand Up @@ -2788,9 +2793,11 @@
$url .= "&amp;filter[{$field}]={$value}";
}
}

$multipage = multipage($total_warnings, $per_page, $page, $url);

// The actual query
$warning_list = [];
$sql = "
SELECT
w.wid, w.title as custom_title, w.points, w.dateline, w.issuedby, w.expires, w.expired, w.daterevoked, w.revokedby,
Expand All @@ -2808,46 +2815,50 @@
";
$query = $db->query($sql);

$warning_list = '';
while ($row = $db->fetch_array($query)) {
$trow = alt_trow();
$row['username'] = htmlspecialchars_uni($row['username']);
$username = format_name($row['username'], $row['usergroup'], $row['displaygroup']);
$username_link = build_profile_link($username, $row['uid']);
$row['mod_username'] = htmlspecialchars_uni($row['mod_username']);
$row['username_link'] = build_profile_link($username, $row['uid']);

$mod_username = format_name($row['mod_username'], $row['mod_usergroup'], $row['mod_displaygroup']);
$mod_username_link = build_profile_link($mod_username, $row['mod_uid']);
$issued_date = my_date('normal', $row['dateline']);
$revoked_text = '';
$row['mod_username_link'] = build_profile_link($mod_username, $row['mod_uid']);

$row['issued_date'] = my_date('normal', $row['dateline']);

if ($row['daterevoked'] > 0) {
$revoked_date = my_date('relative', $row['daterevoked']);
eval("\$revoked_text = \"".$templates->get("modcp_warninglogs_warning_revoked")."\";");
$row['revoked_date'] = my_date('relative', $row['daterevoked']);
}
if ($row['expires'] > 0) {
$expire_date = nice_time($row['expires']-TIME_NOW);

if ($row['expired'] == 1) {
$row['expire_date'] = $lang->expired;
} elseif ($row['expires'] > 0) {
$row['expire_date'] = nice_time($row['expires']-TIME_NOW);
} else {
$expire_date = $lang->never;
$row['expire_date'] = $lang->never;
}
$title = $row['title'];

if (empty($row['title'])) {
$title = $row['custom_title'];
$row['title'] = $row['custom_title'];
}
$title = htmlspecialchars_uni($title);

if ($row['points'] >= 0) {
$points = '+'.$row['points'];
$row['points'] = '+'.$row['points'];
}

eval("\$warning_list .= \"".$templates->get("modcp_warninglogs_warning")."\";");
}

if (!$warning_list) {
eval("\$warning_list = \"".$templates->get("modcp_warninglogs_nologs")."\";");
$warning_list[] = $row;
}

$plugins->run_hooks('modcp_warninglogs_end');

eval("\$warninglogs = \"".$templates->get("modcp_warninglogs")."\";");
output_page($warninglogs);
$select['username'] = $mybb->input['filter']['username'];
$select['mod_username'] = $mybb->input['filter']['mod_username'];
$select['reason'] = $mybb->input['filter']['reason'];
$select['per_page'] = $per_page;

output_page(\MyBB\template('modcp/warninglogs.twig', [
'multipage' => $multipage,
'select' => $select,
'warning_list' => $warning_list,
]));
}

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

0 comments on commit 8b6b055

Please sign in to comment.