PluginProbe
Translation with DeepL API / 2.4.3.9
Translation with DeepL API v2.4.3.9
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.3.9, at admin/deepl-admin-functions.php

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