PluginProbe
Translation with DeepL API / 1.7.5
Translation with DeepL API v1.7.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 1.7.5, at admin/deepl-admin-functions.php

123 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 function deepl_language_selector(
4 $type = 'target',
5 $id = 'deepl_language_selector',
6 $selected = false
7 ) {
8 $languages = DeepLConfiguration::DefaultsAllLanguages();
9
10 $wp_locale = get_locale();
11
12 $default_target_language = DeepLConfiguration::getDefaultTargetLanguage();
13
14 if( $type == 'target' && $selected == false ) {
15 $selected = $default_target_language;
16 //plouf( $languages );
17 }
18
19 $html = '';
20
21 $html .= "\n" . '<select id="' . $id . '" name="' . $id . '">';
22
23 if( $type == 'source' ) $html .= '
24 <option value="auto">' . __( 'Automatic', 'wpdeepl' ) . '</option>';
25
26
27 $languages_to_display = DeepLConfiguration::getDisplayedLanguages();
28
29 foreach( $languages as $ln_id => $language ) {
30
31 if( $languages_to_display && !in_array( $ln_id, $languages_to_display ) ) {
32 continue;
33 }
34 if(
35 $default_target_language
36 && $ln_id == $default_target_language
37 && $type == 'source'
38 ) {
39 //continue;
40 }
41
42 $html .= '
43 <option value="' . $ln_id .'"';
44
45 if( $ln_id == $selected ) {
46 $html .= ' selected="selected"';
47 }
48 $label = ( $wp_locale && isset( $language['labels'][$wp_locale] )) ? $language['labels'][$wp_locale] : $language['labels']['fr_FR'];
49 $html .= '>' . $label. '</option>';
50 }
51 if( $type == 'target' ) $html .= '
52 <option value="notranslation">' . __( 'Dont\'t translate', 'wpdeepl' ) . '</option>';
53
54 $html .="\n</select>";
55
56 return $html;
57 }
58
59 function wpdeepl_show_clear_logs_button() {
60 echo '
61 <p class="submit">
62 <button name="clear_logs" class="button-primary" type="submit" value="clear_logs">' . __('Clear logs', 'wpdeepl') .'</button>
63 </p>';
64
65 }
66
67
68
69 function wpdeepl_clear_logs() {
70 $log_files = glob( trailingslashit( WPDEEPL_FILES ) .'*.log');
71 if($log_files) foreach( $log_files as $log_file) {
72 unlink($log_file);
73 }
74 echo '<div class="notice notice-success"><p>' . __('Log files deleted', 'wpdeepl') . '</p></div>';
75
76
77
78 }
79 function wpdeepl_log( $bits, $type ) {
80 $log_lines = array_merge(array('date' => date('d/m/Y H:i:s')), $bits);
81 $log_line = serialize($log_lines) . "\n";
82 $type = filter_var( $type, FILTER_SANITIZE_STRING );
83 $log_file = trailingslashit( WPDEEPL_FILES ) . date( 'Y-m' ) . '-' . $type . '.log';
84 file_put_contents( $log_file, $log_line, FILE_APPEND );
85 }
86
87 function wpdeepl_display_logs() {
88
89
90 echo '<h3 class="wc-settings-sub-title" id="logs">' . __('Logs','wpdeepl') . '</h3>';
91
92 $log_files = glob( trailingslashit( WPDEEPL_FILES ) .'*.log');
93 if($log_files) {
94 foreach($log_files as $log_file) {
95 $file_name = basename( $log_file );
96 $contents = file_get_contents( $log_file );
97 if(preg_match('#(\d+)-(\d+)-(\w+)\.log#', $file_name, $match)) {
98 $date = $match[2] . '/' . $match[1];
99 echo '<h3>';
100 printf(
101 __("File '%s' for %s", 'wpdeepl' ),
102 $match[3],
103 $date
104 );
105 echo '</h3>';
106
107 $lines = explode("\n", $contents);
108 foreach($lines as $line) {
109 plouf(unserialize($line));
110 }
111
112 }
113
114 }
115 }
116 else {
117 _e( 'No log files', 'wpdeepl' );
118 }
119
120
121 }
122
123