Skip to content

Commit

Permalink
Move deprecated functions to a separate file (#1311)
Browse files Browse the repository at this point in the history
These functions do not carry the logical load of the code in the files.
Most of these functions should be removed in next major release (version 4).
  • Loading branch information
homeandriy authored Apr 7, 2023
1 parent c4b59d8 commit ba8e615
Show file tree
Hide file tree
Showing 10 changed files with 321 additions and 314 deletions.
8 changes: 0 additions & 8 deletions src/admin/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -552,14 +552,6 @@ function qtranxf_get_admin_highlight_css( $highlight_mode ) {
return $css;
}

function qtranxf_add_admin_css() {
_deprecated_function( __FUNCTION__, '3.14.0', 'qtranxf_admin_enqueue_scripts' );
}

function qtranxf_admin_head() {
_deprecated_function( __FUNCTION__, '3.10.0', 'qtranxf_admin_enqueue_scripts' );
}

function qtranxf_admin_enqueue_scripts() {
global $q_config;
wp_register_style( 'qtranslate-admin', plugins_url( 'css/admin.css', QTRANSLATE_FILE ), array(), QTX_VERSION );
Expand Down
5 changes: 0 additions & 5 deletions src/admin/admin_options.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ function qtranxf_admin_set_default_options( &$options ) {
$options = apply_filters( 'qtranslate_option_config_admin', $options );
}

function qtranxf_admin_loadConfig() {
_deprecated_function( __FUNCTION__, '3.10.0', 'qtranxf_admin_load_config' );
qtranxf_admin_load_config();
}

function qtranxf_admin_load_config() {
global $q_config, $qtranslate_options;
qtranxf_admin_set_default_options( $qtranslate_options );
Expand Down
40 changes: 0 additions & 40 deletions src/admin/admin_options_update.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@
require_once QTRANSLATE_DIR . '/src/admin/import_export.php';
require_once QTRANSLATE_DIR . '/src/modules/admin_module_manager.php';

function qtranxf_editConfig() {
_deprecated_function( __FUNCTION__, '3.10.0', 'qtranxf_edit_config' );
qtranxf_edit_config();
}

function qtranxf_edit_config() {
global $q_config;
if ( ! qtranxf_verify_nonce( 'qtranslate-x_configuration_form' ) ) {
Expand Down Expand Up @@ -316,11 +311,6 @@ function qtranxf_edit_config() {
}
}

function qtranxf_resetConfig() {
_deprecated_function( __FUNCTION__, '3.10.0', 'qtranxf_admin_reset_config' );
qtranxf_reset_config();
}

function qtranxf_reset_config() {
global $qtranslate_options;

Expand Down Expand Up @@ -429,11 +419,6 @@ function qtranxf_update_option_bool( $nm, $default_value = null ) {
}
}

function qtranxf_saveConfig() {
_deprecated_function( __FUNCTION__, '3.10.0', 'qtranxf_save_config' );
qtranxf_save_config();
}

/**
* saves entire configuration
*/
Expand Down Expand Up @@ -499,11 +484,6 @@ function qtranxf_save_config() {
do_action_deprecated( 'qtranslate_saveConfig', array(), '3.10.0', 'qtranslate_save_config' );
}

function qtranxf_reloadConfig() {
_deprecated_function( __FUNCTION__, '3.10.0', 'qtranxf_reload_config' );
qtranxf_reload_config();
}

function qtranxf_reload_config() {
global $q_config;
$url_info = $q_config['url_info'] ?? null;
Expand All @@ -522,11 +502,6 @@ function qtranxf_reload_config() {
qtranxf_load_option_qtrans_compatibility();
}

function qtranxf_updateSetting( $var, $type = QTX_STRING, $def = null ) {
_deprecated_function( __FUNCTION__, '3.10.0', 'qtranxf_update_setting' );
qtranxf_update_setting( $var, $type, $def );
}

function qtranxf_update_setting( $var, $type = QTX_STRING, $def = null ) {
global $q_config, $qtranslate_options;
if ( ! isset( $_POST['submit'] ) ) {
Expand Down Expand Up @@ -697,11 +672,6 @@ function qtranxf_update_i18n_config() {
}
}

function qtranxf_updateSettingFlagLocation( $name ) {
_deprecated_function( __FUNCTION__, '3.10.0', 'qtranxf_update_setting_flag_location' );
qtranxf_update_setting_flag_location( $name );
}

function qtranxf_update_setting_flag_location( $nm ) {
global $q_config;
if ( ! isset( $_POST['submit'] ) ) {
Expand Down Expand Up @@ -730,11 +700,6 @@ function qtranxf_update_setting_flag_location( $nm ) {
return true;
}

function qtranxf_updateSettingIgnoreFileTypes( $name ) {
_deprecated_function( __FUNCTION__, '3.10.0', 'qtranxf_update_setting_ignore_file_types' );
qtranxf_update_setting_ignore_file_types( $name );
}

function qtranxf_update_setting_ignore_file_types( $name ) {
global $q_config;
if ( ! isset( $_POST['submit'] ) ) {
Expand Down Expand Up @@ -789,11 +754,6 @@ function qtranxf_parse_post_type_excluded() {
return true;
}

function qtranxf_updateSettings() {
_deprecated_function( __FUNCTION__, '3.10.0', 'qtranxf_update_settings' );
qtranxf_update_settings();
}

function qtranxf_update_settings() {
global $qtranslate_options, $q_config;

Expand Down
73 changes: 0 additions & 73 deletions src/admin/admin_utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,6 @@ function qtranxf_ensure_language_set( &$langs, $lang, $default_value = null ) {
return '';
}

function qtranxf_getLanguageEdit() {
_deprecated_function( __FUNCTION__, '3.10.0', 'qtranxf_get_edit_language' );
qtranxf_get_edit_language();
}

function qtranxf_get_edit_language() {
global $q_config;

Expand Down Expand Up @@ -258,34 +253,6 @@ function qtranxf_language_column( $column ) {
return $column;
}

function qtranxf_fetch_file_selection( $dir, $suffix = '.css' ) {
_deprecated_function( __FUNCTION__, '3.14.0' );
$files = array();
$dir_handle = @opendir( $dir );
if ( ! $dir_handle ) {
return false;
}
while ( false !== ( $file = readdir( $dir_handle ) ) ) {
if ( ! qtranxf_endsWith( $file, $suffix ) ) {
continue;
}
$name = basename( $file, $suffix );
if ( ! $name ) {
continue;
}
$name = str_replace( '_', ' ', $name );
if ( qtranxf_endsWith( $name, '.min' ) ) {
$name = substr( $name, -4 );
$files[ $name ] = $file;
} elseif ( ! isset( $files[ $name ] ) ) {
$files[ $name ] = $file;
}
}
ksort( $files );

return $files;
}

function qtranxf_before_admin_bar_render() {
global $wp_admin_bar, $q_config;
if ( ! isset( $wp_admin_bar ) ) {
Expand Down Expand Up @@ -340,28 +307,6 @@ function qtranxf_trim_words( $text, $num_words, $more, $original_text ) {
}
}

/* @since 3.3.8.7 use filter 'admin_title' instead
* function qtranxf_filter_options_general($value){
* global $q_config;
* global $pagenow;
* switch($pagenow){
* case 'options-general.php':
* case 'customize.php'://there is more work to do for this case
* return $value;
* default: break;
* }
* $lang = $q_config['language'];
* return qtranxf_use_language($lang,$value,false,false);
* }
* add_filter('option_blogname', 'qtranxf_filter_options_general');
* add_filter('option_blogdescription', 'qtranxf_filter_options_general');
*/

function qtranxf_updateGettextDatabases( $force = false, $only_for_language = '' ) {
_deprecated_function( __FUNCTION__, '3.10.0', 'qtranxf_update_gettext_databases' );
qtranxf_update_gettext_databases( $force, $only_for_language );
}

function qtranxf_update_gettext_databases( $force = false, $only_for_language = '' ) {
require_once QTRANSLATE_DIR . '/src/admin/update_gettext_db.php';

Expand Down Expand Up @@ -447,24 +392,6 @@ function qtranxf_post_type_optional( $post_type ) {
return ! in_array( $post_type, [ 'revision', 'nav_menu_item' ] );
}

function qtranxf_json_encode( $o ) {
_deprecated_function( __FUNCTION__, '3.10.0' );
return json_encode( $o, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES );
}

/**
* @since 3.4
* return reference to $page_config['forms'][$name]['fields']
*/
function qtranxf_config_add_form( &$page_config, $name ) {
_deprecated_function( __FUNCTION__, '3.10.0' );
if ( ! isset( $page_config['forms'][ $name ] ) ) {
$page_config['forms'][ $name ] = array( 'fields' => array() );
} else if ( ! isset( $page_config['forms'][ $name ]['fields'] ) ) {
$page_config['forms'][ $name ]['fields'] = array();
}
}

/**
* @param string $nonce_name Name specified when generating the nonce
* @param string $nonce_field Form input name for the nonce
Expand Down
5 changes: 0 additions & 5 deletions src/admin/update_gettext_db.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
exit;
}

function qtranxf_updateGettextDatabasesEx( $force = false, $only_for_language = '' ) {
_deprecated_function( __FUNCTION__, '3.10.0', 'qtranxf_update_gettext_databases_ex' );
qtranxf_update_gettext_databases_ex( $force, $only_for_language );
}

/**
* return 'true', if no update needed,
* or 'false', if update is impossible to do,
Expand Down
135 changes: 0 additions & 135 deletions src/date_time.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,19 +271,6 @@ function qtranxf_convert_date_format_to_strftime_format( $format ) {
return stripslashes( $format );
}

/**
* [Legacy] Converter of a format given in DateTime format, transformed to the extended "QTX-strftime" format.
*
* @param string $format in DateTime format.
*
* @return string
* @deprecated Use qtranxf_convert_date_format_to_strftime_format.
*/
function qtranxf_convertDateFormatToStrftimeFormat( $format ) {
_deprecated_function( __FUNCTION__, '3.13.0', 'qtranxf_convert_date_format_to_strftime_format' );
return qtranxf_convert_date_format_to_strftime_format( $format );
}

/**
* Converter of a format/default pair to "QTX-strftime" format, applying 'use_strftime' configuration.
*
Expand Down Expand Up @@ -322,20 +309,6 @@ function qtranxf_convert_to_strftime_format_using_config( $format, $default_form
}
}

/**
* [Legacy] Converter of a format/default pair to "QTX-strftime" format, applying 'use_strftime' configuration.
*
* @param string $format ATTENTION - always given in date PHP format.
* @param string $default_format , following the strftime configuration.
*
* @return string
* @deprecated Use qtranxf_convert_to_strftime_format_using_config.
*/
function qtranxf_convertFormat( $format, $default_format ) {
_deprecated_function( __FUNCTION__, '3.13.0', 'qtranxf_convert_to_strftime_format_using_config' );
return qtranxf_convert_to_strftime_format_using_config( $format, $default_format );
}

/**
* Return the date or time format set for the current language config or default language.
*
Expand All @@ -355,114 +328,6 @@ function qtranxf_get_language_date_or_time_format( $config_key ) {
}
}

/**
* [Legacy] Converter of a date format to "QTX-strftime" format, applying qTranslate 'use_strftime' configuration.
*
* @param string $format
*
* @return string
* @deprecated Use qtranxf_get_language_date_or_time_format.
*/
function qtranxf_convertDateFormat( $format ) {
_deprecated_function( __FUNCTION__, '3.13.0', 'qtranxf_get_language_date_or_time_format' );
$default_format = qtranxf_get_language_date_or_time_format( 'date_format' );
return qtranxf_convertFormat( $format, $default_format );
}

/**
* [Legacy] Converter of a time format to "QTX-strftime" format, applying qTranslate 'use_strftime' configuration.
*
* @param string $format
*
* @return string
* @deprecated Use qtranxf_get_language_date_or_time_format.
*/
function qtranxf_convertTimeFormat( $format ) {
_deprecated_function( __FUNCTION__, '3.13.0', 'qtranxf_get_language_date_or_time_format' );
$default_format = qtranxf_get_language_date_or_time_format( 'time_format' );
return qtranxf_convertFormat( $format, $default_format );
}

/**
* [Legacy] Extension of PHP "QTX-strftime", valid up to PHP 8.0.
*
* @param string $format extended strftime with additional features such as %q
* @param int $date timestamp
* @param string $default Default result when $format is empty.
* @param string $before Text copied before result.
* @param string $after Text copied after result.
*
* @return mixed|string
* @deprecated Use qxtranxf_intl_strftime, since strftime is deprecated from PHP8.1.
* @See https://www.php.net/manual/en/function.strftime.php
*/
function qtranxf_strftime( $format, $date, $default = '', $before = '', $after = '' ) {
_deprecated_function( __FUNCTION__, '3.13.0', 'qxtranxf_intl_strftime' );

if ( empty( $format ) ) {
return $default;
}

// add date suffix ability (%q) to strftime
$day = intval( ltrim( strftime( "%d", $date ), '0' ) );
$search = array();
$replace = array();

// date S
$search[] = '/(([^%])%q|^%q)/';
if ( $day == 1 || $day == 21 || $day == 31 ) {
$replace[] = '$2st';
} elseif ( $day == 2 || $day == 22 ) {
$replace[] = '$2nd';
} elseif ( $day == 3 || $day == 23 ) {
$replace[] = '$2rd';
} else {
$replace[] = '$2th';
}

$search[] = '/(([^%])%E|^%E)/';
$replace[] = '${2}' . $day; // date j
$search[] = '/(([^%])%f|^%f)/';
$replace[] = '${2}' . date( 'w', $date ); // date w
$search[] = '/(([^%])%F|^%F)/';
$replace[] = '${2}' . date( 'z', $date ); // date z
$search[] = '/(([^%])%i|^%i)/';
$replace[] = '${2}' . date( 'n', $date ); // date n
$search[] = '/(([^%])%J|^%J)/';
$replace[] = '${2}' . date( 't', $date ); // date t
$search[] = '/(([^%])%k|^%k)/';
$replace[] = '${2}' . date( 'L', $date ); // date L
$search[] = '/(([^%])%K|^%K)/';
$replace[] = '${2}' . date( 'B', $date ); // date B
$search[] = '/(([^%])%l|^%l)/';
$replace[] = '${2}' . date( 'g', $date ); // date g
$search[] = '/(([^%])%L|^%L)/';
$replace[] = '${2}' . date( 'G', $date ); // date G
$search[] = '/(([^%])%N|^%N)/';
$replace[] = '${2}' . date( 'u', $date ); // date u
$search[] = '/(([^%])%Q|^%Q)/';
$replace[] = '${2}' . date( 'e', $date ); // date e
$search[] = '/(([^%])%o|^%o)/';
$replace[] = '${2}' . date( 'I', $date ); // date I
$search[] = '/(([^%])%O|^%O)/';
$replace[] = '${2}' . date( 'O', $date ); // date O
$search[] = '/(([^%])%s|^%s)/';
$replace[] = '${2}' . date( 'P', $date ); // date P
$search[] = '/(([^%])%v|^%v)/';
$replace[] = '${2}' . date( 'T', $date ); // date T
$search[] = '/(([^%])%1|^%1)/';
$replace[] = '${2}' . date( 'Z', $date ); // date Z
$search[] = '/(([^%])%2|^%2)/';
$replace[] = '${2}' . date( 'c', $date ); // date c
$search[] = '/(([^%])%3|^%3)/';
$replace[] = '${2}' . date( 'r', $date ); // date r
$search[] = '/(([^%])%4|^%4)/';
$replace[] = '${2}' . $date; // date U
$format = preg_replace( $search, $replace, $format );

return $before . strftime( $format, $date ) . $after;
}

/**
* [Legacy] Generalized formatting of a date, applying qTranslate 'use_strftime' config.
*
Expand Down
Loading

0 comments on commit ba8e615

Please sign in to comment.