mirror of
https://github.com/fusionpbx/fusionpbx.git
synced 2025-12-30 00:53:50 +00:00
Documentation, format class, no modification. (#7629)
This commit is contained in:
@@ -1,58 +1,122 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* cache class provides an abstracted cache
|
||||
* file class provides an abstracted cache
|
||||
*/
|
||||
class file {
|
||||
|
||||
/**
|
||||
* variables
|
||||
*/
|
||||
*/
|
||||
public $recursive;
|
||||
public $files;
|
||||
|
||||
/**
|
||||
* Set in the constructor. Must be a database object and cannot be null.
|
||||
*
|
||||
* @var database Database Object
|
||||
*/
|
||||
private $database;
|
||||
|
||||
/**
|
||||
* Settings object set in the constructor. Must be a settings object and cannot be null.
|
||||
*
|
||||
* @var settings Settings Object
|
||||
*/
|
||||
private $settings;
|
||||
|
||||
/**
|
||||
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* User UUID set in the constructor. This can be passed in through the $settings_array associative array or set in
|
||||
* the session global array
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $user_uuid;
|
||||
|
||||
/**
|
||||
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set in the session global array
|
||||
* Domain UUID set in the constructor. This can be passed in through the $settings_array associative array or set
|
||||
* in the session global array
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $domain_uuid;
|
||||
|
||||
/**
|
||||
* Called when the object is created
|
||||
* Constructor for the class.
|
||||
*
|
||||
* This method initializes the object with setting_array and session data.
|
||||
*
|
||||
* @param array $setting_array An optional array of settings to override default values. Defaults to [].
|
||||
*/
|
||||
public function __construct(array $setting_array = []) {
|
||||
//set domain and user UUIDs
|
||||
$this->domain_uuid = $setting_array['domain_uuid'] ?? $_SESSION['domain_uuid'] ?? '';
|
||||
$this->user_uuid = $setting_array['user_uuid'] ?? $_SESSION['user_uuid'] ?? '';
|
||||
public function __construct(array $setting_array = []) {
|
||||
//set domain and user UUIDs
|
||||
$this->domain_uuid = $setting_array['domain_uuid'] ?? $_SESSION['domain_uuid'] ?? '';
|
||||
$this->user_uuid = $setting_array['user_uuid'] ?? $_SESSION['user_uuid'] ?? '';
|
||||
|
||||
//set objects
|
||||
$this->database = $setting_array['database'] ?? database::new();
|
||||
$this->settings = $setting_array['settings'] ?? new settings(['database' => $this->database, 'domain_uuid' => $this->domain_uuid, 'user_uuid' => $this->user_uuid]);
|
||||
//set objects
|
||||
$this->database = $setting_array['database'] ?? database::new();
|
||||
$this->settings = $setting_array['settings'] ?? new settings(['database' => $this->database, 'domain_uuid' => $this->domain_uuid, 'user_uuid' => $this->user_uuid]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Glob search for a list of files
|
||||
* @var string $dir this is the directory to scan
|
||||
* @var boolean $recursive get the sub directories
|
||||
* @return array list of files or an empty array if not found
|
||||
* Returns an array of sound files.
|
||||
*
|
||||
* This method retrieves a list of sound files based on the provided language,
|
||||
* dialect, and voice settings. If no specific values are provided, default values
|
||||
* will be used.
|
||||
*
|
||||
* @param string $language The desired language (default: 'en').
|
||||
* @param string $dialect The desired dialect (default: 'us').
|
||||
* @param string $voice The desired voice (default: 'callie').
|
||||
*
|
||||
* @return array An array of sound files.
|
||||
*/
|
||||
public function sounds($language = 'en', $dialect = 'us', $voice = 'callie') {
|
||||
//define an empty array
|
||||
$array = [];
|
||||
|
||||
//set default values
|
||||
if (!isset($language)) {
|
||||
$language = 'en';
|
||||
}
|
||||
if (!isset($dialect)) {
|
||||
$dialect = 'us';
|
||||
}
|
||||
if (!isset($voice)) {
|
||||
$voice = 'callie';
|
||||
}
|
||||
|
||||
//set the variables
|
||||
if (!empty($this->settings->get('switch', 'sounds')) && file_exists($this->settings->get('switch', 'sounds'))) {
|
||||
$dir = $this->settings->get('switch', 'sounds') . '/' . $language . '/' . $dialect . '/' . $voice;
|
||||
$rate = '8000';
|
||||
$files = $this->glob($dir . '/*/' . $rate, true);
|
||||
}
|
||||
|
||||
//loop through the languages
|
||||
if (!empty($files)) {
|
||||
foreach ($files as $file) {
|
||||
$file = substr($file, strlen($dir) + 1);
|
||||
$file = str_replace("/" . $rate, "", $file);
|
||||
$array[] = $file;
|
||||
}
|
||||
}
|
||||
|
||||
//return the list of sounds
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds files in the specified directory.
|
||||
*
|
||||
* This method recursively searches for files and directories within the given
|
||||
* directory, returning an array of paths if found. If no recursion is performed,
|
||||
* only the files directly within the directory are returned.
|
||||
*
|
||||
* @param string $dir The directory path to search.
|
||||
* @param bool $recursive Whether to recursively traverse subdirectories.
|
||||
*
|
||||
* @return array An array of file paths found in the specified directory.
|
||||
*/
|
||||
public function glob($dir, $recursive): array {
|
||||
$files = [];
|
||||
@@ -60,7 +124,7 @@ class file {
|
||||
$tree = glob(rtrim($dir, '/') . '/*');
|
||||
if ($recursive) {
|
||||
if (is_array($tree)) {
|
||||
foreach($tree as $file) {
|
||||
foreach ($tree as $file) {
|
||||
if (is_dir($file)) {
|
||||
if ($recursive == true) {
|
||||
$files[] = $this->glob($file, $recursive);
|
||||
@@ -71,41 +135,8 @@ class file {
|
||||
}
|
||||
}
|
||||
}
|
||||
return $files;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the sounds list of search as a relative path without the rate
|
||||
*/
|
||||
public function sounds($language = 'en', $dialect = 'us', $voice = 'callie') {
|
||||
//define an empty array
|
||||
$array = [];
|
||||
|
||||
//set default values
|
||||
if (!isset($language)) { $language = 'en'; }
|
||||
if (!isset($dialect)) { $dialect = 'us'; }
|
||||
if (!isset($voice)) { $voice = 'callie'; }
|
||||
|
||||
//set the variables
|
||||
if (!empty($this->settings->get('switch', 'sounds')) && file_exists($this->settings->get('switch', 'sounds'))) {
|
||||
$dir = $this->settings->get('switch', 'sounds').'/'.$language.'/'.$dialect.'/'.$voice;
|
||||
$rate = '8000';
|
||||
$files = $this->glob($dir.'/*/'.$rate, true);
|
||||
}
|
||||
|
||||
//loop through the languages
|
||||
if (!empty($files)) {
|
||||
foreach($files as $file) {
|
||||
$file = substr($file, strlen($dir)+1);
|
||||
$file = str_replace("/".$rate, "", $file);
|
||||
$array[] = $file;
|
||||
}
|
||||
}
|
||||
|
||||
//return the list of sounds
|
||||
return $array;
|
||||
return $files;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -116,5 +147,3 @@ class file {
|
||||
$files = $file->sounds();
|
||||
print_r($files);
|
||||
*/
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user