file.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * cache class provides an abstracted cache
  4. *
  5. * @method string glob
  6. */
  7. class file {
  8. /**
  9. * variables
  10. */
  11. public $recursive;
  12. public $files;
  13. /**
  14. * Called when the object is created
  15. */
  16. public function __construct() {
  17. //place holder
  18. }
  19. /**
  20. * Glob search for a list of files
  21. * @var string $dir this is the directory to scan
  22. * @var boolean $recursive get the sub directories
  23. */
  24. public function glob($dir, $recursive) {
  25. $files = [];
  26. if ($dir != '' || $dir != '/') {
  27. $tree = glob(rtrim($dir, '/') . '/*');
  28. if ($recursive) {
  29. if (is_array($tree)) {
  30. foreach($tree as $file) {
  31. if (is_dir($file)) {
  32. if ($recursive == true) {
  33. $files[] = $this->glob($file, $recursive);
  34. }
  35. } elseif (is_file($file)) {
  36. $files[] = $file;
  37. }
  38. }
  39. }
  40. else {
  41. $files[] = $file;
  42. }
  43. }
  44. else {
  45. $files[] = $file;
  46. }
  47. return $files;
  48. }
  49. }
  50. /**
  51. * Get the sounds list of search as a relative path without the rate
  52. */
  53. public function sounds($language = 'en', $dialect = 'us', $voice = 'callie') {
  54. //define an empty array
  55. $array = [];
  56. //set default values
  57. if (!isset($language)) { $language = 'en'; }
  58. if (!isset($dialect)) { $dialect = 'us'; }
  59. if (!isset($voice)) { $voice = 'callie'; }
  60. //set the variables
  61. if (!empty($_SESSION['switch']['sounds']['dir']) && file_exists($_SESSION['switch']['sounds']['dir'])) {
  62. $dir = $_SESSION['switch']['sounds']['dir'].'/'.$language.'/'.$dialect.'/'.$voice;
  63. $rate = '8000';
  64. $files = $this->glob($dir.'/*/'.$rate, true);
  65. }
  66. //loop through the languages
  67. if (!empty($files)) {
  68. foreach($files as $file) {
  69. $file = substr($file, strlen($dir)+1);
  70. $file = str_replace("/".$rate, "", $file);
  71. $array[] = $file;
  72. }
  73. }
  74. //return the list of sounds
  75. return $array;
  76. }
  77. }
  78. /*
  79. //add multi-lingual support
  80. $file = new file;
  81. $files = $file->sounds();
  82. print_r($files);
  83. */
  84. ?>