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

116 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 foreach( $languages as $ln_id => $language ) {
27 if(
28 $default_target_language
29 && $ln_id == $default_target_language
30 && $type == 'source'
31 ) {
32 continue;
33 }
34
35 $html .= '
36 <option value="' . $ln_id .'"';
37
38 if( $ln_id == $selected ) {
39 $html .= ' selected="selected"';
40 }
41 $label = ( $wp_locale && isset( $language['labels'][$wp_locale] )) ? $language['labels'][$wp_locale] : $language['labels']['fr_FR'];
42 $html .= '>' . $label. '</option>';
43 }
44 if( $type == 'target' ) $html .= '
45 <option value="notranslation">' . __( 'Dont\'t translate', 'wpdeepl' ) . '</option>';
46
47 $html .="\n</select>";
48
49 return $html;
50 }
51
52 function wpdeepl_show_clear_logs_button() {
53 echo '
54 <p class="submit">
55 <button name="clear_logs" class="button-primary" type="submit" value="clear_logs">' . __('Clear logs', 'wpdeepl') .'</button>
56 </p>';
57
58 }
59
60
61
62 function wpdeepl_clear_logs() {
63 $log_files = glob( trailingslashit( WPDEEPL_FILES ) .'*.log');
64 if($log_files) foreach( $log_files as $log_file) {
65 unlink($log_file);
66 }
67 echo '<div class="notice notice-success"><p>' . __('Log files deleted', 'wpdeepl') . '</p></div>';
68
69
70
71 }
72 function wpdeepl_log( $bits, $type ) {
73 $log_lines = array_merge(array('date' => date('d/m/Y H:i:s')), $bits);
74 $log_line = serialize($log_lines) . "\n";
75 $type = filter_var( $type, FILTER_SANITIZE_STRING );
76 $log_file = trailingslashit( WPDEEPL_FILES ) . date( 'Y-m' ) . '-' . $type . '.log';
77 file_put_contents( $log_file, $log_line, FILE_APPEND );
78 }
79
80 function wpdeepl_display_logs() {
81
82
83 echo '<h3 class="wc-settings-sub-title" id="logs">' . __('Logs','wpdeepl') . '</h3>';
84
85 $log_files = glob( trailingslashit( WPDEEPL_FILES ) .'*.log');
86 if($log_files) {
87 foreach($log_files as $log_file) {
88 $file_name = basename( $log_file );
89 $contents = file_get_contents( $log_file );
90 if(preg_match('#(\d+)-(\d+)-(\w+)\.log#', $file_name, $match)) {
91 $date = $match[2] . '/' . $match[1];
92 echo '<h3>';
93 printf(
94 __("File '%s' for %s", 'wpdeepl' ),
95 $match[3],
96 $date
97 );
98 echo '</h3>';
99
100 $lines = explode("\n", $contents);
101 foreach($lines as $line) {
102 plouf(unserialize($line));
103 }
104
105 }
106
107 }
108 }
109 else {
110 _e( 'No log files', 'wpdeepl' );
111 }
112
113
114 }
115
116