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
wpdeepl / admin / deepl-admin-functions.php

deepl-admin-functions.php in Translation with DeepL API 2.4.5, at admin/deepl-admin-functions.php

181 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
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
22 function deepl_language_selector(
23 $type = 'target',
24 $css_id = 'deepl_language_selector',
25 $selected = false,
26 $not_selected = false,
27 $forbid_auto = false
28 ) {
29 $languages = DeepLConfiguration::DefaultsAllLanguages();
30
31 $wp_locale = get_locale();
32
33 $default_target_language = DeepLConfiguration::getDefaultTargetLanguage();
34
35 if ( $type == 'target' && $selected == false ) {
36 $selected = $default_target_language;
37 //plouf( $languages );
38 }
39
40 $html = "";
41
42 $html .= "\n" . '<select id="' . $css_id . '" name="' . $css_id . '" class="deepl_translate_form">';
43
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>';
54
55 }
56 }
57 }
58
59
60 $languages_to_display = DeepLConfiguration::getDisplayedLanguages();
61
62 foreach ( $languages as $ln_id => $language ) {
63
64 if ( $languages_to_display && !in_array( $ln_id, $languages_to_display ) ) {
65 continue;
66 }
67 if (
68 $default_target_language
69 && $ln_id == $default_target_language
70 && $type == 'source'
71 ) {
72 //continue;
73 }
74
75 $html .= '
76 <option value="' . $ln_id .'"';
77
78 if ( $ln_id == $selected && $ln_id != $not_selected ) {
79 $html .= ' selected="selected"';
80 }
81 $label = ( $wp_locale && isset( $language['labels'][$wp_locale] )) ? $language['labels'][$wp_locale] : $language['labels']['fr_FR'];
82 $html .= '>' . $label. '</option>';
83 }
84 if ( $type == 'target' ) $html .= '
85 <option value="notranslation">' . __( 'Dont\'t translate', 'wpdeepl' ) . '</option>';
86
87 $html .="\n</select>";
88
89 return $html;
90 }
91
92 function wpdeepl_show_clear_logs_button() {
93 echo '
94 <p class="submit">
95 <button name="clear_logs" class="button-primary" type="submit" value="clear_logs">' . __('Clear logs', 'wpdeepl') .'</button>
96 </p>';
97 }
98
99
100
101 function wpdeepl_clear_logs() {
102 $log_files = glob( trailingslashit( WPDEEPL_FILES ) .'*.log');
103 if ($log_files) foreach ( $log_files as $log_file) {
104 unlink($log_file);
105 }
106 echo '<div class="notice notice-success"><p>' . __('Log files deleted', 'wpdeepl') . '</p></div>';
107 }
108 function wpdeepl_log( $bits, $type ) {
109 $log_lines = array_merge(array('date' => date('d/m/Y H:i:s')), $bits);
110 $log_line = serialize($log_lines) . "\n";
111 $type = html_entity_decode( $type );
112 $log_file = trailingslashit( WPDEEPL_FILES ) . date( 'Y-m' ) . '-' . $type . '.log';
113 file_put_contents( $log_file, $log_line, FILE_APPEND );
114 }
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
147 function wpdeepl_display_logs() {
148
149
150 echo '<h3 class="wc-settings-sub-title" id="logs">' . __('Logs','wpdeepl') . '</h3>';
151
152 $log_files = glob( trailingslashit( WPDEEPL_FILES ) .'*.log');
153 if ($log_files) {
154 foreach ($log_files as $log_file) {
155 $file_name = basename( $log_file );
156 $contents = file_get_contents( $log_file );
157 if (preg_match('#(\d+)-(\d+)-(\w+)\.log#', $file_name, $match)) {
158 $date = $match[2] . '/' . $match[1];
159 echo '<h3>';
160 printf(
161 __("File '%s' for %s", 'wpdeepl' ),
162 $match[3],
163 $date
164 );
165 echo '</h3>';
166
167 $lines = explode("\n", $contents);
168 foreach ($lines as $line) {
169 plouf(unserialize($line));
170 }
171
172 }
173
174 }
175 }
176 else {
177 _e( 'No log files', 'wpdeepl' );
178 }
179 }
180
181