file.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. * Called when there are no references to a particular object
  21. * unset the variables used in the class
  22. */
  23. public function __destruct() {
  24. foreach ($this as $key => $value) {
  25. unset($this->$key);
  26. }
  27. }
  28. /**
  29. * Glob search for a list of files
  30. * @var string $dir this is the directory to scan
  31. * @var boolean $recursive get the sub directories
  32. */
  33. public function glob($dir, $recursive) {
  34. if ($dir != '' || $dir != '/') {
  35. $tree = glob(rtrim($dir, '/') . '/*');
  36. if ($recursive) {
  37. if (is_array($tree)) {
  38. foreach($tree as $file) {
  39. if (is_dir($file)) {
  40. if ($recursive == true) {
  41. $files[] = $this->glob($file, $recursive);
  42. }
  43. } elseif (is_file($file)) {
  44. $files[] = $file;
  45. }
  46. }
  47. }
  48. else {
  49. $files[] = $file;
  50. }
  51. }
  52. else {
  53. $files[] = $file;
  54. }
  55. return $files;
  56. }
  57. }
  58. /**
  59. * Get the sounds list of search as a relative path without the rate
  60. */
  61. public function sounds() {
  62. $dir = $_SESSION['switch']['sounds']['dir'].'/en/us/callie';
  63. $rate = '8000';
  64. $files = $this->glob($dir.'/*/'.$rate, true);
  65. foreach($files as $file) {
  66. $file = substr($file, strlen($dir)+1);
  67. $file = str_replace("/".$rate, "", $file);
  68. $array[] = $file;
  69. }
  70. return $array;
  71. }
  72. }
  73. /*
  74. //add multi-lingual support
  75. $file = new file;
  76. $files = $file->sounds();
  77. print_r($files);
  78. */
  79. ?>