* check if plugin exist before uninstalling

* fixed some bug when you uninstall and then try to install again on the same page
* moved some characters.frags code to twig template
This commit is contained in:
slawkens 2017-10-11 15:24:54 +02:00
parent 005356ebb3
commit 6c3439acf9
5 changed files with 42 additions and 37 deletions

View File

@ -40,25 +40,31 @@ function deleteDirectory($dir) {
if(isset($_REQUEST['uninstall'])){ if(isset($_REQUEST['uninstall'])){
$uninstall = $_REQUEST['uninstall']; $uninstall = $_REQUEST['uninstall'];
$string = file_get_contents(BASE . 'plugins/' . $uninstall . '.json'); $filename = BASE . 'plugins/' . $uninstall . '.json';
$plugin_info = json_decode($string, true); if(!file_exists($filename)) {
if($plugin_info == false) { error('Plugin ' . $uninstall . ' does not exist.');
warning('Cannot load plugin info ' . $uninstall . '.json');
} }
else { else {
$success = true; $string = file_get_contents($filename);
foreach($plugin_info['uninstall'] as $file) { $plugin_info = json_decode($string, true);
$file = BASE . $file; if($plugin_info == false) {
if(!deleteDirectory($file)) { warning('Cannot load plugin info ' . $uninstall . '.json');
$success = false;
}
}
if($success) {
success('Successfully uninstalled plugin ' . $uninstall);
} }
else { else {
error('Error while uninstalling plugin ' . $uninstall . ': ' . error_get_last()); $success = true;
foreach($plugin_info['uninstall'] as $file) {
$file = BASE . $file;
if(!deleteDirectory($file)) {
$success = false;
}
}
if($success) {
success('Successfully uninstalled plugin ' . $uninstall);
}
else {
error('Error while uninstalling plugin ' . $uninstall . ': ' . error_get_last());
}
} }
} }
} }

View File

@ -335,8 +335,7 @@ WHERE killers.death_id = '".$death['id']."' ORDER BY killers.final_hit DESC, kil
foreach($player_frags as $frag) foreach($player_frags as $frag)
{ {
$description = 'Fragged <a href="' . getPlayerLink($frag[name], false) . '">' . $frag[name] . '</a> at level ' . $frag[level]; $description = 'Fragged <a href="' . getPlayerLink($frag[name], false) . '">' . $frag[name] . '</a> at level ' . $frag[level];
$description .= '. ('.(($frag['unjustified'] == 0) ? '<font size="1" color="green">Justified</font>' : '<font size="1" color="red">Unjustified</font>').')'; $frags[] = array('time' => $frag['date'], 'description' => $description, 'unjustified' => $frag['unjustified'] != 0);
$frags[] = array('time' => $frag['date'], 'description' => $description);
} }
} }
} }

View File

@ -1,4 +1,4 @@
<form enctype="multipart/form-data" method="post"> <form enctype="multipart/form-data" method="post" action="{{ constant('ADMIN_URL') }}?p=plugins">
<input type="hidden" name="upload_plugin" /> <input type="hidden" name="upload_plugin" />
<table cellspacing="3" border="0"> <table cellspacing="3" border="0">
<tr> <tr>

View File

@ -242,7 +242,7 @@
{% for frag in frags %} {% for frag in frags %}
<tr bgcolor="'{{ getStyle(i) }}"> <tr bgcolor="'{{ getStyle(i) }}">
<td width="20%" align="center">{{ frag.time|date("j M Y, H:i") }}</td> <td width="20%" align="center">{{ frag.time|date("j M Y, H:i") }}</td>
<td>{{ frag.description }}</td> <td>{{ frag.description }}({% if frag.unjustified %}<font size="1" color="red">Unjustified</font>{% else %}<font size="1" color="green">Justified</font>{% endif %})</td>
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>

View File

@ -1,21 +1,21 @@
<table border="0" cellspacing="1" cellpadding="4" width="100%"> <table border="0" cellspacing="1" cellpadding="4" width="100%">
<tr bgcolor="{{ config.vdarkborder }}"> <tr bgcolor="{{ config.vdarkborder }}">
<td colspan="3" class="white"><b>News archive</b></td> <td colspan="3" class="white"><b>News archive</b></td>
</tr> </tr>
{% set i = 0 %} {% set i = 0 %}
{% for news in newses %} {% for news in newses %}
{% set i = i + 1 %} {% set i = i + 1 %}
<tr bgcolor="{{ getStyle(i) }}"> <tr bgcolor="{{ getStyle(i) }}">
<td width=4%> <td width=4%>
<center> <center>
<img src="{{ template_path }}/images/news/icon_{{ news.icon_id }}_small.gif"/> <img src="{{ template_path }}/images/news/icon_{{ news.icon_id }}_small.gif"/>
</center> </center>
</td> </td>
<td>{{ news.date|date('j.n.Y') }}</td> <td>{{ news.date|date('j.n.Y') }}</td>
<td> <td>
<b><a href="{{ news.link }}">{{ news.title }}</a></b> <b><a href="{{ news.link }}">{{ news.title }}</a></b>
</td> </td>
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>