| Linux webm007.cluster106.gra.hosting.ovh.net 5.15.167-ovh-vps-grsec-zfs-classid #1 SMP Tue Sep 17 08:14:20 UTC 2024 x86_64 Path : /home/eglisebaa/www/wp-content/plugins/trx_addons/includes/ |
| Current File : /home/eglisebaa/www/wp-content/plugins/trx_addons/includes/plugin.files.php |
<?php
/**
* File system manipulations
*
* @package WordPress
* @subpackage ThemeREX Addons
* @since v1.0
*/
// Don't load directly
if ( ! defined( 'TRX_ADDONS_VERSION' ) ) {
die( '-1' );
}
/* Enqueue scripts and styles
------------------------------------------------------------------------------------- */
// Enqueue slider scripts and styles
if ( !function_exists( 'trx_addons_enqueue_slider' ) ) {
function trx_addons_enqueue_slider($engine='all') {
if ($engine=='all' || $engine=='swiper') {
// 3.4.2 - Latest version with jQuery support (not compatible with Elementor 2.1.0+)
// 4+ - New version not need jQuery - using Dom7 (compatible with Elementor 2.1.0+)
wp_enqueue_style( 'jquery-swiper', trx_addons_get_file_url('js/swiper/swiper.min.css'), array(), null );
wp_enqueue_script( 'jquery-swiper', trx_addons_get_file_url('js/swiper/swiper.min.js'), array('jquery'), null, true );
}
if ($engine=='all' || $engine=='elastistack') {
wp_enqueue_script( 'modernizr', trx_addons_get_file_url('js/elastistack/modernizr.custom.js'), array(), null, true );
wp_enqueue_script( 'draggabilly', trx_addons_get_file_url('js/elastistack/draggabilly.pkgd.min.js'), array(), null, true );
wp_enqueue_script( 'elastistack', trx_addons_get_file_url('js/elastistack/elastistack.js'), array(), null, true );
}
}
}
// Enqueue popup scripts and styles
// Link must have attribute: data-rel="popupEngine" or data-rel="popupEngine[gallery]"
if ( !function_exists( 'trx_addons_enqueue_popup' ) ) {
function trx_addons_enqueue_popup($engine='') {
if ($engine=='pretty') {
wp_enqueue_style( 'prettyphoto', trx_addons_get_file_url('js/prettyphoto/css/prettyPhoto.css'), array(), null );
wp_enqueue_script( 'prettyphoto', trx_addons_get_file_url('js/prettyphoto/jquery.prettyPhoto.min.js'), array('jquery'), 'no-compose', true );
} else {
wp_enqueue_style( 'magnific-popup',trx_addons_get_file_url('js/magnific/magnific-popup.min.css'), array(), null );
wp_enqueue_script( 'magnific-popup',trx_addons_get_file_url('js/magnific/jquery.magnific-popup.min.js'), array('jquery'), null, true );
}
}
}
// Enqueue WP colorpicker in front-end
if ( !function_exists( 'trx_addons_enqueue_wp_color_picker' ) ) {
function trx_addons_enqueue_wp_color_picker() {
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_script( 'iris', admin_url( 'js/iris.min.js' ), array( 'jquery-ui-draggable', 'jquery-ui-slider', 'jquery-touch-punch' ), null, true);
wp_enqueue_script( 'wp-color-picker', admin_url( 'js/color-picker.min.js' ), array( 'iris' ), null, true);
wp_localize_script( 'wp-color-picker', 'wpColorPickerL10n', array(
'clear' => __( 'Clear', 'trx_addons' ),
'defaultString' => __( 'Default', 'trx_addons' ),
'pick' => __( 'Select Color', 'trx_addons' ),
'current' => __( 'Current Color', 'trx_addons' ),
));
}
}
// Enqueue Google map script
if ( !function_exists( 'trx_addons_enqueue_googlemap' ) ) {
function trx_addons_enqueue_googlemap() {
$api_key = trx_addons_get_option('api_google');
if (trx_addons_is_on(trx_addons_get_option('api_google_load')) && !empty($api_key)) {
wp_enqueue_script( 'google-maps', 'https://maps.googleapis.com/maps/api/js' .( $api_key ? '?key=' . $api_key : '' ), array(), null, true );
}
}
}
// Enqueue Yandex map script
if ( !function_exists( 'trx_addons_enqueue_yandexmap' ) ) {
function trx_addons_enqueue_yandexmap() {
$api_key = trx_addons_get_option('api_yandex');
if (trx_addons_is_on(trx_addons_get_option('api_yandex_load'))) {
wp_enqueue_script( 'yandex-maps', !empty($api_key)
? 'https://enterprise.api-maps.yandex.ru/2.1/?lang=en_US&coordorder=latlong&apikey='.$api_key
: 'https://api-maps.yandex.ru/2.1/?lang=en_US&coordorder=latlong',
array(), null, true );
}
}
}
// Enqueue OpenStreen map script and style
if ( !function_exists( 'trx_addons_enqueue_osmap' ) ) {
function trx_addons_enqueue_osmap() {
if (trx_addons_is_on(trx_addons_get_option('api_openstreet_load'))) {
// LeaFlet OSM lib
wp_enqueue_style( 'openstreet-maps', 'https://unpkg.com/leaflet@1.4.0/dist/leaflet.css', array(), null );
wp_enqueue_script( 'openstreet-maps', 'https://unpkg.com/leaflet@1.4.0/dist/leaflet.js', array(), null, true );
// Geocoder Control
wp_enqueue_style( 'openstreet-maps-geocoder', 'https://unpkg.com/leaflet-control-geocoder/dist/Control.Geocoder.css', array(), null );
wp_enqueue_script( 'openstreet-maps-geocoder', 'https://unpkg.com/leaflet-control-geocoder/dist/Control.Geocoder.js', array(), null, true );
// Clustering
wp_enqueue_style( 'openstreet-maps-cluster', 'https://unpkg.com/leaflet.markercluster@1.4.1/dist/MarkerCluster.css', array(), null );
wp_enqueue_style( 'openstreet-maps-cluster-default', 'https://unpkg.com/leaflet.markercluster@1.4.1/dist/MarkerCluster.Default.css', array(), null );
wp_enqueue_script( 'openstreet-maps-cluster', 'https://unpkg.com/leaflet.markercluster@1.4.1/dist/leaflet.markercluster.js', array(), null, true );
// Mapbox GL
if ( trx_addons_get_option('api_openstreet_tiler') == 'vector' ) {
wp_enqueue_style( 'openstreet-maps-mapbox-gl', 'https://cdn.maptiler.com/mapbox-gl-js/v0.53.0/mapbox-gl.css', array(), null );
wp_enqueue_script( 'openstreet-maps-mapbox-gl', 'https://cdn.maptiler.com/mapbox-gl-js/v0.53.0/mapbox-gl.js', array(), null, true );
wp_enqueue_script( 'openstreet-maps-mapbox-gl-leaflet', 'https://cdn.maptiler.com/mapbox-gl-leaflet/latest/leaflet-mapbox-gl.js', array(), null, true );
}
}
}
}
// Enqueue Select2 scripts and styles
if ( !function_exists( 'trx_addons_enqueue_select2' ) ) {
function trx_addons_enqueue_select2() {
wp_enqueue_style( 'select2', trx_addons_get_file_url('js/select2/select2.min.css'), array(), null );
wp_enqueue_script( 'select2', trx_addons_get_file_url('js/select2/select2.min.js'), array('jquery'), null, true );
}
}
/* Merge scripts and styles
------------------------------------------------------------------------------------- */
// Merge all separate styles and scripts to the single file to increase page upload speed
if ( !function_exists( 'trx_addons_merge_js' ) ) {
function trx_addons_merge_js($to, $list) {
$s = '';
foreach ($list as $f) {
$s .= trx_addons_fgc(trx_addons_get_file_dir($f));
}
if ( $s != '') {
trx_addons_fpc( trx_addons_get_file_dir($to),
'/* '
. strip_tags( __("ATTENTION! This file was generated automatically! Don't change it!!!", 'trx_addons') )
. "\n----------------------------------------------------------------------- */\n"
. apply_filters( 'trx_addons_filter_js_output', trx_addons_minify_js( $s ), $to )
);
}
}
}
// Merge styles to the CSS file
if ( ! function_exists( 'trx_addons_merge_css' ) ) {
function trx_addons_merge_css( $to, $list, $need_responsive = false ) {
global $TRX_ADDONS_STORAGE;
$responsive = $TRX_ADDONS_STORAGE['responsive'];
if ($need_responsive) $responsive = apply_filters('trx_addons_filter_responsive_sizes', $responsive);
$sizes = array();
$output = '';
foreach ( $list as $f ) {
$fdir = trx_addons_get_file_dir( $f );
if ( '' != $fdir ) {
$css = trx_addons_fgc( $fdir );
if ( $need_responsive ) {
$pos = 0;
while( false !== $pos ) {
$pos = strpos($css, '@media' );
if ( false !== $pos ) {
$pos += 7;
$pos_lbrace = strpos( $css, '{', $pos );
//Old way: need rbrace of the @media just after \n
//$pos_rbrace = strpos( $css, "\n}", $pos_lbrace );
//New way: allow rbrace anywhere
$cnt = 0;
for ( $pos_rbrace = $pos_lbrace + 1; $pos_rbrace < strlen( $css ); $pos_rbrace++ ) {
if ( substr( $css, $pos_rbrace, 1 ) == '{' ) {
$cnt++;
} elseif ( substr( $css, $pos_rbrace, 1 ) == '}' ) {
if ( $cnt > 0 ) {
$cnt--;
} else {
break;
}
}
}
$media = trim( substr( $css, $pos, $pos_lbrace - $pos ) );
if ( empty( $sizes[ $media ] ) ) {
$sizes[ $media ] = '';
}
$sizes[ $media ] .= "\n\n" . apply_filters( 'trx_addons_filter_merge_css', substr( $css, $pos_lbrace + 1, $pos_rbrace - $pos_lbrace - 1 ) );
$css = substr( $css, $pos_rbrace + 1);
}
}
} else {
$output .= "\n\n" . apply_filters( 'trx_addons_filter_merge_css', $css );
}
}
}
if ( $need_responsive ) {
foreach ( $responsive as $k => $v ) {
$media = ( ! empty( $v['min'] ) ? "(min-width: {$v['min']}px)" : '' )
. ( ! empty( $v['min'] ) && ! empty( $v['max'] ) ? ' and ' : '' )
. ( ! empty( $v['max'] ) ? "(max-width: {$v['max']}px)" : '' );
if ( ! empty( $sizes[ $media ] ) ) {
$output .= "\n\n"
// Translators: Add responsive size's name to the comment
. strip_tags( sprintf( __( '/* SASS Suffix: --%s */', 'trx_addons' ), $k ) )
. "\n"
. "@media {$media} {\n"
. $sizes[ $media ]
. "\n}\n";
unset( $sizes[ $media ] );
}
}
if ( count( $sizes ) > 0 ) {
$output .= "\n\n"
. strip_tags( __( '/* Unknown Suffixes: */', 'trx_addons' ) );
foreach ( $sizes as $k => $v ) {
$output .= "\n\n"
. "@media {$k} {\n"
. $v
. "\n}\n";
}
}
}
if ( $output != '') {
trx_addons_fpc(
trx_addons_get_file_dir( $to ),
'/* '
. strip_tags( __("ATTENTION! This file was generated automatically! Don't change it!!!", 'trx_addons') )
. "\n----------------------------------------------------------------------- */\n"
. apply_filters( 'trx_addons_filter_css_output', trx_addons_minify_css( $output ), $to )
);
}
}
}
// Merge styles to the SASS file
if ( !function_exists( 'trx_addons_merge_sass' ) ) {
function trx_addons_merge_sass($to, $list, $need_responsive=false, $root='../') {
global $TRX_ADDONS_STORAGE;
$responsive = $TRX_ADDONS_STORAGE['responsive'];
if ($need_responsive) $responsive = apply_filters('trx_addons_filter_responsive_sizes', $responsive);
$sass = array(
'import' => '',
'sizes' => array()
);
$save = false;
foreach ($list as $f) {
$add = false;
if (($fdir = trx_addons_get_file_dir($f)) != '') {
if ($need_responsive) {
$css = trx_addons_fgc($fdir);
if (strpos($css, '@required')!==false) $add = true;
foreach ($responsive as $k=>$v) {
if (preg_match("/([\d\w\-_]+--{$k})\(/", $css, $matches)) {
$sass['sizes'][$k] = (!empty($sass['sizes'][$k]) ? $sass['sizes'][$k] : '') . "\t@include {$matches[1]}();\n";
$add = true;
}
}
} else
$add = true;
}
if ($add) {
$sass['import'] .= apply_filters('trx_addons_filter_sass_import', "@import \"{$root}{$f}\";\n", $f);
$save = true;
}
}
if ($save) {
$output = '/* '
. strip_tags( __("ATTENTION! This file was generated automatically! Don't change it!!!", 'trx_addons') )
. "\n----------------------------------------------------------------------- */\n"
. $sass['import'];
if ($need_responsive) {
foreach ($responsive as $k => $v) {
if (!empty($sass['sizes'][$k])) {
$output .= "\n\n"
. strip_tags( sprintf( __("/* SASS Suffix: --%s */", 'trx_addons'), $k) )
. "\n"
. "@media " . (!empty($v['min']) ? "(min-width: {$v['min']}px)" : '')
. (!empty($v['min']) && !empty($v['max']) ? ' and ' : '')
. (!empty($v['max']) ? "(max-width: {$v['max']}px)" : '')
. " {\n"
. $sass['sizes'][$k]
. "}\n";
}
}
}
trx_addons_fpc(
trx_addons_get_file_dir($to),
apply_filters( 'trx_addons_filter_sass_output', $output, $to )
);
}
}
}
/* Check if file/folder present in the child theme and return path (url) to it.
Else - path (url) to file in the main theme dir
------------------------------------------------------------------------------------- */
if (!function_exists('trx_addons_get_file_dir')) {
function trx_addons_get_file_dir($file, $return_url=false) {
if ($file[0]=='/') $file = substr($file, 1);
$theme_dir = get_template_directory().'/'.TRX_ADDONS_PLUGIN_BASE.'/';
$theme_url = get_template_directory_uri().'/'.TRX_ADDONS_PLUGIN_BASE.'/';
$child_dir = get_stylesheet_directory().'/'.TRX_ADDONS_PLUGIN_BASE.'/';
$child_url = get_stylesheet_directory_uri().'/'.TRX_ADDONS_PLUGIN_BASE.'/';
$dir = '';
if (($filtered_dir = apply_filters('trx_addons_filter_get_theme_file_dir', '', TRX_ADDONS_PLUGIN_BASE.'/'.($file), $return_url)) != '')
$dir = $filtered_dir;
else if ($theme_dir != $child_dir && file_exists(($child_dir).($file)))
$dir = ($return_url ? $child_url : $child_dir) . trx_addons_check_min_file($file, $child_dir);
else if (file_exists(($theme_dir).($file)))
$dir = ($return_url ? $theme_url : $theme_dir) . trx_addons_check_min_file($file, $theme_dir);
else if (file_exists(TRX_ADDONS_PLUGIN_DIR . ($file)))
$dir = ($return_url ? TRX_ADDONS_PLUGIN_URL : TRX_ADDONS_PLUGIN_DIR) . trx_addons_check_min_file($file, TRX_ADDONS_PLUGIN_DIR);
return apply_filters( 'trx_addons_filter_get_file_dir', $dir, $file, $return_url );
}
}
if (!function_exists('trx_addons_get_file_url')) {
function trx_addons_get_file_url($file) {
return trx_addons_get_file_dir($file, true);
}
}
// Return file extension from full name/path
if (!function_exists('trx_addons_get_file_ext')) {
function trx_addons_get_file_ext($file) {
$ext = pathinfo($file, PATHINFO_EXTENSION);
return empty($ext) ? '' : $ext;
}
}
// Return file name from full name/path
if (!function_exists('trx_addons_get_file_name')) {
function trx_addons_get_file_name($file, $without_ext=true) {
$parts = pathinfo($file);
return !empty($parts['filename']) && $without_ext ? $parts['filename'] : $parts['basename'];
}
}
// Detect folder location (in the child theme or in the main theme)
if (!function_exists('trx_addons_get_folder_dir')) {
function trx_addons_get_folder_dir($folder, $return_url=false) {
if ($folder[0]=='/') $folder = substr($folder, 1);
$theme_dir = get_template_directory().'/'.TRX_ADDONS_PLUGIN_BASE.'/';
$theme_url = get_template_directory_uri().'/'.TRX_ADDONS_PLUGIN_BASE.'/';
$child_dir = get_stylesheet_directory().'/'.TRX_ADDONS_PLUGIN_BASE.'/';
$child_url = get_stylesheet_directory_uri().'/'.TRX_ADDONS_PLUGIN_BASE.'/';
$dir = '';
if (($filtered_dir = apply_filters('trx_addons_filter_get_theme_folder_dir', '', TRX_ADDONS_PLUGIN_BASE.'/'.($folder), $return_url)) != '')
$dir = $filtered_dir;
else if ($theme_dir != $child_dir && is_dir(($child_dir).($folder)))
$dir = ($return_url ? $child_url : $child_dir).($folder);
else if (is_dir(($theme_dir).($folder)))
$dir = ($return_url ? $theme_url : $theme_dir).($folder);
else if (is_dir((TRX_ADDONS_PLUGIN_DIR).($folder)))
$dir = ($return_url ? TRX_ADDONS_PLUGIN_URL : TRX_ADDONS_PLUGIN_DIR).($folder);
return apply_filters( 'trx_addons_filter_get_folder_dir', $dir, $folder, $return_url );
}
}
if (!function_exists('trx_addons_get_folder_url')) {
function trx_addons_get_folder_url($folder) {
return trx_addons_get_folder_dir($folder, true);
}
}
// Get domain part from URL
if (!function_exists('trx_addons_get_domain_from_url')) {
function trx_addons_get_domain_from_url($url) {
if (($pos=strpos($url, '//'))!==false) $url = substr($url, $pos+2);
if (($pos=strpos($url, '/'))!==false) $url = substr($url, 0, $pos);
return $url;
}
}
// Return .min version (if exists and filetime .min > filetime original) instead original
if (!function_exists('trx_addons_check_min_file')) {
function trx_addons_check_min_file($file, $dir) {
if (substr($file, -3)=='.js') {
if (substr($file, -7)!='.min.js' && trx_addons_is_off(trx_addons_get_option('debug_mode', false, false))) {
$dir = trailingslashit($dir);
$file_min = substr($file, 0, strlen($file)-3).'.min.js';
if (file_exists($dir . $file_min) && filemtime($dir . $file) <= filemtime($dir . $file_min)) $file = $file_min;
}
} else if (substr($file, -4)=='.css') {
if (substr($file, -8)!='.min.css' && trx_addons_is_off(trx_addons_get_option('debug_mode', false, false))) {
$dir = trailingslashit($dir);
$file_min = substr($file, 0, strlen($file)-4).'.min.css';
if (file_exists($dir . $file_min) && filemtime($dir . $file) <= filemtime($dir . $file_min)) $file = $file_min;
}
}
return $file;
}
}
/* Init WP Filesystem before the plugins and theme init
------------------------------------------------------------------- */
if (!function_exists('trx_addons_init_filesystem')) {
add_action( 'after_setup_theme', 'trx_addons_init_filesystem', 0);
function trx_addons_init_filesystem() {
if( !function_exists('WP_Filesystem') ) {
require_once trailingslashit(ABSPATH) . 'wp-admin/includes/file.php';
}
if (is_admin()) {
$url = admin_url();
$creds = false;
// First attempt to get credentials.
if ( function_exists('request_filesystem_credentials') && false === ( $creds = request_filesystem_credentials( $url, '', false, false, array() ) ) ) {
// If we comes here - we don't have credentials
// so the request for them is displaying no need for further processing
return false;
}
// Now we got some credentials - try to use them.
if ( !WP_Filesystem( $creds ) ) {
// Incorrect connection data - ask for credentials again, now with error message.
if ( function_exists('request_filesystem_credentials') ) request_filesystem_credentials( $url, '', true, false );
return false;
}
return true; // Filesystem object successfully initiated.
} else {
WP_Filesystem();
}
return true;
}
}
if ( ! function_exists('trx_addons_prepare_path')) {
/**
* Replace '\' with '/' in the file/folder path
*
* @param string $name File/folder path
*
* @return string Safe path
*/
function trx_addons_prepare_path( $name ) {
return str_replace( '\\', defined( 'DIRECTORY_SEPARATOR' ) ? DIRECTORY_SEPARATOR : '/', trim( $name ) );
}
}
if ( ! function_exists( 'trx_addons_unzip_file' ) ) {
/**
* Init a $wp_filesystem ( if need ) and unzip file
*
* @param string $zip path to zip file
* @param string $dest path to destination folder
*
* @return bool true if success
*/
function trx_addons_unzip_file( $zip, $dest ) {
global $wp_filesystem;
if ( empty( $wp_filesystem ) || ! is_object( $wp_filesystem ) ) {
trx_addons_init_filesystem( true );
}
return unzip_file( $zip, $dest );
}
}
// Put data into specified file
if ( ! function_exists( 'trx_addons_fpc' ) ) {
/**
* Put data to the specified file
*
* @param string $file File name (or path relative to the theme folder)
* @param string $data Data to put into the file
* @param int $flag Flag to modify the behavior of the function
*
* @return int Number of bytes that were written to the file, or false on failure.
*/
function trx_addons_fpc( $file, $data, $flag = 0 ) {
if ( ! empty( $file ) ) {
$file = trx_addons_prepare_path( $file );
return file_put_contents( $file, $data, $flag );
}
return false;
}
}
// Get text from specified file
if ( ! function_exists( 'trx_addons_fgc' ) ) {
/**
* Get content of the specified file
*
* @param string $file File name (or path relative to the theme folder)
* @param bool $unpack Unpack data after get it from file
*
* @return string Content of the file
*/
function trx_addons_fgc( $file, $unpack = false ) {
$tmp_cont = '';
if ( ! empty( $file ) ) {
if ( trx_addons_is_url( $file ) ) { //&& ! $allow_url_fopen
$tmp_cont = trx_addons_remote_get( $file );
} else {
$file = trx_addons_prepare_path( $file );
if ( file_exists( $file ) ) {
$tmp_cont = file_get_contents( $file );
}
}
}
if ( ! empty( $tmp_cont ) && $unpack && trx_addons_get_file_ext( $file ) == 'zip' ) {
$tmp_name = 'tmp-'.rand().'.zip';
$tmp = wp_upload_bits( $tmp_name, null, $tmp_cont );
if ( $tmp['error'] ) {
$tmp_cont = '';
} else {
trx_addons_unzip_file( $tmp['file'], dirname( $tmp['file'] ) );
$file_name = trailingslashit( dirname( $tmp['file'] ) ) . basename( $file, '.zip' ) . '.txt';
$tmp_cont = trx_addons_fgc( $file_name );
unlink( $tmp['file'] );
unlink( $file_name );
}
}
return $tmp_cont;
}
}
// Get array with rows from specified file
if ( ! function_exists( 'trx_addons_fga' ) ) {
/**
* Get array with rows from specified file
*
* @param string $file File name (or path relative to the theme folder)
*
* @return array Array with rows from the file
*/
function trx_addons_fga( $file ) {
if ( ! empty( $file ) ) {
$file = trx_addons_prepare_path( $file );
if ( file_exists( $file ) ) {
return file( $file );
}
}
return array();
}
}
// Get text from specified file via HTTP (cURL)
if (!function_exists('trx_addons_remote_get')) {
function trx_addons_remote_get($file, $timeout=-1) {
// Set timeout as half of the PHP execution time
if ($timeout < 1) $timeout = round( 0.5 * max(30, ini_get('max_execution_time')));
if (substr($file, 0, 2) == '//') $file = trx_addons_get_protocol() . ':' . $file;
$response = wp_remote_get($file, array(
'method' => 'GET',
'timeout' => $timeout
)
);
return !is_wp_error($response) && isset($response['response']['code']) && $response['response']['code']==200
? $response['body']
: '';
}
}
// Get text from specified file via HTTP (cURL)
if (!function_exists('trx_addons_remote_post')) {
function trx_addons_remote_post($file, $args, $timeout=-1) {
// Set timeout as half of the PHP execution time
if ($timeout < 1) $timeout = round( 0.5 * max(30, ini_get('max_execution_time')));
if (substr($file, 0, 2) == '//') $file = trx_addons_get_protocol() . ':' . $file;
$response = wp_remote_post($file, array(
'method' => 'POST',
'timeout' => $timeout,
'body' => $args
)
);
return !is_wp_error($response) && isset($response['response']['code']) && $response['response']['code']==200 ? $response['body'] : '';
}
}
// Get JSON from specified url via HTTP (cURL) and return object or null
if (!function_exists('trx_addons_retrieve_json')) {
add_filter( 'trx_addons_filter_retrieve_json', 'trx_addons_retrieve_json' );
function trx_addons_retrieve_json($url) {
$data = '';
$resp = trim( trx_addons_remote_get($url) );
if ( in_array( substr($resp, 0, 1), array( '{', '[' ) ) ) {
$data = json_decode($resp, true);
}
return $data;
}
}
// Remove unsafe characters from file/folder path
if ( ! function_exists( 'trx_addons_esc' ) ) {
/**
* Remove unsafe characters from file/folder path
*
* @param string $name File/folder path
* @param bool $local If true - remove only unsafe characters, but not ':'
*
* @return string Safe path
*/
function trx_addons_esc( $name, $local = false ) {
return str_replace(
array_merge( array( '\\', '~', '$', ';', '+', '>', '<', '|', '"', "'", '`', "\xFF", "\x0A", "\x0D", '*', '?', '^' ), ! $local ? array( ':' ) : array() ),
defined( 'DIRECTORY_SEPARATOR' ) ? DIRECTORY_SEPARATOR : '/',
trim( $name )
);
}
}
if ( ! function_exists( 'trx_addons_url_to_local_path' ) ) {
/**
* Convert URL to local path
*
* @param string $url URL to convert
*
* @return string Local path
*/
function trx_addons_url_to_local_path( $url ) {
$path = '';
// Remove scheme from url
$url = trx_addons_remove_protocol( $url );
// Get upload path & dir
$upload_info = wp_upload_dir();
// Where check file
$locations = array(
'uploads' => array(
'dir' => $upload_info['basedir'],
'url' => trx_addons_remove_protocol($upload_info['baseurl'])
),
'child' => array(
'dir' => get_stylesheet_directory(),
'url' => trx_addons_remove_protocol(get_stylesheet_directory_uri())
),
'theme' => array(
'dir' => get_template_directory(),
'url' => trx_addons_remove_protocol(get_template_directory_uri())
)
);
// Find a file in locations
foreach( $locations as $key => $loc ) {
// Check if $url is in location
if ( false === strpos( $url, $loc['url'] ) ) continue;
// Get a path from the URL
$path = str_replace( $loc['url'], $loc['dir'], $url );
// Check if a file exists
if ( file_exists( $path ) ) {
break;
}
$path = '';
}
return $path;
}
}
if ( ! function_exists( 'trx_addons_sanitize_file_name' ) ) {
/**
* Remove unsafe characters from the file name
*
* @param string $name File name
*
* @return string Safe name
*/
function trx_addons_sanitize_file_name( $name ) {
return sanitize_file_name( (string)$name );
}
}