Advertisement
Ewwe

Banlist.parser.class PHP 5

Jun 10th, 2016
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.74 KB | None | 0 0
  1. <?php
  2. class Banlist
  3. {
  4.     private $host , $user , $password;
  5.     private $local_file = "bpc_samp.ban";
  6.     private $local_file_ = "bpc_samp.ban_";
  7.  
  8.     public function __construct( $host , $user , $password )
  9.     {
  10.         if( $this->valornull( $host ) != null and $this->valornull( $user )  != null and $this->valornull( $password ) != null )
  11.         {
  12.             $this->host = $host;
  13.             $this->user = $user;
  14.             $this->password = $password;
  15.         }else throw new Exception("FTP Account not correct!");
  16.     }
  17.  
  18.     public function getBanlistFile($file = "samp.ban" )
  19.     {
  20.         $conn_id = ftp_connect( $this->host );
  21.         $login_result = ftp_login( $conn_id , $this->user , $this->password );
  22.         if (ftp_get( $conn_id, $this->local_file_ , $file , FTP_BINARY))
  23.         {
  24.             unlink( $this->local_file );
  25.             rename( $this->local_file_ , $this->local_file );
  26.         } else throw new Exception("File not downloaded!");
  27.         ftp_close( $conn_id );
  28.     }
  29.  
  30.     public function parseBanlistFile( $file_path = "bpc_samp.ban" )
  31.     {
  32.         $data = file_get_contents( $file_path );
  33.         $data = rtrim( $data , "\n");
  34.         $data = explode("\n",$data );
  35.         foreach( $data as $ban )
  36.         {
  37.             $baninfo = explode(" [",$ban);
  38.             $bandetails["IP"] = $baninfo[0];
  39.             $baninfo = explode("] ",$baninfo[1]);
  40.             $bandetails["DATE"] = $baninfo[0];
  41.             $baninfo = explode(" - ",$baninfo[1]);
  42.             $bandetails["PLAYER"] = $baninfo[0];
  43.             $bandetails["REASON"] = $baninfo[1];
  44.             $output[] = [
  45.                 "IP" => $bandetails["IP"],
  46.                 "DATE" => $bandetails["DATE"],
  47.                 "PLAYER" => $bandetails["PLAYER"],
  48.                 "REASON" => $bandetails["REASON"]
  49.             ];
  50.         }
  51.         return $output;
  52.     }
  53.  
  54.     public function stylizeRow( $prefix , $suffix , $rowprefix , $rowsuffix)
  55.     {
  56.         $data = $this->parseBanlistFile();
  57.         foreach( $data as $record => $r )
  58.         {
  59.             $rows[] = $rowprefix.$prefix.$r["IP"].$suffix.$prefix.$r["DATE"].$suffix.$prefix.$r["PLAYER"].$suffix.$prefix.$r["REASON"].$suffix.$rowsuffix;
  60.         }
  61.         return $rows;
  62.     }
  63.  
  64.     public function stylizeRowEcho( $prefix , $suffix , $rowprefix , $rowsuffix)
  65.     {
  66.         $data = $this->parseBanlistFile();
  67.         foreach( $data as $record => $r )
  68.         {
  69.             echo $rowprefix.$prefix.$r["IP"].$suffix.$prefix.$r["DATE"].$suffix.$prefix.$r["PLAYER"].$suffix.$prefix.$r["REASON"].$suffix.$rowsuffix;
  70.         }
  71.     }
  72.  
  73.     private function valornull( $variable )
  74.     {
  75.         if( strlen( trim( $variable ) ) == 0 ) return null;
  76.         else return $variable;
  77.     }
  78. }
  79.  ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement