Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2013
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.73 KB | None | 0 0
  1. <?php
  2.  
  3. function globistr($string = '', $mbEncoding = ''/*optional e.g.'UTF-8'*/)
  4. {
  5.     //returns a case insensitive Version of the searchPattern for glob();
  6.     // e.g.: globistr('./*.jpg') => './*.[jJ][pP][gG]'
  7.     // e.g.: glob(dirname(__FILE__).'/'.globistr('*.jpg')) => '/.../*.[jJ][pP][gG]'
  8.    
  9.     // known problems: globistr('./[abc].jpg') => FALSE:'./[[aA][bB][cC]].[jJ][pP][gG]'
  10.     //(Problem: existing Pattern[abc] will be overwritten)
  11.     // known solution: './[abc].'.globistr('jpg') => RIGHT: './[abc].[jJ][pP][gG]'
  12.     //(Solution: globistr() only caseSensitive Part, not everything)
  13.     $return = "";
  14.     if($mbEncoding !== ''){ //multiByte Version
  15.         $string = mb_convert_case($string,MB_CASE_LOWER,$mbEncoding);
  16.     }
  17.     else{ //standard Version (not multiByte,default)
  18.         $string = strtolower($string);
  19.     }
  20.     $mystrlen = strlen($string);
  21.     for($i=0;$i<$mystrlen;$i++){
  22.         if($mbEncoding !== ''){//multiByte Version
  23.             $myChar = mb_substr($string,$i,1,$mbEncoding);
  24.             //$myUpperChar = mb_strtoupper($myChar,$mbEncoding);
  25.             $myUpperChar = mb_convert_case($myChar,MB_CASE_UPPER,$mbEncoding);
  26.         }else{
  27.             $myChar = substr($string,$i,1);
  28.             $myUpperChar = strtoupper($myChar);
  29.         }
  30.         if($myUpperChar !== $myChar){ //there is a lower- and upperChar, / Char is case sentitive
  31.             $return .= '['.$myChar.$myUpperChar.']'; //adding both Versions : [xX]
  32.         }else{//only one case Version / Char is case insentitive
  33.             $return .= $myChar; //adding '1','.','*',...
  34.         }
  35.     }
  36.     return $return;
  37. }
  38.  
  39. if ( ! function_exists('glob_recursive'))
  40. {
  41.     // Does not support flag GLOB_BRACE
  42.    
  43.     function glob_recursive($pattern, $flags = 0)
  44.     {
  45.         $files = glob($pattern, $flags);
  46.  
  47.         foreach (glob(dirname($pattern).'\*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir)
  48.         {
  49.             $files = array_merge($files, glob_recursive($dir.'\\'.basename($pattern), $flags));
  50.         }
  51.        
  52.         return $files;
  53.     }
  54. }
  55.  
  56. function glob_files($filenames, $source_folder)
  57. {
  58.     if( !is_dir( $source_folder ) ) {
  59.         die ( "Invalid directory.\n\n" );
  60.     }
  61.    
  62.     $filenames = explode(' ', $filenames);
  63.     $formats = array('mp4', 'avi', 'mkv');
  64.     $key = 0;
  65.     foreach ($filenames as $filename):
  66.         foreach ($formats as $format):
  67.            
  68.             $FILES = glob_recursive($source_folder."\*".globistr($filename)."*.".$format);
  69.            
  70.             foreach($FILES as $file) {
  71.                
  72.                 $FILE_LIST[$key]['path'] = substr( $file, 0, ( strrpos( $file, "\\" ) +1 ) );
  73.                 $FILE_LIST[$key]['name'] = substr( $file, ( strrpos( $file, "\\" ) +1 ) );    
  74.                 $FILE_LIST[$key]['size'] = filesize( $file );
  75.                 $FILE_LIST[$key]['date'] = date('Y-m-d G:i:s', filemtime( $file ) );
  76.                 $key++;
  77.                
  78.             }
  79.  
  80.         endforeach;
  81.     endforeach;
  82.  
  83.     if (count($filenames) > 1):
  84.        
  85.         $SEARCH_MATCH = array();
  86.         $MOVIE_NAMES = array();
  87.  
  88.         $matches = array();
  89.         foreach ($FILE_LIST as $index => $f)
  90.         {
  91.             if (isset( $matches[$f['name']] ) && !in_array($f['name'], $MOVIE_NAMES))
  92.             {
  93.                 array_push($SEARCH_MATCH, $f);
  94.                 array_push($MOVIE_NAMES, $f['name']);
  95.             }
  96.             $matches[$f['name']] = $index;
  97.         }
  98.  
  99.     elseif (!empty($FILE_LIST)):
  100.         $SEARCH_MATCH = $FILE_LIST;
  101.     endif;
  102.  
  103.     if (!empty($SEARCH_MATCH))
  104.     {
  105.         return $SEARCH_MATCH;
  106.     }
  107.     else
  108.     {
  109.         return "No files found\n";
  110.     }
  111. }
  112.  
  113. if (isset($_POST['search'])):
  114.     $search = $_POST['search'];
  115. endif;
  116.  
  117. if (isset($search)):
  118.     $videos = glob_files($search, 'videos');
  119. endif;
  120. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement