PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.2.0
GiveWP – Donation Plugin and Fundraising Platform v2.2.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
donors 7 years ago emails 7 years ago forms 7 years ago payments 7 years ago reports 8 years ago settings 7 years ago shortcodes 7 years ago tools 7 years ago upgrades 7 years ago views 8 years ago EDD_SL_Plugin_Updater.php 8 years ago abstract-admin-settings-page.php 8 years ago add-ons.php 8 years ago admin-actions.php 7 years ago admin-filters.php 8 years ago admin-footer.php 8 years ago admin-pages.php 8 years ago class-addon-activation-banner.php 7 years ago class-admin-settings.php 7 years ago class-api-keys-table.php 8 years ago class-blank-slate.php 8 years ago class-give-settings.php 7 years ago class-i18n-module.php 8 years ago dashboard-widgets.php 8 years ago give-metabox-functions.php 7 years ago plugins.php 7 years ago welcome.php 8 years ago
class-i18n-module.php
360 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 /**
85 * Initialize i18n banner.
86 */
87 function init() {
88
89 // First get user's locale (4.7+).
90 $this->locale = function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale();
91
92 // This plugin is en_US native.
93 if ( 'en_US' === $this->locale ) {
94 return;
95 }
96
97 if (
98 ! $this->hide_promo()
99 && ( ! empty( $_GET['post_type'] ) && 'give_forms' === $_GET['post_type'] )
100 && ( ! empty( $_GET['page'] ) && 'give-settings' === $_GET['page'] )
101 ) {
102 add_action( $this->hook, array( $this, 'promo' ) );
103 }
104 }
105
106
107 /**
108 * Check whether the promo should be hidden or not.
109 *
110 * @access private
111 *
112 * @return bool
113 */
114 private function hide_promo() {
115 $hide_promo = Give_Cache::get( 'give_i18n_give_promo_hide', true );
116 if ( ! $hide_promo ) {
117 if ( filter_input( INPUT_GET, 'remove_i18n_promo', FILTER_VALIDATE_INT ) === 1 ) {
118 // No expiration time, so this would normally not expire, but it wouldn't be copied to other sites etc.
119 Give_Cache::set( 'give_i18n_give_promo_hide', true, null, true );
120 $hide_promo = true;
121 }
122 }
123
124 return $hide_promo;
125 }
126
127 /**
128 * Generates a promo message.
129 *
130 * @access private
131 *
132 * @return bool|string $message
133 */
134 private function promo_message() {
135 $message = false;
136
137 // Using a translation less than 90% complete.
138 if ( $this->translation_exists && $this->translation_loaded && $this->percent_translated < 90 ) {
139 $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' );
140 } elseif ( ! $this->translation_loaded && $this->translation_exists ) {
141 $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' );
142 } elseif ( ! $this->translation_exists ) {
143 $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' );
144 }
145
146 // Links.
147 $registration_link = sprintf( '<a href="%1$s" target="_blank">%2$s</a>', 'https://wordpress.org/support/register.php', esc_html__( 'WordPress.org', 'give' ) );
148 $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' ) );
149
150 // Message.
151 $message = sprintf( $message, $this->locale_name, 'Give', $this->percent_translated, $registration_link, $translations_link );
152
153 return $message;
154
155 }
156
157 /**
158 * Outputs a promo box
159 */
160 public function promo() {
161
162 $this->translation_details();
163 $message = $this->promo_message();
164
165 if ( $message ) {
166 $this->print_css();
167
168 ob_start();
169 ?>
170 <div id="give-i18n-notice" class="give-addon-alert updated give-notice" style="display: none">
171
172 <a href="https://wordpress.org/support/register.php" class="alignleft give-i18n-icon" style="margin:0" target="_blank"><span class="dashicons dashicons-translation"
173 style="font-size: 110px; text-decoration: none;"></span></a>
174
175 <div class="give-i18n-notice-content">
176 <a href="<?php echo esc_url( add_query_arg( array( 'remove_i18n_promo' => '1' ) ) ); ?>" class="dismiss"><span class="dashicons dashicons-dismiss"></span></a>
177
178 <h2 style="margin: 10px 0;"><?php printf( esc_html__( 'Help Translate Give to %s', 'give' ), $this->locale_name ); ?></h2>
179 <p><?php echo $message; ?></p>
180 <p>
181 <a href="https://wordpress.org/support/register.php" target="_blank"><?php _e( 'Register now &raquo;', 'give' ); ?></a>
182 </p>
183 </div>
184 </div>
185 <?php
186
187 $notice_html = ob_get_clean();
188
189 // Register notice.
190 Give()->notices->register_notice( array(
191 'id' => 'give-i18n-notice',
192 'type' => 'updated',
193 'description_html' => $notice_html,
194 'show' => true,
195 ) );
196 }
197 }
198
199
200 /**
201 * Output notice css
202 *
203 * @since 1.8.16
204 * @access private
205 */
206 private function print_css() {
207 ?>
208 <style>
209 /* Banner specific styles */
210 div.give-addon-alert.updated {
211 padding: 10px 20px;
212 position: relative;
213 border-color: #66BB6A;
214 overflow: hidden;
215 }
216
217 div.give-addon-alert a {
218 color: #66BB6A;
219 }
220
221 #give-i18n-notice > .give-i18n-icon {
222 overflow: hidden;
223 }
224
225 #give-i18n-notice > .give-i18n-icon .dashicons {
226 width: 110px;
227 height: 110px;
228 }
229
230 #give-i18n-notice > .give-i18n-icon:focus {
231 box-shadow: none;
232 }
233
234 .give-i18n-notice-content {
235 margin: 0 30px 0 125px;
236 }
237
238 div.give-addon-alert .dismiss {
239 position: absolute;
240 right: 20px;
241 height: 100%;
242 top: 50%;
243 margin-top: -10px;
244 outline: none;
245 box-shadow: none;
246 text-decoration: none;
247 color: #AAA;
248 }
249
250 div.give-addon-alert .dismiss:hover {
251 color: #333;
252 }
253
254 /* RTL Styles for banner */
255 body.rtl .give-i18n-notice-content {
256 margin: 0 125px 0 30px;
257 }
258
259 body.rtl div.give-addon-alert .dismiss {
260 left: 20px;
261 right: auto;
262 }
263
264 </style>
265 <?php
266 }
267
268 /**
269 * Try to find the transient for the translation set or retrieve them.
270 *
271 * @access private
272 *
273 * @return object|null
274 */
275 private function find_or_initialize_translation_details() {
276
277 $set = Give_Cache::get( "give_i18n_give_{$this->locale}", true );
278
279 if ( ! $set ) {
280 $set = $this->retrieve_translation_details();
281 Give_Cache::set( "give_i18n_give_{$this->locale}", $set, DAY_IN_SECONDS, true );
282 }
283
284 return $set;
285 }
286
287 /**
288 * Try to get translation details from cache, otherwise retrieve them, then parse them.
289 *
290 * @access private
291 */
292 private function translation_details() {
293 $set = $this->find_or_initialize_translation_details();
294
295 $this->translation_exists = ! is_null( $set );
296 $this->translation_loaded = is_textdomain_loaded( 'give' );
297
298 $this->parse_translation_set( $set );
299 }
300
301 /**
302 * Retrieve the translation details from Give Translate.
303 *
304 * @access private
305 *
306 * @return object|null
307 */
308 private function retrieve_translation_details() {
309
310 $api_url = trailingslashit( $this->glotpress_url );
311
312 $resp = wp_remote_get( $api_url );
313
314 if ( is_wp_error( $resp ) || wp_remote_retrieve_response_code( $resp ) === '404' ) {
315 return null;
316 }
317
318 $body = wp_remote_retrieve_body( $resp );
319 unset( $resp );
320
321 if ( $body ) {
322 $body = json_decode( $body );
323
324 foreach ( $body->translation_sets as $set ) {
325 if ( ! property_exists( $set, 'wp_locale' ) ) {
326 continue;
327 }
328
329 if ( $this->locale == $set->wp_locale ) {
330 return $set;
331 }
332 }
333 }
334
335 return null;
336 }
337
338 /**
339 * Set the needed private variables based on the results from Give Translate.
340 *
341 * @param object $set The translation set
342 *
343 * @access private
344 */
345 private function parse_translation_set( $set ) {
346 if ( $this->translation_exists && is_object( $set ) ) {
347 $this->locale_name = $set->name;
348 $this->percent_translated = $set->percent_translated;
349 } else {
350 $this->locale_name = '';
351 $this->percent_translated = '';
352 }
353 }
354 }
355
356 $give_i18n = new Give_i18n_Banner( array(
357 'hook' => 'admin_notices',
358 'glotpress_url' => 'https://translate.wordpress.org/api/projects/wp-plugins/give/stable/',
359 ) );
360