Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/advanced.../classes
File: class-translation-promo.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Translation_Promo.
[2] Fix | Delete
*
[3] Fix | Delete
* @package AdvancedAds
[4] Fix | Delete
* @author Advanced Ads <info@wpadvancedads.com>
[5] Fix | Delete
* @since 1.45.0
[6] Fix | Delete
*/
[7] Fix | Delete
[8] Fix | Delete
defined( 'ABSPATH' ) || exit;
[9] Fix | Delete
[10] Fix | Delete
/**
[11] Fix | Delete
* This class defines a promo box and checks your translation site's API for stats about it.
[12] Fix | Delete
*
[13] Fix | Delete
* @copyright Yoast i18n https://github.com/Yoast/i18n-module
[14] Fix | Delete
*/
[15] Fix | Delete
class Translation_Promo {
[16] Fix | Delete
/**
[17] Fix | Delete
* Your translation site's logo.
[18] Fix | Delete
*
[19] Fix | Delete
* @var string
[20] Fix | Delete
*/
[21] Fix | Delete
private $glotpress_logo;
[22] Fix | Delete
[23] Fix | Delete
/**
[24] Fix | Delete
* Your translation site's name.
[25] Fix | Delete
*
[26] Fix | Delete
* @var string
[27] Fix | Delete
*/
[28] Fix | Delete
private $glotpress_name;
[29] Fix | Delete
[30] Fix | Delete
/**
[31] Fix | Delete
* Your translation site's URL.
[32] Fix | Delete
*
[33] Fix | Delete
* @var string
[34] Fix | Delete
*/
[35] Fix | Delete
private $glotpress_url;
[36] Fix | Delete
[37] Fix | Delete
/**
[38] Fix | Delete
* The URL to actually do the API request to.
[39] Fix | Delete
*
[40] Fix | Delete
* @var string
[41] Fix | Delete
*/
[42] Fix | Delete
private $api_url;
[43] Fix | Delete
[44] Fix | Delete
/**
[45] Fix | Delete
* Hook where you want to show the promo box.
[46] Fix | Delete
*
[47] Fix | Delete
* @var string
[48] Fix | Delete
*/
[49] Fix | Delete
private $hook;
[50] Fix | Delete
[51] Fix | Delete
/**
[52] Fix | Delete
* Will contain the site's locale.
[53] Fix | Delete
*
[54] Fix | Delete
* @access private
[55] Fix | Delete
* @var string
[56] Fix | Delete
*/
[57] Fix | Delete
private $locale;
[58] Fix | Delete
[59] Fix | Delete
/**
[60] Fix | Delete
* Will contain the locale's name, obtained from your translation site.
[61] Fix | Delete
*
[62] Fix | Delete
* @access private
[63] Fix | Delete
* @var string
[64] Fix | Delete
*/
[65] Fix | Delete
private $locale_name;
[66] Fix | Delete
[67] Fix | Delete
/**
[68] Fix | Delete
* Will contain the percentage translated for the plugin translation project in the locale.
[69] Fix | Delete
*
[70] Fix | Delete
* @access private
[71] Fix | Delete
* @var int
[72] Fix | Delete
*/
[73] Fix | Delete
private $percent_translated;
[74] Fix | Delete
[75] Fix | Delete
/**
[76] Fix | Delete
* Name of your plugin.
[77] Fix | Delete
*
[78] Fix | Delete
* @var string
[79] Fix | Delete
*/
[80] Fix | Delete
private $plugin_name;
[81] Fix | Delete
[82] Fix | Delete
/**
[83] Fix | Delete
* Project slug for the project on your translation site.
[84] Fix | Delete
*
[85] Fix | Delete
* @var string
[86] Fix | Delete
*/
[87] Fix | Delete
private $project_slug;
[88] Fix | Delete
[89] Fix | Delete
/**
[90] Fix | Delete
* URL to point to for registration links.
[91] Fix | Delete
*
[92] Fix | Delete
* @var string
[93] Fix | Delete
*/
[94] Fix | Delete
private $register_url;
[95] Fix | Delete
[96] Fix | Delete
/**
[97] Fix | Delete
* Your plugins textdomain.
[98] Fix | Delete
*
[99] Fix | Delete
* @var string
[100] Fix | Delete
*/
[101] Fix | Delete
private $textdomain;
[102] Fix | Delete
[103] Fix | Delete
/**
[104] Fix | Delete
* Indicates whether there's a translation available at all.
[105] Fix | Delete
*
[106] Fix | Delete
* @access private
[107] Fix | Delete
* @var bool
[108] Fix | Delete
*/
[109] Fix | Delete
private $translation_exists;
[110] Fix | Delete
[111] Fix | Delete
/**
[112] Fix | Delete
* Indicates whether the translation's loaded.
[113] Fix | Delete
*
[114] Fix | Delete
* @access private
[115] Fix | Delete
* @var bool
[116] Fix | Delete
*/
[117] Fix | Delete
private $translation_loaded;
[118] Fix | Delete
[119] Fix | Delete
/**
[120] Fix | Delete
* Constructs the i18n module for wordpress.org.
[121] Fix | Delete
*
[122] Fix | Delete
* Required fields are the 'textdomain', 'plugin_name' and 'hook'.
[123] Fix | Delete
*
[124] Fix | Delete
* @param array $args The settings for the i18n module.
[125] Fix | Delete
* @param bool $show_translation_box Whether the translation box should be shown.
[126] Fix | Delete
*/
[127] Fix | Delete
public function __construct( $args, $show_translation_box = true ) {
[128] Fix | Delete
if ( ! is_admin() ) {
[129] Fix | Delete
return;
[130] Fix | Delete
}
[131] Fix | Delete
[132] Fix | Delete
$args = $this->set_defaults( $args );
[133] Fix | Delete
$this->locale = $this->get_admin_locale();
[134] Fix | Delete
if ( $this->is_default_language( $this->locale ) ) {
[135] Fix | Delete
return;
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
$this->init( $args );
[139] Fix | Delete
[140] Fix | Delete
if ( $show_translation_box ) {
[141] Fix | Delete
add_action( $this->hook, array( $this, 'promo' ) );
[142] Fix | Delete
}
[143] Fix | Delete
[144] Fix | Delete
$this->set_api_url( $args['textdomain'] );
[145] Fix | Delete
}
[146] Fix | Delete
[147] Fix | Delete
/**
[148] Fix | Delete
* Returns whether the language is en_US.
[149] Fix | Delete
*
[150] Fix | Delete
* @param string $language The language to check.
[151] Fix | Delete
*
[152] Fix | Delete
* @return bool Returns true if the language is en_US.
[153] Fix | Delete
*/
[154] Fix | Delete
protected function is_default_language( $language ) {
[155] Fix | Delete
return 'en_US' === $language;
[156] Fix | Delete
}
[157] Fix | Delete
[158] Fix | Delete
/**
[159] Fix | Delete
* Returns the locale used in the admin.
[160] Fix | Delete
*
[161] Fix | Delete
* WordPress 4.7 introduced the ability for users to specify an Admin language
[162] Fix | Delete
* different from the language used on the front end. This checks if the feature
[163] Fix | Delete
* is available and returns the user's language, with a fallback to the site's language.
[164] Fix | Delete
* Can be removed when support for WordPress 4.6 will be dropped, in favor
[165] Fix | Delete
* of WordPress get_user_locale() that already fallbacks to the site’s locale.
[166] Fix | Delete
*
[167] Fix | Delete
* @returns string The locale.
[168] Fix | Delete
*/
[169] Fix | Delete
private function get_admin_locale() {
[170] Fix | Delete
if ( function_exists( 'get_user_locale' ) ) {
[171] Fix | Delete
return get_user_locale();
[172] Fix | Delete
}
[173] Fix | Delete
[174] Fix | Delete
return get_locale();
[175] Fix | Delete
}
[176] Fix | Delete
[177] Fix | Delete
/**
[178] Fix | Delete
* This is where you decide where to display the messages and where you set the plugin specific variables.
[179] Fix | Delete
*
[180] Fix | Delete
* @access private
[181] Fix | Delete
*
[182] Fix | Delete
* @param array $args Contains the settings for the class.
[183] Fix | Delete
*/
[184] Fix | Delete
private function init( $args ) {
[185] Fix | Delete
foreach ( $args as $key => $arg ) {
[186] Fix | Delete
$this->$key = $arg;
[187] Fix | Delete
}
[188] Fix | Delete
}
[189] Fix | Delete
[190] Fix | Delete
/**
[191] Fix | Delete
* Check whether the promo should be hidden or not.
[192] Fix | Delete
*
[193] Fix | Delete
* @access private
[194] Fix | Delete
*
[195] Fix | Delete
* @return bool
[196] Fix | Delete
*/
[197] Fix | Delete
private function hide_promo() {
[198] Fix | Delete
$hide_promo = get_transient( 'yoast_i18n_' . $this->project_slug . '_promo_hide' );
[199] Fix | Delete
if ( ! $hide_promo ) {
[200] Fix | Delete
if ( filter_input( INPUT_GET, 'remove_i18n_promo', FILTER_VALIDATE_INT ) === 1 ) {
[201] Fix | Delete
// No expiration time, so this would normally not expire, but it wouldn't be copied to other sites etc.
[202] Fix | Delete
set_transient( 'yoast_i18n_' . $this->project_slug . '_promo_hide', true );
[203] Fix | Delete
$hide_promo = true;
[204] Fix | Delete
}
[205] Fix | Delete
}
[206] Fix | Delete
return $hide_promo;
[207] Fix | Delete
}
[208] Fix | Delete
[209] Fix | Delete
/**
[210] Fix | Delete
* Returns the i18n_promo message from the i18n_module. Returns en empty string if the promo shouldn't be shown.
[211] Fix | Delete
*
[212] Fix | Delete
* @access public
[213] Fix | Delete
*
[214] Fix | Delete
* @return string The i18n promo message.
[215] Fix | Delete
*/
[216] Fix | Delete
public function get_promo_message() {
[217] Fix | Delete
if ( ! $this->is_default_language( $this->locale ) && ! $this->hide_promo() ) {
[218] Fix | Delete
return $this->promo_message();
[219] Fix | Delete
}
[220] Fix | Delete
[221] Fix | Delete
return '';
[222] Fix | Delete
}
[223] Fix | Delete
[224] Fix | Delete
/**
[225] Fix | Delete
* Generates a promo message.
[226] Fix | Delete
*
[227] Fix | Delete
* @access private
[228] Fix | Delete
*
[229] Fix | Delete
* @return bool|string $message
[230] Fix | Delete
*/
[231] Fix | Delete
private function promo_message() {
[232] Fix | Delete
[233] Fix | Delete
$this->translation_details();
[234] Fix | Delete
[235] Fix | Delete
$message = false;
[236] Fix | Delete
[237] Fix | Delete
if ( $this->translation_exists && $this->translation_loaded && $this->percent_translated < 90 ) {
[238] Fix | Delete
/* translators: 1: language name; 3: completion percentage; 4: link to translation platform. */
[239] Fix | Delete
$message = __( 'As you can see, there is a translation of this plugin in %1$s. This translation is currently %3$d%% complete. We need your help to make it complete and to fix any errors. Please register at %4$s to help complete the translation to %1$s!', $this->textdomain );
[240] Fix | Delete
}
[241] Fix | Delete
elseif ( ! $this->translation_loaded && $this->translation_exists ) {
[242] Fix | Delete
/* translators: 1: language name; 2: plugin name; 3: completion percentage; 4: link to translation platform. */
[243] Fix | Delete
$message = __( 'You\'re using WordPress in %1$s. While %2$s has been translated to %1$s for %3$d%%, it\'s not been shipped with the plugin yet. You can help! Register at %4$s to help complete the translation to %1$s!', $this->textdomain );
[244] Fix | Delete
}
[245] Fix | Delete
elseif ( ! $this->translation_exists ) {
[246] Fix | Delete
/* translators: 2: plugin name; 4: link to translation platform. */
[247] Fix | Delete
$message = __( 'You\'re using WordPress in a language we don\'t support yet. We\'d love for %2$s to be translated in that language too, but unfortunately, it isn\'t right now. You can change that! Register at %4$s to help translate it!', $this->textdomain );
[248] Fix | Delete
}
[249] Fix | Delete
[250] Fix | Delete
$registration_link = sprintf(
[251] Fix | Delete
'<a href="%1$s">%2$s</a>',
[252] Fix | Delete
esc_url( $this->register_url ),
[253] Fix | Delete
esc_html( $this->glotpress_name )
[254] Fix | Delete
);
[255] Fix | Delete
[256] Fix | Delete
$message = sprintf(
[257] Fix | Delete
esc_html( $message ),
[258] Fix | Delete
esc_html( $this->locale_name ),
[259] Fix | Delete
esc_html( $this->plugin_name ),
[260] Fix | Delete
(int) $this->percent_translated,
[261] Fix | Delete
$registration_link
[262] Fix | Delete
);
[263] Fix | Delete
[264] Fix | Delete
if ( $message ) {
[265] Fix | Delete
$message = '<p>' . $message . '</p><p><a href="' . esc_url( $this->register_url ) . '">' . esc_html__( 'Register now &raquo;', $this->textdomain ) . '</a></p>';
[266] Fix | Delete
}
[267] Fix | Delete
[268] Fix | Delete
return $message;
[269] Fix | Delete
}
[270] Fix | Delete
[271] Fix | Delete
/**
[272] Fix | Delete
* Returns a button that can be used to dismiss the i18n-message.
[273] Fix | Delete
*
[274] Fix | Delete
* @access private
[275] Fix | Delete
*
[276] Fix | Delete
* @return string
[277] Fix | Delete
*/
[278] Fix | Delete
public function get_dismiss_i18n_message_button() {
[279] Fix | Delete
return sprintf(
[280] Fix | Delete
/* translators: %1$s is the notification dismissal link start tag, %2$s is the link closing tag. */
[281] Fix | Delete
esc_html__( '%1$sPlease don\'t show me this notification anymore%2$s', $this->textdomain ),
[282] Fix | Delete
'<a class="button" href="' . esc_url( add_query_arg( array( 'remove_i18n_promo' => '1' ) ) ) . '">',
[283] Fix | Delete
'</a>'
[284] Fix | Delete
);
[285] Fix | Delete
}
[286] Fix | Delete
[287] Fix | Delete
/**
[288] Fix | Delete
* Sets the default values for wordpress.org
[289] Fix | Delete
*
[290] Fix | Delete
* @param array $args The arguments to set defaults for.
[291] Fix | Delete
*
[292] Fix | Delete
* @return array The arguments with the arguments set.
[293] Fix | Delete
*/
[294] Fix | Delete
private function set_defaults( $args ) {
[295] Fix | Delete
[296] Fix | Delete
if ( ! isset( $args['glotpress_logo'] ) ) {
[297] Fix | Delete
$args['glotpress_logo'] = 'https://plugins.svn.wordpress.org/' . $args['textdomain'] . '/assets/icon-128x128.png';
[298] Fix | Delete
}
[299] Fix | Delete
[300] Fix | Delete
if ( ! isset( $args['register_url'] ) ) {
[301] Fix | Delete
$args['register_url'] = 'https://translate.wordpress.org/projects/wp-plugins/' . $args['textdomain'] . '/';
[302] Fix | Delete
}
[303] Fix | Delete
[304] Fix | Delete
if ( ! isset( $args['glotpress_name'] ) ) {
[305] Fix | Delete
$args['glotpress_name'] = 'Translating WordPress';
[306] Fix | Delete
}
[307] Fix | Delete
[308] Fix | Delete
if ( ! isset( $args['project_slug'] ) ) {
[309] Fix | Delete
$args['project_slug'] = $args['textdomain'];
[310] Fix | Delete
}
[311] Fix | Delete
[312] Fix | Delete
return $args;
[313] Fix | Delete
}
[314] Fix | Delete
[315] Fix | Delete
/**
[316] Fix | Delete
* Outputs a promo box.
[317] Fix | Delete
*
[318] Fix | Delete
* @access public
[319] Fix | Delete
*/
[320] Fix | Delete
public function promo() {
[321] Fix | Delete
$message = $this->get_promo_message();
[322] Fix | Delete
[323] Fix | Delete
if ( $message ) {
[324] Fix | Delete
echo '<div id="i18n_promo_box" style="border:1px solid #ccc;background-color:#fff;padding:10px;max-width:650px; overflow: hidden;">';
[325] Fix | Delete
echo '<a href="' . esc_url( add_query_arg( array( 'remove_i18n_promo' => '1' ) ) ) . '" style="color:#333;text-decoration:none;font-weight:bold;font-size:16px;border:1px solid #ccc;padding:1px 4px;" class="alignright">X</a>';
[326] Fix | Delete
[327] Fix | Delete
echo '<div>';
[328] Fix | Delete
/* translators: %s: plugin name. */
[329] Fix | Delete
echo '<h2>' . sprintf( esc_html__( 'Translation of %s', $this->textdomain ), esc_html( $this->plugin_name ) ) . '</h2>';
[330] Fix | Delete
if ( isset( $this->glotpress_logo ) && is_string( $this->glotpress_logo ) && '' !== $this->glotpress_logo ) {
[331] Fix | Delete
echo '<a href="' . esc_url( $this->register_url ) . '"><img class="alignright" style="margin:0 5px 5px 5px;max-width:200px;" src="' . esc_url( $this->glotpress_logo ) . '" alt="' . esc_attr( $this->glotpress_name ) . '"/></a>';
[332] Fix | Delete
}
[333] Fix | Delete
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- correctly escaped in promo_message() method.
[334] Fix | Delete
echo $message;
[335] Fix | Delete
echo '</div>';
[336] Fix | Delete
echo '</div>';
[337] Fix | Delete
}
[338] Fix | Delete
}
[339] Fix | Delete
[340] Fix | Delete
/**
[341] Fix | Delete
* Try to find the transient for the translation set or retrieve them.
[342] Fix | Delete
*
[343] Fix | Delete
* @access private
[344] Fix | Delete
*
[345] Fix | Delete
* @return object|null
[346] Fix | Delete
*/
[347] Fix | Delete
private function find_or_initialize_translation_details() {
[348] Fix | Delete
$set = get_transient( 'yoast_i18n_' . $this->project_slug . '_' . $this->locale );
[349] Fix | Delete
[350] Fix | Delete
if ( ! $set ) {
[351] Fix | Delete
$set = $this->retrieve_translation_details();
[352] Fix | Delete
set_transient( 'yoast_i18n_' . $this->project_slug . '_' . $this->locale, $set, DAY_IN_SECONDS );
[353] Fix | Delete
}
[354] Fix | Delete
[355] Fix | Delete
return $set;
[356] Fix | Delete
}
[357] Fix | Delete
[358] Fix | Delete
/**
[359] Fix | Delete
* Try to get translation details from cache, otherwise retrieve them, then parse them.
[360] Fix | Delete
*
[361] Fix | Delete
* @access private
[362] Fix | Delete
*/
[363] Fix | Delete
private function translation_details() {
[364] Fix | Delete
$set = $this->find_or_initialize_translation_details();
[365] Fix | Delete
[366] Fix | Delete
$this->translation_exists = ! is_null( $set );
[367] Fix | Delete
$this->translation_loaded = is_textdomain_loaded( $this->textdomain );
[368] Fix | Delete
[369] Fix | Delete
$this->parse_translation_set( $set );
[370] Fix | Delete
}
[371] Fix | Delete
[372] Fix | Delete
/**
[373] Fix | Delete
* Set the API URL on the i18n object.
[374] Fix | Delete
*
[375] Fix | Delete
* @param string $textdomain The textdomain to use for the API URL.
[376] Fix | Delete
*/
[377] Fix | Delete
private function set_api_url( $textdomain ) {
[378] Fix | Delete
$this->api_url = 'https://translate.wordpress.org/api/projects/wp-plugins/' . $textdomain . '/stable/';
[379] Fix | Delete
}
[380] Fix | Delete
[381] Fix | Delete
/**
[382] Fix | Delete
* Returns the API URL to use when requesting translation information.
[383] Fix | Delete
*
[384] Fix | Delete
* @return string
[385] Fix | Delete
*/
[386] Fix | Delete
private function get_api_url() {
[387] Fix | Delete
if ( empty( $this->api_url ) ) {
[388] Fix | Delete
$this->api_url = trailingslashit( $this->glotpress_url ) . 'api/projects/' . $this->project_slug;
[389] Fix | Delete
}
[390] Fix | Delete
[391] Fix | Delete
return $this->api_url;
[392] Fix | Delete
}
[393] Fix | Delete
[394] Fix | Delete
/**
[395] Fix | Delete
* Retrieve the translation details from Yoast Translate.
[396] Fix | Delete
*
[397] Fix | Delete
* @access private
[398] Fix | Delete
*
[399] Fix | Delete
* @return object|null
[400] Fix | Delete
*/
[401] Fix | Delete
private function retrieve_translation_details() {
[402] Fix | Delete
$api_url = $this->get_api_url();
[403] Fix | Delete
[404] Fix | Delete
$resp = wp_remote_get( $api_url );
[405] Fix | Delete
if ( is_wp_error( $resp ) || wp_remote_retrieve_response_code( $resp ) !== 200 ) {
[406] Fix | Delete
return null;
[407] Fix | Delete
}
[408] Fix | Delete
$body = wp_remote_retrieve_body( $resp );
[409] Fix | Delete
unset( $resp );
[410] Fix | Delete
[411] Fix | Delete
if ( $body ) {
[412] Fix | Delete
$body = json_decode( $body );
[413] Fix | Delete
if ( empty( $body->translation_sets ) ) {
[414] Fix | Delete
return null;
[415] Fix | Delete
}
[416] Fix | Delete
foreach ( $body->translation_sets as $set ) {
[417] Fix | Delete
if ( ! property_exists( $set, 'wp_locale' ) ) {
[418] Fix | Delete
continue;
[419] Fix | Delete
}
[420] Fix | Delete
[421] Fix | Delete
// For informal and formal locales, we have to complete the locale code by concatenating the slug ('formal' or 'informal') to the xx_XX part.
[422] Fix | Delete
if ( $set->slug !== 'default' && strtolower( $this->locale ) === strtolower( $set->wp_locale . '_' . $set->slug ) ) {
[423] Fix | Delete
return $set;
[424] Fix | Delete
}
[425] Fix | Delete
[426] Fix | Delete
if ( $this->locale === $set->wp_locale ) {
[427] Fix | Delete
return $set;
[428] Fix | Delete
}
[429] Fix | Delete
}
[430] Fix | Delete
}
[431] Fix | Delete
[432] Fix | Delete
return null;
[433] Fix | Delete
}
[434] Fix | Delete
[435] Fix | Delete
/**
[436] Fix | Delete
* Set the needed private variables based on the results from Yoast Translate.
[437] Fix | Delete
*
[438] Fix | Delete
* @param object $set The translation set.
[439] Fix | Delete
*
[440] Fix | Delete
* @access private
[441] Fix | Delete
*/
[442] Fix | Delete
private function parse_translation_set( $set ) {
[443] Fix | Delete
if ( $this->translation_exists && is_object( $set ) ) {
[444] Fix | Delete
$this->locale_name = $set->name;
[445] Fix | Delete
$this->percent_translated = $set->percent_translated;
[446] Fix | Delete
}
[447] Fix | Delete
else {
[448] Fix | Delete
$this->locale_name = '';
[449] Fix | Delete
$this->percent_translated = '';
[450] Fix | Delete
}
[451] Fix | Delete
}
[452] Fix | Delete
}
[453] Fix | Delete
[454] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function