105 lines
3.0 KiB
PHP
105 lines
3.0 KiB
PHP
<?php
|
|
/**
|
|
* app/functions/common.php
|
|
*
|
|
* @version 3.0
|
|
* @author Joey Kimsey <Joey@thetempusproject.com>
|
|
* @link https://TheTempusProject.com
|
|
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
|
|
*/
|
|
function getClassName($class) {
|
|
$className = get_class($class);
|
|
$classNameParts = explode('\\', $className);
|
|
return end($classNameParts);
|
|
}
|
|
|
|
function convertClassNameToFileName( $class_name ) {
|
|
$lower = lcfirst( $class_name ) . '.php';
|
|
$upper_split = preg_split( '/(?=[A-Z])/', $lower );
|
|
$file_name = strtolower( implode( '_', $upper_split ) );
|
|
return $file_name;
|
|
}
|
|
|
|
function convertFileNameToClassName( $file_name ) {
|
|
$file_name = str_ireplace( '.php', '', $file_name );
|
|
$file_name = rtrim( $file_name, DIRECTORY_SEPARATOR );
|
|
$class_name = '';
|
|
if ( stripos( $file_name, '_' ) ) {
|
|
$exploded = explode( '_', $file_name );
|
|
foreach ( $exploded as $key => $value ) {
|
|
$class_name .= ucfirst( $value );
|
|
}
|
|
} else {
|
|
$class_name .= ucfirst( $file_name );
|
|
}
|
|
return $class_name;
|
|
}
|
|
|
|
function convertFolderToClassName( $folder ) {
|
|
$file_name = rtrim( $folder, DIRECTORY_SEPARATOR );
|
|
$parts_array = explode(DIRECTORY_SEPARATOR, $file_name);
|
|
$file_name = array_pop($parts_array);
|
|
|
|
$class_name = '';
|
|
if ( stripos( $file_name, '_' ) ) {
|
|
$exploded = explode( '_', $file_name );
|
|
foreach ( $exploded as $key => $value ) {
|
|
$class_name .= ucfirst( $value );
|
|
}
|
|
} else {
|
|
$class_name .= ucfirst( $file_name );
|
|
}
|
|
return $class_name;
|
|
}
|
|
|
|
function convertFileNameToPluginClass( $file_name ) {
|
|
$class_name = convertFolderToClassName( $file_name );
|
|
$class = (string) APP_SPACE . '\\Plugins\\' . $class_name;
|
|
return $class;
|
|
}
|
|
|
|
function convertFileNameToModelClass( $file_name ) {
|
|
$class_name = convertFileNameToClassName( $file_name );
|
|
$class = (string) APP_SPACE . '\\Models\\' . $class_name;
|
|
return $class;
|
|
}
|
|
|
|
function getFileList( $folder = '' ) {
|
|
if ( empty( $folder ) ) {
|
|
$folder = PLUGIN_DIRECTORY;
|
|
}
|
|
if ( !file_exists( $folder ) ) {
|
|
return false;
|
|
}
|
|
$pluginFolders = scandir( $folder );
|
|
array_shift( $pluginFolders ); // remove the .
|
|
array_shift( $pluginFolders ); // remove the ..
|
|
return $pluginFolders;
|
|
}
|
|
|
|
function dv( $variable ) {
|
|
echo '<pre>';
|
|
echo var_export( $variable, true );
|
|
echo '</pre>';
|
|
exit;
|
|
}
|
|
|
|
function iv( $variable ) {
|
|
echo '<pre>';
|
|
echo var_export( $variable, true );
|
|
echo '</pre>';
|
|
}
|
|
|
|
function generateToken(): string {
|
|
return bin2hex(random_bytes(32)); // Generates a 64-character hexadecimal token
|
|
}
|
|
|
|
function generateRandomString( $length = 10 ) {
|
|
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
$charactersLength = strlen( $characters );
|
|
$randomString = '';
|
|
for ($i = 0; $i < $length; $i++) {
|
|
$randomString .= $characters[random_int(0, $charactersLength - 1)];
|
|
}
|
|
return $randomString;
|
|
} |