PluginProbe ʕ •ᴥ•ʔ
Advanced Ads – Ad Manager & AdSense / 1.51.3
Advanced Ads – Ad Manager & AdSense v1.51.3
2.0.23 2.0.22 2.0.21 1.38.0 1.39.0 1.39.1 1.39.2 1.39.3 1.39.4 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.40.0 1.40.1 1.40.2 1.41.0 1.42.0 1.42.1 1.42.2 1.43.0 1.44.0 1.44.1 1.45.0 1.45.1 1.46.0 1.47.0 1.47.1 1.47.2 1.47.3 1.47.4 1.47.5 1.48.0 1.48.1 1.49.0 1.5.0 1.5.0.1 1.5.1 1.5.2 1.5.2.1 1.5.4 1.5.4.1 1.5.5 1.50.0 1.51.0 1.51.1 1.51.2 1.51.3 1.52.0 1.52.1 1.52.2 1.52.3 1.52.4 1.53.0 1.53.1 1.53.2 1.54.0 1.54.1 1.55.0 1.56.0 1.56.1 1.56.2 1.56.3 1.56.4 1.6 1.6.1 1.6.10 1.6.10.1 1.6.10.2 1.6.11 1.6.11.1 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.17.1 1.6.17.2 1.6.2 1.6.2.1 1.6.3 1.6.4 1.6.4.1 1.6.5 1.6.6 1.6.6.1 1.6.7 1.6.7.1 1.6.8 1.6.8.1 1.6.8.2 1.6.8.3 1.6.9 1.6.9.1 1.6.9.2 1.6.9.3 1.6.9.4 1.7 1.7.0.1 1.7.0.2 1.7.0.3 1.7.1 1.7.1.1 1.7.1.2 1.7.1.3 1.7.1.4 1.7.1.5 1.7.10 trunk 1.7.11 1.0.1 1.7.12 1.0.2 1.7.13 1.0.3 1.7.14 1.1.0 1.7.15 1.1.1 1.7.16 1.1.2 1.7.17 1.1.3 1.7.18 1.10 1.7.19 1.10.1 1.7.2 1.10.10 1.7.2.1 1.10.11 1.7.20 1.10.12 1.7.21 1.10.2 1.7.22 1.10.3 1.7.23 1.10.4 1.7.24 1.10.5 1.7.25 1.10.6 1.7.3 1.10.7 1.7.4 1.10.8 1.7.4.1 1.10.9 1.7.4.2 1.11 1.7.4.3 1.11.1 1.7.4.4 1.11.2 1.7.4.5 1.12 1.7.5 1.13 1.7.5.1 1.13.1 1.7.6 1.13.2 1.7.7 1.13.3 1.7.8 1.13.4 1.7.9 1.13.5 1.7.9.1 1.13.6 1.7.9.2 1.13.7 1.7.9.3 1.13.8 1.8 1.14 1.8.1 1.14.1 1.8.10 1.14.10 1.8.11 1.14.11 1.8.12 1.14.2 1.8.13 1.14.3 1.8.14 1.14.4 1.8.15 1.14.5 1.8.16 1.14.6 1.8.17 1.14.7 1.8.18 1.14.8 1.8.19 1.14.9 1.8.2 1.15 1.8.20 1.16 1.8.21 1.16.1 1.8.22 1.17 1.8.23 1.17.1 1.8.24 1.17.10 1.8.25 1.17.10-rc.1 1.8.26 1.17.11 1.8.27 1.17.12 1.8.28 1.17.12-rc.1 1.8.29 1.17.2 1.8.3 1.17.3 1.8.30 1.17.4 1.8.4 1.17.5 1.8.5 1.17.6 1.8.6 1.17.7 1.8.7 1.17.8 1.8.8 1.17.9 1.8.9 1.17.9-beta.1 1.9 1.18.0 2.0.0 1.19.0 2.0.1 1.19.1 2.0.10 1.2 2.0.11 1.2.1 2.0.12 1.2.2 2.0.13 1.2.3 2.0.14 1.2.4 2.0.15 1.2.5 2.0.16 1.2.6 2.0.17 1.2.7 2.0.18 1.20.0 2.0.19 1.20.0-rc.1 2.0.2 1.20.0-rc.2 2.0.20 1.20.1 2.0.3 1.20.2 2.0.4 1.20.3 2.0.5 1.21.0 2.0.6 1.21.1 2.0.7 1.22.0 2.0.8 1.22.1 2.0.9 1.22.2 1.23.0 1.23.1 1.23.2 1.24.0 1.24.1 1.24.2 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.29.0 1.29.1 1.3 1.3.1 1.3.10 1.3.11 1.3.12 1.3.13 1.3.14 1.3.15 1.3.16 1.3.17 1.3.18 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.30.0 1.30.1 1.30.2 1.30.2-rc.1 1.30.3 1.30.4 1.30.4-rc.1 1.30.5 1.31.0 1.31.1 1.32.0 1.32.0-rc.1 1.33.0 1.33.1 1.33.2 1.34.0 1.35.0 1.35.1 1.36.0 1.36.1 1.36.2 1.36.3 1.37.0 1.37.1 1.37.2
advanced-ads / classes / class-translation-promo.php
advanced-ads / classes Last commit date
Advanced_Ads_Modal.php 2 years ago EDD_SL_Plugin_Updater.php 2 years ago ad-ajax.php 2 years ago ad-debug.php 2 years ago ad-expiration.php 3 years ago ad-health-notices.php 2 years ago ad-model.php 2 years ago ad-select.php 3 years ago ad.php 2 years ago ad_ajax_callbacks.php 2 years ago ad_group.php 2 years ago ad_placements.php 2 years ago ad_type_abstract.php 2 years ago ad_type_content.php 2 years ago ad_type_dummy.php 2 years ago ad_type_group.php 2 years ago ad_type_image.php 2 years ago ad_type_plain.php 2 years ago checks.php 2 years ago class-translation-promo.php 2 years ago compatibility.php 2 years ago display-conditions.php 2 years ago filesystem.php 2 years ago frontend_checks.php 2 years ago in-content-injector.php 2 years ago inline-css.php 2 years ago plugin.php 2 years ago upgrades.php 2 years ago utils.php 3 years ago visitor-conditions.php 2 years ago widget.php 2 years ago
class-translation-promo.php
455 lines
1 <?php
2 /**
3 * Translation_Promo.
4 *
5 * @package AdvancedAds
6 * @author Advanced Ads <info@wpadvancedads.com>
7 * @since 1.45.0
8 */
9
10 defined( 'ABSPATH' ) || exit;
11
12 /**
13 * This class defines a promo box and checks your translation site's API for stats about it.
14 *
15 * @copyright Yoast i18n https://github.com/Yoast/i18n-module
16 */
17 class Translation_Promo {
18 /**
19 * Your translation site's logo.
20 *
21 * @var string
22 */
23 private $glotpress_logo;
24
25 /**
26 * Your translation site's name.
27 *
28 * @var string
29 */
30 private $glotpress_name;
31
32 /**
33 * Your translation site's URL.
34 *
35 * @var string
36 */
37 private $glotpress_url;
38
39 /**
40 * The URL to actually do the API request to.
41 *
42 * @var string
43 */
44 private $api_url;
45
46 /**
47 * Hook where you want to show the promo box.
48 *
49 * @var string
50 */
51 private $hook;
52
53 /**
54 * Will contain the site's locale.
55 *
56 * @access private
57 * @var string
58 */
59 private $locale;
60
61 /**
62 * Will contain the locale's name, obtained from your translation site.
63 *
64 * @access private
65 * @var string
66 */
67 private $locale_name;
68
69 /**
70 * Will contain the percentage translated for the plugin translation project in the locale.
71 *
72 * @access private
73 * @var int
74 */
75 private $percent_translated;
76
77 /**
78 * Name of your plugin.
79 *
80 * @var string
81 */
82 private $plugin_name;
83
84 /**
85 * Project slug for the project on your translation site.
86 *
87 * @var string
88 */
89 private $project_slug;
90
91 /**
92 * URL to point to for registration links.
93 *
94 * @var string
95 */
96 private $register_url;
97
98 /**
99 * Your plugins textdomain.
100 *
101 * @var string
102 */
103 private $textdomain;
104
105 /**
106 * Indicates whether there's a translation available at all.
107 *
108 * @access private
109 * @var bool
110 */
111 private $translation_exists;
112
113 /**
114 * Indicates whether the translation's loaded.
115 *
116 * @access private
117 * @var bool
118 */
119 private $translation_loaded;
120
121 /**
122 * Constructs the i18n module for wordpress.org.
123 *
124 * Required fields are the 'textdomain', 'plugin_name' and 'hook'.
125 *
126 * @param array $args The settings for the i18n module.
127 * @param bool $show_translation_box Whether the translation box should be shown.
128 */
129 public function __construct( $args, $show_translation_box = true ) {
130 if ( ! is_admin() ) {
131 return;
132 }
133
134 $args = $this->set_defaults( $args );
135 $this->locale = $this->get_admin_locale();
136 if ( $this->is_default_language( $this->locale ) ) {
137 return;
138 }
139
140 $this->init( $args );
141
142 if ( $show_translation_box ) {
143 add_action( $this->hook, array( $this, 'promo' ) );
144 }
145
146 $this->set_api_url( $args['textdomain'] );
147 }
148
149 /**
150 * Returns whether the language is en_US.
151 *
152 * @param string $language The language to check.
153 *
154 * @return bool Returns true if the language is en_US.
155 */
156 protected function is_default_language( $language ) {
157 return 'en_US' === $language;
158 }
159
160 /**
161 * Returns the locale used in the admin.
162 *
163 * WordPress 4.7 introduced the ability for users to specify an Admin language
164 * different from the language used on the front end. This checks if the feature
165 * is available and returns the user's language, with a fallback to the site's language.
166 * Can be removed when support for WordPress 4.6 will be dropped, in favor
167 * of WordPress get_user_locale() that already fallbacks to the site’s locale.
168 *
169 * @returns string The locale.
170 */
171 private function get_admin_locale() {
172 if ( function_exists( 'get_user_locale' ) ) {
173 return get_user_locale();
174 }
175
176 return get_locale();
177 }
178
179 /**
180 * This is where you decide where to display the messages and where you set the plugin specific variables.
181 *
182 * @access private
183 *
184 * @param array $args Contains the settings for the class.
185 */
186 private function init( $args ) {
187 foreach ( $args as $key => $arg ) {
188 $this->$key = $arg;
189 }
190 }
191
192 /**
193 * Check whether the promo should be hidden or not.
194 *
195 * @access private
196 *
197 * @return bool
198 */
199 private function hide_promo() {
200 $hide_promo = get_transient( 'yoast_i18n_' . $this->project_slug . '_promo_hide' );
201 if ( ! $hide_promo ) {
202 if ( filter_input( INPUT_GET, 'remove_i18n_promo', FILTER_VALIDATE_INT ) === 1 ) {
203 // No expiration time, so this would normally not expire, but it wouldn't be copied to other sites etc.
204 set_transient( 'yoast_i18n_' . $this->project_slug . '_promo_hide', true );
205 $hide_promo = true;
206 }
207 }
208 return $hide_promo;
209 }
210
211 /**
212 * Returns the i18n_promo message from the i18n_module. Returns en empty string if the promo shouldn't be shown.
213 *
214 * @access public
215 *
216 * @return string The i18n promo message.
217 */
218 public function get_promo_message() {
219 if ( ! $this->is_default_language( $this->locale ) && ! $this->hide_promo() ) {
220 return $this->promo_message();
221 }
222
223 return '';
224 }
225
226 /**
227 * Generates a promo message.
228 *
229 * @access private
230 *
231 * @return bool|string $message
232 */
233 private function promo_message() {
234
235 $this->translation_details();
236
237 $message = false;
238
239 if ( $this->translation_exists && $this->translation_loaded && $this->percent_translated < 90 ) {
240 /* translators: 1: language name; 3: completion percentage; 4: link to translation platform. */
241 $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 );
242 }
243 elseif ( ! $this->translation_loaded && $this->translation_exists ) {
244 /* translators: 1: language name; 2: plugin name; 3: completion percentage; 4: link to translation platform. */
245 $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 );
246 }
247 elseif ( ! $this->translation_exists ) {
248 /* translators: 2: plugin name; 4: link to translation platform. */
249 $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 );
250 }
251
252 $registration_link = sprintf(
253 '<a href="%1$s">%2$s</a>',
254 esc_url( $this->register_url ),
255 esc_html( $this->glotpress_name )
256 );
257
258 $message = sprintf(
259 esc_html( $message ),
260 esc_html( $this->locale_name ),
261 esc_html( $this->plugin_name ),
262 (int) $this->percent_translated,
263 $registration_link
264 );
265
266 if ( $message ) {
267 $message = '<p>' . $message . '</p><p><a href="' . esc_url( $this->register_url ) . '">' . esc_html__( 'Register now &raquo;', $this->textdomain ) . '</a></p>';
268 }
269
270 return $message;
271 }
272
273 /**
274 * Returns a button that can be used to dismiss the i18n-message.
275 *
276 * @access private
277 *
278 * @return string
279 */
280 public function get_dismiss_i18n_message_button() {
281 return sprintf(
282 /* translators: %1$s is the notification dismissal link start tag, %2$s is the link closing tag. */
283 esc_html__( '%1$sPlease don\'t show me this notification anymore%2$s', $this->textdomain ),
284 '<a class="button" href="' . esc_url( add_query_arg( array( 'remove_i18n_promo' => '1' ) ) ) . '">',
285 '</a>'
286 );
287 }
288
289 /**
290 * Sets the default values for wordpress.org
291 *
292 * @param array $args The arguments to set defaults for.
293 *
294 * @return array The arguments with the arguments set.
295 */
296 private function set_defaults( $args ) {
297
298 if ( ! isset( $args['glotpress_logo'] ) ) {
299 $args['glotpress_logo'] = 'https://plugins.svn.wordpress.org/' . $args['textdomain'] . '/assets/icon-128x128.png';
300 }
301
302 if ( ! isset( $args['register_url'] ) ) {
303 $args['register_url'] = 'https://translate.wordpress.org/projects/wp-plugins/' . $args['textdomain'] . '/';
304 }
305
306 if ( ! isset( $args['glotpress_name'] ) ) {
307 $args['glotpress_name'] = 'Translating WordPress';
308 }
309
310 if ( ! isset( $args['project_slug'] ) ) {
311 $args['project_slug'] = $args['textdomain'];
312 }
313
314 return $args;
315 }
316
317 /**
318 * Outputs a promo box.
319 *
320 * @access public
321 */
322 public function promo() {
323 $message = $this->get_promo_message();
324
325 if ( $message ) {
326 echo '<div id="i18n_promo_box" style="border:1px solid #ccc;background-color:#fff;padding:10px;max-width:650px; overflow: hidden;">';
327 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>';
328
329 echo '<div>';
330 /* translators: %s: plugin name. */
331 echo '<h2>' . sprintf( esc_html__( 'Translation of %s', $this->textdomain ), esc_html( $this->plugin_name ) ) . '</h2>';
332 if ( isset( $this->glotpress_logo ) && is_string( $this->glotpress_logo ) && '' !== $this->glotpress_logo ) {
333 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>';
334 }
335 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- correctly escaped in promo_message() method.
336 echo $message;
337 echo '</div>';
338 echo '</div>';
339 }
340 }
341
342 /**
343 * Try to find the transient for the translation set or retrieve them.
344 *
345 * @access private
346 *
347 * @return object|null
348 */
349 private function find_or_initialize_translation_details() {
350 $set = get_transient( 'yoast_i18n_' . $this->project_slug . '_' . $this->locale );
351
352 if ( ! $set ) {
353 $set = $this->retrieve_translation_details();
354 set_transient( 'yoast_i18n_' . $this->project_slug . '_' . $this->locale, $set, DAY_IN_SECONDS );
355 }
356
357 return $set;
358 }
359
360 /**
361 * Try to get translation details from cache, otherwise retrieve them, then parse them.
362 *
363 * @access private
364 */
365 private function translation_details() {
366 $set = $this->find_or_initialize_translation_details();
367
368 $this->translation_exists = ! is_null( $set );
369 $this->translation_loaded = is_textdomain_loaded( $this->textdomain );
370
371 $this->parse_translation_set( $set );
372 }
373
374 /**
375 * Set the API URL on the i18n object.
376 *
377 * @param string $textdomain The textdomain to use for the API URL.
378 */
379 private function set_api_url( $textdomain ) {
380 $this->api_url = 'https://translate.wordpress.org/api/projects/wp-plugins/' . $textdomain . '/stable/';
381 }
382
383 /**
384 * Returns the API URL to use when requesting translation information.
385 *
386 * @return string
387 */
388 private function get_api_url() {
389 if ( empty( $this->api_url ) ) {
390 $this->api_url = trailingslashit( $this->glotpress_url ) . 'api/projects/' . $this->project_slug;
391 }
392
393 return $this->api_url;
394 }
395
396 /**
397 * Retrieve the translation details from Yoast Translate.
398 *
399 * @access private
400 *
401 * @return object|null
402 */
403 private function retrieve_translation_details() {
404 $api_url = $this->get_api_url();
405
406 $resp = wp_remote_get( $api_url );
407 if ( is_wp_error( $resp ) || wp_remote_retrieve_response_code( $resp ) !== 200 ) {
408 return null;
409 }
410 $body = wp_remote_retrieve_body( $resp );
411 unset( $resp );
412
413 if ( $body ) {
414 $body = json_decode( $body );
415 if ( empty( $body->translation_sets ) ) {
416 return null;
417 }
418 foreach ( $body->translation_sets as $set ) {
419 if ( ! property_exists( $set, 'wp_locale' ) ) {
420 continue;
421 }
422
423 // For informal and formal locales, we have to complete the locale code by concatenating the slug ('formal' or 'informal') to the xx_XX part.
424 if ( $set->slug !== 'default' && strtolower( $this->locale ) === strtolower( $set->wp_locale . '_' . $set->slug ) ) {
425 return $set;
426 }
427
428 if ( $this->locale === $set->wp_locale ) {
429 return $set;
430 }
431 }
432 }
433
434 return null;
435 }
436
437 /**
438 * Set the needed private variables based on the results from Yoast Translate.
439 *
440 * @param object $set The translation set.
441 *
442 * @access private
443 */
444 private function parse_translation_set( $set ) {
445 if ( $this->translation_exists && is_object( $set ) ) {
446 $this->locale_name = $set->name;
447 $this->percent_translated = $set->percent_translated;
448 }
449 else {
450 $this->locale_name = '';
451 $this->percent_translated = '';
452 }
453 }
454 }
455