PluginProbe
Translation with DeepL API / 2.4.5
Translation with DeepL API v2.4.5
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
← All changes | admin/deepl-admin-functions.php +85 -27 1.7.52.4.5 View file →
@@ -1,10 +1,31 @@
1 1 <?php
2 2
3 +function wpdeepl_test_admin() {
4 +
5 +
6 + return;
7 + /*
8 + $glossary_id = 'da005df2-fb26-4165-8310-b07c9cc1b492';
9 + $list = deepl_listGlossaryEntries( $glossary_id, 'tsv' );
10 + plouf( $list );
11 + die('okazeaze6a8z4e6e4az4');
12 +*/
13 + //deepl_deleteGlosssary( );
14 +
15 +
16 +}
17 +
18 +
19 +
20 +
21 +
3 22 function deepl_language_selector(
4 23 $type = 'target',
5 - $id = 'deepl_language_selector',
6 - $selected = false
24 + $css_id = 'deepl_language_selector',
25 + $selected = false,
26 + $not_selected = false,
27 + $forbid_auto = false
7 28 ) {
8 29 $languages = DeepLConfiguration::DefaultsAllLanguages();
9 30
10 31 $wp_locale = get_locale();
@@ -10,32 +31,44 @@
10 31 $wp_locale = get_locale();
11 32
12 33 $default_target_language = DeepLConfiguration::getDefaultTargetLanguage();
13 34
14 - if( $type == 'target' && $selected == false ) {
35 + if ( $type == 'target' && $selected == false ) {
15 36 $selected = $default_target_language;
16 37 //plouf( $languages );
17 38 }
18 39
19 - $html = '';
40 + $html = "";
20 41
21 - $html .= "\n" . '<select id="' . $id . '" name="' . $id . '">';
42 + $html .= "\n" . '<select id="' . $css_id . '" name="' . $css_id . '" class="deepl_translate_form">';
22 43
23 - if( $type == 'source' ) $html .= '
24 - <option value="auto">' . __( 'Automatic', 'wpdeepl' ) . '</option>';
44 + if ( $type == 'source' ) {
45 + if( !$forbid_auto ) {
46 + if( !defined('WPDEEPLPRO_NAME') || !DeepLConfiguration::usingGlossaries() ) {
47 + $html .= '
48 + <option value="auto">' . __( 'Automatic', 'wpdeepl' ) . '</option>';
49 + }
50 +
51 + else {
52 + $html .= '
53 + <option value="auto">' . __( 'Automatic (no glossary)', 'wpdeepl' ) . '</option>';
25 54
55 + }
56 + }
57 + }
26 58
59 +
27 60 $languages_to_display = DeepLConfiguration::getDisplayedLanguages();
28 61
29 - foreach( $languages as $ln_id => $language ) {
62 + foreach ( $languages as $ln_id => $language ) {
30 63
31 - if( $languages_to_display && !in_array( $ln_id, $languages_to_display ) ) {
64 + if ( $languages_to_display && !in_array( $ln_id, $languages_to_display ) ) {
32 65 continue;
33 66 }
34 - if(
67 + if (
35 68 $default_target_language
36 69 && $ln_id == $default_target_language
37 - && $type == 'source'
70 + && $type == 'source'
38 71 ) {
39 72 //continue;
40 73 }
41 74
@@ -41,15 +74,15 @@
41 74
42 75 $html .= '
43 76 <option value="' . $ln_id .'"';
44 77
45 - if( $ln_id == $selected ) {
78 + if ( $ln_id == $selected && $ln_id != $not_selected ) {
46 79 $html .= ' selected="selected"';
47 80 }
48 81 $label = ( $wp_locale && isset( $language['labels'][$wp_locale] )) ? $language['labels'][$wp_locale] : $language['labels']['fr_FR'];
49 82 $html .= '>' . $label. '</option>';
50 83 }
51 - if( $type == 'target' ) $html .= '
84 + if ( $type == 'target' ) $html .= '
52 85 <option value="notranslation">' . __( 'Dont\'t translate', 'wpdeepl' ) . '</option>';
53 86
54 87 $html .="\n</select>";
55 88
@@ -60,9 +93,8 @@
60 93 echo '
61 94 <p class="submit">
62 95 <button name="clear_logs" class="button-primary" type="submit" value="clear_logs">' . __('Clear logs', 'wpdeepl') .'</button>
63 96 </p>';
64 -
65 97 }
66 98
67 99
68 100
@@ -67,38 +99,66 @@
67 99
68 100
69 101 function wpdeepl_clear_logs() {
70 102 $log_files = glob( trailingslashit( WPDEEPL_FILES ) .'*.log');
71 - if($log_files) foreach( $log_files as $log_file) {
103 + if ($log_files) foreach ( $log_files as $log_file) {
72 104 unlink($log_file);
73 105 }
74 106 echo '<div class="notice notice-success"><p>' . __('Log files deleted', 'wpdeepl') . '</p></div>';
75 -
76 -
77 -
78 107 }
79 108 function wpdeepl_log( $bits, $type ) {
80 109 $log_lines = array_merge(array('date' => date('d/m/Y H:i:s')), $bits);
81 110 $log_line = serialize($log_lines) . "\n";
82 - $type = filter_var( $type, FILTER_SANITIZE_STRING );
111 + $type = html_entity_decode( $type );
83 112 $log_file = trailingslashit( WPDEEPL_FILES ) . date( 'Y-m' ) . '-' . $type . '.log';
84 113 file_put_contents( $log_file, $log_line, FILE_APPEND );
85 114 }
86 115
116 +
117 +function wpdeepl_prune_logs() {
118 + if ( !current_user_can( 'manage_options' ) ) {
119 + return false;
120 + }
121 +
122 + if( !wp_verify_nonce( $_GET[ 'nonce' ], 'prune_logs' ) ) {
123 + return false;
124 + }
125 +
126 + $logs = glob( trailingslashit( WPDEEPL_FILES ) . '*.log');
127 + if ($logs) foreach ($logs as $log_file) {
128 + $file_name = basename( $log_file );
129 + if (preg_match('#(\d+)-(\d+)-(\w+)\.log#', $file_name, $match)) {
130 + //$date = $match[2] . '/' . $match[1];
131 +
132 + $log_time = mktime(0, 0, 0, $match[2], 1, $match[1] );
133 +
134 + $first_day_of_the_month = new DateTime('first day of this month');
135 + $first_day_of_the_month->modify('- 1 day');
136 + $first_day_time = $first_day_of_the_month->getTimestamp();
137 +
138 + if ( $log_time < $first_day_time ) {
139 + //echo " <br />SUPPRESSION $log_file : " . date('Y-m-d H:i:s', $log_time) . " < " . date('Y-m-d H:i:s', $first_day_time );
140 + unlink( $log_file );
141 + }
142 + }
143 + }
144 +}
145 +
146 +
87 147 function wpdeepl_display_logs() {
88 148
89 -
149 +
90 150 echo '<h3 class="wc-settings-sub-title" id="logs">' . __('Logs','wpdeepl') . '</h3>';
91 151
92 152 $log_files = glob( trailingslashit( WPDEEPL_FILES ) .'*.log');
93 - if($log_files) {
94 - foreach($log_files as $log_file) {
153 + if ($log_files) {
154 + foreach ($log_files as $log_file) {
95 155 $file_name = basename( $log_file );
96 156 $contents = file_get_contents( $log_file );
97 - if(preg_match('#(\d+)-(\d+)-(\w+)\.log#', $file_name, $match)) {
157 + if (preg_match('#(\d+)-(\d+)-(\w+)\.log#', $file_name, $match)) {
98 158 $date = $match[2] . '/' . $match[1];
99 159 echo '<h3>';
100 - printf(
160 + printf(
101 161 __("File '%s' for %s", 'wpdeepl' ),
102 162 $match[3],
103 163 $date
104 164 );
@@ -104,9 +164,9 @@
104 164 );
105 165 echo '</h3>';
106 166
107 167 $lines = explode("\n", $contents);
108 - foreach($lines as $line) {
168 + foreach ($lines as $line) {
109 169 plouf(unserialize($line));
110 170 }
111 171
112 172 }
@@ -115,8 +175,6 @@
115 175 }
116 176 else {
117 177 _e( 'No log files', 'wpdeepl' );
118 178 }
119 -
120 -
121 179 }
122 180