PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.30.0
GiveWP – Donation Plugin and Fundraising Platform v2.30.0
4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / includes / admin / class-i18n-module.php
give / includes / admin Last commit date
add-ons 4 years ago donors 4 years ago emails 3 years ago forms 3 years ago payments 3 years ago reports 4 years ago settings 2 years ago shortcodes 4 years ago tools 3 years ago upgrades 3 years ago views 3 years ago abstract-admin-settings-page.php 6 years ago admin-actions.php 3 years ago admin-filters.php 3 years ago admin-footer.php 5 years ago admin-pages.php 3 years ago class-addon-activation-banner.php 4 years ago class-admin-settings.php 4 years ago class-api-keys-table.php 4 years ago class-blank-slate.php 3 years ago class-give-admin.php 5 years ago class-give-html-elements.php 6 years ago class-i18n-module.php 4 years ago dashboard-widgets.php 3 years ago give-metabox-functions.php 3 years ago import-functions.php 3 years ago misc-functions.php 3 years ago plugins.php 3 years ago setting-page-functions.php 6 years ago
class-i18n-module.php
363 lines
1 <?php
2
3 /**
4 * Class Give_i18n
5 */
6 class Give_i18n_Banner {
7
8 /**
9 * Your translation site's URL.
10 *
11 * @var string
12 */
13 private $glotpress_url;
14
15 /**
16 * Hook where you want to show the promo box.
17 *
18 * @var string
19 */
20 private $hook;
21
22 /**
23 * Will contain the site's locale.
24 *
25 * @access private
26 * @var string
27 */
28 private $locale;
29
30 /**
31 * Will contain the locale's name, obtained from your translation site.
32 *
33 * @access private
34 * @var string
35 */
36 private $locale_name;
37
38 /**
39 * Will contain the percentage translated for the plugin translation project in the locale.
40 *
41 * @access private
42 * @var int
43 */
44 private $percent_translated;
45
46
47 /**
48 * Indicates whether there's a translation available at all.
49 *
50 * @access private
51 * @var bool
52 */
53 private $translation_exists;
54
55 /**
56 * Indicates whether the translation's loaded.
57 *
58 * @access private
59 * @var bool
60 */
61 private $translation_loaded;
62
63 /**
64 * Give_i18n constructor.
65 *
66 * @param $args
67 */
68 public function __construct( $args ) {
69
70 // Only for admins.
71 if ( ! is_admin() ) {
72 return;
73 }
74
75 foreach ( $args as $key => $arg ) {
76 $this->$key = $arg;
77 }
78
79 add_action( 'admin_init', array( $this, 'init' ) );
80
81 }
82
83 /**
84 * Initialize i18n banner.
85 */
86 function init() {
87
88 // First get user's locale (4.7+).
89 $this->locale = function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale();
90
91 // This plugin is en_US native.
92 if ( 'en_US' === $this->locale ) {
93 return;
94 }
95
96 if (
97 ! $this->hide_promo()
98 && ( ! empty( $_GET['post_type'] ) && 'give_forms' === $_GET['post_type'] )
99 && ( ! empty( $_GET['page'] ) && 'give-settings' === $_GET['page'] )
100 ) {
101 add_action( $this->hook, array( $this, 'promo' ) );
102 }
103 }
104
105
106 /**
107 * Check whether the promo should be hidden or not.
108 *
109 * @access private
110 *
111 * @return bool
112 */
113 private function hide_promo() {
114 $hide_promo = Give_Cache::get( 'give_i18n_give_promo_hide', true );
115 if ( ! $hide_promo ) {
116 if ( filter_input( INPUT_GET, 'remove_i18n_promo', FILTER_VALIDATE_INT ) === 1 ) {
117 // No expiration time, so this would normally not expire, but it wouldn't be copied to other sites etc.
118 Give_Cache::set( 'give_i18n_give_promo_hide', true, null, true );
119 $hide_promo = true;
120 }
121 }
122
123 return $hide_promo;
124 }
125
126 /**
127 * Generates a promo message.
128 *
129 * @access private
130 *
131 * @return bool|string $message
132 */
133 private function promo_message() {
134 $message = false;
135
136 // Using a translation less than 90% complete.
137 if ( $this->translation_exists && $this->translation_loaded && $this->percent_translated < 90 ) {
138 $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 %5$s to %1$s!', 'give' );
139 } elseif ( ! $this->translation_loaded && $this->translation_exists ) {
140 $message = __( 'You\'re using WordPress in %1$s. While %2$s has been %3$d%% translated to %1$s, it has not been shipped with the plugin yet. You can help! Register at %4$s to help complete the translation to %1$s!', 'give' );
141 } elseif ( ! $this->translation_exists ) {
142 $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!', 'give' );
143 }
144
145 // Links.
146 $registration_link = sprintf( '<a href="%1$s" target="_blank">%2$s</a>', 'https://wordpress.org/support/register.php', esc_html__( 'WordPress.org', 'give' ) );
147 $translations_link = sprintf( '<a href="%1$s" target="_blank">%2$s</a>', 'https://translate.wordpress.org/projects/wp-plugins/give', esc_html__( 'complete the translation', 'give' ) );
148
149 // Message.
150 $message = sprintf( $message, $this->locale_name, 'Give', $this->percent_translated, $registration_link, $translations_link );
151
152 return $message;
153
154 }
155
156 /**
157 * Outputs a promo box
158 */
159 public function promo() {
160
161 $this->translation_details();
162 $message = $this->promo_message();
163
164 if ( $message ) {
165 $this->print_css();
166
167 ob_start();
168 ?>
169 <div id="give-i18n-notice" class="give-addon-alert updated give-notice" style="display: none">
170
171 <a href="https://wordpress.org/support/register.php" class="alignleft give-i18n-icon" style="margin:0" target="_blank"><span class="dashicons dashicons-translation"
172 style="font-size: 110px; text-decoration: none;"></span></a>
173
174 <div class="give-i18n-notice-content">
175 <a href="<?php echo esc_url( add_query_arg( array( 'remove_i18n_promo' => '1' ) ) ); ?>" class="dismiss"><span class="dashicons dashicons-dismiss"></span></a>
176
177 <h2 style="margin: 10px 0;"><?php printf( esc_html__( 'Help Translate GiveWP to %s', 'give' ), $this->locale_name ); ?></h2>
178 <p><?php echo $message; ?></p>
179 <p>
180 <a href="https://wordpress.org/support/register.php" target="_blank"><?php _e( 'Register now &raquo;', 'give' ); ?></a>
181 </p>
182 </div>
183 </div>
184 <?php
185
186 $notice_html = ob_get_clean();
187
188 // Register notice.
189 Give()->notices->register_notice(
190 array(
191 'id' => 'give-i18n-notice',
192 'type' => 'updated',
193 'description_html' => $notice_html,
194 'show' => true,
195 )
196 );
197 }
198 }
199
200
201 /**
202 * Output notice css
203 *
204 * @since 1.8.16
205 * @access private
206 */
207 private function print_css() {
208 ?>
209 <style>
210 /* Banner specific styles */
211 div.give-addon-alert.updated {
212 padding: 10px 20px;
213 position: relative;
214 border-color: #69B868;
215 overflow: hidden;
216 }
217
218 div.give-addon-alert a {
219 color: #69B868;
220 }
221
222 #give-i18n-notice > .give-i18n-icon {
223 overflow: hidden;
224 }
225
226 #give-i18n-notice > .give-i18n-icon .dashicons {
227 width: 110px;
228 height: 110px;
229 }
230
231 #give-i18n-notice > .give-i18n-icon:focus {
232 box-shadow: none;
233 }
234
235 .give-i18n-notice-content {
236 margin: 0 30px 0 125px;
237 }
238
239 div.give-addon-alert .dismiss {
240 position: absolute;
241 right: 20px;
242 height: 100%;
243 top: 50%;
244 margin-top: -10px;
245 outline: none;
246 box-shadow: none;
247 text-decoration: none;
248 color: #AAA;
249 }
250
251 div.give-addon-alert .dismiss:hover {
252 color: #333;
253 }
254
255 /* RTL Styles for banner */
256 body.rtl .give-i18n-notice-content {
257 margin: 0 125px 0 30px;
258 }
259
260 body.rtl div.give-addon-alert .dismiss {
261 left: 20px;
262 right: auto;
263 }
264
265 </style>
266 <?php
267 }
268
269 /**
270 * Try to find the transient for the translation set or retrieve them.
271 *
272 * @access private
273 *
274 * @return object|null
275 */
276 private function find_or_initialize_translation_details() {
277
278 $set = Give_Cache::get( "give_i18n_give_{$this->locale}", true );
279
280 if ( ! $set ) {
281 $set = $this->retrieve_translation_details();
282 Give_Cache::set( "give_i18n_give_{$this->locale}", $set, DAY_IN_SECONDS, true );
283 }
284
285 return $set;
286 }
287
288 /**
289 * Try to get translation details from cache, otherwise retrieve them, then parse them.
290 *
291 * @access private
292 */
293 private function translation_details() {
294 $set = $this->find_or_initialize_translation_details();
295
296 $this->translation_exists = ! is_null( $set );
297 $this->translation_loaded = is_textdomain_loaded( 'give' );
298
299 $this->parse_translation_set( $set );
300 }
301
302 /**
303 * Retrieve the translation details from Give Translate.
304 *
305 * @access private
306 *
307 * @return object|null
308 */
309 private function retrieve_translation_details() {
310
311 $api_url = trailingslashit( $this->glotpress_url );
312
313 $resp = wp_remote_get( $api_url );
314
315 if ( is_wp_error( $resp ) || wp_remote_retrieve_response_code( $resp ) === '404' ) {
316 return null;
317 }
318
319 $body = wp_remote_retrieve_body( $resp );
320 unset( $resp );
321
322 if ( $body ) {
323 $body = json_decode( $body );
324
325 foreach ( $body->translation_sets as $set ) {
326 if ( ! property_exists( $set, 'wp_locale' ) ) {
327 continue;
328 }
329
330 if ( $this->locale == $set->wp_locale ) {
331 return $set;
332 }
333 }
334 }
335
336 return null;
337 }
338
339 /**
340 * Set the needed private variables based on the results from Give Translate.
341 *
342 * @param object $set The translation set
343 *
344 * @access private
345 */
346 private function parse_translation_set( $set ) {
347 if ( $this->translation_exists && is_object( $set ) ) {
348 $this->locale_name = $set->name;
349 $this->percent_translated = $set->percent_translated;
350 } else {
351 $this->locale_name = '';
352 $this->percent_translated = '';
353 }
354 }
355 }
356
357 $give_i18n = new Give_i18n_Banner(
358 array(
359 'hook' => 'admin_notices',
360 'glotpress_url' => 'https://translate.wordpress.org/api/projects/wp-plugins/give/stable/',
361 )
362 );
363