retesere20

move-uploaded-addon-to-folder

Jun 6th, 2021
14
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. public function wp_handle_upload_filter( $array=['file' => 'path/to/wp-content/uploads/2018/12/example.ext', 'url' => 'https://.....example.ext', 'type' => 'application/zip'], $action= 'sideload|upload' )
  3. {
  4. $file = $array['file'];
  5. if($array['type']=="application/zip" || $array['type']=="application/x-zip")
  6. {
  7. $filename = basename($file);
  8. $found = false;
  9.  
  10. $found_files=[];
  11. if (function_exists('zip_open'))
  12. {
  13. $zip = zip_open($file);
  14. if (is_resource($zip))
  15. {
  16. while ($zip_entry = zip_read($zip))
  17. {
  18. $found_files[]=zip_entry_name($zip_entry);
  19. //if (zip_entry_open($zip, $zip_entry))
  20. //{
  21. //echo zip_entry_read($zip_entry);
  22. //zip_entry_close($zip_entry);
  23. //}
  24. }
  25. zip_close($zip);
  26. }
  27. }
  28. elseif (class_exists('\ZipArchive'))
  29. {
  30. $za = new \ZipArchive();
  31. $za->open($file);
  32. for( $i = 0; $i < $za->numFiles; $i++ ){
  33. $stat = $za->statIndex( $i );
  34. $found_files[] = basename( $stat['name'] ) ;
  35. }
  36. }
  37. //elseif( stripos($filename, $this->pro_file_part) !== false)
  38. //{
  39. // $found = true;
  40. //}
  41.  
  42. //if contains
  43. if(!empty($found_files))
  44. {
  45. foreach(array_filter($found_files) as $each)
  46. {
  47. if( stripos($each, $this->addon_namepart.'/'.$this->slug)!==false)
  48. {
  49. $found = true;
  50. }
  51. }
  52. }
  53.  
  54. if($found)
  55. {
  56. $this->helpers->unzip($file, $this->addons_dir);
  57. $this->helpers->move_folder_contents($this->addons_dir.'/'. $this->addon_namepart, $this->addons_dir);
  58. $this->helpers->rmdir_recursive($this->addons_dir.'/'. $this->addon_namepart);
  59. $need_space = stripos($_SERVER['REQUEST_URI'], 'upload.php') !== false ? '�?�?�?�?�?�?�?�?' : '';
  60. return ['error'=> $need_space."Thank You �? Addon has been installed, you can activate it with the key !"];
  61. }
  62. }
  63. return $array;
  64. }
RAW Paste Data