Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Banlist
- {
- private $host , $user , $password;
- private $local_file = "bpc_samp.ban";
- private $local_file_ = "bpc_samp.ban_";
- public function __construct( $host , $user , $password )
- {
- if( $this->valornull( $host ) != null and $this->valornull( $user ) != null and $this->valornull( $password ) != null )
- {
- $this->host = $host;
- $this->user = $user;
- $this->password = $password;
- }else throw new Exception("FTP Account not correct!");
- }
- public function getBanlistFile($file = "samp.ban" )
- {
- $conn_id = ftp_connect( $this->host );
- $login_result = ftp_login( $conn_id , $this->user , $this->password );
- if (ftp_get( $conn_id, $this->local_file_ , $file , FTP_BINARY))
- {
- unlink( $this->local_file );
- rename( $this->local_file_ , $this->local_file );
- } else throw new Exception("File not downloaded!");
- ftp_close( $conn_id );
- }
- public function parseBanlistFile( $file_path = "bpc_samp.ban" )
- {
- $data = file_get_contents( $file_path );
- $data = rtrim( $data , "\n");
- $data = explode("\n",$data );
- foreach( $data as $ban )
- {
- $baninfo = explode(" [",$ban);
- $bandetails["IP"] = $baninfo[0];
- $baninfo = explode("] ",$baninfo[1]);
- $bandetails["DATE"] = $baninfo[0];
- $baninfo = explode(" - ",$baninfo[1]);
- $bandetails["PLAYER"] = $baninfo[0];
- $bandetails["REASON"] = $baninfo[1];
- $output[] = [
- "IP" => $bandetails["IP"],
- "DATE" => $bandetails["DATE"],
- "PLAYER" => $bandetails["PLAYER"],
- "REASON" => $bandetails["REASON"]
- ];
- }
- return $output;
- }
- public function stylizeRow( $prefix , $suffix , $rowprefix , $rowsuffix)
- {
- $data = $this->parseBanlistFile();
- foreach( $data as $record => $r )
- {
- $rows[] = $rowprefix.$prefix.$r["IP"].$suffix.$prefix.$r["DATE"].$suffix.$prefix.$r["PLAYER"].$suffix.$prefix.$r["REASON"].$suffix.$rowsuffix;
- }
- return $rows;
- }
- public function stylizeRowEcho( $prefix , $suffix , $rowprefix , $rowsuffix)
- {
- $data = $this->parseBanlistFile();
- foreach( $data as $record => $r )
- {
- echo $rowprefix.$prefix.$r["IP"].$suffix.$prefix.$r["DATE"].$suffix.$prefix.$r["PLAYER"].$suffix.$prefix.$r["REASON"].$suffix.$rowsuffix;
- }
- }
- private function valornull( $variable )
- {
- if( strlen( trim( $variable ) ) == 0 ) return null;
- else return $variable;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement