Godleydemon

addon Infractions

Dec 31st, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 36.83 KB | None | 0 0
  1. <?php
  2. /*
  3.  *  Made by Samerton
  4.  *  http://worldscapemc.co.uk
  5.  *
  6.  *  License: MIT
  7.  *  Copyright (c) 2016 Samerton
  8.  */
  9.  
  10. // Infractions class
  11.  
  12. class Infractions {
  13.     private $_db,
  14.             $_data,
  15.             $_language,
  16.             $_prefix;
  17.  
  18.     // Connect to database
  19.  
  20.     public function __construct($inf_db, $language) {
  21.         $this->_db = DB_Custom::getInstance($inf_db['address'], $inf_db['name'], $inf_db['username'], $inf_db['password']);
  22.         $this->_prefix = $inf_db['prefix'];
  23.         $this->_language = $language;
  24.     }
  25.    
  26.     // Receive a list of all infractions for BungeeAdminTools, either for a single user or for all users
  27.     // Params: $uuid (string), UUID of a user. If null, will list all infractions
  28.     public function bat_getAllInfractions($uuid = null) {
  29.         if($uuid !== null){
  30.             $field = "uuid";
  31.             $symbol = "=";
  32.             $equals = $uuid;
  33.         } else {
  34.             $field = "uuid";
  35.             $symbol = "<>";
  36.             $equals = "0";
  37.         }
  38.         $bans = $this->_db->get($this->_prefix . 'ban', array($field, $symbol, $equals))->results();
  39.         $kicks = $this->_db->get($this->_prefix . 'kick', array($field, $symbol, $equals))->results();
  40.         $mutes = $this->_db->get($this->_prefix . 'mute', array($field, $symbol, $equals))->results();
  41.        
  42.         $results = array();
  43.         $i = 0;
  44.        
  45.         foreach($bans as $ban){
  46.             $results[$i]["id"] = $ban->ban_id;
  47.             $results[$i]["uuid"] = $ban->UUID;
  48.             $results[$i]["staff"] = htmlspecialchars($ban->ban_staff);
  49.             $results[$i]["issued"] = strtotime($ban->ban_begin);
  50.             $results[$i]["issued_human"] = date("jS M Y, H:i", strtotime($ban->ban_begin));
  51.             if($ban->ban_reason !== null){
  52.                 $results[$i]["reason"] = htmlspecialchars($ban->ban_reason);
  53.             } else {
  54.                 $results[$i]["reason"] = "-";
  55.             }
  56.             if($ban->ban_unbandate !== null){
  57.                 $results[$i]["unbanned"] = "true";
  58.                 $results[$i]["unbanned_by"] = htmlspecialchars($ban->ban_unbanstaff);
  59.                 $results[$i]["unbanned_date"] = htmlspecialchars($ban->ban_unbandate);
  60.                 if($ban->ban_unbanreason !== "noreason"){
  61.                     $results[$i]["unbanned_reason"] = htmlspecialchars($ban->ban_unbanreason);
  62.                 }
  63.             }
  64.             if($ban->ban_end !== null){
  65.                 $results[$i]["type"] = "temp_ban";
  66.                 $results[$i]["type_human"] = '<span class="label label-danger">' . $this->_language['temp_ban'] . '</span>';
  67.                 if($ban->ban_state == 0){
  68.                     $results[$i]["expires"] = strtotime($ban->ban_end);
  69.                     $results[$i]["expires_human"] = '<span class="label label-success" rel="tooltip" data-trigger="hover" data-original-title="' . str_replace('{x}', date("jS M Y", strtotime($ban->ban_end)), $this->_language['expired_x']) . '">' . $this->_language['expired'] . '</span>';
  70.                 } else {
  71.                     $results[$i]["expires"] = strtotime($ban->ban_end);
  72.                     $results[$i]["expires_human"] = '<span class="label label-danger" rel="tooltip" data-trigger="hover" data-original-title="' . str_replace('{x}', date("jS M Y", strtotime($ban->ban_end)), $this->_language['expires_x']) . '">' . $this->_language['active'] . '</span>';
  73.                 }
  74.             } else {
  75.                 $results[$i]["type"] = "ban";
  76.                 $results[$i]["type_human"] = '<span class="label label-danger">' . $this->_language['ban'] . '</span>';
  77.                 if($ban->ban_unbandate !== null){
  78.                     $results[$i]["expires_human"] = '<span class="label label-success">' . $this->_language['revoked'] .'</span>';
  79.                 } else {
  80.                     $results[$i]["expires_human"] = '<span class="label label-danger">' . $this->_language['permanent'] . '</span>';
  81.                 }
  82.             }
  83.             $i++;
  84.         }
  85.        
  86.         foreach($kicks as $kick){
  87.             $results[$i]["id"] = $kick->kick_id;
  88.             $results[$i]["uuid"] = $kick->UUID;
  89.             $results[$i]["staff"] = htmlspecialchars($kick->kick_staff);
  90.             $results[$i]["issued"] = strtotime($kick->kick_date);
  91.             $results[$i]["issued_human"] = date("jS M Y, H:i", strtotime($kick->kick_date));
  92.             $results[$i]["reason"] = htmlspecialchars($kick->kick_reason);
  93.             $results[$i]["type"] = "kick";
  94.             $results[$i]["type_human"] = '<span class="label label-primary">' . $this->_language['kick'] . '</span>';
  95.             $results[$i]["expires_human"] = '';
  96.             $i++;
  97.         }
  98.        
  99.         foreach($mutes as $mute){
  100.             $results[$i]["id"] = $mute->mute_id;
  101.             $results[$i]["uuid"] = $mute->UUID;
  102.             $results[$i]["staff"] = htmlspecialchars($mute->mute_staff);
  103.             $results[$i]["issued"] = strtotime($mute->mute_begin);
  104.             $results[$i]["issued_human"] = date("jS M Y, H:i", strtotime($mute->mute_begin));
  105.             if($mute->mute_reason !== null){
  106.                 $results[$i]["reason"] = htmlspecialchars($mute->mute_reason);
  107.             } else {
  108.                 $results[$i]["reason"] = "-";
  109.             }
  110.             $results[$i]["type"] = "mute";
  111.             $results[$i]["type_human"] = '<span class="label label-warning">' . $this->_language['mute'] . '</span>';
  112.             if($mute->mute_unmutedate !== null){
  113.                 $results[$i]["unmuted"] = "true";
  114.                 $results[$i]["unmuted_by"] = htmlspecialchars($mute->mute_unmutestaff);
  115.                 $results[$i]["unmuted_date"] = htmlspecialchars($mute->mute_unmutedate);
  116.                 if($mute->mute_unmutereason !== "noreason"){
  117.                     $results[$i]["unmuted_reason"] = htmlspecialchars($mute->mute_unmutereason);
  118.                 }
  119.             }
  120.             if($mute->mute_end !== null){
  121.                 if($mute->mute_state == 0){
  122.                     $results[$i]["expires"] = strtotime($mute->mute_end);
  123.                     $results[$i]["expires_human"] = '<span class="label label-success" rel="tooltip" data-trigger="hover" data-original-title="' . str_replace('{x}', date("jS M Y", strtotime($mute->mute_end)), $this->_language['expired_x']) . '">' . $this->_language['expired'] . '</span>';
  124.                 } else {
  125.                     $results[$i]["expires"] = strtotime($mute->mute_end);
  126.                     $results[$i]["expires_human"] = '<span class="label label-danger" rel="tooltip" data-trigger="hover" data-original-title="' . str_replace('{x}', date("jS M Y", strtotime($mute->mute_end)), $this->_language['expires_x']) . '">' . $this->_language['active'] . '</span>';
  127.                 }
  128.             } else {
  129.                 if($mute->mute_unmutedate !== null){
  130.                     $results[$i]["expires_human"] = '<span class="label label-success">' . $this->_language['revoked'] .'</span>';
  131.                 } else {
  132.                     $results[$i]["expires_human"] = '<span class="label label-danger">' . $this->_language['permanent'] . '</span>';
  133.                 }
  134.             }
  135.             $i++;
  136.         }
  137.        
  138.         // Sort by date
  139.         function date_compare($a, $b)
  140.         {
  141.             $t1 = $a['issued'];
  142.             $t2 = $b['issued'];
  143.             return $t2 - $t1;
  144.         }    
  145.         usort($results, 'date_compare');
  146.         return $results;
  147.     }
  148.    
  149.     // Receive an object containing infraction information for a specified infraction ID and type (BungeeAdminTools)
  150.     // Params: $type (string), either ban, kick or mute; $id (int), ID of infraction
  151.     public function bat_getInfraction($type, $id) {
  152.         if($type === "ban" || $type === "temp_ban"){
  153.             $result = $this->_db->get($this->_prefix . 'ban', array("ban_id", "=", $id))->results();
  154.             return $result;
  155.         } else if($type === "kick"){
  156.             $result = $this->_db->get($this->_prefix . 'kick', array("kick_id", "=", $id))->results();
  157.             return $result;
  158.         } else if($type === "mute"){
  159.             $result = $this->_db->get($this->_prefix . 'mute', array("mute_id", "=", $id))->results();
  160.             return $result;
  161.         }
  162.         return false;
  163.     }
  164.    
  165.     // Get a username from a UUID
  166.     // Params: $uuid (string) - UUID of user
  167.     public function bat_getUsernameFromUUID($uuid){
  168.         // Query database
  169.         $results = $this->_db->get($this->_prefix . 'players', array('uuid', '=', $uuid))->results();
  170.         return $results;
  171.     }
  172.  
  173.     // Receive a list of all infractions for Ban Management, either for a single user or for all users
  174.     // Params: $uuid (string), UUID of a user. If null, will list all infractions
  175.     public function bm_getAllInfractions($uuid = null) {
  176.         // First, we need to get the player ID (if specified)
  177.         if($uuid !== null){
  178.             $field = "player_id";
  179.             $symbol = "=";
  180.             $equals = pack("H*", str_replace('-', '', $uuid));
  181.         } else {
  182.             $field = "player_id";
  183.             $symbol = "<>";
  184.             $equals = "0";
  185.         }
  186.         $bans = $this->_db->get($this->_prefix . 'player_bans', array($field, $symbol, $equals))->results();
  187.         $kicks = $this->_db->get($this->_prefix . 'player_kicks', array($field, $symbol, $equals))->results();
  188.         $mutes = $this->_db->get($this->_prefix . 'player_mutes', array($field, $symbol, $equals))->results();
  189.         $warnings = $this->_db->get($this->_prefix . 'player_warnings', array($field, $symbol, $equals))->results();
  190.        
  191.         $results = array();
  192.         $i = 0;
  193.        
  194.         // Bans - first, current bans
  195.         foreach($bans as $ban){
  196.             $results[$i]["id"] = $ban->id;
  197.             $results[$i]["uuid"] = bin2hex($ban->player_id);
  198.            
  199.             // Console or a player?
  200.             if(bin2hex($ban->actor_id) == '2b28d0bed7484b93968e8f4ab16999b3'){
  201.                 $results[$i]["staff"] = 'Console';
  202.             } else {
  203.                 // We need to get the player's username first
  204.                 $username = $this->_db->get($this->_prefix . 'players', array('id', '=', $ban->actor_id))->results();
  205.                 $username = htmlspecialchars($username[0]->name);
  206.                 $results[$i]["staff"] = $username;
  207.             }
  208.            
  209.             $results[$i]["issued"] = $ban->created;
  210.             $results[$i]["issued_human"] = date("jS M Y, H:i", $ban->created);
  211.            
  212.             // Is a reason set?
  213.             if($ban->reason !== null){
  214.                 $results[$i]["reason"] = htmlspecialchars($ban->reason);
  215.             } else {
  216.                 $results[$i]["reason"] = "-";
  217.             }
  218.            
  219.             // Is it a temp-ban?
  220.             if($ban->expires != 0){
  221.                 $results[$i]["type"] = "temp_ban";
  222.                 $results[$i]["type_human"] = "<span class=\"label label-danger\">" . $this->_language['temp_ban'] . "</span>";
  223.                 $results[$i]["expires_human"] = "<span class=\"label label-success\" rel=\"tooltip\" data-trigger=\"hover\" data-original-title=\"" . str_replace('{x}', date("jS M Y", $ban->expires), $this->_language['expires_x']) . "\">" . $this->_language['active'] . "</span>";
  224.                 $results[$i]["expires"] = $ban->expires;
  225.             } else {
  226.                 $results[$i]["type"] = "ban";
  227.                 $results[$i]["type_human"] = "<span class=\"label label-danger\">" . $this->_language['ban'] . "</span>";
  228.                 $results[$i]["expires_human"] = "<span class=\"label label-danger\">" . $this->_language['permanent'] . "</span>";
  229.             }
  230.             $i++;
  231.         }
  232.         // Bans - next, previous bans
  233.         $bans = $this->_db->get($this->_prefix . 'player_ban_records', array($field, $symbol, $equals))->results();
  234.         foreach($bans as $ban){
  235.             $results[$i]["id"] = $ban->id;
  236.             $results[$i]["uuid"] = bin2hex($ban->player_id);
  237.             $results[$i]['past'] = true;
  238.            
  239.             // Console or a player?
  240.             if(bin2hex($ban->pastActor_id) == '2b28d0bed7484b93968e8f4ab16999b3'){
  241.                 $results[$i]["staff"] = 'Console';
  242.             } else {
  243.                 // We need to get the player's username first
  244.                 $username = $this->_db->get($this->_prefix . 'players', array('id', '=', $ban->pastActor_id))->results();
  245.                 $username = htmlspecialchars($username[0]->name);
  246.                 $results[$i]["staff"] = $username;
  247.             }
  248.            
  249.             $results[$i]["issued"] = $ban->pastCreated;
  250.             $results[$i]["issued_human"] = date("jS M Y, H:i", $ban->pastCreated);
  251.            
  252.             // Is a reason set?
  253.             if($ban->reason !== null){
  254.                 $results[$i]["reason"] = htmlspecialchars($ban->reason);
  255.             } else {
  256.                 $results[$i]["reason"] = "-";
  257.             }
  258.            
  259.             // Was it a temp-ban?
  260.             if($ban->expired != 0){
  261.                 $results[$i]["type"] = "temp_ban";
  262.                 $results[$i]["type_human"] = "<span class=\"label label-danger\">" . $this->_language['temp_ban'] . "</span>";
  263.                 $results[$i]["expires"] = strtotime($ban->expired);
  264.                 $results[$i]["expires_human"] = "<span class=\"label label-success\" rel=\"tooltip\" data-trigger=\"hover\" data-original-title=\"" . str_replace('{x}', date("jS M Y", $ban->expired), $this->_language['expired_x']) . "\">" . $this->_language['expired'] . "</span>";
  265.             } else {
  266.                 $results[$i]["type"] = "ban";
  267.                 $results[$i]["type_human"] = "<span class=\"label label-danger\">" . $this->_language['ban'] . "</span>";
  268.                 $results[$i]["expires_human"] = "<span class=\"label label-success\">" . $this->_language['revoked'] . "</span>";
  269.             }
  270.             $i++;
  271.         }
  272.        
  273.         // Kicks
  274.         foreach($kicks as $kick){
  275.             $results[$i]["id"] = $kick->id;
  276.             $results[$i]["uuid"] = bin2hex($kick->player_id);
  277.            
  278.             // Console or a player?
  279.             if(bin2hex($kick->actor_id) == '2b28d0bed7484b93968e8f4ab16999b3'){
  280.                 $results[$i]["staff"] = 'Console';
  281.             } else {
  282.                 // We need to get the player's username first
  283.                 $username = $this->_db->get($this->_prefix . 'players', array('id', '=', $kick->actor_id))->results();
  284.                 $username = htmlspecialchars($username[0]->name);
  285.                 $results[$i]["staff"] = $username;
  286.             }
  287.            
  288.             $results[$i]["issued"] = $kick->created;
  289.             $results[$i]["issued_human"] = date("jS M Y, H:i", $kick->created);
  290.             $results[$i]["reason"] = htmlspecialchars($kick->reason);
  291.             $results[$i]["type"] = "kick";
  292.             $results[$i]["type_human"] = "<span class=\"label label-primary\">" . $this->_language['kick'] . "</span>";
  293.             $results[$i]["expires_human"] = '';
  294.             $i++;
  295.         }
  296.        
  297.         // Mutes - first, current mutes
  298.         foreach($mutes as $mute){
  299.             $results[$i]["id"] = $mute->id;
  300.             $results[$i]["uuid"] = bin2hex($mute->player_id);
  301.            
  302.             // Console or a player?
  303.             if(bin2hex($mute->actor_id) == '2b28d0bed7484b93968e8f4ab16999b3'){
  304.                 $results[$i]["staff"] = 'Console';
  305.             } else {
  306.                 // We need to get the player's username first
  307.                 $username = $this->_db->get($this->_prefix . 'players', array('id', '=', $mute->actor_id))->results();
  308.                 $username = htmlspecialchars($username[0]->name);
  309.                 $results[$i]["staff"] = $username;
  310.             }
  311.            
  312.             $results[$i]["issued"] = $mute->created;
  313.             $results[$i]["issued_human"] = date("jS M Y, H:i", $mute->created);
  314.            
  315.             // Is a reason set?
  316.             if($mute->reason !== null){
  317.                 $results[$i]["reason"] = htmlspecialchars($mute->reason);
  318.             } else {
  319.                 $results[$i]["reason"] = "-";
  320.             }
  321.            
  322.             $results[$i]["type"] = "mute";
  323.             $results[$i]["type_human"] = "<span class=\"label label-warning\">" . $this->_language['mute'] . "</span>";
  324.            
  325.             // Is it a temp mute?
  326.             if($mute->expires != 0){
  327.                 $results[$i]["expires_human"] = "<span class=\"label label-success\" rel=\"tooltip\" data-trigger=\"hover\" data-original-title=\"" . str_replace('{x}', date("jS M Y", $mute->expires), $this->_language['expires_x']) . "\">" . $this->_language['active'] . "</span>";
  328.                 $results[$i]["expires"] = $mute->expires;
  329.             } else {
  330.                 $results[$i]["expires_human"] = "<span class=\"label label-danger\">" . $this->_language['permanent'] . "</span>";
  331.             }
  332.  
  333.             $i++;
  334.         }
  335.        
  336.         // Mutes - next, previous mutes
  337.         $mutes = $this->_db->get($this->_prefix . 'player_mute_records', array($field, $symbol, $equals))->results();
  338.         foreach($mutes as $mute){
  339.             $results[$i]["id"] = $mute->id;
  340.             $results[$i]["uuid"] = bin2hex($mute->player_id);
  341.             $results[$i]['past'] = true;
  342.            
  343.             // Console or a player?
  344.             if(bin2hex($mute->pastActor_id) == '2b28d0bed7484b93968e8f4ab16999b3'){
  345.                 $results[$i]["staff"] = 'Console';
  346.             } else {
  347.                 // We need to get the player's username first
  348.                 $username = $this->_db->get($this->_prefix . 'players', array('id', '=', $mute->pastActor_id))->results();
  349.                 $username = htmlspecialchars($username[0]->name);
  350.                 $results[$i]["staff"] = $username;
  351.             }
  352.            
  353.             $results[$i]["issued"] = $mute->pastCreated;
  354.             $results[$i]["issued_human"] = date("jS M Y, H:i", $mute->pastCreated);
  355.            
  356.             // Is a reason set?
  357.             if($mute->reason !== null){
  358.                 $results[$i]["reason"] = htmlspecialchars($mute->reason);
  359.             } else {
  360.                 $results[$i]["reason"] = "-";
  361.             }
  362.            
  363.             $results[$i]["type"] = "mute";
  364.             $results[$i]["type_human"] = "<span class=\"label label-warning\">" . $this->_language['mute'] . "</span>";
  365.            
  366.             // Was it a temp-ban?
  367.             if($mute->expired != 0){
  368.                 $results[$i]["expires"] = strtotime($mute->expired);
  369.                 $results[$i]["expires_human"] = "<span class=\"label label-success\" rel=\"tooltip\" data-trigger=\"hover\" data-original-title=\"" . str_replace('{x}', date("jS M Y", $mute->expired), $this->_language['expired_x']) . "\">" . $this->_language['expired'] . "</span>";
  370.             } else {
  371.                 $results[$i]["type_human"] = "<span class=\"label label-danger\">" . $this->_language['mute'] . "</span>";
  372.                 $results[$i]["expires_human"] = "<span class=\"label label-success\">" . $this->_language['revoked'] . "</span>";
  373.             }
  374.             $i++;
  375.         }
  376.        
  377.         // Warnings
  378.         foreach($warnings as $warning){
  379.             $results[$i]["id"] = $warning->id;
  380.             $results[$i]["uuid"] = bin2hex($warning->player_id);
  381.            
  382.             // Console or a player?
  383.             if(bin2hex($warning->actor_id) == '2b28d0bed7484b93968e8f4ab16999b3'){
  384.                 $results[$i]["staff"] = 'Console';
  385.             } else {
  386.                 // We need to get the player's username first
  387.                 $username = $this->_db->get('bm_players', array('id', '=', $warning->actor_id))->results();
  388.                 $username = htmlspecialchars($username[0]->name);
  389.                 $results[$i]["staff"] = $username;
  390.             }
  391.            
  392.             $results[$i]["issued"] = $warning->created;
  393.             $results[$i]["issued_human"] = date("jS M Y, H:i", $warning->created);
  394.             $results[$i]["reason"] = htmlspecialchars($warning->reason);
  395.             $results[$i]["type"] = "warning";
  396.             $results[$i]["type_human"] = "<span class=\"label label-info\">" . $this->_language['warning'] . "</span>";
  397.             $results[$i]["expires_human"] = '';
  398.             $i++;
  399.         }
  400.  
  401.         // Order by date, most recent first
  402.         function date_compare($a, $b){
  403.             $t1 = $a['issued'];
  404.             $t2 = $b['issued'];
  405.             return $t2 - $t1;
  406.         }    
  407.         usort($results, 'date_compare');
  408.         return $results;
  409.     }
  410.    
  411.     // Receive an object containing infraction information for a specified infraction ID and type (Ban Management)
  412.     // Params: $type (string), either ban, kick or mute; $id (int), ID of infraction
  413.     public function bm_getInfraction($type, $id, $past = false) {
  414.         if($type === "ban" || $type === "temp_ban"){
  415.             if(!$past) $result = $this->_db->get($this->_prefix . 'player_bans', array("id", "=", $id))->results();
  416.             else $result = $this->_db->get($this->_prefix . 'player_ban_records', array("id", "=", $id))->results();
  417.             return $result;
  418.         } else if($type === "kick"){
  419.             $result = $this->_db->get($this->_prefix . 'player_kicks', array("id", "=", $id))->results();
  420.             return $result;
  421.         } else if($type === "mute"){
  422.             if(!$past) $result = $this->_db->get($this->_prefix . 'player_mutes', array("id", "=", $id))->results();
  423.             else $result = $this->_db->get($this->_prefix . 'player_mute_records', array("id", "=", $id))->results();
  424.             return $result;
  425.         } else if($type === "warning"){
  426.             $result = $this->_db->get($this->_prefix . 'player_warnings', array("id", "=", $id))->results();
  427.             return $result;
  428.         }
  429.         return false;
  430.     }
  431.    
  432.     // Receive the username from an ID (Ban Management)
  433.     // Params: $id (string (binary)), player_id of user to lookup
  434.     public function bm_getUsernameFromID($id) {
  435.         $result = $this->_db->get($this->_prefix . 'players', array('id', '=', $id))->results();
  436.         if(count($result)){
  437.             return htmlspecialchars($result[0]->name);
  438.         }
  439.         return false;
  440.     }
  441.    
  442.     // Receive a list of all infractions for LiteBans, either for a single user or for all users
  443.     // Params: $uuid (string), UUID of a user. If null, will list all infractions
  444.     public function lb_getAllInfractions($uuid = null) {
  445.         if($uuid !== null){
  446.             $field = "uuid";
  447.             $symbol = "=";
  448.             $equals = $uuid;
  449.         } else {
  450.             $field = "uuid";
  451.             $symbol = "<>";
  452.             $equals = "0";
  453.         }
  454.  
  455.         $bans = $this->_db->get($this->_prefix . 'bans', array($field, $symbol, $equals))->results();
  456.         $kicks = $this->_db->get($this->_prefix . 'kicks', array($field, $symbol, $equals))->results();
  457.         $mutes = $this->_db->get($this->_prefix . 'mutes', array($field, $symbol, $equals))->results();
  458.         $warnings = $this->_db->get($this->_prefix . 'warnings', array($field, $symbol, $equals))->results();
  459.        
  460.         $results = array();
  461.         $i = 0;
  462.  
  463.         // Bans
  464.         foreach($bans as $ban){
  465.             $username = $this->_db->get($this->_prefix . 'history', array('uuid', '=', htmlspecialchars($ban->uuid)))->results();
  466.            
  467.             if(count($username) > 1){
  468.                 // get most recent name
  469.                 usort($username, function($a, $b) {
  470.                     return strtotime($b->date) - strtotime($a->date);
  471.                 });
  472.             }
  473.             if(count($username)) $username = $username[0]->name; else $username = 'Unknown';
  474.  
  475.             $results[$i]["username"] = htmlspecialchars($username);
  476.             $results[$i]["id"] = $ban->id;
  477.             $results[$i]["staff"] = htmlspecialchars($ban->banned_by_name);
  478.            
  479.             $results[$i]["issued"] = $ban->time / 1000;
  480.             $results[$i]["issued_human"] = date("jS M Y, H:i", $ban->time / 1000);
  481.            
  482.             // Is a reason set?
  483.             if($ban->reason !== null){
  484.                 $results[$i]["reason"] = htmlspecialchars($ban->reason);
  485.             } else {
  486.                 $results[$i]["reason"] = "-";
  487.             }
  488.            
  489.             // Is it a temp-ban?
  490.             if($ban->until != -1){
  491.                 $results[$i]["type"] = "temp_ban";
  492.                 $results[$i]["type_human"] = "<span class=\"label label-danger\">" . $this->_language['temp_ban'] . "</span>";
  493.                 if($ban->active == 0x01){
  494.                     $results[$i]["expires_human"] = "<span class=\"label label-success\" rel=\"tooltip\" data-trigger=\"hover\" data-original-title=\"" . str_replace('{x}', date("jS M Y", $ban->until / 1000), $this->_language['expires_x']) . "\">" . $this->_language['active'] . "</span>";
  495.                     $results[$i]["expires"] = $ban->until / 1000;
  496.                 } else {
  497.                     $results[$i]["expires_human"] = "<span class=\"label label-info\" rel=\"tooltip\" data-trigger=\"hover\" data-original-title=\"" . str_replace('{x}', date("jS M Y", $ban->until / 1000), $this->_language['expired_x']) . "\">" . $this->_language['expired'] . "</span>";
  498.                     $results[$i]["expires"] = $ban->until / 1000;
  499.                 }
  500.             } else {
  501.                 $results[$i]["type"] = "ban";
  502.                 $results[$i]["type_human"] = "<span class=\"label label-danger\">" . $this->_language['ban'] . "</span>";
  503.  
  504.                 if($ban->active == null){
  505.                     // Active
  506.                     $results[$i]["expires_human"] = "<span class=\"label label-danger\">" . $this->_language['permanent'] ."</span>";
  507.                 } else {
  508.                     if($ban->active == 0x01){
  509.                         $results[$i]["expires_human"] = "<span class=\"label label-danger\">" . $this->_language['permanent'] ."</span>";
  510.                     } else {
  511.                         $results[$i]["expires_human"] = "<span class=\"label label-success\">" . $this->_language['revoked'] ."</span>";   
  512.                     }
  513.                 }
  514.             }
  515.             $i++;
  516.         }
  517.        
  518.         // Mutes
  519.         foreach($mutes as $mute){
  520.             $username = $this->_db->get($this->_prefix . 'history', array('uuid', '=', htmlspecialchars($mute->uuid)))->results();
  521.  
  522.             if(count($username) > 1){
  523.                 // get most recent name
  524.                 usort($username, function($a, $b) {
  525.                     return strtotime($b->date) - strtotime($a->date);
  526.                 });
  527.             }
  528.             if(count($username)) $username = $username[0]->name; else $username = 'Unknown';
  529.            
  530.             $results[$i]["username"] = htmlspecialchars($username);
  531.             $results[$i]["id"] = $mute->id;
  532.             $results[$i]["staff"] = htmlspecialchars($mute->banned_by_name);
  533.            
  534.             $results[$i]["issued"] = $mute->time / 1000;
  535.             $results[$i]["issued_human"] = date("jS M Y, H:i", $mute->time / 1000);
  536.            
  537.             // Is a reason set?
  538.             if($mute->reason !== null){
  539.                 $results[$i]["reason"] = htmlspecialchars($mute->reason);
  540.             } else {
  541.                 $results[$i]["reason"] = "-";
  542.             }
  543.            
  544.             $results[$i]["type"] = "mute";
  545.             $results[$i]["type_human"] = "<span class=\"label label-warning\">" . $this->_language['mute'] . "</span>";
  546.            
  547.             // Is it a temp-mute?
  548.             if($mute->until != -1){
  549.                 if($mute->active == 0x01){
  550.                     $results[$i]["expires_human"] = "<span class=\"label label-success\" rel=\"tooltip\" data-trigger=\"hover\" data-original-title=\"" . str_replace('{x}', date("jS M Y", $mute->until / 1000), $this->_language['expires_x']) . "\">" . $this->_language['active'] . "</span>";
  551.                     $results[$i]["expires"] = $mute->until / 1000;
  552.                 } else {
  553.                     $results[$i]["expires_human"] = "<span class=\"label label-info\" rel=\"tooltip\" data-trigger=\"hover\" data-original-title=\"" . str_replace('{x}', date("jS M Y", $mute->until / 1000), $this->_language['expired_x']) . "\">" . $this->_language['expired'] . "</span>";
  554.                     $results[$i]["expires"] = $mute->until / 1000;
  555.                 }
  556.             } else {
  557.                 if($mute->active == null){
  558.                     // Active
  559.                     $results[$i]["expires_human"] = "<span class=\"label label-danger\">" . $this->_language['permanent'] ."</span>";
  560.                 } else {
  561.                     if($mute->active == 0x01){
  562.                         $results[$i]["expires_human"] = "<span class=\"label label-danger\">" . $this->_language['permanent'] ."</span>";
  563.                     } else {
  564.                         $results[$i]["expires_human"] = "<span class=\"label label-success\">" . $this->_language['revoked'] ."</span>";   
  565.                     }
  566.                 }
  567.             }
  568.             $i++;
  569.         }
  570.        
  571.         // Warnings
  572.         foreach($warnings as $warning){
  573.             $username = $this->_db->get($this->_prefix . 'history', array('uuid', '=', htmlspecialchars($warning->uuid)))->results();
  574.  
  575.             if(count($username) > 1){
  576.                 // get most recent name
  577.                 usort($username, function($a, $b) {
  578.                     return strtotime($b->date) - strtotime($a->date);
  579.                 });
  580.             }
  581.             if(count($username)) $username = $username[0]->name; else $username = 'Unknown';
  582.            
  583.             $results[$i]["username"] = htmlspecialchars($username);
  584.             $results[$i]["id"] = $warning->id;
  585.             $results[$i]["staff"] = htmlspecialchars($warning->banned_by_name);
  586.            
  587.             $results[$i]["issued"] = $warning->time / 1000;
  588.             $results[$i]["issued_human"] = date("jS M Y, H:i:s", $warning->time / 1000);
  589.            
  590.             // Is a reason set?
  591.             if($warning->reason !== null){
  592.                 $results[$i]["reason"] = htmlspecialchars($warning->reason);
  593.             } else {
  594.                 $results[$i]["reason"] = "-";
  595.             }
  596.  
  597.  
  598.             $results[$i]["type"] = "warning";
  599.             $results[$i]["type_human"] = "<span class=\"label label-info\">" . $this->_language['warning'] . "</span>";
  600.             $results[$i]["expires_human"] = '';
  601.  
  602.             $i++;
  603.         }
  604.        
  605.         // Kicks
  606.         foreach($kicks as $kick){
  607.             $username = $this->_db->get($this->_prefix . 'history', array('uuid', '=', htmlspecialchars($kick->uuid)))->results();
  608.  
  609.             if(count($username) > 1){
  610.                 // get most recent name
  611.                 usort($username, function($a, $b) {
  612.                     return strtotime($b->date) - strtotime($a->date);
  613.                 });
  614.             }
  615.             if(count($username)) $username = $username[0]->name; else $username = 'Unknown';
  616.            
  617.             $results[$i]["username"] = htmlspecialchars($username);
  618.             $results[$i]["id"] = $kick->id;
  619.             $results[$i]["staff"] = htmlspecialchars($kick->banned_by_name);
  620.            
  621.             $results[$i]["issued"] = $kick->time / 1000;
  622.             $results[$i]["issued_human"] = date("jS M Y, H:i:s", $kick->time / 1000);
  623.            
  624.             // Is a reason set?
  625.             if($kick->reason !== null){
  626.                 $results[$i]["reason"] = htmlspecialchars($kick->reason);
  627.             } else {
  628.                 $results[$i]["reason"] = "-";
  629.             }
  630.  
  631.             $results[$i]["type"] = "kick";
  632.             $results[$i]["type_human"] = "<span class=\"label label-default\">" . $this->_language['kick'] . "</span>";
  633.             $results[$i]["expires_human"] = '';
  634.  
  635.             $i++;
  636.         }
  637.  
  638.         // Order by date, most recent first
  639.         function date_compare($a, $b){
  640.             $t1 = $a['issued'];
  641.             $t2 = $b['issued'];
  642.             return $t2 - $t1;
  643.         }    
  644.         usort($results, 'date_compare');
  645.  
  646.         return $results;
  647.     }
  648.    
  649.     // Receive an object containing infraction information for a specified infraction ID and type (LiteBans)
  650.     // Params: $type (string), either ban, kick or mute; $id (int), ID of infraction
  651.     public function lb_getInfraction($type, $id) {
  652.         if($type === "ban" || $type === "temp_ban"){
  653.             $results = $this->_db->get($this->_prefix . 'bans', array("id", "=", $id))->results();
  654.            
  655.             $username = $this->_db->get($this->_prefix . 'history', array('uuid', '=', htmlspecialchars($results[0]->uuid)))->results();
  656.  
  657.             if(count($username) > 1){
  658.                 // get most recent name
  659.                 usort($username, function($a, $b) {
  660.                     return strtotime($b->date) - strtotime($a->date);
  661.                 });
  662.             }
  663.             if(count($username)) $username = htmlspecialchars($username[0]->name); else $username = 'Unknown';
  664.            
  665.             return array($results[0], $username);
  666.         } else if($type === "mute"){
  667.             $results = $this->_db->get($this->_prefix . 'mutes', array("id", "=", $id))->results();
  668.            
  669.             $username = $this->_db->get($this->_prefix . 'history', array('uuid', '=', htmlspecialchars($results[0]->uuid)))->results();
  670.  
  671.             if(count($username) > 1){
  672.                 // get most recent name
  673.                 usort($username, function($a, $b) {
  674.                     return strtotime($b->date) - strtotime($a->date);
  675.                 });
  676.             }
  677.             if(count($username)) $username = htmlspecialchars($username[0]->name); else $username = 'Unknown';
  678.            
  679.             return array($results[0], $username);
  680.         } else if($type === "warning"){
  681.             $results = $this->_db->get($this->_prefix . 'warnings', array("id", "=", $id))->results();
  682.            
  683.             $username = $this->_db->get($this->_prefix . 'history', array('uuid', '=', htmlspecialchars($results[0]->uuid)))->results();
  684.  
  685.             if(count($username) > 1){
  686.                 // get most recent name
  687.                 usort($username, function($a, $b) {
  688.                     return strtotime($b->date) - strtotime($a->date);
  689.                 });
  690.             }
  691.             if(count($username)) $username = htmlspecialchars($username[0]->name); else $username = 'Unknown';
  692.            
  693.             return array($results[0], $username);
  694.         } else if($type === "kick"){
  695.             $results = $this->_db->get($this->_prefix . 'kicks', array("id", "=", $id))->results();
  696.            
  697.             $username = $this->_db->get($this->_prefix . 'history', array('uuid', '=', htmlspecialchars($results[0]->uuid)))->results();
  698.  
  699.             if(count($username) > 1){
  700.                 // get most recent name
  701.                 usort($username, function($a, $b) {
  702.                     return strtotime($b->date) - strtotime($a->date);
  703.                 });
  704.             }
  705.             if(count($username)) $username = htmlspecialchars($username[0]->name); else $username = 'Unknown';
  706.            
  707.             return array($results[0], $username);
  708.         }
  709.         return false;
  710.     }
  711.    
  712.     // Receive a list of all infractions for Ban and Mute Plugin, either for a single user or for all users
  713.     // Params: $uuid (string), UUID of a user. If null, will list all infractions
  714.     public function bam_getAllInfractions($uuid = null) {
  715.         if($uuid !== null){
  716.             $field = "UUID";
  717.             $symbol = "=";
  718.             $equals = $uuid;
  719.         } else {
  720.             $field = "UUID";
  721.             $symbol = "<>";
  722.             $equals = "0";
  723.         }
  724.         $bans = $this->_db->get('history', array($field, $symbol, $equals))->results();
  725.         $mutes = $this->_db->get('mutes', array($field, $symbol, $equals))->results();
  726.        
  727.         $results = array();
  728.         $i = 0;
  729.        
  730.         foreach($bans as $ban){
  731.             $results[$i]["id"] = htmlspecialchars($ban->name) . ';' . strtotime($ban->time);
  732.             $results[$i]["uuid"] = str_replace('-', '', $ban->UUID);
  733.             $results[$i]["staff"] = htmlspecialchars($ban->banner);
  734.             $results[$i]["issued"] = strtotime($ban->time);
  735.             $results[$i]["issued_human"] = date("jS M Y, H:i", strtotime($ban->time));
  736.             if($ban->cause !== null){
  737.                 $results[$i]["reason"] = htmlspecialchars($ban->cause);
  738.             } else {
  739.                 $results[$i]["reason"] = "-";
  740.             }
  741.            
  742.             if($ban->dauer !== 'Permanent'){
  743.                 $results[$i]["type"] = "temp_ban";
  744.                 $results[$i]["type_human"] = '<span class="label label-danger">' . $this->_language['temp_ban'] . '</span>';
  745.                
  746.                 // Todo: determine expire time
  747.                 $results[$i]["expires"] = '';
  748.                 $results[$i]["expires_human"] = '';
  749.             } else {
  750.                 $results[$i]["type"] = "ban";
  751.                 $results[$i]["type_human"] = '<span class="label label-danger">' . $this->_language['ban'] . '</span>';
  752.                 $results[$i]["expires_human"] = '<span class="label label-danger">' . $this->_language['permanent'] . '</span>';
  753.                
  754.                 // Todo: determine if revoked or not
  755.             }
  756.  
  757.             $i++;
  758.         }
  759.        
  760.         foreach($mutes as $mute){
  761.             $results[$i]["id"] = htmlspecialchars($mute->name) . ';' . strtotime($mute->time);
  762.             $results[$i]["uuid"] = str_replace('-', '', $mute->UUID);
  763.             $results[$i]["staff"] = htmlspecialchars($mute->banner);
  764.             if($mute->cause !== null){
  765.                 $results[$i]["reason"] = htmlspecialchars($mute->cause);
  766.             } else {
  767.                 $results[$i]["reason"] = "-";
  768.             }
  769.             $results[$i]["type"] = "mute";
  770.             $results[$i]["type_human"] = '<span class="label label-warning">' . $this->_language['mute'] . '</span>';
  771.  
  772.             if($mute->time !== null){
  773.                 $results[$i]["expires"] = strtotime($mute->time);
  774.                 $results[$i]["expires_human"] = '<span class="label label-danger" rel="tooltip" data-trigger="hover" data-original-title="' . str_replace('{x}', date("jS M Y", strtotime($mute->time)), $this->_language['expires_x']) . '">' . $this->_language['active'] . '</span>';
  775.             } else {
  776.                 $results[$i]['expires'] = 0;
  777.                 $results[$i]["expires_human"] = '<span class="label label-danger">' . $this->_language['permanent'] . '</span>';
  778.             }
  779.             $i++;
  780.         }
  781.        
  782.         // Sort by date
  783.         function date_compare($a, $b)
  784.         {
  785.             if(isset($a['issued'])){
  786.                 $t1 = $a['issued'];
  787.             } else {
  788.                 $t1 = $a['expires'];
  789.             }
  790.             if(isset($b['issued'])){
  791.                 $t2 = $b['issued'];
  792.             } else {
  793.                 $t2 = $b['expires'];
  794.             }
  795.             return $t2 - $t1;
  796.         }    
  797.         usort($results, 'date_compare');
  798.         return $results;
  799.     }
  800.    
  801.     // Receive an object containing infraction information for a specified infraction ID and type (Ban and Mute plugin)
  802.     // Params: $type (string), either ban, kick or mute; $id (int), ID of infraction
  803.     public function bam_getInfraction($type, $id) {
  804.         $ids = explode(';', $id);
  805.         $name = $ids[0];
  806.         if($ids[1]) $time = date('Y-m-d H:i:s', $ids[1]);
  807.         else $time = null;
  808.        
  809.         if($type === "ban" || $type === "temp_ban"){
  810.             $results = $this->_db->get('history', array("time", "=", $time))->results();
  811.             foreach($results as $result){
  812.                 if($result->name == $name) return $result;
  813.             }
  814.         } else if($type === "mute"){
  815.             if($time){
  816.                 $results = $this->_db->get('mutes', array("time", "=", $time))->results();
  817.                 foreach($results as $result){
  818.                     if($result->name == $name) return $result;
  819.                 }
  820.             } else {
  821.                 $results = $this->_db->get('mutes', array('name', '=', htmlspecialchars($name)))->results();
  822.                 foreach($results as $result){
  823.                     if($result->time == null) return $result;
  824.                 }
  825.             }
  826.         }
  827.  
  828.         return false;
  829.     }
  830.    
  831.     // Receive a list of all infractions for BungeeUtilisals, either for a single user or for all users
  832.     // Params: $uuid (string), UUID of a user. If null, will list all infractions
  833.     public function bu_getAllInfractions($uuid = null) {
  834.         if($uuid !== null){
  835.             $ban_field = "Banned";
  836.             $mute_field = "Muted";
  837.             $symbol = "=";
  838.             $equals = $uuid;
  839.         } else {
  840.             $ban_field = "Banned";
  841.             $mute_field = "Muted";
  842.             $symbol = "<>";
  843.             $equals = "0";
  844.         }
  845.         $bans = $this->_db->get('bans', array($ban_field, $symbol, $equals))->results();
  846.         $mutes = $this->_db->get('mutes', array($mute_field, $symbol, $equals))->results();
  847.        
  848.         $results = array();
  849.         $i = 0;
  850.        
  851.         foreach($bans as $ban){
  852.             $results[$i]["id"] = htmlspecialchars($ban->Banned);
  853.             $results[$i]["uuid"] = htmlspecialchars($ban->Banned);
  854.             $results[$i]["staff"] = htmlspecialchars($ban->BannedBy);
  855.  
  856.             if($ban->Reason !== null){
  857.                 $results[$i]["reason"] = htmlspecialchars($ban->Reason);
  858.             } else {
  859.                 $results[$i]["reason"] = "-";
  860.             }
  861.            
  862.             if($ban->BanTime != '-1'){
  863.                 $results[$i]["type"] = "temp_ban";
  864.                 $results[$i]["type_human"] = '<span class="label label-danger">' . $this->_language['temp_ban'] . '</span>';
  865.                
  866.                 // Convert expiry date
  867.                 $date = $ban->BanTime / 1000;
  868.                
  869.                 $results[$i]["expires"] = strtotime($ban->BanTime);
  870.                 $results[$i]["expires_human"] = '<span class="label label-danger" rel="tooltip" data-trigger="hover" data-original-title="' . str_replace('{x}', date("jS M Y", $date), $this->_language['expires_x']) . '">' . $this->_language['active'] . '</span>';
  871.             } else {
  872.                 $results[$i]["type"] = "ban";
  873.                 $results[$i]["type_human"] = '<span class="label label-danger">' . $this->_language['ban'] . '</span>';
  874.                 $results[$i]["expires_human"] = '<span class="label label-danger">' . $this->_language['permanent'] . '</span>';
  875.             }
  876.  
  877.             $i++;
  878.         }
  879.        
  880.         foreach($mutes as $mute){
  881.             $results[$i]["id"] = htmlspecialchars($mute->Muted);
  882.             $results[$i]["uuid"] = htmlspecialchars($mute->Muted);
  883.             $results[$i]["staff"] = htmlspecialchars($mute->MutedBy);
  884.  
  885.             if($mute->Reason !== null){
  886.                 $results[$i]["reason"] = htmlspecialchars($mute->Reason);
  887.             } else {
  888.                 $results[$i]["reason"] = "-";
  889.             }
  890.            
  891.             if($mute->MuteTime != '-1'){
  892.                 $results[$i]["type"] = "temp_mute";
  893.                 $results[$i]["type_human"] = '<span class="label label-warning">' . $this->_language['mute'] . '</span>';
  894.                
  895.                 // Convert expiry date
  896.                 $date = $mute->MuteTime / 1000;
  897.                
  898.                 $results[$i]["expires"] = strtotime($mute->MuteTime);
  899.                 $results[$i]["expires_human"] = '<span class="label label-warning" rel="tooltip" data-trigger="hover" data-original-title="' . str_replace('{x}', date("jS M Y", $date), $this->_language['expires_x']) . '">' . $this->_language['active'] . '</span>';
  900.             } else {
  901.                 $results[$i]["type"] = "mute";
  902.                 $results[$i]["type_human"] = '<span class="label label-warning">' . $this->_language['mute'] . '</span>';
  903.                 $results[$i]["expires_human"] = '<span class="label label-danger">' . $this->_language['permanent'] . '</span>';
  904.             }
  905.  
  906.             $i++;
  907.         }
  908.         return $results;
  909.     }
  910.    
  911.     // Receive an object containing infraction information for a specified infraction ID and type (BungeeUtilisals plugin)
  912.     // Params: $type (string), either ban or mute; $id (string), UUID of infraction
  913.     public function bu_getInfraction($type, $id) {
  914.         if($type === "ban" || $type === "temp_ban"){
  915.             $results = $this->_db->get('bans', array("Banned", "=", $id))->results();
  916.  
  917.             if(count($results)) return $results[0];
  918.         } else if($type === "mute" || $type === "temp_mute"){
  919.             $results = $this->_db->get('mutes', array("Muted", "=", $id))->results();
  920.  
  921.             if(count($results)) return $results[0];
  922.         }
  923.  
  924.         return false;
  925.     }
  926.    
  927. }
Advertisement
Add Comment
Please, Sign In to add comment