wpml-plugin-string-scanner.class.php
1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
use WPML\API\Sanitize;
class WPML_Plugin_String_Scanner extends WPML_String_Scanner implements IWPML_ST_String_Scanner {
private $current_plugin_file;
public function scan() {
$plugin_file = $_POST['plugin'];
$this->current_plugin_file = WPML_PLUGINS_DIR . '/' . $plugin_file;
$this->current_type = 'plugin';
$this->current_path = dirname( $this->current_plugin_file );
$this->text_domain = $this->get_plugin_text_domain();
$this->scan_starting( $this->current_type );
$text_domain = $this->get_plugin_text_domain();
$this->init_text_domain( $text_domain );
$this->scan_plugin_files();
$this->current_type = 'plugin';
$this->set_stats( 'plugin_localization_domains', $plugin_file );
$this->scan_response();
}
private function scan_plugin_files( $dir_or_file = false, $recursion = 0 ) {
require_once WPML_ST_PATH . '/inc/potx.php';
foreach ( $_POST['files'] as $file ) {
$file = (string) Sanitize::string( $file );
if ( $this->file_hashing->hash_changed( $file ) ) {
_potx_process_file( $file, 0, array( $this, 'store_results' ), '_potx_save_version', $this->get_default_domain() );
$this->add_scanned_file( $file );
}
}
}
private function get_plugin_text_domain() {
$text_domain = '';
if ( ! function_exists( 'get_plugin_data' ) ) {
include_once ABSPATH . '/wp-admin/includes/plugin.php';
}
if ( function_exists( 'get_plugin_data' ) ) {
$plugin_data = get_plugin_data( $this->current_plugin_file );
if ( isset( $plugin_data['TextDomain'] ) && $plugin_data['TextDomain'] != '' ) {
$text_domain = $plugin_data['TextDomain'];
return $text_domain;
}
return $text_domain;
}
return $text_domain;
}
}