PluginProbe
Translation with DeepL API / 0.1.20180323
Translation with DeepL API v0.1.20180323
trunk 0.1.20180323 1.0 1.2.5.1 1.5.2.5 1.7.5 2.4.3.12 2.4.3.9 2.4.5
wpdeepl / admin.php

admin.php in Translation with DeepL API 0.1.20180323, at admin.php

145 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3
4 add_action('admin_menu','wpdeepl_add_submenu');
5
6 function wpdeepl_add_submenu() {
7 add_submenu_page(
8 'options-general.php',
9 __('DeepL translation', 'wpdeepl_i18n'),
10 __('DeepL', 'wpdeepl_i18n'),
11 'edit_posts',
12 'wpdeepl',
13 'wpdeepl_admin_page'
14 );
15
16 }
17
18
19 function wpdeepl_admin_page() {
20
21 $option_keys = array('wpdeepl_key','wpdeepl_default_locale','wpdeepl_replace_content');
22
23 if($_REQUEST['action'] == 'update') {
24 check_admin_referer( 'wpdeepl_settings');
25
26 foreach($option_keys as $option_key) {
27 update_option( $option_key, $_REQUEST[$option_key]);
28 }
29 }
30
31 foreach($option_keys as $option_key) {
32 $options[$option_key] = get_option($option_key);
33 }
34
35 $WPDeepL_Metabox = new WPDeepL_Metabox();
36
37
38 ?>
39 <style type="text/css">
40 .progress-bar {
41 background-color: #1a1a1a;
42 height: 30px;
43 padding: 5px;
44 width: 500px;
45 margin: 5px 0;
46 border-radius: 5px;
47 box-shadow: 0 1px 5px #000 inset, 0 1px 0 #444;
48 }
49 .progress-bar span {
50 display: inline-block;
51 float: left;
52 height: 100%;
53 border-radius: 3px;
54 box-shadow: 0 1px 0 rgba(255, 255, 255, .5) inset;
55 transition: width .4s ease-in-out;
56 }
57 .blue span {
58 background-color: #34c2e3;
59 }
60 .orange span {
61 background-color: #fecf23;
62 }
63 .progress-text {
64 text-align: right;
65 color: #000;
66 margin: -25px 0px;
67 }
68
69 </style>
70 <div class="wrap">
71 <form method="get" id="wpdeepl-form">
72 <input type="hidden" name="page" value="wpdeepl" />
73 <input type="hidden" name="action" value="update" />
74 <h2><?php _e( 'Settings', 'wpdeepl_i18n' ); ?></h2>
75
76 <?php if(get_option('wpdeepl_key')) : ?>
77 <h3><?php _e('Usage','wpdeepl_i18n'); ?></h3>
78 <?php
79 $DeepLApiUsage = new DeepLApiUsage(get_option('wpdeepl_key'));
80 $usage = $DeepLApiUsage->request();
81
82
83 if($usage) {
84 $ratio = round(100 * ( $usage['character_count'] / $usage['character_limit']),4);
85
86 ?>
87 <div class="progress-bar blue">
88 <span style="width: <?php echo round((100 - $ratio),0); ?>%"></span>
89 <div class="progress-text"><?php
90 printf(__('%s / %s characters translated','wpdeepl_i18n'),$usage['character_count'], $usage['character_limit'] );
91 echo " - " . $ratio; ?> %</div>
92 </div>
93
94
95 <?php
96 }
97 endif; ?>
98
99
100 <?php wp_nonce_field( 'wpdeepl_settings' ); ?>
101
102 <table class="form-table">
103 <tbody>
104 <tr>
105 <th scope="row"><label for="wpdeepl_default_locale"><?php _e('Default locale','wpdeepl_i18n'); ?></label></th>
106 <td><?php echo $WPDeepL_Metabox->language_selector('wpdeepl_default_locale',$options['wpdeepl_default_locale'], false, true); ?></td>
107 </tr>
108 <tr>
109 <th scope="row"><label for="wpdeepl_key"><?php _e('API Key','wpdeepl_i18n'); ?></label></th>
110 <td><input type="text" size="50" name="wpdeepl_key" value="<?php echo $options['wpdeepl_key']; ?>" />
111 <p class="description"><?php printf(__('<a href="%s">Get a DeepL Pro Account here</a>. Get your API Key from <a href="%s">DeepL account page</a>','wpdeepl_i18n'),'https://www.deepl.com/pro.html','https://www.deepl.com/subscription.html'); ?></p>
112 </td>
113 </tr>
114 <tr>
115 <th scope="row"><label for="wpdeepl_replace_content"><?php _e('Default behavior','wpdeepl_i18n'); ?></label></th>
116 <td>
117 <?php
118 $choices = array(
119 '1' => __('Replace content','wpdeepl_i18n'),
120 '2' => __('Append to content','wpdeepl_i18n'),
121 );
122 foreach($choices as $value => $label) : ?>
123 <span style="display: block;">
124 <input type="radio" name="wpdeepl_replace_content" value="<?php echo $value; ?>"<?php
125 if($value == $options['wpdeepl_replace_content']) echo ' checked="checked"'; ?>>
126 <label><?php echo $label; ?></label>
127 </span>
128 <?php endforeach; ?>
129 <br />
130 </td>
131
132 </tr>
133
134 </tbody>
135
136 </table>
137
138 <?php submit_button(); ?>
139
140 </form>
141
142 <?php
143
144 return;
145 }