Guest User

Untitled

a guest
Jun 19th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.34 KB | None | 0 0
  1. <?php
  2.     /*
  3.     * @function select
  4.     * @description Select table rows
  5.     * @param Array $fields
  6.     * @param String $table
  7.     * @param String $arguments (optional)
  8.     * @return Array $rows
  9.     */
  10.     public function select($fields,$table,$arguments=""){
  11.         //var_dump($this->res['connection'],$table);
  12.         $list = ftp_rawlist($this->res['connection'],$table);  
  13.         $result = array();
  14.        
  15.         function not_empty($var){return !empty($var);}
  16.        
  17.         function perm2octal($s){
  18.            
  19.             $p = array(
  20.                 '-' => 0,
  21.                 'x' => 1,
  22.                 'w' => 2,
  23.                 'r' => 4,
  24.             );
  25.             $r = 0;
  26.             foreach(str_split($s) AS $c){
  27.                 $r+=$p[$c];
  28.             }
  29.            
  30.             return $r;
  31.         }
  32.        
  33.         foreach($list AS $file){
  34.             if(substr($file,0,1)=='-'){
  35.                 $parse = explode(' ',$file);
  36.                 $parse = array_filter($parse,"not_empty");
  37.                
  38.                 $t['rights'] = (int) implode(array_map("perm2octal",str_split(substr(array_shift($parse),1),3)));
  39.                 $code = array_shift($parse);
  40.  
  41.                 $t['owner'] = array_shift($parse);
  42.                 $t['group'] = array_shift($parse);
  43.                 $t['size'] = (int) array_shift($parse);
  44.                
  45.                 $last = count($parse)-1;
  46.                 $t['name'] = $parse[$last];
  47.                 unset($parse[$last]);
  48.                
  49.                 $t['date'] = @strtotime(implode(' ',$parse));
  50.                 $return = array();
  51.                
  52.                 if(count($fields)){
  53.                     foreach($fields AS $field){
  54.                         if(in_array($field,$this->res['fields'])){
  55.                             if($field == 'content'){
  56.                                 $return['content'] = '';
  57.                                
  58.                                 $tmp = tmpfile();
  59.                                 ftp_fget($this->res['connection'],$tmp,$table.'/'.$t['name'],FTP_ASCII,0);
  60.                                 fseek($tmp,0);
  61.                                 while(!feof($tmp)){
  62.                                     $return['content'] .= fread($tmp,1024);
  63.                                 }
  64.                             }
  65.                             else{
  66.                                 $return[$field] = $t[$field];
  67.                             }
  68.                         }
  69.                     }
  70.                 }
  71.                 else{
  72.                     $return = $t;
  73.                 }
  74.                
  75.                 if(count($return)){ $result[] = $return; }
  76.             }
  77.         }
  78.        
  79.         $this->res['result'] = $result;
  80.         return $this->_result();
  81.     }
  82. ?>
Add Comment
Please, Sign In to add comment